From: Jean-Paul Pelteret Date: Fri, 12 Oct 2018 13:19:18 +0000 (+0200) Subject: Add tests to check compilation with AD numbers: Physics NS (part 3) X-Git-Tag: v9.1.0-rc1~626^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d74f962acca490f31a4b341f85405cdf29d130ea;p=dealii.git Add tests to check compilation with AD numbers: Physics NS (part 3) Physics::Transformations --- diff --git a/tests/ad_common_tests/physics_functions_03.h b/tests/ad_common_tests/physics_functions_03.h new file mode 100644 index 0000000000..e2dd5a0d33 --- /dev/null +++ b/tests/ad_common_tests/physics_functions_03.h @@ -0,0 +1,138 @@ +// --------------------------------------------------------------------- +// +// 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 functions in the Physics namespace compile +// with the various auto-differentiable number types: +// StandardTensors + +#include +#include + +#include + +#include +#include + +#include + +#include "../tests.h" + +using namespace dealii; +namespace AD = dealii::Differentiation::AD; + +template +void +test_physics() +{ + typedef + typename AD::NumberTraits::ad_type ADNumberType; + + std::cout << "*** Test physics functions: Standard tensors, " + << "dim = " << Utilities::to_string(dim) << ", " + << "Type code: " << static_cast(ad_type_code) << std::endl; + + Tensor<2, dim, ADNumberType> grad_u; + const Tensor<2, dim, ADNumberType> F = + Physics::Elasticity::Kinematics::F(grad_u); + const Tensor<1, dim, ADNumberType> N; + const Tensor<1, dim, ADNumberType> V; + const Tensor<2, dim, ADNumberType> T1; + const SymmetricTensor<2, dim, ADNumberType> T2; + const Tensor<4, dim, ADNumberType> TT1; + const SymmetricTensor<4, dim, ADNumberType> TT2; + + const Tensor<1, dim, ADNumberType> ddet_F_dC = + Physics::Transformations::nansons_formula(N, F); + + // Contravariant + { + const Tensor<1, dim, ADNumberType> V_out = + Physics::Transformations::Contravariant::push_forward(V, F); + const Tensor<2, dim, ADNumberType> T1_out = + Physics::Transformations::Contravariant::push_forward(T1, F); + const SymmetricTensor<2, dim, ADNumberType> T2_out = + Physics::Transformations::Contravariant::push_forward(T2, F); + const Tensor<4, dim, ADNumberType> TT1_out = + Physics::Transformations::Contravariant::push_forward(TT1, F); + const SymmetricTensor<4, dim, ADNumberType> TT2_out = + Physics::Transformations::Contravariant::push_forward(TT2, F); + } + { + const Tensor<1, dim, ADNumberType> V_out = + Physics::Transformations::Contravariant::pull_back(V, F); + const Tensor<2, dim, ADNumberType> T1_out = + Physics::Transformations::Contravariant::pull_back(T1, F); + const SymmetricTensor<2, dim, ADNumberType> T2_out = + Physics::Transformations::Contravariant::pull_back(T2, F); + const Tensor<4, dim, ADNumberType> TT1_out = + Physics::Transformations::Contravariant::pull_back(TT1, F); + const SymmetricTensor<4, dim, ADNumberType> TT2_out = + Physics::Transformations::Contravariant::pull_back(TT2, F); + } + + // Covariant + { + const Tensor<1, dim, ADNumberType> V_out = + Physics::Transformations::Covariant::push_forward(V, F); + const Tensor<2, dim, ADNumberType> T1_out = + Physics::Transformations::Covariant::push_forward(T1, F); + const SymmetricTensor<2, dim, ADNumberType> T2_out = + Physics::Transformations::Covariant::push_forward(T2, F); + const Tensor<4, dim, ADNumberType> TT1_out = + Physics::Transformations::Covariant::push_forward(TT1, F); + const SymmetricTensor<4, dim, ADNumberType> TT2_out = + Physics::Transformations::Covariant::push_forward(TT2, F); + } + { + const Tensor<1, dim, ADNumberType> V_out = + Physics::Transformations::Covariant::pull_back(V, F); + const Tensor<2, dim, ADNumberType> T1_out = + Physics::Transformations::Covariant::pull_back(T1, F); + const SymmetricTensor<2, dim, ADNumberType> T2_out = + Physics::Transformations::Covariant::pull_back(T2, F); + const Tensor<4, dim, ADNumberType> TT1_out = + Physics::Transformations::Covariant::pull_back(TT1, F); + const SymmetricTensor<4, dim, ADNumberType> TT2_out = + Physics::Transformations::Covariant::pull_back(TT2, F); + } + + // Piola + { + const Tensor<1, dim, ADNumberType> V_out = + Physics::Transformations::Piola::push_forward(V, F); + const Tensor<2, dim, ADNumberType> T1_out = + Physics::Transformations::Piola::push_forward(T1, F); + const SymmetricTensor<2, dim, ADNumberType> T2_out = + Physics::Transformations::Piola::push_forward(T2, F); + const Tensor<4, dim, ADNumberType> TT1_out = + Physics::Transformations::Piola::push_forward(TT1, F); + const SymmetricTensor<4, dim, ADNumberType> TT2_out = + Physics::Transformations::Piola::push_forward(TT2, F); + } + { + const Tensor<1, dim, ADNumberType> V_out = + Physics::Transformations::Piola::pull_back(V, F); + const Tensor<2, dim, ADNumberType> T1_out = + Physics::Transformations::Piola::pull_back(T1, F); + const SymmetricTensor<2, dim, ADNumberType> T2_out = + Physics::Transformations::Piola::pull_back(T2, F); + const Tensor<4, dim, ADNumberType> TT1_out = + Physics::Transformations::Piola::pull_back(TT1, F); + const SymmetricTensor<4, dim, ADNumberType> TT2_out = + Physics::Transformations::Piola::pull_back(TT2, F); + } +} diff --git a/tests/adolc/physics_functions_03_1.cc b/tests/adolc/physics_functions_03_1.cc new file mode 100644 index 0000000000..5a6d162171 --- /dev/null +++ b/tests/adolc/physics_functions_03_1.cc @@ -0,0 +1,40 @@ +// --------------------------------------------------------------------- +// +// 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 functions in the Physics namespace compile +// with the various auto-differentiable number types: +// Transformations +// +// AD number type: ADOL-C taped + +#include "../ad_common_tests/physics_functions_03.h" +#include "../tests.h" + +int +main() +{ + initlog(); + + deallog.push("Double"); + { + test_physics<2, double, AD::NumberTypes::adolc_taped>(); + test_physics<3, double, AD::NumberTypes::adolc_taped>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/adolc/physics_functions_03_1.output b/tests/adolc/physics_functions_03_1.output new file mode 100644 index 0000000000..3c6dd257b1 --- /dev/null +++ b/tests/adolc/physics_functions_03_1.output @@ -0,0 +1,3 @@ + +DEAL::Double:OK +DEAL::OK diff --git a/tests/adolc/physics_functions_03_2.cc b/tests/adolc/physics_functions_03_2.cc new file mode 100644 index 0000000000..1a0d78afee --- /dev/null +++ b/tests/adolc/physics_functions_03_2.cc @@ -0,0 +1,40 @@ +// --------------------------------------------------------------------- +// +// 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 functions in the Physics namespace compile +// with the various auto-differentiable number types: +// Transformations +// +// AD number type: ADOL-C tapeless + +#include "../ad_common_tests/physics_functions_03.h" +#include "../tests.h" + +int +main() +{ + initlog(); + + deallog.push("Double"); + { + test_physics<2, double, AD::NumberTypes::adolc_tapeless>(); + test_physics<3, double, AD::NumberTypes::adolc_tapeless>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/adolc/physics_functions_03_2.output b/tests/adolc/physics_functions_03_2.output new file mode 100644 index 0000000000..3c6dd257b1 --- /dev/null +++ b/tests/adolc/physics_functions_03_2.output @@ -0,0 +1,3 @@ + +DEAL::Double:OK +DEAL::OK diff --git a/tests/sacado/physics_functions_03_1.cc b/tests/sacado/physics_functions_03_1.cc new file mode 100644 index 0000000000..64ada8f6b4 --- /dev/null +++ b/tests/sacado/physics_functions_03_1.cc @@ -0,0 +1,48 @@ +// --------------------------------------------------------------------- +// +// 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 functions in the Physics namespace compile +// with the various auto-differentiable number types: +// Transformations +// +// AD number type: Sacado DFad + +#include "../ad_common_tests/physics_functions_03.h" +#include "../tests.h" + +int +main() +{ + initlog(); + + deallog.push("Double"); + { + test_physics<2, double, AD::NumberTypes::adolc_taped>(); + test_physics<3, double, AD::NumberTypes::adolc_taped>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog.push("Float"); + { + test_physics<2, float, AD::NumberTypes::adolc_taped>(); + test_physics<3, float, AD::NumberTypes::adolc_taped>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/sacado/physics_functions_03_1.output b/tests/sacado/physics_functions_03_1.output new file mode 100644 index 0000000000..ea4ec510fe --- /dev/null +++ b/tests/sacado/physics_functions_03_1.output @@ -0,0 +1,4 @@ + +DEAL::Double:OK +DEAL::Float:OK +DEAL::OK diff --git a/tests/sacado/physics_functions_03_2.cc b/tests/sacado/physics_functions_03_2.cc new file mode 100644 index 0000000000..553ad377ad --- /dev/null +++ b/tests/sacado/physics_functions_03_2.cc @@ -0,0 +1,48 @@ +// --------------------------------------------------------------------- +// +// 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 functions in the Physics namespace compile +// with the various auto-differentiable number types: +// Transformations +// +// AD number type: Sacado DFad-DFad + +#include "../ad_common_tests/physics_functions_03.h" +#include "../tests.h" + +int +main() +{ + initlog(); + + deallog.push("Double"); + { + test_physics<2, double, AD::NumberTypes::sacado_dfad_dfad>(); + test_physics<3, double, AD::NumberTypes::sacado_dfad_dfad>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog.push("Float"); + { + test_physics<2, float, AD::NumberTypes::sacado_dfad_dfad>(); + test_physics<3, float, AD::NumberTypes::sacado_dfad_dfad>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/sacado/physics_functions_03_2.output b/tests/sacado/physics_functions_03_2.output new file mode 100644 index 0000000000..ea4ec510fe --- /dev/null +++ b/tests/sacado/physics_functions_03_2.output @@ -0,0 +1,4 @@ + +DEAL::Double:OK +DEAL::Float:OK +DEAL::OK diff --git a/tests/sacado/physics_functions_03_3.cc b/tests/sacado/physics_functions_03_3.cc new file mode 100644 index 0000000000..36db47db73 --- /dev/null +++ b/tests/sacado/physics_functions_03_3.cc @@ -0,0 +1,48 @@ +// --------------------------------------------------------------------- +// +// 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 functions in the Physics namespace compile +// with the various auto-differentiable number types: +// Transformations +// +// AD number type: Sacado Rad + +#include "../ad_common_tests/physics_functions_03.h" +#include "../tests.h" + +int +main() +{ + initlog(); + + deallog.push("Double"); + { + test_physics<2, double, AD::NumberTypes::sacado_rad>(); + test_physics<3, double, AD::NumberTypes::sacado_rad>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog.push("Float"); + { + test_physics<2, float, AD::NumberTypes::sacado_rad>(); + test_physics<3, float, AD::NumberTypes::sacado_rad>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/sacado/physics_functions_03_3.output b/tests/sacado/physics_functions_03_3.output new file mode 100644 index 0000000000..ea4ec510fe --- /dev/null +++ b/tests/sacado/physics_functions_03_3.output @@ -0,0 +1,4 @@ + +DEAL::Double:OK +DEAL::Float:OK +DEAL::OK diff --git a/tests/sacado/physics_functions_03_4.cc b/tests/sacado/physics_functions_03_4.cc new file mode 100644 index 0000000000..7ebb3cbf5a --- /dev/null +++ b/tests/sacado/physics_functions_03_4.cc @@ -0,0 +1,48 @@ +// --------------------------------------------------------------------- +// +// 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 functions in the Physics namespace compile +// with the various auto-differentiable number types: +// Transformations +// +// AD number type: Sacado Rad-DFad + +#include "../ad_common_tests/physics_functions_03.h" +#include "../tests.h" + +int +main() +{ + initlog(); + + deallog.push("Double"); + { + test_physics<2, double, AD::NumberTypes::sacado_rad_dfad>(); + test_physics<3, double, AD::NumberTypes::sacado_rad_dfad>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog.push("Float"); + { + test_physics<2, float, AD::NumberTypes::sacado_rad_dfad>(); + test_physics<3, float, AD::NumberTypes::sacado_rad_dfad>(); + deallog << "OK" << std::endl; + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/sacado/physics_functions_03_4.output b/tests/sacado/physics_functions_03_4.output new file mode 100644 index 0000000000..ea4ec510fe --- /dev/null +++ b/tests/sacado/physics_functions_03_4.output @@ -0,0 +1,4 @@ + +DEAL::Double:OK +DEAL::Float:OK +DEAL::OK