Commit 5d478feb authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

made meshes const

parent 959a4f1f
Pipeline #157166 passed with stages
in 11 minutes and 10 seconds
......@@ -20,7 +20,7 @@ private:
void updateCounter();
public:
NormalDistributionReal(Meshes &meshes) :
NormalDistributionReal(const Meshes &meshes) :
SampleGenerator(meshes), uniformDist(UniformDistributionReal(meshes, 0.0, 1.0)) {}
Scalar EvalSample() override;
......@@ -43,7 +43,7 @@ private:
}
public:
NormalDistributionComplex(Meshes &meshes) :
NormalDistributionComplex(const Meshes &meshes) :
SampleGenerator(meshes),
normalDist(meshes) {}
......@@ -68,7 +68,7 @@ private:
}
public:
NormalDistributionRVector(Meshes &meshes, int size = -1) :
NormalDistributionRVector(const Meshes &meshes, int size = -1) :
SampleGenerator(meshes),
normalDist(meshes) {
if (size != -1)
......@@ -102,7 +102,7 @@ private:
}
public:
NormalDistributionCVector(Meshes &meshes, int size = -1) :
NormalDistributionCVector(const Meshes &meshes, int size = -1) :
SampleGenerator(meshes),
normalDist(meshes) {
if (size != -1)
......@@ -140,7 +140,7 @@ private:
}
public:
NormalDistributionRMatrix(Meshes &meshes, int rows = -1, int cols = -1) :
NormalDistributionRMatrix(const Meshes &meshes, int rows = -1, int cols = -1) :
SampleGenerator(meshes),
normalDist(meshes, cols) {
if (rows != -1)
......@@ -174,7 +174,7 @@ private:
}
public:
NormalDistributionCMatrix(Meshes &meshes, int rows = -1, int cols = -1) :
NormalDistributionCMatrix(const Meshes &meshes, int rows = -1, int cols = -1) :
SampleGenerator(meshes),
normalDist(meshes, cols) {
if (rows != -1)
......
......@@ -27,9 +27,9 @@ protected:
virtual void drawSample(const SampleID &id) = 0;
public:
Meshes &meshes; // todo make const ref or remove completely
const Meshes &meshes;
explicit SampleGenerator(Meshes &meshes)
explicit SampleGenerator(const Meshes &meshes)
: meshes(meshes), commSplit(meshes.CommSplit()) {
// Todo add prefix
config.get("GeneratorVerbose", verbose);
......@@ -114,7 +114,7 @@ public:
class ScalarDummy : public SampleGenerator<Scalar> {
public:
ScalarDummy(Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
ScalarDummy(const Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
void drawSample(const SampleID &id) override {
vout(1) << "Dummy Generator" << endl;
......@@ -125,7 +125,7 @@ public:
class ComplexDummy : public SampleGenerator<Complex> {
public:
ComplexDummy(Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
ComplexDummy(const Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
void drawSample(const SampleID &id) override {
vout(1) << "Dummy Generator" << endl;
......
#include "SampleGeneratorContainer.hpp"
void SampleGeneratorContainer::init(Meshes &meshes, GeneratorNames names) {
void SampleGeneratorContainer::init(const Meshes &meshes, GeneratorNames names) {
for (auto const &genName: names) {
if (genName == "NormalDistributionReal")
scalarGenerator = new NormalDistributionReal(meshes);
......
......@@ -12,7 +12,7 @@ typedef std::vector<std::string> GeneratorNames;
class SampleGeneratorContainer {
void init(Meshes &meshes, GeneratorNames names);
void init(const Meshes &meshes, GeneratorNames names);
public:
SampleGenerator<Scalar> *scalarGenerator = nullptr;
......@@ -31,27 +31,19 @@ public:
SampleGenerator<CMatrix> *cMatrixGenerator = nullptr;
SampleGeneratorContainer(GeneratorNames names, Meshes &meshes) {
SampleGeneratorContainer(const GeneratorNames &names, const Meshes &meshes) {
init(meshes, names);
}
~SampleGeneratorContainer() {
if (scalarGenerator != nullptr)
delete scalarGenerator;
if (complexGenerator != nullptr)
delete complexGenerator;
if (vectorFieldGenerator != nullptr)
delete vectorFieldGenerator;
if (tensorGenerator != nullptr)
delete tensorGenerator;
if (rVectorGenerator != nullptr)
delete rVectorGenerator;
if (cVectorGenerator != nullptr)
delete cVectorGenerator;
if (rMatrixGenerator != nullptr)
delete rMatrixGenerator;
if (cMatrixGenerator != nullptr)
delete cMatrixGenerator;
delete scalarGenerator;
delete complexGenerator;
delete vectorFieldGenerator;
delete tensorGenerator;
delete rVectorGenerator;
delete cVectorGenerator;
delete rMatrixGenerator;
delete cMatrixGenerator;
}
void DrawSample(const SampleID &id);
......
......@@ -43,7 +43,7 @@ private:
};
public:
UniformDistributionReal(Meshes &meshes, double a, double b) :
UniformDistributionReal(const Meshes &meshes, double a, double b) :
a(a), b(b), SampleGenerator(meshes) {
this->randNumberGen = SelectType(GTYPE);
this->randNumberGen->init_sprng(
......@@ -80,7 +80,7 @@ private:
}
public:
UniformDistributionRVector(Meshes &meshes, int size, double a, double b) :
UniformDistributionRVector(const Meshes &meshes, int size, double a, double b) :
SampleGenerator(meshes),
uniformDist(meshes, a, b) {
if (size != -1)
......
......@@ -42,7 +42,7 @@ protected:
void drawSample(const SampleID &id) override;
public:
CirculantEmbedding1D(Meshes &meshes) :
CirculantEmbedding1D(const Meshes &meshes) :
SampleGenerator(meshes), disc(meshes, 0), generator(meshes),
covariance(CovarianceFunction1D()) {
......@@ -99,7 +99,7 @@ protected:
public:
explicit CirculantEmbedding2D(
Meshes &meshes, CovarianceFunction2D covariance=CovarianceFunction2D()) :
const Meshes &meshes, CovarianceFunction2D covariance= CovarianceFunction2D()) :
SampleGenerator(meshes), disc(meshes, 0), generator(meshes),
covariance(covariance) {
......
......@@ -20,7 +20,7 @@ public:
SampleSolution *solutionFaceFlux;
HybridFaceNormalFluxGenerator(Meshes &meshes) :
HybridFaceNormalFluxGenerator(const Meshes &meshes) :
SampleGenerator(meshes) {
createPDESolver();
}
......
......@@ -26,7 +26,7 @@ protected:
void plotSolution(SampleSolution &solution) override;
public:
EllipticPDESolver(IStochasticEllipticAssemble *assemble, Meshes &meshes,
EllipticPDESolver(IStochasticEllipticAssemble *assemble, const Meshes &meshes,
const std::string &quantity = "L2",
const std::string &costMeasure = "size") :
PDESolver(meshes, quantity, costMeasure),
......
......@@ -18,7 +18,7 @@ protected:
int plotting = 0;
Meshes &meshes;
const Meshes &meshes;
std::string quantity;
......@@ -33,7 +33,7 @@ protected:
virtual void plotSolution(SampleSolution &solution) = 0;
public:
PDESolver(Meshes &meshes, const std::string &quantity,
PDESolver(const Meshes &meshes, const std::string &quantity,
const std::string &costMeasure) :
meshes(meshes), quantity(quantity), costMeasure(costMeasure) {
config.get("PDESolverVerbose", verbose);
......@@ -95,7 +95,7 @@ protected:
public:
DummyPDESolver(IStochasticDummyAssemble *assemble,
Meshes &meshes,
const Meshes &meshes,
const std::string &quantity = "L2",
const std::string &costMeasure = "size") :
PDESolver(meshes, quantity, costMeasure), assemble(assemble) {
......
......@@ -3,7 +3,7 @@
#include "TransportPDESolver.hpp"
PDESolver *PDESolverCreator::Create(Meshes &meshes) {
PDESolver *PDESolverCreator::Create(const Meshes &meshes) {
if (_model == "LagrangeElliptic")
return new EllipticPDESolver(
new LagrangeEllipticAssemble(
......
......@@ -59,7 +59,7 @@ public:
return "Interval";
}
PDESolver *Create(Meshes &meshes);
PDESolver *Create(const Meshes &meshes);
std::unique_ptr<PDESolver> CreateUnique(Meshes &meshes);
};
......
......@@ -23,7 +23,7 @@ protected:
public:
TransportPDESolver(IStochasticLinearTransportAssemble *assemble,
Meshes &meshes,
const Meshes &meshes,
const std::string &quantity = "L2",
const std::string &costMeasure = "size") :
PDESolver(meshes, quantity, costMeasure), assemble(assemble),
......
#include "IStochasticProblem.hpp"
StochasticDummyProblem *
CreateStochasticDummyProblem(const std::string &problemName, Meshes &meshes) {
CreateStochasticDummyProblem(const std::string &problemName, const Meshes &meshes) {
if (problemName == "StochasticDummyProblem")
return new StochasticDummyProblem(meshes);
if (problemName == "StochasticDummyScalarGeneratorProblem")
......
......@@ -4,8 +4,6 @@
#include "Sample.hpp"
#include "SampleGeneratorContainer.hpp"
#include "Algebra.hpp"
class IStochasticProblem {
protected:
......@@ -16,7 +14,7 @@ protected:
SampleGeneratorContainer genContainer;
public:
IStochasticProblem(Meshes &meshes, GeneratorNames genNames) :
IStochasticProblem(const Meshes &meshes, const GeneratorNames &genNames) :
meshes(meshes), genContainer(genNames, meshes) {
config.get("ProblemVerbose", verbose);
}
......@@ -31,7 +29,7 @@ public:
class StochasticDummyProblem : public IStochasticProblem {
public:
StochasticDummyProblem(
Meshes &meshes, GeneratorNames genNames = {}) :
const Meshes &meshes, GeneratorNames genNames = {}) :
IStochasticProblem(meshes, genNames) {}
virtual double GeneratorValue() {
......@@ -46,7 +44,7 @@ public:
class StochasticDummyScalarGeneratorProblem : public StochasticDummyProblem {
public:
StochasticDummyScalarGeneratorProblem(
Meshes &meshes, GeneratorNames genNames = {"NormalDistributionReal"})
const Meshes &meshes, GeneratorNames genNames = {"NormalDistributionReal"})
: StochasticDummyProblem(meshes, genNames) {}
double GeneratorValue() override {
......@@ -61,7 +59,7 @@ public:
class StochasticDummyComplexGeneratorProblem : public StochasticDummyProblem {
public:
StochasticDummyComplexGeneratorProblem(
Meshes &meshes, GeneratorNames genNames = {"NormalDistributionComplex"})
const Meshes &meshes, GeneratorNames genNames = {"NormalDistributionComplex"})
: StochasticDummyProblem(meshes, genNames) {}
double GeneratorValue() override {
......@@ -77,7 +75,7 @@ public:
class StochasticDummyVectorFieldGeneratorProblem : public StochasticDummyProblem {
public:
StochasticDummyVectorFieldGeneratorProblem(
Meshes &meshes, GeneratorNames genNames = {})
const Meshes &meshes, GeneratorNames genNames = {})
: StochasticDummyProblem(meshes, genNames) {}
double GeneratorValue() override {
......@@ -93,7 +91,7 @@ public:
class StochasticDummyTensorGeneratorProblem : public StochasticDummyProblem {
public:
StochasticDummyTensorGeneratorProblem(
Meshes &meshes, GeneratorNames genNames = {}) :
const Meshes &meshes, GeneratorNames genNames = {}) :
StochasticDummyProblem(meshes, genNames) {}
double GeneratorValue() override {
......@@ -108,7 +106,7 @@ public:
class StochasticDummyRVectorGeneratorProblem : public StochasticDummyProblem {
public:
StochasticDummyRVectorGeneratorProblem(
Meshes &meshes, GeneratorNames genNames = {"NormalDistributionRVector"})
const Meshes &meshes, GeneratorNames genNames = {"NormalDistributionRVector"})
: StochasticDummyProblem(meshes, genNames) {}
double GeneratorValue() override {
......@@ -123,7 +121,7 @@ public:
class StochasticDummyCVectorGeneratorProblem : public StochasticDummyProblem {
public:
StochasticDummyCVectorGeneratorProblem(
Meshes &meshes, GeneratorNames genNames = {"NormalDistributionCVector"})
const Meshes &meshes, GeneratorNames genNames = {"NormalDistributionCVector"})
: StochasticDummyProblem(meshes, genNames) {}
double GeneratorValue() override {
......@@ -138,7 +136,7 @@ public:
class StochasticDummyRMatrixGeneratorProblem : public StochasticDummyProblem {
public:
StochasticDummyRMatrixGeneratorProblem(
Meshes &meshes, GeneratorNames genNames = {"NormalDistributionRMatrix"})
const Meshes &meshes, GeneratorNames genNames = {"NormalDistributionRMatrix"})
: StochasticDummyProblem(meshes, genNames) {}
double GeneratorValue() override {
......@@ -153,7 +151,7 @@ public:
class StochasticDummyCMatrixGeneratorProblem : public StochasticDummyProblem {
public:
StochasticDummyCMatrixGeneratorProblem(
Meshes &meshes, GeneratorNames genNames = {"NormalDistributionCMatrix"})
const Meshes &meshes, GeneratorNames genNames = {"NormalDistributionCMatrix"})
: StochasticDummyProblem(meshes, genNames) {}
double GeneratorValue() override {
......@@ -166,6 +164,6 @@ public:
};
StochasticDummyProblem *
CreateStochasticDummyProblem(const std::string &problemName, Meshes &meshes);
CreateStochasticDummyProblem(const std::string &problemName, const Meshes &meshes);
#endif
......@@ -2,7 +2,7 @@
IStochasticEllipticProblem *
CreateStochasticEllipticProblem(const string &problemName, Meshes &meshes) {
CreateStochasticEllipticProblem(const string &problemName, const Meshes &meshes) {
if (problemName == "StochasticLaplace1D")
return new StochasticLaplace1D(meshes);
if (problemName == "Laplace1D")
......
......@@ -6,7 +6,7 @@
class IStochasticEllipticProblem : public IStochasticProblem {
public:
IStochasticEllipticProblem(Meshes &meshes, GeneratorNames genNames = {})
IStochasticEllipticProblem(const Meshes &meshes, GeneratorNames genNames = {})
: IStochasticProblem(meshes, genNames) {}
virtual Scalar Solution(const Point &x) const = 0;
......@@ -25,7 +25,7 @@ public:
class StochasticLaplace1D : public IStochasticEllipticProblem {
public:
StochasticLaplace1D(Meshes &meshes) :
explicit StochasticLaplace1D(const Meshes &meshes) :
IStochasticEllipticProblem(meshes, GeneratorNames{"CirculantEmbedding"}) {};
Scalar Solution(const Point &x) const override {
......@@ -49,7 +49,7 @@ public:
class Laplace1D : public IStochasticEllipticProblem {
public:
Laplace1D(Meshes &meshes) : IStochasticEllipticProblem(meshes) {};
explicit Laplace1D(const Meshes &meshes) : IStochasticEllipticProblem(meshes) {};
Scalar Solution(const Point &x) const override {
return 1 - x[0];
......@@ -72,7 +72,7 @@ public:
class StochasticLaplace2D : public IStochasticEllipticProblem {
public:
StochasticLaplace2D(Meshes &meshes) :
explicit StochasticLaplace2D(const Meshes &meshes) :
IStochasticEllipticProblem(meshes, GeneratorNames{"CirculantEmbedding"}) {}
Scalar Solution(const Point &x) const override {
......@@ -94,7 +94,7 @@ public:
class StochasticLaplace2DTest : public IStochasticEllipticProblem {
public:
StochasticLaplace2DTest(Meshes &meshes) :
explicit StochasticLaplace2DTest(const Meshes &meshes) :
IStochasticEllipticProblem(meshes, GeneratorNames{"UniformDistributionRVector"}) {}
Scalar Solution(const Point &x) const override {
......@@ -122,7 +122,7 @@ public:
class Laplace2D : public IStochasticEllipticProblem {
public:
Laplace2D(Meshes &meshes) : IStochasticEllipticProblem(meshes) {}
explicit Laplace2D(const Meshes &meshes) : IStochasticEllipticProblem(meshes) {}
Scalar Solution(const Point &x) const override {
return -x[1];
......@@ -142,6 +142,6 @@ public:
};
IStochasticEllipticProblem *
CreateStochasticEllipticProblem(const string &problemName, Meshes &meshes);
CreateStochasticEllipticProblem(const string &problemName, const Meshes &meshes);
#endif //STOCHASTICELLIPTICPROBLEM_HPP
......@@ -2,7 +2,7 @@
IStochasticTransportProblem *
CreateStochasticTransportProblem(std::string problemName, Meshes &meshes) {
CreateStochasticTransportProblem(std::string problemName, const Meshes &meshes) {
if (problemName == "StochasticPollution1D")
return new StochasticPollution1D(meshes);
if (problemName == "Pollution1D")
......
......@@ -16,20 +16,21 @@ private:
double T = 1.0;
public:
IStochasticTransportProblem(Meshes &meshes, GeneratorNames genNames = {})
explicit IStochasticTransportProblem(
const Meshes &meshes, const GeneratorNames &genNames = {})
: IStochasticProblem(meshes, genNames) {
config.get("CFL", CFL);
config.get("t0", t0);
config.get("T", T);
}
double GetStepSize(int h) { return CFL * h; }
double GetStepSize(int h) const { return CFL * h; }
double GetStartTime() { return t0; }
double GetStartTime() const { return t0; }
double GetEndTime() { return T; }
double GetEndTime() const { return T; }
double GetCFL() { return CFL; }
double GetCFL() const { return CFL; }
bool RHS() const { return rhs; }
......@@ -45,7 +46,7 @@ public:
class StochasticPollution1D : public IStochasticTransportProblem {
public:
StochasticPollution1D(Meshes &meshes) :
explicit StochasticPollution1D(const Meshes &meshes) :
IStochasticTransportProblem(meshes, GeneratorNames{"HybridFluxGenerator"}) {}
Scalar Solution(double t, const Point &x) const override {
......@@ -67,7 +68,7 @@ public:
class Pollution1D : public IStochasticTransportProblem {
public:
Pollution1D(Meshes &meshes) : IStochasticTransportProblem(meshes) {}
explicit Pollution1D(const Meshes &meshes) : IStochasticTransportProblem(meshes) {}
Scalar Solution(double t, const Point &x) const override {
if (abs(1.0 * t - x[0] + 0.5) > 0.06251) return 0.0;
......@@ -92,7 +93,7 @@ private:
double cc = 6.0;
public:
StochasticPollutionCosHat1D(Meshes &meshes) :
explicit StochasticPollutionCosHat1D(const Meshes &meshes) :
IStochasticTransportProblem(meshes, GeneratorNames{"HybridFluxGenerator"}) {}
Scalar Solution(double t, const Point &x) const override {
......@@ -117,7 +118,8 @@ public:
class PollutionCosHat1D : public IStochasticTransportProblem {
public:
PollutionCosHat1D(Meshes &meshes) : IStochasticTransportProblem(meshes) {}
explicit PollutionCosHat1D(const Meshes &meshes) :
IStochasticTransportProblem(meshes) {}
};
class StochasticPollution2D : public IStochasticTransportProblem {
......@@ -125,7 +127,7 @@ private:
double d = 1.0 / 16.0;
public:
StochasticPollution2D(Meshes &meshes) :
explicit StochasticPollution2D(const Meshes &meshes) :
IStochasticTransportProblem(meshes, GeneratorNames{"HybridFluxGenerator"}) {}
Scalar Solution(double t, const Point &x) const override {
......@@ -151,7 +153,7 @@ private:
double d = 1.0 / 16.0;
public:
Pollution2D(Meshes &meshes) : IStochasticTransportProblem(meshes) {}
explicit Pollution2D(const Meshes &meshes) : IStochasticTransportProblem(meshes) {}
Scalar Solution(double t, const Point &x) const override {
if ((abs(1 - x[1] - 1.5 * d) < d / 2) && (abs(0.5 - x[0]) < 4 * d))
......@@ -159,7 +161,7 @@ public:
return 0.0;
}
VectorField TransportFlux(const Point &x) const {
static VectorField TransportFlux(const Point &x) {
return VectorField(0.0, -1.0);
}
......@@ -180,7 +182,7 @@ private:
double amplitude = 1.00;
double cc = 6.0;
public:
StochasticPollutionCosHat2D(Meshes &meshes) :
explicit StochasticPollutionCosHat2D(const Meshes &meshes) :
IStochasticTransportProblem(meshes, GeneratorNames{"HybridFluxGenerator1D"}) {}
double Solution(double t, const Point &x) const override {
......@@ -206,7 +208,8 @@ public:
class PollutionCosHat2D : public IStochasticTransportProblem {
double amplitude = 2.0 / Pi;
public:
explicit PollutionCosHat2D(Meshes &meshes) : IStochasticTransportProblem(meshes) {}
explicit PollutionCosHat2D(const Meshes &meshes)
: IStochasticTransportProblem(meshes) {}
double Solution(double t, const Point &x) const override {
Point midPoint = 0.25 * (Point(cos(2. * Pi * t), sin(2. * Pi * t))
......@@ -216,7 +219,7 @@ public:
return 0.0;
}
VectorField CircleVectorField(const Point &x) const {
static VectorField CircleVectorField(const Point &x) {
return 2 * Pi * VectorField(-x[1], x[0], 0.0);
}
......@@ -240,18 +243,18 @@ private:
VectorField vectorField;
public:
StochasticGaussHat2D(Meshes &meshes) :
explicit StochasticGaussHat2D(const Meshes &meshes) :
vectorField(VectorField(1 / sqrt(2), 1 / sqrt(2), 0)),
IStochasticTransportProblem(meshes) {}
Scalar Solution(double t, const Point &x) const override {
// Todo 2D Gaussfunction for t = 0
// 1 / (sigma * sqrt(2 * PI)) exp ()
// Todo 2D Gauss function for t = 0
// 1 / (sigma * sqrt(2 * PI)) exp ()
if (abs(1.0 * t - x[0] + 0.5) > 0.06251) return 0.0;
return 1.0;
}
VectorField CircleVectorField(const Point &x) const {
static VectorField CircleVectorField(const Point &x) {
return 2 * Pi * VectorField(-x[1], x[0], 0.0);
}
......@@ -272,7 +275,7 @@ private:
Tensor sigma;
public:
GaussHat2D(Meshes &meshes) :
explicit GaussHat2D(const Meshes &meshes) :
sigma(Tensor()),
IStochasticTransportProblem(meshes) {
sigma[0][0] = 0.005;
......@@ -282,7 +285,7 @@ public:
sigma[2][2] = 1.0; // Todo this is needed even in 2D case which is not quite clean
}
Point mu(double t) const {
static Point mu(double t) {
return 0.25 * (Point(cos(2. * Pi * t), sin(2. * Pi * t)) + Point(1.0, 1.0));
}
......@@ -294,7 +297,7 @@ public:
return factor * exp(exponent);
}