Marker.h 7.25 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


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

/** \file Marker.h */

#ifndef AMDIS_MARKER_H
#define AMDIS_MARKER_H

#include "Element.h"
#include "ElInfo.h"
#include "Flag.h"
#include "Mesh.h"
#include "AdaptInfo.h"
#include "Traverse.h"
#include "MatrixVector.h"

namespace AMDiS {

  /**
   * \ingroup Adaption
   * 
   * \brief
   * Base class for all scalar markers.
   */
  class Marker
  {
  public:
45
    /// Constructor.
Thomas Witkowski's avatar
Thomas Witkowski committed
46
    Marker() {}
47

48
    /// Constructor.
49
    Marker(std::string name_, int row_)
50
51
52
53
      : name(name_), 
	row(row_),
	maximumMarking(false),
	p(2),
54
	info(10),
55
56
	maxRefineLevel(-1),
	minRefineLevel(-1)
57
    {
58
59
60
61
      Parameters::get(name + "->p", p);
      Parameters::get(name + "->info", info);
      Parameters::get(name + "->max refinement level", maxRefineLevel);
      Parameters::get(name + "->min refinement level", minRefineLevel);
Thomas Witkowski's avatar
Thomas Witkowski committed
62
    }
63

64
    /// destructor
Thomas Witkowski's avatar
Thomas Witkowski committed
65
    virtual ~Marker() {}
66

Thomas Witkowski's avatar
Thomas Witkowski committed
67
68
69
    /// 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.
70
71
    inline void setMark(Element *el, char newMark) 
    {
72
73
74
75
      char oldMark = el->getMark();

      if (!maximumMarking || (newMark > oldMark)) {
	el->setMark(newMark);
76
77
78
79
80
81
82
83
84
85
86
87
88
89

	if (oldMark > 0) {
	  elMarkRefine--; 
	} else {
	  if (oldMark < 0) 
	    elMarkCoarsen--;
	}

	if (newMark > 0) {
	  elMarkRefine++; 
	} else { 
	  if (newMark < 0) 
	    elMarkCoarsen++;
	}
90
      }
Thomas Witkowski's avatar
Thomas Witkowski committed
91
    }
92

93
    /// Can be used by sub classes. Called before traversal.
94
    virtual void initMarking(AdaptInfo *adaptInfo, Mesh *mesh);
95

96
    /// Can be used by sub classes. Called after traversal.
97
    virtual void finishMarking(AdaptInfo *adaptInfo);
98

99
    /// Marks one element.
100
    virtual void markElement(AdaptInfo *adaptInfo, ElInfo *elInfo);
101
  
102
    /// Marking of the mesh.
103
    virtual Flag markMesh(AdaptInfo *adaptInfo, Mesh *mesh);
104

105
106
107
    /// Sets \ref maximumMarking.
    inline void setMaximumMarking(bool maxMark) 
    {
108
      maximumMarking = maxMark;
Thomas Witkowski's avatar
Thomas Witkowski committed
109
    }
110

111
112
    inline int getElMarkRefine() 
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
113
114
      return elMarkRefine; 
    }
115

116
117
    inline int getElMarkCoarsen() 
    { 
118
      return elMarkCoarsen; 
Thomas Witkowski's avatar
Thomas Witkowski committed
119
    }
120

Thomas Witkowski's avatar
Thomas Witkowski committed
121
    /// Returns \ref name of the Marker
122
123
124
125
126
    inline std::string getName() const 
    { 
      return name; 
    }

127
    /// Creates a scalr marker depending on the strategy set in parameters.
128
    static Marker *createMarker(std::string name, int row_);
129
130

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

Thomas Witkowski's avatar
Thomas Witkowski committed
134
135
    /// Equal to -1 for scalar problems. Component number if marker is
    /// part of a vector valued marker.
136
137
    int row;

138
    /// estimation sum
139
140
    double estSum;

141
    /// estmation maximum
142
143
    double estMax;

Thomas Witkowski's avatar
Thomas Witkowski committed
144
145
    /// If true, elements are marked only if the new value is bigger than
    /// the current marking.
146
147
    bool maximumMarking;

Thomas Witkowski's avatar
Thomas Witkowski committed
148
149
    /// Lower limit for error estimation, from which an element is marked for
    /// refinement
150
151
    double markRLimit;

Thomas Witkowski's avatar
Thomas Witkowski committed
152
153
    /// Upper limit for error estimation, from which an element is marked for 
    /// coarsening
154
155
    double markCLimit;

156
    /// power in estimator norm
157
158
    double p;

159
    /// Info level.
160
161
    int info;

162
    /// Counter for elements marked for refinement
163
164
    int elMarkRefine;

165
    /// Counter for elements marked for coarsening
166
167
    int elMarkCoarsen;

168
    /// Maximal level of all elements.
169
    int maxRefineLevel;
170
171
172

    /// Minimal level of all elements.
    int minRefineLevel;
173
174
175
176
177
178
179
180
181
182
183
184
  };


  /**
   * \ingroup Adaption
   * 
   * \brief
   * Global refinement.
   */
  class GRMarker : public Marker
  {
  public:
185
    /// Constructor.
186
    GRMarker(std::string name_, int row_) 
187
      : Marker(name_, row_) 
Thomas Witkowski's avatar
Thomas Witkowski committed
188
    {}
189

190
191
192
    /// Implementation of Marker::markElement().
    virtual void markElement(AdaptInfo *adaptInfo, ElInfo *elInfo) 
    {
193
      Element *el = elInfo->getElement();
194
      if (adaptInfo->isRefinementAllowed(row == -1 ? 0 : row))
195
	setMark(el, adaptInfo->getRefineBisections(row == -1 ? 0 : row));
Thomas Witkowski's avatar
Thomas Witkowski committed
196
    }
197
198
199
200
201
202
203
204
205
206
207
208
  };


  /**
   * \ingroup Adaption
   * 
   * \brief
   * Maximum strategy.
   */
  class MSMarker : public Marker
  {
  public:
209
    /// Constructor.
210
    MSMarker(std::string name_, int row_) 
211
212
213
214
      : Marker(name_, row_),
	MSGamma(0.5),
	MSGammaC(0.1)
    {
215
216
      Parameters::get(name + "->MSGamma", MSGamma);
      Parameters::get(name + "->MSGammaC", MSGammaC);
Thomas Witkowski's avatar
Thomas Witkowski committed
217
    }
218

219
220
221
    /// Implementation of MarkScal::initMarking().
    virtual void initMarking(AdaptInfo *adaptInfo, Mesh *mesh) 
    {
222
223
224
225
226
227
228
      Marker::initMarking(adaptInfo, mesh);
    
      double MSGammaP = pow(MSGamma, p);
      double MSGammaCP = pow(MSGammaC, p);

      markRLimit = MSGammaP * adaptInfo->getEstMax(row == -1 ? 0 : row);
      markCLimit = MSGammaCP * adaptInfo->getEstMax(row == -1 ? 0 : row);
Thomas Witkowski's avatar
Thomas Witkowski committed
229
    }
230
231
  
  protected:
232
    /// Marking parameter.
233
234
    double MSGamma;

235
    /// Marking parameter.
236
237
238
239
240
241
242
243
244
245
246
247
248
    double MSGammaC;
  };


  /**
   * \ingroup Adaption
   * 
   * \brief
   * Equidistribution strategy
   */
  class ESMarker : public Marker
  {
  public:
249
    /// Constructor.
250
    ESMarker(std::string name_, int row_) 
251
252
253
254
      : Marker(name_, row_),
	ESTheta(0.9),
	ESThetaC(0.2)
    {
255
256
      Parameters::get(name + "->ESTheta", ESTheta);
      Parameters::get(name + "->ESThetaC", ESThetaC);
Thomas Witkowski's avatar
Thomas Witkowski committed
257
    }
258

259
    /// Implementation of MarkScal::initMarking().
260
    virtual void initMarking(AdaptInfo *adaptInfo, Mesh *mesh);
261
262
  
  protected:
263
    /// Marking parameter.
264
265
    double ESTheta;

266
    /// Marking parameter.
267
268
269
270
271
272
273
274
275
276
277
278
279
    double ESThetaC;
  };


  /**
   * \ingroup Adaption
   * 
   * \brief
   * Guaranteed error reduction strategy 
   */
  class GERSMarker : public Marker
  {
  public:
280
    /// Constructor.
281
    GERSMarker(std::string name_, int row_) 
282
283
284
285
286
287
      : Marker(name_, row_),
	oldErrSum(0.0),
	GERSThetaStar(0.6),
	GERSNu(0.1),
	GERSThetaC(0.1)
    {
288
289
290
      Parameters::get(name + "->GERSThetaStar", GERSThetaStar);
      Parameters::get(name + "->GERSNu", GERSNu);
      Parameters::get(name + "->GERSThetaC", GERSThetaC);
Thomas Witkowski's avatar
Thomas Witkowski committed
291
    }
292

293
    /// Implementation of Marker::markMesh().
294
    virtual Flag markMesh(AdaptInfo *adaptInfo, Mesh *mesh);
295
296

  protected:
297
    /// Refinement marking function.
298
    void markElementForRefinement(AdaptInfo *adaptInfo, ElInfo *elInfo);
299

300
    /// Coarsening marking function.
301
    void markElementForCoarsening(AdaptInfo *adaptInfo, ElInfo *elInfo);
302
303

  protected:
304
    /// Marking parameter.
305
306
    double GERSSum;

307
    /// Marking parameter.
308
309
    double oldErrSum;

310
    /// Marking parameter.
311
312
    double GERSThetaStar;

313
    /// Marking parameter.
314
315
    double GERSNu;

316
    /// Marking parameter.
317
318
319
320
321
322
    double GERSThetaC;
  };

}

#endif