From 2b2e8a76017e5900f9961177a00b74214a3463e4 Mon Sep 17 00:00:00 2001 From: David Wells Date: Thu, 3 Feb 2022 12:12:41 -0500 Subject: [PATCH] Augment a test to verify detection. --- tests/matrix_free/laplace_operator_01.cc | 28 +++++++++++++++++++++++- tests/matrix_free/laplace_operator_02.cc | 3 ++- tests/matrix_free/laplace_operator_03.cc | 4 ++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/tests/matrix_free/laplace_operator_01.cc b/tests/matrix_free/laplace_operator_01.cc index 8c64120b1e..1dc773a350 100644 --- a/tests/matrix_free/laplace_operator_01.cc +++ b/tests/matrix_free/laplace_operator_01.cc @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -139,6 +140,18 @@ test() mf.vmult(out, in); + // Check that things work with LinearOperator too. This verifies that the + // detection mechanism for initialize_dof_vector() works. + { + LinearAlgebra::distributed::Vector out2; + mf.initialize_dof_vector(out2); + + const auto op_mf = linear_operator(mf); + op_mf.vmult(out2, in); + + out2 -= out; + AssertThrow(out2.l2_norm() == 0.0, ExcInternalError()); + } // assemble trilinos sparse matrix with // (v, u) for reference @@ -194,8 +207,21 @@ test() sparse_matrix.vmult(ref, in); out -= ref; - const double diff_norm = out.linfty_norm(); + // For completeness, try again with LinearOperator for the same detection + // reasons as above: + { + LinearAlgebra::distributed::Vector out2; + mf.initialize_dof_vector(out2); + + const auto op_mf = linear_operator(sparse_matrix); + op_mf.vmult(out2, in); + + out2 -= ref; + AssertThrow(out2.l2_norm() == 0.0, ExcInternalError()); + } + + const double diff_norm = out.linfty_norm(); deallog << "Norm of difference: " << diff_norm << std::endl << std::endl; } diff --git a/tests/matrix_free/laplace_operator_02.cc b/tests/matrix_free/laplace_operator_02.cc index 7a8ddcaaa9..b2cde0be55 100644 --- a/tests/matrix_free/laplace_operator_02.cc +++ b/tests/matrix_free/laplace_operator_02.cc @@ -15,7 +15,8 @@ -// the same as laplace_operator_01, but tests heterogeneous Laplace operator. +// the same as laplace_operator_01 (excluding the extra detection tests), but +// tests heterogeneous Laplace operator. #include #include diff --git a/tests/matrix_free/laplace_operator_03.cc b/tests/matrix_free/laplace_operator_03.cc index 59f6bd2a65..abbc56b498 100644 --- a/tests/matrix_free/laplace_operator_03.cc +++ b/tests/matrix_free/laplace_operator_03.cc @@ -15,8 +15,8 @@ -// the same as laplace_operator_01, but heterogeneous Laplace operator with a -// single constant coefficient per cell +// the same as laplace_operator_01 (excluding the extra detection tests), but +// heterogeneous Laplace operator with a single constant coefficient per cell #include #include -- 2.39.5