Estimator.h 6.12 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
    {
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
135
136
137
138
139
      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");

140
141
142
      uhOld[system] = uhOld_;
    }

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

Thomas Witkowski's avatar
Thomas Witkowski committed
149
150
    inline Flag getTraverseFlag() 
    { 
151
      return traverseFlag; 
Thomas Witkowski's avatar
Thomas Witkowski committed
152
    }
153

Thomas Witkowski's avatar
Thomas Witkowski committed
154
155
    inline Mesh* getMesh() 
    { 
156
      return mesh; 
Thomas Witkowski's avatar
Thomas Witkowski committed
157
    }
158

Thomas Witkowski's avatar
Thomas Witkowski committed
159
160
    inline int getRow() 
    { 
161
      return row; 
Thomas Witkowski's avatar
Thomas Witkowski committed
162
    }
163
164

  protected:
165
    /// Name of the Estimator
166
    std::string name;
167

168
    /// Used norm
169
170
    Norm norm;
 
171
    /// Sum of all error estimates
172
173
    double est_sum;

174
    /// Sum of all time error estimates
175
176
    double est_t_sum;

177
    /// Max of all time error estimates
178
179
    double est_t_max;

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

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

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

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

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

217

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

230
    /// destructor
Thomas Witkowski's avatar
Thomas Witkowski committed
231
    virtual ~EstimatorCreator() {}
232

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

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

  protected:
246
    /// Name of the estimator to be created.
247
    std::string name;
248

249
    /// Row of the estimator.
250
251
252
253
254
255
    int row;
  };

}

#endif // AMDIS_ESTIMATOR_H