Commit 8c1946b2 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

updated ref on mpp

parent 5631c6a4
#include "m++.h"
#include "MLMCMain.h"
#include "MainProgram.hpp"
#ifdef COMPLEX
......@@ -11,9 +11,10 @@ int main(int argc, char **argv) {
Config::setConfigFileName("m++.conf");
DPO dpo(&argc, argv);
auto mlmcMain = new MLMCMain();
mlmcMain->Run();
delete mlmcMain;
std::unique_ptr<MainProgram> mainProgram =
std::make_unique<MainProgram>();
mainProgram->Initialize();
mainProgram->Run();
return 0;
}
#include "MLMCMain.h"
#include "MainProgram.hpp"
using namespace std;
void MLMCMain::initialize() {
meshes = getMeshes();
disc = getDiscretization();
stochasticField = getStochasticField();
problem = StochasticProblemFactory::CreateStochasticProblemFrom(problemName);
assemble = getAssemble();
void MainProgram::Initialize() {
meshes = createMeshes();
disc = createDiscretization();
stochField = createStochasticField();
problem = createStochasticProblem();
assemble = createAssemble();
plots = new MultilevelPlotter(*meshes);
mlmc = new MultilevelMonteCarlo(initLevels, initSampleAmount, meshes, *plots,
stochasticField, assemble);
}
Meshes *MLMCMain::getMeshes() {
if (problemName.find("1D") != string::npos)
return new Meshes("Line", pLevel, maxLevel);
if (problemName.find("2D") != string::npos)
return new Meshes("UnitSquare", pLevel, maxLevel);
if (problemName.find("Square500") != string::npos)
return new Meshes("Square500", pLevel, maxLevel);
Exit("\nMesh not found in " + problemName + "\n")
}
Discretization *MLMCMain::getDiscretization() {
if (modelName == "LagrangeFEM") {
if (degree == 1)
return new Discretization("linear", 1, meshes->dim());
if (degree == 2)
return new Discretization("serendipity", 1, meshes->dim());
}
if (modelName == "MixedFEM" || modelName == "HybridFEM")
return new Discretization("RT0_P0", 1, meshes->dim());
if (modelName == "DGFEM")
return new DGDiscretization(new DGDoF(degree));
if (modelName == "EGFEM")
return new EGDiscretization(new EGDoF(degree));
if (modelName == "LinearWC")
return nullptr;
if (modelName == "QuadraticWC")
return nullptr;
if (modelName == "LinearDPG")
return nullptr;
if (modelName == "QuadraticDPG")
return nullptr;
if (modelName == "DGTransport")
return new DGDiscretization(new DGDoF(degree));
Exit("\nDiscretization not found in " + modelName + "\n")
}
StochasticField *MLMCMain::getStochasticField() {
if (problemName.find("Stochastic") != string::npos) {
if (problemName.find("Laplace") != string::npos)
return new StochasticField(*meshes, "CirculantEmbedding");
if (problemName.find("Pollution") != string::npos)
return new StochasticField(*meshes, "HybridFluxGenerator");
}
if (problemName.find("Deterministic") != string::npos) {
if (problemName.find("Laplace") != string::npos)
return new StochasticField(*meshes,
"DeterministicPermeabilityGenerator");
if (problemName.find("Pollution") != string::npos)
return new StochasticField(*meshes,
"DeterministicHybridFluxGenerator");
}
}
Assemble *MLMCMain::getAssemble() {
if (problemName.find("Laplace") != string::npos) {
auto ellipticProblem = dynamic_cast<StochasticEllipticProblem *>(problem);
if (modelName == "LagrangeFEM")
return new EllipticAssemble(disc, ellipticProblem);
if (modelName == "MixedFEM")
return new MixedEllipticAssemble(disc, ellipticProblem);
if (modelName == "HybridFEM")
return new HybridEllipticAssemble(disc, ellipticProblem);
if (modelName == "DGFEM")
return new DGEllipticAssemble(disc, ellipticProblem);
} else if (problemName.find("Pollution") != string::npos) {
auto transportProblem = dynamic_cast<StochasticTransportProblem *>(problem);
Plot plot(meshes->fine(), meshes->dim(), 2);
return new DGTransportAssemble(disc, transportProblem, &plot);
}
Exit("\nAssembling for this problem not implemented yet\n")
stochField, assemble);
}
void MLMCMain::Run() {
this->printInfo();
void MainProgram::Run() {
this->PrintInfo();
mlmc->PrintInfo();
meshes->PrintInfo();
// assemble->PrintInfo();
......@@ -117,7 +44,7 @@ void MLMCMain::Run() {
}
}
void MLMCMain::printInfo() {
void MainProgram::PrintInfo() {
Vout(1) << endl
<< "Main Info:" << endl
<< " Problem: " << problemName << endl
......@@ -130,3 +57,87 @@ void MLMCMain::printInfo() {
Vout(1) << " epsilonList: " << vec2str(epsilonList) << endl;
Vout(1) << endl;
}
unique_ptr<Meshes> MainProgram::createMeshes() {
if (problemName.find("1D") != string::npos)
return make_unique<Meshes>("Line", pLevel, maxLevel);
if (problemName.find("2D") != string::npos)
return make_unique<Meshes>("UnitSquare", pLevel, maxLevel);
Exit("\nMesh not found in " + problemName + "\n")
}
unique_ptr<Discretization> MainProgram::createDiscretization() {
if (modelName == "LagrangeFEM" && degree == 1)
return make_unique<Discretization>("linear", 1, meshes->dim());
if (modelName == "LagrangeFEM" && degree == 2)
return make_unique<Discretization>("serendipity", 1, meshes->dim());
if (modelName == "MixedFEM" || modelName == "HybridFEM")
return make_unique<Discretization>("RT0_P0", 1, meshes->dim());
if (modelName == "DGFEM")
return make_unique<DGDiscretization>(new DGDoF(degree));
if (modelName == "DGTransport")
return make_unique<DGDiscretization>(new DGDoF(degree));
Exit("\nDiscretization not found in " + modelName + "\n")
}
unique_ptr<StochasticField> MainProgram::createStochasticField() {
if (meshes == nullptr) Exit(
"\nMeshes have to be initialized to create stochastic field\n")
if (problemName.find("Stochastic") != string::npos) {
if (problemName.find("Laplace") != string::npos)
return make_unique<StochasticField>(*meshes, "CirculantEmbedding");
if (problemName.find("Pollution") != string::npos)
return make_unique<StochasticField>(*meshes, "HybridFluxGenerator");
}
if (problemName.find("Deterministic") != string::npos) {
if (problemName.find("Laplace") != string::npos)
return make_unique<StochasticField>(
*meshes, "DeterministicPermeabilityGenerator");
if (problemName.find("Pollution") != string::npos)
return make_unique<StochasticField>(
*meshes, "DeterministicHybridFluxGenerator");
}
}
unique_ptr<StochasticProblem> MainProgram::createStochasticProblem() {
if (problemName.find("StochasticLaplace1D") != -1 ||
problemName.find("DeterministicLaplace1D") != -1)
return make_unique<StochasticLaplace1D>();
if (problemName.find("StochasticLaplace2D") != -1 ||
problemName.find("DeterministicLaplace2D") != -1)
return make_unique<StochasticLaplace2D>();
if (problemName.find("StochasticPollution1D") != -1 ||
problemName.find("DeterministicPollution1D") != -1)
return make_unique<StochasticPollution1D>();
if (problemName.find("StochasticPollutionCosHat1D") != -1 ||
problemName.find("DeterministicPollutionCosHat1D") != -1)
return make_unique<StochasticPollutionCosHat1D>();
if (problemName.find("StochasticPollution2D") != -1 ||
problemName.find("DeterministicPollution2D") != -1)
return make_unique<StochasticPollution2D>();
if (problemName.find("StochasticPollutionCosHat2D") != -1 ||
problemName.find("DeterministicPollutionCosHat2D") != -1)
return make_unique<StochasticPollutionCosHat2D>();
if (problemName.find("StochasticPollutionMollifiedBar2D") != -1 ||
problemName.find("DeterministicPollutionMollifiedBar2D") != -1)
return make_unique<StochasticPollutionMollifiedBar2D>();
}
unique_ptr<Assemble> MainProgram::createAssemble() {
if (problemName.find("Laplace") != string::npos) {
auto ellipticProblem = dynamic_cast<StochasticEllipticProblem *>(problem.get());
if (modelName == "LagrangeFEM")
return make_unique<EllipticAssemble>(disc, ellipticProblem);
if (modelName == "MixedFEM")
return new MixedEllipticAssemble(disc, ellipticProblem);
if (modelName == "HybridFEM")
return new HybridEllipticAssemble(disc, ellipticProblem);
if (modelName == "DGFEM")
return new DGEllipticAssemble(disc, ellipticProblem);
} else if (problemName.find("Pollution") != string::npos) {
auto transportProblem = dynamic_cast<StochasticTransportProblem *>(problem);
Plot plot(meshes->fine(), meshes->dim(), 2);
return new DGTransportAssemble(disc, transportProblem, &plot);
}
Exit("\nAssembling for this problem not implemented yet\n")
}
......@@ -2,7 +2,7 @@
#define MLMC_MLMCMAIN_H
#include "assemble/AssembleHeader.h"
#include "problem/StochasticProblemFactory.hpp"
#include "problem/StochasticEllipticProblem.hpp"
#include "MultilevelMonteCarlo.h"
#include "discretization/DGDiscretization.h"
#include "stochastics/StochasticField.h"
......@@ -10,7 +10,7 @@
#include "utils/MatrixGraphContainer.hpp"
class MLMCMain {
class MainProgram {
public:
int verbose = 0;
......@@ -26,18 +26,17 @@ public:
vector<int> initSampleAmount = {12, 6, 3};
vector<double> epsilonList = {0.1, 0.05, 0.01};
Meshes *meshes = nullptr;
MultilevelPlotter *plots = nullptr;
Discretization *disc = nullptr;
unique_ptr<Meshes> meshes = nullptr;
unique_ptr<Discretization> disc = nullptr;
unique_ptr<StochasticField> stochField = nullptr;
unique_ptr<StochasticProblem> problem = nullptr;
unique_ptr<Assemble> assemble = nullptr;
StochasticField *stochasticField = nullptr;
StochasticProblem *problem = nullptr;
Assemble *assemble = nullptr;
MultilevelPlotter *plots = nullptr;
MultilevelMonteCarlo *mlmc = nullptr;
MLMCMain() {
MainProgram() {
config.get("MainVerbose", verbose);
config.get("epsilon", epsilon);
config.get("plevel", pLevel);
config.get("maxLevel", maxLevel);
......@@ -63,14 +62,9 @@ public:
for (auto &level: initLevels)
initSampleAmount.push_back(uniformSampleAmount);
}
initialize();
}
~MLMCMain() {
delete meshes;
delete disc;
delete stochasticField;
~MainProgram() {
delete problem;
delete assemble;
delete mlmc;
......@@ -78,20 +72,21 @@ public:
void Run();
private:
void initialize();
void Initialize();
void PrintInfo();
Meshes *getMeshes();
private:
Discretization *getDiscretization();
unique_ptr<Meshes> createMeshes();
StochasticField *getStochasticField();
unique_ptr<Discretization> createDiscretization();
StochasticProblem *getStochasticProblem();
unique_ptr<StochasticField> createStochasticField();
Assemble *getAssemble();
unique_ptr<StochasticProblem> createStochasticProblem();
void printInfo();
unique_ptr<Assemble> createAssemble();
static void headConvergenceTest() {
mout << endl << "**********************************************************"
......
#include "MatrixGraphContainer.hpp"
#ifndef MATRIXGRAPHCONTAINER_HPP
#define MATRIXGRAPHCONTAINER_HPP
#include "m++.h"
//class MatrixGraphContainer {
//private:
// Meshes &meshes;
//
// map<string, MatrixGraphs> mapMatrixGraph;
//public:
// MatrixGraphContainer(const string &problemName, Meshes &meshes) :
// meshes(meshes) {
// if (problemName.find("Laplace") != string::npos) {
// mapMatrixGraph["cell1"] = MatrixGraphs(meshes, dof("cell", 1));
// mapMatrixGraph["cell3"] = MatrixGraphs(meshes, dof("cell", 3));
// }
// }
//};
#endif //MATRIXGRAPHCONTAINER_HPP
# Test Executables
#add_executable(TestCirculantEmbedding mlmc/tests/TestCirculantEmbedding.C)
#add_executable(TestRNManager mlmc/tests/TestRNManager.C)
# Linking
#target_link_libraries(TestCirculantEmbedding MLMC sprng SRC LIB_PS ${SUPERLU}
# blas lapack fftw3 m ${GTEST_LIB})
#target_link_libraries(TestRNManager MLMC sprng fftw3 m ${GTEST_LIB})
\ No newline at end of file
Subproject commit d8e8e0c6efe46224dfc4ba7b204d58a1b798af9f
Subproject commit a729454428f0f673cba4a05a020e0d2e7fcf2cdf
# Includes for mlmc tests
#---------------------------------------------------------------------------------------#
set(PROJECT_TEST_DIR ${PROJECT_SOURCE_DIR}/tests)
set(PROJECT_TEST_BINARY_DIR ${PROJECT_BINARY_DIR}/tests)
# Manage folder structure build folder
file(MAKE_DIRECTORY ${PROJECT_TEST_BINARY_DIR}/data/vtk)
file(MAKE_DIRECTORY ${PROJECT_TEST_BINARY_DIR}/data/gp)
file(MAKE_DIRECTORY ${PROJECT_TEST_BINARY_DIR}/data/py)
file(MAKE_DIRECTORY ${PROJECT_TEST_BINARY_DIR}/log)
file(MAKE_DIRECTORY ${PROJECT_TEST_BINARY_DIR}/data/dual)
#---------------------------------------------------------------------------------------#
# Test Executables
add_executable(TestMainProgram ${PROJECT_TEST_DIR}/TestMainProgram.cpp)
# Linking
target_link_libraries(TestMainProgram MLMC sprng SRC LIB_PS fftw3 m ${SUPERLU}
${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GTEST_LIB})
#---------------------------------------------------------------------------------------#
#include "gtest/gtest.h"
#include "MainProgram.hpp"
#include "m++.h"
using namespace ::testing;
TEST(MainProgram, TestConstructor) {
std::unique_ptr<MainProgram> mainProgram = std::make_unique<MainProgram>();
ASSERT_EQ(mainProgram->problemName, "");
ASSERT_EQ(mainProgram->modelName, "");
ASSERT_EQ(mainProgram->fieldName, "");
ASSERT_EQ(mainProgram->verbose, 0);
ASSERT_EQ(mainProgram->epsilon, 0.1);
}
TEST(MainProgram, TestCreateMeshes) {
}
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());
}
return RUN_ALL_TESTS();
}
\ No newline at end of file
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