Commit f75949f1 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

new test structure preparing communicator split

parent 942aebf5
#include "montecarlo/MonteCarlo.hpp"
#include "pdesolver/PDESolverCreator.hpp"
#include "TestMonteCarlo.hpp"
#include "mesh/MeshesCreator.hpp"
MONTECARLO_INTERVAL_TESTS(TestMonteCarloInterval)
#include "TestEnvironment.hpp"
//MONTECARLO_INTERVAL_TESTS(TestMonteCarloIntervalWithSplit)
//
//MONTECARLO_INTERVAL_TESTS(TestMonteCarloIntervalWithDoubleSplit)
//
//MONTECARLO_INTERVAL_TESTS(TestMonteCarloIntervalWithFullSplit)
constexpr double MONTECARLO_TEST_TOLERANCE = 1e-2;
class TestMonteCarlo : public Test {
protected:
int commSplit;
int pLevel = 2;
int level = 3;
int dM = 1e5;
Meshes *meshes;
PDESolver *pdeSolver;
MonteCarlo mc;
TestMonteCarlo(const std::string &meshName, int commSplit = 0) :
meshes(MeshesCreator("Interval").
WithCommSplit(commSplit).
WithDistribute("RCB", 0).
WithoutOverlap(0).
WithPLevel(pLevel).
WithLevel(level).
Create()),
pdeSolver(PDESolverCreator(*meshes).
WithProblem("StochasticDummyScalarGeneratorProblem").
WithQuantity("GeneratorValue").
WithModel("DummyPDESolver").
Create()),
mc(MonteCarlo(Level(level), dM, true, meshes, pdeSolver)) {
mc.Method();
}
void TearDown() {
PPM->Barrier(0);
PPM->ClearCommunicators(false);
if (!meshes) delete meshes;
if (!pdeSolver) delete pdeSolver;
}
};
class TestMonteCarloInterval : public TestMonteCarlo {
protected:
TestMonteCarloInterval(int commSplit = 0) :
TestMonteCarlo("Interval", commSplit) {}
};
TEST_F(TestMonteCarloInterval, TestMethodOnlyFine) {
EXPECT_NEAR(mc.avgs.Q, 0.0, MONTECARLO_TEST_TOLERANCE);
EXPECT_NEAR(mc.avgs.Y, 0.0, MONTECARLO_TEST_TOLERANCE);
EXPECT_NEAR(mc.vars.Q, 1.0, MONTECARLO_TEST_TOLERANCE);
EXPECT_NEAR(mc.vars.Y, 1.0, MONTECARLO_TEST_TOLERANCE);
}
int main(int argc, char **argv) {
return MppTest(
MppTestBuilder(argc, argv).
......
#ifndef TESTMONTECARLO_HPP
#define TESTMONTECARLO_HPP
#include "montecarlo/MonteCarlo.hpp"
#include "pdesolver/PDESolverCreator.hpp"
#include "mesh/MeshesCreator.hpp"
#include "TestEnvironment.hpp"
constexpr double MONTECARLO_TEST_TOLERANCE = 1e-2;
class TestMonteCarlo : public TestWithParam<std::string> {
protected:
int commSplit;
int pLevel = 2;
int level = 3;
int dM = 1e5;
Meshes *meshes;
PDESolver *pdeSolver;
MonteCarlo mc;
TestMonteCarlo(const std::string &meshName, int commSplit = 0) :
meshes(MeshesCreator("Interval").
WithCommSplit(commSplit).
WithDistribute("RCB", 0).
WithoutOverlap(0).
WithPLevel(pLevel).
WithLevel(level).
Create()),
pdeSolver(PDESolverCreator(*meshes, 0, 0).
WithProblem(GetParam()).
WithQuantity("GeneratorValue").
WithModel("DummyPDESolver").
Create()),
mc(MonteCarlo(Level(level), dM, true, meshes, pdeSolver)) {
mc.Method();
}
void TearDown() {
PPM->Barrier(0);
PPM->ClearCommunicators(false);
if (!meshes) delete meshes;
if (!pdeSolver) delete pdeSolver;
}
};
class TestMonteCarloInterval : public TestMonteCarlo {
protected:
TestMonteCarloInterval(int commSplit = 0) :
TestMonteCarlo("Interval", commSplit) {}
};
class TestMonteCarloIntervalWithSplit : public TestMonteCarloInterval {
protected:
TestMonteCarloIntervalWithSplit() :
TestMonteCarloInterval(1) {}
};
class TestMonteCarloIntervalWithDoubleSplit : public TestMonteCarloInterval {
protected:
TestMonteCarloIntervalWithDoubleSplit() :
TestMonteCarloInterval(2) {}
};
class TestMonteCarloIntervalFullSplit : public TestMonteCarloInterval {
protected:
TestMonteCarloIntervalFullSplit() :
TestMonteCarloInterval(-1) {}
};
#define MONTECARLO_INTERVAL_TESTS(MonteCarloIntervalTestClass)\
\
INSTANTIATE_TEST_SUITE_P(TestMeshesCreator, MonteCarloIntervalTestClass, Values(\
"StochasticDummyScalarGeneratorProblem"\
));\
\
TEST_P(MonteCarloIntervalTestClass, TestMethodOnlyFine) {\
EXPECT_NEAR(mc.avgs.Q, 0.0, MONTECARLO_TEST_TOLERANCE);\
EXPECT_NEAR(mc.avgs.Y, 0.0, MONTECARLO_TEST_TOLERANCE);\
EXPECT_NEAR(mc.vars.Q, 1.0, MONTECARLO_TEST_TOLERANCE);\
EXPECT_NEAR(mc.vars.Y, 1.0, MONTECARLO_TEST_TOLERANCE);\
}\
#endif //TESTMONTECARLO_HPP
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment