source: sasview/sansmodels/src/sans/models/c_extensions/triaxial_ellipsoid.c @ 97603c0

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 97603c0 was 3c102d4, checked in by Jae Cho <jhjcho@…>, 15 years ago

fixed problems in 2d

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