source: sasview/sansmodels/src/sans/models/c_extensions/fcc.c @ fe10df5

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since fe10df5 was 4628e31, checked in by Jae Cho <jhjcho@…>, 14 years ago

changed the unit of angles into degrees

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Scattering model for a SC_ParaCrystal
3 */
4#include "fcc.h"
5#include "libSphere.h"
6#include <math.h>
7
8
9/**
10 * Function to evaluate 1D scattering function
11 * @param pars: parameters of the FCC_ParaCrystal
12 * @param q: q-value
13 * @return: function value
14 */
15double fcc_analytical_1D(FCParameters *pars, double q) {
16        double dp[7];
17        double result;
18
19        dp[0] = pars->scale;
20        dp[1] = pars->dnn;
21        dp[2] = pars->d_factor;
22        dp[3] = pars->radius;
23        dp[4] = pars->sldSph;
24        dp[5] = pars->sldSolv;
25        dp[6] = pars->background;
26
27        result = FCC_ParaCrystal(dp, q);
28        // This FIXES a singualrity the kernel in libigor.
29        if ( result == INFINITY || result == NAN){
30                result = pars->background;
31        }
32        return result;
33}
34
35/**
36 * Function to evaluate 2D scattering function
37 * @param pars: parameters of the FCC_ParaCrystal
38 * @param q: q-value
39 * @return: function value
40 */
41double fc_analytical_2DXY(FCParameters *pars, double qx, double qy){
42        double q;
43        q = sqrt(qx*qx+qy*qy);
44        return fc_analytical_2D_scaled(pars, q, qx/q, qy/q);
45}
46
47double fc_analytical_2D(FCParameters *pars, double q, double phi) {
48        return fc_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
49}
50
51/**
52 * Function to evaluate 2D scattering function
53 * @param pars: parameters of the FCCCrystalModel
54 * @param q: q-value
55 * @param q_x: q_x / q
56 * @param q_y: q_y / q
57 * @return: function value
58 */
59double fc_analytical_2D_scaled(FCParameters *pars, double q, double q_x, double q_y) {
60        double a3_x, a3_y, a3_z, a2_x, a2_y, a1_x, a1_y;
61        double b3_x, b3_y, b3_z, b2_x, b2_y, b1_x, b1_y;
62        double q_z;
63        double alpha, vol, cos_val_b3, cos_val_b2, cos_val_b1, cos_val_a3, cos_val_a2, cos_val_a1;
64        double a1_dot_q, a2_dot_q,a3_dot_q;
65        double answer;
66        double Pi = 4.0*atan(1.0);
67        double aa, Da, qDa_2, latticeScale, Zq, Fkq, Fkq_2,contrast;
68
69        double dp[5];
70        dp[0] = 1.0;
71        dp[1] = pars->radius;
72        dp[2] = pars->sldSph;
73        dp[3] = pars->sldSolv;
74        dp[4] = 0.0;
75        //convert angle degree to radian
76        double theta = pars->theta * Pi/180.0;
77        double phi = pars->phi * Pi/180.0;
78        double psi = pars->psi * Pi/180.0;
79
80        aa = pars->dnn;
81        Da = pars->d_factor*aa;
82        qDa_2 = pow(q*Da,2.0);
83        //contrast = pars->sldSph - pars->sldSolv;
84
85        latticeScale = 4.0*(4.0/3.0)*Pi*(dp[1]*dp[1]*dp[1])/pow(aa*sqrt(2.0),3.0);
86        // q vector
87        q_z = 0.0; // for SANS; assuming qz is negligible
88        /// Angles here are respect to detector coordinate
89        ///  instead of against q coordinate in PRB 36(46), 3(6), 1754(3854)
90    // b3 axis orientation
91    b3_x = sin(theta) * cos(phi);//negative sign here???
92    b3_y = sin(theta) * sin(phi);
93    b3_z = cos(theta);
94    cos_val_b3 =  b3_x*q_x + b3_y*q_y + b3_z*q_z;
95    alpha = acos(cos_val_b3);
96    // b1 axis orientation
97    b1_x = sin(psi);
98    b1_y = cos(psi);
99        cos_val_b1 = (b1_x*q_x + b1_y*q_y);
100    // b2 axis orientation
101        cos_val_b2 = sin(acos(cos_val_b1));
102        // alpha correction
103        cos_val_b2 *= sin(alpha);
104        cos_val_b1 *= sin(alpha);
105
106    // Compute the angle btw vector q and the a3 axis
107    a3_dot_q = 0.5*aa*q*(cos_val_b2+cos_val_b1);
108
109    // a1 axis
110    a1_dot_q = 0.5*aa*q*(cos_val_b2+cos_val_b3);
111
112    // a2 axis
113    a2_dot_q = 0.5*aa*q*(cos_val_b3+cos_val_b1);
114
115    // The following test should always pass
116    if (fabs(cos_val_b3)>1.0) {
117        printf("fcc_ana_2D: Unexpected error: cos(alpha)>1\n");
118        return 0;
119    }
120    // Get Fkq and Fkq_2
121    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));
122    Fkq_2 = Fkq*Fkq;
123    // Call Zq=Z1*Z2*Z3
124    Zq = (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a1_dot_q)+Fkq_2);
125    Zq = Zq * (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a2_dot_q)+Fkq_2);
126    Zq = Zq * (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a3_dot_q)+Fkq_2);
127
128        // Use SphereForm directly from libigor
129        answer = SphereForm(dp,q)*Zq;
130
131        //consider scales
132        answer *= latticeScale * pars->scale;
133
134        // This FIXES a singualrity the kernel in libigor.
135        if ( answer == INFINITY || answer == NAN){
136                answer = 0.0;
137        }
138
139        // add background
140        answer += pars->background;
141
142        return answer;
143}
Note: See TracBrowser for help on using the repository browser.