BaseProblem.h 4.51 KB
Newer Older
1
2
3
4
5
6
7
8
/** \file BaseProblem.h */

#ifndef BASE_PROBLEM_H
#define BASE_PROBLEM_H

#include "AMDiS.h"
#include "time/RosenbrockStationary.h"
#include "CouplingTimeInterface.h"
9
#include "VtuReader.h"
10
11
12
13
14
15
16
17
18
19
20

using namespace AMDiS;

const Flag MESH_ADOPTED = 1<<2;
const Flag DATA_ADOPTED = 1<<3;

template<typename ProblemType=ProblemStat>
class BaseProblem : public ProblemIterationInterface,
		    public ProblemInstatBase
{
public:
21
  
22
23
24
25
26
  BaseProblem(const std::string &name_);
  ~BaseProblem()
  {
    delete prob;
  }
27
  
28
  /// Initialisation of the problem.
29
30
31
32
  void initialize(Flag initFlag,
		  ProblemStat *adoptProblem = NULL,
		  Flag adoptFlag = INIT_NOTHING);
  
33
34
35
  /// Initialisation of DOFVectors and AbstractFunctions,
  /// is called in \ref initTimeInteface after feSpace and mesh are initialized
  virtual void initData() {};
36
  
37
38
  /// calls \ref initData, \ref fillOperators and \ref fillBoundaryConditions in this ordering
  virtual void initTimeInterface()
39
40
  { 
    FUNCNAME("BaseProblem::initTimeInterface()");
41
42
43
    initData();
    fillOperators();
    fillBoundaryConditions();
44
45
  }
  
46
  /// read solution DOFVectors from .arh, .dat or .vtu files
47
  virtual Flag initDataFromFile(AdaptInfo *adaptInfo);
48
  
49
50
  /// calls \ref initDataFromFile
  virtual void solveInitialProblem(AdaptInfo *adaptInfo)
51
52
  { 
    FUNCNAME("BaseProblem::solveInitialProblem()");
53
    Flag initFlag = initDataFromFile(adaptInfo);
54
  }
55
56
57

  /// calls \ref writeFiles
  virtual void transferInitialSolution(AdaptInfo *adaptInfo)
58
59
  { 
    FUNCNAME("BaseProblem::transferInitialSolution()");
60
61
    oldMeshChangeIdx = getMesh()->getChangeIndex();
    writeFiles(adaptInfo, false);
62
  }
63
64

  /// This method is called before \ref beginIteration, \ref oneIteration and \ref endIteration.
65
66
  virtual void initTimestep(AdaptInfo *adaptInfo) 
  {}
67
68
69
70
71
72
73
74
75
76

  /// calls \ref writeFiles
  virtual void closeTimestep(AdaptInfo *adaptInfo);

  virtual void beginIteration(AdaptInfo *adaptInfo);
  virtual Flag oneIteration(AdaptInfo *adaptInfo, Flag toDo = FULL_ITERATION);
  virtual void endIteration(AdaptInfo *adaptInfo);

  /// Calls writeFiles of the problem
  virtual void writeFiles(AdaptInfo *adaptInfo, bool force)
77
78
  { 
    FUNCNAME("BaseProblem::writeFiles()");
79
    prob->writeFiles(adaptInfo, force);
80
  }
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  
  // getting methods

  /// pointer to the solution of the problem
  SystemVector *getSolution()
  {
    return prob->getSolution();
  }

  /// pointer to the mesh of the problem
  inline Mesh* getMesh(int comp = 0) 
  {
    return prob->getMesh(comp); 
  }

  /// pointer to the feSpace of the problem
Thomas Witkowski's avatar
Thomas Witkowski committed
97
  inline const FiniteElemSpace* getFeSpace(int comp = 0) 
98
99
100
101
102
103
104
105
  {
    return prob->getFeSpace(comp); 
  }

  /// name of the baseBroblem
  std::string getName()
  {
    return name;
106
  }
107
108
109
110

  int getNumProblems() 
  {
    return 1;
111
  }
112
113
114
115
  
  int getNumComponents()
  {
    return prob->getNumComponents();
116
  }
117

118
  ProblemType *getProblem(int number = 0)
119
  {
120
    if (number < 0 || number >= getNumProblems())
121
      throw(std::runtime_error("problem with given number does not exist"));
122

123
124
    if (number == 0)
      return prob;
125
126
127

    return NULL;
  }
128
129
130
131
132
133
134

  ProblemType *getProblem(std::string name)
  {
    if (name == "prob")
      return prob;
    else
      throw(std::runtime_error("problem with given name '" + name + "' does not exist"));
135
  }
136
137
138
139
140
141
142
143
144
145
146
147
148

  // setting methods

  void setAssembleMatrixOnlyOnce_butTimestepChange(int i, int j)
  {
    fixedMatrixTimestep.push_back(std::make_pair(i,j));
  }

  void setNumberOfTimesteps(int nTimesteps_)
  {
    nTimesteps= nTimesteps_;
  }

149
150
151
152
153
  void serialize(std::ostream&) 
  {}

  void deserialize(std::istream&) 
  {}
154
155

  /// method where operators are added to the problem
156
157
  virtual void fillOperators()
  {}
158
159
  
  /// method where boundary conditions are added to the problem
160
161
  virtual void fillBoundaryConditions() 
  {}
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

  /// classical backward-euler time-discretization
  void addTimeOperator(ProblemStat *prob, int i, int j);
  
  /// for rosenbrock-problems a special time-operator can be added
  void addTimeOperator(RosenbrockStationary *prob, int i, int j);
  
protected:

  ProblemType *prob;

  /// catch errors and exceptions in solve-block and continue with last iteration on failure
  /// standard: false
  bool secureIteration; 

  /// dimension of the mesh (set in \ref initialize(...) )
  unsigned dim;
  
  /// dimension of world (set in constructur)
  unsigned dow;

  int nTimesteps;
  int oldMeshChangeIdx;

  double oldTimestep;

private:

  std::vector<std::pair<int,int> > fixedMatrixTimestep;

};

#include "BaseProblem.hh"

typedef BaseProblem<ProblemStat> StandardBaseProblem;

#endif // BASE_PROBLEM_H