OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
HelpFunctions.hpp
Go to the documentation of this file.
1//
2// Created by jstark on 2019-11-08.
3//
12#ifndef REDISTANCING_SUSSMAN_HELPFUNCTIONS_HPP
13#define REDISTANCING_SUSSMAN_HELPFUNCTIONS_HPP
14
15#include <iostream>
16#include <fstream>
23template <class T>
24int sgn(T val)
25{
26 return (T(0) < val) - (val < T(0));
27}
46template <typename T>
47T smooth_S(T val, T epsilon)
48{
49 return (val / sqrt(val * val + epsilon * epsilon));
50}
51
52
63template <class T>
64bool isApproxEqual(T val1, T val2, T tolerance)
65{
66 return (val1 <= val2 + tolerance && val1 >= val2 - tolerance);
67}
68
75template <typename T>
76void append_value_to_textfile(std::string & textfile, T value)
77{
78 std::ofstream out(textfile, std::ios_base::app);
79 out << value;
80}
81
89template <typename T>
90std::string to_string_with_precision(const T myValue, const size_t n = 6)
91{
92 std::ostringstream out;
93 out.precision(n);
94 out << std::fixed << myValue;
95 return out.str();
96}
97
98
99#endif //REDISTANCING_SUSSMAN_HELPFUNCTIONS_HPP
T smooth_S(T val, T epsilon)
Gets the smoothed sign of a variable.
int sgn(T val)
Gets the sign of a variable.
std::string to_string_with_precision(const T myValue, const size_t n=6)
Converts value into string maintaining a desired precision.
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.
bool isApproxEqual(T val1, T val2, T tolerance)
Checks, if two values are sufficiently close to each other within a given tolerance range,...