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

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 c09ace41 was 4628e31, checked in by Jae Cho <jhjcho@…>, 14 years ago

changed the unit of angles into degrees

  • Property mode set to 100644
File size: 3.3 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 * 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) {
[f10063e]19        double dp[9];
[975ec8e]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;
[f10063e]27        dp[5] = pars->sld_core;
28        dp[6] = pars->sld_shell;
29        dp[7] = pars->sld_solvent;
30        dp[8] = pars->background;
[975ec8e]31
32        // Call library function to evaluate model
[f10063e]33        return OblateForm(dp, q);
[975ec8e]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);
[f10063e]75        double sldcs,sldss;
[975ec8e]76
[4628e31]77        //convert angle degree to radian
78        double theta = pars->axis_theta * Pi/180.0;
79        double phi = pars->axis_phi * Pi/180.0;
80
81
[975ec8e]82    // ellipsoid orientation, the axis of the rotation is consistent with the ploar axis.
[4628e31]83    cyl_x = sin(theta) * cos(phi);
84    cyl_y = sin(theta) * sin(phi);
85    cyl_z = cos(theta);
[f10063e]86    //del sld
87    sldcs = pars->sld_core - pars->sld_shell;
88    sldss = pars->sld_shell- pars->sld_solvent;
[975ec8e]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
[f10063e]107        // Call the IGOR library function to get the kernel: MUST use gfn4 not gf2 because of the def of params.
108        answer = gfn4(cos_val,pars->equat_core,pars->polar_core,pars->equat_shell,pars->polar_shell,sldcs,sldss,q);
109        //It seems that it should be normalized somehow. How???
[975ec8e]110
111        //normalize by cylinder volume
112        //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
[f10063e]113    vol = 4.0*Pi/3.0*pars->equat_shell*pars->equat_shell*pars->polar_shell;
[975ec8e]114        answer /= vol;
115
116        //convert to [cm-1]
117        answer *= 1.0e8;
118
119        //Scale
120        answer *= pars->scale;
121
122        // add in the background
123        answer += pars->background;
124
125        return answer;
126}
127
128
Note: See TracBrowser for help on using the repository browser.