source: sasmodels/sasmodels/models/cylinder.c @ 1f21edf

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 1f21edf was 1f21edf, checked in by Paul Kienzle <pkienzle@…>, 10 years ago

restore missing 4x in cylinder.c form

  • Property mode set to 100644
File size: 7.2 KB
Line 
1/* PARAMETERS
2{
3name: "cylinder",
4title: "Cylinder with uniform scattering length density",
5include: [ "lib/J1.c", "lib/gauss76.c", "lib/cylkernel.c" ],
6parameters: [
7   // [ "name", "units", default, [lower, upper], "type", "description" ],
8   [ "sld", "1e-6/Ang^2", 4, [-Infinity,Infinity], "",
9     "Cylinder scattering length density" ],
10   [ "solvent_sld", "1e-6/Ang^2", 1, [-Infinity,Infinity], "",
11     "Solvent scattering length density" ],
12   [ "radius", "Ang",  20, [0, Infinity], "volume",
13     "Cylinder radius" ],
14   [ "length", "Ang",  400, [0, Infinity], "volume",
15     "Cylinder length" ],
16   [ "theta", "degrees", 60, [-Infinity, Infinity], "orientation",
17     "In plane angle" ],
18   [ "phi", "degrees", 60, [-Infinity, Infinity], "orientation",
19     "Out of plane angle" ],
20],
21}
22PARAMETERS END
23
24DOCUMENTATION
25.. _CylinderModel:
26
27CylinderModel
28=============
29
30This model provides the form factor for a right circular cylinder with uniform
31scattering length density. The form factor is normalized by the particle volume.
32
33For information about polarised and magnetic scattering, click here_.
34
35Definition
36----------
37
38The output of the 2D scattering intensity function for oriented cylinders is
39given by (Guinier, 1955)
40
41.. math::
42
43    P(q,\alpha) = \frac{\text{scale}}{V}f^2(q) + \text{bkg}
44
45where
46
47.. math::
48
49    f(q) = 2 (\Delta \rho) V
50           \frac{\sin (q L/2 \cos \alpha)}{q L/2 \cos \alpha}
51           \frac{J_1 (q r \sin \alpha)}{q r \sin \alpha}
52
53and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, $V$
54is the volume of the cylinder, $L$ is the length of the cylinder, $r$ is the
55radius of the cylinder, and $d\rho$ (contrast) is the scattering length density
56difference between the scatterer and the solvent. $J_1$ is the first order
57Bessel function.
58
59To provide easy access to the orientation of the cylinder, we define the
60axis of the cylinder using two angles $\theta$ and $\phi$. Those angles
61are defined in Figure :num:`figure #CylinderModel-orientation`.
62
63.. _CylinderModel-orientation:
64
65.. figure:: img/image061.JPG
66
67    Definition of the angles for oriented cylinders.
68
69.. figure:: img/image062.JPG
70
71    Examples of the angles for oriented pp against the detector plane.
72
73NB: The 2nd virial coefficient of the cylinder is calculated based on the
74radius and length values, and used as the effective radius for $S(Q)$
75when $P(Q) \cdot S(Q)$ is applied.
76
77The returned value is scaled to units of |cm^-1| and the parameters of
78the CylinderModel are the following:
79
80%(parameters)s
81
82The output of the 1D scattering intensity function for randomly oriented
83cylinders is then given by
84
85.. math::
86
87    P(q) = \frac{\text{scale}}{V}
88        \int_0^{\pi/2} f^2(q,\alpha) \sin \alpha d\alpha + \text{background}
89
90The *theta* and *phi* parameters are not used for the 1D output. Our
91implementation of the scattering kernel and the 1D scattering intensity
92use the c-library from NIST.
93
94Validation of the CylinderModel
95-------------------------------
96
97Validation of our code was done by comparing the output of the 1D model
98to the output of the software provided by the NIST (Kline, 2006).
99Figure :num:`figure #CylinderModel-compare` shows a comparison of
100the 1D output of our model and the output of the NIST software.
101
102.. _CylinderModel-compare:
103
104.. figure:: img/image065.JPG
105
106    Comparison of the SasView scattering intensity for a cylinder with the
107    output of the NIST SANS analysis software.
108    The parameters were set to: *Scale* = 1.0, *Radius* = 20 |Ang|,
109    *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and
110    *Background* = 0.01 |cm^-1|.
111
112In general, averaging over a distribution of orientations is done by
113evaluating the following
114
115.. math::
116
117    P(q) = \int_0^{\pi/2} d\phi
118        \int_0^\pi p(\theta, \phi) P_0(q,\alpha) \sin \theta d\theta
119
120
121where $p(\theta,\phi)$ is the probability distribution for the orientation
122and $P_0(q,\alpha)$ is the scattering intensity for the fully oriented
123system. Since we have no other software to compare the implementation of
124the intensity for fully oriented cylinders, we can compare the result of
125averaging our 2D output using a uniform distribution $p(\theta, \phi) = 1.0$.
126Figure :num:`figure #CylinderModel-crosscheck` shows the result of
127such a cross-check.
128
129.. _CylinderModel-crosscheck:
130
131.. figure:: img/image066.JPG
132
133    Comparison of the intensity for uniformly distributed cylinders
134    calculated from our 2D model and the intensity from the NIST SANS
135    analysis software.
136    The parameters used were: *Scale* = 1.0, *Radius* = 20 |Ang|,
137    *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and
138    *Background* = 0.0 |cm^-1|.
139
140DOCUMENTATION END
141*/
142real form_volume(real radius, real length);
143real Iq(real q, real sld, real solvent_sld, real radius, real length);
144real Iqxy(real qx, real qy, real sld, real solvent_sld, real radius, real length, real theta, real phi);
145
146
147real form_volume(real radius, real length)
148{
149    return M_PI*radius*radius*length;
150}
151
152real Iq(real q,
153    real sld,
154    real solvent_sld,
155    real radius,
156    real length)
157{
158    const real h = REAL(0.5)*length;
159    real summ = REAL(0.0);
160    for (int i=0; i<76 ;i++) {
161        //const real zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0;
162        const real zi = REAL(0.5)*(Gauss76Z[i]*M_PI_2 + M_PI_2);
163        summ += Gauss76Wt[i] * CylKernel(q, radius, h, zi);
164    }
165    //const real form = (uplim-lolim)/2.0*summ;
166    const real form = summ * M_PI_4;
167
168    // Multiply by contrast^2, normalize by cylinder volume and convert to cm-1
169    // NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
170    // The additional volume factor is for polydisperse volume normalization.
171    const real s = (sld - solvent_sld) * form_volume(radius, length);
172    return REAL(1.0e-4) * form * s * s;
173}
174
175
176real Iqxy(real qx, real qy,
177    real sld,
178    real solvent_sld,
179    real radius,
180    real length,
181    real theta,
182    real phi)
183{
184    real sn, cn; // slots to hold sincos function output
185
186    // Compute angle alpha between q and the cylinder axis
187    SINCOS(theta*M_PI_180, sn, cn);
188    // # The following correction factor exists in sasview, but it can't be
189    // # right, so we are leaving it out for now.
190    // const real correction = fabs(cn)*M_PI_2;
191    const real q = sqrt(qx*qx+qy*qy);
192    const real cos_val = cn*cos(phi*M_PI_180)*(qx/q) + sn*(qy/q);
193    const real alpha = acos(cos_val);
194
195    // The following is CylKernel() / sin(alpha), but we are doing it in place
196    // to avoid sin(alpha)/sin(alpha) for alpha = 0.  It is also a teensy bit
197    // faster since we don't mulitply and divide sin(alpha).
198    SINCOS(alpha, sn, cn);
199    const real besarg = q*radius*sn;
200    const real siarg = REAL(0.5)*q*length*cn;
201    // lim_{x->0} J1(x)/x = 1/2,   lim_{x->0} sin(x)/x = 1
202    const real bj = (besarg == REAL(0.0) ? REAL(0.5) : J1(besarg)/besarg);
203    const real si = (siarg == REAL(0.0) ? REAL(1.0) : sin(siarg)/siarg);
204    const real form = REAL(4.0)*bj*bj*si*si;
205
206    // Multiply by contrast^2, normalize by cylinder volume and convert to cm-1
207    // NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl
208    // The additional volume factor is for polydisperse volume normalization.
209    const real s = (sld - solvent_sld) * form_volume(radius, length);
210    return REAL(1.0e-4) * form * s * s; // * correction;
211}
Note: See TracBrowser for help on using the repository browser.