Estimator.h 6.07 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
#include "Flag.h"
#include "Global.h"
#include "FixVec.h"
#include "SystemVector.h"
#include "CreatorInterface.h"

namespace AMDiS {

  /**
   * \ingroup Estimator
   * 
   * \brief
   * Estimator for scalar problems.
   */
  class Estimator
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
47
    Estimator() {}
48

49
    /// Constructor.
50
    Estimator(std::string name_, int r);
51

52
    /// destructor
Thomas Witkowski's avatar
Thomas Witkowski committed
53
    virtual ~Estimator() {}
54

55
    /// Returns \ref name of the Estimator
Thomas Witkowski's avatar
Thomas Witkowski committed
56
57
    inline const std::string& getName() const 
    { 
58
      return name; 
Thomas Witkowski's avatar
Thomas Witkowski committed
59
    }
60

61
    /// Performs the estimation and returns the final \ref est_sum
62
63
    virtual double estimate(double timestep = 0.0);

64
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
65
    virtual void init(double timestep) {}
66

67
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
68
    virtual void estimateElement(ElInfo *elInfo) {}
69

70
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
71
    virtual void exit(bool output=true) {}
72

73
    /// Returns \ref est_sum of the Estimator
Thomas Witkowski's avatar
Thomas Witkowski committed
74
75
    inline double getErrorSum() const 
    { 
76
      return est_sum; 
Thomas Witkowski's avatar
Thomas Witkowski committed
77
    }
78

79
    /// Sets \ref est_sum of the Estimator
Thomas Witkowski's avatar
Thomas Witkowski committed
80
81
    inline void setErrorSum(double sum) 
    { 
82
      est_sum = sum; 
Thomas Witkowski's avatar
Thomas Witkowski committed
83
    }
84

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

91
    /// Returns the estimated time error.
Thomas Witkowski's avatar
Thomas Witkowski committed
92
93
    virtual double getTimeEst() const 
    { 
94
      return est_t_sum; 
Thomas Witkowski's avatar
Thomas Witkowski committed
95
    }
96

97
    /// Returns the maximal time estimation.
Thomas Witkowski's avatar
Thomas Witkowski committed
98
99
    virtual double getTimeEstMax() const 
    { 
100
      return est_t_max; 
Thomas Witkowski's avatar
Thomas Witkowski committed
101
    }
102

103
    /// Sets \ref est_max of the Estimator
Thomas Witkowski's avatar
Thomas Witkowski committed
104
105
    inline void setErrorMax(double m) 
    { 
106
      est_max = m; 
Thomas Witkowski's avatar
Thomas Witkowski committed
107
    }
108

109
    /// Returns \ref norm.
Thomas Witkowski's avatar
Thomas Witkowski committed
110
111
    inline Norm getErrorNorm() 
    { 
112
      return norm; 
Thomas Witkowski's avatar
Thomas Witkowski committed
113
    }
114

115
    /// Adds one system to the estimator.
116
117
118
119
    virtual void addSystem(DOFMatrix *matrix_,
			   DOFVector<double> *uh_,
			   DOFVector<double> *fh_,
			   DOFVector<double> *uhOld_ = NULL)
120
121
122
123
124
    {
      matrix.push_back(matrix_);
      uh.push_back(uh_);
      fh.push_back(fh_);
      uhOld.push_back(uhOld_);
Thomas Witkowski's avatar
Thomas Witkowski committed
125
    }
126

Thomas Witkowski's avatar
Thomas Witkowski committed
127
128
129
130
131
    void setNewMatrix(int i, DOFMatrix *m) 
    {
      matrix[i] = m;
    }

132
    /// Adds pointer to old solution to the given system.
133
    virtual void addUhOldToSystem(int system, DOFVector<double> *uhOld_) 
134
135
136
137
138
139
    {
      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_;
    }

140
    /// Returns number of systems.
Thomas Witkowski's avatar
Thomas Witkowski committed
141
142
    inline int getNumSystems() 
    { 
143
      return static_cast<int>(matrix.size()); 
Thomas Witkowski's avatar
Thomas Witkowski committed
144
    }
145

Thomas Witkowski's avatar
Thomas Witkowski committed
146
147
    inline Flag getTraverseFlag() 
    { 
148
      return traverseFlag; 
Thomas Witkowski's avatar
Thomas Witkowski committed
149
    }
150

Thomas Witkowski's avatar
Thomas Witkowski committed
151
152
    inline Mesh* getMesh() 
    { 
153
      return mesh; 
Thomas Witkowski's avatar
Thomas Witkowski committed
154
    }
155

Thomas Witkowski's avatar
Thomas Witkowski committed
156
157
    inline int getRow() 
    { 
158
      return row; 
Thomas Witkowski's avatar
Thomas Witkowski committed
159
    }
160
161

  protected:
162
    /// Name of the Estimator
163
    std::string name;
164

165
    /// Used norm
166
167
    Norm norm;
 
168
    /// Sum of all error estimates
169
170
    double est_sum;

171
    /// Sum of all time error estimates
172
173
    double est_t_sum;

174
    /// Max of all time error estimates
175
176
    double est_t_max;

177
    /// Maximal error estimate
178
179
180
181
182
183
184
185
    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.
     */ 
186
    std::vector<DOFMatrix*> matrix;
187

188
    /// Vector of solution vectors for the different systems.
189
    std::vector<DOFVector<double>*> uh;
190
191
192
193
194

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

197
    /// Vector of RHS vectors for the different systems.
198
    std::vector<DOFVector<double>*> fh;
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

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

214

215
216
217
218
219
220
221
222
223
  /** 
   * \ingroup Estimator
   *
   * \brief
   * Interface for creators of concrete estimators. 
   */
  class EstimatorCreator : public CreatorInterface<Estimator>
  { 
  public:
224
    /// constructor
Thomas Witkowski's avatar
Thomas Witkowski committed
225
    EstimatorCreator() : row(-1) {}
226

227
    /// destructor
Thomas Witkowski's avatar
Thomas Witkowski committed
228
    virtual ~EstimatorCreator() {}
229

230
    /// Sets \ref name
Thomas Witkowski's avatar
Thomas Witkowski committed
231
232
    void setName(std::string name_) 
    { 
233
      name = name_; 
Thomas Witkowski's avatar
Thomas Witkowski committed
234
    }
235

236
    /// Sets \ref row
Thomas Witkowski's avatar
Thomas Witkowski committed
237
238
    void setRow(int r) 
    { 
239
      row = r; 
Thomas Witkowski's avatar
Thomas Witkowski committed
240
    }
241
242

  protected:
243
    /// Name of the estimator to be created.
244
    std::string name;
245

246
    /// Row of the estimator.
247
248
249
250
251
252
    int row;
  };

}

#endif // AMDIS_ESTIMATOR_H