OpenFPM_pdata  4.1.0 Project that contain the implementation of distributed structures
HelpFunctions.hpp File Reference

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 >
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...

## Detailed Description

Header file containing small mathematical help-functions that are needed e.g. for the Sussman redistancing.

Date
November 2019

Definition in file HelpFunctions.hpp.

## ◆ append_value_to_textfile()

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.

Template Parameters
 T Inferred type of the input variable, whose value should be appended to textfile as string.
Parameters
 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.

## ◆ isApproxEqual()

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.

Template Parameters
 T Inferred type of the two variables, for which it should be checked, if they are sufficiently close.
Parameters
 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.
Returns
True, if val1 and val2 are the same +/- tolerance. False, if they differ by more than tolerance.

Definition at line 64 of file HelpFunctions.hpp.

## ◆ sgn()

template<class T >
 int sgn ( T val )

Gets the sign of a variable.

Template Parameters
 T Inferred type of input variable.
Parameters
 val Scalar variable of arbitrary type for which the sign should be determined.
Returns
Integer variable that contains a -1, if argument negative, 0 if argument=0, and +1 if argument positive.

Definition at line 24 of file HelpFunctions.hpp.

## ◆ smooth_S()

template<typename T >
 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.

Template Parameters
 T Inferred type of the variable for which the smooth sign should be determined.
Parameters
 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$
Returns
Smooth sign of the argument variable:

$sgn_{\epsilon}(\phi)$

.

Definition at line 47 of file HelpFunctions.hpp.

## ◆ to_string_with_precision()

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.

Template Parameters
 T Template type of vlaue.
Parameters
 myValue Value of type T. n Number of digits after the point the string of the value should have
Returns
String containing myValue with precision n.

Definition at line 90 of file HelpFunctions.hpp.