ProblemInstat.h 6.99 KB
Newer Older
1
2
3
4
5
6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut fr Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
12
13
14
15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// ==                                                                        ==
// ============================================================================

/** \file ProblemInstat.h */

#ifndef AMDIS_PROBLEM_INSTAT_H_
#define AMDIS_PROBLEM_INSTAT_H_

#include "ProblemScal.h"
#include "ProblemVec.h"
#include "ProblemTimeInterface.h"
#include "AdaptInstationary.h"

namespace AMDiS {

  /**
   * \ingroup Problem
   *
   * \brief
   * Base class for ProblemInstatScal and ProblemInstatVec.
   */
  class ProblemInstat : public ProblemTimeInterface,
			public ProblemStatBase
  {
  public:
42
43
    /// Constructor.
    ProblemInstat(std::string probName,
44
		  ProblemStatBase *initialProb)
45
      : name(probName),
46
	initialProblem(initialProb ? initialProb : this)
47
    {}
48

49
    /// Destructor.
50
51
    virtual ~ProblemInstat();

52
    /// Initialisation of the problem.
53
54
55
56
    virtual void initialize(Flag initFlag,
			    ProblemInstat *adoptProblem = NULL,
			    Flag adoptFlag = INIT_NOTHING);

57
58
59
60
61
62
63
    virtual void setTime(AdaptInfo* adaptInfo) 
    {
      cTime = adaptInfo->getTime();
      tau = adaptInfo->getTimestep();
      invTau = 1.0 / tau;
    }

64
65
    virtual void solve(AdaptInfo* adaptInfo) {}

66
67
    virtual void solve(AdaptInfo *adaptInfo, bool fixedMatrix) 
    {
68
69
      solve(adaptInfo);
    }
70

71
    virtual void estimate(AdaptInfo *adaptInfo) {}
72

73
    virtual void buildBeforeRefine(AdaptInfo *adaptInfo, Flag) {}
74

75
    virtual void buildBeforeCoarsen(AdaptInfo *adaptInfo, Flag) {}
76

77
    virtual void buildAfterCoarsen(AdaptInfo *adaptInfo, Flag, bool, bool) {}
78

79
80
    virtual Flag markElements(AdaptInfo *adaptInfo) 
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
81
      return 0; 
82
    }
83

84
85
    virtual Flag refineMesh(AdaptInfo *adaptInfo) 
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
86
      return 0; 
87
    }
88

89
90
    virtual Flag coarsenMesh(AdaptInfo *adaptInfo) 
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
91
      return 0; 
92
    }
93

94
    /// Implementation of ProblemTimeInterface::closeTimestep().
95
    virtual void closeTimestep() {}
96

97
    /// Returns \ref name.
Thomas Witkowski's avatar
Thomas Witkowski committed
98
    inline std::string getName() 
99
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
100
      return name; 
101
    }
102

103
    /// Used by \ref problemInitial
104
105
    virtual void solveInitialProblem(AdaptInfo *adaptInfo);  

106
107
108
109
110
111
112
113
114
115
116
117
118
119
    double* getTime()
    {
      return &cTime;
    }

    double* getTau()
    {
      return τ
    }

    double* getInvTau()
    {
      return &invTau;
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
120

121
  protected:
122
    /// Name of the problem.
123
    std::string name;
124
125

    ProblemStatBase *initialProblem;
126
127
128
129
130
131
132
133
134

    /// Time
    double cTime;

    /// Timestep
    double tau;

    /// 1 / timestep
    double invTau;
135
136
137
138
139
140
141
142
143
144
145
146
  };


  /**
   * \ingroup Problem
   *
   * \brief
   * Standard implementation of ProblemTimeInterface for a time dependent problems.
   */
  class ProblemInstatScal : public ProblemInstat
  {
  public:
147
    /// Constructs a ProblemInstatScal with prob as its stationary problem.
148
    ProblemInstatScal(std::string name,
149
150
151
		      ProblemScal *prob,
		      ProblemStatBase *initialProb = NULL);

152
153
154
155
    ProblemInstatScal(std::string name, ProblemScal& prob);

    ProblemInstatScal(std::string name, ProblemScal& prob, ProblemStatBase& initialProb);

156
    /// Destructor.
157
158
    virtual ~ProblemInstatScal();

159
    /// Initialisation of the problem.
160
161
162
163
    virtual void initialize(Flag initFlag,
			    ProblemInstat *adoptProblem = NULL,
			    Flag adoptFlag = INIT_NOTHING);

164
    /// Used in \ref initialize().
165
    virtual void createUhOld();
166
 
167
    /// Implementation of ProblemTimeInterface::initTimestep().
168
169
    virtual void initTimestep(AdaptInfo *adaptInfo);

170
    /// Implementation of ProblemTimeInterface::closeTimestep().
171
172
    virtual void closeTimestep(AdaptInfo *adaptInfo);
  
173
174
175
    /// Returns \ref problemStat.
    inline ProblemScal* getStatProblem() 
    { 
176
      return problemStat; 
177
    }
178

179
180
181
    /// Returns \ref oldSolution.
    inline DOFVector<double> *getOldSolution() 
    { 
182
      return oldSolution; 
183
    }
184

185
    /// Used by \ref problemInitial
186
187
    virtual void transferInitialSolution(AdaptInfo *adaptInfo);  

188
    virtual void serialize(std::ostream &out) {}
Thomas Witkowski's avatar
Thomas Witkowski committed
189

190
    virtual void deserialize(std::istream &in) {}
191
192
   
  protected:
193
    /// Space problem solved in each timestep.
194
195
    ProblemScal* problemStat;

196
    /// Solution of the last timestep.
197
198
199
200
201
202
203
204
205
206
207
208
209
210
    DOFVector<double>* oldSolution;
  };


  /**
   * \ingroup Problem
   *
   * \brief
   * Standard implementation of ProblemTimeInterface for a time dependent 
   * vector valued problems.
   */
  class ProblemInstatVec : public ProblemInstat
  {
  public:
211
    /// Constructs a ProblemInstatVec with prob as its stationary problem.
212
    ProblemInstatVec(std::string name, 
213
214
215
		     ProblemVec *prob,
		     ProblemStatBase *initialProb = NULL);

216
217
218
219
    ProblemInstatVec(std::string name, ProblemVec &prob);

    ProblemInstatVec(std::string name, ProblemVec &prob, ProblemStatBase &initialProb);

220
    /// Destructor.
221
222
    virtual ~ProblemInstatVec();

223
    /// Initialisation of the problem.
224
225
226
227
    virtual void initialize(Flag initFlag,
			    ProblemInstat *adoptProblem = NULL,
			    Flag adoptFlag = INIT_NOTHING);

228
    /// Used in \ref initialize().
229
230
    virtual void createUhOld();

231
    /// Implementation of ProblemTimeInterface::initTimestep().
232
233
    virtual void initTimestep(AdaptInfo *adaptInfo);

234
    /// Implementation of ProblemTimeInterface::closeTimestep().
235
236
    virtual void closeTimestep(AdaptInfo *adaptInfo);
  
237
238
239
    /// Returns \ref problemStat.
    inline ProblemVec* getStatProblem() 
    {
240
      return problemStat; 
Thomas Witkowski's avatar
Thomas Witkowski committed
241
    }
242

243
244
245
    /// Returns \ref oldSolution.
    inline SystemVector *getOldSolution() 
    { 
246
      return oldSolution; 
Thomas Witkowski's avatar
Thomas Witkowski committed
247
    }
248

249
    /// Used by \ref problemInitial
250
251
    virtual void transferInitialSolution(AdaptInfo *adaptInfo);  

Thomas Witkowski's avatar
Thomas Witkowski committed
252
    virtual void serialize(std::ostream &out) {}
Thomas Witkowski's avatar
Thomas Witkowski committed
253

Thomas Witkowski's avatar
Thomas Witkowski committed
254
    virtual void deserialize(std::istream &in) {}
255
256

  protected:
257
    /// Space problem solved in each timestep.
258
259
    ProblemVec* problemStat;

260
    /// Solution of the last timestep.
261
262
263
264
265
266
    SystemVector *oldSolution;
  };

}

#endif