Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions tests/DirectSolver/directSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <random>
#include <vector>

#include "../test_tools.h"

#include "../../include/GMGPolar/gmgpolar.h"

#include "../../include/Residual/ResidualGive/residualGive.h"
Expand Down Expand Up @@ -44,22 +46,6 @@
#include "../include/InputFunctions/DensityProfileCoefficients/zoniShiftedGyroCoefficients.h"
#include "../include/InputFunctions/SourceTerms/refined_ZoniShiftedGyro_CulhamGeometry.h"

namespace DirectSolverTest
{
Vector<double> generate_random_sample_data(const PolarGrid& grid, unsigned int seed)
{
Vector<double> x("x", grid.numberOfNodes());
std::mt19937 gen(seed);
std::uniform_real_distribution<double> 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: */
Expand Down
18 changes: 2 additions & 16 deletions tests/DirectSolver/directSolverNoMumps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <random>
#include <vector>

#include "../test_tools.h"

#include "../../include/GMGPolar/gmgpolar.h"

#include "../../include/Residual/ResidualGive/residualGive.h"
Expand Down Expand Up @@ -44,22 +46,6 @@
#include "../include/InputFunctions/DensityProfileCoefficients/zoniShiftedGyroCoefficients.h"
#include "../include/InputFunctions/SourceTerms/refined_ZoniShiftedGyro_CulhamGeometry.h"

namespace DirectSolverTestNoMumps
{
Vector<double> generate_random_sample_data(const PolarGrid& grid, unsigned int seed)
{
Vector<double> x("x", grid.numberOfNodes());
std::mt19937 gen(seed);
std::uniform_real_distribution<double> 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? */

Expand Down
18 changes: 2 additions & 16 deletions tests/ExtrapolatedSmoother/extrapolated_smoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <random>
#include <vector>

#include "../test_tools.h"

#include "../../include/GMGPolar/gmgpolar.h"

#include "../../include/Residual/ResidualGive/residualGive.h"
Expand All @@ -26,22 +28,6 @@

#include <random>

namespace ExtrapolatedExtrapolatedSmootherTest
{
Vector<double> generate_random_sample_data(const PolarGrid& grid, unsigned int seed)
{
Vector<double> x("x", grid.numberOfNodes());
std::mt19937 gen(seed);
std::uniform_real_distribution<double> 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? */

Expand Down
21 changes: 3 additions & 18 deletions tests/Interpolation/extrapolated_prolongation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <random>

#include "../test_tools.h"

#include "../../include/GMGPolar/gmgpolar.h"
#include "../../include/Interpolation/interpolation.h"
#include "../../include/InputFunctions/domainGeometry.h"
Expand All @@ -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<double> generate_random_sample_data(const PolarGrid& grid, unsigned int seed)
{
Vector<double> vector("vector", grid.numberOfNodes());
std::mt19937 gen(seed); // Standard mersenne_twister_engine seeded with seed
std::uniform_real_distribution<double> 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<double> fine_radii = {0.1, 0.2, 0.25, 0.5, 0.8, 0.9, 1.3, 1.4, 2.0};
Expand All @@ -42,7 +27,7 @@ TEST(ExtrapolatedProlongationTest, ExtrapolatedProlongationSmoothingRadius)
Interpolation interpolation_operator(maxOpenMPThreads, DirBC_Interior);

unsigned int seed = 42;
Vector<double> x = generate_random_sample_data(coarse_grid, seed);
Vector<double> x = generate_random_sample_data(coarse_grid, seed, 0.0, 1.0);

// Apply prolongation to both functions
Vector<double> result1("result1", finest_grid.numberOfNodes());
Expand Down
16 changes: 3 additions & 13 deletions tests/Interpolation/extrapolated_restriction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <random>

#include "../test_tools.h"

#include "../../include/GMGPolar/gmgpolar.h"
#include "../../include/Interpolation/interpolation.h"
#include "../../include/InputFunctions/domainGeometry.h"
Expand All @@ -12,18 +14,6 @@

namespace ExtrapolatedRestrictionTest
{
// Function to generate sample data for vector x using random values with seed
Vector<double> generate_random_sample_data(const PolarGrid& grid, unsigned int seed)
{
Vector<double> vector("vector", grid.numberOfNodes());
std::mt19937 gen(seed); // Standard mersenne_twister_engine seeded with seed
std::uniform_real_distribution<double> 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. */

Expand Down Expand Up @@ -117,7 +107,7 @@ TEST(ExtrapolatedRestrictionTest, applyExtrapolatedRestriction)
Interpolation interpolation_operator(maxOpenMPThreads, DirBC_Interior);

unsigned int seed = 42;
Vector<double> x = generate_random_sample_data(finest_grid, seed);
Vector<double> x = generate_random_sample_data(finest_grid, seed, 0.0, 1.0);

// Apply prolongation to both functions
Vector<double> result1("result1", coarse_grid.numberOfNodes());
Expand Down
18 changes: 2 additions & 16 deletions tests/Interpolation/prolongation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,12 @@

#include <random>

#include "../test_tools.h"

#include "../../include/GMGPolar/gmgpolar.h"
#include "../../include/Interpolation/interpolation.h"
#include "../../include/InputFunctions/DensityProfileCoefficients/poissonCoefficients.h"

namespace ProlongationTest
{
Vector<double> generate_random_sample_data(const PolarGrid& grid, unsigned int seed)
{
Vector<double> vector("vector", grid.numberOfNodes());
std::mt19937 gen(seed);
std::uniform_real_distribution<double> 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<double> fine_radii = {0.1, 0.2, 0.25, 0.5, 0.8, 0.9, 1.3, 1.4, 2.0};
Expand Down
15 changes: 3 additions & 12 deletions tests/Interpolation/restriction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@

#include <random>

#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<double> generate_random_sample_data(const PolarGrid& grid, unsigned int seed)
{
Vector<double> vector("vector", grid.numberOfNodes());
std::mt19937 gen(seed); // Standard mersenne_twister_engine seeded with seed
std::uniform_real_distribution<double> 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. */
Expand Down Expand Up @@ -118,7 +109,7 @@ TEST(RestrictionTest, applyRestriction)

Interpolation interpolation_operator(maxOpenMPThreads, DirBC_Interior);

Vector<double> x = generate_random_sample_data(finest_grid, 42);
Vector<double> x = generate_random_sample_data(finest_grid, 42, 0.0, 1.0);

// Apply prolongation to both functions
Vector<double> result1("result1", coarse_grid.numberOfNodes());
Expand Down
18 changes: 2 additions & 16 deletions tests/Residual/residual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <vector>
#include <random>

#include "../test_tools.h"

#include "../../include/GMGPolar/gmgpolar.h"

#include "../../include/Residual/ResidualGive/residualGive.h"
Expand All @@ -20,22 +22,6 @@
#include "../include/InputFunctions/DensityProfileCoefficients/zoniShiftedCoefficients.h"
#include "../include/InputFunctions/SourceTerms/polarR6_ZoniShifted_CzarnyGeometry.h"

namespace ResidualTest
{
Vector<double> generate_random_sample_data(const PolarGrid& grid, unsigned int seed)
{
Vector<double> x("x", grid.numberOfNodes());
std::mt19937 gen(seed);
std::uniform_real_distribution<double> 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? */

Expand Down
18 changes: 2 additions & 16 deletions tests/Smoother/smoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <random>
#include <vector>

#include "../test_tools.h"

#include "../../include/GMGPolar/gmgpolar.h"

#include "../../include/Residual/ResidualGive/residualGive.h"
Expand All @@ -24,22 +26,6 @@

#include <random>

namespace SmootherTest
{
Vector<double> generate_random_sample_data(const PolarGrid& grid, unsigned int seed)
{
Vector<double> x("x", grid.numberOfNodes());
std::mt19937 gen(seed);
std::uniform_real_distribution<double> 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? */

Expand Down
17 changes: 17 additions & 0 deletions tests/test_tools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include <random>

#include "../include/PolarGrid/polargrid.h"
#include "../include/LinearAlgebra/vector.h"

inline Vector<double> generate_random_sample_data(const PolarGrid& grid, unsigned int seed, double min_val = -100.0,
double max_val = 100.0)
{
Vector<double> x("x", grid.numberOfNodes());
std::mt19937 gen(seed);
std::uniform_real_distribution<double> dist(min_val, max_val);
for (uint i = 0; i < x.size(); ++i) {
x(i) = dist(gen);
}
return x;
}