1 | /** |
---|
2 | * Scattering model for a hollow cylinder |
---|
3 | * @author:gervaise alina / UTK |
---|
4 | */ |
---|
5 | |
---|
6 | #include "hollow_cylinder.h" |
---|
7 | #include "libCylinder.h" |
---|
8 | #include <math.h> |
---|
9 | #include <stdio.h> |
---|
10 | |
---|
11 | |
---|
12 | /** |
---|
13 | * Function to evaluate 1D scattering function |
---|
14 | * @param pars: parameters of the hollow cylinder |
---|
15 | * @param q: q-value |
---|
16 | * @return: function value |
---|
17 | */ |
---|
18 | double hollow_cylinder_analytical_1D(HollowCylinderParameters *pars, double q) { |
---|
19 | double dp[6]; |
---|
20 | |
---|
21 | dp[0] = pars->scale; |
---|
22 | dp[1] = pars->core_radius; |
---|
23 | dp[2] = pars->radius; |
---|
24 | dp[3] = pars->length; |
---|
25 | dp[4] = pars->contrast; |
---|
26 | dp[5] = pars->background; |
---|
27 | |
---|
28 | return HollowCylinder(dp, q); |
---|
29 | } |
---|
30 | |
---|
31 | /** |
---|
32 | * Function to evaluate 2D scattering function |
---|
33 | * @param pars: parameters of the Hollow cylinder |
---|
34 | * @param q: q-value |
---|
35 | * @return: function value |
---|
36 | */ |
---|
37 | double hollow_cylinder_analytical_2DXY(HollowCylinderParameters *pars, double qx, double qy) { |
---|
38 | double q; |
---|
39 | q = sqrt(qx*qx+qy*qy); |
---|
40 | return hollow_cylinder_analytical_2D_scaled(pars, q, qx/q, qy/q); |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * Function to evaluate 2D scattering function |
---|
45 | * @param pars: parameters of the hollow cylinder |
---|
46 | * @param q: q-value |
---|
47 | * @param phi: angle phi |
---|
48 | * @return: function value |
---|
49 | */ |
---|
50 | double hollow_cylinder_analytical_2D(HollowCylinderParameters *pars, double q, double phi) { |
---|
51 | return hollow_cylinder_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * Function to evaluate 2D scattering function |
---|
56 | * @param pars: parameters of the hollow cylinder |
---|
57 | * @param q: q-value |
---|
58 | * @param q_x: q_x / q |
---|
59 | * @param q_y: q_y / q |
---|
60 | * @return: function value |
---|
61 | */ |
---|
62 | double hollow_cylinder_analytical_2D_scaled(HollowCylinderParameters *pars, double q, double q_x, double q_y) { |
---|
63 | double cyl_x, cyl_y, cyl_z; |
---|
64 | double q_z; |
---|
65 | double alpha,vol, cos_val; |
---|
66 | double answer; |
---|
67 | |
---|
68 | // Cylinder orientation |
---|
69 | cyl_x = sin(pars->axis_theta) * cos(pars->axis_phi); |
---|
70 | cyl_y = sin(pars->axis_theta) * sin(pars->axis_phi); |
---|
71 | cyl_z = cos(pars->axis_theta); |
---|
72 | |
---|
73 | // q vector |
---|
74 | q_z = 0; |
---|
75 | |
---|
76 | // Compute the angle btw vector q and the |
---|
77 | // axis of the cylinder |
---|
78 | cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; |
---|
79 | |
---|
80 | // The following test should always pass |
---|
81 | if (fabs(cos_val)>1.0) { |
---|
82 | printf("core_shell_cylinder_analytical_2D: Unexpected error: cos(alpha)=%g\n", cos_val); |
---|
83 | return 0; |
---|
84 | } |
---|
85 | |
---|
86 | alpha = acos( cos_val ); |
---|
87 | |
---|
88 | // Call the IGOR library function to get the kernel |
---|
89 | answer = HolCylKernel(q, pars->core_radius, pars->radius, pars->length, cos_val); |
---|
90 | |
---|
91 | //normalize by cylinder volume |
---|
92 | vol=acos(-1.0)*((pars->core_radius *pars->core_radius)-(pars->radius*pars->radius)) |
---|
93 | *(pars->length); |
---|
94 | answer /= vol; |
---|
95 | |
---|
96 | //convert to [cm-1] |
---|
97 | answer *= 1.0e8; |
---|
98 | |
---|
99 | //Scale |
---|
100 | answer *= pars->scale; |
---|
101 | |
---|
102 | // add in the background |
---|
103 | answer += pars->background; |
---|
104 | |
---|
105 | return answer; |
---|
106 | } |
---|