Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mpp
MLUQ
Commits
e7c056cd
Commit
e7c056cd
authored
Apr 21, 2020
by
niklas.baumgarten
Browse files
test for main program
parent
4407388e
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/TestMainProgram.cpp
View file @
e7c056cd
#include
"gtest/gtest.h"
#include
"TestEnvironment.hpp"
#include
"TestMainProgram.hpp"
#include
"MainProgram.hpp"
#include
"m++.h"
using
namespace
::
testing
;
struct
KeyValuePair
{
string
key
;
string
value
;
};
class
TestMainProgram
:
public
::
Test
{
class
TestMainProgram
:
public
Test
WithParam
<
KeyValuePair
>
{
protected:
map
<
string
,
string
>
configMapMLMCExperiment
=
{
{
"MainVerbose"
,
"0"
},
{
"Problem"
,
"StochasticLaplace1D"
},
{
"Model"
,
"LagrangeFEM"
},
{
"Experiment"
,
"MLMCExperiment"
},
{
"epsilon"
,
"0.1"
},
{
"plevel"
,
"0"
},
{
"maxLevel"
,
"8"
},
{
"degree"
,
"1"
},
{
"initLevels"
,
"[3, 4, 5]"
},
{
"initSampleAmount"
,
"[12, 6, 3]"
}
};
MainProgramConfig
mainProgramConfig
;
std
::
unique_ptr
<
MainProgram
>
mainProgram
;
void
SetUp
()
override
{
config
=
Config
(
configMapMLMCExperiment
);
mainProgramConfig
.
buildMapVector
();
mainProgramConfig
.
buildConfigMap
();
mainProgramConfig
.
programConfigMap
[
GetParam
().
key
]
=
GetParam
().
value
;
config
=
Config
(
mainProgramConfig
.
programConfigMap
);
// Refactor
logging
=
new
Logging
;
logging
->
initialize
();
mainProgram
=
std
::
make_unique
<
MainProgram
>
();
mainProgram
->
Initialize
();
}
};
TEST_F
(
TestMainProgram
,
TestRunMLMCExperiment
)
{
mainProgram
->
Run
();
INSTANTIATE_TEST_CASE_P
(
TestMainProgram
,
TestMainProgram
,
Values
(
KeyValuePair
{
"Problem"
,
"StochasticLaplace1D"
},
KeyValuePair
{
"Problem"
,
"StochasticLaplace2D"
}
));
TEST_P
(
TestMainProgram
,
TestInitialize
)
{
ASSERT_NE
(
mainProgram
->
meshes
,
nullptr
);
ASSERT_NE
(
mainProgram
->
disc
,
nullptr
);
ASSERT_NE
(
mainProgram
->
stochField
,
nullptr
);
ASSERT_NE
(
mainProgram
->
problem
,
nullptr
);
ASSERT_NE
(
mainProgram
->
assemble
,
nullptr
);
ASSERT_NE
(
mainProgram
->
mlmc
,
nullptr
);
}
int
main
(
int
argc
,
char
**
argv
)
{
InitGoogleTest
(
&
argc
,
argv
);
Config
::
setSearchPath
(
"../../tests/"
);
Config
::
setConfigFileName
(
"m++.conf"
);
DPO
dpo
(
&
argc
,
argv
);
TestEventListeners
&
listeners
=
UnitTest
::
GetInstance
()
->
listeners
();
if
(
!
PPM
->
master
())
{
delete
listeners
.
Release
(
listeners
.
default_result_printer
());
}
TEST_P
(
TestMainProgram
,
TestRunMLMCExperiment
)
{
ASSERT_EQ
(
mainProgram
->
Run
(),
0
);
ASSERT_TRUE
(
mainProgram
->
mlmc
->
totalErr
<
mainProgram
->
epsilon
);
}
return
RUN_ALL_TESTS
();
int
main
(
int
argc
,
char
**
argv
)
{
return
MAIN_TEST_WITH_PPM
(
argc
,
argv
,
"../../mlmc/"
);
}
\ No newline at end of file
tests/TestMainProgram.hpp
View file @
e7c056cd
//
// Created by niklas on 26.03.20.
//
#ifndef TESTMAINPROGRAM_HPP
#define TESTMAINPROGRAM_HPP
#include
<map>
#include
<string>
class
MainProgramConfig
{
public:
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>
vec
=
{};
std
::
map
<
std
::
string
,
std
::
string
>
programConfigMap
=
{};
void
buildConfigMap
()
{
for
(
auto
&
configMap
:
vec
)
{
programConfigMap
.
insert
(
configMap
.
begin
(),
configMap
.
end
());
}
}
void
buildMapVector
(
const
std
::
map
<
std
::
string
,
std
::
string
>
&
_problemMap_
=
{},
const
std
::
map
<
std
::
string
,
std
::
string
>
&
_mlmcMap_
=
{},
const
std
::
map
<
std
::
string
,
std
::
string
>
&
_stochFieldMap_
=
{},
const
std
::
map
<
std
::
string
,
std
::
string
>
&
_solverMap_
=
{},
const
std
::
map
<
std
::
string
,
std
::
string
>
&
_plottingMap_
=
{},
const
std
::
map
<
std
::
string
,
std
::
string
>
&
_verboseMap_
=
{},
const
std
::
map
<
std
::
string
,
std
::
string
>
&
_loggingMap_
=
{})
{
if
(
_problemMap_
.
empty
())
vec
.
push_back
(
problemMap
);
else
vec
.
push_back
(
_problemMap_
);
if
(
_mlmcMap_
.
empty
())
vec
.
push_back
(
mlmcMap
);
else
vec
.
push_back
(
_mlmcMap_
);
if
(
_stochFieldMap_
.
empty
())
vec
.
push_back
(
stochFieldMap
);
else
vec
.
push_back
(
_stochFieldMap_
);
if
(
_solverMap_
.
empty
())
vec
.
push_back
(
solverMap
);
else
vec
.
push_back
(
_solverMap_
);
if
(
_plottingMap_
.
empty
())
vec
.
push_back
(
plottingMap
);
else
vec
.
push_back
(
_plottingMap_
);
if
(
_verboseMap_
.
empty
())
vec
.
push_back
(
verboseMap
);
else
vec
.
push_back
(
_verboseMap_
);
if
(
_loggingMap_
.
empty
())
vec
.
push_back
(
loggingMap
);
else
vec
.
push_back
(
_loggingMap_
);
}
std
::
map
<
std
::
string
,
std
::
string
>
problemMap
=
{
{
"Experiment"
,
"MLMCExperiment"
},
{
"Problem"
,
"StochasticLaplace2D"
},
{
"Model"
,
"LagrangeFEM"
},
{
"Functional"
,
"L2"
},
{
"degree"
,
"1"
},
{
"plevel"
,
"2"
},
};
std
::
map
<
std
::
string
,
std
::
string
>
mlmcMap
=
{
{
"maxLevel"
,
"7"
},
{
"epsilon"
,
"0.01"
},
{
"mcOnly"
,
"false"
},
{
"uniformSampleAmount"
,
"500"
},
{
"maxLevel"
,
"9"
},
{
"initLevels"
,
"[3, 4, 5]"
},
{
"initSampleAmount"
,
"[12, 6, 3]"
},
};
std
::
map
<
std
::
string
,
std
::
string
>
stochFieldMap
=
{
{
"StochasticField"
,
"LogNormal"
},
{
"mean"
,
"1.0"
},
{
"sigma"
,
"1.0"
},
{
"norm_p"
,
"2"
},
{
"lambda1"
,
"0.15"
},
{
"lambda2"
,
"0.15"
},
{
"smoothing"
,
"1.8"
},
{
"evtol"
,
"1e-10"
}
};
std
::
map
<
std
::
string
,
std
::
string
>
solverMap
=
{
{
"LinearReduction"
,
"1e-12"
},
{
"LinearEpsilon"
,
"1e-10"
},
{
"LinearSteps"
,
"3000"
},
{
"NewtonSteps"
,
"1"
},
{
"NewtonLineSearchSteps"
,
"0"
},
};
std
::
map
<
std
::
string
,
std
::
string
>
plottingMap
=
{
{
"GeneratorPlotting"
,
"-1"
},
{
"MCPlotting"
,
"-1"
},
};
std
::
map
<
std
::
string
,
std
::
string
>
verboseMap
=
{
{
"MCVerbose"
,
"0"
},
{
"PDEVerbose"
,
"0"
},
{
"MLMCVerbose"
,
"1"
},
{
"MainVerbose"
,
"1"
},
{
"MeshVerbose"
,
"0"
},
{
"ConfigVerbose"
,
"0"
},
{
"LinearVerbose"
,
"-1"
},
// Todo 0 should be mute
{
"NewtonVerbose"
,
"-1"
},
// Todo 0 should be mute
{
"GeneratorVerbose"
,
"0"
},
};
std
::
map
<
std
::
string
,
std
::
string
>
loggingMap
=
{
{
"TimeLevel"
,
"-1"
},
{
"MuteLevel"
,
"-1"
},
{
"DebugLevel"
,
"-1"
},
};
};
#endif //TESTMAINPROGRAM_HPP
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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