Marker.h 6.95 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
    /// Implementation of MarkScal::initMarking().
220
    void initMarking(AdaptInfo *adaptInfo, Mesh *mesh);
221 222
  
  protected:
223
    /// Marking parameter.
224 225
    double MSGamma;

226
    /// Marking parameter.
227 228 229 230 231 232 233 234 235 236 237 238 239
    double MSGammaC;
  };


  /**
   * \ingroup Adaption
   * 
   * \brief
   * Equidistribution strategy
   */
  class ESMarker : public Marker
  {
  public:
240
    /// Constructor.
241
    ESMarker(std::string name_, int row_) 
242 243 244 245
      : Marker(name_, row_),
	ESTheta(0.9),
	ESThetaC(0.2)
    {
246 247
      Parameters::get(name + "->ESTheta", ESTheta);
      Parameters::get(name + "->ESThetaC", ESThetaC);
Thomas Witkowski's avatar
Thomas Witkowski committed
248
    }
249

250
    /// Implementation of MarkScal::initMarking().
251
    virtual void initMarking(AdaptInfo *adaptInfo, Mesh *mesh);
252 253
  
  protected:
254
    /// Marking parameter.
255 256
    double ESTheta;

257
    /// Marking parameter.
258 259 260 261 262 263 264 265 266 267 268 269 270
    double ESThetaC;
  };


  /**
   * \ingroup Adaption
   * 
   * \brief
   * Guaranteed error reduction strategy 
   */
  class GERSMarker : public Marker
  {
  public:
271
    /// Constructor.
272
    GERSMarker(std::string name_, int row_) 
273 274 275 276 277 278
      : Marker(name_, row_),
	oldErrSum(0.0),
	GERSThetaStar(0.6),
	GERSNu(0.1),
	GERSThetaC(0.1)
    {
279 280 281
      Parameters::get(name + "->GERSThetaStar", GERSThetaStar);
      Parameters::get(name + "->GERSNu", GERSNu);
      Parameters::get(name + "->GERSThetaC", GERSThetaC);
Thomas Witkowski's avatar
Thomas Witkowski committed
282
    }
283

284
    /// Implementation of Marker::markMesh().
285
    virtual Flag markMesh(AdaptInfo *adaptInfo, Mesh *mesh);
286 287

  protected:
288
    /// Refinement marking function.
289
    void markElementForRefinement(AdaptInfo *adaptInfo, ElInfo *elInfo);
290

291
    /// Coarsening marking function.
292
    void markElementForCoarsening(AdaptInfo *adaptInfo, ElInfo *elInfo);
293 294

  protected:
295
    /// Marking parameter.
296 297
    double GERSSum;

298
    /// Marking parameter.
299 300
    double oldErrSum;

301
    /// Marking parameter.
302 303
    double GERSThetaStar;

304
    /// Marking parameter.
305 306
    double GERSNu;

307
    /// Marking parameter.
308 309 310 311 312 313
    double GERSThetaC;
  };

}

#endif