source: sasview/sansmodels/src/sans/models/c_extensions/triaxial_ellipsoid.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: 4.3 KB
Line 
1/**
2 * Scattering model for a cylinder
3 * @author: Mathieu Doucet / UTK
4 */
5
6#include "triaxial_ellipsoid.h"
7#include <math.h>
8#include "libCylinder.h"
9#include <stdio.h>
10#include <stdlib.h>
11
12
13/**
14 * Function to evaluate 1D scattering function
15 * @param pars: parameters of the triaxial ellipsoid
16 * @param q: q-value
17 * @return: function value
18 */
19double triaxial_ellipsoid_analytical_1D(TriaxialEllipsoidParameters *pars, double q) {
20        double dp[7];
21
22        // Fill paramater array
23        dp[0] = pars->scale;
24        dp[1] = pars->semi_axisA;
25        dp[2] = pars->semi_axisB;
26        dp[3] = pars->semi_axisC;
27        dp[4] = pars->sldEll;
28        dp[5] = pars->sldSolv;
29        dp[6] = pars->background;
30
31        // Call library function to evaluate model
32        return TriaxialEllipsoid(dp, q);
33}
34
35double triaxial_ellipsoid_kernel(TriaxialEllipsoidParameters *pars, double q, double alpha, double nu) {
36        double t,a,b,c;
37        double kernel;
38        double pi = 4.0*atan(1.0);
39
40        a = pars->semi_axisA ;
41        b = pars->semi_axisB ;
42        c = pars->semi_axisC ;
43
44        t = q * sqrt(a*a*cos(nu)*cos(nu)+b*b*sin(nu)*sin(nu)*sin(alpha)*sin(alpha)+c*c*cos(alpha)*cos(alpha));
45        if (t==0.0){
46                kernel  = 1.0;
47        }else{
48                kernel  = 3.0*(sin(t)-t*cos(t))/(t*t*t);
49        }
50        return kernel*kernel;
51}
52
53
54/**
55 * Function to evaluate 2D scattering function
56 * @param pars: parameters of the triaxial ellipsoid
57 * @param q: q-value
58 * @return: function value
59 */
60double triaxial_ellipsoid_analytical_2DXY(TriaxialEllipsoidParameters *pars, double qx, double qy) {
61        double q;
62        q = sqrt(qx*qx+qy*qy);
63    return triaxial_ellipsoid_analytical_2D_scaled(pars, q, qx/q, qy/q);
64}
65
66
67/**
68 * Function to evaluate 2D scattering function
69 * @param pars: parameters of the triaxial ellipsoid
70 * @param q: q-value
71 * @param phi: angle phi
72 * @return: function value
73 */
74double triaxial_ellipsoid_analytical_2D(TriaxialEllipsoidParameters *pars, double q, double phi) {
75    return triaxial_ellipsoid_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
76}
77
78/**
79 * Function to evaluate 2D scattering function
80 * @param pars: parameters of the triaxial ellipsoid
81 * @param q: q-value
82 * @param q_x: q_x / q
83 * @param q_y: q_y / q
84 * @return: function value
85 */
86double triaxial_ellipsoid_analytical_2D_scaled(TriaxialEllipsoidParameters *pars, double q, double q_x, double q_y) {
87        double cyl_x, cyl_y, cyl_z, ell_x, ell_y;
88        double q_z;
89        double cos_nu,nu;
90        double alpha, vol, cos_val;
91        double answer;
92    double pi = 4.0*atan(1.0);
93
94        //convert angle degree to radian
95        double theta = pars->axis_theta * pi/180.0;
96        double phi = pars->axis_phi * pi/180.0;
97        double psi = pars->axis_psi * pi/180.0;
98
99    // Cylinder orientation
100    cyl_x = sin(theta) * cos(phi);
101    cyl_y = sin(theta) * sin(phi);
102    cyl_z = cos(theta);
103
104    // q vector
105    q_z = 0.0;
106
107        //dx = 1.0;
108        //dy = 1.0;
109    // Compute the angle btw vector q and the
110    // axis of the cylinder
111    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
112
113    // The following test should always pass
114    if (fabs(cos_val)>1.0) {
115        printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n");
116        return 0;
117    }
118
119    // Note: cos(alpha) = 0 and 1 will get an
120    // undefined value from CylKernel
121        alpha = acos( cos_val );
122
123    //ellipse orientation:
124        // the elliptical corss section was transformed and projected
125        // into the detector plane already through sin(alpha)and furthermore psi remains as same
126        // on the detector plane.
127        // So, all we need is to calculate the angle (nu) of the minor axis of the ellipse wrt
128        // the wave vector q.
129
130        //x- y- component on the detector plane.
131    ell_x =  cos(psi);
132    ell_y =  sin(psi);
133
134    // calculate the axis of the ellipse wrt q-coord.
135    cos_nu = ell_x*q_x + ell_y*q_y;
136    nu = acos(cos_nu);
137
138        // Call the IGOR library function to get the kernel
139        answer = triaxial_ellipsoid_kernel(pars, q, alpha, nu);
140
141        // Multiply by contrast^2
142        answer *= (pars->sldEll- pars->sldSolv)*(pars->sldEll- pars->sldSolv);
143
144        //normalize by cylinder volume
145        //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
146    vol = 4.0* pi/3.0  * pars->semi_axisA * pars->semi_axisB * pars->semi_axisC;
147        answer *= vol;
148        //convert to [cm-1]
149        answer *= 1.0e8;
150        //Scale
151        answer *= pars->scale;
152
153        // add in the background
154        answer += pars->background;
155
156        return answer;
157}
Note: See TracBrowser for help on using the repository browser.