source: sasview/sansmodels/src/sans/models/c_extensions/elliptical_cylinder.c @ 2c041e9

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 2c041e9 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.5 KB
RevLine 
[ae3ce4e]1/**
2 * Scattering model for a cylinder with elliptical cross-section
3 */
4
5#include "elliptical_cylinder.h"
6#include <math.h>
7#include "libCylinder.h"
8#include <stdio.h>
9#include <stdlib.h>
10
11
12/**
13 * Function to evaluate 1D scattering function
14 * @param pars: parameters of the cylinder
15 * @param q: q-value
16 * @return: function value
17 */
18double elliptical_cylinder_analytical_1D(EllipticalCylinderParameters *pars, double q) {
[f10063e]19        double dp[7];
[3fe701a]20
[ae3ce4e]21        // Fill paramater array
22        dp[0] = pars->scale;
23        dp[1] = pars->r_minor;
24        dp[2] = pars->r_ratio;
25        dp[3] = pars->length;
[f10063e]26        dp[4] = pars->sldCyl;
27        dp[5] = pars->sldSolv;
28        dp[6] = pars->background;
[3fe701a]29
[ae3ce4e]30        // Call library function to evaluate model
[3fe701a]31        return EllipCyl20(dp, q);
[ae3ce4e]32}
33
[975ec8e]34double elliptical_cylinder_kernel(EllipticalCylinderParameters *pars, double q, double alpha, double nu) {
[ae3ce4e]35        double qr;
36        double qL;
[975ec8e]37        double Be,Si;
[ae3ce4e]38        double r_major;
39        double kernel;
[3fe701a]40
[ae3ce4e]41        r_major = pars->r_ratio * pars->r_minor;
42
[3fe701a]43        qr = q*sin(alpha)*sqrt( r_major*r_major*sin(nu)*sin(nu) + pars->r_minor*pars->r_minor*cos(nu)*cos(nu) );
[ae3ce4e]44        qL = q*pars->length*cos(alpha)/2.0;
[3fe701a]45
[975ec8e]46        if (qr==0){
47                Be = 0.5;
48        }else{
49                Be = NR_BessJ1(qr)/qr;
50        }
51        if (qL==0){
52                Si = 1.0;
53        }else{
54                Si = sin(qL)/qL;
55        }
56
57
58        kernel = 2.0*Be * Si;
[ae3ce4e]59        return kernel*kernel;
60}
61
62/**
63 * Function to evaluate 2D scattering function
64 * @param pars: parameters of the cylinder
65 * @param q: q-value
66 * @return: function value
67 */
68double elliptical_cylinder_analytical_2DXY(EllipticalCylinderParameters *pars, double qx, double qy) {
69        double q;
70        q = sqrt(qx*qx+qy*qy);
71    return elliptical_cylinder_analytical_2D_scaled(pars, q, qx/q, qy/q);
[3fe701a]72}
[ae3ce4e]73
74/**
75 * Function to evaluate 2D scattering function
76 * @param pars: parameters of the cylinder
77 * @param q: q-value
[3fe701a]78 * @param theta: angle theta = angle wrt z axis
79 * @param phi: angle phi = angle around y axis (starting from the x+-direction as phi = 0)
[ae3ce4e]80 * @return: function value
81 */
82double elliptical_cylinder_analytical_2D(EllipticalCylinderParameters *pars, double q, double phi) {
83    return elliptical_cylinder_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
[3fe701a]84}
[ae3ce4e]85
86/**
87 * Function to evaluate 2D scattering function
88 * @param pars: parameters of the cylinder
89 * @param q: q-value
90 * @param q_x: q_x / q
91 * @param q_y: q_y / q
92 * @return: function value
93 */
94double elliptical_cylinder_analytical_2D_scaled(EllipticalCylinderParameters *pars, double q, double q_x, double q_y) {
95        double cyl_x, cyl_y, cyl_z;
[3fe701a]96        double ell_x, ell_y;
[ae3ce4e]97        double q_z;
98        double alpha, vol, cos_val;
[3fe701a]99        double nu, cos_nu;
[ae3ce4e]100        double answer;
[4628e31]101        //convert angle degree to radian
102        double pi = 4.0*atan(1.0);
103        double theta = pars->cyl_theta * pi/180.0;
104        double phi = pars->cyl_phi * pi/180.0;
105        double psi = pars->cyl_psi * pi/180.0;
[3fe701a]106
107    //Cylinder orientation
[4628e31]108    cyl_x = sin(theta) * cos(phi);
109    cyl_y = sin(theta) * sin(phi);
110    cyl_z = cos(theta);
[3fe701a]111
[ae3ce4e]112    // q vector
113    q_z = 0;
[3fe701a]114
[ae3ce4e]115    // Compute the angle btw vector q and the
116    // axis of the cylinder
117    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
[3fe701a]118
[ae3ce4e]119    // The following test should always pass
120    if (fabs(cos_val)>1.0) {
121        printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n");
122        return 0;
123    }
[3fe701a]124
[ae3ce4e]125    // Note: cos(alpha) = 0 and 1 will get an
126    // undefined value from CylKernel
127        alpha = acos( cos_val );
[3fe701a]128
129    //ellipse orientation:
130        // the elliptical corss section was transformed and projected
131        // into the detector plane already through sin(alpha)and furthermore psi remains as same
132        // on the detector plane.
133        // So, all we need is to calculate the angle (nu) of the minor axis of the ellipse wrt
134        // the wave vector q.
135
136        //x- y- component on the detector plane.
[4628e31]137    ell_x =  cos(psi);
138    ell_y =  sin(psi);
[3fe701a]139
140    // calculate the axis of the ellipse wrt q-coord.
141    cos_nu = ell_x*q_x + ell_y*q_y;
142    nu = acos(cos_nu);
143
144    // The following test should always pass
145    if (fabs(cos_nu)>1.0) {
146        printf("cyl_ana_2D: Unexpected error: cos(nu)>1\n");
147        return 0;
148    }
149
[975ec8e]150        answer = elliptical_cylinder_kernel(pars, q, alpha,nu);
[3fe701a]151
[ae3ce4e]152        // Multiply by contrast^2
[f10063e]153        answer *= (pars->sldCyl - pars->sldSolv) * (pars->sldCyl - pars->sldSolv);
[3fe701a]154
[ae3ce4e]155        //normalize by cylinder volume
156        //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
157    vol = acos(-1.0) * pars->r_minor * pars->r_minor * pars->r_ratio * pars->length;
158        answer *= vol;
[3fe701a]159
[ae3ce4e]160        //convert to [cm-1]
161        answer *= 1.0e8;
[3fe701a]162
[ae3ce4e]163        //Scale
164        answer *= pars->scale;
[3fe701a]165
[ae3ce4e]166        // add in the background
167        answer += pars->background;
[3fe701a]168
[ae3ce4e]169        return answer;
170}
[3fe701a]171
Note: See TracBrowser for help on using the repository browser.