Commit 80d6fe9a authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

Merge branch '29-make-mesh-const-in-generator' into 'feature'

Resolve "Make mesh const in generator"

Closes #29

See merge request !41
parents 959a4f1f 6c59350a
Pipeline #157176 passed with stages
in 11 minutes and 9 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;
......@@ -136,7 +136,7 @@ public:
class VectorFieldDummy : public SampleGenerator<VectorField> {
public:
VectorFieldDummy(Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
VectorFieldDummy(const Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
void drawSample(const SampleID &id) override {
vout(1) << "Dummy Generator" << endl;
......@@ -147,7 +147,7 @@ public:
class TensorDummy : public SampleGenerator<Tensor> {
public:
TensorDummy(Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
TensorDummy(const Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
void drawSample(const SampleID &id) override {
vout(1) << "Dummy Generator" << endl;
......@@ -158,7 +158,7 @@ public:
class RVectorDummy : public SampleGenerator<RVector> {
public:
RVectorDummy(Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
RVectorDummy(const Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
void drawSample(const SampleID &id) override {
vout(1) << "Dummy Generator" << endl;
......@@ -169,7 +169,7 @@ public:
class CVectorDummy : public SampleGenerator<CVector> {
public:
CVectorDummy(Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
CVectorDummy(const Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
void drawSample(const SampleID &id) override {
vout(1) << "Dummy Generator" << endl;
......@@ -180,7 +180,7 @@ public:
class RMatrixDummy : public SampleGenerator<RMatrix> {
public:
RMatrixDummy(Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
RMatrixDummy(const Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
void drawSample(const SampleID &id) override {
vout(1) << "Dummy Generator" << endl;
......@@ -191,7 +191,7 @@ public:
class CMatrixDummy : public SampleGenerator<CMatrix> {
public:
CMatrixDummy(Meshes &meshes) : SampleGenerator(meshes) { verbose = 0; }
CMatrixDummy(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)
......@@ -116,7 +116,7 @@ private:
}
public:
UniformDistributionRMatrix(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)
......
......@@ -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();
}
......@@ -40,7 +40,7 @@ class HybridCellFluxGenerator : public SampleGenerator<VectorField> {
void drawSample(const SampleID &id) override {};
public:
HybridCellFluxGenerator(Meshes &meshes, HybridFaceNormalFluxGenerator &generator) :
HybridCellFluxGenerator(const Meshes &meshes, HybridFaceNormalFluxGenerator &generator) :
SampleGenerator(meshes),
generator(generator) {}
......
......@@ -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(
......@@ -74,6 +74,6 @@ PDESolver *PDESolverCreator::Create(Meshes &meshes) {
Exit(_model + " not found")
}
std::unique_ptr<PDESolver> PDESolverCreator::CreateUnique(Meshes &meshes) {
std::unique_ptr<PDESolver> PDESolverCreator::CreateUnique(const Meshes &meshes) {
return std::unique_ptr<PDESolver>(Create(meshes));
}
......@@ -59,9 +59,9 @@ public:
return "Interval";
}
PDESolver *Create(Meshes &meshes);
PDESolver *Create(const Meshes &meshes);
std::unique_ptr<PDESolver> CreateUnique(Meshes &meshes);
std::unique_ptr<PDESolver> CreateUnique(const Meshes &meshes);
};
#endif //PDESOLVERCREATOR_HPP
......@@ -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
......@@ -37,7 +37,7 @@ protected:
double reaction = 1.0;
public:
IStochasticReactionProblem(Meshes &meshes, GeneratorNames genNames={}) :
IStochasticReactionProblem(const Meshes &meshes, GeneratorNames genNames={}) :
IStochasticProblem(meshes, genNames) {
config.get("Diffusion", diffusion);
config.get("Convection", convection);
......@@ -110,7 +110,7 @@ inline Scalar u0(const Point &x) {
class ExponentialReaction2D : public IStochasticReactionProblem {
public:
ExponentialReaction2D(Meshes &meshes) :
ExponentialReaction2D(const Meshes &meshes) :
IStochasticReactionProblem(meshes) {};
Scalar Concentration(double t, const Point &x) const override {
......@@ -141,7 +141,7 @@ private:
double r0 = 1.0;
double r1 = 0.0;
public:
LogisticReaction2D(Meshes &meshes) :
LogisticReaction2D(const Meshes &meshes) :
IStochasticReactionProblem(meshes) {
config.get("Reaction0", r0);
config.get("Reaction1", r1);
......
......@@ -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: