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

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 33aea7f 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
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) {
[f10063e]19        double dp[7];
[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;
[f10063e]25        dp[4] = pars->sldCyl;
26        dp[5] = pars->sldSolv;
27        dp[6] = pars->background;
[e2afadf]28
[27fea3f]29        return HollowCylinder(dp, q);
30}
[e2afadf]31
[27fea3f]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);
[e2afadf]42}
[27fea3f]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));
[e2afadf]53}
[27fea3f]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;
[4628e31]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;
[e2afadf]72
[27fea3f]73    // Cylinder orientation
[4628e31]74    cyl_x = sin(theta) * cos(phi);
75    cyl_y = sin(theta) * sin(phi);
76    cyl_z = cos(theta);
[e2afadf]77
[27fea3f]78    // q vector
79    q_z = 0;
[e2afadf]80
[27fea3f]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;
[e2afadf]84
[27fea3f]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    }
[e2afadf]90
[27fea3f]91        alpha = acos( cos_val );
[e2afadf]92
[27fea3f]93        // Call the IGOR library function to get the kernel
[e2afadf]94        answer = HolCylKernel(q, pars->core_radius, pars->radius, pars->length, cos_val);
95
[f10063e]96        // Multiply by contrast^2
97        answer *= (pars->sldCyl - pars->sldSolv)*(pars->sldCyl - pars->sldSolv);
98
[27fea3f]99        //normalize by cylinder volume
[4628e31]100        vol=pi*((pars->radius*pars->radius)-(pars->core_radius *pars->core_radius))
[27fea3f]101                        *(pars->length);
[4628e31]102        answer *= vol;
[e2afadf]103
[27fea3f]104        //convert to [cm-1]
105        answer *= 1.0e8;
[e2afadf]106
[27fea3f]107        //Scale
108        answer *= pars->scale;
[e2afadf]109
[27fea3f]110        // add in the background
111        answer += pars->background;
[e2afadf]112
[27fea3f]113        return answer;
114}
Note: See TracBrowser for help on using the repository browser.