From: Martin Kronbichler Date: Fri, 15 Mar 2024 09:42:58 +0000 (+0100) Subject: New test cases X-Git-Tag: v9.6.0-rc1~475^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16754%2Fhead;p=dealii.git New test cases --- diff --git a/tests/matrix_free/evaluate_1d_shape_10.cc b/tests/matrix_free/evaluate_1d_shape_10.cc new file mode 100644 index 0000000000..ad5116e3e5 --- /dev/null +++ b/tests/matrix_free/evaluate_1d_shape_10.cc @@ -0,0 +1,125 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2018 - 2022 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + + +// check the correctness of the 1d evaluation functions used in FEEvaluation, +// path evaluate_general with numbers of type std::complex, when using same +// array for in and out + +#include + +#include + +#include "../tests.h" + + +template +void +test() +{ + deallog << "Test " << M << " x " << N << std::endl; + AlignedVector> shape(M * N); + for (unsigned int i = 0; i < M; ++i) + for (unsigned int j = 0; j < N; ++j) + shape[i * N + j] = -1. + 2. * random_value(); + + std::complex x[N + M], x_ref[N], y_ref[M]; + for (unsigned int i = 0; i < N; ++i) + x[i] = std::complex(random_value(), random_value()); + + // compute reference + for (unsigned int i = 0; i < M; ++i) + { + y_ref[i] = 0.; + for (unsigned int j = 0; j < N; ++j) + y_ref[i] += shape[i * N + j] * x[j]; + } + + // apply function for tensor product + internal::EvaluatorTensorProduct> + evaluator(shape, shape, shape); + if (type == 0) + evaluator.template values<0, false, false>(x, x); + if (type == 1) + evaluator.template gradients<0, false, false>(x, x); + if (type == 2) + evaluator.template hessians<0, false, false>(x, x); + + deallog << "Errors no transpose: "; + for (unsigned int i = 0; i < M; ++i) + deallog << x[i] - y_ref[i] << ' '; + deallog << std::endl; + + + for (unsigned int i = 0; i < M; ++i) + x[i] = random_value(); + + // compute reference + for (unsigned int i = 0; i < N; ++i) + { + x_ref[i] = 0.; + for (unsigned int j = 0; j < M; ++j) + x_ref[i] += shape[j * N + i] * x[j]; + } + + // apply function for tensor product + if (type == 0) + evaluator.template values<0, true, false>(x, x); + if (type == 1) + evaluator.template gradients<0, true, false>(x, x); + if (type == 2) + evaluator.template hessians<0, true, false>(x, x); + + deallog << "Errors transpose: "; + for (unsigned int i = 0; i < N; ++i) + deallog << x[i] - x_ref[i] << ' '; + deallog << std::endl; +} + +int +main() +{ + initlog(); + + deallog.push("values"); + test<4, 4, 0>(); + test<3, 3, 0>(); + test<4, 3, 0>(); + test<3, 4, 0>(); + test<3, 5, 0>(); + deallog.pop(); + + deallog.push("gradients"); + test<4, 4, 1>(); + test<3, 3, 1>(); + test<4, 3, 1>(); + test<3, 4, 1>(); + test<3, 5, 1>(); + deallog.pop(); + + deallog.push("hessians"); + test<4, 4, 2>(); + test<3, 3, 2>(); + test<4, 3, 2>(); + test<3, 4, 2>(); + test<3, 5, 2>(); + deallog.pop(); + + return 0; +} diff --git a/tests/matrix_free/evaluate_1d_shape_10.output b/tests/matrix_free/evaluate_1d_shape_10.output new file mode 100644 index 0000000000..5fc7096614 --- /dev/null +++ b/tests/matrix_free/evaluate_1d_shape_10.output @@ -0,0 +1,46 @@ + +DEAL:values::Test 4 x 4 +DEAL:values::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:values::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:values::Test 3 x 3 +DEAL:values::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:values::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:values::Test 4 x 3 +DEAL:values::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:values::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:values::Test 3 x 4 +DEAL:values::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:values::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:values::Test 3 x 5 +DEAL:values::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:values::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:gradients::Test 4 x 4 +DEAL:gradients::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:gradients::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:gradients::Test 3 x 3 +DEAL:gradients::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:gradients::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:gradients::Test 4 x 3 +DEAL:gradients::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:gradients::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:gradients::Test 3 x 4 +DEAL:gradients::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:gradients::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:gradients::Test 3 x 5 +DEAL:gradients::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:gradients::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:hessians::Test 4 x 4 +DEAL:hessians::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:hessians::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:hessians::Test 3 x 3 +DEAL:hessians::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:hessians::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:hessians::Test 4 x 3 +DEAL:hessians::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:hessians::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:hessians::Test 3 x 4 +DEAL:hessians::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:hessians::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:hessians::Test 3 x 5 +DEAL:hessians::Errors no transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) +DEAL:hessians::Errors transpose: (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000) (0.00000,0.00000)