Changeset 0c2389e in sasview


Ignore:
Timestamp:
Jan 4, 2012 6:00:52 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:
8343e18
Parents:
dbddbf5
Message:

refactored capped cylinder

Location:
sansmodels/src
Files:
2 deleted
5 edited

Legend:

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

    r67424cd r0c2389e  
    11#if !defined(capcyl_h) 
    22#define capcyl_h 
     3#include "parameters.hh" 
    34 
    45/** 
     
    2728 //[ORIENTATION_PARAMS]= <text> phi; theta; phi.width; theta.width</text> 
    2829 
    29 typedef struct { 
    30     /// Scale factor 
    31     //  [DEFAULT]=scale= 1.0 
    32     double scale; 
     30class CappedCylinderModel{ 
     31public: 
     32  // Model parameters 
     33  /// Scale factor 
     34  //  [DEFAULT]=scale= 1.0 
     35  Parameter scale; 
    3336 
    34     /// rad_cyl [A] 
    35     //  [DEFAULT]=rad_cyl=20.0 [A] 
    36     double rad_cyl; 
     37  /// rad_cyl [A] 
     38  //  [DEFAULT]=rad_cyl=20.0 [A] 
     39  Parameter rad_cyl; 
    3740 
    38     /// length of the cylinder 
    39     //  [DEFAULT]=len_cyl=400.0 [A] 
    40     double len_cyl; 
     41  /// length of the cylinder 
     42  //  [DEFAULT]=len_cyl=400.0 [A] 
     43  Parameter len_cyl; 
    4144 
    42     /// Radius of sphere [A] 
    43     //  [DEFAULT]=rad_cap=40.0 [A] 
    44     double rad_cap; 
     45  /// Radius of sphere [A] 
     46  //  [DEFAULT]=rad_cap=40.0 [A] 
     47  Parameter rad_cap; 
    4548 
    46     /// sld_capcyl [1/A^(2)] 
    47     //  [DEFAULT]=sld_capcyl= 1.0e-6 [1/A^(2)] 
    48     double sld_capcyl; 
     49  /// sld_capcyl [1/A^(2)] 
     50  //  [DEFAULT]=sld_capcyl= 1.0e-6 [1/A^(2)] 
     51  Parameter sld_capcyl; 
    4952 
    50     /// sld_solv [1/A^(2)] 
    51     //  [DEFAULT]=sld_solv= 6.3e-6 [1/A^(2)] 
    52     double sld_solv; 
     53  /// sld_solv [1/A^(2)] 
     54  //  [DEFAULT]=sld_solv= 6.3e-6 [1/A^(2)] 
     55  Parameter sld_solv; 
    5356 
    54         /// Incoherent Background [1/cm] 
    55         //  [DEFAULT]=background=0.0 [1/cm] 
    56         double background; 
     57  /// Incoherent Background [1/cm] 
     58  //  [DEFAULT]=background=0.0 [1/cm] 
     59  Parameter background; 
    5760 
    58     /// Angle of the main axis against z-axis in detector plane [deg] 
    59     //  [DEFAULT]=theta=0.0 [deg] 
    60     double theta; 
    61     /// Azimuthal angle around z-axis in detector plane [deg] 
    62     //  [DEFAULT]=phi=0.0 [deg] 
    63     double phi; 
     61  /// Angle of the main axis against z-axis in detector plane [deg] 
     62  //  [DEFAULT]=theta=0.0 [deg] 
     63  Parameter theta; 
    6464 
    65 } CapCylParameters; 
     65  /// Azimuthal angle around z-axis in detector plane [deg] 
     66  //  [DEFAULT]=phi=0.0 [deg] 
     67  Parameter phi; 
    6668 
     69  // Constructor 
     70  CappedCylinderModel(); 
    6771 
    68  
    69 /// 1D scattering function 
    70 double capcyl_analytical_1D(CapCylParameters *pars, double q); 
    71  
    72 /// 2D scattering function 
    73 double capcyl_analytical_2D(CapCylParameters *pars, double q, double phi); 
    74 double capcyl_analytical_2DXY(CapCylParameters *pars, double qx, double qy); 
    75 double capcyl_analytical_2D_scaled(CapCylParameters *pars, double q, double q_x, double q_y); 
     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}; 
    7678 
    7779#endif 
  • sansmodels/src/c_models/capcyl.cpp

    r67424cd r0c2389e  
    2121 
    2222#include <math.h> 
    23 #include "models.hh" 
    2423#include "parameters.hh" 
    2524#include <stdio.h> 
     
    2726 
    2827extern "C" { 
     28  #include "GaussWeights.h" 
    2929        #include "libCylinder.h" 
    30         #include "capcyl.h" 
    31 } 
     30} 
     31#include "capcyl.h" 
     32 
     33// Convenience parameter structure 
     34typedef struct { 
     35    double scale; 
     36    double rad_cyl; 
     37    double len_cyl; 
     38    double rad_cap; 
     39    double sld_capcyl; 
     40    double sld_solv; 
     41    double background; 
     42    double theta; 
     43    double phi; 
     44} CapCylParameters; 
    3245 
    3346CappedCylinderModel :: CappedCylinderModel() { 
     
    4457        theta  = Parameter(0.0, true); 
    4558        phi    = Parameter(0.0, true); 
     59} 
     60 
     61static double capcyl2d_kernel(double dp[], double q, double alpha) { 
     62  int j; 
     63  double Pi; 
     64  double scale,contr,bkg,sldc,slds; 
     65  double len,rad,hDist,endRad; 
     66  int nordj=76; 
     67  double zi=alpha,yyy,answer;     //running tally of integration 
     68  double summj,vaj,vbj,zij;     //for the inner integration 
     69  double arg1,arg2,inner,be; 
     70 
     71 
     72  scale = dp[0]; 
     73  rad = dp[1]; 
     74  len = dp[2]; 
     75  endRad = dp[3]; 
     76  sldc = dp[4]; 
     77  slds = dp[5]; 
     78  bkg = dp[6]; 
     79 
     80  hDist = -1.0*sqrt(fabs(endRad*endRad-rad*rad));   //by definition for this model 
     81 
     82  contr = sldc-slds; 
     83 
     84  Pi = 4.0*atan(1.0); 
     85  vaj = -1.0*hDist/endRad; 
     86  vbj = 1.0;    //endpoints of inner integral 
     87 
     88  summj=0.0; 
     89 
     90  for(j=0;j<nordj;j++) { 
     91    //20 gauss points for the inner integral 
     92    zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;    //the "t" dummy 
     93    yyy = Gauss76Wt[j] * ConvLens_kernel(dp,q,zij,zi);    //uses the same Kernel as the Dumbbell, here L>0 
     94    summj += yyy; 
     95  } 
     96  //now calculate the value of the inner integral 
     97  inner = (vbj-vaj)/2.0*summj; 
     98  inner *= 4.0*Pi*endRad*endRad*endRad; 
     99 
     100  //now calculate outer integrand 
     101  arg1 = q*len/2.0*cos(zi); 
     102  arg2 = q*rad*sin(zi); 
     103  yyy = inner; 
     104 
     105  if(arg2 == 0) { 
     106    be = 0.5; 
     107  } else { 
     108    be = NR_BessJ1(arg2)/arg2; 
     109  } 
     110 
     111  if(arg1 == 0.0) {   //limiting value of sinc(0) is 1; sinc is not defined in math.h 
     112    yyy += Pi*rad*rad*len*2.0*be; 
     113  } else { 
     114    yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be; 
     115  } 
     116  yyy *= yyy;   //sin(zi); 
     117  answer = yyy; 
     118 
     119 
     120  answer /= Pi*rad*rad*len + 2.0*Pi*(2.0*endRad*endRad*endRad/3.0+endRad*endRad*hDist-hDist*hDist*hDist/3.0);   //divide by volume 
     121  answer *= 1.0e8;    //convert to cm^-1 
     122  answer *= contr*contr; 
     123  answer *= scale; 
     124  answer += bkg; 
     125 
     126  return answer; 
     127} 
     128 
     129/** 
     130 * Function to evaluate 2D scattering function 
     131 * @param pars: parameters of the BarBell 
     132 * @param q: q-value 
     133 * @param q_x: q_x / q 
     134 * @param q_y: q_y / q 
     135 * @return: function value 
     136 */ 
     137static double capcyl_analytical_2D_scaled(CapCylParameters *pars, double q, double q_x, double q_y) { 
     138  double cyl_x, cyl_y, cyl_z; 
     139  double q_z; 
     140  double alpha, cos_val; 
     141  double answer; 
     142  double dp[7]; 
     143  //convert angle degree to radian 
     144  double pi = 4.0*atan(1.0); 
     145  double theta = pars->theta * pi/180.0; 
     146  double phi = pars->phi * pi/180.0; 
     147 
     148  dp[0] = pars->scale; 
     149  dp[1] = pars->rad_cyl; 
     150  dp[2] = pars->len_cyl; 
     151  dp[3] = pars->rad_cap; 
     152  dp[4] = pars->sld_capcyl; 
     153  dp[5] = pars->sld_solv; 
     154  dp[6] = pars->background; 
     155 
     156 
     157  //double Pi = 4.0*atan(1.0); 
     158    // Cylinder orientation 
     159    cyl_x = sin(theta) * cos(phi); 
     160    cyl_y = sin(theta) * sin(phi); 
     161    cyl_z = cos(theta); 
     162 
     163    // q vector 
     164    q_z = 0; 
     165 
     166    // Compute the angle btw vector q and the 
     167    // axis of the cylinder 
     168    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 
     169 
     170    // The following test should always pass 
     171    if (fabs(cos_val)>1.0) { 
     172      printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     173      return 0; 
     174    } 
     175 
     176    // Note: cos(alpha) = 0 and 1 will get an 
     177    // undefined value from CylKernel 
     178  alpha = acos( cos_val ); 
     179 
     180  // Call the IGOR library function to get the kernel 
     181  answer = capcyl2d_kernel(dp, q, alpha)/sin(alpha); 
     182 
     183 
     184  return answer; 
     185 
     186} 
     187 
     188/** 
     189 * Function to evaluate 2D scattering function 
     190 * @param pars: parameters of the BarBell 
     191 * @param q: q-value 
     192 * @return: function value 
     193 */ 
     194static double capcyl_analytical_2DXY(CapCylParameters *pars, double qx, double qy){ 
     195  double q; 
     196  q = sqrt(qx*qx+qy*qy); 
     197  return capcyl_analytical_2D_scaled(pars, q, qx/q, qy/q); 
    46198} 
    47199 
  • sansmodels/src/c_models/cylinder.cpp

    rdbddbf5 r0c2389e  
    2828        #include "libCylinder.h" 
    2929        #include "libStructureFactor.h" 
    30         #include "cylinder.h" 
    31 } 
     30} 
     31#include "cylinder.h" 
    3232 
    3333// Convenience parameter structure 
  • sansmodels/src/c_models/models.hh

    rdbddbf5 r0c2389e  
    2727using namespace std; 
    2828 
    29  
    30 class CappedCylinderModel{ 
    31 public: 
    32         // Model parameters 
    33         Parameter scale; 
    34         Parameter rad_cyl; 
    35         Parameter len_cyl; 
    36         Parameter rad_cap; 
    37         Parameter sld_capcyl; 
    38         Parameter sld_solv; 
    39         Parameter background; 
    40         Parameter theta; 
    41         Parameter phi; 
    42  
    43         // Constructor 
    44         CappedCylinderModel(); 
    45  
    46         // Operators to get I(Q) 
    47         double operator()(double q); 
    48         double operator()(double qx, double qy); 
    49         double calculate_ER(); 
    50         double evaluate_rphi(double q, double phi); 
    51 }; 
    5229 
    5330 
  • sansmodels/src/python_wrapper/CCappedCylinderModel.cpp

    r67424cd r0c2389e  
    1818 * 
    1919 * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY 
    20  *          DO NOT MODIFY THIS FILE, MODIFY capcyl.h 
     20 *          DO NOT MODIFY THIS FILE, MODIFY ../c_extensions/capcyl.h 
    2121 *          AND RE-RUN THE GENERATOR SCRIPT 
    2222 * 
     
    3333#include <math.h> 
    3434#include <time.h> 
     35 
     36} 
     37 
    3538#include "capcyl.h" 
    36 } 
    37  
    38 #include "models.hh" 
    3939#include "dispersion_visitor.hh" 
    4040 
Note: See TracChangeset for help on using the changeset viewer.