source: sans/Analysis/branches/ajj_23APR07/IGOR_Package_Files/Put in User Procedures/SANS_Models_v3.00/Models_2D/CoreShellCyl2D.ipf @ 200

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

Changed 2D model calculations to use a FIXED 25 integration points in an effort to get the number of integration points out of the fitting coefficient wave.

Added "Freeze Model" back to the SANS Models menu

Added the 2D model functions to the list on the model picker

Minor tweaks to the wrapper

File size: 5.0 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion=6.0
3
4//
5// The plotting macro sets up TWO dependencies
6// - one for the triplet calculation
7// - one for a matrix to display, a copy of the triplet
8//
9// For display, there are two copies of the matrix. One matrix is linear, and is a copy of the
10// triplet (which is ALWAYS linear). The other matrix is toggled log/lin for display
11// in the same way the 2D SANS data matrix is handled.
12//
13
14///  REQUIRES DANSE XOP for 2D FUNCTIONS
15
16//
17// the calculation is done as for the QxQy data set:
18// three waves XYZ, then converted to a matrix
19//
20Proc PlotCoreShellCylinder2D(str)                                               
21        String str
22        Prompt str,"Pick the data folder containing the 2D data",popup,getAList(4)
23       
24        SetDataFolder $("root:"+str)
25       
26        // Setup parameter table for model function
27//      make/O/T/N=15 parameters_CSCyl2D
28//      Make/O/D/N=15 coef_CSCyl2D
29        make/O/T/N=14 parameters_CSCyl2D
30        Make/O/D/N=14 coef_CSCyl2D
31       
32        coef_CSCyl2D[0] = 1.0
33        coef_CSCyl2D[1] = 20.0
34        coef_CSCyl2D[2] = 10.0
35        coef_CSCyl2D[3] = 200.0
36        coef_CSCyl2D[4] = 1.0e-6
37        coef_CSCyl2D[5] = 4.0e-6
38        coef_CSCyl2D[6] = 1.0e-6
39        coef_CSCyl2D[7] = 0.0
40        coef_CSCyl2D[8] = 1.57
41        coef_CSCyl2D[9] = 0.0
42        coef_CSCyl2D[10] = 0.0
43        coef_CSCyl2D[11] = 0.0
44        coef_CSCyl2D[12] = 0.0
45        coef_CSCyl2D[13] = 0.0
46        //hard-wire the number of integration points
47//      coef_CSCyl2D[14] = 10
48       
49        parameters_CSCyl2D[0] = "Scale"
50        parameters_CSCyl2D[1] = "Radius"
51        parameters_CSCyl2D[2] = "Thickness"
52        parameters_CSCyl2D[3] = "Length"
53        parameters_CSCyl2D[4] = "Core SLD"
54        parameters_CSCyl2D[5] = "Shell SLD"
55        parameters_CSCyl2D[6] = "Solvent SLD"
56        parameters_CSCyl2D[7] = "Background"
57        parameters_CSCyl2D[8] = "Axis Theta"
58        parameters_CSCyl2D[9] = "Axis Phi"
59        parameters_CSCyl2D[10] = "Sigma of polydisp in Radius [Angstrom]"
60        parameters_CSCyl2D[11] = "Sigma of polydisp in Thickness [Angstrom]"
61        parameters_CSCyl2D[12] = "Sigma of polydisp in Theta [rad]"
62        parameters_CSCyl2D[13] = "Sigma of polydisp in Phi [rad]"
63//      parameters_CSCyl2D[14] = "Num of polydisp points"
64       
65        Edit parameters_CSCyl2D,coef_CSCyl2D                                   
66       
67        // generate the triplet representation
68        Duplicate/O $(str+"_qx") xwave_CSCyl2D
69        Duplicate/O $(str+"_qy") ywave_CSCyl2D,zwave_CSCyl2D                   
70               
71        Variable/G gs_CSCyl2D=0
72        gs_CSCyl2D := CoreShellCylinder2D(coef_CSCyl2D,zwave_CSCyl2D,xwave_CSCyl2D,ywave_CSCyl2D)       //AAO 2D calculation
73       
74        Display ywave_CSCyl2D vs xwave_CSCyl2D
75        modifygraph log=0
76        ModifyGraph mode=3,marker=16,zColor(ywave_CSCyl2D)={zwave_CSCyl2D,*,*,YellowHot,0}
77        ModifyGraph standoff=0
78        ModifyGraph width={Aspect,1}
79        ModifyGraph lowTrip=0.001
80        Label bottom "qx (A\\S-1\\M)"
81        Label left "qy (A\\S-1\\M)"
82        AutoPositionWindow/M=1/R=$(WinName(0,1)) $WinName(0,2)
83       
84        // generate the matrix representation
85        ConvertQxQy2Mat(xwave_CSCyl2D,ywave_CSCyl2D,zwave_CSCyl2D,"CSCyl2D_mat")
86        Duplicate/O $"CSCyl2D_mat",$"CSCyl2D_lin"               //keep a linear-scaled version of the data
87        // _mat is for display, _lin is the real calculation
88
89        // not a function evaluation - this simply keeps the matrix for display in sync with the triplet calculation
90        Variable/G gs_CSCyl2Dmat=0
91        gs_CSCyl2Dmat := UpdateQxQy2Mat(xwave_CSCyl2D,ywave_CSCyl2D,zwave_CSCyl2D,CSCyl2D_lin,CSCyl2D_mat)
92       
93       
94        SetDataFolder root:
95        AddModelToStrings("CoreShellCylinder2D","coef_CSCyl2D","CSCyl2D")
96End
97
98//AAO version, uses XOP if available
99// simply calls the original single point calculation with
100// a wave assignment (this will behave nicely if given point ranges)
101//
102// NON-THREADED IMPLEMENTATION
103//
104//Function CoreShellCylinder2D(cw,zw,xw,yw) : FitFunc
105//      Wave cw,zw,xw,yw
106//     
107//#if exists("CoreShellCylinderModel_D")
108//      Make/O/D/N=15 CSCyl2D_tmp
109//      CSCyl2D_tmp = cw
110//      CSCyl2D_tmp[14] = 25
111//
112//      zw = CoreShellCylinderModel_D(CSCyl2D_tmp,xw,yw)
113//     
114////    zw = CoreShellCylinderModel_D(cw,xw,yw)
115//#else
116//      Abort "You do not have the SANS Analysis XOP installed"
117//#endif
118//      return(0)
119//End
120//
121
122//threaded version of the function
123ThreadSafe Function CoreShellCylinder2D_T(cw,zw,xw,yw,p1,p2)
124        WAVE cw,zw,xw,yw
125        Variable p1,p2
126       
127#if exists("CoreShellCylinderModel_D")                  //to hide the function if XOP not installed
128
129        Make/O/D/N=15 CSCyl2D_tmp
130        CSCyl2D_tmp = cw
131        CSCyl2D_tmp[14] = 25
132
133        zw[p1,p2]= CoreShellCylinderModel_D(CSCyl2D_tmp,xw,yw)
134       
135#endif
136
137        return 0
138End
139
140//
141//  Fit function that is actually a wrapper to dispatch the calculation to N threads
142//
143// nthreads is 1 or an even number, typically 2
144// it doesn't matter if npt is odd. In this case, fractional point numbers are passed
145// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points
146// and the points "2.5" and "3.5" evaluate correctly as 2 and 3
147//
148Function CoreShellCylinder2D(cw,zw,xw,yw) : FitFunc
149        Wave cw,zw,xw,yw
150       
151        Variable npt=numpnts(yw)
152        Variable i,nthreads= ThreadProcessorCount
153        variable mt= ThreadGroupCreate(nthreads)
154
155        for(i=0;i<nthreads;i+=1)
156        //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1)
157                ThreadStart mt,i,CoreShellCylinder2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1))
158        endfor
159
160        do
161                variable tgs= ThreadGroupWait(mt,100)
162        while( tgs != 0 )
163
164        variable dummy= ThreadGroupRelease(mt)
165       
166        return(0)
167End
Note: See TracBrowser for help on using the repository browser.