Commit cf83fce1 authored by Praetorius, Simon's avatar Praetorius, Simon

converting routines for phasefields and signed distance functions

parent 49bb4f10
......@@ -5,6 +5,10 @@
using namespace AMDiS;
/// \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$
///
struct SignedDistFctToPhaseField : AbstractFunction<double, WorldVector<double> >
{
SignedDistFctToPhaseField(double epsilon_,
......@@ -27,6 +31,67 @@ private:
double scalingFactor;
};
/// \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.
///
struct SignedDistFctListToPhaseField : AbstractFunction<double, WorldVector<double> >
{
SignedDistFctListToPhaseField(double epsilon_,
......@@ -54,6 +119,10 @@ private:
};
/// \brief
/// Calculates the maximum of vector of distance function. This describes the intersections of the areas
/// of negative values, of the distance functions.
///
struct SignedDistList : AbstractFunction<double, WorldVector<double> >
{
SignedDistList(std::vector<AbstractFunction<double,WorldVector<double> >*> dist_)
......@@ -89,6 +158,14 @@ private:
std::vector<AbstractFunction<double,WorldVector<double> >*> dist;
};
/// \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$
///
struct PhaseFieldToSignedDist : AbstractFunction<double, double>
{
PhaseFieldToSignedDist(double epsilon_= -1.0, double scalingFactor_ = 1.0/sqrt(2.0))
......@@ -111,48 +188,13 @@ private:
double scalingFactor;
};
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;
};
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 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>.
///
struct ChToPhaseField : AbstractFunction<double, double>
{
ChToPhaseField() : AbstractFunction<double, double>(1) {};
......@@ -162,6 +204,13 @@ struct ChToPhaseField : AbstractFunction<double, double>
}
};
/// \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>.
///
struct PhaseFieldToCh : AbstractFunction<double, double>
{
PhaseFieldToCh() : AbstractFunction<double, double>(1) {};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment