MathFunctions.h 1.01 KB
 Naumann, Andreas committed May 25, 2010 1 2 ``````#ifndef AMDIS_MATHFUNCTIONS_H #define AMDIS_MATHFUNCTIONS_H `````` Praetorius, Simon committed May 25, 2010 3 4 `````` #include "Global.h" `````` Naumann, Andreas committed Oct 22, 2010 5 ``````#include `````` Praetorius, Simon committed May 25, 2010 6 `````` `````` Naumann, Andreas committed Oct 22, 2010 7 ``````using namespace std; `````` Naumann, Andreas committed May 25, 2010 8 9 ``````namespace AMDiS { //converts signed distance to phasefield `````` Naumann, Andreas committed May 28, 2010 10 11 `````` inline double Phi1(double r, double eps) { return 0.5 * (1 - tanh(3 * r / eps)); } inline double Phi2(double r, double eps) { return 0.5 * (1 + tanh(3 * r / eps)); } `````` Naumann, Andreas committed May 25, 2010 12 13 14 15 `````` //levelset: positive (1) in the set, negative (-1) outside, zero on the boundary inline double LevelSet(double r) { `````` Naumann, Andreas committed May 28, 2010 16 `````` if (r < 0) `````` Naumann, Andreas committed May 25, 2010 17 `````` return 1; `````` Naumann, Andreas committed May 28, 2010 18 `````` if (r > 0) `````` Naumann, Andreas committed May 25, 2010 19 20 21 22 `````` return -1; return 0; } `````` 23 `````` inline double Phi1ToR(double p1, double eps) { `````` Naumann, Andreas committed Oct 22, 2010 24 25 26 `````` double x = max(-1.0 + numeric_limits< double >::epsilon(), min(1.0 - numeric_limits< double >::epsilon(), p1)); return eps / 3.0 * log((1 + x) / (1 - x)) * 0.5; `````` 27 `````` } `````` Naumann, Andreas committed Oct 22, 2010 28 `````` `````` 29 `````` inline double Phi2ToR(double p2, double eps) { `````` Naumann, Andreas committed Oct 22, 2010 30 31 32 `````` double x = max(-1.0 + numeric_limits< double >::epsilon(), min(1.0 - numeric_limits< double >::epsilon(), 1 + 2 * p2)); return eps / 3.0 * log( (1 + x) / (1 - x) ); `````` 33 `````` } `````` Naumann, Andreas committed Oct 22, 2010 34 `````` `````` Naumann, Andreas committed May 25, 2010 35 36 ``````} #endif``````