Estimator.h 7.54 KB
Newer Older
1
2
3
4
5
6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut für 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
// ==                                                                        ==
// ============================================================================

/** \file Estimator.h */

/** \defgroup Estimator Estimator module
 * @{ <img src="estimator.png"> @}
 */

#ifndef AMDIS_ESTIMATOR_H
#define AMDIS_ESTIMATOR_H

29
#include "AMDiS_fwd.h"
30
31
32
33
34
#include "Flag.h"
#include "Global.h"
#include "FixVec.h"
#include "SystemVector.h"
#include "CreatorInterface.h"
35
36
#include "ComponentTraverseInfo.h"
#include "DualTraverse.h"
37
38
39
40
41
42
43
44
45
46
47
48

namespace AMDiS {

  /**
   * \ingroup Estimator
   * 
   * \brief
   * Estimator for scalar problems.
   */
  class Estimator
  {
  public:
49
50
51
    Estimator() 
      : traverseInfo(0)
    {}
52

53
    /// Constructor.
54
    Estimator(std::string name_, int r);
55

56
    /// destructor
Thomas Witkowski's avatar
Thomas Witkowski committed
57
    virtual ~Estimator() {}
58

59
    /// Returns \ref name of the Estimator
Thomas Witkowski's avatar
Thomas Witkowski committed
60
    inline std::string getName() const 
Thomas Witkowski's avatar
Thomas Witkowski committed
61
    { 
62
      return name; 
Thomas Witkowski's avatar
Thomas Witkowski committed
63
    }
64

65
    /// Performs the estimation and returns the final \ref est_sum
66
67
    virtual double estimate(double timestep = 0.0);

68
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
69
    virtual void init(double timestep) {}
70

71
72
73
74
75
76
77
78
    /** \brief
     * Estimates the error on an element. If there is more than one mesh used in the
     * problem description, it may be necessary to used the dual mesh traverse. In this
     * case elInfo is the element of the main mesh, i.e., the mesh of the row FE space,
     * and dualElInfo contains all elInfo informations about the main mesh element and
     * the col (or aux) mesh element.
     */
    virtual void estimateElement(ElInfo *elInfo, DualElInfo *dualElInfo = NULL) {}
79

80
    ///
81
    virtual void exit(bool output = true) {}
82

83
    /// Returns \ref est_sum of the Estimator
Thomas Witkowski's avatar
Thomas Witkowski committed
84
85
    inline double getErrorSum() const 
    { 
86
      return est_sum; 
Thomas Witkowski's avatar
Thomas Witkowski committed
87
    }
88

89
    /// Sets \ref est_sum of the Estimator
Thomas Witkowski's avatar
Thomas Witkowski committed
90
91
    inline void setErrorSum(double sum) 
    { 
92
      est_sum = sum; 
Thomas Witkowski's avatar
Thomas Witkowski committed
93
    }
94

95
    /// Returns \ref est_max of the Estimator
Thomas Witkowski's avatar
Thomas Witkowski committed
96
97
    inline double getErrorMax() const 
    { 
98
      return est_max; 
Thomas Witkowski's avatar
Thomas Witkowski committed
99
    }
100

101
    /// Returns the estimated time error.
Thomas Witkowski's avatar
Thomas Witkowski committed
102
103
    virtual double getTimeEst() const 
    { 
104
      return est_t_sum; 
Thomas Witkowski's avatar
Thomas Witkowski committed
105
    }
106

107
    /// Returns the maximal time estimation.
Thomas Witkowski's avatar
Thomas Witkowski committed
108
109
    virtual double getTimeEstMax() const 
    { 
110
      return est_t_max; 
Thomas Witkowski's avatar
Thomas Witkowski committed
111
    }
112

113
    /// Sets \ref est_max of the Estimator
Thomas Witkowski's avatar
Thomas Witkowski committed
114
115
    inline void setErrorMax(double m) 
    { 
116
      est_max = m; 
Thomas Witkowski's avatar
Thomas Witkowski committed
117
    }
118

119
    /// Returns \ref norm.
Thomas Witkowski's avatar
Thomas Witkowski committed
120
121
    inline Norm getErrorNorm() 
    { 
122
      return norm; 
Thomas Witkowski's avatar
Thomas Witkowski committed
123
    }
124

125
    /// Adds one system to the estimator.
126
127
128
129
    virtual void addSystem(DOFMatrix *matrix_,
			   DOFVector<double> *uh_,
			   DOFVector<double> *fh_,
			   DOFVector<double> *uhOld_ = NULL)
130
131
132
133
134
    {
      matrix.push_back(matrix_);
      uh.push_back(uh_);
      fh.push_back(fh_);
      uhOld.push_back(uhOld_);
Thomas Witkowski's avatar
Thomas Witkowski committed
135
    }
136

Thomas Witkowski's avatar
Thomas Witkowski committed
137
138
139
140
141
    void setNewMatrix(int i, DOFMatrix *m) 
    {
      matrix[i] = m;
    }

142
    /// Adds pointer to old solution to the given system.
143
    virtual void addUhOldToSystem(int system, DOFVector<double> *uhOld_) 
144
    {
Thomas Witkowski's avatar
nix.  
Thomas Witkowski committed
145
146
147
148
149
      FUNCNAME("Estimator::addUhOldToSystem()");

      TEST_EXIT(static_cast<int>(uhOld.size()) > system)("Invalid system!\n");
      TEST_EXIT(uhOld[system] == NULL)("There is already an uhOld!\n");

150
151
152
      uhOld[system] = uhOld_;
    }

153
    /// Returns number of systems.
Thomas Witkowski's avatar
Thomas Witkowski committed
154
155
    inline int getNumSystems() 
    { 
156
      return static_cast<int>(matrix.size()); 
Thomas Witkowski's avatar
Thomas Witkowski committed
157
    }
158

Thomas Witkowski's avatar
Thomas Witkowski committed
159
160
    inline Flag getTraverseFlag() 
    { 
161
      return traverseFlag; 
Thomas Witkowski's avatar
Thomas Witkowski committed
162
    }
163

Thomas Witkowski's avatar
Thomas Witkowski committed
164
165
    inline Mesh* getMesh() 
    { 
166
      return mesh; 
Thomas Witkowski's avatar
Thomas Witkowski committed
167
    }
168

Thomas Witkowski's avatar
Thomas Witkowski committed
169
170
    inline int getRow() 
    { 
171
      return row; 
Thomas Witkowski's avatar
Thomas Witkowski committed
172
    }
173

174
175
176
177
178
179
180
181
182
183
184
185
186
    /// Sets \ref traverseInfo.
    void setTraverseInfo(const ComponentTraverseInfo &ti)
    {
      traverseInfo = ti;
    }

  protected:
    /// Traverse one mesh to estimate the error.
    void singleMeshTraverse();

    /// Traverses two meshes to estimate the error.
    void dualMeshTraverse();

187
  protected:
188
    /// Name of the Estimator
189
    std::string name;
190

191
    /// Used norm
192
193
    Norm norm;
 
194
    /// Sum of all error estimates
195
196
    double est_sum;

197
198
199
    /// Maximal error estimate
    double est_max;

200
    /// Sum of all time error estimates
201
202
    double est_t_sum;

203
    /// Max of all time error estimates
204
205
206
207
208
209
210
211
    double est_t_max;

    /** \brief
     * Vector of DOFMatrix pointers. There can be more than one
     * DOFMatrix, if the Estimator is part of a vector valued 
     * estimator. Then it contains also coupling matrices
     * of the different vector components.
     */ 
212
    std::vector<DOFMatrix*> matrix;
213

214
    /// Vector of solution vectors for the different systems.
215
    std::vector<DOFVector<double>*> uh;
216
217
218
219
220

    /** \brief
     * Vector of old solutions vectors for the different systems. 
     * Used for instationary problems.
     */
221
    std::vector<DOFVector<double>*> uhOld;
222

223
    /// Vector of RHS vectors for the different systems.
224
    std::vector<DOFVector<double>*> fh;
225
226
227
228
229
230
231
232
233
234

    /** \brief
     * Used, if the scalar estimator builds one row of a vector valued estimator.
     * Then row gives the position in the vector valued estimator, used
     * for calculation of the time derivative.
     */
    int row;

    Flag traverseFlag;

235
236
237
238
    /** \brief
     * The mesh on which the error must be estimated. If there is more than one mesh
     * used, here the main, i.e., the row mesh, is stored.
     */
239
240
    Mesh *mesh;

241
242
243
244
245
246
247
    /** \brief
     * If there is only one mesh used at all, this variable is not used. In the case
     * that the error must be estimated on a system row with more than one mesh, here
     * either the column mesh or the auxiliary mesh is stored.
     */
    Mesh *auxMesh;

248
    double timestep;
249
250
251
252
253
254

    /** \brief
     * Stores information about which mesh(es) must be travesed to estimate
     * the error on the component matrices.
     */
    ComponentTraverseInfo traverseInfo;
255
256
  };

257

258
259
260
261
262
263
264
265
266
  /** 
   * \ingroup Estimator
   *
   * \brief
   * Interface for creators of concrete estimators. 
   */
  class EstimatorCreator : public CreatorInterface<Estimator>
  { 
  public:
267
    /// constructor
Thomas Witkowski's avatar
Thomas Witkowski committed
268
    EstimatorCreator() : row(-1) {}
269

270
    /// destructor
Thomas Witkowski's avatar
Thomas Witkowski committed
271
    virtual ~EstimatorCreator() {}
272

273
    /// Sets \ref name
Thomas Witkowski's avatar
Thomas Witkowski committed
274
275
    void setName(std::string name_) 
    { 
276
      name = name_; 
Thomas Witkowski's avatar
Thomas Witkowski committed
277
    }
278

279
    /// Sets \ref row
Thomas Witkowski's avatar
Thomas Witkowski committed
280
281
    void setRow(int r) 
    { 
282
      row = r; 
Thomas Witkowski's avatar
Thomas Witkowski committed
283
    }
284
285

  protected:
286
    /// Name of the estimator to be created.
287
    std::string name;
288

289
    /// Row of the estimator.
290
291
292
293
294
295
    int row;
  };

}

#endif // AMDIS_ESTIMATOR_H