source: sasview/sansmodels/src/sans/models/c_extensions/sc.c @ d6da3b1

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 d6da3b1 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.6 KB
RevLine 
[94a3f8f]1/*
2 * Scattering model for a SC_ParaCrystal
3 */
4#include "sc.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 SC_ParaCrystal
12 * @param q: q-value
13 * @return: function value
14 */
15double sc_analytical_1D(SCParameters *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 = SC_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 SC_ParaCrystal
38 * @param q: q-value
39 * @return: function value
40 */
41double sc_analytical_2DXY(SCParameters *pars, double qx, double qy){
42        double q;
43        q = sqrt(qx*qx+qy*qy);
44        return sc_analytical_2D_scaled(pars, q, qx/q, qy/q);
45}
46
47double sc_analytical_2D(SCParameters *pars, double q, double phi) {
48        return sc_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 SCCrystalModel
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 sc_analytical_2D_scaled(SCParameters *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, a1_z;
61        double q_z;
[d5b6a9d]62        double alpha, vol, cos_val_a3, cos_val_a2, cos_val_a1;
[94a3f8f]63        double a1_dot_q, a2_dot_q,a3_dot_q;
64        double answer;
65        double Pi = 4.0*atan(1.0);
66        double aa, Da, qDa_2, latticeScale, Zq;
67
68        double dp[5];
69        dp[0] = 1.0;
70        dp[1] = pars->radius;
71        dp[2] = pars->sldSph;
72        dp[3] = pars->sldSolv;
73        dp[4] = 0.0;
74
[4628e31]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
[94a3f8f]80        aa = pars->dnn;
81        Da = pars->d_factor*aa;
82        qDa_2 = pow(q*Da,2.0);
83
84        latticeScale = (4.0/3.0)*Pi*(dp[1]*dp[1]*dp[1])/pow(aa,3.0);
85        /// Angles here are respect to detector coordinate instead of against q coordinate(PRB 36, 3, 1754)
86    // a3 axis orientation
[4628e31]87    a3_x = sin(theta) * cos(phi);//negative sign here???
88    a3_y = sin(theta) * sin(phi);
89    a3_z = cos(theta);
[94a3f8f]90
91    // q vector
92    q_z = 0.0;
93
94    // Compute the angle btw vector q and the a3 axis
95    cos_val_a3 = a3_x*q_x + a3_y*q_y + a3_z*q_z;
[18f2ca1]96    alpha = acos(cos_val_a3);
[94a3f8f]97    //alpha = acos(cos_val_a3);
98    a3_dot_q = aa*q*cos_val_a3;
99    // a1 axis orientation
[4628e31]100    a1_x = sin(psi);
101    a1_y = cos(psi);
[94a3f8f]102
103    cos_val_a1 = a1_x*q_x + a1_y*q_y;
[18f2ca1]104    a1_dot_q = aa*q*cos_val_a1*sin(alpha);
[94a3f8f]105
106    // a2 axis orientation
[4628e31]107    a2_x = sqrt(1.0-sin(theta)*cos(phi))*cos(psi);
108    a2_y = sqrt(1.0-sin(theta)*cos(phi))*sin(psi);
[94a3f8f]109    // a2 axis
[18f2ca1]110    cos_val_a2 =  sin(acos(cos_val_a1));//a2_x*q_x + a2_y*q_y;
111    a2_dot_q = aa*q*cos_val_a2*sin(alpha);
[94a3f8f]112
113    // The following test should always pass
114    if (fabs(cos_val_a3)>1.0) {
115        printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n");
116        return 0;
117    }
118    // Call Zq=Z1*Z2*Z3
119    Zq = (1.0-exp(-qDa_2))/(1.0-2.0*exp(-0.5*qDa_2)*cos(a1_dot_q)+exp(-qDa_2));
120    Zq = Zq * (1.0-exp(-qDa_2))/(1.0-2.0*exp(-0.5*qDa_2)*cos(a2_dot_q)+exp(-qDa_2));
121    Zq = Zq * (1.0-exp(-qDa_2))/(1.0-2.0*exp(-0.5*qDa_2)*cos(a3_dot_q)+exp(-qDa_2));
122
123        // Use SphereForm directly from libigor
124        answer = SphereForm(dp,q)*Zq;
125
126        //consider scales
127        answer *= latticeScale * pars->scale;
128
129        // This FIXES a singualrity the kernel in libigor.
130        if ( answer == INFINITY || answer == NAN){
131                answer = 0.0;
132        }
133
134        // add background
135        answer += pars->background;
136
137        return answer;
138}
Note: See TracBrowser for help on using the repository browser.