52 #define M_PI 3.1415926535897932384626433832795029L 55 #define M_LN2 0.6931471805599453094172321214581766L 59 inline int min(
int i,
int j)
60 {
return ( i <= j ? i : j ); }
63 inline long min(
long i,
long j)
64 {
return ( i <= j ? i : j ); }
67 inline double min(
double i,
double j)
68 {
return ( i <= j ? i : j ); }
71 inline int max(
int i,
int j)
72 {
return ( i >= j ? i : j ); }
75 inline double clamp(
int a,
int lower,
int upper)
76 {
return ( a <= lower ? lower : ( a >= upper ? upper : a ) ); }
79 inline long max(
long i,
long j)
80 {
return ( i >= j ? i : j ); }
83 inline double max(
double i,
double j)
84 {
return ( i >= j ? i : j ); }
87 inline double clamp(
double a,
double lower,
double upper)
88 {
return ( a <= lower ? lower : ( a >= upper ? upper : a ) ); }
91 inline double sgn(
double i)
92 {
return ( i < 0. ? -1. : 1. ); }
99 inline bool isnan(
double x) {
return _isnan(x) != 0; }
108 inline double cbrt(
double x) {
return sgn(x) * pow(fabs(x), 1.0 / 3.0); }
112 inline double sqr(
double x) {
return x * x; }
115 inline double macbra(
double x) {
return ( x >= 0 ? x : 0 ); }
117 inline double negbra(
double x) {
return ( x <= 0 ? x : 0 ); }
131 void cubic(
double a,
double b,
double c,
double d,
double *r1,
double *r2,
double *r3,
int *num);
149 void cubic3r(
double a,
double b,
double c,
double d,
double *r1,
double *r2,
double *r3,
int *num);
154 int iperm(
int val,
int rank);
157 #define MATHFEM_C 0.38196601 158 #define MATHFEM_R ( 1 - MATHFEM_C ) 159 #define MATHFEM_BRENT_MAXITER 100 163 double ( T :: *
pmf )(double);
166 mem_fun( T * o,
double ( T :: *p )(
double) ) :
pmf(p), ptr(o) { }
173 double ( * func )(double);
175 c_fun(
double ( * p )(
double) ) : func(p) { }
176 double operator() (
double x)
const {
return ( * func )( x ); }
195 template<
class T >
double gss(
double ax,
double bx,
double cx,
const T &f,
196 double tol,
double &xmin)
199 double f1, f2, x0, x1, x2, x3;
205 if ( fabs(cx - bx) > fabs(bx - ax) ) {
217 while ( fabs(x3 - x0) > tol * ( fabs(x1) + fabs(x2) ) ) {
249 template<
class T >
double brent(
double ax,
double bx,
double cx,
const T &f,
250 double tol,
double &xmin)
253 double x_left = ax, x_right = cx;
254 double x, x_midpoint, v, w, u, tol1, tol2, p, q, r, e_tmp, d = 0.0, fx, fv, fw, fu;
261 x_midpoint = 0.5 * ( x_left + x_right );
264 tol1 = tol * fabs(x) + 1.0e-10;
266 if ( fabs(x - x_midpoint) <= ( tol2 - 0.5 * ( x_right - x_left ) ) ) {
272 if ( fabs(e) > tol1 ) {
274 r = ( x - w ) * ( fx - fv );
275 q = ( x - v ) * ( fx - fw );
276 p = ( x - v ) * q - ( x - w ) * r;
288 if ( fabs(p) < fabs(0.5 * q * e_tmp) && p < q * ( x - x_left ) && p < q * ( x_right - x ) ) {
291 if ( ( u - x_left ) < tol2 || ( x_right - u ) < tol2 ) {
292 d = ( x < x_midpoint ) ? tol1 : -tol1;
295 e = ( x < x_midpoint ) ? x_right - x : -( x - x_left );
299 e = ( x < x_midpoint ) ? x_right - x : -( x - x_left );
303 if ( fabs(d) >= tol1 ) {
306 u = x + ( ( d > 0 ) ? tol1 : -tol1 );
331 if ( fu <= fw || w == x ) {
336 }
else if ( fu <= fv || v == x || v == w ) {
mem_fun(T *o, double(T::*p)(double))
int max(int i, int j)
Returns bigger value form two given decimals.
double sgn(double i)
Returns the signum of given value (if value is < 0 returns -1, otherwise returns 1) ...
#define MATHFEM_BRENT_MAXITER
double macbra(double x)
Returns the positive part of given float.
void cubic(double a, double b, double c, double d, double *r1, double *r2, double *r3, int *num)
Solves cubic equation for real roots.
#define OOFEM_LOG_WARNING(...)
void cubic3r(double a, double b, double c, double d, double *r1, double *r2, double *r3, int *num)
Solves cubic equation for real roots, assuming that if cubic polynomial given then the only possibili...
int iperm(int val, int rank)
Returns iperm of val, in specific rank.
double brent(double ax, double bx, double cx, const T &f, double tol, double &xmin)
c_fun(double(*p)(double))
void ls2fit(const FloatArray &x, const FloatArray &y, FloatArray &a)
Least-square fit of 2nd degree polynomial .
Class representing vector of real numbers.
double clamp(int a, int lower, int upper)
Returns the clamped value of a between upper and lower.
double cbrt(double x)
Returns the cubic root of x.
double operator()(double x) const
double signum(double i)
Returns the signum of given value (i = 0 returns 0, i < 0 returns -1, i > 0 returns 1) ...
int min(int i, int j)
Returns smaller value from two given decimals.
the oofem namespace is to define a context or scope in which all oofem names are defined.
double negbra(double x)
Returns the negative part of given float.
double gss(double ax, double bx, double cx, const T &f, double tol, double &xmin)
Minimize function of one variable using golden section search.