1 | /* |
---|
2 | * Scattering model for a Capped Cylinder |
---|
3 | */ |
---|
4 | #include "capcyl.h" |
---|
5 | #include <math.h> |
---|
6 | #include "GaussWeights.h" |
---|
7 | #include "libCylinder.h" |
---|
8 | |
---|
9 | /** |
---|
10 | * Function to evaluate 1D scattering function |
---|
11 | * @param pars: parameters of the CappedCylinder |
---|
12 | * @param q: q-value |
---|
13 | * @return: function value |
---|
14 | */ |
---|
15 | double capcyl_analytical_1D(CapCylParameters *pars, double q) { |
---|
16 | double dp[7]; |
---|
17 | double result; |
---|
18 | |
---|
19 | dp[0] = pars->scale; |
---|
20 | dp[1] = pars->rad_cyl; |
---|
21 | dp[2] = pars->len_cyl; |
---|
22 | dp[3] = pars->rad_cap; |
---|
23 | dp[4] = pars->sld_capcyl; |
---|
24 | dp[5] = pars->sld_solv; |
---|
25 | dp[6] = pars->background; |
---|
26 | |
---|
27 | result = CappedCylinder(dp, q); |
---|
28 | // Make Sure it never goes to inf/nan. |
---|
29 | if ( result == INFINITY || result == NAN){ |
---|
30 | result = pars->background; |
---|
31 | } |
---|
32 | return result; |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | double capcyl2d_kernel(double dp[], double q, double alpha) { |
---|
37 | int i,j; |
---|
38 | double Pi; |
---|
39 | double scale,contr,bkg,sldc,slds; |
---|
40 | double len,rad,hDist,endRad; |
---|
41 | int nordj=76; |
---|
42 | double zi=alpha,yyy,answer; //running tally of integration |
---|
43 | double summj,vaj,vbj,zij; //for the inner integration |
---|
44 | double arg1,arg2,inner,be; |
---|
45 | |
---|
46 | |
---|
47 | scale = dp[0]; |
---|
48 | rad = dp[1]; |
---|
49 | len = dp[2]; |
---|
50 | endRad = dp[3]; |
---|
51 | sldc = dp[4]; |
---|
52 | slds = dp[5]; |
---|
53 | bkg = dp[6]; |
---|
54 | |
---|
55 | hDist = -1.0*sqrt(fabs(endRad*endRad-rad*rad)); //by definition for this model |
---|
56 | |
---|
57 | contr = sldc-slds; |
---|
58 | |
---|
59 | Pi = 4.0*atan(1.0); |
---|
60 | vaj = -1.0*hDist/endRad; |
---|
61 | vbj = 1.0; //endpoints of inner integral |
---|
62 | |
---|
63 | summj=0.0; |
---|
64 | |
---|
65 | for(j=0;j<nordj;j++) { |
---|
66 | //20 gauss points for the inner integral |
---|
67 | zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0; //the "t" dummy |
---|
68 | yyy = Gauss76Wt[j] * ConvLens_kernel(dp,q,zij,zi); //uses the same Kernel as the Dumbbell, here L>0 |
---|
69 | summj += yyy; |
---|
70 | } |
---|
71 | //now calculate the value of the inner integral |
---|
72 | inner = (vbj-vaj)/2.0*summj; |
---|
73 | inner *= 4.0*Pi*endRad*endRad*endRad; |
---|
74 | |
---|
75 | //now calculate outer integrand |
---|
76 | arg1 = q*len/2.0*cos(zi); |
---|
77 | arg2 = q*rad*sin(zi); |
---|
78 | yyy = inner; |
---|
79 | |
---|
80 | if(arg2 == 0) { |
---|
81 | be = 0.5; |
---|
82 | } else { |
---|
83 | be = NR_BessJ1(arg2)/arg2; |
---|
84 | } |
---|
85 | |
---|
86 | if(arg1 == 0.0) { //limiting value of sinc(0) is 1; sinc is not defined in math.h |
---|
87 | yyy += Pi*rad*rad*len*2.0*be; |
---|
88 | } else { |
---|
89 | yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be; |
---|
90 | } |
---|
91 | yyy *= yyy; //sin(zi); |
---|
92 | answer = yyy; |
---|
93 | |
---|
94 | |
---|
95 | answer /= Pi*rad*rad*len + 2.0*Pi*(2.0*endRad*endRad*endRad/3.0+endRad*endRad*hDist-hDist*hDist*hDist/3.0); //divide by volume |
---|
96 | answer *= 1.0e8; //convert to cm^-1 |
---|
97 | answer *= contr*contr; |
---|
98 | answer *= scale; |
---|
99 | answer += bkg; |
---|
100 | |
---|
101 | return answer; |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | /** |
---|
106 | * Function to evaluate 2D scattering function |
---|
107 | * @param pars: parameters of the BarBell |
---|
108 | * @param q: q-value |
---|
109 | * @return: function value |
---|
110 | */ |
---|
111 | double capcyl_analytical_2DXY(CapCylParameters *pars, double qx, double qy){ |
---|
112 | double q; |
---|
113 | q = sqrt(qx*qx+qy*qy); |
---|
114 | return capcyl_analytical_2D_scaled(pars, q, qx/q, qy/q); |
---|
115 | } |
---|
116 | |
---|
117 | double capcyl_analytical_2D(CapCylParameters *pars, double q, double phi) { |
---|
118 | return capcyl_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); |
---|
119 | } |
---|
120 | |
---|
121 | /** |
---|
122 | * Function to evaluate 2D scattering function |
---|
123 | * @param pars: parameters of the BarBell |
---|
124 | * @param q: q-value |
---|
125 | * @param q_x: q_x / q |
---|
126 | * @param q_y: q_y / q |
---|
127 | * @return: function value |
---|
128 | */ |
---|
129 | double capcyl_analytical_2D_scaled(CapCylParameters *pars, double q, double q_x, double q_y) { |
---|
130 | double cyl_x, cyl_y, cyl_z; |
---|
131 | double q_z; |
---|
132 | double alpha, vol, cos_val; |
---|
133 | double answer; |
---|
134 | double dp[7]; |
---|
135 | |
---|
136 | dp[0] = pars->scale; |
---|
137 | dp[1] = pars->rad_cyl; |
---|
138 | dp[2] = pars->len_cyl; |
---|
139 | dp[3] = pars->rad_cap; |
---|
140 | dp[4] = pars->sld_capcyl; |
---|
141 | dp[5] = pars->sld_solv; |
---|
142 | dp[6] = pars->background; |
---|
143 | |
---|
144 | |
---|
145 | //double Pi = 4.0*atan(1.0); |
---|
146 | // Cylinder orientation |
---|
147 | cyl_x = sin(pars->theta) * cos(pars->phi); |
---|
148 | cyl_y = sin(pars->theta) * sin(pars->phi); |
---|
149 | cyl_z = cos(pars->theta); |
---|
150 | |
---|
151 | // q vector |
---|
152 | q_z = 0; |
---|
153 | |
---|
154 | // Compute the angle btw vector q and the |
---|
155 | // axis of the cylinder |
---|
156 | cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; |
---|
157 | |
---|
158 | // The following test should always pass |
---|
159 | if (fabs(cos_val)>1.0) { |
---|
160 | printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n"); |
---|
161 | return 0; |
---|
162 | } |
---|
163 | |
---|
164 | // Note: cos(alpha) = 0 and 1 will get an |
---|
165 | // undefined value from CylKernel |
---|
166 | alpha = acos( cos_val ); |
---|
167 | |
---|
168 | // Call the IGOR library function to get the kernel |
---|
169 | answer = capcyl2d_kernel(dp, q, alpha)/sin(alpha); |
---|
170 | |
---|
171 | |
---|
172 | return answer; |
---|
173 | |
---|
174 | } |
---|