1 | /** |
---|
2 | * Scattering model for a staked disk |
---|
3 | * TODO: Add 2D analysis |
---|
4 | */ |
---|
5 | |
---|
6 | #include "stakeddisks.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 staked disks |
---|
16 | * @param q: q-value |
---|
17 | * @return: function value |
---|
18 | */ |
---|
19 | double flexible_cylinder_analytical_1D(StakedParameters *pars, double q) { |
---|
20 | double dp[10]; |
---|
21 | |
---|
22 | // Fill paramater array |
---|
23 | dp[0] = pars->scale; |
---|
24 | dp[1] = pars->length; |
---|
25 | dp[2] = pars->kuhn_length; |
---|
26 | dp[3] = pars->radius; |
---|
27 | dp[4] = pars->contrast; |
---|
28 | dp[5] = pars->background; |
---|
29 | |
---|
30 | // Call library function to evaluate model |
---|
31 | return FlexExclVolCyl(dp, q); |
---|
32 | } |
---|
33 | /** |
---|
34 | * Function to evaluate 2D scattering function |
---|
35 | * @param pars: parameters of the staked disks |
---|
36 | * @param q: q-value |
---|
37 | * @return: function value |
---|
38 | */ |
---|
39 | double flexible_cylinder_analytical_2DXY(FlexibleCylinderParameters *pars, double qx, double qy) { |
---|
40 | double q; |
---|
41 | q = sqrt(qx*qx+qy*qy); |
---|
42 | return flexible_cylinder_analytical_2D_scaled(pars, q, qx/q, qy/q); |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | /** |
---|
47 | * Function to evaluate 2D scattering function |
---|
48 | * @param pars: parameters of the staked disks |
---|
49 | * @param q: q-value |
---|
50 | * @param phi: angle phi |
---|
51 | * @return: function value |
---|
52 | */ |
---|
53 | double flexible_cylinder_analytical_2D(FlexibleCylinderParameters *pars, double q, double phi) { |
---|
54 | return flexible_cylinder_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * Function to evaluate 2D scattering function |
---|
59 | * @param pars: parameters of the staked disks |
---|
60 | * @param q: q-value |
---|
61 | * @param q_x: q_x / q |
---|
62 | * @param q_y: q_y / q |
---|
63 | * @return: function value |
---|
64 | */ |
---|
65 | double flexible_cylinder_analytical_2D_scaled(FlexibleCylinderParameters *pars, double q, double q_x, double q_y) { |
---|
66 | double cyl_x, cyl_y, cyl_z; |
---|
67 | double q_z; |
---|
68 | double alpha, vol, cos_val; |
---|
69 | double answer; |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | // parallelepiped 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 | // Compute the angle btw vector q and the |
---|
82 | // axis of the parallelepiped |
---|
83 | cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; |
---|
84 | |
---|
85 | // The following test should always pass |
---|
86 | if (fabs(cos_val)>1.0) { |
---|
87 | printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); |
---|
88 | return 0; |
---|
89 | } |
---|
90 | |
---|
91 | // Note: cos(alpha) = 0 and 1 will get an |
---|
92 | // undefined value from PPKernel |
---|
93 | alpha = acos( cos_val ); |
---|
94 | |
---|
95 | // Call the IGOR library function to get the kernel |
---|
96 | answer = CylKernel(q, pars->radius, pars->length/2.0, alpha) / sin(alpha); |
---|
97 | |
---|
98 | // Multiply by contrast^2 |
---|
99 | answer *= pars->contrast*pars->contrast; |
---|
100 | |
---|
101 | //normalize by staked disks volume |
---|
102 | //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vparallel |
---|
103 | vol = acos(-1.0) * pars->radius * pars->radius * pars->length; |
---|
104 | answer *= vol; |
---|
105 | |
---|
106 | //convert to [cm-1] |
---|
107 | answer *= 1.0e8; |
---|
108 | |
---|
109 | //Scale |
---|
110 | answer *= pars->scale; |
---|
111 | |
---|
112 | // add in the background |
---|
113 | answer += pars->background; |
---|
114 | |
---|
115 | return answer; |
---|
116 | } |
---|
117 | |
---|
118 | |
---|