From 27894e1a55da4d17add7c3125ec80b5759c9da61 Mon Sep 17 00:00:00 2001 From: Menno Fraters Date: Fri, 28 Feb 2020 10:20:25 -0800 Subject: [PATCH] add tests for rank 2 tensor orthogonalization function. --- tests/ad_common_tests/tensor_functions_01.h | 3 ++- tests/tensors/constexpr_tensor.cc | 21 +++++++++++++++++++++ tests/tensors/constexpr_tensor.output | 4 ++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/ad_common_tests/tensor_functions_01.h b/tests/ad_common_tests/tensor_functions_01.h index e00e044980..85f4fc853a 100644 --- a/tests/ad_common_tests/tensor_functions_01.h +++ b/tests/ad_common_tests/tensor_functions_01.h @@ -61,7 +61,8 @@ test_tensor() 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 Tensor<2, dim, ADNumberType> A_orth = orthogonalize(A); + const ADNumberType A_l1_norm = l1_norm(A, 1e-8); const ADNumberType A_linf_norm = linfty_norm(A); const ADNumberType A_ddot_B = double_contract<0, 0, 1, 1>(A, B); diff --git a/tests/tensors/constexpr_tensor.cc b/tests/tensors/constexpr_tensor.cc index 49748c3ae7..d1f2f0905e 100644 --- a/tests/tensors/constexpr_tensor.cc +++ b/tests/tensors/constexpr_tensor.cc @@ -17,6 +17,8 @@ #include +#include + #include "../tests.h" template @@ -177,6 +179,25 @@ main() DEAL_II_CONSTEXPR const auto dummy_6 = contract3(a, middle, a); DEAL_II_CONSTEXPR const auto dummy_7 = adjugate(a); DEAL_II_CONSTEXPR const auto dummy_8 = cofactor(a); + deallog << "Deteriminant before orthogonalization: " << determinant(a) + << std::endl; + const auto dummy_9 = orthogonalize(a, 1e-8); + deallog << "Deteriminant after orthogonalization: " << determinant(dummy_9) + << std::endl; + Assert(determinant(dummy_9) - 1. < 1e-8, ExcInternalError()); + + + constexpr double non_orthogonal_init[3][3] = {{1., 2., 3.}, + {1., 1.5, 2.}, + {2., 0., 1}}; + constexpr Tensor<2, 3> non_orthogonal{non_orthogonal_init}; + + deallog << "Deteriminant before orthogonalization: " + << determinant(non_orthogonal) << std::endl; + const auto dummy_10 = orthogonalize(non_orthogonal, 1e-8); + deallog << "Deteriminant after orthogonalization: " + << determinant(dummy_10) << std::endl; + Assert(determinant(dummy_10) - 1. < 1e-8, ExcInternalError()); } { diff --git a/tests/tensors/constexpr_tensor.output b/tests/tensors/constexpr_tensor.output index 5b07862e37..29275c9ddc 100644 --- a/tests/tensors/constexpr_tensor.output +++ b/tests/tensors/constexpr_tensor.output @@ -166,4 +166,8 @@ DEAL::Using Tensor within constexpr functions DEAL::15.2000 DEAL::116.000 DEAL::Used memory: 72 +DEAL::Deteriminant before orthogonalization: 1.00000 +DEAL::Deteriminant after orthogonalization: 1.00000 +DEAL::Deteriminant before orthogonalization: -1.50000 +DEAL::Deteriminant after orthogonalization: -1.00000 DEAL::OK -- 2.39.5