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