]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test that checks the creation of symbol maps from tensors.
authorJean-Paul Pelteret <jppelteret@gmail.com>
Sun, 5 May 2019 14:35:08 +0000 (16:35 +0200)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Sun, 5 May 2019 14:35:08 +0000 (16:35 +0200)
Also tests setting their values afterwards.

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

diff --git a/tests/symengine/substitution_maps_tensor_03.cc b/tests/symengine/substitution_maps_tensor_03.cc
new file mode 100644 (file)
index 0000000..a5488dc
--- /dev/null
@@ -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 <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();
+  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 (file)
index 0000000..6b1efba
--- /dev/null
@@ -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 (file)
index 0000000..edf10d3
--- /dev/null
@@ -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 <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();
+  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 (file)
index 0000000..6b1efba
--- /dev/null
@@ -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

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.