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

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

Updated the definition of SLD params according to new libigor functions

  • Property mode set to 100644
File size: 2.9 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
72    // Cylinder orientation
73    cyl_x = sin(pars->cyl_theta) * cos(pars->cyl_phi);
74    cyl_y = sin(pars->cyl_theta) * sin(pars->cyl_phi);
75    cyl_z = cos(pars->cyl_theta);
76
77    // q vector
78    q_z = 0;
79
80    // Compute the angle btw vector q and the
81    // axis of the cylinder
82    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
83
84    // The following test should always pass
85    if (fabs(cos_val)>1.0) {
86        printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n");
87        return 0;
88    }
89
90    // Note: cos(alpha) = 0 and 1 will get an
91    // undefined value from CylKernel
92        alpha = acos( cos_val );
93
94        // Call the IGOR library function to get the kernel
95        answer = CylKernel(q, pars->radius, pars->length/2.0, alpha) / sin(alpha);
96
97        // Multiply by contrast^2
98        answer *= (pars->sldCyl - pars->sldSolv)*(pars->sldCyl - pars->sldSolv);
99
100        //normalize by cylinder volume
101        //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
102    vol = acos(-1.0) * pars->radius * pars->radius * pars->length;
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}
116
Note: See TracBrowser for help on using the repository browser.