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

refactoring

parent 94655784
Pipeline #168550 passed with stages
in 19 minutes and 26 seconds
......@@ -4,6 +4,7 @@
void MonteCarlo::Method() {
std::string parallelStr = aggregate.parallel ? "Parallel" : "Seriell";
mout.StartBlock(parallelStr + " MC l=" + to_string(level));
vout(1) << "epsilon=" << to_string(epsilon) << endl;
std::unique_ptr<Meshes> meshes = meshesCreator.
WithMeshName(pdeSolverCreator.GetMeshName()).
......@@ -17,16 +18,7 @@ void MonteCarlo::Method() {
std::unique_ptr<PDESolver> pdeSolver = pdeSolverCreator.
CreateUnique(*meshes);
if (epsilon == 0.0) {
vout(1) << "Start with: " << aggregate;
method(*pdeSolver);
vout(1) << "End with: " << aggregate;
} else {
vout(1) << "epsilon=" << to_string(epsilon) << endl;
vout(1) << "Start with: " << aggregate;
adaptiveMethod(*pdeSolver);
vout(1) << "End with: " << aggregate;
}
method(*pdeSolver);
value = aggregate.mean.Q;
cost = aggregate.mean.C;
......@@ -41,33 +33,20 @@ void MonteCarlo::updateSampleIds(SampleSolution &fSol, SampleSolution &cSol) {
cSol.id = coarseId;
}
void MonteCarlo::method(PDESolver &pdeSolver) {
SampleSolution fineSolution(pdeSolver.GetDisc(), fineId);
SampleSolution coarseSolution(pdeSolver.GetDisc(), coarseId);
while (aggregate.ctr.dMcomm != 0) {
updateSampleIds(fineSolution, coarseSolution);
pdeSolver.Run(fineSolution);
if (!onlyFine) pdeSolver.Run(coarseSolution);
aggregate.Update(fineSolution, coarseSolution);
}
aggregate.UpdateParallel();
errors.Estimate(aggregate);
}
void MonteCarlo::updateSampleCounter() {
int optimalM = (int) (ceil(aggregate.sVar.Q / (epsilon * epsilon)));
aggregate.UpdateSampleCounter(optimalM - aggregate.ctr.M);
}
void MonteCarlo::adaptiveMethod(PDESolver &pdeSolver) {
void MonteCarlo::method(PDESolver &pdeSolver) {
SampleSolution fineSolution(pdeSolver.GetDisc(), fineId);
SampleSolution coarseSolution(pdeSolver.GetDisc(), coarseId);
while (aggregate.ctr.dM != 0) {
vout(1) << "Start with: " << aggregate;
while (aggregate.ctr.dMcomm != 0) {
updateSampleIds(fineSolution, coarseSolution);
pdeSolver.Run(fineSolution);
......@@ -78,11 +57,15 @@ void MonteCarlo::adaptiveMethod(PDESolver &pdeSolver) {
aggregate.UpdateParallel();
errors.Estimate(aggregate);
if (errors.numeric < epsilon) {
if (errors.total > epsilon)
updateSampleCounter();
} else {
Exit("Numeric Error is too big too reach error bound")
vout(1) << "End with: " << aggregate;
if (epsilon != 0.0) {
if (errors.numeric < epsilon) {
if (errors.total > epsilon)
updateSampleCounter();
} else {
Exit("Numeric Error is too big too reach error bound")
}
}
}
}
......@@ -30,8 +30,6 @@ protected:
void method(PDESolver &pdeSolver);
void adaptiveMethod(PDESolver &pdeSolver);
void updateSampleCounter();
public:
......
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