Commit 966fa319 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

Merge branch '38-refactor-sample-and-sampleid' into 'feature'

Resolve "Refactor Sample and SampleID"

Closes #38

See merge request !52
parents b55f4a7b 2d9ca37b
Pipeline #161762 passed with stages
in 16 minutes and 39 seconds
...@@ -37,9 +37,7 @@ void MonteCarlo::method() { ...@@ -37,9 +37,7 @@ void MonteCarlo::method() {
pdeSolver->DrawSample(fineId); pdeSolver->DrawSample(fineId);
pdeSolver->Run(fineSolution); pdeSolver->Run(fineSolution);
if (onlyFine) { if (!onlyFine) {
coarseSolution.Init();
} else {
pdeSolver->DrawSample(coarseId); pdeSolver->DrawSample(coarseId);
pdeSolver->Run(coarseSolution); pdeSolver->Run(coarseSolution);
} }
......
#ifndef SAMPLE_HPP #ifndef SAMPLE_HPP
#define SAMPLE_HPP #define SAMPLE_HPP
#include "Algebra.hpp" #include "Vector.hpp"
#include <string> #include <string>
#include <utility>
struct SampleID { struct SampleID {
public: std::string name = "U";
int fLevel;
int cLevel; int fLevel{};
std::string name = "U"; int cLevel{};
int number; int number{};
bool coarse; // Todo should be; SampleID makes more sense then bool coarse{};
SampleID() {} explicit SampleID(std::string name = "U") : name(std::move(name)) {}
SampleID(int level, int number, bool coarse, const std::string &name = "U") : SampleID(int level, int number, bool coarse, std::string name = "U") :
fLevel(level), cLevel( (level > 0) ? (level - 1) : 0), fLevel(level), cLevel((level > 0) ? (level - 1) : 0),
number(number), coarse(coarse), name(name) {} number(number), coarse(coarse), name(std::move(name)) {}
int level() const { int level() const {
if (coarse) return cLevel; if (coarse) return cLevel;
else return fLevel; else return fLevel;
}; };
std::string IdString(const std::string &name_) const { std::string IdString() const {
return name_ + "." + std::to_string(fLevel) return name + "." + std::to_string(fLevel)
+ "." + std::to_string((int) coarse) + "." + std::to_string((int) coarse)
+ "." + std::to_string(number); + "." + std::to_string(number);
} }
std::string IdString() const { friend Logging &operator<<(Logging &s, const SampleID &id) {
return IdString(name); return s << id.IdString();
} }
}; };
// Todo remove init
struct SampleSolution { struct SampleSolution {
SampleID id; SampleID id;
public: public:
double Q; // Quantity of interest of sample solution double Q = 0.0; // Quantity of interest of sample solution
double C; // Cost to compute sample solution double C = 0.0; // Cost to compute sample solution
double W; // Weight of the sample solution double W = 0.0; // Weight of the sample solution
Vector U; // Finite element coefficient vector of sample solution Vector U; // Finite element coefficient vector of sample solution
SampleSolution(IDiscretization *disc, const std::string &name = "U") :
U(Vector((*disc))) {
this->id.name = name;
Init();
}
SampleSolution(IDiscretization *disc, const SampleID &id, SampleSolution(IDiscretization *disc, const SampleID &id,
const std::string &name = "U") : const std::string &name = "U") :
id(id), U(Vector(*disc, id.level())) { id(id), U(Vector(0.0, *disc, id.level())) {
this->id.name = name; this->id.name = name;
Init();
} }
SampleSolution(const Vector &U, const SampleID &id, const std::string &name = "U") : const SampleID &Id() const {
id(id), U(U) { return id;
this->id.name = name;
} }
std::string IdString() const { std::string IdString() const {
return id.IdString(); return id.IdString();
} }
const SampleID &Id() const { friend Logging &operator<<(Logging &s, const SampleSolution &sol) {
return id; return s << sol.id << endl << "Q=" << sol.Q <<
} ", C=" << sol.C << ", W=" << sol.W << endl;
void Init() {
Q = 0.0;
C = 0.0;
U = 0.0;
W = 0.0;
} }
}; };
......
...@@ -39,7 +39,7 @@ public: ...@@ -39,7 +39,7 @@ public:
void DrawSample(const SampleID &id) { void DrawSample(const SampleID &id) {
mout.StartBlock(Name()); mout.StartBlock(Name());
vout(1) << id.IdString() << endl; vout(1) << id << endl;
drawSample(id); drawSample(id);
mout.EndBlock(verbose == 0); mout.EndBlock(verbose == 0);
} }
......
...@@ -40,7 +40,7 @@ public: ...@@ -40,7 +40,7 @@ public:
void Run(SampleSolution &solution) { void Run(SampleSolution &solution) {
mout.StartBlock("PDE Solver"); mout.StartBlock("PDE Solver");
vout(2) << solution.IdString() << endl; vout(2) << solution.id << endl;
run(solution); run(solution);
computeQ(solution); computeQ(solution);
computeCost(solution); computeCost(solution);
......
...@@ -30,9 +30,9 @@ int main(int argc, char **argv) { ...@@ -30,9 +30,9 @@ int main(int argc, char **argv) {
return MppTest( return MppTest(
MppTestBuilder(argc, argv). MppTestBuilder(argc, argv).
WithConfigEntry("PDESolverPlotting", 1). WithConfigEntry("PDESolverPlotting", 1).
WithConfigEntry("PDESolverVerbose", 1). WithConfigEntry("PDESolverVerbose", 2).
WithConfigEntry("AssembleVerbose", 1). WithConfigEntry("AssembleVerbose", 1).
WithConfigEntry("MeshesVerbose", 2). WithConfigEntry("MeshesVerbose", 1).
WithConfigEntry("NewtonVerbose", 1). WithConfigEntry("NewtonVerbose", 1).
WithConfigEntry("LinearVerbose", 1). WithConfigEntry("LinearVerbose", 1).
WithConfigEntry("MeshVerbose", 2). WithConfigEntry("MeshVerbose", 2).
......
Subproject commit 360aa55f8b139d7ae55fa6ee91128e098b1494fb Subproject commit 013875033410aee0dc883c6db261d14bb4532b1f
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