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

added plot to sample generator and changed field generation interface

parent f70f7350
#include "CirculantEmbedding.h"
void CirculantEmbedding1D::GenerateFineSample(Vector &fineField) {
void CirculantEmbedding1D::generateFineSample(Vector &fineField) {
if (internalCounter == 0)
fineComplexField = generateField();
......@@ -33,7 +33,7 @@ void CirculantEmbedding1D::GenerateFineSample(Vector &fineField) {
// TM(c(),c.Child(k))[0] = 1;
// }
void CirculantEmbedding1D::GetCoarseSample(const Vector &fineField, Vector &coarseField) {
void CirculantEmbedding1D::generateCoarseSample(const Vector &fineField, Vector &coarseField) {
coarseField = 0;
for (cell c = coarseField.cells(); c != coarseField.cells_end(); c++) {
row coarseRow = coarseField.find_row(c());
......@@ -162,7 +162,7 @@ vector<double> CirculantEmbedding1D::getSqrtEV() {
return sqrt_ev_return;
}
void CirculantEmbedding2D::GenerateFineSample(Vector &fineField) {
void CirculantEmbedding2D::generateFineSample(Vector &fineField) {
if (internalCounter == 0)
fineComplexField = generateField();
......@@ -185,7 +185,7 @@ void CirculantEmbedding2D::GenerateFineSample(Vector &fineField) {
internalCounter %= 2;
}
void CirculantEmbedding2D::GetCoarseSample(const Vector &fineField, Vector &coarseField) {
void CirculantEmbedding2D::generateCoarseSample(const Vector &fineField, Vector &coarseField) {
coarseField = 0;
for (cell c = coarseField.cells(); c != coarseField.cells_end(); ++c) {
row coarseRow = coarseField.find_row(c());
......
......@@ -11,6 +11,13 @@ class CirculantEmbedding : public SampleGenerator {
protected:
int internalCounter = 0;
RNManager *rnmg;
void generatePlot(const Vector &sample) override {
plot->celldata(sample);
string namePerm = sampleDir + "/perm";
plot->vtk_celldata(namePerm);
}
public:
double evtol = 1e-10;
string fieldType = "LogNormal";
......@@ -33,11 +40,11 @@ public:
DeterministicPermeabilityGenerator(int l, Meshes &meshes)
: CirculantEmbedding(l, meshes) {}
void GenerateFineSample(Vector &fineField) override {
void generateFineSample(Vector &fineField) override {
fineField = 1.0;
};
void GetCoarseSample(const Vector &fineField, Vector &coarseField) override {
void generateCoarseSample(const Vector &fineField, Vector &coarseField) override {
coarseField = 1.0;
}
};
......@@ -59,9 +66,9 @@ public:
numberOfCellsEmbedded = sqrtEigenvalues.size();
}
void GenerateFineSample(Vector &fineField) override;
void generateFineSample(Vector &fineField) override;
void GetCoarseSample(const Vector &fineField, Vector &coarseField) override;
void generateCoarseSample(const Vector &fineField, Vector &coarseField) override;
private:
vector<complex<double>> generateField();
......@@ -92,9 +99,9 @@ public:
numberOfCellsEmbedded[1] = sqrtEigenvalues[0].size();
}
void GenerateFineSample(Vector &fineField) override;
void generateFineSample(Vector &fineField) override;
void GetCoarseSample(const Vector &fineField, Vector &coarseField) override;
void generateCoarseSample(const Vector &fineField, Vector &coarseField) override;
private:
vector<vector<complex<double>>> fineComplexField;
......
#include "HybridFluxGenerator.h"
void HybridFluxGenerator::GenerateFineSample(Vector &fineField) {
void HybridFluxGenerator::generateFineSample(Vector &fineField) {
MatrixGraphs cellMg1(meshes, dof("cell", 1));
MatrixGraphs cellMg3(meshes, dof("cell", 3));
MatrixGraphs faceMg(meshes, dof("face", 1));
......@@ -21,12 +21,10 @@ void HybridFluxGenerator::GenerateFineSample(Vector &fineField) {
newton(*assemble, u);
assemble->setFlux(u, flux);
assemble->SetNormalFlux(u, normalFlux);
PlotSample(perm, u, flux, normalFlux);
}
void HybridFluxGenerator::GetCoarseSample(const Vector &fineField,
Vector &coarseField) {
void HybridFluxGenerator::generateCoarseSample(const Vector &fineField,
Vector &coarseField) {
coarseField = 0;
for (cell c = coarseField.cells(); c != coarseField.cells_end(); c++) {
row coarseRow = coarseField.find_row(c());
......@@ -38,26 +36,4 @@ void HybridFluxGenerator::GetCoarseSample(const Vector &fineField,
for (int i = 0; i < coarseRow.n(); ++i)
coarseField(coarseRow, i) /= c.Children();
}
}
void HybridFluxGenerator::PlotSample(const Vector &perm,
const Vector &u,
const Vector &flux,
const Vector &normalFlux) {
if (plotting >= 4) {
// string nameU = sampleDir + "/u_hybrid";
// assemble->plotU(*plot, u, nameU);
}
if (plotting >= 3) {
string namePerm = sampleDir + "/perm";
assemble->plotPerm(*plot, perm, namePerm);
}
if (plotting >= 2) {
string nameFlux = sampleDir +"/flux";
assemble->plotFlux(*plot, flux, nameFlux);
}
if (plotting >= 1) {
string nameNormalFlux = sampleDir +"/normalFlux";
// Todo Normal Flux
}
}
}
\ No newline at end of file
......@@ -12,7 +12,11 @@ protected:
StochasticEllipticProblem *problem = nullptr;
HybridEllipticAssemble *assemble = nullptr;
CirculantEmbedding *permeabilityGenerator = nullptr;
Plot *plot = nullptr;
void generatePlot(const Vector &sample) override {
string nameFlux = sampleDir +"/flux";
assemble->plotFlux(sample, nameFlux);
}
public:
explicit HybridFluxGenerator(int l, Meshes &meshes)
......@@ -28,14 +32,9 @@ public:
delete permeabilityGenerator;
};
void PlotSample(const Vector &perm,
const Vector &u,
const Vector &flux,
const Vector &normalFlux);
void GenerateFineSample(Vector &fineField) override;
void generateFineSample(Vector &fineField) override;
void GetCoarseSample(const Vector &fineField, Vector &coarseField) override;
void generateCoarseSample(const Vector &fineField, Vector &coarseField) override;
};
class HybridFluxGenerator1D : public HybridFluxGenerator {
......
......@@ -10,10 +10,16 @@
class SampleGenerator {
protected:
int plotting = 0;
GeneratorLogger *logger;
Plot *plot = nullptr;
GeneratorLogger *logger = nullptr;
string sampleDir = "";
virtual void GenerateFineSample(Vector &fineField) = 0;
virtual void generateFineSample(Vector &fineField) = 0;
virtual void generateCoarseSample(const Vector &fineField, Vector &coarseField) = 0;
virtual void generatePlot(const Vector &sample) = 0;
public:
int l;
......@@ -28,17 +34,27 @@ public:
delete logger;
}
virtual void GetFineSample(Vector &fineField) {
void GetFineSample(Vector &fineField) {
logger->StartMethodMsg();
GenerateFineSample(fineField);
generateFineSample(fineField);
if (plotting) generatePlot(fineField);
logger->EndMethodMsg();
}
virtual void GetCoarseSample(const Vector &fineField, Vector &coarseField) = 0;
void GetCoarseSample(const Vector &fineField, Vector &coarseField) {
logger->StartMethodMsg();
generateCoarseSample(fineField, coarseField);
if (plotting) generatePlot(coarseField);
logger->EndMethodMsg();
}
void SetSampleDir(const string& sampleDirName) {
sampleDir = sampleDirName;
}
void SetPlot(Plot *plot) {
this->plot = plot;
}
};
#endif //SAMPLEGENERATOR_H
......@@ -8,6 +8,33 @@
class StochasticField {
public:
string generatorName = "";
map<int, SampleGenerator *> generators;
Meshes &meshes;
explicit StochasticField(Meshes &meshes, string generatorName) :
meshes(meshes), generatorName(std::move(generatorName)) {
for (int l = meshes.pLevel(); l <= meshes.Level(); l++)
generators[l] = getGenerator(l);
}
void GetFineSample(int l, Vector &fineField) {
generators[l]->GetFineSample(fineField);
}
void GetCoarseSample(int l, const Vector &fineField, Vector &coarseField) {
generators[l]->GetCoarseSample(fineField, coarseField);
}
void SetSampleDir(int l, const string &sampleDirName) {
generators[l]->SetSampleDir(sampleDirName);
}
void SetPlot(int l, Plot *plot) {
generators[l]->SetPlot(plot);
}
private:
SampleGenerator *getGenerator(int l) {
if (generatorName == "CirculantEmbedding") {
......@@ -30,25 +57,6 @@ private:
}
Exit("Generator does not exist")
}
public:
string generatorName = "";
map<int, SampleGenerator *> generators;
Meshes &meshes;
explicit StochasticField(Meshes &meshes, string generatorName) :
meshes(meshes), generatorName(std::move(generatorName)) {
for (int l = meshes.pLevel(); l <= meshes.Level(); l++)
generators[l] = getGenerator(l);
}
void GetFineSample(int l, Vector &fineField) {
generators[l]->GetFineSample(fineField);
}
void GetCoarseSample(int l, const Vector &fineField, Vector &coarseField) {
generators[l]->GetCoarseSample(fineField, coarseField);
}
};
#endif //STOCHASTICFIELD_H
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