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

test for main program

parent 4407388e
#include "gtest/gtest.h" #include "TestEnvironment.hpp"
#include "TestMainProgram.hpp"
#include "MainProgram.hpp" #include "MainProgram.hpp"
#include "m++.h"
using namespace ::testing; struct KeyValuePair {
string key;
string value;
};
class TestMainProgram : public ::Test { class TestMainProgram : public TestWithParam<KeyValuePair> {
protected: protected:
map<string, string> configMapMLMCExperiment = { MainProgramConfig mainProgramConfig;
{"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]"}
};
std::unique_ptr<MainProgram> mainProgram; std::unique_ptr<MainProgram> mainProgram;
void SetUp() override { 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 = std::make_unique<MainProgram>();
mainProgram->Initialize(); mainProgram->Initialize();
} }
}; };
TEST_F(TestMainProgram, TestRunMLMCExperiment) { INSTANTIATE_TEST_CASE_P(TestMainProgram, TestMainProgram, Values(
mainProgram->Run(); 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) { TEST_P(TestMainProgram, TestRunMLMCExperiment) {
InitGoogleTest(&argc, argv); ASSERT_EQ(mainProgram->Run(), 0);
ASSERT_TRUE(mainProgram->mlmc->totalErr < mainProgram->epsilon);
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());
}
return RUN_ALL_TESTS(); int main(int argc, char **argv) {
return MAIN_TEST_WITH_PPM(argc, argv, "../../mlmc/");
} }
\ No newline at end of file
//
// Created by niklas on 26.03.20.
//
#ifndef TESTMAINPROGRAM_HPP #ifndef TESTMAINPROGRAM_HPP
#define 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 #endif //TESTMAINPROGRAM_HPP
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