16#ifndef dealii_differentiation_sd_symengine_scalar_operations_h
17#define dealii_differentiation_sd_symengine_scalar_operations_h
21#ifdef DEAL_II_WITH_SYMENGINE
28# include <symengine/basic.h>
29# include <symengine/symengine_rcp.h>
32# include <type_traits>
162 const SymEngine::RCP<const SymEngine::Basic> &
symbol,
163 const SymEngine::RCP<const SymEngine::Basic> &value);
187 typename ValueType = double,
228 typename ValueType = double,
270 template <
bool ignore_inval
id_symbols = false,
typename ValueType =
double>
304 typename ValueType = double,
306 typename T = std::enable_if_t<
307 !std::is_base_of<Expression, SymbolicType>::value &&
310 const SymEngine::RCP<const SymEngine::Basic> &>::value>>
341 typename ValueType = double,
345 const std::vector<SymbolicType> &
symbols);
366 template <
bool ignore_inval
id_symbols = false,
typename ValueType =
double>
414 typename ValueType = double,
463 typename T = std::enable_if_t<
466 const SymEngine::RCP<const SymEngine::Basic> &>::value &&
467 std::is_constructible<SymbolicType, ValueType>::value>>
471 const ValueType & value);
492 template <
typename SymbolicType,
typename ValueType>
495 const std::vector<SymbolicType> &
symbols,
496 const std::vector<ValueType> & values);
519 template <
typename SymbolicType,
typename ValueType>
523 const std::pair<SymbolicType, ValueType> &
symbol_value);
577 template <
typename SymbolicType,
typename ValueType>
581 const std::vector<std::pair<SymbolicType, ValueType>> &
symbol_values);
652 typename T = std::enable_if_t<
655 const SymEngine::RCP<const SymEngine::Basic> &>::value &&
656 std::is_constructible<ExpressionType, ValueType>::value>>
681 template <
typename ExpressionType,
typename ValueType>
684 const std::vector<ValueType> & values);
707 template <
typename ExpressionType,
typename ValueType>
710 const std::pair<ExpressionType, ValueType> &
symbol_value);
734 template <
typename ExpressionType,
typename ValueType>
737 const std::vector<std::pair<ExpressionType, ValueType>> &
symbol_values);
782 const std::pair<ExpressionType, ValueType> &
symbol_value,
816 template <
bool ignore_inval
id_symbols = false>
820 const SymEngine::RCP<const SymEngine::Basic> &
symbol,
821 const SymEngine::RCP<const SymEngine::Basic> &value);
854 template <
bool ignore_inval
id_symbols = false>
895 typename = std::enable_if_t<
898 const SymEngine::RCP<const SymEngine::Basic> &>::value &&
899 std::is_constructible<ExpressionType, ValueType>::value>>
903 const ValueType & value);
941 typename = std::enable_if_t<
944 const SymEngine::RCP<const SymEngine::Basic> &>::value &&
945 std::is_constructible<ExpressionType, ValueType>::value>>
948 const std::vector<ExpressionType> &
symbols,
949 const std::vector<ValueType> & values);
967 template <
bool ignore_inval
id_symbols = false>
1018 const std::pair<ExpressionType, ValueType> &
symbol_value);
1070 const std::vector<std::pair<ExpressionType, ValueType>> &
symbol_values);
1123 const std::pair<ExpressionType, ValueType> &
symbol_value,
1147 template <
typename...
Args>
1160 template <
typename...
Args>
1245 template <
typename ExpressionType,
typename ValueType>
1248 const std::vector<std::pair<ExpressionType, ValueType>> &
symbol_values,
1322 template <
typename ValueType>
1326 const ValueType & value);
1385 template <
typename ValueType>
1421 template <
typename ValueType,
typename...
Args>
1472 template <
bool ignore_inval
id_symbols,
typename ValueType>
1475 const Expression &
symbol)
1494 using SE_RCP_Basic =
const SymEngine::RCP<const SymEngine::Basic> &;
1507 const std::vector<SymbolicType> &
symbols)
1515 template <
bool ignore_inval
id_symbols,
typename ValueType>
1530 ExcMessage(
"Entry already exists in symbol map"));
1552 template <
typename SymbolicType,
typename ValueType,
typename>
1556 const ValueType & value)
1559 using SE_RCP_Basic =
const SymEngine::RCP<const SymEngine::Basic> &;
1567 template <
typename SymbolicType,
typename ValueType>
1570 const std::vector<SymbolicType> &
symbols,
1571 const std::vector<ValueType> & values)
1576 typename std::vector<SymbolicType>::const_iterator
it_symb =
1578 typename std::vector<ValueType>::const_iterator
it_val =
values.begin();
1587 template <
typename SymbolicType,
typename ValueType>
1591 const std::pair<SymbolicType, ValueType> &
symbol_value)
1603 const std::pair<SymbolicType, ValueType> &
symbol_value,
1611 template <
typename SymbolicType,
typename ValueType>
1615 const std::vector<std::pair<SymbolicType, ValueType>> &
symbol_values)
1626 template <
typename ExpressionType,
typename ValueType,
typename>
1636 template <
typename ExpressionType,
typename ValueType>
1639 const std::vector<ValueType> & values)
1647 template <
typename ExpressionType,
typename ValueType>
1650 const std::pair<ExpressionType, ValueType> &
symbol_value)
1658 template <
typename ExpressionType,
typename ValueType>
1661 const std::vector<std::pair<ExpressionType, ValueType>> &
symbol_values)
1672 const std::pair<ExpressionType, ValueType> &
symbol_value,
1698 template <
bool ignore_inval
id_symbols>
1702 const SymEngine::RCP<const SymEngine::Basic> &
symbol,
1703 const SymEngine::RCP<const SymEngine::Basic> &value)
1710 "Substitution with a number that does not represent a symbol or symbolic derivative"));
1712 ExcMessage(
"This symbol is already in the map."));
1720 ExcMessage(
"This symbol is already in the map."));
1729 template <
bool ignore_inval
id_symbols>
1732 const Expression &
symbol,
1733 const Expression & value)
1735 internal::add_to_substitution_map<ignore_invalid_symbols>(
1736 substitution_map,
symbol.get_RCP(),
value.get_RCP());
1747 const ValueType & value)
1749 using SE_RCP_Basic =
const SymEngine::RCP<const SymEngine::Basic> &;
1750 internal::add_to_substitution_map<ignore_invalid_symbols>(
1763 const std::vector<ExpressionType> &
symbols,
1764 const std::vector<ValueType> & values)
1768 "Vector of symbols and values must be of equal length."));
1771 typename std::vector<ValueType>::const_iterator
it_v =
values.begin();
1772 using SE_RCP_Basic =
const SymEngine::RCP<const SymEngine::Basic> &;
1776 internal::add_to_substitution_map<ignore_invalid_symbols>(
1790 const std::pair<ExpressionType, ValueType> &
symbol_value)
1804 const std::vector<std::pair<ExpressionType, ValueType>> &
symbol_values)
1814 template <
bool ignore_inval
id_symbols>
1821 const SymEngine::RCP<const SymEngine::Basic> &
symbol = entry.first;
1822 const SymEngine::RCP<const SymEngine::Basic> &
value = entry.second;
1823 internal::add_to_substitution_map<ignore_invalid_symbols>(
1824 substitution_map,
symbol, value);
1836 const std::pair<ExpressionType, ValueType> &
symbol_value,
1846 template <
typename...
Args>
1859 template <
typename...
Args>
1875 template <
typename ExpressionType,
typename ValueType>
1878 const std::vector<std::pair<ExpressionType, ValueType>> &
symbol_values,
1886 template <
typename ValueType>
1889 const Expression &
symbol,
1890 const ValueType & value)
1905 template <
typename ValueType>
1914 template <
typename ValueType,
typename...
Args>
Expression substitute(const types::substitution_map &substitution_values) const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
void add_to_substitution_map(types::substitution_map &substitution_map, const SymEngine::RCP< const SymEngine::Basic > &symbol, const SymEngine::RCP< const SymEngine::Basic > &value)
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)
ValueType substitute_and_evaluate(const Expression &expression, const types::substitution_map &substitution_map)
types::substitution_map make_symbol_map(const SymbolicType &symbol)
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_symbol_map(types::substitution_map &symbol_map, const Expression &symbol)
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)