MeshFunction_Level.h 11.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/******************************************************************************
 *
 * Extension of AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: Simon Praetorius et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/


#ifndef EXTENSIONS_MESH_FUNCTION_LEVEL_H
#define EXTENSIONS_MESH_FUNCTION_LEVEL_H
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

using namespace AMDiS;


/** \brief
 * Base-Implementation of a MeshRefinementFunction for refinement of phase-field
 * interfaces. operator() must be overwritten in subclasses. Class provides
 * basic parameters for the refinement like refinement-level values on interface
 * or in the interesting domain and defines the refinement range for the phase-
 * field variable, i.e. interface is defined in [0.05, 0.95]
 **/
template<typename T>
class PhaseFieldRefinementBase : public MeshRefinementFunction<T, int>
{
public:

  PhaseFieldRefinementBase(Mesh *mesh) : 
    MeshRefinementFunction<T, int>(mesh),
    lInner(10),
    lOuter(10),
    lInterface(14),
    minPhase(0.05),
    maxPhase(0.95),
    minOuterPhase(0.001),
    maxOuterPhase(0.999)
  {
      Parameters::get("mesh->refinement->level in inner domain",lInner);
      Parameters::get("mesh->refinement->level in outer domain",lOuter);
      Parameters::get("mesh->refinement->level on interface",lInterface);

      lInterface-= mesh->getMacroElementLevel();
      lInner-= mesh->getMacroElementLevel();
      lOuter-= mesh->getMacroElementLevel();

      int local_globalSize = 10;
      Parameters::get("mesh->refinement->initial level", local_globalSize);
      MeshRefinementFunction<T, int>::globalSize = local_globalSize;

      Parameters::get("mesh->refinement->min interface value",minPhase);
      Parameters::get("mesh->refinement->max interface value",maxPhase);
      Parameters::get("mesh->refinement->min outer interface value",minOuterPhase);
      Parameters::get("mesh->refinement->max outer interface value",maxOuterPhase);
  }

  double meshSize() { return levelToH(MeshRefinementFunction<T, int>::globalSize); }

protected:

  int lInner;
  int lOuter;
  int lInterface;
  
  double minPhase;
  double maxPhase;
  double minOuterPhase;
  double maxOuterPhase;
};


/** \brief
 * Implementation of PhaseFieldRefinementBase. Provides the method operator()
 * that defines the regions for interface refinement and domain refinement, etc.
 **/
class PhaseFieldRefinement : public PhaseFieldRefinementBase<double>
{
public:

    PhaseFieldRefinement(Mesh* mesh_) : PhaseFieldRefinementBase<double>(mesh_) {};
    
    int operator()(const double& phase) const {
      int result= lOuter;
      if (minPhase < phase && phase < maxPhase)
        result= lInterface;         // auf dem Interface
      else if (phase > minOuterPhase && phase <= minPhase)
        result= std::max(lOuter, static_cast<int>(floor((lOuter+lInterface)/2.0)));
      else if (phase < maxOuterPhase && phase >= maxPhase)
        result= std::max(lInner, static_cast<int>(floor((lInner+lInterface)/2.0)));
      else if (phase > (minPhase+maxPhase)/2.0)
        result= lInner;
      return result;
    }
};


/** \brief
 * Implementation of PhaseFieldRefinementBase. Provides the method operator()
 * that defines the regions for interface refinement and domain refinement, etc.
 * Additionally to the phase-field value a list of refinement points can be given
 * where the mesh should be refined up to the a given level, e.g. in corners of 
 * the macro-mesh.
 **/
class PhaseFieldCoordsRefinement : public PhaseFieldRefinementBase< std::pair<WorldVector<double>, double> >
{
public:
    PhaseFieldCoordsRefinement(Mesh* mesh_, std::vector<WorldVector<double> > points_, double radius_) :
      PhaseFieldRefinementBase< std::pair<WorldVector<double>, double> >(mesh_),
117
      lPoints(14),
118
      points(points_),
119
      radius(radius_)
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
    {
        Parameters::get("mesh->refinement->level on points",lPoints);
        lPoints-= mesh->getMacroElementLevel();
    }
    
    int operator()(const std::pair<WorldVector<double>, double>& data) const {
      double phase = data.second;
      int result= lOuter;
      if (minPhase < phase && phase < maxPhase)
        result = lInterface;         // auf dem Interface
      else if ((phase > minOuterPhase && phase <= minPhase) || (phase < maxOuterPhase && phase >= maxPhase))
        result = std::max(lInner, static_cast<int>(floor((lOuter+lInterface)/2.0)));
      else if (phase > 0.5)
        result = lInner;

      WorldVector<double> x = data.first;
      double minDist = 1.e15;
      for (unsigned i = 0; i < points.size(); ++i) {
        minDist = std::min(minDist, norm(points[i]-x));
      }
      double lambda = std::max(0.0, 1.0 - minDist/radius);
      result = std::max(result, static_cast<int>(floor(lOuter+lambda*(lPoints-lOuter))));

      return result;
    }
    
private:

    int lPoints;

    std::vector<WorldVector<double> > points;

    double radius;
};


/** \brief
 * Implementation of MeshRefinementFunction. Provides the method operator()
 * that defines a list of refinement points where the mesh should be refined 
 * up to the a given level, e.g. in corners of the macro-mesh.
 **/
class CoordsRefinement : public MeshRefinementFunction< WorldVector<double>, int >
{
public:
    CoordsRefinement(Mesh* mesh_, std::vector<WorldVector<double> > points_, double radius_) 
    :
    MeshRefinementFunction< WorldVector<double>, int >(mesh_),
    points(points_),
    radius(radius_)
    {
        lInner= 15; lPoints = 20;
        Parameters::get("mesh->refinement->level on points",lPoints);
        Parameters::get("mesh->refinement->level in inner domain",lInner);
        lPoints-= mesh->getMacroElementLevel();
        lInner-= mesh->getMacroElementLevel();

        globalSize= lInner;
    }
    
    int operator()(const WorldVector<double>& x) const {
      double minDist = 1.e15;
      for (unsigned i = 0; i < points.size(); ++i) {
        minDist = std::min(minDist, norm(points[i]-x));
      }
      int result = lInner;
      double lambda = std::max(0.0, 1.0 - minDist/radius);
      result = std::max(result, static_cast<int>(floor(lInner+lambda*(lPoints-lInner))));

      return result;
    }
    double meshSize() { return levelToH(lInner); }
    
private:
    int lInner, lPoints;
    std::vector<WorldVector<double> > points;
    double radius;
};


/** \brief
 * Implementation of PhaseFieldRefinementBase. Provides the method operator()
 * that defines the level of refinement depending on a list of phase-fields, e.g.
 * a diffuse-domain representation and a Cahn-Hilliard field.
 **/
class PhaseFieldChRefinement : public PhaseFieldRefinementBase< std::vector<double> >
{
public:
  PhaseFieldChRefinement(Mesh* mesh_) 
  :
  PhaseFieldRefinementBase< std::vector<double> >(mesh_),
  lInterfaceDomain(14)
  {
    Parameters::get("mesh->refinement->level on domain interface",lInterfaceDomain);
    lInterfaceDomain-= mesh->getMacroElementLevel();
    
    Parameters::get("mesh->refinement->initial level", globalSize);
  }
  
  int operator()(const std::vector<double>& phases) const 
  {
    int result= lOuter;
    for (unsigned i = 0; i < phases.size(); ++i) {
      int localResult= lOuter;
      if (minPhase < phases[i] && phases[i] < maxPhase
        && (i < 1 || phases[i-1] > 0.5))
        localResult= (i==0 ? lInterfaceDomain : lInterface);         // auf dem Interface
      else if (phases[i] > 0.5
        && (i < 1 || phases[i-1] > 0.5))
        localResult= lInner;            // im Innern des Gebietes
      if (((phases[i] > minOuterPhase && phases[i] <= minPhase) || (phases[i] < maxOuterPhase && phases[i] >= maxPhase))
        && (i < 1 || phases[i-1] > 0.5))
        localResult= static_cast<int>(floor((lInner + lInterface) / 2.0));
      result= std::max(result, localResult);
    }
    return result;
  }
    
private:

  int lInterfaceDomain;
};


/** \brief
 * Base-Implementation of a MeshRefinementFunction for refinement of phase-field
 * interfaces. operator() must be overwritten in subclasses. Class provides
 * basic parameters for the refinement like refinement-level values on interface
 * or in the interesting domain and defines the refinement range for the phase-
 * field variable, i.e. interface is defined in [0.05, 0.95]
 **/
template<typename T>
class SignedDistRefinementBase : public MeshRefinementFunction<T, int>
{
public:

  SignedDistRefinementBase(Mesh *mesh) :
    MeshRefinementFunction<T, int>(mesh),
    lInner(10),
    lOuter(10),
    lInterface(14),
    interfaceWidth(0.2),
    fadeOutWidth(0.0),
    signInInnerDomain(-1.0)
  {
      Parameters::get("mesh->refinement->level in inner domain",lInner);
      Parameters::get("mesh->refinement->level in outer domain",lOuter);
      Parameters::get("mesh->refinement->level on interface",lInterface);

      lInterface-= mesh->getMacroElementLevel();
      lInner-= mesh->getMacroElementLevel();
      lOuter-= mesh->getMacroElementLevel();

      int local_globalSize = 10;
      Parameters::get("mesh->refinement->initial level", local_globalSize);
      MeshRefinementFunction<T, int>::globalSize = local_globalSize;

      Parameters::get("mesh->refinement->interface width",interfaceWidth);
      Parameters::get("mesh->refinement->fade out width",fadeOutWidth);
      Parameters::get("mesh->refinement->sign in inner domain",signInInnerDomain);
  }

  double meshSize() { return levelToH(MeshRefinementFunction<T, int>::globalSize); }

protected:

  int lInner;
  int lOuter;
  int lInterface;

  double interfaceWidth;
  double fadeOutWidth;
  double signInInnerDomain;
};


/** \brief
 * Implementation of PhaseFieldRefinementBase. Provides the method operator()
 * that defines the regions for interface refinement and domain refinement, etc.
 **/
class SignedDistRefinement : public SignedDistRefinementBase<double>
{
public:

    SignedDistRefinement(Mesh* mesh_) : SignedDistRefinementBase<double>(mesh_) {};

    int operator()(const double& dist) const {
      int result= lOuter;
      if (abs(dist) < interfaceWidth)
        result= lInterface;         // auf dem Interface
      else if (abs(dist) < fadeOutWidth+interfaceWidth && signInInnerDomain*dist < 0.0) {
	double lambda = abs(dist)/fadeOutWidth - interfaceWidth/fadeOutWidth;
        result= static_cast<int>(floor(lambda*lInner+(1.0-lambda)*lInterface));
      } else if (abs(dist) < fadeOutWidth+interfaceWidth && signInInnerDomain*dist > 0.0) {
	double lambda = abs(dist)/fadeOutWidth - interfaceWidth/fadeOutWidth;
        result= static_cast<int>(floor(lambda*lOuter+(1.0-lambda)*lInterface));
      } else if (signInInnerDomain*dist < 0.0)
        result= lInner;
      return result;
    }
};

321

322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
class ESIndicator : public MeshRefinementFunction< std::vector<double>, int >
{
public:
  ESIndicator(Mesh* mesh_) 
  :
  MeshRefinementFunction< std::vector<double>, int >(mesh_)
  {
    Parameters::get("mesh->refinement->initial level", globalSize);
  }
  
  int operator()(const std::vector<double>& means) const 
  {
    double tol = means[0];
    return (abs(means[1]-means[2]) > tol ? 0 : -1);
  }
    
  double indicator(const std::vector<double>& means) const 
  {
    return abs(means[1]-means[2]);
  }
};
343
344

#endif // EXTENSIONS_MESH_FUNCTION_LEVEL_H