ProblemStat.h 21.5 KB
Newer Older
1
2
3
4
5
6
7
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
8
 * Authors:
9
10
11
12
13
14
15
16
17
 * Simon Vey, Thomas Witkowski, Andreas Naumann, 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.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
18
 *
19
 ******************************************************************************/
20
21


22

23
/** \file ProblemStat.h */
24

25
26
#ifndef AMDIS_PROBLEM_STAT_H
#define AMDIS_PROBLEM_STAT_H
27

Thomas Witkowski's avatar
Thomas Witkowski committed
28
29
#include <vector>
#include <list>
30
#include <functional>
31
#include "AMDiS_fwd.h"
32
#include "ProblemStatBase.h"
33
#include "Initfile.h"
34
35
36
#include "Boundary.h"
#include "MatrixVector.h"
#include "StandardProblemIteration.h"
37
#include "io/ElementFileWriter.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
38
#include "ComponentTraverseInfo.h"
39
#include "AbstractFunction.h"
40
#include "solver/SolverMatrix.h"
41
#include "SystemVector.h"
42
43
44

namespace AMDiS {

45
  struct OperatorPos
46
47
48
49
50
  {
    int row, col;
    double *factor, *estFactor;
  };

51

52
  /**
53
   * \ingroup Problem
54
55
56
57
58
   *
   * \brief
   * This class defines the stationary problem definition in sequential
   * computations. For parallel computations, see \ref ParallelProblemStatBase.
   **/
59
  class ProblemStatSeq : public ProblemStatBase
60
  {
61
  protected:
62
    // Defines a mapping type from dof indices to world coordinates.
63
    typedef std::map<DegreeOfFreedom, WorldVector<double> > DofToCoord;
64
65

    // Defines a mapping type from dof indices to world coordinates.
66
    typedef std::map<WorldVector<double>, DegreeOfFreedom> CoordToDof;
67

68
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
69
    /// Constructor
70
    ProblemStatSeq(std::string nameStr,
71
		   ProblemIterationInterface *problemIteration = NULL);
72

Thomas Witkowski's avatar
Thomas Witkowski committed
73
    /// Destructor
Thomas Witkowski's avatar
Thomas Witkowski committed
74
    virtual ~ProblemStatSeq();
75

Thomas Witkowski's avatar
Thomas Witkowski committed
76
    /// Initialisation of the problem.
77
    virtual void initialize(Flag initFlag,
78
			    ProblemStatSeq *adoptProblem = NULL,
79
80
			    Flag adoptFlag = INIT_NOTHING);

Thomas Witkowski's avatar
Thomas Witkowski committed
81
    /// Used in \ref initialize().
82
83
    virtual void createMesh();

84
85
86
    /// Used in \ref initialize().
    virtual void createRefCoarseManager();

Thomas Witkowski's avatar
Thomas Witkowski committed
87
    /// Used in \ref initialize().
88
    virtual void createFeSpace(DOFAdmin *admin);
89

Thomas Witkowski's avatar
Thomas Witkowski committed
90
    /// Used in \ref initialize().
91
92
    virtual void createMatricesAndVectors();

Thomas Witkowski's avatar
Thomas Witkowski committed
93
    /// Used in \ref initialize().
94
95
    virtual void createSolver();

Thomas Witkowski's avatar
Thomas Witkowski committed
96
    /// Used in \ref initialize().
97
98
    virtual void createEstimator();

Thomas Witkowski's avatar
Thomas Witkowski committed
99
    /// Used in \ref initialize().
100
101
    virtual void createMarker();

Thomas Witkowski's avatar
Thomas Witkowski committed
102
    /// Used in \ref initialize().
103
104
    virtual void createFileWriter();

105
    /// Used in \ref initialize(). This function is deprecated and should not
106
    /// be used anymore. There is no guarantee that it will work in the future.
107
108
    virtual void doOtherStuff();

109
110
    /// Implementation of ProblemStatBase::solve(). Deligates the solving
    /// of problems system to \ref solver.
111
112
    void solve(AdaptInfo *adaptInfo,
	       bool createMatrixData = true,
113
	       bool storeMatrixData = false) override;
114

115
116
    /// Implementation of ProblemStatBase::estimate(). Deligates the estimation
    /// to \ref estimator.
117
    void estimate(AdaptInfo *adaptInfo) override;
118

119
120
    /// Implementation of ProblemStatBase::markElements().
    /// Deligated to \ref adapt.
121
    Flag markElements(AdaptInfo *adaptInfo) override;
122

123
124
    /// Implementation of ProblemStatBase::refineMesh(). Deligated to the
    /// RefinementManager of \ref adapt.
125
    Flag refineMesh(AdaptInfo *adaptInfo) override;
126

127
128
    /// Implementation of ProblemStatBase::coarsenMesh(). Deligated to the
    /// CoarseningManager of \ref adapt.
129
    Flag coarsenMesh(AdaptInfo *adaptInfo) override;
130

131
132
    /// Implementation of ProblemStatBase::buildBeforeRefine().
    /// Does nothing here.
133
    void buildBeforeRefine(AdaptInfo *adaptInfo, Flag) override {}
134

135
136
    /// Implementation of ProblemStatBase::buildBeforeCoarsen().
    /// Does nothing here.
137
    void buildBeforeCoarsen(AdaptInfo *adaptInfo, Flag) override {}
138

139
140
141
    /// Implementation of ProblemStatBase::buildAfterCoarsen().
    /// Assembles \ref A and \ref rhs. With the last two parameters, assembling
    /// can be restricted to matrices or vectors only.
142
    void buildAfterCoarsen(AdaptInfo *adaptInfo, Flag flag,
143
				   bool assembleMatrix = true,
144
				   bool assembleVector = true) override;
145

Praetorius, Simon's avatar
Praetorius, Simon committed
146
147
148
149
150
    /// assemble all operators of matrix and vector side
    void assemble(AdaptInfo* adaptInfo)
    {
      buildAfterCoarsen(adaptInfo, 0, true, true);
    }
151

152
153
    bool dualMeshTraverseRequired();

154
    void dualAssemble(AdaptInfo *adaptInfo, Flag flag,
155
		      bool asmMatrix = true, bool asmVector = true);
156

157
158
    /// Returns nr of components \ref nComponents
    virtual int getNumComponents()
159
160
    {
      return nComponents;
Thomas Witkowski's avatar
Thomas Witkowski committed
161
    }
162

163
    /// Returns nr of additional components \ref nAddComponents
164
165
166
167
    virtual int getNumAddComponents()
    {
      return nAddComponents;
    }
168

169
    /// Writes output files. TODO: Make obsolete.
170
171
    void writeFiles(AdaptInfo *adaptInfo, bool force);

172
173
174
    /// Writes output files.
    void writeFiles(AdaptInfo &adaptInfo, bool force);

Thomas Witkowski's avatar
Thomas Witkowski committed
175
    /// Interpolates fct to \ref solution.
176
    void interpolInitialSolution(std::vector<AbstractFunction<double, WorldVector<double> >*> *fct);
177

178
    /// Adds an operator to \ref A.
179
    void addMatrixOperator(Operator *op, int i, int j,
180
			   double *factor = NULL, double *estFactor = NULL);
181

182
    /// Adds an operator to \ref A.
183
    void addMatrixOperator(Operator &op, int i, int j,
184
			   double *factor = NULL, double *estFactor = NULL);
185

186
    /// Adds an operator to \ref rhs.
187
    void addVectorOperator(Operator *op, int i,
188
			   double *factor = NULL, double *estFactor = NULL);
189

190
    /// Adds an operator to \ref rhs.
191
    void addVectorOperator(Operator &op, int i,
192
			   double *factor = NULL, double *estFactor = NULL);
193

194
    /// Adds a Dirichlet boundary condition, where the rhs is given by an
195
    /// abstract function.
196
    virtual void addDirichletBC(BoundaryType type, int row, int col,
197
				AbstractFunction<double, WorldVector<double> > *b);
198
199


Praetorius, Simon's avatar
Praetorius, Simon committed
200
#if HAS_CXX11
201
    /// Adds a Dirichlet boundary condition, where the rhs is given by an
202
203
204
205
    /// lambda function or a std::function object
    virtual void addDirichletBC(BoundaryType type, int row, int col,
				std::function<double(WorldVector<double>)> b);
#endif
206

207
208
    /// Adds a Dirichlet boundary condition, where the rhs is given by a DOF
    /// vector.
209
210
211
    virtual void addDirichletBC(BoundaryType type, int row, int col,
				DOFVector<double> *vec);

212
213
    /// Adds a Neumann boundary condition, where the rhs is given by an
    /// abstract function.
214
    virtual void addNeumannBC(BoundaryType type, int row, int col,
215
216
			      AbstractFunction<double, WorldVector<double> > *n);

217
218
    /// Adds a Neumann boundary condition, where the rhs is given by an DOF
    /// vector.
219
    virtual void addNeumannBC(BoundaryType type, int row, int col,
220
221
222
			      DOFVector<double> *n);

    /// Adds Robin boundary condition.
223
    virtual void addRobinBC(BoundaryType type, int row, int col,
224
225
226
			    AbstractFunction<double, WorldVector<double> > *n,
			    AbstractFunction<double, WorldVector<double> > *r);

227
    /// Adds Robin boundary condition.
228
    virtual void addRobinBC(BoundaryType type, int row, int col,
229
230
231
232
			    DOFVector<double> *n,
			    DOFVector<double> *r);

    /// Adds Robin boundary condition.
233
    virtual void addRobinBC(BoundaryType type, int row, int col,
234
235
236
			    Operator *n,
			    Operator *r);

237
    /// Adds a periodic boundary condition.
238
239
    virtual void addPeriodicBC(BoundaryType type, int row, int col);

240
    /// add boundary operator to matrix side
241
    virtual void addBoundaryMatrixOperator(BoundaryType type,
242
243
          Operator *op, int row, int col);

244
    virtual void addBoundaryMatrixOperator(BoundaryType type,
245
246
247
248
249
250
          Operator &op, int row, int col)
    {
      addBoundaryMatrixOperator(type, &op, row, col);
    }

    /// add boundary operator to rhs (vector) side
251
    virtual void addBoundaryVectorOperator(BoundaryType type,
252
253
          Operator *op, int row);

254
    virtual void addBoundaryVectorOperator(BoundaryType type,
255
256
257
258
259
          Operator &op, int row)
    {
      addBoundaryVectorOperator(type, &op, row);
    }

260
261
    /// This function assembles a DOFMatrix and a DOFVector for the case,
    /// the meshes from row and col FE-space are equal.
262
    void assembleOnOneMesh(const FiniteElemSpace *feSpace,
Thomas Witkowski's avatar
Thomas Witkowski committed
263
			   Flag assembleFlag,
Thomas Witkowski's avatar
Thomas Witkowski committed
264
265
			   DOFMatrix *matrix, DOFVector<double> *vector);

Thomas Witkowski's avatar
Thomas Witkowski committed
266
267

    ///
268
269
270
271
    void assembleBoundaryConditions(DOFVector<double> *rhs,
				    DOFVector<double> *solution,
				    Mesh *mesh,
				    Flag assembleFlag);
272

273

274
    /** \name getting methods
275
     * \{
276
277
     */

Thomas Witkowski's avatar
Thomas Witkowski committed
278
    /// Returns \ref solution.
279
280
281
    inline SystemVector* getSolution()
    {
      return solution;
Thomas Witkowski's avatar
Thomas Witkowski committed
282
    }
283

284
    inline DOFVector<double>* getSolution(int i)
285
286
287
288
    {
      return solution->getDOFVector(i);
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
289
    /// Returns \ref rhs.
290
291
292
    inline SystemVector* getRhs()
    {
      return rhs;
Thomas Witkowski's avatar
Thomas Witkowski committed
293
    }
294

295
    inline DOFVector<double>* getRhsVector(int i = 0)
296
297
298
299
    {
      return rhs->getDOFVector(i);
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
300
    /// Returns \ref systemMatrix.
301
302
303
    inline Matrix<DOFMatrix*> *getSystemMatrix()
    {
      return systemMatrix;
Thomas Witkowski's avatar
Thomas Witkowski committed
304
    }
305

Thomas Witkowski's avatar
Thomas Witkowski committed
306
    /// Returns a pointer to the corresponding DOFMatrix.
307
    inline DOFMatrix* getSystemMatrix(int row, int col)
308
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
309
310
311
312
      return (*systemMatrix)[row][col];
    }

    /// Returns mesh of given component
313
    inline Mesh* getMesh(int comp = 0)
314
    {
315
      FUNCNAME("ProblemStatSeq::getMesh()");
Thomas Witkowski's avatar
Thomas Witkowski committed
316
      TEST_EXIT(comp < static_cast<int>(componentMeshes.size()) && comp >= 0)
317
	("invalid component number\n");
318
      return componentMeshes[comp];
Thomas Witkowski's avatar
Thomas Witkowski committed
319
    }
320

Thomas Witkowski's avatar
Thomas Witkowski committed
321
    /// Returns \ref meshes
322
    inline std::vector<Mesh*> getMeshes()
323
    {
324
      return meshes;
Thomas Witkowski's avatar
Thomas Witkowski committed
325
    }
326

Thomas Witkowski's avatar
Thomas Witkowski committed
327
    /// Returns \ref feSpace_.
328
329
    inline const FiniteElemSpace* getFeSpace(int comp = 0)
    {
330
      FUNCNAME("ProblemStatSeq::getFeSpace()");
331
      TEST_EXIT(comp < static_cast<int>(componentSpaces.size()) && comp >= 0)
332
	("invalid component number: %d\n", comp);
333
      return componentSpaces[comp];
Thomas Witkowski's avatar
Thomas Witkowski committed
334
    }
335

Thomas Witkowski's avatar
Thomas Witkowski committed
336
    /// Returns \ref feSpaces.
337
338
339
    inline std::vector<const FiniteElemSpace*>& getFeSpaces()
    {
      return feSpaces;
Thomas Witkowski's avatar
Thomas Witkowski committed
340
    }
341

Thomas Witkowski's avatar
Thomas Witkowski committed
342
    /// Returns \ref componentSpaces;
343
    inline std::vector<const FiniteElemSpace*>& getComponentSpaces()
344
    {
345
      return componentSpaces;
346
347
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
348
    /// Returns \ref estimator.
349
350
351
    inline std::vector<Estimator*> getEstimators()
    {
      return estimator;
Thomas Witkowski's avatar
Thomas Witkowski committed
352
    }
353

Thomas Witkowski's avatar
Thomas Witkowski committed
354
    /// Returns \ref estimator.
355
356
357
    inline Estimator* getEstimator(int comp = 0)
    {
      return estimator[comp];
Thomas Witkowski's avatar
Thomas Witkowski committed
358
    }
359

Thomas Witkowski's avatar
Thomas Witkowski committed
360
    /// Returns \ref refinementManager.
361
362
363
    inline RefinementManager* getRefinementManager(int comp = 0)
    {
      return refinementManager;
Thomas Witkowski's avatar
Thomas Witkowski committed
364
    }
365

Thomas Witkowski's avatar
Thomas Witkowski committed
366
    /// Returns \ref refinementManager.
367
368
369
    inline CoarseningManager* getCoarseningManager(int comp = 0)
    {
      return coarseningManager;
Thomas Witkowski's avatar
Thomas Witkowski committed
370
    }
371

Thomas Witkowski's avatar
Thomas Witkowski committed
372
    /// Returns \ref solver.
373
374
375
    inline LinearSolverInterface* getSolver()
    {
      return solver;
Thomas Witkowski's avatar
Thomas Witkowski committed
376
    }
377

Thomas Witkowski's avatar
Thomas Witkowski committed
378
    /// Returns \ref marker.
379
380
381
    inline Marker *getMarker(int comp = 0)
    {
      return marker[comp];
Thomas Witkowski's avatar
Thomas Witkowski committed
382
    }
383

Thomas Witkowski's avatar
Thomas Witkowski committed
384
    /// Returns \ref marker.
385
386
387
    inline std::vector<Marker*> getMarkers()
    {
      return marker;
Thomas Witkowski's avatar
Thomas Witkowski committed
388
    }
389

Thomas Witkowski's avatar
Thomas Witkowski committed
390
    /// Returns the name of the problem
391
    inline std::string getName() override
392
393
    {
      return name;
Thomas Witkowski's avatar
Thomas Witkowski committed
394
    }
395

Praetorius, Simon's avatar
Praetorius, Simon committed
396
    /// Returns the name of the problem
397
    inline std::string getComponentName(int comp = 0)
Praetorius, Simon's avatar
Praetorius, Simon committed
398
399
400
401
402
403
    {
      TEST_EXIT(comp < static_cast<int>(componentNames.size()) && comp >= 0)
	("invalid component number\n");
      return componentNames[comp];
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
404
    /// Returns \ref useGetBound.
405
406
407
    inline bool getBoundUsed()
    {
      return useGetBound;
Thomas Witkowski's avatar
Thomas Witkowski committed
408
    }
409

410
411
412
413
414
415
    /// Returns \ref info.
    int getInfo()
    {
      return info;
    }

416
417
418
419
420
421
    /// Returns \ref deserialized;
    bool isDeserialized()
    {
      return deserialized;
    }

422
423
424
    /** \} */

    /** \name setting methods
425
     * \{
426
427
     */

Thomas Witkowski's avatar
Thomas Witkowski committed
428
    /// Sets \ref estimator.
429
430
431
    inline void setEstimator(std::vector<Estimator*> est)
    {
      estimator = est;
Thomas Witkowski's avatar
Thomas Witkowski committed
432
    }
433

Thomas Witkowski's avatar
Thomas Witkowski committed
434
    /// Sets the FE space for the given component.
435
    inline void setFeSpace(const FiniteElemSpace *feSpace, int comp = 0)
436
    {
437
      feSpaces[comp] = feSpace;
Thomas Witkowski's avatar
Thomas Witkowski committed
438
    }
439

440
441
442
443
444
    void setFeSpaces(std::vector<FiniteElemSpace const*> feSpaces_)
    {
      feSpaces = feSpaces_;
    }

445
    void setComponentSpace(int comp, const FiniteElemSpace *feSpace)
446
447
448
    {
      if (static_cast<int>(componentSpaces.size()) < nComponents)
        componentSpaces.resize(nComponents);
449
      TEST_EXIT(comp >= 0 && comp < nComponents + nAddComponents)
450
451
452
453
        ("Component number not in feasable range!");

      componentSpaces[comp] = feSpace;
    }
454

Thomas Witkowski's avatar
Thomas Witkowski committed
455
    /// Sets \ref estimator.
456
457
458
    inline void setEstimator(Estimator* est, int comp = 0)
    {
      estimator[comp] = est;
Thomas Witkowski's avatar
Thomas Witkowski committed
459
    }
460

Thomas Witkowski's avatar
Thomas Witkowski committed
461
    /// Sets \ref marker.
462
463
464
    inline void setMarker(Marker* mark, int comp = 0)
    {
      marker[comp] = mark;
Thomas Witkowski's avatar
Thomas Witkowski committed
465
    }
466

Thomas Witkowski's avatar
Thomas Witkowski committed
467
    /// Sets \ref solver.
468
469
470
    inline void setSolver(LinearSolverInterface* sol)
    {
      solver = sol;
Thomas Witkowski's avatar
Thomas Witkowski committed
471
    }
472

473
474
475
476
477
    void setSolverMatrix(SolverMatrix<Matrix<DOFMatrix*> >& solverMatrix_)
    {
      solverMatrix.setMatrix(*solverMatrix_.getOriginalMat());
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
478
    ///
479
    inline void setAssembleMatrixOnlyOnce(int i = 0, int j = 0, bool value = true)
480
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
481
      assembleMatrixOnlyOnce[i][j] = value;
482
483
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
484
    ///
485
    void setExactSolutionFct(AbstractFunction<double, WorldVector<double> > *fct,
486
			     int component)
487
    {
488
489
490
      exactSolutionFcts[component] = fct;
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
491
    ///
492
    AbstractFunction<double, WorldVector<double> > *getExactSolutionFct(int i = 0)
493
    {
494
      return exactSolutionFcts[i];
495
496
    }

497
    ///
498
    std::vector< AbstractFunction<double, WorldVector<double> >* > getExactSolutionFcts()
499
500
501
502
    {
      return exactSolutionFcts;
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
503
    ///
504
    void setComputeExactError(bool v)
505
    {
506
507
508
      computeExactError = v;
    }

509
510
511
512
513
514
    /// Sets \ref writeAsmInfo;
    void setWriteAsmInfo(bool b)
    {
      writeAsmInfo = b;
    }

515
    void setMeshes(std::vector<Mesh*> meshes_)
516
517
518
519
520
521
522
523
524
    {
      meshes = meshes_;
      nMeshes = static_cast<int>(meshes.size());
    }

    void setComponentMesh(int comp, Mesh* mesh)
    {
      if (static_cast<int>(componentMeshes.size()) < nComponents)
        componentMeshes.resize(nComponents);
525
      TEST_EXIT(comp >= 0 && comp < nComponents + nAddComponents)
526
527
528
529
530
531
532
533
534
535
536
537
538
539
        ("Component number not in feasable range!");

      componentMeshes[comp] = mesh;
    }

    void setRefinementManager(RefinementManager *ref)
    {
      refinementManager = ref;
    }

    void setCoarseningManager(CoarseningManager *coarse)
    {
      coarseningManager = coarse;
    }
540
541
    /** \} */

542
    /// Outputs the mesh of the given component, but the values are taken from
543
    /// the residual error estimator.
544
    void writeResidualMesh(int comp, AdaptInfo *adaptInfo, std::string name);
545

Thomas Witkowski's avatar
Thomas Witkowski committed
546
    /// Function that implements the serialization procedure.
547
    void serialize(std::ostream &out) override;
548

Thomas Witkowski's avatar
Thomas Witkowski committed
549
    /// Function that implements the deserialization procedure.
550
    void deserialize(std::istream &in) override;
Thomas Witkowski's avatar
Thomas Witkowski committed
551
552

    /// Returns \ref fileWriters.
553
    std::vector<FileWriterInterface*>& getFileWriterList()
554
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
555
556
      return fileWriters;
    }
557

558
    /// Returns \ref solutionTime.
559
560
561
562
    double getSolutionTime()
    {
      return solutionTime;
    }
563

564
    /// Returns \ref buildTime.
565
566
567
568
    double getBuildTime()
    {
      return buildTime;
    }
569

Thomas Witkowski's avatar
Thomas Witkowski committed
570
  protected:
571
572
    /// If the exact solution is known, the problem can compute the exact
    /// error instead of the error estimation. This is done in this function.
Thomas Witkowski's avatar
Thomas Witkowski committed
573
574
    void computeError(AdaptInfo *adaptInfo);

575
  protected:
576

Thomas Witkowski's avatar
Thomas Witkowski committed
577
    /// Name of this problem.
578
    std::string name;
579

Thomas Witkowski's avatar
Thomas Witkowski committed
580
    /// Number of problem components
581
    int nComponents;
582

583
584
    /// Number of additional components
    int nAddComponents;
585

586
587
    /// Stores the names for all components. Is used for naming the solution
    /// vectors, \ref solution.
588
    std::vector<std::string> componentNames;
589

590
591
592
    /// Number of problem meshes. If all components are defined on the same mesh,
    /// this number is 1. Otherwise, this variable is the number of different meshes
    /// within the problem.
Thomas Witkowski's avatar
Thomas Witkowski committed
593
594
595
    int nMeshes;

    /// FE spaces of this problem.
596
    std::vector<const FiniteElemSpace*> feSpaces;
597

Thomas Witkowski's avatar
Thomas Witkowski committed
598
    /// Meshes of this problem.
599
    std::vector<Mesh*> meshes;
600

Thomas Witkowski's avatar
Thomas Witkowski committed
601
    /// Pointer to the fe spaces for the different problem components
602
    std::vector<const FiniteElemSpace*> componentSpaces;
603

Thomas Witkowski's avatar
Thomas Witkowski committed
604
    /// Pointer to the meshes for the different problem components
605
    std::vector<Mesh*> componentMeshes;
606

607
608
609
    /// Stores information about which meshes must be traversed to assemble the
    /// specific components. I.e., it was implemented to make use of different
    /// meshes for different components.
Thomas Witkowski's avatar
Thomas Witkowski committed
610
    ComponentTraverseInfo traverseInfo;
611

Thomas Witkowski's avatar
Thomas Witkowski committed
612
    /// Responsible for element marking.
613
    std::vector<Marker*> marker;
614

Thomas Witkowski's avatar
Thomas Witkowski committed
615
    /// Estimator of this problem. Used in \ref estimate().
616
    std::vector<Estimator*> estimator;
617

Thomas Witkowski's avatar
Thomas Witkowski committed
618
    /// Linear solver of this problem. Used in \ref solve().
619
    LinearSolverInterface *solver;
620

Thomas Witkowski's avatar
Thomas Witkowski committed
621
622
    /// System vector  storing the calculated solution of the problem.
    SystemVector *solution;
623

624
    /// System vector for the right hand side
Thomas Witkowski's avatar
Thomas Witkowski committed
625
    SystemVector *rhs;
626

Thomas Witkowski's avatar
Thomas Witkowski committed
627
628
    /// System matrix
    Matrix<DOFMatrix*> *systemMatrix;
629

630
631
632
    /// Composed system matrix
    SolverMatrix<Matrix<DOFMatrix*> > solverMatrix;

633
634
635
636
637
    /// Some DOFMatrices of the systemMatrix may be assembled only once (for
    /// example if they are independent of the time or older solutions). If
    /// [i][j] of this field is set to true, the corresponding DOFMatrix will
    /// be assembled only once. All other matrices will be assembled at every
    /// time step.
638
    std::vector<std::vector<bool> > assembleMatrixOnlyOnce;
639

640
641
642
643
    /// If [i][j] of this field is set to true, the corresponding DOFMatrix of
    /// the systemMatrix has been assembled at least once. This field is used
    /// to determine, if assembling of a matrix can be ommitted, if it is set
    /// to be assembled only once.
644
    std::vector<std::vector<bool> > assembledMatrix;
645

Thomas Witkowski's avatar
Thomas Witkowski committed
646
647
    /// Determines whether domain boundaries should be considered at assembling.
    bool useGetBound;
648

Thomas Witkowski's avatar
Thomas Witkowski committed
649
    /// Writes the meshes and solution after the adaption loop.
650
    std::vector<FileWriterInterface*> fileWriters;
651

652
653
654
    /// 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.
Thomas Witkowski's avatar
Thomas Witkowski committed
655
    RefinementManager *refinementManager;
656

657
658
659
    /// 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.
Thomas Witkowski's avatar
Thomas Witkowski committed
660
    CoarseningManager *coarseningManager;
661

Thomas Witkowski's avatar
Thomas Witkowski committed
662
663
    /// Info level.
    int info;
664

665
666
    /// If true, the stationary problem was deserialized from some serialization
    /// file.
667
668
    bool deserialized;

669
670
671
    /// This vectors stores pointers to functions defining the exact solution of
    /// the problem. This may be used to compute the real error of the computed
    /// solution.
672
    std::vector<AbstractFunction<double, WorldVector<double> >*> exactSolutionFcts;
673

674
675
    /// If true, the error is not estimated but computed from the exact solution
    /// defined by \ref exactSolutionFcts.
676
    bool computeExactError;
677
678

    /// If at least on boundary condition is set, this variable is true. It is
679
    /// used to ensure that no operators are added after boundary condition were
680
    /// set. If this would happen, boundary conditions could set wrong on off
681
    /// diagonal matrices.
682
    bool boundaryConditionSet;
683

684
    /// If true, AMDiS prints information about the assembling procedure to
685
    /// the screen.
686
    bool writeAsmInfo;
687

688
    std::map<Operator*, std::vector<OperatorPos> > operators;
689

690
    /// time needed to solve the linear system
691
    double solutionTime;
692

693
    /// time needed to assemble the linear system
694
    double buildTime;
695

696
    template <class> friend class detail::CouplingProblemStat;
697
  };
698

699
  namespace detail
700
  {
701
    template <class ProblemStatType>
702
    struct ProblemStat : public ProblemStatType,
703
			 public StandardProblemIteration
704
    {
705
      using ProblemStatType::getName;
706
      using ProblemStatType::info;
707

708
709
710
711
712
713
714
715
716
717
      /// Constructor
      ProblemStat(std::string nameStr,
		  ProblemIterationInterface *problemIteration = NULL)
	: ProblemStatType(nameStr, problemIteration),
	  StandardProblemIteration(this)
      { }

      /// Returns number of managed problems
      // implements StandardProblemIteration::getNumProblems()
      virtual int getNumProblems() override
718
719
      {
	return 1;
720
721
722
723
724
725
      }

      /// Returns the problem with the given number. If only one problem
      /// is managed by this master problem, the number hasn't to be given.
      // implements StandardProblemIteration::getProblem(int)
      virtual ProblemStatBase *getProblem(int number = 0) override
726
727
      {
	return this;
728
729
730
731
732
733
734
      }

      /// Determines the execution order of the single adaption steps. If adapt is
      /// true, mesh adaption will be performed. This allows to avoid mesh adaption,
      /// e.g. in timestep adaption loops of timestep adaptive strategies.
      // implements StandardProblemIteration::oneIteration(AdaptInfo*, Flag)
      virtual Flag oneIteration(AdaptInfo *adaptInfo, Flag toDo = FULL_ITERATION) override
735
      {
736
737
738
739
	for (int i = 0; i < ProblemStatType::getNumComponents(); i++)
	  if (adaptInfo->spaceToleranceReached(i))
	    adaptInfo->allowRefinement(false, i);
	  else
740
	    adaptInfo->allowRefinement(true, i);
741
742
743
744
745

	return StandardProblemIteration::oneIteration(adaptInfo, toDo);
      }
    };
  }
746

747
748
#ifndef HAVE_PARALLEL_DOMAIN_AMDIS
  typedef detail::ProblemStat<ProblemStatSeq> ProblemStat;
749
#endif
750
751
752
}

#endif