Changeset 011e0e4 in sasview


Ignore:
Timestamp:
Jan 5, 2012 2:23:15 PM (12 years ago)
Author:
Mathieu Doucet <doucetm@…>
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
Message:

core-shell + ellipsoid refactor

Location:
sansmodels/src
Files:
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/c_extensions/core_shell.h

    r67424cd r011e0e4  
    11#if !defined(core_shell_h) 
    22#define core_shell_h 
     3#include "parameters.hh" 
    34 
    45/** 
     
    2122 
    2223 
    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; 
     24class CoreShellModel{ 
     25public: 
     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}; 
    4659 
    4760 
    48  
    49 /// 1D scattering function 
    50 //double core_shell_analytical_1D(CoreShellParameters *pars, double q); 
    51  
    52 /// 2D scattering function 
    53 //double core_shell_analytical_2D(CoreShellParameters *pars, double q, double phi); 
    54 //double core_shell_analytical_2DXY(CoreShellParameters *pars, double qx, double qy); 
    55  
    5661#endif 
  • sansmodels/src/c_extensions/core_shell_cylinder.h

    r67424cd r011e0e4  
    11#if !defined(core_shell_cylinder_h) 
    22#define core_shell_cylinder_h 
     3#include "parameters.hh" 
    34 
    45/** 
    56 * Structure definition for core-shell cylinder parameters 
    67 */ 
    7  //[PYTHONCLASS] = CoreShellCylinderModel 
    8  //[DISP_PARAMS] = radius, thickness, length, axis_theta, axis_phi 
    9  //[DESCRIPTION] = <text>P(q,alpha)= scale/Vs*f(q)^(2) + bkg,  where: f(q)= 2(core_sld 
     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 
    1011//                      - solvant_sld)* Vc*sin[qLcos(alpha/2)] 
    1112//                      /[qLcos(alpha/2)]*J1(qRsin(alpha)) 
    12  //                     /[qRsin(alpha)]+2(shell_sld-solvent_sld) 
    13  //                     *Vs*sin[q(L+T)cos(alpha/2)][[q(L+T) 
    14  //                     *cos(alpha/2)]*J1(q(R+T)sin(alpha)) 
    15  //                     /q(R+T)sin(alpha)] 
    16  // 
    17  //                     alpha:is the angle between the axis of 
    18  //          the cylinder and the q-vector 
    19  //                     Vs: the volume of the outer shell 
    20  //                     Vc: the volume of the core 
    21  //                     L: the length of the core 
    22  //             shell_sld: the scattering length density 
    23  //                     of the shell 
    24  //                     solvent_sld: the scattering length density 
    25  //                     of the solvent 
    26  //                     bkg: the background 
    27  //                     T: the thickness 
    28  //             R+T: is the outer radius 
    29  //             L+2T: The total length of the outershell 
    30  //                     J1: the first order Bessel function 
    31  //             theta: axis_theta of the cylinder 
    32  //             phi: the axis_phi of the cylinder... 
    33  //             </text> 
    34  //[FIXED]= <text> axis_phi.width; axis_theta.width; length.width;radius.width; thickness.width</text> 
    35  //[ORIENTATION_PARAMS]= axis_phi; axis_theta;axis_phi.width; axis_theta.width 
     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 
    3637 
     38class CoreShellCylinderModel{ 
     39public: 
     40  // Model parameters 
    3741 
    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; 
    4245 
    43     /// Core radius [A] 
    44     //  [DEFAULT]=radius=20.0 [A] 
    45     double radius; 
     46  /// Scale factor 
     47  //  [DEFAULT]=scale=1.0 
     48  Parameter scale; 
    4649 
    47     /// Shell thickness [A] 
    48     //  [DEFAULT]=thickness=10.0 [A] 
    49     double thickness; 
     50  /// Shell thickness [A] 
     51  //  [DEFAULT]=thickness=10.0 [A] 
     52  Parameter thickness; 
    5053 
    51     /// Core length [A] 
    52     //  [DEFAULT]=length=400.0 [A] 
    53     double length; 
     54  /// Core length [A] 
     55  //  [DEFAULT]=length=400.0 [A] 
     56  Parameter length; 
    5457 
    55     /// Core SLD [1/A^(2)] 
    56     //  [DEFAULT]=core_sld=1.0e-6 [1/A^(2)] 
    57     double core_sld; 
     58  /// Core SLD [1/A^(2)] 
     59  //  [DEFAULT]=core_sld=1.0e-6 [1/A^(2)] 
     60  Parameter core_sld; 
    5861 
    59     /// Shell SLD [1/A^(2)] 
    60     //  [DEFAULT]=shell_sld=4.0e-6 [1/A^(2)] 
    61     double shell_sld; 
     62  /// Shell SLD [1/A^(2)] 
     63  //  [DEFAULT]=shell_sld=4.0e-6 [1/A^(2)] 
     64  Parameter shell_sld; 
    6265 
    63     /// Solvent SLD [1/A^(2)] 
    64     //  [DEFAULT]=solvent_sld=1.0e-6 [1/A^(2)] 
    65     double solvent_sld; 
     66  /// Solvent SLD [1/A^(2)] 
     67  //  [DEFAULT]=solvent_sld=1.0e-6 [1/A^(2)] 
     68  Parameter solvent_sld; 
    6669 
    67         /// Incoherent Background [1/cm] 
    68         //  [DEFAULT]=background=0 [1/cm] 
    69         double background; 
     70  /// Incoherent Background [1/cm] 
     71  //  [DEFAULT]=background=0 [1/cm] 
     72  Parameter background; 
    7073 
    71     /// Orientation of the long axis of the core-shell cylinder w/respect incoming beam [deg] 
    72     //  [DEFAULT]=axis_theta=90.0 [deg] 
    73     double axis_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; 
    7477 
    75     /// Orientation of the long axis of the core-shell cylinder in the plane of the detector [deg] 
    76     //  [DEFAULT]=axis_phi=0.0 [deg] 
    77     double axis_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; 
    7881 
    79 } CoreShellCylinderParameters; 
     82  // Constructor 
     83  CoreShellCylinderModel(); 
    8084 
    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}; 
    9091 
    9192#endif 
  • sansmodels/src/c_extensions/corefourshell.h

    r67424cd r011e0e4  
    11#if !defined(corefourshell_h) 
    22#define corefourshell_h 
     3#include "parameters.hh" 
    34 
    45/** 
    56 * Structure definition for sphere parameters 
    67 */ 
    7  //[PYTHONCLASS] = CoreFourShellModel 
    8  //[DISP_PARAMS] = rad_core0, thick_shell1,thick_shell2,thick_shell3,thick_shell4 
    9  //[DESCRIPTION] =<text> Calculates the scattering intensity from a core-4 shell structure. 
    10  //                     scale = scale factor * volume fraction 
    11  //                             rad_core0: the radius of the core 
    12  //                             sld_core0: the SLD of the core 
    13  //                             thick_shelli: the thickness of the i'th shell from the core 
    14  //                             sld_shelli: the SLD of the i'th shell from the core 
    15  //                             sld_solv: the SLD of the solvent 
    16  //                             background: incoherent background 
    17  //             </text> 
    18  //[FIXED]=<text>  thick_shell4.width; thick_shell1.width;thick_shell2.width;thick_shell3.width;rad_core0.width </text> 
    19  //[ORIENTATION_PARAMS]= <text> </text> 
     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> 
    2021 
    21 typedef struct { 
    22     /// Scale factor 
    23     //  [DEFAULT]=scale= 1.0 
    24     double scale; 
     22class CoreFourShellModel{ 
     23public: 
     24  // Model parameters 
     25  /// Scale factor 
     26  //  [DEFAULT]=scale= 1.0 
     27  Parameter scale; 
    2528 
    26     /// Radius of the core0 [A] 
    27     //  [DEFAULT]=rad_core0=60. [A] 
    28     double rad_core0; 
     29  /// Radius of the core0 [A] 
     30  //  [DEFAULT]=rad_core0=60. [A] 
     31  Parameter rad_core0; 
    2932 
    30     /// sld of core0 [1/A^(2)] 
    31     //  [DEFAULT]=sld_core0= 6.4e-6 [1/A^(2)] 
    32     double sld_core0; 
     33  /// sld of core0 [1/A^(2)] 
     34  //  [DEFAULT]=sld_core0= 6.4e-6 [1/A^(2)] 
     35  Parameter sld_core0; 
    3336 
    34     /// thickness of the shell1 [A] 
    35      //  [DEFAULT]=thick_shell1=10.0 [A] 
    36     double thick_shell1; 
     37  /// thickness of the shell1 [A] 
     38  //  [DEFAULT]=thick_shell1=10.0 [A] 
     39  Parameter thick_shell1; 
    3740 
    38      ///        sld of shell1 [1/A^(2)] 
    39      //  [DEFAULT]=sld_shell1= 1.0e-6 [1/A^(2)] 
    40      double sld_shell1; 
     41  ///  sld of shell1 [1/A^(2)] 
     42  //  [DEFAULT]=sld_shell1= 1.0e-6 [1/A^(2)] 
     43  Parameter sld_shell1; 
    4144 
    42      ///        thickness of the shell2 [A] 
    43       //  [DEFAULT]=thick_shell2=10.0 [A] 
    44      double thick_shell2; 
     45  ///  thickness of the shell2 [A] 
     46  //  [DEFAULT]=thick_shell2=10.0 [A] 
     47  Parameter thick_shell2; 
    4548 
    46       ///       sld of shell2 [1/A^(2)] 
    47       //  [DEFAULT]=sld_shell2= 2.0e-6 [1/A^(2)] 
    48       double sld_shell2; 
     49  /// sld of shell2 [1/A^(2)] 
     50  //  [DEFAULT]=sld_shell2= 2.0e-6 [1/A^(2)] 
     51  Parameter sld_shell2; 
    4952 
    50       ///       thickness of the shell3 [A] 
    51        //  [DEFAULT]=thick_shell3=10.0 [A] 
    52       double thick_shell3; 
     53  /// thickness of the shell3 [A] 
     54  //  [DEFAULT]=thick_shell3=10.0 [A] 
     55  Parameter thick_shell3; 
    5356 
    54        ///      sld of shell3 [1/A^(2)] 
    55        //  [DEFAULT]=sld_shell3= 3.0e-6 [1/A^(2)] 
    56        double sld_shell3; 
     57  ///  sld of shell3 [1/A^(2)] 
     58  //  [DEFAULT]=sld_shell3= 3.0e-6 [1/A^(2)] 
     59  Parameter sld_shell3; 
    5760 
    58        ///      thickness of the shell4 [A] 
    59         //  [DEFAULT]=thick_shell4=10.0 [A] 
    60        double thick_shell4; 
     61  ///  thickness of the shell4 [A] 
     62  //  [DEFAULT]=thick_shell4=10.0 [A] 
     63  Parameter thick_shell4; 
    6164 
    62         ///     sld of shell4 [1/A^(2)] 
    63         //  [DEFAULT]=sld_shell4= 4.0e-6 [1/A^(2)] 
    64         double sld_shell4; 
     65  /// sld of shell4 [1/A^(2)] 
     66  //  [DEFAULT]=sld_shell4= 4.0e-6 [1/A^(2)] 
     67  Parameter sld_shell4; 
    6568 
    66     /// sld_solv[1/A^(2)] 
    67     //  [DEFAULT]=sld_solv= 6.4e-6 [1/A^(2)] 
    68     double sld_solv; 
     69  /// sld_solv[1/A^(2)] 
     70  //  [DEFAULT]=sld_solv= 6.4e-6 [1/A^(2)] 
     71  Parameter sld_solv; 
    6972 
    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; 
    7476 
     77  // Constructor 
     78  CoreFourShellModel(); 
    7579 
    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}; 
    8386 
    8487#endif 
  • sansmodels/src/c_extensions/ellipsoid.h

    r67424cd r011e0e4  
    11#if !defined(ellipsoid_h) 
    22#define ellipsoid_h 
     3#include "parameters.hh" 
    34 
    45/** 
     
    78 * Ref: Jan Skov Pedersen, Advances in Colloid and Interface Science, 70 (1997) 171-210 
    89 */ 
    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 
     35class EllipsoidModel{ 
     36public: 
     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}; 
    3378 
    3479 
    35 typedef struct { 
    36     /// Scale factor 
    37     //  [DEFAULT]=scale=1.0 
    38     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 function 
    71 double ellipsoid_analytical_1D(EllipsoidParameters *pars, double q); 
    72  
    73 /// 2D scattering function 
    74 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  
    7880#endif 
  • sansmodels/src/c_models/corefourshell.cpp

    r67424cd r011e0e4  
    2121 
    2222#include <math.h> 
    23 #include "models.hh" 
    2423#include "parameters.hh" 
    2524#include <stdio.h> 
    2625using namespace std; 
     26#include "corefourshell.h" 
    2727 
    2828extern "C" { 
    2929        #include "libSphere.h" 
    30         #include "corefourshell.h" 
    31 } 
     30} 
     31 
     32typedef 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; 
    3247 
    3348CoreFourShellModel :: CoreFourShellModel() { 
  • sansmodels/src/c_models/coreshellcylinder.cpp

    r67424cd r011e0e4  
    1818 *   sansmodels/src/libigor 
    1919 * 
    20  *      TODO: refactor so that we pull in the old sansmodels.c_extensions 
    2120 */ 
    2221 
    2322#include <math.h> 
    24 #include "models.hh" 
    2523#include "parameters.hh" 
    2624#include <stdio.h> 
    2725using namespace std; 
     26#include "core_shell_cylinder.h" 
    2827 
    2928extern "C" { 
    3029        #include "libCylinder.h" 
    3130        #include "libStructureFactor.h" 
    32         #include "core_shell_cylinder.h" 
    33 } 
     31} 
     32 
     33typedef 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 */ 
     55static 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 */ 
     114static 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 
    34120 
    35121CoreShellCylinderModel :: CoreShellCylinderModel() { 
  • sansmodels/src/c_models/coreshellsphere.cpp

    r67424cd r011e0e4  
    2121 
    2222#include <math.h> 
    23 #include "models.hh" 
    2423#include "parameters.hh" 
    2524#include <stdio.h> 
    2625using namespace std; 
     26#include "core_shell.h" 
    2727 
    2828extern "C" { 
    29         #include "libSphere.h" 
    30         #include "core_shell.h" 
     29#include "libSphere.h" 
    3130} 
    3231 
     32typedef 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 
    3342CoreShellModel :: CoreShellModel() { 
    34         scale      = Parameter(1.0); 
    35         radius     = Parameter(60.0, true); 
    36         radius.set_min(0.0); 
    37         thickness  = Parameter(10.0, true); 
    38         thickness.set_min(0.0); 
    39         core_sld   = Parameter(1.e-6); 
    40         shell_sld  = Parameter(2.e-6); 
    41         solvent_sld = Parameter(3.e-6); 
    42         background = Parameter(0.0); 
     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); 
    4352} 
    4453 
     
    5059 */ 
    5160double CoreShellModel :: operator()(double q) { 
    52         double dp[7]; 
     61  double dp[7]; 
    5362 
    54         // Fill parameter array for IGOR library 
    55         // Add the background after averaging 
     63  // Fill parameter array for IGOR library 
     64  // Add the background after averaging 
    5665 
    57         dp[0] = scale(); 
    58         dp[1] = radius(); 
    59         dp[2] = thickness(); 
    60         dp[3] = core_sld(); 
    61         dp[4] = shell_sld(); 
    62         dp[5] = solvent_sld(); 
    63         dp[6] = 0.0; 
     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; 
    6473 
    6574 
    66         // Get the dispersion points for the radius 
    67         vector<WeightPoint> weights_rad; 
    68         radius.get_weights(weights_rad); 
     75  // Get the dispersion points for the radius 
     76  vector<WeightPoint> weights_rad; 
     77  radius.get_weights(weights_rad); 
    6978 
    70         // Get the dispersion points for the thickness 
    71         vector<WeightPoint> weights_thick; 
    72         thickness.get_weights(weights_thick); 
     79  // Get the dispersion points for the thickness 
     80  vector<WeightPoint> weights_thick; 
     81  thickness.get_weights(weights_thick); 
    7382 
    74         // Perform the computation, with all weight points 
    75         double sum = 0.0; 
    76         double norm = 0.0; 
    77         double vol = 0.0; 
     83  // Perform the computation, with all weight points 
     84  double sum = 0.0; 
     85  double norm = 0.0; 
     86  double vol = 0.0; 
    7887 
    79         // Loop over radius weight points 
    80         for(size_t i=0; i<weights_rad.size(); i++) { 
    81                 dp[1] = weights_rad[i].value; 
     88  // Loop over radius weight points 
     89  for(size_t i=0; i<weights_rad.size(); i++) { 
     90    dp[1] = weights_rad[i].value; 
    8291 
    83                 // Loop over thickness weight points 
    84                 for(size_t j=0; j<weights_thick.size(); j++) { 
    85                         dp[2] = weights_thick[j].value; 
    86                         //Un-normalize SphereForm by volume 
    87                         sum += weights_rad[i].weight 
    88                                 * weights_thick[j].weight * CoreShellForm(dp, q)* pow(weights_rad[i].value+weights_thick[j].value,3); 
     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); 
    8998 
    90                         //Find average volume 
    91                         vol += weights_rad[i].weight * weights_thick[j].weight 
    92                                 * pow(weights_rad[i].value+weights_thick[j].value,3); 
    93                         norm += weights_rad[i].weight 
    94                                 * weights_thick[j].weight; 
    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  } 
    97106 
    98         if (vol != 0.0 && norm != 0.0) { 
    99                 //Re-normalize by avg volume 
    100                 sum = sum/(vol/norm);} 
     107  if (vol != 0.0 && norm != 0.0) { 
     108    //Re-normalize by avg volume 
     109    sum = sum/(vol/norm);} 
    101110 
    102         return sum/norm + background(); 
     111  return sum/norm + background(); 
    103112} 
    104113 
     
    110119 */ 
    111120double CoreShellModel :: operator()(double qx, double qy) { 
    112         double q = sqrt(qx*qx + qy*qy); 
    113         return (*this).operator()(q); 
     121  double q = sqrt(qx*qx + qy*qy); 
     122  return (*this).operator()(q); 
    114123} 
    115124 
     
    122131 */ 
    123132double CoreShellModel :: evaluate_rphi(double q, double phi) { 
    124         return (*this).operator()(q); 
     133  return (*this).operator()(q); 
    125134} 
    126135/** 
     
    129138 */ 
    130139double CoreShellModel :: calculate_ER() { 
    131         CoreShellParameters dp; 
     140  CoreShellParameters dp; 
    132141 
    133         dp.radius     = radius(); 
    134         dp.thickness  = thickness(); 
     142  dp.radius     = radius(); 
     143  dp.thickness  = thickness(); 
    135144 
    136         double rad_out = 0.0; 
     145  double rad_out = 0.0; 
    137146 
    138         // Perform the computation, with all weight points 
    139         double sum = 0.0; 
    140         double norm = 0.0; 
     147  // Perform the computation, with all weight points 
     148  double sum = 0.0; 
     149  double norm = 0.0; 
    141150 
    142151 
    143         // Get the dispersion points for the major shell 
    144         vector<WeightPoint> weights_thickness; 
    145         thickness.get_weights(weights_thickness); 
     152  // Get the dispersion points for the major shell 
     153  vector<WeightPoint> weights_thickness; 
     154  thickness.get_weights(weights_thickness); 
    146155 
    147         // Get the dispersion points for the minor shell 
    148         vector<WeightPoint> weights_radius ; 
    149         radius.get_weights(weights_radius); 
     156  // Get the dispersion points for the minor shell 
     157  vector<WeightPoint> weights_radius ; 
     158  radius.get_weights(weights_radius); 
    150159 
    151         // Loop over major shell weight points 
    152         for(int j=0; j< (int)weights_thickness.size(); j++) { 
    153                 dp.thickness = weights_thickness[j].value; 
    154                 for(int k=0; k< (int)weights_radius.size(); k++) { 
    155                         dp.radius = weights_radius[k].value; 
    156                         sum += weights_thickness[j].weight 
    157                                 * weights_radius[k].weight*(dp.radius+dp.thickness); 
    158                         norm += weights_thickness[j].weight* weights_radius[k].weight; 
    159                 } 
    160         } 
    161         if (norm != 0){ 
    162                 //return the averaged value 
    163                 rad_out =  sum/norm;} 
    164         else{ 
    165                 //return normal value 
    166                 rad_out = (dp.radius+dp.thickness);} 
     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);} 
    167176 
    168         return rad_out; 
     177  return rad_out; 
    169178} 
  • sansmodels/src/c_models/ellipsoid.cpp

    r67424cd r011e0e4  
    1818 *   sansmodels/src/libigor 
    1919 * 
    20  *      TODO: refactor so that we pull in the old sansmodels.c_extensions 
    2120 */ 
    2221 
    2322#include <math.h> 
    24 #include "models.hh" 
    2523#include "parameters.hh" 
    2624#include <stdio.h> 
    2725using namespace std; 
     26#include "ellipsoid.h" 
    2827 
    2928extern "C" { 
    3029        #include "libCylinder.h" 
    3130        #include "libStructureFactor.h" 
    32         #include "ellipsoid.h" 
     31} 
     32 
     33typedef 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 */ 
     52static 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 */ 
     111static 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); 
    33115} 
    34116 
  • sansmodels/src/c_models/models.hh

    r0ba3b08 r011e0e4  
    2727using namespace std; 
    2828 
    29  
    30  
    31 class CoreShellModel{ 
    32 public: 
    33         // Model parameters 
    34         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         // Constructor 
    43         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 parameters 
    55         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         // Constructor 
    70         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 parameters 
    82         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         // Constructor 
    94         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 parameters 
    106         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         // Constructor 
    116         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  
    12529class EllipticalCylinderModel{ 
    12630public: 
Note: See TracChangeset for help on using the changeset viewer.