Header file containing small mathematical help-functions that are needed e.g. for the Sussman redistancing. More...
#include <iostream>
#include <fstream>
Go to the source code of this file.
Functions | |
template<class T > | |
int | sgn (T val) |
Gets the sign of a variable. More... | |
template<typename T > | |
T | smooth_S (T val, T epsilon) |
Gets the smoothed sign of a variable. More... | |
template<class T > | |
bool | isApproxEqual (T val1, T val2, T tolerance) |
Checks, if two values are sufficiently close to each other within a given tolerance range, as to be considered as approximately equal. More... | |
template<typename T > | |
void | append_value_to_textfile (std::string &textfile, T value) |
Appends the value of a given variable of any type to a textfile as string. More... | |
template<typename T > | |
std::string | to_string_with_precision (const T myValue, const size_t n=6) |
Converts value into string maintaining a desired precision. More... | |
Header file containing small mathematical help-functions that are needed e.g. for the Sussman redistancing.
Definition in file HelpFunctions.hpp.
void append_value_to_textfile | ( | std::string & | textfile, |
T | value | ||
) |
Appends the value of a given variable of any type to a textfile as string.
T | Inferred type of the input variable, whose value should be appended to textfile as string. |
textfile | Std::string that contains the path and filename of the textfile, to which value should be added. |
value | Variable that contains the value which should be appended to the textfile . |
Definition at line 76 of file HelpFunctions.hpp.
bool isApproxEqual | ( | T | val1, |
T | val2, | ||
T | tolerance | ||
) |
Checks, if two values are sufficiently close to each other within a given tolerance range, as to be considered as approximately equal.
T | Inferred type of the two variables, for which it should be checked, if they are sufficiently close. |
val1 | Variable that contains the first value. |
val2 | Variable that contains the second value. |
tolerance | Tolerance (or error) by which values are allowed to deviate while still being considered as equal. |
val1
and val2
are the same +/- tolerance
. False, if they differ by more than tolerance
. Definition at line 64 of file HelpFunctions.hpp.
int sgn | ( | T | val | ) |
Gets the sign of a variable.
T | Inferred type of input variable. |
val | Scalar variable of arbitrary type for which the sign should be determined. |
Definition at line 24 of file HelpFunctions.hpp.
T smooth_S | ( | T | val, |
T | epsilon | ||
) |
Gets the smoothed sign of a variable.
Sign function with smoothing effect on numerical solution (see: Peng et al. "A PDE-Based Fast Local Level Set Method", equation (36). Peng et al.: "The choice of approximation to S(d) by (36) solves the problem of the changing of sign of Phi (thus moving the interface across the cell boundary) in the reinitialization step when Phi is steep and speeds up the convergence when Phi is flat at the interface."
\[ sgn_{\epsilon}(\phi) = \frac{\phi}{ \sqrt{\phi^2 + |\nabla\phi|^2 \Delta x^2} }\]
where the φ is the approximation of the SDF from the last iteration.
T | Inferred type of the variable for which the smooth sign should be determined. |
val | Scalar variable for which the smooth sign should be determined. |
epsilon | Scalar variable containing the smoothing factor. In case of Peng: \[\epsilon = |\nabla\phi|^2 \Delta x^2\] |
\[sgn_{\epsilon}(\phi)\]
.Definition at line 47 of file HelpFunctions.hpp.
std::string to_string_with_precision | ( | const T | myValue, |
const size_t | n = 6 |
||
) |
Converts value into string maintaining a desired precision.
T | Template type of vlaue. |
myValue | Value of type T. |
n | Number of digits after the point the string of the value should have |
Definition at line 90 of file HelpFunctions.hpp.