[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. |
---|
[d529d93] | 5 | May be a reasonable approximation for other shapes of particles that |
---|
| 6 | freely rotate, and for moderately polydisperse systems. Though strictly |
---|
| 7 | the maths needs to be modified (no \Beta(Q) correction yet in sasview). |
---|
[301e096] | 8 | |
---|
[d529d93] | 9 | radius_effective is the effective hard sphere radius. |
---|
| 10 | volfraction is the volume fraction occupied by the spheres. |
---|
| 11 | |
---|
| 12 | In sasview the effective radius may be calculated from the parameters |
---|
| 13 | used in the form factor $P(q)$ that this $S(q)$ is combined with. |
---|
| 14 | |
---|
| 15 | For numerical stability the computation uses a Taylor series expansion |
---|
| 16 | at very small $qR$, there may be a very minor glitch at the transition point |
---|
| 17 | in some circumstances. |
---|
| 18 | |
---|
| 19 | The S(Q) uses the Percus-Yevick closure where the interparticle |
---|
[529b8b4] | 20 | potential is |
---|
[301e096] | 21 | |
---|
[eb69cce] | 22 | .. math:: |
---|
[529b8b4] | 23 | |
---|
| 24 | U(r) = \begin{cases} |
---|
| 25 | \infty & r < 2R \\ |
---|
| 26 | 0 & r \geq 2R |
---|
| 27 | \end{cases} |
---|
[301e096] | 28 | |
---|
[eb69cce] | 29 | where $r$ is the distance from the center of the sphere of a radius $R$. |
---|
[301e096] | 30 | |
---|
| 31 | For a 2D plot, the wave transfer is defined as |
---|
| 32 | |
---|
| 33 | .. math:: |
---|
| 34 | |
---|
[529b8b4] | 35 | q = \sqrt{q_x^2 + q_y^2} |
---|
[301e096] | 36 | |
---|
| 37 | |
---|
[eb69cce] | 38 | References |
---|
| 39 | ---------- |
---|
[301e096] | 40 | |
---|
| 41 | J K Percus, J Yevick, *J. Phys. Rev.*, 110, (1958) 1 |
---|
| 42 | """ |
---|
| 43 | |
---|
[3c56da87] | 44 | from numpy import inf |
---|
[301e096] | 45 | |
---|
[034e19a] | 46 | name = "hardsphere" |
---|
| 47 | title = "Hard sphere structure factor, with Percus-Yevick closure" |
---|
[301e096] | 48 | description = """\ |
---|
[3e428ec] | 49 | [Hard sphere structure factor, with Percus-Yevick closure] |
---|
[301e096] | 50 | Interparticle S(Q) for random, non-interacting spheres. |
---|
[3e428ec] | 51 | May be a reasonable approximation for other shapes of |
---|
| 52 | particles that freely rotate, and for moderately polydisperse |
---|
| 53 | systems. Though strictly the maths needs to be modified - |
---|
| 54 | which sasview does not do yet. |
---|
[d529d93] | 55 | radius_effective is the hard sphere radius |
---|
[3e428ec] | 56 | volfraction is the volume fraction occupied by the spheres. |
---|
[301e096] | 57 | """ |
---|
[a5d0d00] | 58 | category = "structure-factor" |
---|
[8e45182] | 59 | structure_factor = True |
---|
[e98c1e0] | 60 | single = False |
---|
[301e096] | 61 | |
---|
[3e428ec] | 62 | # ["name", "units", default, [lower, upper], "type","description"], |
---|
[d529d93] | 63 | parameters = [["radius_effective", "Ang", 50.0, [0, inf], "volume", |
---|
[3e428ec] | 64 | "effective radius of hard sphere"], |
---|
| 65 | ["volfraction", "", 0.2, [0, 0.74], "", |
---|
| 66 | "volume fraction of hard spheres"], |
---|
| 67 | ] |
---|
[301e096] | 68 | |
---|
| 69 | # No volume normalization despite having a volume parameter |
---|
| 70 | # This should perhaps be volume normalized? |
---|
| 71 | form_volume = """ |
---|
| 72 | return 1.0; |
---|
| 73 | """ |
---|
| 74 | |
---|
| 75 | Iq = """ |
---|
[f0fb9fe] | 76 | double D,A,B,G,X,X2,X4,S,C,FF,HARDSPH; |
---|
[934f906] | 77 | // these are c compiler instructions, can also put normal code inside the "if else" structure |
---|
| 78 | #if FLOAT_SIZE > 4 |
---|
| 79 | // double precision orig had 0.2, don't call the variable cutoff as PAK already has one called that! Must use UPPERCASE name please. |
---|
| 80 | // 0.05 better, 0.1 OK |
---|
| 81 | #define CUTOFFHS 0.05 |
---|
| 82 | #else |
---|
| 83 | // 0.1 bad, 0.2 OK, 0.3 good, 0.4 better, 0.8 no good |
---|
| 84 | #define CUTOFFHS 0.4 |
---|
| 85 | #endif |
---|
[f0fb9fe] | 86 | |
---|
[d529d93] | 87 | if(fabs(radius_effective) < 1.E-12) { |
---|
[f0fb9fe] | 88 | HARDSPH=1.0; |
---|
| 89 | return(HARDSPH); |
---|
| 90 | } |
---|
[97e6d3c] | 91 | // removing use of pow(xxx,2) and rearranging the calcs of A, B & G cut ~40% off execution time ( 0.5 to 0.3 msec) |
---|
| 92 | X = 1.0/( 1.0 -volfraction); |
---|
| 93 | D= X*X; |
---|
| 94 | A= (1.+2.*volfraction)*D; |
---|
| 95 | A *=A; |
---|
[d529d93] | 96 | X=fabs(q*radius_effective*2.0); |
---|
[f0fb9fe] | 97 | |
---|
| 98 | if(X < 5.E-06) { |
---|
| 99 | HARDSPH=1./A; |
---|
| 100 | return(HARDSPH); |
---|
| 101 | } |
---|
[97e6d3c] | 102 | X2 =X*X; |
---|
| 103 | B = (1.0 +0.5*volfraction)*D; |
---|
| 104 | B *= B; |
---|
| 105 | B *= -6.*volfraction; |
---|
[f0fb9fe] | 106 | G=0.5*volfraction*A; |
---|
| 107 | |
---|
[934f906] | 108 | if(X < CUTOFFHS) { |
---|
| 109 | // RKH Feb 2016, use Taylor series expansion for small X |
---|
[97e6d3c] | 110 | // else no obvious way to rearrange the equations to avoid needing a very high number of significant figures. |
---|
[f0fb9fe] | 111 | // Series expansion found using Mathematica software. Numerical test in .xls showed terms to X^2 are sufficient |
---|
[97e6d3c] | 112 | // for 5 or 6 significant figures, but I put the X^4 one in anyway |
---|
| 113 | //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; |
---|
| 114 | // refactoring the polynomial makes it very slightly faster (0.5 not 0.6 msec) |
---|
| 115 | //FF = 8*A +6*B + 4*G + ( -0.8*A -2.0*B/3.0 -0.5*G +(A/35. +B/40. +G/50.)*X2)*X2; |
---|
| 116 | |
---|
| 117 | FF = 8.0*A +6.0*B + 4.0*G + ( -0.8*A -B/1.5 -0.5*G +(A/35. +0.0125*B +0.02*G)*X2)*X2; |
---|
| 118 | |
---|
[f0fb9fe] | 119 | // combining the terms makes things worse at smallest Q in single precision |
---|
| 120 | //FF = (8-0.8*X2)*A +(3.0-X2/3.)*2*B + (4+0.5*X2)*G +(A/35. +B/40. +G/50.)*X4; |
---|
| 121 | // note that G = -volfraction*A/2, combining this makes no further difference at smallest Q |
---|
[97e6d3c] | 122 | //FF = (8 +2.*volfraction + ( volfraction/4. -0.8 +(volfraction/100. -1./35.)*X2 )*X2 )*A + (3.0 -X2/3. +X4/40.)*2.*B; |
---|
[f0fb9fe] | 123 | HARDSPH= 1./(1. + volfraction*FF ); |
---|
| 124 | return(HARDSPH); |
---|
| 125 | } |
---|
[97e6d3c] | 126 | X4=X2*X2; |
---|
[f0fb9fe] | 127 | SINCOS(X,S,C); |
---|
| 128 | |
---|
[97e6d3c] | 129 | // RKH Feb 2016, use version FISH code as is better than original sasview one at small Q in single precision, and more than twice as fast in double. |
---|
| 130 | //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; |
---|
| 131 | // refactoring the polynomial here & above makes it slightly faster |
---|
| 132 | |
---|
| 133 | FF= (( G*( (4.*X2 -24.)*X*S -(X4 -12.*X2 +24.)*C +24. )/X2 + B*(2.*X*S -(X2-2.)*C -2.) )/X + A*(S-X*C))/X ; |
---|
[f0fb9fe] | 134 | HARDSPH= 1./(1. + 24.*volfraction*FF/X2 ); |
---|
| 135 | |
---|
[97e6d3c] | 136 | // changing /X and /X2 to *MX1 and *MX2, no significantg difference? |
---|
| 137 | //MX=1.0/X; |
---|
| 138 | //MX2=MX*MX; |
---|
| 139 | //FF= (( G*( (4.*X2 -24.)*X*S -(X4 -12.*X2 +24.)*C +24. )*MX2 + B*(2.*X*S -(X2-2.)*C -2.) )*MX + A*(S-X*C)) ; |
---|
| 140 | //HARDSPH= 1./(1. + 24.*volfraction*FF*MX2*MX ); |
---|
| 141 | |
---|
| 142 | // grouping the terms, was about same as sasmodels for single precision issues |
---|
[f0fb9fe] | 143 | // 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 ); |
---|
| 144 | // HARDSPH= 1./(1. + 24.*volfraction*FF/X2 ); |
---|
| 145 | // remove 1/X2 from final line, take more powers of X inside the brackets, stil bad |
---|
| 146 | // 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; |
---|
| 147 | // HARDSPH= 1./(1. + 24.*volfraction*FF ); |
---|
| 148 | return(HARDSPH); |
---|
[301e096] | 149 | """ |
---|
| 150 | |
---|
| 151 | Iqxy = """ |
---|
| 152 | // never called since no orientation or magnetic parameters. |
---|
[529b8b4] | 153 | return Iq(sqrt(qx*qx+qy*qy), IQ_PARAMETERS); |
---|
[301e096] | 154 | """ |
---|
| 155 | |
---|
| 156 | # ER defaults to 0.0 |
---|
| 157 | # VR defaults to 1.0 |
---|
| 158 | |
---|
[d529d93] | 159 | demo = dict(radius_effective=200, volfraction=0.2, radius_effective_pd=0.1, radius_effective_pd_n=40) |
---|
[301e096] | 160 | oldname = 'HardsphereStructure' |
---|
[d529d93] | 161 | oldpars = dict(radius_effective="effect_radius",radius_effective_pd="effect_radius_pd",radius_effective_pd_n="effect_radius_pd_n") |
---|
[093f754] | 162 | # Q=0.001 is in the Taylor series, low Q part, so add Q=0.1, assuming double precision sasview is correct |
---|
[7f47777] | 163 | tests = [ |
---|
[d529d93] | 164 | [ {'scale': 1.0, 'background' : 0.0, 'radius_effective' : 50.0, 'volfraction' : 0.2, |
---|
| 165 | 'radius_effective_pd' : 0}, [0.001,0.1], [0.209128,0.930587]] |
---|
[7f47777] | 166 | ] |
---|
[d529d93] | 167 | # ADDED by: RKH ON: 16Mar2016 using equations from FISH as better than orig sasview, see notes above. Added Taylor expansions at small Q, |
---|