[301e096] | 1 | # Note: model title and parameter table are inserted automatically |
---|
[529b8b4] | 2 | r"""Calculate the interparticle structure factor for monodisperse |
---|
| 3 | spherical particles interacting through hard sphere (excluded volume) |
---|
| 4 | interactions. |
---|
[301e096] | 5 | |
---|
[529b8b4] | 6 | The calculation uses the Percus-Yevick closure where the interparticle |
---|
| 7 | potential is |
---|
[301e096] | 8 | |
---|
[eb69cce] | 9 | .. math:: |
---|
[529b8b4] | 10 | |
---|
| 11 | U(r) = \begin{cases} |
---|
| 12 | \infty & r < 2R \\ |
---|
| 13 | 0 & r \geq 2R |
---|
| 14 | \end{cases} |
---|
[301e096] | 15 | |
---|
[eb69cce] | 16 | where $r$ is the distance from the center of the sphere of a radius $R$. |
---|
[301e096] | 17 | |
---|
| 18 | For a 2D plot, the wave transfer is defined as |
---|
| 19 | |
---|
| 20 | .. math:: |
---|
| 21 | |
---|
[529b8b4] | 22 | q = \sqrt{q_x^2 + q_y^2} |
---|
[301e096] | 23 | |
---|
| 24 | |
---|
[7ed702f] | 25 | .. figure:: img/hardSphere_1d.jpg |
---|
[301e096] | 26 | |
---|
[eb69cce] | 27 | 1D plot using the default values (in linear scale). |
---|
[301e096] | 28 | |
---|
[eb69cce] | 29 | References |
---|
| 30 | ---------- |
---|
[301e096] | 31 | |
---|
| 32 | J K Percus, J Yevick, *J. Phys. Rev.*, 110, (1958) 1 |
---|
| 33 | """ |
---|
| 34 | |
---|
[3c56da87] | 35 | from numpy import inf |
---|
[301e096] | 36 | |
---|
[f0fb9fe] | 37 | name = "hardsphere_fish" |
---|
| 38 | title = "Hard sphere structure factor from FISH, with Percus-Yevick closure" |
---|
[301e096] | 39 | description = """\ |
---|
[3e428ec] | 40 | [Hard sphere structure factor, with Percus-Yevick closure] |
---|
[301e096] | 41 | Interparticle S(Q) for random, non-interacting spheres. |
---|
[3e428ec] | 42 | May be a reasonable approximation for other shapes of |
---|
| 43 | particles that freely rotate, and for moderately polydisperse |
---|
| 44 | systems. Though strictly the maths needs to be modified - |
---|
| 45 | which sasview does not do yet. |
---|
| 46 | effect_radius is the hard sphere radius |
---|
| 47 | volfraction is the volume fraction occupied by the spheres. |
---|
[301e096] | 48 | """ |
---|
[a5d0d00] | 49 | category = "structure-factor" |
---|
[301e096] | 50 | |
---|
[3e428ec] | 51 | # ["name", "units", default, [lower, upper], "type","description"], |
---|
| 52 | parameters = [["effect_radius", "Ang", 50.0, [0, inf], "volume", |
---|
| 53 | "effective radius of hard sphere"], |
---|
| 54 | ["volfraction", "", 0.2, [0, 0.74], "", |
---|
| 55 | "volume fraction of hard spheres"], |
---|
| 56 | ] |
---|
[301e096] | 57 | |
---|
| 58 | # No volume normalization despite having a volume parameter |
---|
| 59 | # This should perhaps be volume normalized? |
---|
| 60 | form_volume = """ |
---|
| 61 | return 1.0; |
---|
| 62 | """ |
---|
| 63 | |
---|
| 64 | Iq = """ |
---|
[f0fb9fe] | 65 | double D,A,B,G,X,X2,X4,S,C,FF,HARDSPH; |
---|
| 66 | |
---|
| 67 | if(fabs(effect_radius) < 1.E-12) { |
---|
| 68 | HARDSPH=1.0; |
---|
| 69 | return(HARDSPH); |
---|
| 70 | } |
---|
| 71 | D=pow((1.-volfraction),2); |
---|
| 72 | A=pow((1.+2.*volfraction)/D, 2); |
---|
| 73 | X=fabs(q*effect_radius*2.0); |
---|
| 74 | |
---|
| 75 | if(X < 5.E-06) { |
---|
| 76 | HARDSPH=1./A; |
---|
| 77 | return(HARDSPH); |
---|
| 78 | } |
---|
| 79 | X2=pow(X,2); |
---|
| 80 | X4=pow(X2,2); |
---|
| 81 | B=-6.*volfraction* pow((1.+0.5*volfraction)/D ,2); |
---|
| 82 | G=0.5*volfraction*A; |
---|
| 83 | |
---|
| 84 | if(X < 0.2) { |
---|
| 85 | // use Taylor series expansion for small X, IT IS VERY PICKY ABOUT THE X CUT OFF VALUE, ought to be lower in double. |
---|
| 86 | // No obvious way to rearrange the equations to avoid needing a very high number of significant figures. |
---|
| 87 | // Series expansion found using Mathematica software. Numerical test in .xls showed terms to X^2 are sufficient |
---|
| 88 | // for 5 or 6 significant figures but I put the X^4 one in anyway |
---|
| 89 | FF = 8*A +6*B + 4*G - (0.8*A +2.0*B/3.0 +0.5*G)*X2 +(A/35. +B/40. +G/50.)*X4; |
---|
| 90 | // combining the terms makes things worse at smallest Q in single precision |
---|
| 91 | //FF = (8-0.8*X2)*A +(3.0-X2/3.)*2*B + (4+0.5*X2)*G +(A/35. +B/40. +G/50.)*X4; |
---|
| 92 | // note that G = -volfraction*A/2, combining this makes no further difference at smallest Q |
---|
| 93 | //FF = (8 +2.*volfraction + ( volfraction/4. -0.8 +(volfraction/100. -1./35.)*X2 )*X2 )*A + (3.0 -X2/3. +X4/40)*2*B; |
---|
| 94 | HARDSPH= 1./(1. + volfraction*FF ); |
---|
| 95 | return(HARDSPH); |
---|
| 96 | } |
---|
| 97 | SINCOS(X,S,C); |
---|
| 98 | |
---|
| 99 | // RKH Feb 2016, use version from FISH code as it is better than original sasview one at small Q in single precision |
---|
| 100 | FF=A*(S-X*C)/X + B*(2.*X*S -(X2-2.)*C -2.)/X2 + G*( (4.*X2*X -24.*X)*S -(X4 -12.*X2 +24.)*C +24. )/X4; |
---|
| 101 | HARDSPH= 1./(1. + 24.*volfraction*FF/X2 ); |
---|
| 102 | |
---|
| 103 | // rearrange the terms, is now about same as sasmodels |
---|
| 104 | // FF=A*(S/X-C) + B*(2.*S/X - C +2.0*(C-1.0)/X2) + G*( (4./X -24./X3)*S -(1.0 -12./X2 +24./X4)*C +24./X4 ); |
---|
| 105 | // HARDSPH= 1./(1. + 24.*volfraction*FF/X2 ); |
---|
| 106 | // remove 1/X2 from final line, take more powers of X inside the brackets, stil bad |
---|
| 107 | // FF=A*(S/X3-C/X2) + B*(2.*S/X3 - C/X2 +2.0*(C-1.0)/X4) + G*( (4./X -24./X3)*S -(1.0 -12./X2 +24./X4)*C +24./X4 )/X2; |
---|
| 108 | // HARDSPH= 1./(1. + 24.*volfraction*FF ); |
---|
| 109 | return(HARDSPH); |
---|
[301e096] | 110 | """ |
---|
| 111 | |
---|
| 112 | Iqxy = """ |
---|
| 113 | // never called since no orientation or magnetic parameters. |
---|
[529b8b4] | 114 | return Iq(sqrt(qx*qx+qy*qy), IQ_PARAMETERS); |
---|
[301e096] | 115 | """ |
---|
| 116 | |
---|
| 117 | # ER defaults to 0.0 |
---|
| 118 | # VR defaults to 1.0 |
---|
| 119 | |
---|
[3e428ec] | 120 | demo = dict(effect_radius=200, volfraction=0.2, effect_radius_pd=0.1, effect_radius_pd_n=40) |
---|
[301e096] | 121 | oldname = 'HardsphereStructure' |
---|
| 122 | oldpars = dict() |
---|
[093f754] | 123 | # Q=0.001 is in the Taylor series, low Q part, so add Q=0.1, assuming double precision sasview is correct |
---|
[7f47777] | 124 | tests = [ |
---|
| 125 | [ {'scale': 1.0, 'background' : 0.0, 'effect_radius' : 50.0, 'volfraction' : 0.2, |
---|
[093f754] | 126 | 'effect_radius_pd' : 0}, [0.001,0.1], [0.209128,0.930587]] |
---|
[7f47777] | 127 | ] |
---|
| 128 | |
---|