/* spherical_deriv.c check numerical calculation of derivatives */ /* in spherical coordinates. */ /* data structure rtp[][][] field values at radius, theta and phi */ /* rval[] values of r at index 0, 1, ..., nr-1 */ /* tval[] values of theta -Pi, -Pi+dt, ... Pi-dt */ /* pval[] values of phi =pi/2, -Pi/2+dp, ,,, */ /* */ /* method, use nuderiv to compute numerical derivatives */ /* u(r,t,p) = */ /* du/dr = analytic */ /* du/dt = analytic */ /* du/dp = analytic */ #include #include #include "nuderiv.h" #define Pi 3.14159265358979323846 #define nr 7 #define nt 16 #define np 12 static double rtp[nr][nt][np]; static double rval[nr] = { 0.25, 0.5, 0.75, 1.0 , 1.25, 1.5, 1.75}; static double tval[nt]; /* computed below */ static double pval[np]; static double rcoef[nr]; static double tcoef[nt]; static double pcoef[np]; double u(double r, double t, double p) { return 1.0/((r*r+0.1) * ((t-Pi/4.0)*(t-Pi/4.0)+0.2) * ((p-Pi/8.0)*(p-Pi/8.0)+0.3) ); } double dudr(double r, double t, double p) { return -(2.0*r)/((r*r+0.1)*(r*r+0.1) * ((t-Pi/4.0)*(t-Pi/4.0)+0.2) * ((p-Pi/8.0)*(p-Pi/8.0)+0.3) ); } double dudt(double r, double t, double p) { return -(2.0*t-Pi/2.0)/((r*r+0.1) * ((t-Pi/4.0)*(t-Pi/4.0)+0.2) * ((t-Pi/4.0)*(t-Pi/4.0)+0.2) * ((p-Pi/8.0)*(p-Pi/8.0)+0.3)); } double dudp(double r, double t, double p) { return -(2.0*p-Pi/4.0)/((r*r+0.1) * ((t-Pi/4.0)*(t-Pi/4.0)+0.2) * ((p-Pi/8.0)*(p-Pi/8.0)+0.3) * ((p-Pi/8.0)*(p-Pi/8.0)+0.3)); } int main(int argc, char * argv[]) { int i, j, k, m; int mm, mb; double rd, td, pd; double drc, dtc, dpc; printf("spherical_deriv.c checking numerical derivatives \n"); for(i=0; i