Changeset 8343e18 in sasview for sansmodels/src
- Timestamp:
- Jan 4, 2012 6:16:15 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:
- df88829
- Parents:
- 0c2389e
- Location:
- sansmodels/src
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/c_extensions/parallelepiped.h
r67424cd r8343e18 1 /*2 TODO: Add 2D model3 */4 5 1 #if !defined(parallelepiped_h) 6 2 #define parallelepiped_h 3 #include "parameters.hh" 4 7 5 /** Structure definition for Parallelepiped parameters 8 6 * [PYTHONCLASS] = ParallelepipedModel … … 23 21 24 22 **/ 25 typedef struct {26 /// Scale factor27 // [DEFAULT]=scale=1.028 double scale;29 /// Length of short edge of the parallelepiped [A]30 // [DEFAULT]=short_a=35 [A]31 double short_a;32 /// Length of short edge edge of the parallelepiped [A]33 // [DEFAULT]=short_b=75 [A]34 double short_b;35 /// Length of long edge of the parallelepiped [A]36 // [DEFAULT]=long_c=400 [A]37 double long_c;38 /// SLD_Pipe [1/A^(2)]39 // [DEFAULT]=sldPipe=6.3e-6 [1/A^(2)]40 double sldPipe;41 /// sldSolv [1/A^(2)]42 // [DEFAULT]=sldSolv=1.0e-6 [1/A^(2)]43 double sldSolv;44 /// Incoherent Background [1/cm]45 // [DEFAULT]=background=0.0 [1/cm]46 double background;47 /// Orientation of the parallelepiped axis w/respect incoming beam [deg]48 // [DEFAULT]=parallel_theta=0.0 [deg]49 double parallel_theta;50 /// Orientation of the longitudinal axis of the parallelepiped in the plane of the detector [deg]51 // [DEFAULT]=parallel_phi=0.0 [deg]52 double parallel_phi;53 /// Orientation of the cross-sectional minor axis of the parallelepiped in the plane of the detector [deg]54 // [DEFAULT]=parallel_psi=0.0 [deg]55 double parallel_psi;56 23 24 class ParallelepipedModel{ 25 public: 26 // Model parameters 27 /// Scale factor 28 // [DEFAULT]=scale=1.0 29 Parameter scale; 30 /// Length of short edge of the parallelepiped [A] 31 // [DEFAULT]=short_a=35 [A] 32 Parameter short_a; 33 /// Length of short edge edge of the parallelepiped [A] 34 // [DEFAULT]=short_b=75 [A] 35 Parameter short_b; 36 /// Length of long edge of the parallelepiped [A] 37 // [DEFAULT]=long_c=400 [A] 38 Parameter long_c; 39 /// SLD_Pipe [1/A^(2)] 40 // [DEFAULT]=sldPipe=6.3e-6 [1/A^(2)] 41 Parameter sldPipe; 42 /// sldSolv [1/A^(2)] 43 // [DEFAULT]=sldSolv=1.0e-6 [1/A^(2)] 44 Parameter sldSolv; 45 /// Incoherent Background [1/cm] 46 // [DEFAULT]=background=0.0 [1/cm] 47 Parameter background; 48 /// Orientation of the parallelepiped axis w/respect incoming beam [deg] 49 // [DEFAULT]=parallel_theta=0.0 [deg] 50 Parameter parallel_theta; 51 /// Orientation of the longitudinal axis of the parallelepiped in the plane of the detector [deg] 52 // [DEFAULT]=parallel_phi=0.0 [deg] 53 Parameter parallel_phi; 54 /// Orientation of the cross-sectional minor axis of the parallelepiped in the plane of the detector [deg] 55 // [DEFAULT]=parallel_psi=0.0 [deg] 56 Parameter parallel_psi; 57 57 58 } ParallelepipedParameters; 58 // Constructor 59 ParallelepipedModel(); 59 60 60 61 62 /// 1D scattering function 63 double parallelepiped_analytical_1D(ParallelepipedParameters *pars, double q); 64 65 /// 2D scattering function 66 double parallelepiped_analytical_2D(ParallelepipedParameters *pars, double q, double phi); 67 double parallelepiped_analytical_2DXY(ParallelepipedParameters *pars, double qx, double qy); 68 double parallelepiped_analytical_2D_scaled(ParallelepipedParameters *pars, double q, double q_x, double q_y); 61 // Operators to get I(Q) 62 double operator()(double q); 63 double operator()(double qx, double qy); 64 double calculate_ER(); 65 double evaluate_rphi(double q, double phi); 66 }; 69 67 #endif -
sansmodels/src/c_models/models.hh
r0c2389e r8343e18 26 26 27 27 using namespace std; 28 29 30 31 class ParallelepipedModel{32 public:33 // Model parameters34 Parameter scale;35 Parameter short_a;36 Parameter short_b;37 Parameter long_c;38 Parameter sldPipe;39 Parameter sldSolv;40 Parameter background;41 Parameter parallel_theta;42 Parameter parallel_phi;43 Parameter parallel_psi;44 45 // Constructor46 ParallelepipedModel();47 48 // Operators to get I(Q)49 double operator()(double q);50 double operator()(double qx, double qy);51 double calculate_ER();52 double evaluate_rphi(double q, double phi);53 };54 55 28 56 29 class CSParallelepipedModel{ -
sansmodels/src/c_models/parallelepiped.cpp
r67424cd r8343e18 18 18 * sansmodels/src/libigor 19 19 * 20 * TODO: refactor so that we pull in the old sansmodels.c_extensions21 20 * TODO: add 2D function 22 21 */ … … 31 30 #include "libCylinder.h" 32 31 #include "libStructureFactor.h" 33 #include "parallelepiped.h" 32 } 33 #include "parallelepiped.h" 34 35 // Convenience parameter structure 36 typedef struct { 37 double scale; 38 double short_a; 39 double short_b; 40 double long_c; 41 double sldPipe; 42 double sldSolv; 43 double background; 44 double parallel_theta; 45 double parallel_phi; 46 double parallel_psi; 47 } ParallelepipedParameters; 48 49 50 static double pkernel(double a, double b,double c, double ala, double alb, double alc){ 51 // mu passed in is really mu*sqrt(1-sig^2) 52 double argA,argB,argC,tmp1,tmp2,tmp3; //local variables 53 54 //handle arg=0 separately, as sin(t)/t -> 1 as t->0 55 argA = a*ala/2.0; 56 argB = b*alb/2.0; 57 argC = c*alc/2.0; 58 if(argA==0.0) { 59 tmp1 = 1.0; 60 } else { 61 tmp1 = sin(argA)*sin(argA)/argA/argA; 62 } 63 if (argB==0.0) { 64 tmp2 = 1.0; 65 } else { 66 tmp2 = sin(argB)*sin(argB)/argB/argB; 67 } 68 69 if (argC==0.0) { 70 tmp3 = 1.0; 71 } else { 72 tmp3 = sin(argC)*sin(argC)/argC/argC; 73 } 74 75 return (tmp1*tmp2*tmp3); 76 77 } 78 79 /** 80 * Function to evaluate 2D scattering function 81 * @param pars: parameters of the parallelepiped 82 * @param q: q-value 83 * @param q_x: q_x / q 84 * @param q_y: q_y / q 85 * @return: function value 86 */ 87 static double parallelepiped_analytical_2D_scaled(ParallelepipedParameters *pars, double q, double q_x, double q_y) { 88 double cparallel_x, cparallel_y, cparallel_z, bparallel_x, bparallel_y, parallel_x, parallel_y; 89 double q_z; 90 double alpha, vol, cos_val_c, cos_val_b, cos_val_a, edgeA, edgeB, edgeC; 91 92 double answer; 93 double pi = 4.0*atan(1.0); 94 95 //convert angle degree to radian 96 double theta = pars->parallel_theta * pi/180.0; 97 double phi = pars->parallel_phi * pi/180.0; 98 double psi = pars->parallel_psi * pi/180.0; 99 100 edgeA = pars->short_a; 101 edgeB = pars->short_b; 102 edgeC = pars->long_c; 103 104 105 // parallelepiped c axis orientation 106 cparallel_x = sin(theta) * cos(phi); 107 cparallel_y = sin(theta) * sin(phi); 108 cparallel_z = cos(theta); 109 110 // q vector 111 q_z = 0.0; 112 113 // Compute the angle btw vector q and the 114 // axis of the parallelepiped 115 cos_val_c = cparallel_x*q_x + cparallel_y*q_y + cparallel_z*q_z; 116 alpha = acos(cos_val_c); 117 118 // parallelepiped a axis orientation 119 parallel_x = sin(psi);//cos(pars->parallel_theta) * sin(pars->parallel_phi)*sin(pars->parallel_psi); 120 parallel_y = cos(psi);//cos(pars->parallel_theta) * cos(pars->parallel_phi)*cos(pars->parallel_psi); 121 122 cos_val_a = parallel_x*q_x + parallel_y*q_y; 123 124 125 126 // parallelepiped b axis orientation 127 bparallel_x = sqrt(1.0-sin(theta)*cos(phi))*cos(psi);//cos(pars->parallel_theta) * cos(pars->parallel_phi)* cos(pars->parallel_psi); 128 bparallel_y = sqrt(1.0-sin(theta)*cos(phi))*sin(psi);//cos(pars->parallel_theta) * sin(pars->parallel_phi)* sin(pars->parallel_psi); 129 // axis of the parallelepiped 130 cos_val_b = sin(acos(cos_val_a)) ; 131 132 133 134 // The following test should always pass 135 if (fabs(cos_val_c)>1.0) { 136 printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 137 return 0; 138 } 139 140 // Call the IGOR library function to get the kernel 141 answer = pkernel( q*edgeA, q*edgeB, q*edgeC, sin(alpha)*cos_val_a,sin(alpha)*cos_val_b,cos_val_c); 142 143 // Multiply by contrast^2 144 answer *= (pars->sldPipe - pars->sldSolv) * (pars->sldPipe - pars->sldSolv); 145 146 //normalize by cylinder volume 147 //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vparallel 148 vol = edgeA* edgeB * edgeC; 149 answer *= vol; 150 151 //convert to [cm-1] 152 answer *= 1.0e8; 153 154 //Scale 155 answer *= pars->scale; 156 157 // add in the background 158 answer += pars->background; 159 160 return answer; 161 } 162 163 /** 164 * Function to evaluate 2D scattering function 165 * @param pars: parameters of the parallelepiped 166 * @param q: q-value 167 * @return: function value 168 */ 169 static double parallelepiped_analytical_2DXY(ParallelepipedParameters *pars, double qx, double qy) { 170 double q; 171 q = sqrt(qx*qx+qy*qy); 172 return parallelepiped_analytical_2D_scaled(pars, q, qx/q, qy/q); 34 173 } 35 174 -
sansmodels/src/python_wrapper/CParallelepipedModel.cpp
r67424cd r8343e18 18 18 * 19 19 * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY 20 * DO NOT MODIFY THIS FILE, MODIFY parallelepiped.h20 * DO NOT MODIFY THIS FILE, MODIFY ../c_extensions/parallelepiped.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 "parallelepiped.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.