OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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.
 
template<typename T >
smooth_S (T val, T epsilon)
 Gets the smoothed sign of a variable.
 
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<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<typename T >
std::string to_string_with_precision (const T myValue, const size_t n=6)
 Converts value into string maintaining a desired precision.
 

Detailed Description

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

Author
Justina Stark
Date
November 2019

Definition in file HelpFunctions.hpp.

Function Documentation

◆ append_value_to_textfile()

template<typename T >
void append_value_to_textfile ( std::string &  textfile,
value 
)

Appends the value of a given variable of any type to a textfile as string.

Template Parameters
TInferred type of the input variable, whose value should be appended to textfile as string.
Parameters
textfileStd::string that contains the path and filename of the textfile, to which value should be added.
valueVariable 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 ( val1,
val2,
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
TInferred type of the two variables, for which it should be checked, if they are sufficiently close.
Parameters
val1Variable that contains the first value.
val2Variable that contains the second value.
toleranceTolerance (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 ( val)

Gets the sign of a variable.

Template Parameters
TInferred type of input variable.
Parameters
valScalar 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 ( val,
epsilon 
)

Gets the smoothed sign of a variable.

Sign function with smoothing effect on numerical solution (see:

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
TTemplate type of vlaue.
Parameters
myValueValue of type T.
nNumber 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.