From dee4c33dc8bc080cbf139ddd62e823746a0abc98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Mon, 29 Nov 2021 19:10:48 +0100 Subject: [PATCH] Add tests for integration along 2d and 3d lines --- tests/test_LineTransformation.cpp | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_LineTransformation.cpp b/tests/test_LineTransformation.cpp index f7acac50f..764a842b8 100644 --- a/tests/test_LineTransformation.cpp +++ b/tests/test_LineTransformation.cpp @@ -1,6 +1,8 @@ #include <catch2/catch_approx.hpp> #include <catch2/catch_test_macros.hpp> +#include <analysis/GaussQuadratureDescriptor.hpp> +#include <analysis/QuadratureManager.hpp> #include <geometry/LineTransformation.hpp> // clazy:excludeall=non-pod-global-static @@ -40,6 +42,21 @@ TEST_CASE("LineTransformation", "[geometry]") REQUIRE(t(1)[1] == Catch::Approx(0.7)); REQUIRE(t.velocityNorm() == Catch::Approx(l2Norm(0.5 * (b - a)))); + + auto p = [](const R2& X) { + const double x = X[0]; + const double y = X[1]; + return 2 * x * x + 3 * x - 3 * y * y + y + 2; + }; + + QuadratureFormula<1> qf = QuadratureManager::instance().getLineFormula(GaussQuadratureDescriptor(2)); + + double sum = 0; + for (size_t i = 0; i < qf.numberOfPoints(); ++i) { + sum += qf.weight(i) * t.velocityNorm() * p(t(qf.point(i))); + } + + REQUIRE(sum == Catch::Approx(24.8585155630822)); } SECTION("3D") @@ -62,5 +79,21 @@ TEST_CASE("LineTransformation", "[geometry]") REQUIRE(t(1)[2] == Catch::Approx(0.3)); REQUIRE(t.velocityNorm() == Catch::Approx(l2Norm(0.5 * (b - a)))); + + auto p = [](const R3& X) { + const double x = X[0]; + const double y = X[1]; + const double z = X[2]; + return 2 * x * x + 3 * x - 3 * y * y + y + 2 * z * z - 0.5 * z + 2; + }; + + QuadratureFormula<1> qf = QuadratureManager::instance().getLineFormula(GaussQuadratureDescriptor(2)); + + double sum = 0; + for (size_t i = 0; i < qf.numberOfPoints(); ++i) { + sum += qf.weight(i) * t.velocityNorm() * p(t(qf.point(i))); + } + + REQUIRE(sum == Catch::Approx(30.08440406681767)); } } -- GitLab