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

first SC implementation which passes simple quadrature test

parent bdb78dcd
#include "StochasticCollocation.hpp"
void StochasticCollocation::Method() {
mout.StartBlock("Stochastic Collocation l=" + to_string(level));
vout(1) << "Start with: " << aggregate;
method();
aggregate.UpdateParallel();
vout(1) << "End with: " << aggregate;
mout.EndBlock(verbose == 0);
}
void StochasticCollocation::updateSampleIds(SampleSolution &fSol, SampleSolution &cSol) {
fineId.number = aggregate.index();
coarseId.number = aggregate.index();
fSol.id = fineId;
cSol.id = coarseId;
}
void StochasticCollocation::method() {
std::unique_ptr<Meshes> meshes = meshesCreator.
WithMeshName(pdeSolverCreator.GetMeshName()).
WithCommSplit(aggregate.commSplit).
WithPLevel(level - 1).
WithLevel(level).
CreateUnique();
std::unique_ptr<PDESolver> pdeSolver = pdeSolverCreator.
CreateUnique(*meshes);
SampleSolution fineSolution(pdeSolver->GetDisc(), fineId);
SampleSolution coarseSolution(pdeSolver->GetDisc(), coarseId);
int numGridPoints = pdeSolver->GetProblem()->NumOfSamples();
aggregate.UpdateSampleCounter(numGridPoints);
while (aggregate.ctr.dMcomm != 0) {
updateSampleIds(fineSolution, coarseSolution);
pdeSolver->DrawSample(fineId);
pdeSolver->Run(fineSolution);
aggregate.Update(fineSolution, coarseSolution);
}
}
\ No newline at end of file
......@@ -3,9 +3,17 @@
#include "Estimator.hpp"
#include <utility>
class StochasticCollocation : public Estimator {
private:
protected:
int verbose = 1;
bool onlyFine;
bool parallel;
SampleID fineId;
SampleID coarseId;
......@@ -13,6 +21,11 @@ private:
MeshesCreator meshesCreator;
PDESolverCreator pdeSolverCreator;
void updateSampleIds(SampleSolution &fSol, SampleSolution &cSol);
void method();
public:
StochasticCollocation(double epsilon, int level, int stochLevel,
bool onlyFine, bool parallel,
......@@ -20,42 +33,11 @@ public:
PDESolverCreator pdeCreator = PDESolverCreator()) :
Estimator(epsilon, level, 0),
fineId(SampleID(level, 0, false)), coarseId(SampleID(level, 0, true)),
meshesCreator(meshesCreator), pdeSolverCreator(pdeCreator) {}
std::string Name() const override {
return "StochasticCollocation";
}
void Method() override {
std::unique_ptr<Meshes> meshes = meshesCreator.
WithMeshName(pdeSolverCreator.GetMeshName()).
WithCommSplit(aggregate.commSplit).
WithPLevel(level - 1).
WithLevel(level).
CreateUnique();
std::unique_ptr<PDESolver> pdeSolver = pdeSolverCreator.
CreateUnique(*meshes);
SampleSolution fineSolution(pdeSolver->GetDisc(), fineId);
SampleSolution coarseSolution(pdeSolver->GetDisc(), coarseId);
pdeSolver->DrawSample(fineId);
pdeSolver->Run(fineSolution);
while (aggregate.ctr.dMcomm != 0) {
pdeSolver->DrawSample(fineId);
pdeSolver->Run(fineSolution);
aggregate.Update(fineSolution, coarseSolution);
// errors.Estimate(aggregate);
//
// if (errors.stochastic > epsilon && epsilon != 0.0)
// mout << "TODO" << endl;
// aggregate.
}
}
meshesCreator(std::move(meshesCreator)), pdeSolverCreator(std::move(pdeCreator)) {}
std::string Name() const override { return "StochasticCollocation"; }
void Method() override;
};
#endif //STOCHASTICCOLLOCATION_HPP
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