BaseProblem.h 5.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/******************************************************************************
 *
 * 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.
 * 
 ******************************************************************************/
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 "VtuReader.h"
25
#include "pugixml.hpp"
26

27
28
29
30
31
32
#if __cplusplus > 199711L
  #define _OVERRIDE_ override
#else
  #define _OVERRIDE_
#endif

33
34
35
36
37
using namespace AMDiS;

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

Praetorius, Simon's avatar
Praetorius, Simon committed
38
template<class ProblemType=ProblemStat, bool safeguard = false>
39
40
41
42
class BaseProblem : public ProblemIterationInterface,
		    public ProblemInstatBase
{
public:
43
  
44
  BaseProblem(const std::string &name_, bool createProblem = true);
45
46
  ~BaseProblem()
  {
47
48
    if (prob)
      delete prob;
49
50
51
52
53
54
55
56
    
    for (size_t i = 0; i < operatorTermList.size(); i++)
      delete operatorTermList[i];
    operatorTermList.clear();
    
    for (size_t i = 0; i < operatorList.size(); i++)
      delete operatorList[i];
    operatorList.clear();
57
  }
58
  
59
  /// Initialisation of the problem.
60
61
62
63
  void initialize(Flag initFlag,
		  ProblemStat *adoptProblem = NULL,
		  Flag adoptFlag = INIT_NOTHING);
  
64
65
  /// Initialisation of DOFVectors and AbstractFunctions,
  /// is called in \ref initTimeInteface after feSpace and mesh are initialized
Praetorius, Simon's avatar
Praetorius, Simon committed
66
  virtual void initData() {}
67
  
68
  /// Method is called at the end of \ref initTimeInteface
Praetorius, Simon's avatar
Praetorius, Simon committed
69
  virtual void finalizeData() {}
70
  
71
72
  /// calls \ref initData, \ref fillOperators and \ref fillBoundaryConditions in this ordering
  virtual void initTimeInterface()
73
  { 
74
75
76
    initData();
    fillOperators();
    fillBoundaryConditions();
77
    finalizeData();
78
79
  }
  
80
  /// read solution DOFVectors from .arh, .dat or .vtu files
81
  virtual Flag initDataFromFile(AdaptInfo *adaptInfo);
82
  
83
84
  /// calls \ref initDataFromFile
  virtual void solveInitialProblem(AdaptInfo *adaptInfo)
85
  { 
86
    Flag initFlag = initDataFromFile(adaptInfo);
87
  }
88
89
90

  /// calls \ref writeFiles
  virtual void transferInitialSolution(AdaptInfo *adaptInfo)
91
  { 
92
93
    oldMeshChangeIdx = getMesh()->getChangeIndex();
    writeFiles(adaptInfo, false);
94
  }
95
96

  /// This method is called before \ref beginIteration, \ref oneIteration and \ref endIteration.
97
98
  virtual void initTimestep(AdaptInfo *adaptInfo) 
  {}
99
100
101
102
103
104
105
106
107
108

  /// 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)
109
  { 
110
    prob->writeFiles(adaptInfo, force);
111
  }
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  
  // 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
128
  inline const FiniteElemSpace* getFeSpace(int comp = 0) 
129
130
131
132
133
134
135
136
  {
    return prob->getFeSpace(comp); 
  }

  /// name of the baseBroblem
  std::string getName()
  {
    return name;
137
  }
138
139
140
141

  int getNumProblems() 
  {
    return 1;
142
  }
143
144
145
146
  
  int getNumComponents()
  {
    return prob->getNumComponents();
147
  }
148

149
  ProblemType *getProblem(int number = 0)
150
  {
151
    if (number < 0 || number >= getNumProblems())
152
      throw(std::runtime_error("problem with given number does not exist"));
153

154
155
    if (number == 0)
      return prob;
156
157
158

    return NULL;
  }
159

Praetorius, Simon's avatar
Praetorius, Simon committed
160
  ProblemType *getProblem(std::string name_)
161
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
162
    if (name_ == "prob")
163
164
      return prob;
    else
Praetorius, Simon's avatar
Praetorius, Simon committed
165
166
167
168
169
170
171
172
      throw(std::runtime_error("problem with given name '" + name_ + "' does not exist"));
  }

  void setProblem(ProblemType *prob_, bool destroy = true)
  {
    if (destroy && prob)
      delete prob;
    prob = prob_;
173
  }
174
175
176
177
178
179
180
181
182
183
184
185
186

  // setting methods

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

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

187
188
189
190
191
  void serialize(std::ostream&) 
  {}

  void deserialize(std::istream&) 
  {}
192
193

  /// method where operators are added to the problem
194
195
  virtual void fillOperators()
  {}
196
197
  
  /// method where boundary conditions are added to the problem
198
199
  virtual void fillBoundaryConditions() 
  {}
200
201
202
203
204
205
206

  /// 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);
  
207
208
209
  template<typename T>
  static void initFileWriterFromFile(AdaptInfo* adaptInfo, FileWriterTemplated<T>& fileWriter, bool keep_all = false);
  
210
protected:
Praetorius, Simon's avatar
Praetorius, Simon committed
211
  std::string name;
212
213
214
215
216
217
218
219
220
221
222
223
224

  ProblemType *prob;

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

  int nTimesteps;
  int oldMeshChangeIdx;

  double oldTimestep;
225
226
227
228
  
  /// lists of objects to delete in the destructor
  std::vector<OperatorTerm*> operatorTermList;
  std::vector<Operator*> operatorList;
229
230
231
232
233
234
235
236
237
238
239

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

};

#include "BaseProblem.hh"

typedef BaseProblem<ProblemStat> StandardBaseProblem;

#endif // BASE_PROBLEM_H