From f31b73d54efc2b70b5e47d947ef8037f73afa68b Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Fri, 5 Apr 2024 10:47:09 +0200 Subject: [PATCH] New test case --- tests/base/quadrature_initialize.cc | 85 +++++++++++++++++++++++++ tests/base/quadrature_initialize.output | 9 +++ 2 files changed, 94 insertions(+) create mode 100644 tests/base/quadrature_initialize.cc create mode 100644 tests/base/quadrature_initialize.output diff --git a/tests/base/quadrature_initialize.cc b/tests/base/quadrature_initialize.cc new file mode 100644 index 0000000000..674f589712 --- /dev/null +++ b/tests/base/quadrature_initialize.cc @@ -0,0 +1,85 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 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. +// +// ------------------------------------------------------------------------ + + + +// test various Quadrature::initialize functions + + +#include + +#include "../tests.h" + +template +void +compare_quadratures(const Quadrature &reference, + const Quadrature &check) +{ + AssertDimension(reference.size(), check.size()); + for (unsigned int i = 0; i < reference.size(); ++i) + { + // Check for exact equality because data gets copied, so there should be + // no roundoff + if (reference.point(i).distance(check.point(i)) > 0) + deallog << " error point " << i << reference.point(i) << " vs " + << check.point(i); + if (reference.weight(i) != check.weight(i)) + deallog << " error weight " << i << reference.weight(i) << " vs " + << check.weight(i); + } + deallog << "OK" << std::endl; +} + +template +void +test() +{ + deallog.push(std::to_string(dim) + "d"); + Quadrature quadrature_2; + { + QGauss quad(2); + quadrature_2.initialize(quad.get_points(), quad.get_weights()); + deallog << "Testing initialize(vector&, vector&): "; + compare_quadratures(quad, quadrature_2); + } + { + QGauss quad(3); + quadrature_2.initialize(quad.get_points(), quad.get_weights()); + deallog << "Testing initialize(vector&, vector&): "; + compare_quadratures(quad, quadrature_2); + } + { + QGauss quad(2); + quadrature_2.initialize(make_array_view(quad.get_points()), + make_array_view(quad.get_weights())); + deallog << "Testing initialize(ArrayView, ArrayView): "; + compare_quadratures(quad, quadrature_2); + } + { + Quadrature quad(quadrature_2.get_points()); + quadrature_2.initialize(make_array_view(quad.get_points())); + deallog << "Testing initialize(ArrayView): "; + compare_quadratures(quad, quadrature_2); + } + deallog.pop(); +} + +int +main() +{ + initlog(); + + test<1>(); + test<2>(); +} diff --git a/tests/base/quadrature_initialize.output b/tests/base/quadrature_initialize.output new file mode 100644 index 0000000000..d7c4de1033 --- /dev/null +++ b/tests/base/quadrature_initialize.output @@ -0,0 +1,9 @@ + +DEAL:1d::Testing initialize(vector&, vector&): OK +DEAL:1d::Testing initialize(vector&, vector&): OK +DEAL:1d::Testing initialize(ArrayView, ArrayView): OK +DEAL:1d::Testing initialize(ArrayView): OK +DEAL:2d::Testing initialize(vector&, vector&): OK +DEAL:2d::Testing initialize(vector&, vector&): OK +DEAL:2d::Testing initialize(ArrayView, ArrayView): OK +DEAL:2d::Testing initialize(ArrayView): OK -- 2.39.5