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

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 c6d3301 was 2339249f, checked in by Jae Cho <jhjcho@…>, 15 years ago

Found and fixed an error on normalizing by the volume

  • Property mode set to 100644
File size: 2.9 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
69    // Cylinder orientation
70    cyl_x = sin(pars->axis_theta) * cos(pars->axis_phi);
71    cyl_y = sin(pars->axis_theta) * sin(pars->axis_phi);
72    cyl_z = cos(pars->axis_theta);
73
74    // q vector
75    q_z = 0;
76
77    // Compute the angle btw vector q and the
78    // axis of the cylinder
79    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
80
81    // The following test should always pass
82    if (fabs(cos_val)>1.0) {
83        printf("core_shell_cylinder_analytical_2D: Unexpected error: cos(alpha)=%g\n", cos_val);
84        return 0;
85    }
86
87        alpha = acos( cos_val );
88
89        // Call the IGOR library function to get the kernel
90        answer = HolCylKernel(q, pars->core_radius, pars->radius, pars->length, cos_val);
91
92        // Multiply by contrast^2
93        answer *= (pars->sldCyl - pars->sldSolv)*(pars->sldCyl - pars->sldSolv);
94
95        //normalize by cylinder volume
96        vol=acos(-1.0)*((pars->radius*pars->radius)-(pars->core_radius *pars->core_radius))
97                        *(pars->length);
98        answer /= vol;
99
100        //convert to [cm-1]
101        answer *= 1.0e8;
102
103        //Scale
104        answer *= pars->scale;
105
106        // add in the background
107        answer += pars->background;
108
109        return answer;
110}
Note: See TracBrowser for help on using the repository browser.