Changeset 8343e18 in sasview for sansmodels/src/c_models


Ignore:
Timestamp:
Jan 4, 2012 6:16: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:
df88829
Parents:
0c2389e
Message:

refactored parallelepiped

Location:
sansmodels/src/c_models
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/c_models/models.hh

    r0c2389e r8343e18  
    2626 
    2727using namespace std; 
    28  
    29  
    30  
    31 class ParallelepipedModel{ 
    32 public: 
    33         // Model parameters 
    34         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         // Constructor 
    46         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  
    5528 
    5629class CSParallelepipedModel{ 
  • sansmodels/src/c_models/parallelepiped.cpp

    r67424cd r8343e18  
    1818 *   sansmodels/src/libigor 
    1919 * 
    20  *      TODO: refactor so that we pull in the old sansmodels.c_extensions 
    2120 *      TODO: add 2D function 
    2221 */ 
     
    3130        #include "libCylinder.h" 
    3231        #include "libStructureFactor.h" 
    33         #include "parallelepiped.h" 
     32} 
     33#include "parallelepiped.h" 
     34 
     35// Convenience parameter structure 
     36typedef 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 
     50static 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 */ 
     87static 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 */ 
     169static 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); 
    34173} 
    35174 
Note: See TracChangeset for help on using the changeset viewer.