MathFunctions.h 1.85 KB
Newer Older
1
2
3
4
5
6
7
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ==  http://www.amdis-fem.org                                              ==
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

/** \file MathFunctions.h */

#ifndef AMDIS_MATHFUNCTIONS_H
#define AMDIS_MATHFUNCTIONS_H

#include "Global.h"
#include <limits>

using namespace std;
namespace AMDiS {
  //converts signed distance to phasefield
  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)); }
  
  //levelset: positive (1) in the set, negative (-1) outside, zero on the boundary
  inline double LevelSet(double r)
  {
    if (r < 0)
      return 1;
    if (r > 0)
41
42
43
44
      return -1;
    return 0;
  }

45
46
47
48
  inline double Phi1ToR(double p1, double eps) 
  {
    double x = std::max(-1.0 + numeric_limits<double>::epsilon(), 
		    std::min(1.0 - numeric_limits<double>::epsilon(), p1));
49
    return eps / 3.0 * log((1 + x) / (1 - x)) * 0.5;
50
  }
51

52
53
54
55
  inline double Phi2ToR(double p2, double eps) 
  {
    double x = std::max(-1.0 + numeric_limits<double>::epsilon(), 
		    std::min(1.0 - numeric_limits<double>::epsilon(), 1 + 2 * p2));
56
    return eps / 3.0 * log( (1 + x) / (1 - x) );
57
  }
58

59
60
}
#endif