Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mpp
MLUQ
Commits
f75949f1
Commit
f75949f1
authored
Jan 27, 2021
by
niklas.baumgarten
Browse files
new test structure preparing communicator split
parent
942aebf5
Changes
2
Hide whitespace changes
Inline
Side-by-side
mlmc/tests/montecarlo/TestMonteCarlo.cpp
View file @
f75949f1
#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
).
...
...
mlmc/tests/montecarlo/TestMonteCarlo.hpp
0 → 100644
View file @
f75949f1
#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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment