]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test that checks the addition of scalars to symbol maps.
authorJean-Paul Pelteret <jppelteret@gmail.com>
Sun, 5 May 2019 13:44:59 +0000 (15:44 +0200)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Sun, 5 May 2019 13:50:29 +0000 (15:50 +0200)
Also tests setting their values afterwards.

tests/symengine/substitution_maps_scalar_04.cc [new file with mode: 0644]
tests/symengine/substitution_maps_scalar_04.output [new file with mode: 0644]

diff --git a/tests/symengine/substitution_maps_scalar_04.cc b/tests/symengine/substitution_maps_scalar_04.cc
new file mode 100644 (file)
index 0000000..2f672c0
--- /dev/null
@@ -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 <deal.II/differentiation/sd.h>
+
+#include <complex>
+#include <iostream>
+#include <string>
+
+#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<double>(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<double>{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::pair<SD::Expression, double>>{
+                                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 (file)
index 0000000..094c85f
--- /dev/null
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.