source: sasview/sansmodels/src/sans/models/c_extensions/ellipsoid.c @ 01de557

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 01de557 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 
[ae3ce4e]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
[44aa1ed]13 *
[ae3ce4e]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;
[44aa1ed]25
[ae3ce4e]26        sin_alpha = sin(angle);
27        cos_alpha = cos(angle);
[44aa1ed]28
[ae3ce4e]29        // Modified length for phase
[44aa1ed]30        length = r_small*sqrt(sin_alpha*sin_alpha +
[ae3ce4e]31                        r_long*r_long/(r_small*r_small)*cos_alpha*cos_alpha);
[44aa1ed]32
[ae3ce4e]33        // Spherical scattering ampliture, with modified length for ellipsoid
[8f20419d]34        sph_func = 3.0*( sin(q*length) - q*length*cos(q*length) ) / (q*q*q*length*length*length);
[44aa1ed]35
[ae3ce4e]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) {
[f10063e]46        double dp[6];
[44aa1ed]47
[ae3ce4e]48        dp[0] = pars->scale;
49        dp[1] = pars->radius_a;
50        dp[2] = pars->radius_b;
[f10063e]51        dp[3] = pars->sldEll;
52        dp[4] = pars->sldSolv;
53        dp[5] = pars->background;
[44aa1ed]54
[ae3ce4e]55        return EllipsoidForm(dp, q);
56}
[44aa1ed]57
[ae3ce4e]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);
[44aa1ed]68}
[ae3ce4e]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));
[44aa1ed]79}
[ae3ce4e]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;
[4628e31]92        double alpha, f, vol, sin_val, cos_val;
[ae3ce4e]93        double answer;
[4628e31]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;
[44aa1ed]98
[ae3ce4e]99    // Ellipsoid orientation
[4628e31]100    cyl_x = sin(theta) * cos(phi);
101    cyl_y = sin(theta) * sin(phi);
102    cyl_z = cos(theta);
[44aa1ed]103
[ae3ce4e]104    // q vector
[8f20419d]105    q_z = 0.0;
[44aa1ed]106
[ae3ce4e]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;
[44aa1ed]110
[ae3ce4e]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    }
[44aa1ed]116
[ae3ce4e]117    // Angle between rotation axis and q vector
118        alpha = acos( cos_val );
[44aa1ed]119
[ae3ce4e]120        // Call the IGOR library function to get the kernel
[df4702f]121        answer = EllipsoidKernel(q, pars->radius_b, pars->radius_a, cos_val);
[44aa1ed]122
[ae3ce4e]123        // Multiply by contrast^2
[f10063e]124        answer *= (pars->sldEll - pars->sldSolv) * (pars->sldEll - pars->sldSolv);
[44aa1ed]125
[ae3ce4e]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;
[44aa1ed]129
[ae3ce4e]130        //convert to [cm-1]
131        answer *= 1.0e8;
[44aa1ed]132
[ae3ce4e]133        //Scale
134        answer *= pars->scale;
[44aa1ed]135
[ae3ce4e]136        // add in the background
137        answer += pars->background;
[44aa1ed]138
[ae3ce4e]139        return answer;
140}
Note: See TracBrowser for help on using the repository browser.