diff --git a/tests/DirectSolver/directSolver.cpp b/tests/DirectSolver/directSolver.cpp index 84e8c5a3..06e7e5ff 100644 --- a/tests/DirectSolver/directSolver.cpp +++ b/tests/DirectSolver/directSolver.cpp @@ -3,6 +3,8 @@ #include #include +#include "../test_tools.h" + #include "../../include/GMGPolar/gmgpolar.h" #include "../../include/Residual/ResidualGive/residualGive.h" @@ -44,22 +46,6 @@ #include "../include/InputFunctions/DensityProfileCoefficients/zoniShiftedGyroCoefficients.h" #include "../include/InputFunctions/SourceTerms/refined_ZoniShiftedGyro_CulhamGeometry.h" -namespace DirectSolverTest -{ -Vector generate_random_sample_data(const PolarGrid& grid, unsigned int seed) -{ - Vector x("x", grid.numberOfNodes()); - std::mt19937 gen(seed); - std::uniform_real_distribution dist(-100.0, 100.0); - for (uint i = 0; i < x.size(); ++i) { - x(i) = dist(gen); - } - return x; -} -} // namespace DirectSolverTest - -using namespace DirectSolverTest; - #ifdef GMGPOLAR_USE_MUMPS /* Test 1/2: */ diff --git a/tests/DirectSolver/directSolverNoMumps.cpp b/tests/DirectSolver/directSolverNoMumps.cpp index 49207283..7ae3eec7 100644 --- a/tests/DirectSolver/directSolverNoMumps.cpp +++ b/tests/DirectSolver/directSolverNoMumps.cpp @@ -3,6 +3,8 @@ #include #include +#include "../test_tools.h" + #include "../../include/GMGPolar/gmgpolar.h" #include "../../include/Residual/ResidualGive/residualGive.h" @@ -44,22 +46,6 @@ #include "../include/InputFunctions/DensityProfileCoefficients/zoniShiftedGyroCoefficients.h" #include "../include/InputFunctions/SourceTerms/refined_ZoniShiftedGyro_CulhamGeometry.h" -namespace DirectSolverTestNoMumps -{ -Vector generate_random_sample_data(const PolarGrid& grid, unsigned int seed) -{ - Vector x("x", grid.numberOfNodes()); - std::mt19937 gen(seed); - std::uniform_real_distribution dist(-100.0, 100.0); - for (uint i = 0; i < x.size(); ++i) { - x(i) = dist(gen); - } - return x; -} -} // namespace DirectSolverTestNoMumps - -using namespace DirectSolverTestNoMumps; - /* Test 1/2: */ /* Does the Take and Give Implementation match up? */ diff --git a/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp b/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp index 90729ec6..714403a5 100644 --- a/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp +++ b/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp @@ -3,6 +3,8 @@ #include #include +#include "../test_tools.h" + #include "../../include/GMGPolar/gmgpolar.h" #include "../../include/Residual/ResidualGive/residualGive.h" @@ -26,22 +28,6 @@ #include -namespace ExtrapolatedExtrapolatedSmootherTest -{ -Vector generate_random_sample_data(const PolarGrid& grid, unsigned int seed) -{ - Vector x("x", grid.numberOfNodes()); - std::mt19937 gen(seed); - std::uniform_real_distribution dist(-100.0, 100.0); - for (uint i = 0; i < x.size(); ++i) { - x(i) = dist(gen); - } - return x; -} -} // namespace ExtrapolatedExtrapolatedSmootherTest - -using namespace ExtrapolatedExtrapolatedSmootherTest; - /* Test 1/2: */ /* Does the Take and Give Implementation match up? */ diff --git a/tests/Interpolation/extrapolated_prolongation.cpp b/tests/Interpolation/extrapolated_prolongation.cpp index 0e749047..b5a26db0 100644 --- a/tests/Interpolation/extrapolated_prolongation.cpp +++ b/tests/Interpolation/extrapolated_prolongation.cpp @@ -2,6 +2,8 @@ #include +#include "../test_tools.h" + #include "../../include/GMGPolar/gmgpolar.h" #include "../../include/Interpolation/interpolation.h" #include "../../include/InputFunctions/domainGeometry.h" @@ -10,23 +12,6 @@ #include "../../include/InputFunctions/DomainGeometry/circularGeometry.h" #include "../../include/InputFunctions/DensityProfileCoefficients/poissonCoefficients.h" -namespace ExtrapolatedProlongationTest -{ -// Function to generate sample data for vector x using random values with seed -Vector generate_random_sample_data(const PolarGrid& grid, unsigned int seed) -{ - Vector vector("vector", grid.numberOfNodes()); - std::mt19937 gen(seed); // Standard mersenne_twister_engine seeded with seed - std::uniform_real_distribution dist(0.0, 1.0); // Generate random double between 0 and 1 - for (uint i = 0; i < vector.size(); ++i) { - vector[i] = dist(gen); - } - return vector; -} -} // namespace ExtrapolatedProlongationTest - -using namespace ExtrapolatedProlongationTest; - TEST(ExtrapolatedProlongationTest, ExtrapolatedProlongationSmoothingRadius) { std::vector fine_radii = {0.1, 0.2, 0.25, 0.5, 0.8, 0.9, 1.3, 1.4, 2.0}; @@ -42,7 +27,7 @@ TEST(ExtrapolatedProlongationTest, ExtrapolatedProlongationSmoothingRadius) Interpolation interpolation_operator(maxOpenMPThreads, DirBC_Interior); unsigned int seed = 42; - Vector x = generate_random_sample_data(coarse_grid, seed); + Vector x = generate_random_sample_data(coarse_grid, seed, 0.0, 1.0); // Apply prolongation to both functions Vector result1("result1", finest_grid.numberOfNodes()); diff --git a/tests/Interpolation/extrapolated_restriction.cpp b/tests/Interpolation/extrapolated_restriction.cpp index 6d619a7b..f988fda3 100644 --- a/tests/Interpolation/extrapolated_restriction.cpp +++ b/tests/Interpolation/extrapolated_restriction.cpp @@ -2,6 +2,8 @@ #include +#include "../test_tools.h" + #include "../../include/GMGPolar/gmgpolar.h" #include "../../include/Interpolation/interpolation.h" #include "../../include/InputFunctions/domainGeometry.h" @@ -12,18 +14,6 @@ namespace ExtrapolatedRestrictionTest { -// Function to generate sample data for vector x using random values with seed -Vector generate_random_sample_data(const PolarGrid& grid, unsigned int seed) -{ - Vector vector("vector", grid.numberOfNodes()); - std::mt19937 gen(seed); // Standard mersenne_twister_engine seeded with seed - std::uniform_real_distribution dist(0.0, 1.0); // Generate random double between 0 and 1 - for (uint i = 0; i < vector.size(); ++i) { - vector[i] = dist(gen); - } - return vector; -} - /* In src/Interpolation/restriction.cpp the Restriction Operator is implemented with "Take". */ /* Here we test against the "Give" version. */ @@ -117,7 +107,7 @@ TEST(ExtrapolatedRestrictionTest, applyExtrapolatedRestriction) Interpolation interpolation_operator(maxOpenMPThreads, DirBC_Interior); unsigned int seed = 42; - Vector x = generate_random_sample_data(finest_grid, seed); + Vector x = generate_random_sample_data(finest_grid, seed, 0.0, 1.0); // Apply prolongation to both functions Vector result1("result1", coarse_grid.numberOfNodes()); diff --git a/tests/Interpolation/prolongation.cpp b/tests/Interpolation/prolongation.cpp index 01655b11..3eb46183 100644 --- a/tests/Interpolation/prolongation.cpp +++ b/tests/Interpolation/prolongation.cpp @@ -2,26 +2,12 @@ #include +#include "../test_tools.h" + #include "../../include/GMGPolar/gmgpolar.h" #include "../../include/Interpolation/interpolation.h" #include "../../include/InputFunctions/DensityProfileCoefficients/poissonCoefficients.h" -namespace ProlongationTest -{ -Vector generate_random_sample_data(const PolarGrid& grid, unsigned int seed) -{ - Vector vector("vector", grid.numberOfNodes()); - std::mt19937 gen(seed); - std::uniform_real_distribution dist(-100.0, 100.0); - for (uint i = 0; i < vector.size(); ++i) { - vector[i] = dist(gen); - } - return vector; -} -} // namespace ProlongationTest - -using namespace ProlongationTest; - TEST(ProlongationTest, ProlongationTest) { std::vector fine_radii = {0.1, 0.2, 0.25, 0.5, 0.8, 0.9, 1.3, 1.4, 2.0}; diff --git a/tests/Interpolation/restriction.cpp b/tests/Interpolation/restriction.cpp index 006f8c75..fa7c5e1b 100644 --- a/tests/Interpolation/restriction.cpp +++ b/tests/Interpolation/restriction.cpp @@ -2,23 +2,14 @@ #include +#include "../test_tools.h" + #include "../../include/GMGPolar/gmgpolar.h" #include "../../include/Interpolation/interpolation.h" #include "../../include/InputFunctions/DensityProfileCoefficients/poissonCoefficients.h" namespace RestrictionTest { -// Function to generate sample data for vector x using random values with seed -Vector generate_random_sample_data(const PolarGrid& grid, unsigned int seed) -{ - Vector vector("vector", grid.numberOfNodes()); - std::mt19937 gen(seed); // Standard mersenne_twister_engine seeded with seed - std::uniform_real_distribution dist(0.0, 1.0); // Generate random double between 0 and 1 - for (uint i = 0; i < vector.size(); ++i) { - vector[i] = dist(gen); - } - return vector; -} /* In src/Interpolation/restriction.cpp the Restriction Operator is implemented with "Take". */ /* Here we test against the "Give" version. */ @@ -118,7 +109,7 @@ TEST(RestrictionTest, applyRestriction) Interpolation interpolation_operator(maxOpenMPThreads, DirBC_Interior); - Vector x = generate_random_sample_data(finest_grid, 42); + Vector x = generate_random_sample_data(finest_grid, 42, 0.0, 1.0); // Apply prolongation to both functions Vector result1("result1", coarse_grid.numberOfNodes()); diff --git a/tests/Residual/residual.cpp b/tests/Residual/residual.cpp index 7522f8c3..70ec6449 100644 --- a/tests/Residual/residual.cpp +++ b/tests/Residual/residual.cpp @@ -3,6 +3,8 @@ #include #include +#include "../test_tools.h" + #include "../../include/GMGPolar/gmgpolar.h" #include "../../include/Residual/ResidualGive/residualGive.h" @@ -20,22 +22,6 @@ #include "../include/InputFunctions/DensityProfileCoefficients/zoniShiftedCoefficients.h" #include "../include/InputFunctions/SourceTerms/polarR6_ZoniShifted_CzarnyGeometry.h" -namespace ResidualTest -{ -Vector generate_random_sample_data(const PolarGrid& grid, unsigned int seed) -{ - Vector x("x", grid.numberOfNodes()); - std::mt19937 gen(seed); - std::uniform_real_distribution dist(-100.0, 100.0); - for (uint i = 0; i < x.size(); ++i) { - x(i) = dist(gen); - } - return x; -} -} // namespace ResidualTest - -using namespace ResidualTest; - /* Test 1/1: */ /* Does the Take and Give Implementation match up? */ diff --git a/tests/Smoother/smoother.cpp b/tests/Smoother/smoother.cpp index 40ea3003..8fad3f54 100644 --- a/tests/Smoother/smoother.cpp +++ b/tests/Smoother/smoother.cpp @@ -3,6 +3,8 @@ #include #include +#include "../test_tools.h" + #include "../../include/GMGPolar/gmgpolar.h" #include "../../include/Residual/ResidualGive/residualGive.h" @@ -24,22 +26,6 @@ #include -namespace SmootherTest -{ -Vector generate_random_sample_data(const PolarGrid& grid, unsigned int seed) -{ - Vector x("x", grid.numberOfNodes()); - std::mt19937 gen(seed); - std::uniform_real_distribution dist(-100.0, 100.0); - for (uint i = 0; i < x.size(); ++i) { - x(i) = dist(gen); - } - return x; -} -} // namespace SmootherTest - -using namespace SmootherTest; - /* Test 1/2: */ /* Does the Take and Give Implementation match up? */ diff --git a/tests/test_tools.h b/tests/test_tools.h new file mode 100644 index 00000000..75d7e6bd --- /dev/null +++ b/tests/test_tools.h @@ -0,0 +1,17 @@ +#pragma once +#include + +#include "../include/PolarGrid/polargrid.h" +#include "../include/LinearAlgebra/vector.h" + +inline Vector generate_random_sample_data(const PolarGrid& grid, unsigned int seed, double min_val = -100.0, + double max_val = 100.0) +{ + Vector x("x", grid.numberOfNodes()); + std::mt19937 gen(seed); + std::uniform_real_distribution dist(min_val, max_val); + for (uint i = 0; i < x.size(); ++i) { + x(i) = dist(gen); + } + return x; +}