From 9461ebd8f3a018ab352de8170ff708671718b1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Tue, 16 Aug 2022 15:24:08 +0200 Subject: [PATCH] test: add new test case for diffusion module Test case defines a 2D grid with closed boundaries and 1 constant cell in the middle. Every other cell is set to 0. After each iteration the sum of all cells must be greater in comparison to the previous state of field. --- test/testDiffusion.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/test/testDiffusion.cpp b/test/testDiffusion.cpp index aebdbfb..9672b8f 100644 --- a/test/testDiffusion.cpp +++ b/test/testDiffusion.cpp @@ -1,7 +1,7 @@ #include -#include #include #include +#include #include using namespace Diffusion; @@ -123,3 +123,43 @@ TEST_CASE( } } } + +TEST_CASE("2D closed boundaries, 1 constant cell in the middle") { + std::vector field(N * M, 0); + double val = 1e-2; + + BTCSDiffusion diffu = setupDiffu(N, M); + BTCSBoundaryCondition bc(N, M); + + field[MID] = val; + bc(BC_INNER, MID) = {BC_TYPE_CONSTANT, val}; + + uint32_t max_iterations = 100; + + double sum = val; + + for (int t = 0; t < max_iterations; t++) { + diffu.simulate(field.data(), alpha.data(), bc); + + CHECK_EQ(field[MID], val); + + double new_sum = .0; + + for (int i = 0; i < M; i++) { + // iterate through columns + for (int j = 0; j < N; j++) { + new_sum += field[i * N + j]; + } + } + + if (sum > new_sum) { + CAPTURE(sum); + CAPTURE(new_sum); + FAIL("Sum of concentrations is equal or lower than to previous iteration " + "after iteration ", + t + 1); + } + + sum = new_sum; + } +}