]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add tests to check compilation with AD numbers: Tensor class
authorJean-Paul Pelteret <jppelteret@gmail.com>
Fri, 12 Oct 2018 13:16:35 +0000 (15:16 +0200)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Fri, 12 Oct 2018 13:16:35 +0000 (15:16 +0200)
13 files changed:
tests/ad_common_tests/tensor_functions_01.h [new file with mode: 0644]
tests/adolc/tensor_functions_01_1.cc [new file with mode: 0644]
tests/adolc/tensor_functions_01_1.output [new file with mode: 0644]
tests/adolc/tensor_functions_01_2.cc [new file with mode: 0644]
tests/adolc/tensor_functions_01_2.output [new file with mode: 0644]
tests/sacado/tensor_functions_01_1.cc [new file with mode: 0644]
tests/sacado/tensor_functions_01_1.output [new file with mode: 0644]
tests/sacado/tensor_functions_01_2.cc [new file with mode: 0644]
tests/sacado/tensor_functions_01_2.output [new file with mode: 0644]
tests/sacado/tensor_functions_01_3.cc [new file with mode: 0644]
tests/sacado/tensor_functions_01_3.output [new file with mode: 0644]
tests/sacado/tensor_functions_01_4.cc [new file with mode: 0644]
tests/sacado/tensor_functions_01_4.output [new file with mode: 0644]

diff --git a/tests/ad_common_tests/tensor_functions_01.h b/tests/ad_common_tests/tensor_functions_01.h
new file mode 100644 (file)
index 0000000..4b4c819
--- /dev/null
@@ -0,0 +1,76 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 - 2018 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Header file:
+// Test to check that the various Tensor functions compile
+// with the various auto-differentiable number types
+
+#include <deal.II/base/tensor.h>
+
+#include <deal.II/differentiation/ad.h>
+
+#include <iostream>
+
+#include "../tests.h"
+
+using namespace dealii;
+namespace AD = dealii::Differentiation::AD;
+
+template <int dim, typename number_t, enum AD::NumberTypes ad_type_code>
+void
+test_tensor()
+{
+  typedef
+    typename AD::NumberTraits<number_t, ad_type_code>::ad_type ADNumberType;
+
+  std::cout << "*** Test Tensor functions, "
+            << "dim = " << Utilities::to_string(dim) << ", "
+            << "Type code: " << static_cast<int>(ad_type_code) << std::endl;
+
+  const ADNumberType                 a = 1.0;
+  const Tensor<1, dim, ADNumberType> v1;
+  const Tensor<1, dim, ADNumberType> v2;
+  const Tensor<2, dim, ADNumberType> A(
+    unit_symmetric_tensor<dim, ADNumberType>());
+  const Tensor<2, dim, ADNumberType> B(
+    unit_symmetric_tensor<dim, ADNumberType>());
+
+  const Tensor<2, dim, ADNumberType> C1 = A + B;
+  const Tensor<2, dim, ADNumberType> C2 = A - B;
+  const Tensor<2, dim, ADNumberType> C3 = A * B;
+  const Tensor<2, dim, ADNumberType> C4 = a * A;
+  const Tensor<2, dim, ADNumberType> C5 = A * a;
+  const Tensor<2, dim, ADNumberType> C6 = A / a;
+
+  const ADNumberType                 det_A       = determinant(A);
+  const ADNumberType                 tr_A        = trace(A);
+  const Tensor<2, dim, ADNumberType> A_inv       = invert(A);
+  const Tensor<2, dim, ADNumberType> A_T         = transpose(A);
+  const Tensor<2, dim, ADNumberType> A_adj       = adjugate(A);
+  const Tensor<2, dim, ADNumberType> A_cof       = cofactor(A);
+  const ADNumberType                 A_l1_norm   = l1_norm(A);
+  const ADNumberType                 A_linf_norm = linfty_norm(A);
+
+  const ADNumberType                 A_ddot_B = double_contract(A, B);
+  const Tensor<2, dim, ADNumberType> A_dot_B  = contract<1, 0>(A, B);
+  const ADNumberType                 sp_A_B   = scalar_product(A, B);
+  const Tensor<4, dim, ADNumberType> op_A_B   = outer_product(A, B);
+
+  if (dim == 2)
+    const Tensor<1, dim, ADNumberType> v3 = cross_product_2d(v1);
+  if (dim == 3)
+    const Tensor<1, dim, ADNumberType> v3 = cross_product_3d(v1, v2);
+}
diff --git a/tests/adolc/tensor_functions_01_1.cc b/tests/adolc/tensor_functions_01_1.cc
new file mode 100644 (file)
index 0000000..57925c5
--- /dev/null
@@ -0,0 +1,39 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 - 2018 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Test to check that the various Tensor functions compile
+// with the various auto-differentiable number types
+//
+// AD number type: ADOL-C taped
+
+#include "../ad_common_tests/tensor_functions_01.h"
+#include "../tests.h"
+
+int
+main()
+{
+  initlog();
+
+  deallog.push("Double");
+  {
+    test_tensor<2, double, AD::NumberTypes::adolc_taped>();
+    test_tensor<3, double, AD::NumberTypes::adolc_taped>();
+    deallog << "OK" << std::endl;
+  }
+  deallog.pop();
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/adolc/tensor_functions_01_1.output b/tests/adolc/tensor_functions_01_1.output
new file mode 100644 (file)
index 0000000..3c6dd25
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::Double:OK
+DEAL::OK
diff --git a/tests/adolc/tensor_functions_01_2.cc b/tests/adolc/tensor_functions_01_2.cc
new file mode 100644 (file)
index 0000000..274fb95
--- /dev/null
@@ -0,0 +1,39 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 - 2018 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Test to check that the various Tensor functions compile
+// with the various auto-differentiable number types
+//
+// AD number type: ADOL-C tapeless
+
+#include "../ad_common_tests/tensor_functions_01.h"
+#include "../tests.h"
+
+int
+main()
+{
+  initlog();
+
+  deallog.push("Double");
+  {
+    test_tensor<2, double, AD::NumberTypes::adolc_tapeless>();
+    test_tensor<3, double, AD::NumberTypes::adolc_tapeless>();
+    deallog << "OK" << std::endl;
+  }
+  deallog.pop();
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/adolc/tensor_functions_01_2.output b/tests/adolc/tensor_functions_01_2.output
new file mode 100644 (file)
index 0000000..3c6dd25
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::Double:OK
+DEAL::OK
diff --git a/tests/sacado/tensor_functions_01_1.cc b/tests/sacado/tensor_functions_01_1.cc
new file mode 100644 (file)
index 0000000..610aa78
--- /dev/null
@@ -0,0 +1,39 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 - 2018 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Test to check that the various Tensor functions compile
+// with the various auto-differentiable number types
+//
+// AD number type: Sacado DFad
+
+#include "../ad_common_tests/tensor_functions_01.h"
+#include "../tests.h"
+
+int
+main()
+{
+  initlog();
+
+  deallog.push("Double");
+  {
+    test_tensor<2, double, AD::NumberTypes::sacado_dfad>();
+    test_tensor<3, double, AD::NumberTypes::sacado_dfad>();
+    deallog << "OK" << std::endl;
+  }
+  deallog.pop();
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/sacado/tensor_functions_01_1.output b/tests/sacado/tensor_functions_01_1.output
new file mode 100644 (file)
index 0000000..3c6dd25
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::Double:OK
+DEAL::OK
diff --git a/tests/sacado/tensor_functions_01_2.cc b/tests/sacado/tensor_functions_01_2.cc
new file mode 100644 (file)
index 0000000..caff61d
--- /dev/null
@@ -0,0 +1,39 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 - 2018 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Test to check that the various Tensor functions compile
+// with the various auto-differentiable number types
+//
+// AD number type: Sacado DFad-DFad
+
+#include "../ad_common_tests/tensor_functions_01.h"
+#include "../tests.h"
+
+int
+main()
+{
+  initlog();
+
+  deallog.push("Double");
+  {
+    test_tensor<2, double, AD::NumberTypes::sacado_dfad_dfad>();
+    test_tensor<3, double, AD::NumberTypes::sacado_dfad_dfad>();
+    deallog << "OK" << std::endl;
+  }
+  deallog.pop();
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/sacado/tensor_functions_01_2.output b/tests/sacado/tensor_functions_01_2.output
new file mode 100644 (file)
index 0000000..3c6dd25
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::Double:OK
+DEAL::OK
diff --git a/tests/sacado/tensor_functions_01_3.cc b/tests/sacado/tensor_functions_01_3.cc
new file mode 100644 (file)
index 0000000..2389c40
--- /dev/null
@@ -0,0 +1,39 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 - 2018 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Test to check that the various Tensor functions compile
+// with the various auto-differentiable number types
+//
+// AD number type: Sacado Rad
+
+#include "../ad_common_tests/tensor_functions_01.h"
+#include "../tests.h"
+
+int
+main()
+{
+  initlog();
+
+  deallog.push("Double");
+  {
+    test_tensor<2, double, AD::NumberTypes::sacado_rad>();
+    test_tensor<3, double, AD::NumberTypes::sacado_rad>();
+    deallog << "OK" << std::endl;
+  }
+  deallog.pop();
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/sacado/tensor_functions_01_3.output b/tests/sacado/tensor_functions_01_3.output
new file mode 100644 (file)
index 0000000..3c6dd25
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::Double:OK
+DEAL::OK
diff --git a/tests/sacado/tensor_functions_01_4.cc b/tests/sacado/tensor_functions_01_4.cc
new file mode 100644 (file)
index 0000000..b57f559
--- /dev/null
@@ -0,0 +1,39 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 - 2018 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Test to check that the various Tensor functions compile
+// with the various auto-differentiable number types
+//
+// AD number type: Sacado Rad-DFad
+
+#include "../ad_common_tests/tensor_functions_01.h"
+#include "../tests.h"
+
+int
+main()
+{
+  initlog();
+
+  deallog.push("Double");
+  {
+    test_tensor<2, double, AD::NumberTypes::sacado_rad_dfad>();
+    test_tensor<3, double, AD::NumberTypes::sacado_rad_dfad>();
+    deallog << "OK" << std::endl;
+  }
+  deallog.pop();
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/sacado/tensor_functions_01_4.output b/tests/sacado/tensor_functions_01_4.output
new file mode 100644 (file)
index 0000000..3c6dd25
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::Double:OK
+DEAL::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.