1/*******************************************************************************
2*         McStas instrument definition URL=http://www.mcstas.org
3*
4* Instrument: Template monochromator Diffractometer
5*
6* %Identification
7* Written by: C. M. I Enrique, K. Lieutenant, E. Farhi and L. Cussen
8* Date: 13 Apr 2006
9* Origin: ILL
10* %INSTRUMENT_SITE: ILL
11*
12* Simple monochromator Diffractometer for powders
13*
14* %Description
15* The diffractometer D2B is characterised by the very high take-off angle (135 deg)
16* for the monochromator, which has a relatively large mosaic spread of 20' to
17* compensate for the corresponding intensity (dl/l) loss. It is 300 mm high,
18* focusing vertically onto about 50 mm; this large incident vertical divergence
19* is matched by 200 mm high detectors and collimators. A complete diffraction
20* pattern is obtained after about 100 steps of 0.025 deg in 2theta, since the 64
21* detectors are spaced at 2.5 deg intervals. Such scans take typically 30 minutes;
22* they are repeated to improve statistics.
23*
24* D2B was designed for work on samples and high resolution of very large
25* d-spacings using wavelengths of between 2.4 Å and 6 Å. Wavelengths can easily be
26* changed under computer control, since they are all obtained by a simple rotation
27* within the Ge[hhl] plane. A large graphite filter can be switched in to provide
28* a very clean beam at 2.4 Angs, and a cold Be-filter can be used for longer
29* wavelengths.
30*
31* This model implements as well the Caglioti UVW equations, that give estimates
32* of the instrument resolution.
33*
34* Monochromator lattice parameter
35* Ge       111 DM=3.266 AA
36* Ge       311 DM=1.714 AA
37* Ge       511 DM=1.089 AA
38* Ge       533 DM=0.863 AA
39*
40* %Example: lambda=1 Detector: D2B_BananaPSD_I=1.4489E+04
41*
42* %Parameters
43* lambda: [Angs]  Wavelength at monochromator, computed from DM and THETA_M if left as 0.
44* coating: [1]    Super-mirror in-beam tube guide coating
45* DM: [Angs]      d-spacing of monochromator, computed from lambda and THETA_M if left as 0.
46* THETA_M: [deg]  Monochromator take-off angle, computed from lambda and DM if left as 0.
47* TILT: [deg]     Monochromator additional tilt, for rocking curves
48* RV: [m]         Monochromator vertical curvature, 0 for flat, -1 for automatic setting
49* L1: [m]         Source-Monochromator distance
50* L2: [m]         Monochromator-Sample distance
51* L3: [m]         Sample-Detector distance
52* Powder: [str]   File name for powder description
53* verbose: [1]    Print DIF configuration. 0 to be quiet
54* ALPHA1: [min]   Horizontal collimator divergence for L1 arm (before monochromator)
55* ALPHA2: [min]   Horizontal collimator divergence for L2 arm (monochromator-sample)
56* ALPHA3: [min]   Horizontal collimator divergence for L3 arm (sample-detector)
57* ETA: [min]      Monochromator horizontal mosaic (gaussian)
58* SM: [1]         Scattering sense of beam from Monochromator. 1:left, -1:right
59* Dheight: [m]    Banana detector height
60*
61* %Link
62* G. Caglioti, A. Paoletti, F.P. Ricci, Nucl. Instr. and. Meth. 3 (1958) 223
63* %Link
64* L.D. Cussen, Nucl. Instr. and. Meth. A 554 (2005) 406
65* %Link
66* M. Morhac, NIM A 600 (2009) 478
67*
68* %End
69*******************************************************************************/
70DEFINE INSTRUMENT ILL_D2B(lambda=1.594, DM=0, string Powder="Na2Ca3Al2F14.laz", RV=-1, L1=16.05, L2=2.645, L3=1.3, verbose=1, ALPHA1=18,ALPHA2=11,ALPHA3=5, ETA=12, THETA_M=67.5, TILT=0, SM=1, Dheight=0.3,coating=0)
71
72/* The DECLARE section allows us to declare variables or  small      */
73/* functions in C syntax. These may be used in the whole instrument. */
74DECLARE
75%{
76double U,V,W;   /* Caglioti UVW parameters */
77double L0;
78%}
79
80/* The INITIALIZE section is executed when the simulation starts     */
81/* (C code). You may use them as component parameter values.         */
82INITIALIZE
83%{
84double L;
85double KI, Vi, EI;
86double ALPHA3_Opt;
87
88if (!THETA_M && lambda && DM)
89	THETA_M =asin(lambda/(2*DM))*RAD2DEG;
90else if (THETA_M && !lambda && DM)
91	lambda = fabs(sin(THETA_M*DEG2RAD))*2*DM;
92else if (THETA_M && lambda)
93	DM = fabs(lambda/sin(DEG2RAD*THETA_M)/2.0);
94
95THETA_M *= SM; /* take-off direction left or right */
96
97/* test input parameters */
98if (!THETA_M || !DM || !lambda) exit(fprintf(stderr,
99      "%s: ERROR: Monochromator take-off, d-spacing or wavelength is null (THETA_M=%g, DM=%g, lambda=%g). Abort.\n",
100      NAME_CURRENT_COMP, THETA_M, DM, lambda));
101
102/* perform additional computations */
103if (!L1)    L = L2;
104else        L = 1/(1/L1+1/L2);
105if (RV < 0) RV=2*L*sin(DEG2RAD*THETA_M);
106KI = 2*PI/lambda;
107Vi = K2V*fabs(KI);
108EI = VS2E*Vi*Vi;
109
110if (ALPHA1<0)  ALPHA1=600;
111if (ALPHA2<0)  ALPHA2=600;
112if (ALPHA3<0)  ALPHA3=600;
113if (ETA<=0)    ETA   =30;
114
115/* compute Cagioloti U,V,W and L0 (intensity) */
116U = 4*(ALPHA1*ALPHA1 * ALPHA2*ALPHA2 + ALPHA1*ALPHA1 * ETA*ETA + ALPHA2*ALPHA2 * ETA*ETA)
117     /(tan(THETA_M*DEG2RAD)*tan(THETA_M*DEG2RAD) * (ALPHA1*ALPHA1 + ALPHA2*ALPHA2 + 4*ETA*ETA));
118
119V = 4*ALPHA2*ALPHA2*(ALPHA1*ALPHA1 +2*ETA*ETA)
120     /(tan(THETA_M*DEG2RAD) * (ALPHA1*ALPHA1 + ALPHA2*ALPHA2 + 4*ETA*ETA));
121
122W = ALPHA3*ALPHA3+(ALPHA1*ALPHA1 * ALPHA2*ALPHA2 + 4*ALPHA2*ALPHA2 * ETA*ETA)
123                 /(ALPHA1*ALPHA1 + ALPHA2*ALPHA2 + 4*ETA*ETA);
124L0 = (ALPHA1*ETA*ALPHA2*ALPHA3/tan(fabs(THETA_M)*DEG2RAD))
125   / sqrt(ALPHA1*ALPHA1 + ALPHA2*ALPHA2 + 4*ETA*ETA);
126
127ALPHA3_Opt = 1/sqrt(1/ALPHA1/ALPHA1+1/ALPHA2/ALPHA2+1/ETA/ETA);
128
129if (verbose) {
130  printf("%s: Detailed DIF configuration\n", NAME_CURRENT_COMP);
131  printf("* Incoming beam: lambda=%.4g [Angs] EI=%.4g [meV]  KI=%.4g [Angs-1] Vi=%g [m/s]\n",
132    lambda, EI, KI, Vi);
133  printf("* Monochromator:  DM=%.4g [Angs] RV=%.4g [m] %s, take-off 2*THETA_M=%.4g [deg]\n",
134    DM, RV, (!RV ? "flat" : "curved"), THETA_M*2);
135  printf("* Resolution:     Caglioti              U=%g V=%g W=%g [deg^2]\n", U/60/60, V/60/60, W/60/60);
136  printf("                  Optimal          ALPHA3=%g [min]\n",  ALPHA3_Opt);
137  printf("                  Optimal resolution A1/2=%g [min]\n",  ALPHA3_Opt/sqrt(2));
138  printf("                  Normalized Intensity L0=%g [min^3]\n", L0);
139}
140
141RV = fabs(RV)*SM;
142
143
144%}
145
146/* Here comes the TRACE section, where the actual      */
147/* instrument is defined as a sequence of components.  */
148TRACE
149
150COMPONENT Origin = Progress_bar()
151  AT (0,0,0) ABSOLUTE
152
153/* source with constant flux. Directly send neutron events to monochromator area */
154COMPONENT Source = Source_gen(dist = 11, focus_xw = fabs(0.05*fabs(sin(DEG2RAD*THETA_M))), focus_yh = 0.3, radius=0.11,
155	lambda0 = lambda, dlambda = lambda*0.01,
156	T1=683.7,I1=0.5874e+13,T2=257.7,I2=2.5099e+13,T3=16.7 ,I3=1.0343e+12)
157  AT (0, 0, 0) RELATIVE Origin
158
159/* octogonal slit, and further rectangular slits */
160COMPONENT Win0 = Slit(radius = 0.11)                   AT (0, 0, 2.462) RELATIVE Origin
161COMPONENT Oct1 = Slit(xwidth = 0.15, yheight = 0.15)   AT (0, 0, 2.512) RELATIVE Origin
162COMPONENT Oct2 = Slit(xwidth = 0.177, yheight = 0.177) AT (0, 0, 2.512) RELATIVE Origin ROTATED (0,0,45) RELATIVE Origin
163COMPONENT Win1 = Slit(radius = 0.0565)  AT (0, 0, 3.5321) RELATIVE Origin
164COMPONENT Win2 = Slit(radius = 0.0555)  AT (0, 0, 4.0421) RELATIVE Origin
165COMPONENT Win3 = Slit(radius = 0.0575)  AT (0, 0, 4.087)  RELATIVE Origin
166COMPONENT Win4 = Slit(radius = 0.0575)  AT (0, 0, 4.999)  RELATIVE Origin
167COMPONENT Win5 = Slit(radius = 0.0625)  AT (0, 0, 5.006)  RELATIVE Origin
168COMPONENT Win6 = Slit(radius = 0.0625)  AT (0, 0, 5.151)  RELATIVE Origin
169
170COMPONENT SMguide = Guide(w1=0.07, h1=0.3, m=coating, l=5)
171  WHEN (coating>0)
172  AT (0,0,11) RELATIVE Origin
173
174/* ALPHA1 collimator */
175COMPONENT Alpha_One = Collimator_linear(
176  xwidth = 0.07, yheight = 0.30, length = 0.70, divergence = ALPHA1, transmission = 1.0)
177  WHEN (ALPHA1>0)
178  AT (0, 0, L1-1.045) RELATIVE Origin
179
180COMPONENT Slit_Mono = Slit(xwidth = 0.05, yheight = 0.3)
181  AT (0, 0, L1-0.1) RELATIVE Origin
182
183COMPONENT D2B_Mono_XY = Monitor_nD(
184     options="x y, all auto",
185     bins = 40, xwidth = 0.1, yheight = 0.3, restore_neutron=1)
186   AT (0, 0, 0) RELATIVE PREVIOUS
187COMPONENT D2B_ALPHA1_Div = Monitor_nD(
188     options="dx dy, all auto",
189     bins = 40, xwidth = 0.1, yheight = 0.3, restore_neutron=1)
190   AT (0, 0, 0) RELATIVE PREVIOUS
191COMPONENT D2B_Mono_Lambda = Monitor_nD(
192     options="lambda, all auto",
193     bins = 40, xwidth = 0.1, yheight = 0.3, restore_neutron=1)
194   AT (0, 0, 0) RELATIVE PREVIOUS
195
196/* TIP: monochromator cradle */
197COMPONENT mono_cradle = Arm()
198  AT (0, 0, L1) RELATIVE Origin
199
200/* TIP: curved monochromator with NH>1 NV>1 et RH>0 RV>0 */
201SPLIT COMPONENT Monok = Monochromator_curved(
202    width = 0.1, height = 0.3, NH = 1, NV = 28, RV=RV,
203    mosaich = ETA, mosaicv = 12, DM = DM)
204  AT (0, 0, 0) RELATIVE mono_cradle
205  ROTATED (0, THETA_M+TILT, 0) RELATIVE mono_cradle
206
207/* TIP: positioning diffraction direction for monok (order 1) */
208COMPONENT mono_out = Arm()
209  AT (0, 0, 0) RELATIVE mono_cradle
210  ROTATED (0, 2*THETA_M, 0) RELATIVE mono_cradle
211
212COMPONENT Shield_Hole = Guide_channeled(
213    w1 = 0.05, h1 = 0.274, w2 = 0.044, h2 = 0.201, l = 0.752, R0 = 0, nslit = 1)
214  AT (0, 0, 0.304) RELATIVE mono_out
215
216/* ALPHA2 collimator */
217COMPONENT Alpha_Two = Collimator_linear(
218    xwidth = 0.05, yheight = 0.2, length = 0.2, divergence = ALPHA2, transmission = 1.0)
219  WHEN (ALPHA2>0)
220  AT (0, 0, L2-0.25) RELATIVE mono_out
221
222COMPONENT Slit_Sample = Slit(xwidth = 0.01, yheight = 0.05)
223  AT (0, 0, L2-0.02) RELATIVE mono_out
224
225COMPONENT D2B_ALPHA2_Div = Monitor_nD(
226     options="dx dy, all auto",
227     bins = 40, xwidth = 0.02, yheight = 0.05, restore_neutron=1)
228   AT (0, 0, 0) RELATIVE PREVIOUS
229COMPONENT D2B_Sample_Lambda = Monitor_nD(
230     options="lambda, all auto",
231     bins = 40, xwidth = 0.02, yheight = 0.05, restore_neutron=1)
232   AT (0, 0, 0) RELATIVE PREVIOUS
233
234/* sample position */
235SPLIT COMPONENT Arm_Sample = Arm()
236  AT (0, 0, L2) RELATIVE mono_out
237
238COMPONENT Container_in = PowderN(reflections="V.laz", radius = 0.0025+0.00051, thickness = 0.0005, yheight = 0.04,
239                         concentric = 1, p_interact=0.1, d_phi=RAD2DEG*atan2(Dheight+0.05,L3))
240  AT (0, 0, 0) RELATIVE Arm_Sample
241
242COMPONENT Sample = PowderN(
243    reflections = Powder, radius = 0.0025, d_phi=RAD2DEG*atan2(Dheight+0.05,L3),
244    yheight = 0.04)
245  AT (0, 0, 0) RELATIVE Arm_Sample
246
247COMPONENT Container_out = COPY(Container_in)(concentric=0)
248  AT (0, 0, 0) RELATIVE Arm_Sample
249
250/* ALPHA3 radial collimator */
251COMPONENT collimador_radial = Collimator_radial(
252    yheight=Dheight, length=.30,
253    divergence=ALPHA3,verbose=1,approx=1,
254    theta_min=-165, theta_max=-5, radius=L3-0.3-0.01)
255  WHEN (ALPHA3>0)
256	AT (0, 0, 0) RELATIVE Sample
257
258/* perfect detector: 1D(theta) */
259COMPONENT D2B_BananaTheta = Monitor_nD(
260    options = "banana, angle limits=[5 165], bins=3200",
261    radius = L3, yheight = Dheight, restore_neutron=1)
262  AT (0, 0, 0) RELATIVE Sample
263
264COMPONENT D2B_BananaThetaCenter = Monitor_nD(
265    options = "banana, angle limits=[5 165], bins=3200",
266    radius = L3, yheight = 0.1, restore_neutron=1)
267  AT (0, 0, 0) RELATIVE Sample
268
269/* perfect detector: 2D(theta,y) to see diffraction rings */
270COMPONENT D2B_BananaPSD = Monitor_nD(
271    options = "banana, theta limits=[-165 -5] bins=320, y bins=25",
272    radius = L3*1.005, yheight = Dheight)
273  AT (0, 0, 0) RELATIVE Sample
274
275/* The END token marks the instrument definition end */
276END
277
278