PDESolver.hpp 2.29 KB
Newer Older
niklas.baumgarten's avatar
niklas.baumgarten committed
1
2
3
#ifndef PDESOLVER_HPP
#define PDESOLVER_HPP

niklas.baumgarten's avatar
imports    
niklas.baumgarten committed
4
#include "IStochasticDummyAssemble.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
5
#include "Sample.hpp"
6

7
#include "TimeIntegrator.hpp"
8
#include "Newton.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
9
#include "GMRES.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
10
#include "Plotting.hpp"
11

12
#include <typeinfo>
niklas.baumgarten's avatar
niklas.baumgarten committed
13
14
15
16


class PDESolver {
protected:
17
  int verbose = 1;
niklas.baumgarten's avatar
niklas.baumgarten committed
18

19
  int plotting = 0;
niklas.baumgarten's avatar
niklas.baumgarten committed
20

21
  virtual void run(SampleSolution &solution) = 0;
niklas.baumgarten's avatar
niklas.baumgarten committed
22

23
  virtual void computeQ(SampleSolution &solution) = 0;
niklas.baumgarten's avatar
niklas.baumgarten committed
24

25
  virtual void computeCost(SampleSolution &solution) = 0;
niklas.baumgarten's avatar
niklas.baumgarten committed
26

27
  virtual void plotSolution(SampleSolution &solution) = 0;
niklas.baumgarten's avatar
niklas.baumgarten committed
28

29
  void weightSolution(SampleSolution &solution) const {
30
    solution.W = GetProblem()->SampleWeight(solution.id);
31
32
  }

niklas.baumgarten's avatar
niklas.baumgarten committed
33
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
34
  PDESolver() {
35
36
37
38
    config.get("PDESolverVerbose", verbose);
    config.get("PDESolverPlotting", plotting);
  }

39
  virtual ~PDESolver() = default;
40
41
42

  void Run(SampleSolution &solution) {
    mout.StartBlock("PDE Solver");
niklas.baumgarten's avatar
niklas.baumgarten committed
43
    vout(2) << solution.id << endl;
44
45
46
47
    run(solution);
    computeQ(solution);
    computeCost(solution);
    plotSolution(solution);
48
    weightSolution(solution);
niklas.baumgarten's avatar
niklas.baumgarten committed
49
    vout(2) << "Q=" << solution.Q << " cost=" << solution.C << endl;
50
51
52
53
54
55
56
57
58
59
60
61
    mout.EndBlock(verbose <= 1);
  }

  virtual IAssemble *GetAssemble() const = 0;

  virtual IDiscretization *GetDisc() const = 0;

  virtual IStochasticProblem *GetProblem() const = 0;

  virtual void DrawSample(const SampleID &id) = 0;

  virtual std::string Name() const = 0;
niklas.baumgarten's avatar
niklas.baumgarten committed
62
63
};

niklas.baumgarten's avatar
niklas.baumgarten committed
64
65
class DummyPDESolver : public PDESolver {
private:
66
  IStochasticDummyAssemble *assemble;
niklas.baumgarten's avatar
niklas.baumgarten committed
67
68

protected:
niklas.baumgarten's avatar
niklas.baumgarten committed
69
  void run(SampleSolution &solution) override {}
niklas.baumgarten's avatar
niklas.baumgarten committed
70

niklas.baumgarten's avatar
niklas.baumgarten committed
71
  void computeQ(SampleSolution &solution) override {
niklas.baumgarten's avatar
niklas.baumgarten committed
72
    solution.Q = assemble->FunctionEvaluation();
niklas.baumgarten's avatar
niklas.baumgarten committed
73
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
74

niklas.baumgarten's avatar
niklas.baumgarten committed
75
  void computeCost(SampleSolution &solution) override {
niklas.baumgarten's avatar
niklas.baumgarten committed
76
    solution.C = 1.0;  // Cost corresponds to one function evaluation
niklas.baumgarten's avatar
niklas.baumgarten committed
77
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
78

niklas.baumgarten's avatar
niklas.baumgarten committed
79
  void plotSolution(SampleSolution &solution) override {}
niklas.baumgarten's avatar
niklas.baumgarten committed
80
81

public:
niklas.baumgarten's avatar
niklas.baumgarten committed
82
83
  explicit DummyPDESolver(IStochasticDummyAssemble *assemble) :
    PDESolver(), assemble(assemble) {}
84

85
  IAssemble *GetAssemble() const override { return assemble; }
niklas.baumgarten's avatar
niklas.baumgarten committed
86

87
  IDiscretization *GetDisc() const override { return assemble->GetDisc(); }
niklas.baumgarten's avatar
niklas.baumgarten committed
88

89
  IStochasticProblem *GetProblem() const override { return assemble->GetProblem(); }
niklas.baumgarten's avatar
niklas.baumgarten committed
90

91
  void DrawSample(const SampleID &id) override { assemble->DrawSample(id); }
niklas.baumgarten's avatar
niklas.baumgarten committed
92

93
  std::string Name() const override { return "DummyPDESolver"; }
niklas.baumgarten's avatar
niklas.baumgarten committed
94
95
};

niklas.baumgarten's avatar
niklas.baumgarten committed
96
#endif //PDESOLVER_HPP