Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
signed_distance_transformation.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2025-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_signed_distance_transformation_h
5#define lethe_signed_distance_transformation_h
6
7
9
10/**
11 * @brief Abstract class for the transformation of the signed distance to the
12 * phase indicator for the CLS solver when geometric redistanciation is used.
13 */
15{
16public:
17 /**
18 * @brief Default destructor.
19 */
21
22
23 /**
24 * @brief Instantiate and return a pointer to a
25 * SignedDistanceTransformationBase object by casting it to the proper child
26 * class.
27 *
28 * @param[in] geometric_redistanciation_parameters CLS geometric
29 * redistanciation parameters.
30 *
31 * @return Casted SignedDistanceTransformationBase child class object.
32 */
33 static std::shared_ptr<SignedDistanceTransformationBase>
35 &geometric_redistanciation_parameters);
36
37 /**
38 * @brief Compute the value of the phase indicator from the signed distance.
39 *
40 * @param[in] signed_distance Value of the signed distance
41 *
42 * @return Value of the computed phase indicator after applying the
43 * transformation.
44 */
45 inline virtual double
46 transform_signed_distance(const double signed_distance) = 0;
47};
48
49/**
50 * @brief Transforms the signed distance to the phase indicator with a hyperbolic
51 * tangent function.
52 *
53 * The phase indicator is defined as:
54 *
55 * \f$\phi = 0.5 - 0.5 \tanh(d/\varepsilon)\f$
56 *
57 * where \f$d\f$ is the signed distance and \f$\varepsilon\f$
58 * is a model parameter giving a measure of the interface thickness.
59 *
60 */
62{
63public:
64 /**
65 * @brief Constructor of the hyperbolic tangent signed distance transformation.
66 *
67 * @param[in] tanh_thickness Value of the \f$\varepsilon\f$ parameter
68 * modulating the interface thickness.
69 */
73
74 /**
75 * @brief Computes the value of the phase indicator from the signed distance.
76 *
77 * @param[in] signed_distance Value of the signed distance
78 *
79 * @return Value of the computed phase indicator after applying the
80 * transformation.
81 */
82 inline double
83 transform_signed_distance(const double signed_distance) override
84 {
85 return 0.5 - 0.5 * tanh(signed_distance / tanh_thickness);
86 }
87
88private:
89 /**
90 * User-defined parameter that defines the thickness of the interface. It
91 * influences its sharpness: a smaller value leads to a sharper interface.
92 */
93 const double tanh_thickness;
94};
95
96/**
97 * @brief Transforms the signed distance to the phase indicator with a piecewise
98 * polynomial function (degree 4).
99 *
100 * The phase indicator is defined as:
101 *
102 * if \f$d < 0 \f$
103 * \f$\phi = 0.5 - 0.5(4d' + 6d'^2 + 4*d'^3 + d'^4)\f$
104 *
105 * else
106 * \f$\phi = 0.5 - 0.5(4d' - 6d'^2 + 4*d'^3 - d'^4)\f$
107 *
108 * with \f$d' = d/d_\mathrm{max}\f$, where \f$d\f$ the signed distance and
109 * \f$d_\mathrm{max}\f$ the maximum redistanciation distance. This
110 * transformation clamps the phase indicator to 0 or 1 when \f$d = \pm
111 * d_\mathrm{max}\f$.
112 *
113 */
116{
117public:
118 /**
119 * @brief Constructor of the piecewise polynomial signed distance
120 * transformation.
121 *
122 * @param[in] max_reinitialization_distance Value of the maximum distance
123 */
125 const double max_reinitialization_distance)
126 : max_reinitialization_distance_inv(1.0 / max_reinitialization_distance)
127 {}
128
129 /**
130 * @brief Computes the value of the phase indicator from the signed distance.
131 *
132 * @param[in] signed_distance Value of the signed distance
133 *
134 * @return Value of the computed phase indicator after applying the transtion.
135 */
136 inline double
137 transform_signed_distance(const double signed_distance) override
138 {
139 const double dimentionless_d =
140 signed_distance * max_reinitialization_distance_inv;
141
142 double piecewise_polynomial_value;
143
144 if (dimentionless_d < 0.0)
145 {
146 piecewise_polynomial_value =
147 4.0 * dimentionless_d +
148 6.0 * Utilities::fixed_power<2>(dimentionless_d) +
149 4.0 * Utilities::fixed_power<3>(dimentionless_d) +
150 Utilities::fixed_power<4>(dimentionless_d);
151
152 return 0.5 - 0.5 * piecewise_polynomial_value;
153 }
154 else
155 {
156 piecewise_polynomial_value =
157 4.0 * dimentionless_d -
158 6.0 * Utilities::fixed_power<2>(dimentionless_d) +
159 4.0 * Utilities::fixed_power<3>(dimentionless_d) -
160 Utilities::fixed_power<4>(dimentionless_d);
161
162 return 0.5 - 0.5 * piecewise_polynomial_value;
163 }
164 }
165
166private:
167 /**
168 * Inverse of the maximum redistanciation distance.
169 */
171};
172
173#endif
Abstract class for the transformation of the signed distance to the phase indicator for the CLS solve...
virtual ~SignedDistanceTransformationBase()=default
Default destructor.
virtual double transform_signed_distance(const double signed_distance)=0
Compute the value of the phase indicator from the signed distance.
static std::shared_ptr< SignedDistanceTransformationBase > model_cast(const Parameters::CLS_GeometricInterfaceReinitialization &geometric_redistanciation_parameters)
Instantiate and return a pointer to a SignedDistanceTransformationBase object by casting it to the pr...
SignedDistanceTransformationPiecewisePolynomial(const double max_reinitialization_distance)
Constructor of the piecewise polynomial signed distance transformation.
double transform_signed_distance(const double signed_distance) override
Computes the value of the phase indicator from the signed distance.
SignedDistanceTransformationTanh(const double tanh_thickness)
Constructor of the hyperbolic tangent signed distance transformation.
double transform_signed_distance(const double signed_distance) override
Computes the value of the phase indicator from the signed distance.
Parameters for geometric reinitialization of the interface used with the CLS solver.