Estimator.h 5.92 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
56
    inline const std::string& getName() const { 
57
      return name; 
Thomas Witkowski's avatar
Thomas Witkowski committed
58
    }
59

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

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

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

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

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

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

82
    /// Returns \ref est_max of the Estimator
83
84
    inline double getErrorMax() const { 
      return est_max; 
Thomas Witkowski's avatar
Thomas Witkowski committed
85
    }
86

87
    /// Returns the estimated time error.
88
89
    virtual double getTimeEst() const { 
      return est_t_sum; 
Thomas Witkowski's avatar
Thomas Witkowski committed
90
    }
91

92
    /// Returns the maximal time estimation.
93
94
    virtual double getTimeEstMax() const { 
      return est_t_max; 
Thomas Witkowski's avatar
Thomas Witkowski committed
95
    }
96

97
    /// Sets \ref est_max of the Estimator
98
99
    inline void setErrorMax(double m) { 
      est_max = m; 
Thomas Witkowski's avatar
Thomas Witkowski committed
100
    }
101

102
    /// Returns \ref norm.
103
104
    inline Norm getErrorNorm() { 
      return norm; 
Thomas Witkowski's avatar
Thomas Witkowski committed
105
    }
106

107
    /// Adds one system to the estimator.
108
109
110
111
    virtual void addSystem(DOFMatrix *matrix_,
			   DOFVector<double> *uh_,
			   DOFVector<double> *fh_,
			   DOFVector<double> *uhOld_ = NULL)
112
113
114
115
116
    {
      matrix.push_back(matrix_);
      uh.push_back(uh_);
      fh.push_back(fh_);
      uhOld.push_back(uhOld_);
Thomas Witkowski's avatar
Thomas Witkowski committed
117
    }
118

119
    /// Adds pointer to old solution to the given system.
120
    virtual void addUhOldToSystem(int system, DOFVector<double> *uhOld_) 
121
122
123
124
125
126
    {
      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_;
    }

127
    /// Returns number of systems.
128
129
    inline int getNumSystems() { 
      return static_cast<int>(matrix.size()); 
Thomas Witkowski's avatar
Thomas Witkowski committed
130
    }
131

132
133
    inline Flag getTraverseFlag() { 
      return traverseFlag; 
Thomas Witkowski's avatar
Thomas Witkowski committed
134
    }
135

136
137
    inline Mesh* getMesh() { 
      return mesh; 
Thomas Witkowski's avatar
Thomas Witkowski committed
138
    }
139
140
141

    inline int getRow() { 
      return row; 
Thomas Witkowski's avatar
Thomas Witkowski committed
142
    }
143
144

  protected:
145
    /// Name of the Estimator
146
    std::string name;
147

148
    /// Used norm
149
150
    Norm norm;
 
151
    /// Sum of all error estimates
152
153
    double est_sum;

154
    /// Sum of all time error estimates
155
156
    double est_t_sum;

157
    /// Max of all time error estimates
158
159
    double est_t_max;

160
    /// Maximal error estimate
161
162
163
164
165
166
167
168
    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.
     */ 
169
    std::vector<DOFMatrix*> matrix;
170

171
    /// Vector of solution vectors for the different systems.
172
    std::vector<DOFVector<double>*> uh;
173
174
175
176
177

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

180
    /// Vector of RHS vectors for the different systems.
181
    std::vector<DOFVector<double>*> fh;
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

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

197

198
199
200
201
202
203
204
205
206
  /** 
   * \ingroup Estimator
   *
   * \brief
   * Interface for creators of concrete estimators. 
   */
  class EstimatorCreator : public CreatorInterface<Estimator>
  { 
  public:
207
    /// constructor
Thomas Witkowski's avatar
Thomas Witkowski committed
208
    EstimatorCreator() : row(-1) {}
209

210
    /// destructor
Thomas Witkowski's avatar
Thomas Witkowski committed
211
    virtual ~EstimatorCreator() {}
212

213
    /// Sets \ref name
214
    void setName(std::string name_) { 
215
      name = name_; 
Thomas Witkowski's avatar
Thomas Witkowski committed
216
    }
217

218
    /// Sets \ref row
219
220
    void setRow(int r) { 
      row = r; 
Thomas Witkowski's avatar
Thomas Witkowski committed
221
    }
222
223

  protected:
224
    /// Name of the estimator to be created.
225
    std::string name;
226

227
    /// Row of the estimator.
228
229
230
231
232
233
    int row;
  };

}

#endif // AMDIS_ESTIMATOR_H