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

added adaptive method

parent a7bb0dd1
Pipeline #168491 canceled with stages
in 34 minutes and 44 seconds
......@@ -5,22 +5,31 @@ void MonteCarlo::Method() {
std::string parallelStr = aggregate.parallel ? "Parallel" : "Seriell";
mout.StartBlock(parallelStr + " MC l=" + to_string(level));
std::unique_ptr<Meshes> meshes = meshesCreator.
WithMeshName(pdeSolverCreator.GetMeshName()).
WithCommSplit(aggregate.commSplit).
WithPLevel(level - 1).
WithLevel(level).
CreateUnique();
meshes->PrintInfo();
std::unique_ptr<PDESolver> pdeSolver = pdeSolverCreator.
CreateUnique(*meshes);
if (epsilon == 0.0) {
vout(1) << "Start with: " << aggregate;
method();
aggregate.UpdateParallel();
method(*pdeSolver);
vout(1) << "End with: " << aggregate;
} else {
vout(1) << "epsilon=" << to_string(epsilon) << endl;
vout(1) << "Start with: " << aggregate;
adaptiveMethod();
aggregate.UpdateParallel();
adaptiveMethod(*pdeSolver);
vout(1) << "End with: " << aggregate;
}
value = aggregate.mean.Q;
cost = aggregate.mean.C;
// errors = 0.0;
mout.EndBlock(verbose == 0);
}
......@@ -32,37 +41,62 @@ void MonteCarlo::updateSampleIds(SampleSolution &fSol, SampleSolution &cSol) {
cSol.id = coarseId;
}
void MonteCarlo::method() {
// WithPLevel(onlyFine ? level : level - 1)
std::unique_ptr<Meshes> meshes = meshesCreator.
WithMeshName(pdeSolverCreator.GetMeshName()).
WithCommSplit(aggregate.commSplit).
WithPLevel(level - 1).
WithLevel(level).
CreateUnique();
void MonteCarlo::method(PDESolver &pdeSolver) {
meshes->PrintInfo();
std::unique_ptr<PDESolver> pdeSolver = pdeSolverCreator.
CreateUnique(*meshes);
SampleSolution fineSolution(pdeSolver->GetDisc(), fineId);
SampleSolution coarseSolution(pdeSolver->GetDisc(), coarseId);
SampleSolution fineSolution(pdeSolver.GetDisc(), fineId);
SampleSolution coarseSolution(pdeSolver.GetDisc(), coarseId);
while (aggregate.ctr.dMcomm != 0) {
updateSampleIds(fineSolution, coarseSolution);
pdeSolver->DrawSample(fineId);
pdeSolver->Run(fineSolution);
pdeSolver.DrawSample(fineId);
pdeSolver.Run(fineSolution);
if (!onlyFine) {
pdeSolver->DrawSample(coarseId);
pdeSolver->Run(coarseSolution);
pdeSolver.DrawSample(coarseId);
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() {
void MonteCarlo::adaptiveMethod(PDESolver &pdeSolver) {
SampleSolution fineSolution(pdeSolver.GetDisc(), fineId);
SampleSolution coarseSolution(pdeSolver.GetDisc(), coarseId);
while (aggregate.ctr.dM != 0) {
while (aggregate.ctr.dMcomm != 0) {
updateSampleIds(fineSolution, coarseSolution);
pdeSolver.DrawSample(fineId);
pdeSolver.Run(fineSolution);
if (!onlyFine) {
pdeSolver.DrawSample(coarseId);
pdeSolver.Run(coarseSolution);
}
aggregate.Update(fineSolution, coarseSolution);
}
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")
}
}
}
......@@ -28,9 +28,11 @@ protected:
void updateSampleIds(SampleSolution &fSol, SampleSolution &cSol);
void method();
void method(PDESolver &pdeSolver);
void adaptiveMethod();
void adaptiveMethod(PDESolver &pdeSolver);
void updateSampleCounter();
public:
MonteCarlo(double epsilon, int level, int initSamples, bool onlyFine, bool parallel,
......
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