ProblemInstat.h 6.38 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

/** \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:
43
44
    /// Constructor.
    ProblemInstat(std::string probName,
45
		  ProblemStatBase *initialProb)
46
      : name(probName),
47
	initialProblem(initialProb ? initialProb : this)
48
    {}
49

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    double* getTau()
    {
      return τ
    }

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

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

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

    /// Time
    double cTime;

    /// Timestep
    double tau;

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


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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

#endif