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

final folder structure, further fixes might follow

parent 0deaa546
Pipeline #118473 passed with stages
in 6 minutes and 57 seconds
......@@ -37,7 +37,7 @@ unit-test-mlmc:
GIT_STRATEGY: none
image: ${REGISTRY}/${IMAGE_NAME_MLMC}
script:
- cd /mpp/build/tests
- cd /mpp/build/
- ctest
dependencies: [ "build-mlmc" ]
tags: [ docker ]
......@@ -49,9 +49,8 @@ mpi-test-mlmc:
GIT_STRATEGY: none
image: ${REGISTRY}/${IMAGE_NAME_MLMC}
script:
- cd /mpp/build/tests/integration
- mpirun -n 4 TestMainProgramElliptic
# - mpirun -n 4 TestMainProgramTransport
- cd /mpp/build/mlmc/tests
- mpirun -n 4 TestMain
dependencies: [ "build-mlmc" ]
tags: [ docker ]
......
......@@ -42,7 +42,6 @@ include(${PROJECT_MPP_DIR}/CMakeListsMpp.inc)
#find_package(FFTW3 REQUIRED) (Can't be found but still seems to link in)
link_directories(${PROJECT_SOURCE_DIR}/sprng5/lib)
# Include directories
include_directories(${PROJECT_SOURCE_DIR}/sprng5/include)
include_directories(${PROJECT_SOURCE_DIR}/mlmc/src)
......@@ -51,8 +50,7 @@ include_directories(${PROJECT_SOURCE_DIR}/mlmc/src)
add_subdirectory(mlmc/src)
# Libraries
set(MLMC_LIBRARIES PDESOLVER MONTECARLO PROBLEMS MLMC sprng fftw3 m ${MPP_LIBRARIES})
set(MLMC_TEST_LIBRARIES PDESOLVER MONTECARLO PROBLEMS MLMC sprng fftw3 m ${MPP_TEST_LIBRARIES})
set(MLMC_LIBRARIES PDESOLVER MONTECARLO PROBLEMS sprng fftw3 m ${MPP_LIBRARIES})
# Executables
add_executable(MLMC-M++ mlmc/src/Main.cpp)
......@@ -62,5 +60,5 @@ target_link_libraries(MLMC-M++ ${MLMC_LIBRARIES})
# Tests
if (BUILD_MLMC_TESTS)
add_subdirectory(tests)
add_subdirectory(mlmc/tests)
endif ()
include_directories(basics)
add_subdirectory(basics)
include_directories(problems)
add_subdirectory(problems)
......@@ -6,8 +9,3 @@ add_subdirectory(pdesolver)
include_directories(montecarlo)
add_subdirectory(montecarlo)
include(main/CMakeLists.txt)
add_library(MLMC STATIC ${main})
target_link_libraries(MLMC PDESOLVER)
#include "m++.hpp"
#include "main/MainProgram.hpp"
#include "Main.hpp"
#ifdef COMPLEX
#error undef COMPLEX in src/Compiler.h
......@@ -10,9 +10,7 @@ int main(int argc, char **argv) {
Config::setConfigFileName("m++.conf");
Mpp::initialize(&argc, argv);
std::unique_ptr<MainProgram> mainProgram = std::make_unique<MainProgram>();
mainProgram->Initialize();
int rc = mainProgram->Run();
return rc;
MainProgram mainProgram;
mainProgram.Initialize();
return mainProgram.Run();
}
#ifndef MLMC_MLMCMAIN_H
#define MLMC_MLMCMAIN_H
#ifndef MAIN_HPP
#define MAIN_HPP
#include "montecarlo/MultilevelMonteCarlo.hpp"
......@@ -12,9 +12,22 @@ private:
std::string problemName;
Meshes *createMeshes(); // Todo remove
Meshes *createMeshes() {
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 == "StochasticInitialConditions2D") // Todo Refactor
return new Meshes("ComparisonSquare.geo", pLevel, maxLevel);
Exit("\nMesh not found in " + problemName + "\n")
}
PDESolver *createPDESolver();
PDESolver *createPDESolver() {
return PDESolverCreator(*meshes).
WithModel(modelName).
WithDegree(degree).
WithProblem(problemName).Create();
}
public:
int pLevel = 0; // Todo remove
......@@ -53,9 +66,30 @@ public:
delete pdeSolver;
}
void Initialize();
void Initialize() {
// Todo: only use for Generators in problems and cell types in disc
// (even here it should be removed)
meshes = createMeshes();
pdeSolver = createPDESolver();
mlmc = new MultilevelMonteCarlo(*meshes, pdeSolver);
mlmc->PrintInfo();
meshes->PrintInfo();
}
int Run() {
mout.StartBlock("MLMC Experiment");
mout << "Run" << endl;
mlmc->Method();
mout.EndBlock();
mout << endl;
mlmc->PrintMCResults();
mlmc->PrintExponentResults();
mlmc->PrintMLMCResults();
return 0;
}
int Run();
};
#endif //MLMC_MLMCMAIN_H
#endif //MAIN_HPP
add_library(BASICS STATIC
Level.cpp
Sample.cpp
PlotMap.cpp
Utilities.cpp
)
target_link_libraries(BASICS)
\ No newline at end of file
#include "Level.hpp"
void Level::Update(int level, int plevel) {
fine = level;
coarse = level - 1;
pLevel = plevel;
mGfine = fine - pLevel;
if (coarse - pLevel > 0)
mGcoarse = coarse - pLevel;
else
mGcoarse = 0;
}
int Level::MGLevel(bool getCoarse) const {
if (getCoarse)
return coarse;
else
return fine;
}
bool Level::operator==(const Level &level) const {
if (this->fine != level.fine)
return false;
if (this->coarse != level.coarse)
return false;
if (this->pLevel != level.pLevel)
return false;
if (this->mGfine != level.mGfine)
return false;
if (this->mGcoarse != level.mGcoarse)
return false;
return true;
}
bool Level::operator==(int level) const {
if (this->fine != level)
return false;
return true;
}
bool Level::operator<=(const Level &level) const {
if (this->fine < level.fine) return true;
else return false;
}
bool Level::operator>=(const Level &level) const {
if (this->fine > level.fine) return true;
else return false;
}
bool Level::operator<(const Level &level) const {
if (this->fine < level.fine) return true;
else return false;
}
bool Level::operator>(const Level &level) const {
if (this->fine > level.fine) return true;
else return false;
}
bool Level::operator<(int level) const {
if (this->fine < level) return true;
else return false;
}
bool Level::operator>(int level) const {
if (this->fine > level) return true;
else return false;
}
bool Level::operator<=(int level) const {
if (this->fine <= level) return true;
else return false;
}
bool Level::operator>=(int level) const {
if (this->fine >= level) return true;
else return false;
}
#ifndef LEVEL_HPP
#define LEVEL_HPP
#include <vector>
#include <map>
struct Level {
int fine;
int coarse;
......@@ -18,85 +22,95 @@ struct Level {
Update(level, pLevel);
}
void Update(int level, int plevel) {
fine = level;
coarse = level - 1;
pLevel = plevel;
mGfine = fine - pLevel;
if (coarse - pLevel > 0)
mGcoarse = coarse - pLevel;
else
mGcoarse = 0;
}
void Update(int level, int plevel);
int MGLevel(bool _coarse_) const {
if (coarse)
return coarse;
else
return fine;
}
int MGLevel(bool getCoarse) const;
// Todo
// Is it really a good idea to check everything
// Might have unknown side effects
bool operator==(const Level &level) const {
if (this->fine != level.fine)
return false;
if (this->coarse != level.coarse)
return false;
if (this->pLevel != level.pLevel)
return false;
if (this->mGfine != level.mGfine)
return false;
if (this->mGcoarse != level.mGcoarse)
return false;
return true;
}
bool operator==(const Level &level) const;
bool operator==(int level) const {
if (this->fine != level)
return false;
return true;
}
bool operator==(int level) const;
bool operator<=(const Level &level) const;
bool operator>=(const Level &level) const;
bool operator<(const Level &level) const;
bool operator>(const Level &level) const;
bool operator<(int level) const;
bool operator>(int level) const;
bool operator<=(int level) const;
bool operator>=(int level) const;
};
bool operator<=(const Level &level) const {
if (this->fine < level.fine) return true;
else return false;
/*
* Todo:
* * make second key template for degree
* to realize MultidegreeMonteCarlo
* * also key (thus Level) should include proc information
*/
template<typename T>
struct LevelMap : public std::map<Level, T> {
LevelMap() {};
LevelMap(std::initializer_list<std::pair<Level, T>> levelMap) {
for (std::pair<Level, T> pair : levelMap) {
this->emplace(pair.first, T(pair.second));
}
}
bool operator>=(const Level &level) const {
if (this->fine > level.fine) return true;
else return false;
std::map<Level, T> SetWithVectors(std::vector<Level> levels,
std::vector<T> entries) {
for (int i = 0; i < levels.size(); i++)
(*this)[levels[i]] = entries[i];
return *this;
}
bool operator<(const Level &level) const {
if (this->fine < level.fine) return true;
else return false;
std::vector<int> GetLevelVector() const {
std::vector<int> levelVector;
for (auto &&[level, entry]: *this)
levelVector.push_back(level.fine);
return levelVector;
}
bool operator>(const Level &level) const {
if (this->fine > level.fine) return true;
else return false;
std::vector<double> GetQVector() const {
std::vector<double> qVector;
for (auto &&[level, entry]: *this)
qVector.push_back(entry.Q);
return qVector;
}
bool operator<(int level) const {
if (this->fine < level) return true;
else return false;
std::vector<double> GetYVector() const {
std::vector<double> yVector;
for (auto &&[level, entry]: *this)
yVector.push_back(entry.Y);
return yVector;
}
bool operator>(int level) const {
if (this->fine > level) return true;
else return false;
std::vector<double> GetCostVector() const {
std::vector<double> costVector;
for (auto &&[level, entry]: *this)
costVector.push_back(entry.Cost);
return costVector;
}
bool operator<=(int level) const {
if (this->fine <= level) return true;
else return false;
std::vector<int> GetMVector() const {
std::vector<int> mVector;
for (auto &&[level, entry]: *this)
mVector.push_back(entry.M);
return mVector;
}
bool operator>=(int level) const {
if (this->fine >= level) return true;
else return false;
std::vector<int> GetdMVector() const {
std::vector<int> dMVector;
for (auto &&[level, entry]: *this)
dMVector.push_back(entry.dM);
return dMVector;
}
};
......
#ifndef LEVELMAP_HPP
#define LEVELMAP_HPP
#include "Level.hpp"
#include <vector>
#include <map>
// Todo: make second key template for degree to realize MultidegreeMonteCarlo
// Todo: also key should include proc information
template<typename T>
struct LevelMap : public std::map<Level, T> {
LevelMap() {};
LevelMap(std::initializer_list<std::pair<Level, T>> levelMap) {
for (std::pair<Level, T> pair : levelMap) {
this->emplace(pair.first, T(pair.second));
}
}
std::map<Level, T> SetWithVectors(std::vector<Level> levels,
std::vector<T> entries) {
for (int i = 0; i < levels.size(); i++)
(*this)[levels[i]] = entries[i];
return *this;
}
std::vector<int> GetLevelVector() const {
std::vector<int> levelVector;
for (auto &&[level, entry]: *this)
levelVector.push_back(level.fine);
return levelVector;
}
std::vector<double> GetQVector() const {
std::vector<double> qVector;
for (auto &&[level, entry]: *this)
qVector.push_back(entry.Q);
return qVector;
}
std::vector<double> GetYVector() const {
std::vector<double> yVector;
for (auto &&[level, entry]: *this)
yVector.push_back(entry.Y);
return yVector;
}
std::vector<double> GetCostVector() const {
std::vector<double> costVector;
for (auto &&[level, entry]: *this)
costVector.push_back(entry.Cost);
return costVector;
}
std::vector<int> GetMVector() const {
std::vector<int> mVector;
for (auto &&[level, entry]: *this)
mVector.push_back(entry.M);
return mVector;
}
std::vector<int> GetdMVector() const {
std::vector<int> dMVector;
for (auto &&[level, entry]: *this)
dMVector.push_back(entry.dM);
return dMVector;
}
};
struct MonteCarloMap;
#endif //LEVELMAP_HPP
#include "PlotMap.hpp"
// Todo bring implementations over here!
\ No newline at end of file
#ifndef PLOTMAP_HPP
#define PLOTMAP_HPP
#include "SampleID.hpp"
#include "Sample.hpp"
#include "Plot.hpp"
#include "dof/LagrangeDoF.hpp"
......
#include "Sample.hpp"
int Sample::MGLevel() const {
return level.MGLevel(coarse);
}
std::string Sample::Str() const {
return "l:" + std::to_string(level.fine) +
"-m:" + std::to_string(number) +
"-c:" + std::to_string((int) coarse);
}
void SampleSolution::Init() {
Q = 0.0;
Cost = 0.0;
U = 0.0;
}
#ifndef SAMPLESOLUTION_HPP
#define SAMPLESOLUTION_HPP
#ifndef SAMPLE_HPP
#define SAMPLE_HPP
#include "Level.hpp"
#include "basics/SampleID.hpp"
#include "matrixgraph/CellMatrixGraph.hpp"
#include "Algebra.hpp"
#include <string>
struct Sample {
Level level;
int number;
bool coarse;
Sample() {}
Sample(Level level, int number, bool coarse) :
level(level), number(number), coarse(coarse) {}
int MGLevel() const;
std::string Str() const;
};
struct SampleSolution {
std::string name = "U";
SampleID id;
Sample id;
double Q;
......@@ -28,17 +48,12 @@ struct SampleSolution {
Init();
}
SampleSolution(MatrixGraphs *solMGraphs, const SampleID &id) :
SampleSolution(MatrixGraphs *solMGraphs, const Sample &id) :
id(id), U(Vector((*solMGraphs)[id.MGLevel()])) {
Init();
}
void Init() {
Q = 0.0;
Cost = 0.0;
U = 0.0;
}
void Init();
};
#endif //SAMPLESOLUTION_HPP
#endif //SAMPLE_HPP
#ifndef SAMPLEID_HPP
#define SAMPLEID_HPP
#include "basics/Level.hpp"
#include <string>
struct SampleID {
Level level;
int number;
bool coarse;
SampleID() {}
SampleID(Level level, int number, bool coarse) :
level(level), number(number), coarse(coarse) {}
int MGLevel() const {
return level.MGLevel(coarse);
}
std::string Str() const {
return "l:" + std::to_string(level.fine) +
"-m:" + std::to_string(number) +
"-c:" + std::to_string((int) coarse);
}
};
#endif //SAMPLEID_HPP
#include "Utils.hpp"
using namespace std;
#include "Utilities.hpp"