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

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 cee6867 was 27fea3f, checked in by Gervaise Alina <gervyh@…>, 15 years ago

add a few models 1D

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[27fea3f]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[6];
20       
21        dp[0] = pars->scale;
22        dp[1] = pars->core_radius;
23        dp[2] = pars->shell_radius;
24        dp[3] = pars->length;
25        dp[4] = pars->contrast;
26        dp[5] = pars->background;
27       
28        return HollowCylinder(dp, q);
29}
30   
31/**
32 * Function to evaluate 2D scattering function
33 * @param pars: parameters of the Hollow cylinder
34 * @param q: q-value
35 * @return: function value
36 */
37double hollow_cylinder_analytical_2DXY(HollowCylinderParameters *pars, double qx, double qy) {
38        double q;
39        q = sqrt(qx*qx+qy*qy);
40    return hollow_cylinder_analytical_2D_scaled(pars, q, qx/q, qy/q);
41} 
42
43/**
44 * Function to evaluate 2D scattering function
45 * @param pars: parameters of the hollow cylinder
46 * @param q: q-value
47 * @param phi: angle phi
48 * @return: function value
49 */
50double hollow_cylinder_analytical_2D(HollowCylinderParameters *pars, double q, double phi) {
51    return hollow_cylinder_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
52} 
53
54/**
55 * Function to evaluate 2D scattering function
56 * @param pars: parameters of the hollow cylinder
57 * @param q: q-value
58 * @param q_x: q_x / q
59 * @param q_y: q_y / q
60 * @return: function value
61 */
62double hollow_cylinder_analytical_2D_scaled(HollowCylinderParameters *pars, double q, double q_x, double q_y) {
63        double cyl_x, cyl_y, cyl_z;
64        double q_z;
65        double  alpha,vol, cos_val;
66        double answer;
67       
68    // Cylinder orientation
69    cyl_x = sin(pars->axis_theta) * cos(pars->axis_phi);
70    cyl_y = sin(pars->axis_theta) * sin(pars->axis_phi);
71    cyl_z = cos(pars->axis_theta);
72     
73    // q vector
74    q_z = 0;
75       
76    // Compute the angle btw vector q and the
77    // axis of the cylinder
78    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
79   
80    // The following test should always pass
81    if (fabs(cos_val)>1.0) {
82        printf("core_shell_cylinder_analytical_2D: Unexpected error: cos(alpha)=%g\n", cos_val);
83        return 0;
84    }
85   
86        alpha = acos( cos_val );
87       
88        // Call the IGOR library function to get the kernel
89        answer = HolCylKernel(q, pars->core_radius, pars->shell_radius, pars->length, cos_val);
90       
91        //normalize by cylinder volume
92        vol=acos(-1.0)*((pars->core_radius *pars->core_radius)-(pars->shell_radius*pars->shell_radius))
93                        *(pars->length);
94        answer /= vol;
95       
96        //convert to [cm-1]
97        answer *= 1.0e8;
98       
99        //Scale
100        answer *= pars->scale;
101       
102        // add in the background
103        answer += pars->background;
104       
105        return answer;
106}
Note: See TracBrowser for help on using the repository browser.