Commit ee108579 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

made DrawSample pure virtual and let each Problem handle it's own Generator

parent 80d6fe9a
Pipeline #157199 passed with stages
in 11 minutes and 8 seconds
......@@ -22,7 +22,7 @@ void NormalDistributionReal::updateCounter() {
internalCounter = internalCounter % 2;
}
Scalar NormalDistributionReal::EvalSample() {
Scalar NormalDistributionReal::EvalSample() const {
if (internalCounter)
return firstSample;
else
......
......@@ -23,7 +23,7 @@ public:
NormalDistributionReal(const Meshes &meshes) :
SampleGenerator(meshes), uniformDist(UniformDistributionReal(meshes, 0.0, 1.0)) {}
Scalar EvalSample() override;
Scalar EvalSample() const override;
string Name() const override {
return "NormalDistributionReal";
......@@ -47,7 +47,7 @@ public:
SampleGenerator(meshes),
normalDist(meshes) {}
Complex EvalSample() override {
Complex EvalSample() const override {
return sample;
}
......@@ -81,7 +81,7 @@ public:
sample.resize(sizeN);
}
RVector EvalSample() override {
RVector EvalSample() const override {
return sample;
}
......@@ -119,7 +119,7 @@ public:
return sample.size();
}
CVector EvalSample() override {
CVector EvalSample() const override {
return sample;
}
......@@ -153,7 +153,7 @@ public:
sample.resize(rows, cols);
}
RMatrix EvalSample() override {
RMatrix EvalSample() const override {
return sample;
}
......@@ -188,7 +188,7 @@ public:
sample.resize(rows, cols);
}
CMatrix EvalSample() override {
CMatrix EvalSample() const override {
return sample;
}
......
......@@ -48,31 +48,31 @@ public:
virtual size_t SampleSize() const { return 0; };
virtual T EvalSample() {
virtual T EvalSample() const {
Exit("Not implemented")
}
virtual T EvalSample(const Point &x) {
virtual T EvalSample(const Point &x) const {
Exit("Not implemented")
}
virtual T EvalSample(int n, const Point &x) {
virtual T EvalSample(int n, const Point &x) const {
Exit("Not implemented")
}
virtual T EvalSample(double t, const Point &x) {
virtual T EvalSample(double t, const Point &x) const {
Exit("Not implemented")
}
virtual T EvalSample(const cell &c) {
virtual T EvalSample(const cell &c) const {
Exit("Not implemented")
}
virtual T EvalSample(int n, const cell &c) {
virtual T EvalSample(int n, const cell &c) const {
Exit("Not implemented")
}
virtual T EvalSample(double t, const cell &c) {
virtual T EvalSample(double t, const cell &c) const {
Exit("Not implemented")
}
......
......@@ -53,7 +53,7 @@ public:
~UniformDistributionReal() { randNumberGen->free_sprng(); };
Scalar EvalSample() override {
Scalar EvalSample() const override {
if (internalCounter)
return firstSample;
else
......@@ -93,7 +93,7 @@ public:
sample.resize(sizeN);
}
RVector EvalSample() override {
RVector EvalSample() const override {
return sample;
}
......@@ -116,7 +116,8 @@ private:
}
public:
UniformDistributionRMatrix(const Meshes &meshes, int rows, int cols, double a, double b) :
UniformDistributionRMatrix(const Meshes &meshes, int rows, int cols, double a, double b)
:
SampleGenerator(meshes),
uniformDist(meshes, cols, a, b) {
if (rows != -1)
......@@ -129,7 +130,7 @@ public:
sample.resize(rows, cols);
}
RMatrix EvalSample() override {
RMatrix EvalSample() const override {
return sample;
}
......
......@@ -85,7 +85,7 @@ RVector CirculantEmbedding1D::GenerateGaussianField(const SampleID &id) {
return gaussianField;
}
Tensor CirculantEmbedding1D::EvalSample(const cell &c) {
Tensor CirculantEmbedding1D::EvalSample(const cell &c) const {
return sampleVec->operator()(c(), 0) * One;
}
......@@ -174,7 +174,7 @@ RMatrix CirculantEmbedding2D::GenerateGaussianField(const SampleID &id) {
return gaussianField;
}
Tensor CirculantEmbedding2D::EvalSample(const cell &c) {
Tensor CirculantEmbedding2D::EvalSample(const cell &c) const {
return sampleVec->operator()(c(), 0) * One;
}
......
......@@ -63,7 +63,7 @@ public:
RVector GenerateGaussianField(const SampleID &id);
Tensor EvalSample(const cell &c) override;
Tensor EvalSample(const cell &c) const override;
string Name() const override { return "CirculantEmbedding1D"; }
};
......@@ -120,7 +120,7 @@ public:
RMatrix GenerateGaussianField(const SampleID &id);
Tensor EvalSample(const cell &c) override;
Tensor EvalSample(const cell &c) const override;
string Name() const override { return "CirculantEmbedding2D"; }
};
......
......@@ -28,7 +28,7 @@ void HybridFaceNormalFluxGenerator::drawSample(const SampleID &id) {
assemble->SetNormalFlux(solutionFaceValues->U, solutionFaceFlux->U);
}
Scalar HybridFaceNormalFluxGenerator::EvalSample(int face, const cell &c) {
Scalar HybridFaceNormalFluxGenerator::EvalSample(int face, const cell &c) const {
RTLagrangeElement elem(solutionFaceFlux->U, c);
RTFaceElement faceElem(solutionFaceFlux->U, c, face);
return (solutionFaceFlux->U)(elem[face], 0) * elem.Sign(face) / faceElem.Area();
......@@ -40,7 +40,7 @@ HybridFaceNormalFluxGenerator::~HybridFaceNormalFluxGenerator() {
if (!solutionFaceFlux) delete solutionFaceFlux;
}
VectorField HybridCellFluxGenerator::EvalSample(const cell &c) {
VectorField HybridCellFluxGenerator::EvalSample(const cell &c) const {
RTLagrangeElement elem(generator.solutionFaceFlux->U, c);
VectorField F = zero;
double area = 0;
......
......@@ -14,24 +14,24 @@ private:
void drawSample(const SampleID &id) override;
public:
PDESolver *pdeSolver;
PDESolver *pdeSolver{};
SampleSolution *solutionFaceValues;
SampleSolution *solutionFaceValues{};
SampleSolution *solutionFaceFlux;
SampleSolution *solutionFaceFlux{};
HybridFaceNormalFluxGenerator(const Meshes &meshes) :
explicit HybridFaceNormalFluxGenerator(const Meshes &meshes) :
SampleGenerator(meshes) {
createPDESolver();
}
~HybridFaceNormalFluxGenerator();
~HybridFaceNormalFluxGenerator() override;
string Name() const override {
return "HybridFaceNormalFluxGenerator";
}
Scalar EvalSample(int face, const cell &c) override;
Scalar EvalSample(int face, const cell &c) const override;
};
class HybridCellFluxGenerator : public SampleGenerator<VectorField> {
......@@ -44,7 +44,7 @@ public:
SampleGenerator(meshes),
generator(generator) {}
VectorField EvalSample(const cell &c) override;
VectorField EvalSample(const cell &c) const override;
string Name() const override {
return "HybridCellFluxGenerator";
......
......@@ -11,62 +11,68 @@ protected:
const Meshes &meshes;
SampleGeneratorContainer genContainer;
public:
IStochasticProblem(const Meshes &meshes, const GeneratorNames &genNames) :
meshes(meshes), genContainer(genNames, meshes) {
explicit IStochasticProblem(const Meshes &meshes) : meshes(meshes) {
config.get("ProblemVerbose", verbose);
}
void DrawSample(const SampleID &id) {
genContainer.DrawSample(id);
}
virtual void DrawSample(const SampleID &id) = 0;
virtual string Name() const = 0;
};
class StochasticDummyProblem : public IStochasticProblem {
public:
StochasticDummyProblem(
const Meshes &meshes, GeneratorNames genNames = {}) :
IStochasticProblem(meshes, genNames) {}
explicit StochasticDummyProblem(const Meshes &meshes) :
IStochasticProblem(meshes) {}
virtual double GeneratorValue() {
return 0.0;
};
virtual string Name() const {
void DrawSample(const SampleID &id) override {}
string Name() const override {
return "StochasticDummyProblem";
}
};
class StochasticDummyScalarGeneratorProblem : public StochasticDummyProblem {
NormalDistributionReal scalarGenerator;
public:
StochasticDummyScalarGeneratorProblem(
const Meshes &meshes, GeneratorNames genNames = {"NormalDistributionReal"})
: StochasticDummyProblem(meshes, genNames) {}
explicit StochasticDummyScalarGeneratorProblem(const Meshes &meshes) :
StochasticDummyProblem(meshes),
scalarGenerator(NormalDistributionReal(meshes)) {}
void DrawSample(const SampleID &id) override {
scalarGenerator.DrawSample(id);
}
double GeneratorValue() override {
return this->genContainer.scalarGenerator->EvalSample();
return this->scalarGenerator.EvalSample();
}
virtual string Name() const override {
string Name() const override {
return "StochasticDummyScalarGeneratorProblem";
}
};
class StochasticDummyComplexGeneratorProblem : public StochasticDummyProblem {
NormalDistributionComplex complexGenerator;
public:
StochasticDummyComplexGeneratorProblem(
const Meshes &meshes, GeneratorNames genNames = {"NormalDistributionComplex"})
: StochasticDummyProblem(meshes, genNames) {}
explicit StochasticDummyComplexGeneratorProblem(const Meshes &meshes) :
StochasticDummyProblem(meshes),
complexGenerator(NormalDistributionComplex(meshes)) {}
void DrawSample(const SampleID &id) override {
complexGenerator.DrawSample(id);
}
double GeneratorValue() override {
return abs_compl(this->genContainer.complexGenerator->EvalSample());
return abs_compl(this->complexGenerator.EvalSample());
}
virtual string Name() const override {
string Name() const override {
return "StochasticDummyComplexGeneratorProblem";
}
};
......@@ -74,15 +80,16 @@ public:
// TODO
class StochasticDummyVectorFieldGeneratorProblem : public StochasticDummyProblem {
public:
StochasticDummyVectorFieldGeneratorProblem(
const Meshes &meshes, GeneratorNames genNames = {})
: StochasticDummyProblem(meshes, genNames) {}
explicit StochasticDummyVectorFieldGeneratorProblem(const Meshes &meshes)
: StochasticDummyProblem(meshes) {}
void DrawSample(const SampleID &id) override {}
double GeneratorValue() override {
return 0.0;
}
virtual string Name() const override {
string Name() const override {
return "StochasticDummyVectorFieldGeneratorProblem";
}
};
......@@ -90,75 +97,80 @@ public:
// TODO
class StochasticDummyTensorGeneratorProblem : public StochasticDummyProblem {
public:
StochasticDummyTensorGeneratorProblem(
const Meshes &meshes, GeneratorNames genNames = {}) :
StochasticDummyProblem(meshes, genNames) {}
explicit StochasticDummyTensorGeneratorProblem(const Meshes &meshes) :
StochasticDummyProblem(meshes) {}
void DrawSample(const SampleID &id) override {}
double GeneratorValue() override {
return 0.0;
}
virtual string Name() const override {
string Name() const override {
return "StochasticDummyTensorGeneratorProblem";
}
};
class StochasticDummyRVectorGeneratorProblem : public StochasticDummyProblem {
NormalDistributionRVector rVectorGenerator;
public:
StochasticDummyRVectorGeneratorProblem(
const Meshes &meshes, GeneratorNames genNames = {"NormalDistributionRVector"})
: StochasticDummyProblem(meshes, genNames) {}
explicit StochasticDummyRVectorGeneratorProblem(const Meshes &meshes) :
StochasticDummyProblem(meshes),
rVectorGenerator(NormalDistributionRVector(meshes)) {}
double GeneratorValue() override {
return this->genContainer.rVectorGenerator->EvalSample().Mean();
return this->rVectorGenerator.EvalSample().Mean();
}
virtual string Name() const override {
string Name() const override {
return "StochasticDummyRVectorGeneratorProblem";
}
};
class StochasticDummyCVectorGeneratorProblem : public StochasticDummyProblem {
NormalDistributionCVector cVectorGenerator;
public:
StochasticDummyCVectorGeneratorProblem(
const Meshes &meshes, GeneratorNames genNames = {"NormalDistributionCVector"})
: StochasticDummyProblem(meshes, genNames) {}
explicit StochasticDummyCVectorGeneratorProblem(const Meshes &meshes) :
StochasticDummyProblem(meshes),
cVectorGenerator(NormalDistributionCVector(meshes)) {}
double GeneratorValue() override {
return abs_compl(this->genContainer.cVectorGenerator->EvalSample().Mean());
return abs_compl(this->cVectorGenerator.EvalSample().Mean());
}
virtual string Name() const override {
string Name() const override {
return "StochasticDummyCVectorGeneratorProblem";
}
};
class StochasticDummyRMatrixGeneratorProblem : public StochasticDummyProblem {
NormalDistributionRMatrix rMatrixGenerator;
public:
StochasticDummyRMatrixGeneratorProblem(
const Meshes &meshes, GeneratorNames genNames = {"NormalDistributionRMatrix"})
: StochasticDummyProblem(meshes, genNames) {}
explicit StochasticDummyRMatrixGeneratorProblem(const Meshes &meshes) :
StochasticDummyProblem(meshes),
rMatrixGenerator(NormalDistributionRMatrix(meshes)) {}
double GeneratorValue() override {
return 0.0;
return abs_compl(this->rMatrixGenerator.EvalSample().Mean());
}
virtual string Name() const override {
string Name() const override {
return "StochasticDummyRMatrixGeneratorProblem";
}
};
class StochasticDummyCMatrixGeneratorProblem : public StochasticDummyProblem {
NormalDistributionCMatrix cMatrixGenerator;
public:
StochasticDummyCMatrixGeneratorProblem(
const Meshes &meshes, GeneratorNames genNames = {"NormalDistributionCMatrix"})
: StochasticDummyProblem(meshes, genNames) {}
explicit StochasticDummyCMatrixGeneratorProblem(const Meshes &meshes) :
StochasticDummyProblem(meshes),
cMatrixGenerator(NormalDistributionCMatrix(meshes)) {}
double GeneratorValue() override {
return 0.0;
return abs_compl(this->cMatrixGenerator.EvalSample().Mean());
}
virtual string Name() const override {
string Name() const override {
return "StochasticDummyCMatrixGeneratorProblem";
}
};
......
......@@ -6,8 +6,8 @@
class IStochasticEllipticProblem : public IStochasticProblem {
public:
IStochasticEllipticProblem(const Meshes &meshes, GeneratorNames genNames = {})
: IStochasticProblem(meshes, genNames) {}
explicit IStochasticEllipticProblem(const Meshes &meshes) :
IStochasticProblem(meshes) {}
virtual Scalar Solution(const Point &x) const = 0;
......@@ -17,16 +17,22 @@ public:
virtual Tensor Permeability(const cell &c) const = 0;
void Permeability(Vector &kappa) {
void Permeability(Vector &kappa) const {
for (cell c = kappa.cells(); c != kappa.cells_end(); ++c)
kappa(c(), 0) = Permeability(c)[0][0];
}
};
class StochasticLaplace1D : public IStochasticEllipticProblem {
CirculantEmbedding1D tensorGenerator;
public:
explicit StochasticLaplace1D(const Meshes &meshes) :
IStochasticEllipticProblem(meshes, GeneratorNames{"CirculantEmbedding"}) {};
IStochasticEllipticProblem(meshes),
tensorGenerator(CirculantEmbedding1D(meshes)) {};
void DrawSample(const SampleID &id) override {
tensorGenerator.DrawSample(id);
}
Scalar Solution(const Point &x) const override {
return 1 - x[0];
......@@ -41,7 +47,7 @@ public:
}
Tensor Permeability(const cell &c) const override {
return this->genContainer.tensorGenerator->EvalSample(c);
return this->tensorGenerator.EvalSample(c);
}
string Name() const override { return "StochasticLaplace1D"; }
......@@ -49,7 +55,10 @@ public:
class Laplace1D : public IStochasticEllipticProblem {
public:
explicit Laplace1D(const Meshes &meshes) : IStochasticEllipticProblem(meshes) {};
explicit Laplace1D(const Meshes &meshes) :
IStochasticEllipticProblem(meshes) {};
void DrawSample(const SampleID &id) override {}
Scalar Solution(const Point &x) const override {
return 1 - x[0];
......@@ -71,9 +80,15 @@ public:
};
class StochasticLaplace2D : public IStochasticEllipticProblem {
CirculantEmbedding2D tensorGenerator;
public:
explicit StochasticLaplace2D(const Meshes &meshes) :
IStochasticEllipticProblem(meshes, GeneratorNames{"CirculantEmbedding"}) {}
IStochasticEllipticProblem(meshes),
tensorGenerator(CirculantEmbedding2D(meshes)) {}
void DrawSample(const SampleID &id) override {
tensorGenerator.DrawSample(id);
}
Scalar Solution(const Point &x) const override {
return -x[1];
......@@ -86,16 +101,22 @@ public:
Scalar Load(const Point &x) const override { return 0.0; }
Tensor Permeability(const cell &c) const override {
return this->genContainer.tensorGenerator->EvalSample(c);
return this->tensorGenerator.EvalSample(c);
}
string Name() const override { return "StochasticLaplace2D"; }
};
class StochasticLaplace2DTest : public IStochasticEllipticProblem {
UniformDistributionRVector rVectorGenerator;
public:
explicit StochasticLaplace2DTest(const Meshes &meshes) :
IStochasticEllipticProblem(meshes, GeneratorNames{"UniformDistributionRVector"}) {}
IStochasticEllipticProblem(meshes),
rVectorGenerator(UniformDistributionRVector(meshes, 2, -1.0, 1.0)) {}
void DrawSample(const SampleID &id) override {
rVectorGenerator.DrawSample(id);
}
Scalar Solution(const Point &x) const override {
return -x[1];
......@@ -110,9 +131,9 @@ public:
Tensor Permeability(const cell &c) const override {
if (c()[1] > 0.125 && c()[1] < 0.375) {
if (c()[0] > 0.125 && c()[0] < 0.375)
return (1 + 0.9 * this->genContainer.rVectorGenerator->EvalSample()[0]) * One;
return (1 + 0.9 * this->rVectorGenerator.EvalSample()[0]) * One;
if (c()[0] > 0.625 && c()[0] < 0.875)
return (1 + 0.9 * this->genContainer.rVectorGenerator->EvalSample()[1]) * One;
return (1 + 0.9 * this->rVectorGenerator.EvalSample()[1]) * One;
}
return One;
}
......@@ -124,6 +145,8 @@ class Laplace2D : public IStochasticEllipticProblem {
public:
explicit Laplace2D(const Meshes &meshes) : IStochasticEllipticProblem(meshes) {}
void DrawSample(const SampleID &id) override {}
Scalar Solution(const Point &x) const override {
return -x[1];
}
......
......@@ -38,7 +38,7 @@ protected:
public:
IStochasticReactionProblem(const Meshes &meshes, GeneratorNames genNames={}) :
IStochasticProblem(meshes, genNames) {
IStochasticProblem(meshes) {
config.get("Diffusion", diffusion);
config.get("Convection", convection);
config.get("Reaction", reaction);
......
......@@ -2,7 +2,7 @@
IStochasticTransportProblem *
CreateStochasticTransportProblem(std::string problemName, const Meshes &meshes) {
CreateStochasticTransportProblem(const string &problemName, const Meshes &meshes) {
if (problemName == "StochasticPollution1D")
return new StochasticPollution1D(meshes);
if (problemName == "Pollution1D")
......
......@@ -18,7 +18,7 @@ private:
public:
explicit IStochasticTransportProblem(
const Meshes &meshes, const GeneratorNames &genNames = {})
: IStochasticProblem(meshes, genNames) {
: IStochasticProblem(meshes) {
config.get("CFL", CFL);
config.get("t0", t0);