source: sasview/sansmodels/src/sans/models/c_extensions/elliptical_cylinder.c @ 5ee2306

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

Moving sansmodels to trunk

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[ae3ce4e]1/**
2 * Scattering model for a cylinder with elliptical cross-section
3 */
4
5#include "elliptical_cylinder.h"
6#include <math.h>
7#include "libCylinder.h"
8#include <stdio.h>
9#include <stdlib.h>
10
11
12/**
13 * Function to evaluate 1D scattering function
14 * @param pars: parameters of the cylinder
15 * @param q: q-value
16 * @return: function value
17 */
18double elliptical_cylinder_analytical_1D(EllipticalCylinderParameters *pars, double q) {
19        double dp[6];
20       
21        // Fill paramater array
22        dp[0] = pars->scale;
23        dp[1] = pars->r_minor;
24        dp[2] = pars->r_ratio;
25        dp[3] = pars->length;
26        dp[4] = pars->contrast;
27        dp[5] = pars->background;
28       
29        // Call library function to evaluate model
30        return EllipCyl20(dp, q);       
31}
32
33double elliptical_cylinder_kernel(EllipticalCylinderParameters *pars, double q, double alpha, double psi) {
34        double qr;
35        double qL;
36        double r_major;
37        double kernel;
38       
39        r_major = pars->r_ratio * pars->r_minor;
40
41        qr = q*sin(alpha)*sqrt( r_major*r_major*sin(psi)*sin(psi) + pars->r_minor*pars->r_minor*cos(psi)*cos(psi) );
42        qL = q*pars->length*cos(alpha)/2.0;
43       
44        kernel = 2.0*NR_BessJ1(qr)/qr * sin(qL)/qL;
45        return kernel*kernel;
46}
47
48/**
49 * Function to evaluate 2D scattering function
50 * @param pars: parameters of the cylinder
51 * @param q: q-value
52 * @return: function value
53 */
54double elliptical_cylinder_analytical_2DXY(EllipticalCylinderParameters *pars, double qx, double qy) {
55        double q;
56        q = sqrt(qx*qx+qy*qy);
57    return elliptical_cylinder_analytical_2D_scaled(pars, q, qx/q, qy/q);
58} 
59
60/**
61 * Function to evaluate 2D scattering function
62 * @param pars: parameters of the cylinder
63 * @param q: q-value
64 * @param phi: angle phi
65 * @return: function value
66 */
67double elliptical_cylinder_analytical_2D(EllipticalCylinderParameters *pars, double q, double phi) {
68    return elliptical_cylinder_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
69} 
70
71/**
72 * Function to evaluate 2D scattering function
73 * @param pars: parameters of the cylinder
74 * @param q: q-value
75 * @param q_x: q_x / q
76 * @param q_y: q_y / q
77 * @return: function value
78 */
79double elliptical_cylinder_analytical_2D_scaled(EllipticalCylinderParameters *pars, double q, double q_x, double q_y) {
80        double cyl_x, cyl_y, cyl_z;
81        double q_z;
82        double alpha, vol, cos_val;
83        double answer;
84       
85    // Cylinder orientation
86    cyl_x = sin(pars->cyl_theta) * cos(pars->cyl_phi);
87    cyl_y = sin(pars->cyl_theta) * sin(pars->cyl_phi);
88    cyl_z = cos(pars->cyl_theta);
89     
90    // q vector
91    q_z = 0;
92       
93    // Compute the angle btw vector q and the
94    // axis of the cylinder
95    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
96   
97    // The following test should always pass
98    if (fabs(cos_val)>1.0) {
99        printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n");
100        return 0;
101    }
102   
103    // Note: cos(alpha) = 0 and 1 will get an
104    // undefined value from CylKernel
105        alpha = acos( cos_val );
106       
107        answer = elliptical_cylinder_kernel(pars, q, alpha, pars->cyl_psi);
108       
109        // Multiply by contrast^2
110        answer *= pars->contrast*pars->contrast;
111       
112        //normalize by cylinder volume
113        //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
114    vol = acos(-1.0) * pars->r_minor * pars->r_minor * pars->r_ratio * pars->length;
115        answer *= vol;
116       
117        //convert to [cm-1]
118        answer *= 1.0e8;
119       
120        //Scale
121        answer *= pars->scale;
122       
123        // add in the background
124        answer += pars->background;
125       
126        return answer;
127}
128   
Note: See TracBrowser for help on using the repository browser.