Changeset df88829 in sasview for sansmodels
- Timestamp:
- Jan 4, 2012 6:23:43 PM (13 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- c637521
- Parents:
- 8343e18
- Location:
- sansmodels/src
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/c_extensions/csparallelepiped.h
r67424cd rdf88829 5 5 #if !defined(csparallelepiped_h) 6 6 #define csparallelepiped_h 7 #include "parameters.hh" 7 8 /** Structure definition for CSParallelepiped parameters 8 9 * [PYTHONCLASS] = CSParallelepipedModel … … 28 29 29 30 **/ 30 typedef struct {31 /// Scale factor32 // [DEFAULT]=scale=1.033 double scale;34 /// Length of short edge of the parallelepiped [A]35 // [DEFAULT]=shortA=35 [A]36 double shortA;37 /// Length of mid edge of the parallelepiped [A]38 // [DEFAULT]=midB=75 [A]39 double midB;40 /// Length of long edge of the parallelepiped [A]41 // [DEFAULT]=longC=400 [A]42 double longC;43 /// Thickness of rimA [A]44 // [DEFAULT]=rimA=10 [A]45 double rimA;46 /// Thickness of rimB [A] [A]47 // [DEFAULT]=rimB=10 [A]48 double rimB;49 /// Thickness of rimC [A] [A]50 // [DEFAULT]=rimC=10 [A]51 double rimC;52 /// SLD_rimA [1/A^(2)]53 // [DEFAULT]=sld_rimA=2e-6 [1/A^(2)]54 double sld_rimA;55 /// SLD_rimB [1/A^(2)]56 // [DEFAULT]=sld_rimB=4e-6 [1/A^(2)]57 double sld_rimB;58 /// SLD_rimC [1/A^(2)]59 // [DEFAULT]=sld_rimC=2e-6 [1/A^(2)]60 double sld_rimC;61 /// SLD_pcore [1/A^(2)]62 // [DEFAULT]=sld_pcore=1e-6 [1/A^(2)]63 double sld_pcore;64 /// sld_solv [1/A^(2)]65 // [DEFAULT]=sld_solv=6e-6 [1/A^(2)]66 double sld_solv;67 /// Incoherent Background [1/cm]68 // [DEFAULT]=background=0.06 [1/cm]69 double background;70 /// Orientation of the parallelepiped axis w/respect incoming beam [deg]71 // [DEFAULT]=parallel_theta=0.0 [deg]72 double parallel_theta;73 /// Orientation of the longitudinal axis of the parallelepiped in the plane of the detector [deg]74 // [DEFAULT]=parallel_phi=0.0 [deg]75 double parallel_phi;76 /// Orientation of the cross-sectional minor axis of the parallelepiped in the plane of the detector [deg]77 // [DEFAULT]=parallel_psi=0.0 [deg]78 double parallel_psi;79 31 32 class CSParallelepipedModel{ 33 public: 34 // Model parameters 35 /// Scale factor 36 // [DEFAULT]=scale=1.0 37 Parameter scale; 38 /// Length of short edge of the parallelepiped [A] 39 // [DEFAULT]=shortA=35 [A] 40 Parameter shortA; 41 /// Length of mid edge of the parallelepiped [A] 42 // [DEFAULT]=midB=75 [A] 43 Parameter midB; 44 /// Length of long edge of the parallelepiped [A] 45 // [DEFAULT]=longC=400 [A] 46 Parameter longC; 47 /// Thickness of rimA [A] 48 // [DEFAULT]=rimA=10 [A] 49 Parameter rimA; 50 /// Thickness of rimB [A] [A] 51 // [DEFAULT]=rimB=10 [A] 52 Parameter rimB; 53 /// Thickness of rimC [A] [A] 54 // [DEFAULT]=rimC=10 [A] 55 Parameter rimC; 56 /// SLD_rimA [1/A^(2)] 57 // [DEFAULT]=sld_rimA=2e-6 [1/A^(2)] 58 Parameter sld_rimA; 59 /// SLD_rimB [1/A^(2)] 60 // [DEFAULT]=sld_rimB=4e-6 [1/A^(2)] 61 Parameter sld_rimB; 62 /// SLD_rimC [1/A^(2)] 63 // [DEFAULT]=sld_rimC=2e-6 [1/A^(2)] 64 Parameter sld_rimC; 65 /// SLD_pcore [1/A^(2)] 66 // [DEFAULT]=sld_pcore=1e-6 [1/A^(2)] 67 Parameter sld_pcore; 68 /// sld_solv [1/A^(2)] 69 // [DEFAULT]=sld_solv=6e-6 [1/A^(2)] 70 Parameter sld_solv; 71 /// Incoherent Background [1/cm] 72 // [DEFAULT]=background=0.06 [1/cm] 73 Parameter background; 74 /// Orientation of the parallelepiped axis w/respect incoming beam [deg] 75 // [DEFAULT]=parallel_theta=0.0 [deg] 76 Parameter parallel_theta; 77 /// Orientation of the longitudinal axis of the parallelepiped in the plane of the detector [deg] 78 // [DEFAULT]=parallel_phi=0.0 [deg] 79 Parameter parallel_phi; 80 /// Orientation of the cross-sectional minor axis of the parallelepiped in the plane of the detector [deg] 81 // [DEFAULT]=parallel_psi=0.0 [deg] 82 Parameter parallel_psi; 80 83 81 } CSParallelepipedParameters; 84 // Constructor 85 CSParallelepipedModel(); 82 86 87 // Operators to get I(Q) 88 double operator()(double q); 89 double operator()(double qx, double qy); 90 double calculate_ER(); 91 double evaluate_rphi(double q, double phi); 92 }; 83 93 84 85 /// 1D scattering function86 double csparallelepiped_analytical_1D(CSParallelepipedParameters *pars, double q);87 88 /// 2D scattering function89 double csparallelepiped_analytical_2D(CSParallelepipedParameters *pars, double q, double phi);90 double csparallelepiped_analytical_2DXY(CSParallelepipedParameters *pars, double qx, double qy);91 double csparallelepiped_analytical_2D_scaled(CSParallelepipedParameters *pars, double q, double q_x, double q_y);92 94 #endif -
sansmodels/src/c_models/csparallelepiped.cpp
r67424cd rdf88829 30 30 #include "csparallelepiped.h" 31 31 } 32 33 // Convenience parameter structure 34 typedef struct { 35 double scale; 36 double shortA; 37 double midB; 38 double longC; 39 double rimA; 40 double rimB; 41 double rimC; 42 double sld_rimA; 43 double sld_rimB; 44 double sld_rimC; 45 double sld_pcore; 46 double sld_solv; 47 double background; 48 double parallel_theta; 49 double parallel_phi; 50 double parallel_psi; 51 } CSParallelepipedParameters; 52 53 static double cspkernel(double dp[],double q, double ala, double alb, double alc){ 54 // mu passed in is really mu*sqrt(1-sig^2) 55 double argA,argB,argC,argtA,argtB,argtC,tmp1,tmp2,tmp3,tmpt1,tmpt2,tmpt3; //local variables 56 57 double aa,bb,cc, ta,tb,tc; 58 double Vin,Vot,V1,V2,V3; 59 double rhoA,rhoB,rhoC, rhoP, rhosolv; 60 double dr0, drA,drB, drC; 61 double retVal; 62 63 aa = dp[1]; 64 bb = dp[2]; 65 cc = dp[3]; 66 ta = dp[4]; 67 tb = dp[5]; 68 tc = dp[6]; 69 rhoA=dp[7]; 70 rhoB=dp[8]; 71 rhoC=dp[9]; 72 rhoP=dp[10]; 73 rhosolv=dp[11]; 74 dr0=rhoP-rhosolv; 75 drA=rhoA-rhosolv; 76 drB=rhoB-rhosolv; 77 drC=rhoC-rhosolv; 78 Vin=(aa*bb*cc); 79 Vot=(aa*bb*cc+2.0*ta*bb*cc+2.0*aa*tb*cc+2.0*aa*bb*tc); 80 V1=(2.0*ta*bb*cc); // incorrect V1 (aa*bb*cc+2*ta*bb*cc) 81 V2=(2.0*aa*tb*cc); // incorrect V2(aa*bb*cc+2*aa*tb*cc) 82 V3=(2.0*aa*bb*tc); 83 //aa = aa/bb; 84 ta=(aa+2.0*ta);///bb; 85 tb=(aa+2.0*tb);///bb; 86 tc=(aa+2.0*tc); 87 //handle arg=0 separately, as sin(t)/t -> 1 as t->0 88 argA = q*aa*ala/2.0; 89 argB = q*bb*alb/2.0; 90 argC = q*cc*alc/2.0; 91 argtA = q*ta*ala/2.0; 92 argtB = q*tb*alb/2.0; 93 argtC = q*tc*alc/2.0; 94 95 if(argA==0.0) { 96 tmp1 = 1.0; 97 } else { 98 tmp1 = sin(argA)/argA; 99 } 100 if (argB==0.0) { 101 tmp2 = 1.0; 102 } else { 103 tmp2 = sin(argB)/argB; 104 } 105 106 if (argC==0.0) { 107 tmp3 = 1.0; 108 } else { 109 tmp3 = sin(argC)/argC; 110 } 111 if(argtA==0.0) { 112 tmpt1 = 1.0; 113 } else { 114 tmpt1 = sin(argtA)/argtA; 115 } 116 if (argtB==0.0) { 117 tmpt2 = 1.0; 118 } else { 119 tmpt2 = sin(argtB)/argtB; 120 } 121 if (argtC==0.0) { 122 tmpt3 = 1.0; 123 } else { 124 tmpt3 = sin(argtC)*sin(argtC)/argtC/argtC; 125 } 126 // This expression is different from NIST/IGOR package (I strongly believe the IGOR is wrong!!!). 10/15/2010. 127 retVal =( dr0*tmp1*tmp2*tmp3*Vin + drA*(tmpt1-tmp1)*tmp2*tmp3*V1+ drB*tmp1*(tmpt2-tmp2)*tmp3*V2 + drC*tmp1*tmp2*(tmpt3-tmp3)*V3)* 128 ( dr0*tmp1*tmp2*tmp3*Vin + drA*(tmpt1-tmp1)*tmp2*tmp3*V1+ drB*tmp1*(tmpt2-tmp2)*tmp3*V2 + drC*tmp1*tmp2*(tmpt3-tmp3)*V3); // correct FF : square of sum of phase factors 129 //retVal *= (tmp3*tmp3); 130 retVal /= Vot; 131 132 return (retVal); 133 134 }//Function cspkernel() 135 136 /** 137 * Function to evaluate 2D scattering function 138 * @param pars: parameters of the CSparallelepiped 139 * @param q: q-value 140 * @param q_x: q_x / q 141 * @param q_y: q_y / q 142 * @return: function value 143 */ 144 static double csparallelepiped_analytical_2D_scaled(CSParallelepipedParameters *pars, double q, double q_x, double q_y) { 145 double dp[13]; 146 double cparallel_x, cparallel_y, cparallel_z, bparallel_x, bparallel_y, parallel_x, parallel_y; 147 double q_z; 148 double alpha, cos_val_c, cos_val_b, cos_val_a, edgeA, edgeB, edgeC; 149 150 double answer; 151 //convert angle degree to radian 152 double pi = 4.0*atan(1.0); 153 double theta = pars->parallel_theta * pi/180.0; 154 double phi = pars->parallel_phi * pi/180.0; 155 double psi = pars->parallel_psi* pi/180.0; 156 157 // Fill paramater array 158 dp[0] = 1.0; 159 dp[1] = pars->shortA; 160 dp[2] = pars->midB; 161 dp[3] = pars->longC; 162 dp[4] = pars->rimA; 163 dp[5] = pars->rimB; 164 dp[6] = pars->rimC; 165 dp[7] = pars->sld_rimA; 166 dp[8] = pars->sld_rimB; 167 dp[9] = pars->sld_rimC; 168 dp[10] = pars->sld_pcore; 169 dp[11] = pars->sld_solv; 170 dp[12] = 0.0; 171 172 173 edgeA = pars->shortA; 174 edgeB = pars->midB; 175 edgeC = pars->longC; 176 177 178 // parallelepiped c axis orientation 179 cparallel_x = sin(theta) * cos(phi); 180 cparallel_y = sin(theta) * sin(phi); 181 cparallel_z = cos(theta); 182 183 // q vector 184 q_z = 0.0; 185 186 // Compute the angle btw vector q and the 187 // axis of the parallelepiped 188 cos_val_c = cparallel_x*q_x + cparallel_y*q_y + cparallel_z*q_z; 189 alpha = acos(cos_val_c); 190 191 // parallelepiped a axis orientation 192 parallel_x = sin(psi);//cos(pars->parallel_theta) * sin(pars->parallel_phi)*sin(pars->parallel_psi); 193 parallel_y = cos(psi);//cos(pars->parallel_theta) * cos(pars->parallel_phi)*cos(pars->parallel_psi); 194 195 cos_val_a = parallel_x*q_x + parallel_y*q_y; 196 197 198 199 // parallelepiped b axis orientation 200 bparallel_x = sqrt(1.0-sin(theta)*cos(phi))*cos(psi);//cos(pars->parallel_theta) * cos(pars->parallel_phi)* cos(pars->parallel_psi); 201 bparallel_y = sqrt(1.0-sin(theta)*cos(phi))*sin(psi);//cos(pars->parallel_theta) * sin(pars->parallel_phi)* sin(pars->parallel_psi); 202 // axis of the parallelepiped 203 cos_val_b = sin(acos(cos_val_a)) ; 204 205 206 207 // The following test should always pass 208 if (fabs(cos_val_c)>1.0) { 209 printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 210 return 0; 211 } 212 213 // Call the IGOR library function to get the kernel 214 answer = cspkernel( dp,q, sin(alpha)*cos_val_a,sin(alpha)*cos_val_b,cos_val_c); 215 216 //convert to [cm-1] 217 answer *= 1.0e8; 218 219 //Scale 220 answer *= pars->scale; 221 222 // add in the background 223 answer += pars->background; 224 225 return answer; 226 } 227 228 /** 229 * Function to evaluate 2D scattering function 230 * @param pars: parameters of the CSparallelepiped 231 * @param q: q-value 232 * @return: function value 233 */ 234 static double csparallelepiped_analytical_2DXY(CSParallelepipedParameters *pars, double qx, double qy) { 235 double q; 236 q = sqrt(qx*qx+qy*qy); 237 return csparallelepiped_analytical_2D_scaled(pars, q, qx/q, qy/q); 238 } 239 240 241 32 242 33 243 CSParallelepipedModel :: CSParallelepipedModel() { -
sansmodels/src/c_models/models.hh
r8343e18 rdf88829 27 27 using namespace std; 28 28 29 class CSParallelepipedModel{30 public:31 // Model parameters32 Parameter scale;33 Parameter shortA;34 Parameter midB;35 Parameter longC;36 Parameter rimA;37 Parameter rimB;38 Parameter rimC;39 Parameter sld_rimA;40 Parameter sld_rimB;41 Parameter sld_rimC;42 Parameter sld_pcore;43 Parameter sld_solv;44 Parameter background;45 Parameter parallel_theta;46 Parameter parallel_phi;47 Parameter parallel_psi;48 49 // Constructor50 CSParallelepipedModel();51 52 // Operators to get I(Q)53 double operator()(double q);54 double operator()(double qx, double qy);55 double calculate_ER();56 double evaluate_rphi(double q, double phi);57 };58 29 59 30 class OnionModel{ -
sansmodels/src/python_wrapper/CCSParallelepipedModel.cpp
r67424cd rdf88829 18 18 * 19 19 * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY 20 * DO NOT MODIFY THIS FILE, MODIFY csparallelepiped.h20 * DO NOT MODIFY THIS FILE, MODIFY ../c_extensions/csparallelepiped.h 21 21 * AND RE-RUN THE GENERATOR SCRIPT 22 22 * … … 33 33 #include <math.h> 34 34 #include <time.h> 35 36 } 37 35 38 #include "csparallelepiped.h" 36 }37 38 #include "models.hh"39 39 #include "dispersion_visitor.hh" 40 40
Note: See TracChangeset
for help on using the changeset viewer.