source: sasview/sansmodels/src/sans/models/c_extensions/ellipsoid.c @ 43ecc75f

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 43ecc75f was f10063e, checked in by Jae Cho <jhjcho@…>, 15 years ago

Updated the definition of SLD params according to new libigor functions

  • Property mode set to 100644
File size: 3.5 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*( 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 theta, alpha, f, vol, sin_val, cos_val;
93        double answer;
94
95    // Ellipsoid orientation
96    cyl_x = sin(pars->axis_theta) * cos(pars->axis_phi);
97    cyl_y = sin(pars->axis_theta) * sin(pars->axis_phi);
98    cyl_z = cos(pars->axis_theta);
99
100    // q vector
101    q_z = 0;
102
103    // Compute the angle btw vector q and the
104    // axis of the cylinder
105    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
106
107    // The following test should always pass
108    if (fabs(cos_val)>1.0) {
109        printf("ellipsoid_ana_2D: Unexpected error: cos(alpha)>1\n");
110        return 0;
111    }
112
113    // Angle between rotation axis and q vector
114        alpha = acos( cos_val );
115
116        // Call the IGOR library function to get the kernel
117        answer = EllipsoidKernel(q, pars->radius_b, pars->radius_a, cos_val);
118
119        // Multiply by contrast^2
120        answer *= (pars->sldEll - pars->sldSolv) * (pars->sldEll - pars->sldSolv);
121
122        //normalize by cylinder volume
123    vol = 4.0/3.0 * acos(-1.0) * pars->radius_b * pars->radius_b * pars->radius_a;
124        answer *= vol;
125
126        //convert to [cm-1]
127        answer *= 1.0e8;
128
129        //Scale
130        answer *= pars->scale;
131
132        // add in the background
133        answer += pars->background;
134
135        return answer;
136}
Note: See TracBrowser for help on using the repository browser.