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

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 0f5bc9f was ae3ce4e, checked in by Mathieu Doucet <doucetm@…>, 17 years ago

Moving sansmodels to trunk

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