LevelSetAdaptMesh.h 5.09 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
#ifndef AMDIS_LEVELSETADAPTMESH_H
#define AMDIS_LEVELSETADAPTMESH_H

#include "AdaptInfo.h"
#include "ElInfo.h"
#include "Global.h"
#include "Mesh.h"
#include "ProblemStatBase.h"

#include "ElementLevelSet.h"

using namespace AMDiS;

class LevelSetAdaptMesh 
{
 public:
  /**
   * Constructor.
   */
  LevelSetAdaptMesh(ProblemStatBase *prob_,
		    Mesh *mesh_,
		    ElementLevelSet *elLS_,
		    double sizeInterf_,
		    double sizeNegLs_,
		    double sizePosLs_,
		    bool onlyInterfRef_ = false,
		    bool bandAtInterf_ = false,
		    double bandSize_ = -1.0)
    : prob(prob_),
    mesh(mesh_),
    elLS(elLS_),
    sizeInterf(sizeInterf_),
    sizeNegLs(sizeNegLs_),
    sizePosLs(sizePosLs_),
    onlyInterfRef(onlyInterfRef_),
    bandAtInterf(bandAtInterf_),
    bandSize(bandSize_),
    dim(mesh->getDim())
  {};

  /**
   * Calculates sizes sizeInterf, sizeNegLs, sizePosLs and bandSize 
   * from number of refinements additional to initial global refinements
   * read from init file.
   */
  static void getElementSizesFromInit(const std::string probName,
				      double &sizeInterf_,
				      double &sizeNegLs_,
				      double &sizePosLs_,
				      double &bandSize_);

  /**
   * Sets sizeInterf, sizeNegLs, sizePosLs and bandSize.
   */
  void setElementSizes(double &sizeInterf_,
		       double &sizeNegLs_,
		       double &sizePosLs_,
		       double bandSize_ = -1.0)
  {
    FUNCNAME("LevelSetAdaptMesh::setElementSizes()");

    sizeInterf = sizeInterf_;
    sizeNegLs = sizeNegLs_;
    sizePosLs = sizePosLs_;
    bandSize = bandSize_;

    TEST_EXIT(bandSize > 0 || bandAtInterf == false)
      ("illegal band size!\n");
  };

  /**
   * Sets bandSize.
   */
  void setBandSize(double &bandSize_)
  {
    FUNCNAME("LevelSetAdaptMesh::setBandSize()");

    TEST_EXIT(bandSize_ > 0)("illegal bandSize !\n");

    bandAtInterf = true;
    bandSize = bandSize_;
  };

  /**
   * Adapts mesh to the appropriate element sizes. 
   */
  void adaptMesh(AdaptInfo *adaptInfo);

  /**
   * Get sizeInterf.
   */
  inline double getSizeInterf() {
    return sizeInterf;
  };

 protected:
  /**
   * Element mark function in case no band around the interface is used.
   */
  void markElement_noBand(ElInfo *elInfo);

  /**
   * Element mark function in case a band around the interface is used.
   */
  void markElement_Band(ElInfo *elInfo);

  /**
   * Checks whether element size elSize corresponds to the prescribed size
   * sizeWanted and sets a mark for refinement/coarsening if needed.
   */
  void markElement(ElInfo *elInfo, double elSize, double sizeWanted);

  /**
   * Determines the position of element with respect to the band around
   * the zero level set.
   */
  int calculateElementStatusBand(ElInfo *elInfo);

 protected:
  /**
   * Problem for mesh adaption which gives refinement and coarsening manager.
   */
  ProblemStatBase *prob;

  /**
   * Mesh to be adapted.
   */
  Mesh *mesh;

  /**
   * Holds the level set function and functionalities on intersection point
   * calculation.
   */
  ElementLevelSet *elLS;

  /**
   * Mesh element size after mesh adaption.
   *    sizeInterf - elements cut by zero level set and - if bandAtInterf 
   *                 is true - elements with at most distance bandSize to
   *                 the zero level set
   *    sizeNegLs  - elements in domain with negative level set function
   *                 values (and not within band at interface)
   *    sizePosLs  - elements in domain with positive level set function
   *                 values (and not within band at interface)
   */
  double sizeInterf;
  double sizeNegLs;
  double sizePosLs;

  /**
   * Indicates whether only interface elements or elements within a
   * band around the interface are refined (true) or refinement/coarsening
   * on the complete mesh is done (false).
   */
  bool onlyInterfRef;

  /**
   * Indicates whether band around interface/zero level set is used (true)
   * or not (false). 
   * If band is used, elements with at most distance bandSize to the
   * zero level set are refined to size sizeInterf.
   */
  bool bandAtInterf;

  /**
   * Defines bandwidth if band around interface is used.
   */
  double bandSize;

  /**
   * Constants to describe the position of an element with respect to a band 
   * around the interface.
   *    INTERIOR - in domain with negative level set function values and
   *               not in band
   *    IN_BAND  - at least on vertex of element has distance smaller than
   *               bandSize to the zero level set; the absolute value of
   *               the level set function is taken as the distance to
   *               the zero level set
   *    EXTERIOR - in domain with positive level set function values and
   *               not in band
   */
  static const int LS_ADAPT_MESH_INTERIOR = -1;
  static const int LS_ADAPT_MESH_IN_BAND = 0;
  static const int LS_ADAPT_MESH_EXTERIOR = 1;

  /**
   * Dimension of the mesh.
   */
  int dim;

  /**
   * Variables used in adaptMesh(), markElement_Band() and 
   * markElement_noBand().
   */
  bool doRefine;
  bool doCoarsen;
  bool refinementMarkIsSet;
  bool coarseningMarkIsSet;
};

#endif  // AMDIS_LEVELSETADAPTMESH_H