Changeset 011e0e4 in sasview
- Timestamp:
- Jan 5, 2012 2:23: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:
- 98fdccd
- Parents:
- 0ba3b08
- Location:
- sansmodels/src
- Files:
-
- 2 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/c_extensions/core_shell.h
r67424cd r011e0e4 1 1 #if !defined(core_shell_h) 2 2 #define core_shell_h 3 #include "parameters.hh" 3 4 4 5 /** … … 21 22 22 23 23 typedef struct { 24 /// Scale factor 25 // [DEFAULT]=scale=1.0 26 double scale; 27 /// Core Radius [A] 60.0 28 // [DEFAULT]=radius=60.0 [A] 29 double radius; 30 /// Shell Thickness [A] 10.0 31 // [DEFAULT]=thickness=10 [A] 32 double thickness; 33 /// Core SLD [1/A^(2)] 1.0e-6 34 // [DEFAULT]=core_sld=1.0e-6 [1/A^(2)] 35 double core_sld; 36 /// Shell SLD [1/A^(2)] 2.0e-6 37 // [DEFAULT]=shell_sld=2.0e-6 [1/A^(2)] 38 double shell_sld; 39 /// Solvent SLD [1/A^(2)] 3.0e-6 40 // [DEFAULT]=solvent_sld=3.0e-6 [1/A^(2)] 41 double solvent_sld; 42 /// Incoherent Background [1/cm] 0.000 43 // [DEFAULT]=background=0 [1/cm] 44 double background; 45 } CoreShellParameters; 24 class CoreShellModel{ 25 public: 26 // Model parameters 27 28 /// Core Radius [A] 60.0 29 // [DEFAULT]=radius=60.0 [A] 30 Parameter radius; 31 /// Scale factor 32 // [DEFAULT]=scale=1.0 33 Parameter scale; 34 /// Shell Thickness [A] 10.0 35 // [DEFAULT]=thickness=10 [A] 36 Parameter thickness; 37 /// Core SLD [1/A^(2)] 1.0e-6 38 // [DEFAULT]=core_sld=1.0e-6 [1/A^(2)] 39 Parameter core_sld; 40 /// Shell SLD [1/A^(2)] 2.0e-6 41 // [DEFAULT]=shell_sld=2.0e-6 [1/A^(2)] 42 Parameter shell_sld; 43 /// Solvent SLD [1/A^(2)] 3.0e-6 44 // [DEFAULT]=solvent_sld=3.0e-6 [1/A^(2)] 45 Parameter solvent_sld; 46 /// Incoherent Background [1/cm] 0.000 47 // [DEFAULT]=background=0 [1/cm] 48 Parameter background; 49 50 // Constructor 51 CoreShellModel(); 52 53 // Operators to get I(Q) 54 double operator()(double q); 55 double operator()(double qx, double qy); 56 double calculate_ER(); 57 double evaluate_rphi(double q, double phi); 58 }; 46 59 47 60 48 49 /// 1D scattering function50 //double core_shell_analytical_1D(CoreShellParameters *pars, double q);51 52 /// 2D scattering function53 //double core_shell_analytical_2D(CoreShellParameters *pars, double q, double phi);54 //double core_shell_analytical_2DXY(CoreShellParameters *pars, double qx, double qy);55 56 61 #endif -
sansmodels/src/c_extensions/core_shell_cylinder.h
r67424cd r011e0e4 1 1 #if !defined(core_shell_cylinder_h) 2 2 #define core_shell_cylinder_h 3 #include "parameters.hh" 3 4 4 5 /** 5 6 * Structure definition for core-shell cylinder parameters 6 7 */ 7 8 9 8 //[PYTHONCLASS] = CoreShellCylinderModel 9 //[DISP_PARAMS] = radius, thickness, length, axis_theta, axis_phi 10 //[DESCRIPTION] = <text>P(q,alpha)= scale/Vs*f(q)^(2) + bkg, where: f(q)= 2(core_sld 10 11 // - solvant_sld)* Vc*sin[qLcos(alpha/2)] 11 12 // /[qLcos(alpha/2)]*J1(qRsin(alpha)) 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 13 // /[qRsin(alpha)]+2(shell_sld-solvent_sld) 14 // *Vs*sin[q(L+T)cos(alpha/2)][[q(L+T) 15 // *cos(alpha/2)]*J1(q(R+T)sin(alpha)) 16 // /q(R+T)sin(alpha)] 17 // 18 // alpha:is the angle between the axis of 19 // the cylinder and the q-vector 20 // Vs: the volume of the outer shell 21 // Vc: the volume of the core 22 // L: the length of the core 23 // shell_sld: the scattering length density 24 // of the shell 25 // solvent_sld: the scattering length density 26 // of the solvent 27 // bkg: the background 28 // T: the thickness 29 // R+T: is the outer radius 30 // L+2T: The total length of the outershell 31 // J1: the first order Bessel function 32 // theta: axis_theta of the cylinder 33 // phi: the axis_phi of the cylinder... 34 // </text> 35 //[FIXED]= <text> axis_phi.width; axis_theta.width; length.width;radius.width; thickness.width</text> 36 //[ORIENTATION_PARAMS]= axis_phi; axis_theta;axis_phi.width; axis_theta.width 36 37 38 class CoreShellCylinderModel{ 39 public: 40 // Model parameters 37 41 38 typedef struct { 39 /// Scale factor 40 // [DEFAULT]=scale=1.0 41 double scale; 42 /// Core radius [A] 43 // [DEFAULT]=radius=20.0 [A] 44 Parameter radius; 42 45 43 /// Core radius [A]44 // [DEFAULT]=radius=20.0 [A]45 double radius;46 /// Scale factor 47 // [DEFAULT]=scale=1.0 48 Parameter scale; 46 49 47 48 49 doublethickness;50 /// Shell thickness [A] 51 // [DEFAULT]=thickness=10.0 [A] 52 Parameter thickness; 50 53 51 52 53 doublelength;54 /// Core length [A] 55 // [DEFAULT]=length=400.0 [A] 56 Parameter length; 54 57 55 56 57 doublecore_sld;58 /// Core SLD [1/A^(2)] 59 // [DEFAULT]=core_sld=1.0e-6 [1/A^(2)] 60 Parameter core_sld; 58 61 59 60 61 doubleshell_sld;62 /// Shell SLD [1/A^(2)] 63 // [DEFAULT]=shell_sld=4.0e-6 [1/A^(2)] 64 Parameter shell_sld; 62 65 63 64 65 doublesolvent_sld;66 /// Solvent SLD [1/A^(2)] 67 // [DEFAULT]=solvent_sld=1.0e-6 [1/A^(2)] 68 Parameter solvent_sld; 66 69 67 68 69 doublebackground;70 /// Incoherent Background [1/cm] 71 // [DEFAULT]=background=0 [1/cm] 72 Parameter background; 70 73 71 72 73 doubleaxis_theta;74 /// Orientation of the long axis of the core-shell cylinder w/respect incoming beam [deg] 75 // [DEFAULT]=axis_theta=90.0 [deg] 76 Parameter axis_theta; 74 77 75 76 77 doubleaxis_phi;78 /// Orientation of the long axis of the core-shell cylinder in the plane of the detector [deg] 79 // [DEFAULT]=axis_phi=0.0 [deg] 80 Parameter axis_phi; 78 81 79 } CoreShellCylinderParameters; 82 // Constructor 83 CoreShellCylinderModel(); 80 84 81 82 83 /// 1D scattering function 84 double core_shell_cylinder_analytical_1D(CoreShellCylinderParameters *pars, double q); 85 86 /// 2D scattering function 87 double core_shell_cylinder_analytical_2D(CoreShellCylinderParameters *pars, double q, double phi); 88 double core_shell_cylinder_analytical_2DXY(CoreShellCylinderParameters *pars, double qx, double qy); 89 double core_shell_cylinder_analytical_2D_scaled(CoreShellCylinderParameters *pars, double q, double q_x, double q_y); 85 // Operators to get I(Q) 86 double operator()(double q); 87 double operator()(double qx, double qy); 88 double calculate_ER(); 89 double evaluate_rphi(double q, double phi); 90 }; 90 91 91 92 #endif -
sansmodels/src/c_extensions/corefourshell.h
r67424cd r011e0e4 1 1 #if !defined(corefourshell_h) 2 2 #define corefourshell_h 3 #include "parameters.hh" 3 4 4 5 /** 5 6 * Structure definition for sphere parameters 6 7 */ 7 8 9 10 11 12 13 14 15 16 17 18 19 8 //[PYTHONCLASS] = CoreFourShellModel 9 //[DISP_PARAMS] = rad_core0, thick_shell1,thick_shell2,thick_shell3,thick_shell4 10 //[DESCRIPTION] =<text> Calculates the scattering intensity from a core-4 shell structure. 11 // scale = scale factor * volume fraction 12 // rad_core0: the radius of the core 13 // sld_core0: the SLD of the core 14 // thick_shelli: the thickness of the i'th shell from the core 15 // sld_shelli: the SLD of the i'th shell from the core 16 // sld_solv: the SLD of the solvent 17 // background: incoherent background 18 // </text> 19 //[FIXED]=<text> thick_shell4.width; thick_shell1.width;thick_shell2.width;thick_shell3.width;rad_core0.width </text> 20 //[ORIENTATION_PARAMS]= <text> </text> 20 21 21 typedef struct { 22 /// Scale factor 23 // [DEFAULT]=scale= 1.0 24 double scale; 22 class CoreFourShellModel{ 23 public: 24 // Model parameters 25 /// Scale factor 26 // [DEFAULT]=scale= 1.0 27 Parameter scale; 25 28 26 ///Radius of the core0 [A]27 28 doublerad_core0;29 /// Radius of the core0 [A] 30 // [DEFAULT]=rad_core0=60. [A] 31 Parameter rad_core0; 29 32 30 ///sld of core0 [1/A^(2)]31 32 doublesld_core0;33 /// sld of core0 [1/A^(2)] 34 // [DEFAULT]=sld_core0= 6.4e-6 [1/A^(2)] 35 Parameter sld_core0; 33 36 34 ///thickness of the shell1 [A]35 36 doublethick_shell1;37 /// thickness of the shell1 [A] 38 // [DEFAULT]=thick_shell1=10.0 [A] 39 Parameter thick_shell1; 37 40 38 ///sld of shell1 [1/A^(2)]39 40 doublesld_shell1;41 /// sld of shell1 [1/A^(2)] 42 // [DEFAULT]=sld_shell1= 1.0e-6 [1/A^(2)] 43 Parameter sld_shell1; 41 44 42 ///thickness of the shell2 [A]43 44 doublethick_shell2;45 /// thickness of the shell2 [A] 46 // [DEFAULT]=thick_shell2=10.0 [A] 47 Parameter thick_shell2; 45 48 46 ///sld of shell2 [1/A^(2)]47 48 doublesld_shell2;49 /// sld of shell2 [1/A^(2)] 50 // [DEFAULT]=sld_shell2= 2.0e-6 [1/A^(2)] 51 Parameter sld_shell2; 49 52 50 ///thickness of the shell3 [A]51 52 doublethick_shell3;53 /// thickness of the shell3 [A] 54 // [DEFAULT]=thick_shell3=10.0 [A] 55 Parameter thick_shell3; 53 56 54 ///sld of shell3 [1/A^(2)]55 56 doublesld_shell3;57 /// sld of shell3 [1/A^(2)] 58 // [DEFAULT]=sld_shell3= 3.0e-6 [1/A^(2)] 59 Parameter sld_shell3; 57 60 58 ///thickness of the shell4 [A]59 60 doublethick_shell4;61 /// thickness of the shell4 [A] 62 // [DEFAULT]=thick_shell4=10.0 [A] 63 Parameter thick_shell4; 61 64 62 ///sld of shell4 [1/A^(2)]63 64 doublesld_shell4;65 /// sld of shell4 [1/A^(2)] 66 // [DEFAULT]=sld_shell4= 4.0e-6 [1/A^(2)] 67 Parameter sld_shell4; 65 68 66 ///sld_solv[1/A^(2)]67 68 doublesld_solv;69 /// sld_solv[1/A^(2)] 70 // [DEFAULT]=sld_solv= 6.4e-6 [1/A^(2)] 71 Parameter sld_solv; 69 72 70 /// Incoherent Background [1/cm] 71 // [DEFAULT]=background=0.001 [1/cm] 72 double background; 73 } CoreFourShellParameters; 73 /// Incoherent Background [1/cm] 74 // [DEFAULT]=background=0.001 [1/cm] 75 Parameter background; 74 76 77 // Constructor 78 CoreFourShellModel(); 75 79 76 77 /// 1D scattering function 78 //double corefourshell_analytical_1D(CoreFourShellParameters *pars, double q); 79 80 /// 2D scattering function 81 //double corefourshell_analytical_2D(CoreFourShellParameters *pars, double q, double phi); 82 //double corefourshell_analytical_2DXY(CoreFourShellParameters *pars, double qx, double qy); 80 // Operators to get I(Q) 81 double operator()(double q); 82 double operator()(double qx, double qy); 83 double calculate_ER(); 84 double evaluate_rphi(double q, double phi); 85 }; 83 86 84 87 #endif -
sansmodels/src/c_extensions/ellipsoid.h
r67424cd r011e0e4 1 1 #if !defined(ellipsoid_h) 2 2 #define ellipsoid_h 3 #include "parameters.hh" 3 4 4 5 /** … … 7 8 * Ref: Jan Skov Pedersen, Advances in Colloid and Interface Science, 70 (1997) 171-210 8 9 */ 9 //[PYTHONCLASS] = EllipsoidModel 10 //[DISP_PARAMS] = radius_a, radius_b, axis_theta, axis_phi 11 //[DESCRIPTION] = <text>"P(q.alpha)= scale*f(q)^(2)+ bkg, where f(q)= 3*(sld_ell 12 // - sld_solvent)*V*[sin(q*r(Ra,Rb,alpha)) 13 // -q*r*cos(qr(Ra,Rb,alpha))] 14 // /[qr(Ra,Rb,alpha)]^(3)" 15 // 16 // r(Ra,Rb,alpha)= [Rb^(2)*(sin(alpha))^(2) 17 // + Ra^(2)*(cos(alpha))^(2)]^(1/2) 18 // 19 // scatter_sld: SLD of the scatter 20 // solvent_sld: SLD of the solvent 21 // sldEll: SLD of ellipsoid 22 // sldSolv: SLD of solvent 23 // V: volune of the Eliipsoid 24 // Ra: radius along the rotation axis 25 // of the Ellipsoid 26 // Rb: radius perpendicular to the 27 // rotation axis of the ellipsoid 28 // </text> 29 //[FIXED]= <text> axis_phi.width; axis_theta.width;radius_a.width; 30 //radius_b.width; length.width; r_minor.width; 31 //r_ratio.width</text> 32 //[ORIENTATION_PARAMS]= axis_phi.width; axis_theta.width;axis_phi; axis_theta 10 //[PYTHONCLASS] = EllipsoidModel 11 //[DISP_PARAMS] = radius_a, radius_b, axis_theta, axis_phi 12 //[DESCRIPTION] = <text>"P(q.alpha)= scale*f(q)^(2)+ bkg, where f(q)= 3*(sld_ell 13 // - sld_solvent)*V*[sin(q*r(Ra,Rb,alpha)) 14 // -q*r*cos(qr(Ra,Rb,alpha))] 15 // /[qr(Ra,Rb,alpha)]^(3)" 16 // 17 // r(Ra,Rb,alpha)= [Rb^(2)*(sin(alpha))^(2) 18 // + Ra^(2)*(cos(alpha))^(2)]^(1/2) 19 // 20 // scatter_sld: SLD of the scatter 21 // solvent_sld: SLD of the solvent 22 // sldEll: SLD of ellipsoid 23 // sldSolv: SLD of solvent 24 // V: volune of the Eliipsoid 25 // Ra: radius along the rotation axis 26 // of the Ellipsoid 27 // Rb: radius perpendicular to the 28 // rotation axis of the ellipsoid 29 // </text> 30 //[FIXED]= <text> axis_phi.width; axis_theta.width;radius_a.width; 31 //radius_b.width; length.width; r_minor.width; 32 //r_ratio.width</text> 33 //[ORIENTATION_PARAMS]= axis_phi.width; axis_theta.width;axis_phi; axis_theta 34 35 class EllipsoidModel{ 36 public: 37 // Model parameters 38 /// Rotation axis radius_a [A] 39 // [DEFAULT]=radius_a=20.0 [A] 40 Parameter radius_a; 41 42 /// Scale factor 43 // [DEFAULT]=scale=1.0 44 Parameter scale; 45 46 /// Radius_b [A] 47 // [DEFAULT]=radius_b=400 [A] 48 Parameter radius_b; 49 50 /// sldEll [1/A^(2)] 51 // [DEFAULT]=sldEll=4.0e-6 [1/A^(2)] 52 Parameter sldEll; 53 54 /// sld of solvent [1/A^(2)] 55 // [DEFAULT]=sldSolv=1.0e-6 [1/A^(2)] 56 Parameter sldSolv; 57 58 /// Incoherent Background [1/cm] 59 // [DEFAULT]=background=0 [1/cm] 60 Parameter background; 61 62 /// Orientation of the long axis of the ellipsoid w/respect incoming beam [deg] 63 // [DEFAULT]=axis_theta=90.0 [deg] 64 Parameter axis_theta; 65 /// Orientation of the long axis of the ellipsoid in the plane of the detector [deg] 66 // [DEFAULT]=axis_phi=0.0 [deg] 67 Parameter axis_phi; 68 69 // Constructor 70 EllipsoidModel(); 71 72 // Operators to get I(Q) 73 double operator()(double q); 74 double operator()(double qx, double qy); 75 double calculate_ER(); 76 double evaluate_rphi(double q, double phi); 77 }; 33 78 34 79 35 typedef struct {36 /// Scale factor37 // [DEFAULT]=scale=1.038 double scale;39 40 /// Rotation axis radius_a [A]41 // [DEFAULT]=radius_a=20.0 [A]42 double radius_a;43 44 /// Radius_b [A]45 // [DEFAULT]=radius_b=400 [A]46 double radius_b;47 48 /// sldEll [1/A^(2)]49 // [DEFAULT]=sldEll=4.0e-6 [1/A^(2)]50 double sldEll;51 52 /// sld of solvent [1/A^(2)]53 // [DEFAULT]=sldSolv=1.0e-6 [1/A^(2)]54 double sldSolv;55 56 /// Incoherent Background [1/cm]57 // [DEFAULT]=background=0 [1/cm]58 double background;59 60 /// Orientation of the long axis of the ellipsoid w/respect incoming beam [deg]61 // [DEFAULT]=axis_theta=90.0 [deg]62 double axis_theta;63 /// Orientation of the long axis of the ellipsoid in the plane of the detector [deg]64 // [DEFAULT]=axis_phi=0.0 [deg]65 double axis_phi;66 } EllipsoidParameters;67 68 69 70 /// 1D scattering function71 double ellipsoid_analytical_1D(EllipsoidParameters *pars, double q);72 73 /// 2D scattering function74 double ellipsoid_analytical_2D(EllipsoidParameters *pars, double q, double phi);75 double ellipsoid_analytical_2DXY(EllipsoidParameters *pars, double qx, double qy);76 double ellipsoid_analytical_2D_scaled(EllipsoidParameters *pars, double q, double q_x, double q_y);77 78 80 #endif -
sansmodels/src/c_models/corefourshell.cpp
r67424cd r011e0e4 21 21 22 22 #include <math.h> 23 #include "models.hh"24 23 #include "parameters.hh" 25 24 #include <stdio.h> 26 25 using namespace std; 26 #include "corefourshell.h" 27 27 28 28 extern "C" { 29 29 #include "libSphere.h" 30 #include "corefourshell.h" 31 } 30 } 31 32 typedef struct { 33 double scale; 34 double rad_core0; 35 double sld_core0; 36 double thick_shell1; 37 double sld_shell1; 38 double thick_shell2; 39 double sld_shell2; 40 double thick_shell3; 41 double sld_shell3; 42 double thick_shell4; 43 double sld_shell4; 44 double sld_solv; 45 double background; 46 } CoreFourShellParameters; 32 47 33 48 CoreFourShellModel :: CoreFourShellModel() { -
sansmodels/src/c_models/coreshellcylinder.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 "core_shell_cylinder.h" 28 27 29 28 extern "C" { 30 29 #include "libCylinder.h" 31 30 #include "libStructureFactor.h" 32 #include "core_shell_cylinder.h" 33 } 31 } 32 33 typedef struct { 34 double scale; 35 double radius; 36 double thickness; 37 double length; 38 double core_sld; 39 double shell_sld; 40 double solvent_sld; 41 double background; 42 double axis_theta; 43 double axis_phi; 44 } CoreShellCylinderParameters; 45 46 47 /** 48 * Function to evaluate 2D scattering function 49 * @param pars: parameters of the core-shell cylinder 50 * @param q: q-value 51 * @param q_x: q_x / q 52 * @param q_y: q_y / q 53 * @return: function value 54 */ 55 static double core_shell_cylinder_analytical_2D_scaled(CoreShellCylinderParameters *pars, double q, double q_x, double q_y) { 56 double cyl_x, cyl_y, cyl_z; 57 double q_z; 58 double alpha, vol, cos_val; 59 double answer; 60 //convert angle degree to radian 61 double pi = 4.0*atan(1.0); 62 double theta = pars->axis_theta * pi/180.0; 63 double phi = pars->axis_phi * pi/180.0; 64 65 // Cylinder orientation 66 cyl_x = sin(theta) * cos(phi); 67 cyl_y = sin(theta) * sin(phi); 68 cyl_z = cos(theta); 69 70 // q vector 71 q_z = 0; 72 73 // Compute the angle btw vector q and the 74 // axis of the cylinder 75 cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 76 77 // The following test should always pass 78 if (fabs(cos_val)>1.0) { 79 printf("core_shell_cylinder_analytical_2D: Unexpected error: cos(alpha)=%g\n", cos_val); 80 return 0; 81 } 82 83 alpha = acos( cos_val ); 84 85 // Call the IGOR library function to get the kernel 86 answer = CoreShellCylKernel(q, pars->radius, pars->thickness, 87 pars->core_sld,pars->shell_sld, 88 pars->solvent_sld, pars->length/2.0, alpha) / fabs(sin(alpha)); 89 90 //normalize by cylinder volume 91 vol=pi*(pars->radius+pars->thickness) 92 *(pars->radius+pars->thickness) 93 *(pars->length+2.0*pars->thickness); 94 answer /= vol; 95 96 //convert to [cm-1] 97 answer *= 1.0e8; 98 99 //Scale 100 answer *= pars->scale; 101 102 // add in the background 103 answer += pars->background; 104 105 return answer; 106 } 107 108 /** 109 * Function to evaluate 2D scattering function 110 * @param pars: parameters of the core-shell cylinder 111 * @param q: q-value 112 * @return: function value 113 */ 114 static double core_shell_cylinder_analytical_2DXY(CoreShellCylinderParameters *pars, double qx, double qy) { 115 double q; 116 q = sqrt(qx*qx+qy*qy); 117 return core_shell_cylinder_analytical_2D_scaled(pars, q, qx/q, qy/q); 118 } 119 34 120 35 121 CoreShellCylinderModel :: CoreShellCylinderModel() { -
sansmodels/src/c_models/coreshellsphere.cpp
r67424cd r011e0e4 21 21 22 22 #include <math.h> 23 #include "models.hh"24 23 #include "parameters.hh" 25 24 #include <stdio.h> 26 25 using namespace std; 26 #include "core_shell.h" 27 27 28 28 extern "C" { 29 #include "libSphere.h" 30 #include "core_shell.h" 29 #include "libSphere.h" 31 30 } 32 31 32 typedef struct { 33 double scale; 34 double radius; 35 double thickness; 36 double core_sld; 37 double shell_sld; 38 double solvent_sld; 39 double background; 40 } CoreShellParameters; 41 33 42 CoreShellModel :: CoreShellModel() { 34 35 36 37 38 39 40 41 42 43 scale = Parameter(1.0); 44 radius = Parameter(60.0, true); 45 radius.set_min(0.0); 46 thickness = Parameter(10.0, true); 47 thickness.set_min(0.0); 48 core_sld = Parameter(1.e-6); 49 shell_sld = Parameter(2.e-6); 50 solvent_sld = Parameter(3.e-6); 51 background = Parameter(0.0); 43 52 } 44 53 … … 50 59 */ 51 60 double CoreShellModel :: operator()(double q) { 52 61 double dp[7]; 53 62 54 55 63 // Fill parameter array for IGOR library 64 // Add the background after averaging 56 65 57 58 59 60 61 62 63 66 dp[0] = scale(); 67 dp[1] = radius(); 68 dp[2] = thickness(); 69 dp[3] = core_sld(); 70 dp[4] = shell_sld(); 71 dp[5] = solvent_sld(); 72 dp[6] = 0.0; 64 73 65 74 66 67 68 75 // Get the dispersion points for the radius 76 vector<WeightPoint> weights_rad; 77 radius.get_weights(weights_rad); 69 78 70 71 72 79 // Get the dispersion points for the thickness 80 vector<WeightPoint> weights_thick; 81 thickness.get_weights(weights_thick); 73 82 74 75 76 77 83 // Perform the computation, with all weight points 84 double sum = 0.0; 85 double norm = 0.0; 86 double vol = 0.0; 78 87 79 80 81 88 // Loop over radius weight points 89 for(size_t i=0; i<weights_rad.size(); i++) { 90 dp[1] = weights_rad[i].value; 82 91 83 84 85 86 87 88 92 // Loop over thickness weight points 93 for(size_t j=0; j<weights_thick.size(); j++) { 94 dp[2] = weights_thick[j].value; 95 //Un-normalize SphereForm by volume 96 sum += weights_rad[i].weight 97 * weights_thick[j].weight * CoreShellForm(dp, q)* pow(weights_rad[i].value+weights_thick[j].value,3); 89 98 90 91 92 93 94 95 96 99 //Find average volume 100 vol += weights_rad[i].weight * weights_thick[j].weight 101 * pow(weights_rad[i].value+weights_thick[j].value,3); 102 norm += weights_rad[i].weight 103 * weights_thick[j].weight; 104 } 105 } 97 106 98 99 100 107 if (vol != 0.0 && norm != 0.0) { 108 //Re-normalize by avg volume 109 sum = sum/(vol/norm);} 101 110 102 111 return sum/norm + background(); 103 112 } 104 113 … … 110 119 */ 111 120 double CoreShellModel :: operator()(double qx, double qy) { 112 113 121 double q = sqrt(qx*qx + qy*qy); 122 return (*this).operator()(q); 114 123 } 115 124 … … 122 131 */ 123 132 double CoreShellModel :: evaluate_rphi(double q, double phi) { 124 133 return (*this).operator()(q); 125 134 } 126 135 /** … … 129 138 */ 130 139 double CoreShellModel :: calculate_ER() { 131 140 CoreShellParameters dp; 132 141 133 134 142 dp.radius = radius(); 143 dp.thickness = thickness(); 135 144 136 145 double rad_out = 0.0; 137 146 138 139 140 147 // Perform the computation, with all weight points 148 double sum = 0.0; 149 double norm = 0.0; 141 150 142 151 143 144 145 152 // Get the dispersion points for the major shell 153 vector<WeightPoint> weights_thickness; 154 thickness.get_weights(weights_thickness); 146 155 147 148 149 156 // Get the dispersion points for the minor shell 157 vector<WeightPoint> weights_radius ; 158 radius.get_weights(weights_radius); 150 159 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 160 // Loop over major shell weight points 161 for(int j=0; j< (int)weights_thickness.size(); j++) { 162 dp.thickness = weights_thickness[j].value; 163 for(int k=0; k< (int)weights_radius.size(); k++) { 164 dp.radius = weights_radius[k].value; 165 sum += weights_thickness[j].weight 166 * weights_radius[k].weight*(dp.radius+dp.thickness); 167 norm += weights_thickness[j].weight* weights_radius[k].weight; 168 } 169 } 170 if (norm != 0){ 171 //return the averaged value 172 rad_out = sum/norm;} 173 else{ 174 //return normal value 175 rad_out = (dp.radius+dp.thickness);} 167 176 168 177 return rad_out; 169 178 } -
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 -
sansmodels/src/c_models/models.hh
r0ba3b08 r011e0e4 27 27 using namespace std; 28 28 29 30 31 class CoreShellModel{32 public:33 // Model parameters34 Parameter radius;35 Parameter scale;36 Parameter thickness;37 Parameter core_sld;38 Parameter shell_sld;39 Parameter solvent_sld;40 Parameter background;41 42 // Constructor43 CoreShellModel();44 45 // Operators to get I(Q)46 double operator()(double q);47 double operator()(double qx, double qy);48 double calculate_ER();49 double evaluate_rphi(double q, double phi);50 };51 52 class CoreFourShellModel{53 public:54 // Model parameters55 Parameter scale;56 Parameter rad_core0;57 Parameter sld_core0;58 Parameter thick_shell1;59 Parameter sld_shell1;60 Parameter thick_shell2;61 Parameter sld_shell2;62 Parameter thick_shell3;63 Parameter sld_shell3;64 Parameter thick_shell4;65 Parameter sld_shell4;66 Parameter sld_solv;67 Parameter background;68 69 // Constructor70 CoreFourShellModel();71 72 // Operators to get I(Q)73 double operator()(double q);74 double operator()(double qx, double qy);75 double calculate_ER();76 double evaluate_rphi(double q, double phi);77 };78 79 class CoreShellCylinderModel{80 public:81 // Model parameters82 Parameter radius;83 Parameter scale;84 Parameter thickness;85 Parameter length;86 Parameter core_sld;87 Parameter shell_sld;88 Parameter solvent_sld;89 Parameter background;90 Parameter axis_theta;91 Parameter axis_phi;92 93 // Constructor94 CoreShellCylinderModel();95 96 // Operators to get I(Q)97 double operator()(double q);98 double operator()(double qx, double qy);99 double calculate_ER();100 double evaluate_rphi(double q, double phi);101 };102 103 class EllipsoidModel{104 public:105 // Model parameters106 Parameter radius_a;107 Parameter scale;108 Parameter radius_b;109 Parameter sldEll;110 Parameter sldSolv;111 Parameter background;112 Parameter axis_theta;113 Parameter axis_phi;114 115 // Constructor116 EllipsoidModel();117 118 // Operators to get I(Q)119 double operator()(double q);120 double operator()(double qx, double qy);121 double calculate_ER();122 double evaluate_rphi(double q, double phi);123 };124 125 29 class EllipticalCylinderModel{ 126 30 public:
Note: See TracChangeset
for help on using the changeset viewer.