Estimator.h 7.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Flag.h"
#include "Global.h"
#include "FixVec.h"
#include "SystemVector.h"
#include "CreatorInterface.h"

namespace AMDiS {

  // ============================================================================
  // ===== class Estimator ======================================================
  // ============================================================================

  /**
   * \ingroup Estimator
   * 
   * \brief
   * Estimator for scalar problems.
   */
  class Estimator
  {
  public:
    MEMORY_MANAGED(Estimator);

Thomas Witkowski's avatar
Thomas Witkowski committed
53
    Estimator() {}
54
55
56
57

    /** \brief
     * Constructor.
     */
58
    Estimator(std::string name_, int r);
59
60
61
62

    /** \brief
     * destructor
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
63
    virtual ~Estimator() {}
64
65
66
67

    /** \brief
     * Returns \ref name of the Estimator
     */
68
    inline const std::string& getName() const { 
69
      return name; 
Thomas Witkowski's avatar
Thomas Witkowski committed
70
    }
71
72
73
74
75
76

    /** \brief
     * Performs the estimation and returns the final \ref est_sum
     */
    virtual double estimate(double timestep = 0.0);

77
78
79
    /** \brief
     *
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
80
    virtual void init(double timestep) {}
81

82
83
84
    /** \brief
     *
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
85
    virtual void estimateElement(ElInfo *elInfo) {}
86

87
88
89
    /** \brief
     *
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
90
    virtual void exit(bool output=true) {}
91
92
93
94
95
96

    /** \brief
     * Returns \ref est_sum of the Estimator
     */
    inline double getErrorSum() const { 
      return est_sum; 
Thomas Witkowski's avatar
Thomas Witkowski committed
97
    }
98
99
100
101
102
103

    /** \brief
     * Sets \ref est_sum of the Estimator
     */
    inline void setErrorSum(double sum) { 
      est_sum = sum; 
Thomas Witkowski's avatar
Thomas Witkowski committed
104
    }
105
106
107
108
109
110

    /** \brief
     * Returns \ref est_max of the Estimator
     */
    inline double getErrorMax() const { 
      return est_max; 
Thomas Witkowski's avatar
Thomas Witkowski committed
111
    }
112
113
114
115
116
117

    /** \brief
     * Returns the estimated time error.
     */
    virtual double getTimeEst() const { 
      return est_t_sum; 
Thomas Witkowski's avatar
Thomas Witkowski committed
118
    }
119
120
121
122
123
124

    /** \brief
     * Returns the maximal time estimation.
     */
    virtual double getTimeEstMax() const { 
      return est_t_max; 
Thomas Witkowski's avatar
Thomas Witkowski committed
125
    }
126
127
128
129
130
131

    /** \brief
     * Sets \ref est_max of the Estimator
     */
    inline void setErrorMax(double m) { 
      est_max = m; 
Thomas Witkowski's avatar
Thomas Witkowski committed
132
    }
133
134
135
136
137
138

    /** \brief
     * Returns \ref norm.
     */
    inline Norm getErrorNorm() { 
      return norm; 
Thomas Witkowski's avatar
Thomas Witkowski committed
139
    }
140
141
142
143

    /** \brief
     * Adds one system to the estimator.
     */
144
145
146
147
    virtual void addSystem(DOFMatrix *matrix_,
			   DOFVector<double> *uh_,
			   DOFVector<double> *fh_,
			   DOFVector<double> *uhOld_ = NULL)
148
149
150
151
152
    {
      matrix.push_back(matrix_);
      uh.push_back(uh_);
      fh.push_back(fh_);
      uhOld.push_back(uhOld_);
Thomas Witkowski's avatar
Thomas Witkowski committed
153
    }
154
155
156
157

    /** \brief
     * Adds pointer to old solution to the given system.
     */
158
    virtual void addUhOldToSystem(int system, DOFVector<double> *uhOld_) 
159
160
161
162
163
164
165
166
167
168
169
    {
      TEST_EXIT(static_cast<int>(uhOld.size()) > system)("invalid system\n");
      TEST_EXIT(uhOld[system] == NULL)("there is already an uhOld\n");
      uhOld[system] = uhOld_;
    }

    /** \brief
     * Returns number of systems.
     */
    inline int getNumSystems() { 
      return static_cast<int>(matrix.size()); 
Thomas Witkowski's avatar
Thomas Witkowski committed
170
    }
171

172
173
    inline Flag getTraverseFlag() { 
      return traverseFlag; 
Thomas Witkowski's avatar
Thomas Witkowski committed
174
    }
175

176
177
    inline Mesh* getMesh() { 
      return mesh; 
Thomas Witkowski's avatar
Thomas Witkowski committed
178
    }
179
180
181

    inline int getRow() { 
      return row; 
Thomas Witkowski's avatar
Thomas Witkowski committed
182
    }
183
184
185
186
187

  protected:
    /** \brief
     * Name of the Estimator
     */
188
    std::string name;
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220

    /** \brief
     * Used norm
     */
    Norm norm;
 
    /** \brief
     * Sum of all error estimates
     */
    double est_sum;

    /** \brief
     * Sum of all time error estimates
     */
    double est_t_sum;

    /** \brief
     * Max of all time error estimates
     */
    double est_t_max;

    /** \brief
     * Maximal error estimate
     */
    double est_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.
     */ 
221
    std::vector<DOFMatrix*> matrix;
222
223
224
225

    /** \brief
     * Vector of solution vectors for the different systems.
     */
226
    std::vector<DOFVector<double>*> uh;
227
228
229
230
231

    /** \brief
     * Vector of old solutions vectors for the different systems. 
     * Used for instationary problems.
     */
232
    std::vector<DOFVector<double>*> uhOld;
233
234
235
236

    /** \brief
     * Vector of RHS vectors for the different systems.
     */
237
    std::vector<DOFVector<double>*> fh;
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

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

    Mesh *mesh;

    double timestep;
  };

253

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
  // ============================================================================
  // ===== class EstimatorCreator ===============================================
  // ============================================================================

  /** 
   * \ingroup Estimator
   *
   * \brief
   * Interface for creators of concrete estimators. 
   */
  class EstimatorCreator : public CreatorInterface<Estimator>
  { 
  public:
    /** \brief
     * constructor
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
270
    EstimatorCreator() : row(-1) {}
271
272
273
274

    /** \brief
     * destructor
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
275
    virtual ~EstimatorCreator() {}
276
277
278
279

    /** \brief
     * Sets \ref name
     */
280
    void setName(std::string name_) { 
281
      name = name_; 
Thomas Witkowski's avatar
Thomas Witkowski committed
282
    }
283
284
285
286

    /** \brief
     * Sets \ref row
     */
287
288
    void setRow(int r) { 
      row = r; 
Thomas Witkowski's avatar
Thomas Witkowski committed
289
    }
290
291
292
293
294

  protected:
    /** \brief
     * Name of the estimator to be created.
     */
295
    std::string name;
296
297
298
299
300
301
302
303
304
305

    /** \brief
     * Row of the estimator.
     */
    int row;
  };

}

#endif // AMDIS_ESTIMATOR_H