Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
phi.h
Go to the documentation of this file.
1
25struct phi {
26 phi (Float n1=2, Float c1=1, Float r1=0) : n(n1), c(c1), r(r1) {}
27 Float operator() (const Float& x) const {
28 if (x <= 0) return 0;
29 if (n == 1) return x/(c+r);
30 if (r == 0) return pow(x/c,1/n);
31 Float y = x/(c+r);
32 const Float tol = numeric_limits<Float>::epsilon();
33 for (size_t i = 0; true; ++i) {
34 Float ry = f(y)-x;
35 Float dy = -ry/df_dy(y);
36 if (fabs(ry) <= tol && fabs(dy) <= tol) break;
37 if (i >= max_iter) break;
38 if (y+dy > 0) {
39 y += dy;
40 } else {
41 y /= 2;
42 check_macro (1+y != y, "phi: machine precision problem");
43 }
44 }
45 return y;
46 }
47 Float derivative (const Float& x) const {
48 Float phi_x = operator()(x);
49 return 1/(r + n*c*pow(phi_x,-1+n));
50 }
51protected:
52 Float f(Float y) const { return c*pow(y,n) + r*y; }
53 Float df_dy(Float y) const { return n*c*pow(y,-1+n) + r; }
55 static const size_t max_iter = 100;
56};
see the Float page for the full documentation
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
space_mult_list< T, M > pow(const space_basic< T, M > &X, size_t n)
Definition space_mult.h:120
Definition cavity_dg.h:29
Definition phi.h:25
phi(Float n1=2, Float c1=1, Float r1=0)
Definition phi.h:26
Float c
Definition phi.h:54
Float derivative(const Float &x) const
Definition phi.h:47
static const size_t max_iter
Definition phi.h:55
Float n
Definition phi.h:54
Float r
Definition phi.h:54
Float f(Float y) const
Definition phi.h:52
Float df_dy(Float y) const
Definition phi.h:53
Float operator()(const Float &x) const
Definition phi.h:27