Changeset 758 for sans/XOP_Dev/MonteCarlo
- Timestamp:
- Oct 26, 2010 3:32:14 PM (12 years ago)
- Location:
- sans/XOP_Dev/MonteCarlo
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/XOP_Dev/MonteCarlo/DebyeSpheres.c
r623 r758 22 22 using Debye's method. 23 23 24 Warning: 25 The call to WaveData() below returns a pointer to the middle 26 of an unlocked Macintosh handle. In the unlikely event that your 27 calculations could cause memory to move, you should copy the coefficient 28 values to local variables or an array before such operations. 24 everything was previously declared as float, some inputs were as double. 25 26 -- to avoid confusion, calculate everything in double, pass everything in as double 27 -- this is more precision than is necessary, but avoids strange results from type casting 28 behind the scenes 29 29 */ 30 30 int 31 31 DebyeSpheresX(AltiParamsPtr p) 32 32 { 33 floatqv; // input q-value34 floatival; //output intensity value35 float*xv,*yv,*zv,*rv; //pointers to input xyz-rho coordinates33 double qv; // input q-value 34 double ival; //output intensity value 35 double *xv,*yv,*zv,*rv; //pointers to input xyz-rho coordinates 36 36 int i,j; 37 37 int npt; 38 floatrval,grid,vol,fQR,dum,dij;38 double rval,grid,vol,fQR,dum,dij; 39 39 40 40 … … 60 60 61 61 //check to see that all are float, not double 62 /* 62 63 if(WaveType(p->rhowavH) != NT_FP32 ) { 63 64 SetNaN64(&p->result); … … 76 77 return kExpectedNT_FP32; 77 78 } 78 79 */ 79 80 80 // convert the input to float. Do all calculations as float. 81 82 rval = (float) p->Rprimary; // primary sphere radius 83 grid = (float) p->grid; // calling program should set this to 0.62*Rprimary 84 qv = (float) p->qval; 81 //check to see that all are double 82 if(WaveType(p->rhowavH) != NT_FP64 ) { 83 SetNaN64(&p->result); 84 return kExpectedNT_FP64; 85 } 86 if(WaveType(p->zwavH) != NT_FP64 ) { 87 SetNaN64(&p->result); 88 return kExpectedNT_FP64; 89 } 90 if(WaveType(p->ywavH) != NT_FP64 ) { 91 SetNaN64(&p->result); 92 return kExpectedNT_FP64; 93 } 94 if(WaveType(p->xwavH) != NT_FP64 ) { 95 SetNaN64(&p->result); 96 return kExpectedNT_FP64; 97 } 98 99 100 // (NO) -- convert the input to float. Do all calculations as float. 101 // do everything in double. no reason to do in float, except for the previous Altivec incarnation 102 103 rval = p->Rprimary; // primary sphere radius 104 grid = p->grid; // calling program should set this to 0.62*Rprimary 105 qv = p->qval; 85 106 86 107 // … … 109 130 } 110 131 111 p->result = (DOUBLE)ival;132 p->result = ival; 112 133 113 134 return 0; … … 116 137 117 138 118 float PhiQR(float qval, floatrval)139 double PhiQR(double qval, double rval) 119 140 { 120 floatretval,qr;141 double retval,qr; 121 142 122 143 qr = qval*rval; 123 retval = ( float) (3*(sin(qr) - qr*cos(qr))/qr/qr/qr );144 retval = ( 3*(sin(qr) - qr*cos(qr))/qr/qr/qr ); 124 145 return(retval); 125 146 } 126 147 127 float XYZDistance(float x1, float x2,float y1, float y2,float z1, floatz2)148 double XYZDistance(double x1, double x2,double y1, double y2,double z1, double z2) 128 149 { 129 floatretval,dx,dy,dz;150 double retval,dx,dy,dz; 130 151 131 152 dx = (x1-x2); 132 153 dy = (y1-y2); 133 154 dz = (z1-z2); 134 retval = (float)sqrt( dx*dx + dy*dy + dz*dz );155 retval = sqrt( dx*dx + dy*dy + dz*dz ); 135 156 return(retval); 136 157 } -
sans/XOP_Dev/MonteCarlo/DebyeSpheres.h
r674 r758 12 12 // result is the last parameter, always. 13 13 typedef struct AltiParams { 14 DOUBLEgrid; // effective c-to-c distance between spheres = 0.62*Rprimary15 DOUBLERprimary; //primary sphere radius14 double grid; // effective c-to-c distance between spheres = 0.62*Rprimary 15 double Rprimary; //primary sphere radius 16 16 waveHndl rhowavH; // rho at xyz!!! 17 17 waveHndl zwavH; // z coordinate. ALL are expected to be SP waves 18 18 waveHndl ywavH; // y coordinate. 19 19 waveHndl xwavH; // x coordinate. 20 DOUBLEqval; // q-value.20 double qval; // q-value. 21 21 void* tp; //unused void for threadsafe functions 22 DOUBLEresult;22 double result; 23 23 }AltiParams, *AltiParamsPtr; 24 24 25 25 26 float PhiQR(float qval, floatrval);27 float XYZDistance(float x1, float x2,float y1, float y2,float z1, floatz2);26 double PhiQR(double qval, double rval); 27 double XYZDistance(double x1, double x2,double y1, double y2,double z1, double z2); 28 28 int DebyeSpheresX(AltiParamsPtr p); -
sans/XOP_Dev/MonteCarlo/MonteCarlo.h
r623 r758 54 54 int Monte_SANSX3(MC_ParamsPtr p); 55 55 int Monte_SANSX4(MC_ParamsPtr p); 56 57 long MC_round(double x); 56 58 int FindPixel(double testQ, double testPhi, double lam, double sdd, double pixSize, double xCtr, double yCtr, long *xPixel, long *yPixel); 57 59 int NewDirection(double *vx, double *vy, double *vz, double theta, double phi); -
sans/XOP_Dev/MonteCarlo/MonteCarlo.r
r673 r758 68 68 { 69 69 NT_FP64, /* single precision wave (q-wave) */ 70 NT_FP 32+ WAVE_TYPE, /* single precision wave (x coordinates) */71 NT_FP 32+ WAVE_TYPE, /* single precision wave (y coordinates) */72 NT_FP 32+ WAVE_TYPE, /* single precision wave (z coordinates) */73 NT_FP 32+ WAVE_TYPE, /* single precision wave (rho at xyz) */70 NT_FP64 + WAVE_TYPE, /* single precision wave (x coordinates) */ 71 NT_FP64 + WAVE_TYPE, /* single precision wave (y coordinates) */ 72 NT_FP64 + WAVE_TYPE, /* single precision wave (z coordinates) */ 73 NT_FP64 + WAVE_TYPE, /* single precision wave (rho at xyz) */ 74 74 NT_FP64, // Rprimary, the primary sphere radius 75 75 NT_FP64, // grid, should be passed as 0.62*Rprimary -
sans/XOP_Dev/MonteCarlo/MonteCarlo_Main.c
r711 r758 16 16 #include "DebyeSpheres.h" 17 17 18 19 // this function is here simply because MS visual studio does not contain lround() or round() in math.h 20 // rounds away from zero 21 // -- only used in FindPixel 22 long MC_round(double x) 23 { 24 if(x == 0) { 25 return (long)(0); 26 } 27 if(x > 0) { 28 return (long)(x + 0.5f); 29 } else { // x < 0 30 return (long)(x - 0.5f); 31 } 32 } 33 34 18 35 int 19 36 FindPixel(double testQ, double testPhi, double lam, double sdd, … … 29 46 theta = 2.0*asin(qy*lam/4.0/pi); 30 47 dy = sdd*tan(theta); 31 *yPixel = lround(yCtr + dy/pixSize); //corrected 7/2010 to round away from zero, to avoid 2x counts in row 0 and column 0 48 // *yPixel = lround(yCtr + dy/pixSize); //corrected 7/2010 to round away from zero, to avoid 2x counts in row 0 and column 0 49 *yPixel = MC_round(yCtr + dy/pixSize); //corrected 7/2010 to round away from zero, to avoid 2x counts in row 0 and column 0 32 50 33 51 theta = 2.0*asin(qx*lam/4.0/pi); 34 52 dx = sdd*tan(theta); 35 *xPixel = lround(xCtr + dx/pixSize); 53 // *xPixel = lround(xCtr + dx/pixSize); 54 *xPixel = MC_round(xCtr + dx/pixSize); 36 55 37 56 //if on detector, return xPix and yPix values, otherwise -1
Note: See TracChangeset
for help on using the changeset viewer.