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() {
pdeSolver->DrawSample(fineId);
pdeSolver->Run(fineSolution);
if (onlyFine) {
coarseSolution.Init();
} else {
if (!onlyFine) {
pdeSolver->DrawSample(coarseId);
pdeSolver->Run(coarseSolution);
}
......
#ifndef SAMPLE_HPP
#define SAMPLE_HPP
#include "Algebra.hpp"
#include "Vector.hpp"
#include <string>
#include <utility>
struct SampleID {
public:
int fLevel;
std::string name = "U";
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") :
fLevel(level), cLevel( (level > 0) ? (level - 1) : 0),
number(number), coarse(coarse), name(name) {}
SampleID(int level, int number, bool coarse, std::string name = "U") :
fLevel(level), cLevel((level > 0) ? (level - 1) : 0),
number(number), coarse(coarse), name(std::move(name)) {}
int level() const {
if (coarse) return cLevel;
else return fLevel;
};
std::string IdString(const std::string &name_) const {
return name_ + "." + std::to_string(fLevel)
std::string IdString() const {
return name + "." + std::to_string(fLevel)
+ "." + std::to_string((int) coarse)
+ "." + std::to_string(number);
}
std::string IdString() const {
return IdString(name);
friend Logging &operator<<(Logging &s, const SampleID &id) {
return s << id.IdString();
}
};
// Todo remove init
struct SampleSolution {
SampleID id;
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
SampleSolution(IDiscretization *disc, const std::string &name = "U") :
U(Vector((*disc))) {
this->id.name = name;
Init();
}
SampleSolution(IDiscretization *disc, const SampleID &id,
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;
Init();
}
SampleSolution(const Vector &U, const SampleID &id, const std::string &name = "U") :
id(id), U(U) {
this->id.name = name;
const SampleID &Id() const {
return id;
}
std::string IdString() const {
return id.IdString();
}
const SampleID &Id() const {
return id;
}
void Init() {
Q = 0.0;
C = 0.0;
U = 0.0;
W = 0.0;
friend Logging &operator<<(Logging &s, const SampleSolution &sol) {
return s << sol.id << endl << "Q=" << sol.Q <<
", C=" << sol.C << ", W=" << sol.W << endl;
}
};
......
......@@ -39,7 +39,7 @@ public:
void DrawSample(const SampleID &id) {
mout.StartBlock(Name());
vout(1) << id.IdString() << endl;
vout(1) << id << endl;
drawSample(id);
mout.EndBlock(verbose == 0);
}
......
......@@ -40,7 +40,7 @@ public:
void Run(SampleSolution &solution) {
mout.StartBlock("PDE Solver");
vout(2) << solution.IdString() << endl;
vout(2) << solution.id << endl;
run(solution);
computeQ(solution);
computeCost(solution);
......
......@@ -30,9 +30,9 @@ int main(int argc, char **argv) {
return MppTest(
MppTestBuilder(argc, argv).
WithConfigEntry("PDESolverPlotting", 1).
WithConfigEntry("PDESolverVerbose", 1).
WithConfigEntry("PDESolverVerbose", 2).
WithConfigEntry("AssembleVerbose", 1).
WithConfigEntry("MeshesVerbose", 2).
WithConfigEntry("MeshesVerbose", 1).
WithConfigEntry("NewtonVerbose", 1).
WithConfigEntry("LinearVerbose", 1).
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