16 #ifndef dealii_differentiation_sd_symengine_number_types_h 17 #define dealii_differentiation_sd_symengine_number_types_h 19 #include <deal.II/base/config.h> 21 #ifdef DEAL_II_WITH_SYMENGINE 24 # include <symengine/basic.h> 25 # include <symengine/dict.h> 26 # include <symengine/symengine_exception.h> 27 # include <symengine/symengine_rcp.h> 30 # include <symengine/expression.h> 31 # include <symengine/integer.h> 32 # include <symengine/logic.h> 33 # include <symengine/number.h> 34 # include <symengine/rational.h> 37 # include <symengine/add.h> 38 # include <symengine/functions.h> 39 # include <symengine/mul.h> 40 # include <symengine/pow.h> 43 # include <symengine/eval.h> 44 # include <symengine/eval_arb.h> 45 # include <symengine/eval_double.h> 48 # include <deal.II/base/exceptions.h> 49 # include <deal.II/base/numbers.h> 51 # include <deal.II/differentiation/sd/symengine_number_traits.h> 52 # include <deal.II/differentiation/sd/symengine_types.h> 54 # include <symengine/derivative.h> 59 # include <type_traits> 63 DEAL_II_NAMESPACE_OPEN
81 <<
"The string '" << arg1
82 <<
"' could not be parsed successfully. Are you sure that (1) it " 83 <<
"consists of legitimate operations and syntax, and (2) you've " 84 <<
"previously declared all symbolic variables that are present " 85 <<
"in the expression?");
206 template <
typename NumberType,
207 typename =
typename std::enable_if<
208 std::is_arithmetic<NumberType>::value>::type>
218 template <
typename NumberType,
219 typename =
typename std::enable_if<
220 std::is_arithmetic<NumberType>::value>::type>
221 explicit Expression(
const std::complex<NumberType> &value);
226 Expression(
const SymEngine::integer_class &value);
234 template <
typename NumberType,
235 typename =
typename std::enable_if<
236 std::is_integral<NumberType>::value>::type>
237 Expression(
const NumberType &numerator,
const NumberType &denominator);
242 Expression(
const SymEngine::rational_class &value);
305 Expression(
const std::vector<std::pair<Expression, Expression>>
306 & condition_expression,
328 Expression(
const std::vector<std::pair<Expression, Expression>>
329 &condition_expression);
353 const bool parse_as_expression =
false);
362 const types::symbol_vector &arguments);
376 explicit Expression(
const SymEngine::Expression &rhs);
386 Expression(
const SymEngine::RCP<const SymEngine::Basic> &rhs);
401 Expression(SymEngine::RCP<const SymEngine::Basic> &&rhs);
430 print(std::ostream &stream)
const;
438 save(std::ostream &stream)
const;
451 load(std::istream &stream);
466 template <
class Archive>
468 serialize(Archive &archive,
const unsigned int version);
480 const SymEngine::Expression &
487 const SymEngine::Basic &
494 const SymEngine::RCP<const SymEngine::Basic> &
571 template <
typename NumberType>
592 template <
typename NumberType>
602 template <
typename NumberType>
612 template <
typename NumberType>
622 template <
typename NumberType>
646 const SymEngine::RCP<const SymEngine::Symbol> &symbol)
const;
653 differentiate(
const SymEngine::RCP<const SymEngine::Basic> &symbol)
const;
675 substitute(
const types::substitution_map &substitution_values)
const;
698 template <
typename NumberType>
709 template <
typename ReturnType>
712 const types::substitution_map &substitution_values)
const;
771 template <
typename ResultType>
772 explicit operator ResultType()
const;
778 explicit operator const SymEngine::Expression &()
const;
784 operator const SymEngine::RCP<const SymEngine::Basic> &()
const;
792 SymEngine::Expression &
1016 template <
typename NumberType,
1017 typename =
typename std::enable_if<
1018 std::is_constructible<Expression, NumberType>::value>::type>
1033 template <
typename NumberType,
1034 typename =
typename std::enable_if<
1035 std::is_constructible<Expression, NumberType>::value>::type>
1050 template <
typename NumberType,
1051 typename =
typename std::enable_if<
1052 std::is_constructible<Expression, NumberType>::value>::type>
1067 template <
typename NumberType,
1068 typename =
typename std::enable_if<
1069 std::is_constructible<Expression, NumberType>::value>::type>
1084 template <
typename NumberType,
1085 typename =
typename std::enable_if<
1086 std::is_constructible<Expression, NumberType>::value>::type>
1100 template <
typename NumberType,
1101 typename =
typename std::enable_if<
1102 std::is_constructible<Expression, NumberType>::value>::type>
1116 template <
typename NumberType,
1117 typename =
typename std::enable_if<
1118 std::is_constructible<Expression, NumberType>::value>::type>
1133 template <
typename NumberType,
1134 typename =
typename std::enable_if<
1135 std::is_constructible<Expression, NumberType>::value>::type>
1158 template <
typename NumberType,
typename>
1164 template <
typename NumberType,
typename>
1165 Expression::Expression(
const std::complex<NumberType> &value)
1170 template <
typename NumberType,
typename>
1171 Expression::Expression(
const NumberType &numerator,
1172 const NumberType &denominator)
1174 SymEngine::Rational::from_two_ints(*SymEngine::integer(numerator),
1175 *SymEngine::integer(denominator)))
1179 template <
class Archive>
1181 Expression::serialize(Archive &ar,
const unsigned int )
1190 const Expression default_constructed;
1191 const bool likely_writing_out =
1192 (get_RCP()->__eq__(*default_constructed.get_RCP()) ==
false);
1194 std::stringstream sstream;
1195 std::string expr = default_constructed.get_RCP()->__str__();
1198 if (likely_writing_out)
1201 expr = sstream.str();
1208 if (!likely_writing_out)
1219 template <
typename NumberType>
1221 Expression::substitute(
const Expression &symbol,
1222 const NumberType &value)
const 1224 Assert(SymEngine::is_a<SymEngine::Symbol>(symbol.get_value()),
1226 "Substitution with a number that does not represent a symbol."));
1228 types::substitution_map sub_vals;
1229 sub_vals[symbol] = Expression(value);
1234 template <
typename ReturnType>
1236 Expression::substitute_and_evaluate(
1237 const types::substitution_map &substitution_values)
const 1239 return static_cast<ReturnType
>(
substitute(substitution_values));
1243 template <
typename NumberType>
1245 Expression::operator=(
const NumberType &rhs)
1247 *
this = Expression(rhs);
1252 template <
typename NumberType>
1254 Expression::operator+=(
const NumberType &rhs)
1256 *
this = Expression(SymEngine::add(get_RCP(), Expression(rhs).get_RCP()));
1261 template <
typename NumberType>
1263 Expression::operator-=(
const NumberType &rhs)
1265 *
this = Expression(SymEngine::sub(get_RCP(), Expression(rhs).get_RCP()));
1270 template <
typename NumberType>
1272 Expression::operator*=(
const NumberType &rhs)
1274 *
this = Expression(SymEngine::mul(get_RCP(), Expression(rhs).get_RCP()));
1279 template <
typename NumberType>
1281 Expression::operator/=(
const NumberType &rhs)
1283 *
this = Expression(SymEngine::div(get_RCP(), Expression(rhs).get_RCP()));
1288 template <
typename ResultType>
1289 Expression::operator ResultType()
const 1291 return static_cast<ResultType
>(get_expression());
1303 template <
int rank_,
int dim,
typename Number>
1319 typename =
typename std::enable_if<std::is_arithmetic<T>::value>::type>
1328 typename =
typename std::enable_if<std::is_arithmetic<T>::value>::type>
1337 typename =
typename std::enable_if<std::is_arithmetic<T>::value>::type>
1339 value(
const std::complex<T> &t)
1344 template <
typename T,
int dim>
1351 template <
typename T,
int dim>
1353 value(
const Tensor<0, dim, std::complex<T>> &t)
1367 if (SymEngine::is_a_Number(value.
get_value()))
1369 const SymEngine::RCP<const SymEngine::Number> number_rcp =
1370 SymEngine::rcp_static_cast<
const SymEngine::Number>(value.
get_RCP());
1371 return number_rcp->is_zero();
1397 DEAL_II_NAMESPACE_CLOSE
1399 #endif // DEAL_II_WITH_SYMENGINE 1401 #endif // dealii_differentiation_sd_symengine_number_types_h std::ostream & operator<<(std::ostream &stream, const Expression &expression)
Expression operator+(Expression lhs, const Expression &rhs)
Expression operator<(const Expression &lhs, const Expression &rhs)
Expression differentiate(const Expression &symbol) const
std::istream & operator>>(std::istream &stream, Expression &expression)
Expression & operator/=(const Expression &rhs)
Expression operator-() const
Expression operator &&(const Expression &lhs, const Expression &rhs)
Expression operator>=(const Expression &lhs, const Expression &rhs)
void load(std::istream &stream)
Expression & parse(const std::string &expression)
bool value_is_zero(const Number &value)
ReturnType substitute_and_evaluate(const types::substitution_map &substitution_values) const
void serialize(Archive &archive, const unsigned int version)
std::ostream & print(std::ostream &stream) const
bool values_are_equal(const Number1 &value_1, const Number2 &value_2)
Expression substitute(const types::substitution_map &substitution_values) const
const SymEngine::RCP< const SymEngine::Basic > & get_RCP() const
Expression operator/(Expression lhs, const Expression &rhs)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define DeclException1(Exception1, type1, outsequence)
Expression operator<=(const Expression &lhs, const Expression &rhs)
#define Assert(cond, exc)
Expression & operator*=(const Expression &rhs)
Expression operator|(const Expression &lhs, const Expression &rhs)
static ::ExceptionBase & ExcSymEngineParserError(std::string arg1)
const SymEngine::Basic & get_value() const
const SymEngine::Expression & get_expression() const
Expression & operator=(const Expression &rhs)
Expression operator>(const Expression &lhs, const Expression &rhs)
void save(std::ostream &stream) const
Expression operator*(Expression lhs, const Expression &rhs)
Expression operator!(const Expression &expression)
virtual ~Expression()=default
SymEngine::Expression expression
Expression substitute(const Expression &expression, const types::substitution_map &substitution_map)
bool value_is_less_than(const Number1 &value_1, const Number2 &value_2)
Expression operator==(const Expression &lhs, const Expression &rhs)
Expression operator||(const Expression &lhs, const Expression &rhs)
Expression operator^(const Expression &lhs, const Expression &rhs)
Expression & operator-=(const Expression &rhs)
Expression operator-(Expression lhs, const Expression &rhs)
Expression & operator+=(const Expression &rhs)
Expression operator!=(const Expression &lhs, const Expression &rhs)
Expression operator &(const Expression &lhs, const Expression &rhs)