1 | /** |
---|
2 | * Scattering model for a fuzzy sphere |
---|
3 | */ |
---|
4 | |
---|
5 | #include <math.h> |
---|
6 | #include "libSphere.h" |
---|
7 | #include "fuzzysphere.h" |
---|
8 | #include <stdio.h> |
---|
9 | #include <stdlib.h> |
---|
10 | |
---|
11 | // scattering from a uniform sphere w/ fuzzy surface |
---|
12 | // Modified from FuzzySpheres in libigor/libSphere.c without polydispersion: JHC |
---|
13 | double fuzzysphere_kernel(double dp[], double q){ |
---|
14 | double pi,x,xr; |
---|
15 | double radius,sldSph,sldSolv,scale,bkg,delrho,fuzziness,f2,bes,vol,f; //my local names |
---|
16 | |
---|
17 | pi = 4.0*atan(1.0); |
---|
18 | x= q; |
---|
19 | scale = dp[0]; |
---|
20 | radius = dp[1]; |
---|
21 | fuzziness = dp[2]; |
---|
22 | sldSph = dp[3]; |
---|
23 | sldSolv = dp[4]; |
---|
24 | bkg = dp[5]; |
---|
25 | delrho=sldSph-sldSolv; |
---|
26 | |
---|
27 | xr = x*radius; |
---|
28 | //handle xr==0 separately |
---|
29 | if(xr == 0.0){ |
---|
30 | bes = 1.0; |
---|
31 | }else{ |
---|
32 | bes = 3.0*(sin(xr)-xr*cos(xr))/(xr*xr*xr); |
---|
33 | } |
---|
34 | vol = 4.0*pi/3.0*radius*radius*radius; |
---|
35 | f = vol*bes*delrho; // [=] A |
---|
36 | f *= exp(-0.5*fuzziness*fuzziness*x*x); |
---|
37 | // normalize to single particle volume, convert to 1/cm |
---|
38 | f2 = f * f / vol * 1.0e8; // [=] 1/cm |
---|
39 | |
---|
40 | f2 *= scale; |
---|
41 | f2 += bkg; |
---|
42 | |
---|
43 | return(f2); //scale, and add in the background |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | /** |
---|
48 | * Function to evaluate 1D scattering function |
---|
49 | * @param pars: parameters of the fuzzysphere |
---|
50 | * @param q: q-value |
---|
51 | * @return: function value |
---|
52 | */ |
---|
53 | double fuzzysphere_analytical_1D(FuzzySphereParameters *pars, double q) { |
---|
54 | double dp[6]; |
---|
55 | |
---|
56 | dp[0] = pars->scale; |
---|
57 | dp[1] = pars->radius; |
---|
58 | dp[2] = pars->fuzziness; |
---|
59 | dp[3] = pars->sldSph; |
---|
60 | dp[4] = pars->sldSolv; |
---|
61 | dp[5] = pars->background; |
---|
62 | |
---|
63 | return fuzzysphere_kernel(dp, q); |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Function to evaluate 2D scattering function |
---|
68 | * @param pars: parameters of the fuzzysphere |
---|
69 | * @param q: q-value |
---|
70 | * @return: function value |
---|
71 | */ |
---|
72 | double fuzzysphere_analytical_2D(FuzzySphereParameters *pars, double q, double phi) { |
---|
73 | return fuzzysphere_analytical_1D(pars,q); |
---|
74 | } |
---|
75 | |
---|
76 | double sphere_analytical_2DXY(FuzzySphereParameters *pars, double qx, double qy){ |
---|
77 | return fuzzysphere_analytical_1D(pars,sqrt(qx*qx+qy*qy)); |
---|
78 | } |
---|