Commit 13b08eb3 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

refactored MonteCarlo

parent b1fe4c71
......@@ -14,22 +14,18 @@ void MonteCarlo::Method() {
void MonteCarlo::method() {
for (int m = ctr.M; m < ctr.M + ctr.dM; m++) {
fineId.number = m;
fineSolution.id = fineId;
plotter->SetDirectory(fineId);
assemble->DrawSample(fineId);
pdeSolver->Run(assemble, fineSolution);
if (!onlyFine) {
coarseId.number = m;
coarseSolution.id = coarseId;
plotter->SetDirectory(coarseId);
assemble->DrawSample(coarseId);
pdeSolver->Run(assemble, coarseSolution);
} else {
coarseSolution.Init();
}
sums.Update(fineSolution.Cost,
fineSolution.Q - coarseSolution.Q,
fineSolution.Q);
findSampleSolution(m, fineId, fineSolution);
if (onlyFine) coarseSolution.Init();
else findSampleSolution(m, coarseId, coarseSolution);
sums.Update(fineSolution, coarseSolution);
ctr.Update();
}
}
void MonteCarlo::findSampleSolution(int m, SampleID &id, SampleSolution &solution) {
id.number = m;
solution.id = id;
plotter->SetDirectory(id);
assemble->DrawSample(id);
pdeSolver->Run(assemble, solution);
}
......@@ -2,7 +2,7 @@
#define MLMC_MC_HPP
#include "main/MultilevelPlotter.hpp"
#include "StatisticMeasures.hpp"
#include "EmpiricMeasures.hpp"
#include "PDESolver.hpp"
#include "utility/SampleID.hpp"
#include "assemble/IStochasticAssemble.hpp"
......@@ -16,6 +16,8 @@ protected:
virtual void method();
void findSampleSolution(int m, SampleID &id, SampleSolution &solution);
public:
int level = 0;
int pLevel = 0;
......@@ -45,8 +47,8 @@ public:
level(level), onlyFine(onlyFine),
assemble(assemble), pdeSolver(pdeSolver),
solMGraphs(MatrixGraphs(meshes, *assemble->GetDiscretization())),
coarseSolution(SampleSolution(solMGraphs, level - 1)),
fineSolution(SampleSolution(solMGraphs, level)) {
coarseSolution(SampleSolution(solMGraphs, level - meshes.pLevel() - 1)),
fineSolution(SampleSolution(solMGraphs, level - meshes.pLevel())) {
config.get("MCPlotting", plotting);
config.get("MCVerbose", verbose);
......@@ -54,7 +56,7 @@ public:
ctr.dM = dM;
fineId.level = level;
fineId.coarse = false;
coarseId.level = level - 1;
coarseId.level = level;
coarseId.coarse = true;
}
......
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