From 43fa21bc9978c3c78c380088759c2f78c77a7f47 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Sun, 5 May 2019 15:51:29 +0200 Subject: [PATCH] Add test that checks the creation of symbol maps from scalars. Also tests setting their values afterwards. --- .../symengine/substitution_maps_scalar_05.cc | 92 +++++++++++++++++++ .../substitution_maps_scalar_05.output | 28 ++++++ 2 files changed, 120 insertions(+) create mode 100644 tests/symengine/substitution_maps_scalar_05.cc create mode 100644 tests/symengine/substitution_maps_scalar_05.output diff --git a/tests/symengine/substitution_maps_scalar_05.cc b/tests/symengine/substitution_maps_scalar_05.cc new file mode 100644 index 0000000000..aa92aac284 --- /dev/null +++ b/tests/symengine/substitution_maps_scalar_05.cc @@ -0,0 +1,92 @@ +// --------------------------------------------------------------------- +// +// 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 scalar 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(); + + deallog << "Construct symbol map" << std::endl; + const SD::types::substitution_map symbol_map_1 = + SD::make_symbol_map(SD::Expression("x1")); + const SD::types::substitution_map symbol_map_2 = SD::make_symbol_map( + SD::types::symbol_vector{SD::Expression("x2"), SD::Expression("x3")}); + // Add via map, but check that associated values are ignored. + const SD::types::substitution_map symbol_map_3 = SD::make_symbol_map( + SD::types::substitution_map{{SD::Expression("x4"), SD::Expression(4)}, + {SD::Expression("x5"), SD::Expression(5)}, + {SD::Expression("x6"), SD::Expression(6)}}); + const SD::types::substitution_map symbol_map_4 = SD::make_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::types::substitution_map symbol_map = merge_substitution_maps( + symbol_map_1, symbol_map_2, symbol_map_3, symbol_map_4); + 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_05.output b/tests/symengine/substitution_maps_scalar_05.output new file mode 100644 index 0000000000..094c85f791 --- /dev/null +++ b/tests/symengine/substitution_maps_scalar_05.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 -- 2.39.5