From: Jean-Paul Pelteret Date: Sat, 11 May 2019 15:37:04 +0000 (+0200) Subject: Merge pull request #8008 from jppelteret/sd-map_utilities_04 X-Git-Tag: v9.1.0-rc1~68 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb60250692fff2dc32bfeb236b7a52b79a92260e;p=dealii.git Merge pull request #8008 from jppelteret/sd-map_utilities_04 SD scalar and tensor operations: Make, add to, and set value in symbol map --- bb60250692fff2dc32bfeb236b7a52b79a92260e diff --cc include/deal.II/differentiation/sd/symengine_scalar_operations.h index 692273a65e,ab8029fa39..3a3334adc6 --- a/include/deal.II/differentiation/sd/symengine_scalar_operations.h +++ b/include/deal.II/differentiation/sd/symengine_scalar_operations.h @@@ -768,12 -1109,193 +1193,193 @@@ namespace Differentiatio { namespace SD { - /* ---------------- Symbolic substitution map creation --------------*/ + /* ---------------- Symbol map creation and manipulation --------------*/ + + + template + types::substitution_map + make_symbol_map(const SymbolicType &symbol) + { + types::substitution_map symbol_map; + add_to_symbol_map(symbol_map, symbol); + return symbol_map; + } + + + template + types::substitution_map + make_symbol_map(const SymbolicType &symbol, const Args &... other_symbols) + { + types::substitution_map symbol_map; + add_to_symbol_map(symbol_map, + symbol, + other_symbols...); + return symbol_map; + } + + + template + void + add_to_symbol_map(types::substitution_map &symbol_map, + const Expression & symbol) + { + // Call the above function + add_to_substitution_map( + symbol_map, + symbol, + dealii::internal::NumberType::value(0.0)); + } + + + template + void + add_to_symbol_map(types::substitution_map &symbol_map, + const SymbolicType & symbol) + { + // Call the above function + using SE_RCP_Basic = const SymEngine::RCP &; + add_to_substitution_map( + symbol_map, + static_cast(symbol), + dealii::internal::NumberType::value(0.0)); + } + + + template + void + add_to_symbol_map(types::substitution_map & symbol_map, + const std::vector &symbols) + { + for (const auto &symbol : symbols) + add_to_symbol_map(symbol_map, + symbol); + } + + + template + void + add_to_symbol_map(types::substitution_map & symbol_map, + const types::substitution_map &other_symbols) + { + // We should be cautious as to whether or not the user has + // hand-made the other_symbols map to be "merged" in. + // So instead of blindly merging using the merge_substitution_maps() + // function, we do it by hand and check for invalid symbols + // if required. + for (types::substitution_map::const_iterator it = other_symbols.begin(); + it != other_symbols.end(); + ++it) + { + Assert(symbol_map.find(it->first) == symbol_map.end(), + ExcMessage("Entry already exists in symbol map")); + add_to_symbol_map( + symbol_map, Expression(it->first)); + } + } + + + template + void + add_to_symbol_map(types::substitution_map &symbol_map, + const SymbolicType & symbol, + const Args &... other_symbols) + { + add_to_symbol_map(symbol_map, symbol); + add_to_symbol_map(symbol_map, + other_symbols...); + } + + + template + void + set_value_in_symbol_map(types::substitution_map &substitution_map, + const ExpressionType & symbol, + const ValueType & value) + { + // Call the above function + using SE_RCP_Basic = const SymEngine::RCP &; + internal::set_value_in_symbol_map(substitution_map, + static_cast(symbol), + static_cast( + ExpressionType(value))); + } + + + template + void + set_value_in_symbol_map(types::substitution_map & substitution_map, + const std::vector &symbols, + const std::vector & values) + { + Assert(symbols.size() == values.size(), + ExcDimensionMismatch(symbols.size(), values.size())); + + typename std::vector::const_iterator it_symb = + symbols.begin(); + typename std::vector::const_iterator it_val = values.begin(); + for (; it_symb != symbols.end(); ++it_symb, ++it_val) + { + Assert(it_val != values.end(), ExcInternalError()); + set_value_in_symbol_map(substitution_map, *it_symb, *it_val); + } + } + + + template + void + set_value_in_symbol_map( + types::substitution_map & substitution_map, + const std::pair &symbol_value) + { + set_value_in_symbol_map(substitution_map, + symbol_value.first, + symbol_value.second); + } + + + template + void + set_value_in_symbol_map( + types::substitution_map & substitution_map, + const std::pair &symbol_value, + const Args &... other_symbol_values) + { + set_value_in_symbol_map(substitution_map, symbol_value); + set_value_in_symbol_map(substitution_map, other_symbol_values...); + } + + + template + void + set_value_in_symbol_map( + types::substitution_map & substitution_map, + const std::vector> &symbol_values) + { + // Call the above function + for (const auto &entry : symbol_values) + set_value_in_symbol_map(substitution_map, entry.first, entry.second); + } + + + /* ------------------ Symbol substitution map creation ----------------*/ - template + template types::substitution_map - make_substitution_map(const Expression &symbol, const ValueType &value) + make_substitution_map(const ExpressionType &symbol, const ValueType &value) { types::substitution_map substitution_map; add_to_substitution_map(substitution_map, symbol, value);