Commit 975a3f70 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

worked on benchmark and mainprog tests

parent aa9d365f
# ----- Problem Settings -----
Experiment = MLMCExperiment
#Experiment = ConvergenceTest
......@@ -12,13 +13,13 @@ Model = LagrangeFEM
degree = 1
plevel = 2
functional = L2
Functional = L2
#functional = Energy
#funcitonal = H1
#functional = Outflow
#functional = Goal
# Multilevel Monte Carlo
# ----- Multilevel Monte Carlo -----
maxLevel = 9
epsilon = 0.01
mcOnly = false
......@@ -26,7 +27,7 @@ initLevels = 3, 4, 5
initSampleAmount = 12, 6, 3
uniformSampleAmount = 500
# Stochastic Field
# ----- Stochastic Field -----
StochasticField = LogNormal
mean = 1.0
sigma = 1.0
......@@ -36,19 +37,19 @@ lambda2 = 0.15
smoothing = 1.8
evtol = 1e-10
# Solver
# ----- Solver -----
LinearReduction = 1e-12
LinearEpsilon = 1e-10
LinearSteps = 3000
NewtonSteps = 1
NewtonLineSearchSteps = 0
# Plotting
# ----- Plotting -----
GeneratorPlotting = 1
MCPlotting = 1
A
# Verbose
# ----- Verbose -----
MCVerbose = 1
PDEVerbose = 1
MainVerbose = 1
......@@ -58,7 +59,7 @@ LinearVerbose = -1
NewtonVerbose = -1
GeneratorVerbose = -1
# Logging
# ----- Logging -----
TimeLevel = -1
MuteLevel = -1
DebugLevel = -1
\ No newline at end of file
#include "TestEnvironment.hpp"
#include "ConfigMapCreator.hpp"
#include "MainProgram.hpp"
class TestEllipticResults : public TestWithParam<ConfigMapForTest> {
protected:
std::unique_ptr<MainProgram> mainProgram;
void SetUp() override {
ConfigMapForTest configMapForTest;
std::map<std::string, std::string> finalMap = configMapForTest.defaultConfigMap;
std::map<std::string, std::string> additionalMap = GetParam().additionalConfigMap;
for (auto &pair: additionalMap)
finalMap[pair.first] = pair.second;
config = Config(finalMap);
// Refactor
logging = new Logging;
logging->initialize();
mainProgram = std::make_unique<MainProgram>();
mainProgram->Initialize();
}
};
INSTANTIATE_TEST_CASE_P(TestEllipticResults, TestEllipticResults, Values(
ConfigMapForTest{std::map<std::string, std::string>{
{"Experiment", "ConvergenceTest"},
{"initLevels", "[3, 4, 5, 6, 7, 8, 9]"},
{"maxLevel", "9"},
{"uniformSampleAmount", "20"},
{"Problem", "StochasticLaplace2D"}}},
ConfigMapForTest{std::map<std::string, std::string>{
{"Experiment", "ConvergenceTest"},
{"initLevels", "[3, 4, 5, 6, 7, 8, 9]"},
{"maxLevel", "9"},
{"uniformSampleAmount", "20"},
{"Problem", "StochasticLaplace2D"},
{"sigma", "1.5"}}},
ConfigMapForTest{std::map<std::string, std::string>{
{"Experiment", "ConvergenceTest"},
{"initLevels", "[3, 4, 5, 6, 7, 8, 9]"},
{"maxLevel", "9"},
{"uniformSampleAmount", "20"},
{"Problem", "StochasticLaplace2D"},
{"sigma", "2.0"}}},
ConfigMapForTest{std::map<std::string, std::string>{
{"Experiment", "ConvergenceTest"},
{"initLevels", "[3, 4, 5, 6, 7, 8, 9]"},
{"maxLevel", "9"},
{"uniformSampleAmount", "20"},
{"Problem", "StochasticLaplace2D"},
{"lambda", "0.05"}}},
ConfigMapForTest{std::map<std::string, std::string>{
{"Experiment", "ConvergenceTest"},
{"initLevels", "[3, 4, 5, 6, 7, 8, 9]"},
{"maxLevel", "9"},
{"uniformSampleAmount", "20"},
{"Problem", "StochasticLaplace2D"},
{"lambda", "0.15"}}},
ConfigMapForTest{std::map<std::string, std::string>{
{"Experiment", "ConvergenceTest"},
{"initLevels", "[3, 4, 5, 6, 7, 8, 9]"},
{"maxLevel", "9"},
{"uniformSampleAmount", "20"},
{"Problem", "StochasticLaplace2D"},
{"smoothing", "1.4"}}},
ConfigMapForTest{std::map<std::string, std::string>{
{"Experiment", "ConvergenceTest"},
{"initLevels", "[3, 4, 5, 6, 7, 8, 9]"},
{"maxLevel", "9"},
{"uniformSampleAmount", "20"},
{"Problem", "StochasticLaplace2D"},
{"smoothing", "1.8"}}}
));
TEST_P(TestEllipticResults, TestOldResults) {
ASSERT_EQ(mainProgram->Run(), 0);
ASSERT_TRUE(mainProgram->mlmc->totalErr < mainProgram->epsilon);
}
int main(int argc, char **argv) {
return MAIN_TEST_WITH_PPM(argc, argv, "../../mlmc/");
}
\ No newline at end of file
......@@ -3,11 +3,15 @@
# Test Executables
add_executable(TestMainProgram TestMainProgram.cpp)
add_executable(BenchmarkOldResults BenchmarkOldResults.cpp)
#add_executable(TestMultilevelPlotter TestMultilevelPlotter.cpp)
# Linking
target_link_libraries(TestMainProgram MLMC sprng SRC LIB_PS fftw3 m ${SUPERLU}
set(libs MLMC sprng SRC LIB_PS fftw3 m ${SUPERLU}
${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GTEST_LIB})
# Linking
target_link_libraries(TestMainProgram ${libs})
target_link_libraries(BenchmarkOldResults ${libs})
#target_link_libraries(TestMultilevelPlotter MLMC SRC ${SUPERLU}
# ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GTEST_LIB})
#---------------------------------------------------------------------------------------#
......@@ -5,81 +5,27 @@
#include <string>
class MainProgramConfig {
public:
std::vector<std::map<std::string, std::string>> vec = {};
std::map<std::string, std::string> programConfigMap = {};
struct ConfigMapForTest {
std::map<std::string, std::string> additionalConfigMap;
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 = {
const std::map<std::string, std::string> defaultConfigMap = {
// ----- Problem Settings -----
{"Experiment", "MLMCExperiment"},
{"Problem", "StochasticLaplace2D"},
{"Problem", "StochasticLaplace1D"},
{"Model", "LagrangeFEM"},
{"Functional", "L2"},
{"degree", "1"},
{"plevel", "2"},
};
std::map<std::string, std::string> mlmcMap = {
// ----- Multilevel Monte Carlo -----
{"maxLevel", "7"},
{"epsilon", "0.01"},
{"mcOnly", "false"},
{"uniformSampleAmount", "500"},
{"maxLevel", "9"},
{"uniformSampleAmount", "100"},
{"initLevels", "[3, 4, 5]"},
{"initSampleAmount", "[12, 6, 3]"},
};
std::map<std::string, std::string> stochFieldMap = {
// ----- Stochastic Field -----
{"StochasticField", "LogNormal"},
{"mean", "1.0"},
{"sigma", "1.0"},
......@@ -87,24 +33,21 @@ public:
{"lambda1", "0.15"},
{"lambda2", "0.15"},
{"smoothing", "1.8"},
{"evtol", "1e-10"}
};
{"evtol", "1e-10"},
std::map<std::string, std::string> solverMap = {
// ----- Solver -----
{"LinearReduction", "1e-12"},
{"LinearEpsilon", "1e-10"},
{"LinearSteps", "3000"},
{"NewtonSteps", "1"},
{"NewtonLineSearchSteps", "0"},
};
std::map<std::string, std::string> plottingMap = {
// ----- Plotting -----
{"GeneratorPlotting", "-1"},
{"MCPlotting", "-1"},
};
std::map<std::string, std::string> verboseMap = {
{"MCVerbose", "0"},
// ----- Verbose ----- // Todo einfach größer null
{"MCVerbose", "1"},
{"PDEVerbose", "0"},
{"MLMCVerbose", "1"},
{"MainVerbose", "1"},
......@@ -113,10 +56,9 @@ public:
{"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"},
// ----- Logging -----
{"TimeLevel", "-1"}, // Todo einfach größer null
{"MuteLevel", "-1"},
{"DebugLevel", "-1"},
};
......
#include "gtest/gtest.h"
#include "m++.h"
#include "EllipticMain.h"
using namespace ::testing;
class TestEllipticProblems1D : public Test {
protected:
map<string, string> configMap = {
{"Model", "LagrangeFEM"},
{"degree", "1"},
{"Problem", "StochasticLaplace2D"}
{"plevel", "2"},
{"LinearSolver", "GMRES"},
{"Preconditioner", "SuperLU"},
{"Transfer", "MatrixTransfer"},
{"presmoothing", "5"},
{"postsmoothing", "5"},
{"SmootherDamp", "0.8"},
{"Smoother", "SGS"},
{"BasePreconditioner", "LIB_PS"},
{"BaseSolver", "LS"},
{"BaseSolverVerbose", "-1"},
{"LinearReduction", "1e-20"},
{"LinearEpsilon", "1e-10"},
{"LinearSteps", "800"},
{"LinearVerbose", "-1"},
{"NewtonVerbose", "-1"},
{"NewtonEpsilon", "1e-9"},
{"NewtonSteps", "1"},
{"NewtonLineSearchSteps", "0"},
{"DebugLevel", "-1"},
{"TimeLevel", "-1"},
{"MuteLevel", "-999"},
{"vtkplot", "1"}};
virtual void SetUo() {
}
};
TEST_F(TestEllipticProblems1D, LinearFEM) {
vector<string> problems = {"P0Test1D", "P1Test1D", "P2Test1D",
"P3Test1D", "P4Test1D"};
vector<string> levels = {"2", "3", "4", "5", "6"};
vector<string> degrees = {"0", "1", "2", "3", "4", "5", "6"};
configMap["Mesh"] = "LineDirichlet";
configMap["Model"] = "LagrangeFEM";
configMap["degree"] = "1";
for(auto &level: levels) {
configMap["level"] = level;
for(auto &problem : problems) {
configMap["Problem"] = problem;
config = Config(configMap);
std::unique_ptr<EllipticMain> ellipticMain = std::make_unique<EllipticMain>();
ellipticMain->run();
}
}
}
int main(int argc, char **argv) {
InitGoogleTest(&argc, argv);
Config::setSearchPath("../tutorial/tests/");
Config::setConfigFileName("m++.conf");
DPO dpo(&argc, argv);
TestEventListeners &listeners = UnitTest::GetInstance()->listeners();
if (!PPM->master()) {
delete listeners.Release(listeners.default_result_printer());
}
return RUN_ALL_TESTS();
}
\ No newline at end of file
#include "TestEnvironment.hpp"
#include "TestMainProgram.hpp"
#include "ConfigMapCreator.hpp"
#include "MainProgram.hpp"
struct KeyValuePair {
string key;
string value;
};
class TestMainProgram : public TestWithParam<KeyValuePair> {
class TestMainProgram : public TestWithParam<ConfigMapForTest> {
protected:
MainProgramConfig mainProgramConfig;
std::unique_ptr<MainProgram> mainProgram;
void SetUp() override {
mainProgramConfig.buildMapVector();
mainProgramConfig.buildConfigMap();
mainProgramConfig.programConfigMap[GetParam().key] = GetParam().value;
ConfigMapForTest configMapForTest;
std::map<std::string, std::string> finalMap = configMapForTest.defaultConfigMap;
std::map<std::string, std::string> additionalMap = GetParam().additionalConfigMap;
config = Config(mainProgramConfig.programConfigMap);
for (auto &pair: additionalMap)
finalMap[pair.first] = pair.second;
config = Config(finalMap);
// Refactor
logging = new Logging;
......@@ -30,8 +27,10 @@ protected:
};
INSTANTIATE_TEST_CASE_P(TestMainProgram, TestMainProgram, Values(
KeyValuePair{"Problem", "StochasticLaplace1D"},
KeyValuePair{"Problem", "StochasticLaplace2D"}
ConfigMapForTest{std::map<std::string, std::string>{}},
ConfigMapForTest{std::map<std::string, std::string>{
{"Problem", "StochasticLaplace2D"}}}
));
TEST_P(TestMainProgram, TestInitialize) {
......
Markdown is supported
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