From: Jean-Paul Pelteret Date: Sat, 27 Apr 2019 09:42:14 +0000 (+0200) Subject: Add functions to create SD subsitution maps from tensor types X-Git-Tag: v9.1.0-rc1~146^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7973%2Fhead;p=dealii.git Add functions to create SD subsitution maps from tensor types --- diff --git a/include/deal.II/differentiation/sd/symengine_tensor_operations.h b/include/deal.II/differentiation/sd/symengine_tensor_operations.h index c325bf9cc8..3c14848697 100644 --- a/include/deal.II/differentiation/sd/symengine_tensor_operations.h +++ b/include/deal.II/differentiation/sd/symengine_tensor_operations.h @@ -366,6 +366,44 @@ namespace Differentiation //@} + /** + * @name Symbol substitution map creation + */ + //@{ + + /** + * Return a substitution map that has the entry keys given by the + * @p symbol_tensor and the values given by the @p value_tensor. It is + * expected that all key entries be valid symbols or symbolic expressions. + * + * It is possible to map symbolic types to other symbolic types + * using this function. For more details on this, see the other + * \ref make_substitution_map(const Expression &,const ValueType &) + * function. + */ + template + types::substitution_map + make_substitution_map(const Tensor &symbol_tensor, + const Tensor & value_tensor); + + /** + * Return a substitution map that has the entry keys given by the + * @p symbol_tensor and the values given by the @p value_tensor. It is + * expected that all key entries be valid symbols or symbolic expressions. + * + * It is possible to map symbolic types to other symbolic types + * using this function. For more details on this, see the other + * \ref make_substitution_map(const Expression &,const ValueType &) + * function. + */ + template + types::substitution_map + make_substitution_map( + const SymmetricTensor &symbol_tensor, + const SymmetricTensor & value_tensor); + + //@} + /** * @name Symbol substitution map enlargement */ @@ -811,6 +849,32 @@ namespace Differentiation } + /* ---------------- Symbolic substitution map creation --------------*/ + + + template + types::substitution_map + make_substitution_map(const Tensor &symbol_tensor, + const Tensor & value_tensor) + { + types::substitution_map substitution_map; + add_to_substitution_map(substitution_map, symbol_tensor, value_tensor); + return substitution_map; + } + + + template + types::substitution_map + make_substitution_map( + const SymmetricTensor &symbol_tensor, + const SymmetricTensor & value_tensor) + { + types::substitution_map substitution_map; + add_to_substitution_map(substitution_map, symbol_tensor, value_tensor); + return substitution_map; + } + + /* ---------------- Symbolic substitution map enlargement --------------*/ diff --git a/tests/symengine/substitution_maps_tensor_02.cc b/tests/symengine/substitution_maps_tensor_02.cc new file mode 100644 index 0000000000..cc44eb8877 --- /dev/null +++ b/tests/symengine/substitution_maps_tensor_02.cc @@ -0,0 +1,61 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// Check that functions to create substitution maps from tensor variables work +// correctly. + +#include + +#include + +#include "../tests.h" + +using namespace dealii; +namespace SD = Differentiation::SD; +namespace SE = ::SymEngine; + +int +main() +{ + initlog(); + const unsigned int dim = 2; + + Tensor<2, dim> t; + SymmetricTensor<2, dim> st; + for (unsigned int i = 0; i < t.n_independent_components; ++i) + t[t.unrolled_to_component_indices(i)] = i; + for (unsigned int i = 0; i < st.n_independent_components; ++i) + st[st.unrolled_to_component_indices(i)] = i; + + + SD::types::substitution_map substitution_map; + SD::add_to_substitution_map(substitution_map, + SD::Expression("x1"), + SD::Expression(1)); + + SD::merge_substitution_maps( + substitution_map, + SD::make_substitution_map(SD::make_tensor_of_symbols<2, dim>("t1"), t), + SD::make_substitution_map( + SD::make_symmetric_tensor_of_symbols<2, dim>("st1"), st), + SD::make_substitution_map(SD::make_tensor_of_symbols<2, dim>("t2"), t), + SD::make_substitution_map( + SD::make_symmetric_tensor_of_symbols<2, dim>("st2"), st)); + + SD::Utilities::print_substitution_map(deallog, substitution_map); + + deallog << "OK" << std::endl; +} diff --git a/tests/symengine/substitution_maps_tensor_02.output b/tests/symengine/substitution_maps_tensor_02.output new file mode 100644 index 0000000000..c562f76802 --- /dev/null +++ b/tests/symengine/substitution_maps_tensor_02.output @@ -0,0 +1,17 @@ + +DEAL::x1 = 1 +t2_01 = 1.0 +t2_00 = 0.0 +t2_10 = 2.0 +t2_11 = 3.0 +t1_00 = 0.0 +t1_01 = 1.0 +t1_11 = 3.0 +t1_10 = 2.0 +st2_11 = 1.0 +st2_00 = 0.0 +st2_01 = 2.0 +st1_11 = 1.0 +st1_00 = 0.0 +st1_01 = 2.0 +OK