Bachelor project

– Investigation of neutron moderators with spherical voids

Mads Bertelsen (10.08.1988) and Pia Jensen (15.07.1988). Project done during block 1 and 2 in the year 2010/2011. Hand-in date: 06.01.2011.

Primary project supervisor: Kim Lefmann^{a}. Secondary project supervisor: Ian Bearden^{b}. Safety representant: Axel Boisen^{c}.

aNanophysics, Niels Bohr Institute. ^{b}Experimental Particle Physics, Niels Bohr Institute. ^{c}Technics and Support, Niels Bohr Institute.

ii

Abstract  iii

Abstract

In this project, neutron moderation is investigated by theoretical calculations, simulation and experiments. A non-absorbing moderator is simulated with the assumption that neutron moderation events can be approximated by classical elastic collisions of spheres with anti-parallel velocities. The needed energy dependent cross sections are provided by the Brookhaven National Laboratory NNDC database, [1]. From theory, a higher flux over voids and a small focusing effect from a concave void is expected. The simulation predicts the neutron flux from a moderator block with a spherical void in the surface to have a larger intensity above the void than a corrosponding flat block, but does not show a focusing effect.

An experiment is constructed which uses paraffin wax blocks as moderator material on top of a larger moderator with an imbedded radioactive neutron source. Neutron flux measurements along a line intersecting a spherical void in the center of a moderator block, compared to measurements taken with a flat block, showed a greater increase in flux than predicted by the simulation data. This difference is explained by the neglection of absorption, which is shown to be more significant than assumed, and then added to the simulation. This addition did limit the simulation to thermal neutrons, but the improvement made correlation between measurements and simulated data excellent. Hence, absorption is a more important aspect of moderation than initially assumed. The neutron source did not have the needed intensity for measurements of the focusing effect, but construction of a fusion based neutron source is under way. This source will have a much higher intensity, and measurements of the focusing effect will be possible along with more controlled moderator experiments.

Resumé

I dette projekt undersøges neutronmoderation ved hjælp af teoretiske udregninger, simulation og eksperimenter. En ikke-absorberende moderator simuleres under approksimationen at moderering af neutroner kan modelleres som elastiske kollisioner af kugler med anti-parallelle hastigheder. De brugte energiafhængige tværsnit er taget fra Brookhaven National Laboratory NNDC databasen, [1]. Fra teorien forventes der en højere flux fra en moderatorblok med et hul i overfladen, samt en lille fokuserende effekt fra et konkavt hul. Simulationen forudsiger at neutronfluxen fra en moderator med et sfærisk hul i overfladen har en større intensitet over hullet end en tilsvarende flad moderator, men viser ikke nogen fokuserende effekt.

Videre udføres et eksperiment der bruger paraffinblokke som moderator oven på en større moderator med en radioaktiv neutronkilde i midten. Målinger af neutronfluxen bliver taget langs en linie der skærer over et sfærisk hul i centrum af en moderatorblok, og sammenlignet med en flad blok ses der en større flux-stigning end den af simulationen forudsagte. Denne forskel forklares af antagelsen om nul absorption, der viser sig at være mere signifikant end antaget, hvorefter absorption tilføjes til simulationen. Denne tilføjelse begrænser simulationen til kun at simulere termiske neutroner, men korrelationen mellem målinger og de simulerede data bliver fremragende. Det konkluderes at absorption er en vigtigere del af moderation end hidtil antaget. Neutronkilden havde ikke den nødvendige intensitet for at kunne lave målinger over den fokuserende effekt, men konstruktionen af en fusionsbaseret neutronkilde er i gang. Denne kilde vil have en meget højere intensitet, og målinger af den fokuserende effekt, samt mere kontrollerede moderatoreksperimenter, vil være mulige.

Group work statement

Mads and Pia contributed equally to the work in the project. Mads focused primarily on the simulation, while Pia focused primarily on the data analysis. The report was written in unison.

iv

Contents

1 Introduction 1

2 Theory 1 2.1 Neutron scattering definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2.2 Moderator physics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2.3 The effects of moderator geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.3.1 Diffusion theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.3.2 Solution of the balance equation for a finite slab moderator . . . . . . . . . . . 6 2.3.3 Possible effects of a void . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3 Simulation 8

3.1 Making the simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.1.1 Scattering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.1.2 Starting parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.1.3 Simulation structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.1.4 Random number generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3.2 Initial analysis of simulation data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.2.1 Neutron flux at different moderator distances . . . . . . . . . . . . . . . . . . . 12 3.2.2 Neutron divergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.2.3 Neutron origins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

4 Experiment 16 4.1 Moderator blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4.2 Radioactive neutron source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4.3 Counting neutrons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

4.3.1 Detector dark count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4.4 Measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

4.4.1 Background count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 4.4.2 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

5 Simulation compared to measured data 20 5.1 Correct energy distribution input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 5.2 Convolution of simulation data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 5.3 Discussion of results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5.3.1 Higher gain due to absorption . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 5.3.2 Assymmetry of the sph1 moderator measurements . . . . . . . . . . . . . . . . 23 5.3.3 Precision of normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

6 Future 24 6.1 Use of optimized moderator geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 6.2 More powerful small scale neutron source . . . . . . . . . . . . . . . . . . . . . . . . . 25

7 Conclusion 25

References 27

Appendixes

A Thermal neutrons i B The neutron velocity after elastic scattering i

C Mean free paths ii C.1 Cellulose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii C.2 Water . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii

D The density of paraffin wax iii

E Maximal gains iii E.1 For absorption only . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii E.2 According to diffusion theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv

F Measurements v

G Extra figures viii

H Source codes xi H.1 Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi H.2 Data analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . liv H.3 MatLAB scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . lxxxi

List of Figures

2.1 Scattering of a neutron on a hydrogen nucleus . . . . . . . . . . . . . . . . . . . . . . . 2 2.2 The angles θ and α as functions of p . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.3 Sketch showing the two angles θ′ and θ . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.4 The “source volume” for two different differential volume positions . . . . . . . . . . . 8 2.5 Illustration of the focusing effect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.1 The flowchart of the main simulation loop . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.2 Slices through a moderator with a concave void . . . . . . . . . . . . . . . . . . . . . . 10 3.3 The concept of the mirroring routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.4 Flux of neutrons intersecting planes at different heights above the moderators . . . . . 14 3.5 Calculation of a point in the divergence plot . . . . . . . . . . . . . . . . . . . . . . . . 15 3.6 Histograms over the x-divergence of neutrons from different areas . . . . . . . . . . . . 15 3.7 The final scattering points of 5000 neutrons from the three moderators . . . . . . . . . 16 4.1 Exploded view of the boxes made for the moderator blocks . . . . . . . . . . . . . . . 17 4.2 The detector NIM array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4.3 Data for two moderators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 5.1 Energy distribution of a simulation of the primary moderator . . . . . . . . . . . . . . 21 5.2 Data for two moderators, with convoluted simulation data . . . . . . . . . . . . . . . . 22 5.3 Comparison of the neutron scalar flux with and without absorption . . . . . . . . . . . 23 5.4 Data for two moderators, with convoluted simulation data from an absorption run . . 24 F.1 Dimensions of the detector and the boron plastic housing . . . . . . . . . . . . . . . . v F.2 Dimensions of the two moderator blocks used during the measurements . . . . . . . . vi F.3 Dimensions of the top of the primary moderator . . . . . . . . . . . . . . . . . . . . . vi G.1 Figure 3.7, for all neutron energies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viii G.2 Data for two moderators, with simulation data from three different simulation runs . . ix G.3 Schematic overview of the fusion-based neutron source . . . . . . . . . . . . . . . . . . x G.4 Typical neutron paths from the simulation . . . . . . . . . . . . . . . . . . . . . . . . . x H.1 Over-all flowchart for the simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii H.2 The energy dependent scattering cross section . . . . . . . . . . . . . . . . . . . . . . . xiii H.3 Over-all flowchart for the data analysis program . . . . . . . . . . . . . . . . . . . . . lv H.4 First part flowchart from the main analysis flowchart . . . . . . . . . . . . . . . . . . . lvi H.5 Second part flowchart from the main analysis flowchart . . . . . . . . . . . . . . . . . . lvi

List of Tables

4.1 The average height of the detector and the boron plastic . . . . . . . . . . . . . . . . . 19 4.2 The results of the dark count and background measurements . . . . . . . . . . . . . . 19 E.1 Maximal gains according to diffusion theory with and without absorption . . . . . . . iv F.1 Measurements taken for the flat moderator . . . . . . . . . . . . . . . . . . . . . . . . vii F.2 Measurements taken for the sph1 moderator . . . . . . . . . . . . . . . . . . . . . . . . vii viii

Preface

This is a bachelor project, written by Mads Bertelsen and Pia Jensen as the final part of our B.Sc. educations at the Niels Bohr Instute at the University of Copenhagen.

The original idea of the project was to construct a fusion-based neutron source, and use this to study moderator physics with a focus on geometry. A lot of time was used for planning the construction and acquiring parts: Vacuum chamber, deuterium gas, wolfram grid, high-voltage feedthrough, bipolar high voltage power supply (in need of conversion to unipolar) and moderator material. It was apparent that the neutron source would not be finished on time, because the high voltage power supply conversion was more complicated than predicted. Furthermore, the constuction of a wolfram grid and feedthrough proved more demanding than anticipated. However, the project could be completed with the old radioactive neutron source of the institute, even though it was already embedded in moderator material. Since we wanted to investigate geometrical effects of moderators, we had to have control over surface geometry, so sample moderator blocks were needed.

A version of the report, along with all source codes and larger versions of some figures, has been uploaded to the following web-page:

   http://fys.bozack.dk/docs/bachelor/

It is recommended to visit the page, to see figures of larger resolution and detail than what was possible to put in the report.

Acknowledgements

Thanks to our supervisor Kim Lefmann for excellent support and for accepting our crazy ideas; to our safety representant Axel Boisen for a lot of practical help, planning of electrical curcuits, and approving of the overall project possibility in terms of electrical safety; to Uwe Filges from PSI in Switzerland for theoretical counseling and inspiration; and to Ian Bearden for further counseling.

Thanks to Axel Boisen for providing used X-ray equipment, from which we could use the 50 kW power supply, feedthrough and wires; to Jan W. Thomsen for vacuum chamber and deuterium gas; to the NBI workshop for simpler construction alternatives; and to Morten Bo Madsen for lending us laboratory space.

Mads Bertelsen and Pia Jensen

The University of Copenhagen, The Niels Bohr Institute, January 2011 x

\underline{2 Theory 1}

1 Introduction

This project is about neutron moderation – specifically about the flux distribution near the surface of a moderator, and how this depends on surface geometry. These topics have been studied with complex computation-heavy simulations, [2], earlier, e.g. [3, 4, 5] – but the purpose of this project is to test if a much simpler model is sufficient to explain the results.

Neutrons are moderated to low energies in order to be used for, e.g., scattering experiments, where structure of matter can be investigated. A simulation is written to estimate the differences in neutron flux from a flat moderator surface compared to a moderator with a spherical void. It is intended to investigate both how a void can increase the flux, and whether a void can partially focus neutrons. The simulation uses scattering cross section data from the Brookhaven National Laboratory NNDC database, [1], and a scattering model based on elastic collisions of spheres with anti-parallel initial velocities, while the absorption cross section is assumed insignificant.

An experiment is made to test the accuracy of the simulation by using two moderator blocks of paraffin wax respectivly flat and with a spherical void. These blocks are placed on a neutron source with a larger paraffin moderator, and the outgoing flux is measured with a helium-3 counter. The simulated data follows the shape of the measurements, but the measured intensity increase from the void is larger than expected. This difference in intensity is explained by the neglection of absorption in the simulation. A focusing effect is not comfirmed.

The results found in this project is similar to results found^{a} in [3, 5], and could be relevant for large-scale neutron facilities – like the European Spallation Source, [6], which is currently in the preconstruction phase – where even a small increase in flux from the moderators could make a large difference for the experimenters.

2 Theory

In this section, the necessary theory for the rest of the project, both simulation and experiment, will be presented.

2.1 Neutron scattering definitions

The probability of a neutron event, e.g., a scattering or absorption, is described by the cross section σ, defined as

σ_{x} = \frac{1}{Ψ} · number of neutron events of type x per second,  (2.1)

where Ψ is the flux of neutrons – the number of neutrons per second per surface area orthogonal to the beam direction. Further, the cross section usually depends on the neutron energy. To get a macroscopic cross section Σ, independent on the sample volume, it is normal to further define

Σ_{x} = nσ_{x},  (2.2)

where n = N/V is the number density of scattering or absorbing nuclei. The total macroscopic cross section for neutron events, Σ_{t}, can be seen as the sum of cross sections for absorption, Σ_{a}, and for scattering, Σ_{s}. This can of course be generalized to cases with several different types of interacting nuclei in the volume, but will not be used here.

aGain values cannot be directly compared, due to differences in geometry.

\underline{2 2 Theory}

2.2 Moderator physics

A neutron moderator is a substance used for lowering the energy of neutrons by scattering them. According to equation (2.2), a good moderator must have a small cross section for absorption and a large cross section for scattering, as well as a large number density of the scattering nuclei.

These properties are needed for lowering the energy of fast neutrons (neutrons of energies higher than 1 MeV, [7]) to energies corresponding to the moderator temperature, e.g., 300 K, without loosing too many of them in the process due to absorption. The energy of the neutron changes in a series of collisions with atomic nuclei in the moderator, and since the atoms have a thermal velocity, the neutron velocities will, eventually fluctuate around some equilibrium value corresponding to this. These slowed down neutrons are called thermal neutrons, and have energies in the order of^{b} 0.025 eV.

Thermal neutrons are in high demand because their wavelength is in the same order as distances between atoms in crystals (Å), and hence they are good for scattering experiments, which reveal the structure of those crystals. Further, the energy of thermal neutrons is of the same order as excitations in materials, such as phonons, waves traveling in the crystal lattice. These excitations can be studied because of the great difference between energies of neutrons that did and did not interact with the crystal.

To describe a moderator, the distance between scattering collisions is needed. If random positioning of moderator atoms in assumed, the intensity I of unscattered neutrons in a beam, with initial intensity I_{0} going into the moderator, will decrease exponentially, [8, chap. 2],

I(z) = I_{0} exp (−Σ_{s}z).  (2.3)

The quantity λ = 1/Σ_{s} is often denoted the mean free path, and is the average length a neutron travel before being scattered. The relation in equation (2.3) can be used as a probability distribution, describing the probability for the distance between two scatterings.

x y orthogonal parallel rrθ_{u_{H}} un x_{C}

(a)

x y x_{C} 2r x_{C} 2r _{(b)}

Figure 2.1: Scattering of a neutron with velocity u_{n} on a hydrogen nucleus with velocity u_{H}. The impact parameter x_{C} can at most have size 2r. By rotating around the x-axis, all three-dimensional sphere collisions with anti-parallel initial velocities can be represented by this diagram.

The next step is to describe what happens at a scattering event. A scattering event in a moderator can be seen as classical elastic collision of spheres, and in this project only hydrogen is considered as moderator. The collision is assumed classical as an approximation to the quantum mechanical equivalent, to have simpler calculations and hence get a more efficient simulation. The neutron and the hydrogen nucleus are modeled as two spheres with anti-parallel velocity vectors and equal mass and radius. This approximation is reasonable, since it is most probable for the neutron to hit a hydrogen nucleus which is traveling in the opposite direction of itself, especially for lower energy neutrons.

bFor an explanation of the concept of thermal neutrons, and the calculation of this value, see appendix A.

The collision between two spheres can be modeled in two dimensions without loss of generality, since the coordinate system can be transformed so both centers are in the same plane. On figure 2.1(a), the collision is sketched with the important variables, the radius r of both particles, the impact parameter, x_{C}, and the velocities before the collision, u_{n} and u_{H}, for the neutron and the hydrogen nucleus, respectively. The coordinate system is transformed to a system with an axis parallel to the line connecting the centers, with the second axis being orthogonal to this. This corresponds to a rotation of θ − π/2 = sin^{−1} (x_{C}/(2r)). It is done to exploit that the only momentum exchange happens along the line connecting the centers (assuming no friction), hence the orthogonal composant is unchanged. The parallel parts of the velocities, u_{n,p} = u_{n} sin θ and u_{H,p} = u_{H} sin θ, where the p subscripts refer to “parallel”, complies with momentum conservation, so if the velocities after the collision are called v_{n} and v_{H}, respectively,

mu_{n,p} + mu_{H,p} = mv_{n,p} + mv_{H,p}.  (2.4)

In addition, assuming elastic collision, there is energy conservation – giving the equation

\frac{1}{2}mu_{n}^{2} + \frac{1}{2}mu_{H}^{2} = \frac{1}{2}mv_{n}^{2} + \frac{1}{2}mv_{H}^{2}.  (2.5)

The two equations combine^{c} to give the final neutron velocity in (parallel,orthogonal)-coordinates

v_{n} = (\begin{matrix}v_{n,p} \\ v_{n,o} \end{matrix}) = (\begin{matrix}u_{H,p} \\ u_{n,o} \end{matrix}) ,  (2.6)

where the o subscripts refer to “orthogonal”. If the initial energy of the neutron is E_{i}, the final neutron energy after the collision, E_{f}, can further be shown to be

E_{f} = E_{i} cos^{2} θ + E_{H} sin^{2} θ,  (2.7)

where E_{H} is the energy of the hydrogen atom before the collision, assumed to be the thermal energy for every collision. This energy has been chosen as a constant to keep the simulation simple, and avoid fluctuations of the neutron energy around the thermal energy.

With the above assumptions, it is apparent that if a neutron starts with higher energy than thermal, it will never get an energy below thermal, since cos^{2} θ + sin^{2} θ = 1. Assuming an even distribution of θ, the average of sin^{2} θ and cos^{2} θ over 0 < θ < π/2 is 1/2, and the expression for the average energy after collision can be rewritten as

⟨E_{f}⟩ = \frac{⟨E_{i}⟩}{2} + \frac{⟨E_{H}⟩}{2} = \frac{⟨E_{H}⟩ + ⟨E_{E}⟩}{2} + \frac{⟨E_{H}⟩}{2} = \frac{⟨E_{E}⟩}{2} + ⟨E_{H}⟩,  (2.8)

where E_{E} is the excess energy, E_{i} − E_{H}. Hence, the neutron will on average converge towards thermal energy by half the excess energy at each scattering.

In a random collision between two spheres, the distribution of θ is, however, not evenly distributed: θ depends on the impact parameter x_{C}, which is not evenly distributed either. The impact parameter should be seen as the distance from a random point in a circle with radius 2r, to the center. This large circle represents all possible three-dimensional sphere collisions with anti-parallel initial velocities, assumed to be evenly distributed for symmetry reasons, see figure 2.1(b). The probability for an event in the smaller circle with radius x_{C} in respect to the larger circle with radius 2r,

p = \frac{πx_{C}^{2}}{4πr^{2}} ,  (2.9)

cFor the full derivation, see appendix B.

should be evenly distributed since the distribution on the circle is uniform. Hence, the distribution of x_{C} is

x_{C}^{2} = 4r^{2}p ⇒ x_{C} = \sqrt{4r^{2}p} = 2r\sqrt{p},  (2.10)

where p is evenly distributed in the interval between 0 and 1. The function

θ = \frac{π}{2} − sin^{−1} (\frac{x_{C}}{2r} ) = \frac{π}{2} − sin^{−1} \sqrt{p}  (2.11)

is shown on figure 2.2(a), where a straight line would indicate an even distribution. So θ is almost evenly distributed, but have lower probability for angles near 0 and π/2.

The change of the neutron direction after the collision is given by the angle between the velocity vector before and after the collision. The angle between the rotated orthogonal axis and the initial neutron velocity vector is θ, and the angle between the orthogonal axis and the final neutron velocity vector is

θ′ = \frac{π}{2} − |tan^{−1} (\frac{u_{n,o}}{u_{H,p}} )| = \frac{π}{2} − |tan^{−1} (\frac{u_{n} cos θ}{u_{H} sin θ} )|  (2.12)
= \frac{π}{2} − |tan^{−1} (\frac{\sqrt{E_{n}} cos θ}{\sqrt{E_{H}} sin θ} )| = \frac{π}{2} −| tan^{−1}(\sqrt{\frac{E_{n}}{E_{H}}} \frac{1}{tan θ} )|.  (2.13)

As seen on figure 2.3, the sum of these two angles give the angular difference between initial and final neutron velocities, α,

α = θ′ + θ = \frac{π}{2} −| tan^{−1}(\sqrt{\frac{E_{n}}{E_{H}}} \frac{1}{tan θ} )| + θ,  (2.14)

denoted the scattering angle. In figure 2.2(b), the distribution of α is shown using the known distribution of θ from equation (2.11). The distribution is shown for three neutron energies; fast neutrons, neutrons of 1 eV and thermal neutrons. For higher energies, the probability for backwards scattering (α > π/2) is almost zero, and as the energy decreases towards thermal it approaches a uniform distribution, but with slightly lower probability for 0 and π. Note that a transformation to the center of mass system is eqvivalent to having equal energies, so on 2.2(b), the thermal line corresponds to the center of mass distribution for all energies – which is very close to even, meaning an almost isotropic angle distribution.

p θ [rad]_{0}_{π/2}_{π/4}_{0}_{0.25}_{0.5}_{0.75}_{1}

(a) θ(p) from equation (2.11)

p α [rad]_{0}_{π}_{π/2}_{0}_{0.25}_{0.5}_{0.75}_{1} E_{n} = 0.025 eV E_{n} = 1 eV E_{n} = 1 MeV

(b) α(θ(p)) from equation (2.14)

Figure 2.2: The angles θ and α, as functions of the evenly distributed variable p, which can be between 0 and 1. A straight line segment corresponds to an even distribution at that area, and hence the distribution of θ, and the thermal energy distribution of α, are almost isotropic.

From this simple model it is apparent that the neutron direction after scattering is almost isotropic in the laboratory system for thermal neutrons. This does, however, exclude the effects of collisions with non-parallel initial velocities and the probability distribution of initial velocities from the moderator atoms. These effects will change the scattering angle probability distribution as a function of the

parallel orthogonal θ θ′ α_{u_{n}}_{v_{n}}α = θ′ + θ

Figure 2.3: Sketch showing the relation of the two angles θ′ and θ to the scattering angle α. See figure 2.1 for the definition of the used coordinate system.

neutron energy.

In this project, hydrogen moderators are used, and data from the NNDC database, [1], suggest a behavior very close to isotropic scattering in the center of mass system for energies between 10 μeV and 20 MeV. There is, however, low favoring of scattering angles close to 0 and less likelyhood of scattering angles close to π, which does not totally agree with the model above. However, this effect is very small and there is little information about how the angle is measured.

2.3 The effects of moderator geometry

This project focuses on how moderator geometry affects the outgoing flux of a moderator. To discuss this, diffusion theory is needed for a basic understanding of how neutrons is distributed as a function of the depth of the moderator.

2.3.1 Diffusion theory

Neutron diffusion theory is based on the neutron balance equation for a differential volume element, adapted^{d} from [9],

\frac{∂n}{∂t} = S − Σ_{a}φ(r) − ∇ · J(r).  (2.15)

This equation states that the change in neutron density n in a differential volume in time is equal to the rate of neutrons coming from a source in the region, S, minus the neutrons lost to absorption, Σ_{a}φ, where φ is the neutron scalar flux – the product of the neutron density n and the neutron speed v – minus the leakage of neutrons out of the volume, the divergence of the neutron current J(r).

If a solution φ_{1}(z) yields ∂n/∂t = 0 for all differential volumes in a volume, the neutron density n(r, t) must be time-independent. However, a simple expression for the neutron current J needs to be calculated before one can solve the differential equation. This derivation follows a similar derivation in [9, chap. 3]. Consider a small area dA_{z} in the xy-plane at the center of a spherical coordinate system with r = (r, θ, γ). If all neutrons have equal energy (and hence equal speed), the downward currrent in this area is found by integrating over contributions from all differential volumes dV = r^{2} sin θ dr dθ dγ with z > 0. Assuming isotropic scattering in the laboratory system, the amount of neutrons coming from the differiential volume dV is

J_{−}(0; r, θ, γ) dA_{z} = \frac{Σ_{s}}{4πr^{2}} φ(r) cos θ dA_{z} dV,  (2.16)

but some of these neutrons will be scattered or absorbed on the way from dV to dA_{z}, so it must be modified by a factor of exp (−Σ_{t}r) according to equation (2.3). Integrating over all these volumes with z > 0 yields

J_{−}(0)dA_{z} = \frac{Σ_{s}}{4π} ∫_{0}^{∞} dr ∫_{π/2}^{π} dθ ∫_{0}^{2π} dγ φ(r) sin θ cos θe^{−Σ_{t}r} dA_{z}.  (2.17)

dThe fission term is assumed to be zero.

To be able to evaluate this integral, the neutron scalar flux is approximated to a first order Taylor expansion. Hence, in carthesian coordinates, it can be written as

φ(r) ≈ φ(0) + x \frac{∂φ}{∂x}|_{0} + y \frac{∂φ}{∂y}|_{0} + z \frac{∂φ}{∂z}|_{0} .  (2.18)

When transforming to spherical coordinates, it is realized that the integral over the x- and y-terms will be zero, since the transformations include factors of sin γ or cos γ, which integrates to zero. Hence only the z-part and the constant is needed, φ(0) + r cos θ ∂φ/∂z. With this last piece of the puzzle, the integral can be evaluated.

J_{−}(0) =\frac{Σ_{s}}{4π} ∫_{0}^{∞} dr ∫_{π/2}^{π} dθ ∫_{0}^{2π} dγ sin θ cos θ (φ(0) + r cos θ \frac{∂φ}{∂z}|_{0}) e^{−Σ_{t}r}  (2.19)
=\frac{Σ_{s}}{4π} ∫_{0}^{∞} dr ∫_{π/2}^{π} dθ ∫_{0}^{2π} dγ ( \frac{∂φ}{∂z}|_{0} sin θ cos^{2} θre^{−Σ_{t}r} + φ(0) sin θ cos θe^{−Σ_{t}r})
=\frac{Σ_{s}}{2} ( \frac{∂φ}{∂z}|_{0} ∫_{π/2}^{π} dθ sin θ cos^{2} θ ∫_{0}^{∞} re^{−Σ_{t}r}dr + φ(0) ∫_{π/2}^{π} dθ sin θ cos θ ∫_{0}^{∞} e^{−Σ_{t}r}dr)
=\frac{Σ_{s}}{2} ( \frac{∂φ}{∂z}|_{0} [\frac{cos^{3} θ}{3} ]_{π/2}^{π} [−\frac{e^{−Σ_{t}r}}{Σ_{t}} (r + \frac{1}{Σ_{t}} )]_{0}^{∞} + φ(0) [\frac{sin^{2} θ}{2} ]_{π/2}^{π} [\frac{e^{−Σ_{t}r}}{Σ_{t}} ]_{0}^{∞})
=\frac{Σ_{s}}{6Σ_{t}^{2}} \frac{∂φ}{∂z}|_{0} + \frac{Σ_{s}}{4Σ_{t}} φ(0).  (2.20)

Further assuming low absorption, the total macroscopic cross section Σ_{t} is almost equal to the scattering cross section Σ_{s}, and hence

J_{−}(0) = \frac{1}{4}φ(0) + \frac{1}{6Σ_{s}} \frac{∂φ}{∂z}|_{0} = \frac{1}{4}φ(0) + \frac{1}{2}D \frac{∂φ}{∂z}|_{0} ,  (2.21)

where the diffusion coefficient D is defined as 1/(3Σ_{s}). A similar calculation for z < 0 would give J_{+}(0) = φ(0)/4 − D/2 ∂φ/∂z|_{0}, so the total current in the z-direction is

J_{z}(0) = J_{+}(0) − J_{−}(0) = −D \frac{∂φ}{∂z}|_{0} .  (2.22)

Parallel derivations for the xz- and yz-planes yields similar results, and collecting them gives the vector neutron current at origo,

J(0) = −D∇φ(0).  (2.23)

Since the Taylor approximation could have been done for any point in space, the derivation is general, so J = −D∇φ. This approximation is known as Fick’s law, [9], and when used for the neutron current in the balance equation, neutron diffusion theory is obtained,

\frac{∂n}{∂t} = S − Σ_{a}φ(r) + ∇ · D∇φ.  (2.24)

Equipped with neutron diffusion theory, it is a matter of calculations to find the neutron scalar flux distribution, and, since the diffusion theory assumes only one possible speed, the neutron density distribution.

2.3.2 Solution of the balance equation for a finite slab moderator

For a finite slab moderator, a box with only a single finite dimension, 0 < z < t, and a source S_{0} in the xy-plane at z = 0, the neutron balance equation for 0 < z < t, with the assumption of zero absorption, is

\frac{∂n}{∂t} = ∇ · D∇φ = 0 ⇒ \frac{dφ(z)}{dz} = 0,  (2.25)

since the neutron scalar flux must be constant in every xy-plane for symmetry reasons, and hence only the z-component have a nonzero contribution. This differential equation has the general solution φ(z) = az + b, where a and b must be found from the boundary conditions. At the source plane, the current must comply with

J_{+}(0) = \frac{1}{4}φ(0) − \frac{1}{2}D \frac{dφ(z)}{dz}|_{0} = \frac{S_{0}}{2} ⇒ \frac{b}{4} = \frac{S_{0}}{2} ⇒ b = 2S_{0}.  (2.26)

By further requiring that J_{−}(t) = 0, a can be found,

J_{−}(t) = \frac{1}{4}φ(t) + \frac{1}{2}D \frac{dφ(z)}{dz}|_{t} = 0 ⇒ \frac{1}{2}(at + b) + Da = 0 ⇒ a = −\frac{b}{t + 2D} .  (2.27)

Substituing the expression for b from equation (2.26),

a = −\frac{2S_{0}}{t + 2D}  (2.28)

and hence the final solution is

φ(z) = 2S_{0} (1 − \frac{z}{t + 2D} ) .  (2.29)

The distribution of neutron flux in the slab is linear, and has a lower positive value at the top, z = t. So, even without leakage through the side walls of a box, the neutron density falls as the distance to the top surface falls. The neutron current out of the box, J_{+}(t), is given by

J_{+}(t) = \frac{1}{4}φ(t) − \frac{1}{2}D \frac{dφ(z)}{dz}|_{t} = \frac{S_{0}}{2} (1 − \frac{t}{t + 2D} ) + \frac{S_{0}D}{t + 2D}  (2.30)
= \frac{S_{0}}{2} (1 − \frac{t}{t + 2D} + \frac{2D}{t + 2D} ) = \frac{S_{0}}{2} (\frac{t + 2D − t + 2D}{t + 2D} ) = \frac{2S_{0}D}{t + 2D} .  (2.31)

Notice that this current vanishes for t → ∞, since the probability for the neutrons to exit through the z = 0 plane increases with thickness. In the case of a finite box, neutrons escaping through the sides will make the resulting top surface current smaller yet.

The remainder of this project is examining what a change in the surface shape would do to the flux at the surface. From the above results, it is clear that a small hole could “dig down” into a region with higher neutron density, even though that would of course change the entire solution. It would be quite difficult to solve the neutron balance equation for a non-convex volume, since the boundary condition of no ingoing current used in equation (2.27) would not be true. The derivations in this section were only done to get a feel for the way neutrons behave in moderators, and is not very accurate. Exactly this inaccuracy is the reason why simulation was chosen instead of numerical solution of the neutron balance equation. Diffusion theory assumes a slowly varying neutron scalar flux, which is a very good assumption a few mean paths from the boundaries, but litterature explains that this is a very bad approximation closer to the walls, [9]. Since the goal of this project exactly is to see what happens at the walls, another approach is needed.

2.3.3 Possible effects of a void

Since diffusion theory changes the naive intuitive picture of equal neutron density in a moderator because of the steady state “as much goes in as out”, it does highlight why a simple hole in the moderator could increase the neutron flux in a small area in comparison to a flat surface: The neutron density is simply higher inside the moderator closer to the source. In addition, one must consider that the “source volume” for a point on the surface is smaller than a point in a hole, but at most by a factor of 2, as illustrated in figure 2.4. These effects combined could give more than a factor of 2 flux in a small area.

dV_{S} dV_{V} Neutrons can only enter the volume from the lower half of 4π Neutrons can enter the volume from almost all 4π

Figure 2.4: If a differential volume dV_{S} at the surface of a moderator can recieve neutrons from a “source volume” below and beside the volume, a volume dV_{V} at the bottom of a void in the moderator can at most recieve neutrons from a “source volume” that is almost two times the source volume for dV_{S}.

When considering a partly spherical void in the surface, there might further be a focusing effect of the neutrons: The shortest way from a scattering event in the moderator to the surface is the way orthogonal to the surface, where the factor exp(−Σ_{t}r) is largest. If this effect is present, a small neutron hot-spot could be made at a distance from the moderator corresponding to the position of the center of sphere defining the void, see figure 2.5.

Figure 2.5: It is expected that the largest number of neutrons coming from a surface element of a moderator will exit as a normal to the surface, shown as arrows above. However, it is not known how broad the angular distribution is. If the distribution is very narrow, a hot-spot where the lines converge is expected, as shown.

3 Simulation

A fortran simulation was written in order to investigate the effects of a concave void in the surface of a neutron moderator. The primary focus of the simulation should be on moderator geometry, but the neutron scattering should be a reasonable approximation to the known behavior^{e}. It was chosen to make a simple simulation from scratch, instead of using an already made simulation package, like MCNP [2], since this allows for a better understanding of the different effects seen from the simulation, as well as requiring a lot less computational power.

3.1 Making the simulation

The concept was to simulate the movements of each neutron in the moderator until it exits the moderator, assuming zero absorption, Σ_{a} = 0. This assumption seems reasonable, since the macroscopic scattering cross section for paraffin, which is used as moderator material during this project, is^{f} Σ_{s} = 2.25 cm^{−1}, whereas the macroscopic absorption cross section is only Σ_{a} = 0.025 cm^{−1}. The simulation runs in steps where a scattering takes place by calculating a new direction and distance to the next scattering point, while correcting the energy of the neutron. The routines carrying out these scattering calculations are explained in this section, and are shown in appendix H.1.

eWhere the known behavior is assumed to be the data from the NNDC database, [1].

The finite size of the moderator further complicates the program, since the neutrons are assumed not to scatter from air, but are allowed to enter the moderator again if, e.g., a void is crossed. The structure of the program is focusing on these geometrical considerations, which will also be explained in this section.

3.1.1 Scattering

The distance to the next scattering event is determined by equation (2.3), I(z) = I_{0} exp (−Σ_{s}z), where Σ_{s} is the macroscopic cross section for elastic scattering, which is dependent on the neutron energy. This equation is used as a probability distribution for the distance between each scattering event. The cross section for elastic collision with hydrogen as a function of energy is taken from the NNDC database, [1]. It should be noted that the simulation quality can never exceed the quality of the used data. The exponentially distributed random number generator used for the distance do not allow endpoints, so the distance will never be zero.

The way a neutron chooses a random direction after a scattering could be assumed isotropic in the laboratory system, which was the assumption of diffusion theory. The random direction could also be chosen to follow elastic collision of spheres, as calculated in section 2.2, which is closer to isotropic scattering in the center of mass system. It was chosen to try both approaches by allowing to change between the models in the program. When using elastic scattering, the impact parameter x_{C} is given by a random distribution following equation (2.10). The last rotational degree of freedom is handled by an evenly distributed random number generator which returns an angle in the interval [0, 2π].

After each scattering event where the neutron is above thermal energy, the energy is decreased. The simple approach is to use the result from equation (2.8), which states that on average, the energy above thermal is approximately halved. This simple approach is used when isotropic scattering is used for the simulation. When elastic scattering is used, the next energy is calculated from the impact parameter, equation (2.11) inserted into equation (2.7). In the flowchart, figure 3.1, the calculation of random distance, random direction and energy decrease is labeled as one, under scattering. If interested, the reader can see two typical neutron paths from the simulation in figure G.4.

3.1.2 Starting parameters

The moderator is a box shape with a void in the top surface and a homogenous neutron beam entering the bottom side. The starting point of each neutron is created by selecting a random point on the bottom^{g}, and then the direction is set to be orthogonal to the bottom. It is possible to use a simple distribution of starting energies. In the flowchart, this routine is refered to as newneutron.

3.1.3 Simulation structure

The point of writing the simulation is to investigate concave voids in the surface of the moderator, which adds to the complexity of the program in comparison to a flat surface. When a void is present, it is possible for a given neutron to intersect the void or end in the void. After each scattering event, a routine called posmod determines in what part of space the new position is, which determines the possible situations that should be checked for. There are 4 possible results of posmod, and the structure of the simulation for each of these is breifly explained below.

fFound using equation (2.2), and the values σ_{s} = 30 b, [1], and σ_{a} = 0.33 b, [8] for hydrogen, and n for paraffin, to be found in section 4.1.

gThe random point cannot be too close to the edges, in the order of one percent of the moderator width from each side.

If the neutron is in the “safe” part of the moderator, meaning that the neutron has a z-value lower than the deepest part of the void, the program checks if the last position was in the “safe” part as well. If this is true, there is no way for the neutron to interact with the void, and the next scattering is performed, after which a new position r is found by newpos, saving the old position r_old in the process. If the last position was above the lowest part of the void, the program goes to the next branch of the flowchart, since there was a possible intersection with the void.

newneutron posmod interbox outputm output intervoid

inorout concavecheck intervoid distchange newpos2 r old in safe zone? scattering newpos

4: out of simple box 3: in void 2: in moderator (not safe)

1: in moderator (safe) yes no intersect in simple intersect out of simple interside 6 (outgoing) interside 1,2,3,4,5 no problem

problem

Figure 3.1: The flowchart of the main simulation loop. Each new neutron is initialized in the newneutron routine, and is then sent through the posmod to newpos or newpos2 loops until ending in the output via the output or outputm routine. A chosen number of neutrons is simulated, after which the program exits.

The branch which checks for possible void intersections has input from posmod when the neutron is in the moderator and above the lowest part of the void, as well as from the special case from the first branch. The routine concavecheck quickly checks for intersections by checking three equidistant points on the line between the new and old position. In this way, the program ignores intersections with small distance traveled in the void, which improves performance, but is not as precise as possible. concavecheck could have been written with the analytic solution to intersection between line and sphere, but a routine was not written for this when concavecheck was made, and there was never time to rewrite it. If no intersection is found, a new scattering event is started. If an intersection is found, the intersection points between line and void is found by intervoid, and the distance the neutron should travel is increased correspondingly with the routine distchange as shown on figure 3.2(a). A routine called newpos2 updates the position without changing the old position, so the possible old position in written data will be correct.

L_{1} r old r ⇒_{L_{1} r old r}

(a)

L_{2} r old r ⇒_{L_{2} r old r temp r}

(b)

Figure 3.2: Slices through a moderator with a concave void, showing how the neutrons can intersect the void and end in it, along with the handling of these situations by the simulation.

If the result of posmod is that the position is in the void, intersections with the void are found and the routine inorout checks if any of the intersections are outside the box wherein the moderator is. If this is the case, the neutron has left the moderator, and the position r, direction r_{direc}, energy E, and other information, is written to a data file by output. If the intersections are such that the neutron can continue in the moderator, the distance is altered with distchange, which yields results as shown in figure 3.2(b). Note that the position r_temp is saved, to avoid a false-positive from the concavecheck routine in the next iteration.

Finally, if posmod determines that the newest neutron position is not in the moderator or void, the intersection between the line defined by the old and new position on the sides of the moderator is determined by interbox. If the neutron left the moderator from the top side, denoted side number 6, the routine output saves the neutron parameters for output. The program stops when a predetermined number of neutrons have left the moderator from the top surface of the moderator, including the neutrons leaving via the void. If the neutrons that exit from other sides are of interest, the routine outputm is used to write these data into another data file. In this project, all sides except the top are saved in this way until a certain file size is reached. Users input the number of simulated neutrons which is to be output through the top of the moderator. This corresponds to setting the quality of the histograms used to visualise the data. This numbering logic of the simulation will yield different total simulated neutrons between each configuration, and hence additional care is needed when normalizing data. This way is preferred over the more usual method of inputting a set number of neutrons, since it gives a consistency in quality of the histograms which needs to be compared.

The program can be changed to use reflectors on specific sides of the moderator with the routine mirror – which will update the position accordingly, as shown in figure 3.3 – instead of writing to data with the outputm routine. Reflectors were used under debugging and test-runs, because all simulated neutrons then reaches the top surface or void, greatly increasing performance.

L_{1} r old r ⇒_{L_{1} r old r}

Figure 3.3: The concept of the mirror routine is to send back neutrons that try to exit sides other that the actual output side of the moderator.

3.1.4 Random number generators

The random number generators used for this project are from Numerical Recipes, [10]. When a real number between 0 and 1 is needed, a ran1 routine is called. This routine was chosen because of a great relationship between performance and statistical quality of the results. ran1 has a very long period of about 2.3 × 10^{18}, before the sequence repeats itself. Due to a misprint in [10], the period was initially though to be only 2 × 10^{9}, and it was estimated that period exhaustion would occur within 30 min of computation time. To avoid potential period exhaustion, a ran1 routine with new starting seed was used for each needed variable, effectivly prolonging the period. After realizing the decision was made because of a misprint, it was too late to change it – but with the actual much longer period this is not a problem, since the probability for period overlap is very small; in the order of 10^{−9}.

3.2 Initial analysis of simulation data

The simulation writes out parameters for each neutron exiting the output face of the moderator, as well as for a chosen number of neutrons exiting the sides of the moderator. The primary parameters are the last scattering point of the neutron, r, the current direction of the neutron velocity given as a normalized vector, r_{direc}, and the neutron energy E.

The data file from the simulation is read into a specialized analysis program^{h}, which can then calculate more viewer-friendly outputs, that can be plotted and worked further on in MatLAB^{i}, [11]. These different outputs will be explained when they are used. An important first thing the program does, is to only use the neutrons that have their energy below a certain threshold, since the moderator is used for lowering the energy. The neutron detector that will be used in the experimental part of the project uses helium-3, and the cross section for slow neutron reactions are in orders of magnitude larger than for fast neutrons. A threshold of 1 eV is used, even though the probability for detection is large even in the keV range. All the results below look very similar with thresholds up in the keV range. In a few instances the behavior of other energy intervals is interesting, but it will be noted if other intervals are used.

3.2.1 Neutron flux at different moderator distances

Since one of the hypotheses raised in section 2.3.3 was that there was a focusing effect of a concave void in a moderator, it is necessary to look at the flux of neutrons at different distances away from the moderator. A hot-spot is expected at a certain distance to the moderator, and can be confirmed if the intensity behind and in front of the point has lower intensity.

The neutron flux is measured as neutron intersections of a plane at the wanted distance. So, since the simulation output is the last point of the neutron, r, along with a direction vector r_{direc}, this is done for each neutron by calculating the intersection of the plane (x, y, z) = (t, s, z_{pl}) and the line (x, y, z) = r + ur_{direc}, where the parameters are t, s, u ∈ ℝ. The intersection must be for the u where the line has the same z-component as the plane,

u = \frac{z_{pl} − r_{z}}{r_{direc,z}} .  (3.1)

Inserting this u into the equation of the line, the point on the given plane is

(\begin{matrix}x \\ y \end{matrix}) = (\begin{matrix}r_{x} + \frac{z_{pl} − r_{z}}{r_{direc,z}} r_{direc,x} \\ r_{y} + \frac{z_{pl} − r_{z}}{r_{direc,z}} r_{direc,y} \end{matrix}) .  (3.2)

The analysis program is fed with the data file along with the z_{pl}-component of the plane, and then outputs the (x, y)-coordinates of each neutron intersecting the plane. To visualize the flux, these data are read into MatLAB, and then plotted as a two-dimensional histogram.

To see if there is a focusing effect, several different moderator surfaces are simulated. Most important is the flat moderator surface, which is the output all the other simulation results must be compared to (since this surface is not expected to focus the neutrons). Further, two moderators with partly spherical voids are simulated – both with the same 5 cm radius circular hole in the moderator surface, but one with the full depth, 5 cm – from here on denoted as the sph1 moderator – the other with half the depth, 2.5 cm – denoted the sph2 moderator. All moderators are simulated to have a width^{j} of 22 cm in both the x- and y-direction, and height z_{mod} = 6.8 cm.

The flux histograms for all three moderators, at four different Δz = z_{pl} − z_{mod} values, are shown in figure 3.4. Notice that only neutrons of energies below 1 eV have been counted. The first row of histograms is for the flat moderator, the next is for the sph2 moderator, and the last is for the sph1 moderator – and the higher the histogram, the closer the plane is to the moderator.

hThe source code, and an explanation of the program, can be seen in appendix H.2.

iFor all used MatLAB routines, see appendix H.3.

jThese are the dimensions that will be used for the moderator blocks in the experiment as well.

On the figure, it is first of all visible that there is not a focusing effect as was expected from the discussion in section 2.3.3 – instead, the neutron flux simply dissipates and becomes smaller for the planes farther away from the moderator surface. The third row of graphs is for a plane positioned at the center of the sphere tracing out the void in the sph2 moderator, where the focusing effect of this void should result in a hot-spot. However, this is not visible in the results.

Instead of seeing a focusing effect though, another interesting observation can be noted: The flux of neutrons above the voids is very high as compared to the flux over the same spot of the flat moderator. This is as expected, because the neutron flux distribution in the moderator is higher closer to the source (here, the bottom of the moderator), as well as because the “source volume” is higher for a moderator volume at the bottom of a void. Especially the flux over the deep void in the sph1 moderator is significant, as it is approximately 2.7 times larger than the flux from the flat moderator. A gain of a factor 2.7 seems reasonable in respect to the different theories presented.

3.2.2 Neutron divergence

Another formulation of the focusing idea was that the neutrons coming from, say, the right part of the void, would mainly go towards the left when exiting the moderator. To see if this is indeed the case, it is necessary to look at the divergence of the neutrons.

The divergence is a measure of the angular deviation of the neutron velocity to the main beam axis, [8], here the z-axis. Both the divergence in the x- and y-direction is wanted, and each point in the divergence plot can be seen as represented by a vector d = d d̂ from origo, see figure 3.5(a). The unitless length d represents an angle between the neutron velocity and the beam axis in real space, and can hence be given as

d = cos^{−1} (\frac{r_{direc} · ẑ}{|r_{direc}||ẑ|}) = cos^{−1}(r_{direc,z}),  (3.3)

where it was used that both the unit vector ẑ and the direction vector r_{direc} has unit length. The direction of the divergence vector, d̂, is simply the unit vector pointing in the direction of r_{direc}, but only in the x- and y-dimension. Hence,

d̂ = \frac{1}{\sqrt{r_{direc,x}^{2} + r_{direc,y}^{2}}} (\begin{matrix}r_{direc,x} \\ r_{direc,y} \end{matrix}) .  (3.4)

With this, the divergence in the x-direction is simply d_{x}, while the divergence in the y-direction is d_{y}, see figure 3.5(b).

The analysis program is once again used to calculate divergencies, this time in two parts. First, it calculates which neutrons are emitted from the void, by testing which neutrons intersect the spherical shell defining the void. Then, the divergence of these neutrons, or only of the neutrons coming from the right side of the void, is written to output as x- and y-divergence. These data can then be visualized in MatLAB. The easiest way to compare two divergence plots is to only plot a single dimensional histogram over one of the divergence directions. This way, several histograms can be plotted in the same graph. Such two graphs are shown in figure 3.6, where both the divergence of neutrons from the full void and the divergence of the neutrons from one half of the void is shown together, for the sph1 and sph2 moderators. Notice that, once again, only neutrons of energies below 1 eV is counted.

The histograms have been normalized so they show the same number of neutrons with zero divergence, which makes it easier to compare the distributions. The histograms are very similar, with the main difference being the less smooth nature of the histogram with lowest available datapoints. Since the divergence plot of the neutrons coming from only one side of the void is not skewed compared

14  3 Simulation

(a) Flat, Δz = 1 mm  (b) Sph2, Δz = 1 mm  (c) Sph1, Δz = 1 mm

(d) Flat, Δz = 13 mm  (e) Sph2, Δz = 13 mm  (f) Sph1, Δz = 13 mm

(g) Flat, Δz = 25 mm  (h) Sph2, Δz = 25 mm  (i) Sph1, Δz = 25 mm

(j) Flat, Δz = 37 mm  (k) Sph2, Δz = 37 mm  (l) Sph1, Δz = 37 mm

0 Linear flux scale [arb. unit] →

Figure 3.4: Flux of neutrons below 1 eV intersecting planes at different Δz = z_{pl} − z_{mod} values, for the flat, the sph2 (half-depth spherical void) and the sph1 (full-depth spherical void) moderators. All the graphs have size such that the white square, indicating the moderator size, has width and height 22 cm. The expected focusing effect is not present, but another interesting effect of larger flux for a deeper void is visible. The plots have been normalized such that the seen intensities correspond to the same number of neutrons sent into the three moderators.

x-divergence y-divergence d = d d̂ dxd_{y}

(a)

ẑ_{r_{direc}} d_{x} d_{y}r_{direc,x} r_{direc,y} r_{direc,z}

(b)

Figure 3.5: To calculate the point in the divergence plot, (a), the two angles d_{x} and d_{y} must be calculated for the neutron direction vector r_{direc}, (b).

−π/2 −π/4 0 π/4 π/2 0 50 100 150 200 250

x-divergence [rad] # of neutrons in bin (all y-divergencies)

Full

Half

(a) Sph1 moderator (full-depth spherical void)

−π/2 −π/4 0 π/4 π/2 0 50 100 150 200 250

x-divergence [rad] # of neutrons in bin (all y-divergencies)

Full

Half

(b) Sph2 moderator (half-depth spherical void)

Figure 3.6: Histograms over the x-divergence of neutrons below 1 eV exiting the moderators from the full spherical void, or only from one half of the void. Note that the histograms have been normalized to have the same height, to make the comparison easier. The histograms are not skewed compared to each other, indicating that focusing is absent.

to the divergence plot of all the neutrons from the void, the focusing effect is once more deemed non-existing. The similarity of the distributions is very surprising since neutrons in the moderator needs a direction towards the sphere to be used for this plot, and a sum over these from half a sphere was expected to point towards the other half of the sphere. This result is not fully understood, but the calculations and programming needed for the plots have been thoroughly checked for errors.

3.2.3 Neutron origins

To examine the higher flux coming from the voids, it could be instructive to plot where in the moderator the neutrons scatter last, before being written to output. These positions are exactly the r data from the simulation output, and can easily be plotted directly in MatLAB. In figure 3.7, such plots are shown for both the flat, sph1 and sph2 moderators, for neutrons of energies below^{k} 1 eV. Note that the color coding in the graphs is only there to show the z-positions of the points, helping to visualize the shape.

As expected, the points are distributed near the surface of the moderators. It is visible that the density of points near the horizontal surface of the two moderators with voids is smaller than the density of points near the surface of the flat moderator, meaning that some of the neutrons that would otherwise have exited through the horizontal surface instead exited through the void. This effect is also visible in the first row of figure 3.4, where the flux of neutrons from the area around the voids is smaller than the flux from the same area on the flat moderator. It corresponds well with both the “source volume” idea and the diffusion theory stating that the neutron density is larger closer to the source.

kFor a view of the same plot with all neutron energies, see figure G.1 (in appendix G).

z-direction [cm]_{0}_{10}_{20}_{30}_{40}_{50}_{60}_{70} x-direction [cm]_{0}_{50}_{100}_{150}_{200} y-direction [cm]_{0}_{50}_{100}_{150}_{200}

(a) Flat moderator

z-direction [cm]_{0}_{10}_{20}_{30}_{40}_{50}_{60}_{70} x-direction [cm]_{0}_{50}_{100}_{150}_{200} y-direction [cm]_{0}_{50}_{100}_{150}_{200}

(b) Sph1 moderator (full-depth spherical void)

z-direction [cm]_{0}_{10}_{20}_{30}_{40}_{50}_{60}_{70} x-direction [cm]_{0}_{50}_{100}_{150}_{200} y-direction [cm]_{0}_{50}_{100}_{150}_{200}

(c) Sph2 moderator (half-depth spherical void)

Figure 3.7: The final scattering points r of 5000 neutrons below 1 eV from the flat, sph1 and sph2 moderators. The coloring is simply to ease the viewer, and starts with warm colors for high z values, becoming colder for falling z. The box in the plots is the outline of the moderator.

4 Experiment

The simulation was made to model a block of moderator, so to investigate whether or not the simulation results were realistic, a series of measurements were done on similar moderator blocks in the laboratory. In this section, these measurements will be explained.

4.1 Moderator blocks

The sample moderator blocks were made with wood frames, each made of four pieces of pine plank – two of length 22 cm and two of length 25 cm – along with a bottom plate of hardboard, see figure 4.1. The depth of the frame is 6.8 cm, and the thickness of the planks is 1.5 cm. Wood consists mainly of cellulose, (C_{6}H_{10}O_{5})_{n}, and neither carbon, hydrogen or oxygen have large absorption cross sections. Hydrogen, though, have a large scattering cross section, and the wood acts as a neutron moderator with a mean free path^{l} for thermal neutrons of approximately 1.4 cm. Note that the wood is not modeled as part of the moderator block in the simulation.

The intended moderator to use, though, is not wood, but paraffin wax, which has a high density of hydrogen atoms, and hence is a good moderator. Paraffin wax consists of carbohydride chains of the form C_{n}H_{2n+2}, with a length n between 20 and 40 for the solid waxes. The number density of hydrogen atoms in the wax is

n_{H} = \frac{2n + 2}{nM_{C} + (2n + 2)M_{H}} ρN_{A},  (4.1)

lFor the calculation of this mean free path, as well as the one used for water later, see appendix C.

C B A A B Hardboard Pine plank A: 22 cm × 6.8 cm × 1.5 cm B: 25 cm × 6.8 cm × 1.5 cm C: 25 cm × 25 cm × 0.4 cm

Figure 4.1: Exploded view of the boxes made for the moderator blocks. The boxes are made such that the inside measurements are 22 cm × 22 cm × 6.8 cm.

where the density of the used paraffin wax^{m} is ρ = 0.85 g/cm^{3}. Using the average carbohydride chain length, n = 30, and the NNDC database value, [1], of the thermal hydrogen scattering cross section, σ_{s} = 30 b, [1], this makes the mean free path for thermal neutrons Σ^{−1} = (n_{H}σ_{s})^{−1} = 0.44 cm. This is a lot smaller than the mean free path for wood, showing that paraffin is indeed a better moderator. For a second comparison, normal water, an often used neutron moderator, has a mean free path for thermal neutrons of 0.50 cm.

The wood frame is filled with paraffin wax by first melting the wax over a waterbath, and then pouring it into the frame. The wax solidifies in the new form, and different concave voids can be carved out by hand. For the experiments, only a single void was made – corresponding to the sph1 moderator used during the simulations: A partly spherical void making a 5 cm radius circular hole in the moderator surface, with a depth of 5 cm. If the exact measurements of the used flat and sph1 moderators is wanted, see figure F.2.

4.2 Radioactive neutron source

The experiment was done with the already existing radioactive neutron source, originally designed for activation experiments. The actual source consists of a mix of alpha-radioactive ^{226}Ra and ^{9}Be inside a small lead container. Inside this mix, the following two reactions happen,

_{88}^{226}Ra → _{86}^{222}Rn + _{2}^{4}He,  (4.2)
_{2}^{4}He + _{4}^{9}Be → _{6}^{12}C + _{0}^{1}n,  (4.3)

sending out neutrons with energy of around^{n} 5.7 MeV. The lead container is positioned approximately at the center of a cylindrical paraffin block of height 31 cm and diameter 46 cm (one side of the cylinder has been cut off in the full height though – if wanted, an overview can be seen in figure F.3). Hollow cylindrical aluminium tubes run from the top, and almost through the length of the paraffin cylinder – making space for activation samples. For radiation safety, the cylinder is further encased in a larger iron barrel.

A sample moderator block can fit through the hatch, and be positioned on the top of the aluminium tubes, almost having contact with the top of the paraffin cylinder but for a few cm. Though, since the hatch on the neutron source is fairly small, to make measurements possible the blocks are not placed on the center of the main moderator – but instead with one side following the cut-off side, and another side positioned as a tangent to one of the aluminium tubes, a bit off-center.

mThis density was determined experimentally for the used paraffin wax, see appendix D.

nThis energy is found by looking at the difference in mass between the two sides of equation (4.3), and convert to energy by use of E = mc^{2}. It is assumed that ^{4}He, ^{9}Be and ^{12}C are motionless. In reality, the neutrons will exit the reaction with a distribution of energies, [7].

4.3 Counting neutrons

A helium-3 neutron counter – consisting of an aluminium container for the helium-3 gas, along with a small controller box sending back and forth the high voltage and signal – is used to measure the neutron flux. The system relies on the reaction

_{0}^{1}n + _{2}^{3}He → _{1}^{3}H^{+} + _{1}^{1}H^{+} + 2e^{−}  (4.4)

to detect neutrons, by help of a 1.5 kV high voltage and argon gas for charge amplification. However, the counter will also react on gamma photons. To only count the actual neutron events, an array of NIM modules is connected to the basic helium-3 counter, see figure 4.2. The signal from the detector is amplified and sent to a single channel analyzer (SCA), which sends out a logical pulse if the detector signal lies within set bounds. These bounds have been set to minimize the gamma background, while still making the neutron counts detectable.

Detector Detector-box HV-amplifier Amplifier SCA Linear ratemeter Counter Oscilloscope ^{detector signal}^{hv}_{hv} ^{com}_{com} _{unipolar signal} unip. signal sca signal_{sca signal}^{sca signal}_{1.50} 00000000245

Figure 4.2: The detector NIM array. The signal from the detector is amplified and sent on to an SCA, which outputs a logical pulse for each counted neutron. Such a pulse can be seen with the corresponding (amplified) detector neutron pulse on the oscilloscope to the right. The neutrons are counted on a simple counter.

The neutron counter is used to measure the flux of neutrons from the surface of the moderator blocks, so to discard neutrons coming from elsewhere, the counter has been incased in plastic containing boron. The interested reader can see the measurements of the detector and the housing in figure F.1. The detector was positioned such that it pointed towards the surface, and the hole in the plastic for the wire pointed upwards toward the ceiling. The ceiling was far away, and made largely of concrete, which does not scatter neutrons well^{o}. It was neither practical nor necessary to cover the wire side of the detector, because of limited wire length and the geometry. Since the actual inner dimensions of the helium-3 aluminium chamber is unknown, the detector was used pointing towards the measured point.

4.3.1 Detector dark count

The detector dark count is in this case the rate of false countings, and is especially relevant given the low rate of neutrons from the moderator surface. However, since neutron radiation background is very low, it is possible to get an estimate of the detector dark count by taking a long measurement without the neutron source in the same room. This 75 min long measurement gave only a total count of 2, corresponding to the flux shown in table 4.2, so the dark count is well below the average measurements – which is of the order of 1 cpm – and is thus not a problem. Notice that the counts are assumed to be Poisson distributed, [12]. The dark count is probably cosmic gamma radiation with energy high enough to fool the SCA bounds. It could also consist of electrical noise.

oConcrete does contain water, which scatters neutrons, but because of the distance to the ceiling, the contribution from this was low.

4.4 Measurements

A flat paraffin block was used for comparison, to measure the gain. The detector was moved parallel to one of the moderator sides, along a line over the center of the moderator surface – denoted the x-axis. The position of this axis is illustrated in figure F.3. Measurements were done with times in the order of 20 min per point. Due to the long counting times, and the obvious symmetry, measurements close to the side was mainly done in one side.

Moderator Detector height Boron plast height ⟨z_{det}⟩ [mm] ⟨z_{boron}⟩ [mm]
over surface [cm] over surface [cm]
Flat  1.6 ± 0.1  0.2 ± 0.1  84.5  70.3
Sph1  1.7 ± 0.2  0.3 ± 0.2  85.3  71.1

Table 4.1: The average height of the detector and the boron plastic during the two measurements. The z_{det} and z_{boron} values are used for convoluting the simulated data to compare it with the measured data, explained in section 5.2.

The measurement geometry, including the height of the detector over the surface, the detector position in the boron plastic, and the distance to the edges of the moderator, was recorded in a data file^{p}. The height of the detector, and the bottom part of the boron plastic, is shown in table 4.1. Next, the same measurements were done over the sph1 moderator block (with the full-depth spherical void). The height of the detector was kept as close as possible to the corresponding values for the measurements on the flat block.

Each series of measurements were taken in one long series with the detector only moved forward on the center line. At the end of each series an old measurement position was checked, such that any systematic error related to time, e.g., warm-up of counting electronics, could be spotted. These checks were always consistent with previous measurements.

4.4.1 Background count

To estimate the neutron background, a boron plastic cap was used to close the measurement hole for the detector. With this configuration, a 75 min measurement above the center of both the flat moderator and the sph1 moderator was taken, to check for any intensity proportional background, such as holes in the cage or insufficent absorption in the cage material. The results are shown in table 4.2. These two measurements were within the counting uncertaincy of each other. The average of the measurements was taken as the neutron input from the top of the boron plastic container, which includes the dark count, and thus were subtracted from all measurements as a background.

Measurement  Flux I [cpm]
Dark count of the helium-3 detector  0.07 ± 0.03
Background count over the flat moderator  0.42 ± 0.10
Background count over the sph1 moderator  0.51 ± 0.11
Averaged background count to subtract from data 0.47 ± 0.07

Table 4.2: The results of the dark count and background measurements. Notice that the uncertainties have been found by assuming Poisson distributed counts. The uncertainty of the averaged background was found by using the accumulation law, [12], on the two other uncertainties.

pFor tables of all the measurements, see appendix F.

4.4.2 Data

The data obtained after background correction is shown on figure 4.3, and the effect of the void is clearly seen: The peak intensity above the void is 3.7 times larger than the corresponding intensity above the flat moderator. To confirm that this result is a consequence of neutron scattering, and not just the effect of less absorption of the ray going through the moderator, the gain is compared to the maximum possible gain from a simple absorption expression. This is calculated^{q} to be a factor of 1.13, and hence can in no way alone explain the large gain.

0_{2}_{4}_{6}_{8}_{10}_{12}_{14}_{16}_{18}_{20}_{22}_{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8} Position along moderator middle x [cm] Flux of neutrons I [cpm] Sph1 data Flat data

Figure 4.3: Data taken for the flat and sph1 moderators. The two vertical lines indicate approximately where the spherical void begins and ends.

The measurements for the flat moderator are reasonably symmetric, but with a spherical void there seems to be higher intensities for small x-values. This is also visible in the high flux areas, since the peak seems to be off-center towards smaller x-values. The data from the flat moderator does not seem to show the same effect, since the intensity levels are approximately symmetric around the center. Because of this, it is not possible to normalize using these data as a reference.

5 Simulation compared to measured data

The simulation was made to model a simple system with a single moderator block, but the experiment was run with a more complex setup, where the neutrons originated from a larger moderator cylinder, and were counted using a detector of a certain size. To be able to compare the simulation data with the measured data, it is hence necessary to take the neutron energy distribution from the main moderator into account, as well as convolute the simulation data with the detector size.

5.1 Correct energy distribution input

For the experiments, the moderator blocks were positioned above the radioactive neutron source, which was itself inside a primary moderator cylinder. However, the simulation is primarily focusing on the small moderator blocks, and does not simulate the primary moderator. To simulate the small moderator blocks in a more realistic way though, the energy distribution from the primary moderator is needed as a starting condition.

The primary moderator can be approximated in the simulation as a large block moderator with the same height and top area as the paraffin cylinder. Every simulated neutron is set to start with a random direction from the center of the block, all with an energy of 5.7 MeV from the reaction in (4.3). After simulating this configuration, the energy distribution of the neutrons emitted from the top of the block is analyzed, as shown in figure 5.1.

qSee appendix E.1 for the calculation.

10^{0} 10^{2} 10^{4} 10^{6} 0 400 800 1200

Energy E [eV] Number of neutrons with energy E Histogram Linear fit:

y = 2.2266 × 10^{−4} E + 23.154

Figure 5.1: The distribution of energies of a simulation of the primary moderator. Note that the point corresponding to thermal energy is not visible in this plot, since it is at a height of 11 610, corresponding to 59.5 % of the total number of neutrons having thermal energy. Along with the histogram is a linear fit of all points except the thermal energy point.

Only the distribution from a run with isotropical scattering is shown in the figure, since that distribution is easier to work with in a histogram. The isotropical scattering version of the simulation simply decreases the neutron energy by half of the difference between the neutron energy and thermal energy, and hence it is easy to count the number of neutrons with specific energies – simply because the different energies are already known. The corresponding distribution from the elastical scattering simulation is very similar – but since the neutron energy decrease in a more continuous manner here, it is harder to plot a histogram that is easily deciphered. For the isotropic scattering simulation, 59.5 % of the neutrons reaching the top of the large block were thermal, while for the elastic it was 61.5 %. The rest of the neutrons follow a linear distribution, as shown in the fit in figure 5.1. This distribution was very close to be the same for the two energy decrease types.

The final energy distribution is chosen to be 61.5 % thermal, where the number from the elastic scattering run has been chosen because this scattering model is closest to the actual neutron behavior, and the linear distribution from thermal to 5.7 MeV. The starting direction in the secondary moderator is orthogonal to the starting plane, as the direction data from the main moderator was not analysed. Note that this input energy distribution has been used for all the simulation runs shown in this report.

5.2 Convolution of simulation data

To be able to compare the real data with the simulated data, it is necessary to convolute with the size of the detector. The actual measurements were taken as points above a line on the middle of the moderator block. The simplest approach is to make a convoluted simulated data point by simply counting the number of neutrons intersecting a plane the size of the end of the detector, at the height of the detector in the real experiment, the z_{det} values in table 4.1. A more advanced approach is to do the same, but now only count the neutrons that do not intersect the bottom part of the absorbing boron plastic housing. The boron housing started at the heights given as z_{boron} in table 4.1 in the measurements.

Finding the neutrons that intersect a certain area of a plane is a simple extension of the plane intersection procedure explained in section 3.2.1, so doing the convolution is simply a matter of testing whether or not each neutron reach the detector plane without intersecting one of the absorber planes. This should then be done for each wanted data point over the moderator surface.

The data has been shown along with their corresponding convoluted simulation data in figure 5.2. The simulation worked by simulating neutrons until a pre-determined number of neutrons had exited the top moderator surface, so since a different fraction of the total number of simulated neutrons is emitted though the top from different moderator configurations, the convoluted simulation data was normalized so comparison between simulation runs was possible. All simulation data have then been multiplied by an equal small factor f, to make the intensities comparable to the measured intensities. The factor f was found by simply varying the size, until the simulated data for the flat moderator had approximately the same height as the measured data.

0_{2}_{4}_{6}_{8}_{10}_{12}_{14}_{16}_{18}_{20}_{22}_{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8} Position along moderator middle x [cm] Flux of neutrons I [cpm] Sph1 data Sph1 simulated Flat data Flat simulated

Figure 5.2: Data taken for the flat and sph1 moderators, along with the corresponding convoluted simulation data. The two vertical lines indicate approximately where the spherical void begins and ends.

5.3 Discussion of results

When comparing simulation predictions and measured data, it is important to specify what the objective is. The simulation was not made to predict behavior of this exact system, but for a simpler single moderator system. Hence, there will be behavior in the measurements not described by the simulation. In this project, the objective is to estimate the quality of the predictions of the simulation.

Overall, the simulated data follows the shape of the measured data, but the intensity increase caused by the void is greater than the simulation predicts: Simulation predicted a gain for the sph1 moderator as compared to the flat moderator of a factor 2.7, but the measurements show a gain of 3.7.

5.3.1 Higher gain due to absorption

The effects of absorption have so far been ignored: It was initially thought that absorption would not alter the overall shape of the simulation data, but only require a larger normalization constant f to fit the data. The effect of absorption without scattering was further evaluated to be very small. Diffusion theory does, however, have an absorption term which alters the shape of the solution, see equation (2.24). The neutron scalar flux was calculated for a finite slab in section 2.3.2 without absorption, and in [9, chap. 3] the corresponding solution can be found with absorption,

φ(z) = 2S_{0} \frac{sinh (\frac{t − z}{L} ) + \frac{2D}{L} cosh (\frac{t − z}{L} )}{(\frac{2D}{L} + 1)^{2}e^{t/L} − (\frac{2D}{L} − 1)^{2}e^{−t/L}} ,  (5.1)

where D = 1/(3Σ_{s}) and L^{2} = D/Σ_{a}. On figure 5.3 the two solutions have been plotted for thermal neutrons in hydrogen using Σ_{a} = 0.025 cm^{−1}, Σ_{s} = 2.25 cm^{−1} and a thickness of t = 6.8 cm.

z [cm] φ [S_{0}]_{0}_{0.5}_{1}_{1.5}_{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}without absorption with absorption

z [cm] φ [S_{0}]

0 0.1 0.2 0.3 6.4 6.6

6.8 moderator top

Figure 5.3: Comparison of the neutron scalar flux from diffusion theory with and without absorption, corresponding to equation (2.29) and (5.1).

According to the figure, absorption is important for the neutron scalar flux as a function of depth. This could very well have an impact on the effects of a void in the surface, since the difference between neutron density at the surface and at a depth is larger than anticipated: Simply comparing the two solutions, the maximal gain^{r} for a spherical void like in the sph1 moderator is evaluated to be 7.6 for the solution without absorption, and 12.5 for the solution with absorption.

To see if absorption could really explain the difference between the measured gain and the simulated gain, a simple extension to the simulation was written. Because of time limitations this was only done for thermal neutrons, and consists of an exponentially distributed maximum distance assigned to each neutron, following I(z) = I_{0} exp (−Σ_{a}z) with Σ_{a} = 0.025 cm^{−1}. If a neutron, probably after many scatterings in the moderator, does reach the maximum distance, it is considered lost, and the loop is stopped. This could not be done as easily in a simulation where neutrons changes energy, since the absorption cross section is energy dependent. The results of this simulation run is seen in figure 5.4 with a comparison to a run without absorption and with normal energy start distribution, as was shown in figure 5.2. The new simulation data matches the measurements very well: The gain is 3.6, less than 5 % from the measured gain of 3.7. However, the improvement could have been caused by the fact that only thermal neutrons were simulated, so to falsify this, a simulation run with thermal neutrons, but no absorption, was completed – showing a gain of 2.4 (a plot of the result can be seen in figure G.2(b)). Hence, the difference in gain between the normal simulation and the measurements is most likely explained by absorption in the moderator, which was hence much more important than initially assumed. The acuraccy of the simulation is above expectations, especially when considering the simple scattering model.

5.3.2 Assymmetry of the sph1 moderator measurements

The measured data for the sph1 moderator showed a slight asymmetry, with higher count rates for small x-values. This was not seen in the simulated data. A first explanation might be that the distance between the detector and the moderator surface changed almost linearly during the measurements because the detector was mounted on a rail, which was not completely horizontal. These heights can be seen in the tables in appendix F. The height of the detector was larger for small x-values, corresponding to a larger visible solid angle of moderator, and thus a slightly higher flux would be measured. It is currently not understood why the sph1 sample was more affected by this than the flat moderator.

Since the detector heights were recorded, and had a simple correlation with x, this could be incorporated in the convolution routine, to investigate if this could explain the asymmetry. However, due to the late discovery of the systematic error, this was not done.

A second explanation might be an uneven flux of neutrons from the primary moderator: If the incoming distribution is larger near the small x-values, the resulting effect might be larger for moderators with voids, since neutrons sent into a flat moderator have a larger length of moderator to \underline{24 6 Future}

rFor the calculation of these values, see appendix E.2.

0_{2}_{4}_{6}_{8}_{10}_{12}_{14}_{16}_{18}_{20}_{22}_{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8} Position along moderator middle x [cm] Flux of neutrons I [cpm] Sph1 data Sph1 simulated Sph1 simulated w.a. Flat data Flat simulated Flat simulated w.a.

Figure 5.4: Data taken for the flat and sph1 moderators, along with the corresponding convoluted simulation data, as shown in figure 5.2, and the convoluted simulation data from a run with absorption (though only with thermal neutrons). The two vertical lines indicate approximately where the spherical void begins and ends. Note that only 1 × 10^{6}, unlike the usual 7.5 × 10^{6}, neutrons were output from the simulation with absorption, due to time limitations.

dissipate in before they reach the surface. If the incoming distribution is larger on, say, the left side of a moderator with a void, some of the neutrons that would dissipate from this side to the other, might instead exit the moderator from the void – resulting in a smaller neutron count from the right side of the moderator surface. This explanation is further made probable by the fact that the primary moderator had empty aluminium tubes running throughout its length, and these might act in the same way as the voids investigated during this project. A simulation run was done with a cylindrical void in a moderator block, and the same effect as for a spherical void was present: The flux above the cylindrical void was larger than for a similar flat moderator block, concluding that it was very possible that the flux from the primary moderator was uneven.

This effect might have been avoided with higher moderator blocks, which was initially planned: The currently used blocks were meant to go on top of a buffer moderator block. Unfortunately, to get a significant neutron count this was not possible with the used neutron source, since the moderator blocks had to be positioned below the hatch, and hence couldn’t have the collected height of the two blocks.

5.3.3 Precision of normalization

Both simulated data sets were normalized by the same factor f, since they had the same source parameters. However, there is no definite argument for the normalizing factors to be equal, since only a fraction of the moderator system was simulated. Neutrons lost through the sides or bottom of the simulated secondary moderator could hit the main moderator again and potentially be scattered back to the secondary moderator – and if this effect is different for the two configurations, the same f factor should not be used. It is, however, difficult to gauge this effect without simulating the entire system.

6 Future

6.1 Use of optimized moderator geometry

Optimization of moderator geometries is still an on-going subject, [3, 4, 5, 13], where even a small increase in beam intensity is valuable. A new spallation neutron source, the European Spallation Source in Lund [6], is currently in the pre-construction phase, and results from this project, as well as from similar investigations by others, could potentially be used for optimizing the brilliance of the beam there.

6.2 More powerful small scale neutron source

The original purpose of this project was to build a neutron source in the form of a Farnsworth-Hirsch fusor, [14] – a device using inertial electrostatic confinement to accelerate deuterium ions towards the center of a spherical symmetry, see figure G.3. In the center, the ions will fuse and emit neutrons from the reaction

_{1}^{2}D + _{1}^{2}D → _{2}^{3}He + _{0}^{1}n.  (6.1)

These neutrons will have energies of up to 2.45 MeV, [7, chap. 14], and will have to be moderated to be measured by the helium-3 counter. This was where the moderator physics came into the picture.

Unfortunately though, the project took longer time to finish than anticipated, and at the moment the fusor is not running. When it is finally working, it is expected to produce an output of up to 20 times the output of the radioactive source used in this project, [15], reducing the counting times significantly, and hence providing the possibility for more detailed measurements of moderator geometry effects.

7 Conclusion

The flux distribution from the surface of a paraffin wax moderator was studied by means of simulation and experiment. A void in the surface of the moderator was predicted to increase the flux, and a small focusing effect was expected. The simulation was written to investigate such effects in a non-absorbing moderator by using cross section data from the Brookhaven National Laboratory NNDC database, [1], and assuming that the neutron moderation could be modeled as classical elastic collision of spheres. The focus of the simulation was on the geometrical implications of a void in the surface, and a flux increase near a void was seen, similar to [3, 5], but no focusing related to the void was observed in simulated data.

To test the predictions of the simulation, an experiment using paraffin wax blocks was conducted with a radioactive neutron source, which proved insufficient for measurements on the focusing effect, but could be used for measurements near the surface of the moderator. The measurements showed a much larger flux increase over the void than the simulation predicted, but the simulated data did follow the shape of the measurements. By means of diffusion theory, the effects of absorption was estimated to be important for the effects of a void, and absorption was added to the simulation, limiting the simulation to thermal neutrons. The effect was however seen, and a very close match between measurements and simulation was obtained. Hence, a simulation built upon simple classical elastic collision of spheres is sufficiently accurate, within 5 %, to predict the flux increase near a large spherical void in a neutron moderator, as long as absorption is also taken into account.

To improve upon the results from this project, a fusion based neutron source will be constructed. This will give full control over the moderator geometry, since a single moderator can then be used. The larger intensity that should become available would allow for further studies of the expected focusing effect, and much faster measurements of other interesting geometries. Further, the energy restriction of the absorption addition can be removed by using data from [1] to model absorption probabilities between every scattering event, and hence improve the quality of the predictions.

26

References

[1] National Nuclear Data Center, Brookhaven National Laboratory: Evaluated Nuclear Data File (ENDF) Retrieval & Plotting, version 3.2. www.nndc.bnl.gov/sigma, December 2010.

[2] Los Alamos National Laboratory: MCNP home page. http://mcnp-green.lanl.gov/.

[3] Steven E. Keller, Brent J. Heuser, and John M. Carpenter: MNCP simulations of neutron moderation in the IPNS C moderator. Physica B, 241-243:30–32, 1998.

[4] Y. Ogawa, Y. Kiyanagi, N. Kosugi, H. Iwasa, M. Furusaka, and N. Watanabe: Intensity enhancement of cold neutrons from a coupled liquid-hydrogen moderator for pulsed cold neutron sources. Nuclear Instruments & Methods in Physics Research A, 432:415–421, 1999.

[5] D. J. Picton, S. M. Bennington, T. A. Broome, and T. D. Beynon: Design options for coupled cold moderators on a low power spallation source. Nuclear Instruments & Methods in Physics Research A, 545:363–374, 2005.

[6] The European Spallation Source: ESS home page. http://ess-scandinavia.eu.

[7] Kenneth S. Krane: Introductory Nuclear Physics. Wiley, first edition, 1988.

[8] Kim Lefmann: Neutron Scattering: Theory, Instrumentation, and Simulation. Niels Bohr Institute, 2010.

[9] Weston M. Stacey: Nuclear Reactor Physics. Wiley, second edition, 2007.

[10] William H. Press, Saul A. Teukolsky, William T. Vetterling, and Brian P. Flannery: Numerical Recipes in Fortran 77 – The Art of Scientific Computing, volume 1. Cambridge University Press, second edition, 2006.

[11] MathWorks: Matlab version 7.11.0 (R2010b). www.mathworks.com/products/matlab/.

[12] John R. Taylor: An Introduction to Error Analysis. University Science Books, second edition, 1982.

[13] C. M. Lavelle, D. V. Baxter, A. Bogdanov, V. P. Derenchuk, H. Kaiser, M. B. Leuschner, M. A. Lone, W. Lozowski, H. Nann, B. v. Przewoski, N. Remmes, T. Rinckel, Y. Shin, W. M. Snow, and P. E. Sokol: Neutronic design and measured performance of the Low Energy Neutron Source (LENS) target moderator reflector assembly. Nuclear Instruments & Methods in Physics Research A, 587:324–341, 2008.

[14] Robert L. Hirsch and Gene A. Meks: Patent disclosure: Apparatus for generating fusion reactions, 1968.

[15] The Open Source Fusor Research Consortium: fusor.net forums. www.fusor.net/board/index.

php?site=fusor.

[16] G. L. Squires: Introduction to the theory of thermal neutron scattering. Dover publications, 1978.

[17] Erik Strandgaard Andersen, Paul Jespersgaard, and Ove Grønbæk Østergaard: Databog Fysik Kemi. F & K Forlaget, 10. edition, 2005.

[18] GNU Project: GCC, the GNU Compiler Collection. http://gcc.gnu.org/.

28

Appendixes

A Thermal neutrons

Thermal neutrons are called so because they move with speeds comparable to atoms in a gas with room temperature. The normal way to define room temperature here is to define the thermal speed as v_{th} = 2200 m/s, [8, chap. 2]. This speed then corresponds to the kinetical energy, [16],

E_{th} = \frac{1}{2}m_{n}v_{th}^{2},  (A.1)

where m_{n} = 1.675 × 10^{−27} kg is the neutron mass. Evaluated, this energy is 0.025 eV. The temperature can be found by

E_{th} = k_{B}T_{th},  (A.2)

where k_{B} = 8.617 × 10^{−5} eV/K is Boltzmanns constant. Evaluated, the temperature is found to be 293.5 K, or 20.3 ^{∘}C, which is well within the normal meaning of the word “room temperature”.

The (de-Broglie) wavelength λ of a neutron can be calculated from the energy, by using that

λ = \frac{2πℏ}{m_{n}v} ,  (A.3)

from [8]. Inserting the thermal speed v_{th}, the wavelength of thermal neutrons can then be calculated to be 1.797 Å, exactly the same order as lattice-spacing in crystals.

B The neutron velocity after elastic scattering

The momentum conservation in equation (2.4) and the energy conservation in equation (2.5) can both be simplified by dividing out the masses,

mu_{n,p} + mu_{H,p} = mv_{n,p} + mv_{H,p} ⇒ u_{n,p} + u_{H,p} = v_{n,p} + v_{H,p},  (B.1)
\frac{1}{2}mu_{n}^{2} + \frac{1}{2}mu_{H}^{2} = \frac{1}{2}mv_{n}^{2} + \frac{1}{2}mv_{H}^{2} ⇒ u_{n}^{2} + u_{H}^{2} = v_{n}^{2} + v_{H}^{2}.  (B.2)

The energy conservation equation is then further written out by using v_{i}^{2} = v_{i,p}^{2} + v_{i,o}^{2}, and the equations are now

u_{n,p} + u_{H,p} = v_{n,p} + v_{H,p},  (B.3)
u_{n}^{2} + u_{H}^{2} = v_{n,p}^{2} + v_{n,o}^{2} + v_{H,p}^{2} + v_{H,o}^{2}.  (B.4)

It is then used that momentum, and in this case speed, in the orthogonal direction is unchanged for both particles, v_{n,o} = u_{n,o} and v_{H,o} = u_{H,o}. Further, since v_{H,p} is not important as an end result, this variable is chosen for isolation and substitution, making the two equations

v_{H,p} = u_{n,p} + u_{H,p} − v_{n,p},  (B.5)
u_{n}^{2} + u_{H}^{2} = v_{n,p}^{2} + u_{n,o}^{2} + v_{H,p}^{2} + u_{H,o}^{2}.  (B.6)

Substituting equation (B.5) into equation (B.6),

u_{n}^{2} + u_{H}^{2} = v_{n,p}^{2} + u_{n,o}^{2} + (u_{n,p} + u_{H,p} − v_{n,p})^{2} + u_{H,o}^{2}  (B.7)
= v_{n,p}^{2} + u_{n,o}^{2} + u_{n,p}^{2} + u_{H,p}^{2} + v_{n,p}^{2} + 2u_{n,p}u_{H,p} − 2u_{n,p}v_{n,p} − 2u_{H,p}v_{n,p} + u_{H,o}^{2},  (B.8)

and since u_{n}^{2} = u_{n,p}^{2} + u_{n,o}^{2} and u_{H}^{2} = u_{H,p}^{2} + u_{H,o}^{2}, these parts cancel, leaving

0 = v_{n,p}^{2} + v_{n,p}^{2} + 2u_{n,p}u_{H,p} − 2u_{n,p}v_{n,p} − 2u_{H,p}v_{n,p}  (B.9)
= 2v_{n,p}^{2} − v_{n,p}(u_{n,p} + u_{H,p}) + 2u_{n,p}u_{H,p}.  (B.10)

This second order equation has the solutions v_{n,p} = u_{H,p} and v_{n,p} = u_{n,p}, where the first corresponds to the state after collision, and the second corresponds to the state before collision. The state before collision is trivial, so this solution is not used further.

Since the orthogonal part of the velocities were unchanged, the full final velocity of the neutron is now known, and can be written in (parallel,orthogonal)-coordinates as

v_{n} = (\begin{matrix}v_{n,p} \\ v_{n,o} \end{matrix}) = (\begin{matrix}u_{H,p} \\ u_{n,o} \end{matrix}) .  (B.11)

Using this result, the final energy of the neutron, E_{f}, is then

E_{f} = \frac{1}{2}mv_{n}^{2} = \frac{1}{2}m(v_{n,p}^{2} + v_{n,o}^{2}) = \frac{1}{2}m(u_{H,p}^{2} + u_{n,o}^{2}) = \frac{1}{2}m((−u_{H} sin θ)^{2} + (u_{n} cos θ)^{2})  (B.12)
= \frac{1}{2}m(u_{H}^{2} sin^{2} θ + u_{n}^{2} cos^{2} θ) = \frac{1}{2}mu_{H}^{2} sin^{2} θ + \frac{1}{2}mu_{n}^{2} cos^{2} θ = E_{i} sin^{2} θ + E_{H} cos^{2} θ,  (B.13)

where E_{i} is the initial neutron energy, and E_{H} is the initial hydrogen energy, assumed to be the thermal energy. It was here used that the parallel and orthogonal parts of the inital velocity vectors can be written as

u_{n,p} = u_{n} sin θ,  u_{n,o} = u_{n} cos θ,  u_{H,p} = −u_{H} sin θ,  u_{H,o} = −u_{H} cos θ,  (B.14)

where u_{n} and u_{H} is the length of the initial neutron and hydrogen velocity, respectively, see figure 2.1(a).

C Mean free paths

The mean free path of a neutron in a certain substance is a measure of how long a neutron can travel in the substance before being scattered. This value is the reciprocal of the macroscopic cross section, Σ, [9, chap. 11],

λ = \frac{1}{Σ}.  (C.1)

According to equation (2.2), the macroscopic cross section can be found as the product of the cross section σ and the scatterer number density n = N/V.

C.1 Cellulose

For cellulose, which has the chemical formula (C_{5}H_{10}O_{5})_{n}, it can be assumed that only the hydrogen nuclei scatter neutrons, and hence the number density of the scattering nuclei is simply the number density of the hydrogen nuclei

n_{H} = \frac{10n}{6nM_{C} + 10nM_{H} + 5nM_{O}} ρN_{A},  (C.2)

where N_{A} = 6.022 × 10^{23} mole^{−1} is Avogadros number, and ρ is the density of cellulose, which is between 0.4 and 0.9 g/cm^{3}, [17]. The M_{X} variables are simply the molar masses of the three atoms. Using the average value of the density, ρ = 0.65 g/cm^{3}, the evaluated number density is n_{H} = 2.41 cm^{−3}. Since the thermal scattering cross section for hydrogen is σ_{th,H} = 30 b, [1], the mean free path is λ = Σ^{−1} = (n_{H}σ_{th,H})^{−1} = 1.38 cm.

C.2 Water

Water, which has the well-known chemical formula H_{2}O, is also a great scatterer, because of the large density of hydrogen nuclei. The number density is

n_{H} = \frac{2}{2M_{H} + M_{O}} ρN_{A},  (C.3)

where ρ = 1.0 g/cm^{3} is the density of water at room temperature. Evaluated, this number density is 6.69 × 10^{22} cm^{−3}, and the mean free path is only 0.499 cm.

D The density of paraffin wax

To determine the density, ρ, of the used paraffin wax, a small sample of the wax was casted in a plastic cup along with the large moderator blocks. After setting, the sample was removed from the cup and immersed in water to determine its volume, which was found to be V = 186 ± 2 cm^{3}. Afterwards, the sample was weighed on a scale, and its mass was determined to be m = 158.2 ± 0.1 g. The density was then calculated by using

ρ = \frac{m}{V},  (D.1)

and was found to be ρ = 0.851 g/cm^{3}. The uncertainty of this result can be found by use of the accumulation law, [12], which states that

δρ = \sqrt{(\frac{∂ρ}{∂V} δV )^{2} + (\frac{∂ρ}{∂m} δm)^{2}} = \sqrt{\frac{m^{2}}{V^{4}} δV^{2} + \frac{1}{V^{2}} δm^{2}},  (D.2)

and hence the final result is that the density of the used paraffin wax is ρ = 0.851 ± 0.009 g/cm^{3}. This result is as expected, since a normal paraffin wax has a density between 0.8 and 0.9 g/cm^{3}, [17].

E Maximal gains

E.1 For absorption only

It is possible to calculate the maximum gain of a void in a moderator, as compared to a similar flat moderator, by using a similar expression as equation (2.3), but for absorption,

I(z) = I_{0} exp (−Σ_{a}z).  (E.1)

For a moderator of height h with a void of depth d, the maximum possible gain as compared to a moderator of heigh h without a void, is

gain(h, d) = exp ( − Σ_{a}(h − d)) ; exp (−Σ_{a}h),  (E.2)

if only taking absorption into account. The limit of this gain, for d → h – meaning that the moderator thickness at the bottom of the void goes towards zero – is simply exp (Σ_{a}h).

For the moderator blocks used during this project, of height h = 6.8 cm, the maximum possible gain for any void due only to absorption is hence 1.185, while the maximum possible gain for the void in the sph1 moderator, with d = 5 cm, is 1.133.

E.2 According to diffusion theory

The maximal gain, if only looking at the neutron current J from diffusion theory, can be calculated for the sph1 moderator by simply inserting the known macroscopic absorption and scattering cross sections, Σ_{a} and Σ_{s}, and the thickness t = 6.8 cm – and then compare with a point at a depth in the moderator. The depth can either be the extreme – the deepest point of the void – or the more realistic – the average depth of the void.

To find the average depth of the void, it is first of all necessary to write the void as a function. A cross section of a half-spherical void can be written as a half-circular void, that has heights

h(x) = t − \sqrt{r^{2} − (r − x)^{2}},  (E.3)

where t is the thickness of the moderator that the void is on, r is the radius of the circle (and hence also of the sphere), and x here is zero at the start of the circle void, and 2r at the end. The average height of the void is then

\frac{1}{2r} ∫_{0}^{2r} h(x) dx,  (E.4)

which can be evaluated to be 2.87 cm in the case of the sph1 moderator.

It is then just a question of inserting the known values into the solution without absorption, equation (2.29), and the solution with absorption, equation (5.1),

φ(z) = 2S_{0} (1 − \frac{z}{t + 2D} ) ,  φ(z) = 4S_{0} \frac{sinh (\frac{t − z}{L} ) + \frac{2D}{L} cosh (\frac{t − z}{L} )}{(\frac{2D}{L} + 1)^{2}e^{t/L} − (\frac{2D}{L} − 1)^{2}e^{−t/L}} ,  (E.5)

respectively, and finally calculating the upwards current, J_{+}(z), given by

J_{+}(z) = \frac{1}{4}φ(z) − \frac{1}{2}D \frac{∂φ}{∂z}|_{z}  (E.6)

in section 2.3.1. The results are shown in table E.1.

Height z [cm]  1.8  2.87 6.8  Gain in lar- Gain in ave-
gest depth rage depth
Upwards neutron current 0.394 0.319 0.042 9.381  7.595
w.o. absorption, J_{+} [S_{0}]
Upwards neutron current 0.237 0.15 0.012 19.75  12.5
w. absorption, J_{+} [S_{0}]

Table E.1: Maximal gains according to diffusion theory with and without absorption, for the sph1 moderator with two calculated dephts.

F Measurements

In this appendix, the full measurements taken for the used two moderator blocks, the flat moderator and the sph1 moderator, are shown in tables. The saved data are as follows: The position in the xand y-direction (see figure F.3), the height of the boron plastic housing over the moderator surface z_{boron} (this was not possible to measure over the void in the sph1 moderator, and is hence not always shown), the height of the detector inside the housing h (measured from the top and down to the detector top), the counting times in minutes and seconds T, and the number of counts N.

The detector height z_{det} can be found from the housing height and the height of the detector in the housing by using that

z_{det} = z_{boron} + L_{boron} − L_{det} − h,  (F.1)

where L_{boron} = 18.7 cm is the length of the housing and L_{det} = 12.75 cm is the length of the detector, both shown in figure F.1.

5.205 cm 5.205 cm 18.7 cm5.43 cm 5.43 cm 2.97 cm2.68 cm 2.68 cm 12.75 cmboron plastic thickness: 0.53 cm

Figure F.1: Dimensions of the detector and the boron plastic housing. Notice that there is no helium-3 gas in the cylindrical thud on the end of the detector, but the inside dimensions of the chamber are otherwise unknown.

Notice that the x- and y-position was measured from the paraffin edge to the boron housing edge in the corresponding direction, hence, to get the actual data point position – at the center of the detector – it is necessary to calculate

x_{det} = x + \frac{W_{boron}}{2} ,  y_{det} = y + \frac{W_{boron}}{2} ,  (F.2)

where W_{boron} = 5.205 cm is the width of the boron housing, see figure F.1.

Measurements for the flat moderator are shown in table F.1, while measurements for the sph1 moderator are shown in table F.2. Notice that the measurements were taken in the same sequence as they are shown in the table, and that the bottom measurements (below a horizontal line) are the consistency checks mentioned in the report.

vi  Appendix F Measurements

22.0 cm 22.1 cm 22.1 cm 21.9 cm 89.5^{∘} 90.0^{∘} 89.9^{∘} 90.1^{∘} Align edge

(a) Flat moderator

21.9 cm 22.0 cm 22.0 cm 22.0 cm 88.2^{∘} 91.8^{∘} 88.1^{∘} 92.0^{∘} 5.74 cm 6.04 cm 5.76 cm 5.93 cm 10.21 cm Align edge

(b) Sph1 moderator – void depth is 5 cm

Figure F.2: Overview of the two moderator blocks used during the measurements. Notice that this is the measurements of the paraffin blocks, not the wood frames.

x [cm]_{0}_{22} y [cm]_{0}_{22}_{46 cm} Align edge

Figure F.3: Overview of the top of the primary moderator of the radioactive source, along with the position of the seven aluminium tubes running throughout the height of the moderator. The position of the moderator blocks on top of the primary moderator is indicated, along with the used x- and y-axes. The indicated align edge is the same as indicated in figure F.2.

Position Position Housing height Detector in housing Counting time Count
x [cm]  y [cm]  z_{boron} [cm]  h [cm]  T [min] [sec] N [unitless]
1.63  8.46  0.35  4.52  20  57.99 46
2.62  8.48  0.38  4.54  22  9.23 49
3.72  8.44  0.265  4.53  23  21.91 53
4.925 8.47  0.33  4.51  23  34.97 48
5.73  8.43  0.29  4.54  20  28.11 42
6.65  8.44  0.29  4.52  21  19.10 47
7.77  8.47  0.24  4.53  20  0.54 38
8.635 8.475  0.25  4.54  23  34.49 60
9.525 8.54  0.155  4.54  20  5.13 44
10.495 8.48  0.18  4.53  22  36.84 50
11.59  8.46  0.16  4.55  22  45.82 39
12.63  8.52  0.15  4.52  22  34.50 35
13.70  8.50  0.13  4.52  21  17.03 44
14.76  8.50  0.12  4.53  20  56.25 50
15.43  8.52  0.12  4.52  21  38.75 51
16.45  8.52  0.18  4.53  21  55.41 28
16.9  8.30  0.13  4.54  20  34.17 37
18.2  8.38  0.18  4.54  20  51.13 38
0.31  8.48  0.27  4.53  19  59.04 35
16.85  8.34  0.385  4.53  27  35.43 58

Table F.1: Measurements taken for the flat moderator. Measurements were taken in the sequence they are shown above. The two measurements under the line were consistency checks.

Position Position Housing height Detector in housing Counting time Count
x [cm]  y [cm]  z_{boron} [cm]  h [cm]  T [min] [sec] N [unitless]
1.04  8.35  0.50  4.52  28  33.39 71
2.00  8.40  0.50  4.52  27  27.94 72
2.80  8.36  0.45  4.52  27  44.10 87
4.11  8.38  0.40  4.53  21  21.80 86
5.06  8.40  0.345  4.53  21  16.29 113
6.05  8.39  0.30  4.54  23  39.19 163
6.92  8.43  -  4.535  23  22.91 168
7.94  8.415  -  4.52  30  35.67 217
9.11  8.485  -  4.54  20  32.37 142
10.07  8.46  0.355  4.525  24  27.00 164
10.98  8.46  0.34  4.55  21  26.72 134
11.99  8.46  0.30  4.55  26  43.88 126
12.59  8.36  0.30  4.54  21  24.75 70
13.37  8.46  0.25  4.54  21  41.11 59
14.26  8.46  0.245  4.535  22  20.73 50
14.77  8.43  0.25  4.525  20  35.97 34
15.525 8.51  0.20  4.52  20  32.39 37
16.14  8.47  0.17  4.53  20  0.52 38
16.9  8.36  0.16  4.45  21  15.65 31
17.8  8.33  0.15  4.545  20  18.10 27
2.19  8.59  0.30  4.54  13  0.23 31

Table F.2: Measurements taken for the sph1 moderator. Measurements were taken in the sequence they are shown above. The measurements under the line was a consistency check.

G Extra figures

In this section are alternative plots to the ones in the main part of the report. These are placed here, instead of inside the main report, due to their minimal relevance and due to space limitations.

Figure G.1 shows the same three plots of the r values for the last scattering point of 5000 neutrons as was shown in figure 3.7 on page 16 – but with all neutron energies instead of only energies below 1 eV.

Figure G.2 shows the three convoluted datasets, where the first is the normal simulation, as shown in figure 5.2 on page 22, the second is the same simulation as the first, but now only run for thermal neutrons, and the third figure is the simulation run for only thermal neutrons, but with an absorption term in the simulation as well, as shown in figure 5.4 on page 24.

Finally, figure G.3 shows a schematic overview of the fusion-based neutron source it had been hoped to finish during this project.

z-direction [cm]_{0}_{10}_{20}_{30}_{40}_{50}_{60}_{70} x-direction [cm]_{0}_{50}_{100}_{150}_{200} y-direction [cm]_{0}_{50}_{100}_{150}_{200}

(a) Flat moderator

z-direction [cm]_{0}_{10}_{20}_{30}_{40}_{50}_{60}_{70} x-direction [cm]_{0}_{50}_{100}_{150}_{200} y-direction [cm]_{0}_{50}_{100}_{150}_{200}

(b) Sph1 moderator (full-depth spherical void)

z-direction [cm]_{0}_{10}_{20}_{30}_{40}_{50}_{60}_{70} x-direction [cm]_{0}_{50}_{100}_{150}_{200} y-direction [cm]_{0}_{50}_{100}_{150}_{200}

(c) Sph2 moderator (half-depth spherical void)

Figure G.1: The same plots as in figure 3.7 on page 16, but now with all neutron energies (there are still only 5000 points plotted though). It is visible how a large number of high-energy neutrons exit directly from the bottom input face of the moderator, but the voids in the bottom two moderators are still visible.

Appendix G Extra figures  ix

0_{2}_{4}_{6}_{8}_{10}_{12}_{14}_{16}_{18}_{20}_{22}_{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8} Position along moderator middle x [cm] Flux of neutrons I [cpm] Sph1 data Sph1 simulated Flat data Flat simulated

(a) Normal simulation, several energies (figure 5.2)

0_{2}_{4}_{6}_{8}_{10}_{12}_{14}_{16}_{18}_{20}_{22}_{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8} Position along moderator middle x [cm] Flux of neutrons I [cpm] Sph1 data Sph1 simulated thm. Flat data Flat simulated thm.

(b) Normal simulation, only thermal energies

0_{2}_{4}_{6}_{8}_{10}_{12}_{14}_{16}_{18}_{20}_{22}_{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8} Position along moderator middle x [cm] Flux of neutrons I [cpm] Sph1 data Sph1 simulated w.a. Flat data Flat simulated w.a.

(c) Simulation with absorption, only thermal energies

Figure G.2: Data taken for the flat and sph1 moderators, along with corresponding convoluted simulation data from three different runs: The normal run with an energy distribution corresponding to the energy distribution from the primary moderator, a simulation run with only thermal energy neutrons, and a simulation run with only thermal energy neutrons, where the simulation incorporates absorption as well. Note that only 1 × 10^{6}, unlike the usual 7.5 × 10^{6}, neutrons were simulated for figure (b) and (c), due to time limitations.

x  Appendix G Extra figures

V A Deuterium gas Vacuum system Pressure sensor − + High voltage power supply Vacuum chamber Inner grid High voltage feedthrough Camera

Figure G.3: Schematic overview of the fusion-based neutron source, which was originally meant to be finished during the project.

z-direction [cm]_{0}_{10}_{20}_{30}_{40}_{50}_{60}_{70} x-direction [cm]_{0}_{50}_{100}_{150}_{200} y-direction [cm]_{0}_{50}_{100}_{150}_{200}

(a) Typical short path. The input energy of this neutron was E = 0.963 MeV, and it scattered 21 times before becoming thermal, and 59 times before exiting the moderator through the top surface.

z-direction [cm]_{0}_{10}_{20}_{30}_{40}_{50}_{60}_{70} x-direction [cm]_{0}_{50}_{100}_{150}_{200} y-direction [cm]_{0}_{50}_{100}_{150}_{200}

(b) Typical long path. The input energy of this neutron was thermal, and it scattered 360 times before exiting the moderator through the top surface.

Figure G.4: Typical neutron paths from the simulation.

H Source codes

All fortran code have been compiled and tested using the gfortran compiler, which is part of the standard GNU compiler bundle, gcc, [18]. The Intel fortran compiler, ifort, should work as well, but have not been tested. Makefiles are shown along with the code in this appendix.

MatLAB code have been run on MatLAB version 7.11.0 (R2010b), [11], but should work fine on other versions as well.

H.1 Simulation

In this appendix the source code of the main simulation will be presented. A detailed flowchart describing the subroutine simulate in the module mainloop can be seen on figure H.1, both with and without the optional mirror subroutine. The concept of the program is explained in the simulation section of the project, but there will be comments on each module in this appendix. The knowledge needed to write this program was obtained from the courses Dat F and Computer Physics at the University of Copenhagen.

The program does not use input at runtime, but needs to be compiled with different options for changes to be made. The options are found in main.f90 where it is possible to select isotropic or elastic scattering, flat moderator or moderator with void – a spherical void or a cylindric void – absorption or no absorption, and the option to use our approximation of the main moderator. It is also possible to enter a test mode by changeing the test option. If this is done, the program will ask for starting parameters of each neutron at runtime, and special cases can be tested.

The size and shape of the moderator for the different options can be changed in moderator.f90, where variables for the different dimensions of the basic moderator block is present. The dimensions and center for a spherical void and cylindrical void are also available in this file. The amount of neutrons output in the main data file is changed in the file definitions.f90 by changing the variable

nmax.

After the wanted changes are made, the program needs to be compiled. Use make clean and make to do this, and then run the program with main.x.

In some places it is clear that the program was changed a lot in the last few days of writing to check different kinds of ideas, but we hope the structure is still understandable.

The cross section data needed for the program was obtained via the web page of NNDC, [1], and is plotted on figure H.2 with the 10^{th} order polynomial approximation (when both the first and second axes are logarithmic) used for the project. It should be noted that this 10^{th} order polynomial is bad for performance, so when the neutron reaches thermal energy, a seperately stored cross section for thermal energy is used for the remainder of the neutron run. First, the makefile (called makefile) is presented. It is used to compile the program by running the command make. In the makefile, module dependencies are stated, but it is not recommended to read the program in this order if the objective is to understand the idea.

1# compiler c h o i c e
2 FC  = g f o r t r a n

3

4# v a r i o u s f l a g s f o r the compiler
5 F90FLAGS = −O0 −g

6

7# r e l a t i o n between ∗. f 9 0 and ∗. o f i l e s
8 . SUFFIXES :
9 . SUFFIXES : . f 9 0 . o
10 . f 9 0 . o :
11  $ (FC) −c $ (F90FLAGS) $<

12

13# d e f i n e the f i l e s needed f o r the program main . x

xii  H.1 Simulation

newneutron posmod interbox outputm output intervoid

inorout concavecheck intervoid distchange newpos2 r old in safe zone? randirec randist newpos

4: out of simple box 3: in void 2: in moderator (not safe)

1: in moderator (safe) yes no intersect in simple intersect out of simple interside 6 (outgoing) interside 1,2,3,4,5 no problem problem

(a)

newneutron posmod interbox mirror output intervoid

inorout concavecheck intervoid distchange newpos2 r old in safe zone? randirec randist newpos

4: out of simple box 3: in void 2: in moderator (not safe)

1: in moderator (safe) yes no intersect in simple intersect out of simple interside 6 (outgoing) interside 1,2,3,4,5 no problem problem

(b)

Figure H.1: The over-all flowchart for the simulation. The version in figure (a) is the normal version of the program, writing out neutrons from the top surface with the output routine and neutrons from the other sides with the outputm routine. The version in figure (b) is the more efficient version of the program, that uses the mirror routine to mirror all neutrons trying to exit the sides back into the moderator.

Appendix H Source codes  xiii

10^{−5} 10^{0} 10^{5} 10_{0} 10_{1} 10_{2} 10_{3} Incident neutron energy E [eV] Scattering cross section σ_{s} [b] 0.025 eV 5.7 MeV NNDC cross section data Fitted curve

Figure H.2: The energy dependent scattering cross section σ_{s} gotten from the NNDC database, [1]. The points are fitted with a curve, which is then used in the simulation to give the correct scattering cross section for given energies. Marked on the plot are both the thermal energy at E = 0.025 eV and the maximal used energy in the simulation, E = 5.7 MeV.

14 main = main . o ranphys . o exprandom . o random . o moderator . o i o . o d e f i n i t i o n s . o math . o
geometry . o mainloop . o phys . o

15

16# c o n t r o l the c o m p i l a t i o n o f the code
17 main . x : $ ( main )
18  $ (FC) $ (F90FLAGS) $ ( main ) −o main . x

19

20# cleanup
21 c l e a n :
22  rm −f ∗. o ∗.mod ∗.M ∗. dat

23

24 c l e a n a l l :
25  rm −f ∗. o ∗. x ∗.mod ∗.M ∗. dat

26

27# dependencis f o r the v a r i o u s f i l e s in the p r o j e c t

28

29 main . o :  random . o i o . o moderator . o exprandom . o d e f i n i t i o n s . o ranphys . o
geometry . o mainloop . o phys . o
30 mainloop . o :  random . o i o . o moderator . o exprandom . o d e f i n i t i o n s . o ranphys . o
geometry . o phys . o
31 ranphys . o :  random . o exprandom . o d e f i n i t i o n s . o phys . o i o . o geometry . o
32 exprandom . o :  d e f i n i t i o n s . o random . o
33 moderator . o :  d e f i n i t i o n s . o math . o
34 geometry . o :  d e f i n i t i o n s . o
35 math . o :  d e f i n i t i o n s . o
36 i o . o :  d e f i n i t i o n s . o math . o exprandom . o phys . o
37 phys . o :  d e f i n i t i o n s . o

The next part is the main file (called main.f90), where the main options are located. These are explained quickly by comments in the program and at the start of this section. This file contains the loop over all simulated neutrons and the code for exiting this loop when the end criteria is met. There is also a simple progress system for simple feedback on the progress of the program while it is running. The file also contains the code which chooses neutrons which should have their path stored, which can be useful for visualizing neutron paths or if there is an error at a certain neutron on every run. In addition, it contains the main part of the test routine, but this is only used when test = 1.

1 Program main

xiv  H.1 Simulation

3 !=!
4 != Main part o f program f o r s i m u l a t i n g neutron moderator =!
5 != m a t e r i a l . There i s a number o f o p t i o n s in t h i s f i l e =!
6 != with information under each e x p l a n a t i o n .  =!
7 != I t should be noted the program works with u n i t s :  =!
8 != l e n g t h in mm, energy in eV  =!
9 != A d d i t i o n a l o p t i o n s can be found in the f i l e s :  =!
10 != d e f i n i t i o n . f90  =!
11 != nmax : number o f neutrons o u t p u t t e d from the top =!
12 !=  mfactor : number o f neutrons o u t p u t t e d from s i d e s =!
13 != ( a maximum, s e t in u n i t s o f nmax ) =!
14 !=  Ehydro : energy o f hydrogen atoms in the moderator =!
15 != moderator . f90  =!
16 !=  Geometry o f the d i f f e r e n t shapes supported  =!
17 !=  can be changed in t h i s f i l e  =!
18 != mainloop . f90 needs to be e d i t e d f o r neutron mirrors =!
19 !=  to be used . This r e q u i r e s knowledge o f i n t e r s i d e , =!
20 != which can be found in i n t e r b o x in math . f90 =!
21 !=  =!
22 != The program has a t e s t mode which can be h e l p f u l l to =!
23 != understand the programs method . To e n a b e l i t , change =!
24 != the v a r i a b e l t e s t to 1 , then compile and run .  =!
25 != At runtime a guide in s t a r t i n g a neutron w i l l be  =!
26 != given , and the path data w i l l be saved .  =!
27 != I f the format seems u n i n t u i t i v e , i o . f90 can be viewd =!
28 != f o r h e l p .  =!
29 !=!

30

31 use random
32 use i o
33 use d e f i n i t i o n s
34 use exprandom
35 use ranphys
36 use moderator
37 use math
38 use geometry
39 use mainloop

40

41 implicit none

42

43 seed1=−2935
44 seed2=−9475
45 seed3=−5475
46 seed4=−4935
47 seed5=−2135
48 seed6=−7696
49 seed7=−3592
50 seed8=−5923
51 seed9=−1030
52 seed10 =−14849

53

54 imax=50000
55 l =0
56 l 2=0
57 pathn=0
58 t e r r o r =0
59 b e r r o r=0
60 merror=0
61 absorped=0
62 E1=5.7E6
63 Etermisk=Ehydro

Appendix H Source codes  xv

64 n=0
65 k=0
66m=0

67 68

69 E=Etermisk
70 c a l l c r o s s s e c t i o n
71 sigma2 =7.515E19∗ c r o s s
72 E=E1
73 c a l l c r o s s s e c t i o n
74 sigma1 =7.515E19∗ c r o s s
75 sigmaabs =0.0025

76

77 !=!
78 != Set t e s t to 0 to s i m u l a t e nmax neutrons in moderator =!
79 != s e t t e s t to 1 to t e s t system , i o at runtime  =!
80 !=!
81  t e s t =0
82 !=!
83 != Set i s o t r o p i c =1 to use i s o t r o p i c s c a t t e r i n g  =!
84 != s e t i s o t r o p i c =0 to use non i s o t r o p i c s c a t t e r i n g  =!
85 !=!
86  i s o t r o p i c =0
87 !=!
88 != Set c y l i n d e r=1 i f you want to t e s t f o r a b i g box  =!
89 != resembling our main moderator .  =!
90 != Neutron s t a r t w i l l be a p o i n t source at the c e n t e r  =!
91 != with random d i r e c t i o n and energy 5.7MeV  =!
92 !=!
93  c y l i n d e r=0
94 !=!
95 != Set c y l i n d e r v=1 i f you want to run the program with =!
96 != a c y l i n d r i c a l void  =!
97 != Set c y l i n d e r v=0 i f you want to run the program with =!
98 != a s p h e r i c a l void .  =!
99 !=!
100  c y l i n d e r v =0
101 !=!
102 != I f f l a t =1 the sphere and c y l i n d e r w i l l not i n t e r s e c t =!
103 != the moderator , making the moderator f l a t .  =!
104 !=!
105  f l a t =0
106 !=!
107 != To t e s t the e f f e c t s o f absorption , a b s o r p t i o n can be =!
108 != enabled , but t h i s w i l l l i m i t the s i m u l a t i o n to one =!
109 != energy l e v e l , chosen to be thermal .  =!
110 != a b s o r p t i o n=1 to e n a b l e  =!
111 !=!
112  a b s o r p t i o n=0

113

114 i f ( t e s t ==0) then
115 !=!
116 != MAIN PROGRAM START =!
117 !=!

118

119 c a l l message
120 c a l l setmoderator

121

122 !=!
123 != MAIN LOOP START =!
124 !=!

xvi  H.1 Simulation

125

126 do

127

128 !=!
129 != PROGRESS SYSTEM =!
130 !=!

131

132  i f ( l=i n t (nmax/20) ) then
133  print ∗,100∗ n/nmax , ’ percent done ’
134  l =0
135  endif

136

137 !=!
138 != NEUTRON PATH SELECTOR =!
139 !=!

140

141  i f ( l 2=i n t (nmax/10) ) then
142  pathc=1
143  pathn=pathn+1
144  c a l l p a t h i n i t ( pathn , k )
145  l 2=0
146  else
147  pathc=0
148  endif
149 !=!
150 != END SYSTEM =!
151 !=!

152

153 i f ( n=nmax) then
154 print ∗, ’ n=nmax ! happend at k= ’ , k
155 exit
156 endif

157

158 k=k+1
159 !=!
160 != SIMULATE NEUTRON =!
161 !=!
162 i n t e r a c t =1
163 t d i s t =0
164 boundary=0
165 e r r o r=0
166 stuck=0
167 f a i l =0

168

169 c a l l newneutron ( seed4 , seed5 , seed3 )
170 c a l l s i m u l a t e

171

172 enddo

173

174 !=!
175 != MAIN LOOP END =!
176 !=!

177

178 c a l l w r i t e t o d i s k
179 c a l l writetodiskm
180 c a l l endmessage

181

182 !=!
183 != MAIN PROGRAM END =!
184 !=!

Appendix H Source codes  xvii

186 else i f ( t e s t ==1) then

187

188 c a l l setmoderator

189

190 do
191  pathc=1
192  pathn=pathn+1
193  c a l l p a t h i n i t ( pathn , pathn )

194

195 c a l l t e s t s t a r t i o

196

197 c a l l c r o s s s e c t i o n

198

199 sigma =7.96E19∗ c r o s s

200

201  c a l l path ( pathn , 0 , r o l d ( : ) )

202

203 c a l l s i m u l a t e t e s t
204 c a l l endmessage
205 c a l l t e s t e n d i o
206 i f ( t e s t d o n e . ne . 1 ) exit
207 end do

208

209 end i f

210

211 end program main

The main loop module (called mainloop.f90) represents the logic of a neutron simulation for the needed geometry. This routine is visualized in the flowchart. The routine needs to be changed when reflectors are used (with the routine mirror), which is done by uncommentating the lines of code containing the mirror subroutine and changing the conditions of the if-sentence to the desired sides.

1 module mainloop

2

3 use random
4 use i o
5 use d e f i n i t i o n s
6 use exprandom
7 use ranphys
8 use moderator
9 use math
10 use geometry

11

12 contains

13

14 !=!
15 != Simulates puts a l l the elements t o g e t h e r to produce a  =!
16 != s i m u l a t i o n . Do loop i s over i n t e r a c t i o n s , imax i s a f a i l s a f e =!
17 != in case o f a neutron g e t t i n g s t u c k  =!
18 != I f a neutron g e t s s t u c k the l a s t ten p o s i t i o n updates w i l l be =!
19 != showed at runtime . I f t h i s i s a problem , i n c r e a s e imax .  =!
20 != This part o f the program i s v i s u a l i z e d with the f l o w c h a r t  =!
21 !=!

22

23 subroutine s i m u l a t e
24 implicit none

25

26 do i =1,imax+1  ! loop over neutron i n t e r a k t i o n e r

27

28 ! c a l l saferun  ! Saferun was used f o r debugging
29 c a l l posmod

xviii  H.1 Simulation

31 i f ( p o s s t a t u s ==1) then  ! Neutron in simple s a f e box

32

33  i f ( r o l d ( 3 ) . l e . safezmax ) then
34  c a l l r a n d i r e c ( seed1 , seed2 )
35  c a l l r a n d i s t
36  c a l l newpos ( i )
37  t d i s t=t d i s t+d i s t
38  i n t e r a c t=i n t e r a c t +1
39  else
40  c a l l concavecheck
41  i f ( ccheck==1) then
42  i f ( c y l i n d e r v ==1) c a l l i n t e r c y l i n d e r
43  i f ( c y l i n d e r v ==0) c a l l i n t e r s p h e r e
44  c a l l d i s t c h a n g e
45  c a l l newpos2 ( i )
46  else
47  c a l l r a n d i r e c ( seed1 , seed2 )
48  c a l l r a n d i s t
49  c a l l newpos ( i )
50  t d i s t=t d i s t+d i s t
51  i n t e r a c t=i n t e r a c t +1
52  endif
53  endif

54

55 else i f ( p o s s t a t u s ==2) then  ! Neutron in simple box care zone
56 c a l l concavecheck ! but not in the sphere
57  i f ( ccheck==1) then
58  i f ( c y l i n d e r v ==1) c a l l i n t e r c y l i n d e r
59  i f ( c y l i n d e r v ==0) c a l l i n t e r s p h e r e
60  c a l l d i s t c h a n g e
61  c a l l newpos2 ( i )
62  else
63  c a l l r a n d i r e c ( seed1 , seed2 )
64  c a l l r a n d i s t
65  c a l l newpos ( i )
66  t d i s t=t d i s t+d i s t
67  i n t e r a c t=i n t e r a c t +1
68  endif

69

70 else i f ( p o s s t a t u s ==3) then  ! Neutron in simple box care zone
71  i f ( c y l i n d e r v ==1) c a l l i n t e r c y l i n d e r ! and in sphere void
72  i f ( c y l i n d e r v ==0) c a l l i n t e r s p h e r e
73  c a l l i n o r o u t
74 i f ( i o r u ==1) then ! ioru=1 means in simple box
75  c a l l d i s t c h a n g e
76  c a l l newpos2 ( i )
77 else ! out o f simple box
78  n=n+1
79  c a l l output ( k , i )
80  l=l +1
81  l 2=l 2+1
82  exit
83  endif

84

85 else i f ( p o s s t a t u s ==4) then  ! Neutron i s not in simple box
86  c a l l i n t e r b o x
87 i f ( i n t e r s i d e ==6) then ! Neutron i s outgoing
88  n=n+1
89  c a l l output ( k , i )
90  l=l +1
91  l 2=l 2+1

Appendix H Source codes  xix

92  exit
93 ! e l s e i f ( i n t e r s i d e ==1) then ! Neutron h i t boundary , turns arround
94 !  c a l l mirror
95 !  c a l l newpos ( i )
96 !  boundary=boundary+1
97 !  i n t e r a c t=i n t e r a c t +1
98  else
99  m=m+1
100  i f (m. l e . mfactor ∗nmax) then
101  c a l l outputm ( k , i )
102  mmax=m
103  exit
104  else
105  exit
106  endif
107  endif

108

109 else i f ( stuck==1) then
110  print ∗, ’ neutron nr ’ , k , ’ got stuck , no data ’
111  exit

112

113 else
114  print ∗, ’ p o s s t a t u s e r r o r ’
115  stop
116 endif

117

118 i f ( i . gt . imax −10) then
119  print ∗, ’ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ’
120  print ∗, ’ r o l d= ’ , r o l d
121 print ∗, ’ r = ’ , r
122  print ∗, ’ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ’
123 endif

124

125 i f ( i=imax . or . stuck==1) then
126  r ( : ) =0
127  r o l d ( : ) =0
128  f a i l =1
129  print ∗, ’ Neutron number ’ , k , ’ f a i l e d ’ , i , stuck
130  c a l l output ( k , i )
131  exit
132 endif

133

134 i f ( a b s o r p t i o n ==1.and . t d i s t . gt . tdistmax ) then
135 absorped=absorped+1
136 exit
137 endif

138

139 enddo

140

141 end subroutine s i m u l a t e

142

143 !=!
144 != s i m u l a t e t e s t i s a copy o f s i m u l a t e with the f i r s t i t e r a t i o n =!
145 != done without random d i s t a n c e so the user can choose the  =!
146 != f i r s t d i s t a n c e to c r e a t e s p e c i f i c troublesome s i t u a t i o n s .  =!
147 !=!

148

149 subroutine s i m u l a t e t e s t
150 implicit none
151 integer : : s t o p i t

xx  H.1 Simulation

153 s t o p i t = 0

154

155 i =1

156

157 i f ( a b s o r p t i o n ==1.and . t d i s t . gt . tdistmax ) then
158 absorped=absorped+1
159 s t o p i t =1
160 endif

161 162

163 ! c a l l saferun
164 c a l l posmod

165

166 i f ( p o s s t a t u s ==1) then  ! Neutron in simple s a f e box

167

168  i f ( r o l d ( 3 ) . l e . safezmax ) then
169  c a l l r a n d i r e c ( seed1 , seed2 )
170  c a l l r a n d i s t
171  c a l l newpos ( i )
172  t d i s t=t d i s t+d i s t
173  i n t e r a c t=i n t e r a c t +1
174  else
175  c a l l concavecheck
176  i f ( ccheck==1) then
177  i f ( c y l i n d e r v ==1) c a l l i n t e r c y l i n d e r
178  i f ( c y l i n d e r v ==0) c a l l i n t e r s p h e r e
179  c a l l d i s t c h a n g e
180  c a l l newpos2 ( i )
181  else
182  c a l l r a n d i r e c ( seed1 , seed2 )
183  c a l l r a n d i s t
184  c a l l newpos ( i )
185  t d i s t=t d i s t+d i s t
186  i n t e r a c t=i n t e r a c t +1
187  endif
188  endif

189

190 else i f ( p o s s t a t u s ==2) then  ! Neutron in simple box care zcyone
191 c a l l concavecheck ! but not in the sphere
192  i f ( ccheck==1) then
193  i f ( c y l i n d e r v ==1) c a l l i n t e r c y l i n d e r
194  i f ( c y l i n d e r v ==0) c a l l i n t e r s p h e r e
195  c a l l d i s t c h a n g e
196  c a l l newpos2 ( i )
197  else
198  c a l l r a n d i r e c ( seed1 , seed2 )
199  c a l l r a n d i s t
200  c a l l newpos ( i )
201  t d i s t=t d i s t+d i s t
202  i n t e r a c t=i n t e r a c t +1
203  endif

204

205 else i f ( p o s s t a t u s ==3) then  ! Neutron in simple box care zone
206  i f ( c y l i n d e r v ==1) c a l l i n t e r c y l i n d e r ! and in sphere void
207  i f ( c y l i n d e r v ==0) c a l l i n t e r s p h e r e
208  c a l l i n o r o u t
209 i f ( i o r u ==1) then ! ioru=1 means in simple box
210  c a l l d i s t c h a n g e
211  c a l l newpos2 ( i )
212 else ! out o f simple box
213  n=n+1

Appendix H Source codes  xxi

214  c a l l output ( k , i )
215  l=l +1
216  l 2=l 2+1
217  s t o p i t =1
218  endif

219

220 else i f ( p o s s t a t u s ==4) then  ! Neutron i s not in simple box
221  c a l l i n t e r b o x
222 i f ( i n t e r s i d e ==6) then ! Neutron i s outgoing
223  n=n+1
224  c a l l output ( k , i )
225  l=l +1
226  l 2=l 2+1
227  s t o p i t =1
228 ! e l s e i f ( i n t e r s i d e ==1) then ! Neutron h i t boundary , turn arround
229 !  c a l l mirror
230 !  c a l l newpos ( i )
231 !  boundary=boundary+1
232 !  i n t e r a c t=i n t e r a c t +1
233  else
234  m=m+1
235  i f (m. l e . mfactor ∗nmax) then
236  c a l l outputm ( k , i )
237  mmax=m
238  s t o p i t =1
239  else
240  s t o p i t =1
241  endif
242  endif

243

244 else i f ( stuck==1) then
245  print ∗, ’ neutron nr ’ , k , ’ got stuck , no data ’
246  s t o p i t =1

247

248 else
249  print ∗, ’ p o s s t a t u s e r r o r ’
250  stop
251 endif

252

253 i f ( i . gt . imax −10) then
254  print ∗, ’ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ’
255  print ∗, ’ r o l d= ’ , r o l d
256 print ∗, ’ r = ’ , r
257  print ∗, ’ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ’
258 endif

259

260 i f ( i=imax . or . stuck==1) then
261  r ( : ) =0
262  r o l d ( : ) =0
263  f a i l =1
264  print ∗, ’ Neutron number ’ , k , ’ f a i l e d ’ , i , stuck
265  c a l l output ( k , i )
266  s t o p i t =1
267 endif

268

269 do i =2,imax+1  ! loop over neutron i n t e r a k t i o n e r

270

271 i f ( a b s o r p t i o n ==1.and . t d i s t . gt . tdistmax ) then
272 absorped=absorped+1
273 exit
274 endif

xxii  H.1 Simulation

275

276 ! p r i n t ∗, ’ p o s i t i o n  ’ , r ( : )
277 ! p r i n t ∗, ’ o l d p o s i t i o n ’ , r o l d ( : )

278

279 ! c a l l saferun
280 c a l l posmod

281

282 i f ( p o s s t a t u s ==1) then  ! Neutron in simple s a f e box

283

284  i f ( r o l d ( 3 ) . l e . safezmax ) then
285  c a l l r a n d i r e c ( seed1 , seed2 )
286  c a l l r a n d i s t
287  c a l l newpos ( i )
288  t d i s t=t d i s t+d i s t
289  i n t e r a c t=i n t e r a c t +1
290  else
291  c a l l concavecheck
292  i f ( ccheck==1) then
293  i f ( c y l i n d e r v ==1) c a l l i n t e r c y l i n d e r
294  i f ( c y l i n d e r v ==0) c a l l i n t e r s p h e r e
295  c a l l d i s t c h a n g e
296  c a l l newpos2 ( i )
297  else
298  c a l l r a n d i r e c ( seed1 , seed2 )
299  c a l l r a n d i s t
300  c a l l newpos ( i )
301  t d i s t=t d i s t+d i s t
302  i n t e r a c t=i n t e r a c t +1
303  endif
304  endif

305

306 else i f ( p o s s t a t u s ==2) then  ! Neutron in simple box care zcyone
307 c a l l concavecheck ! but not in the sphere
308  i f ( ccheck==1) then
309  i f ( c y l i n d e r v ==1) c a l l i n t e r c y l i n d e r
310  i f ( c y l i n d e r v ==0) c a l l i n t e r s p h e r e
311  c a l l d i s t c h a n g e
312  c a l l newpos2 ( i )
313  else
314  c a l l r a n d i r e c ( seed1 , seed2 )
315  c a l l r a n d i s t
316  c a l l newpos ( i )
317  t d i s t=t d i s t+d i s t
318  i n t e r a c t=i n t e r a c t +1
319  endif

320

321 else i f ( p o s s t a t u s ==3) then  ! Neutron in simple box care zone
322  i f ( c y l i n d e r v ==1) c a l l i n t e r c y l i n d e r ! and in sphere void
323  i f ( c y l i n d e r v ==0) c a l l i n t e r s p h e r e
324  c a l l i n o r o u t
325 i f ( i o r u ==1) then ! ioru=1 means in simple box
326  c a l l d i s t c h a n g e
327  c a l l newpos2 ( i )
328 else ! out o f simple box
329  n=n+1
330  c a l l output ( k , i )
331  l=l +1
332  l 2=l 2+1
333  exit
334  endif

Appendix H Source codes  xxiii

336 else i f ( p o s s t a t u s ==4) then  ! Neutron i s not in simple box
337  c a l l i n t e r b o x
338 i f ( i n t e r s i d e ==6) then ! Neutron i s outgoing
339  n=n+1
340  c a l l output ( k , i )
341  l=l +1
342  l 2=l 2+1
343  exit
344 ! e l s e i f ( i n t e r s i d e ==1) then ! Neutron h i t boundary , turn arround
345 !  c a l l mirror
346 !  c a l l newpos ( i )
347 !  boundary=boundary+1
348 !  i n t e r a c t=i n t e r a c t +1
349  else
350  m=m+1
351  i f (m. l e . mfactor ∗nmax) then
352  c a l l outputm ( k , i )
353  mmax=m
354  exit
355  else
356  exit
357  endif
358  endif

359

360 else i f ( stuck==1) then
361  print ∗, ’ neutron nr ’ , k , ’ got stuck , no data ’
362  exit

363

364 else
365  print ∗, ’ p o s s t a t u s e r r o r ’
366  stop
367 endif

368

369 i f ( i . gt . imax −10) then
370  print ∗, ’ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ’
371  print ∗, ’ r o l d= ’ , r o l d
372 print ∗, ’ r = ’ , r
373  print ∗, ’ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ’
374 endif

375

376 i f ( i=imax . or . stuck==1) then
377  r ( : ) =0
378  r o l d ( : ) =0
379  f a i l =1
380  print ∗, ’ Neutron number ’ , k , ’ f a i l e d ’ , i , stuck
381  c a l l output ( k , i )
382  exit
383 endif

384

385 enddo

386

387 end subroutine s i m u l a t e t e s t

388

389 end module mainloop

The definitions module (called definitions.f90) contains the types of all variables, and a definition of the number of neutrons wanted in the datafile: nmax.

1 module d e f i n i t i o n s

2

3 !=!
4 != In t h i s module the type o f needed v a r i a b e l s i s d e f i n e d .  =!

xxiv  H.1 Simulation

5 != For performance reasons the wanted number o f neutrons in  =!
6 != the primary d a t a f i l e i s chosen here , o t h e r w i s e a l l o c a t a b l e  =!
7 != arrays would be needed which w i l l slow down performance  =!
8 !=!
9 implicit none
10 integer , parameter  : : nmax=500000 , mfactor=1
11 real , parameter  : : Ehydro =0.025 , pi =3.14159
12 real , dimension (nmax , 1 4 )  : : r e s u l t s
13 real , dimension ( mfactor ∗nmax , 1 4 ) : : r e s u l t s m
14 real , dimension ( 3 )  : : r , r o l d , r d i r e c , r 0 s p h e r e , r i n t e r b , r i n t e r s 1 , &
15  r i n t e r s 2 , r temp , r d i r e c o l d , ccentrum , r i n t e r c 1 , &
16  r i n t e r c 2
17 real  : : sigma , sigma1 , sigma2 , s c a t t e r i n g a n g l e , E, E1 , &
18  Etermisk , tdistmax , d i s t , xmax , ymax , zmax , r s p h e r e , &
19  t d i s t , u1 , u2 , u3 , u4 , c r o s s , sigmaabs , czmax , czmin , &
20  r c y l i n d e r , h c y l i n d e r , safezmax , impact angle
21 integer  : : posstatus , i n t e r s i d e , i n t e r a c t , boundary , ioru , &
22  ccheck , e r r o r , stuck , f a i l , imax , i s o t r o p i c , pathc , &
23  pathn , t e r r o r , berror , merror , mserror , k , i , n , l , l2 ,m, &
24  mmax, seed1 , seed2 , seed3 , seed4 , seed5 , seed6 , seed7 , &
25  t e s t , testdone , t e s t d i s t , seed8 , seed9 , c y l i n d e r , &
26  c y l i n d e r v , f l a t , absorption , absorped , seed10
27 character ( 4 0 )  : : name

28

29 end module d e f i n i t i o n s

In the moderator module (called moderator.f90) the moderator geometry is defined in the subroutine setmoderator. The file also contains the posmod routine, which determines what part of space a neutron is in. The concavecheck routine checks if the neutron intersected the void in the last interation by checking 3 points on the line between these points. It does not check endpoints, since the routine would not be called if any of these were in the void. The last subroutine in the file is called saferun, and was only used for debugging, not for any runs which delivered data to the project.

1 module moderator

2

3 use d e f i n i t i o n s
4 use math

5

6 contains

7

8 !=!
9 != setmoderator d e f i n e the p h y s i c a l shape o f the moderator  =!
10 != The moderator i s box shaped and s t a r t s in (0 ,0 ,0)  =!
11 != and extends to (xmax , ymax , zmax ) which are s e t here .  =!
12 != A sphere deformation may be used at the output end :  =!
13 != d e s c r i b e d by a c e n t e r r 0 s p h e r e and r a d i u s r s p h e r e  =!
14 != This sphere should g e n e r a l y c e n t e r with z>zmax  =!
15 != The sphere d e s c r i b e s a region without moderator  =!
16 != The program works in u n i t s o f mm ( m i l i m e t e r s )  =!
17 != I f c y l i n d e r=0 the moderator resembels a small b l o c k .  =!
18 != I f c y l i n d e r=1 the moderator approximates the main moderator =!
19 != ( which does not support v o i d s ) =!
20 != I f c y l i n d e r v=1 the small moderator has a c y l i n d e r void  =!
21 !=  =!
22 != Other v o i d s can be added but i t w i l l need a new i n t e r v o i d  =!
23 != r o u t i n e f o r t h a t geometry . The geometry i s r e q u i r e d to be  =!
24 != concave , o t h e r w i s e the program w i l l not t a k e care o f  =!
25 != c e r t a i n c l a s s e s o f s p e c i a l cases .  =!
26 !=!

27

28 subroutine setmoderator

Appendix H Source codes  xxv

29 implicit none

30

31 i f ( c y l i n d e r ==1) then  ! Main moderator
32 xmax=410
33 ymax=410
34 zmax=310
35 else

36

37 xmax=220.
38 ymax=220.
39 zmax=68.

40

41 i f ( f l a t ==1) then  ! F l a t moderator
42  r 0 s p h e r e ( 1 )=xmax / 2 .
43  r 0 s p h e r e ( 2 )=ymax / 2 .
44  r 0 s p h e r e ( 3 )=zmax+100
45  r s p h e r e=1
46  safezmax=r 0 s p h e r e ( 3 )−r s p h e r e

47

48  r c y l i n d e r =1
49  h c y l i n d e r=1
50  ccentrum ( 1 )=xmax ∗ 0 . 5
51  ccentrum ( 2 )=ymax ∗ 0 . 5
52  ccentrum ( 3 )=zmax+100

53

54  czmax=ccentrum ( 3 ) +0.5∗ h c y l i n d e r
55  czmin=ccentrum ( 3 ) −0.5∗ h c y l i n d e r
56  safezmax=ccentrum ( 3 ) −0.5∗ h c y l i n d e r

57

58 else

59

60 i f ( c y l i n d e r v ==0) then  ! Sphere void
61  r 0 s p h e r e ( 1 )=xmax/2.+1.5
62  r 0 s p h e r e ( 2 )=ymax/2. −0.85
63  r 0 s p h e r e ( 3 )=zmax+25
64  r s p h e r e=s q r t (25∗∗2+50.105∗∗2)
65  safezmax=r 0 s p h e r e ( 3 )−r s p h e r e

66

67  ccentrum ( : ) =0
68  ccentrum ( 3 )=zmax+100
69  r c y l i n d e r =1
70  h c y l i n d e r=1

71

72 else i f ( c y l i n d e r v ==1) then  ! Cylinder void

73

74  r c y l i n d e r =10
75  h c y l i n d e r =40
76  ccentrum ( 1 )=xmax ∗ 0 . 5
77  ccentrum ( 2 )=ymax ∗ 0 . 5
78  ccentrum ( 3 )=zmax−0.5∗ h c y l i n d e r

79

80  czmax=ccentrum ( 3 ) +0.5∗ h c y l i n d e r
81  czmin=ccentrum ( 3 ) −0.5∗ h c y l i n d e r
82  safezmax=ccentrum ( 3 ) −0.5∗ h c y l i n d e r

83

84  r 0 s p h e r e ( : ) =0
85  r 0 s p h e r e ( 3 )=zmax+100
86  r s p h e r e=1

87

88 endif
89 endif

xxvi  H.1 Simulation

90 endif

91

92 end subroutine setmoderator

93

94 !=!
95 != posmod checks i f the p o s i t i o n i s in the moderator .  =!
96 != o u t p u t s i n t e g e r p o s s t a t u s  =!
97 != p o s s t a t u s = 1 i f r i s in s a f e simple box  =!
98 != p o s s t a t u s = 2 i f r i s in care zone and out o f sphere  =!
99 != p o s s t a t u s = 3 i f r i s in care zone and in void  =!
100 != p o s s t a t u s = 4 i f r i s out o f simple box  =!
101 !=  =!
102 != The simple box i s d e f i n e d as the box without the void .  =!
103 !=  =!
104 != This r o u t i n e has been checked with sample points , and no  =!
105 != e r r o r s were found =!
106 !=!

107

108 subroutine posmod
109 implicit none

110

111 i f ( r ( 1 ) . l e . xmax . and . r ( 2 ) . l e . ymax . and . r ( 3 ) . l e . zmax &
112  . and . r ( 1 ) . ge . 0 . . and . r ( 2 ) . ge . 0 . . and . r ( 3 ) . ge . 0 . ) then

113

114  i f ( r ( 3 ) . gt . safezmax ) then
115  i f ( c y l i n d e r v ==0) then
116  i f ( d i s t a n c e ( r , r 0 s p h e r e ) . l t . r s p h e r e ) then
117  p o s s t a t u s=3
118  else
119  p o s s t a t u s=2
120  endif
121  else i f ( c y l i n d e r v ==1) then
122  i f ( ( r ( 1 )−ccentrum ( 1 ) ) ∗∗2+( r ( 2 )−ccentrum ( 2 ) ) ∗ ∗ 2 . l t . r c y l i n d e r ∗∗2) then
123  p o s s t a t u s=3
124  else
125  p o s s t a t u s=2
126  endif
127  endif
128  else
129  p o s s t a t u s=1
130  endif

131

132 else
133  p o s s t a t u s=4

134

135 endif

136

137 end subroutine posmod

138

139 !=!
140 != concavecheck p i c k s t h r e e p o i n t s between r and r o l d , and  =!
141 != checks i f any o f t h o s e are in the sphere void .  =!
142 != Output : ccheck=1 i f one or more p o i n t s i s in the sphere  =!
143 != Output : ccheck=0 i f no p o i n t s i s in the sphere  =!
144 !=!

145

146 subroutine concavecheck
147 implicit none
148 real , dimension ( 3 )  : : point
149 real  : : sep
150 integer  : : j

Appendix H Source codes  xxvii

151

152 ccheck=0

153

154 sep=d i s t a n c e ( r ( : ) , r o l d ( : ) )

155

156 i f ( c y l i n d e r v ==0) then
157 i f ( d i s t a n c e ( r temp ( : ) , r 0 s p h e r e ( : ) ) . gt . r s p h e r e ) then
158  do j =1,3
159  point ( : )=r o l d ( : ) +0.25∗ real ( j ) ∗ sep ∗ r d i r e c ( : )
160  i f ( d i s t a n c e ( point , r 0 s p h e r e ) . l t . r s p h e r e ) then
161  ccheck=1
162  endif
163  enddo
164 endif
165 else i f ( c y l i n d e r v ==1) then
166 i f ( ( r temp ( 1 )−ccentrum ( 1 ) ) ∗∗2+( r temp ( 2 )−ccentrum ( 2 ) ) ∗ ∗ 2 . l t . r c y l i n d e r ∗∗2 &
167  . and . r temp ( 3 ) . l t . czmax . and . r temp ( 3 ) . gt . czmin ) then
168  ccheck=0
169 else
170  do j =1,3
171  point ( : )=r o l d ( : ) +0.25∗ real ( j ) ∗ sep ∗ r d i r e c ( : )
172  i f ( ( point ( 1 )−ccentrum ( 1 ) ) ∗∗2+( point ( 2 )−ccentrum ( 2 ) ) ∗ ∗ 2 . l t . r c y l i n d e r ∗∗2 &
173  . and . point ( 3 ) . gt . czmin . and . point ( 3 ) . l t . czmax ) then
174  ccheck=1
175  endif
176  enddo
177 endif
178 endif

179

180 end subroutine concavecheck

181

182 !=!
183 != SAFERUN ONLY USED FOR DEBUGGING  =!
184 != saferun a v o i d s l o o p s at the c o s t o f p o s s i b l e s t a t i s t i c a l  =!
185 != e r r o r . I f both r and r o l d has s u s p i c i o u s coordinates ,  =!
186 != the neutron w i l l be moved q u i t e f a r i n t o the moderator  =!
187 != to aviod corner l o o p s  =!
188 != Saferun should be r e w r i t t e n to do much more s u b t l e changes  =!
189 != i f i t i s wanted f o r very l a r g e d a t a s e t s . I t i s not used  =!
190 != anymore s i n c e the program does not return e r r o r s .  =!
191 != We s u g g e s t j u s t dropping neutrons with e r r o r s i f the program =!
192 != i s used f o r very l a r g e d a t a s e t s and e r r o r s not found by us =!
193 != i s p r e s e n t because o f very low p r o b a b i l i t i e s .  =!
194 !=!

195

196 subroutine s a f e r u n

197

198 ! i f ( r o l d (1) . g t . xmax −0.001. or . r o l d (2) . g t . ymax −0.001. or . r o l d (3) . g t . zmax −0.001 &
199 !  . or . r o l d (1) . l t . 0 . 0 0 1 . or . r o l d (2) . l t . 0 . 0 0 1 . or . r o l d (3) . l t . 0 . 0 0 1 ) then

200

201 i f ( r o l d ( 1 ) . gt . xmax . or . r o l d ( 2 ) . gt . ymax . or . r o l d ( 3 ) . gt . zmax &
202  . or . r o l d ( 1 ) . l t . 0 . . or . r o l d ( 2 ) . l t . 0 . . or . r o l d ( 3 ) . l t . 0 . ) then

203

204 i f ( r ( 1 ) . gt . xmax−0.001. or . r ( 2 ) . gt . ymax−0.001. or . r ( 3 ) . gt . zmax−0.001 &
205  . or . r ( 1 ) . l t . 0 . 0 0 1 . or . r ( 2 ) . l t . 0 . 0 0 1 . or . r ( 3 ) . l t . 0 . 0 0 1 ) then

206

207  i f ( r ( 1 ) . ge . xmax−0.0001) r ( 1 )=xmax−0.001
208 i f ( r ( 1 ) . l e . 0 . 0 0 0 1 ) r ( 1 ) =0.001
209  i f ( r ( 2 ) . ge . ymax−0.0001) r ( 2 )=ymax−0.001
210 i f ( r ( 2 ) . l e . 0 . 0 0 0 1 ) r ( 2 ) =0.001
211  i f ( r ( 3 ) . ge . zmax −0.0001) r ( 3 )=zmax−0.001

212  i f ( r ( 3 ) . l e . 0 . 0 0 0 1 )  r ( 3 ) =0.001

213

214  i f ( e r r o r . gt . 3 0 0 ) stuck=1

215

216  e r r o r=e r r o r+1
217  t e r r o r=t e r r o r +1
218 end i f

219

220 end i f

221

222 end subroutine s a f e r u n

223

224 end module moderator

The ranphys module (called ranphys.f90) contains mainly physics which are influenced by some random parameter. First up is randirec, which was described in the project. It can be used to find an isotropic (laboratory system) direction, or it can calculate the scattering angle from the impact angle, which is found by a random impact parameter. The final rotational freedom is removed with another random varabld, which is used when finding the new direction vector.

randist changes the energy if it is more than one percent larger than thermal, otherwise it will use a stored value for the cross section to improve performance. The distance is found by the exponentially distributed random number generator expdev which is in the file exprandom.f90.

The last subroutine in the file is called newneutron, and it sets the starting point and direction for the next neutron. The amount of thermal neutrons can easily be changed. If absorption is used, a starting energy of thermal will always be used, since the approach used will not yield correct results for any other energy.

The subroutine mirror represents the possiblity of reflectors. The routine uses data from a box intersection routine to select the right plane to use as a mirror.

1 module ranphys

2

3 use d e f i n i t i o n s
4 use random
5 use exprandom
6 use phys
7 use i o
8 use math
9 use geometry

10

11 contains

12

13 !=!
14 != r a n d i r e c chooses a random d i r e c t i o n f o r the neutron to go  =!
15 != a f t e r a i n t e r a c t i o n with the moderator . Seperate f o r  =!
16 != i s o t r o p i c and e l a s t i c s c a t t e r i n g .  =!
17 !=!

18

19 subroutine r a n d i r e c ( a1 , a2 )  ! input two n e g a t i v e seeds
20 implicit none
21 real  : : theta , phi ,RL
22 real , dimension ( 2 )  : : r a n c i r c t e m p
23 real , dimension ( 3 )  : : m, u , v , a , x
24 integer  : : a1 , a2

25

26 r d i r e c o l d=r d i r e c

27

28 i f ( i s o t r o p i c ==1) then
29 theta =2.∗3.14159∗ ran1theta ( a1 )
30 phi =acos (1. −2.∗ ran1phi ( a2 ) )

Appendix H Source codes  xxix

31

32 r d i r e c ( 1 )=cos ( theta ) ∗ s i n ( phi )
33 r d i r e c ( 2 )=s i n ( theta ) ∗ s i n ( phi )
34 r d i r e c ( 3 )=cos ( phi )
35 else

36

37 r a n c i r c t e m p=r a n c i r c ( seed8 , seed9 )

38

39 impact angle=pi ∗0.5 − a s i n ( r a n c i r c t e m p ( 1 ) )

40

41 s c a t t e r i n g a n g l e=abs ( pi−abs ( atan ( −s q r t (E/Ehydro ) ∗1/ tan ( impact angle ) ) ) &
42  −atan (1/ tan ( impact angle ) ) )

43

44m( : )=r d i r e c o l d ( : ) ∗ cos ( s c a t t e r i n g a n g l e )

45

46 a ( 1 ) =301
47 a ( 2 ) =4910
48 a ( 3 ) =−138

49

50 i f ( l e n g t h ( c r o s s p ( a ,m) )==0 ) then
51 a ( 1 ) =103
52 a ( 2 ) =−459
53 a ( 3 ) =11
54 endif

55

56 u ( : )=c r o s s p (m, a ) / l e n g t h ( c r o s s p (m, a ) )

57

58 v ( : )=c r o s s p (m, u ) / l e n g t h ( c r o s s p (m, u ) )

59

60 RL=s i n ( s c a t t e r i n g a n g l e )

61

62 x ( : )=m+u ( : ) ∗RL∗ cos ( r a n c i r c t e m p ( 2 ) )+v ( : ) ∗RL∗ s i n ( r a n c i r c t e m p ( 2 ) )

63

64 r d i r e c ( : )=x ( : ) / l e n g t h ( x )

65

66 endif

67

68 end subroutine r a n d i r e c

69

70 !=!
71 != r a n d i s t chooses a random d i s t a n c e f o r the neutron to t r a v e l =!
72 != b e f o r e next i n t e r a c t i o n with the moderator  =!
73 !=!

74

75 subroutine r a n d i s t  ! input seed ( a1 ) and sigma (L)
76 implicit none

77 78

79 i f (E. gt . Etermisk ∗ 1 . 0 1 ) then

80

81  i f ( i s o t r o p i c ==1) then
82  E=(E−Etermisk ) ∗0.5+ Etermisk
83  else
84  E=E∗ cos ( impact angle ) ∗∗2+Ehydro∗ s i n ( impact angle ) ∗∗2
85  endif

86

87 c a l l c r o s s s e c t i o n
88 i f ( c y l i n d e r ==1) then
89 sigma =7.947E19∗ c r o s s
90 else
91 sigma =7.515E19∗ c r o s s

xxx  H.1 Simulation

92 endif

93 94

95 d i s t=expdev ( seed3 , sigma )

96

97 else

98

99 E=Etermisk
100 d i s t=expdev ( seed3 , sigma2 )

101

102 endif

103

104 end subroutine r a n d i s t

105

106 !=!
107 != Newneutron s e t s a s t a r t i n g p o i n t and a s t a r t i n g depth in the =!
108 != moderator . I f the f i r s t p o i n t i s above the output surface , =!
109 != the s i m u l a t e r o u t i n e w i l l handel i t c o r r e c t l y .  =!
110 != Other forms o f s t a r t i n g c o n d i t i o n s can be entered here .  =!
111 != The s i m u l a t i o n c u r r e n t l y uses i s o t r o p i c s t a r t i n g at the  =!
112 != middel i f the main moderator i s simulated .  =!
113 != The s i m u l a t i o n uses uniformly d i s t r i b u t e d s t a r t i n g p o i n t s on =!
114 != the z=0 plane . A l l d i r e c t i o n s i s in the z d i r e c t i o n .  =!
115 !=!

116

117 subroutine newneutron ( a4 , a5 , a6 )  ! input seed ( a4 , a5 )
118 implicit none
119 integer : : a4 , a5 , a6
120 real  : : theta , phi ,RL
121 real , dimension ( 2 )  : : r a n c i r c t e m p
122 real , dimension ( 3 )  : : m, u , v , a , x
123 integer  : : a1 , a2

124

125 r ( : ) =0
126 r o l d ( : ) =0

127

128 i f ( c y l i n d e r ==0) then

129

130 i f ( a b s o r p t i o n==0) then
131 i f ( ran1E1 ( seed6 ) . l t . 0 . 6 1 5 ) then  ! 61.5 percent thermal
132  E=Etermisk
133 else
134 E=E1∗ l i n d e v ( seed7 ) / s q r t ( 2 . ) ! r e s t i s l i n e a r d i s t r i b u t e d .
135 endif

136

137 c a l l c r o s s s e c t i o n
138 sigma =7.515E19∗ c r o s s

139

140 r ( 1 ) =0.98∗xmax∗ ran1x ( a4 ) +0.01∗xmax
141 r o l d ( 1 )=r ( 1 )
142 r ( 2 ) =0.98∗ymax∗ ran1y ( a5 ) +0.01∗ymax
143 r o l d ( 2 )=r ( 2 )
144 r ( 3 )=expdev ( a6 , sigma ) +0.001
145 d i s t=r ( 3 )
146 r o l d ( 3 ) =0.01
147 t d i s t=r ( 3 )
148 r d i r e c ( 1 )=0
149 r d i r e c ( 2 )=0
150 r d i r e c ( 3 )=1
151 else

Appendix H Source codes  xxxi

153  E=Etermisk
154  tdistmax=expabs ( seed10 , sigmaabs )

155

156 c a l l c r o s s s e c t i o n
157 sigma =7.515E19∗ c r o s s

158

159 r ( 1 ) =0.98∗xmax∗ ran1x ( a4 ) +0.01∗xmax
160 r o l d ( 1 )=r ( 1 )
161 r ( 2 ) =0.98∗ymax∗ ran1y ( a5 ) +0.01∗ymax
162 r o l d ( 2 )=r ( 2 )
163 r ( 3 )=expdev ( a6 , sigma ) +0.001
164 d i s t=r ( 3 )
165 r o l d ( 3 ) =0.01
166 t d i s t=r ( 3 )
167 r d i r e c ( 1 )=0
168 r d i r e c ( 2 )=0
169 r d i r e c ( 3 )=1
170 endif

171

172 else

173

174 E=E1

175

176 r ( 1 )=xmax ∗ 0 . 5
177 r o l d ( 1 )=r ( 1 ) +0.001
178 r ( 2 )=ymax ∗ 0 . 5
179 r o l d ( 2 )=r ( 2 ) +0.001
180 r ( 3 )=zmax ∗ 0 . 5
181 d i s t =0
182 r o l d ( 3 )=r ( 3 ) +0.001
183 t d i s t =0
184 r d i r e c ( 1 )=0
185 r d i r e c ( 2 )=0
186 r d i r e c ( 3 )=1

187

188 theta =2.∗3.14159∗ ran1theta ( a1 )
189 phi =acos (1. −2.∗ ran1phi ( a2 ) )

190

191 r d i r e c ( 1 )=cos ( theta ) ∗ s i n ( phi )
192 r d i r e c ( 2 )=s i n ( theta ) ∗ s i n ( phi )
193 r d i r e c ( 3 )=cos ( phi )

194

195 c a l l c r o s s s e c t i o n
196 sigma =7.947E19∗ c r o s s
197 d i s t=expdev ( seed3 , sigma )
198 t d i s t=t d i s t+d i s t
199 i n t e r a c t=i n t e r a c t +1

200 201

202 c a l l newpos ( 0 )

203

204 endif

205

206 end subroutine newneutron

207

208 end module ranphys

The geometry module (called geometry.f90) contains subroutines where the position, last position or distance is changed. newpos and newpos2 updates the current position and temporary position, but only the first updates the old position. distchange adds the distance a neutron have travelled in the void so it will penetrate the moderator to the correct depth in the next iteration. inorout

xxxii  H.1 Simulation

checks solutions for intersections with the void to see if the neutron has a chance to continue in the moderator.

1 module geometry

2

3 use d e f i n i t i o n s
4 use math
5 use i o

6

7 contains

8

9 !=!
10 != newpos s e t s the new p o s i t i o n , and s t o r e s the o l d as r o l d  =!
11 != r temp i s important when a neutron have had a d i s t c h a n g e  =!
12 != because o f a void , and i s concavechecked a f t e r w a r d s  =!
13 !=!

14

15 subroutine newpos ( counter )
16 implicit none
17 integer : : counter

18

19 r o l d ( : )=r ( : )
20 r temp ( : )=r ( : )
21 r ( : )=r o l d ( : )+d i s t ∗ r d i r e c ( : )
22 i f ( pathc==1) c a l l path ( pathn , counter , r o l d ( : ) )

23

24 end subroutine newpos

25

26 !=!
27 != newpos2 i s l i k e newpos1 , but i t doesn ’ t change r o l d ( : ) ,  =!
28 != t h i s i s u s e f u l l when c o r r e c t i n g path l e n g t h s  =!
29 != r temp i s important when a neutron have had a d i s t c h a n g e  =!
30 != because o f a void , and i s concavechecked a f t e r w a r d s  =!
31 !=!

32

33 subroutine newpos2 ( counter )
34 implicit none
35 integer : : counter

36

37 i f ( pathc==1) c a l l path ( pathn , counter , r ( : ) )
38 r temp ( : )=r ( : )
39 r ( : )=r o l d ( : )+d i s t ∗ r d i r e c ( : )

40

41 end subroutine newpos2

42

43 !=!
44 != d i s t c h a n g e i s a simple t o o l to change the d i s t a n c e the  =!
45 !=  the neutron needs to t r a v e l based on i n t e r s e c t i o n s with  =!
46 !=  the void  =!
47 !=!

48

49 subroutine d i s t c h a n g e
50 implicit none

51

52 i f ( c y l i n d e r v ==0) then
53 d i s t=d i s t+d i s t a n c e ( r i n t e r s 1 , r i n t e r s 2 )
54 else i f ( c y l i n d e r v ==1) then
55 d i s t=d i s t+d i s t a n c e ( r i n t e r c 1 , r i n t e r c 2 )
56 endif

57

58 end subroutine d i s t c h a n g e

Appendix H Source codes  xxxiii

60 !=!
61 != i n o r o u t i s a simple t o o l to check i f i n t e r s e c t i o n s with  =!
62 != the void i s in the simple box or not .  =!
63 != Output : ioru=1 : Both i n t e r s e c t i o n s in simple box  =!
64 != Output : ioru=0 : One or more o f the i n t e r s e c t i o n not in box =!
65 !=!

66

67 subroutine i n o r o u t
68 implicit none

69

70 i f ( c y l i n d e r v ==0) then
71 i f ( r i n t e r s 1 ( 3 ) . l e . zmax . and . r i n t e r s 2 ( 3 ) . l e . zmax ) then
72  i o r u=1
73 else
74  i o r u=0
75 endif
76 else
77 i f ( r i n t e r c 1 ( 3 ) . l e . zmax . and . r i n t e r c 2 ( 3 ) . l e . zmax ) then
78  i o r u=1
79 else
80  i o r u=0
81 endif
82 endif

83

84 end subroutine i n o r o u t

85 86

87 !=!
88 != mirror mirrors the d i r e c t i o n o f the neutron a f t e r h i t t i n g a =!
89 !=  s i m u l a t i o n boundary , and c a l c u l a t e s the remaining d i s t a n c e =!
90 != Has been checked with simple s i t u a t i o n s  =!
91 != There have been some problems with t h i s code s i n c e the  =!
92 != i n t e r s e c t i o n s do not have s u f f i e c i e n t accuracy .  =!
93 != Hence i t have been w r i t t e n in a way where t h i s i s not  =!
94 != as c r i t i c a l . r i s s e t so r o l d w i l l be at the s i d e .  =!
95 != The program assumes r o l d i s i n s i d e the simple box at a l l  =!
96 != times , i f t h i s i s not t r u e i t w i l l f a i l and i t w i l l t e l l so =!
97 != at runtime .  =!
98 !=!

99

100 subroutine mirror
101 implicit none

102

103 i f ( i n t e r s i d e ==1) then
104 i f ( d i s t −d i s t a n c e ( r o l d , r i n t e r b ) . ge . −0.00001) then
105 d i s t=d i s t −d i s t a n c e ( r o l d , r i n t e r b )
106 r d i r e c ( 3 )=−r d i r e c ( 3 )
107  r ( 1 )=r i n t e r b ( 1 )
108  r ( 2 )=r i n t e r b ( 2 )
109  r ( 3 ) =0.0001
110 i f ( d i s t . l t . 0 ) mserror=mserror+1
111 else
112 print ∗, ’ mirror e r r o r : d i s t n e g a t i v e ’
113 stuck=1
114 merror=merror+1
115 endif
116 endif

117

118 i f ( i n t e r s i d e ==2) then
119 i f ( d i s t −d i s t a n c e ( r o l d , r i n t e r b ) . ge . −0.00001) then
120 d i s t=d i s t −d i s t a n c e ( r o l d , r i n t e r b )

xxxiv  H.1 Simulation

121 r d i r e c ( 2 )=−r d i r e c ( 2 )
122  r ( 1 )=r i n t e r b ( 1 )
123  r ( 2 ) =0.0001
124  r ( 3 )=r i n t e r b ( 3 )
125 i f ( d i s t . l t . 0 ) mserror=mserror+1
126 else
127 print ∗, ’ mirror e r r o r : d i s t n e g a t i v e ’
128 merror=merror+1
129 stuck=1
130 endif
131 endif

132

133 i f ( i n t e r s i d e ==3) then
134 i f ( d i s t −d i s t a n c e ( r o l d , r i n t e r b ) . ge . −0.00001) then
135 d i s t=d i s t −d i s t a n c e ( r o l d , r i n t e r b )
136 r d i r e c ( 2 )=−r d i r e c ( 2 )
137  r ( 1 )=r i n t e r b ( 1 )
138  r ( 2 )=ymax−0.0001
139  r ( 3 )=r i n t e r b ( 3 )
140 i f ( d i s t . l t . 0 ) mserror=mserror+1
141 else
142 print ∗, ’ mirror e r r o r : d i s t n e g a t i v e ’
143 merror=merror+1
144 stuck=1
145 endif
146 endif

147

148 i f ( i n t e r s i d e ==4) then
149 i f ( d i s t −d i s t a n c e ( r o l d , r i n t e r b ) . ge . −0.00001) then
150 d i s t=d i s t −d i s t a n c e ( r o l d , r i n t e r b )
151 r d i r e c ( 1 )=−r d i r e c ( 1 )
152  r ( 1 )=xmax−0.0001
153  r ( 2 )=r i n t e r b ( 2 )
154  r ( 3 )=r i n t e r b ( 3 )
155 i f ( d i s t . l t . 0 ) mserror=mserror+1
156 else
157 print ∗, ’ mirror e r r o r : d i s t n e g a t i v e ’
158 merror=merror+1
159 stuck=1
160 endif
161 endif

162

163 i f ( i n t e r s i d e ==5) then
164 i f ( d i s t −d i s t a n c e ( r o l d , r i n t e r b ) . ge . −0.00001) then
165 d i s t=d i s t −d i s t a n c e ( r o l d , r i n t e r b )
166 r d i r e c ( 1 )=−r d i r e c ( 1 )
167  r ( 1 ) =0.0001
168  r ( 2 )=r i n t e r b ( 2 )
169  r ( 3 )=r i n t e r b ( 3 )
170 i f ( d i s t . l t . 0 ) mserror=mserror+1
171 else
172 print ∗, ’ mirror e r r o r : d i s t n e g a t i v e ’
173 merror=merror+1
174 stuck=1
175 endif
176 endif

177

178 end subroutine mirror

179

180 end module geometry

The physics module (called phys.f90) contains the data from NNDC [1] in the form of a 10^{th} order

Appendix H Source codes  xxxv

polynomial (or actually, the logarithm of a 10^{th} order polynomial of the logaritms of E), as shown in figure H.2.

1 module phys

2

3 use d e f i n i t i o n s

4

5 contains

6

7 !=!
8 != c r o s s s e c t i o n i s a small database with the c r o s s s e c t i o n s f o r =!
9 != neutron hydrogen c o l l i s i o n s at d i f f e r e n t neutron e n e r g i e s . =!
10 != I t i s a 10 th order t a y l o r f i t to data from NNDC  =!
11 !=!

12 13

14 subroutine c r o s s s e c t i o n
15 implicit none
16 real : : E temp , s temp

17

18 E temp = log10 (E)

19

20 s temp = − 1.2066E−007 ∗ E temp ∗∗(10) &
21  + 9.6423E−007 ∗ E temp ∗∗9  &
22  + 9.7495E−006 ∗ E temp ∗∗8  &
23  − 7.5128E−005 ∗ E temp ∗∗7  &
24  − 0.00030864 ∗ E temp ∗∗6  &
25  + 0.0021051  ∗ E temp ∗∗5  &
26  + 0.0037625  ∗ E temp ∗∗4  &
27  − 0.028526  ∗ E temp ∗∗3  &
28  + 0.024864  ∗ E temp ∗∗2  &
29  − 0.0023165  ∗ E temp  &
30  + 1.3019

31

32 c r o s s = (10∗∗ s temp ) ∗1E−22

33

34 end subroutine c r o s s s e c t i o n

35

36 end module phys

Most input/output is done by the I/O module (called io.f90). There are messages to be shown at runtime in different situations, and subroutines for collecting data while the program runs and subroutines to write this data to a file when the simulation is done. The main data file is called data.dat, the data from selected sides (chosen in the main loop) is in the file datam.dat, and finally there is the path data in path_x.dat where x runs from 1 to 19. Default is to create 10 path data files.

1 module i o

2

3 use d e f i n i t i o n s
4 use math
5 use phys
6 use exprandom

7

8 contains

9

10 !=!
11 != In the s u b r o u t i n e message a s t a r t i n g message i s produced .  =!
12 != This i s needed when running l o n g e r s i m u l a t i o n s so s e t t i n g s =!
13 != can be checked .  =!
14 !=!

xxxvi  H.1 Simulation

15

16 subroutine message
17 implicit none
18 print ∗, ’=STARTUP MESSAGE=’
19 print ∗, ’ This program s i m u l a t e s a neutron moderator . ’
20 print ∗, ’ P l e a s e s e e main . f 9 0 and moderator . f 9 0 f o r o p t i o n s . ’
21 print ∗, ’ The program i s not in t e s t mode and w i l l run ’
22 print ∗, ’ with randomly generated i n i t i a l neutrons . ’
23 print ∗, ’ Options i s as f o l l o w s : ’
24 print ∗, ’nmax= ’ ,nmax
25 i f ( i s o t r o p i c ==1) then
26 print ∗, ’ S c a t t e r i n g i s simulated as i s o t r o p i c . ’
27 print ∗, ’ Energy d e c r e a s e s nonrandomly . ’
28 else i f ( i s o t r o p i c ==0) then
29 print ∗, ’ E l a s t i c s c a t t e r i n g i s simulated . ’
30 print ∗, ’ Energy d e c r e a s e s randomly ’
31 endif

32

33 i f ( a b s o r p t i o n==1) then
34 print ∗, ’ Absorption i s simulated ’
35 print ∗, ’ A l l neutrons s t a r t with thermal energy ’
36 endif

37

38 i f ( f l a t ==1) then
39 print ∗, ’A FLAT moderator s u r f a c e i s used . ’
40 endif

41

42 i f ( c y l i n d e r v ==1.and . f l a t ==0) then
43 print ∗, ’A CYLINDER void in the moderator s u r f a c e i s used . ’
44 endif

45

46 i f ( c y l i n d e r v ==0.and . f l a t ==0) then
47 print ∗, ’A SPHERE void in the moderator s u r f a c e i s used . ’
48 endif

49

50 i f ( c y l i n d e r ==1) then
51 print ∗, ’WARNING, SIMULATING BIGGER MAIN MODERATOR! ’
52 endif
53 print ∗, ’=RUNNING PROGRAM=’

54

55 end subroutine message

56

57 !=!
58 != Endmessage g i v e s runtime output a f t e r the s i m u l a t i o n s i s done=!
59 != Small e r r o r s i s counted throughout the s i m u l a t i o n and the  =!
60 != t o t a l numbers i s shown here . I f t h e s e seem to b i g to change =!
61 != any s t a t i s t i c s , the data should not be used .  =!
62 != With the current s t a t e o f the simulation , runs at 30 m i l l i o n =!
63 != simulated neutrons does not produce e r r o r s .  =!
64 !=!

65

66 subroutine endmessage
67 implicit none

68

69 print ∗, ’ data w r i t t e n ’
70 i f ( a b s o r p t i o n==1) then
71 print ∗, ’ number o f f absorped n : ’ , absorped
72 endif
73 print ∗, ’ number o f small e r r o r s : ’ , t e r r o r+b e r r o r
74 print ∗, ’ box i n t e r s e c t e r r o r s : ’ , b e r r o r
75 print ∗, ’ mirror d i s t <0 e r r o r s : ’ , merror

Appendix H Source codes  xxxvii

76 print ∗, ’ mirror d i s t =0 events : ’ , mserror
77 print ∗, ’ s a f e r u n  e r r o r s : ’ , t e r r o r

78

79 end subroutine endmessage

80

81 !=!
82 != Output i s used everytime a neutrons data should be w r i t t e n to =!
83 != the temporary data f i l e s t o r e d in ram .  =!
84 != output i s t e s t e d with w r i t e t o d i s k  =!
85 !=!

86

87 subroutine output ( counter , counter2 )
88 implicit none
89 integer  : : counter , counter2

90

91 i f ( pathc==1) c a l l path ( pathn , counter2 , r o l d ( : ) )
92 i f ( pathc==1) c a l l path ( pathn , counter2 +1, r ( : ) )

93

94 r e s u l t s (n , : ) =(/ r o l d ( 1 ) , r o l d ( 2 ) , r o l d ( 3 ) ,&
95  r d i r e c ( 1 ) , r d i r e c ( 2 ) , r d i r e c ( 3 ) , &
96  E, t d i s t , real ( i n t e r a c t ) , real ( boundary ) , &
97  real ( e r r o r ) , real ( stuck ) , real ( f a i l ) , real ( k ) /)

98

99 end subroutine output

100

101 !=!
102 != outputm w r i t e s another s e t o f output  =!
103 !=!

104

105 subroutine outputm ( counter , counter2 )
106 implicit none
107 integer  : : counter , counter2

108

109 i f ( pathc==1) c a l l path ( pathn , counter2 , r o l d ( : ) )
110 i f ( pathc==1) c a l l path ( pathn , counter2 +1, r ( : ) )

111

112 r e s u l t s m (m, : ) =(/ r o l d ( 1 ) , r o l d ( 2 ) , r o l d ( 3 ) ,&
113  r d i r e c ( 1 ) , r d i r e c ( 2 ) , r d i r e c ( 3 ) , &
114  E, t d i s t , real ( i n t e r a c t ) , real ( boundary ) , &
115  real ( e r r o r ) , real ( stuck ) , real ( f a i l ) , real ( k ) /)

116

117 end subroutine outputm

118

119 !=!
120 != w r i t e t o d i s k w r i t e s data from the ram and to the d i s k a f t e r  =!
121 != a l l wanted neutrons i s simulated . This i n c r e a s e s performance =!
122 != s i n c e h a r d d i s k search times are s i g n i f i c a n t , but not  =!
123 != not r e l e v a n t when w r i t i n g one long s t r i p o f data i n s t e a d o f =!
124 != many s m a l l e r .  =!
125 != The data f i l e i s c a l l e d data . dat and has header l i n e s from  =!
126 != the i n f o v a r i a b e l . In t h i s way d a t a f i l e s w i l l not g e t mixed =!
127 != up .  =!
128 != w r i t e t o d i s k i s t e s t e d with output  =!
129 !=!

130

131 subroutine w r i t e t o d i s k
132 implicit none
133 integer : : k1 , n o t w r i t t e n
134 real , dimension ( 1 6 ) : : i n f o

135

136 n o t w r i t t e n=0

xxxviii  H.1 Simulation

137

138 do k1=1,nmax
139 i f ( r e s u l t s ( k1 , 1 3 ) . gt . 0 . 5 . or . r e s u l t s ( k1 , 1 2 ) . gt . 0 . 5 . or . r e s u l t s ( k1 , 1 1 ) . gt . 0 . 5 ) then
140 n o t w r i t t e n=n o t w r i t t e n+1
141 endif
142 enddo

143

144 i n f o =(/xmax , ymax , zmax , r 0 s p h e r e , r s p h e r e , E1 , Etermisk , real (nmax−n o t w r i t t e n )&
145  , real ( k ) , real ( t e s t ) , real ( i s o t r o p i c ) , real ( c y l i n d e r ) &
146  , real ( c y l i n d e r v ) , real ( f l a t ) /)

147

148 n o t w r i t t e n=0

149

150 open (10 , f i l e= ’ data . dat ’ )

151

152 write (10 , ’ (8 x (1 x , g14 . 6 ) ) ’ ) i n f o ( : )

153

154 close ( 1 0 )

155

156 open (10 , f i l e= ’ data . dat ’ , position= ’ append ’ )

157

158 do k1=1,nmax
159 i f ( r e s u l t s ( k1 , 1 3 ) . l t . 0 . 5 . and . r e s u l t s ( k1 , 1 2 ) . l t . 0 . 5 . and . r e s u l t s ( k1 , 1 1 ) . l t . 0 . 5 ) then
160 write (10 , ’ (11(1 x , g18 . 1 0 ) ) ’ ) r e s u l t s ( k1 , 1 4 ) , r e s u l t s ( k1 , 1 : 1 0 )
161 else
162 n o t w r i t t e n=n o t w r i t t e n+1
163 endif
164 end do

165

166 close ( 1 0 )

167

168 i f ( n o t w r i t t e n==0) print ∗, ’ Every event in d a t a f i l e ’
169 i f ( n o t w r i t t e n . ne . 0 ) print ∗, ’Number o f events d i s c a r d e d : ’ , n o t w r i t t e n

170

171 end subroutine w r i t e t o d i s k

172

173 !=!
174 != This v e r s i o n o f w r i t e t o d i s k t a k e s care o f d a t t a from outputm =!
175 != w r i t e t o d i s k i s t e s t e d with output  =!
176 !=!

177

178 subroutine writetodiskm
179 implicit none
180 integer : : k1 , n o t w r i t t e n
181 real , dimension ( 1 6 ) : : i n f o

182

183 n o t w r i t t e n=0

184

185 do k1=1,mmax
186 i f ( r e s u l t s m ( k1 , 1 3 ) . gt . 0 . 5 . or . r e s u l t s m ( k1 , 1 2 ) . gt . 0 . 5 . or . r e s u l t s m ( k1 , 1 1 ) . gt . 0 . 5 ) then
187 n o t w r i t t e n=n o t w r i t t e n+1
188 endif
189 enddo

190

191 i n f o =(/xmax , ymax , zmax , r 0 s p h e r e , r s p h e r e , E1 , Etermisk , real (mmax−n o t w r i t t e n )&
192  , real ( k ) , real ( t e s t ) , real ( i s o t r o p i c ) , real ( c y l i n d e r ) &
193  , real ( c y l i n d e r v ) , real ( f l a t ) /)

194

195 n o t w r i t t e n=0

196

197 open (10 , f i l e= ’ datam . dat ’ )

Appendix H Source codes  xxxix

198

199 write (10 , ’ (8 x (1 x , g14 . 6 ) ) ’ ) i n f o ( : )

200

201 close ( 1 0 )

202

203 open (10 , f i l e= ’ datam . dat ’ , position= ’ append ’ )

204

205 do k1=1,mmax
206 i f ( r e s u l t s m ( k1 , 1 3 ) . l t . 0 . 5 . and . r e s u l t s m ( k1 , 1 2 ) . l t . 0 . 5 . and . r e s u l t s m ( k1 , 1 1 ) . l t . 0 . 5 )

then

207 write (10 , ’ (11(1 x , g18 . 1 0 ) ) ’ ) r e s u l t s m ( k1 , 1 4 ) , r e s u l t s m ( k1 , 1 : 1 0 )
208 else
209 n o t w r i t t e n=n o t w r i t t e n+1
210 endif
211 end do

212

213 close ( 1 0 )

214

215 i f ( n o t w r i t t e n==0) print ∗, ’ Every mirror event in d a t a f i l e ’
216 i f ( n o t w r i t t e n . ne . 0 ) print ∗, ’Number o f mirror events
d i s c a r d e d / nothappend : ’ , n o t w r i t t e n

217

218 end subroutine writetodiskm

219 220

221 !=!
222 != P a t h i n i t i n i t i a l i z e s a path data f i l e . On a t y p i c a l run a few =!
223 != simulated neutrons w i l l have t h e i r path recorded .  =!
224 != This r o u t i n e s t a r t s a path f i l e .  =!
225 != p a t h i n i t o v e r w r i t e s nr f i l e , so path can  =!
226 != use append without r i s k i n g to continue  =!
227 != an o l d f i l e  =!
228 !=!

229

230 subroutine p a t h i n i t ( nr , neutron )
231 implicit none
232 integer  : : nr , neutron
233 real , dimension ( 3 ) : : vec

234

235 i f ( nr . l t . 1 0 ) then
236 name= ’ path ’ // char ( 4 8 ) // char ( nr +48)// ’ . dat ’
237 else i f ( nr . ge . 1 0 . and . nr . l t . 2 0 ) then
238 name= ’ path ’ // char ( 4 9 ) // char ( nr −10+48)// ’ . dat ’
239 endif

240

241 open (20 , f i l e=name)
242 write (20 , ’ (11(1 x , g18 . 1 0 ) ) ’ ) nr , neutron , xmax , ymax , zmax , r 0 s p h e r e , r s p h e r e , E1 , Etermisk
243 close ( 2 0 )

244 245

246 end subroutine p a t h i n i t

247

248 !=!
249 != Path i s a low performance w r i t e r which w r i t e s the current  =!
250 != p o s i t i o n o f the neutron f o r each i t e r a t i o n . Since few  =!
251 != neutrons are f o l l o w e d in t h i s way i t i s not important f o r  =!
252 != o v e r a l l performance  =!
253 !=!

254

255 subroutine path ( nr , counter , vec )
256 implicit none

xl  H.1 Simulation

257 integer  : : counter , nr
258 real , dimension ( 3 ) : : vec

259

260 i f ( nr . l t . 1 0 ) then
261 name= ’ path ’ // char ( 4 8 ) // char ( nr +48)// ’ . dat ’
262 else i f ( nr . ge . 1 0 . and . nr . l t . 2 0 ) then
263 name= ’ path ’ // char ( 4 9 ) // char ( nr −10+48)// ’ . dat ’
264 endif

265

266 open (20 , f i l e=name, position= ’ append ’ )
267 write (20 , ’ ( 6 ( 1 x , g18 . 1 0 ) ) ’ ) counter , vec ( : ) , d i s t ,E
268 close ( 2 0 )

269

270 end subroutine path

271

272 !=!
273 != T e s t s t a r t i o t a k e s care o f needed i o f o r t e s t mode .  =!
274 != Test mode saves the path o f every neutron .  =!
275 != I t was used mainly f o r debugging where i t can be used to  =!
276 != c r e a t e s p e c i f i c s p e c i a l cases and checking i f the program =!
277 != handles the s i t u a t i o n c o r r e c t l y .  =!
278 != The r o u t i n e are not q u i t e up to date though , so o p t i o n s are =!
279 != not w e l l supported in the i o part , but can be used with  =!
280 != caution and a l i t t l e r e w r i t i n g in main . f90  =!
281 !=!

282

283 subroutine t e s t s t a r t i o
284 implicit none

285

286 print ∗, ’= TEST MODE =’
287 print ∗, ’ In t e s t mode the u s e r can s p e c i f y a s t a r t point and d i r e c t i o n ’
288 print ∗, ’ and watch the path o f the neutron . ’
289 print ∗, ’ Test mode has not been updated to show a c c u r a t e i n f o r m a t i o n ’
290 print ∗, ’ in c a s e s with c y l i n d e r v =1 or c y l i n d e r=1  ’
291 print ∗, ’=’
292 print ∗, ’Do you want to s p e c i f y the f i r s t d i s t ? (1 f o r yes , 0 f o r no ) ’
293 read ∗, t e s t d i s t
294 print ∗, ’=’
295 print ∗, ’ The moderator i s a box from ( 0 , 0 , 0 ) to ’
296 print ∗, ’xmax ’ ,xmax
297 print ∗, ’ymax ’ ,ymax
298 print ∗, ’ zmax ’ , zmax
299 print ∗, ’=’
300 i f ( f l a t ==0) then
301 print ∗, ’ The moderator has a void in i t , shaped l i k e a sphere with ’
302 print ∗, ’ c e n t e r x ’ , r 0 s p h e r e ( 1 )
303 print ∗, ’ c e n t e r y ’ , r 0 s p h e r e ( 2 )
304 print ∗, ’ c e n t e r z ’ , r 0 s p h e r e ( 3 )
305 print ∗, ’ r a d i u s ’ , r s p h e r e
306 else
307 print ∗, ’ The moderator s u r f a c e i s f l a t ’
308 endif
309 print ∗, ’=’
310 print ∗, ’ I n s e r t s t a r t r o l d c o o r d i n a t e s ’
311 read ∗, r o l d ( : )
312 print ∗, ’=’
313 print ∗, ’ I n s e r t s t a r t r c o o r d i n a t e s ’
314 read ∗, r ( : )
315 print ∗, ’=’
316 print ∗, ’ I n s e r t s t a r t d i r e c t i o n as xyz v e c t o r . Will be normalized ’
317 read ∗, r d i r e c ( : )

Appendix H Source codes  xli

318

319 r d i r e c=r d i r e c / l e n g t h ( r d i r e c )

320

321 print ∗, ’ normalized r d i r e c ’ , r d i r e c
322 print ∗, ’=’
323 print ∗, ’ I n s e r t the neutron energy in e l e c t r o n v o l t s ( thermal =0.025eV ’
324 read ∗,E
325 print ∗, ’=’

326

327 c a l l c r o s s s e c t i o n
328 sigma =7.96E19∗ c r o s s

329

330 i f ( t e s t d i s t ==1) then
331 print ∗, ’ I n s e r t f i r s t d i s t a n c e ’
332 read ∗, d i s t
333 print ∗, ’=’
334 else
335 d i s t=expdev ( seed3 , sigma )
336 endif
337 print ∗, ’ I n s e r t 3 n e g a t i v e i n t e g e r s f o r random s e e d s ’
338 read ∗, seed1 , seed2 , seed3
339 print ∗, ’=’

340

341 end subroutine t e s t s t a r t i o

342

343 !=!
344 != t e s t e n d i o asks i f another t e s t run i s wanted  =!
345 !=!

346

347 subroutine t e s t e n d i o

348

349 print ∗, ’=’
350 print ∗, ’Do you want to make another t e s t path ? (1 f o r yes ) ’
351 read ∗, t e s t d o n e
352 print ∗, ’=’

353

354 end subroutine t e s t e n d i o

355

356 end module i o

The mathematical module (called math.f90) contains simple math and more specific subroutines for intersections with different geometries. interbox finds the intersection with the simple box containing the moderator, ignoring any voids. intersphere finds the intersection between the line joining r_old and r and the sphere defined in the moderator module. intercylinder is similar, but finds the intersections with a cylinder.

1 module math

2

3 use d e f i n i t i o n s

4

5 contains

6

7 !=!
8 != C a l c u l a t e s the l e n g t h o f a v e c t o r  =!
9 !=!

10

11 function l e n g t h ( r1 )
12 implicit none
13 real , dimension ( 3 )  : : r1
14 real  : : l e n g t h

xlii  H.1 Simulation

16 l e n g t h=s q r t ( r1 ( 1 ) ∗∗2 + r1 ( 2 ) ∗∗2 + r1 ( 3 ) ∗∗2)
17 return

18

19 end function l e n g t h

20

21 !=!
22 != C a l c u l a t e s the c r o s s product o f two v e c t o r s =!
23 !=!

24

25 function c r o s s p ( r1 , r2 )
26 implicit none
27 real , dimension ( 3 )  : : r1 , r2 , c r o s s p

28

29 c r o s s p ( 1 )=r1 ( 2 ) ∗ r2 ( 3 )−r2 ( 2 ) ∗ r1 ( 3 )
30 c r o s s p ( 2 )=r1 ( 3 ) ∗ r2 ( 1 )−r2 ( 3 ) ∗ r1 ( 1 )
31 c r o s s p ( 3 )=r1 ( 1 ) ∗ r2 ( 2 )−r2 ( 1 ) ∗ r1 ( 2 )

32

33 return

34

35 end function c r o s s p

36

37 !=!
38 != C a l c u l a t e s the d i s t a n c e between two p o i n t s =!
39 !=!

40

41 function d i s t a n c e ( r1 , r2 )
42 implicit none
43 real , dimension ( 3 )  : : r1 , r2
44 real  : : d i s t a n c e

45

46 d i s t a n c e=s q r t ( ( r1 ( 1 )−r2 ( 1 ) ) ∗∗2 + ( r1 ( 2 )−r2 ( 2 ) ) ∗∗2 + ( r1 ( 3 )−r2 ( 3 ) ) ∗∗2)
47 return

48

49 end function d i s t a n c e

50

51 !=!
52 != i n t e r b o x checks the i n t e r s e c t i o n between the l i n e made by  =!
53 != the o l d neutron p o s i t i o n and d i r e c t i o n and the simple box . =!
54 != The simple box i s the box as i t would be without void .  =!
55 != Output i s the i n t e r s e c t i o n r i n t e r b and i n t e r s i d e i n t e g e r  =!
56 !=  =!
57 != i n t e r s i d e = 1 i f i n t e r s e c t i o n i s on i n g o i n g s i d e ( z=0)  =!
58 != i n t e r s i d e = 2 i f i n t e r s e c t i o n i s on buttom s i d e  ( y=0)  =!
59 != i n t e r s i d e = 3 i f i n t e r s e c t i o n i s on top s i d e  ( y=ymax)  =!
60 != i n t e r s i d e = 4 i f i n t e r s e c t i o n i s on l e f t s i d e  ( x=xmax)  =!
61 != i n t e r s i d e = 5 i f i n t e r s e c t i o n i s on r i g h t s i d e  ( x=0)  =!
62 != i n t e r s i d e = 6 i f i n t e r s e c t i o n i s on outgoing s i d e ( z=zmax )  =!
63 !=  =!
64 != When neutrons h i t a corner og edge where both i n t e r s e c t i o n s =!
65 != could be considered v a l i d , the s i d e l o w e s t number i s chosen . =!
66 != This i s done to be 100% sure neutrons with i n t e r s i d e =6 are  =!
67 != outgoing  =!
68 !=!

69

70 subroutine i n t e r b o x
71 implicit none
72 real  : : t
73 real , dimension ( 3 )  : : r t e s t
74 integer  : : done

75

Appendix H Source codes  xliii

77 done=0
78 i n t e r s i d e =0

79

80 ! Assuming i n t e r s e c t i o n i s on i n g o i n g s i d e
81 i f ( done==0) then
82 i f ( r d i r e c ( 3 ) . ne . 0 . ) then
83 t=(− r o l d ( 3 ) ) / r d i r e c ( 3 )
84 r t e s t ( : )=r o l d ( : )+t ∗ r d i r e c ( : )
85 i f ( t . ge . 0 . . and . t . l e . d i s t ) then
86  i f ( r t e s t ( 1 ) . ge . 0 . . and . r t e s t ( 1 ) . l e . xmax . and . r t e s t ( 2 ) . ge . 0 . . and . r t e s t ( 2 ) . l e . ymax)

then

87  r i n t e r b=r t e s t
88  i n t e r s i d e =1
89  done=1
90  endif
91 endif
92 endif
93 endif

94

95 ! Assuming i n t e r s e c t i o n i s on buttom s i d e
96 i f ( done==0) then
97 i f ( r d i r e c ( 2 ) . ne . 0 . ) then
98 t=(− r o l d ( 2 ) ) / r d i r e c ( 2 )
99 r t e s t ( : )=r o l d ( : )+t ∗ r d i r e c ( : )
100 i f ( t . ge . 0 . . and . t . l e . d i s t ) then
101  i f ( r t e s t ( 1 ) . ge . 0 . . and . r t e s t ( 1 ) . l e . xmax . and . r t e s t ( 3 ) . ge . 0 . . and . r t e s t ( 3 ) . l e . zmax )

then

102  r i n t e r b=r t e s t
103  i n t e r s i d e =2
104  done=1
105  endif
106 endif
107 endif
108 endif

109

110 ! Assuming i n t e r s e c t i o n i s on top s i d e
111 i f ( done==0) then
112 i f ( r d i r e c ( 2 ) . ne . 0 . ) then
113 t=(ymax−r o l d ( 2 ) ) / r d i r e c ( 2 )
114 r t e s t ( : )=r o l d ( : )+t ∗ r d i r e c ( : )
115 i f ( t . ge . 0 . . and . t . l e . d i s t ) then
116  i f ( r t e s t ( 1 ) . ge . 0 . . and . r t e s t ( 1 ) . l e . xmax . and . r t e s t ( 3 ) . ge . 0 . . and . r t e s t ( 3 ) . l e . zmax )

then

117  r i n t e r b=r t e s t
118  i n t e r s i d e =3
119  done=1
120  endif
121 endif
122 endif
123 endif

124

125 ! Assuming i n t e r s e c t i o n i s on l e f t s i d e
126 i f ( done==0) then
127 i f ( r d i r e c ( 1 ) . ne . 0 . ) then
128 t=(xmax−r o l d ( 1 ) ) / r d i r e c ( 1 )
129 r t e s t ( : )=r o l d ( : )+t ∗ r d i r e c ( : )
130 i f ( t . ge . 0 . . and . t . l e . d i s t ) then
131  i f ( r t e s t ( 2 ) . ge . 0 . . and . r t e s t ( 2 ) . l e . ymax . and . r t e s t ( 3 ) . ge . 0 . . and . r t e s t ( 3 ) . l e . zmax )

then

132  r i n t e r b=r t e s t
133  i n t e r s i d e =4

xliv  H.1 Simulation

134  done=1
135  endif
136 endif
137 endif
138 endif

139

140 ! Assuming i n t e r s e c t i o n i s on r i g h t s i d e
141 i f ( done==0) then
142 i f ( r d i r e c ( 1 ) . ne . 0 . ) then
143 t=(− r o l d ( 1 ) ) / r d i r e c ( 1 )
144 r t e s t ( : )=r o l d ( : )+t ∗ r d i r e c ( : )
145 i f ( t . ge . 0 . . and . t . l e . d i s t ) then
146  i f ( r t e s t ( 2 ) . ge . 0 . . and . r t e s t ( 2 ) . l e . ymax . and . r t e s t ( 3 ) . ge . 0 . . and . r t e s t ( 3 ) . l e . zmax )

then

147  r i n t e r b=r t e s t
148  i n t e r s i d e =5
149  done=1
150  endif
151 endif
152 endif
153 endif

154

155 ! Assuming i n t e r s e c t i o n i s on outgoing s i d e
156 i f ( done==0) then
157 i f ( r d i r e c ( 3 ) . ne . 0 . ) then
158 t=(zmax−r o l d ( 3 ) ) / r d i r e c ( 3 )
159 r t e s t ( : )=r o l d ( : )+t ∗ r d i r e c ( : )
160 i f ( t . ge . 0 . . and . t . l e . d i s t ) then
161  i f ( r t e s t ( 1 ) . ge . 0 . . and . r t e s t ( 1 ) . l e . xmax . and . r t e s t ( 2 ) . ge . 0 . . and . r t e s t ( 2 ) . l e . ymax)

then

162  r i n t e r b=r t e s t
163  i n t e r s i d e =6
164  done=1
165  endif
166 endif
167 endif
168 endif

169

170 i f ( i n t e r s i d e ==0) then
171 print ∗, ’ Error in box i n t e r s e c t ’
172 b e r r o r=b e r r o r+1
173 stuck=1
174 endif

175

176 end subroutine i n t e r b o x

177

178 !=!
179 != i n t e r s p h e r e checks the i n t e r s e c t i o n between the l i n e made by =!
180 != r o l d and r d i r e c and the sphere d i s r i b i n g the void in the =!
181 != moderator .  =!
182 != Outputs are r i n t e r s 1 and r i n t e r s 2  =!
183 != u1 and u2 i s s t o r e d as g l o b a l v a r a b l e s , so o t h e r r o u t i n e s  =!
184 != can check i f the s o l u t i o n s are in p a s t or f u t u r e f o r the  =!
185 != neutron  =!
186 !=!

187

188 subroutine i n t e r s p h e r e
189 implicit none
190 real , dimension ( 3 )  : : P1 , P2
191 real  : : a , b , c

Appendix H Source codes  xlv

193 P1 ( : )=r o l d ( : )
194 P2 ( : )=r o l d ( : )+r d i r e c ( : )

195

196 ! The i n t e r s e c t i o n i s the s o l u t i o n to the second order equation with c o e f f i c e n t s :

197

198 a=(P2 ( 1 )−P1 ( 1 ) ) ∗∗2+(P2 ( 2 )−P1 ( 2 ) ) ∗∗2+(P2 ( 3 )−P1 ( 3 ) ) ∗∗2

199

200 b=2∗( ( P2 ( 1 )−P1 ( 1 ) ) ∗( P1 ( 1 )−r 0 s p h e r e ( 1 ) ) +&
201  ( P2 ( 2 )−P1 ( 2 ) ) ∗( P1 ( 2 )−r 0 s p h e r e ( 2 ) ) +&
202  ( P2 ( 3 )−P1 ( 3 ) ) ∗( P1 ( 3 )−r 0 s p h e r e ( 3 ) ) )

203

204 c=r 0 s p h e r e ( 1 ) ∗∗2+ r 0 s p h e r e ( 2 ) ∗∗2+ r 0 s p h e r e ( 3 ) ∗∗2 + &
205  P1 ( 1 ) ∗∗2 + P1 ( 2 ) ∗∗2 + P1 ( 3 ) ∗∗2 − &
206  2 . ∗ ( r 0 s p h e r e ( 1 ) ∗P1 ( 1 ) + r 0 s p h e r e ( 2 ) ∗P1 ( 2 ) + r 0 s p h e r e ( 3 ) ∗P1 ( 3 ) ) &
207  − r s p h e r e ∗∗2

208

209 u1=(−b−s q r t ( b∗∗2. −4.∗ a∗ c ) ) / ( 2 . ∗ a )
210 u2=(−b+s q r t ( b∗∗2. −4.∗ a∗ c ) ) / ( 2 . ∗ a )

211

212 i f ( b∗∗2. −4.∗ a∗ c . l t . 0 ) then
213 print ∗, ’ i n t e r s p h e r e e r r o r , no s o l u t i o n s ’
214 else
215 r i n t e r s 1 ( : )=P1 ( : )+u1 ∗(P2 ( : )−P1 ( : ) )
216 r i n t e r s 2 ( : )=P1 ( : )+u2 ∗(P2 ( : )−P1 ( : ) )
217 endif

218 219

220 end subroutine i n t e r s p h e r e

221

222 !=!
223 != i n t e r c y l i n d e r checks the i n t e r s e c t i o n between the l i n e made =!
224 != by r o l d and r d i r e c and the c y l i n d e r d i s r i b i n g the s t a r t =!
225 != o f the moderator system  =!
226 != Outputs are r i n t e r c 1 and r i n t e r c 2  =!
227 != u3 and u4 i s s t o r e d as g l o b a l v a r a b l e s , so o t h e r r o u t i n e s  =!
228 != can check i f the s o l u t i o n s are in p a s t or f u t u r e f o r the  =!
229 != neutron  =!
230 !=!

231

232 subroutine i n t e r c y l i n d e r
233 implicit none
234 real : : a , b , c , t
235 integer : : c1done , c2done
236 real , dimension ( 3 ) : : r t e s t

237

238 c1done=0
239 c2done=0

240

241 a=r d i r e c ( 1 ) ∗∗2+ r d i r e c ( 2 ) ∗∗2
242 b=2.∗( r d i r e c ( 1 ) ∗( r o l d ( 1 )−ccentrum ( 1 ) ) + r d i r e c ( 2 ) ∗( r o l d ( 2 )−ccentrum ( 2 ) ) )
243 c= r o l d ( 1 ) ∗∗2 + r o l d ( 2 ) ∗∗2 − 2 . ∗ ( r o l d ( 1 ) ∗ ccentrum ( 1 ) + r o l d ( 2 ) ∗ ccentrum ( 2 ) ) &
244  − r c y l i n d e r ∗∗2+ccentrum ( 1 ) ∗∗2+ccentrum ( 2 ) ∗∗2

245 246

247 u3=(−b−s q r t ( b∗∗2. −4.∗ a∗ c ) ) / ( 2 . ∗ a )
248 u4=(−b+s q r t ( b∗∗2. −4.∗ a∗ c ) ) / ( 2 . ∗ a )

249

250 i f ( b∗∗2. −4.∗ a∗ c . l t . 0 ) then
251  print ∗, ’ i n t e r c y l i n d e r e r r o r , no s o l u t i o n s ( box e r r o r ) ’ , p o s s t a t u s
252  b e r r o r=b e r r o r+1
253 else

xlvi  H.1 Simulation

254 i f ( r o l d ( 3 )+u3∗ r d i r e c ( 3 ) . l e . czmax . and . &
255  r o l d ( 3 )+u3∗ r d i r e c ( 3 ) . ge . czmin ) then
256  r i n t e r c 1 ( : )=r o l d+u3∗ r d i r e c
257  c1done=1
258 endif
259 i f ( r o l d ( 3 )+u4∗ r d i r e c ( 3 ) . l e . czmax . and . &
260  r o l d ( 3 )+u4∗ r d i r e c ( 3 ) . ge . czmin ) then
261  r i n t e r c 2 ( : )=r o l d+u4∗ r d i r e c
262  c2done=1
263 endif

264

265 i f ( c1done==0) then
266  t=(czmax−r o l d ( 3 ) ) / r d i r e c ( 3 )
267  r t e s t ( : )=r o l d ( : )+t ∗ r d i r e c ( : )
268  i f ( ( r t e s t ( 1 )−ccentrum ( 1 ) ) ∗∗2 + ( r t e s t ( 2 )−ccentrum ( 2 ) ) ∗ ∗ 2 . l e . r c y l i n d e r ∗∗2) then
269  r i n t e r c 1=r t e s t
270  u3=t
271  c1done=1
272  endif

273

274  t=(czmin−r o l d ( 3 ) ) / r d i r e c ( 3 )
275  r t e s t ( : )=r o l d ( : )+t ∗ r d i r e c ( : )
276  i f ( ( r t e s t ( 1 )−ccentrum ( 1 ) ) ∗∗2 + ( r t e s t ( 2 )−ccentrum ( 2 ) ) ∗ ∗ 2 . l e . r c y l i n d e r ∗∗2) then
277  r i n t e r c 1=r t e s t
278  u3=t
279  c1done=1
280  endif
281 endif

282

283 i f ( c2done==0) then
284  t=(czmin−r o l d ( 3 ) ) / r d i r e c ( 3 )
285  r t e s t ( : )=r o l d ( : )+t ∗ r d i r e c ( : )
286  i f ( ( r t e s t ( 1 )−ccentrum ( 1 ) ) ∗∗2 + ( r t e s t ( 2 )−ccentrum ( 2 ) ) ∗ ∗ 2 . l e . r c y l i n d e r ∗∗2) then
287  r i n t e r c 2=r t e s t
288  u4=t
289  c2done=1
290  endif

291

292  t=(czmax−r o l d ( 3 ) ) / r d i r e c ( 3 )
293  r t e s t ( : )=r o l d ( : )+t ∗ r d i r e c ( : )
294  i f ( ( r t e s t ( 1 )−ccentrum ( 1 ) ) ∗∗2 + ( r t e s t ( 2 )−ccentrum ( 2 ) ) ∗ ∗ 2 . l e . r c y l i n d e r ∗∗2) then
295  r i n t e r c 2=r t e s t
296  u4=t
297  c2done=1
298  endif
299 endif

300

301 i f ( c1done==0.or . c2done==0) then
302 print ∗, ’ c y l l i n d e r i n t e r s e c t e r r o r , no s o l u t i o n ’
303 b e r r o r=b e r r o r+1
304 endif

305

306 endif

307

308 end subroutine i n t e r c y l i n d e r

309

310 end module math

The subroutines in random.f90 are mainly copied from [10]. ran1 is a recomended random function which was chosen because of a nice blend of performance and ability to pass statistical tests searching for correlations in the sequence. A ran1 test sequence was analyzed, and no flaws were apparent. The

Appendix H Source codes  xlvii

last function, rancirc picks a random point in a circle.

1 module random

2

3 contains

4

5 !=!
6 != Random f u n c t i o n s copyed from numerical r e c i p e s .  =!
7 != ran1 i s p r i m a r i l y used , but i t does r e q u i r e ran0 .  =!
8 != The random f u n c t i o n s have been checked and seems to be what =!
9 != i s e x p e c t e d .  =!
10 !=!

11

12 function ran0 ( idum )
13 implicit none
14 Integer : : idum
15 real  : : ran0
16 integer , parameter : : IA=16807 ,IM=2147483647 ,IQ=127773 ,IR=2836 ,MASK=123459876
17 real , parameter  : : AM=1./IM
18 Integer k
19 idum=i e o r ( idum ,MASK)
20 k=idum/IQ
21 idum=IA ∗( idum−k∗IQ )−IR∗k
22 i f ( idum . l t . 0 ) idum=idum+IM
23 ran0=AM∗idum
24 idum=i e o r ( idum ,MASK)
25 return

26

27 end function ran0

28

29 function r a n 1 d i s t ( idum )
30 implicit none
31 integer , parameter : : IA=16807 ,IM=2147483647 ,IQ=127773 ,IR=2836 ,NTAB=32
32 integer , parameter : : NDIV=1+(IM−1)/NTAB
33 real , parameter  : : AM=1./IM , EPS=1.2e −7,RNMX=1.−eps
34 real  : : r a n 1 d i s t
35 integer  : : j , k , i v (NTAB) , iy , idum
36 SAVE iv , i y
37DATA i v /NTAB∗0/ , i y /0/
38 i f ( idum . l e . 0 . or . i y . eq . 0 ) then
39  idum=max(−idum , 1 )
40  do j=NTAB+8,1,−1
41  k=idum/IQ
42  idum=IA ∗( idum−k∗IQ )−IR∗k
43  i f ( idum . l t . 0 ) idum=idum+IM
44  i f ( j . l e .NTAB) i v ( j )=idum
45  enddo
46  i y=i v ( 1 )
47 endif
48 k=idum/IQ
49 idum=IA ∗( idum−k∗IQ )−IR∗k
50 i f ( idum . l t . 0 ) idum=idum+IM
51 j=1+i y /NDIV
52 i y=i v ( j )
53 i v ( j )=idum
54 r a n 1 d i s t=min (AM∗ iy ,RNMX)
55 return

56

57 end function r a n 1 d i s t

58

59 function ran1abs ( idum )
60 implicit none

xlviii  H.1 Simulation

61 integer , parameter : : IA=16807 ,IM=2147483647 ,IQ=127773 ,IR=2836 ,NTAB=32
62 integer , parameter : : NDIV=1+(IM−1)/NTAB
63 real , parameter  : : AM=1./IM , EPS=1.2e −7,RNMX=1.−eps
64 real  : : ran1abs
65 integer  : : j , k , i v (NTAB) , iy , idum
66 SAVE iv , i y
67DATA i v /NTAB∗0/ , i y /0/
68 i f ( idum . l e . 0 . or . i y . eq . 0 ) then
69  idum=max(−idum , 1 )
70  do j=NTAB+8,1,−1
71  k=idum/IQ
72  idum=IA ∗( idum−k∗IQ )−IR∗k
73  i f ( idum . l t . 0 ) idum=idum+IM
74  i f ( j . l e .NTAB) i v ( j )=idum
75  enddo
76  i y=i v ( 1 )
77 endif
78 k=idum/IQ
79 idum=IA ∗( idum−k∗IQ )−IR∗k
80 i f ( idum . l t . 0 ) idum=idum+IM
81 j=1+i y /NDIV
82 i y=i v ( j )
83 i v ( j )=idum
84 ran1abs=min (AM∗ iy ,RNMX)
85 return

86

87 end function ran1abs

88

89 function ran1theta ( idum )
90 implicit none
91 integer , parameter : : IA=16807 ,IM=2147483647 ,IQ=127773 ,IR=2836 ,NTAB=32
92 integer , parameter : : NDIV=1+(IM−1)/NTAB
93 real , parameter  : : AM=1./IM , EPS=1.2e −7,RNMX=1.−eps
94 real  : : ran1theta
95 integer  : : j , k , i v (NTAB) , iy , idum
96 SAVE iv , i y
97DATA i v /NTAB∗0/ , i y /0/
98 i f ( idum . l e . 0 . or . i y . eq . 0 ) then
99  idum=max(−idum , 1 )
100  do j=NTAB+8,1,−1
101  k=idum/IQ
102  idum=IA ∗( idum−k∗IQ )−IR∗k
103  i f ( idum . l t . 0 ) idum=idum+IM
104  i f ( j . l e .NTAB) i v ( j )=idum
105  enddo
106  i y=i v ( 1 )
107 endif
108 k=idum/IQ
109 idum=IA ∗( idum−k∗IQ )−IR∗k
110 i f ( idum . l t . 0 ) idum=idum+IM
111 j=1+i y /NDIV
112 i y=i v ( j )
113 i v ( j )=idum
114 ran1theta=min (AM∗ iy ,RNMX)
115 return

116

117 end function ran1theta

118

119 function ran1phi ( idum )
120 implicit none
121 integer , parameter : : IA=16807 ,IM=2147483647 ,IQ=127773 ,IR=2836 ,NTAB=32

Appendix H Source codes  xlix

122 integer , parameter : : NDIV=1+(IM−1)/NTAB
123 real , parameter  : : AM=1./IM , EPS=1.2e −7,RNMX=1.−eps
124 real  : : ran1phi
125 integer  : : j , k , i v (NTAB) , iy , idum
126 SAVE iv , i y
127DATA i v /NTAB∗0/ , i y /0/
128 i f ( idum . l e . 0 . or . i y . eq . 0 ) then
129  idum=max(−idum , 1 )
130  do j=NTAB+8,1,−1
131  k=idum/IQ
132  idum=IA ∗( idum−k∗IQ )−IR∗k
133  i f ( idum . l t . 0 ) idum=idum+IM
134  i f ( j . l e .NTAB) i v ( j )=idum
135  enddo
136  i y=i v ( 1 )
137 endif
138 k=idum/IQ
139 idum=IA ∗( idum−k∗IQ )−IR∗k
140 i f ( idum . l t . 0 ) idum=idum+IM
141 j=1+i y /NDIV
142 i y=i v ( j )
143 i v ( j )=idum
144 ran1phi=min (AM∗ iy ,RNMX)
145 return

146

147 end function ran1phi

148

149 function ran1x ( idum )
150 implicit none
151 integer , parameter : : IA=16807 ,IM=2147483647 ,IQ=127773 ,IR=2836 ,NTAB=32
152 integer , parameter : : NDIV=1+(IM−1)/NTAB
153 real , parameter  : : AM=1./IM , EPS=1.2e −7,RNMX=1.−eps
154 real  : : ran1x
155 integer  : : j , k , i v (NTAB) , iy , idum
156 SAVE iv , i y
157DATA i v /NTAB∗0/ , i y /0/
158 i f ( idum . l e . 0 . or . i y . eq . 0 ) then
159  idum=max(−idum , 1 )
160  do j=NTAB+8,1,−1
161  k=idum/IQ
162  idum=IA ∗( idum−k∗IQ )−IR∗k
163  i f ( idum . l t . 0 ) idum=idum+IM
164  i f ( j . l e .NTAB) i v ( j )=idum
165  enddo
166  i y=i v ( 1 )
167 endif
168 k=idum/IQ
169 idum=IA ∗( idum−k∗IQ )−IR∗k
170 i f ( idum . l t . 0 ) idum=idum+IM
171 j=1+i y /NDIV
172 i y=i v ( j )
173 i v ( j )=idum
174 ran1x=min (AM∗ iy ,RNMX)
175 return

176

177 end function ran1x

178

179 function ran1y ( idum )
180 implicit none
181 integer , parameter : : IA=16807 ,IM=2147483647 ,IQ=127773 ,IR=2836 ,NTAB=32
182 integer , parameter : : NDIV=1+(IM−1)/NTAB

l  H.1 Simulation

183 real , parameter  : : AM=1./IM , EPS=1.2e −7,RNMX=1.−eps
184 real  : : ran1y
185 integer  : : j , k , i v (NTAB) , iy , idum
186 SAVE iv , i y
187DATA i v /NTAB∗0/ , i y /0/
188 i f ( idum . l e . 0 . or . i y . eq . 0 ) then
189  idum=max(−idum , 1 )
190  do j=NTAB+8,1,−1
191  k=idum/IQ
192  idum=IA ∗( idum−k∗IQ )−IR∗k
193  i f ( idum . l t . 0 ) idum=idum+IM
194  i f ( j . l e .NTAB) i v ( j )=idum
195  enddo
196  i y=i v ( 1 )
197 endif
198 k=idum/IQ
199 idum=IA ∗( idum−k∗IQ )−IR∗k
200 i f ( idum . l t . 0 ) idum=idum+IM
201 j=1+i y /NDIV
202 i y=i v ( j )
203 i v ( j )=idum
204 ran1y=min (AM∗ iy ,RNMX)
205 return

206

207 end function ran1y

208

209 function ran1E1 ( idum )
210 implicit none
211 integer , parameter : : IA=16807 ,IM=2147483647 ,IQ=127773 ,IR=2836 ,NTAB=32
212 integer , parameter : : NDIV=1+(IM−1)/NTAB
213 real , parameter  : : AM=1./IM , EPS=1.2e −7,RNMX=1.−eps
214 real  : : ran1E1
215 integer  : : j , k , i v (NTAB) , iy , idum
216 SAVE iv , i y
217DATA i v /NTAB∗0/ , i y /0/
218 i f ( idum . l e . 0 . or . i y . eq . 0 ) then
219  idum=max(−idum , 1 )
220  do j=NTAB+8,1,−1
221  k=idum/IQ
222  idum=IA ∗( idum−k∗IQ )−IR∗k
223  i f ( idum . l t . 0 ) idum=idum+IM
224  i f ( j . l e .NTAB) i v ( j )=idum
225  enddo
226  i y=i v ( 1 )
227 endif
228 k=idum/IQ
229 idum=IA ∗( idum−k∗IQ )−IR∗k
230 i f ( idum . l t . 0 ) idum=idum+IM
231 j=1+i y /NDIV
232 i y=i v ( j )
233 i v ( j )=idum
234 ran1E1=min (AM∗ iy ,RNMX)
235 return

236

237 end function ran1E1

238

239 function ran1E2 ( idum )
240 implicit none
241 integer , parameter : : IA=16807 ,IM=2147483647 ,IQ=127773 ,IR=2836 ,NTAB=32
242 integer , parameter : : NDIV=1+(IM−1)/NTAB
243 real , parameter  : : AM=1./IM , EPS=1.2e −7,RNMX=1.−eps

Appendix H Source codes  li

244 real  : : ran1E2
245 integer  : : j , k , i v (NTAB) , iy , idum
246 SAVE iv , i y
247DATA i v /NTAB∗0/ , i y /0/
248 i f ( idum . l e . 0 . or . i y . eq . 0 ) then
249  idum=max(−idum , 1 )
250  do j=NTAB+8,1,−1
251  k=idum/IQ
252  idum=IA ∗( idum−k∗IQ )−IR∗k
253  i f ( idum . l t . 0 ) idum=idum+IM
254  i f ( j . l e .NTAB) i v ( j )=idum
255  enddo
256  i y=i v ( 1 )
257 endif
258 k=idum/IQ
259 idum=IA ∗( idum−k∗IQ )−IR∗k
260 i f ( idum . l t . 0 ) idum=idum+IM
261 j=1+i y /NDIV
262 i y=i v ( j )
263 i v ( j )=idum
264 ran1E2=min (AM∗ iy ,RNMX)
265 return

266

267 end function ran1E2

268

269 !=!
270 != r a n c i r c p i c k s a random p o i n t on a c i r c l e with r a d i u s and  =!
271 != angle . Needs the r a n c i r c 1 and 2 which uses ran1  =!
272 !=!

273

274 function r a n c i r c ( idum1 , idum2 )

275

276 implicit none
277 integer  : : idum1 , idum2
278 real  : : dum1 , dum2
279 real , dimension ( 2 ) : : r a n c i r c

280

281 do
282 dum1 = r a n 1 c i r c 1 ( idum1 )
283 dum2 = r a n 1 c i r c 2 ( idum2 )
284 i f ( dum1 = 0 . . or . dum2 = 0 . ) then
285 else
286 exit
287 endif
288 enddo

289

290 r a n c i r c ( 1 ) = s q r t (dum2)  ! r v a l u e ( on u n i t c i r c l e )
291 r a n c i r c ( 2 ) = 2∗3.14159 ∗ dum1  ! t h e t a v a l u e

292

293 return

294

295 end function r a n c i r c

296

297 function r a n 1 c i r c 1 ( idum )
298 implicit none
299 integer , parameter : : IA=16807 ,IM=2147483647 ,IQ=127773 ,IR=2836 ,NTAB=32
300 integer , parameter : : NDIV=1+(IM−1)/NTAB
301 real , parameter  : : AM=1./IM , EPS=1.2e −7,RNMX=1.−eps
302 real  : : r a n 1 c i r c 1
303 integer  : : j , k , i v (NTAB) , iy , idum
304 SAVE iv , i y

lii  H.1 Simulation

305DATA i v /NTAB∗0/ , i y /0/
306 i f ( idum . l e . 0 . or . i y . eq . 0 ) then
307  idum=max(−idum , 1 )
308  do j=NTAB+8,1,−1
309  k=idum/IQ
310  idum=IA ∗( idum−k∗IQ )−IR∗k
311  i f ( idum . l t . 0 ) idum=idum+IM
312  i f ( j . l e .NTAB) i v ( j )=idum
313  enddo
314  i y=i v ( 1 )
315 endif
316 k=idum/IQ
317 idum=IA ∗( idum−k∗IQ )−IR∗k
318 i f ( idum . l t . 0 ) idum=idum+IM
319 j=1+i y /NDIV
320 i y=i v ( j )
321 i v ( j )=idum
322 r a n 1 c i r c 1=min (AM∗ iy ,RNMX)
323 return

324

325 end function r a n 1 c i r c 1

326

327 function r a n 1 c i r c 2 ( idum )
328 implicit none
329 integer , parameter : : IA=16807 ,IM=2147483647 ,IQ=127773 ,IR=2836 ,NTAB=32
330 integer , parameter : : NDIV=1+(IM−1)/NTAB
331 real , parameter  : : AM=1./IM , EPS=1.2e −7,RNMX=1.−eps
332 real  : : r a n 1 c i r c 2
333 integer  : : j , k , i v (NTAB) , iy , idum
334 SAVE iv , i y
335DATA i v /NTAB∗0/ , i y /0/
336 i f ( idum . l e . 0 . or . i y . eq . 0 ) then
337  idum=max(−idum , 1 )
338  do j=NTAB+8,1,−1
339  k=idum/IQ
340  idum=IA ∗( idum−k∗IQ )−IR∗k
341  i f ( idum . l t . 0 ) idum=idum+IM
342  i f ( j . l e .NTAB) i v ( j )=idum
343  enddo
344  i y=i v ( 1 )
345 endif
346 k=idum/IQ
347 idum=IA ∗( idum−k∗IQ )−IR∗k
348 i f ( idum . l t . 0 ) idum=idum+IM
349 j=1+i y /NDIV
350 i y=i v ( j )
351 i v ( j )=idum
352 r a n 1 c i r c 2=min (AM∗ iy ,RNMX)
353 return

354

355 end function r a n 1 c i r c 2

356

357 end module

The last module, exprandom (called exprandom.f90), have different non-evenly distributed random functions. The most important one is expdev, the exponential distributed random number generator with variable exponent L. This is used whenever a distance to the next scattering is needed. The linear distributed lindev is used for the random starting energy for neutrons originating from the primary moderator. The last subroutine, expabs is a copy of the first, but used only for absorption. The method used to make these distributions is explained in [10].

Appendix H Source codes  liii

1 module exprandom

2

3 use d e f i n i t i o n s
4 use random

5

6 contains

7

8 !=!
9 != Exponentialy d i s t r i b u t e d random f u n c t i o n . Needs ran1 r o u t i n e =!
10 != and have r a n 1 d i s t r e s e r v e d . Only used f o r random d i s t a n c e  =!
11 != Copyed from numerical r e c i p e s and t e s t e d  =!
12 !=!

13

14 function expdev ( idum , L)
15 implicit none
16 integer : : idum
17 real  : : expdev , dum, L

18

19 do
20 dum=r a n 1 d i s t ( idum )
21 i f (dum . eq . 0 . ) then
22 else
23 exit
24 endif
25 enddo

26

27 expdev=−l o g (dum) /L
28 return

29

30 end function expdev

31

32 !=!
33 != Linear random f u n c t i o n f o r choosing s t a r t i n g energy .  =!
34 != The method f o r c r e a t i n g needed d i s t r i b u t i o n s l e a r n e d from  =!
35 != numerical r e c i p e s . There was no l i n e a r f u n c t i o n to copy .  =!
36 !=!

37

38 function l i n d e v ( idum )
39 implicit none
40 integer : : idum
41 real  : : lindev , dum

42

43 do
44 dum=ran1E2 ( idum )
45 i f (dum . eq . 0 . ) then
46 else
47 exit
48 endif
49 enddo

50

51 l i n d e v=s q r t (2∗dum)
52 return

53

54 end function l i n d e v

55

56 !=!
57 ! Copy o f expdev , but used f o r a b s o r p t i o n c a l c u l a t i o n s  =!
58 !=!

59

60 function expabs ( idum , L)
61 implicit none

62 integer : : idum
63 real  : : expabs , dum, L

64

65 do
66 dum=ran1abs ( idum )
67 i f (dum . eq . 0 . ) then
68 else
69 exit
70 endif
71 enddo

72

73 expabs=−l o g (dum) /L
74 return

75

76 end function expabs

77

78 end module exprandom

H.2 Data analysis

All calculation-heavy data analysis is done in the fortran program shown in this appendix. The program is made to guide the user through the different possible analysis options. The over-all flowchart of the program can be seen in figure H.3. The most time-consuming part of the program is not the actual calculations, but rather the read-in and write-out of datafiles. Hence, the routine onemore top gives the user the possibility to go back and do more with the same datafile, without having to read it in again.

The makefile (called makefile) gives information on how the different fortran files depend on each other, and makes compilation easy. Simply writing make in a terminal positioned in the directory containing the code and makefile, the analysis program will be compiled and be ready to run.

1# compiler
2#FC  = i f o r t
3 FC  = g f o r t r a n
4 FLAGS = −O3
5#FLAGS = −g −O0

6

7# r u l e s f o r making . o out o f . f 9 0
8 . SUFFIXES :
9 . SUFFIXES : . f 9 0 . o
10 . f 9 0 . o :
11  $ (FC) −c $ (FLAGS) $<

12

13# main program l i s t
14 LIST = main . o i o . o d a t a i o . o c h o i c e s . o g l o b a l v a r s . o math . o simplemath . o

15

16# c o n t r o l the c o m p i l a t i o n
17 a n a l y s i s : $ ( LIST )
18  $ (FC) $ (FLAGS) $ ( LIST ) −o a n a l y s i s . x

19

20# cleanup
21 c l e a n :
22  rm −f ∗. o ∗.mod ∗.M

23

24 c l e a n a l l :
25  rm −f ∗. o ∗. x ∗.mod ∗.M

26

27# dependencies
28 main . o :  g l o b a l v a r s . o i o . o d a t a i o . o c h o i c e s . o math . o
29 i o . o :  g l o b a l v a r s . o

Appendix H Source codes  lv

welcome datafile name readdata choice Emax choice what z pl intersec pl intersec out Eout out one more div all div out choice div

see the rest of this part in figure H.4

div out choice conv

see the rest of this part in figure H.5

conv out side intersec side intersec out Eout out onemore top ending

1: plane intersections 2: divergence 3: divergence

on area

4: convolution 5: intersection of sides Yes No No

Yes

Figure H.3: The over-all flowchart for the data analysis program.

30 d a t a i o . o :  g l o b a l v a r s . o i o . o
31 c h o i c e s . o :  g l o b a l v a r s . o
32 math . o :  g l o b a l v a r s . o simplemath . o
33 mathsimple . o :

The main program file (called main.f90) controls the main program loop, and sends the user throught the wanted analysis procedures.

1 !=
2 ! Main program f i l e f o r the data a n a l y s i s program
3 !=

4

5 program a n a l y s i s

6

7 use g l o b a l v a r s  ! g l o b a l v a r i a b l e s
8 use i o  ! input / output r o u t i n e s
9 use c h o i c e s  ! c h o i c e r o u t i n e s
10 use d a t a i o  ! input / output r o u t i n e s f o r data
11 use math  ! c a l c u l a t i o n r o u t i n e s

12

13 c a l l welcome  ! welcome the user to the program
14 c a l l d a t a f i l e n a m e  ! ask f o r the d a t a f i l e name
15 c a l l readdata  ! read data from d a t a f i l e

16

17 do

choice div what z pl intersec choice div2 rect corners

div rect circ options choice div3 div circ div halfcircR div halfcircR simple div halfcircL div halfcircL simple sph intersec choice div4 div sph div halfsphR div halfsphL div out

1: on area 2: from sphere 1: rectangle

2: circle 1 2 3 4 5 1 2

3

Figure H.4: The first part flowchart from the main analysis flowchart in figure H.3, corresponding to the “3: divergence on area” branch after the choice routine.

choice div detec what z pl intersec num of p conv simple detec what z pl intersec num of p conv adv1 conv out

Figure H.5: The second part flowchart from the main analysis flowchart in figure H.3, corresponding to the “4: convolution” branch after the choice routine.

Appendix H Source codes  lvii

18 i f ( runnowtop = ’Y ’ ) then

19

20  c a l l choice Emax  ! p i c k neutrons with c e r t a i n energy
21  c a l l c h o i c e  ! ask what to do with the data

22

23  select case ( a n a l y s i s c h o i c e )

24

25  ! i n t e r s e c t i o n s o f a plane
26  case ( 1 )
27  do
28  i f ( runnow = ’Y ’ ) then
29  c a l l what z  ! ask f o r plane z−v a l u e
30  c a l l p l i n t e r s e c  ! f i n d i n t e r s e c t i o n s o f the plane
31  c a l l p l i n t e r s e c o u t  ! output the i n t e r s e c t i o n v a l u e s
32  c a l l Eout out  ! i f wanted , p r i n t e n e r g i e s to f i l e
33  c a l l one more  ! ask i f i t should be done again
34  e l s e i f ( runnow = ’N ’ ) then
35  exit
36  endif
37  enddo

38

39  ! d i v e r g e n c e o f a l l neutrons
40  case ( 2 )
41  c a l l d i v a l l  ! c a l c d i v e r g e n c e o f a l l neutrons
42  c a l l d i v o u t  ! output the d i v e r g e n c e v a l u e s

43

44  ! d i v e r g e n c e o f neutrons coming from or e n t e r i n g c e r t a i n areas
45  case ( 3 )
46 c a l l c h o i c e d i v ! ask what kind o f d i v c a l c
47  select case ( a n a l y s i s c h o i c e )

48

49  ! d i v e r g e n c e o f neutrons i n t e r s e c t i n g an area on a plane
50  case ( 1 )
51  c a l l what z  ! ask f o r plane z−v a l u e
52  c a l l p l i n t e r s e c  ! f i n d i n t e r s e c t i o n s o f the plane

53

54  c a l l c h o i c e d i v 2  ! ask what kind o f i n t e r s e c
55  select case ( a n a l y s i s c h o i c e )

56

57  ! d i v e r g e n c e o f neutrons i n t e r s e c t i n g a r e c t a n g u l a r area
58  case ( 1 )
59  c a l l r e c t c o r n e r s  ! ask f o r r e c t a n g l e p r o p e r t i e s
60  c a l l d i v r e c t  ! c a l c d i v o f neutrons in r e c t

61

62  ! d i v e r g e n c e o f neutrons i n t e r s e c t i n g part o f a c i r c u l a r area
63  case ( 2 )
64  c a l l c i r c o p t i o n s  ! ask f o r c i r c l e p r o p e r t i e s

65

66  c a l l c h o i c e d i v 3  ! ask what part o f c i r c l e
67  select case ( a n a l y s i s c h o i c e )

68

69  ! d i v o f neutrons i n t e r s e c a c i r c u l a r area
70  case ( 1 )
71  c a l l d i v c i r c  ! c a l c d i v o f neutrons in c i r c

72

73  ! d i v o f neutrons i n t e r s e c R h a l f o f a c i r c u l a r area
74  case ( 2 )
75  c a l l d i v h a l f c i r c R  ! c a l c d i v o f neutrons in h a l f c i r c

76

77  ! d i v o f neutrons i n t e r s e c R h a l f o f a c i r c u l a r area ( simple )
78  case ( 3 )

lviii  H.2 Data analysis

79  c a l l d i v h a l f c i r c R s i m p l e ! simple d i v o f neutrons in h a l f c i r c

80

81  ! d i v o f neutrons i n t e r s e c L h a l f o f a c i r c u l a r area
82  case ( 4 )
83  c a l l d i v h a l f c i r c L  ! c a l c d i v o f neutrons in h a l f c i r c

84

85  ! d i v o f neutrons i n t e r s e c L h a l f o f a c i r c u l a r area ( simple )
86  case ( 5 )
87  c a l l d i v h a l f c i r c L s i m p l e ! simple d i v o f neutrons in h a l f c i r c

88

89  end select

90

91  end select

92

93  ! d i v e r g e n c e o f neutrons coming from somewhere in the sphere h o l e
94  case ( 2 )
95  c a l l s p h i n t e r s e c  ! i n t e r s e c o f the output sphere h o l e

96

97  c a l l c h o i c e d i v 4  ! ask what part o f sphere
98  select case ( a n a l y s i s c h o i c e )

99

100  ! d i v o f neutrons coming from sphere h o l e
101  case ( 1 )
102  c a l l div sph  ! c a l c d i v f o r neutrons from sphere

103

104  ! d i v o f neutrons coming from R h a l f o f sphere h o l e
105  case ( 2 )
106  c a l l d i v h a l f s p h R  ! c a l c d i v f o r neutrons from h a l f s p h

107

108  ! d i v o f neutrons coming from L h a l f o f sphere h o l e
109  case ( 3 )
110  c a l l d i v h a l f s p h L  ! c a l c d i v f o r neutrons from h a l f s p h

111

112  end select

113

114  end select
115  c a l l d i v o u t  ! output the d i v v a l u e s

116

117  ! work with c o n v o l u t i o n
118  case ( 4 )
119  c a l l c h o i c e c o n v

120

121  select case ( a n a l y s i s c h o i c e )

122

123  ! simple c o n v o l u t i o n ( count number o f neutrons in d e t e c t o r r e c t a n g l e )
124  case ( 1 )
125  c a l l d e t e c w h a t z  ! ask f o r d e t e c t o r z−v a l u e ( h e i g h t )
126  c a l l p l i n t e r s e c  ! f i n d i n t e r s e c t i o n s o f the plane
127  c a l l num of p  ! ask f o r wanted number o f p o i n t s
128  c a l l conv simple  ! c a l c u l a t e the d a t a p o i n t s

129

130  ! more advanced c o n v o l u t i o n ( removes neutrons t h a t h i t bor−p l a s t )
131  case ( 2 )
132  c a l l detec what z adv1  ! ask f o r d e t e c t o r z−v a l u e s ( h e i g h t )
133  c a l l p l i n t e r s e c  ! f i n d i n t e r s e c t i o n s o f the plane
134  c a l l num of p  ! ask f o r wanted number o f p o i n t s
135  c a l l conv adv1  ! c a l c u l a t e the d a t a p o i n t s

136

137  end select
138  c a l l conv out  ! output the c o n v o l u t i o n data

Appendix H Source codes  lix

140  ! i n t e r s e c t i o n o f moderator s i d e s
141  case ( 5 )
142  c a l l s i d e i n t e r s e c  ! c a l c u l a t e i n t e r s e c t i o n with s i d e s
143  c a l l s i d e i n t e r s e c o u t  ! output the i n t e r s e c t i o n v a l u e s
144  c a l l Eout out  ! i f wanted , p r i n t e n e r g i e s to f i l e

145

146  end select
147  c a l l one moretop  ! ask i f program should be run again

148

149 e l s e i f ( runnowtop = ’N ’ ) then
150  c a l l ending  ! end the program

151

152 endif
153 enddo

154

155 end program a n a l y s i s

The global variables module (called globalvars.f90) defines all variables used globally in the program. If any subroutines need temporary variables, these are defined within the routine, to save memory.

1 !=
2 ! Module c o n t a i n i n g a l l g l o b a l v a r i a b l e s
3 !=

4

5 module g l o b a l v a r s

6

7 implicit none

8

9 real , parameter  : : detec W = 2 9 . 3 , Al W = 2

10

11 integer  : : a n a l y s i s c h o i c e , N f u l l , N, divN , sphN , &
12  intN , numP
13 character  : : runnowtop = ’Y ’ , runnow = ’Y ’ , Espec = ’N ’ , &
14  EoutYN
15 character ( 4 0 )  : : d a t a f i l e , o u t p u t f i l e
16 real  : : z p l , Estart , Etherm , Emin = 0 , Emax = 1E9 , &
17  z b o r

18

19 real , dimension ( 3 )  : : mod , c i r c
20 real , dimension ( 4 )  : : sph , r e c t

21

22 real , dimension ( : ) , allocatable  : : n r f u l l , E f u l l , nr , E
23 real , dimension ( : , : ) , allocatable : : r f u l l , r d i r e c f u l l , r , r d i r e c , pl xy , &
24  div , sph xyz , counter , Eout

25

26 end module g l o b a l v a r s

The primary I/O module (called io.f90) contains subroutines taking care of simple input and output for reading in parameters at runtime.

1 !=
2 ! Module c o n t a i n i n g simple input / output r o u t i n e s
3 !=

4

5 module i o

6

7 use g l o b a l v a r s  ! g l o b a l v a r i a b l e s used throughout program

8

9 contains

10

11 !=

lx  H.2 Data analysis

12 ! I s s u e s a welcome message to the program and s t a r t s t h i n g s

13

14 subroutine welcome

15

16 implicit none

17

18 print ∗, ’ ’
19 print ∗, ’ This i s the a n a l y s i s program f o r the neutron s i m u l a t o r ’
20 print ∗, ’− ’
21 print ∗, ’ ’

22

23 end subroutine welcome

24

25 !=
26 ! Reads the name o f the wanted d a t a f i l e

27

28 subroutine d a t a f i l e n a m e

29

30 implicit none

31

32 print ∗, ’What i s your d a t a f i l e c a l l e d ? ’
33 print ∗, ’ ’

34

35 read ( ∗ , ∗) d a t a f i l e

36

37 print ∗, ’ ’

38

39 end subroutine d a t a f i l e n a m e

40

41 !=
42 ! Questioning f o r z−v a l u e o f the plane to work with

43

44 subroutine what z

45

46 implicit none

47

48 print ∗, ’What z−value should the plane be p o s i t i o n e d at ? ’
49 print ∗, ’ ’

50

51 read ( ∗ , ∗) z p l

52

53 print ∗, ’ ’

54

55 end subroutine what z

56

57 !=
58 ! Questioning f o r z−v a l u e o f the d e t e c t o r to work with

59

60 subroutine d e t e c w h a t z

61

62 implicit none

63

64 print ∗, ’ At what h e i g h t i s the a c t u a l d e t e c t o r over the moderator ? ’
65 print ∗, ’ ’

66

67 read ( ∗ , ∗) z p l

68

69 print ∗, ’ ’

70

71 end subroutine d e t e c w h a t z

Appendix H Source codes  lxi

73 !=
74 ! Questioning f o r z−v a l u e o f the d e t e c t o r to work with

75

76 subroutine detec what z adv1

77

78 implicit none

79

80 print ∗, ’ At what h e i g h t i s the a c t u a l d e t e c t o r over the moderator ? ’
81 print ∗, ’ ’

82

83 read ( ∗ , ∗) z p l

84

85 print ∗, ’ ’

86

87 print ∗, ’ At what h e i g h t i s the bor−p l a s t bottom over the moderator ? ’
88 print ∗, ’ ’

89

90 read ( ∗ , ∗) z b o r

91

92 print ∗, ’ ’

93

94 end subroutine detec what z adv1

95

96 !=
97 ! Reading in the corners o f the d i v e r g e n c e r e c t a n g l e

98

99 subroutine r e c t c o r n e r s

100

101 implicit none

102

103 print ∗, ’ P l e a s e g i v e the r e c t a n g l e as xmin , xmax , ymin , ymax : ’
104 print ∗, ’ ’

105

106 read ( ∗ , ∗) r e c t ( 1 ) , r e c t ( 2 ) , r e c t ( 3 ) , r e c t ( 4 )

107

108 print ∗, ’ ’

109

110 end subroutine r e c t c o r n e r s

111

112 !=
113 ! Reading in the o p t i o n s o f the d i v e r g e n c e c i r c l e

114

115 subroutine c i r c o p t i o n s

116

117 implicit none

118

119 print ∗, ’ P l e a s e g i v e the c i r c l e as xcenter , ycenter , r a d i u s : ’
120 print ∗, ’ ’

121

122 read ( ∗ , ∗) c i r c ( 1 ) , c i r c ( 2 ) , c i r c ( 3 )

123

124 print ∗, ’ ’

125

126 end subroutine c i r c o p t i o n s

127

128 !=
129 ! Asking how many d a t a p o i n t s the user wants

130

131 subroutine num of p

132

133 implicit none

lxii  H.2 Data analysis

134

135 print ∗, ’How many d a t a p o i n t s do you want? ’
136 print ∗, ’ ’

137

138 read ( ∗ , ∗) numP

139

140 print ∗, ’ ’

141

142 end subroutine num of p

143

144 !=
145 ! Doing the f i n a l t h i n g s b e f o r e the program s h u t s down

146

147 subroutine o u t f i l e n a m e a s k

148

149 implicit none

150

151 print ∗, ’What should the output f i l e be c a l l e d ? ’
152 print ∗, ’ ’

153

154 read ( ∗ , ∗) o u t p u t f i l e

155

156 print ∗, ’ ’

157

158 end subroutine o u t f i l e n a m e a s k

159

160 !=
161 ! Doing the f i n a l t h i n g s b e f o r e the program s h u t s down

162

163 subroutine ending

164

165 implicit none

166

167 i f ( a l l o c a t e d ( p l x y ) )  deallocate ( p l x y )
168 i f ( a l l o c a t e d ( Eout ) )  deallocate ( Eout )
169 i f ( a l l o c a t e d ( sph xyz ) ) deallocate ( sph xyz )

170

171 deallocate ( n r f u l l , r f u l l , r d i r e c f u l l , E f u l l , nr , r , r d i r e c , E )

172

173 print ∗, ’ Program f i n i s h e d ! ’
174 print ∗, ’ ’

175

176 end subroutine ending

177

178 end module i o

The data I/O module (called dataio.f90) contains subroutines taking care of input and output of data from simulation datafiles and analysis output files.

1 !=
2 ! Module c o n t a i n i n g input / output r o u t i n e s connected to data
3 !=

4

5 module d a t a i o

6

7 use g l o b a l v a r s  ! g l o b a l v a r i a b l e s used throughout program
8 use i o  ! input / output r o u t i n e s

9

10 contains

11

12 !=
13 ! Reading data from the d a t a f i l e

Appendix H Source codes  lxiii

14

15 subroutine readdata

16

17 implicit none
18 integer  : : i , i o s
19 real , dimension ( : , : ) , allocatable : : datatemp
20 real  : : neut num
21 real , dimension ( 6 )  : : headTmp

22

23 i = l e n t r i m ( d a t a f i l e )
24 open( 10 , f i l e=d a t a f i l e ( : i ) , status= ’ old ’ , iostat=i o s )

25

26 i f ( i o s . ne . 0 ) then
27 stop ’ Error reading f i l e ! ’
28 endif

29

30 read ( 10 , ∗ ) mod( 1 )  ! moderator xmax [cm]
31 read ( 10 , ∗ ) mod( 2 )  ! moderator ymax [cm]
32 read ( 10 , ∗ ) mod( 3 )  ! moderator zmax [cm]
33 read ( 10 , ∗ ) sph ( 1 )  ! sphere c e n t e r x [cm]
34 read ( 10 , ∗ ) sph ( 2 )  ! sphere c e n t e r y [cm]
35 read ( 10 , ∗ ) sph ( 3 )  ! sphere c e n t e r z [cm]
36 read ( 10 , ∗ ) sph ( 4 )  ! sphere c e n t e r r [cm]
37 read ( 10 , ∗ ) E s t a r t  ! s t a r t energy o f a l l neutrons [ eV ]
38 read ( 10 , ∗ ) Etherm  ! thermal energy [ eV ]
39 read ( 10 , ∗ ) neut num  ! t o t a l number o f neutrons in d a t a f i l e
40 read ( 10 , ∗ ) headTmp ( 1 )  ! t o t a l number o f neutrons simulated , not saved
41 read ( 10 , ∗ ) headTmp ( 2 )  ! output f o r debugging purposes , not saved
42 read ( 10 , ∗ ) headTmp ( 3 )  ! output f o r debugging purposes , not saved
43 read ( 10 , ∗ ) headTmp ( 4 )  ! output f o r debugging purposes , not saved
44 read ( 10 , ∗ ) headTmp ( 5 )  ! output f o r debugging purposes , not saved
45 read ( 10 , ∗ ) headTmp ( 6 )  ! output f o r debugging purposes , not saved

46

47 N f u l l = i n t ( neut num )
48 ! N f u l l = 20  ! i f fewer p o i n t s i s wanted ( f o r t e s t i n g purposes )

49

50 allocate ( datatemp (11 , N f u l l ) , n r f u l l ( N f u l l ) , r f u l l ( 3 , N f u l l ) , &
51  r d i r e c f u l l ( 3 , N f u l l ) , E f u l l ( N f u l l ) )

52

53 read ( 10 , ∗ ) datatemp  ! temporary data array

54

55 close ( 1 0 )

56

57 n r f u l l ( : )  = datatemp ( 1 , : )  ! neutron number
58 r f u l l ( 1 , : )  = datatemp ( 2 , : )  ! p o s i t i o n x
59 r f u l l ( 2 , : )  = datatemp ( 3 , : )  ! p o s i t i o n y
60 r f u l l ( 3 , : )  = datatemp ( 4 , : )  ! p o s i t i o n z
61 r d i r e c f u l l ( 1 , : ) = datatemp ( 5 , : )  ! d i r e c t i o n x
62 r d i r e c f u l l ( 2 , : ) = datatemp ( 6 , : )  ! d i r e c t i o n y
63 r d i r e c f u l l ( 3 , : ) = datatemp ( 7 , : )  ! d i r e c t i o n z
64 E f u l l ( : )  = datatemp ( 8 , : )  ! neutron f i n a l energy

65

66 deallocate ( datatemp )

67

68 end subroutine readdata

69

70 !=
71 ! Asks what energy i n t e r v a l should be used and makes the corresponding arrays

72

73 subroutine choice Emax

lxiv  H.2 Data analysis

75 implicit none
76 integer  : : i
77 real , dimension ( : ) , allocatable  : : nrtemp , Etemp
78 real , dimension ( : , : ) , allocatable : : rtemp , r d i r e c t e m p

79

80 print ∗, ’Do you want to work with only a c e r t a i n energy i n t e r v a l ? (Y) es or (N) o ’
81 print ∗, ’ ’

82

83 read ( ∗ , ∗) Espec

84

85 print ∗, ’ ’

86

87 i f ( Espec = ’Y ’ ) then
88 print ∗, ’ Then g i v e the energy i n t e r v a l as Emin , Emax : ’
89 print ∗, ’ ’

90

91 read ( ∗ , ∗) Emin , Emax

92

93 print ∗, ’ ’

94

95 allocate ( nrtemp ( N f u l l ) , rtemp ( 3 , N f u l l ) , r d i r e c t e m p ( 3 , N f u l l ) , &
96  Etemp( N f u l l ) )  ! note N f u l l i s a max

97

98 N = 0
99 do i = 1 , N f u l l
100  i f ( E f u l l ( i ) . ge . Emin . and . E f u l l ( i ) . l e . Emax ) then
101  N = N + 1
102  nrtemp (N)  = n r f u l l ( i )  ! neutron number
103  rtemp ( : ,N)  = r f u l l ( : , i )  ! p o s i t i o n
104  r d i r e c t e m p ( : ,N) = r d i r e c f u l l ( : , i )  ! d i r e c t i o n
105  Etemp(N)  = E f u l l ( i )  ! neutron f i n a l energy
106  endif
107 enddo

108

109 allocate ( nr (N) , r ( 3 ,N) , r d i r e c ( 3 ,N) , E(N) )
110 nr ( : )  = nrtemp ( 1 :N)  ! neutron number
111 r ( : , : )  = rtemp ( : , 1 :N)  ! p o s i t i o n
112 r d i r e c ( : , : ) = r d i r e c t e m p ( : , 1 :N)  ! d i r e c t i o n
113 E ( : ) = Etemp ( 1 :N) ! neutron f i n a l energy
114 deallocate ( nrtemp , rtemp , r directemp , Etemp )

115

116 else i f ( Espec = ’N ’ ) then
117 N = N f u l l

118

119 allocate ( nr (N) , r ( 3 ,N) , r d i r e c ( 3 ,N) , E(N) )
120 nr  = n r f u l l  ! neutron number
121 r  = r f u l l  ! p o s i t i o n
122 r d i r e c = r d i r e c f u l l  ! d i r e c t i o n
123 E = E f u l l ! neutron f i n a l energy
124 else
125 stop ’ Error , you should choose e i t h e r Y or N! ’
126 endif

127

128 end subroutine choice Emax

129

130 !=
131 ! Output i n t e r s e c t i o n data

132

133 subroutine p l i n t e r s e c o u t

134

135 implicit none

Appendix H Source codes  lxv

136 integer : : i , k , i o s

137

138 c a l l o u t f i l e n a m e a s k

139

140 i = l e n t r i m ( o u t p u t f i l e )
141 open( 10 , f i l e=o u t p u t f i l e ( : i ) , status= ’ new ’ , iostat=i o s )

142

143 i f ( i o s . ne . 0 ) then
144 stop ’ Error c r e a t i n g f i l e ! ’
145 endif

146

147 write ( 1 0 , ∗) , z p l

148

149 do k = 1 ,N
150 write ( 1 0 , ∗) , p l x y ( : , k )
151 enddo

152

153 close ( 1 0 )
154 deallocate ( p l x y )

155

156 end subroutine p l i n t e r s e c o u t

157

158 !=
159 ! Output energy data

160

161 subroutine Eout out

162

163 implicit none
164 integer : : i , k , i o s

165

166 print ∗, ’ Should the energy o f the neutrons be w r i t t e n to a f i l e ? (Y) es or (N) o ’
167 print ∗, ’ ’

168

169 read ( ∗ , ∗) EoutYN

170

171 print ∗, ’ ’

172

173 i f ( EoutYN = ’Y ’ ) then
174 c a l l o u t f i l e n a m e a s k

175

176 i = l e n t r i m ( o u t p u t f i l e )
177 open( 10 , f i l e=o u t p u t f i l e ( : i ) , status= ’ new ’ , iostat=i o s )

178

179 i f ( i o s . ne . 0 ) then
180  stop ’ Error c r e a t i n g f i l e ! ’
181 endif

182

183 do k = 1 ,N
184  write ( 1 0 , ∗) , Eout ( : , k )
185 enddo

186

187 close ( 1 0 )
188 deallocate ( Eout )

189

190 else i f ( EoutYN . ne . ’Y ’ . and . EoutYN . ne . ’N ’ ) then
191 stop ’ Error , you should choose e i t h e r Y or N! ’
192 endif

193

194 end subroutine Eout out

195

196 !=

lxvi  H.2 Data analysis

197 ! Output d i v e r g e n c e data

198

199 subroutine d i v o u t

200

201 implicit none

202

203 integer : : i , k , i o s

204

205 c a l l o u t f i l e n a m e a s k

206

207 i = l e n t r i m ( o u t p u t f i l e )
208 open( 10 , f i l e=o u t p u t f i l e ( : i ) , status= ’ new ’ , iostat=i o s )

209

210 i f ( i o s . ne . 0 ) then
211 stop ’ Error c r e a t i n g f i l e ! ’
212 endif

213

214 write ( 1 0 , ∗) , z p l

215

216 do k = 1 , divN
217 write ( 1 0 , ∗) , div ( : , k )
218 enddo

219

220 close ( 1 0 )
221 deallocate ( div )

222

223 end subroutine d i v o u t

224

225 !=
226 ! Output c o n v o l u t i o n data

227

228 subroutine conv out

229

230 implicit none

231

232 integer : : i , k , i o s

233

234 c a l l o u t f i l e n a m e a s k

235

236 i = l e n t r i m ( o u t p u t f i l e )
237 open( 10 , f i l e=o u t p u t f i l e ( : i ) , status= ’ new ’ , iostat=i o s )

238

239 i f ( i o s . ne . 0 ) then
240 stop ’ Error c r e a t i n g f i l e ! ’
241 endif

242

243 do k = 1 ,numP
244 write ( 1 0 , ∗) , counter ( : , k )
245 enddo

246

247 close ( 1 0 )
248 deallocate ( counter )

249

250 end subroutine conv out

251

252 !=
253 ! Output s i d e i n t e r s e c t i o n data

254

255 subroutine s i d e i n t e r s e c o u t

256

257 implicit none

Appendix H Source codes  lxvii

258 integer : : i , k , i o s

259

260 c a l l o u t f i l e n a m e a s k

261

262 i = l e n t r i m ( o u t p u t f i l e )
263 open( 10 , f i l e=o u t p u t f i l e ( : i ) , status= ’ new ’ , iostat=i o s )

264

265 i f ( i o s . ne . 0 ) then
266 stop ’ Error c r e a t i n g f i l e ! ’
267 endif

268

269 do k = 1 , intN
270 write ( 1 0 , ∗) , p l x y ( : , k )
271 enddo

272

273 close ( 1 0 )
274 deallocate ( p l x y )

275

276 end subroutine s i d e i n t e r s e c o u t

277

278 end module d a t a i o

The choices module (called choices.f90) contains all subroutines concerning choices of analysis type through the program run. These subroutines determine where to go next in the main loop.

1 !=
2 ! Module c o n t a i n i n g r o u t i n e s f o r making c h o i c e s
3 !=

4

5 module c h o i c e s

6

7 use g l o b a l v a r s  ! g l o b a l v a r i a b l e s used throughout program

8

9 contains

10

11 !=
12 ! Asks what kind o f a n a l y s i s i s wanted with the d a t a f i l e

13

14 subroutine c h o i c e

15

16 implicit none

17

18 print ∗, ’What kind o f a n a l y s i s do you want? ’
19 print ∗, ’ ’
20 print ∗, ’ 1 . I n t e r s e c t i o n s o f a plane ’
21 print ∗, ’ 2 . Divergence o f a l l neutrons ’
22 print ∗, ’ 3 . Divergence o f neutrons coming from or e n t e r i n g c e r t a i n a r e a s ’
23 print ∗, ’ 4 . Convolution o f data ’
24 print ∗, ’ 5 . I n t e r s e c t i o n o f moderator s i d e s ’
25 print ∗, ’ ’

26

27 read ( ∗ , ∗) a n a l y s i s c h o i c e

28

29 print ∗, ’ ’

30

31 i f ( a n a l y s i s c h o i c e . ne . 1 . and . a n a l y s i s c h o i c e . ne . 2 . and . &
32  a n a l y s i s c h o i c e . ne . 3 . and . a n a l y s i s c h o i c e . ne . 4 . and . &
33  a n a l y s i s c h o i c e . ne . 5 ) then
34 stop ’ Error , you should choose one o f the o p t i o n s above ! ’
35 endif

36

37 end subroutine c h o i c e

lxviii  H.2 Data analysis

38

39 !=
40 ! Asks what kind o f a n a l y s i s i s wanted f o r the d i v e r g e n c e option

41

42 subroutine c h o i c e d i v

43

44 implicit none

45

46 print ∗, ’What kind o f d i v e r g e n c e a n a l y s i s do you want? ’
47 print ∗, ’ ’
48 print ∗, ’ 1 . Divergence o f neutrons i n t e r s e c t i n g an area on a plane ’
49 print ∗, ’ 2 . Divergence o f neutrons coming from somewhere in the sphere h o l e ’
50 print ∗, ’ ’

51

52 read ( ∗ , ∗) a n a l y s i s c h o i c e

53

54 print ∗, ’ ’

55

56 i f ( a n a l y s i s c h o i c e . ne . 1 . and . a n a l y s i s c h o i c e . ne . 2 ) then
57 stop ’ Error , you should choose one o f the o p t i o n s above ! ’
58 endif

59

60 end subroutine c h o i c e d i v

61

62 !=
63 ! Asks what kind i n t e r s e c t i o n area the program should work with

64

65 subroutine c h o i c e d i v 2

66

67 implicit none

68

69 print ∗, ’What kind o f area should be continued with ? ’
70 print ∗, ’ ’
71 print ∗, ’ 1 . Neutrons i n t e r s e c t i n g a r e c t a n g u l a r area ’
72 print ∗, ’ 2 . Neutrons i n t e r s e c t i n g a c i r c u l a r area ’
73 print ∗, ’ ’

74

75 read ( ∗ , ∗) a n a l y s i s c h o i c e

76

77 print ∗, ’ ’

78

79 i f ( a n a l y s i s c h o i c e . ne . 1 . and . a n a l y s i s c h o i c e . ne . 2 ) then
80 stop ’ Error , you should choose one o f the o p t i o n s above ! ’
81 endif

82

83 end subroutine c h o i c e d i v 2

84

85 !=
86 ! Asks what part o f the c i r c l e t h a t should be l o o k e d at

87

88 subroutine c h o i c e d i v 3

89

90 implicit none

91

92 print ∗, ’ Where on the c i r c l e should the neutrons i n t e r s e c t ? ’
93 print ∗, ’ ’
94 print ∗, ’ 1 . The f u l l c i r c l e ’
95 print ∗, ’ 2 . Only the r i g h t h a l f ’
96 print ∗, ’ 3 . Only the r i g h t h a l f ( simple ) ’
97 print ∗, ’ 4 . Only the l e f t h a l f ’
98 print ∗, ’ 5 . Only the l e f t h a l f ( simple ) ’

Appendix H Source codes  lxix

99 print ∗, ’ ’

100

101 read ( ∗ , ∗) a n a l y s i s c h o i c e

102

103 print ∗, ’ ’

104

105 i f ( a n a l y s i s c h o i c e . ne . 1 . and . a n a l y s i s c h o i c e . ne . 2 . and . &
106  a n a l y s i s c h o i c e . ne . 3 . and . a n a l y s i s c h o i c e . ne . 4 . and . &
107  a n a l y s i s c h o i c e . ne . 5 ) then
108 stop ’ Error , you should choose one o f the o p t i o n s above ! ’
109 endif

110

111 end subroutine c h o i c e d i v 3

112

113 !=
114 ! Asks which neutrons should be worked with

115

116 subroutine c h o i c e d i v 4

117

118 implicit none

119

120 print ∗, ’ Which neutrons should be worked with ? ’
121 print ∗, ’ ’
122 print ∗, ’ 1 . Neutrons coming from the sphere h o l e ’
123 print ∗, ’ 2 . Neutrons coming from the r i g h t h a l f o f the sphere h o l e ’
124 print ∗, ’ 3 . Neutrons coming from the l e f t h a l f o f the sphere h o l e ’
125 print ∗, ’ ’

126

127 read ( ∗ , ∗) a n a l y s i s c h o i c e

128

129 print ∗, ’ ’

130

131 i f ( a n a l y s i s c h o i c e . ne . 1 . and . a n a l y s i s c h o i c e . ne . 2 . and . &
132  a n a l y s i s c h o i c e . ne . 3 ) then
133 stop ’ Error , you should choose one o f the o p t i o n s above ! ’
134 endif

135

136 end subroutine c h o i c e d i v 4

137

138 !=
139 ! Asks what kind o f c o n v o l u t i o n should be done

140

141 subroutine c h o i c e c o n v

142

143 implicit none

144

145 print ∗, ’What kind o f c o n v o l u t i o n do you want to do? ’
146 print ∗, ’ ’
147 print ∗, ’ 1 . Simple c o n v o l u t i o n ’
148 print ∗, ’ 2 . More advanced c o n v o l u t i o n ( remove neutrons h i t t i n g bor−p l a s t ) ’
149 print ∗, ’ ’

150

151 read ( ∗ , ∗) a n a l y s i s c h o i c e

152

153 print ∗, ’ ’

154

155 i f ( a n a l y s i s c h o i c e . ne . 1 . and . a n a l y s i s c h o i c e . ne . 2 ) then
156 stop ’ Error , you should choose one o f the o p t i o n s above ! ’
157 endif

158

159 end subroutine c h o i c e c o n v

lxx  H.2 Data analysis

160

161 !=
162 ! Asking i f the program should do more with the data ( o v e r a l l )

163

164 subroutine one moretop

165

166 implicit none

167

168 print ∗, ’Run program again with the same d a t a f i l e ? (Y) es or (N) o ’
169 print ∗, ’ ’

170

171 read ( ∗ , ∗) runnowtop

172

173 i f ( runnowtop . ne . ’Y ’ . and . runnowtop . ne . ’N ’ ) then
174 stop ’ Error , you should choose e i t h e r Y or N! ’
175 endif

176

177 i f ( runnowtop = ’Y ’ ) then
178 i f ( a l l o c a t e d ( p l x y ) )  deallocate ( p l x y )
179 i f ( a l l o c a t e d ( sph xyz ) ) deallocate ( sph xyz )
180 i f ( a l l o c a t e d ( Eout ) )  deallocate ( Eout )
181 i f ( a l l o c a t e d ( nr ) )  deallocate ( nr )
182 i f ( a l l o c a t e d ( r ) )  deallocate ( r )
183 i f ( a l l o c a t e d ( r d i r e c ) ) deallocate ( r d i r e c )
184 i f ( a l l o c a t e d ( E ) )  deallocate ( E )
185 endif

186

187 print ∗, ’ ’

188

189 end subroutine one moretop

190

191 !=
192 ! Asking i f the program should do more with the data ( i n s i d e plane−loop )

193

194 subroutine one more

195

196 implicit none

197

198 print ∗, ’Run the i n t e r s e c t i o n c a l c u l a t i o n again f o r a new z ? (Y) es or (N) o ’
199 print ∗, ’ ’

200

201 read ( ∗ , ∗) runnow

202

203 i f ( runnow . ne . ’Y ’ . and . runnow . ne . ’N ’ ) then
204 stop ’ Error , you should choose e i t h e r Y or N! ’
205 endif

206

207 print ∗, ’ ’

208

209 end subroutine one more

210

211 end module c h o i c e s

The mathematical module (called math.f90) contains subroutines and functions taking care of doing the actual analysis of the simulation data.

1 !=
2 ! Module c o n t a i n i n g a l l l a r g e r mathematical r o u t i n e s
3 !=

4

5 module math

Appendix H Source codes  lxxi

7 use g l o b a l v a r s  ! g l o b a l v a r i a b l e s used throughout program
8 use simplemath  ! simple c a l c u l a t i o n r o u t i n e s

9

10 contains

11

12 !=
13 ! C a l c u l a t i n g a l l ( x , y ) p o i n t s o f i n t e r s e c t i o n at chosen z

14

15 subroutine p l i n t e r s e c

16

17 implicit none
18 integer : : i

19

20 allocate ( p l x y ( 3 ,N) , Eout ( 2 ,N) )

21

22 do i = 1 ,N
23 p l x y ( 1 , i ) = nr ( i )
24 p l x y ( 2 : 3 , i ) = p l a n e i n t e r s e c z ( r ( : , i ) , r d i r e c ( : , i ) , z p l )
25 Eout ( 1 , i ) = nr ( i )
26 Eout ( 2 , i ) = E( i )
27 enddo

28

29 end subroutine p l i n t e r s e c

30

31 !=
32 ! C a l c u l a t e a l l ( x , y , z ) p o i n t s o f i n t e r s e c t i o n with s p h e r i c a l h o l e

33

34 subroutine s p h i n t e r s e c

35

36 implicit none
37 integer  : : i , i i
38 real , dimension ( : , : ) , allocatable : : sph xyz temp , sph xyz temp2

39

40 allocate ( sph xyz temp ( 4 ,N) , sph xyz temp2 ( 4 ,N) )

41

42 sphN = 0
43 do i = 1 ,N
44 sph xyz temp ( 1 , i ) = nr ( i )
45 sph xyz temp ( 2 : 4 , i ) = s p h i n t e r s e c 1 ( r ( : , i ) , r d i r e c ( : , i ) )

46

47 i f ( sph xyz temp ( 2 , i ) . gt . 0 . 0 1 . and . sph xyz temp ( 3 , i ) . gt . 0 . 0 1 . and . &
48  sph xyz temp ( 4 , i ) . gt . 0 . 0 1 ) then
49  sphN = sphN + 1
50  sph xyz temp2 ( : , sphN ) = sph xyz temp ( : , i )
51 endif
52 enddo

53

54 allocate ( sph xyz ( 4 , sphN ) )
55 sph xyz ( : , 1 : sphN ) = sph xyz temp2 ( : , 1 : sphN )
56 deallocate ( sph xyz temp , sph xyz temp2 )

57

58 end subroutine s p h i n t e r s e c

59

60 !=
61 ! C a l c u l a t i n g a l l d i v e r g e n c i e s

62

63 subroutine d i v a l l

64

65 implicit none
66 integer : : i

lxxii  H.2 Data analysis

68 allocate ( div ( 3 ,N) )

69

70 do i = 1 ,N
71 div ( 1 , i ) = nr ( i )
72 div ( 2 : 3 , i ) = d i v e r g e n c e 1 ( r d i r e c ( : , i ) )
73 enddo

74

75 divN = N

76

77 end subroutine d i v a l l

78

79 !=
80 ! C a l c u l a t i n g d i v e r g e n c i e s o f neutrons i n t e r s e c t i n g a r e c t a n g l e

81

82 subroutine d i v r e c t

83

84 implicit none
85 integer  : : i
86 real , dimension ( : , : ) , allocatable : : divtemp

87

88 allocate ( divtemp ( 5 ,N) )  ! note N i s a max

89

90 divN = 0
91 do i = 1 ,N
92 i f ( p l x y ( 2 , i ) . ge . r e c t ( 1 ) . and . p l x y ( 2 , i ) . l e . r e c t ( 2 ) . and . p l x y ( 3 , i ) &
93  . ge . r e c t ( 3 ) . and . p l x y ( 3 , i ) . l e . r e c t ( 4 ) ) then
94  divN = divN + 1
95  divtemp ( 1 , divN ) = nr ( i )
96  divtemp ( 2 : 3 , divN ) = d i v e r g e n c e 1 ( r d i r e c ( : , i ) )
97  divtemp ( 4 , divN ) = p l x y ( 2 , i )
98  divtemp ( 5 , divN ) = p l x y ( 3 , i )
99 endif
100 enddo

101

102 allocate ( div ( 5 , divN ) )
103 div = divtemp ( : , 1 : divN )
104 deallocate ( divtemp )

105

106 end subroutine d i v r e c t

107

108 !=
109 ! C a l c u l a t i n g d i v e r g e n c i e s o f neutrons i n t e r s e c t i n g a c i r c l e

110

111 subroutine d i v c i r c

112

113 implicit none
114 integer  : : i
115 real , dimension ( : , : ) , allocatable : : divtemp

116

117 allocate ( divtemp ( 5 ,N) )  ! note N i s a max

118

119 divN = 0
120 do i = 1 ,N
121 i f ( s q r t ( ( p l x y ( 2 , i )−c i r c ( 1 ) ) ∗∗2 + ( p l x y ( 3 , i )−c i r c ( 2 ) ) ∗∗2 ) . l e . &
122  c i r c ( 3 ) ) then
123  divN = divN + 1
124  divtemp ( 1 , divN ) = nr ( i )
125  divtemp ( 2 : 3 , divN ) = d i v e r g e n c e 1 ( r d i r e c ( : , i ) )
126  divtemp ( 4 , divN ) = p l x y ( 2 , i )
127  divtemp ( 5 , divN ) = p l x y ( 3 , i )
128 endif

Appendix H Source codes  lxxiii

129 enddo

130

131 allocate ( div ( 5 , divN ) )
132 div = divtemp ( : , 1 : divN )
133 deallocate ( divtemp )

134

135 end subroutine d i v c i r c

136

137 !=
138 ! C a l c u l a t i n g d i v e r g e n c i e s o f neutrons i n t e r s e c t i n g a h a l f −c i r c l e

139

140 subroutine d i v h a l f c i r c R

141

142 implicit none
143 integer  : : i
144 real , dimension ( : , : ) , allocatable : : divtemp

145

146 allocate ( divtemp ( 5 ,N) )  ! note N i s a max

147

148 divN = 0
149 do i = 1 ,N
150 i f ( s q r t ( ( p l x y ( 2 , i )−c i r c ( 1 ) ) ∗∗2 + ( p l x y ( 3 , i )−c i r c ( 2 ) ) ∗∗2 ) . l e . c i r c ( 3 ) &
151  . and . p l x y ( 2 , i ) . ge . c i r c ( 1 ) ) then
152  divN = divN + 1
153  divtemp ( 1 , divN ) = nr ( i )
154  divtemp ( 2 : 3 , divN ) = d i v e r g e n c e 1 ( r d i r e c ( : , i ) )
155  divtemp ( 4 , divN ) = p l x y ( 2 , i )
156  divtemp ( 5 , divN ) = p l x y ( 3 , i )
157 endif
158 enddo

159

160 allocate ( div ( 5 , divN ) )
161 div = divtemp ( : , 1 : divN )
162 deallocate ( divtemp )

163

164 end subroutine d i v h a l f c i r c R

165

166 !=
167 ! C a l c u l a t i n g d i v e r g e n c i e s o f neutrons i n t e r s e c t i n g a h a l f −c i r c l e

168

169 subroutine d i v h a l f c i r c L

170

171 implicit none
172 integer  : : i
173 real , dimension ( : , : ) , allocatable : : divtemp

174

175 allocate ( divtemp ( 5 ,N) )  ! note N i s a max

176

177 divN = 0
178 do i = 1 ,N
179 i f ( s q r t ( ( p l x y ( 2 , i )−c i r c ( 1 ) ) ∗∗2 + ( p l x y ( 3 , i )−c i r c ( 2 ) ) ∗∗2 ) . l e . c i r c ( 3 ) &
180  . and . p l x y ( 2 , i ) . l e . c i r c ( 1 ) ) then
181  divN = divN + 1
182  divtemp ( 1 , divN ) = nr ( i )
183  divtemp ( 2 : 3 , divN ) = d i v e r g e n c e 1 ( r d i r e c ( : , i ) )
184  divtemp ( 4 , divN ) = p l x y ( 2 , i )
185  divtemp ( 5 , divN ) = p l x y ( 3 , i )
186 endif
187 enddo

188

189 allocate ( div ( 5 , divN ) )

lxxiv  H.2 Data analysis

190 div = divtemp ( : , 1 : divN )
191 deallocate ( divtemp )

192

193 end subroutine d i v h a l f c i r c L

194

195 !=
196 ! C a l c u l a t i n g d i v e r g e n c i e s ( not a n g l e s ) o f neutrons i n t e r s e c t i n g a h a l f −c i r c l e

197

198 subroutine d i v h a l f c i r c R s i m p l e

199

200 implicit none
201 integer  : : i
202 real , dimension ( : , : ) , allocatable : : divtemp

203

204 allocate ( divtemp ( 5 ,N) )  ! note N i s a max

205

206 divN = 0
207 do i = 1 ,N
208 i f ( s q r t ( ( p l x y ( 2 , i )−c i r c ( 1 ) ) ∗∗2 + ( p l x y ( 3 , i )−c i r c ( 2 ) ) ∗∗2 ) . l e . c i r c ( 3 ) &
209  . and . p l x y ( 2 , i ) . ge . c i r c ( 1 ) ) then
210  divN = divN + 1
211  divtemp ( 1 , divN ) = nr ( i )
212  divtemp ( 2 , divN ) = r d i r e c ( 1 , i )
213  divtemp ( 3 , divN ) = r d i r e c ( 2 , i )
214  divtemp ( 4 , divN ) = p l x y ( 2 , i )
215  divtemp ( 5 , divN ) = p l x y ( 3 , i )
216 endif
217 enddo

218

219 allocate ( div ( 5 , divN ) )
220 div = divtemp ( : , 1 : divN )
221 deallocate ( divtemp )

222

223 end subroutine d i v h a l f c i r c R s i m p l e

224

225 !=
226 ! C a l c u l a t i n g d i v e r g e n c i e s ( not a n g l e s ) o f neutrons i n t e r s e c t i n g a h a l f −c i r c l e

227

228 subroutine d i v h a l f c i r c L s i m p l e

229

230 implicit none
231 integer  : : i
232 real , dimension ( : , : ) , allocatable : : divtemp

233

234 allocate ( divtemp ( 5 ,N) )  ! note N i s a max

235

236 divN = 0
237 do i = 1 ,N
238 i f ( s q r t ( ( p l x y ( 2 , i )−c i r c ( 1 ) ) ∗∗2 + ( p l x y ( 3 , i )−c i r c ( 2 ) ) ∗∗2 ) . l e . c i r c ( 3 ) &
239  . and . p l x y ( 2 , i ) . l e . c i r c ( 1 ) ) then
240  divN = divN + 1
241  divtemp ( 1 , divN ) = nr ( i )
242  divtemp ( 2 , divN ) = r d i r e c ( 1 , i )
243  divtemp ( 3 , divN ) = r d i r e c ( 2 , i )
244  divtemp ( 4 , divN ) = p l x y ( 2 , i )
245  divtemp ( 5 , divN ) = p l x y ( 3 , i )
246 endif
247 enddo

248

249 allocate ( div ( 5 , divN ) )
250 div = divtemp ( : , 1 : divN )

Appendix H Source codes  lxxv

251 deallocate ( divtemp )

252

253 end subroutine d i v h a l f c i r c L s i m p l e

254

255 !=
256 ! C a l c u l a t e d i v e r g e n c i e s f o r neutrons coming from h a l f o f the s p h e r i c a l h o l e

257

258 subroutine div sph

259

260 implicit none
261 integer  : : i
262 real , dimension ( : , : ) , allocatable : : divtemp

263

264 allocate ( divtemp ( 6 , sphN ) )  ! note sphN i s a max

265

266 divN = 0
267 do i = 1 , sphN
268 i f ( sph xyz ( 4 , i ) . l e . mod( 3 ) ) then
269  divN = divN + 1
270  divtemp ( 1 , divN ) = sph xyz ( 1 , i )
271  divtemp ( 2 : 3 , divN ) = d i v e r g e n c e 1 ( r d i r e c ( : , i ) )
272  divtemp ( 4 : 6 , divN ) = sph xyz ( 2 : 4 , i )
273 endif
274 enddo

275

276 allocate ( div ( 6 , divN ) )
277 div = divtemp ( : , 1 : divN )
278 deallocate ( divtemp )

279

280 end subroutine div sph

281

282 !=
283 ! C a l c u l a t e d i v e r g e n c i e s f o r neutrons coming from h a l f o f the s p h e r i c a l h o l e

284

285 subroutine d i v h a l f s p h R

286

287 implicit none
288 integer  : : i
289 real , dimension ( : , : ) , allocatable : : divtemp

290

291 allocate ( divtemp ( 6 , sphN ) )  ! note sphN i s a max

292

293 divN = 0
294 do i = 1 , sphN
295 i f ( sph xyz ( 4 , i ) . l e . mod( 3 ) . and . sph xyz ( 2 , i ) . ge . sph ( 1 ) ) then
296  divN = divN + 1
297  divtemp ( 1 , divN ) = sph xyz ( 1 , i )
298  divtemp ( 2 : 3 , divN ) = d i v e r g e n c e 1 ( r d i r e c ( : , i ) )
299  divtemp ( 4 : 6 , divN ) = sph xyz ( 2 : 4 , i )
300 endif
301 enddo

302

303 allocate ( div ( 6 , divN ) )
304 div = divtemp ( : , 1 : divN )
305 deallocate ( divtemp )

306

307 end subroutine d i v h a l f s p h R

308

309 !=
310 ! C a l c u l a t e d i v e r g e n c i e s f o r neutrons coming from h a l f o f the s p h e r i c a l h o l e

lxxvi  H.2 Data analysis

312 subroutine d i v h a l f s p h L

313

314 implicit none
315 integer  : : i
316 real , dimension ( : , : ) , allocatable : : divtemp

317

318 allocate ( divtemp ( 6 , sphN ) )  ! note sphN i s a max

319

320 divN = 0
321 do i = 1 , sphN
322 i f ( sph xyz ( 4 , i ) . l e . mod( 3 ) . and . sph xyz ( 2 , i ) . l e . sph ( 1 ) ) then
323  divN = divN + 1
324  divtemp ( 1 , divN ) = sph xyz ( 1 , i )
325  divtemp ( 2 : 3 , divN ) = d i v e r g e n c e 1 ( r d i r e c ( : , i ) )
326  divtemp ( 4 : 6 , divN ) = sph xyz ( 2 : 4 , i )
327 endif
328 enddo

329

330 allocate ( div ( 6 , divN ) )
331 div = divtemp ( : , 1 : divN )
332 deallocate ( divtemp )

333

334 end subroutine d i v h a l f s p h L

335

336 !=
337 ! C a l c u l a t e simple c o n v o l u t i o n ( count number o f neutrons in d e t e c t o r r e c t a n g l e )

338

339 subroutine conv simple

340

341 implicit none
342 integer : : i , j
343 real  : : d , detec xmin , detec xmax , detec ymin , detec ymax

344

345 allocate ( counter ( 2 ,numP) )

346

347 d = ( mod( 1 ) − detec W ) / ( real (nump−1) )

348

349 do i = 1 , numP
350 counter ( 1 , i ) = detec W / 2 . + ( i −1)∗d
351 counter ( 2 , i ) = 0

352

353 detec xmin = counter ( 1 , i ) − detec W / 2 .
354 detec xmax = counter ( 1 , i ) + detec W / 2 .
355 detec ymin = mod( 2 ) / 2 . − detec W / 2 .
356 detec ymax = mod( 2 ) / 2 . + detec W / 2 .

357

358 do j = 1 , N
359  i f ( p l x y ( 2 , j ) . ge . detec xmin+Al W . and . p l x y ( 2 , j ) . l e . &
360  detec xmax−Al W . and . p l x y ( 3 , j ) . ge . detec ymin+Al W . and . &
361  p l x y ( 3 , j ) . l e . detec ymax−Al W ) then
362  counter ( 2 , i ) = counter ( 2 , i ) + 1
363  endif
364 enddo
365 enddo

366

367 end subroutine conv simple

368

369 !=
370 ! C a l c u l a t e advanced c o n v o l u t i o n ( number o f neutrons g e t t i n g p a s t bor−p l a s t )

371

372 subroutine conv adv1

Appendix H Source codes  lxxvii

373

374 implicit none
375 integer  : : i , j , i n t e r s e c
376 real  : : d , detec xmin , detec xmax , detec ymin , detec ymax , u
377 real , dimension ( 3 ) : : r t e s t

378

379 allocate ( counter ( 2 ,numP) )

380

381 d = ( mod( 1 ) − detec W ) / ( real (nump−1) )

382

383 do i = 1 , numP
384 counter ( 1 , i ) = detec W / 2 . + ( i −1)∗d
385 counter ( 2 , i ) = 0

386

387 detec xmin = counter ( 1 , i ) − detec W / 2 .
388 detec xmax = counter ( 1 , i ) + detec W / 2 .
389 detec ymin = mod( 2 ) / 2 . − detec W / 2 .
390 detec ymax = mod( 2 ) / 2 . + detec W / 2 .

391

392 do j = 1 , N
393  i f ( p l x y ( 2 , j ) . ge . detec xmin+Al W . and . p l x y ( 2 , j ) . l e . &
394  detec xmax−Al W . and . p l x y ( 3 , j ) . ge . detec ymin+Al W . and . &
395  p l x y ( 3 , j ) . l e . detec ymax−Al W ) then

396

397  i n t e r s e c = 0

398

399  i f ( r d i r e c ( 1 , j ) . ne . 0 . ) then
400  u = ( detec xmin − r ( 1 , j ) ) / r d i r e c ( 1 , j )
401  r t e s t ( : ) = r ( : , j ) + u ∗ r d i r e c ( : , j )
402  i f ( r t e s t ( 2 ) . ge . detec ymin . and . r t e s t ( 2 ) . l e . detec ymax . and . &
403  r t e s t ( 3 ) . ge . z b o r . and . r t e s t ( 3 ) . l e . z p l ) then
404  i n t e r s e c = i n t e r s e c + 1
405  endif
406  u = ( detec xmax − r ( 1 , j ) ) / r d i r e c ( 1 , j )
407  r t e s t ( : ) = r ( : , j ) + u ∗ r d i r e c ( : , j )
408  i f ( r t e s t ( 2 ) . ge . detec ymin . and . r t e s t ( 2 ) . l e . detec ymax . and . &
409  r t e s t ( 3 ) . ge . z b o r . and . r t e s t ( 3 ) . l e . z p l ) then
410  i n t e r s e c = i n t e r s e c + 1
411  endif
412  endif

413

414  i f ( r d i r e c ( 2 , j ) . ne . 0 . ) then
415  u = ( detec ymin − r ( 2 , j ) ) / r d i r e c ( 2 , j )
416  r t e s t ( : ) = r ( : , j ) + u ∗ r d i r e c ( : , j )
417  i f ( r t e s t ( 1 ) . ge . detec xmin . and . r t e s t ( 1 ) . l e . detec xmax . and . &
418  r t e s t ( 3 ) . ge . z b o r . and . r t e s t ( 3 ) . l e . z p l ) then
419  i n t e r s e c = i n t e r s e c + 1
420  endif
421  u = ( detec ymax − r ( 2 , j ) ) / r d i r e c ( 2 , j )
422  r t e s t ( : ) = r ( : , j ) + u ∗ r d i r e c ( : , j )
423  i f ( r t e s t ( 1 ) . ge . detec xmin . and . r t e s t ( 1 ) . l e . detec xmax . and . &
424  r t e s t ( 3 ) . ge . z b o r . and . r t e s t ( 3 ) . l e . z p l ) then
425  i n t e r s e c = i n t e r s e c + 1
426  endif
427  endif

428

429  i f ( i n t e r s e c = 0 ) then
430  counter ( 2 , i ) = counter ( 2 , i ) + 1
431  endif
432  endif
433 enddo

lxxviii  H.2 Data analysis

434 enddo

435

436 end subroutine conv adv1

437

438 !=
439 ! C a l c u l a t i n g a l l p o i n t s o f i n t e r s e c t i o n at moderator s i d e s

440

441 subroutine s i d e i n t e r s e c

442

443 implicit none
444 integer  : : i
445 real , dimension ( 3 )  : : Ptmp1 , Ptmp2 , Ptmp3 , Ptmp4
446 real , dimension ( : , : ) , allocatable : : pl xytemp , Eouttemp

447

448 allocate ( pl xytemp ( 4 ,N) , Eouttemp ( 2 ,N) )  ! note N i s a max

449

450 intN = 0
451 do i = 1 ,N
452 Ptmp1 = p l a n e i n t e r s e c x ( r ( : , i ) , r d i r e c ( : , i ) , mod( 1 ) +0.1 )
453 Ptmp2 = p l a n e i n t e r s e c y ( r ( : , i ) , r d i r e c ( : , i ) , mod( 2 ) +0.1 )
454 Ptmp3 = p l a n e i n t e r s e c x ( r ( : , i ) , r d i r e c ( : , i ) , −0.1 )
455 Ptmp4 = p l a n e i n t e r s e c y ( r ( : , i ) , r d i r e c ( : , i ) , −0.1 )

456

457 i f ( Ptmp1 ( 3 ) > 0 . and . Ptmp1 ( 1 ) >= 0 . and . Ptmp1 ( 1 ) <= mod( 2 ) . and . &
458  Ptmp1 ( 2 ) >= 0 . and . Ptmp1 ( 2 ) <= mod( 3 ) ) then
459  intN = intN + 1
460  pl xytemp ( 1 , intN ) = nr ( i )
461  pl xytemp ( 2 : 3 , intN ) = Ptmp1 ( 1 : 2 )
462  pl xytemp ( 4 , intN ) = 1
463  Eouttemp ( 1 , intN ) = nr ( i )
464  Eouttemp ( 2 , intN ) = E( i )

465

466 e l s e i f ( Ptmp2 ( 3 ) > 0 . and . Ptmp2 ( 1 ) >= 0 . and . Ptmp2 ( 1 ) <= mod( 1 ) . and . &
467  Ptmp2 ( 2 ) >= 0 . and . Ptmp2 ( 2 ) <= mod( 3 ) ) then
468  intN = intN + 1
469  pl xytemp ( 1 , intN ) = nr ( i )
470  pl xytemp ( 2 : 3 , intN ) = Ptmp2 ( 1 : 2 )
471  pl xytemp ( 4 , intN ) = 2
472  Eouttemp ( 1 , intN ) = nr ( i )
473  Eouttemp ( 2 , intN ) = E( i )

474

475 e l s e i f ( Ptmp3 ( 3 ) > 0 . and . Ptmp3 ( 1 ) >= 0 . and . Ptmp3 ( 1 ) <= mod( 2 ) . and . &
476  Ptmp3 ( 2 ) >= 0 . and . Ptmp3 ( 2 ) <= mod( 3 ) ) then
477  intN = intN + 1
478  pl xytemp ( 1 , intN ) = nr ( i )
479  pl xytemp ( 2 : 3 , intN ) = Ptmp3 ( 1 : 2 )
480  pl xytemp ( 4 , intN ) = 3
481  Eouttemp ( 1 , intN ) = nr ( i )
482  Eouttemp ( 2 , intN ) = E( i )

483

484 e l s e i f ( Ptmp4 ( 3 ) > 0 . and . Ptmp4 ( 1 ) >= 0 . and . Ptmp4 ( 1 ) <= mod( 1 ) . and . &
485  Ptmp4 ( 2 ) >= 0 . and . Ptmp4 ( 2 ) <= mod( 3 ) ) then
486  intN = intN + 1
487  pl xytemp ( 1 , intN ) = nr ( i )
488  pl xytemp ( 2 : 3 , intN ) = Ptmp4 ( 1 : 2 )
489  pl xytemp ( 4 , intN ) = 4
490  Eouttemp ( 1 , intN ) = nr ( i )
491  Eouttemp ( 2 , intN ) = E( i )

492

493 endif

Appendix H Source codes  lxxix

495 enddo

496

497 allocate ( p l x y ( 4 , intN ) , Eout ( 2 , intN ) )
498 p l x y ( : , : ) = pl xytemp ( : , 1 : intN )
499 Eout ( : , : ) = Eouttemp ( : , 1 : intN )
500 deallocate ( pl xytemp , Eouttemp )

501

502 end subroutine s i d e i n t e r s e c

503

504 !=
505 ! C a l c u l a t e i n t e r s e c t i o n at chosen x f o r a s i n g l e neutron

506

507 function p l a n e i n t e r s e c x ( pos , d i r e c , planex )

508

509 implicit none
510 real  : : planex , u
511 real , dimension ( 3 ) : : p l a n e i n t e r s e c x
512 real , dimension ( 3 ) : : pos , d i r e c

513

514 u = ( planex − pos ( 1 ) ) /( d i r e c ( 1 ) )
515 p l a n e i n t e r s e c x ( 1 ) = pos ( 2 ) + u ∗ d i r e c ( 2 )
516 p l a n e i n t e r s e c x ( 2 ) = pos ( 3 ) + u ∗ d i r e c ( 3 )
517 p l a n e i n t e r s e c x ( 3 ) = u

518

519 end function p l a n e i n t e r s e c x

520

521 !=
522 ! C a l c u l a t e i n t e r s e c t i o n at chosen y f o r a s i n g l e neutron

523

524 function p l a n e i n t e r s e c y ( pos , d i r e c , planey )

525

526 implicit none
527 real  : : planey , u
528 real , dimension ( 3 ) : : p l a n e i n t e r s e c y
529 real , dimension ( 3 ) : : pos , d i r e c

530

531 u = ( planey − pos ( 2 ) ) /( d i r e c ( 2 ) )
532 p l a n e i n t e r s e c y ( 1 ) = pos ( 1 ) + u ∗ d i r e c ( 1 )
533 p l a n e i n t e r s e c y ( 2 ) = pos ( 3 ) + u ∗ d i r e c ( 3 )
534 p l a n e i n t e r s e c y ( 3 ) = u

535

536 end function p l a n e i n t e r s e c y

537

538 !=
539 ! C a l c u l a t e i n t e r s e c t i o n at chosen z f o r a s i n g l e neutron

540

541 function p l a n e i n t e r s e c z ( pos , d i r e c , planez )

542

543 implicit none
544 real  : : planez , u
545 real , dimension ( 2 ) : : p l a n e i n t e r s e c z
546 real , dimension ( 3 ) : : pos , d i r e c

547

548 u = ( planez − pos ( 3 ) ) /( d i r e c ( 3 ) )
549 p l a n e i n t e r s e c z ( 1 ) = pos ( 1 ) + u ∗ d i r e c ( 1 )
550 p l a n e i n t e r s e c z ( 2 ) = pos ( 2 ) + u ∗ d i r e c ( 2 )

551

552 end function p l a n e i n t e r s e c z

553

554 !=
555 ! C a l c u l a t e xyz i n t e r s e c t i o n o f the s p h e r i c a l h o l e

lxxx  H.2 Data analysis

556

557 function s p h i n t e r s e c 1 ( pos , d i r e c )

558

559 implicit none
560 real , dimension ( 3 ) : : pos , d i r e c , s p h i n t e r s e c 1 , P1 , P2 ! , I1 , I2
561 real  : : a , b , c , u1 , u2

562

563 P1 = pos
564 P2 = pos + d i r e c

565

566 a = ( P2 ( 1 ) − P1 ( 1 ) ) ∗∗2 + ( P2 ( 2 ) − P1 ( 2 ) ) ∗∗2 + ( P2 ( 3 ) − P1 ( 3 ) ) ∗∗2
567 b = 2∗( ( P2 ( 1 ) − P1 ( 1 ) ) ∗ ( P1 ( 1 ) − sph ( 1 ) ) + &
568  ( P2 ( 2 ) − P1 ( 2 ) ) ∗ ( P1 ( 2 ) − sph ( 2 ) ) + &
569  ( P2 ( 3 ) − P1 ( 3 ) ) ∗ ( P1 ( 3 ) − sph ( 3 ) ) )
570 c = sph ( 1 ) ∗∗2 + sph ( 2 ) ∗∗2 + sph ( 3 ) ∗∗2 + P1 ( 1 ) ∗∗2 + P1 ( 2 ) ∗∗2 + P1 ( 3 ) ∗∗2 &
571  − 2 . ∗ ( sph ( 1 ) ∗P1 ( 1 ) + sph ( 2 ) ∗P1 ( 2 ) + sph ( 3 ) ∗P1 ( 3 ) ) − ( sph ( 4 ) −0.01) ∗∗2

572

573 i f ( b∗∗2 − 4 . ∗ a∗ c . gt . 0 ) then  ! polynomial have a s o l u t i o n
574 u1 = ( −b − s q r t ( b∗∗2 − 4 . ∗ a∗ c ) ) / ( 2 . ∗ a )
575 u2 = ( −b + s q r t ( b∗∗2 − 4 . ∗ a∗ c ) ) / ( 2 . ∗ a )

576

577 i f ( u1 . gt . 0 . and . u2 . gt . 0 ) then  ! i n t e r s e c t i o n s are in forward time
578 i f ( u1 . l t . u2 ) then ! u1 i s f i r s t i n t e r s e c t i o n
579  s p h i n t e r s e c 1 = P1 ( : ) + u1 ∗ ( P2 ( : ) − P1 ( : ) )
580 e l s e i f ( u2 . l t . u1 ) then ! u2 i s f i r s t i n t e r s e c t i o n
581  s p h i n t e r s e c 1 = P1 ( : ) + u2 ∗ ( P2 ( : ) − P1 ( : ) )
582  endif
583 else  ! i n t e r s e c t i o n s are not in forward time
584  s p h i n t e r s e c 1 ( 1 ) = 0
585  s p h i n t e r s e c 1 ( 2 ) = 0
586  s p h i n t e r s e c 1 ( 3 ) = 0
587 endif
588 else  ! polynomial doesn ’ t have a s o l u t i o n
589 s p h i n t e r s e c 1 ( 1 ) = 0
590 s p h i n t e r s e c 1 ( 2 ) = 0
591 s p h i n t e r s e c 1 ( 3 ) = 0
592 endif

593

594 end function s p h i n t e r s e c 1

595

596 !=
597 ! C a l c u l a t e d i v e r g e n c e f o r a s i n g l e neutron

598

599 function d i v e r g e n c e 1 ( d i r e c )

600

601 implicit none
602 real , dimension ( 2 ) : : divergence1 , xy
603 real , dimension ( 3 ) : : d i r e c

604

605 xy ( 1 ) = d i r e c ( 1 )  ! x− and y−component o f d i r e c t i o n in one v e c t o r
606 xy ( 2 ) = d i r e c ( 2 )

607

608 d i v e r g e n c e 1 ( 1 ) = d i r e c ( 1 ) / length2 ( xy ) ∗ acos ( d i r e c ( 3 ) / length3 ( d i r e c ) )
609 d i v e r g e n c e 1 ( 2 ) = d i r e c ( 2 ) / length2 ( xy ) ∗ acos ( d i r e c ( 3 ) / length3 ( d i r e c ) )

610

611 end function d i v e r g e n c e 1

612

613 end module math

The simple mathematical module (called simplemath.f90) contains functions with simple arithmetic mathematical functions, used in the mathematical module above.

1 !=
2 ! Module c o n t a i n i n g a l l simple mathematical f u n c t i o n s
3 !=

4

5 module simplemath

6

7 contains

8

9 !=
10 ! C a l c u l a t i n g the l e n g t h o f a 2D v e c t o r

11

12 function length2 ( vec )

13

14 implicit none
15 real , dimension ( 2 ) : : vec
16 real  : : length2

17

18 length2 = s q r t ( vec ( 1 ) ∗∗2 + vec ( 2 ) ∗∗2 )

19

20 end function length2

21

22 !=
23 ! C a l c u l a t i n g the l e n g t h o f a 3D v e c t o r

24

25 function length3 ( vec )

26

27 implicit none
28 real , dimension ( 3 ) : : vec
29 real  : : length3

30

31 length3 = s q r t ( vec ( 1 ) ∗∗2 + vec ( 2 ) ∗∗2 + vec ( 3 ) ∗∗2 )

32

33 end function length3

34

35 end module simplemath

H.3 MatLAB scripts

MatLAB is used to do the less calculation-heavy data analysis that the fortran program shown in section H.2 isn’t necessary for. Further, it is used to plot data in a large number of different ways.

Most of the graphs shown in this report, and a lot more that there weren’t room for, are plotted as parts of a single script file. In this script file, data (both the datafile directly from the simulation, and the data from the fortran analysis program) is read in, worked with, and plotted. To only have to code things once, most of the actual code is done in functions, which are then called with appropriate input parameters in the script. The script is shown below. It should be easy to adapt the script to do any needed new plotting.

1%% I n i t i a l o p t i o n s

2

3% Clear screen , o l d v a r i a b l e s , e t c .
4 clc
5 clear a l l
6 close a l l

7

8% Set path to f u n c t i o n d i r e c t o r y
9 path backup = path ;
10 path ( path backup , ’ f u n c t i o n s ’ )

11

12% Data d i r e c t o r i e s

lxxxii  H.3 MatLAB scripts

13 dd data = ’ . . / . . / data / measurements / ’ ;
14 dd path = ’ . . / . . / data / paths / ’ ;
15 dd s1 = ’ . . / . . / data / sim / sph1 / ’ ;
16 dd s2 = ’ . . / . . / data / sim / sph2 / ’ ;
17 d d f  = ’ . . / . . / data / sim / f l a t / ’ ;

18

19%% Read in s i m u l a t i o n data

20

21% Number o f d a t a p o i n t s to read in from the main d a t a f i l e s
22 n r e a d i n s 1 = 1000000;
23 n r e a d i n s 2 = 1000000;
24 n r e a d i n f = 1000000;

25

26% Read in from s i m u l a t i o n d a t a f i l e s
27 [ opt s1 , d a t a s 1 ] = read data ( [ dd s1 , ’ data ’ ] , 1 , n r e a d i n s 1 ) ;
28 [ opt s2 , d a t a s 2 ] = read data ( [ dd s2 , ’ data ’ ] , 1 , n r e a d i n s 2 ) ;
29 [ o p t f , d a t a f ] = read data ( [ dd f , ’ data ’ ] , 1 , n r e a d i n f ) ;

30

31% Read in from s i m u l a t i o n d a t a f i l e s ( s i d e f i l e s )
32 [ o p t s s 1 , d a t a s s 1 ] = read data ( [ dd s1 , ’ datam ’ ] , 1 , n r e a d i n s 1 ) ;
33 [ o p t s s 2 , d a t a s s 2 ] = read data ( [ dd s2 , ’ datam ’ ] , 1 , n r e a d i n s 2 ) ;
34 [ o p t s f , d a t a s f ] = read data ( [ dd f , ’ datam ’ ] , 1 , n r e a d i n f ) ;

35

36% Read in from i n t e r s e c t i o n d a t a f i l e s
37 [ z p l s 1 1 , p l x y s 1 1 ] = r e a d d a t a p l x y ( [ dd s1 , ’ data plxy69 ’ ] , 0 , 1 ) ;
38 [ z p l s 1 5 , p l x y s 1 5 ] = r e a d d a t a p l x y ( [ dd s1 , ’ data plxy81 ’ ] , 0 , 1 ) ;
39 [ z p l s 1 6 , p l x y s 1 6 ] = r e a d d a t a p l x y ( [ dd s1 , ’ data plxy93 ’ ] , 0 , 1 ) ;
40 [ z p l s 1 7 , p l x y s 1 7 ] = r e a d d a t a p l x y ( [ dd s1 , ’ data plxy105 ’ ] , 0 , 1 ) ;
41 [ z p l s 2 1 , p l x y s 2 1 ] = r e a d d a t a p l x y ( [ dd s2 , ’ data plxy69 ’ ] , 0 , 1 ) ;
42 [ z p l s 2 5 , p l x y s 2 5 ] = r e a d d a t a p l x y ( [ dd s2 , ’ data plxy81 ’ ] , 0 , 1 ) ;
43 [ z p l s 2 6 , p l x y s 2 6 ] = r e a d d a t a p l x y ( [ dd s2 , ’ data plxy93 ’ ] , 0 , 1 ) ;
44 [ z p l s 2 7 , p l x y s 2 7 ] = r e a d d a t a p l x y ( [ dd s2 , ’ data plxy105 ’ ] , 0 , 1 ) ;
45 [ z p l f 1 , p l x y f 1 ] = r e a d d a t a p l x y ( [ dd f , ’ data plxy69 ’ ] , 0 , 1 ) ;
46 [ z p l f 5 , p l x y f 5 ] = r e a d d a t a p l x y ( [ dd f , ’ data plxy81 ’ ] , 0 , 1 ) ;
47 [ z p l f 6 , p l x y f 6 ] = r e a d d a t a p l x y ( [ dd f , ’ data plxy93 ’ ] , 0 , 1 ) ;
48 [ z p l f 7 , p l x y f 7 ] = r e a d d a t a p l x y ( [ dd f , ’ data plxy105 ’ ] , 0 , 1 ) ;

49

50% Read in from side −i n t e r s e c t i o n d a t a f i l e s
51 [ s i n t s 1 ] = r e a d d a t a s i d e i n s e c ( [ dd s1 , ’ s i d e i n t e r s e c ’ ] , 0 , 1 ) ;
52 [ s i n t f ] = r e a d d a t a s i d e i n s e c ( [ dd f , ’ s i d e i n t e r s e c ’ ] , 0 , 1 ) ;

53

54% Read in from d i v e r g e n c e d a t a f i l e s
55 [ ˜ , d i v s p h s 1 ]  = r e a d d a t a d i v 6 ( [ dd s1 , ’ divsph ’ ] , 0 , 1 ) ;
56 [ ˜ , divhsphR s1 ] = r e a d d a t a d i v 6 ( [ dd s1 , ’ divhalfsphR ’ ] , 0 , 1 ) ;
57 [ ˜ , d i v s p h s 2 ]  = r e a d d a t a d i v 6 ( [ dd s2 , ’ divsph ’ ] , 0 , 1 ) ;
58 [ ˜ , divhsphR s2t ] = r e a d d a t a d i v 6 ( [ dd s2 , ’ divhalfsphR ’ ] , 0 , 1 ) ;

59

60% Read in and p l o t paths
61 [ path optf , p a t h s f ] = r e a d d a t a p a t h ( ’ Short path ’ , [ dd path , ’ few ’ ] , 0 , 1 )
62 [ path optm , pathsm ] = r e a d d a t a p a t h ( ’ Long path ’ , [ dd path , ’many ’ ] , 0 , 1 )

63

64%% Make n o r m a l i z a t i o n f a c t o r s

65

66% Factor to make the numbers e a s i e r to work with
67 f a c = 10ˆ 7;

68

69% Define the n o r m a l i z a t i o n f a c t o r s f o r the d i f f e r e n t d a t a s e t s
70% S number o f neutrons simulated in t o t a l − opt (11)
71% U number o f neutrons w r i t t e n to d a t a f i l e − opt (10)
72% I number o f neutrons read in from the d a t a f i l e − num readin
73% U = kS , K = U/S , I = kS ’ , S ’ = I /k = IS /U

Appendix H Source codes  lxxxiii

74% r e a l i n t e n s i t y = i n t e n s i t y /S ’ = i n t e n s i t y U/( IS )
75 norm s1 = f a c ∗ o p t s 1 ( 1 0 ) / ( n r e a d i n s 1 ∗ o p t s 1 ( 1 1 ) ) ;
76 norm s2 = f a c ∗ o p t s 2 ( 1 0 ) / ( n r e a d i n f ∗ o p t s 2 ( 1 1 ) ) ;
77 norm f = f a c ∗ o p t f ( 1 0 ) / ( n r e a d i n f ∗ o p t f ( 1 1 ) ) ;

78

79% Normalization f a c t o r s about neutrons going through bottom ( only used at conv )
80 normb s1 = o p t s 1 ( 1 1 ) /( o p t s 1 ( 1 1 ) − o p t s 1 ( 1 0 ) − length ( s i n t s 1 ( : , 1 ) ) ∗ …
81  o p t s 1 ( 1 1 ) / d a t a s s 1 (end , 1 ) ) ;
82 normb f = o p t f ( 1 1 ) /( o p t f ( 1 1 ) − o p t f ( 1 0 ) − length ( s i n t f ( : , 1 ) ) ∗ …
83  o p t f ( 1 1 ) / d a t a s f (end , 1 ) ) ;

84 85

86%% Plot i n t e r s e c t i o n data as histograms

87

88% I n i t i a l o p t i o n s
89 bin = [ 1 0 0 1 0 0 ] ;  %number o f b i n s in histograms [ x y ]
90 cax = [ 0 4 3 5 ] ;  %over−a l l a x i s o f i n t e n s i t y c o l o r

91

92% C a l c u l a t e histograms
93 [ x s11 , y s11 , h i s t s 1 1 ] = p l i n s e c h i s t ( ’ Sph1 ’ , opt s1 , plxy s11 , z p l s 1 1 , …
94  norm s1 , bin , cax ) ;
95 [ x s15 , y s15 , h i s t s 1 5 ] = p l i n s e c h i s t ( ’ Sph1 ’ , opt s1 , plxy s15 , z p l s 1 5 , …
96  norm s1 , bin , cax ) ;
97 [ x s16 , y s16 , h i s t s 1 6 ] = p l i n s e c h i s t ( ’ Sph1 ’ , opt s1 , plxy s16 , z p l s 1 6 , …
98  norm s1 , bin , cax ) ;
99 [ x s17 , y s17 , h i s t s 1 7 ] = p l i n s e c h i s t ( ’ Sph1 ’ , opt s1 , plxy s17 , z p l s 1 7 , …
100  norm s1 , bin , cax ) ;
101 [ x s21 , y s21 , h i s t s 2 1 ] = p l i n s e c h i s t ( ’ Sph2 ’ , opt s2 , plxy s21 , z p l s 2 1 , …
102  norm s2 , bin , cax ) ;
103 [ x s25 , y s25 , h i s t s 2 5 ] = p l i n s e c h i s t ( ’ Sph2 ’ , opt s2 , plxy s25 , z p l s 2 5 , …
104  norm s2 , bin , cax ) ;
105 [ x s26 , y s26 , h i s t s 2 6 ] = p l i n s e c h i s t ( ’ Sph2 ’ , opt s2 , plxy s26 , z p l s 2 6 , …
106  norm s2 , bin , cax ) ;
107 [ x s27 , y s27 , h i s t s 2 7 ] = p l i n s e c h i s t ( ’ Sph2 ’ , opt s2 , plxy s27 , z p l s 2 7 , …
108  norm s2 , bin , cax ) ;
109 [ x f1 , y f1 , h i s t f 1 ]  = p l i n s e c h i s t ( ’ Flat ’ , o p t f , p l x y f 1 , z p l f 1 , norm f , …
110  bin , cax ) ;
111 [ x f5 , y f5 , h i s t f 5 ]  = p l i n s e c h i s t ( ’ Flat ’ , o p t f , p l x y f 5 , z p l f 5 , norm f , …
112  bin , cax ) ;
113 [ x f6 , y f6 , h i s t f 6 ]  = p l i n s e c h i s t ( ’ Flat ’ , o p t f , p l x y f 6 , z p l f 6 , norm f , …
114  bin , cax ) ;
115 [ x f7 , y f7 , h i s t f 7 ]  = p l i n s e c h i s t ( ’ Flat ’ , o p t f , p l x y f 7 , z p l f 7 , norm f , …
116  bin , cax ) ;

117

118%% Plot where the neutrons come from

119

120% I n i t i a l o p t i o n s
121 Emax = 1 ;  %maximum energy to work with
122 numP = 5000; %number o f p o i n t s to p l o t

123

124% Plot the s c a t t e r p l o t s
125 [ ˜ ] = p l o t r o l d ( ’ Sph1 ’ , opt s1 , data s1 , Emax,numP ) ;
126 [ ˜ ] = p l o t r o l d ( ’ Sph2 ’ , opt s2 , data s2 , Emax,numP ) ;
127 [ ˜ ] = p l o t r o l d ( ’ Flat ’ , o p t f , d a t a f , Emax,numP ) ;

128

129%% Plot side −i n t e r s e c t i o n data

130

131% I n i t i a l o p t i o n s
132 bin = [ 1 0 0 1 0 0 ] ;  %number o f b i n s in histograms [ x y ]
133 cax = [ 0 3 5 3 ] ;  %over−a l l a x i s o f i n t e n s i t y c o l o r

lxxxiv  H.3 MatLAB scripts

135% C a l c u l a t e histograms
136 [ x s1 , z s1 , h i s t s 1 ] = s i d e i n s e c h i s t ( ’ Sph1 ’ , opt s1 , s i n t s 1 , norm s1 , bin , cax ) ;
137 [ x f , z f , h i s t f ]  = s i d e i n s e c h i s t ( ’ Flat ’ , o p t f , s i n t f , norm f , bin , cax ) ;

138

139%% Plot d i v e r g e n c e data as histograms

140

141% I n i t i a l o p t i o n s
142 bin = [ 5 0 5 0 ] ;  %number o f b i n s in histograms [ x y ]
143 cax = [ 0 3 5 3 ] ;  %over−a l l a x i s o f i n t e n s i t y c o l o r

144

145% C a l c u l a t e histograms
146 [ x sph s1 , y sph s1 , h i s t s p h s 1 ]  = …
147 d i v e r g h i s t n o r m ( ’ Sph1 ’ , divsph s1 , bin , cax ) ;
148 [ x hsphR s1 , y hsphR s1 , h i s t h s p h R s 1 ] = …
149 d i v e r g h i s t n o r m ( ’ Sph1 , halfsphR ’ , divhsphR s1 , bin , cax ) ;
150 [ x sph s2 , y sph s2 , h i s t s p h s 2 ]  = …
151 d i v e r g h i s t n o r m ( ’ Sph2 ’ , divsph s2 , bin , cax ) ;
152 [ x hsphR s2 , y hsphR s2 , h i s t h s p h R s 2 ] = …
153 d i v e r g h i s t n o r m ( ’ Sph2 , halfsphR ’ , divhsphR s2t , bin , cax ) ;

154

155% Plot as a sum in only one dimension i n s t e a d
156 [ h i s t s p h s 1 1 D ] = hist2Dtohist1D ( ’ Sph1 ’ , x sph s1 , h i s t s p h s 1 )
157 [ hist hsphR s1 1D ] = hist2Dtohist1D ( ’ Sph1 , halfsphR ’ , x hsphR s1 , h i s t h s p h R s 1 )
158 [ h i s t s p h s 2 1 D ] = hist2Dtohist1D ( ’ Sph2 ’ , x sph s2 , h i s t s p h s 2 )
159 [ hist hsphR s2 1D ] = hist2Dtohist1D ( ’ Sph2 , halfsphR ’ , x hsphR s2 , h i s t h s p h R s 2 )

160

161% Plot as two p l o t s
162 figure
163 plot ( x sph s1 , h i s t s p h s 1 1 D , ’−b ’ ) ;  hold on
164 plot ( x hsphR s1 , hist hsphR s1 1D , ’−g ’ )
165 t i t l e ( ’ Histogram over x−d i v e r g e n c i e s ’ )
166 xlabel ( ’ x−d i v e r g e n c e [ rad ] ’ )
167 ylabel ( ’ number o f neutrons in bin ( f o r a l l y−d i v e r g e n c i e s ) ’ )
168 legend ( ’ Sph1 ’ , ’ Sph1 , halfsphR ’ )
169 grid

170

171 figure
172 plot ( x sph s2 , h i s t s p h s 2 1 D , ’−b ’ ) ;  hold on
173 plot ( x hsphR s2 , hist hsphR s2 1D , ’−g ’ )
174 t i t l e ( ’ Histogram over x−d i v e r g e n c i e s ’ )
175 xlabel ( ’ x−d i v e r g e n c e [ rad ] ’ )
176 ylabel ( ’ number o f neutrons in bin ( f o r a l l y−d i v e r g e n c i e s ) ’ )
177 legend ( ’ Sph2 ’ , ’ Sph2 , halfsphR ’ )
178 grid

179

180%% Read in c o n v o l u t e d s i m u l a t i o n data

181

182% Factor to g e t c o n v o l u t i o n data down to the measurement count−r a t e s
183 f a c t o r = 0.3∗10ˆ ( −3) ;

184

185% Total read−in f a c t o r s
186 f s 1 = f a c t o r ∗ norm s1 ;
187 f f = f a c t o r ∗ norm f ;

188

189% Read in from c o n v o l u t i o n d a t a f i l e s
190 [ x s1 , N s1 ] = read data conv ( [ dd s1 , ’ data convr ’ ] , f s 1 ) ;
191 [ x f , N f ] = read data conv ( [ dd f , ’ data convr ’ ] , f f ) ;

192

193%% Read in measured data

194

195% Dark count measurement

Appendix H Source codes  lxxxv

196 [ ˜ , ˜ , ˜ , ˜ , ˜ , ˜ , N mdc , dN mdc ] = r e a d r e a l d a t a ( [ dd data , ’ dc01 ’ ] ) ;

197

198 fprintf ( [ ’ Dark count has been found to be : ’ ,num2str(N mdc ( 1 ) ) , ’ +/− ’ , …
199  num2str(dN mdc ( 1 ) ) , ’ \n\n ’ ] )

200

201% Background measurements
202 [ ˜ , ˜ , ˜ , ˜ , ˜ , ˜ , N mbg , dN mbg ] = r e a d r e a l d a t a ( [ dd data , ’ bg01 ’ ] ) ;

203

204 fprintf ( [ ’ Background above f l a t 1 moderator : ’ ,num2str(N mbg ( 1 ) ) , ’ +/− ’ , …
205  num2str(dN mbg ( 1 ) ) , ’ \n ’ ] )
206 fprintf ( [ ’ Background above sph1 moderator : ’ ,num2str(N mbg ( 2 ) ) , ’ +/− ’ , …
207  num2str(dN mbg ( 2 ) ) , ’ \n\n ’ ] )

208

209% Measurements over the sph1 moderator
210 [ x ms1 , dx ms1 , T ms1 , dT ms1 , N T ms1 , dN T ms1 , Nin ms1 , dNin ms1 ] = …
211 r e a d r e a l d a t a w h ( [ dd data , ’ sph101 ’ ] ) ;

212

213% Measurements over the f l a t moderator
214 [ x mf , dx mf , T mf , dT mf , N T mf , dN T mf , Nin mf , dNin mf ] = …
215 r e a d r e a l d a t a w h ( [ dd data , ’ f l a t 0 1 ’ ] ) ;

216

217% Measurements over the c y l 1 moderator
218 [ x mc1 , dx mc1 , c1 de , c1 dde , T mc1 , dT mc1 , N T mc1 , dN T mc1 , Nin mc1 , …
219 dNin mc1 ] = r e a d r e a l d a t a c y l ( [ dd data , ’ c y l 0 1 ’ ] ) ;

220

221% Correct data with background measurements
222 BGN  = ( N mbg ( 1 ) + N mbg ( 2 ) ) / 2 ;
223 dBGN  = sqrt ( dN mbg ( 1 ) ˆ 2 + dN mbg ( 2 ) ˆ 2 ) / 2 ;
224 [ N ms1 , dN ms1 ] = removebg ( Nin ms1 , dNin ms1 , BGN, dBGN ) ;
225 [ N mf , dN mf ] = removebg ( Nin mf , dNin mf , BGN, dBGN ) ;
226 [ N mc1 , dN mc1 ] = removebg ( Nin mc1 , dNin mc1 , BGN, dBGN ) ;

227

228%% Plot measured data along with the c o n v o l u t e d s i m u l a t i o n data

229

230 figure
231 r e c t a n g l e ( ’ P o s i t i o n ’ , [ 5 . 9 3 , 0 , 2 2 − 5 . 7 6 − 5 . 9 3 , 8 ] ) ; hold on
232 errorbar ( x ms1 , N ms1 , dN ms1 , ’ . b ’ )
233 plot ( x s1 , N s1 , ’−b ’ )
234 errorbar ( x mf , N mf , dN mf , ’ . g ’ )
235 plot ( x f , N f , ’−g ’ )
236 t i t l e ( ’ Neutron f l u x f o r two moderators ’ )
237 xlabel ( ’ P o s i t i o n along moderator middle , x [ cm ] ’ )
238 ylabel ( ’ Flux o f neutrons , I [ cpm ] ’ )
239 legend ( ’ Sph1 moderator ’ , ’ Simulated i n t e n s i t y ’ , ’ Flat moderator ’ , ’ Simulated i n t e n s i t y ’ )

240

241%% Final o p t i o n s

242

243% Set path back to normal
244 path ( path backup )

Following are all the used functions in the sequence they are used in the script. They should be selfexplanatory with the comments written in the top of each function, along with the shorter comments written during the function codes.

1 function [ opt , data ] = read data ( f i l e , bool , np )
2% Reads the from a f u l l s i m u l a t i o n data f i l e .
3%
4% Explanation o f input parameters :
5% f i l e  name o f f i l e ( without the ” . dat ”)
6%  example : ’ l a r g e f l a t ’
7% b o o l  boolean (1 or 0)
8% np  number o f wanted p o i n t s i f b o o l=1

lxxxvi  H.3 MatLAB scripts

9%
10% Overview o f the opt array :
11% opt (1)  xmax
12% opt (2)  ymax
13% opt (3)  zmax
14% opt (4)  sphere c e n t e r x
15% opt (5)  sphere c e n t e r y
16% opt (6)  sphere c e n t e r z
17% opt (7)  sphere r a d i u s
18% opt (8)  s t a r t energy o f neutrons
19% opt (9)  thermal energy
20% opt (10)  number o f simulated neutrons in output
21% opt (11)  number o f simulated neutrons in t o t a l
22% opt (12)  not used here ( debugging o f s i m u l a t i o n code )
23% opt (13)  not used here ( debugging o f s i m u l a t i o n code )
24% opt (14)  not used here ( debugging o f s i m u l a t i o n code )
25% opt (15)  not used here ( debugging o f s i m u l a t i o n code )
26% opt (16)  not used here ( debugging o f s i m u l a t i o n code )
27%
28% Overview o f the data array :
29% data ( : , 1 )  neutron number
30% data ( : , 2 )  neutron p o s i t i o n in x
31% data ( : , 3 )  neutron p o s i t i o n in y
32% data ( : , 4 )  neutron p o s i t i o n in z
33% data ( : , 5 )  neutron d i r e c t i o n in x
34% data ( : , 6 )  neutron d i r e c t i o n in y
35% data ( : , 7 )  neutron d i r e c t i o n in z
36% data ( : , 8 )  neutron energy
37% data ( : , 9 )  t o t a l t r a v e l e d d i s t a n c e
38% data ( : , 1 0 )  number o f i n t e r a c t i o n s
39% data ( : , 1 1 )  number o f mirrorings

40

41% Open f i l e and read in s i m u l a t i o n o p t i o n s
42 fprintf ( [ ’ Working with d a t a f i l e ’ , f i l e , ’ . dat … \ n\n ’ ] )
43 f i d = fopen ( [ f i l e , ’ . dat ’ ] ) ;
44 datao = c e l l 2 m a t ( t e x t s c a n ( f i d , ’%n ’ , ’ h e a d e r l i n e s ’ , 0 ) ) ;
45 fclose ( f i d ) ;

46

47% Save the o p t i o n s from the d a t a f i l e i n t o the c o r r e c t array
48 opt = datao ( 1 : 1 6 ) ;

49

50% Print the found o p t i o n s
51 i f ( bool = 1)
52  fprintf ( [ ’ In t o t a l , ’ ,num2str( opt ( 1 0 ) ) , ’ neutrons were output , ’ ] )
53  fprintf ( [ ’ but only the f i r s t ’ ,num2str( np ) , ’ has been read in . \ n ’ ] )
54 e l s e i f ( bool = 0)
55  fprintf ( [ ’ In t o t a l , ’ ,num2str( opt ( 1 0 ) ) , ’ neutrons were output . \ n ’ ] )
56 end
57 fprintf ( [ ’ In t o t a l , ’ ,num2str( opt ( 1 1 ) ) , ’ neutrons were a c t u a l l y ’ , …
58  ’ simulated . \ n\n ’ ] )
59 fprintf ( ’ The moderator has  ’ )
60 fprintf ( [ ’  xmax = ’ ,num2str( opt ( 1 ) ) , ’ ’ ] )
61 fprintf ( [ ’  ymax = ’ ,num2str( opt ( 2 ) ) , ’ ’ ] )
62 fprintf ( [ ’  zmax = ’ ,num2str( opt ( 3 ) ) , ’ \n ’ ] )
63 fprintf ( ’ The sphere has  ’ )
64 fprintf ( [ ’  x = ’ ,num2str( opt ( 4 ) ) , ’ ’ ] )
65 fprintf ( [ ’  y = ’ ,num2str( opt ( 5 ) ) , ’ ’ ] )
66 fprintf ( [ ’  z = ’ ,num2str( opt ( 6 ) ) , ’ ’ ] )
67 fprintf ( [ ’  r = ’ ,num2str( opt ( 7 ) ) , ’ \n ’ ] )
68 fprintf ( ’ The neutrons s t a r t with energy  ’ )
69 fprintf ( [ ’  E0 = ’ ,num2str( opt ( 8 ) ) , ’ \n\n ’ ] )

Appendix H Source codes  lxxxvii

70

71% Open f i l e and read data
72 f i d = fopen ( [ f i l e , ’ . dat ’ ] ) ;  %open f i l e again
73 datat = c e l l 2 m a t ( t e x t s c a n ( f i d , ’%n %n %n %n %n %n %n %n %n %n %n %n %n %n ’ , …
74  ’ h e a d e r l i n e s ’ ,16) ) ;
75 fclose ( f i d ) ;  %c l o s e f i l e again

76

77% Decide how many d a t a p o i n t s i s to be used
78 i f ( bool = 0)  %check type
79 imax = length ( datat ( : , 1 ) ) ; %f u l l d a t a s e t
80 e l s e i f ( bool = 1)
81 imax = np ; %only s t a r t o f data
82 end

83

84 data = datat ( 1 : imax , : ) ;

85

86 end
1 function [ z p l , p l x y ] = r e a d d a t a p l x y ( f i l e , bool , np )
2% Read in i n t e r s e c t i o n data .
3%
4% Explanation o f input parameters :
5% f i l e  f i l e name in the data d i r e c t o r y
6% b o o l  i f 1 , only read in the np p o i n t s ; i f 0 , read a l l
7% np  number o f p o i n t s to read in i f b o o l = 1
8%
9% Explanation o f output v a r i a b l e s :
10% z p l  plane z−p o s i t i o n f o r i n t e r s e c t i o n c a l c u l a t i o n
11% p l x y ( : , 1 ) neutron number
12% p l x y ( : , 2 ) neutron x−p o s i t i o n on plane
13% p l x y ( : , 3 ) neutron y−p o s i t i o n on plane

14

15% Open f i l e and read in data f i l e o p t i o n s
16 fprintf ( [ ’ Working with i n t e r s e c t i o n d a t a f i l e ’ , f i l e , ’ . dat … \ n\n ’ ] )
17 f i d = fopen ( [ f i l e , ’ . dat ’ ] ) ;
18 datao = c e l l 2 m a t ( t e x t s c a n ( f i d , ’%n ’ , ’ h e a d e r l i n e s ’ , 0 ) ) ;
19 fclose ( f i d ) ;

20

21% Save the o p t i o n s from the d a t a f i l e
22 z p l = datao ( 1 ) ;

23

24% Print the found o p t i o n s
25 fprintf ( [ ’ The plane i s p o s i t i o n e d at z = ’ ,num2str( z p l ) , ’ . \ n\n ’ ] )

26

27% Open f i l e and read data
28 f i d = fopen ( [ f i l e , ’ . dat ’ ] ) ;
29 datat = c e l l 2 m a t ( t e x t s c a n ( f i d , ’%n %n %n ’ , ’ h e a d e r l i n e s ’ , 1 ) ) ;
30 fclose ( f i d ) ;

31

32% Decide how many d a t a p o i n t s i s to be used
33 i f ( bool = 0)  %check type
34 imax = length ( datat ( : , 1 ) ) ; %f u l l d a t a s e t
35 e l s e i f ( bool = 1)
36 imax = np ; %only s t a r t o f data
37 end

38

39% Save the output v a r i a b l e
40 p l x y = datat ( 1 : imax , : ) ;

41

42 end
1 function [ p o i n t s ] = r e a d d a t a s i d e i n s e c ( f i l e , bool , np )

lxxxviii  H.3 MatLAB scripts

2% Read in s i d e i n t e r s e c t i o n data .
3%
4% Explanation o f input parameters :
5% f i l e  f i l e name in the data d i r e c t o r y
6% b o o l  i f 1 , only read in the np p o i n t s ; i f 0 , read a l l
7% np  number o f p o i n t s to read in i f b o o l = 1
8%
9% Overview o f the p o i n t s array :
10% p o i n t s ( : , 1 )  neutron number
11% p o i n t s ( : , 2 )  neutron x−p o s i t i o n on plane
12% p o i n t s ( : , 3 )  neutron y−p o s i t i o n on plane
13% p o i n t s ( : , 4 )  which plane was i n t e r s e c t e d (1 , 2 , 3 or 4)

14

15% Open f i l e and read data
16 fprintf ( [ ’ Working with s i d e i n t e r s e c t i o n d a t a f i l e ’ , f i l e , ’ . dat … \ n\n ’ ] )
17 f i d = fopen ( [ f i l e , ’ . dat ’ ] ) ;
18 datat = c e l l 2 m a t ( t e x t s c a n ( f i d , ’%n %n %n %n ’ , ’ h e a d e r l i n e s ’ , 0 ) ) ;
19 fclose ( f i d ) ;

20

21% Decide how many d a t a p o i n t s i s to be used
22 i f ( bool = 0)  %check type
23 imax = length ( datat ( : , 1 ) ) ; %f u l l d a t a s e t
24 e l s e i f ( bool = 1)
25 imax = np ; %s t a r t o f data
26 end

27

28% Save the output v a r i a b l e
29 p o i n t s = datat ( 1 : imax , : ) ;

30

31 end
1 function [ opt , div ] = r e a d d a t a d i v 6 ( f i l e , bool , np )
2% Read in d i v e r g e n c e data .
3%
4% Explanation o f input parameters :
5% f i l e  f i l e name in the data d i r e c t o r y
6% b o o l  i f 1 , only read in the np p o i n t s ; i f 0 , read a l l
7% np  number o f p o i n t s to read in i f b o o l = 1
8%
9% Overview o f the opt array :
10% opt  plane z−p o s i t i o n f o r d i v e r g e n c e c a l c u l a t i o n
11%
12% Overview o f the d i v array :
13% d i v ( : , 1 )  neutron number
14% d i v ( : , 2 )  neutron x−d i v e r g e n c e
15% d i v ( : , 3 )  neutron y−d i v e r g e n c e
16% d i v ( : , 4 )  x
17% d i v ( : , 5 )  y
18% d i v ( : , 6 )  z

19

20% Open f i l e and read in s i m u l a t i o n o p t i o n s
21 fprintf ( [ ’ Working with div d a t a f i l e ’ , f i l e , ’ . dat … \ n\n ’ ] )
22 f i d = fopen ( [ f i l e , ’ . dat ’ ] ) ;
23 datao = c e l l 2 m a t ( t e x t s c a n ( f i d , ’%n ’ , ’ h e a d e r l i n e s ’ , 0 ) ) ;
24 fclose ( f i d ) ;

25

26% Save the o p t i o n s from the d a t a f i l e
27 opt = datao ( 1 ) ;

28

29% Print the found o p t i o n s
30 fprintf ( [ ’ The plane i s p o s i t i o n e d at z = ’ ,num2str( opt ) , ’ . \ n\n ’ ] )

Appendix H Source codes  lxxxix

32% Open f i l e and read data
33 f i d = fopen ( [ f i l e , ’ . dat ’ ] ) ;
34 datat = c e l l 2 m a t ( t e x t s c a n ( f i d , ’%n %n %n %n %n %n ’ , ’ h e a d e r l i n e s ’ , 1 ) ) ;
35 fclose ( f i d ) ;

36

37% Decide how many d a t a p o i n t s i s to be used
38 i f ( bool = 0)  %check type
39 imax = length ( datat ( : , 1 ) ) ; %f u l l d a t a s e t
40 e l s e i f ( bool = 1)
41 imax = np ; %only s t a r t o f data
42 end

43

44% Save the output v a r i a b l e
45 div = datat ( 1 : imax , : ) ;

46

47 end
1 function [ Ox, Oy, Ohist ] = p l i n s e c h i s t ( t i , opt , pl xy , z p l ,norm, nbin , c o l o r s )
2% C a l c u l a t i n g the two−dimensional histogram o f a matrix , and p l o t t i n g i t with
3% the moderator s i z e taken from the opt v a r i a b l e .
4%
5% Explanation o f input parameters :
6% t i  e x t r a part f o r the p l o t t i t l e
7% opt  data o p t i o n s from the data f i l e
8% p l x y  ( i , x , y ) p o i n t s o f i n t e r s e c t i o n in the plane ( i i s neutron number )
9% z p l  the z−v a l u e where the plane i s p l a c e d
10% norm  n o r m a l i z a t i o n constant
11% nbin  number o f b i n s as [ x b i n s y b i n s ]
12% c o l o r s  the c a x i s v e c t o r
13%
14% Explanation o f output v a r i a b l e s :
15% Ox  x−v a l u e s corresponding to the f i r s t a x i s numbers in the histogram
16% Oy  y−v a l u e s corresponding to the second a x i s numbers in the histogram
17% Ohist  the histogram i t s e l f , as a nbin (1) x nbin (2) matrix

18

19% Output what the r o u t i n e i s doing
20 fprintf ( [ ’ C a l c u l a t i n g histogram o f i n t e r s e c t i o n s o f a plane with ’ , …
21  ’ z = ’ ,num2str( z p l ) , ’ = zmax + ’ ,num2str( z p l −opt ( 3 ) ) , ’ … \ n\n ’ ] )

22

23% C a l c u l a t e edges
24 s0x = 0 −0.25∗ opt ( 1 ) ;
25 s1x = 1.25∗ opt ( 1 ) ;
26 s0y = 0 −0.25∗ opt ( 2 ) ;
27 s1y = 1.25∗ opt ( 2 ) ;

28

29 nbinx = nbin ( 1 ) ;
30 nbiny = nbin ( 2 ) ;

31

32 edgesx  = s0x : s1x / nbinx : s1x ;
33 edgesx mean = ( s0x : s1x / nbinx : s1x−s1x / nbinx ) + ( s1x−s0x ) /2/ nbinx ;
34 edgesy  = s0y : s1y / nbiny : s1y ;
35 edgesy mean = ( s0y : s1y / nbiny : s1y−s1y / nbiny ) + ( s1y−s0y ) /2/ nbiny ;

36

37 edges = c e l l ( [ 1 , 2 ] ) ;
38 edges {1} = edgesx ;
39 edges {2} = edgesy ;

40

41 p l a n e p o s i t i o n s = [ p l x y ( : , 2 ) , p l x y ( : , 3 ) ] ;

42

43% C a l c u l a t e histogram and normalize i t
44 N = h i s t 3 ( p l a n e p o s i t i o n s , ’ Edges ’ , edges ) ;
45 N = t r a n s p o s e (N) ∗ norm;

xc  H.3 MatLAB scripts

46

47% Plot the histogram along with the moderator s i z e
48 figure ; hold on
49 pcolor ( edgesx mean , edgesy mean ,N( 1 : end−1 ,1:end−1) )
50 shading f l a t
51 r e c t a n g l e ( ’ P o s i t i o n ’ , [ 0 , 0 , opt ( 1 ) , opt ( 2 ) ] )
52 axis ( [ s0x s1x s0y s1y ] )
53 t i t l e ( [ ’ I n t e r s e c t i o n s o f the z = ’ ,num2str( z p l ) , ’ plane . ’ , t i ] )
54 xlabel ( ’ x−d i r e c t i o n ’ )
55 ylabel ( ’ y−d i r e c t i o n ’ )
56 colorbar
57 caxis ( c o l o r s )

58

59% Save output v a l u e s
60 Ox  = edgesx mean ( 1 : end) ;
61 Oy  = edgesy mean ( 1 : end) ;
62 Ohist = N( 1 : end−1 ,1:end−1) ;

63

64 end
1 function [ intdatOUT ] = p l o t r o l d ( t i , opt , data , Emax,numP )
2% Plot a chosen number o f points , with energy below Emax, in a s c a t t e r p l o t ,
3% where the moderator s i z e i s shown as a box .
4%
5% Explanation o f input parameters :
6% t i  e x t r a t e x t f o r the p l o t t i t l e
7% opt  o p t i o n s from the d a t a f i l e ( used to make moderator box )
8% data  data from d a t a f i l e
9% Emax  the program p l o t s only p o i n t s with neutron energy l e s s than Emax
10% numP  number o f p o i n t s to p l o t
11%
12% Explanation o f output v a r i a b l e s :
13% intdatOUT the a c t u a l p o i n t s chosen to be p l o t t e d

14

15% Checking f o r c o r r e c t input
16 i f ( numP > length ( data ( : , 8 ) ) )
17  numP = length ( data ( : , 8 ) ) ;
18  fprintf ( [ ’ERROR: The wanted number o f p o i n t s was l a r g e r than the ’ , …
19  ’ number o f a c c e s s i b l e \ npoints in the d a t a s e t ! The number has ’ , …
20  ’ s e t to the l a r g e s t p o s s i b l e number : ’ ,num2str(numP) , ’ \n\n ’ ] )
21 end

22

23% Defining moderator f a c e s to put in the p l o t
24 xmin = 0 ; xmax = opt ( 1 ) ;
25 ymin = 0 ; ymax = opt ( 2 ) ;
26 zmin = 0 ; zmax = opt ( 3 ) ;

27

28 xpatch1 = [ xmax xmax xmin xmin ] ;
29 ypatch1 = [ ymin ymin ymin ymin ] ;
30 zpatch1 = [ zmin zmax zmax zmin ] ;
31 xpatch2 = [ xmax xmin xmin xmax ] ;
32 ypatch2 = [ ymin ymin ymax ymax ] ;
33 zpatch2 = [ zmax zmax zmax zmax ] ;
34 xpatch3 = [ xmin xmin xmin xmin ] ;
35 ypatch3 = [ ymin ymax ymax ymin ] ;
36 zpatch3 = [ zmax zmax zmin zmin ] ;
37 xpatch4 = [ xmin xmax xmax xmin ] ;
38 ypatch4 = [ ymin ymin ymax ymax ] ;
39 zpatch4 = [ zmin zmin zmin zmin ] ;
40 xpatch5 = [ xmax xmax xmax xmax ] ;
41 ypatch5 = [ ymin ymin ymax ymax ] ;
42 zpatch5 = [ zmin zmax zmax zmin ] ;

Appendix H Source codes  xci

43 xpatch6 = [ xmax xmin xmin xmax ] ;
44 ypatch6 = [ ymax ymax ymax ymax ] ;
45 zpatch6 = [ zmax zmax zmin zmin ] ;

46

47% I n i t i a l i z e f i g u r e
48 figure

49

50% Plot the moderator f a c e s
51 patch ( xpatch1 , ypatch1 , zpatch1 , ’ r ’ , ’ FaceAlpha ’ , 0 )
52 patch ( xpatch2 , ypatch2 , zpatch2 , ’ y ’ , ’ FaceAlpha ’ , 0 )
53 patch ( xpatch3 , ypatch3 , zpatch3 , ’ g ’ , ’ FaceAlpha ’ , 0 )
54 patch ( xpatch4 , ypatch4 , zpatch4 , ’ c ’ , ’ FaceAlpha ’ , 0 )
55 patch ( xpatch5 , ypatch5 , zpatch5 , ’ b ’ , ’ FaceAlpha ’ , 0 )
56 patch ( xpatch6 , ypatch6 , zpatch6 , ’ k ’ , ’ FaceAlpha ’ , 0 )

57

58 hold on

59

60 t i t l e ( [ ’ Last point f o r the neutrons . Emax = ’ ,num2str(Emax) , ’ eV . ’ , t i ] )
61 xlabel ( ’ x−d i r e c t i o n ’ )
62 ylabel ( ’ y−d i r e c t i o n ’ )
63 zlabel ( ’ z−d i r e c t i o n ’ )

64

65% Set axes
66 x l = xmax − xmin ;
67 y l = ymax − ymin ;
68 z l = zmax − zmin ;
69 axis ( [ xmin−x l /10 xmax+x l /10 ymin−y l /10 ymax+y l /10 zmin−z l /10 zmax+z l / 1 0 ] )

70

71% Set viewing angle
72 Az = 3 9 ; El = 2 6 ;
73 view (Az , El )

74

75% Find the p o i n t s to p l o t
76 k1 = 0 ;
77 i n t d a t = zeros (numP, 3 ) ;
78 for i = 1 : length ( data ( : , 1 ) )
79  i f ( data ( i , 8 ) <= Emax)
80  i f ( k1 < numP)
81  k1 = k1 + 1 ;
82  i n t d a t ( k1 , 1 ) = data ( i , 2 ) ;
83  i n t d a t ( k1 , 2 ) = data ( i , 3 ) ;
84  i n t d a t ( k1 , 3 ) = data ( i , 4 ) ;
85  end
86  end
87 end

88

89% Check f o r e r r o r s
90 i f ( k1 < numP )
91  fprintf ( [ ’ERROR: The wanted number o f p o i n t s was l a r g e r than the ’ , …
92  ’ number o f a c c e s s i b l e \ npoints with the r i g h t energy . The ’ , …
93  ’ number has been s e t to the l a r g e s t p o s s i b l e : ’ ,num2str( k1 ) , …
94  ’ \n\n ’ ] )
95 end

96

97% Plot the p o i n t s
98 s c a t t e r 3 ( i n t d a t ( 1 : k1 , 1 ) , i n t d a t ( 1 : k1 , 2 ) , i n t d a t ( 1 : k1 , 3 ) , ’ . ’ , ’ CData ’ , i n t d a t ( 1 : k1 , 3 ) )

99

100% Save the output v a r i a b l e
101 intdatOUT = i n t d a t ( 1 : k1 , : ) ;

102

103 end

xcii  H.3 MatLAB scripts

1 function [ OUTx,OUTz, OUThist ] = s i d e i n s e c h i s t ( t i , opt , points ,norm, nbin , c o l o r s )
2% C a l c u l a t i n g the two−dimensional histogram o f a matrix , and p l o t t i n g i t with
3% the moderator s i z e taken from the opt v a r i a b l e .
4%
5% Explanation o f input parameters :
6% t i  e x t r a part f o r the p l o t t i t l e
7% opt  data o p t i o n s from the data f i l e
8% p o i n t s  ( i , x , z , I ) p o i n t s o f i n t e r s e c t i o n in the plane ( i i s neutron number )
9% norm  n o r m a l i z a t i o n constant
10% nbin  number o f b i n s as [ x b i n s z b i n s ]
11% c o l o r s  the c a x i s v e c t o r
12%
13% Explanation o f output v a r i a b l e s :
14% Ox  x/y−v a l u e s corresponding to the f i r s t a x i s numbers in the histogram
15% Oz  z−v a l u e s corresponding to the second a x i s numbers in the histogram
16% Ohist  the histogram i t s e l f , as a nbin (1) x nbin (2) matrix

17

18% Output what the r o u t i n e i s doing
19 fprintf ( ’ C a l c u l a t i n g histogram o f i n t e r s e c t i o n s o f moderator s i d e … \ n\n ’ )

20

21% C a l c u l a t e edges
22 s0x = 0 −0.5∗ opt ( 1 ) ;
23 s1x = 1 . 5 ∗ opt ( 1 ) ;
24 s0z = 0 −0.5∗ opt ( 3 ) ;
25 s1z = 1 . 5 ∗ opt ( 3 ) ;

26

27 nbinx = nbin ( 1 ) ;
28 nbinz = nbin ( 2 ) ;

29

30 edgesx  = s0x : s1x / nbinx : s1x ;
31 edgesx mean = ( s0x : s1x / nbinx : s1x−s1x / nbinx ) + ( s1x−s0x ) /2/ nbinx ;
32 edgesz  = s0z : s1z / nbinz : s1z ;
33 edgesz mean = ( s0z : s1z / nbinz : s1z−s1z / nbinz ) + ( s1z−s0z ) /2/ nbinz ;

34

35 edges = c e l l ( [ 1 , 2 ] ) ;
36 edges {1} = edgesx ;
37 edges {2} = edgesz ;

38

39 p l a n e p o s i t i o n s = [ p o i n t s ( : , 2 ) , p o i n t s ( : , 3 ) ] ;

40

41% C a l c u l a t e histogram and normalize i t
42 N = h i s t 3 ( p l a n e p o s i t i o n s , ’ Edges ’ , edges ) ;
43 N = t r a n s p o s e (N) ∗ norm;

44

45% Plot the histogram along with the moderator s i z e
46 figure ; hold on
47 pcolor ( edgesx mean , edgesz mean ,N( 1 : end−1 ,1:end−1) )
48 shading f l a t
49 r e c t a n g l e ( ’ P o s i t i o n ’ , [ 0 , 0 , opt ( 1 ) , opt ( 3 ) ] )
50 axis ( [ s0x s1x s0z s1z ] )
51 t i t l e ( [ ’ I n t e r s e c t i o n s o f the moderator s i d e . ’ , t i ] )
52 xlabel ( ’ x− and y−d i r e c t i o n ’ )
53 ylabel ( ’ z−d i r e c t i o n ’ )
54 colorbar
55 caxis ( c o l o r s )

56

57% Save output v a l u e s
58 OUTx  = edgesx mean ( 1 : end) ;
59 OUTz  = edgesz mean ( 1 : end) ;
60 OUThist = N( 1 : end−1 ,1:end−1) ;

Appendix H Source codes  xciii

62 end
1 function [ OUTx,OUTy, OUThist ] = d i v e r g h i s t n o r m ( t i , div , nbin , c o l o r s )
2% C a l c u l a t i n g the two−dimensional histogram o f a matrix . The histogram has been
3% normalized by using the t o t a l number o f p o i n t s in the incoming d i v d a t a s e t .
4%
5% Explanation o f input parameters :
6% t i  e x t r a part f o r the p l o t t i t l e
7% opt  data o p t i o n s from the data f i l e
8% d i v  ( i , x , y ) p o i n t s o f d i v e r g e n c e p o i n t s ( i i s neutron number )
9% nbin  number o f b i n s as [ x b i n s y b i n s ]
10% c o l o r s the c a x i s v e c t o r
11%
12% Explanation o f output v a r i a b l e s :
13% Ox  x−v a l u e s corresponding to the f i r s t a x i s numbers in the histogram
14% Oy  y−v a l u e s corresponding to the second a x i s numbers in the histogram
15% Ohist  the histogram i t s e l f , as a nbin (1) x nbin (2) matrix

16

17% Output what the r o u t i n e i s doing
18 fprintf ( ’ C a l c u l a t i n g histogram o f d i v e r g e n c i e s … \ n\n ’ )

19

20% C a l c u l a t e edges
21 s0x = −1.1∗ pi / 2 ;
22 s1x = 1 . 1 ∗ pi / 2 ;
23 s0y = −1.1∗ pi / 2 ;
24 s1y = 1 . 1 ∗ pi / 2 ;

25

26 nbinx = nbin ( 1 ) ;
27 nbiny = nbin ( 2 ) ;

28

29 edgesx  = s0x : s1x / nbinx : s1x ;
30 edgesx mean = ( s0x : s1x / nbinx : s1x−s1x / nbinx ) + ( s1x−s0x ) /2/ nbinx ;
31 edgesy  = s0y : s1y / nbiny : s1y ;
32 edgesy mean = ( s0y : s1y / nbiny : s1y−s1y / nbiny ) + ( s1y−s0y ) /2/ nbiny ;

33

34 edges = c e l l ( [ 1 , 2 ] ) ;
35 edges {1} = edgesx ;
36 edges {2} = edgesy ;

37

38 p l a n e p o s i t i o n s = [ div ( : , 2 ) , div ( : , 3 ) ] ;

39

40% C a l c u l a t e histogram and normalize i t
41 N = h i s t 3 ( p l a n e p o s i t i o n s , ’ Edges ’ , edges ) ;
42 N = N/length ( p l a n e p o s i t i o n s ( : , 1 ) ) ∗10ˆ 4;
43 N = t r a n s p o s e (N) ;

44

45% Plot the histogram
46 figure ; hold on
47 pcolor ( edgesx mean , edgesy mean ,N( 1 : end−1 ,1:end−1) )
48 axis ( [ s0x s1x s0y s1y ] )
49 shading f l a t
50 t i t l e ( [ ’ D i v e r g e n c i e s . ’ , t i ] )
51 xlabel ( ’ x−d i r e c t i o n divergency [ rad ] ’ )
52 ylabel ( ’ y−d i r e c t i o n divergency [ rad ] ’ )
53 caxis ( c o l o r s )
54 colorbar

55

56% Save output v a l u e s
57 OUTx  = edgesx mean ( 1 : end) ;
58 OUTy  = edgesy mean ( 1 : end) ;
59 OUThist = N( 1 : end−1 ,1:end−1) ;

xciv  H.3 MatLAB scripts

61 end
1 function [ hists1D ] = hist2Dtohist1D ( t i , x , h i s t I N )
2% C a l c u l a t e a one−dimensional histogram from a two−dimensional histogram by
3% summing over one o f the dimensions .
4%
5% Explanation o f input parameters :
6% t i  e x t r a part f o r the p l o t t i t l e
7% x  x−a x i s o f the incoming histogram
8% h i s t I N  incoming histogram
9%
10% Explanation o f output v a r i a b l e s :
11% hists1D the one−dimensional histogram

12

13% Do the a c t u a l c a l c u l a t i o n
14 for i = 1 : length ( h i s t I N ( : , 1 ) )
15  hists1D ( i ) = sum( h i s t I N ( : , i ) ) ; %x
16  %hists1D ( i ) = sum( h i s t I N ( i , : ) ) ; %y
17 end

18

19% Plot the found histogram
20 figure ; hold on
21 plot ( x , hists1D , ’ b ’ )
22 t i t l e ( [ ’ Histogram over x−d i v e r g e n c i e s ’ , t i ] )
23 ylabel ( ’ number o f neutrons in bin ( f o r a l l y−d i v e r g e n c i e s ) ’ )
24 xlabel ( ’ x−d i v e r g e n c e [ rad ] ’ )
25 grid

26

27 end
1 function [ x , dx ,T, dT, N T , dN T ,N, dN ] = r e a d r e a l d a t a ( f i l e )
2% Read in data from d a t a f i l e o f with 13 h e a d e r l i n e s , and rows l i k e the f o l l o w i n g :
3% x [cm] , y [cm] , h1 [cm] , h2 [cm] , T [ min ] , T [ sek ] , N T [ counts ]
4%
5% Explanation o f the d a t a f i l e rows :
6% x  d i s t a n c e from d e t e c t o r ( bor ) s i d e to moderator top s i d e
7% y  d i s t a n c e from d e t e c t o r ( bor ) s i d e to r i g h t s i d e o f moderator
8% h1  d i s t a n c e from d e t e c t o r ( bor ) bottom to moderator s u r f a c e
9%  i f zero , i t was not p o s s i b l e to measure because o f geometry
10% h2  d i s t a n c e from d e t e c t o r ( bor ) top to d e t e c t o r top
11% T  time counted ( s p l i t i n t o minutes and seconds below )
12% N T number o f counts
13%
14% Explanation o f output v a r i a b l e s :
15% x  x−v a l u e ( p o s i t i o n along measuring a x i s )
16% dx  u n c e r t a i n t y o f the x−v a l u e
17% T  counting time
18% dT  u n c e r t a i n t y o f the time
19% N T  count number during time T
20% dN T u n c e r t a i n t y o f the count number
21% N  i n t e n s i t y c a l c u l a t e d in u n i t s o f cpm
22% dN  u n c e r t a i n t y o f the i n t e n s i t y

23

24% Read in data
25 fprintf ( [ ’ Reading in data from d a t a f i l e ’ , f i l e , ’ . dat … \ n ’ ] )
26 f i d = fopen ( [ f i l e , ’ . dat ’ ] ) ;
27 data = c e l l 2 m a t ( t e x t s c a n ( f i d , ’%n %n %n %n %n %n %n ’ , ’ h e a d e r l i n e s ’ ,13) ) ;
28 fclose ( f i d ) ;

29

30% Save the r e l e v a n t v a r i a b l e s
31 x  = data ( : , 1 ) + 2 . 5 5 5 ;  %p o s i t i o n on measuring a x i s
32 T  = data ( : , 5 ) + data ( : , 6 ) / 6 0 ;  %time measured

Appendix H Source codes  xcv

33 N T = data ( : , 7 ) ;  %number o f counts

34

35% C a l c u l a t e u n c e r t a i n t i e s
36 dx = 1/10∗ ones ( 1 , length ( x ) ) ;  %assumed from the measurements
37 dT = zeros ( 1 , length (T) ) ;  %assumed to be i r r e l e v a n t
38 dN T = sqrt (N T) ;  %Poisson d i s t r i b u t e d numbers

39

40% C a l c u l a t e i n t e n s i t y in counts per minute
41 N  = N T . / T;
42 dN = dN T . / T;

43

44 end
1 function [ x , dx ,T, dT, N T , dN T ,N, dN ] = r e a d r e a l d a t a w h ( f i l e )
2% Read in data from d a t a f i l e o f with 13 h e a d e r l i n e s , and rows l i k e the f o l l o w i n g :
3% x [cm] , y [cm] , h1 [cm] , h2 [cm] , T [ min ] , T [ sek ] , N T [ counts ]
4%
5% This f u n c t i o n i s l i k e r e a d r e a l d a t a , but does c a l c u l a t e d e t e c t o r and boron
6% p l a s t h e i g h t , along with u n c e r t a i n t i e s .
7%
8% Explanation o f the d a t a f i l e rows :
9% x  d i s t a n c e from d e t e c t o r ( bor ) s i d e to moderator top s i d e
10% y  d i s t a n c e from d e t e c t o r ( bor ) s i d e to r i g h t s i d e o f moderator
11% h1  d i s t a n c e from d e t e c t o r ( bor ) bottom to moderator s u r f a c e
12%  i f zero , i t was not p o s s i b l e to measure because o f geometry
13% h2  d i s t a n c e from d e t e c t o r ( bor ) top to d e t e c t o r top
14% T  time counted ( s p l i t i n t o minutes and seconds below )
15% N T number o f counts
16%
17% Explanation o f output v a r i a b l e s :
18% x  x−v a l u e ( p o s i t i o n along measuring a x i s )
19% dx  u n c e r t a i n t y o f the x−v a l u e
20% T  counting time
21% dT  u n c e r t a i n t y o f the time
22% N T  count number during time T
23% dN T u n c e r t a i n t y o f the count number
24% N  i n t e n s i t y c a l c u l a t e d in u n i t s o f cpm
25% dN  u n c e r t a i n t y o f the i n t e n s i t y

26

27% Read in data
28 fprintf ( [ ’ Reading in data from d a t a f i l e ’ , f i l e , ’ . dat … \ n ’ ] )
29 f i d = fopen ( [ f i l e , ’ . dat ’ ] ) ;
30 data = c e l l 2 m a t ( t e x t s c a n ( f i d , ’%n %n %n %n %n %n %n ’ , ’ h e a d e r l i n e s ’ ,13) ) ;
31 fclose ( f i d ) ;

32

33% Save the r e l e v a n t v a r i a b l e s
34 x  = data ( : , 1 ) + 2 . 5 5 5 ;  %p o s i t i o n on measuring a x i s
35 T  = data ( : , 5 ) + data ( : , 6 ) / 6 0 ;  %time measured
36 N T = data ( : , 7 ) ;  %number o f counts

37

38% C a l c u l a t e u n c e r t a i n t i e s
39 dx = 1/10∗ ones ( 1 , length ( x ) ) ;  %assumed from the measurements
40 dT = zeros ( 1 , length (T) ) ;  %assumed to be i r r e l e v a n t
41 dN T = sqrt (N T) ;  %Poisson d i s t r i b u t e d numbers

42

43% C a l c u l a t e i n t e n s i t y in counts per minute
44 N  = N T . / T;
45 dN = dN T . / T;

46

47% Pick out a l l a c t u a l measured h e i g h t data
48 h1t = data ( : , 3 ) ;  %h e i g h t from s u r f a c e to bor
49 h2t = data ( : , 4 ) ;  %h e i g h t from d e t e c t o r top to bor

xcvi  H.3 MatLAB scripts

50 dh1t = ones ( 1 , length ( h1t ) ) ∗ 0 . 0 5 ;  %u n c e r t a i n t y from reading nonius
51 dh2t = ones ( 1 , length ( h1t ) ) ∗ 0 . 0 5 ;  %u n c e r t a i n t y from reading nonius
52 k = 0 ;
53 for i = 1 : length ( h1t )
54 i f ( h1t ( i ) > 0) %use only a c t u a l measured data
55  k = k + 1 ;
56  h1 ( k ) = h1t ( i ) ;
57  h2 ( k ) = h2t ( i ) ;
58  dh1 ( k ) = dh1t ( i ) ;
59  dh2 ( k ) = dh2t ( i ) ;
60  end
61 end

62

63% C a l c u l a t e the average h e i g h t o f the d e t e c t o r
64 housing = ones ( 1 , length ( h1 ) ) ∗ 1 8 . 7 ; %l e n g t h o f bor housing
65 dhousing = ones ( 1 , length ( h1 ) ) ∗ 0 . 0 5 ;  %u n c e r t a i n t y from reading nonius
66 detectorL = ones ( 1 , length ( h1 ) ) ∗ 1 2 . 7 5 ;  %l e n g t h o f d e t e c t o r
67 ddetectorL = ones ( 1 , length ( h1 ) ) ∗ 0 . 0 5 ;  %u n c e r t a i n t y from reading nonius
68 h e i g h t  = h1 + housing − detectorL − h2 ;
69 dheight  = sqrt ( dh1 . ˆ 2 + dhousing . ˆ 2 + ddetectorL . ˆ 2 + dh2 . ˆ 2 ) ;
70 avgheight = sum( h e i g h t ) /length ( h e i g h t ) ;
71%d a v g h e i g h t= 1/ l e n g t h ( h e i g h t ) ∗ s q r t (sum( d h e i g h t . ˆ 2 ) ) ;
72 davgheight = (max( h e i g h t )−min( h e i g h t ) ) / 2 ;
73 fprintf ( [ ’ The average h e i g h t o f the d e t e c t o r over the s u r f a c e i s : ’ , …
74  num2str( avgheight ) , ’ +/− ’ ,num2str( davgheight ) , ’ cm\n ’ ] )
75 fprintf ( [ ’  so the average h e i g h t o f the d e t e c t o r over the bottom ’ , …
76  ’ s u r f a c e i s : ’ ,num2str(10∗( avgheight +6.8) ) , ’ mm\n ’ ] )

77

78% C a l c u l a t e the average h e i g h t o f the bor p l a s t
79 avgh1  = sum( h1 ) /length ( h1 ) ;
80%davgh1  = 1/ l e n g t h ( h1 ) ∗ s q r t (sum( dh1 . ˆ 2 ) ) ;
81 davgh1  = (max( h1 )−min( h1 ) ) / 2 ;
82 fprintf ( [ ’ The average h e i g h t o f the bor p l a s t over the s u r f a c e i s : ’ , …
83  num2str( avgh1 ) , ’ +/− ’ ,num2str( davgh1 ) , ’ cm\n ’ ] )
84 fprintf ( [ ’  so the average h e i g h t o f the bor p l a s t over the bottom ’ , …
85  ’ s u r f a c e i s : ’ ,num2str(10∗( avgh1 +6.8) ) , ’ mm\n\n ’ ] )

86

87 end
1 function [ x , dx , de , dde ,T, dT, N T , dN T ,N, dN ] = r e a d r e a l d a t a c y l ( f i l e )
2% Read in data from d a t a f i l e o f with 15 h e a d e r l i n e s , and rows l i k e the f o l l o w i n g :
3% x [cm] , y [cm] , h1 [cm] , h2 [cm] , de [cm] , d i [cm] , T [ min ] , T [ sek ] ,
4% N T [ counts ]
5%
6% Explanation o f the d a t a f i l e rows :
7% x  d i s t a n c e from d e t e c t o r ( bor ) s i d e to moderator top s i d e
8% y  d i s t a n c e from d e t e c t o r ( bor ) s i d e to r i g h t s i d e o f moderator
9% h1  d i s t a n c e from d e t e c t o r ( bor ) bottom to moderator s u r f a c e
10%  i f zero , i t was not p o s s i b l e to measure because o f geometry
11% h2  d i s t a n c e from d e t e c t o r ( bor ) top to d e t e c t o r top
12% de  depht o f h o l e
13% d i  maximum diameter o f h o l e ( t r i e d to keep t h i s one constant )
14% T  time counted ( s p l i t i n t o minutes and seconds below )
15% N T number o f counts
16%
17% Explanation o f output v a r i a b l e s :
18% x  x−v a l u e ( p o s i t i o n along measuring a x i s )
19% dx  u n c e r t a i n t y o f the x−v a l u e
20% de  depht o f h o l e
21% dde  u n c e r t a i n t y in the h o l e depth
22% T  counting time
23% dT  u n c e r t a i n t y o f the time

Appendix H Source codes  xcvii

24% N T  count number during time T
25% dN T u n c e r t a i n t y o f the count number
26% N  i n t e n s i t y c a l c u l a t e d in u n i t s o f cpm
27% dN  u n c e r t a i n t y o f the i n t e n s i t y

28

29% Read in data
30 fprintf ( [ ’ Reading in data from d a t a f i l e ’ , f i l e , ’ . dat … \ n ’ ] )
31 f i d = fopen ( [ f i l e , ’ . dat ’ ] ) ;
32 data = c e l l 2 m a t ( t e x t s c a n ( f i d , ’%n %n %n %n %n %n %n %n %n ’ , ’ h e a d e r l i n e s ’ ,15) ) ;
33 fclose ( f i d ) ;

34

35% Save the r e l e v a n t v a r i a b l e s
36 x = data ( : , 1 ) +2.555; %p o s i t i o n on measuring a x i s
37 de = data ( : , 5 ) ;  %depth o f h o l e
38 T = data ( : , 7 ) + data ( : , 8 ) / 6 0 ; %time measured
39 N T = data ( : , 9 ) ;  %number o f counts

40

41% C a l c u l a t e u n c e r t a i n t i e s
42 dx = 1/10∗ ones ( 1 , length ( x ) ) ;  %assumed from the measurements
43 dde = zeros ( 1 , length ( de ) ) ;  %assumed to be i r r e l e v a n t
44 dT = zeros ( 1 , length (T) ) ;  %assumed to be i r r e l e v a n t
45 dN T = sqrt (N T) ;  %Poisson d i s t r i b u t e d numbers

46

47% C a l c u l a t e i n t e n s i t y in counts per minute
48 N  = N T . / T;
49 dN = dN T . / T;

50

51 end
1 function [ Nout , dNout ] = removebg ( N, dN, bg , dbg )
2% Removes background from data and c a l c u l a t e s the new u n c e r t a i n t i e s .
3%
4% Explanation o f input parameters :
5% N  the found i n t e n s i t y
6% dN  u n c e r t a i n t y in the i n t e n s i t y
7% bg  the found background
8% dbg  u n c e r t a i n t y in the background
9%
10% Explanation o f output v a r i a b l e s :
11% Nout new c a l c u l a t e d i n t e n s i t y , a f t e r the background s u b t r a c t i o n
12% dNout u n c e r t a i n t y in the new i n t e n s i t y

13

14% Perform the c a l c u l a t i o n
15 fprintf ( ’ S u b t r a c t i n g background from data … \ n\n ’ )
16 Nout = N − bg ;
17 dNout = sqrt ( dN. ˆ 2 + dbgˆ 2 ) ;

18

19 end
1 function [ path opt , paths ] = r e a d d a t a p a t h ( t i , f i l e , bool , i n c r )
2% Read in path data and p l o t them ( a l l at once or incremental with user
3% c l i c k i n g a button to p l o t more ) .
4%
5% Explanation o f input parameters :
6% t i  e x t r a t e x t f o r the p l o t t i t l e
7% f i l e  f i l e name in the data d i r e c t o r y
8% b o o l  i f 1 , p l o t i n c r e m e n t i a l l y ; i f 0 , p l o t a l l
9% i n c r  number o f p o i n t s to p l o t at a time i f b o o l = 1
10%
11% Overview o f the p a t h o p t array :
12% p a t h o p t (1)  path number
13% p a t h o p t (2)  neutron number

xcviii  H.3 MatLAB scripts

14% p a t h o p t (3)  xmax o f moderator
15% p a t h o p t (4)  ymax o f moderator
16% p a t h o p t (5)  zmax o f moderator
17% p a t h o p t (6)  x o f sphere c e n t e r
18% p a t h o p t (7)  y o f sphere c e n t e r
19% p a t h o p t (8)  z o f sphere c e n t e r
20% p a t h o p t (9)  r a d i u s o f sphere
21% p a t h o p t (10) s t a r t energy
22% p a t h o p t (11) thermal energy
23%
24% Overview o f the paths array :
25% paths ( : , 1 )  p o i n t number
26% paths ( : , 2 )  p o i n t x−p o s i t i o n
27% paths ( : , 3 )  p o i n t y−p o s i t i o n
28% paths ( : , 4 )  p o i n t z−p o s i t i o n
29% paths ( : , 5 )  d i s t ( f o r debugging )
30% paths ( : , 6 )  neutron energy

31

32% Open f i l e and read in path data o p t i o n s
33 f i d = fopen ( [ f i l e , ’ . dat ’ ] ) ;
34 path opt temp = c e l l 2 m a t ( t e x t s c a n ( f i d , ’%n %n %n %n %n %n %n %n %n %n %n ’ , …
35  ’ h e a d e r l i n e s ’ , 0 ) ) ;
36 fclose ( f i d ) ;

37

38 path opt = path opt temp ( 1 , : ) ;

39

40% Open f i l e and read in path data
41 f i d = fopen ( [ f i l e , ’ . dat ’ ] ) ;
42 paths = c e l l 2 m a t ( t e x t s c a n ( f i d , ’%n %n %n %n %n %n ’ , ’ h e a d e r l i n e s ’ , 1 ) ) ;
43 fclose ( f i d ) ;

44

45% Defining moderator f a c e s to put in the p l o t
46 xmin = 0 ; xmax = path opt ( 3 ) ;
47 ymin = 0 ; ymax = path opt ( 4 ) ;
48 zmin = 0 ; zmax = path opt ( 5 ) ;

49

50 xpatch1 = [ xmax xmax xmin xmin ] ;
51 ypatch1 = [ ymin ymin ymin ymin ] ;
52 zpatch1 = [ zmin zmax zmax zmin ] ;
53 xpatch2 = [ xmax xmin xmin xmax ] ;
54 ypatch2 = [ ymin ymin ymax ymax ] ;
55 zpatch2 = [ zmax zmax zmax zmax ] ;
56 xpatch3 = [ xmin xmin xmin xmin ] ;
57 ypatch3 = [ ymin ymax ymax ymin ] ;
58 zpatch3 = [ zmax zmax zmin zmin ] ;
59 xpatch4 = [ xmin xmax xmax xmin ] ;
60 ypatch4 = [ ymin ymin ymax ymax ] ;
61 zpatch4 = [ zmin zmin zmin zmin ] ;
62 xpatch5 = [ xmax xmax xmax xmax ] ;
63 ypatch5 = [ ymin ymin ymax ymax ] ;
64 zpatch5 = [ zmin zmax zmax zmin ] ;
65 xpatch6 = [ xmax xmin xmin xmax ] ;
66 ypatch6 = [ ymax ymax ymax ymax ] ;
67 zpatch6 = [ zmax zmax zmin zmin ] ;

68

69% I n i t i a l i z e f i g u r e
70 figure

71

72% Plot the moderator f a c e s
73 patch ( xpatch1 , ypatch1 , zpatch1 , ’ r ’ , ’ FaceAlpha ’ , 0 )
74 patch ( xpatch2 , ypatch2 , zpatch2 , ’ y ’ , ’ FaceAlpha ’ , 0 )

Appendix H Source codes  xcix

75 patch ( xpatch3 , ypatch3 , zpatch3 , ’ g ’ , ’ FaceAlpha ’ , 0 )
76 patch ( xpatch4 , ypatch4 , zpatch4 , ’ c ’ , ’ FaceAlpha ’ , 0 )
77 patch ( xpatch5 , ypatch5 , zpatch5 , ’ b ’ , ’ FaceAlpha ’ , 0 )
78 patch ( xpatch6 , ypatch6 , zpatch6 , ’ k ’ , ’ FaceAlpha ’ , 0 )

79

80 hold on

81

82 t i t l e ( [ ’From d a t a f i l e ’ , f i l e , ’ . ’ , t i ] )
83 xlabel ( ’ x−d i r e c t i o n ’ )
84 ylabel ( ’ y−d i r e c t i o n ’ )
85 zlabel ( ’ z−d i r e c t i o n ’ )

86

87% Set axes
88 x l = xmax − xmin ;
89 y l = ymax − ymin ;
90 z l = zmax − zmin ;
91 axis ( [ xmin−x l /10 xmax+x l /10 ymin−y l /10 ymax+y l /10 zmin−z l /10 zmax+z l / 1 0 ] )

92

93% Set viewing angle
94 Az = 3 9 ; El = 2 6 ;
95 view (Az , El )

96

97% Plot path
98 i f ( bool = 0)
99  plot3 ( paths ( : , 2 ) , paths ( : , 3 ) , paths ( : , 4 ) , ’− ’ )
100 else i f ( bool = 1)
101  imax = length ( paths ( : , 2 ) ) ;
102  plot3 ( paths ( 1 : incr , 2 ) , paths ( 1 : incr , 3 ) , paths ( 1 : incr , 4 ) , ’− ’ )

103

104  fprintf ( ’  ’ )
105  for i = i n c r : i n c r : imax
106  fprintf ( ’ \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b ’ )
107  i f ( i + i n c r <= length ( paths ( : , 2 ) ) )
108  plot3 ( paths ( i : i+incr , 2 ) , paths ( i : i+incr , 3 ) , paths ( i : i+incr , 4 ) , ’− ’ )
109  else
110  plot3 ( paths ( i : imax , 2 ) , paths ( i : imax , 3 ) , paths ( i : imax , 4 ) , ’− ’ )
111  end
112  fprintf ( ’ Press any key to continue … ’ )
113  pause
114  end
115 end

116

117 fprintf ( ’ \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b ’ )

118

119 end