Nuclear Instruments and Methods in Physics Research A 634 (2011) S150–S155
Contents lists available at ScienceDirect
Nuclear Instruments and Methods in Physics Research A journal homepage: www.elsevier.com/locate/nima
Using McStas for modelling complex optics, using simple building bricks Peter K. Willendrup a,, Linda Udby b, Erik Knudsen a, Emmanuel Farhi c, Kim Lefmann b,d a
Risø National Laboratory for Sustainable Energy, Technical University of Denmark, Materials Research Division, Frederiksborgvej 399, DK-4000, Denmark University of Copenhagen, Nanoscience and Escience Centers, Niels Bohr Institute, Universitetsparken 5, DK-2100, Denmark Institut Laue-Langevin (ILL), 6 rue J. Horowitz, BP 156, 38042 Grenoble Cedex 9, France d ESS, University of Lund, St. Algatan 4, Sweden b c
a r t i c l e in f o
a b s t r a c t
Available online 2 July 2010
The McStas neutron ray-tracing simulation package is a versatile tool for producing accurate neutron simulations, extensively used for design and optimization of instruments, virtual experiments, data analysis and user training. In McStas, component organization and simulation flow is intrinsically linear: the neutron interacts with the beamline components in a sequential order, one by one. Historically, a beamline component with several parts had to be implemented with a complete, internal description of all these parts, e.g. a guide component including all four mirror plates and required logic to allow scattering between the mirrors. For quite a while, users have requested the ability to allow ‘‘components inside components’’ or meta-components, allowing to combine functionality of several simple components to achieve more complex behaviour, i.e. four single mirror plates together defining a guide. We will here show that it is now possible to define meta-components in McStas, and present a set of detailed, validated examples including a guide with an embedded, wedged, polarizing mirror system of the Helmholtz–Zentrum Berlin type. & 2010 Elsevier B.V. All rights reserved.
Keywords: Monte Carlo simulation McStas Neutron optics Beamline components
1. Introduction The McStas [1,3,4] neutron ray-tracing simulation package is a versatile tool for producing accurate neutron simulations, extensively used for design and optimization of instruments, virtual experiments [2], data analysis and user training. For those unfamiliar with McStas and its concepts, a summary of facts and figures is provided 1.1. The McStas project, facts and figures
McStas first official release in October 1998 (v. 1.0). McStas is at release 1.12a (April 2009—1.12b expected soon
and 2.0 later in 2010). McStas has 136 components in categories of sources, optics, samples and monitors. McStas since 2009 includes support for polarized neutrons. McStas includes 52 example instruments. McStas has complete documentation and tutorial material, all included. McStas is free, open source software (GNU Public License version 2.0).
Corresponding author.
E-mail address:
[email protected] (P.K. Willendrup). 0168-9002/$ - see front matter & 2010 Elsevier B.V. All rights reserved. doi:10.1016/j.nima.2010.06.212
McStas includes valuable user contributions. McStas is used at all major neutron scattering facilities. McStas is platform independent, Debian and Ubuntu GNU/
Linux, Windows XP and Vista (32 bit versions), Mac OS X 10.3-10.6, Solaris 10, FreeBSD are fully supported. McStas features easy-to-use parallelization methods for multicore machines, clusters and grids. Installation is straightforward on all these platforms, but we provide VMware and Knoppix stand-alone solutions for users who want that. Ready to run—no installation procedure.
1.2. Instruments and components In McStas, all users build up an instrumentfile, positioning existing optics- and material components found in the library. Generally, components correspond to structures on the beamline, with given geometry and material properties, i.e. a rectangular reflecting mirror or a linearly tapered guide. The component organization and simulation flow is intrinsically linear: the neutron interacts with the beamline components in a sequential order, one by one. Historically, a beamline component with several parts had to be implemented inside one component with a complete, internal description of all these parts, e.g. a guide component including all
P.K. Willendrup et al. / Nuclear Instruments and Methods in Physics Research A 634 (2011) S150–S155
four mirror plates and required logic to allow scattering between the mirrors.
1.3. Meta-components A meta-component is here thought of as an ‘‘assembly’’ of ‘‘simple’’ McStas components, that together forms a more complex arrangement, shape or behaviour. Those familiar with McStas will already know the GROUP construction which allows several components to work in parallel. One way to think about meta-components is as an iterative, re-entrant GROUP. In the following examples, we define a set of McStas components, propagation to ensure that the neutron leaves each component after scattering plus use of the JUMP keyword for re-entering the meta-component.
2. Examples The following examples all take onset from a McStas instrument with
A small divergent source (size 1 mm2), emitting either neutrons in a narrow band around 5 meV or the full
S151
cold+thermal range of 0–25 meV, taken from a flat energy distribution. A 10 m long guide/mirror assembly with a cross-section of 10 10 cm2. Monitors just before and after the guide. Use of 3 A set of global instrument variables used to probe whether the neutron was scattered or not. 3 EXTEND blocks for setting the instrument variables and performing slight propagation (1 ns) after scattering. (In the standard Mirror component, the neutron is only propagated to the mirror—then the direction of the velocity vector is affected, and hence will fulfill the scattering condition on the same mirror when re-entering the meta-component.). 3 A JUMP statement that returns the neutron to the entrypoint of the meta-component until it was not scattered in the meta-component (i.e. finished interacting with the components inside).
The simplest example is included in the Appendix. 2.1. Linear guide As a starting example of creating McStas meta-components from standard library components, we here build up a guide from
Fig. 1. Left: intensity transported by standard McStas guide component. Right: intensity transported by single-mirror type guide. In complete agreement.
Fig. 2. Left: energy distribution transported by standard McStas guide component. Right: energy distribution transported by single-mirror type guide. In complete agreement.
S152
P.K. Willendrup et al. / Nuclear Instruments and Methods in Physics Research A 634 (2011) S150–S155
a set of four mirrors. (See Appendix A.) The example code has three input parameters: mirror length ML, distance source to mirror MD and Guide which controls if the standard McStas Guide or 4 mirrors is used, by means of WHEN statements. Parameters of the Guide and 4 Mirror plate components correspond to the standard McStas description of an m ¼2
supermirror. Arm components are used to position the 4 Mirror components to shape a guide. Slit components are used before and after the meta-component to mimic the standard Guide which absorbs neutrons that miss the entry or exit. As can be seen in Fig. 1, the transported beam is identical when comparing the Guide component and the meta-component. Also
Fig. 3. Left: events transmitted through guide without scattering. Right: single-mirror type guide, events that scattered on mirror walls.
Fig. 4. McStas simulation output. Top left: beam at guide entry. Top right: full beam after transmission through guide with inserted beamstop. Bottom left: portion of full beam not reflected on guide walls. Bottom right: portion of full beam reflected on guide walls.
P.K. Willendrup et al. / Nuclear Instruments and Methods in Physics Research A 634 (2011) S150–S155
S153
Fig. 5. Axis-parallel visualization of single neutron ray travelling through single-mirror guide with inserted wedge mirrors. Notice reflection on guide wall, inserted wedge, guide wall, and transmission through inserted wedge. (Guide 50 m long for visualization purposes.)
the energy distribution transported is identical in the two cases, as seen in Fig. 2. The approach also allows to study which neutrons were reflected on the mirrors and those which were transported directly, as can be seen in Fig. 3.
2.2. Guide with inserted beamstop To show that other types of components can be included in a meta-component, a circular beamstop is introduced inside the meta-component, halfway between entry and exit. As expected, the central part of the beam is absorbed, as seen in Fig. 4. In addition, neutrons reflected from the guide are seen not to be affected by the beam stop.
2.3. Guide with inserted wedge-mirror Further adding in complexity, two inclined mirrors are added, shaping a wedge mirror extending through the full length of the guide. This resembles the beam polarizing setup at Helmholtz– Zentrum Berlin. In Fig. 5, a neutron bouncing between the wedge-mirror and the outer mirrors is shown (guide length is here 50 m for visualization purposes). The full, transported beam through a 10 m guide is shown in Fig. 6. Neutron polarization effects have not been studied.
3. Conclusion In this paper we have shown that it is now feasible to combine e.g. McStas mirror components into more complex assemblies, using the proposed technique. The main advantage is that the user in some cases avoids writing a new component from scratch, but can rely on existing, well-tested components. A main drawback of the method is that the neutron state at component exit is not handled in exactly the same way across components and could require specific knowledge and handling in the EXTEND sections. Furthermore, some components could require more extensive logic, e.g. when parallelly GROUP’ed components are inserted in the meta-component. In the near future, the McStas team will further explore possibilities and boundary conditions of the method, possibly attacking the problem of component-specific neutron exit states. When component behaviour is uniformized, we will consider to implement the needed Arm’s, JUMP and EXTEND logic using the McStas meta-language, e.g. by a new ASSEMBLY keyword: COMPONENT Mirror1 ¼ Mirror(xwidth ¼ 0.1, yheight ¼ ML, center¼1) AT (0, 0.05, 0) RELATIVE ArmMid ROTATED (-90, 0, 0) RELATIVE ArmMid ASSEMBLY Guide_parts
Alternatively by modification of the existing GROUP mechanism.
S154
P.K. Willendrup et al. / Nuclear Instruments and Methods in Physics Research A 634 (2011) S150–S155
Fig. 6. McStas simulation output. Top left: beam at guide entry. Top right: full beam after transmission through guide with inserted wedge. Bottom left: portion of full beam not reflected on guide walls. Bottom right: portion of full beam reflected on guide walls.
Appendix A. Example code DEFINE INSTRUMENT test(MD¼10,ML¼10,Guide¼0) DECLARE %{ double Scatt, EverScatt; %} TRACE COMPONENT Origin ¼ Progress_bar() AT (0,0,0) ABSOLUTE EXTEND %{ Scatt ¼ 0; EverScatt ¼ 0; %} COMPONENT PointSource ¼ Source_div( xwidth ¼ 0.001, yheight¼0.001, focus_ah ¼180*asin(0.1/MD)/PI, focus_aw ¼ 180*asin(0.1/MD)/PI, E0 ¼5, dE ¼ 0.1) AT (0, 0, 0) RELATIVE Origin COMPONENT ArmEntry ¼ Arm() AT (0,0,MD) RELATIVE PointSource COMPONENT SlitEntry ¼ Slit(xwidth¼0.1, yheight¼0.1) AT (0,0, 0.01) RELATIVE ArmEntry
COMPONENT PreGuidePSD ¼ PSD_monitor( filename ¼ ‘‘preguide", xwidth ¼ 0.11, yheight ¼ 0.11) AT (0, 0, 0.001) RELATIVE SlitEntry COMPONENT ArmMid ¼ Arm() AT (0,0,ML/2.0) RELATIVE ArmEntry EXTEND %{ Scatt ¼ 0; SCATTER; %} COMPONENT Guide0 ¼ Guide(l¼ML, w1 ¼0.1,h1¼0.1,w2¼ 0.1,h2¼0.1,Qc¼0.021) WHEN (Guide¼ ¼1) AT (0,0,0) RELATIVE ArmEntry COMPONENT Mirror1 ¼ Mirror( xwidth ¼ 0.1, yheight ¼ ML, center¼1) WHEN (Guide¼ ¼0) AT (0, 0.05, 0) RELATIVE ArmMid ROTATED (-90, 0, 0) RELATIVE ArmMid EXTEND %{ if (SCATTERED) { Scatt ¼ 1; PROP_DT(1e 9); SCATTER; } %} COMPONENT Mirror2 ¼ Mirror( xwidth ¼ 0.1, yheight¼ ML, center ¼1)
P.K. Willendrup et al. / Nuclear Instruments and Methods in Physics Research A 634 (2011) S150–S155
WHEN (Guide¼ ¼ 0) AT (0, 0.05, 0) RELATIVE ArmMid ROTATED (90, 0, 0) RELATIVE ArmMid EXTEND %{ if (SCATTERED) { Scatt ¼ 2; PROP_DT(1e 9); SCATTER; } %} COMPONENT Mirror3 ¼ Mirror( xwidth ¼ ML, yheight ¼ 0.1, center¼1) WHEN (Guide¼ ¼0) AT (0.05, 0, 0) RELATIVE ArmMid ROTATED (0, 90, 0) RELATIVE ArmMid EXTEND %{ if (SCATTERED) { Scatt ¼ 3; PROP_DT(1e 9); SCATTER; } %} COMPONENT Mirror4 ¼ Mirror( xwidth ¼ ML, yheight ¼ 0.1, center¼1) WHEN (Guide¼ ¼ 0) AT ( 0.05, 0, 0) RELATIVE ArmMid ROTATED (0, 90, 0) RELATIVE ArmMid EXTEND %{ if (SCATTERED) { Scatt ¼ 4; PROP_DT(1e 9); SCATTER; } %} COMPONENT ArmMid2 ¼ Arm() AT (0,0,0) RELATIVE ArmMid EXTEND %{ if (Scatt ¼ ¼ 0) { SCATTER; } else EverScatt ¼ 1; %} COMPONENT ArmMid3 ¼ Arm ()
S155
AT (0,0,0) RELATIVE ArmMid JUMP ArmMid WHEN (Scatt > 0) COMPONENT ArmExit ¼ Arm() AT (0,0,ML/2.0) RELATIVE ArmMid COMPONENT SlitExit ¼ Slit(xwidth¼ 0.1, yheight¼0.1) AT (0,0,0.01) RELATIVE ArmExit COMPONENT EndGuidePSD ¼ PSD_monitor( filename ¼ ‘‘endguide", xwidth ¼ 0.11, yheight ¼ 0.11) AT (0, 0, 0.01) RELATIVE ArmExit COMPONENT EndGuidePSD2 ¼ PSD_monitor( filename ¼ ‘‘endguide2", xwidth ¼ 0.11, yheight ¼ 0.11) WHEN (EverScatt ¼ ¼ 0) AT (0, 0, 0.0101) RELATIVE ArmExit COMPONENT EndGuidePSD3 ¼ PSD_monitor( filename ¼ ‘‘endguide3", xwidth ¼ 0.11, yheight ¼ 0.11) WHEN (EverScatt) AT (0, 0, 0.0102) RELATIVE ArmExit END
References [1] K. Lefmann, K. Nielsen, Neutron News 10 (1999) 20. [2] P. Willendrup, et al., Physica B-Condensed Matter 385 (2006) 1032. [3] P. Willendrup, et al., User and Programmers Guide to the Neutron Ray-Tracing Package McStas, Version 1.12, Risø-R-1416 (rev. ed.) (EN), ISBN 978-87-5503679-6. [4] McStas project website at /http://www.mcstas.orgS.