]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Split out utilities file for SD tests
authorJean-Paul Pelteret <jppelteret@gmail.com>
Tue, 12 May 2020 19:03:42 +0000 (21:03 +0200)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Tue, 12 May 2020 19:03:42 +0000 (21:03 +0200)
tests/symengine/sd_common_tests/batch_optimizer_02.h
tests/symengine/sd_common_tests/batch_optimizer_03.h
tests/symengine/sd_common_tests/batch_optimizer_05.h
tests/symengine/sd_common_tests/batch_optimizer_06.h
tests/symengine/sd_common_tests/cse_03.h
tests/symengine/sd_common_tests/utilities.h [new file with mode: 0644]

index f5b458c646d3778c2e6ef512699de72019fb0022..75d73c8e5466639359f725047576a0887ff43c23 100644 (file)
 
 #include "../../tests.h"
 
+#include "utilities.h"
+
 using namespace dealii;
 namespace SD = Differentiation::SD;
 
-template <int dim, typename NumberType>
-Tensor<2, dim, NumberType>
-make_tensor(const NumberType &val)
-{
-  Tensor<2, dim, NumberType> out;
-  for (unsigned int i = 0; i < dim; ++i)
-    out[i][i] = 1.0;
-
-  for (unsigned int i = 0; i < out.n_independent_components; ++i)
-    out[out.unrolled_to_component_indices(i)] += i + val;
-  return out;
-}
-
-template <int dim, typename NumberType>
-SymmetricTensor<2, dim, NumberType>
-make_symm_tensor(const NumberType &val)
-{
-  SymmetricTensor<2, dim, NumberType> out;
-  for (unsigned int i = 0; i < dim; ++i)
-    out[i][i] = 1.0;
-
-  for (unsigned int i = 0; i < out.n_independent_components; ++i)
-    out[out.unrolled_to_component_indices(i)] += i + val;
-  return out;
-}
-
 template <typename NumberType,
           enum SD::OptimizerType     opt_method,
           enum SD::OptimizationFlags opt_flags>
index d38c275c00f90b5276e3543efcabd91d38891f98..de7d619a9b105738658366f2e8a0277e8da6f958 100644 (file)
 
 #include "../../tests.h"
 
+#include "utilities.h"
+
 using namespace dealii;
 namespace SD = Differentiation::SD;
 
 namespace Diff_Test
 {
-  namespace internal
-  {
-    namespace
-    {
-      template <typename Stream, typename NumberType>
-      void
-      print(Stream &stream, const std::string &name, const NumberType &val)
-      {
-        stream << name << ": " << val << std::endl;
-      }
-      template <typename Stream, int dim, typename NumberType>
-      void
-      print(Stream &                          stream,
-            const std::string &               name,
-            const Tensor<0, dim, NumberType> &val)
-      {
-        stream << name << ": " << val << std::endl;
-      }
-      template <typename Stream, int dim, typename NumberType>
-      void
-      print(Stream &                          stream,
-            const std::string &               name,
-            const Tensor<1, dim, NumberType> &t)
-      {
-        for (unsigned int i = 0; i < dim; ++i)
-          stream << name << "[" << i << "]: " << t[i] << std::endl;
-      }
-      template <typename Stream, int dim, typename NumberType>
-      void
-      print(Stream &                          stream,
-            const std::string &               name,
-            const Tensor<2, dim, NumberType> &t)
-      {
-        for (unsigned int i = 0; i < dim; ++i)
-          for (unsigned int j = 0; j < dim; ++j)
-            stream << name << "[" << i << "][" << j << "]: " << t[i][j]
-                   << std::endl;
-      }
-      template <typename Stream, int dim, typename NumberType>
-      void
-      print(Stream &                                   stream,
-            const std::string &                        name,
-            const SymmetricTensor<2, dim, NumberType> &t)
-      {
-        for (unsigned int i = 0; i < dim; ++i)
-          for (unsigned int j = i; j < dim; ++j)
-            stream << name << "[" << i << "][" << j << "]: " << t[i][j]
-                   << std::endl;
-      }
-      template <typename Stream, int dim, typename NumberType>
-      void
-      print(Stream &                          stream,
-            const std::string &               name,
-            const Tensor<3, dim, NumberType> &t)
-      {
-        for (unsigned int i = 0; i < dim; ++i)
-          for (unsigned int j = 0; j < dim; ++j)
-            for (unsigned int k = 0; k < dim; ++k)
-              stream << name << "[" << i << "][" << j << "][" << k
-                     << "]: " << t[i][j][k] << std::endl;
-      }
-      template <typename Stream, int dim, typename NumberType>
-      void
-      print(Stream &                          stream,
-            const std::string &               name,
-            const Tensor<4, dim, NumberType> &t)
-      {
-        for (unsigned int i = 0; i < dim; ++i)
-          for (unsigned int j = 0; j < dim; ++j)
-            for (unsigned int k = 0; k < dim; ++k)
-              for (unsigned int l = 0; l < dim; ++l)
-                stream << name << "[" << i << "][" << j << "][" << k << "]["
-                       << l << "]: " << t[i][j][k][l] << std::endl;
-      }
-      template <typename Stream, int dim, typename NumberType>
-      void
-      print(Stream &                                   stream,
-            const std::string &                        name,
-            const SymmetricTensor<4, dim, NumberType> &t)
-      {
-        for (unsigned int i = 0; i < dim; ++i)
-          for (unsigned int j = i; j < dim; ++j)
-            for (unsigned int k = 0; k < dim; ++k)
-              for (unsigned int l = k; l < dim; ++l)
-                stream << name << "[" << i << "][" << j << "][" << k << "]["
-                       << l << "]: " << t[i][j][k][l] << std::endl;
-      }
-    } // namespace
-  }   // namespace internal
-
   template <int dim,
             typename NumberType,
             enum SD::OptimizerType     opt_method,
@@ -166,9 +78,9 @@ namespace Diff_Test
     const bool print_symbols = true;
     if (print_symbols == true)
       {
-        internal::print(deallog, "psi", symbolic_psi);
-        internal::print(deallog, "S", symbolic_S);
-        internal::print(deallog, "HH", symbolic_HH);
+        print(deallog, "psi", symbolic_psi);
+        print(deallog, "S", symbolic_S);
+        print(deallog, "HH", symbolic_HH);
       }
 
     // Numerical substitution
@@ -194,9 +106,9 @@ namespace Diff_Test
     const bool print_values = true;
     if (print_values == true)
       {
-        internal::print(deallog, "psi", optimizer.evaluate(symbolic_psi));
-        internal::print(deallog, "S", optimizer.evaluate(symbolic_S));
-        internal::print(deallog, "HH", optimizer.evaluate(symbolic_HH));
+        print(deallog, "psi", optimizer.evaluate(symbolic_psi));
+        print(deallog, "S", optimizer.evaluate(symbolic_S));
+        print(deallog, "HH", optimizer.evaluate(symbolic_HH));
       }
   }
 
@@ -263,11 +175,11 @@ namespace Diff_Test
     const bool print_symbols = true;
     if (print_symbols == true)
       {
-        internal::print(deallog, "psi (Q)", symbolic_psi_CQi);
-        internal::print(deallog, "psi", symbolic_psi);
-        internal::print(deallog, "S (Q)", symbolic_S_CQi);
-        internal::print(deallog, "S", symbolic_S);
-        internal::print(deallog, "HH", symbolic_HH);
+        print(deallog, "psi (Q)", symbolic_psi_CQi);
+        print(deallog, "psi", symbolic_psi);
+        print(deallog, "S (Q)", symbolic_S_CQi);
+        print(deallog, "S", symbolic_S);
+        print(deallog, "HH", symbolic_HH);
       }
 
     // Numerical substitution
@@ -297,9 +209,9 @@ namespace Diff_Test
     const bool print_values = true;
     if (print_values == true)
       {
-        internal::print(deallog, "psi", optimizer.evaluate(symbolic_psi));
-        internal::print(deallog, "S", optimizer.evaluate(symbolic_S));
-        internal::print(deallog, "HH", optimizer.evaluate(symbolic_HH));
+        print(deallog, "psi", optimizer.evaluate(symbolic_psi));
+        print(deallog, "S", optimizer.evaluate(symbolic_S));
+        print(deallog, "HH", optimizer.evaluate(symbolic_HH));
       }
   }
 
@@ -345,8 +257,8 @@ namespace Diff_Test
         "Qd", sub_vals_func_symb_dependencies);
     const SymmetricTensor<4, dim, SD::Expression> dQd_SD_dC =
       SD::differentiate(Qd_SD, C_SD);
-    //    internal::print(deallog,"Qd_SD",Qd_SD);
-    //    internal::print(deallog,"dQd_SD_dC",dQd_SD_dC);
+    //    print(deallog,"Qd_SD",Qd_SD);
+    //    print(deallog,"dQd_SD_dC",dQd_SD_dC);
 
     // Now we substitute out the independent internal variable
     // for one that has a sensitivity on the primary independent variable
@@ -360,7 +272,7 @@ namespace Diff_Test
     const SymmetricTensor<4, dim, SD::Expression> symbolic_HH_total_impl =
       2.0 * SD::differentiate(symbolic_S_subs_Q,
                               C_SD); // HH = 2*dS_dC = 4*d2psi_dC_dC
-    //    internal::print(deallog,"symbolic_HH_total_impl",symbolic_HH_total_impl);
+    //    print(deallog,"symbolic_HH_total_impl",symbolic_HH_total_impl);
 
     // An example of an implicit relationship would be
     // dQ/dt = 2.0*C*log( det(C)*log(Q(C) )
@@ -376,7 +288,7 @@ namespace Diff_Test
       SD::make_substitution_map(std::make_pair(Qd_SD, Qi_SD),
                                 std::make_pair(SD::differentiate(Qd_SD, C_SD),
                                                dQ_dC_i_SD));
-    //    internal::print(deallog,"dQ_dC_i",dQ_dC_i);
+    //    print(deallog,"dQ_dC_i",dQ_dC_i);
 
     // Substitute derivative terms
     SD::resolve_explicit_dependencies(sub_vals_explicit);
@@ -398,9 +310,9 @@ namespace Diff_Test
     const bool print_symbols = true;
     if (print_symbols == true)
       {
-        internal::print(deallog, "psi", symbolic_psi);
-        internal::print(deallog, "S", symbolic_S);
-        internal::print(deallog, "HH", symbolic_HH);
+        print(deallog, "psi", symbolic_psi);
+        print(deallog, "S", symbolic_S);
+        print(deallog, "HH", symbolic_HH);
       }
 
     // Numerical substitution
@@ -435,9 +347,9 @@ namespace Diff_Test
     const bool print_values = true;
     if (print_values == true)
       {
-        internal::print(deallog, "psi", optimizer.evaluate(symbolic_psi));
-        internal::print(deallog, "S", optimizer.evaluate(symbolic_S));
-        internal::print(deallog, "HH", optimizer.evaluate(symbolic_HH));
+        print(deallog, "psi", optimizer.evaluate(symbolic_psi));
+        print(deallog, "S", optimizer.evaluate(symbolic_S));
+        print(deallog, "HH", optimizer.evaluate(symbolic_HH));
       }
   }
 
index 98630f43205734acbb5b1985a36a4f1eeca51ec4..3a5c52392e850ec7efd8f7f26f1a530297298ab2 100644 (file)
 #include "../../tests.h"
 
 #include "serialization.h"
+#include "utilities.h"
 
 using namespace dealii;
 namespace SD = Differentiation::SD;
 
-
-template <int dim, typename NumberType>
-Tensor<2, dim, NumberType>
-make_tensor(const NumberType &val)
-{
-  Tensor<2, dim, NumberType> out;
-  for (unsigned int i = 0; i < dim; ++i)
-    out[i][i] = 1.0;
-
-  for (unsigned int i = 0; i < out.n_independent_components; ++i)
-    out[out.unrolled_to_component_indices(i)] += i + val;
-  return out;
-}
-
-template <int dim, typename NumberType>
-SymmetricTensor<2, dim, NumberType>
-make_symm_tensor(const NumberType &val)
-{
-  SymmetricTensor<2, dim, NumberType> out;
-  for (unsigned int i = 0; i < dim; ++i)
-    out[i][i] = 1.0;
-
-  for (unsigned int i = 0; i < out.n_independent_components; ++i)
-    out[out.unrolled_to_component_indices(i)] += i + val;
-  return out;
-}
-
 template <int dim,
           typename NumberType,
           enum SD::OptimizerType     opt_method,
index 2b9ca2c2cf48b31d7f934887ae3639706efe308c..8ee67385f9aa5474629e068f65902b774d1016bc 100644 (file)
 #include "../../tests.h"
 
 #include "serialization.h"
+#include "utilities.h"
+
 
 using namespace dealii;
 namespace SD = Differentiation::SD;
 
-
-template <int dim, typename NumberType>
-Tensor<2, dim, NumberType>
-make_tensor(const NumberType &val)
-{
-  Tensor<2, dim, NumberType> out;
-  for (unsigned int i = 0; i < dim; ++i)
-    out[i][i] = 1.0;
-
-  for (unsigned int i = 0; i < out.n_independent_components; ++i)
-    out[out.unrolled_to_component_indices(i)] += i + val;
-  return out;
-}
-
-template <int dim, typename NumberType>
-SymmetricTensor<2, dim, NumberType>
-make_symm_tensor(const NumberType &val)
-{
-  SymmetricTensor<2, dim, NumberType> out;
-  for (unsigned int i = 0; i < dim; ++i)
-    out[i][i] = 1.0;
-
-  for (unsigned int i = 0; i < out.n_independent_components; ++i)
-    out[out.unrolled_to_component_indices(i)] += i + val;
-  return out;
-}
-
 template <int dim,
           typename NumberType,
           enum SD::OptimizerType     opt_method,
index c5b30861607a49670729de0cf09f0fc718c083ba..c87c9854537ff7c53f9de2e20067980184de6d2b 100644 (file)
@@ -35,6 +35,8 @@
 #include <fstream>
 #include <iomanip>
 
+#include "utilities.h"
+
 using namespace dealii;
 namespace SD = Differentiation::SD;
 
@@ -266,65 +268,6 @@ struct CoupledFunction
 template <int dim, typename NumberType>
 const double CoupledFunction<dim, NumberType>::sf(2.2);
 
-template <typename Stream, typename NumberType>
-void
-print(Stream &stream, const std::string &name, const NumberType &val)
-{
-  stream << name << ": " << val << std::endl;
-}
-template <typename Stream, int dim, typename NumberType>
-void
-print(Stream &                          stream,
-      const std::string &               name,
-      const Tensor<0, dim, NumberType> &val)
-{
-  stream << name << ": " << val << std::endl;
-}
-template <typename Stream, int dim, typename NumberType>
-void
-print(Stream &                          stream,
-      const std::string &               name,
-      const Tensor<1, dim, NumberType> &t)
-{
-  for (unsigned int i = 0; i < dim; ++i)
-    stream << name << "[" << i << "]: " << t[i] << std::endl;
-}
-template <typename Stream, int dim, typename NumberType>
-void
-print(Stream &                          stream,
-      const std::string &               name,
-      const Tensor<2, dim, NumberType> &t)
-{
-  for (unsigned int i = 0; i < dim; ++i)
-    for (unsigned int j = 0; j < dim; ++j)
-      stream << name << "[" << i << "][" << j << "]: " << t[i][j] << std::endl;
-}
-template <typename Stream, int dim, typename NumberType>
-void
-print(Stream &                          stream,
-      const std::string &               name,
-      const Tensor<3, dim, NumberType> &t)
-{
-  for (unsigned int i = 0; i < dim; ++i)
-    for (unsigned int j = 0; j < dim; ++j)
-      for (unsigned int k = 0; k < dim; ++k)
-        stream << name << "[" << i << "][" << j << "][" << k
-               << "]: " << t[i][j][k] << std::endl;
-}
-template <typename Stream, int dim, typename NumberType>
-void
-print(Stream &                          stream,
-      const std::string &               name,
-      const Tensor<4, dim, NumberType> &t)
-{
-  for (unsigned int i = 0; i < dim; ++i)
-    for (unsigned int j = 0; j < dim; ++j)
-      for (unsigned int k = 0; k < dim; ++k)
-        for (unsigned int l = 0; l < dim; ++l)
-          stream << name << "[" << i << "][" << j << "][" << k << "][" << l
-                 << "]: " << t[i][j][k][l] << std::endl;
-}
-
 template <int dim,
           typename number_t,
           enum SD::OptimizerType     opt_method,
diff --git a/tests/symengine/sd_common_tests/utilities.h b/tests/symengine/sd_common_tests/utilities.h
new file mode 100644 (file)
index 0000000..a251e26
--- /dev/null
@@ -0,0 +1,144 @@
+
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2020 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.
+//
+// ---------------------------------------------------------------------
+
+
+#include <deal.II/base/symmetric_tensor.h>
+#include <deal.II/base/tensor.h>
+
+
+template <int dim, typename NumberType>
+Tensor<2, dim, NumberType>
+make_tensor(const NumberType &val)
+{
+  Tensor<2, dim, NumberType> out;
+  for (unsigned int i = 0; i < dim; ++i)
+    out[i][i] = 1.0;
+
+  for (unsigned int i = 0; i < out.n_independent_components; ++i)
+    out[out.unrolled_to_component_indices(i)] += i + val;
+  return out;
+}
+
+
+template <int dim, typename NumberType>
+SymmetricTensor<2, dim, NumberType>
+make_symm_tensor(const NumberType &val)
+{
+  SymmetricTensor<2, dim, NumberType> out;
+  for (unsigned int i = 0; i < dim; ++i)
+    out[i][i] = 1.0;
+
+  for (unsigned int i = 0; i < out.n_independent_components; ++i)
+    out[out.unrolled_to_component_indices(i)] += i + val;
+  return out;
+}
+
+
+template <typename Stream, typename NumberType>
+void
+print(Stream &stream, const std::string &name, const NumberType &val)
+{
+  stream << name << ": " << val << std::endl;
+}
+
+
+template <typename Stream, int dim, typename NumberType>
+void
+print(Stream &                          stream,
+      const std::string &               name,
+      const Tensor<0, dim, NumberType> &val)
+{
+  stream << name << ": " << val << std::endl;
+}
+
+
+template <typename Stream, int dim, typename NumberType>
+void
+print(Stream &                          stream,
+      const std::string &               name,
+      const Tensor<1, dim, NumberType> &t)
+{
+  for (unsigned int i = 0; i < dim; ++i)
+    stream << name << "[" << i << "]: " << t[i] << std::endl;
+}
+
+
+template <typename Stream, int dim, typename NumberType>
+void
+print(Stream &                          stream,
+      const std::string &               name,
+      const Tensor<2, dim, NumberType> &t)
+{
+  for (unsigned int i = 0; i < dim; ++i)
+    for (unsigned int j = 0; j < dim; ++j)
+      stream << name << "[" << i << "][" << j << "]: " << t[i][j] << std::endl;
+}
+
+
+template <typename Stream, int dim, typename NumberType>
+void
+print(Stream &                                   stream,
+      const std::string &                        name,
+      const SymmetricTensor<2, dim, NumberType> &t)
+{
+  for (unsigned int i = 0; i < dim; ++i)
+    for (unsigned int j = i; j < dim; ++j)
+      stream << name << "[" << i << "][" << j << "]: " << t[i][j] << std::endl;
+}
+
+
+template <typename Stream, int dim, typename NumberType>
+void
+print(Stream &                          stream,
+      const std::string &               name,
+      const Tensor<3, dim, NumberType> &t)
+{
+  for (unsigned int i = 0; i < dim; ++i)
+    for (unsigned int j = 0; j < dim; ++j)
+      for (unsigned int k = 0; k < dim; ++k)
+        stream << name << "[" << i << "][" << j << "][" << k
+               << "]: " << t[i][j][k] << std::endl;
+}
+
+
+template <typename Stream, int dim, typename NumberType>
+void
+print(Stream &                          stream,
+      const std::string &               name,
+      const Tensor<4, dim, NumberType> &t)
+{
+  for (unsigned int i = 0; i < dim; ++i)
+    for (unsigned int j = 0; j < dim; ++j)
+      for (unsigned int k = 0; k < dim; ++k)
+        for (unsigned int l = 0; l < dim; ++l)
+          stream << name << "[" << i << "][" << j << "][" << k << "][" << l
+                 << "]: " << t[i][j][k][l] << std::endl;
+}
+
+
+template <typename Stream, int dim, typename NumberType>
+void
+print(Stream &                                   stream,
+      const std::string &                        name,
+      const SymmetricTensor<4, dim, NumberType> &t)
+{
+  for (unsigned int i = 0; i < dim; ++i)
+    for (unsigned int j = i; j < dim; ++j)
+      for (unsigned int k = 0; k < dim; ++k)
+        for (unsigned int l = k; l < dim; ++l)
+          stream << name << "[" << i << "][" << j << "][" << k << "][" << l
+                 << "]: " << t[i][j][k][l] << std::endl;
+}
\ No newline at end of file

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.