Commit 4a540a65 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

worked on SparseGridGenerator and StochasticCollocation

parent 6d463004
......@@ -14,9 +14,12 @@ private:
PDESolverCreator pdeSolverCreator;
public:
StochasticCollocation(MeshesCreator meshesCreator = MeshesCreator(),
StochasticCollocation(double epsilon, int level, int stochLevel,
bool onlyFine, bool parallel,
MeshesCreator meshesCreator = MeshesCreator(),
PDESolverCreator pdeCreator = PDESolverCreator()) :
Estimator(0.0, 0, 0),
Estimator(epsilon, level, 0),
fineId(SampleID(level, 0, false)), coarseId(SampleID(level, 0, true)),
meshesCreator(meshesCreator), pdeSolverCreator(pdeCreator) {}
std::string Name() const override {
......@@ -37,6 +40,9 @@ public:
SampleSolution fineSolution(pdeSolver->GetDisc(), fineId);
SampleSolution coarseSolution(pdeSolver->GetDisc(), coarseId);
pdeSolver->DrawSample(fineId);
pdeSolver->Run(fineSolution);
while (aggregate.ctr.dMcomm != 0) {
pdeSolver->DrawSample(fineId);
......
......@@ -18,23 +18,23 @@ protected:
int outputs;
RVector sample;
double weight = 0.0;
std::vector<double> points{};
RVector sample {};
std::vector<double> weights{};
void drawSample(const SampleID &id) override {
// Todo the parallelization
for (int i = 0; i < dimension; i++) {
sample[i] = points.front();
// points.erase(points.begin());
std::vector<RVector> samples{};
weight = weights.front();
// weights.erase(points.begin());
}
void fillSampleVector() {
std::vector<double> points = grid.getPoints();
for (auto it_start = points.begin(); it_start != points.end(); it_start += dimension)
samples.emplace_back(std::vector<double>(it_start, it_start + dimension));
}
void drawSample(const SampleID &id) override {
sample = samples[id.number];
weight = weights[id.number];
};
public:
......@@ -42,18 +42,18 @@ public:
TasGrid::TypeDepth depth = TasGrid::type_level,
TasGrid::TypeOneDRule rule = TasGrid::rule_clenshawcurtis) :
SampleGenerator(meshes), dimension(dimension), outputs(outputs),
depth(depth), rule(rule), sample(RVector(dimension)) {
depth(depth), rule(rule) {
grid.makeGlobalGrid(dimension, outputs, level, depth, rule);
points = grid.getPoints();
weights = grid.getQuadratureWeights();
fillSampleVector();
}
void CreateGlobalGrid(int level) {
grid.makeGlobalGrid(dimension, outputs, level, depth, rule);
}
std::vector<double> GetPoints() {
return points;
std::vector<RVector> GetSamples() {
return samples;
}
std::vector<double> GetWeights() {
......@@ -68,10 +68,14 @@ public:
return grid.getNumDimensions();
}
RVector EvalSample() const override {
return sample;
}
// todo move to stochastic collocation class
double Quadrature(double func(double, double)) {
double I = 0.0;
std::vector<double> points = GetPoints();
std::vector<double> points = grid.getPoints();
std::vector<double> weights = GetWeights();
int num_points = GetNumPoints();
for (int i = 0; i < num_points; i++) {
......
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