source: sans/Analysis/trunk/Put in User Procedures/SANS_Models_v3.00/PolyHardSphereInten.ipf @ 56

Last change on this file since 56 was 42, checked in by srkline, 16 years ago

initial checkin of Analysis v.3.00 files

File size: 7.6 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2
3////////////////////////////////////////////////
4// GaussUtils.proc and PlotUtils.proc MUST be included for the smearing calculation to compile
5// Adopting these into the experiment will insure that they are always present
6////////////////////////////////////////////////
7// this example is for the scattered intensity from a dense dispersion of polydisperse spheres
8// hard sphere interactions are included (exact, multicomponent Percus-Yevick)
9// the polydispersity in radius is a Schulz distribution
10//
11// 06 NOV 98 SRK
12////////////////////////////////////////////////
13
14Proc PlotPolyHardSpheres(num,qmin,qmax)
15        Variable num=128,qmin=0.001,qmax=0.7
16        Prompt num "Enter number of data points for model: "
17        Prompt qmin "Enter minimum q-value (^-1) for model: "
18        Prompt qmax "Enter maximum q-value (^-1) for model: "
19       
20        Make/O/D/n=(num) xwave_phs,ywave_phs
21        xwave_phs =alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
22        Make/O/D coef_phs = {100,0.12,0.1,2.0e-6,0.1}
23        make/o/t parameters_phs = {"Radius (A)","polydispersity","volume fraction","contrast (A^-2)","background (cm^-1)"}
24        Edit parameters_phs,coef_phs
25        ywave_phs := PolyHSIntensity(coef_phs,xwave_phs)
26        Display ywave_phs vs xwave_phs
27        ModifyGraph log=1,marker=29,msize=2,mode=4
28        Label bottom "q (\\S-1\\M)"
29        Label left "Intensity (cm\\S-1\\M)"
30        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
31End
32
33///////////////////////////////////////////////////////////
34
35Proc PlotSmearedPolyHardSpheres()               
36        //no input parameters necessary, it MUST use the experimental q-values
37        // from the experimental data read in from an AVE/QSIG data file
38       
39        // if no gQvals wave, data must not have been loaded => abort
40        if(ResolutionWavesMissing())
41                Abort
42        endif
43       
44        // Setup parameter table for model function
45        Make/O/D smear_coef_phs = {100,0.12,0.1,2.0e-6,0.1}
46        make/o/t smear_parameters_phs = {"Radius (A)","polydispersity","volume fraction","contrast (A^-2)","background (cm^-1)"}
47        Edit smear_parameters_phs,smear_coef_phs
48       
49        // output smeared intensity wave, dimensions are identical to experimental QSIG values
50        // make extra copy of experimental q-values for easy plotting
51        Duplicate/O $gQvals smeared_phs,smeared_qvals
52        SetScale d,0,0,"1/cm",smeared_phs
53
54        smeared_phs := SmearedPolyHardSpheres(smear_coef_phs,$gQvals)
55        Display smeared_phs vs smeared_qvals
56        ModifyGraph log=1,marker=29,msize=2,mode=4
57        Label bottom "q (\\S-1\\M)"
58        Label left "Intensity (cm\\S-1\\M)"
59        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
60End
61
62
63///////////////////////////////////////////////////////////////
64// unsmeared model calculation
65//   This program calculates the effective structure factor for a suspension
66//   of spheres whose size distribution is given by a Schulz distribution
67//   PY closure was used to solve.  Equations are analytical.
68//   Follows paper by W.L. Griffith, Phys. Rev. A 35 (5) p.2200 1987
69//  Original coding (F) by Jon Bender, U. Delaware
70//      converted to c 2/97 SRK
71// converted to IGOR 12/97 SRK
72//
73// replace single letter variables like "e" with "ee" (to be done MAY04)
74//
75///////////////////////////
76Function PolyHSIntensity(w,k) : FitFunc
77        Wave w                  // the coefficient wave
78        Variable k              // the x values, as a variable (single k is OK)
79
80        // assign local variables
81        Variable mu,mu1,d1,d2,d3,d4,d5,d6,capd,rho,beta
82        Variable ll,l1,bb,cc,chi,chi1,chi2,ee,t1,t2,t3,pp
83        Variable ka,zz,v1,v2,p1,p2
84        Variable h1,h2,h3,h4,e1,yy,y1,ss,s1,s2,s3,hint1,hint2
85        Variable capl,capl1,capmu,capmu1,r3,pq,happ
86        Variable ka2,r1,heff
87        Variable hh
88         
89        //* reassign names to the variable set */
90        Variable rad,z2,phi,cont,bkg,sigma
91         
92        rad = w[0]              // radius (A)
93        sigma = 2*rad
94        z2 = w[1]               //polydispersity (0<z2<1)
95        phi = w[2]              // volume fraction (0<phi<1)
96        cont = w[3]*1.0e4               // contrast (odd units)
97        bkg = w[4]              // background (1/cm)
98
99        zz=1/(z2*z2)-1.0
100        bb = sigma/(zz+1)
101        cc = zz+1
102
103//*c   Compute the number density by <r-cubed>, not <r> cubed*/
104        r1 = sigma/2.0
105        r3 = r1*r1*r1
106        r3 *= (zz+2)*(zz+3)/((zz+1)*(zz+1))
107        rho=phi/(1.3333333333*pi*r3)
108        t1 = rho*bb*cc
109        t2 = rho*bb*bb*cc*(cc+1)
110        t3 = rho*bb*bb*bb*cc*(cc+1)*(cc+2)
111        capd = 1-pi*t3/6
112//************
113        v1=1/(1+bb*bb*k*k)
114        v2=1/(4+bb*bb*k*k)
115        pp=(v1^(cc/2))*sin(cc*atan(bb*k))
116        p1=bb*cc*(v1^((cc+1)/2))*sin((cc+1)*atan(bb*k))
117        p2=cc*(cc+1)*bb*bb*(v1^((cc+2)/2))*sin((cc+2)*atan(bb*k))
118        mu=(2^cc)*(v2^(cc/2))*sin(cc*atan(bb*k/2))
119        mu1=(2^(cc+1))*bb*cc*(v2^((cc+1)/2))*sin((cc+1)*atan(k*bb/2))
120        s1=bb*cc
121        s2=cc*(cc+1)*bb*bb
122        s3=cc*(cc+1)*(cc+2)*bb*bb*bb
123        chi=(v1^(cc/2))*cos(cc*atan(bb*k))
124        chi1=bb*cc*(v1^((cc+1)/2))*cos((cc+1)*atan(bb*k))
125        chi2=cc*(cc+1)*bb*bb*(v1^((cc+2)/2))*cos((cc+2)*atan(bb*k))
126        ll=(2^cc)*(v2^(cc/2))*cos(cc*atan(bb*k/2))
127        l1=(2^(cc+1))*bb*cc*(v2^((cc+1)/2))*cos((cc+1)*atan(k*bb/2))
128        d1=(pi/capd)*(2+(pi/capd)*(t3-(rho/k)*(k*s3-p2)))
129        d2=((pi/capd)^2)*(rho/k)*(k*s2-p1)
130        d3=(-1.0)*((pi/capd)^2)*(rho/k)*(k*s1-pp)
131        d4=(pi/capd)*(k-(pi/capd)*(rho/k)*(chi1-s1))
132        d5=((pi/capd)^2)*((rho/k)*(chi-1)+0.5*k*t2)
133        d6=((pi/capd)^2)*(rho/k)*(chi2-s2)
134 // e1,e,y1,y evaluated in one big ugly line instead - no continuation character in IGOR
135//            e1=pow((pi/capd),2)*pow((rho/k/k),2)*((chi-1)*(chi2-s2)
136//       -(chi1-s1)*(chi1-s1)-(k*s1-p)*(k*s3-p2)+pow((k*s2-p1),2));
137//            e=1-(2*pi/capd)*(1+0.5*pi*t3/capd)*(rho/k/k/k)*(k*s1-p)
138//       -(2*pi/capd)*rho/k/k*((chi1-s1)+(0.25*pi*t2/capd)*(chi2-s2))-e1;
139//            y1=pow((pi/capd),2)*pow((rho/k/k),2)*((k*s1-p)*(chi2-s2)
140//       -2*(k*s2-p1)*(chi1-s1)+(k*s3-p2)*(chi-1));
141//            y = (2*pi/capd)*(1+0.5*pi*t3/capd)*(rho/k/k/k)
142//       *(chi+0.5*k*k*s2-1)-(2*pi*rho/capd/k/k)*(k*s2-p1
143//       +(0.25*pi*t2/capd)*(k*s3-p2))-y1;
144       
145        e1=((pi/capd)^2)*((rho/k/k)^2)*((chi-1)*(chi2-s2)-(chi1-s1)*(chi1-s1)-(k*s1-pp)*(k*s3-p2)+((k*s2-p1)^2))
146        ee=1-(2*pi/capd)*(1+0.5*pi*t3/capd)*(rho/k/k/k)*(k*s1-pp)-(2*pi/capd)*rho/k/k*((chi1-s1)+(0.25*pi*t2/capd)*(chi2-s2))-e1
147        y1=((pi/capd)^2)*((rho/k/k)^2)*((k*s1-pp)*(chi2-s2)-2*(k*s2-p1)*(chi1-s1)+(k*s3-p2)*(chi-1))
148        yy = (2*pi/capd)*(1+0.5*pi*t3/capd)*(rho/k/k/k)*(chi+0.5*k*k*s2-1)-(2*pi*rho/capd/k/k)*(k*s2-p1+(0.25*pi*t2/capd)*(k*s3-p2))-y1       
149
150        capl=2.0*pi*cont*rho/k/k/k*(pp-0.5*k*(s1+chi1))
151        capl1=2.0*pi*cont*rho/k/k/k*(p1-0.5*k*(s2+chi2))
152        capmu=2.0*pi*cont*rho/k/k/k*(1-chi-0.5*k*p1)
153        capmu1=2.0*pi*cont*rho/k/k/k*(s1-chi1-0.5*k*p2)
154 
155        h1=capl*(capl*(yy*d1-ee*d6)+capl1*(yy*d2-ee*d4)+capmu*(ee*d1+yy*d6)+capmu1*(ee*d2+yy*d4))
156        h2=capl1*(capl*(yy*d2-ee*d4)+capl1*(yy*d3-ee*d5)+capmu*(ee*d2+yy*d4)+capmu1*(ee*d3+yy*d5))
157        h3=capmu*(capl*(ee*d1+yy*d6)+capl1*(ee*d2+yy*d4)+capmu*(ee*d6-yy*d1)+capmu1*(ee*d4-yy*d2))
158        h4=capmu1*(capl*(ee*d2+yy*d4)+capl1*(ee*d3+yy*d5)+capmu*(ee*d4-yy*d2)+capmu1*(ee*d5-yy*d3))
159
160//*  This part computes the second integral in equation (1) of the paper.*/
161
162        hint1 = -2.0*(h1+h2+h3+h4)/(k*k*k*(ee*ee+yy*yy))
163 
164//*  This part computes the first integral in equation (1).  It also
165// generates the KC approximated effective structure factor.*/
166
167        pq=4*pi*cont*(sin(k*sigma/2)-0.5*k*sigma*cos(k*sigma/2))
168        hint2=8*pi*pi*rho*cont*cont/(k*k*k*k*k*k)*(1-chi-k*p1+0.25*k*k*(s2+chi2))
169 
170        ka=k*(sigma/2)
171//
172        hh=hint1+hint2          // this is the model intensity
173//
174        heff=1.0+hint1/hint2
175        ka2=ka*ka
176//*
177//  heff is PY analytical solution for intensity divided by the
178//   form factor.  happ is the KC approximated effective S(q)
179 
180//*******************
181//  add in the background then return the intensity value
182
183        return (hh+bkg)
184
185End   // end of fcngrif()
186
187// this is all there is to the smeared calculation!
188Function SmearedPolyHardSpheres(w,x) :FitFunc
189        Wave w
190        Variable x
191       
192        Variable ans
193        SVAR sq = gSig_Q
194        SVAR qb = gQ_bar
195        SVAR sh = gShadow
196        SVAR gQ = gQVals
197       
198        //the name of your unsmeared model is the first argument
199        ans = Smear_Model_20(PolyHSIntensity,$sq,$qb,$sh,$gQ,w,x)
200
201        return(ans)
202End
Note: See TracBrowser for help on using the repository browser.