ProblemScal.h 10.2 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
// ==                                                                        ==
// ============================================================================

/** \file ProblemScal.h */

#ifndef AMDIS_PROBLEMSCAL_H
#define AMDIS_PROBLEMSCAL_H

25
#include <list>
26
#include "AMDiS_fwd.h"
27
28
29
30
31
32
#include "Global.h"
#include "ProblemStatBase.h"
#include "AbstractFunction.h"
#include "FixVec.h"
#include "Boundary.h"
#include "StandardProblemIteration.h"
33

34
35
36
37
38
39
namespace AMDiS {

  class ProblemScal : public ProblemStatBase,
		      public StandardProblemIteration
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
40
    ProblemScal(std::string nameStr, 
41
		ProblemIterationInterface *problemIteration = NULL)
42
      : StandardProblemIteration(this),
43
        name(nameStr),
Thomas Witkowski's avatar
Thomas Witkowski committed
44
	feSpace(NULL),
45
46
47
48
49
50
51
	mesh(NULL),
	marker(NULL),
	estimator(NULL),
	solver(NULL),
	solution(NULL),
	rhs(NULL),
	systemMatrix(NULL),
52
	useGetBound(true),
53
54
	refinementManager(NULL),
	coarseningManager(NULL),
Thomas Witkowski's avatar
Thomas Witkowski committed
55
	info(10)
56
    {}
57

58
    /// Destructor
59
    virtual ~ProblemScal();
60

61
    /// Initialisation of the problem.
62
63
64
65
    virtual void initialize(Flag initFlag,
			    ProblemScal *adoptProblem = NULL,
			    Flag adoptFlag = INIT_NOTHING);

66
    /// Used in \ref initialize().
67
68
    virtual void createMesh();

69
    /// Used in \ref initialize().
70
71
    virtual void createFESpace();

72
    /// Used in \ref initialize().
73
74
    virtual void createMatricesAndVectors();

75
    /// Used in \ref initialize().
76
77
    virtual void createSolver();

78
    /// Used in \ref initialize().
79
80
    virtual void createEstimator();

81
    /// Used in \ref initialize().
82
83
    virtual void createMarker();

84
    /// Used in \ref initialize().
85
86
87
88
89
90
    virtual void createFileWriter();

    /** \brief
     * Implementation of ProblemStatBase::solve(). Deligates the solving
     * of problems system to \ref solver.
     */
91
    virtual void solve(AdaptInfo *adaptInfo, bool fixedMatrix);
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

    /** \brief
     * Implementation of ProblemStatBase::estimate(). Deligates the estimation
     * to \ref estimator.
     */
    virtual void estimate(AdaptInfo *adaptInfo);

    /** \brief
     * Implementation of ProblemStatBase::markElements().
     * Deligated to \ref adapt.
     */
    virtual Flag markElements(AdaptInfo *adaptInfo);

    /** \brief
     * Implementation of ProblemStatBase::refineMesh(). Deligated to the
     * RefinementManager of \ref adapt.
     */
    virtual Flag refineMesh(AdaptInfo *adaptInfo);

    /** \brief
     * Implementation of ProblemStatBase::coarsenMesh(). Deligated to the
     * CoarseningManager of \ref adapt.
     */
    virtual Flag coarsenMesh(AdaptInfo *adaptInfo);

    /** \brief
     * Implementation of ProblemStatBase::buildBeforeRefine().
     * Does nothing here.
     */
121
    virtual void buildBeforeRefine(AdaptInfo *adaptInfo, Flag) {}
122
123
124
125
126

    /** \brief
     * Implementation of ProblemStatBase::buildBeforeCoarsen().
     * Does nothing here.
     */
127
    virtual void buildBeforeCoarsen(AdaptInfo *adaptInfo, Flag) {}
128

129
130
    void createPrecon();

131
132
133
134
    /** \brief
     * Implementation of ProblemStatBase::buildAfterCoarsen().
     * Assembles \ref A and \ref rhs.
     */
135
136
137
    virtual void buildAfterCoarsen(AdaptInfo *adaptInfo, Flag flag,
				   bool assembleMatrix = true,
				   bool assembleVector = true);
138

139
    /// Returns number of managed problems
140
141
    virtual int getNumProblems() 
    { 
142
      return 1; 
143
    }
144

145
    /// Implementation of ProblemStatBase::getNumComponents()
146
147
    virtual int getNumComponents() 
    { 
148
      return 1; 
149
    }
150
151
152
153
154

    /** \brief
     * Returns the problem with the given number. If only one problem
     * is managed by this master problem, the number hasn't to be given.
     */
155
156
    virtual ProblemStatBase *getProblem(int number = 0) 
    { 
157
      return this; 
158
    }
159

160
    /// Writes output files. TODO: Make obsolete.
161
162
    void writeFiles(AdaptInfo *adaptInfo, bool force);

163
164
165
    /// Writes output files.
    void writeFiles(AdaptInfo &adaptInfo, bool force);

166
167
    /// Interpolates fct to \ref solution.
    void interpolInitialSolution(AbstractFunction<double, WorldVector<double> > *fct);
168

169
    /// Adds an Operator to \ref systemMatrix.
170
    void addMatrixOperator(Operator *op, 
171
			   double *factor = NULL, double *estFactor = NULL);
172

173
    /// Adds an Operator to \ref rhs.
174
    void addVectorOperator(Operator *op, 
175
			   double *factor = NULL, double *estFactor = NULL);
176

177
    /// Adds dirichlet boundary conditions.
178
179
180
    virtual void addDirichletBC(BoundaryType type, 
				AbstractFunction<double, WorldVector<double> >* b);

181
    /// Adds dirichlet boundary conditions.
182
183
184
    virtual void addDirichletBC(BoundaryType type, 
				DOFVector<double> *vec);

185
    /// Adds robin boundary conditions.
186
187
188
189
    virtual void addRobinBC(BoundaryType type, 
			    AbstractFunction<double, WorldVector<double> > *n,
			    AbstractFunction<double, WorldVector<double> > *r);

190
    /// Adds robin boundary conditions.
191
    virtual void addRobinBC(BoundaryType type, 
192
			    DOFVector<double> *n, 
193
194
			    DOFVector<double> *r);

195
    /// Adds Neumann boundary conditions.
196
197
198
199
    virtual void addNeumannBC(BoundaryType type, 
			      AbstractFunction<double, WorldVector<double> > *n);


200
    /// Adds periodic boundary conditions.
201
    virtual void addPeriodicBC(BoundaryType type);
202
    
203
204
205
206
    /** \name getting methods
     * \{ 
     */

207
    /// Returns \ref solution.
208
209
    inline DOFVector<double>* getSolution() 
    { 
210
211
      return solution; 
    }
212

213
    /// Returns \ref rhs.
214
215
    inline DOFVector<double>* getRHS() 
    { 
216
217
      return rhs; 
    }
218

219
    /// Returns \ref systemMatrix.
220
221
    inline DOFMatrix *getSystemMatrix() 
    { 
222
223
      return systemMatrix; 
    }
224

225
    /// Returns \ref mesh
226
227
    inline Mesh* getMesh() 
    { 
228
229
      return mesh; 
    }
230

Thomas Witkowski's avatar
Thomas Witkowski committed
231
    /// Returns \ref feSpace.
232
233
    inline FiniteElemSpace* getFESpace() 
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
234
      return feSpace; 
235
    }
236

237
    /// Returns \ref estimator_.
238
239
    inline Estimator* getEstimator() 
    { 
240
241
      return estimator; 
    }
242

243
    /// Returns \ref refinementManager.
244
245
    inline RefinementManager* getRefinementManager() 
    { 
246
      return refinementManager; 
247
    }
248

249
    /// Returns \ref solver.
250
251
    inline OEMSolver* getSolver() 
    { 
252
253
      return solver; 
    }
254

255
    /// Returns \ref marker_.
256
257
    inline Marker *getMarker() 
    { 
258
259
      return marker; 
    }
260

261
    /// Returns \ref name.
Thomas Witkowski's avatar
Thomas Witkowski committed
262
    virtual inline std::string getName() 
263
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
264
      return name; 
265
    }
266

267
    /// Returns \ref useGetBound.
268
269
    inline bool getBoundUsed() 
    { 
270
      return useGetBound; 
271
    }
272

273
    ///
274
275
    inline CoarseningManager *getCoarseningManager() 
    {
276
      return coarseningManager;
277
    }
278
279
280
281
282
283
284

    /** \} */

    /** \name setting methods
     * \{ 
     */

285
    /// Sets \ref mesh
286
287
    void setMeshFromProblemVec(ProblemVec* pv, int i = 0); 

Thomas Witkowski's avatar
Thomas Witkowski committed
288
    /// Sets \ref feSpace.
289
290
    inline void setFESpace(FiniteElemSpace* fe) 
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
291
      feSpace = fe; 
292
    }
293

294
    /// Sets \ref estimator_.
295
296
    inline void setEstimator(Estimator* est) 
    { 
297
298
      estimator = est; 
    }
299

300
    /// Sets \ref solver.
301
302
    inline void setSolver(OEMSolver* sol) 
    { 
303
304
      solver = sol; 
    }
305

306
    /// Sets \ref marker.
307
308
    inline void setMarker(Marker *m) 
    {
309
310
      marker = m;
    }
311
312
313

    /** \} */

Thomas Witkowski's avatar
Thomas Witkowski committed
314
    void writeResidualMesh(AdaptInfo *adaptInfo, std::string name);
315

316
    /// Serialization of this class to a stream.
Thomas Witkowski's avatar
Thomas Witkowski committed
317
    virtual void serialize(std::ostream &out);
318

319
    /// Deserialization of this class from a stream.
Thomas Witkowski's avatar
Thomas Witkowski committed
320
    virtual void deserialize(std::istream &in);
321

322
    /// Returns \ref fileWriters.
323
    std::vector<FileWriterInterface*>& getFileWriterList() 
324
    {
325
326
      return fileWriters;
    }
327

328
329
330
331
332
333
    /// Returns \ref info.
    int getInfo()
    {
      return info;
    }

334
  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
335
336
    /// Name of this problem.
    std::string name;
337

338
    /// FiniteElemSpace of this problem.
Thomas Witkowski's avatar
Thomas Witkowski committed
339
    FiniteElemSpace *feSpace;
340

341
    /// Mesh of this problem.
342
    Mesh *mesh;
343

344
    /// Responsible for element marking.
345
    Marker *marker;
346

347
    /// Estimator of this problem. Used in \ref estimate().
348
    Estimator *estimator;
349

350
    /// Linear solver of this problem. Used in \ref solve().
351
    OEMSolver *solver;
352

353
    /// DOFVector storing the calculated solution of the problem.
354
    DOFVector<double> *solution;
355

356
    /// DOFVector for the right hand side 
357
    DOFVector<double> *rhs;
358

359
    /// System matrix
360
    DOFMatrix *systemMatrix;
361

362
363
    /// Determines whether domain boundaries should be considered at assembling.
    bool useGetBound;
364

365
    /// Writes the meshes and solution after the adaption loop.
366
    std::vector<FileWriterInterface*> fileWriters;
367
368
369
370
371
372

    /** \brief
     * All actions of mesh refinement are performed by refinementManager.
     * If new refinement algorithms should be realized, one has to override
     * RefinementManager and give one instance of it to AdaptStationary.
     */
373
    RefinementManager *refinementManager;
374
375
376
377
378
379

    /** \brief
     * All actions of mesh coarsening are performed by coarseningManager.
     * If new coarsening algorithms should be realized, one has to override
     * CoarseningManager and give one instance of it to AdaptStationary.
     */
380
    CoarseningManager *coarseningManager;
381
  
382
    /// Info level.
Thomas Witkowski's avatar
Thomas Witkowski committed
383
    int info;
384
385
386
387
388
  };

}

#endif