source: sasview/sansmodels/src/sans/models/c_extensions/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: 3.6 KB
Line 
1/**
2 * Scattering model for an ellipsoid
3 * @author: Mathieu Doucet / UTK
4 */
5
6#include "ellipsoid.h"
7#include "libCylinder.h"
8#include <math.h>
9#include <stdio.h>
10
11/**
12 * Test kernel for validation
13 *
14 * @param q: q-value
15 * @param r_small: small axis length
16 * @param r_long: rotation axis length
17 * @param angle: angle between rotation axis and q vector
18 * @return: oriented kernel value
19 */
20double kernel(double q, double r_small, double r_long, double angle) {
21        double length;
22        double sin_alpha;
23        double cos_alpha;
24        double sph_func;
25
26        sin_alpha = sin(angle);
27        cos_alpha = cos(angle);
28
29        // Modified length for phase
30        length = r_small*sqrt(sin_alpha*sin_alpha +
31                        r_long*r_long/(r_small*r_small)*cos_alpha*cos_alpha);
32
33        // Spherical scattering ampliture, with modified length for ellipsoid
34        sph_func = 3.0*( sin(q*length) - q*length*cos(q*length) ) / (q*q*q*length*length*length);
35
36        return sph_func*sph_func;
37}
38
39/**
40 * Function to evaluate 1D scattering function
41 * @param pars: parameters of the ellipsoid
42 * @param q: q-value
43 * @return: function value
44 */
45double ellipsoid_analytical_1D(EllipsoidParameters *pars, double q) {
46        double dp[6];
47
48        dp[0] = pars->scale;
49        dp[1] = pars->radius_a;
50        dp[2] = pars->radius_b;
51        dp[3] = pars->sldEll;
52        dp[4] = pars->sldSolv;
53        dp[5] = pars->background;
54
55        return EllipsoidForm(dp, q);
56}
57
58/**
59 * Function to evaluate 2D scattering function
60 * @param pars: parameters of the ellipsoid
61 * @param q: q-value
62 * @return: function value
63 */
64double ellipsoid_analytical_2DXY(EllipsoidParameters *pars, double qx, double qy) {
65        double q;
66        q = sqrt(qx*qx+qy*qy);
67    return ellipsoid_analytical_2D_scaled(pars, q, qx/q, qy/q);
68}
69
70/**
71 * Function to evaluate 2D scattering function
72 * @param pars: parameters of the ellipsoid
73 * @param q: q-value
74 * @param phi: angle phi
75 * @return: function value
76 */
77double ellipsoid_analytical_2D(EllipsoidParameters *pars, double q, double phi) {
78    return ellipsoid_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
79}
80
81/**
82 * Function to evaluate 2D scattering function
83 * @param pars: parameters of the ellipsoid
84 * @param q: q-value
85 * @param q_x: q_x / q
86 * @param q_y: q_y / q
87 * @return: function value
88 */
89double ellipsoid_analytical_2D_scaled(EllipsoidParameters *pars, double q, double q_x, double q_y) {
90        double cyl_x, cyl_y, cyl_z;
91        double q_z, lenq;
92        double alpha, f, vol, sin_val, cos_val;
93        double answer;
94        //convert angle degree to radian
95        double pi = 4.0*atan(1.0);
96        double theta = pars->axis_theta * pi/180.0;
97        double phi = pars->axis_phi * pi/180.0;
98
99    // Ellipsoid 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    // Compute the angle btw vector q and the
108    // axis of the cylinder
109    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
110
111    // The following test should always pass
112    if (fabs(cos_val)>1.0) {
113        printf("ellipsoid_ana_2D: Unexpected error: cos(alpha)>1\n");
114        return 0;
115    }
116
117    // Angle between rotation axis and q vector
118        alpha = acos( cos_val );
119
120        // Call the IGOR library function to get the kernel
121        answer = EllipsoidKernel(q, pars->radius_b, pars->radius_a, cos_val);
122
123        // Multiply by contrast^2
124        answer *= (pars->sldEll - pars->sldSolv) * (pars->sldEll - pars->sldSolv);
125
126        //normalize by cylinder volume
127    vol = 4.0/3.0 * acos(-1.0) * pars->radius_b * pars->radius_b * pars->radius_a;
128        answer *= vol;
129
130        //convert to [cm-1]
131        answer *= 1.0e8;
132
133        //Scale
134        answer *= pars->scale;
135
136        // add in the background
137        answer += pars->background;
138
139        return answer;
140}
Note: See TracBrowser for help on using the repository browser.