phi.h
Go to the documentation of this file.
struct phi {
phi (Float n1=2, Float c1=1, Float r1=0) : n(n1), c(c1), r(r1) {}
Float operator() (const Float& x) const {
if (x <= 0) return 0;
if (n == 1) return x/(c+r);
if (r == 0) return pow(x/c,1/n);
Float y = x/(c+r);
const Float tol = numeric_limits<Float>::epsilon();
for (size_t i = 0; true; ++i) {
Float ry = f(y)-x;
Float dy = -ry/df_dy(y);
if (fabs(ry) <= tol && fabs(dy) <= tol) break;
if (i >= max_iter) break;
if (y+dy > 0) {
y += dy;
} else {
y /= 2;
check_macro (1+y != y, "phi: machine precision problem");
}
}
return y;
}
Float derivative (const Float& x) const {
Float phi_x = operator()(x);
return 1/(r + n*c*pow(phi_x,-1+n));
}
protected:
Float f(Float y) const { return c*pow(y,n) + r*y; }
Float df_dy(Float y) const { return n*c*pow(y,-1+n) + r; }
Float n,c,r;
static const size_t max_iter = 100;
};
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