Commit 464e2e5f authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

refactored Sample and SampleID

parent 6faafcd7
#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();
explicit SampleSolution(IDiscretization *disc,
const std::string &name = "U") :
id(name), U(Vector(0.0, (*disc))) {
}
SampleSolution(IDiscretization *disc, const SampleID &id,
const std::string &name = "U") :
id(id), U(Vector(*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;
}
};
......
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