Commit 73e3e381 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

started with new generators and renaming sample id

parent a1c195de
Pipeline #118479 passed with stages
in 7 minutes and 35 seconds
#include "Sample.hpp"
int Sample::MGLevel() const {
int SampleID::MGLevel() const {
return level.MGLevel(coarse);
}
std::string Sample::Str() const {
std::string SampleID::Str() const {
return "l:" + std::to_string(level.fine) +
"-m:" + std::to_string(number) +
"-c:" + std::to_string((int) coarse);
......
......@@ -9,16 +9,16 @@
#include <string>
struct Sample {
struct SampleID {
Level level;
int number;
bool coarse;
Sample() {}
SampleID() {}
Sample(Level level, int number, bool coarse) :
SampleID(Level level, int number, bool coarse) :
level(level), number(number), coarse(coarse) {}
int MGLevel() const;
......@@ -30,7 +30,7 @@ struct Sample {
struct SampleSolution {
std::string name = "U";
Sample id;
SampleID id;
double Q;
......@@ -48,7 +48,7 @@ struct SampleSolution {
Init();
}
SampleSolution(MatrixGraphs *solMGraphs, const Sample &id) :
SampleSolution(MatrixGraphs *solMGraphs, const SampleID &id) :
id(id), U(Vector((*solMGraphs)[id.MGLevel()])) {
Init();
}
......
......@@ -14,8 +14,8 @@ void MonteCarlo::Method() {
void MonteCarlo::method() {
Sample coarseId;
Sample fineId;
SampleID coarseId;
SampleID fineId;
SampleSolution coarseSolution(solMGraphs, level.mGcoarse);
SampleSolution fineSolution(solMGraphs, level.mGfine);
......@@ -35,7 +35,7 @@ void MonteCarlo::method() {
}
}
void MonteCarlo::computeSampleSolution(int m, Sample &id, SampleSolution &solution) {
void MonteCarlo::computeSampleSolution(int m, SampleID &id, SampleSolution &solution) {
id.number = m;
solution.id = id;
pdeSolver->DrawSample(id);
......
......@@ -13,7 +13,7 @@ protected:
void method();
void computeSampleSolution(int m, Sample &id, SampleSolution &solution);
void computeSampleSolution(int m, SampleID &id, SampleSolution &solution);
public:
Level level;
......
......@@ -16,7 +16,7 @@ public:
explicit IStochasticEllipticAssemble(IStochasticEllipticProblem *problem) :
problem(problem) {};
void DrawSample(const Sample &id) {
void DrawSample(const SampleID &id) {
problem->DrawSample(id);
}
......
......@@ -23,7 +23,7 @@ public:
InfoEntries problemEntries = problem->GetInfoEntries();
};
void DrawSample(const Sample &id) {
void DrawSample(const SampleID &id) {
problem->DrawSample(id);
}
......
......@@ -87,7 +87,7 @@ public:
virtual IStochasticProblem *GetProblem() const = 0;
virtual void DrawSample(const Sample &id) = 0;
virtual void DrawSample(const SampleID &id) = 0;
};
class EllipticPDESolver : public PDESolver {
......@@ -126,7 +126,7 @@ public:
return assemble->GetProblem();
}
void DrawSample(const Sample &id) override {
void DrawSample(const SampleID &id) override {
assemble->DrawSample(id);
}
};
......@@ -182,7 +182,7 @@ public:
return assemble->GetProblem();
}
void DrawSample(const Sample &id) override {
void DrawSample(const SampleID &id) override {
assemble->DrawSample(id);
}
};
......
......@@ -42,7 +42,7 @@ public:
generators.clear();
};
void DrawSample(const Sample &id) {
void DrawSample(const SampleID &id) {
for (auto &gen : generators)
gen.second->DrawSample(id);
}
......
#include "CirculantEmbedding.hpp"
void CirculantEmbedding1D::generateFineSample(Sample id,
void CirculantEmbedding1D::generateFineSample(SampleID id,
Vector *&fineSample,
Vector *&coarseSample) {
fineSample = new Vector(cellMGraphs[id.level.mGfine]);
......@@ -30,7 +30,7 @@ void CirculantEmbedding1D::generateFineSample(Sample id,
coarseSample = nullptr;
}
void CirculantEmbedding1D::generateCoarseSample(Sample id,
void CirculantEmbedding1D::generateCoarseSample(SampleID id,
Vector *&fineSample,
Vector *&coarseSample) {
coarseSample = new Vector(cellMGraphs[id.level.mGcoarse]);
......@@ -157,7 +157,7 @@ SqrtEigenValues1D CirculantEmbedding1D::computeSqrtEV() {
return sqrt_ev_return;
}
void CirculantEmbedding2D::generateFineSample(Sample id,
void CirculantEmbedding2D::generateFineSample(SampleID id,
Vector *&fineSample,
Vector *&coarseSample) {
fineSample = new Vector(cellMGraphs[id.level.mGfine]);
......@@ -189,7 +189,7 @@ void CirculantEmbedding2D::generateFineSample(Sample id,
coarseSample = nullptr;
}
void CirculantEmbedding2D::generateCoarseSample(Sample id,
void CirculantEmbedding2D::generateCoarseSample(SampleID id,
Vector *&fineSample,
Vector *&coarseSample) {
coarseSample = new Vector(cellMGraphs[id.level.mGcoarse]);
......
......@@ -62,11 +62,11 @@ public:
rnmg = new RandomNumberManager(streamnum, nstreams, gtype);
}
virtual void generateFineSample(Sample id,
virtual void generateFineSample(SampleID id,
Vector *&fineSample,
Vector *&coarseSample) = 0;
virtual void generateCoarseSample(Sample id,
virtual void generateCoarseSample(SampleID id,
Vector *&fineSample,
Vector *&coarseSample) = 0;
......@@ -94,11 +94,11 @@ public:
numberOfCellsEmbedded = sqrtEigenvalues.size();
}
void generateFineSample(Sample id,
void generateFineSample(SampleID id,
Vector *&fineSample,
Vector *&coarseSample) override;
void generateCoarseSample(Sample id,
void generateCoarseSample(SampleID id,
Vector *&fineSample,
Vector *&coarseSample) override;
......@@ -144,11 +144,11 @@ public:
numberOfCellsEmbedded[1] = sqrtEigenvalues[0].size();
}
void generateFineSample(Sample id,
void generateFineSample(SampleID id,
Vector *&fineSample,
Vector *&coarseSample) override;
void generateCoarseSample(Sample id,
void generateCoarseSample(SampleID id,
Vector *&fineSample,
Vector *&coarseSample) override;
......@@ -180,7 +180,7 @@ private:
Vector *coarseSample = nullptr;
protected:
void drawSample(const Sample &id) override {
void drawSample(const SampleID &id) override {
if (!id.coarse) {
circulantEmbeddings[id.level.fine]->generateFineSample(id, fineSample,
coarseSample);
......
......@@ -39,7 +39,7 @@ protected:
Newton *newton;
Meshes &meshes;
void drawSample(const Sample &id) override {
void drawSample(const SampleID &id) override {
if (!id.coarse) {
generateFineSample(id);
// if (plotting)
......@@ -83,7 +83,7 @@ public:
string Name() const override { return "Hybrid Flux Generator"; }
void generateFineSample(Sample id) {
void generateFineSample(SampleID id) {
cellFlux = new Vector(cellMGraphs[id.level.mGfine]);
faceValues = new Vector(faceMGraphs[id.level.mGfine]);
faceFlux = new Vector(faceMGraphs[id.level.mGfine]);
......@@ -94,7 +94,7 @@ public:
assemble->SetFlux(*faceValues, *cellFlux);
}
void generateCoarseSample(Sample id) {
void generateCoarseSample(SampleID id) {
cellFlux = new Vector(cellMGraphs[id.level.mGcoarse]);
faceValues = new Vector(faceMGraphs[id.level.mGcoarse]);
faceFlux = new Vector(faceMGraphs[id.level.mGcoarse]);
......
#ifndef MLMC_RNG_UTILITIES_HPP
#define MLMC_RNG_UTILITIES_HPP
#include "SampleGenerator.hpp"
#include "sprng_cpp.h"
#include <math.h>
......@@ -32,4 +34,18 @@ public:
~RandomNumberManager() { sprng_->free_sprng(); };
};
class NormalDistribution : public SampleGenerator {
virtual string Name() const {
return "NormalDistribution";
};
};
class UniformDistribution : public SampleGenerator {
virtual string Name() const {
return "UniformDistribution";
};
};
#endif //MLMC_RNG_UTILITIES_HPP
......@@ -12,7 +12,7 @@ protected:
int verbose = 0;
virtual void drawSample(const Sample &id) = 0;
virtual void drawSample(const SampleID &id) = 0;
public:
Meshes &meshes;
......@@ -24,7 +24,7 @@ public:
virtual ~SampleGenerator() {}
void DrawSample(const Sample &id) {
void DrawSample(const SampleID &id) {
mout.StartBlock(Name());
vout(1) << id.Str() << endl;
drawSample(id);
......@@ -120,7 +120,7 @@ class DummyGenerator : public SampleGenerator {
public:
DummyGenerator(Meshes &meshes) : SampleGenerator(meshes) {}
void drawSample(const Sample &id) override {
void drawSample(const SampleID &id) override {
vout(1) << "Dummy Generator" << endl;
};
......
......@@ -11,19 +11,19 @@ protected:
std::vector<MatrixGraphs *> someMGraphs;
std::vector<Sample> dummyIDs;
std::vector<SampleID> dummyIDs;
PlotMap plotMap;
TestPlotMap(const std::string &meshName) {
dummyIDs = {
Sample(Level(0, 0), false, -1),
Sample(Level(1, 0), false, -1),
Sample(Level(2, 0), false, -1),
Sample(Level(3, 0), false, -1),
Sample(Level(4, 0), false, -1),
Sample(Level(5, 0), false, -1),
Sample(Level(6, 0), false, -1)
SampleID(Level(0, 0), false, -1),
SampleID(Level(1, 0), false, -1),
SampleID(Level(2, 0), false, -1),
SampleID(Level(3, 0), false, -1),
SampleID(Level(4, 0), false, -1),
SampleID(Level(5, 0), false, -1),
SampleID(Level(6, 0), false, -1)
};
meshes = createTestMeshes(meshName, dummyIDs.back().level.pLevel,
dummyIDs.back().level.fine);
......
......@@ -19,7 +19,7 @@ protected:
MatrixGraphs *mGraphs;
Sample dummyID;
SampleID dummyID;
TestPDESolver(const std::string &meshName) {
dummyID.level = Level(6, 0);
......
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