Estimator.h 7.09 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

/** \file Estimator.h */

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

#ifndef AMDIS_ESTIMATOR_H
#define AMDIS_ESTIMATOR_H

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

namespace AMDiS {

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

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

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

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

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

69
    ///
70
    virtual void init(double timestep) =0;
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.
     */
79
    virtual void estimateElement(ElInfo *elInfo, DualElInfo *dualElInfo = NULL) =0;
80

81
    ///
82
    virtual void exit(bool output = true) =0;
83

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

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

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

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

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

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

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

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

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

143
    /// Adds pointer to old solution to the given system.
144
    virtual void addUhOldToSystem(int system, DOFVector<double> *uhOld_) 
145
    {
Thomas Witkowski's avatar
nix.  
Thomas Witkowski committed
146
147
148
149
150
      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");

151
152
153
      uhOld[system] = uhOld_;
    }

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

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

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

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

175
176
177
178
179
180
181
182
183
184
185
186
187
    /// 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();

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

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

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

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

204
    /// Max of all time error estimates
205
206
207
208
209
210
211
212
    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.
     */ 
213
    std::vector<DOFMatrix*> matrix;
214

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

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

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

    /** \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;

236
237
238
239
    /** \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.
     */
240
241
    Mesh *mesh;

242
243
244
245
246
247
248
    /** \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;

249
    double timestep;
250
251
252
253
254
255

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

258

259
260
261
262
263
264
265
266
267
  /** 
   * \ingroup Estimator
   *
   * \brief
   * Interface for creators of concrete estimators. 
   */
  class EstimatorCreator : public CreatorInterface<Estimator>
  { 
  public:
268
    /// constructor
269
    EstimatorCreator() : row(-1), uh(NULL) {}
270

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

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

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

286
287
288
289
290
    inline void setSolution(DOFVector<double> *uh_)
    {
      uh = uh_;
    }

291
  protected:
292
    /// Name of the estimator to be created.
293
    std::string name;
294

295
    /// Row of the estimator.
296
    int row;
297
298
299

    /// Pointer to solution vector
    DOFVector<double> *uh;
300
301
302
303
304
  };

}

#endif // AMDIS_ESTIMATOR_H