Commit 4a98f7ae authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

refactored HybridFluxGenerator, started with fixing transport

parent 2027608e
......@@ -21,7 +21,7 @@ public:
std::shared_ptr<StochasticTransportProblem> problem)
: DGTAssemble(dynamic_cast<DGDiscretization *>(disc.get())),
problem(move(problem)) {
ReadConfig(Settings, "flux_alpha", flux_alpha);
config.get("flux_alpha", flux_alpha);
logger = IndentedLogger::GetInstance();
}
......
......@@ -46,13 +46,12 @@ void MonteCarloTransport::method() {
void MonteCarloTransport::solvePDE(int l, int m, bool fineLevel,
double &valueQ, double &cost, Vector &solution) {
logger->StartMethod("Start Solving PDE", verbose);
logger->InnerMsg("l: " + to_string(l) +
" m: " + to_string(m), verbose);
logger->InnerMsg("l: " + to_string(l) + " m: " + to_string(m), verbose);
Preconditioner *pc = GetPC("PointBlockGaussSeidel"); //TODO RMV after usage
Preconditioner *pc = GetPC("PointBlockGaussSeidel");
Solver solver(pc, "GMRES");
Solver solver2(pc, "GMRES"); // TODO RMV
DGTimeIntegrator timeIntegrator(solver, solver, solver, solver2);
DGTimeIntegrator timeIntegrator(solver, solver, solver, solver);
TimeSeries timeSeries = getTimeSeries(fineLevel);
assemble->resetTAssemble();
......
......@@ -29,6 +29,9 @@ private:
public:
DGTransportAssemble *assemble;
unique_ptr<Preconditioner> pc;
unique_ptr<Solver> solver;
MatrixGraphs cellMatrixGraphs;
MatrixGraphs faceMatrixGraphs;
CellMatrixGraphs solMatrixGraphs;
......@@ -38,11 +41,8 @@ public:
Vector fineSolution;
Vector coarseSolution;
MonteCarloTransport(int l,
int dM,
bool baseLevel,
Meshes *meshes,
StochasticField *stochFields,
MonteCarloTransport(int l, int dM, bool baseLevel,
Meshes *meshes, StochasticField *stochFields,
DGTransportAssemble *assemble) :
MonteCarlo(l, dM, baseLevel, meshes, stochFields),
assemble(assemble),
......@@ -52,7 +52,9 @@ public:
fineInput(Vector(faceMatrixGraphs[l - pLevel])),
coarseInput(Vector(faceMatrixGraphs[l - pLevel - 1])),
fineSolution(Vector(solMatrixGraphs[l - pLevel])),
coarseSolution(Vector(solMatrixGraphs[l - pLevel - 1])) {
coarseSolution(Vector(solMatrixGraphs[l - pLevel - 1])),
pc(unique_ptr<Preconditioner>(GetPC("PointBlockGaussSeidel"))),
solver(make_unique<Solver>(pc.get(), "GMRES")) {
config.get("startTime", startTime);
config.get("endTime", endTime);
......
......@@ -5,8 +5,9 @@
class StochasticProblem {
public:
protected:
Vector *fieldSample = nullptr;
public:
StochasticProblem() = default;
......
......@@ -5,13 +5,9 @@ void HybridFluxGenerator::generateFineSample(Vector &fineField) {
initialize(true);
permeabilityGenerator->SetSampleDir(sampleDir);
permeabilityGenerator->GetFineSample(*finePerm);
assemble->problem->SetSample(finePerm);
assemble->problem->SetSample(finePerm.get());
Preconditioner *pc = GetPC("SuperLU");
Solver solver(pc, "GMRES");
Newton newton(solver);
(newton)(*assemble, *u);
newton(*assemble, *u);
assemble->setFlux(*u, *flux);
assemble->SetNormalFlux(*u, fineField);
......@@ -24,13 +20,9 @@ void HybridFluxGenerator::generateCoarseSample(const Vector &fineField,
Vector &coarseField) {
initialize(false);
permeabilityGenerator->GetCoarseSample(*finePerm, *coarsePerm);
assemble->problem->SetSample(coarsePerm);
Preconditioner *pc = GetPC("SuperLU");
Solver solver(pc, "GMRES");
Newton newton(solver);
assemble->problem->SetSample(coarsePerm.get());
(newton)(*assemble, *u);
newton(*assemble, *u);
assemble->setFlux(*u, *flux);
assemble->SetNormalFlux(*u, coarseField);
......@@ -41,11 +33,11 @@ void HybridFluxGenerator::generateCoarseSample(const Vector &fineField,
void HybridFluxGenerator::initialize(bool fineField) {
if (fineField) {
flux = new Vector(cellMatrixGraphs[l - meshes.pLevel()]);
u = new Vector(faceMatrixGraphs[l - meshes.pLevel()]);
flux = make_unique<Vector>(cellMatrixGraphs[l - meshes.pLevel()]);
u = make_unique<Vector>(faceMatrixGraphs[l - meshes.pLevel()]);
} else {
flux = new Vector(cellMatrixGraphs[l - meshes.pLevel() - 1]);
u = new Vector(faceMatrixGraphs[l - meshes.pLevel() - 1]);
flux = make_unique<Vector>(cellMatrixGraphs[l - meshes.pLevel() - 1]);
u = make_unique<Vector>(faceMatrixGraphs[l - meshes.pLevel() - 1]);
}
*flux = 0.0, *u = 0.0;
}
......@@ -12,45 +12,39 @@ private:
MatrixGraphs cellMatrixGraphs;
MatrixGraphs faceMatrixGraphs;
Vector *finePerm = nullptr;
Vector *coarsePerm = nullptr;
Vector *flux = nullptr;
Vector *u = nullptr;
unique_ptr<Vector> finePerm;
unique_ptr<Vector> coarsePerm;
unique_ptr<Vector> flux;
unique_ptr<Vector> u;
void initialize(bool fineField);
protected:
Discretization *disc = nullptr;
StochasticEllipticProblem *problem = nullptr;
HybridEllipticAssemble *assemble = nullptr;
CirculantEmbedding *permeabilityGenerator = nullptr;
shared_ptr<IDiscretizationT<>> disc;
shared_ptr<StochasticEllipticProblem> problem;
unique_ptr<HybridEllipticAssemble> assemble;
unique_ptr<CirculantEmbedding> permeabilityGenerator;
unique_ptr<Preconditioner> pc;
Solver solver;
Newton newton;
void generateFineSample(Vector &fineField) override;
void generateCoarseSample(const Vector &fineField, Vector &coarseField) override;
public:
explicit HybridFluxGenerator(int l, Meshes &meshes)
: SampleGenerator(l, meshes),
cellMatrixGraphs(MatrixGraphs(meshes, dof("cell", 3))),
faceMatrixGraphs(MatrixGraphs(meshes, dof("face", 1))) {
finePerm = new Vector(cellMatrixGraphs[l - meshes.pLevel()]);
explicit HybridFluxGenerator(int l, Meshes &meshes) :
SampleGenerator(l, meshes),
cellMatrixGraphs(MatrixGraphs(meshes, dof("cell", 3))),
faceMatrixGraphs(MatrixGraphs(meshes, dof("face", 1))),
pc(unique_ptr<Preconditioner>(GetPC("SuperLU"))),
solver(Solver(pc.get(), "GMRES")),
newton(Newton(solver)) {
finePerm = make_unique<Vector>(cellMatrixGraphs[l - meshes.pLevel()]);
if (l != meshes.pLevel())
coarsePerm = new Vector(cellMatrixGraphs[l - meshes.pLevel() - 1]);
else
coarsePerm = nullptr;
}
~HybridFluxGenerator() {
delete disc;
delete problem;
delete assemble;
delete permeabilityGenerator;
delete finePerm;
delete coarsePerm;
delete flux;
delete u;
coarsePerm = make_unique<Vector>(cellMatrixGraphs[l - meshes.pLevel() - 1]);
}
};
......@@ -58,11 +52,11 @@ class HybridFluxGenerator1D : public HybridFluxGenerator {
public:
explicit HybridFluxGenerator1D(int l, Meshes &meshes) :
HybridFluxGenerator(l, meshes) {
disc = new Discretization("RT0_P0", 1, meshes.dim());
// problem = StochasticProblemFactory::CreateFrom<StochasticEllipticProblem>(
// EStochasticProblem::StochasticLaplace1D);
// assemble = new HybridEllipticAssemble(disc, problem);
permeabilityGenerator = new CirculantEmbedding1D(l, meshes);
disc = make_shared<DiscretizationT<>>(meshes, "RT0_P0");
problem = make_shared<StochasticLaplace1D>();
assemble = make_unique<HybridEllipticAssemble>(disc, problem);
permeabilityGenerator = make_unique<CirculantEmbedding1D>(l, meshes);
}
};
......@@ -70,35 +64,11 @@ class HybridFluxGenerator2D : public HybridFluxGenerator {
public:
explicit HybridFluxGenerator2D(int l, Meshes &meshes)
: HybridFluxGenerator(l, meshes) {
disc = new Discretization("RT0_P0", 1, meshes.dim());
// problem = StochasticProblemFactory::CreateFrom<StochasticEllipticProblem>(
// EStochasticProblem::StochasticLaplace2D);
// assemble = new HybridEllipticAssemble(disc, problem);
permeabilityGenerator = new CirculantEmbedding2D(l, meshes);
}
};
class DeterministicHybridFluxGenerator1D : public HybridFluxGenerator {
public:
explicit DeterministicHybridFluxGenerator1D(int l, Meshes &meshes)
: HybridFluxGenerator(l, meshes) {
disc = new Discretization("RT0_P0", 1, meshes.dim());
// problem = StochasticProblemFactory::CreateFrom<StochasticEllipticProblem>(
// EStochasticProblem::StochasticLaplace1D);
// assemble = new HybridEllipticAssemble(disc, problem);
permeabilityGenerator = new DeterministicPermeabilityGenerator(l, meshes);
}
};
class DeterministicHybridFluxGenerator2D : public HybridFluxGenerator {
public:
explicit DeterministicHybridFluxGenerator2D(int l, Meshes &meshes)
: HybridFluxGenerator(l, meshes) {
disc = new Discretization("RT0_P0", 1, meshes.dim());
// problem = StochasticProblemFactory::CreateFrom<StochasticEllipticProblem>(
// EStochasticProblem::StochasticLaplace2D);
// assemble = new HybridEllipticAssemble(disc, problem);
permeabilityGenerator = new DeterministicPermeabilityGenerator(l, meshes);
disc = make_shared<DiscretizationT<>>(meshes, "RT0_P0");
problem = make_shared<StochasticLaplace2D>();
assemble = make_unique<HybridEllipticAssemble>(disc, problem);
permeabilityGenerator = make_unique<CirculantEmbedding2D>(l, meshes);
}
};
......
......@@ -35,24 +35,13 @@ private:
if (meshes.dim() == 2)
return new CirculantEmbedding2D(l, meshes);
}
if (generatorName == "DeterministicPermeabilityGenerator") {
// if (meshes.dim() == 1)
// return new DeterministicPermeabilityGenerator1D(l, meshes);
// if (meshes.dim() == 2)
// return new DeterministicPermeabilityGenerator2D(l, meshes);
}
if (generatorName == "HybridFluxGenerator") {
if (meshes.dim() == 1)
return new HybridFluxGenerator1D(l, meshes);
if (meshes.dim() == 2)
return new HybridFluxGenerator2D(l, meshes);
}
if (generatorName == "DeterministicHybridFluxGenerator") {
if (meshes.dim() == 1)
return new DeterministicHybridFluxGenerator1D(l, meshes);
if (meshes.dim() == 2)
return new DeterministicHybridFluxGenerator2D(l, meshes);
}
Exit("Generator does not exist")
}
};
......
......@@ -72,15 +72,15 @@ INSTANTIATE_TEST_CASE_P(TestMainProgram, TestMainProgram, Values(
std::map<std::string, std::string>{
{"GeneratorPlotting", "1"},
{"MCPlotting", "1"},
{"Problem", "StochasticLaplace2D"}}},
{"Problem", "StochasticLaplace2D"}}}
// Tests with default transport config
ConfigMapsForTest{defaultTransportConfigMap,
std::map<std::string, std::string>{}},
ConfigMapsForTest{defaultTransportConfigMap,
std::map<std::string, std::string>{
{"Problem", "StochasticPollution2D"}}}
// ConfigMapsForTest{defaultTransportConfigMap,
// std::map<std::string, std::string>{}}
//
// ConfigMapsForTest{defaultTransportConfigMap,
// std::map<std::string, std::string>{
// {"Problem", "StochasticPollution2D"}}}
));
TEST_P(TestMainProgram, TestInitialize) {
......
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