source: sasview/sansmodels/src/sans/models/c_extensions/spheroid.c @ 74b1770

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 74b1770 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: 3.3 KB
Line 
1/**
2 * Scattering model for a prolate
3 * @author: UTK
4 */
5
6#include "spheroid.h"
7#include <math.h>
8#include "libCylinder.h"
9#include <stdio.h>
10#include <stdlib.h>
11
12/**
13 * Function to evaluate 1D scattering function
14 * @param pars: parameters of the prolate
15 * @param q: q-value
16 * @return: function value
17 */
18double spheroid_analytical_1D(SpheroidParameters *pars, double q) {
19        double dp[9];
20
21        // Fill paramater array
22        dp[0] = pars->scale;
23        dp[1] = pars->equat_core;
24        dp[2] = pars->polar_core;
25        dp[3] = pars->equat_shell;
26        dp[4] = pars->polar_shell;
27        dp[5] = pars->sld_core;
28        dp[6] = pars->sld_shell;
29        dp[7] = pars->sld_solvent;
30        dp[8] = pars->background;
31
32        // Call library function to evaluate model
33        return OblateForm(dp, q);
34}
35
36/**
37 * Function to evaluate 2D scattering function
38 * @param pars: parameters of the prolate
39 * @param q: q-value
40 * @return: function value
41 */
42double spheroid_analytical_2DXY(SpheroidParameters *pars, double qx, double qy) {
43        double q;
44        q = sqrt(qx*qx+qy*qy);
45    return spheroid_analytical_2D_scaled(pars, q, qx/q, qy/q);
46}
47
48
49/**
50 * Function to evaluate 2D scattering function
51 * @param pars: parameters of the prolate
52 * @param q: q-value
53 * @param phi: angle phi
54 * @return: function value
55 */
56double spheroid_analytical_2D(SpheroidParameters *pars, double q, double phi) {
57    return spheroid_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
58}
59
60/**
61 * Function to evaluate 2D scattering function
62 * @param pars: parameters of the prolate
63 * @param q: q-value
64 * @param q_x: q_x / q
65 * @param q_y: q_y / q
66 * @return: function value
67 */
68double spheroid_analytical_2D_scaled(SpheroidParameters *pars, double q, double q_x, double q_y) {
69
70        double cyl_x, cyl_y, cyl_z;
71        double q_z;
72        double alpha, vol, cos_val;
73        double answer;
74        double Pi = 4.0*atan(1.0);
75        double sldcs,sldss;
76
77    // ellipsoid orientation, the axis of the rotation is consistent with the ploar axis.
78    cyl_x = sin(pars->axis_theta) * cos(pars->axis_phi);
79    cyl_y = sin(pars->axis_theta) * sin(pars->axis_phi);
80    cyl_z = cos(pars->axis_theta);
81    //del sld
82    sldcs = pars->sld_core - pars->sld_shell;
83    sldss = pars->sld_shell- pars->sld_solvent;
84
85    // q vector
86    q_z = 0;
87
88    // Compute the angle btw vector q and the
89    // axis of the cylinder
90    cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z;
91
92    // The following test should always pass
93    if (fabs(cos_val)>1.0) {
94        printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n");
95        return 0;
96    }
97
98    // Note: cos(alpha) = 0 and 1 will get an
99    // undefined value from CylKernel
100        alpha = acos( cos_val );
101
102        // Call the IGOR library function to get the kernel: MUST use gfn4 not gf2 because of the def of params.
103        answer = gfn4(cos_val,pars->equat_core,pars->polar_core,pars->equat_shell,pars->polar_shell,sldcs,sldss,q);
104        //It seems that it should be normalized somehow. How???
105
106        //normalize by cylinder volume
107        //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
108    vol = 4.0*Pi/3.0*pars->equat_shell*pars->equat_shell*pars->polar_shell;
109        answer /= vol;
110
111        //convert to [cm-1]
112        answer *= 1.0e8;
113
114        //Scale
115        answer *= pars->scale;
116
117        // add in the background
118        answer += pars->background;
119
120        return answer;
121}
122
123
Note: See TracBrowser for help on using the repository browser.