source: sasview/sansmodels/src/c_extensions/core_shell_cylinder.c @ 67424cd

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 67424cd was 67424cd, checked in by Mathieu Doucet <doucetm@…>, 12 years ago

Reorganizing models in preparation of cpp cleanup

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