BaseProblem.h 5.73 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/******************************************************************************
 *
 * Extension of AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: Simon Praetorius et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * See also license.opensource.txt in the distribution.
15
 *
16
 ******************************************************************************/
17
18
19
20
21
22
23

#ifndef BASE_PROBLEM_H
#define BASE_PROBLEM_H

#include "AMDiS.h"
#include "time/RosenbrockStationary.h"
#include "CouplingTimeInterface.h"
24
#include "pugixml.hpp"
25

26
namespace AMDiS { namespace base_problems {
27
28
29
30

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

31
template<class ProblemType=ProblemStat>
32
33
34
35
class BaseProblem : public ProblemIterationInterface,
		    public ProblemInstatBase
{
public:
36

37
  BaseProblem(const std::string &name_, bool createProblem = true);
38
39
  BaseProblem(const std::string &name_, ProblemStat* prob_);

40
41
  ~BaseProblem()
  {
42
    if (prob && createProblem)
43
      delete prob;
44

45
46
47
    for (size_t i = 0; i < operatorTermList.size(); i++)
      delete operatorTermList[i];
    operatorTermList.clear();
48

49
50
51
    for (size_t i = 0; i < operatorList.size(); i++)
      delete operatorList[i];
    operatorList.clear();
52
  }
53

54
  /// Initialisation of the problem.
55
56
57
  void initialize(Flag initFlag,
		  ProblemStat *adoptProblem = NULL,
		  Flag adoptFlag = INIT_NOTHING);
58

59
60
  /// Initialisation of DOFVectors and AbstractFunctions,
  /// is called in \ref initTimeInteface after feSpace and mesh are initialized
Praetorius, Simon's avatar
Praetorius, Simon committed
61
  virtual void initData() {}
62

63
  /// Method is called at the end of \ref initTimeInteface
Praetorius, Simon's avatar
Praetorius, Simon committed
64
  virtual void finalizeData() {}
65

66
67
  /// calls \ref initData, \ref fillOperators and \ref fillBoundaryConditions in this ordering
  virtual void initTimeInterface()
68
  {
69
70
71
    initData();
    fillOperators();
    fillBoundaryConditions();
72
    finalizeData();
73
  }
74

75
  /// read solution DOFVectors from .arh, .dat or .vtu files
76
  virtual Flag initDataFromFile(AdaptInfo *adaptInfo);
77

78
79
  /// calls \ref initDataFromFile
  virtual void solveInitialProblem(AdaptInfo *adaptInfo)
80
  {
81
    Flag initFlag = initDataFromFile(adaptInfo);
82
  }
83
84
85

  /// calls \ref writeFiles
  virtual void transferInitialSolution(AdaptInfo *adaptInfo)
86
  {
87
88
    oldMeshChangeIdx = getMesh()->getChangeIndex();
    writeFiles(adaptInfo, false);
89
  }
90
91

  /// This method is called before \ref beginIteration, \ref oneIteration and \ref endIteration.
92
  virtual void initTimestep(AdaptInfo *adaptInfo) override
93
  {}
94
95

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

98
99
100
  virtual void beginIteration(AdaptInfo *adaptInfo) override;
  virtual Flag oneIteration(AdaptInfo *adaptInfo, Flag toDo = FULL_ITERATION) override;
  virtual void endIteration(AdaptInfo *adaptInfo) override;
101
102
103

  /// Calls writeFiles of the problem
  virtual void writeFiles(AdaptInfo *adaptInfo, bool force)
104
  {
105
    prob->writeFiles(adaptInfo, force);
106
  }
107

108
109
110
111
112
113
114
115
116
  // getting methods

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

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

  /// pointer to the feSpace of the problem
123
  inline const FiniteElemSpace* getFeSpace(int comp = 0)
124
  {
125
    return prob->getFeSpace(comp);
126
127
128
  }

  /// name of the baseBroblem
129
  std::string getName() const
130
131
  {
    return name;
132
  }
133

134
  int getNumProblems() const
135
136
  {
    return 1;
137
  }
138

139
  int getNumComponents() const
140
141
  {
    return prob->getNumComponents();
142
  }
143

144
  ProblemType *getProblem(int number = 0)
145
  {
146
147
    TEST_EXIT(number >= 0 && number < getNumProblems())
      ("problem with given number does not exist\n");
148

149
150
    if (number == 0)
      return prob;
151
152
153

    return NULL;
  }
154

Praetorius, Simon's avatar
Praetorius, Simon committed
155
  ProblemType *getProblem(std::string name_)
156
  {
157
158
    TEST_EXIT(name_ == "prob")("problem with given name '%s' does not exist\n", name_.c_str());
    return prob;
Praetorius, Simon's avatar
Praetorius, Simon committed
159
160
161
162
  }

  void setProblem(ProblemType *prob_, bool destroy = true)
  {
163
    if (destroy && prob && createProblem)
Praetorius, Simon's avatar
Praetorius, Simon committed
164
165
      delete prob;
    prob = prob_;
166
  }
167
168
169
170
171
172
173
174
175
176
177
178
179

  // setting methods

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

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

180
  void serialize(std::ostream&)
181
182
  {}

183
  void deserialize(std::istream&)
184
  {}
185
186

  /// method where operators are added to the problem
187
188
  virtual void fillOperators()
  {}
189

190
  /// method where boundary conditions are added to the problem
191
  virtual void fillBoundaryConditions()
192
  {}
193
194
195

  /// classical backward-euler time-discretization
  void addTimeOperator(ProblemStat *prob, int i, int j);
196

197
198
  /// for rosenbrock-problems a special time-operator can be added
  void addTimeOperator(RosenbrockStationary *prob, int i, int j);
199

200
  template<typename T>
201
  static void initFileWriterFromFile(AdaptInfo* adaptInfo, AMDiS::detail::FileWriter<T>& fileWriter, bool keep_all = false);
202

203
protected:
Praetorius, Simon's avatar
Praetorius, Simon committed
204
  std::string name;
205
206

  ProblemType *prob;
207
  bool createProblem;
208
209
210

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

212
213
214
215
216
217
218
  /// dimension of world (set in constructur)
  unsigned dow;

  int nTimesteps;
  int oldMeshChangeIdx;

  double oldTimestep;
219

220
221
222
  /// lists of objects to delete in the destructor
  std::vector<OperatorTerm*> operatorTermList;
  std::vector<Operator*> operatorList;
223
224
225
226
227
228
229
230

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

};

typedef BaseProblem<ProblemStat> StandardBaseProblem;

231
232
233
234
235
236
} }

using namespace AMDiS::base_problems;

#include "BaseProblem.hh"

237
#endif // BASE_PROBLEM_H