PhaseFieldConvert.h 6.54 KB
Newer Older
1
2
3
4
5
6
7
/** \file PhaseFieldConvert.h */

#ifndef PHASE_FIELD_CONVERT_H
#define PHASE_FIELD_CONVERT_H

using namespace AMDiS;

8
9
10
11
/// \brief
/// Converts an AbstractFunction <i>dist</i>, that describes a signed distance function, to
/// a phasefield function <i>p</i>, by \f$ \frac{1}{2}(1 - tanh(s \cdot dist(x) / \epsilon))\f$
///
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
struct SignedDistFctToPhaseField : AbstractFunction<double, WorldVector<double> >
{
  SignedDistFctToPhaseField(double epsilon_, 
			    AbstractFunction<double,WorldVector<double> > *dist_, 
			    double scalingFactor_ = 1.0/sqrt(2.0))
  : AbstractFunction<double, WorldVector<double> >(6), 
    epsilon(epsilon_), 
    dist(dist_),
    scalingFactor(scalingFactor_) {};

  double operator()(const WorldVector<double> &x) const
  {
    return 0.5 * (1.0 - tanh(scalingFactor * (*dist)(x) / epsilon));
  }
        
private:

  double epsilon;
  AbstractFunction<double,WorldVector<double> > *dist;
  double scalingFactor;
};

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

/// \brief
/// Converts a DOFVector, that describes a signed distance function, to
/// a phasefield function <i>p</i>, by \f$ \frac{1}{2}(1 - tanh(s \cdot dist / \epsilon))\f$.
/// You have to use <i>transformDOF</i> to apply this function to the DOFVector <i>dist</i>.
///
struct SignedDistToPhaseField : AbstractFunction<double, double>
{
  SignedDistToPhaseField(double epsilon_ = -1.0, double scalingFactor_ = 1.0/sqrt(2.0))
  : AbstractFunction<double, double>(6),
    epsilon(epsilon_),
    scalingFactor(scalingFactor_)
  {
    if (epsilon < 0.0)
      Parameters::get("mesh->refinement->epsilon", epsilon);
  }
  
  double operator()(const double &dist) const
  {
    return 0.5 * (1.0 - tanh(scalingFactor * dist / epsilon));
  }
  
private:
  double epsilon;
  double scalingFactor;
};


/// \brief
/// Converts a DOFVector, that describes a signed distance function, to
/// a phasefield function <i>p</i> with values in [-1,1], by \f$ - tanh(s \cdot dist / \epsilon)\f$.
/// You have to use <i>transformDOF</i> to apply this function to the DOFVector <i>dist</i>.
///
struct SignedDistToCh : AbstractFunction<double, double>
{
  SignedDistToCh(double epsilon_ = -1.0, double scalingFactor_ = 1.0/sqrt(2.0))
  : AbstractFunction<double, double>(6),
    epsilon(epsilon_),
    scalingFactor(scalingFactor_)
  {
    if (epsilon < 0.0)
      Parameters::get("mesh->refinement->epsilon", epsilon);
  }
  
  double operator()(const double &dist) const
  {
    return -tanh(scalingFactor * dist / epsilon);
  }
  
private:
  double epsilon;
  double scalingFactor;
};


/// \brief
/// Converts a vector of AbstractFunctions <i>{dist_i}</i>, that describe signed distance functions, to
/// a phasefield function <i>p</i>, by \f$ \frac{1}{2}(1 - tanh(s \cdot \min_i(dist_i(x)) / \epsilon))\f$.
/// The minimum of all distance function describes the union of the areas of negative values, of the 
/// distance functions.
///
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
struct SignedDistFctListToPhaseField : AbstractFunction<double, WorldVector<double> >
{
  SignedDistFctListToPhaseField(double epsilon_, 
				std::vector<AbstractFunction<double,WorldVector<double> >*> dist_, 
				double scalingFactor_ = 1.0/sqrt(2.0))
  : AbstractFunction<double, WorldVector<double> >(6), 
    epsilon(epsilon_), 
    dist(dist_),
    scalingFactor(scalingFactor_) {};

  double operator()(const WorldVector<double> &x) const
  {
    double d = 1.e12;
    for (size_t i = 0; i < dist.size(); ++i) {
      d = std::min((*(dist[i]))(x), d);
    }
    return 0.5 * (1.0 - tanh(scalingFactor * d / epsilon));
  }
        
private:

  double epsilon;
  std::vector<AbstractFunction<double,WorldVector<double> >*> dist;
  double scalingFactor;
};


122
123
124
125
/// \brief
/// Calculates the maximum of vector of distance function. This describes the intersections of the areas
/// of negative values, of the distance functions.
///
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
struct SignedDistList : AbstractFunction<double, WorldVector<double> >
{
  SignedDistList(std::vector<AbstractFunction<double,WorldVector<double> >*> dist_)
  : AbstractFunction<double, WorldVector<double> >(1), 
    dist(dist_) {};

  double operator()(const WorldVector<double> &x) const
  {
    d.setX(x);
    return std::for_each(dist.begin(), dist.end(), d);
  }

private:  
  struct MyMax {
    mutable double val;
    mutable WorldVector< double > x;
    MyMax()
    : val(-1.0e12) {}
    
    void operator()(const AbstractFunction<double,WorldVector<double> >* v) const
    {
      val = max((*v)(x), val);
    }
    
    void setX(const WorldVector<double> &x_) const
    {
      x= x_;
    }
    
    inline operator double() { return val; }
  } d;
  
  std::vector<AbstractFunction<double,WorldVector<double> >*> dist;
};

161
162
163
164
165
166
167
168

/// \brief
/// Converts a DOFVector, that describes a phasefield function <i>phi</i>, to
/// a signed distance function <i>dist</i>, by \f$ atanh(-\phi)\cdot\epsilon/s \f$.
/// You have to use <i>transformDOF</i> to apply this function to the DOFVector <i>phi</i>.
/// the phasefield values are cutted to allow the atanh calculation, by
/// \f$ \phi:=\max(-1 + 10^{-10}, min(1-10^{-10}, \phi) ) \f$
///
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
struct PhaseFieldToSignedDist : AbstractFunction<double, double>
{
  PhaseFieldToSignedDist(double epsilon_= -1.0, double scalingFactor_ = 1.0/sqrt(2.0))
  : AbstractFunction<double, double>(6), 
    epsilon(epsilon_),
    scalingFactor(scalingFactor_)
  {
    if (epsilon < 0.0)
      Parameters::get("mesh->refinement->epsilon", epsilon);
  }
  
  double operator()(const double &phi) const
  {
    double z = std::max(-1.0 + 1.e-10, std::min(1.0 - 1.e-10, -phi));
    return (epsilon/scalingFactor) * atanh(z);
  }
  
private:
  double epsilon;
  double scalingFactor;
};


192
193
194
195
196
197
/// \brief
/// Converts a DOFVector, that describes a phasefield function <i>c</i> with
/// values in [-1, 1], to a phasefield function with values in [0,1], by 
/// \f$ \frac{1}{2}(c + 1) \f$.
/// You have to use <i>transformDOF</i> to apply this function to the DOFVector <i>phi</i>.
///
198
199
200
201
202
203
204
205
206
struct ChToPhaseField : AbstractFunction<double, double>
{
  ChToPhaseField() : AbstractFunction<double, double>(1) {};
  double operator()(const double &c) const
  {
    return std::max(0.0, std::min(1.0, 0.5 * (c + 1.0)));
  }
};

207
208
209
210
211
212
213

/// \brief
/// Converts a DOFVector, that describes a phasefield function <i>phi</i> with
/// values in [0, 1], to a phasefield function with values in [-1,1], by 
/// \f$ 2\cdot\phi-1 \f$.
/// You have to use <i>transformDOF</i> to apply this function to the DOFVector <i>phi</i>.
///
214
215
216
217
218
219
220
221
222
223
struct PhaseFieldToCh : AbstractFunction<double, double>
{
  PhaseFieldToCh() : AbstractFunction<double, double>(1) {};
  double operator()(const double &c) const
  {
    return std::max(-1.0, std::min(1.0, 2.0 * c - 1.0));
  }
};

#endif // PHASE_FIELD_CONVERT_H