![]() |
deal.II version GIT relicensing-2879-g253433159b 2025-03-21 00:10:00+00:00
|
#include <deal.II/differentiation/sd/symengine_number_visitor_internal.h>
Public Member Functions | |
CSEDictionaryVisitor ()=default | |
virtual | ~CSEDictionaryVisitor ()=default |
void | init (const types::symbol_vector &dependent_functions) |
void | call (ReturnType *output_values, const types::symbol_vector &independent_symbols, const ReturnType *substitution_values) |
template<class Archive > | |
void | save (Archive &archive, const unsigned int version) const |
template<class Archive > | |
void | load (Archive &archive, const unsigned int version) |
template<class Archive > | |
void | serialize (Archive &archive, const unsigned int version) |
template<typename StreamType > | |
void | print (StreamType &stream) const |
bool | executed () const |
unsigned int | n_intermediate_expressions () const |
unsigned int | n_reduced_expressions () const |
Protected Member Functions | |
void | init (const SymEngine::vec_basic &dependent_functions) |
void | call (ReturnType *output_values, const SymEngine::vec_basic &independent_symbols, const ReturnType *substitution_values) |
Private Types | |
using | symbol_vector_pair = std::vector< std::pair< SD::Expression, SD::Expression > > |
Private Attributes | |
symbol_vector_pair | intermediate_symbols_exprs |
types::symbol_vector | reduced_exprs |
A class that implements common subexpression elimination for dictionary visitor classes.
It is intended that this class only be used in conjunction with the DictionarySubstitutionVisitor.
Definition at line 54 of file symengine_number_visitor_internal.h.
|
private |
Definition at line 56 of file symengine_number_visitor_internal.h.
|
default |
|
virtualdefault |
void Differentiation::SD::internal::CSEDictionaryVisitor< ReturnType, ExpressionType >::init | ( | const types::symbol_vector & | dependent_functions | ) |
Initialize and perform common subexpression elimination.
Here we build the reduced expressions for the dependent_functions
as well as a list of intermediate, repeating symbolic expressions that are extracted dependent_functions
. This operation leads to the elimination of repeated expressions, so they only have to be evaluated once.
dependent_functions | A vector of expressions that represent the dependent functions that CSE will be performed on. |
void Differentiation::SD::internal::CSEDictionaryVisitor< ReturnType, ExpressionType >::call | ( | ReturnType * | output_values, |
const types::symbol_vector & | independent_symbols, | ||
const ReturnType * | substitution_values | ||
) |
Evaluate the (reduced) dependent functions using the common subexpressions generated during the call to init().
The output_values
are the numerical result of substituting each of the substitution_values
for their corresponding entry of the independent_symbols
. Specifically, we first calculate the numerical values of each reduced subexpression, and feed those into a reduced equivalent of the dependent variables. The result of this is then written into the output_values
array.
[out] | output_values | A pointer to the first element in an array of type ReturnType . After this call, the underlying array will hold the numerical result of substituting the substitution_values into the pre-registered dependent functions. |
[in] | independent_symbols | A vector of symbols that represent the independent variables that are arguments to the previously defined dependent functions. |
[in] | substitution_values | A pointer to the first element in an array of type ReturnType . Each entry in this array stores the numerical value that an independent variable is to take for the purpose of value substitution. |
output_values
and substitution_values
arrays be correctly dimensioned, as there is no range checking performed on these data structures. The output_values
array should have the same number of elements as the dependent functions first passed to this class in the call to init(). Similarly, the substitution_values
array should have the same number of elements as the independent_symbols
vector has.independent_symbols
and substitution_values
. This is not checked within this function, so it is up to the user to ensure that the relationships between the independent variables and their numerical value be correctly set up and maintained. void Differentiation::SD::internal::CSEDictionaryVisitor< ReturnType, ExpressionType >::save | ( | Archive & | archive, |
const unsigned int | version | ||
) | const |
Write the data of this object to a stream for the purpose of serialization using the BOOST serialization library.
void Differentiation::SD::internal::CSEDictionaryVisitor< ReturnType, ExpressionType >::load | ( | Archive & | archive, |
const unsigned int | version | ||
) |
Read the data for this object from a stream for the purpose of serialization using the BOOST serialization library.
void Differentiation::SD::internal::CSEDictionaryVisitor< ReturnType, ExpressionType >::serialize | ( | Archive & | archive, |
const unsigned int | version | ||
) |
Write and read the data of this object from a stream for the purpose of serialization using the BOOST serialization library.
void Differentiation::SD::internal::CSEDictionaryVisitor< ReturnType, ExpressionType >::print | ( | StreamType & | stream | ) | const |
Print all of the intermediate reduced expressions, as well as the final reduced expressions for dependent variables to the stream
.
bool Differentiation::SD::internal::CSEDictionaryVisitor< ReturnType, ExpressionType >::executed | ( | ) | const |
Return a flag stating whether we've performed CSE or not.
unsigned int Differentiation::SD::internal::CSEDictionaryVisitor< ReturnType, ExpressionType >::n_intermediate_expressions | ( | ) | const |
The number of intermediate expressions that must be evaluated as part of the collection of common subexpressions.
unsigned int Differentiation::SD::internal::CSEDictionaryVisitor< ReturnType, ExpressionType >::n_reduced_expressions | ( | ) | const |
The size of the final set of reduced expressions.
|
protected |
Initialize and perform common subexpression elimination.
This function performs the same action as the other init() function, except that it works with native SymEngine data types; the single argument is a vector of SymEngine::RCP<const SymEngine::Basic>
.
dependent_functions | A vector of expressions that represent the dependent functions that CSE will be performed on. |
|
protected |
Evaluate the (reduced) dependent functions using the common subexpressions generated during the call to init().
This function performs the same action as the other init() function, except that it works with native SymEngine data types. The independent_symbols
is represented by a vector of SymEngine::RCP<const SymEngine::Basic>
.
[out] | output_values | A pointer to the first element in an array of type ReturnType . After this call, the underlying array will hold the numerical result of substituting the substitution_values into the pre-registered dependent functions. |
[in] | independent_symbols | A vector of symbols that represent the independent variables that are arguments to the previously defined dependent functions. |
[in] | substitution_values | A pointer to the first element in an array of type ReturnType . Each entry in this array stores the numerical value that an independent variable is to take for the purpose of value substitution. |
|
private |
Intermediate symbols and their definition.
Definition at line 242 of file symengine_number_visitor_internal.h.
|
private |
Final reduced expressions.
Definition at line 247 of file symengine_number_visitor_internal.h.