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

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

fixed a mistake and changed a para_name

  • Property mode set to 100644
File size: 2.7 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];
[e2afadf]20
[27fea3f]21        dp[0] = pars->scale;
22        dp[1] = pars->core_radius;
[e2afadf]23        dp[2] = pars->radius;
[27fea3f]24        dp[3] = pars->length;
25        dp[4] = pars->contrast;
26        dp[5] = pars->background;
[e2afadf]27
[27fea3f]28        return HollowCylinder(dp, q);
29}
[e2afadf]30
[27fea3f]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);
[e2afadf]41}
[27fea3f]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));
[e2afadf]52}
[27fea3f]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;
[e2afadf]67
[27fea3f]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);
[e2afadf]72
[27fea3f]73    // q vector
74    q_z = 0;
[e2afadf]75
[27fea3f]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;
[e2afadf]79
[27fea3f]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    }
[e2afadf]85
[27fea3f]86        alpha = acos( cos_val );
[e2afadf]87
[27fea3f]88        // Call the IGOR library function to get the kernel
[e2afadf]89        answer = HolCylKernel(q, pars->core_radius, pars->radius, pars->length, cos_val);
90
[27fea3f]91        //normalize by cylinder volume
[e2afadf]92        vol=acos(-1.0)*((pars->core_radius *pars->core_radius)-(pars->radius*pars->radius))
[27fea3f]93                        *(pars->length);
94        answer /= vol;
[e2afadf]95
[27fea3f]96        //convert to [cm-1]
97        answer *= 1.0e8;
[e2afadf]98
[27fea3f]99        //Scale
100        answer *= pars->scale;
[e2afadf]101
[27fea3f]102        // add in the background
103        answer += pars->background;
[e2afadf]104
[27fea3f]105        return answer;
106}
Note: See TracBrowser for help on using the repository browser.