arXiv:1707.09274v1 [physics.comp-ph] 28 Jul 2017 xeiet tCS,w odce td oquantify to study EDM a first future conducted a we the COSY, of as Recently, at analysis as experiments systematic option. such full an a projects toward not step therefore limited-budget is For this ours, times. of millions est orpa h simulation the repeat to cessity as contribute alignment the tol- of fabrication accuracy well. mechanical the the and like It erance addition, factors In other particles. experiment. many EDM be- the intended uncertainties the of such for quantify motion affect forehand to will orbit important which therefore and fields, is uniform, motion magnetic perfectly spin the not alter the is will magnet this that dipole consider and a just in problem, current further the the To of complexity large. particularly the parame- very is clarify random computationally simulations of such is in (number study ters) dimension a The such as conduct expensive. simulation to (MC) tool challenging Monte-Carlo a a well-known indeed The is elements machine its task. a of electromagnetic all for and of simulation uncertainties electrical realistic mechanical, a includes that Conducting Particle to tools so. powerful [2]. mag- ring do constitute simulation of accelerator tracking spin the sources and in the imperfections understand netic to importance crucial substan- is EDM frequency, enhanced. deuteron precession tially the spin oper- to the sensitivity be the of Wien will whereby harmonic which RF some installed, an at end, been ated recently this To has [1] ring. filter conven- a be storage COSY, will magnetic SYnchrotron deuteron COoler tional the the at of future, out measurement near carried EDM the In direct first protons. par- a and hadronic deuterons charged as such of ticles, (EDM) moment dipole electric ∗ 1 üihEeti ioemmn Investigations, http://collaborations.fz-juelich.de/ikp/jedi/ moment Dipole Electric Jülich [email protected] author: Corresponding h rnil rbe ihteM ehdi h ne- the is method MC the with problem principle The of is it signals, EDM false the eliminate to order In h JEDI The .ITOUTO N MOTIVATION AND INTRODUCTION I. 1 ntesohsi aeknmto,adi ssonta hsc this that r methods. shown storage Monte-Carlo is used COSY The it commonly the and the filter. method, in to Wien alternative Galerkin moment RF stochastic dipole an the electric inside on deuteron motion spin the and for beam of equations olbrto isa esrmn fthe of measurement a at aims collaboration e opttoa rmwr o atceadsi simulat spin and particle for framework computational new A nipeetto ftePlnma ho xaso sintr is Expansion Chaos Polynomial the of implementation An 1 ntttfrHcfeuntcnk WHAce University Aachen RWTH Hochfrequenztechnik, für Institut 2 ntttfrKrpyi,FrcugznrmJlc,52425 Jülich, Forschungszentrum Kernphysik, für Institut oshnsetu üihadRT ahnUiest,Germ University, Aachen RWTH and Jülich Forschungszentrum ae ntesohsi aeknmethod Galerkin stochastic the on based .Slim, J. 0000 10 3 AAFM Fre n atrExperiments), Matter and (Forces JARA–FAME ree esof tens even or 1 .Rathmann, F. . 2, ∗ oiin,vlcte n pnvectors. spin and velocities partic positions, uncertainties, with vari- fields electromagnetic input include random on the depending of ables polynomials, distribution orthogonal probabilistic or of the Laguerre, set Legendre, orthogonal other Hermite, The any the be computed. can be polynomials to coefficients expansion l tebssfntos fdegree of functions) basis (the als oyoil fdegree of polynomials i pcrlmto htalw o tcatclyvarying stochastically entities for allows physical that method spectral tic C permits PCE ξ hmqatttvl oteeuvln Crsls Sec- results. MC equivalent the tion to quantitatively them fteiptvariables input the of SM n ple tt h emadsi equations. spin Section and SGM. beam the the to it Section applies and (SGM) cest h qain oenn h ytm eean here have system, we the as governing but here, equations intrusive used the is to [3] Ref. access in same The as terms simulations. in methodology tracking of problem number the required of the complexity of the reduce further to al- method. accurate yet MC and the efficient to an ternative as Chaos [4], Polynomial (PCE) This so-called Expansion the [3]. uncertainties of use mechanical made investigation under filter mentioned Wien above the RF of performance electromagnetic the eiw h ai hoeia onain ftePCE. the of foundations theoretical Section basic the reviews ob ersne ntrso rhgnlpolynomials. orthogonal of terms in represented be to n .Heberling D. and eethe Here h oyoilcasepnin(C)i stochas- a is (PCE) expansion chaos polynomial The nti ae,w rsn opttoa framework computational a present we paper, this In hsppri raie sflos Section follows. as organized is paper This VI I OYOILCASEXPANSION CHAOS POLYNOMIAL II. ξ hspprdaswt hsclentities physical with deals paper This . umrzsadcnldstepaper. the concludes and summarizes IV III eso ftePEi employed. is PCE the of version ntttsanwadvr powerful very and new a onstitutes ecie h ansesrqie operform to required steps main the describes Ψ nrdcstesohsi aeknmethod Galerkin stochastic the introduces dcdhr safs ovro the of solver fast a as here oduced n.Tenwapoc sbased is approach new The ing. i Y 25 ahn Aachen, 52056 , r h utvraeotooa polynomi- orthogonal multivariate the are ob xaddit eiso orthogonal of series a into expanded be to eiesalb sdt search to used be shall device Y üih Germany Jülich, sarsos fsm adminput random some of response a as , V Y ,3 1, rsnsterslsadcompares and results the presents p ξ = hsi olw that follows it Thus . teepninodr sfunction as order) expansion (the rf o R etme 5 2018 15, September PRE for Draft X N i any a i Ψ i ( ξ ) p . n the and , ions a II i r the are Y briefly that (1) le 2

The first step in building a polynomial chaos series is (FEM) [11, 12]. In 1921 Boris Galerkin, a Russian math- to determine the probabilistic distribution of the input ematician, proposed a method to solve differential equa- random variables and their number (the dimensionality tions based on functional analysis. In contrast to other of the problem). Once known, the multivariate orthogo- methods, such as finite difference (FD) schemes, the nal polynomials can be constructed using the three-terms does not solve the differential equa- recurrence properties that can be found e.g., in [5]. tions directly, but transforms them into a variational Oftentimes, the number of random variables is larger form (a functional) that is then minimized. The func- than unity, which implies that multivariate polynomials tions minimizing this functional are the solutions to the must be used instead of univariate ones. Obviously, the required differential equations. The variational form is expansion order must be known and, as explained in [6, constructed via the Galerkin projection techniques [in- 7], can be changed adaptively during processing. sert proper ref]. The expansion coefficients can be calculated using in- In this section, the construction of the variational trusive and non-intrusive methods. Non-intrusive meth- form of the beam and spin dynamic equations using the ods consider the deterministic code as a black box, i.e., stochastic Galerkin projection is described in detail. Ne- they do not alter the code nor the equations. The ex- glecting forces other than the electromagnetic ones acting pansion coefficients are calculated using multiple calls to on the charged particles, the beam equations read the deterministic code either via projection or regression. Both require a number of N realization pairs (ξ , Ψ ) (see d q 1 i i ~v = E~ + ~v × B~ − ~v ~v · E~ , and Eq. (1)). Projection requires the evaluation of expecta- dt mγ c2   (5) tion values and relies on the orthogonality of polynomials d   ~r = ~v. to compute the coefficients in the form of dt E {YΨ} a = , (2) The expansion of Eq. (5) in Cartesian coordinates E 2 {Ψ } yields a linear system of six coupled ordinary differen- where the computation of the expectation values (E{·}) tial equations, necessitates the evaluation of integrals. Quadrature methods are one way to do so, and are commonly used d q 1 1 1 1 vx = Ex + vyBz − vzBy − vx(~v · E~ ) , in PCE analyses. Depending on the type of input distri- dt m γ γ γ c2γ   bution, the corresponding quadrature rule can be used. The Gauss-Laguerre quadrature for instance [8], is used (6a) in the case of uniformly distributed random variables. d q 1 1 1 1 This projection method is widely known as non-intrusive vy = Ey + vzBx − vxBz − vy(~v · E~ ) , dt m γ γ γ c2γ spectral projection (NISP) [9].   (6b) Regression, on the other hand, estimates the coeffi- cients that minimize the functional difference between d q 1 1 1 1 v = E + v B − v B − v (~v · E~ ) , and the estimated response Yˆ and the actual response Y, dt z m γ z γ x y γ y x c2γ z   given by (6c) 2 d a = arg min E Yˆ − Y . (3) x = vx , (6d) dt  n o  d The solution of Eq. (3), obtained by linear regression, y = vy , (6e) dt yields d T z = vz . (6f) ai = Ψ · Ψ · Ψ · Y. (4) dt In the context of this work, the regression method [10] Here, ~v denotes the velocity vector of the particles, q the provides more accurate results than the projection particle charge, m the mass, γ the Lorentz factor, and ~r method, it is therefore used here to calculate the expan- the position vector. sion coefficients ai, which are subsequently fed into the When intra-beam scattering and other collective ef- stochastic Galerkin solver. fects are neglected, the simulation of a beam of parti- cles is equivalent to individual simulations with different initial conditions. It is furthermore assumed that the III. STOCHASTIC GALERKIN METHOD number of single particle simulations is sufficiently large APPLIED TO BEAM AND SPIN DYNAMICS to describe the beam. These assumptions permit us to use stochastic methods to solve the differential equations A. Beam dynamics with random coefficients, or with uncertain input vari- ables, or even with random boundary values. According One of the most common methods to solve differ- to a probabilistic distribution, each individual particle of ential equations is the Galerkin-finite element method the population has a different initial position ~r and veloc- 3

(a) C14jl (b) C26jl (c) C37jl (d) C45jl (e) C69jl

(f) C77jl (g) C86jl (h) C93jl (i) C105jl (j) C116jl

FIG. 1. With the m = 5 dimensional problem and an expansion order of p = 4, the number of basis functions is P = 126 (see Eq. (7) of [3]), which results in a (126 × 126 × 126) Cijl tensor. The sparsity of the rank-3 tensor Cijl is illustrated by fixing, e.g., the first index to values of i = 14, 26, 37, 45, 69, 77, 86, 93, 105, and 116, which yields the 10 sparse matrices shown. The multiplication of the PCE coefficients involving this tensor is very fast, as most of the tensor elements are zero, while computing, storing and loading of this tensor constitutes a CPU and memory intensive operation. ity vector ~v. Therefore, the treatment of these parame- value E{·}, which gives ters as random vectors in Eq.(5) justifies the application N N of the SGM. d d E v (k)Ψ Ψ = v (k)E Ψ Ψ Equation (5) describes an initial value problem, where dt xi i l dt xi i l ( i ) i the initial values vary randomly. The initial values are X X   N expanded using non-intrusive PC, particularly with lin- d = v (k)hΨ Ψ i (10) ear regressions, and then the SGM [13] is applied to solve dt xi i l i Eq. (5). As an example, the technique of solving for the X N variable vx is discussed in detail below. d = v (k)hΨ2iδ , vx is expanded as dt xi i il i N X k ( ) where δil is the Kronecker delta which results from the vx = vxi Ψi , (7) i orthogonality of the polynomials. X The electric field is also represented stochastically2 by (k) a finite series as where the vxi are the chaos expansion coefficients. The superscript (k) is used to identify the expansion coeffi- N cients, and also to emphasize that the variables are dis- (k) Ex = exi Ψi . (11) cretized. The coefficients are calculated according to i X (k) T vxi = Ψ · Ψ · Ψ · vx0 , (8) The Lorentz factor γ constitutes also a stochastic vari- able. Unfortunately, it appears in the denominator in all where vx0 are the initial x-components of the particle velocities. Plugging Eq. (7) into the left-hand side of Eq. (6a), we find 2 The Cartesian components of the electric and magnetic fields N N (E~ and B~ ) are functions of the position vector ~r, e.g., E~x (~r ), d d (k) d (k) v = v Ψ = v Ψ . (9) B~x (~r ), etc. The dependence of the field components, for instance dt x dt xi i dt xi i i i E~x (~r ) = E~x (x,y,z), on position, does not pose a problem for X X the PCE method, as long as the input variables (e.g., ~r and ~v) Now, the stochastic Galerkin projection is applied are independent. The field components are considered as a black box and the expansion is carried out non-intrusively. by multiplying Eq. (9) with Ψl and taking the expectation 4 terms of Eq. (5). To solve this problem, 1/γ is expanded By applying the stochastic Galerkin projection to instead of γ. Let α be defined as Eq. (16), it follows that

1 N N N α = , (12) E (k) (k) (k) γ {αvyBzΨl} = αi vyj bzk hΨiΨjΨkΨli i j k then α is expanded as X X X N N N N (k) (k) (k) (k) = αi vyi bzj Dijkl . α = αi Ψi . (13) i j k i X X X X (17) The stochastic Galerkin projection is applied by mul- Dijkl is similar to Cijl, but it constitutes a rank-4 tensor. tiplying the product of Eqs. (11) and (13) by Ψk, subse- quently the expectation value E{·} is calculated. It thus The case for the third term of Eq. (6a) yields follows, N N N E (k) (k) (k) N N N N {αvzByΨk} = αi vzj byk hΨiΨjΨkΨli E (k) (k) (k) (k) i j k exi Ψi αj ΨjΨl = exi αj hΨiΨj Ψli X X X   N N N  i j  i j (k) (k) (k) X X X X = α vz by Dijkl . N N i j k i j k   = α(k)e (k)C . X X X i xj ijl (18) i j X X (14) The last term of the right hand side of Eq. (6a), i.e., The Cijl = hΨiΨjΨli constitutes a sparse rank-3 ten- 1 sor. It is constructed offline by computing the tensor αvx ~v · E~ (19) c2 product which constitutes a CPU intensive operation.   The formula to compute Cijl, provided in [13], works only is yet more complicated, as it involves the scalar for low order and low-dimensional cases. In addition, it product. The scalar product operator multiplies the is limited to Gaussian-distributed random variables, and operands component-wise before summing them up. consequently applies only to Hermite polynomials. For These operands, however, are PC coefficients. The corre- 3 the actual version implemented here, Cijl is computed sponding multiplication is in fact a Galerkin one , which numerically and distribution-independent. The imple- involves a series of double products [14], given by mentation has been validated with a one-dimensional quadrature-based one and yielded the same results. 3 N N ~ (k) (k) Fortunately, Cijl needs to be computed only once. It ~v · E = vij eik Ψj Ψk . (20) i j k can be stored and re-used when required. Although the X X X multiplications of the PCE coefficients involve the C ijl This means that Eq. (20) requires the stochas- term, this arithmetic operation does not introduce any tic Galerkin projection to compute a rank-5 tensor, computational overhead as C is sparse. This is illus- ijl which makes the Galerkin method highly inefficient [14]. trated in Fig. 1 for several typical examples of the C ijl In order to solve this problem, a pseudo-spectral tensor . method [9, 15] is used. Using this method, the Galerkin The product of α, magnetic field and velocity is more projection is applied first to the auxiliary variable g (the complicated, because it involves multiple polynomials. k one representing the scalar product), and then secondly The triple product of α, v and B requires to expand y z to the full product in Eq. (19). This way, the rank-4 ten- the two latter quantities as sor product, introduced above in Eq. 17), can be used. In N particular, gk reads (k) vy = vyi Ψi , 3 N N i X (15) E ~ (k) (k) N gl = ~v · E Ψl = vij eik Cijl , (21) (k) i j k Bz = bzi Ψi , n  o X X X i X where the subscript l here constitutes a free variable. (k) (k) And then by applying the stochastic Galerkin projection where vyi and bzi are the expansion coefficients of vy and Bz, respectively. The multiplication of the three sums yields

N N N 3 We actually tried a simple multiplication, but the SGM did not (k) (k) (k) converge to the correct solution, i.e., a strong variations of x, y, αvyBz = αi vyj bzk ΨiΨjΨk . (16) vx, vy and Sy with respect to the MC solution were observed. i j k X X X 5 it follows that N N N E ~ (k) (k) (k) All the terms that interact with field and velocity com- αvx ~v · E Ψl = αi vxj gk Dijkl . ponents are grouped together. It should be noted that i j k n   o X X X here only γ constitutes a stochastic variable. The PCE (22) coefficient are also calculated using the non-intrusive pro- Now that all the terms of Eq. (6a) are expanded, jection method, yielding as described above, and after a similar treatment also Eqs. (6b) to (6f), the system of ordinary differential equa- N tions (ODEs) has been solved. f1 = f1iΨi , (27a) i X B. Spin dynamics N f2 = f2iΨi , (27b) i The spin dynamics in an electromagnetic storage ring X with non-vanishing EDM is described by the generalized N T-BMT equation [16, 17], which reads f3 = f3iΨi , and (27c) i d X S~ = Ω~ MDM + Ω~ EDM × S.~ (23) N dt f4 = f4iΨi . (27d)   EDM MDM i Here, S~ denotes the particles’ spin, and Ω~ and Ω~ X are the angular velocities associated with the magnetic (MDM) and the electric dipole moments (EDM). Ω~ MDM and Ω~ EDM are defined as Ω~ MDM and Ω~ EDM are then rewritten as q γ E~ × β~ Ω~ MDM = − (1+ Gγ) B~ + Gγ + mγ 1+ γ c q    Ω~ MDM = − f B~ + f E~ × β~ − f β~ β~ · B~ , and Gγ2 m 1 2 3 − β~ β~ · B~ ,   γ +1      q η E~ E~   Ω~ EDM = − + β~ × B~ − f β~ β~ · . q η E~ γ E~ m 2 c 4 c Ω~ EDM = − + β~ × B~ − β~ β~ · .  !  m 2 c γ +1 c  !  (28) (24)

The particle velocity is given by β~ = ~v/c, G denotes the anomalous magnetic moment, and η is a dimensionless In the following, the same methodology as described parameter that describes the particle EDM. in Sec.IIIA, is applied to the spin equation. Starting Expanding Eq. (23) in Cartesian coordinates reads with the x-component of the spin vector in Eq. (24) by induction from the derivation described above, it follows d S =ΩMDMS − ΩMDMS +ΩEDMS − ΩEDMS , that dt x y z z y y z z y d MDM MDM EDM EDM Sy =Ωz Sx − Ωx Sz +Ωz Sx − Ωx Sz , N N N dt d (k) MDM(k) (k) Sx = Ωy Szj Cijl d MDM MDM EDM EDM dt i S =Ω S − Ω S +Ω S − Ω S . i i j dt z x y y x x y y x X X X (25) N N MDM(k) (k) − Ωz i Syj Cijl Before proceeding to the stochastic discretization of i j the spin equation in Eq. (23), some variables are intro- X X (29) N N duced to simplify the discretization process. Let EDM(k) (k) + Ωy i Szj Cijl 1 i j f1 = + G, (26a) X X γ N N EDM(k) (k) 1 1 − Ω Sy Cijl . f = G + , (26b) z j j 2 c γ i j   X X Gγ f = , and (26c) 3 1+ γ γ MDM(k) f4 = , (26d) Rewriting Ωy i in terms of the individual compo- γ +1 nents involved, for instance, is equivalent to the following 6 expression violate the independence requirement of the random pa- rameters. In this case, the Nataf transformation [18–20]4 N MDM(k) can be used to solve this problem. Ωy i With all these parameters, the expansion coefficients i X of the initial particle population are constructed using N q the linear regression method, as described in Eq. (8). = − f (k)b (k)C m 1i yj ijl With P = 126, Cijl is a 126 × 26 × 126 tensor. Unless i j  X X a new random quantity is added to the analysis, or the N order of the expansion is changed, the stored Cijl can be (k) (k) (k) (k) (k) (k) + f2i ezi βxj Dijkl − f2i exi βzj Dijkl used when required. When the expansion order p or the i j k dimension of the problem is large, other methods, such X X X   N N N as pseudo-spectral ones, may become more favorable (see (k) (k) (k) e.g. − f3i βyj hk Dijkl , , [21]). i j k  The SGM-based system of equations is solved using X X X 5 (30) Matlab , employing the deterministic ordinary differen- tial equations solver ’ode45 ’ with a fixed time step of where 1 ms, and relative and absolute error tolerances of 10−13 and 10−20, respectively. The ’ode45 ’ solver is based on 3 N N the 4th-order Runge-Kutta integration technique. It is h = E β~ · B~ Ψ = β (k)b (k)C (31) l l ij ik ijl important to note that the same ODE solver is used in i j k n  o X X X both cases, MC and SGM. Here, l constitutes a dummy subscript [which is replaced The implementation of the large system of equations was vectorized, and took less than a second (on average by k in Eq.(30)]. Similarly, the other components of 6 the equation governing the spin dynamics [Eq. (23)] can 0.47s ± 0.2s) of CPU time . be constructed, and this derivation is omitted here for At the final stage, the performance of the SGM must brevity. be evaluated quantitatively, with the help of an adequate error analysis. Due to time and position dependence, the error calculation involves either the mean value or the IV. SIMULATION WALKTHROUGH standard deviation of the quantity under investigation, denoted by ζ. The corresponding errors are called ǫµ and ǫ , respectively, and are defined as The stochastic Galerkin method (SGM) transforms a σ ¯ system of differential equations describing the quantities ζ¯(t) − ζˆ(t) ǫµ(t)= , and (32a) of interest into an augmented system of equations con- ζ¯(t) taining only the coefficients. Depending on the dimen- sion and the expansion order p, the dimension of the new σ[ζ(t)] − σ [ζˆ(t)] ǫσ(t)= . (32b) system of equations is determined. The solutions of the σ[ζ(t)] system are called stochastic modes which are nothing else than the time- and position-dependent expansion coeffi- Here, ζ may refer to either the position, velocity or spin cients. These coefficients can later on be used to recon- vector. ζˆ denotes the estimated value using the SGM. To struct the response for an arbitrary number of particles. conduct an analysis similar to the one described in [4, 22], To perform the simulations, the random variables have the exact initial conditions are fed to both the MC and to be identified first. This can include the particle po- the SGM solver, so that the solution can be compared sitions, velocities, spins and the electric and magnetic on a particle-by-particle basis. In this way, the difference fields. Next, the expansion order p is selected with the between the two solutions reflects the true performance smallest possible value in order for the augmented system of the proposed new method. of equations to be as small as possible as well. The ex- When the dynamics includes electromagnetic fields, pansion order can later be increased, in case the achieved the stochastic expansion coefficients may evolve as a func- accuracy is not satisfactory. In this work, the expansion tion of time and position. It is very common that the order was set to (p =4), which results in very good error values, as will be shown later. Since here, Gaussian distributions were selected, the 4 Nataf transformations are iso-probabilistic transformations that basis functions are Hermite polynomials. The random transform correlated Gaussian variables with arbitrary mean and variables must be standardized in order for the method variance into normally-distributed ones. Without such a trans- to converge. The total number of polynomials (the car- formation, the orthogonality of the basis functions would be vi- olated. dinality of the polynomials) is P = 126 [3]. 5 Mathworks, Inc. Natick, Massachusetts, United States In particle simulations, particles are generated accord- http://www.mathworks.com. ing to a well-defined phase-space population. An exam- 6 The simulations were performed on an HP Z840 workstation with ple is shown in Fig. 9 of [1], and such populations might a single Xeon E5v4 CPU and a RAM capacity of 80 GB. 7

(a) Solution for x(t). (b) Solution for y(t).

(c) Solution for vx(t). (d) Solution for vy(t).

FIG. 2. Results of tracking of 105 particles. On the horizontal axis, the time in seconds over which the tracking simulation evolved is shown, and on the vertical axis, the resulting x, y, vx and vy. The dotted blue lines represent the solution computed using the Monte-Carlo simulations (MC), while the dashed red lines visualize the solutions of the stochastic Galerkin method (SGM). In all four cases, the positions of the lines are nearly indistinguishable, indicating the very good agreement between MC and SGM. electromagnetic fields are functions of position, time, or filter [1] that are computed numerically using the elec- frequency. This adds another level of complexity that the tromagnetic package CST MWS7. SGM must be capable to solve. As a consequence, the performance criterion in Eq. 32 must be modified to cope with position dependence as well, A. Uniform fields

¯ ˆ¯ ζ(z) − ζ(z) The generic simulation scenario serves as a proof-of- ǫµ(z)= , and (33a) ζ¯(z) concept demonstrator for the SGM. 105 particles are con-

sidered8 with normally-distributed initial positions and σ[ζ(z)] − σ[ ζˆ(z)] ǫσ(z)= . (33b) velocities traveling in a uniform electromagnetic field σ[ζ(z)] with E~ = (1, 0, 0) V/m and H~ = (0, 1/173, 0) A/m9, in

a time interval from 0 to 20 seconds. Here, ζ may refer either to the position, velocity or ′ ′ The positions and transverse angles, x, x , y and y are spin dependence, and ζˆ constitutes the corresponding es- generated using a 2σ beam emittance of ǫ =1 µm. The timated value using the SGM, similar to Eq. (32). x,y

V. NUMERICAL RESULTS 7 Computer Simulation Technology, Microwave Studio, CST AG., Darmstadt, Germany, http://www.cst.com. 8 Due to the limited computational resources to carry out the Two different simulation scenarios have been consid- equivalent MC simulations, only 105 particles have been con- ered here. In the first scenario, described in Sec. V A, sidered here. It should be noted that the SGM with the same uniform fields are used with realistic particle properties, resources can support the simulation of a much larger number of while in the second scenario, described in Sec. VB, a re- particles. 9 −7 alistic beam passing through the fields of an RF Wien In vacuum, B~ = µ0H~ = 4 · π · 10 H~ . 8

Parameter Description Value N Number of particles 105 − q Deuteron charge 1.602 · 10 19 C m Deuteron mass 3.344 · 10−27 kg G Deuteron G-factor −0.143 c Speed of light 2.998 · 108 m/s β = v/c Lorentz β 0.459 − ǫ Beam emittance 10 6 µm − ∆p/p Momentum variation 10 4

TABLE I. Typical parameters of a deuteron beam stored at COSY at a momentum of 970 MeV/c, which are used in the FIG. 3. Result of spin tracking simulations in uniform fields particle and spin tracking simulations, described here. using the Monte-Carlo (MC) and the stochastic Galerkin method (SGM). The horizontal axis shows the time t in sec- onds, and the vertical axis the vertical component Sy(t) of ~ transverse velocities vx and vy are calculated by multiply- the spin vector S(t). ′ ′ ing the transverse angles x and y by vz. vz is also mod- eled as a Gaussian random variable with a mean value of β · c m/s and a standard deviation that corresponds to a demonstrated in Figs. 4(a) and 4(b). As we are dealing variation of the beam momentum of ∆p/p = 10−4. The with stochastic quantities, the mean and the standard beam parameters used in the simulations are summarized deviations are used as performance indicators. All esti- ˆ in Table I. mated SGM solutions, xˆ, vˆx, yˆ, vˆy and Sy do not deviate −5 Figure 2 shows the tracking results of the MC and the by more than 10 from the MC solutions, x, vx, y, vy SGM-based simulation of x, vx, y, and vy. Due to the and Sy, which was one of the goals of this study. extended phase space distribution of the beam, the trans- verse velocities vx and vy do not vanish. In x-direction, this leads to a transverse Lorentz force and an oscilla- B. Tracking with realistic RF Wien filter fields tion of the particles around the beam direction, while in y-direction the particles are just drifting. It was veri- In this section, we present simulation results using the fied by simulation that a beam of vanishing emittance ǫ MC and the SGM, where both methods were applied to and momentum variation ∆p/p, performs a perfect drift deuteron beam (see Table I) traveling along the z-axis motion in both x- and y-directions. of an RF Wien filter, whose electromagnetic fields were Very good agreement between the MC method and the calculated using a full-wave simulation based on CST1. SGM-based simulations can clearly be observed in Fig. 2. A detailed description of the calculations and the field In particular, no difference between the oscillation pe- distributions can be found in [1]. riods and the magnitudes for the positions x and the The waveguide RF Wien filter constitutes a novel de- velocities vx are observed. As expected, both methods vice that is presently installed at COSY-Jülich aiming at indicate a pure drift in radial direction, both in terms of a first direct measurement of the deuteron EDM in the position and velocity, as shown in Fig. 2 (d). framework of the JEDI collaboration [23]. The device is The stochastic discretization of the T-BMT equation characterized by high-quality electromagnetic fields that, has been implemented as well, and the numerical results when properly matched, provide a vanishing Lorentz are shown in Fig. 3. The fields, despite the fact that they force. This is achieved by adjusting the field quotient 10 are uniform, can be expanded to include effects of unde- Zq , which makes the device transparent to passage of sired physical phenomena, such as, for instance, misalign- particles (see Eq. (3) of [1]). ments. The simulation scenario assumes a horizontally At the location of COSY, where the device is installed, polarized deuteron beam with initial spin vectors in the the beam size is adjustable by modifying the β-function horizontal (ring) plane, such that S~ = (1, 0, 0). While to values between about β = 0.4 and 4 m [24]. In this the system of ODEs is solved for Sx, Sy and Sz, only paper, we consider only the case when β = 0.4, and a the vertical spin component Sy is displayed in Fig. 3. Of typical initial phase-space ellipse for a well-cooled beam importance for the present investigation is the agreement at the entrance of the RF Wien filter at z = 1 mm are between the SG and MC methods, and not a particular shown in panel (a) of Fig. 5 (for other beam properties, solution of the spin dynamics equations. This is clearly visible in Fig. 3, which shows that both oscillation mag- nitude and frequency of the MC and the SGM evolve synchronously. 10 The field quotient is defined as the ratio of total electric field to By applying Eq. (32), the performance of the SGM is total magnetic field. 9

100 100

10-5 10-10 10-10

10-15 10-20 0 5 10 15 20 0 5 10 15 20

(a) Error analysis for the mean value ǫµ(t) based on (b) Error analysis for the standard deviation ǫσ(t) Eq. (32a). based on Eq. (32b).

FIG. 4. Error analysis involving the mean value ǫµ(t) and the standard deviation ǫσ(t) of the quantities x, y, vx, vy and Sy in the time interval from t = 0 to 20 s.

(a) z = 1mm (b) z = 210 mm (c) z = 610 mm (d) z = 810 mm

FIG. 5. Comparison between the phase-space ellipses between the Monte-Carlo (MC) tracking results (blue crosses) and the stochastic Galerkin method (SGM, red dots) at z = 1, 210, 610 and 810 mm along the beam direction in the waveguide RF Wien filter [1]. The red dots are very dense so that the blue crosses cannot be seen anymore. see also Table I). In panels (b) to (d), the phase-space ellipses are displayed at the positions z = 210, 610 and 810 mm. In all cases, SGM and MC results are in very good agreement. It should furthermore be noted that for the purpose of the present paper, single-pass tracking calculations, i.e., without the ring, fully suffice to make the point. The simulation results from the MC and SGM of the trajectories in the xz plane of the drift region inside the RF Wien filter are shown in Fig. 6. The MC results are represented by the dashed red lines, and the SGM simu- lations by the dotted red lines. Evidently, also here, the SGM results perfectly coincide with their MC counter- parts. FIG. 6. Trajectory simulation of the xz plane in the drift Using Eqs. (33a and b), the deviation of the simulation region along the RF Wien filter using the Monte-Carlo (MC) results of the SGM and the corresponding MC are quan- and the stochastic Galerkin method (SGM). tified in Fig. 7. The horizontal axis represents the beam axis in the RF Wien filter. The solid lines denote the C. Comparison of simulation times errors calculated by considering the mean values ǫµ(z) with respect to the horizontal position x and the velocity vx in x-direction, while the dashed lines correspond to One important performance criterion besides the er- the errors related to the standard deviation ǫσ(z) for the ror analysis is the comparison of the required simulation same quantities. The relative errors in the mean value times. In the following, the generic scenario, described in −7 sense of xǫµ and vxǫµ do not exceed 10 , while the error Sec. V A, is discussed, with particles properties as listed in the mean-squared sense of xǫµ and vxǫµ do not exceed in Table I. 10−10. The smallness of the calculated errors is a good The MC simulations require to evaluate the system of indicator for the excellent performance of the SGM. beam and spin ODEs [Eqs. (5, 6)]. The Matlab simu- 10

10-5 time Ts =4.14 ± 0.39s, as shown in Fig. 8. VI. CONCLUSION

This paper reports on the application of the stochas- 10-10 tic Galerkin method (SGM) to beam and spin tracking simulations. The method has been shown to work well with uniform fields. It has been applied to a realistic sce- nario, involving the electromagnetic fields of the waveg- 10-15 0 200 400 600 800 1000 uide RF Wien filter as well. The results indicate very good agreement with the Monte-Carlo simulations, that were carried out concurrently. The error calculations that we carried out show that FIG. 7. Error analysis involving the mean value ǫ (z) and µ the performance of the SGM is statistically equivalent the standard deviation ǫσ(z) involving the quantities x and vx along the beam direction in the waveguide RF Wien filter. to the Monte-Carlo (MC) method, but with much lower computational demand. While the computational effort 103 of MC-based simulations increases exponentially as func- tion of particle number, the computational effort involved

102 in the SGM is constant, independent of the number of particles tracked. The SGM transforms the original sys- tem of beam and spin ODEs into an augmented system 101 of chaos coefficients, which are determined and then used to reconstruct the response for an arbitrary number of 100 MC particles. The SGM is therefore capable to track large SGM particle numbers in short time without compromising on 10-1 103 104 105 106 the accuracy, and in this way provides a very efficient alternative to MC-based methods. A potential future application of the SGM might be FIG. 8. Comparison of the simulation time required for the spin tracking calculations for storage rings, which are parallelized MC and the stochastic Galerkin method (SGM). 5 necessary in particular for precision experiments, such For particle numbers below about 10 , the methods are com- as the search for electric dipole moments. In such cases, parable, while for larger particle numbers, the SGM with a an ultimate precision is required in the presence of uncer- constant expansion order of p = 4 performs much better than tainties of the optical elements that constitute the ma- the MC. chine. The SGM allows one to conveniently take into account systematic errors from different sources and to lation environment provides a powerful vectorization op- build a hierarchy of error sources. In view of the com- tion that has been used here to parallelize the code execu- putational effort required for the MC-based error evalu- tion. As shown in Fig. 8, for less than N ≈ 105 particles, ation, the SGM may thus become an indispensable tool MC and SGM are about equally fast, but when N in- for future precision experiments. creases further, the required time for the MC increases exponentially11, while the time required for the SGM stays about constant. ACKNOWLEDGMENT Regardless of the number of particles, the system of ODEs involved in the SGM is evaluated exactly P This work has been performed in the framework of times12, corresponding to the number of basis functions. the JEDI collaboration and is supported by an ERC This is the main reason why the SGM is so much faster Advanced-Grant of the European Union (proposal num- than the MC, without reduction in accuracy, as evidenced ber 694340). We would kindly like to thank Alexander in Figs. 4(a), 4(b), and 7. When the expansion order Nass, Helmut Soltner, Martin Gaisser, and Jörg Pretz, p is kept constant, the number of basis functions re- Andreas Lehrach and Jan Hetzel for their useful com- mains constant as well, and hence also the simulation ments and careful reading of the manuscript.

9 11 The time required for the simulating of 2 · 106 particles on the vectorization option, tracking of up to 10 particles becomes pos- available machine6 took about 925.42 ± 0.82 s. Turning off the sible, but the simulation time becomes prohibitively large. 11

[16] V. Bargmann, L. Michel, and V. L. Telegdi, [1] J. Slim, R. Gebel, D. Heberling, F. Hinder, Phys. Rev. Lett. 2, 435 (1959). D. Hölscher, A. Lehrach, B. Lorentz, S. Mey, [17] T. Fukuyama and A. J. Silenko, A. Nass, F. Rathmann, L. Reifferscheidt, H. Solt- International Journal of Modern Physics A 28, 1350147 (2013). ner, H. Straatmann, F. Trinkel, and J. Wolters, [18] J. Hurtado, Structural Reliability: Statistical Learning Nuclear Instruments and Methods in Physics Research Section A:Perspectives Accelerators,, Lecture Spectrometers, Notes in Detectors Applied and and Associate Computa-d Equipment 828, 116 (2016). [2] A. Saleev, N. N. Nikolaev, F. Rathmann, W. Augusty- tional (Springer Berlin Heidelberg, 2013). niak, Z. Bagdasarian, M. Bai, L. Barion, M. Berz, [19] Z. Kotulski and W. Szczepinski, Error Analysis with Ap- S. Chekmenev, G. Ciullo, S. Dymov, D. Eversmann, plications in , Solid Mechanics and Its Appli- M. Gaisser, R. Gebel, K. Grigoryev, D. Grzonka, cations (Springer , 2009). G. Guidoboni, D. Heberling, V. Hejny, N. Hempelmann, [20] R. Lebrun and A. Dutfoy, J. Hetzel, F. Hinder, A. Kacharava, V. Kamerdzhiev, Probabilistic Engineering Mechanics 24, 172 (2009). I. Keshelashvili, I. Koop, A. Kulikov, A. Lehrach, [21] G. Cottrill and F. Harmon (American Institute of Aero- P. Lenisa, N. Lomidze, B. Lorentz, P. Maanen, nautics and Astronautics, 2011) Chap. Hybrid Gauss G. Macharashvili, A. Magiera, D. Mchedlishvili, S. Mey, Pseudospectral and Generalized Polynomial Chaos Algo- F. Müller, A. Nass, A. Pesce, D. Prasuhn, J. Pretz, rithm to Solve Stochastic Trajectory Optimization Prob- M. Rosenthal, V. Schmidt, Y. Semertzidis, Y. Senichev, lems. V. Shmakova, A. Silenko, J. Slim, H. Soltner, A. Stahl, [22] M. Gerritsma, J.-B. van der Steen, R. Stassen, E. Stephenson, H. Stockhorst, H. Ströher, P. Vos, and G. Karniadakis, M. Tabidze, G. Tagliente, R. Talman, P. T. Eng- Journal of 229, 8333 (2010). blom, F. Trinkel, Y. Uzikov, Y. Valdau, E. Valetov, [23] F. Rathmann, A. Saleev, N. N. Nikolaev, and A. Vassiliev, C. Weidemann, A. Wrońska, P. Wüst- on behalf of the JEDI and srEdm collaborations, ner, P. Zuprański, and M. Zurek (JEDI collaboration), Journal of Physics: Conference Series 447, 012011 (2013). Phys. Rev. Accel. Beams 20, 072801 (2017). [24] C. Weidemann, F. Rathmann, H. J. Stein, B. Lorentz, [3] J. Slim, F. Rathmann, A. Nass, H. Solt- Z. Bagdasarian, L. Barion, S. Barsov, U. Bechst- ner, R. Gebel, J. Pretz, and D. Heberling, edt, S. Bertelli, D. Chiladze, G. Ciullo, M. Contal- Nuclear Instruments and Methods in Physics Research Section A:brigo, Accelerators, S. Dymov, Spectrometers, R. Engels, Detectors M. Gaisser, and Associate R. Gebel,d Equipment 859, 52 (2017). [4] D. Xiu and G. E. Karniadakis, P. Goslawski, K. Grigoriev, G. Guidoboni, A. Kacharava, SIAM Journal on Scientific Computing 24, 619 (2002). V. Kamerdzhiev, A. Khoukaz, A. Kulikov, A. Lehrach, [5] P. Parthasarathy and R. Sudhesh, P. Lenisa, N. Lomidze, G. Macharashvili, R. Maier, Applied Letters 19, 1083 (2006). S. Martin, D. Mchedlishvili, H. O. Meyer, S. Merzliakov, [6] G. Blatman and B. Sudret, Probabilistic Engineering Me- M. Mielke, M. Mikirtychiants, S. Mikirtychiants, A. Nass, chanics 25, 183 (2010). N. N. Nikolaev, D. Oellers, M. Papenbrock, A. Pesce, [7] W. Yu, W. Li, A. Elsherbeni, and Y. Rahmat-Samii, Ad- D. Prasuhn, M. Retzlaff, R. Schleichert, D. Schröer, vanced Computational Electromagnetic Methods, Artech H. Seyfarth, H. Soltner, M. Statera, E. Steffens, H. Stock- House antennas and electromagnetics analysis library horst, H. Ströher, M. Tabidze, G. Tagliente, P. T. Eng- (Artech House Publishers, 2015). blom, S. Trusov, Y. Valdau, A. Vasiliev, and P. Wüstner, [8] M. Abramowitz, Handbook of Mathematical Functions, Phys. Rev. ST Accel. Beams 18, 020101 (2015). With Formulas, Graphs, and Mathematical Tables, (Dover Publications, Incorporated, 1974). [9] O. P. Le Maître and O. M. Knio, Spectral Methods for Uncertainty Quantification: With Applications to Computational , Scientific Computation (Springer, Dordrecht, 2010). [10] P. Offermann, H. Mac, T. T. Nguyen, S. Clénet, H. D. Gersem, and K. Hameyer, IEEE Transactions on Magnetics 51, 1 (2015). [11] O. Zienkiewicz, R. Taylor, and J. Zhu, The Finite Ele- ment Method: Its Basis and Fundamentals (Elsevier Sci- ence, 2013). [12] J. Jin, The in Electromagnetics, 3rd ed. (Wiley-IEEE Press, 2014). [13] D. Xiu, Numerical methods for stochastic computations: a spectral method approach (Princeton University Press, 2010). [14] T. Sullivan, Introduction to Uncertainty Quantification, Texts in (Springer International Publishing, 2015). [15] P. Pettersson, G. Iaccarino, and J. Nordström, Journal of Computational Physics 257, 481 (2014).

12 Even this number can be further reduced using a sparse version of PCE[3].