source: sasview/sansmodels/src/sans/models/c_extensions/cylinder.c @ bdc25e2

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 bdc25e2 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
Line 
1/**
2 * Scattering model for a cylinder
3 * @author: Mathieu Doucet / UTK
4 */
5
6#include "cylinder.h"
7#include <math.h>
8#include "libCylinder.h"
9#include <stdio.h>
10#include <stdlib.h>
11
12
13/**
14 * Function to evaluate 1D scattering function
15 * @param pars: parameters of the cylinder
16 * @param q: q-value
17 * @return: function value
18 */
19double cylinder_analytical_1D(CylinderParameters *pars, double q) {
20        double dp[6];
21
22        // Fill paramater array
23        dp[0] = pars->scale;
24        dp[1] = pars->radius;
25        dp[2] = pars->length;
26        dp[3] = pars->sldCyl;
27        dp[4] = pars->sldSolv;
28        dp[5] = pars->background;
29
30        // Call library function to evaluate model
31        return CylinderForm(dp, q);
32}
33
34/**
35 * Function to evaluate 2D scattering function
36 * @param pars: parameters of the cylinder
37 * @param q: q-value
38 * @return: function value
39 */
40double cylinder_analytical_2DXY(CylinderParameters *pars, double qx, double qy) {
41        double q;
42        q = sqrt(qx*qx+qy*qy);
43    return cylinder_analytical_2D_scaled(pars, q, qx/q, qy/q);
44}
45
46
47/**
48 * Function to evaluate 2D scattering function
49 * @param pars: parameters of the cylinder
50 * @param q: q-value
51 * @param phi: angle phi
52 * @return: function value
53 */
54double cylinder_analytical_2D(CylinderParameters *pars, double q, double phi) {
55    return cylinder_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
56}
57
58/**
59 * Function to evaluate 2D scattering function
60 * @param pars: parameters of the cylinder
61 * @param q: q-value
62 * @param q_x: q_x / q
63 * @param q_y: q_y / q
64 * @return: function value
65 */
66double cylinder_analytical_2D_scaled(CylinderParameters *pars, double q, double q_x, double q_y) {
67        double cyl_x, cyl_y, cyl_z;
68        double q_z;
69        double alpha, vol, cos_val;
70        double answer;
71        //convert angle degree to radian
72        double pi = 4.0*atan(1.0);
73        double theta = pars->cyl_theta * pi/180.0;
74        double phi = pars->cyl_phi * pi/180.0;
75
76    // Cylinder orientation
77    cyl_x = sin(theta) * cos(phi);
78    cyl_y = sin(theta) * sin(phi);
79    cyl_z = cos(theta);
80
81    // q vector
82    q_z = 0;
83
84    // Compute the angle btw vector q and the
85    // axis of the cylinder
86    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
87
88    // The following test should always pass
89    if (fabs(cos_val)>1.0) {
90        printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n");
91        return 0;
92    }
93
94    // Note: cos(alpha) = 0 and 1 will get an
95    // undefined value from CylKernel
96        alpha = acos( cos_val );
97
98        // Call the IGOR library function to get the kernel
99        answer = CylKernel(q, pars->radius, pars->length/2.0, alpha) / sin(alpha);
100
101        // Multiply by contrast^2
102        answer *= (pars->sldCyl - pars->sldSolv)*(pars->sldCyl - pars->sldSolv);
103
104        //normalize by cylinder volume
105        //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
106    vol = acos(-1.0) * pars->radius * pars->radius * pars->length;
107        answer *= vol;
108
109        //convert to [cm-1]
110        answer *= 1.0e8;
111
112        //Scale
113        answer *= pars->scale;
114
115        // add in the background
116        answer += pars->background;
117
118        return answer;
119}
120
Note: See TracBrowser for help on using the repository browser.