16#ifdef DEAL_II_WITH_SYMENGINE
23# include <symengine/real_double.h>
30#ifdef DEAL_II_WITH_SYMENGINE
36 namespace SE = ::SymEngine;
54 return Expression(symbol, arguments);
89 if (SE::is_a<SE::Symbol>(entry))
97 if (SE::is_a<SE::FunctionSymbol>(entry))
103 if (SE::is_a<SE::Derivative>(entry))
110 if (SE::is_a<SE::Mul>(entry))
112 const SE::Mul &entry_mul = SE::down_cast<const SE::Mul &>(entry);
114 if (SE::eq(*(entry_mul.get_coef()), *SE::real_double(0.5)))
118 const SE::map_basic_basic &entry_mul_dict =
119 entry_mul.get_dict();
120 if (entry_mul_dict.size() == 1 &&
121 SE::is_a<SE::Derivative>(*(entry_mul_dict.begin()->first)))
133 const SymEngine::RCP<const SymEngine::Basic> &symbol,
134 const SymEngine::RCP<const SymEngine::Basic> &value)
139 "Substitution with a number that does not represent a symbol or symbolic derivative"));
143 ExcMessage(
"Did not find this symbol in the map."));
145 it_sym->second = Expression(value);
153 const Expression &symbol,
154 const Expression &value)
166 for (
const auto &entry : symbol_values)
180 return substitution_map;
193 for (
const auto &entry : symb_map_in)
195 const typename types::substitution_map::const_iterator it_other =
196 symb_map_out.find(entry.first);
197 if (it_other == symb_map_out.end())
198 symb_map_out.insert(std::make_pair(entry.first, entry.second));
201 Assert(SE::eq(*(entry.second.get_RCP()),
202 *(it_other->second.get_RCP())),
203 ExcMessage(
"Key already in map, but values don't match"));
214 const bool force_cyclic_dependency_resolution)
217 const std::size_t
size = symbol_values.size();
219 for (
auto &entry : symbol_values_resolved)
226 Expression &out = entry.second;
228 SE::hash_t hash_new = out.get_RCP()->hash();
229 unsigned int iter = 0;
234 if (force_cyclic_dependency_resolution)
241 out = out.substitute(symbol_values_resolved);
245 out = out.substitute(symbol_values);
250 hash_new = out.get_RCP()->hash();
254 "Unresolvable cyclic dependency detected in substitution map."));
257 while (hash_new != hash_old);
260 return symbol_values_resolved;
268 return expression.
substitute(substitution_map);
Expression substitute(const types::substitution_map &substitution_values) const
Expression differentiate(const Expression &symbol) const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
SD::types::symbol_vector extract_symbols(const SD::types::substitution_map &substitution_values)
bool is_valid_substitution_symbol(const SymEngine::Basic &entry)
void set_value_in_symbol_map(types::substitution_map &substitution_map, const SymEngine::RCP< const SymEngine::Basic > &symbol, const SymEngine::RCP< const SymEngine::Basic > &value)
std::vector< SD::Expression > symbol_vector
std::map< SD::Expression, SD::Expression, internal::ExpressionKeyLess > substitution_map
void merge_substitution_maps(types::substitution_map &substitution_map_out, const types::substitution_map &substitution_map_in)
Expression differentiate(const Expression &f, const Expression &x)
Expression make_symbolic_function(const std::string &symbol, const types::symbol_vector &arguments)
void set_value_in_symbol_map(types::substitution_map &substitution_map, const Expression &symbol, const Expression &value)
void add_to_substitution_map(types::substitution_map &substitution_map, const Expression &symbol, const Expression &value)
types::substitution_map resolve_explicit_dependencies(const types::substitution_map &substitution_map, const bool force_cyclic_dependency_resolution=false)
Expression substitute(const Expression &expression, const types::substitution_map &substitution_map)
types::substitution_map make_substitution_map(const Expression &symbol, const Expression &value)
Expression make_symbol(const std::string &symbol)