#include "sopnamsp.h" #include "machdefs.h" #include #include #include #include #include #include "pexceptions.h" #include "integfunc.h" static unsigned short IntegrateFunc_GlOrder = 0; static vector IntegrateFunc_x; static vector IntegrateFunc_w; /////////////////////////////////////////////////////////// //************** Integration of Functions ***************// /////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// double IntegrateFunc(GenericFunc& func,double xmin,double xmax ,double perc,double dxinc,double dxmax,unsigned short glorder) // --- Integration adaptative --- // Integrate[func[x], {x,xmin,xmax}] // ..xmin,xmax are the integration limits // ..dxinc is the searching increment x = xmin+i*dxinc // if <0 npt = int(|dxinc|) (si<2 alors npt=100) // et dxinc = (xmax-xmin)/npt // ..dxmax is the maximum possible increment (if dxmax<=0 no test) // --- // Partition de [xmin,xmax] en intervalles [x(i),x(i+1)]: // on parcourt [xmin,xmax] par pas de "dxinc" : x(i) = xmin + i*dxinc // on cree un intervalle [x(i),x(i+1)] // - si |f[x(i+1)] - f[x(i)]| > perc*|f[[x(i)]| // - si |x(i+1)-x(i)| >= dxmax (si dxmax>0.) // Dans un intervalle [x(i),x(i+1)] la fonction est integree // avec une methode de gauss-legendre d'ordre "glorder" { double signe = 1.; if(xmin>xmax) {double tmp=xmax; xmax=xmin; xmin=tmp; signe=-1.;} if(glorder==0) glorder = 4; if(perc<=0.) perc=0.1; if(dxinc<=0.) {int n=int(-dxinc); if(n<2) n=100; dxinc=(xmax-xmin)/n;} if(glorder != IntegrateFunc_GlOrder) { IntegrateFunc_GlOrder = glorder; Compute_GaussLeg(glorder,IntegrateFunc_x,IntegrateFunc_w,0.,1.); } // Recherche des intervalles [x(i),x(i+1)] int_4 ninter = 0; double sum = 0., xbas=xmin, fbas=func(xbas), fabsfbas=fabs(fbas); for(double x=xmin+dxinc; xxmax ) {doit = true; x=xmax;} else if( dxmax>0. && dx>dxmax ) doit = true; else if( fabs(f-fbas)>perc*fabsfbas ) doit = true; if( ! doit ) continue; double s = 0.; for(unsigned short i=0;ilxmax) {double tmp=lxmax; lxmax=lxmin; lxmin=tmp; signe=-1.;} if(glorder==0) glorder = 4; if(perc<=0.) perc=0.1; if(dlxinc<=0.) {int n=int(-dlxinc); if(n<2) n=100; dlxinc=(lxmax-lxmin)/n;} if(glorder != IntegrateFunc_GlOrder) { IntegrateFunc_GlOrder = glorder; Compute_GaussLeg(glorder,IntegrateFunc_x,IntegrateFunc_w,0.,1.); } // Recherche des intervalles [lx(i),lx(i+1)] int_4 ninter = 0; double sum = 0., lxbas=lxmin, fbas=func(pow(10.,lxbas)), fabsfbas=fabs(fbas); for(double lx=lxmin+dlxinc; lxlxmax ) {doit = true; lx=lxmax;} else if( dlxmax>0. && dlx>dlxmax ) doit = true; else if( fabs(f-fbas)>perc*fabsfbas ) doit = true; if( ! doit ) continue; double s = 0.; for(unsigned short i=0;i