From: Maximilian Bergbauer Date: Mon, 24 Mar 2025 12:26:17 +0000 (+0100) Subject: Add test X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39c88892f5eacf569f1d34b5f85626197315bff9;p=dealii.git Add test --- diff --git a/tests/matrix_free/point_evaluation_36.cc b/tests/matrix_free/point_evaluation_36.cc new file mode 100644 index 0000000000..12cce4e4d0 --- /dev/null +++ b/tests/matrix_free/point_evaluation_36.cc @@ -0,0 +1,147 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2020 - 2024 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 FEPointEvaluation *_normal_derivative + +#include + +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include + +#include "../tests.h" + +using namespace dealii; + +int +main(int argc, char *argv[]) +{ + initlog(); + + constexpr unsigned int dim = 3; + constexpr unsigned int degree = 2; + constexpr unsigned int components = 2; + + using Number = double; + constexpr unsigned int n_lanes = VectorizedArray::size(); + + const unsigned int cell_batch_index = 0; + + Triangulation triangulation; + MappingQ mapping(1); + + GridGenerator::subdivided_hyper_cube(triangulation, 4, -1, 1); + + auto dof_handler = DoFHandler(triangulation); + + FESystem fe_system(FE_DGQ(degree), components); + + dof_handler.distribute_dofs(fe_system); + + auto matrix_free = MatrixFree>(); + typename MatrixFree>::AdditionalData + additional_data; + additional_data.mapping_update_flags = + update_gradients | update_values | update_quadrature_points; + additional_data.hold_all_faces_to_owned_cells = true; + + AffineConstraints affine_constraints{}; + QGauss quadrature(degree + 1); + std::vector> normals(quadrature.size()); + for (auto &normal : normals) + { + const Number x = 1. / ((dim == 3) ? std::sqrt(3.) : std::sqrt(2.)); + normal[0] = x; + normal[1] = x; + if (dim == 3) + normal[2] = x; + } + NonMatching::ImmersedSurfaceQuadrature surface_quadrature( + quadrature.get_points(), quadrature.get_weights(), normals); + + // setup matrixfree object + matrix_free.reinit( + mapping, dof_handler, affine_constraints, quadrature, additional_data); + + NonMatching::MappingInfo> mapping_info( + mapping, + additional_data.mapping_update_flags | update_normal_vectors | + update_JxW_values); + + std::vector>> cell_vec( + 1, triangulation.begin_active()); + std::vector> quad_vec( + 1, surface_quadrature); + mapping_info.reinit_surface(cell_vec, quad_vec); + + FEPointEvaluation> + evaluator_surface(mapping_info, fe_system); + + FEEvaluation> + evaluator(matrix_free, 0, 0); + + LinearAlgebra::distributed::Vector src; + matrix_free.initialize_dof_vector(src); + for (unsigned int i = 0; i < src.size(); i++) + src[i] = random_value(); + + const auto dofs_per_cell = evaluator.dofs_per_cell; + + evaluator.reinit(cell_batch_index); + evaluator.read_dof_values(src); + + for (unsigned int v = 0; v < 1; ++v) + { + evaluator_surface.reinit(0); + + StridedArrayView strided_view( + &evaluator.begin_dof_values()[0][v], dofs_per_cell); + + evaluator_surface.evaluate(StridedArrayView( + &evaluator.begin_dof_values()[0][v], + dofs_per_cell), + EvaluationFlags::gradients); + + for (const auto q : evaluator_surface.quadrature_point_indices()) + { + evaluator_surface.submit_normal_derivative( + evaluator_surface.get_normal_derivative(q), q); + } + + evaluator_surface.test_and_sum( + StridedArrayView(&evaluator.begin_dof_values()[0][v], + dofs_per_cell), + EvaluationFlags::gradients); + + const unsigned int dofs_per_component = evaluator.dofs_per_component; + for (unsigned int c = 0; c < components; ++c) + { + for (unsigned int i = 0; i < dofs_per_component; ++i) + deallog << strided_view[c * dofs_per_component + i] << ' '; + deallog << std::endl; + } + } +} diff --git a/tests/matrix_free/point_evaluation_36.output b/tests/matrix_free/point_evaluation_36.output new file mode 100644 index 0000000000..42f2853498 --- /dev/null +++ b/tests/matrix_free/point_evaluation_36.output @@ -0,0 +1,3 @@ + +DEAL::6.44867 -7.37949 -1.34442 0.685715 4.27451 -0.475383 -1.23030 0.782474 -1.28447 8.89732 -6.15839 -0.321735 0.648048 -13.0431 13.9347 2.06819 0.487274 -1.29072 0.681675 -1.04991 -0.184467 0.0821562 -6.40214 7.29321 -1.45077 1.00358 -5.67222 +DEAL::-11.5253 14.4797 0.946721 -3.56675 8.06577 -2.88978 -2.48877 1.24201 -0.205010 -2.19776 5.54251 -5.52574 9.39589 -9.39648 -0.987088 0.689703 13.1161 -8.81873 -1.43707 -2.17777 1.37381 -0.0941205 12.5223 -2.07236 -0.480526 -10.0492 -3.46219