Reference documentation for deal.II version 9.5.0
|
#include <deal.II/differentiation/sd/symengine_number_types.h>
Public Member Functions | |
Constructors | |
Expression () | |
Expression (const bool value) | |
template<typename NumberType , typename = std::enable_if_t<std::is_arithmetic<NumberType>::value>> | |
Expression (const NumberType &value) | |
template<typename NumberType , typename = std::enable_if_t<std::is_arithmetic<NumberType>::value>> | |
Expression (const std::complex< NumberType > &value) | |
Expression (const SymEngine::integer_class &value) | |
template<typename NumberType , typename = std::enable_if_t<std::is_integral<NumberType>::value>> | |
Expression (const NumberType &numerator, const NumberType &denominator) | |
Expression (const SymEngine::rational_class &value) | |
Expression (const Expression &condition, const Expression &expression_if_true, const Expression &expression_if_false) | |
Expression (const std::vector< std::pair< Expression, Expression > > &condition_expression, const Expression &expression_otherwise) | |
Expression (const std::vector< std::pair< Expression, Expression > > &condition_expression) | |
Expression (const char *symbol) | |
Expression (const std::string &symb_expr, const bool parse_as_expression=false) | |
Expression (const std::string &symbol_func, const types::symbol_vector &arguments) | |
Expression (const Expression &rhs)=default | |
Expression (const SymEngine::Expression &rhs) | |
Expression (const SymEngine::RCP< const SymEngine::Basic > &rhs) | |
Expression (Expression &&rhs)=default | |
Expression (SymEngine::RCP< const SymEngine::Basic > &&rhs) | |
virtual | ~Expression ()=default |
Expression & | parse (const std::string &expression) |
std::ostream & | print (std::ostream &stream) const |
void | save (std::ostream &stream) const |
void | load (std::istream &stream) |
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) |
Values | |
const SymEngine::Expression & | get_expression () const |
const SymEngine::Basic & | get_value () const |
const SymEngine::RCP< const SymEngine::Basic > & | get_RCP () const |
Math and relational operators with (potentially) symbolic types | |
Expression & | operator= (const Expression &rhs) |
Expression & | operator= (Expression &&rhs) noexcept |
Expression & | operator+= (const Expression &rhs) |
Expression & | operator-= (const Expression &rhs) |
Expression & | operator*= (const Expression &rhs) |
Expression & | operator/= (const Expression &rhs) |
Math and relational operators with numeric types | |
template<typename NumberType > | |
Expression & | operator= (const NumberType &rhs) |
Expression | operator- () const |
template<typename NumberType > | |
Expression & | operator+= (const NumberType &rhs) |
template<typename NumberType > | |
Expression & | operator-= (const NumberType &rhs) |
template<typename NumberType > | |
Expression & | operator*= (const NumberType &rhs) |
template<typename NumberType > | |
Expression & | operator/= (const NumberType &rhs) |
Differentiation | |
Expression | differentiate (const Expression &symbol) const |
Expression | differentiate (const SymEngine::RCP< const SymEngine::Symbol > &symbol) const |
Expression | differentiate (const SymEngine::RCP< const SymEngine::Basic > &symbol) const |
Dictionary-based substitution | |
Expression | substitute (const types::substitution_map &substitution_values) const |
Expression | substitute (const SymEngine::map_basic_basic &substitution_values) const |
Expression | substitute (const Expression &symbol, const Expression &value) const |
template<typename NumberType > | |
Expression | substitute (const Expression &symbol, const NumberType &value) const |
template<typename ReturnType > | |
ReturnType | substitute_and_evaluate (const types::substitution_map &substitution_values) const |
template<typename ReturnType > | |
ReturnType | substitute_and_evaluate (const SymEngine::map_basic_basic &substitution_values) const |
Conversion operators | |
template<typename ResultType > | |
operator ResultType () const | |
operator const SymEngine::Expression & () const | |
operator const SymEngine::RCP< const SymEngine::Basic > & () const | |
Protected Member Functions | |
SymEngine::Expression & | get_expression () |
Private Attributes | |
SymEngine::Expression | expression |
A class to wrap SymEngine expressions.
With this number type, SymEngine numbers can be used to perform scalar and tensor mathematics in deal.II. It (or the SymEngine::Expression class, of which it stores an instance) therefore forms the basis of symbolic computation via SymEngine in deal.II. With it one can perform symbolic differentiation and subsequent substitution with both scalars and deal.II's native Tensor and SymmetricTensor types.
The symbolic features that this class supports includes:
A simple example of how this class may be used is as follows:
A more intricate example of conditional evaluation is as follows:
Lastly, here is an example using symbolic differentiation:
Definition at line 177 of file symengine_number_types.h.
Differentiation::SD::Expression::Expression | ( | ) |
Default constructor.
Definition at line 48 of file symengine_number_types.cc.
|
explicit |
Constructor for boolean types.
Definition at line 53 of file symengine_number_types.cc.
|
explicit |
Constructor for arithmetic number types.
|
explicit |
Constructor for complex numbers templated on arithmetic number types.
Differentiation::SD::Expression::Expression | ( | const SymEngine::integer_class & | value | ) |
Constructor for integer types.
Definition at line 58 of file symengine_number_types.cc.
Differentiation::SD::Expression::Expression | ( | const NumberType & | numerator, |
const NumberType & | denominator | ||
) |
Constructor for rational types.
It is expected that both the numerator
and denominator
be integral types.
Differentiation::SD::Expression::Expression | ( | const SymEngine::rational_class & | value | ) |
Constructor for rational types.
Definition at line 63 of file symengine_number_types.cc.
Differentiation::SD::Expression::Expression | ( | const Expression & | condition, |
const Expression & | expression_if_true, | ||
const Expression & | expression_if_false | ||
) |
Constructor for a piecewise defined function.
The generated expression may be interpreted as the result of the teniary operator, i.e. (condition ? expression_if_true : expression_if_false)
.
The condition
can be any expression that renders an expression that is convertible to a SymEngine::Boolean operator. This includes:
An example of this constructor's use is as follows:
Definition at line 68 of file symengine_number_types.cc.
Differentiation::SD::Expression::Expression | ( | const std::vector< std::pair< Expression, Expression > > & | condition_expression, |
const Expression & | expression_otherwise | ||
) |
Constructor for a piecewise defined function.
The generated expression may be interpreted as the result of the set of nested if-elseif-else statements, i.e. (in pseudo-code)
if the input vector has more than 2 elements.
This variant takes the piecewise evaluated conditions and its results as the first argument, and the default return value as the second argument.
Definition at line 84 of file symengine_number_types.cc.
Differentiation::SD::Expression::Expression | ( | const std::vector< std::pair< Expression, Expression > > & | condition_expression | ) |
Constructor for a piecewise defined function.
The generated expression may be interpreted as the result of the set of nested if-elseif statements, i.e. (in pseudo-code)
if the input vector has more than 2 elements.
This variant takes only the piecewise evaluated conditions and its results. If none of the conditions are met upon evaluation then the returned result will be NaN.
Definition at line 111 of file symengine_number_types.cc.
Differentiation::SD::Expression::Expression | ( | const char * | symbol | ) |
Constructor for symbolic types.
This constructor initializes a symbolic type with a character array representing its symbolic value.
Definition at line 122 of file symengine_number_types.cc.
Differentiation::SD::Expression::Expression | ( | const std::string & | symb_expr, |
const bool | parse_as_expression = false |
||
) |
Constructor for symbolic types.
This constructor initializes a symbolic type with a string representing its symbolic value. If the parse_as_expression
flag is false
, then the symb_expr
(potentially composed of multiple characters) will be interpreted as a single symbol. If the parse_as_expression
flag is true
, then the symb_expr
will be parsed as a symbolic expression (potentially composed of multiple symbols, constants, etc.).
Definition at line 127 of file symengine_number_types.cc.
Differentiation::SD::Expression::Expression | ( | const std::string & | symbol_func, |
const types::symbol_vector & | arguments | ||
) |
Constructor for function symbol types.
This constructor initializes a function symbol with a string representing its symbolic name.
Definition at line 145 of file symengine_number_types.cc.
|
default |
Copy constructor.
|
explicit |
Copy constructor.
Definition at line 153 of file symengine_number_types.cc.
Differentiation::SD::Expression::Expression | ( | const SymEngine::RCP< const SymEngine::Basic > & | rhs | ) |
Copy constructor.
This allows us to create our class straight from the results of SymEngine operations. This is especially important for operations like "diff", because the returned result is not primitive, but rather a set of compound operations.
Definition at line 158 of file symengine_number_types.cc.
|
default |
Move constructor.
Differentiation::SD::Expression::Expression | ( | SymEngine::RCP< const SymEngine::Basic > && | rhs | ) |
Move constructor.
This allows us to create our class straight from the results of SymEngine operations. This is especially important for operations like "diff", because the returned result is not primitive, but rather a set of compound operations.
Definition at line 163 of file symengine_number_types.cc.
|
virtualdefault |
Destructor.
Expression & Differentiation::SD::Expression::parse | ( | const std::string & | expression | ) |
Utilities Parse an expression from a string representing a symbolic expression
. This overwrites any existing value or expression that this object represents.
Definition at line 172 of file symengine_number_types.cc.
std::ostream & Differentiation::SD::Expression::print | ( | std::ostream & | stream | ) | const |
Print the value stored by this object.
Since the stored value could be one of a number of types, we leave SymEngine to cast and output the correct representation of the data.
Definition at line 180 of file symengine_number_types.cc.
void Differentiation::SD::Expression::save | ( | std::ostream & | stream | ) | const |
Save the value stored by this object to the stream
.
Each expression will be saved on a new line of the stream
.
Definition at line 188 of file symengine_number_types.cc.
void Differentiation::SD::Expression::load | ( | std::istream & | stream | ) |
Load the value stored in the stream
into this object using the BOOST serialization library.
It is expected that each expression appears on its own on single line of stream
.
Definition at line 198 of file symengine_number_types.cc.
void Differentiation::SD::Expression::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.
This effectively saves the value stored in this object to the archive
with the given version
number.
void Differentiation::SD::Expression::load | ( | Archive & | archive, |
const unsigned int | version | ||
) |
Read the data of this object from a stream for the purpose of serialization.
This effectively loads into this object the value stored in of the archive
with the given version
number. In doing so, the previous contents of this object are thrown away.
void Differentiation::SD::Expression::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.
This effectively saves or loads the value stored into/out of the archive
with the given version
number into this object. If deserializing data, then the previous contents of this object are thrown away.
const SE::Expression & Differentiation::SD::Expression::get_expression | ( | ) | const |
Return the value or expression that this class instance represents.
Definition at line 213 of file symengine_number_types.cc.
const SE::Basic & Differentiation::SD::Expression::get_value | ( | ) | const |
Return the primitive SymEngine data type that stores the value or expression represented by this object.
Definition at line 227 of file symengine_number_types.cc.
const SE::RCP< const SE::Basic > & Differentiation::SD::Expression::get_RCP | ( | ) | const |
Return the pointer to the primitive SymEngine data type that stores the value or expression represented by this object.
Definition at line 234 of file symengine_number_types.cc.
Expression & Differentiation::SD::Expression::operator= | ( | const Expression & | rhs | ) |
Assignment operator.
Sets the data of this object's expression
equal to that of the rhs
object.
Definition at line 320 of file symengine_number_types.cc.
|
noexcept |
Assignment operator.
Sets the data of this object's expression
equal to that of the rhs
object.
Definition at line 330 of file symengine_number_types.cc.
Expression & Differentiation::SD::Expression::operator+= | ( | const Expression & | rhs | ) |
Addition assignment.
The rhs
expression
is added in-place to that of this object's expression
.
Definition at line 347 of file symengine_number_types.cc.
Expression & Differentiation::SD::Expression::operator-= | ( | const Expression & | rhs | ) |
Subtraction assignment.
The rhs
expression
is subtracted in-place from that of this object's expression
.
Definition at line 355 of file symengine_number_types.cc.
Expression & Differentiation::SD::Expression::operator*= | ( | const Expression & | rhs | ) |
Multiplication assignment.
This object's expression
is multiplied in-place by that of the rhs
expression
.
Definition at line 363 of file symengine_number_types.cc.
Expression & Differentiation::SD::Expression::operator/= | ( | const Expression & | rhs | ) |
Division assignment.
This object's expression
is divided in-place by that of the rhs
expression
.
Definition at line 371 of file symengine_number_types.cc.
Expression & Differentiation::SD::Expression::operator= | ( | const NumberType & | rhs | ) |
Assignment operator.
Set the data of this object's expression
equal to the numerical value of the rhs
.
Expression Differentiation::SD::Expression::operator- | ( | ) | const |
Negation operator.
Return a the result of pre-multipying this object's expression
by -1
.
Definition at line 340 of file symengine_number_types.cc.
Expression & Differentiation::SD::Expression::operator+= | ( | const NumberType & | rhs | ) |
Addition assignment.
The numerical value of the rhs
is added in-place to that of this object's expression
.
Expression & Differentiation::SD::Expression::operator-= | ( | const NumberType & | rhs | ) |
Subtraction assignment.
The numerical value of the rhs
is subtracted in-place from that of this object's expression
.
Expression & Differentiation::SD::Expression::operator*= | ( | const NumberType & | rhs | ) |
Multiplication assignment.
This object's expression
is multiplied in-place by that of the numerical value of the rhs
.
Expression & Differentiation::SD::Expression::operator/= | ( | const NumberType & | rhs | ) |
Division assignment.
This object's expression
is divided in-place by that of the numerical value of the rhs
.
Expression Differentiation::SD::Expression::differentiate | ( | const Expression & | symbol | ) | const |
Return the derivative of this object's expression
with respect to the given symbol
.
Definition at line 261 of file symengine_number_types.cc.
Expression Differentiation::SD::Expression::differentiate | ( | const SymEngine::RCP< const SymEngine::Symbol > & | symbol | ) | const |
Return the derivative of this object's expression
with respect to the given symbol
.
Definition at line 244 of file symengine_number_types.cc.
Expression Differentiation::SD::Expression::differentiate | ( | const SymEngine::RCP< const SymEngine::Basic > & | symbol | ) | const |
Return the derivative of this object's expression
with respect to the potential symbol
.
Definition at line 252 of file symengine_number_types.cc.
Expression Differentiation::SD::Expression::substitute | ( | const types::substitution_map & | substitution_values | ) | const |
Perform substitution of all symbols found in this object's expression
that match a key in the substitution_values
map.
substitution_values
that is paired with a key) need not necessarily be numerical, but may also be another symbolic type.Definition at line 294 of file symengine_number_types.cc.
Expression Differentiation::SD::Expression::substitute | ( | const SymEngine::map_basic_basic & | substitution_values | ) | const |
Perform substitution of all symbols found in this object's expression
that match a key in the substitution_values
map.
This function is like the one above, but takes in a SymEngine map (one that maps a SymEngine::RCP<const SymEngine::Basic>
to another SymEngine::RCP<const SymEngine::Basic>
) as an argument.
substitution_values
that is paired with a key) need not necessarily be numerical, but may also be another symbolic type.Definition at line 286 of file symengine_number_types.cc.
Expression Differentiation::SD::Expression::substitute | ( | const Expression & | symbol, |
const Expression & | value | ||
) | const |
Perform substitution of all symbols found in this object's expression
that match the symbol
. Each symbol
will be substituted with the given value
.
Definition at line 303 of file symengine_number_types.cc.
Expression Differentiation::SD::Expression::substitute | ( | const Expression & | symbol, |
const NumberType & | value | ||
) | const |
Perform substitution of all symbols found in this object's expression
that match the symbol
. Each symbol
will be substituted with the given value
.
ReturnType Differentiation::SD::Expression::substitute_and_evaluate | ( | const types::substitution_map & | substitution_values | ) | const |
Full substitution and evaluation. This creates a Expression by symbol substitution and then immediately computes its numerical value.
ReturnType Differentiation::SD::Expression::substitute_and_evaluate | ( | const SymEngine::map_basic_basic & | substitution_values | ) | const |
Full substitution and evaluation. This creates a Expression by symbol substitution and then immediately computes its numerical value.
This function is like the one above, but takes in a SymEngine map (one that maps a SymEngine::RCP<const SymEngine::Basic>
to another SymEngine::RCP<const SymEngine::Basic>
) as an argument.
|
explicit |
Conversion operator for real integer or floating point values, and complex integer or floating point values.
const NumberType val = static_cast<NumberType>(Expression);
or, probably less desirably,
const NumberType val = NumberType(Expression);
|
explicit |
Conversion operator that returns the value or expression that this class instance represents.
Definition at line 270 of file symengine_number_types.cc.
Differentiation::SD::Expression::operator const SymEngine::RCP< const SymEngine::Basic > & | ( | ) | const |
Conversion operator that returns a SymEngine reference counted pointer to the fundamental type.
|
protected |
Return the value or expression that this class instance represents.
Definition at line 220 of file symengine_number_types.cc.
|
private |
The value or expression that this instance of this class is to represent.
Definition at line 871 of file symengine_number_types.h.