Changeset 0ba3b08 in sasview for sansmodels/src/c_models/bcc.cpp
- Timestamp:
- Jan 5, 2012 12:16:29 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:
- 011e0e4
- Parents:
- bbbed8c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/c_models/bcc.cpp
r67424cd r0ba3b08 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 "bcc.h" 27 27 28 28 extern "C" { 29 29 #include "libSphere.h" 30 #include "bcc.h" 30 } 31 32 // Convenience structure 33 typedef struct { 34 double scale; 35 double dnn; 36 double d_factor; 37 double radius; 38 double sldSph; 39 double sldSolv; 40 double background; 41 double theta; 42 double phi; 43 double psi; 44 45 } BCParameters; 46 47 /** 48 * Function to evaluate 2D scattering function 49 * @param pars: parameters of the BCCCrystalModel 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 bc_analytical_2D_scaled(BCParameters *pars, double q, double q_x, double q_y) { 56 double b3_x, b3_y, b3_z, b1_x, b1_y; 57 double q_z; 58 double alpha, cos_val_b3, cos_val_b2, cos_val_b1; 59 double a1_dot_q, a2_dot_q,a3_dot_q; 60 double answer; 61 double Pi = 4.0*atan(1.0); 62 double aa, Da, qDa_2, latticeScale, Zq, Fkq, Fkq_2; 63 64 //convert angle degree to radian 65 double pi = 4.0*atan(1.0); 66 double theta = pars->theta * pi/180.0; 67 double phi = pars->phi * pi/180.0; 68 double psi = pars->psi * pi/180.0; 69 70 double dp[5]; 71 dp[0] = 1.0; 72 dp[1] = pars->radius; 73 dp[2] = pars->sldSph; 74 dp[3] = pars->sldSolv; 75 dp[4] = 0.0; 76 77 aa = pars->dnn; 78 Da = pars->d_factor*aa; 79 qDa_2 = pow(q*Da,2.0); 80 81 //the occupied volume of the lattice 82 latticeScale = 2.0*(4.0/3.0)*Pi*(dp[1]*dp[1]*dp[1])/pow(aa/sqrt(3.0/4.0),3.0); 83 // q vector 84 q_z = 0.0; // for SANS; assuming qz is negligible 85 /// Angles here are respect to detector coordinate 86 /// instead of against q coordinate(PRB 36(46), 3(6), 1754(3854)) 87 // b3 axis orientation 88 b3_x = sin(theta) * cos(phi);//negative sign here??? 89 b3_y = sin(theta) * sin(phi); 90 b3_z = cos(theta); 91 cos_val_b3 = b3_x*q_x + b3_y*q_y + b3_z*q_z; 92 93 alpha = acos(cos_val_b3); 94 // b1 axis orientation 95 b1_x = sin(psi); 96 b1_y = cos(psi); 97 cos_val_b1 = (b1_x*q_x + b1_y*q_y); 98 // b2 axis orientation 99 cos_val_b2 = sin(acos(cos_val_b1)); 100 // alpha corrections 101 cos_val_b2 *= sin(alpha); 102 cos_val_b1 *= sin(alpha); 103 104 // Compute the angle btw vector q and the a3 axis 105 a3_dot_q = 0.5*aa*q*(cos_val_b2+cos_val_b1-cos_val_b3); 106 107 // a1 axis 108 a1_dot_q = 0.5*aa*q*(cos_val_b3+cos_val_b2-cos_val_b1); 109 110 // a2 axis 111 a2_dot_q = 0.5*aa*q*(cos_val_b3+cos_val_b1-cos_val_b2); 112 113 // The following test should always pass 114 if (fabs(cos_val_b3)>1.0) { 115 printf("bcc_ana_2D: Unexpected error: cos(alpha)>1\n"); 116 return 0; 117 } 118 // Get Fkq and Fkq_2 119 Fkq = exp(-0.5*pow(Da/aa,2.0)*(a1_dot_q*a1_dot_q+a2_dot_q*a2_dot_q+a3_dot_q*a3_dot_q)); 120 Fkq_2 = Fkq*Fkq; 121 // Call Zq=Z1*Z2*Z3 122 Zq = (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a1_dot_q)+Fkq_2); 123 Zq *= (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a2_dot_q)+Fkq_2); 124 Zq *= (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a3_dot_q)+Fkq_2); 125 126 // Use SphereForm directly from libigor 127 answer = SphereForm(dp,q)*Zq; 128 129 //consider scales 130 answer *= latticeScale * pars->scale; 131 132 // This FIXES a singualrity the kernel in libigor. 133 if ( answer == INFINITY || answer == NAN){ 134 answer = 0.0; 135 } 136 137 // add background 138 answer += pars->background; 139 140 return answer; 141 } 142 143 /** 144 * Function to evaluate 2D scattering function 145 * @param pars: parameters of the BCC_ParaCrystal 146 * @param q: q-value 147 * @return: function value 148 */ 149 static double bc_analytical_2DXY(BCParameters *pars, double qx, double qy){ 150 double q; 151 q = sqrt(qx*qx+qy*qy); 152 return bc_analytical_2D_scaled(pars, q, qx/q, qy/q); 31 153 } 32 154
Note: See TracChangeset
for help on using the changeset viewer.