source: sasview/sansmodels/src/sans/models/c_extensions/hollow_cylinder.c @ e52eeea

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 e52eeea 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.0 KB
Line 
1/**
2 * Scattering model for a hollow cylinder
3 * @author:gervaise alina / UTK
4 */
5
6#include "hollow_cylinder.h"
7#include "libCylinder.h"
8#include <math.h>
9#include <stdio.h>
10
11
12/**
13 * Function to evaluate 1D scattering function
14 * @param pars: parameters of the hollow cylinder
15 * @param q: q-value
16 * @return: function value
17 */
18double hollow_cylinder_analytical_1D(HollowCylinderParameters *pars, double q) {
19        double dp[7];
20
21        dp[0] = pars->scale;
22        dp[1] = pars->core_radius;
23        dp[2] = pars->radius;
24        dp[3] = pars->length;
25        dp[4] = pars->sldCyl;
26        dp[5] = pars->sldSolv;
27        dp[6] = pars->background;
28
29        return HollowCylinder(dp, q);
30}
31
32/**
33 * Function to evaluate 2D scattering function
34 * @param pars: parameters of the Hollow cylinder
35 * @param q: q-value
36 * @return: function value
37 */
38double hollow_cylinder_analytical_2DXY(HollowCylinderParameters *pars, double qx, double qy) {
39        double q;
40        q = sqrt(qx*qx+qy*qy);
41    return hollow_cylinder_analytical_2D_scaled(pars, q, qx/q, qy/q);
42}
43
44/**
45 * Function to evaluate 2D scattering function
46 * @param pars: parameters of the hollow cylinder
47 * @param q: q-value
48 * @param phi: angle phi
49 * @return: function value
50 */
51double hollow_cylinder_analytical_2D(HollowCylinderParameters *pars, double q, double phi) {
52    return hollow_cylinder_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
53}
54
55/**
56 * Function to evaluate 2D scattering function
57 * @param pars: parameters of the hollow cylinder
58 * @param q: q-value
59 * @param q_x: q_x / q
60 * @param q_y: q_y / q
61 * @return: function value
62 */
63double hollow_cylinder_analytical_2D_scaled(HollowCylinderParameters *pars, double q, double q_x, double q_y) {
64        double cyl_x, cyl_y, cyl_z;
65        double q_z;
66        double  alpha,vol, cos_val;
67        double answer;
68        //convert angle degree to radian
69        double pi = 4.0*atan(1.0);
70        double theta = pars->axis_theta * pi/180.0;
71        double phi = pars->axis_phi * pi/180.0;
72
73    // Cylinder orientation
74    cyl_x = sin(theta) * cos(phi);
75    cyl_y = sin(theta) * sin(phi);
76    cyl_z = cos(theta);
77
78    // q vector
79    q_z = 0;
80
81    // Compute the angle btw vector q and the
82    // axis of the cylinder
83    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
84
85    // The following test should always pass
86    if (fabs(cos_val)>1.0) {
87        printf("core_shell_cylinder_analytical_2D: Unexpected error: cos(alpha)=%g\n", cos_val);
88        return 0;
89    }
90
91        alpha = acos( cos_val );
92
93        // Call the IGOR library function to get the kernel
94        answer = HolCylKernel(q, pars->core_radius, pars->radius, pars->length, cos_val);
95
96        // Multiply by contrast^2
97        answer *= (pars->sldCyl - pars->sldSolv)*(pars->sldCyl - pars->sldSolv);
98
99        //normalize by cylinder volume
100        vol=pi*((pars->radius*pars->radius)-(pars->core_radius *pars->core_radius))
101                        *(pars->length);
102        answer *= vol;
103
104        //convert to [cm-1]
105        answer *= 1.0e8;
106
107        //Scale
108        answer *= pars->scale;
109
110        // add in the background
111        answer += pars->background;
112
113        return answer;
114}
Note: See TracBrowser for help on using the repository browser.