#include "DMaterialMap.h" #include #include #include // Locate a position in array xx given x static void locate(const double *xx,int n,double x,int *j){ int ju,jm,jl; int ascnd; jl=-1; ju=n; ascnd=(xx[n-1]>=xx[0]); while(ju-jl>1){ jm=(ju+jl)>>1; if (x>=xx[jm]==ascnd) jl=jm; else ju=jm; } if (x==xx[0]) *j=0; else if (x==xx[n-1]) *j=n-2; else *j=jl; } // Polynomial interpolation on a grid. // Adapted from Numerical Recipes in C (2nd Edition), pp. 121-122. static void polint(const double *xa, const double *ya,int n,double x, double *y, double *dy){ int i,m,ns=0; double den,dif,dift,ho,hp,w; double *c=(double *)calloc(n,sizeof(double)); double *d=(double *)calloc(n,sizeof(double)); dif=fabs(x-xa[0]); for (i=0;i0){ imin1=((ind+3)>NUM_Z_POINTS)?NUM_Z_POINTS-4:(ind-1); } else imin1=0; if (ind2>0){ imin2=((ind2+3)>NUM_X_POINTS)?NUM_X_POINTS-4:(ind2-1); } else imin2=0; //---- density ---- // First do the interpolation in the z direction for (int j=imin2;j0){ imin=((ind+3)>NUM_Z_POINTS)?NUM_Z_POINTS-4:(ind-1); } else imin=0; for (int j=0;j0){ imin=((ind2+3)>NUM_X_POINTS)?NUM_X_POINTS-4:(ind2-1); } else imin=0; double fX0; polint(&material_x[imin],&temp[imin],4,r,&fX0,&err); return 1.e5/fX0; }