source: sasview/sansmodels/src/sans/models/c_extensions/spheroid.c @ 2e38ebb

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 2e38ebb was 975ec8e, checked in by Jae Cho <jhjcho@…>, 15 years ago

working on 2D models. Still need smore corrections and unit tests.

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[975ec8e]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/**
14 * Function to evaluate 1D scattering function
15 * @param pars: parameters of the prolate
16 * @param q: q-value
17 * @return: function value
18 */
19double spheroid_analytical_1D(SpheroidParameters *pars, double q) {
20        double dp[8];
21
22        // Fill paramater array
23        dp[0] = pars->scale;
24        dp[1] = pars->equat_core;
25        dp[2] = pars->polar_core;
26        dp[3] = pars->equat_shell;
27        dp[4] = pars->polar_shell;
28        dp[5] = pars->contrast;
29        dp[6] = pars->sld_solvent;
30        dp[7] = pars->background;
31
32        // Call library function to evaluate model
33        return ProlateForm(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
76    // ellipsoid orientation, the axis of the rotation is consistent with the ploar axis.
77    cyl_x = sin(pars->axis_theta) * cos(pars->axis_phi);
78    cyl_y = sin(pars->axis_theta) * sin(pars->axis_phi);
79    cyl_z = cos(pars->axis_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 = gfn4(cos_val,pars->equat_core,pars->polar_core,pars->equat_shell,pars->polar_shell,pars->contrast,pars->sld_solvent,q);
100
101
102        //normalize by cylinder volume
103        //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
104    vol = 4*Pi/3*pars->equat_shell*pars->equat_shell*pars->polar_shell;
105        answer /= vol;
106
107        //convert to [cm-1]
108        answer *= 1.0e8;
109
110        //Scale
111        answer *= pars->scale;
112
113        // add in the background
114        answer += pars->background;
115
116        return answer;
117}
118
119
Note: See TracBrowser for help on using the repository browser.