16 #include <deal.II/base/config.h> 18 #ifdef DEAL_II_WITH_SYMENGINE 20 # include <deal.II/base/signaling_nan.h> 22 # include <deal.II/differentiation/sd/symengine_number_types.h> 23 # include <deal.II/differentiation/sd/symengine_types.h> 24 # include <deal.II/differentiation/sd/symengine_utilities.h> 26 # include <symengine/complex_double.h> 27 # include <symengine/logic.h> 28 # include <symengine/number.h> 29 # include <symengine/parser.h> 30 # include <symengine/real_double.h> 31 # include <symengine/symbol.h> 32 # include <symengine/symengine_exception.h> 36 DEAL_II_NAMESPACE_OPEN
42 namespace SE = ::SymEngine;
54 : expression(SE::boolean(value))
74 "The conditional expression must return a boolean type."));
76 const SE::RCP<const SE::Boolean> condition_rcp =
77 SE::rcp_static_cast<
const SE::Boolean>(condition.
get_RCP());
79 SE::piecewise({{expression_if_true.
get_RCP(), condition_rcp},
80 {expression_if_false.
get_RCP(), SE::boolTrue}});
85 & condition_expression,
88 SE::PiecewiseVec piecewise_function;
89 piecewise_function.reserve(condition_expression.size() + 1);
92 for (
const auto &entry : condition_expression)
94 Assert(SE::is_a_Boolean(entry.first.get_value()),
96 "The conditional expression must return a boolean type."));
97 piecewise_function.push_back(
98 {entry.second.get_RCP(),
99 SE::rcp_static_cast<
const SE::Boolean>(entry.first.get_RCP())});
103 piecewise_function.push_back(
104 {expression_otherwise.
get_RCP(), SE::boolTrue});
107 expression = SE::piecewise(std::move(piecewise_function));
112 &condition_expression)
118 Expression(numbers::signaling_nan<double>()));
123 : expression(SE::symbol(symbol))
128 const bool parse_as_expression)
135 SE::rcp_static_cast<
const SE::Basic>(SE::symbol(
146 const types::symbol_vector &arguments)
147 : expression(SE::function_symbol(
149 Utilities::convert_expression_vector_to_basic_vector(arguments)))
203 std::getline(is, expr);
212 const SE::Expression &
233 const SE::RCP<const SE::Basic> &
268 Expression::operator
const SE::Expression &()
const 270 return get_expression();
274 Expression::operator
const SE::RCP<const SE::Basic> &()
const 276 return get_expression().get_basic();
285 const types::substitution_map &substitution_values)
const 288 Utilities::convert_expression_map_to_basic_map(substitution_values)));
298 "Substitution with a number that does not represent a symbol."));
300 types::substitution_map sub_vals;
301 sub_vals[symbol] = value;
431 ExcMessage(
"The expression must return a boolean type."));
433 const SE::RCP<const SE::Boolean> expression_rcp =
434 SE::rcp_static_cast<
const SE::Boolean>(expression.
get_RCP());
436 return Expression(SE::logical_not(expression_rcp));
443 ExcMessage(
"The lhs expression must return a boolean type."));
445 ExcMessage(
"The rhs expression must return a boolean type."));
447 const SE::RCP<const SE::Boolean> lhs_rcp =
448 SE::rcp_static_cast<
const SE::Boolean>(lhs.
get_RCP());
449 const SE::RCP<const SE::Boolean> rhs_rcp =
450 SE::rcp_static_cast<
const SE::Boolean>(rhs.
get_RCP());
452 return Expression(SE::logical_and({lhs_rcp, rhs_rcp}));
460 ExcMessage(
"The lhs expression must return a boolean type."));
462 ExcMessage(
"The rhs expression must return a boolean type."));
464 const SE::RCP<const SE::Boolean> lhs_rcp =
465 SE::rcp_static_cast<
const SE::Boolean>(lhs.
get_RCP());
466 const SE::RCP<const SE::Boolean> rhs_rcp =
467 SE::rcp_static_cast<
const SE::Boolean>(rhs.
get_RCP());
469 return Expression(SE::logical_or({lhs_rcp, rhs_rcp}));
477 ExcMessage(
"The lhs expression must return a boolean type."));
479 ExcMessage(
"The rhs expression must return a boolean type."));
481 const SE::RCP<const SE::Boolean> lhs_rcp =
482 SE::rcp_static_cast<
const SE::Boolean>(lhs.
get_RCP());
483 const SE::RCP<const SE::Boolean> rhs_rcp =
484 SE::rcp_static_cast<
const SE::Boolean>(rhs.
get_RCP());
486 return Expression(SE::logical_xor({lhs_rcp, rhs_rcp}));
539 DEAL_II_NAMESPACE_CLOSE
541 #endif // DEAL_II_WITH_SYMENGINE 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)
static ::ExceptionBase & ExcIO()
void load(std::istream &stream)
Expression & parse(const std::string &expression)
#define AssertThrow(cond, exc)
std::ostream & print(std::ostream &stream) const
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)
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)
SymEngine::Expression expression
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)