Marker.hpp 7.98 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#pragma once
// TODO: Cleanup of copied comments
#include <string>

#include <dune/grid/common/grid.hh>

#include <amdis/AdaptInfo.hpp>
#include <amdis/Flag.hpp>
#include <amdis/Initfile.hpp>

namespace AMDiS {

  
  /**
   * \ingroup Adaption
   *
   * \brief
   * Base class for all scalar markers.
   */
  template <class Grid>
  class Marker
  {
    
    using GridView = typename Grid::LeafGridView;
    using IndexSet = typename GridView::IndexSet;
    using Element  = typename GridView::template Codim<0>::Entity;
    using EstType = std::vector<std::vector<double> >;

  public:
    /// Constructor.
    Marker() {}

    /// Constructor.
    Marker(std::string name_, int row_, const EstType& est_, Grid* grid_)
      : name(name_),
        row(row_),
        grid(grid_),
        est(est_),
        maximumMarking(false),
        p(2),
        info(10),
        maxRefineLevel(-1),
        minRefineLevel(-1)
    {
      Parameters::get(name + "->p", p);
      Parameters::get(name + "->info", info);
      Parameters::get(name + "->max refinement level", maxRefineLevel);
      Parameters::get(name + "->min refinement level", minRefineLevel);
    }

    /// destructor
    virtual ~Marker() {}

    /// Marks element with newMark. If \ref maximumMarking is set, the element
    /// is marked only if the new mark is bigger than the old one. The return
    /// value specifies whether the element has been marked, or not.
    inline void mark(const Element& elem, int newMark)
    {
      int oldMark = grid->getMark(elem);

      if (!maximumMarking || (newMark > oldMark)) {
        bool (marked) = grid->mark(newMark, elem);
        if (marked) {
          if (oldMark > 0) {
            elMarkRefine--;
          } else if (oldMark < 0) {
            elMarkCoarsen--;
          }

          if (newMark > 0) {
            elMarkRefine++;
          } else if (newMark < 0) {
              elMarkCoarsen++;
          }
        } else {
          msg("Marking failed");
        }
      }
    }

    /// Can be used by sub classes. Called before traversal.
    virtual void initMarking(AdaptInfo& adaptInfo);

    /// Can be used by sub classes. Called after traversal.
    virtual void finishMarking(AdaptInfo& adaptInfo);

    /// Marks one element.
    virtual void markElement(AdaptInfo& adaptInfo, const Element& elem);

    /// Marking of the mesh.
    virtual Flag markGrid(AdaptInfo& adaptInfo);

    /// Sets \ref maximumMarking.
    inline void setMaximumMarking(bool maxMark)
    {
      maximumMarking = maxMark;
    }

    inline int getElMarkRefine()
    {
      return elMarkRefine;
    }

    inline int getElMarkCoarsen()
    {
      return elMarkCoarsen;
    }

    /// Returns \ref name of the Marker
    inline std::string getName() const
    {
      return name;
    }

    /// Creates a scalar marker depending on the strategy set in parameters.
    static Marker<Grid>* createMarker(std::string name, int row_, const EstType& est_, Grid* grid_);

  protected:
    /// Name of the scalar marker.
    std::string name;

    /// Equal to -1 for scalar problems. Component number if marker is
    /// part of a vector valued marker.
    int row;

    /// Pointer to the grid
    Grid* grid;

    /// Pointer to the local error estimates
    EstType est;

    /// estimation sum
    double estSum;

    /// estmation maximum
    double estMax;

    /// If true, elements are marked only if the new value is bigger than
    /// the current marking.
    bool maximumMarking;

    /// Lower limit for error estimation, from which an element is marked for
    /// refinement
    double markRLimit;

    /// Upper limit for error estimation, from which an element is marked for
    /// coarsening
    double markCLimit;

    /// power in estimator norm
    double p;

    /// Info level.
    int info;

    /// Counter for elements marked for refinement
    int elMarkRefine;

    /// Counter for elements marked for coarsening
    int elMarkCoarsen;

    /// Maximal level of all elements.
    int maxRefineLevel;

    /// Minimal level of all elements.
    int minRefineLevel;
  };


  /**
   * \ingroup Adaption
   *
   * \brief
   * Global refinement.
   */
  template <class Grid>
  class GRMarker : public Marker<Grid>
  {
    using GridView = typename Grid::LeafGridView;
    using IndexSet = typename GridView::IndexSet;
    using Element  = typename GridView::template Codim<0>::Entity;
    using EstType = std::vector<std::vector<double> >;

  public:
    /// Constructor.
    GRMarker(std::string name_, int row_, const EstType& est_, Grid* grid_)
      : Marker<Grid>(name_, row_, est_, grid_)
    {}

    /// Implementation of Marker::markElement().
    virtual void markElement(AdaptInfo& adaptInfo, const Element& elem)
    {
      if (adaptInfo.isRefinementAllowed(this->row == -1 ? 0 : this->row))
        this->mark(elem, 1);
    }
  };


  /**
   * \ingroup Adaption
   *
   * \brief
   * Maximum strategy.
   */
  
  template <class Grid>
  class MSMarker : public Marker<Grid>
  {
    using GridView = typename Grid::LeafGridView;
    using IndexSet = typename GridView::IndexSet;
    using Element  = typename GridView::template Codim<0>::Entity;
    using EstType = std::vector<std::vector<double> >;

  public:
    /// Constructor.
    MSMarker(std::string name_, int row_, const EstType& est_, Grid* grid_)
      : Marker<Grid>(name_, row_, est_, grid_),
        MSGamma(0.5),
        MSGammaC(0.1)
    {
      Parameters::get(this->name + "->MSGamma", MSGamma);
      Parameters::get(this->name + "->MSGammaC", MSGammaC);
    }

    /// Implementation of Marker::initMarking().
    void initMarking(AdaptInfo& adaptInfo);

  protected:
    /// Marking parameter.
    double MSGamma;

    /// Marking parameter.
    double MSGammaC;
  };


  /**
   * \ingroup Adaption
   *
   * \brief
   * Equidistribution strategy
   */
  
  template <class Grid>
  class ESMarker : public Marker<Grid>
  {
    using GridView = typename Grid::LeafGridView;
    using IndexSet = typename GridView::IndexSet;
    using Element  = typename GridView::template Codim<0>::Entity;
    using EstType = std::vector<std::vector<double> >;

  public:
    /// Constructor.
    ESMarker(std::string name_, int row_, const EstType& est_, Grid* grid_)
      : Marker<Grid>(name_, row_, est_, grid_),
        ESTheta(0.9),
        ESThetaC(0.2)
    {
      Parameters::get(this->name + "->ESTheta", ESTheta);
      Parameters::get(this->name + "->ESThetaC", ESThetaC);
    }

    /// Implementation of Marker::initMarking().
    virtual void initMarking(AdaptInfo& adaptInfo);

  protected:
    /// Marking parameter.
    double ESTheta;

    /// Marking parameter.
    double ESThetaC;
  };


  /**
   * \ingroup Adaption
   *
   * \brief
   * Guaranteed error reduction strategy
   */
  
  template <class Grid>
  class GERSMarker : public Marker<Grid>
  {
    using GridView = typename Grid::LeafGridView;
    using IndexSet = typename GridView::IndexSet;
    using Element  = typename GridView::template Codim<0>::Entity;
    using EstType = std::vector<std::vector<double> >;

  public:
    /// Constructor.
    GERSMarker(std::string name_, int row_, const EstType& est_, Grid* grid_)
      : Marker<Grid>(name_, row_, est_, grid_),
        oldErrSum(0.0),
        GERSThetaStar(0.6),
        GERSNu(0.1),
        GERSThetaC(0.1)
    {
      Parameters::get(this->name + "->GERSThetaStar", GERSThetaStar);
      Parameters::get(this->name + "->GERSNu", GERSNu);
      Parameters::get(this->name + "->GERSThetaC", GERSThetaC);
    }

    /// Implementation of Marker::markGrid().
    virtual Flag markGrid(AdaptInfo& adaptInfo);

  protected:
    /// Refinement marking function.
    void markElementForRefinement(AdaptInfo& adaptInfo, const Element& elem);

    /// Coarsening marking function.
    void markElementForCoarsening(AdaptInfo& adaptInfo, const Element& elem);

  protected:
    /// Marking parameter.
    double GERSSum;

    /// Marking parameter.
    double oldErrSum;

    /// Marking parameter.
    double GERSThetaStar;

    /// Marking parameter.
    double GERSNu;

    /// Marking parameter.
    double GERSThetaC;
  };

}