11
Computer Physics Communications 135 (2001) 82–92 www.elsevier.nl/locate/cpc Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code R. Sanchez a,, S.P. Hirshman b , H.V. Wong c a Universidad Carlos III, Avda. de la Universidad 30, Leganes, 28911 Madrid, Spain b Oak Ridge National Laboratory, P.O. Box 2009, Oak Ridge, TN 37831-8070, USA c Institute for Fusion Studies, University of Texas at Austin, Austin, TX 78712, USA Received 29 February 2000; received in revised form 9 June 2000; accepted 26 June 2000 Abstract The overall efficiency of the recently developed ideal ballooning code COBRA is greatly improved by using a magnetic equilibrium description based on the same magnetic coordinates used to compute it by the VMEC 3D equilibrium code. VMEC determines this set of coordinates by requiring a spectrally condensed Fourier representation of the solution, releasing in the process the constraint of straight-field-line coordinates. This increases the analytic complexity of the ideal ballooning stability problem, since another equation must be now solved to follow the magnetic field line when integrating the ideal ballooning equation. However, from a numerical point of view, the much smaller number of Fourier harmonics needed together with the elimination of an equilibrium mapping to straight-line coordinates saves an enormous amount of time. This enhancement might prove to be essential within the compact stellarator optimization environment in which the speed and accuracy of this code can play an important role. 2001 Elsevier Science B.V. All rights reserved. PACS: 02.60.Lj; 52.35.Py; 52.55.Mc; 52.55.Kj Keywords: Stellarators; Magnetohydrodynamics; Ballooning instabilities; Magnetic coordinates; Richardson’s extrapolation; Optimization 1. Introduction In a recent publication [1] the COBRA code was in- troduced to evaluate the stability of 3D magnetic con- figurations against ideal MHD ballooning instabilities. These modes are pressure-gradient-driven MHD insta- bilities highly localized along the magnetic field lines, being therefore amenable of a local stability analysis. Together with other more extended MHD pressure- gradient-driven modes (i.e. interchange modes), they set an upper bound for the local value of the pressure * Corresponding author. E-mail address: [email protected] (R. Sanchez). gradient in currentless stellarators, therefore limiting indirectly the maximum amount of plasma (parame- trized in terms of β , the ratio of the confined pres- sure to the confining magnetic energy) that can be confined inside the configuration [2]. In configurations with a net toroidal current, MHD current-driven modes must also be considered. But in any case, sophisticated MHD codes must be used to ascertain their stability due to the complex geometry of asymmetric magnetic configurations. For general MHD stability studies, in- cluding all types of instability drives, global stabil- ity codes such as TERPSICHORE [3] or CAS3D [4] have been developed and are widely used (some other 0010-4655/01/$ – see front matter 2001 Elsevier Science B.V. All rights reserved. PII:S0010-4655(00)00225-3

Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code

Embed Size (px)

Citation preview

Page 1: Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code

Computer Physics Communications 135 (2001) 82–92www.elsevier.nl/locate/cpc

Improved magnetic coordinate representation for idealballooning stability calculations with the COBRA code

R. Sancheza,∗, S.P. Hirshmanb, H.V. Wongc

a Universidad Carlos III, Avda. de la Universidad 30, Leganes, 28911 Madrid, Spainb Oak Ridge National Laboratory, P.O. Box 2009, Oak Ridge, TN 37831-8070, USAc Institute for Fusion Studies, University of Texas at Austin, Austin, TX 78712, USA

Received 29 February 2000; received in revised form 9 June 2000; accepted 26 June 2000

Abstract

The overall efficiency of the recently developed ideal ballooning code COBRA is greatly improved by using a magneticequilibrium description based on the same magnetic coordinates used to compute it by the VMEC 3D equilibrium code. VMECdetermines this set of coordinates by requiring a spectrally condensed Fourier representation of the solution, releasing in theprocess the constraint of straight-field-line coordinates. This increases the analytic complexity of the ideal ballooning stabilityproblem, since another equation must be now solved to follow the magnetic field line when integrating the ideal ballooningequation. However, from a numerical point of view, the much smaller number of Fourier harmonics needed together with theelimination of an equilibrium mapping to straight-line coordinates saves an enormous amount of time. This enhancement mightprove to be essential within the compact stellarator optimization environment in which the speed and accuracy of this code canplay an important role. 2001 Elsevier Science B.V. All rights reserved.

PACS: 02.60.Lj; 52.35.Py; 52.55.Mc; 52.55.Kj

Keywords: Stellarators; Magnetohydrodynamics; Ballooning instabilities; Magnetic coordinates; Richardson’s extrapolation; Optimization

1. Introduction

In a recent publication [1] the COBRA code was in-troduced to evaluate the stability of 3D magnetic con-figurations against ideal MHD ballooning instabilities.These modes are pressure-gradient-drivenMHD insta-bilities highly localized along the magnetic field lines,being therefore amenable of a local stability analysis.Together with other more extended MHD pressure-gradient-driven modes (i.e. interchange modes), theyset an upper bound for the local value of the pressure

* Corresponding author.E-mail address: [email protected] (R. Sanchez).

gradient in currentless stellarators, therefore limitingindirectly the maximum amount of plasma (parame-trized in terms ofβ , the ratio of the confined pres-sure to the confining magnetic energy) that can beconfined inside the configuration [2]. In configurationswith a net toroidal current, MHD current-drivenmodesmust also be considered. But in any case, sophisticatedMHD codes must be used to ascertain their stabilitydue to the complex geometry of asymmetric magneticconfigurations. For general MHD stability studies, in-cluding all types of instability drives, global stabil-ity codes such as TERPSICHORE [3] or CAS3D [4]have been developed and are widely used (some other

0010-4655/01/$ – see front matter 2001 Elsevier Science B.V. All rights reserved.PII: S0010-4655(00)00225-3

Page 2: Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code

R. Sanchez et al. / Computer Physics Communications 135 (2001) 82–92 83

global stability codes based on the stellarator expan-sion are also available [5], but fail for those asymmet-ric geometries where the large aspect ratio assumptionceases to be valid. A good review describing many ofthese codes can be found in Ref. [6]). For pressure-gradient-driven modes, there exist simpler ways todo this analysis depending on the mode extensionalong the magnetic field line: for interchange modes,the large extension allows to use the surface-averagedMercier criterion [7–9]; for ballooning modes, whichare highly localized, the use of the ballooning trans-formation [10] allows to simplify the MHD stabil-ity equations to an ordinary differential equation thatmust be solved numerically. There exist several bal-looning codes developed for 3D asymmetrical config-urations widely used by the stellarator community (forinstance, JMC [11], the ballooning module in TERP-SICHORE or 3DBALLOON [12]).

The need for faster ballooning codes such as CO-BRA was motivated by the current persuit for compactquasi-symmetric configurations [13]. These configu-rations are looked for using a numerical optimizationscheme [14] that requires the repeated evaluation oftheir stability and transport properties. The low aspectratios of these devices (typically,A = R0/a < 4) in-validates most analytical stellarator studies, since thestellarator expansion is strongly violated, and numer-ical exploration is therefore unavoidable. Regardingstability issues, their Mercier stability can be easilyevaluated and it is been included since the earlier ver-sions of the optimizer. But to test stability against bal-looning and/or current-driven MHD modes, very fastand accurate codes are required if they are not to jeop-ardize the optimization efficiency (see Fig. 5). In par-ticular, for ballooning stability calculations, the bal-looning mode growth rate must be evaluated at manymagnetic surfaces (and at many locations within eachof them). The computational time that the aforemen-tioned codes use for this task, that should be repeatedfor hundreds (or even thousands) of iterations is toolarge to be included efficiently within the optimiza-tion procedure. This implies that the ballooning sta-bility calculation has to be done after the optimizationis finished, which in many cases shows that the op-timizer has headed for a more unstable direction inparameter space. Therefore, COBRA was developedwith the aim of computing the growth rates of idealballooning modes in a very fast but accurate fash-

ion, that would allow its efficient integration withinthis stellarator optimization scheme. The initial re-sults obtained were rather promising, since several bal-looning targets could be included in the optimizationsuite [15], which is currently being used to look forattractive quasiomnigeneous [16] (QOS) and quasiax-isymmetric [13] (QAS) compact stellarator configu-rations for the NCSX (NationalCompactStellaratorEXperiment) program [17]. Motivated by these suc-cessful initial results, further developments of the codehave been constantly pursued and the present paper re-ports on some important program along these lines. Toshow more clearly the way in which the efficiency ofCOBRA has been further improved, it will prove use-ful to briefly review the way in which the ballooningstability calculations are carried out numerically.

3D magnetic equilibria of interest for thermonuclearfusion are usually studied assuming the existence ofgood magnetic surfaces forming a family of nestedtori around a central axis (this assumption can beinvalidated by the appearance of magnetic islandsand stochastic regions, but if the configuration doesnot become too asymmetric and by controlling therotational transform profile and excluding all its lower-order rational values from the plasma, this assumptioncan be shown to be a useful approximation). Thesesurfaces are labeled bys, which goes from 0 to 1 aswe move from the magnetic axis to the last closedsurface. The position on each magnetic surface isdescribed by two other magnetic coordinates, a pairof generalized poloidal and toroidal angles,θ andζ ,which may be geometrical or not. Any point in theconfiguration can therefore be described by the setof magnetic coordinates(s, θ, ζ ). Magnetic field linesmust lie on one of these surfaces, being thus definedby the contour levels of some relation between themagnetic coordinates of the typeα = α(s, θ, ζ ) forsome value ofs. The exact expression forα will notbe known until the poloidal and toroidal angles havebeen chosen, but regardless of that, all magnetic linescontained in the magnetic surface labeled ass, will belabeled by a pair(s,α) for some value ofα.

The ideal ballooning stability of these equilibria canthen be assessed by solving the ideal ballooning equa-tion along any magnetic field line on any magnetic sur-face [18]. This equation is a linear second order differ-ential equation of the type:[L0(θ, ζ )+ λR(θ, ζ )

]F = 0, (1)

Page 3: Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code

84 R. Sanchez et al. / Computer Physics Communications 135 (2001) 82–92

where the differential operatorL0 is defined as:

L0(θ, ζ )≡ ( �B · �∇)[P(θ, ζ )( �B · �∇)] +Q(θ, ζ ) (2)

with �B being the magnetic field and the eigenvalueλ(defined asλ ≡ −γ 2, beingγ the ballooning growthrate) determined by requesting the solutionF to be inL2(−∞,+∞). The exact definition of the functionsP,Q andR will be given later.

By introducing now a new set of magnetic coordi-nates of the type(s,α, y), with y being any coordinaterunning along the magnetic field line(s,α), it is ob-tained that:

( �B · �∇)= By ddy, with By ≡ �B · ∇y (3)

and Eq. (1) becomes an ordinary differential equationwith y as the independent variable as soon as thefunctions θ = θ(y), ζ = ζ(y) that parametrize themagnetic field line as a function ofy are known:[d

dy

[P (y)

d

dy

]+ Q(y)+ λR(y)

]F = 0 (4)

with P ≡ PBy , Q≡Q/By andR ≡ R/By . Analyti-cal attempts to approximate the solution of Eq. (4) cannow be carried out via asymptotic or perturbation tech-niques for Stürm–Liouville eigenvalue problems [19].Numerically, the solution can be obtained using themany available algorithms for integration of ordinarydifferential equations.

Following these lines of thought, all the aforemen-tioned ballooning codes solve Eq. (1) using one setof the so-called straight-line magnetic coordinates inwhich magnetic field lines are straight lines and therelation α = α(s, θ, ζ ) becomes extremely simple;in particular, they use those coordinates introducedby Boozer [20],(s, θb, ζb), where the poloidal andtoroidal angles are defined so that the field line rela-tion becomesα = θb− -ι(s)ζb (-ι is the rotational trans-form). Now, they transform Eq. (1) to(s,α, y) coor-dinates choosingy = ζb, and with the magnetic fieldline parametrized asθb(y)= α + -ιy.

But there is a price that numerical algorithms haveto pay for using the simpler analytic form that straight-line magnetic coordinates provide. The most com-monly used 3D MHD equilibrium code, VMEC [21],solves the MHD equilibrium equations using an in-verse Fourier representation in its own internal coor-dinates(s, θv, ζv). This inverse representation means

that all equilibrium data (such as the magnetic field,shape of magnetic surfaces, Jacobian, etc.) is com-puted as odd(O) or even(E) Fourier series (stellara-tor symmetry constrains the allowable parities):

E(s, θv, ζv)=∑m,n

Emn(s)cos(mθv − nζv),

O(s, θv, ζv)=∑m,n

Omn(s)sin(mθv − nζv).(5)

The toroidal angle in VMEC,ζv , is the cylindricaltoroidal angle but the exact definition ofθv is deter-mined at run time to yield the most spectrally con-densed series possible, i.e. using the smallest numberof Fourier harmonics,Mv . As a result,(s, θv, ζv) isnot in general a straight-line set of coordinates andthe equilibrium must be mapped to Boozer coordi-nates before the ballooning equation can be solved bythe ballooning code. The price is then revealed at thispoint. Three issues should be kept in mind:(1) This mapping must be carried out before the bal-

looning equation can be solved by the ballooningcode, which is a computationally very intensiveprocess. The reason is that the number of Boozer–Fourier harmonics,Mb, needed to represent theequilibrium with sufficient accuracy for local sta-bility calculations is much larger than those inthe VMEC-Fourier series. There is no analyticexpression relatingMb andMv , but from exten-sive numerical testing it has been seen that typi-callyMb ∼ 10Mv, with this ratio slightly increas-ing as the aspect ratio of the device is decreased.This ratio becomes so large because constant step-size angular meshes in VMEC coordinates tend toconcentrate points at those locations in real spacewhere the curvature is larger. But regular meshesin Boozer coordinates do not, and therefore theyneed a much larger number of mesh points every-where to achieve a similar accuracy at those lo-cations. And typically, these are the places wheremost unstable ballooning modes appear.

(2) Since there is no systematic way to chooseMb (ormore precisely, the value of toroidal and poloidalBoozer modes), it must be usually determined viaa test and error procedure.

(3) Once the mapping has been completed, the Boo-zer–Fourier series must be inverted within the bal-looning code on every grid point along every cho-sen field line to computeP , Q and R. When

Page 4: Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code

R. Sanchez et al. / Computer Physics Communications 135 (2001) 82–92 85

Fig. 1. Ballooning growth rate for theβ = 2% QOS case computed for increasing values ofMb by COBRA in Boozer coordinates. The numberswithin the parenthesis are respectively the number of poloidal and toroidal modes used.

Mb � 1 this part of the calculation becomes dom-inant: the time begins to increase linearly with thenumber of grid points,Np , as soon asMb � 100and this is certainly the case for fully 3D configu-rations (for comparison,Mb ∼ 100 for a 2D toka-mak equilibrium whileMb ∼ 1000 for a fully 3Dstellarator).

The first and third issues are responsible for thelong computational time required to compute theballooning growth rate. The second issue may turnthe calculation somewhat unreliable, specially withinany optimization procedure. IfMb is not sufficientlylarge, the (stable) results can prove to be very different(unstable) whenMb is increased. This is certainlynot a problem for a single configuration calculation,where checking the convergence of the results israther straightforward. But within the optimization,there is no way to ensure thatMb was sufficientlylarge to represent accurately ALL the intermediateconfigurations that the optimizer may have pointedto while moving inside the configurational parameterspace. And this is important, since the independentvariables used by the optimizer are related to theconfiguration geometrical shape.

All these issues were partially addressed when de-veloping the version of COBRA introduced in Ref. [1].To reduce the computational time while keeping the

same number of Boozer modes, COBRA tried tokeepNp as small as possible without losing accuracy.It used a combination of matrix and variational tech-niques to evaluate the eigenvalue to 4th-order accuracyin the grid step size,h≡ 1/(Np − 1), and then used aRichardson’s extrapolation scheme [22] to extrapolateit to h→ 0 from very large values ofh (that is, usingvery few grid points). With this technique, a speed en-hancement close to 20 times relative to fixed step sizecodes was obtained while ensuring some good but notyet satisfactory convergence properties: the Richard-son’s scheme would not adequately converge ifMb isnot sufficiently large (see Fig. 1, where the bad conver-gence of the growth rate in the outer part of the insta-bility region reveals the inadequate number of Boozermodes). But it was clear that the code would turn muchmore efficient if the equilibrium could be representedwithin COBRA using a set of coordinates requiringmuch fewer number of modes.

In this paper we address this problem, and we showthat the set of coordinates used by VMEC providesthe perfect solution, since they are determined withinVMEC to yield the most compact Fourier represen-tation of the equilibrium. The benefits of solving theballooning equation directly in VMEC coordinates in-clude both speed and reliability: first of all, no time isspent mapping the equilibrium from VMEC to Boozer

Page 5: Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code

86 R. Sanchez et al. / Computer Physics Communications 135 (2001) 82–92

coordinates, a mapping that is certainly dominant atsuch big values ofMb. And at the same time, theconvergence problem with respect toMb would dis-appear. Second, the time spent inverting the Fourier-series within the ballooning code is reduced, since nowthe sums are carried out over many less modes (typi-cally, over 10 times fewer modes). The total time gainwill not be ten times faster though, since other parts ofthe algorithm begin to dominate and a few extra seriesmust also be summed to compute the magnetic field.

The steps to be followed in order to compute the bal-looning growth rate in VMEC magnetic coordinatesare:(1) Parametrizing the magnetic field line: in VMEC

coordinates the field line relation becomes:

α(s, θv, ζv)= θv + λ(s, θv, ζv)− -ιζv, (6)

where the Fourier harmonics forλ(s, θv, ζv) arecalculated by VMEC. The way to solve forθv(ζv)along the magnetic field line in an efficient waythat keeps the Richardson’s extrapolation schemebuilt inside COBRA operative (i.e. exploiting allthe advantages from the extrapolation from coarsemeshes) is shown in Section 2.

(2) Computing the ballooning coefficients: in Sec-tion 3 explicit expressions forP , Q and R willbe derived in VMEC coordinates.

Finally, some numerical results comparing the effi-ciency and accuracy of the new coordinate represen-tation are presented in Section 4 for a reference 3DQOS configuration. Some conclusions will be drawnin Section 5.

2. Following magnetic field lines in VMECcoordinates

Following a magnetic field line in VMEC coordi-nates implies finding the two functions,θv = θv(y) andζv = ζv(y), that parametrize it as a function of the vari-able that runs along the line,y, on some surfaces0.These two functions must satisfy:

α0 = θv(y)+ λ(s0, θv(y), ζv(y)

) − -ι(s0)ζv(y) (7)

for some prescribed valueα0 (determined by the initialpoints,θv(0) andζv(0)). Theλ function is determinedby the VMEC code at run time to choose the definitionof θv that keeps the Fourier representation more

compact. The Fourier harmonics provided by VMECare:

λ(s, θv, ζv)=∑m,n

λmn(s)sin(mθv − nζv). (8)

If y is chosen to bey = ζv , the problem remainingis to invert Eq. (7) to determineθv(ζv) along the fieldline. There are several ways to numerically computethis function. The first one that comes to mind is todifferentiate Eq. (6) along the field line:

dθvdζv

= -ι− dλ/dζv1+ dλ/dθv

= Bθv

Bζv(9)

and integrate itat the same time as the ballooningequation by means of ashooting-like integrationmethod.

But as pointed out in Ref. [1], shooting methodsare not the most efficient schemes when it comes todealing with 3D magnetic configurations. The reasonis that a fairly large amount of time must be spentin computing the ballooning coefficients at each gridpoint. In that reference it was shown to be much moreefficient to use any method in which:(1) the number of points is kept to a minimum to

estimate the eigenvalue and(2) those points already computed can be reused when

refining the estimation.The solution found was to solve for the eigenvalueusing a mixed matrix-variational method with a fixedgrid step size coupled to a Richardson’s extrapolationscheme: the eigenvalue was obtained to fourth orderaccuracy for some initial step size,h0, and then theinitial step size is reduced several times by a factorof two, and the eigenvalue is again obtained. Thisseries inh is extrapolated toh → 0 using a quarticuntil the extrapolation error is below some prescribedtolerance. Since at each new iteration the step size ishalved, only the middle points must be added. Usingthis scheme, speed enhancements close to 20 timeswere achieved compared to the fixed step shootingschemes used by most ballooning codes (and evenmore relative to adaptative grid step size schemes, thatcould not reuse previously computed points).

Therefore, to efficiently couple solving forθv(y) inVMEC coordinates with this Richardson’s extrapola-tion scheme, a way should be chosen such that theevaluation ofθv(ζv) is required ONLY on those newgrid points added at each iteration of the Richard-son’s loop. And this cannot clearly be done integrating

Page 6: Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code

R. Sanchez et al. / Computer Physics Communications 135 (2001) 82–92 87

Eq. (9), since the value at each point of the grid willdepend on that of the previous point: when the num-ber of grid points is doubled, all of them will have tobe revaluated. It is much more efficient to look for theroots of the function:

G(θv)≡ θv + λ(s0, θv, ζv)− -ι(s0)ζv − α0 = 0 (10)

for each value of the toroidal angle at any point ofthe grid. This can be done very quickly by takingadvantage of our knowledge of the derivative ofλ:

dθv(s, θv, ζv)=

∑m,n

mλmn(s)cos(mθv − nζv) (11)

and using Newton–Raphson’s algorithm [23], obtain-ing the root by iterating:

θk+1v = θkv − G(θkv )

dG/dθv(θkv ). (12)

Convergence of this fast but otherwise unreliable(because of its highly unstable character) algorithmcan be ensured by using as initial guess forθkv the finalvalue obtained forθk−1

v , sinceθv(ζv) is going to be asmooth function ofζv .

3. The ideal ballooning equation in VMECcoordinates

The only remaining part of the problem is tocompute the ballooning coefficientsP , Q and Rdirectly in VMEC coordinates. The ideal ballooningequation derivation can be found in many places inthe literature [18,24]. When expressed in the(s,α, y)coordinates introduced in Section 1, it takes thegeneral form:

( �B · ∇)[ |∇α|2B2

( �B · ∇)]F +

(R0

a

)2β0p

Ψ′2 κsF

= γ 2 |∇α|2B2 F (13)

where the magnetic field,�B, and pressure,p, are nor-malized to their values at the magnetic axis,B0 andp0,parallel and perpendicular [to the magnetic field line]lengths are respectively normalized to the major andminor plasma radius,R0 anda, the growth rate is nor-malized to the Alfvén time,τA ≡ (µoρR2

0/B20)

1/2 (be-ing ρ the plasma density) andβ0 ≡ 2µop0/B

20. Ψ is

the toroidal magnetic flux. All the physics of balloon-ing instability dynamics is contained in Eq. (13): thefirst term describes the stabilizing influence of field-line bending, while the right-hand side is the effect ofthe inertia. The remaining destabilizing term is propor-tional to the driving pressure gradient, and contributesto the destabilization of the mode when this is local-ized where the normal curvature is unfavorable, i.e. ifκs < 0.

If the toroidal angle is chosen as the variable run-ning along the field line,y = ζv , the three ballooningcoefficients are then given by:

P ≡ Bζv |∇α|2B2

, Q≡(R0

a

)2β0p

Ψ′2Bζv

κs,

R ≡ |∇α|2BζvB2

(14)

and the derivative along the line becomes:

( �B · ∇)= Bζv d

dζv. (15)

The squared normal wave vector,|∇α|2, in VMECcoordinates can be easily obtained by applying thedifferential operator∇ on Eq. (6), yielding:

|∇α|2 = gθvθv(

1+ ∂λ

∂θv

)2

+ gsvsv(

−-ι′ζv + ∂λ

∂sv

)2

+ gζvζv(

−-ι+ ∂λ

∂ζv

)2

+ 2gsvθv(

−-ι′ζv + ∂λ

∂sv

)(1+ ∂λ

∂θv

)

+ 2gζvθv(

1+ ∂λ

∂θv

)(−-ι+ ∂λ

∂ζv

)

+ 2gsvζv(

−-ι′ζv + ∂λ

∂sv

)(−-ι+ ∂λ

∂ζv

).

(16)

The covariants-component of the curvature vector,κs , can be easily computed from the covariant com-ponents of�κ in VMEC internal coordinates, using themetric matrix (notice thatsv = s, but the subindex iskept for clarity):

∂(sv, θv, ζv)

∂(s,α, ζv)

= 1

1+ ∂λ∂θv

1+ ∂λ

∂θv0 0

-ι′ζv − ∂λ∂sv

1 -ι− ∂λ∂ζv

0 0 1+ ∂λ∂θv

. (17)

Page 7: Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code

88 R. Sanchez et al. / Computer Physics Communications 135 (2001) 82–92

The components of�κ ≡ (�b · ∇)�b in VMEC coordi-nates are:

κsv = 1

B

(∂B

∂sv+ µop

B

− Bsv

B2

[Bζv

∂B

∂ζv+Bθv ∂B

∂θv

]),

κθv = 1

B

(∂B

∂θv− Bθv

B2

[Bζv

∂B

∂ζv+Bθv ∂B

∂θv

]),

(18)

and the equation forκs is:

κs = κsv + κθv(

-ι′ζv − ∂λ/∂sv1+ ∂λ/∂θv

). (19)

Notice that whenλ = 0 and ζv is substituted bythe Boozer toroidal angle,ζb, all expressions givenin Ref. [12] for Boozer coordinates are recovered forboth the normal wave vector and the covariants-component of the curvature vector. Some commentson the way to computeBsv will also prove useful, sincethe inaccuracies in its calculation on resonant rationalsurfaces from the VMEC solution have already beenshown to overestimate interchange stability [9]. Butthe situation for ballooning modes is much less criticaldue to their highly localized structure along the fieldlines [25].

4. Numerical results

To compare the efficiency of using the VMEC mag-netic coordinate representation of the MHD equilib-rium inside COBRA with the previous Boozer repre-sentation, some results for a series of QOS equilibriawith periodicityM = 3, aspect ratioA=R0/a = 3.6,β values ranging from 2 to 3% and containing 41nested magnetic surfaces will be presented. Theseequilibria are ballooning unstable all across the centralregion with both the width of the instability region andthe magnitude of the growth rates increasing withβ ,and were the initial point of an optimization sequencethat looked for QOS configurations with good stabilityand transport properties at low aspect ratio (the opti-mization of these configurations is described at lengthin Ref. [15]).

The number of modes used in the VMEC-seriesrepresentation isMv = 50, six poloidal (0� m � 5)and nine toroidal (−4 � n � 4). To determine theminimum number of Boozer modes required to be

able to carry out the stability computation within therequired accuracy, we have used COBRA on theβ =2% equilibrium, reconstructing it several times withincreasing number of toroidal and poloidal Boozermodes, until the growth rate converges at all surfaces.The right number of poloidal modes seems to be aboutsix times the number of VMEC poloidal modes, andthe number of toroidal modes about three times thenumber of VMEC toroidal modes, as can be seenin Fig. 1. The consequences of using an inadequatenumber of modes are clearly shown in the figure forthe case of insufficient toroidal modes: the growthrates may converge to the wrong values (case withMb = 533 and−7 � nb � 7) and/or fail to convergeat some surfaces (case withMb = 746 and−10 �nb � 10, where the growth rate cannot be computedon the last six surfaces). The final value for thenumber of Boozer modes obtained from this testand error procedure isMb = 888 and−12 � nb �12. With respect to COBRA specific parameters, allruns have been done setting the extrapolation errorwithin the Richardson’s scheme to 10−3, the initialstep size toh0 = 0.4 andKw = 7 (see Ref. [1] foran explanation of these parameters). All calculationshave been performed on the CRAY J-90 at CIEMAT(Spain).

To illustrate first the field line parametrization, bothθv(ζv) andθb(ζb) are plotted on Fig. 2 for the samefield line on the 15th surface. Notice the non-straightcharacter of the VMEC representation of the magneticfield line. The values for the ballooning growth ratesobtained from both magnetic representation are com-pared in Fig. 3 as a function of toroidal magnetic flux.The slight differences can be accounted for by round-off errors, inaccuracies in the mapping to Boozer co-ordinates or from the prescribed error tolerance withinthe Richardson’s extrapolation scheme.

Regarding the speed of the growth rate computation,the total CPU time to calculate the ballooning growthrate for one initial point on 39 surfaces (all exceptthe magnetic axis and the boundary) from the VMECequilibrium solution is compared with the total CPUtime used to do the same task with the Boozerrepresentation (see Table 1). Taking as an examplethe 〈β〉 = 2% equilibrium, the VMEC version ofCOBRA carries out the computation in only 4.00 s.The time used by the version of COBRA using Boozercoordinates is divided in two parts: 49.7 s used by the

Page 8: Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code

R. Sanchez et al. / Computer Physics Communications 135 (2001) 82–92 89

Fig. 2. Poloidal angle variation along the magnetic field line beginning at(0,0) on the 15th-surface as a function of the toroidal angle for bothBoozer (dashed line) and VMEC (solid line) coordinates.

Fig. 3. Comparison of the ballooning growth rates obtained by the Boozer (open symbols) and VMEC (closed symbols+ line) versions ofCOBRA as a function of toroidal flux for an increasingβ series of QOS equilibria.

Table 1CPU time spent (in seconds) by the old and new COBRA and total speed enhancement achieved whencomputing the ballooning growth rate on 39 surfaces (all except for the magnetic axis and the boundary) ofthe series of QOS equilibria described in the text

〈β〉(%) Mapping Boozer COBRA VMEC COBRA Enhancement

2.0 49.72 18.8 4.00 17.13

2.5 50.20 15.9 3.99 16.57

3.0 50.40 19.9 3.69 19.05

Page 9: Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code

90 R. Sanchez et al. / Computer Physics Communications 135 (2001) 82–92

Fig. 4. CPU-time spent by the Boozer (closed circles) and VMEC (open circles) versions of COBRA to compute the ballooning growth rate oneach of the 39 surfaces on CIEMAT’s CRAY J-90.

mapper to Boozer coordinates (that clearly dominatesthe calculation) and 18.8 s to compute the ballooninggrowth rates. The VMEC version of COBRA carriesout the same task 17 times faster.

As stated in Section 1, the growth rate calcula-tion itself is also accelerated within COBRA by thesmaller number of modes included in the series to beinverted. In principle, a speed enhancement of the or-der ofMb/Mv ∼ 888/50∼ 18 should be expected ifthe Fourier inversion were the dominant part of thecalculation. But due to the Richardson’s scheme al-ready introduced in Ref. [1], the number of grid pointsused is already so small that other parts of the algo-rithm begin to be responsible for most of the spenttime (namely the determination of the eigenvalue fromthe matrix) and the enhancement is much smaller. Be-sides, more VMEC-series must now be inverted, sinceno analytical expression can be used to obtain the com-ponents of the magnetic field. In Fig. 4, the CPU-timesrequired by the different representations are plotted to-gether for the same initial point choice as a function ofthe magnetic surface: the CPU-time is reduced by afactor close to 7 in the VMEC representation.

Finally, the amount of time that the VMEC CO-BRA uses within the optimization scheme describedin Ref. [15] and applied to this series of QOS configu-rations is shown in Fig. 5. In the figure, the CPU time

used by the ballooning calculation in a single iterationof the optimization loop (remember that the number ofiterations required to find the configurations appearingin that reference is about one thousand) is seen to beabout 100 times smaller than previous codes allowed.Notice that these times are now negligible compared tothe time that VMEC needs to compute the equilibrium(left side of the figure), while the Boozer COBRA’stime was comparable (when the mapping time is in-cluded) and the conventional codes clearly dominatethe optimization. This enhanced speed also allows toinclude much more locations where the local growthrate can be computed. With the new ballooning code,as good final QOS configurations can be obtained inmuch less time as those shown in the aforementionedreference.

5. Conclusions

The use of VMEC coordinates(s, θv, ζv) to de-scribe the MHD equilibrium within COBRA elim-inates the need for the intermediate mapper codeto Boozer straight-line magnetic coordinates and, atthe same time, reduces considerably the time spentFourier inverting the equilibrium quantities requiredfor the growth rate computation. This increases thespeed of the calculation by a factor close to 20 rel-

Page 10: Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code

R. Sanchez et al. / Computer Physics Communications 135 (2001) 82–92 91

Fig. 5. CPU-time on CIEMAT’s CRAY J-90 distribution used in one optimization iteration: with a conventional fixed step ballooning code(black), with the Boozer version of COBRA (gray) and with the VMEC version of COBRA (white), all for the same precision.

ative to the Boozer version of COBRA. At the sametime, it avoids the appearance of all convergence prob-lems with regards to the accuracy of the Boozer rep-resentation. Given the fact that the Boozer version ofCOBRA was already close to 5 times faster than anyconventional ballooning code (if the Boozer mappingtime is included in the comparison) thanks to the use ofa Richardson’s extrapolation scheme, the VMEC ver-sion of COBRA provides for a total speed enhance-ment close to 100 times relative to most ideal balloon-ing tools at hand, which can prove extremely usefulwithin any of the optimization suites currently in useby the stellarator community (see Fig. 5).

Acknowledgements

One of the authors (R.S.) is very grateful to G. Ger-shon for encouragement and to L.P. Ku for his help inbenchmarking COBRA. This research was supportedin part (R.S.) by Spanish DGES Proyect No. PB96-0112-C02-01. This research was also sponsored by theU.S. Department of Energy, under contract DE-AC05-96OR22464 with Lockheed Martin Energy ResearchCorp.

References

[1] R. Sanchez, S.P. Hirshman, J.C. Whitson, A.S. Ware, J. Com-put. Phys. 161 (2000) 576.

[2] J.P. Freidberg, Ideal Magnetohydrodynamics, Plenum Press,New York, 1987.

[3] D.V. Anderson, W.A. Cooper, R. Gruber, S. Merazzi,U. Schwenn, J. SuperComput. Appl. 4 (1990) 34.

[4] C. Schwab, Phys. Fluids 5 (1993) 3195.[5] L. Garcia, B.A. Carreras, N. Dominguez, J.N. Leboeuf,

V.E. Lynch, Phys. Fluids 2 (1990) 1990.[6] Y. Nakamura et al., J. Comput. Phys. 128 (1996) 43.[7] C. Mercier, Nucl. Fusion 1 (1960) 47.[8] N. Dominguez, J.N. Leboeuf, B.A. Carreras, V.E. Lynch, Nucl.

Fusion 29 (1989) 2079.[9] H.J. Gardner, D.B. Blackwell, Nucl. Fusion 32 (1992) 2009.

[10] J.W. Connor, R.J. Hastie, J.B. Taylor, Phys. Rev. Lett. 40(1978) 396.

[11] J. Nührenberg, R. Zille, in: Theory of Fusion Plasmas, Proc. ofthe 1987 Varenna Workshop, Editrice Compositori, Bologna,1986, p. 3.

[12] R. Sanchez, J.A. Jimenez, L. Garcia, A. Varias, Nucl. Fu-sion 37 (1997) 3557.

[13] J. Nührenberg, W. Lotz, S. Gori, in: Theory of Fusion Plasmas,Proc. of the 1993 Varenna Workshop, Editrice Compositori,Bologna, 1994, p. 3.

[14] S.P. Hirshman, D.A. Spong, J.C. Whitson et al., Phys. Plas-mas 6 (1999) 1858.

[15] R. Sanchez, S.P. Hirshman, A.S. Ware, L.A. Berry, D.A.Spong, Plasma Phys. Contr. Fusion 42 (2000) 641.

[16] J.R. Cary, S.G. Shasharina, Phys. Rev. Lett. 78 (1997) 674.[17] G.H. Neilson, A.H. Reiman, M.C. Zarnstorff, A. Brooks et al.,

Phys. Plasmas 7 (2000) 1911.

Page 11: Improved magnetic coordinate representation for ideal ballooning stability calculations with the COBRA code

92 R. Sanchez et al. / Computer Physics Communications 135 (2001) 82–92

[18] J.W. Connor, R.J. Hastie, J.B. Taylor, Proc. Roy. Soc. LondonA 1 (1979) 365.

[19] C. Bender, S.A. Orszag, Advanced Mathematical Methods forScientists and Engineers, McGraw-Hill, New York, 1978.

[20] A.H. Boozer, Phys. Fluids 23 (1980) 904.[21] S.P. Hirshman, W.I. Van Rij, P. Merkel, Comput. Phys.

Comm. 43 (1986) 143.

[22] G. Dahlquist, A. Björck, Numerical Methods, Prentice-Hall,Englewood Cliffs, NJ, 1974.

[23] W. Press, S. Teukolsky, W. Vettering, B. Flannery, NumericalRecipes, Cambridge Univ. Press, New York, 1992.

[24] D. Correa-Restrepo, Zeits. Naturf. 37 (1982) 848.[25] R. Moeckli, W.A. Cooper, Nucl. Fusion 33 (1993) 1899.