Rheolef
7.1
an efficient C++ finite element environment
phi.h
Go to the documentation of this file.
1
struct
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
}
51
protected
:
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
; }
54
Float
n
,
c
,
r
;
55
static
const
size_t
max_iter
= 100;
56
};
check_macro
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
phi::df_dy
Float df_dy(Float y) const
Definition:
phi.h:53
phi
Definition:
phi.h:25
rheolef::pow
space_mult_list< T, M > pow(const space_basic< T, M > &X, size_t n)
Definition:
space_mult.h:120
phi::f
Float f(Float y) const
Definition:
phi.h:52
phi::operator()
Float operator()(const Float &x) const
Definition:
phi.h:27
phi::max_iter
static const size_t max_iter
Definition:
phi.h:55
phi::n
Float n
Definition:
phi.h:54
phi::r
Float r
Definition:
phi.h:54
Float
see the Float page for the full documentation
phi::derivative
Float derivative(const Float &x) const
Definition:
phi.h:47
epsilon
Float epsilon
Definition:
transmission_error.cc:25
phi::c
Float c
Definition:
phi.h:54
phi::phi
phi(Float n1=2, Float c1=1, Float r1=0)
Definition:
phi.h:26