Changeset 011e0e4 in sasview for sansmodels/src/c_models/ellipsoid.cpp
- Timestamp:
- Jan 5, 2012 2:23:15 PM (12 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:
- 98fdccd
- Parents:
- 0ba3b08
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/c_models/ellipsoid.cpp
r67424cd r011e0e4 18 18 * sansmodels/src/libigor 19 19 * 20 * TODO: refactor so that we pull in the old sansmodels.c_extensions21 20 */ 22 21 23 22 #include <math.h> 24 #include "models.hh"25 23 #include "parameters.hh" 26 24 #include <stdio.h> 27 25 using namespace std; 26 #include "ellipsoid.h" 28 27 29 28 extern "C" { 30 29 #include "libCylinder.h" 31 30 #include "libStructureFactor.h" 32 #include "ellipsoid.h" 31 } 32 33 typedef struct { 34 double scale; 35 double radius_a; 36 double radius_b; 37 double sldEll; 38 double sldSolv; 39 double background; 40 double axis_theta; 41 double axis_phi; 42 } EllipsoidParameters; 43 44 /** 45 * Function to evaluate 2D scattering function 46 * @param pars: parameters of the ellipsoid 47 * @param q: q-value 48 * @param q_x: q_x / q 49 * @param q_y: q_y / q 50 * @return: function value 51 */ 52 static double ellipsoid_analytical_2D_scaled(EllipsoidParameters *pars, double q, double q_x, double q_y) { 53 double cyl_x, cyl_y, cyl_z; 54 double q_z; 55 double alpha, vol, cos_val; 56 double answer; 57 //convert angle degree to radian 58 double pi = 4.0*atan(1.0); 59 double theta = pars->axis_theta * pi/180.0; 60 double phi = pars->axis_phi * pi/180.0; 61 62 // Ellipsoid orientation 63 cyl_x = sin(theta) * cos(phi); 64 cyl_y = sin(theta) * sin(phi); 65 cyl_z = cos(theta); 66 67 // q vector 68 q_z = 0.0; 69 70 // Compute the angle btw vector q and the 71 // axis of the cylinder 72 cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 73 74 // The following test should always pass 75 if (fabs(cos_val)>1.0) { 76 printf("ellipsoid_ana_2D: Unexpected error: cos(alpha)>1\n"); 77 return 0; 78 } 79 80 // Angle between rotation axis and q vector 81 alpha = acos( cos_val ); 82 83 // Call the IGOR library function to get the kernel 84 answer = EllipsoidKernel(q, pars->radius_b, pars->radius_a, cos_val); 85 86 // Multiply by contrast^2 87 answer *= (pars->sldEll - pars->sldSolv) * (pars->sldEll - pars->sldSolv); 88 89 //normalize by cylinder volume 90 vol = 4.0/3.0 * acos(-1.0) * pars->radius_b * pars->radius_b * pars->radius_a; 91 answer *= vol; 92 93 //convert to [cm-1] 94 answer *= 1.0e8; 95 96 //Scale 97 answer *= pars->scale; 98 99 // add in the background 100 answer += pars->background; 101 102 return answer; 103 } 104 105 /** 106 * Function to evaluate 2D scattering function 107 * @param pars: parameters of the ellipsoid 108 * @param q: q-value 109 * @return: function value 110 */ 111 static double ellipsoid_analytical_2DXY(EllipsoidParameters *pars, double qx, double qy) { 112 double q; 113 q = sqrt(qx*qx+qy*qy); 114 return ellipsoid_analytical_2D_scaled(pars, q, qx/q, qy/q); 33 115 } 34 116
Note: See TracChangeset
for help on using the changeset viewer.