From: Jean-Paul Pelteret Date: Sun, 5 May 2019 14:35:08 +0000 (+0200) Subject: Add test that checks the creation of symbol maps from tensors. X-Git-Tag: v9.1.0-rc1~68^2~5 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b60896a222c7dbe690bd0d1caa89a97f0e67b15;p=dealii.git Add test that checks the creation of symbol maps from tensors. Also tests setting their values afterwards. --- diff --git a/tests/symengine/substitution_maps_tensor_03.cc b/tests/symengine/substitution_maps_tensor_03.cc new file mode 100644 index 0000000000..a5488dcd56 --- /dev/null +++ b/tests/symengine/substitution_maps_tensor_03.cc @@ -0,0 +1,71 @@ +// --------------------------------------------------------------------- +// +// 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 add tensor variables to symbol maps, and subsequently +// set their associated values, work correctly. + +#include + +#include +#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; + + deallog << "Construct symbol map" << std::endl; + SD::types::substitution_map symbol_map; + SD::add_to_symbol_map(symbol_map, SD::make_tensor_of_symbols<2, dim>("t1")); + SD::add_to_symbol_map(symbol_map, + SD::make_symmetric_tensor_of_symbols<2, dim>("st1")); + SD::add_to_symbol_map(symbol_map, + SD::make_tensor_of_symbols<2, dim>("t2"), + SD::make_symmetric_tensor_of_symbols<2, dim>("st2")); + + SD::Utilities::print_substitution_map(deallog, symbol_map); + + + deallog << "Set values in symbol map" << std::endl; + SD::set_value_in_symbol_map(symbol_map, + SD::make_tensor_of_symbols<2, dim>("t1"), + t); + SD::set_value_in_symbol_map( + symbol_map, SD::make_symmetric_tensor_of_symbols<2, dim>("st1"), st); + SD::set_value_in_symbol_map( + symbol_map, + std::make_pair(SD::make_tensor_of_symbols<2, dim>("t2"), t), + std::make_pair(SD::make_symmetric_tensor_of_symbols<2, dim>("st2"), st)); + + SD::Utilities::print_substitution_map(deallog, symbol_map); + + deallog << "OK" << std::endl; +} diff --git a/tests/symengine/substitution_maps_tensor_03.output b/tests/symengine/substitution_maps_tensor_03.output new file mode 100644 index 0000000000..6b1efbabd7 --- /dev/null +++ b/tests/symengine/substitution_maps_tensor_03.output @@ -0,0 +1,32 @@ + +DEAL::Construct symbol map +DEAL::t2_01 = 0.0 +t2_00 = 0.0 +t2_10 = 0.0 +t2_11 = 0.0 +t1_00 = 0.0 +t1_01 = 0.0 +t1_11 = 0.0 +t1_10 = 0.0 +st2_11 = 0.0 +st2_00 = 0.0 +st2_01 = 0.0 +st1_11 = 0.0 +st1_00 = 0.0 +st1_01 = 0.0 +Set values in symbol map +DEAL::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 diff --git a/tests/symengine/substitution_maps_tensor_04.cc b/tests/symengine/substitution_maps_tensor_04.cc new file mode 100644 index 0000000000..edf10d37bb --- /dev/null +++ b/tests/symengine/substitution_maps_tensor_04.cc @@ -0,0 +1,73 @@ +// --------------------------------------------------------------------- +// +// 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 symbol maps from tensor variables, and subsequently +// set their associated values, work correctly. + +#include + +#include +#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; + + deallog << "Construct symbol map" << std::endl; + const SD::types::substitution_map symbol_map_1 = + SD::make_symbol_map(SD::make_tensor_of_symbols<2, dim>("t1")); + const SD::types::substitution_map symbol_map_2 = + SD::make_symbol_map(SD::make_symmetric_tensor_of_symbols<2, dim>("st1")); + const SD::types::substitution_map symbol_map_3 = + SD::make_symbol_map(SD::make_tensor_of_symbols<2, dim>("t2"), + SD::make_symmetric_tensor_of_symbols<2, dim>("st2")); + + SD::types::substitution_map symbol_map = + merge_substitution_maps(symbol_map_1, symbol_map_2, symbol_map_3); + SD::Utilities::print_substitution_map(deallog, symbol_map); + + + deallog << "Set values in symbol map" << std::endl; + SD::set_value_in_symbol_map(symbol_map, + SD::make_tensor_of_symbols<2, dim>("t1"), + t); + SD::set_value_in_symbol_map( + symbol_map, SD::make_symmetric_tensor_of_symbols<2, dim>("st1"), st); + SD::set_value_in_symbol_map( + symbol_map, + std::make_pair(SD::make_tensor_of_symbols<2, dim>("t2"), t), + std::make_pair(SD::make_symmetric_tensor_of_symbols<2, dim>("st2"), st)); + + SD::Utilities::print_substitution_map(deallog, symbol_map); + + deallog << "OK" << std::endl; +} diff --git a/tests/symengine/substitution_maps_tensor_04.output b/tests/symengine/substitution_maps_tensor_04.output new file mode 100644 index 0000000000..6b1efbabd7 --- /dev/null +++ b/tests/symengine/substitution_maps_tensor_04.output @@ -0,0 +1,32 @@ + +DEAL::Construct symbol map +DEAL::t2_01 = 0.0 +t2_00 = 0.0 +t2_10 = 0.0 +t2_11 = 0.0 +t1_00 = 0.0 +t1_01 = 0.0 +t1_11 = 0.0 +t1_10 = 0.0 +st2_11 = 0.0 +st2_00 = 0.0 +st2_01 = 0.0 +st1_11 = 0.0 +st1_00 = 0.0 +st1_01 = 0.0 +Set values in symbol map +DEAL::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