+ All Categories
Home > Documents > Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the...

Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the...

Date post: 18-Jan-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
28
Department of Physics and Astronomy Uppsala University P.O. Box 516 SE – 751 20 Uppsala Sweden Papers in the FREIA Report Series are published on internet in PDF- formats. Download from http://uu.diva-portal.org FREIA Report 2017/02 January 2017 Implementation of a solenoidal magnetic field map in FLUKA DEPARTMENT OF PHYSICS AND ASTRONOMY UPPSALA UNIVERSITY Patrik Simion Uppsala University, Uppsala, Sweden
Transcript
Page 1: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

Department of Physics and Astronomy Uppsala University P.O. Box 516 SE – 751 20 Uppsala Sweden

Papers in the FREIA Report Series are published on internet in PDF- formats.

Download from http://uu.diva-portal.org

FREIA Report 2017/02

January 2017

Implementation of a solenoidal

magnetic field map in FLUKA

DEPARTMENT OF PHYSICS AND ASTRONOMY

UPPSALA UNIVERSITY

Patrik Simion

Uppsala University, Uppsala, Sweden

Page 2: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

Implementation of a solenoidal magnetic

�eld map in FLUKA

Patrik Simion

Uppsala University

Project in Applied Physics

Supervisor: Maja Olvegård

Examiner: Mikael Sternad

1

Page 3: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

Abstract

This report describes the creation of a solenoidal magnetic �eld in MATLAB and the process

of integrating said �eld into the physics simulation program FLUKA as a magnetic �eld map.

The implementation of an externally created �eld map in FLUKA was mainly accomplished

through programming of the mag�d.f user de�ned routine which is responsible for reading the

map and for conveying the information to the simulation. In order to validate the magnetic

�eld interpretation in FLUKA, charged pions were tracked through a solenoid magnet. The

FLUKA simulation was compared with theoretical descriptions of the characteristics shown by

a particle travelling inside a solenoid magnet in order to validate that the magnetic �eld behaved

as intended. The method can be further developed to investigate the suitability of alternative

pion collectors for producing well collimated, high intensity neutrino beams.

2

Page 4: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

Contents

1 Introduction 4

1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.2 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.3 Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Solenoid 5

2.1 The Solenoidal Magnetic Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 Characteristics of Particles Moving in a Solenoidal Magnetic Field . . . . . . . . . . 7

2.2.1 Helical Radius . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.2.2 Helical Rotation Angle and Direction . . . . . . . . . . . . . . . . . . . . . . . 8

2.3 Solenoid as a Focusing Magnet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.3.1 Source Outside . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.3.2 Source Inside . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.4 Matrix Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3 Implementation of Magnetic Field Map 11

3.1 MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.2 FLUKA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

3.2.1 mag�d.f . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.3 The Graphical Interface Flair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

4 Comparison of Simulation and Analytical Description 16

4.1 Simulation and Matrix Comparison with Source Outside . . . . . . . . . . . . . . . . 164.1.1 Varying the Source Placement . . . . . . . . . . . . . . . . . . . . . . . . . . 164.1.2 Varying the Initial Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . 174.1.3 Characteristics Inside the Solenoid . . . . . . . . . . . . . . . . . . . . . . . . 19

4.2 Simulation and Matrix Comparison with Source Inside . . . . . . . . . . . . . . . . . 194.2.1 Varying the Particle's Momentum . . . . . . . . . . . . . . . . . . . . . . . . 194.2.2 Varying the Initial Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

5 Discussion and Conclusion 22

5.1 Analysis of the Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225.2 Outlook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

6 Appendix 23

6.1 Appendix A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236.2 Appendix B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256.3 Appendix C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

3

Page 5: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

1 Introduction

1.1 Background

At the European Spallation Source (ESS) the world's most intense proton linear accelerator is beingconstructed and is projected to start operation by 2023 [1]. In parallel to the acceleration of protons,the linac could be used for delivering a neutrino super beam with tremendous intensity. Utilizingthis opportunity is the ESS neutrino Super Beam (ESSνSB) project which will be dedicated to themeasuring of CP violation in the leptonic sector.

The conventional method to produce a neutrino super beam is by employing a magnetic hornto cover the neutrino target where charged pions are produced by impinging proton bunches fromthe linear accelerator. A magnetic horn is of a toroidal structure with the magnetic �eld enclosed,which provides charge separation and focusing of the pions before they decay into neutrinos to formthe neutrino Super Beam. To generate the magnetic �eld, a very high current needs to be passedthrough the walls of the structure, which can only be maintained for a very short time period due tothe resulting heating. Making the horn superconducting would enable DC operation but is greatlycomplicated due to the energy deposition from the pions when passing through the structure'swalls. The duration of the nominal pulse from the ESS linac is much longer than what the horn canhandle without overheating and thus the pulse duration needs to be shortened. The compressionof the proton pulse can be accomplished in an accumulator ring but to reach a satisfying e�ciencyin pulse compression the linac also has to be equipped to accelerate H− pulses to enable chargeexchange injection to the ring. These required extensions to the ESS facility could be omitted if analternative pion collector, that can handle the nominal proton pulses, was to be used instead of thehorn. A superconducting solenoid could provide focusing, but does not provide charge separation,for the long pulses and is considered to be a key component for a viable option to the magnetic horn.An investigation of how di�erent magnetic structures, such as the solenoid, can handle the neutrinoSuper Beam needs to be performed in, for example, the physics simulation program FLUKA whereparticle transport through magnetic �elds can be simulated.

1.2 Objective

The objective of this project is to implement a solenoidal magnetic �eld in the simulations programFLUKA by appending an external �eld map. A magnetic �eld can be implemented in FLUKA byprogramming the user de�ned routines in order to read an external magnetic �eld map. By creatinga solenoidal magnetic �eld in MATLAB using a �nite di�erence method and established electromag-netic theory, the magnetic �eld map could be designed according to the simulation requirements andimplemented in FLUKA as intended. Once the magnetic �eld had been implemented the outcomeof the simulations was compared to relevant theory to assure its consistency.

1.3 Outline

In Section 2 we begin by formulating the theoretical description of the solenoid's magnetic �eldthrough its axial and radial components. The equations that we attain are then to be further usedto create a simpli�ed model which is applicable in FLUKA. We also cover the characteristics shownby particles when moving in the solenoid's �eld along with a description of how the matrix systemis constructed for the later use in comparing simulation to theory. Further on, in Section 3 the focuslies in how the simulation is built by describing the construction of the �eld map in MATLAB aswell as the necessary programming of the user de�ned routines. Shown in Section 4 is the resultsfrom comparing the simulated solenoid to the matrix model for situations where a point-to-parallelfocusing is predicted by theoretical relations.

4

Page 6: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

2 Solenoid

2.1 The Solenoidal Magnetic Field

A solenoid consists of a tightly wound coil which forms a long open cylinder that gives rise toa characteristic magnetic �eld when a current is led through its windings. The magnetic �eldconsidered in this report exists inside the cylinder and extends in the axial direction as fringe �elds.Since the cylinder is open the particles does not have to pass through the structure's wall in orderto be a�ected by the magnetic �eld which increases the chances of the solenoid collector to beoperated in a continuous DC state as a superconductor.

The shape of the solenoid provides compelling reason for using a cylindrical coordinate systemwhen looking at its magnetic �eld. Its axial symmetry allows for a complete description of themagnetic �eld using the radial and axial components, r and z respectively, while the angularcomponent φ cancels out. This means that it is necessary and su�cient to determine the axialmagnetic �eld component Bz and the radial component Br. In Figure 1 a representation of the twomagnetic �eld components are shown.

Figure 1: Schematic showing the components Bz and Br of a solenoidal magnetic �eld and thedimensional variables L, z and R used in eq. (1)

The axial �eld can be determined to the �rst order by initially de�ning a solenoid of in�nite length.In the �rst order approximation this solenoid would have a homogeneous magnetic �eld inside witha strength that is independent of the radial position. In the in�nite length abstraction the axial�eld is given by Bz,inf = µ0nI where µ0 is the permeability of vacuum, n the number of windingsper unit length and I the current.

5

Page 7: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

The on-axis �eld for a solenoid of �nite length can be expressed in terms of Bz,inf by applyingthe Biot-Savart law or through use of a simpli�ed expression. The expression reads [2]

Bz =Bz,inf

2

[(L/2)− z√

(z − (L/2))2 +R2+

(L/2) + z√(z + (L/2))2 +R2

](1)

which is a �rst order description of the axial �eld. In eq. (1) we de�ne the length L of thesolenoid as the distance between the entrance and exit of the solenoid with a radius R as shownin Figure 1. The desired �eld strength Bz,inf at the centre of the solenoid can then be chosenand one decides the width of the �eld, centred in the middle of the solenoid, by the variable zwhich determines how far the axial �eld extends from the solenoid as is also shown in Figure 1. Avisualization of the resulting axial �eld Bz from eq. (2) is presented in Figure 2.

Figure 2: The axial magnetic �eld component Bz calculated using eq. (1) for a L = 1m long solenoidof radius R = 10 cm and a �eld width z = 600 cm at a maximum �eld strength Bz,inf = 9 T , withcorresponding hard edge approximate �eld B0.

The radial �eld can be found by following the reasoning given in [3] where the Laplace equation fora scalar potential is solved by applying a serial form of the solution, which provides a �rst orderlinear term for the radial component. This component is given as

Br =−r2B′z(z) (2)

6

Page 8: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

where r is the radial distance from the solenoidal axis. It is evident in eq. (2) that the radial �elddepends on the change in the axial �eld, B′z(z), and increases in strength further from the centralaxis. The strength of the radial magnetic �eld will therefore be at a maximum at the entrance andexit of the solenoid where the largest changes in Bz occur and will increase in magnitude furtherfrom the solenoid axis. Shown in Figure 3 is the radial �eld calculated at three di�erent radialpositions r for the Bz �eld generated by the solenoid de�ned in Figure 2.

Figure 3: Radial magnetic �eld component Br at radial positions r = 0, 5, 10 cm, calculated usingeq. (2) for the solenoid de�ned in Figure 2.

2.2 Characteristics of Particles Moving in a Solenoidal Magnetic Field

We now go onto looking at the e�ect of a solenoid on the trajectory of a charged pion. For a simpleranalytical description of the solenoid we look at its hard edge equivalent. This means that the axial�eld is assumed to be constant inside the solenoid and zero outside. This, in turn, implies thatthe radial �eld is zero everywhere except at the entrance and exit. The equivalent hard edge axial�eld is calculated by integrating the axial �eld Bz of the solenoid over the total �eld width andthen dividing the result by the length of the solenoid, giving the approximated �eld strength B0 asshown in Figure 2.

A charged particle inside the solenoid �eld follows a helical path. As a charged particle ap-proaches the entrance of the solenoid its transverse momentum will couple to the axial �eld andproduce a rotation about the helical axis. When the charged particle is inside the solenoid, where

7

Page 9: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

the axial �eld can be considered constant, the radius of the rotation will remain constant until theexit of the solenoid is reached.

2.2.1 Helical Radius

Consider a positively charged pion approaching the entrance of a solenoid. In the impulse approx-imation a particle will be given an increase in its azimuthal momentum, from the steep change inthe radial �eld, when it enters the magnet [4]. Using this in addition to the paraxial approxima-tion where we assume very small deviation in the particle's direction and position relative to thesolenoid's symmetry axis. The transverse momentum of a particle, resulting from the kick, can befound by determining the angular and radial components of the momentum for a particle with totalmomentum P [4]. The angular component is given by

Pφ1 = −eB0r12

(3)

where r1 is the radial position of the particle upon entering the magnet and B0 is the axial magnetic�eld. The radial momentum can be calculated as

Pr1 = Pθ1 (4)

with a production angle θ1 which is the direction of the particle relative to the solenoid axis. Withthese components found, the total transverse momentum of the particle is given by

P⊥ =√P 2φ1

+ P 2r1 (5)

The radius Rh of the helical path made by the particle when travelling inside the magnet is thengiven by

Rh =P⊥eB0

(6)

2.2.2 Helical Rotation Angle and Direction

It is possible to calculate the rotation angle φh of a particle about the helical axis as it travelsthrough the solenoidal magnet [4]. By determining the Larmor frequency

ω =qB0

γm(7)

where γ is the Lorentz factor and m is the rest mass of the particle, we can multiply the frequencyby the time it takes for the particle to traverse the length of the magnet

t =L

Pz/γm(8)

so that the rotation angle can be found through

φh = ωt (9)

thus providing the second characteristic of the helical trajectory. By changing the sign of the charge,q = ±e where e is the elementary charge, the particle rotation changes direction in eq. (7), frommoving in a counter-clockwise direction for a positive pion to a clockwise direction for a negativelycharged pion when seen along the z axis, as is predicted by the Lorentz force law.

8

Page 10: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

2.3 Solenoid as a Focusing Magnet

A solenoid can be used as a focusing magnet, We will discuss two distinct cases. The �rst is whenthe source is placed outside of the solenoidal magnet and the second is when the source is placedinside. In both cases the goal is to produce a beam with near zero divergence relative to the solenoidaxis when originating from a point source, denoted point-to-parallel focusing.

2.3.1 Source Outside

To produce a parallel beam from a point source located outside of the solenoid we begin by consid-ering a charged particle leaving the solenoid at some radial position r2 which will cross the magneticaxis at a distance d2. When d2 is positive we may treat the magnet as a thick focusing lens [4] andas the distance, d2, increases, the angle, θ2, of which the particle diverts from the magnetic axis,decreases according to

tan( r2d2

)= θ2 (10)

so that we may accomplish a point-to-parallel focusing as d2 →∞. We calculate where the particlecrosses the magnetic axis through

d2 =2P

eB0 tan(β)(11)

where P is the particle's momentum and β is given by

β =L

2λ− tan−1(

d1) (12)

with d1 being the distance between the source and the entrance of the solenoid. The Larmorwavelength λ is de�ned as [4]

λ =P

eB0(13)

For the case of point-to-parallel focusing, i.e. with d2 →∞, the focal length of the solenoid can beexpressed as

f =2λ

tan( L2λ )(14)

A particle with momentum P starting a distance f from the entrance of the magnet, will leave themagnet travelling in parallel to the symmetry axis of the solenoid, irrespective of its initial angle.

9

Page 11: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

2.3.2 Source Inside

When placing the source inside of the solenoid, a parallel beam can be produced only for particleswith certain discrete momenta given in [4] as

Pn =P0

2n+ 1, (n = 0, 1, 2, ...) (15)

where

P0 =eB0L

π(16)

with the length L′ de�ned as the distance between the source and the exit of the solenoid. Thepoint-to-parallel focusing for the particles is achieved irrespective of initial angle, as for the casewith the source placed outside.

2.4 Matrix Description

To describe the propagation of a particle or particle beam through a solenoid it is possible to usethe transfer-matrix method. In our case the matrix method will be used to set up a system for thepropagation of particles from a point source, located outside or inside the solenoid, as they passthrough the solenoid and continue into free space.

We are interested in �nding the position and direction properties of the particles some distanceafter they leave the solenoid therefore a four dimensional column vector representing the source iscreated

U0 =

x0x′0y0y′0

(17)

corresponding to the particle's position, x and y, as well as the direction relative to the z axis, x′0and y′0. To determine the coordinates of the particle after passing through a system, we seek tocalculate

U1 =M U0 (18)

were M is the matrix representation of the system and the resulting column vector U1 containsnecessary information for comparing the focusing e�ect when employing the transfer-matrix methodto the results from simulations or numerical calculations.

The transfer matrix of a solenoid is based on the same hard-edge model as previous calculations.This means that it can be treated as a combination of the transfer matrices representing the en-trance and exit regions of the magnet and the central uniform �eld [3]. In the hard edge model theentrance region will give an azimuthal momentum which in matrix form is expressed as

M1 =

1 0 0 00 1 eB0

2P 00 0 1 0− eB0

2P 0 0 1

(19)

under the condition that P ≈ Pz from applying the paraxial approximation. The particle willencounter a kick in the opposite direction at the exit which cancels out the azimuthal momentumgiven in M1. The matrix form of the exit region will therefore be the same as in eq. (19) with the

10

Page 12: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

kick given in the opposite direction as

M3 =

1 0 0 00 1 − eB0

2P 00 0 1 0eB0

2P 0 0 1

(20)

To complete the matrix description we need to consider the central part of the solenoid containingthe uniform magnetic �eld. The central matrix describes the helical trajectory inside the uniform�eld and is given as

M2 =

1 L

θ sin(θ) 0 Lθ (1− cos(θ))

0 cos(θ) 0 sin(θ)0 −Lθ (1− cos(θ)) 1 L

θ sin(θ)0 − sin(θ) 0 cos(θ)

(21)

with θ = eB0L/P being the rotation angle completed by the particle inside the solenoid. We cancombine the three matrices to form a complete description of the solenoid

Msol =M3M2M1 =

C2 CS/α CS S2/α−CSα C2 −S2α CS−CS −S2/α C2 CSαS2α −CS −CSα C2

(22)

by setting C = cos(θ/2), S = sin(θ/2), θ = 2Lα and α = eB0/2P . When we are to use the matrixmethod for a source placed inside the solenoid the particle will be a�ected by the centre �eld overthe distance between the source and the exit edge and will thereafter receive the kick from the exitfringe �eld. The e�ect of the half-solenoid can in this case be described by

Msol, inside =M3M2(L′) (23)

where the distance between the source and the exit of the solenoid is given by L′.With the transfer matrix of the solenoid de�ned we can continue to build the system by adding

the propagation matrices for when the particle is travelling through free space, a so called drift.The drift matrix is given by

Mdrift(s) =

1 s 0 00 1 0 00 0 1 s0 0 0 1

(24)

where the variable s indicates the length of the drift. The two systems can now be given as

Msys, outside =Mdrift2MsolMdrift1 (25)

Msys, inside =Mdrift2Msol, inside (26)

depending on the source placement, and used in eq. (18) for calculating U1.

3 Implementation of Magnetic Field Map

3.1 MATLAB

A magnetic �eld map is a discrete representation of a continuous magnetic �eld in a given region.In this case, the magnetic �eld of the solenoid is described by the two components Bz and Br.These components were calculated numerically in MATLAB, see appendix A for details.

11

Page 13: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

The MATLAB program detailed in Appendix A begins with the declaration of the variablesBz,inf , L, R and z, as previously de�ned, to be used in eq. (1) for calculating the Bz �eld. Thiswill at the same time de�ne a magnetic �eld region for the solenoid given by the two variables zand R corresponding to the total width and the radius in a cylindrical coordinate system. We thencontinue by setting the number of measuring points in the axial and radial direction, Nz and Nrrespectively, so that a discretization of the magnetic �eld region can be made which is illustratedin Figure 4.

Figure 4: Discretization of the magnetic �eld region showing measuring points in radial Nr andaxial direction Nz. The axial points begin at position −z/2 and continues along the positive z axisto z/2.

The position coordinates of the measuring points are saved in two vectors named ZB(k) and RB(i)which are used as reference points when extracting the magnetic �eld values inside the simulationprogram. To assign the magnetic �eld values to the axial measuring points the function MagFieldBZ,seen in Appendix B, is used to return the vector BZ(k) which is a discrete representation of eq.(1) with a vector length equal to Nz. A derivative of this vector is then calculated and used todetermine the discrete valued radial component of the magnetic �eld according to eq. (2). Thisresults in the matrix BR(i, k) containing Nr rows and Nz columns due to the dependence on bothradial and axial position in the radial magnetic �eld component Br.

The last step of the program is to save the data in a plain text format which is readable by thesimulation program. Both the position vectors ZB(k) and RB(i) are put in separate �les as singlecolumn vectors creating an ascending indexation.

3.2 FLUKA

FLUKA [5] [6] is a physics simulation program for particle transport and interactions with matter.It has a wide range of applications and can be further diversi�ed through programming of theuser interface routines if special requirements are necessary for the simulation. FLUKA can trackparticles in regions with a magnetic �eld. A homogeneous magnetic �eld can be de�ned directly inthe program. In addition, a magnetic �eld map can be imported into the program. In this case,the user routine mag�d.f is reprogrammed in order to instruct FLUKA on how to interpret themagnetic �eld map.

3.2.1 mag�d.f

The programming written in the mag�d.f user routine is presented in Appendix C and is conductedto provide the simulation with the information contained within the �eld map. FLUKA receives

12

Page 14: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

information from the mag�d.f routine in terms of the total �eld strength B and its direction cosinesin Carteesian coordinates. Therefore we must convert the information in the �eld map from acylindrical to a Carteesian description within the routine before calculating the total �eld strengthand its direction. The way to achieve this can be generalized to a few steps. Every time the particlemoves a small incremental step within the magnetic �eld region the simulation will make a call tothe user routine. During the �rst call to the routine it opens and reads the �les containing the �eldmap. Thereafter, each time the routine is called, it compares the current particle position given byFLUKA to the discrete positions stored in the vectors ZB(i) and RB(k) and extracts the magnetic�eld values from the closest point represented.

At initiation, a section of the routine that is to run only once following the �rst call from FLUKAis handled by the LFIRST command. This section therefore includes the opening and reading ofthe plain text �les that were generated in the MATLAB program to form the �eld map. Whenthe routine is called beyond the �rst time the process of opening and reading the �les is e�ectivelydisregarded.

With the data retrieved the next step is to structure the part which is to run during each call tothe routine. The position of the particle inside the simulation is given by its Cartesian coordinates,X and Y , and must be related to the cylindrical system used in the �eld map. Note that the �eldis independent of the angle tan−1(Y/X). We introduce the radial position variable R =

√X2 + Y 2

inside the routine. We now compare the radial distance given by R to the discrete positions storedinside the vector RB(i). This is done by stepping through the discrete values until the closestrepresentation of R inside RB(i) is found. The corresponding procedure is performed for the axialcomponent to determine the representation of the simulated axial position Z in the vector ZB(k).Once the discrete representation of the particle's position has been identi�ed in RB(i) and ZB(k)the indices i and k are used to access the magnetic �eld values stored in the BZ(k) and BR(i, k)vectors, as described below.

13

Page 15: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

To provide the simulation with the information of the axial magnetic �eld contained in thediscrete BZ(k) vector we note that the magnitude is only dependent on the axial position. Thedirection will be along the positive z-axis and we obtain the value from BZ(k) by inserting the kindex which was determined in the previous procedure.

In the case of the radial component we extract the magnetic �eld value Br from BR(i, k) byinserting the found i and k indices. This provides a radial �eld magnitude with a direction pointingradially towards or away from the symmetry axis of the solenoid for the entrance and exit fringe�elds respectively, see Figure 3. In the routine we resolve the radial component into its x- andy-components by using the particle's current position and the conversion properties between acylindrical and Cartesian system

BRX = BR(i, k)X

R(27)

BRY = BR(i, k)Y

R(28)

where the variables X, Y and R are the position coordinates of the particle given by FLUKA. Withthe radial component resolved we obtain the magnetic �eld in terms of x- and y-components de�nedas BRX and BRY in the mag�d.f routine. The process is illustrated in Figure 5.

Figure 5: Vector resolve of the radial �eld vector BR(i, k) into the Cartesian components BRXand BRY in the mag�d.f routine.

Finally, the total �eld intensity is calculated from the three resulting �eld components throughB =

√BZ(k)2 +BRX2 +BRY 2 which is then used to divide each of the components to e�ectively

normalize and provide the direction cosines for the magnetic �eld in three dimensions which iscompulsory to the routine. An example of the total magnetic �eld vector and its components foran arbitrary point is presented in Figure 6.

14

Page 16: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

Figure 6: The magnetic �eld for an arbitrary point inside the simulation. The three componentsBRX, BRY and BZ(k) are needed to give the direction and magnitude for the total magnetic �eldvector B.

3.3 The Graphical Interface Flair

The advanced interface program for FLUKA called �air [7] was used to construct the project andto run the simulations. This interface provides tools for handling and visualizing the many inputoptions and provides an overview of the complete set-up. In order to run a simulation with themagnetic �eld map there are settings that need to be present and set in a speci�c way. A magnetic�eld region has to be de�ned that has the same width and radius as the magnetic �eld generated fromthe MATLAB code to form the �eld map. In this case a circular cylinder was used and positionedto coincide with the coordinates of the RB(i) and ZB(k) position vectors. The cylindrical regionis then assigned to consist of a vacuum containing a magnetic �eld. To activate the call to the userroutine mag�d.f, the MGNFIELD section needs to be present and its magnetic �eld parametersset to zero. The MGNFIELD section also provides the possibility to dictate the step length of theparticle transport through the magnetic �eld region. It can therefore be used to decide the numberof times the program simulates the particle interaction with the magnetic �eld and the number oftimes the user routine is called. It therefore controls the speed and precision of the simulation.

15

Page 17: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

4 Comparison of Simulation and Analytical Description

We are interested in the focusing e�ect of the solenoid on charged particles and the agreementbetween analytical descriptions to the simulation. The matrix description provides an opportunityto compare the propagation of particles throughout a system corresponding to the simulation whilstwe use the analytical expressions for helical radius and rotation angle to compare parameters insidethe magnet.

Throughout this section the initial direction of the particles when leaving the source are givenby their direction cosines. The direction cosines are de�ned as the cosines of the angles betweena vector and the three Cartesian coordinate axes. The divergence in direction relative to the zaxis has been kept low as to �t the paraxial approximation so that the direction of the particlescorresponding to dx/dz, dy/dz or dr/dz is interchangeable with the corresponding.

4.1 Simulation and Matrix Comparison with Source Outside

The parameters for the comparison consists of those that de�ne the solenoid and those that governsthe particles. We set the solenoid to a �xed geometry, L = 1 m, R = 0.1 m, z = 6 m, with threedi�erent �eld strengths, Bz,inf = 7, 9, 11 T as de�ned in eq. (1). The number of sample pointsare set to Nz = 6001 and Nr = 301.

We then consider eqs. (11)-(13) to determine the momentum of the particles in each of thethree cases, meaning that we may treat the magnet as a thick focusing lens when d2 is positive andapproaches in�nity or is very large. This is accomplished by �nding the maximum value of d2 as afunction of momentum, P , and the distance between source and entrance, d1. From the maximumpoint of d2 we found that the momentum should be set to P = 1.360, 1.305, 1.950 GeV/c for therespective Bz,inf = 7, 9, 11 T solenoids. For the given values of the momentum, the focal lengthin eq. (14) is equal to the value of d1.

4.1.1 Varying the Source Placement

We proceed with the comparison by �rstly looking at the focusing e�ect on the outgoing direction ofthe particles while varying the source's placement. In doing so, we should see an improved focusingwhen the placement of the source is located close to the focal length. The corresponding matrixmodel is set up by varying the �rst drift length, s1, so that it equals the distance between the currentsource position and the entrance of the solenoid. The measurements for the direction of the particlesafter they passed through the solenoid is made at a distance s2 = 2.5 m behind the exit of thesolenoid in both simulation and matrix model. The particles are given their respective momentumfor the three cases and the initial directions are set to x′0 = 0.01 and y′0 = 0.01 giving a radialdirection r′0 =

√(x′0)

2 + (y′0)2. From eq. (14) the focal lengths, f , are found to be 1.22, 0.66, 1.05

m for the Bz,inf = 7, 9, 11 T case respectively. In Figure 7 the direction of the particle is presented

in its radial representation with r′1 =√(x′1)

2 + (y′1)2 for when the source is placed at -250 cm to

when the source is placed at -50 cm, corresponding to the entrance of the solenoid.

16

Page 18: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

Figure 7: Direction of the particles after passing through the solenoid, r′1 is shown as a function ofsource position where -50 cm corresponds to the entrance of the solenoid. Numerical noise is dueto �nite step length in the simulation. a) P = 1.360 GeV/c, Bz,inf = 7 T. b) P = 1.305 GeV/c,Bz,inf = 9 T. c) P = 1.950 GeV/c, Bz,inf = 11 T.

The matrix model predicts a perfect focusing when the source is placed at the focal length that wasfound through analytical calculations. We see that the simulation behaves similarly but has a fewcentimetres longer focal length and does not drop entirely to zero.

4.1.2 Varying the Initial Direction

We now seek to investigate how the focusing of the solenoid a�ects the particles when the initialdirection r′0 is increased while keeping the source �xed at three di�erent positions. Since thefocusing e�ect should be irrelevant of the initial direction of the particle, we expect that r′1/r

′0

remains constant in the matrix case. The three source placements are chosen from Figure 7-b) at-180, -140 and -100 cm with Bz,inf = 9 T and the momentum P = 1.360 GeV/c. At -180 cm thesimulation proves r′1 to be less than what the matrix model predicts, at -100 cm we see the opposite.Near -140 cm the matrix model and simulation predict very close results. Presented in Figure 8 isthe results from the three di�erent source placements.

17

Page 19: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

Figure 8: The focusing e�ect of the solenoid with the direction of the particle upon leaving thesolenoid divided by the initial direction r′1/r

′0 is shown for an increasing initial direction r′0. a)

Source positioned at -100 cm. b) Source positioned at -140 cm. c) Source positioned at -180 cm.

We see that the increasing initial direction does not a�ect the e�ciency of the solenoid. Thedi�erence between simulation and matrix model from the three source placements remain constantfor an increasing r′0.

18

Page 20: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

4.1.3 Characteristics Inside the Solenoid

The particle will follow a helical trajectory inside the magnet, giving rise to a circular motion with awell de�ned radius in the x-y plane. The radius and rotation angle are extracted from the simulationthrough evaluation of the position coordinates of the particle inside the solenoid. In Table 1, welook at the di�erence between the helical radius and rotation angle extracted from the FLUKAsimulation and that of the expected radius Rh in eq. (6) and the total rotation angle φh in eq. (9)for three di�erent conditions. The chosen conditions are when the source is placed at -180, -140and -100 cm, P = 1.360 GeV/c and Bz,inf = 9 T, with the initial directions x′0 = y′0 = 0.038. Notethat a change in the source position results in a change in the radial coordinate r at the entrance.This in turn a�ects the helical radius. Compared to the radius measured from simulation data, theanalytical calculations predict a larger radius in the two latter cases and a smaller radius in the�rst. The rotational angle from analytical calculations are larger in all three cases.

Table 1: Di�erence in helical radius and rotation angle between simulation and analytical calcula-tions for three source placements.

Source Position [cm] Rh [cm] Rsim [cm] φh [rad] φsim [rad]-100 3.0 2.6 1.99 1.69-140 3.6 3.5 1.99 1.66-180 4.4 4.5 1.99 1.63

4.2 Simulation and Matrix Comparison with Source Inside

With the source placed inside the solenoid, at z = 0, the point-to-parallel focusing should beaccomplished for certain discrete values of the momentum given by eq. (15) irrespective the initialdirection of the particles. We look at the comparison between simulation and matrix description fora solenoid with L = 2 m, R = 0.20 m and z = 6 m at three initial �eld strengths Bz,inf = 8, 12, 16T with the number of measuring points set to Nz = 6001 and Nr = 301. The particles, afterpassing through the solenoid, are evaluated 2 m from the exit of the solenoid, corresponding to anexit drift length s2 = 2 m in the matrix description.

4.2.1 Varying the Particle's Momentum

The initial direction is set to x′0 = y′0 = 0.05 rad and we vary the momentum, P , of the particlesbetween 0.1 and 1.1 GeV/c. We formulate the matrix system in eq. (26) using L′ = 1 m in theMsol, inside matrix from eq. (23). In Figure 9 the radial direction of the particles is shown for anincreasing momentum with the vertical lines corresponding to the Pn values from eq. (15).

19

Page 21: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

Figure 9: Direction of the particles after leaving the solenoid, r′1, with the source placed in thecentre of the solenoid shown as a function of increasing momentum. The vertical lines indicate thePn values calculated in eq. (15). a) Bz,inf = 8 T. b) Bz,inf = 12 T. c) Bz,inf = 16 T.

The matrix model's prediction for point-to-parallel focusing and the analytical calculations forthe Pn values coincides accurately. The simulation shows that e�ective focusing occurs when themomentum of the particle is a bit smaller than what is predicted in the matrix model, meaningthat the magnet has a weaker focusing e�ect.

4.2.2 Varying the Initial Direction

We continue by looking at the di�erence in outgoing direction of the particles when the momentumP is set to three di�erent values, P = 0.300, 0.365, 0.400 GeV/c, for the Bz,inf = 12 T solenoidand increase the initial direction of the particles. These values for the momentum corresponds towhen there is a large di�erence, and a very small di�erence, between simulation and matrix modelin Figure 9-b). We should see a constant focusing e�ciency when plotting r′1/r

′0, as in the case

with the source placed outside of the solenoid. Figure 10 shows the radial focusing, r′1/r′0, for when

initial directions, x′0 and y′0, are set between 0.001 and 0.100 with x′0 = y′0.

20

Page 22: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

Figure 10: The focusing e�ect of the solenoid with the direction of the particle upon leaving thesolenoid divided by the initial direction r′1/r

′0 is presented for an increasing initial direction r′0. a)

P = 0.3 GeV/c. b) P = 0.365 GeV/c. c) P = 0.4 GeV/c.

The di�erence between simulation and matrix model from the three momenta cases is close toconstant for an increasing r′0.

21

Page 23: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

5 Discussion and Conclusion

It has been shown that a magnetic �eld map created in MATLAB can be successfully integratedin FLUKA by programming of the user de�ned routines. The process is shown step-by-step andprovides su�cient information to form a basis for more advanced research. Since the simulationprogram FLUKA lacks the built-in tools to generate certain magnetic �elds it is essential that anexternal �eld map can be introduced.

5.1 Analysis of the Results

We have seen from the comparison that the simulation match the matrix model to a satisfactorylevel. We showed in Figure 7 that the simulation provides a weaker focusing than the hard-edgemodel. The simulation showed that the best focusing would occur when the source was placeda few centimetres further away from the entrance of the solenoid, than that predicted from thehard-edge model, but the �nal divergence never reaches zero. When we lower the hard-edge �eldvalue B0 is lowered in the analytical calculations, the waists of the two curves coincide. The resultsin Figure 8 show that the focusing is independent of the initial angle r′0 as expected and that thedi�erence, between matrix and simulation, again can be attributed to the weaker focusing power ofthe realistic �eld in the simulation.

In Figure 9 we observed that the point-to-parallel focusing occur at discrete momenta, as pre-dicted. In the matrix model, these discrete momenta are higher than what the simulation showed.By lowering the hard-edge value, B0, the matrix model would provide point-to-parallel focusing atlower momenta and agree accurately with the simulation. From the variation of initial direction inFigure 10, we see the same behaviour as for the case when the source is placed outside.

The matrix model can be considered unrealistic when compared to the simulation. It can how-ever be shown that by lowering the B0 value in the analytical calculations, the simulation andmatrix model would agree more accurately. The simulation is more credible since we include thefringe �elds, a distributed azimuthal kick and a non-homogeneous axial �eld inside the solenoid.We do not expect the matrix model and simulation to conform perfectly since FLUKA is morerealistic and does not rely on approximations. However, the agreement is enough for us to concludethat the magnetic �eld map has been successfully implemented in FLUKA.

5.2 Outlook

As a result of this project, we have provided a framework for detailed studies of the focusingcapabilities of a solenoid collector. In addition, it o�ers the opportunity to further develop thesimulations to involve combinations of magnets and more complex �elds, such as a dipole �eldwhich would provide a stage of charge separation.

In the upcoming masters thesis, a complete investigation of a magnetic �eld map provided byresearchers from CERN will be performed by using the same principles covered here. This includesincorporating an external �eld map and, in addition, an in-depth analysis of beam characteristicsand focusing. By building a basis for an advanced simulation environment, this project concludesthe �rst step towards a general investigation of a new pion collector.

22

Page 24: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

References

[1] M. Dracos, �The European Spallation Source Neutrino Super Beam for CP Violation discovery,�PoS, vol. NEUTEL2015, p. 043, 2015.

[2] N. Derby and S. Olbert., �Cylindrical magnets and ideal solenoids,� arXiv:0909.3880v1, Sep2009.

[3] P. Royer, �Solenoidal optics,� Technical Report CERN-OPEN-2000-324 ; CERN-NEUTRINO-FACTORY-NOTE-11 ; CERN-NUFACT-NOTE-11 ; CERN-PS-HP-NOTE-99-12, Dec 1999.

[4] K. T. McDonald, �A neutrino horn based on a solenoid lens,� arXiv:physics/0312022v2, Dec2003.

[5] G. Battistoni, F. Cerutti, A. Fasso, A. Ferrari, S. Muraroi, J. Ranft, S. Roesler, and P. R. Sala,�The FLUKA code: Description and benchmarking,� AIP Conf. Proc., vol. 896, no. SLAC-REPRINT-2007-184, pp. 31�49. 19 p, 2007.

[6] A. Ferrari, P. R. Sala, A. Fasso, and J. Ranft, FLUKA: A multi-particle transport code (programversion 2005). Geneva: CERN, 2005. CERN-2005-10; INFN/TC_05/11; SLAC-R-773.

[7] V. Vlachoudis, �Flair: A powerful but user friendly graphical interface for FLUKA,� in Pro-ceedings of the Int. Conf. on Mathematics, Computational Methods & Reactor Physics (M&C2009), Saratoga Springs, New York, U.S.A. (2009), 2009.

6 Appendix

6.1 Appendix A

%% Solenoidal Magnetic Field Map %%%% Creates a magnetic field map for a solenoid using FDM methods%% The dimension of the solenoid is given by the parameters% r and L, where r denotes the radius and L is the total length% of the solenoid itself. In order to calculate the magnetic field% the parameter B_zero needs to be set and corresponds to the desired% magnitude of the magnetic field vector at the center of the solenoid.%% The region in which the magnetic field is calculated is given% by the parameter r which gives the maximum radial distance from% the solenoidal centered z-axis. The width of the magnetic field% along the z-axis is given by the parameter z and is centered% at z = 0.

clear all

%% Dimensions & field intensity %%

r = 10; % Radius of solenoid and magnetic field map [cm]z = 600; % Width of magnetic field centered at z = 0 [cm]L = 100; % Length of solenoid magnet to be used in

% calculating the magnetic field [cm]B_zero = 9; % Solenoid initial magnetic field magnitude [T]

%% Discretization %%

23

Page 25: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

Nr = 301; % Number of measuring points on radial axis [#]Nz = 6001; % Number of measuring points on z-axis [#]

dr = r/(Nr-1); % Step length in radial dimension [cm]RB = 0:dr:r; % Measuring points position in radial directiondz = z/(Nz-1); % Step length in z direction [cm]ZB = -z/2:dz:z/2; % Measuring points position in z direction

%% Magnetic field in z direction, BZ %%

BZ = MagFieldBz(L, r, z, Nz, B_zero); % Returns the magnetic field% strength for each measuring% point in z direction

%% Derivative of BZ %%%% Calculates the changes between points in BZ using a centred FDM% approximation in order to further calculate the radial component% of the magnetic field

k = 2;for k = 2:1:Nz-1BZ_prime(1, k) = (BZ(1, k+1)-BZ(1, k-1))/(2*dz);k = k+1;endBZ_prime(1, Nz) = 0;

%% Magnetic field in radial direction, BR %%%% Calculates the radial component of the magnetic field using the% previously determined BZ_prime vector

BR = zeros(Nr, Nz);i = 1;for i = 1:1:Nr;BR(i, 1:Nz) = (-RB(i))/2*BZ_prime(1, 1:Nz);i = i+1;end

%% Write data to file %%%% Writes the calculated magnetic field vectors BR, BZ, and the measuring% point coordinates to files and places them in the folder shared between% the virtual machine running FLUKA and the current MATLAB workstation

filename_br = 'C:\Users\Patrik\Desktop\FlukaShared\INDATA\BRDATA.txt';filename_bz = 'C:\Users\Patrik\Desktop\FlukaShared\INDATA\BZDATA.txt';filename_rb = 'C:\Users\Patrik\Desktop\FlukaShared\INDATA\RBDATA.txt';filename_zb = 'C:\Users\Patrik\Desktop\FlukaShared\INDATA\ZBDATA.txt';

fid_br = fopen(filename_br, 'w');fid_bz = fopen(filename_bz, 'w');fid_rb = fopen(filename_rb, 'w');fid_zb = fopen(filename_zb, 'w');

formatSpec = '%+.6f \n';fprintf(fid_br, formatSpec, BR);fprintf(fid_bz, formatSpec, BZ);fprintf(fid_rb, formatSpec, RB);fprintf(fid_zb, formatSpec, ZB);

24

Page 26: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

fclose(fid_br);fclose(fid_bz);fclose(fid_rb);fclose(fid_zb);

6.2 Appendix B

function [BZ] = MagFieldBz(L, r, z, Nz, B_zero)%% Returns a vector of length Nz with the magnetic field% values of Bz on the solenoid-centered z-axis. The field% is given in a region which extends +-z/2 from z = 0,% for a solenoid of length L, radius r and magnetic field% intensity B_zero.%% L - Length of solenoid in cm% r - Radius of solenoid in cm% z - total width of field in cm% Nz - Number of measuring points% B_zero - Field intensity in Tesla

dz = z/(Nz-1);BZ = zeros(1, Nz);

i = 1;for z = -z/2:dz:z/2BZ(1, i) = 1/2*B_zero*(((z+L/2)/(sqrt((z+L/2)^2+r^2)))...-((z-L/2)/((sqrt((z-L/2)^2+r^2)))));i = i+1;end

end

6.3 Appendix C

*===magfld=============================================================**SUBROUTINE MAGFLD ( X, Y, Z, BTX, BTY, BTZ, B, NREG, IDISC )

INCLUDE '(DBLPRC)'INCLUDE '(DIMPAR)'INCLUDE '(IOUNIT)'

**----------------------------------------------------------------------** ** Copyright (C) 1988-2010 by Alberto Fasso` & Alfredo Ferrari ** All Rights Reserved. ** ** ** Created in 1988 by Alberto Fasso` ** ** ** Last change on 06-Nov-10 by Alfredo Ferrari ** ** Input variables: ** x,y,z = current position ** nreg = current region ** Output variables: ** btx,bty,btz = cosines of the magn. field vector *

25

Page 27: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

* B = magnetic field intensity (Tesla) ** idisc = set to 1 if the particle has to be discarded ** **----------------------------------------------------------------------***----------------------------------------------------------------------** Parameters Section *

PARAMETER (NR = 301)PARAMETER (NZ = 6001)

DIMENSION BR(NR, NZ)DIMENSION RB(NR)DIMENSION BZ(NZ)DIMENSION ZB(NZ)

INTEGER i, k

REAL dr, dz, BRX, BRY

*----------------------------------------------------------------------** LFIRST Section ** Reads the magnetic field map and saves values in respective vectors ** RB(i) - Position vector in radial direction ** BR(i, k) - Magnetic field magnitude in radial direction ** ZB(k) - Position vector in axial direction ** BZ(k) - Magnetic field magnitude in axial direction *

LOGICAL LFIRSTSAVE LFIRSTDATA LFIRST / .TRUE. /

IF (LFIRST) THEN

OPEN(UNIT = 20, FILE = '/home/flupix/Desktop/FlukaShared/OUTDATA&/FLUKAOUTPUT.txt')OPEN(UNIT = 40, FILE = '/home/flupix/Desktop/FlukaShared/INDATA/&RBDATA.txt')OPEN(UNIT = 41, FILE = '/home/flupix/Desktop/FlukaShared/INDATA/&ZBDATA.txt')OPEN(UNIT = 50, FILE = '/home/flupix/Desktop/FlukaShared/INDATA/&BRDATA.txt')OPEN(UNIT = 51, FILE = '/home/flupix/Desktop/FlukaShared/INDATA/&BZDATA.txt')

DO i = 1, NRREAD(40, *) RB(i)END DODO k = 1, NZDO i = 1, NRREAD(50, *) BR(i, k)END DOEND DO

DO k = 1, NZREAD(41, *) ZB(k)READ(51, *) BZ(k)END DO

CLOSE(40 41 50 51)LFIRST = .FALSE.END IF

*----------------------------------------------------------------------*

26

Page 28: Implementation of a solenoidal magnetic field map …1090819/...Abstract This eprort describes the ationcre of a solenoidal magnetic eld in MATLAB and the essprco of integrating said

* Algorithm Section - Finds closest representation of simulated particle

* in the position vectors RB(i) and ZB(k) thereafter returns the index

* of the found position

i = 1k = 1

dr = RB(NR)/(NR-1)dz = (ZB(NZ)-ZB(1))/(NZ-1)

DO WHILE (Z.GT.ZB(k)+dz/2)k = k+1END DO

R = SQRT(X**2 + Y**2)DO WHILE (R.GT.RB(i)+dr/2)i = i+1END DO

*----------------------------------------------------------------------** Direction Section - Resolves radial magnetic field into x-y components

* and calculates the direction cosines for each field component in

* Cartesian coordinates

IF (BR(i, k).EQ.ZER) THENBRX = ZERZERBRY = BRXELSEBRX = BR(i, k)*X/RBRY = BR(i, k)*Y/RENDIF

B = SQRT(BZ(k)**2 + BRX**2 + BRY**2)BTX = BRX/BBTY = BRY/BBTZ = BZ(k)/B

*----------------------------------------------------------------------** Output Section - Writes and saves the position of the particle moving

* through the magnetic field region

WRITE(20, 100) X, Y, Z100 FORMAT(1X, F9.6, 3X, F9.6, 3X, F12.6)RETURNENDIF

*----------------------------------------------------------------------**====================== End of subroutine Magfld ======================*END

27


Recommended