From cf83fce105f287e8892c8fdbb692a4c3168d64ac Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Tue, 7 Aug 2012 13:20:06 +0000 Subject: [PATCH] converting routines for phasefields and signed distance functions --- extensions/PhaseFieldConvert.h | 131 ++++++++++++++++++++++----------- 1 file changed, 90 insertions(+), 41 deletions(-) diff --git a/extensions/PhaseFieldConvert.h b/extensions/PhaseFieldConvert.h index 4dddd39c..713141c9 100644 --- a/extensions/PhaseFieldConvert.h +++ b/extensions/PhaseFieldConvert.h @@ -5,6 +5,10 @@ using namespace AMDiS; +/// \brief +/// Converts an AbstractFunction dist, that describes a signed distance function, to +/// a phasefield function p, by \f$\frac{1}{2}(1 - tanh(s \cdot dist(x) / \epsilon))\f$ +/// struct SignedDistFctToPhaseField : AbstractFunction > { SignedDistFctToPhaseField(double epsilon_, @@ -27,6 +31,67 @@ private: double scalingFactor; }; + +/// \brief +/// Converts a DOFVector, that describes a signed distance function, to +/// a phasefield function p, by \f$\frac{1}{2}(1 - tanh(s \cdot dist / \epsilon))\f$. +/// You have to use transformDOF to apply this function to the DOFVector dist. +/// +struct SignedDistToPhaseField : AbstractFunction +{ + SignedDistToPhaseField(double epsilon_ = -1.0, double scalingFactor_ = 1.0/sqrt(2.0)) + : AbstractFunction(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 p with values in [-1,1], by \f$- tanh(s \cdot dist / \epsilon)\f$. +/// You have to use transformDOF to apply this function to the DOFVector dist. +/// +struct SignedDistToCh : AbstractFunction +{ + SignedDistToCh(double epsilon_ = -1.0, double scalingFactor_ = 1.0/sqrt(2.0)) + : AbstractFunction(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 {dist_i}, that describe signed distance functions, to +/// a phasefield function p, 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 > { 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 > { SignedDistList(std::vector >*> dist_) @@ -89,6 +158,14 @@ private: std::vector >*> dist; }; + +/// \brief +/// Converts a DOFVector, that describes a phasefield function phi, to +/// a signed distance function dist, by \f$atanh(-\phi)\cdot\epsilon/s \f$. +/// You have to use transformDOF to apply this function to the DOFVector phi. +/// 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 { PhaseFieldToSignedDist(double epsilon_= -1.0, double scalingFactor_ = 1.0/sqrt(2.0)) @@ -111,48 +188,13 @@ private: double scalingFactor; }; -struct SignedDistToPhaseField : AbstractFunction -{ - SignedDistToPhaseField(double epsilon_ = -1.0, double scalingFactor_ = 1.0/sqrt(2.0)) - : AbstractFunction(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 -{ - SignedDistToCh(double epsilon_ = -1.0, double scalingFactor_ = 1.0/sqrt(2.0)) - : AbstractFunction(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 c 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 transformDOF to apply this function to the DOFVector phi. +/// struct ChToPhaseField : AbstractFunction { ChToPhaseField() : AbstractFunction(1) {}; @@ -162,6 +204,13 @@ struct ChToPhaseField : AbstractFunction } }; + +/// \brief +/// Converts a DOFVector, that describes a phasefield function phi 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 transformDOF to apply this function to the DOFVector phi. +/// struct PhaseFieldToCh : AbstractFunction { PhaseFieldToCh() : AbstractFunction(1) {}; -- GitLab