source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/NewModels_2006/TriaxialEllipsoid.ipf @ 166

Last change on this file since 166 was 166, checked in by srkline, 15 years ago

Modified all procedure files to add to the keyword=value strings to identify the function, coefficients, and suffix once the model is plotted (and the objects will exist)

a one-liner in the Plot and PlotSmeared? macros.

  • necessary for smoother functioning of the wrapper panel.
File size: 5.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4//#include "GaussUtils"
5//#include "PlotUtils"
6
7////////////////////////////////////////////////////
8//
9// calculates the scattering from a triaxial ellipsoid
10// with semi-axes a <= b <= c
11//
12// - the user must make sure that the constraints are not violated
13// otherwise the calculation will not be correct
14//
15// a double integral is used, both using Gaussian quadrature
16// routines that are now included with GaussUtils
17// 20-pt quadrature appears to be enough, 76 pt is available
18// by changing the function calls
19//
20////////////////////////////////////////////////////
21
22//this macro sets up all the necessary parameters and waves that are
23//needed to calculate the model function.
24//
25Proc PlotTriaxialEllipsoid(num,qmin,qmax)
26        Variable num=100, qmin=.001, qmax=.7
27        Prompt num "Enter number of data points for model: "
28        Prompt qmin "Enter minimum q-value (^1) for model: "
29        Prompt qmax "Enter maximum q-value (^1) for model: "
30        //
31        Make/O/D/n=(num) xwave_triax, ywave_triax
32        xwave_triax =  alog(log(qmin) + x*((log(qmax)-log(qmin))/num))
33        Make/O/D coef_triax = {1,35,100,400,6e-6,0}                     //CH#2
34        make/o/t parameters_triax = {"Scale Factor","Semi-axis A [smallest]()","Semi-axis B ()","Semi-axis C [largest]()","Contrast (^-2)","Incoherent Bgd (cm-1)"} //CH#3
35        Edit parameters_triax, coef_triax
36       
37        Variable/G root:g_triax
38        g_triax := TriaxialEllipsoid(coef_triax, ywave_triax, xwave_triax)
39        Display ywave_triax vs xwave_triax
40        ModifyGraph marker=29, msize=2, mode=4
41        ModifyGraph log=1
42        Label bottom "q (\\S-1\\M) "
43        Label left "I(q) (cm\\S-1\\M)"
44        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
45       
46        AddModelToStrings("TriaxialEllipsoid","coef_triax","triax")
47//
48End
49
50
51// - sets up a dependency to a wrapper, not the actual SmearedModelFunction
52Proc PlotSmearedTriaxialEllipsoid(str)                                                         
53        String str
54        Prompt str,"Pick the data folder containing the resolution you want",popup,getAList(4)
55       
56        // if any of the resolution waves are missing => abort
57        if(ResolutionWavesMissingDF(str))               //updated to NOT use global strings (in GaussUtils)
58                Abort
59        endif
60       
61        SetDataFolder $("root:"+str)
62       
63        // Setup parameter table for model function
64        Make/O/D smear_coef_triax = {1,35,100,400,6e-6,0}               //CH#4
65        make/o/t smear_parameters_triax = {"Scale Factor","A ()","B ()","C ()","Contrast (^-2)","Incoherent Bgd (cm-1)"}
66        Edit smear_parameters_triax,smear_coef_triax                                    //display parameters in a table
67       
68        // output smeared intensity wave, dimensions are identical to experimental QSIG values
69        // make extra copy of experimental q-values for easy plotting
70        Duplicate/O $(str+"_q") smeared_triax,smeared_qvals                             //
71        SetScale d,0,0,"1/cm",smeared_triax                                                     //
72                                       
73        Variable/G gs_triax=0
74        gs_triax := fSmearedTriaxialEllipsoid(smear_coef_triax,smeared_triax,smeared_qvals)     //this wrapper fills the STRUCT
75       
76        Display smeared_triax vs smeared_qvals                                                                  //
77        ModifyGraph log=1,marker=29,msize=2,mode=4
78        Label bottom "q (\\S-1\\M)"
79        Label left "I(q) (cm\\S-1\\M)"
80        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
81       
82        SetDataFolder root:
83        AddModelToStrings("SmearedTriaxialEllipsoid","smear_coef_triax","triax")
84End
85
86       
87
88//AAO version, uses XOP if available
89// simply calls the original single point calculation with
90// a wave assignment (this will behave nicely if given point ranges)
91Function TriaxialEllipsoid(cw,yw,xw) : FitFunc
92        Wave cw,yw,xw
93       
94#if exists("TriaxialEllipsoidX")
95        yw = TriaxialEllipsoidX(cw,xw)
96#else
97        yw = fTriaxialEllipsoid(cw,xw)
98#endif
99        return(0)
100End
101
102// calculates the form factor of an ellipsoidal solid
103// with semi-axes of a,b,c
104// - a double integral - choose points wisely
105//
106Function fTriaxialEllipsoid(w,x) : FitFunc
107        Wave w
108        Variable x
109//       Input (fitting) variables are:
110        //[0] scale factor
111        //[1] semi-axis A (A)
112        //[2] semi-axis B (A)
113        //[3] semi-axis C (A)
114        //[4] contrast (A^-2)
115        //[5] incoherent background (cm^-1)
116//      give them nice names
117        Variable scale,aa,bb,cc,contr,bkg,inten,qq,ii,arg,mu
118        scale = w[0]
119        aa = w[1]
120        bb = w[2]
121        cc = w[3]
122        contr = w[4]
123        bkg = w[5]
124       
125        Variable/G root:gDumY=0,root:gDumX=0
126       
127        inten = IntegrateFn20(TaE_Outer,0,1,w,x)
128       
129        inten *= 4*Pi/3*aa*cc*bb                //multiply by volume
130        inten *= 1e8            //convert to cm^-1
131        inten *= contr*contr
132        inten *= scale
133        inten += bkg
134       
135        Return (inten)
136End
137
138// outer integral
139// x is the q-value - remember that "mu" in the notation = B*Q
140Function TaE_Outer(w,x,dum)
141        Wave w
142        Variable x,dum
143       
144        Variable retVal,mu,aa,bb,cc,mudum,arg
145        aa = w[1]
146        bb = w[2]
147        cc = w[3]
148       
149        NVAR dy = root:gDumY
150        NVAR dx = root:gDumX
151        dy = dum
152        retval = IntegrateFn20(TaE_inner,0,1,w,x)
153       
154        return(retVal)
155End
156
157//returns the value of the integrand of the inner integral
158Function TaE_Inner(w,x,dum)
159        Wave w
160        Variable x,dum
161       
162        Variable aa,bb,cc,retVal
163       
164        NVAR dy = root:gDumY
165        NVAR dx = root:gDumX
166        dx = dum
167        aa = w[1]
168        bb = w[2]
169        cc = w[3]
170        retVal = TaE(x,aa,bb,cc,dx,dy)
171       
172        return(retVal)
173End
174
175Function TaE(qq,aa,bb,cc,dx,dy)
176        Variable qq,aa,bb,cc,dx,dy
177       
178        Variable val,arg
179        arg = aa*aa*cos(pi*dx/2)*cos(pi*dx/2)
180        arg += bb*bb*sin(pi*dx/2)*sin(pi*dx/2)*(1-dy*dy)
181        arg += cc*cc*dy*dy
182        arg = qq*sqrt(arg)
183       
184        val = 9*((sin(arg) - arg*cos(arg))/arg^3 )^2
185       
186        return(val)
187end
188
189//wrapper to calculate the smeared model as an AAO-Struct
190// fills the struct and calls the ususal function with the STRUCT parameter
191//
192// used only for the dependency, not for fitting
193//
194Function fSmearedTriaxialEllipsoid(coefW,yW,xW)
195        Wave coefW,yW,xW
196       
197        String str = getWavesDataFolder(yW,0)
198        String DF="root:"+str+":"
199       
200        WAVE resW = $(DF+str+"_res")
201       
202        STRUCT ResSmearAAOStruct fs
203        WAVE fs.coefW = coefW   
204        WAVE fs.yW = yW
205        WAVE fs.xW = xW
206        WAVE fs.resW = resW
207       
208        Variable err
209        err = SmearedTriaxialEllipsoid(fs)
210       
211        return (0)
212End
213               
214// this is all there is to the smeared calculation!
215Function SmearedTriaxialEllipsoid(s) :FitFunc
216        Struct ResSmearAAOStruct &s
217
218//      the name of your unsmeared model (AAO) is the first argument
219        Smear_Model_20(TriaxialEllipsoid,s.coefW,s.xW,s.yW,s.resW)
220
221        return(0)
222End
Note: See TracBrowser for help on using the repository browser.