Commit 276f1648 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

refactored logging and plotting

parent f605b1f1
......@@ -3,7 +3,8 @@ set(MLMC_SRC
Utils.C
MLMCMain.C
MultilevelMonteCarlo.C
MonteCarloLogger.C
utils/IndentedLogger.cpp
mc/MonteCarlo.cpp
mc/MonteCarloElliptic.C
mc/MonteCarloTransport.C
assemble/EllipticAssemble.C
......@@ -12,6 +13,6 @@ set(MLMC_SRC
assemble/DGEllipticAssemble.C
stochastics/RNManager.C
stochastics/CirculantEmbedding.C
problem/StochasticEllipticProblem.h stochastics/SampleGenerator.h stochastics/HybridFluxGenerator.C stochastics/HybridFluxGenerator.h problem/StochasticProblemFactory.hpp)
problem/StochasticEllipticProblem.h stochastics/SampleGenerator.h stochastics/HybridFluxGenerator.C stochastics/HybridFluxGenerator.h problem/StochasticProblemFactory.hpp mc/MonteCarlo.cpp utils/MultilevelPlotter.cpp utils/MultilevelPlotter.hpp)
add_library(MLMC STATIC ${MLMC_SRC})
......@@ -11,7 +11,9 @@ void MLMCMain::initialize() {
problem = StochasticProblemFactory::CreateStochasticProblemFrom(problemName);
assemble = getAssemble();
mlmc = new MultilevelMonteCarlo(initLevels, initSampleAmount, meshes,
plots = new MultilevelPlotter(*meshes);
mlmc = new MultilevelMonteCarlo(initLevels, initSampleAmount, meshes, *plots,
stochasticField, assemble);
}
......
......@@ -6,6 +6,7 @@
#include "MultilevelMonteCarlo.h"
#include "discretization/DGDiscretization.h"
#include "stochastics/StochasticField.h"
#include "utils/MultilevelPlotter.hpp"
class MLMCMain {
......@@ -23,6 +24,7 @@ public:
vector<double> epsilonList = {0.1, 0.05, 0.01};
Meshes *meshes = nullptr;
MultilevelPlotter *plots = nullptr;
Discretization *disc = nullptr;
StochasticField *stochasticField = nullptr;
......
#include "MonteCarloLogger.h"
IndentedLogger *IndentedLogger::instance = nullptr;
......@@ -8,9 +8,9 @@ MonteCarlo *MultilevelMonteCarlo::getMonteCarlo(int l, int dM, bool onlyFineLeve
auto transportAssemble = dynamic_cast<DGTransportAssemble *>(assemble);
if (ellipticAssemble != nullptr)
return new MonteCarloElliptic(l, dM, onlyFineLevel, meshes,
stochasticField, ellipticAssemble);
stochasticField, ellipticAssemble, plots);
if (transportAssemble != nullptr)
return new MonteCarloTransport(l, dM, onlyFineLevel, meshes,
return new MonteCarloTransport(l, dM, onlyFineLevel, meshes, plots,
stochasticField, transportAssemble);
Exit("Wrong Assembly Class")
}
......
#ifndef MULTILEVELMONTECARLO_H
#define MULTILEVELMONTECARLO_H
#include "MonteCarloLogger.h"
#include "utils/IndentedLogger.hpp"
#include "mc/MonteCarloElliptic.h"
#include "mc/MonteCarloTransport.h"
......@@ -43,6 +43,7 @@ public:
map<int, MonteCarlo *> mapMonteCarlo;
Meshes *meshes;
MultilevelPlotter &plots;
StochasticField *stochasticField;
Assemble *assemble;
......@@ -58,11 +59,13 @@ public:
MultilevelMonteCarlo(vector<int> &initLevels,
vector<int> &initSampleAmount,
Meshes *meshes,
MultilevelPlotter &plots,
StochasticField *stochasticField,
Assemble *assemble) :
initLevels(initLevels),
initSampleAmount(initSampleAmount),
meshes(meshes),
plots(plots),
stochasticField(stochasticField),
assemble(assemble) {
......
......@@ -2,7 +2,7 @@
#define TUTORIAL_DGTRANSPORT_HPP
#include "DGTAssemble.h"
#include "MonteCarloLogger.h"
#include "utils/IndentedLogger.hpp"
class DGTransportAssemble : public DGTAssemble {
......
......@@ -3,10 +3,11 @@
#include "m++.h"
#include "stochastics/StochasticField.h"
#include "MonteCarloLogger.h"
#include "utils/IndentedLogger.hpp"
#include <sys/stat.h>
#include <utility>
#include <utils/MultilevelPlotter.hpp>
class MonteCarlo {
......@@ -42,8 +43,12 @@ public:
double fineQ = 0.0, coarseQ = 0.0;
double fineCost = 0.0, coarseCost = 0.0;
MonteCarlo(int l, int dM, bool onlyFineLevel,
Meshes *meshes, StochasticField *stochFields) :
MonteCarlo(int l,
int dM,
bool onlyFineLevel,
Meshes *meshes,
MultilevelPlotter &plots,
StochasticField *stochFields) :
l(l), dM(dM), onlyFineLevel(onlyFineLevel),
meshes(meshes), pLevel(meshes->pLevel()),
stochasticField(stochFields) {
......@@ -51,18 +56,13 @@ public:
config.get("MCPlotting", plotting);
config.get("functional", functional);
coarsePlot = new Plot((*meshes)[l - 1], meshes->dim());
finePlot = new Plot((*meshes)[l], meshes->dim());
coarsePlot = plots.GetPlot(l - 1);
finePlot = plots.GetPlot(l);
config.get("MCVerbose", verbose);
logger = IndentedLogger::GetInstance();
}
virtual ~MonteCarlo() {
delete coarsePlot;
delete finePlot;
}
void Method();
protected:
......
......@@ -24,13 +24,17 @@ public:
MatrixGraphs cellMatrixGraphs;
MatrixGraphs solMatrixGraphs;
MonteCarloElliptic(int l, int dM, bool onlyFineLevel, Meshes *meshes,
StochasticField *stochFields, EllipticAssemble *assemble) :
MonteCarlo(l, dM, onlyFineLevel, meshes, stochFields),
MonteCarloElliptic(int l,
int dM,
bool onlyFineLevel,
Meshes *meshes,
StochasticField *stochFields,
EllipticAssemble *assemble,
MultilevelPlotter &plots) :
MonteCarlo(l, dM, onlyFineLevel, meshes, plots, stochFields),
assemble(assemble),
cellMatrixGraphs(MatrixGraphs(*meshes, dof("cell", 3))),
solMatrixGraphs(MatrixGraphs(*meshes, *assemble->disc)) {
}
};
......
......@@ -52,7 +52,7 @@ void MonteCarloTransport::solvePDE(int l,
double &valueQ,
double &cost,
Vector &solution) {
logger->StartMethod("Start Solving PDE on ", verbose);
logger->StartMethod("Start Solving PDE", verbose);
logger->InnerMsg("l: " + to_string(l) +
" m: " + to_string(m), verbose);
......
......@@ -38,9 +38,14 @@ public:
Vector fineSolution;
Vector coarseSolution;
MonteCarloTransport(int l, int dM, bool baseLevel, Meshes *meshes,
StochasticField *stochFields, DGTransportAssemble *assemble) :
MonteCarlo(l, dM, baseLevel, meshes, stochFields),
MonteCarloTransport(int l,
int dM,
bool baseLevel,
Meshes *meshes,
MultilevelPlotter &plots,
StochasticField *stochFields,
DGTransportAssemble *assemble) :
MonteCarlo(l, dM, baseLevel, meshes, plots, stochFields),
assemble(assemble),
cellMatrixGraphs(MatrixGraphs(*meshes, dof("cell", 3))),
faceMatrixGraphs(MatrixGraphs(*meshes, dof("face", 3))),
......
......@@ -4,7 +4,7 @@
#include <utility>
#include "m++.h"
#include "MonteCarloLogger.h"
#include "utils/IndentedLogger.hpp"
class SampleGenerator {
......
#include "IndentedLogger.hpp"
IndentedLogger *IndentedLogger::instance = nullptr;
\ No newline at end of file
......@@ -5,10 +5,10 @@
class IndentedLogger {
private:
static IndentedLogger *instance;
string indent;
string innerIndent;
const string defaultIndent = " ";
......@@ -33,10 +33,6 @@ public:
indent = indent.append(defaultIndent);
}
string GetIndent() {
return indent;
}
void StartMethod(const string& msg, int verbose) {
Date start;
timestamps.push_back(start);
......
#include "MultilevelPlotter.hpp"
//MultilevelPlotter *MultilevelPlotter::instance = nullptr;
\ No newline at end of file
#ifndef MULTILEVELPLOTTER_HPP
#define MULTILEVELPLOTTER_HPP
#include "Plot.h"
class MultilevelPlotter {
map<int, Plot *> mapPlots;
void initializeMap(const vector<int> &levels, const Meshes &meshes) {
for (auto &l: levels) {
mapPlots[l] = new Plot(meshes[l], meshes.dim());
}
}
public:
explicit MultilevelPlotter(const Meshes &meshes) {
vector<int> levels;
for (int l = meshes.pLevel(); l <= meshes.Level(); l++)
levels.push_back(l);
initializeMap(levels, meshes);
}
MultilevelPlotter(int startLevel, int endLevel, const Meshes &meshes) {
vector<int> levels;
for (int l = startLevel; l <= endLevel; l++)
levels.push_back(l);
initializeMap(levels, meshes);
}
explicit MultilevelPlotter(const vector<int> &levels, const Meshes &meshes) {
initializeMap(levels, meshes);
}
Plot *GetPlot(int l) {
return mapPlots[l];
}
~MultilevelPlotter() {
for (auto &plot : mapPlots)
delete plot.second;
}
};
#endif //MULTILEVELPLOTTER_HPP
Supports Markdown
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