19#ifndef _GIMLI_NUMERICBASE__H
20#define _GIMLI_NUMERICBASE__H
28 #define PI 3.141592653589793238462643383279502884197169399375105820974944592308
29 #define PI2 6.2831853071795864769252867665590057683942387987502116419498891846
30 #define PI_2 1.5707963267948967384626433682795028841971193993751058209749445923
33template <
class ValueType > ValueType round(
const ValueType & v, ValueType tol){ return ::rint(v / tol) * tol; }
36DLLEXPORT RVector
logTransDropTol(
const RVector & data,
double logdrop=1e-6,
41DLLEXPORT RVector
logDropTol(
const RVector & data,
double logdrop=1e-6,
45template <
class ValueType > ValueType
degToRad(
const ValueType & deg){
return deg * (2.0 * PI) / 360.0; }
48template <
class ValueType > ValueType
radToDeg(
const ValueType & rad){
return rad * 360.0 / (2.0 * PI); }
50template <
class T > T powInt(
const T & a, uint dim){
55 case 3 :
return a*a*a;
56 case 4 :
return a*a*a*a;
57 case 5 :
return a*a*a*a*a;
58 case 6 :
return a*a*a*a*a*a;
59 default:
return (T)std::pow((
float)a, (
float)dim);
68DLLEXPORT
void GaussLegendre(
double x1,
double x2, uint n, RVector &
x, RVector & w);
80template <
class ValueType > ValueType
besselI0(
const ValueType &
x) {
81 ValueType ax = std::fabs(
x), result = 0.0,
y = 0.0;
84 y =
x / 3.75,
y =
y *
y ;
85 result = 1.0 +
y * (3.5156229 +
90 +
y * 0.45813e-2)))));
93 result = (std::exp(ax) / std::sqrt(ax)) * (0.39894228 +
101 y * 0.392377e-2))))))));
109template <
class ValueType > ValueType
besselI1(
const ValueType &
x) {
110 ValueType ax = std::fabs(
x), result = 0.0,
y = 0.0;
113 y =
x / 3.75,
y =
y *
y;
120 y * 0.32411e-3))))));
123 result = 0.2282967e-1 +
y * (-0.2895312e-1 +
y * (0.1787654e-1 -
y * 0.420059e-2));
124 result = 0.39894228 +
y * (-0.3988024e-1 +
y * (-0.362018e-2 +
125 y * (0.163801e-2 +
y * (-0.1031555e-1 +
y * result)))) ;
126 result *= (std::exp(ax) / std::sqrt(ax));
128 return x < 0.0 ? -result : result;
135template <
class ValueType > ValueType
besselK0(
const ValueType &
x){
136 ValueType
y = 0.0, result = 0.0;
140 result = (-std::log(
x / 2.0) *
besselI0(
x)) + (-0.57721566
149 result = (std::exp(-
x) / std::sqrt(
x)) * (1.25331414
150 +
y * (-0.7832358e-1 +
y * (0.2189568e-1 +
y * (-0.1062446e-1 +
y * (0.587872e-2
152 +
y * 0.53208e-3))))));
160template <
class ValueType > ValueType
besselK1(
const ValueType &
x){
161 ValueType
y = 0.0, result = 0.0;
166 (1.0 /
x) * (1.0 +
y * (0.15443144 +
y * (-0.67278579 +
y * (-0.18156897 +
169 y * (-0.4686e-4))))))) ;
172 result = (std::exp(-
x) / std::sqrt(
x)) * (1.25331414 +
y * (0.23498619 +
177 y * (-0.68245e-3)))))));
219 RVector3 & dg, RVector3 & dgz);
GIMLi main namespace for the Geophyiscal Inversion and Modelling Library.
Definition baseentity.h:24
ValueType degToRad(const ValueType °)
Definition numericbase.h:45
RVector logDropTol(const RVector &data, double logdrop, bool normalize)
Definition numericbase.cpp:25
void GaussLegendre(double x1, double x2, uint n, RVector &x, RVector &w)
Definition numericbase.cpp:102
RVector y(const R3Vector &rv)
Definition pos.cpp:114
RVector x(const R3Vector &rv)
Definition pos.cpp:107
ValueType besselI1(const ValueType &x)
Caluculate modified Bessel function of the first kind.
Definition numericbase.h:109
ValueType besselI0(const ValueType &x)
Caluculate modified Bessel function of the first kind.
Definition numericbase.h:80
ValueType besselK0(const ValueType &x)
Caluculate modified Bessel function of the second kind.
Definition numericbase.h:135
void lineIntegralZ_WonBevis(const RVector3 &p1, const RVector3 &p2, RVector3 &dg, RVector3 &dgz)
Definition numericbase.cpp:172
ValueType besselK1(const ValueType &x)
Caluculate modified Bessel function of the second kind.
Definition numericbase.h:160
RVector3 sphTangential2Initerial(const RVector3 &V, double lat, double lon)
Definition numericbase.cpp:158
ValueType radToDeg(const ValueType &rad)
Definition numericbase.h:48
void GaussLaguerre(uint n, RVector &x, RVector &w)
Definition numericbase.cpp:51
RVector logTransDropTol(const RVector &data, double logdrop, bool normalize)
Definition numericbase.cpp:47