From: Jean-Paul Pelteret Date: Fri, 12 Oct 2018 13:17:11 +0000 (+0200) Subject: Add tests to check compilation with AD numbers: SymmetricTensor class X-Git-Tag: v9.1.0-rc1~626^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=439ccdf20a860e7cecebae1cc88fce1b44006e70;p=dealii.git Add tests to check compilation with AD numbers: SymmetricTensor class --- diff --git a/tests/ad_common_tests/symmetric_tensor_functions_01.h b/tests/ad_common_tests/symmetric_tensor_functions_01.h new file mode 100644 index 0000000000..c88c077bf2 --- /dev/null +++ b/tests/ad_common_tests/symmetric_tensor_functions_01.h @@ -0,0 +1,87 @@ +// --------------------------------------------------------------------- +// +// 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 SymmetricTensor functions compile +// with the various auto-differentiable number types + +#include +#include + +#include + +#include + +#include "../tests.h" + +using namespace dealii; +namespace AD = dealii::Differentiation::AD; + +template +void +test_symmetric_tensor() +{ + typedef + typename AD::NumberTraits::ad_type ADNumberType; + + std::cout << "*** Test SymmetricTensor functions, " + << "dim = " << Utilities::to_string(dim) << ", " + << "Type code: " << static_cast(ad_type_code) << std::endl; + + const ADNumberType a = 1.0; + const Tensor<1, dim, ADNumberType> v; + const SymmetricTensor<2, dim, ADNumberType> A( + unit_symmetric_tensor()); + const SymmetricTensor<2, dim, ADNumberType> B( + unit_symmetric_tensor()); + const Tensor<2, dim, ADNumberType> A_ns( + unit_symmetric_tensor()); + const SymmetricTensor<4, dim, ADNumberType> HH( + identity_tensor()); + + const SymmetricTensor<2, dim, ADNumberType> C1 = A + B; + const SymmetricTensor<2, dim, ADNumberType> C2 = A - B; + const SymmetricTensor<2, dim, ADNumberType> C4 = a * A; + const SymmetricTensor<2, dim, ADNumberType> C5 = A * a; + const SymmetricTensor<2, dim, ADNumberType> C6 = A / a; + + const ADNumberType det_A = determinant(A); + const ADNumberType tr_A = trace(A); + const ADNumberType I1_A = first_invariant(A); + const ADNumberType I2_A = second_invariant(A); + const ADNumberType I3_A = third_invariant(A); + + const SymmetricTensor<2, dim, ADNumberType> A_inv = invert(A); + const SymmetricTensor<2, dim, ADNumberType> A_T = transpose(A); + const SymmetricTensor<2, dim, ADNumberType> A_dev = deviator(A); + const SymmetricTensor<2, dim, ADNumberType> A_symm = symmetrize(A_ns); + // const ADNumberType A_l1_norm = l1_norm(A); + // const ADNumberType A_linf_norm = linfty_norm(A); + + const ADNumberType A_ddot_B_1 = A * B; + const ADNumberType sp_A_B = scalar_product(A, B); + const Tensor<4, dim, ADNumberType> op_A_B = outer_product(A, B); + + + SymmetricTensor<2, dim, ADNumberType> C_dc; + double_contract(C_dc, A, HH); + double_contract(C_dc, HH, A); + + const Tensor<1, dim, ADNumberType> v3 = A * v; + const Tensor<1, dim, ADNumberType> v4 = v * A; + const Tensor<2, dim, ADNumberType> C7 = A * A_ns; + const Tensor<2, dim, ADNumberType> C8 = A_ns * A; +} diff --git a/tests/adolc/symmetric_tensor_functions_01_1.cc b/tests/adolc/symmetric_tensor_functions_01_1.cc new file mode 100644 index 0000000000..72f0227604 --- /dev/null +++ b/tests/adolc/symmetric_tensor_functions_01_1.cc @@ -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 SymmetricTensor functions compile +// with the various auto-differentiable number types +// +// AD number type: ADOL-C taped + +#include "../ad_common_tests/symmetric_tensor_functions_01.h" +#include "../tests.h" + +int +main() +{ + initlog(); + + deallog.push("Double"); + { + test_symmetric_tensor<2, double, AD::NumberTypes::adolc_taped>(); + test_symmetric_tensor<3, double, AD::NumberTypes::adolc_taped>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/adolc/symmetric_tensor_functions_01_1.output b/tests/adolc/symmetric_tensor_functions_01_1.output new file mode 100644 index 0000000000..3c6dd257b1 --- /dev/null +++ b/tests/adolc/symmetric_tensor_functions_01_1.output @@ -0,0 +1,3 @@ + +DEAL::Double:OK +DEAL::OK diff --git a/tests/adolc/symmetric_tensor_functions_01_2.cc b/tests/adolc/symmetric_tensor_functions_01_2.cc new file mode 100644 index 0000000000..4784fee429 --- /dev/null +++ b/tests/adolc/symmetric_tensor_functions_01_2.cc @@ -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 SymmetricTensor functions compile +// with the various auto-differentiable number types +// +// AD number type: ADOL-C tapeless + +#include "../ad_common_tests/symmetric_tensor_functions_01.h" +#include "../tests.h" + +int +main() +{ + initlog(); + + deallog.push("Double"); + { + test_symmetric_tensor<2, double, AD::NumberTypes::adolc_tapeless>(); + test_symmetric_tensor<3, double, AD::NumberTypes::adolc_tapeless>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/adolc/symmetric_tensor_functions_01_2.output b/tests/adolc/symmetric_tensor_functions_01_2.output new file mode 100644 index 0000000000..3c6dd257b1 --- /dev/null +++ b/tests/adolc/symmetric_tensor_functions_01_2.output @@ -0,0 +1,3 @@ + +DEAL::Double:OK +DEAL::OK diff --git a/tests/sacado/symmetric_tensor_functions_01_1.cc b/tests/sacado/symmetric_tensor_functions_01_1.cc new file mode 100644 index 0000000000..e92741ee7f --- /dev/null +++ b/tests/sacado/symmetric_tensor_functions_01_1.cc @@ -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 SymmetricTensor functions compile +// with the various auto-differentiable number types +// +// AD number type: Sacado DFad + +#include "../ad_common_tests/symmetric_tensor_functions_01.h" +#include "../tests.h" + +int +main() +{ + initlog(); + + deallog.push("Double"); + { + test_symmetric_tensor<2, double, AD::NumberTypes::sacado_dfad>(); + test_symmetric_tensor<3, double, AD::NumberTypes::sacado_dfad>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/sacado/symmetric_tensor_functions_01_1.output b/tests/sacado/symmetric_tensor_functions_01_1.output new file mode 100644 index 0000000000..3c6dd257b1 --- /dev/null +++ b/tests/sacado/symmetric_tensor_functions_01_1.output @@ -0,0 +1,3 @@ + +DEAL::Double:OK +DEAL::OK diff --git a/tests/sacado/symmetric_tensor_functions_01_2.cc b/tests/sacado/symmetric_tensor_functions_01_2.cc new file mode 100644 index 0000000000..2fa7dacb6a --- /dev/null +++ b/tests/sacado/symmetric_tensor_functions_01_2.cc @@ -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 SymmetricTensor functions compile +// with the various auto-differentiable number types +// +// AD number type: Sacado DFad-DFad + +#include "../ad_common_tests/symmetric_tensor_functions_01.h" +#include "../tests.h" + +int +main() +{ + initlog(); + + deallog.push("Double"); + { + test_symmetric_tensor<2, double, AD::NumberTypes::sacado_dfad_dfad>(); + test_symmetric_tensor<3, double, AD::NumberTypes::sacado_dfad_dfad>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/sacado/symmetric_tensor_functions_01_2.output b/tests/sacado/symmetric_tensor_functions_01_2.output new file mode 100644 index 0000000000..3c6dd257b1 --- /dev/null +++ b/tests/sacado/symmetric_tensor_functions_01_2.output @@ -0,0 +1,3 @@ + +DEAL::Double:OK +DEAL::OK diff --git a/tests/sacado/symmetric_tensor_functions_01_3.cc b/tests/sacado/symmetric_tensor_functions_01_3.cc new file mode 100644 index 0000000000..31f6b7130f --- /dev/null +++ b/tests/sacado/symmetric_tensor_functions_01_3.cc @@ -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 SymmetricTensor functions compile +// with the various auto-differentiable number types +// +// AD number type: Sacado Rad + +#include "../ad_common_tests/symmetric_tensor_functions_01.h" +#include "../tests.h" + +int +main() +{ + initlog(); + + deallog.push("Double"); + { + test_symmetric_tensor<2, double, AD::NumberTypes::sacado_rad>(); + test_symmetric_tensor<3, double, AD::NumberTypes::sacado_rad>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/sacado/symmetric_tensor_functions_01_3.output b/tests/sacado/symmetric_tensor_functions_01_3.output new file mode 100644 index 0000000000..3c6dd257b1 --- /dev/null +++ b/tests/sacado/symmetric_tensor_functions_01_3.output @@ -0,0 +1,3 @@ + +DEAL::Double:OK +DEAL::OK diff --git a/tests/sacado/symmetric_tensor_functions_01_4.cc b/tests/sacado/symmetric_tensor_functions_01_4.cc new file mode 100644 index 0000000000..ecac4b93d0 --- /dev/null +++ b/tests/sacado/symmetric_tensor_functions_01_4.cc @@ -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 SymmetricTensor functions compile +// with the various auto-differentiable number types +// +// AD number type: Sacado Rad-DFad + +#include "../ad_common_tests/symmetric_tensor_functions_01.h" +#include "../tests.h" + +int +main() +{ + initlog(); + + deallog.push("Double"); + { + test_symmetric_tensor<2, double, AD::NumberTypes::sacado_rad_dfad>(); + test_symmetric_tensor<3, double, AD::NumberTypes::sacado_rad_dfad>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/sacado/symmetric_tensor_functions_01_4.output b/tests/sacado/symmetric_tensor_functions_01_4.output new file mode 100644 index 0000000000..3c6dd257b1 --- /dev/null +++ b/tests/sacado/symmetric_tensor_functions_01_4.output @@ -0,0 +1,3 @@ + +DEAL::Double:OK +DEAL::OK