From: Jean-Paul Pelteret Date: Sun, 5 May 2019 13:44:59 +0000 (+0200) Subject: Add test that checks the addition of scalars to symbol maps. X-Git-Tag: v9.1.0-rc1~68^2~7 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca25803c9c49fb4518b179823131ed1cecb00457;p=dealii.git Add test that checks the addition of scalars to symbol maps. Also tests setting their values afterwards. --- diff --git a/tests/symengine/substitution_maps_scalar_04.cc b/tests/symengine/substitution_maps_scalar_04.cc new file mode 100644 index 0000000000..2f672c0ba3 --- /dev/null +++ b/tests/symengine/substitution_maps_scalar_04.cc @@ -0,0 +1,93 @@ +// --------------------------------------------------------------------- +// +// 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 scalar 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(); + + deallog << "Construct symbol map" << std::endl; + SD::types::substitution_map symbol_map; + SD::add_to_symbol_map(symbol_map, SD::Expression("x1")); + SD::add_to_symbol_map(symbol_map, + SD::types::symbol_vector{SD::Expression("x2"), + SD::Expression("x3")}); + // Add via map, but check that associated values are ignored. + SD::add_to_symbol_map( + symbol_map, + SD::types::substitution_map{{SD::Expression("x4"), SD::Expression(4)}, + {SD::Expression("x5"), SD::Expression(5)}, + {SD::Expression("x6"), SD::Expression(6)}}); + SD::add_to_symbol_map( + symbol_map, + SD::Expression("x7"), + SD::types::symbol_vector{SD::Expression("x8"), SD::Expression("x9")}, + SD::types::substitution_map{{SD::Expression("x10"), SD::Expression(10)}, + {SD::Expression("x11"), SD::Expression(11)}, + {SD::Expression("x12"), SD::Expression(12)}}); + + 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::Expression("x1"), + SD::Expression(1)); + SD::set_value_in_symbol_map(symbol_map, + SD::Expression("x2"), + SD::Expression(2.0)); + SD::set_value_in_symbol_map(symbol_map, + SD::Expression("x3"), + std::complex(3.0)); + SD::set_value_in_symbol_map( + symbol_map, + SD::types::symbol_vector{SD::Expression("x4"), SD::Expression("x5")}, + SD::types::symbol_vector{SD::Expression(4), SD::Expression(5.0)}); + SD::set_value_in_symbol_map(symbol_map, + SD::types::symbol_vector{SD::Expression("x6"), + SD::Expression("x7")}, + std::vector{6.0, 7.0}); + SD::set_value_in_symbol_map(symbol_map, + std::make_pair(SD::Expression("x8"), 8.0)); + SD::set_value_in_symbol_map(symbol_map, + std::vector>{ + std::make_pair(SD::Expression("x9"), 9.0), + std::make_pair(SD::Expression("x10"), 10.0)}); + SD::set_value_in_symbol_map( + symbol_map, + SD::types::substitution_map{{SD::Expression("x10"), SD::Expression(10)}, + {SD::Expression("x11"), SD::Expression(11)}, + {SD::Expression("x12"), SD::Expression(12)}}); + + SD::Utilities::print_substitution_map(deallog, symbol_map); + + deallog << "OK" << std::endl; +} diff --git a/tests/symengine/substitution_maps_scalar_04.output b/tests/symengine/substitution_maps_scalar_04.output new file mode 100644 index 0000000000..094c85f791 --- /dev/null +++ b/tests/symengine/substitution_maps_scalar_04.output @@ -0,0 +1,28 @@ + +DEAL::Construct symbol map +DEAL::x2 = 0.0 +x1 = 0.0 +x4 = 0.0 +x3 = 0.0 +x6 = 0.0 +x5 = 0.0 +x8 = 0.0 +x7 = 0.0 +x9 = 0.0 +x12 = 0.0 +x11 = 0.0 +x10 = 0.0 +Set values in symbol map +DEAL::x2 = 2.0 +x1 = 1 +x4 = 4 +x3 = 3.0 + 0.0*I +x6 = 6.0 +x5 = 5.0 +x8 = 8.0 +x7 = 7.0 +x9 = 9.0 +x12 = 12 +x11 = 11 +x10 = 10 +OK