PDESolver.hpp 3.09 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

niklas.baumgarten's avatar
niklas.baumgarten committed
21
  const Meshes &meshes;
niklas.baumgarten's avatar
niklas.baumgarten committed
22

23
  std::string quantity;
24

25
  std::string costMeasure;
niklas.baumgarten's avatar
niklas.baumgarten committed
26

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

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

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

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

niklas.baumgarten's avatar
niklas.baumgarten committed
35
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
36
  PDESolver(const Meshes &meshes, const std::string &quantity,
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
            const std::string &costMeasure) :
    meshes(meshes), quantity(quantity), costMeasure(costMeasure) {
    config.get("PDESolverVerbose", verbose);
    config.get("PDESolverPlotting", plotting);
  }

  virtual ~PDESolver() {};

  virtual void PrintInfo() const {
    if (verbose > 0)
      mout.PrintInfo(Name(), verbose,
                     PrintInfoEntry("Quantity", quantity),
                     PrintInfoEntry("Cost measure", costMeasure));
  }

  void Run(SampleSolution &solution) {
    mout.StartBlock("PDE Solver");
    vout(2) << solution.IdString() << endl;
    run(solution);
    computeQ(solution);
    computeCost(solution);
    plotSolution(solution);
    vout(2) << "Q=" << solution.Q << " cost=" << solution.Cost << endl;
    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
72
73
};

niklas.baumgarten's avatar
niklas.baumgarten committed
74
75
class DummyPDESolver : public PDESolver {
private:
76
  IStochasticDummyAssemble *assemble;
niklas.baumgarten's avatar
niklas.baumgarten committed
77
78

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

niklas.baumgarten's avatar
niklas.baumgarten committed
81
82
83
84
  void computeQ(SampleSolution &solution) override {
    if (quantity == "GeneratorValue") solution.Q = assemble->GeneratorValue();
    else Exit("Quantity of interest not implemented")
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
85

niklas.baumgarten's avatar
niklas.baumgarten committed
86
87
88
89
90
  void computeCost(SampleSolution &solution) override {
    if (costMeasure == "size") solution.Cost = solution.U.size();
//    else if (costMeasure == "time") solution.Cost = solution.U.size(); // Todo
    else Exit("Cost measure not implemented")
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
91

niklas.baumgarten's avatar
niklas.baumgarten committed
92
  void plotSolution(SampleSolution &solution) override {
niklas.baumgarten's avatar
niklas.baumgarten committed
93
    mpp::plot_mesh(solution.U.GetMesh());
niklas.baumgarten's avatar
niklas.baumgarten committed
94
  }
niklas.baumgarten's avatar
niklas.baumgarten committed
95
96

public:
97
  DummyPDESolver(IStochasticDummyAssemble *assemble,
niklas.baumgarten's avatar
niklas.baumgarten committed
98
                 const Meshes &meshes,
99
100
101
102
103
104
                 const std::string &quantity = "L2",
                 const std::string &costMeasure = "size") :
    PDESolver(meshes, quantity, costMeasure), assemble(assemble) {
    if (verbose > 0) {
      PrintInfo();
      assemble->PrintInfo();
105
    }
106
  }
107

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

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

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

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

116
  std::string Name() const override { return "DummyPDESolver"; }
niklas.baumgarten's avatar
niklas.baumgarten committed
117
118
};

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