Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
phi.h

The Mossolov problem – the phi function.

The Mossolov problem – the phi function

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; }
static const size_t max_iter = 100;
};
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)")
Definition cavity_dg.h:29
Definition phi.h:25
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 df_dy(Float y) const
Definition phi.h:53
Float operator()(const Float &x) const
Definition phi.h:27