From cbb0329a2432fe3c48f071272216834cf73066aa Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Sat, 27 Aug 2022 18:31:39 +0200 Subject: [PATCH] Add test case --- tests/matrix_free/laplace_operator_04.cc | 106 +++++++++++++++++++ tests/matrix_free/laplace_operator_04.output | 12 +++ 2 files changed, 118 insertions(+) create mode 100644 tests/matrix_free/laplace_operator_04.cc create mode 100644 tests/matrix_free/laplace_operator_04.output diff --git a/tests/matrix_free/laplace_operator_04.cc b/tests/matrix_free/laplace_operator_04.cc new file mode 100644 index 0000000000..01098d2fa1 --- /dev/null +++ b/tests/matrix_free/laplace_operator_04.cc @@ -0,0 +1,106 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2020 - 2022 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + + +// check the diagonal of LaplaceOperator for the scalar and vector-valued case + +#include + +#include +#include + +#include +#include + +#include +#include + +#include + +#include + +#include + +#include "../tests.h" + + +template +void +test() +{ + using number = double; + + Triangulation tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(2); + + FE_Q fe_q(fe_degree); + FESystem fe(fe_q, dim); + DoFHandler dof(tria); + dof.distribute_dofs(fe); + + AffineConstraints constraints; + constraints.close(); + + deallog << "Testing " << dof.get_fe().get_name() << std::endl; + + std::shared_ptr> mf_data( + new MatrixFree()); + { + const QGauss<1> quad(fe_degree + 1); + typename MatrixFree::AdditionalData data; + data.tasks_parallel_scheme = MatrixFree::AdditionalData::none; + data.mapping_update_flags = + update_quadrature_points | update_gradients | update_JxW_values; + mf_data->reinit(MappingQ1{}, dof, constraints, quad, data); + } + + MatrixFreeOperators::LaplaceOperator< + dim, + fe_degree, + fe_degree + 1, + 1, + LinearAlgebra::distributed::Vector> + mf_scalar; + MatrixFreeOperators::LaplaceOperator< + dim, + fe_degree, + fe_degree + 1, + dim, + LinearAlgebra::distributed::Vector> + mf_vector; + mf_scalar.initialize(mf_data); + mf_vector.initialize(mf_data); + mf_scalar.compute_diagonal(); + mf_vector.compute_diagonal(); + deallog << "Matrix diagonal scalar: " << std::endl; + mf_scalar.get_matrix_diagonal()->get_vector().print( + deallog.get_file_stream()); + deallog << "Matrix diagonal vector: " << std::endl; + mf_vector.get_matrix_diagonal()->get_vector().print( + deallog.get_file_stream()); +} + + +int +main() +{ + initlog(); + + deallog << std::setprecision(4); + + test<2, 2>(); +} diff --git a/tests/matrix_free/laplace_operator_04.output b/tests/matrix_free/laplace_operator_04.output new file mode 100644 index 0000000000..cef97f8104 --- /dev/null +++ b/tests/matrix_free/laplace_operator_04.output @@ -0,0 +1,12 @@ + +DEAL::Testing FESystem<2>[FE_Q<2>(2)^2] +DEAL::Matrix diagonal scalar: +Process #0 +Local range: [0, 162), global size: 162 +Vector data: +6.222e-01 0.000e+00 1.244e+00 0.000e+00 1.244e+00 0.000e+00 2.489e+00 0.000e+00 1.956e+00 0.000e+00 3.911e+00 0.000e+00 1.956e+00 0.000e+00 3.911e+00 0.000e+00 5.689e+00 0.000e+00 1.244e+00 0.000e+00 2.489e+00 0.000e+00 3.911e+00 0.000e+00 1.956e+00 0.000e+00 3.911e+00 0.000e+00 5.689e+00 0.000e+00 1.244e+00 0.000e+00 2.489e+00 0.000e+00 1.956e+00 0.000e+00 3.911e+00 0.000e+00 3.911e+00 0.000e+00 5.689e+00 0.000e+00 2.489e+00 0.000e+00 3.911e+00 0.000e+00 3.911e+00 0.000e+00 5.689e+00 0.000e+00 1.244e+00 0.000e+00 2.489e+00 0.000e+00 3.911e+00 0.000e+00 1.956e+00 0.000e+00 3.911e+00 0.000e+00 5.689e+00 0.000e+00 6.222e-01 0.000e+00 1.244e+00 0.000e+00 1.956e+00 0.000e+00 1.956e+00 0.000e+00 3.911e+00 0.000e+00 5.689e+00 0.000e+00 2.489e+00 0.000e+00 3.911e+00 0.000e+00 3.911e+00 0.000e+00 5.689e+00 0.000e+00 1.244e+00 0.000e+00 1.956e+00 0.000e+00 3.911e+00 0.000e+00 5.689e+00 0.000e+00 1.244e+00 0.000e+00 2.489e+00 0.000e+00 1.956e+00 0.000e+00 3.911e+00 0.000e+00 3.911e+00 0.000e+00 5.689e+00 0.000e+00 2.489e+00 0.000e+00 3.911e+00 0.000e+00 3.911e+00 0.000e+00 5.689e+00 0.000e+00 6.222e-01 0.000e+00 1.244e+00 0.000e+00 1.956e+00 0.000e+00 3.911e+00 0.000e+00 1.956e+00 0.000e+00 5.689e+00 0.000e+00 1.244e+00 0.000e+00 3.911e+00 0.000e+00 1.956e+00 0.000e+00 5.689e+00 0.000e+00 2.489e+00 0.000e+00 3.911e+00 0.000e+00 3.911e+00 0.000e+00 5.689e+00 0.000e+00 1.244e+00 0.000e+00 1.956e+00 0.000e+00 3.911e+00 0.000e+00 5.689e+00 0.000e+00 1.244e+00 0.000e+00 3.911e+00 0.000e+00 1.956e+00 0.000e+00 5.689e+00 0.000e+00 6.222e-01 0.000e+00 1.956e+00 0.000e+00 1.956e+00 0.000e+00 5.689e+00 0.000e+00 +DEAL::Matrix diagonal vector: +Process #0 +Local range: [0, 162), global size: 162 +Vector data: +6.222e-01 6.222e-01 1.244e+00 1.244e+00 1.244e+00 1.244e+00 2.489e+00 2.489e+00 1.956e+00 1.956e+00 3.911e+00 3.911e+00 1.956e+00 1.956e+00 3.911e+00 3.911e+00 5.689e+00 5.689e+00 1.244e+00 1.244e+00 2.489e+00 2.489e+00 3.911e+00 3.911e+00 1.956e+00 1.956e+00 3.911e+00 3.911e+00 5.689e+00 5.689e+00 1.244e+00 1.244e+00 2.489e+00 2.489e+00 1.956e+00 1.956e+00 3.911e+00 3.911e+00 3.911e+00 3.911e+00 5.689e+00 5.689e+00 2.489e+00 2.489e+00 3.911e+00 3.911e+00 3.911e+00 3.911e+00 5.689e+00 5.689e+00 1.244e+00 1.244e+00 2.489e+00 2.489e+00 3.911e+00 3.911e+00 1.956e+00 1.956e+00 3.911e+00 3.911e+00 5.689e+00 5.689e+00 6.222e-01 6.222e-01 1.244e+00 1.244e+00 1.956e+00 1.956e+00 1.956e+00 1.956e+00 3.911e+00 3.911e+00 5.689e+00 5.689e+00 2.489e+00 2.489e+00 3.911e+00 3.911e+00 3.911e+00 3.911e+00 5.689e+00 5.689e+00 1.244e+00 1.244e+00 1.956e+00 1.956e+00 3.911e+00 3.911e+00 5.689e+00 5.689e+00 1.244e+00 1.244e+00 2.489e+00 2.489e+00 1.956e+00 1.956e+00 3.911e+00 3.911e+00 3.911e+00 3.911e+00 5.689e+00 5.689e+00 2.489e+00 2.489e+00 3.911e+00 3.911e+00 3.911e+00 3.911e+00 5.689e+00 5.689e+00 6.222e-01 6.222e-01 1.244e+00 1.244e+00 1.956e+00 1.956e+00 3.911e+00 3.911e+00 1.956e+00 1.956e+00 5.689e+00 5.689e+00 1.244e+00 1.244e+00 3.911e+00 3.911e+00 1.956e+00 1.956e+00 5.689e+00 5.689e+00 2.489e+00 2.489e+00 3.911e+00 3.911e+00 3.911e+00 3.911e+00 5.689e+00 5.689e+00 1.244e+00 1.244e+00 1.956e+00 1.956e+00 3.911e+00 3.911e+00 5.689e+00 5.689e+00 1.244e+00 1.244e+00 3.911e+00 3.911e+00 1.956e+00 1.956e+00 5.689e+00 5.689e+00 6.222e-01 6.222e-01 1.956e+00 1.956e+00 1.956e+00 1.956e+00 5.689e+00 5.689e+00 -- 2.39.5