As mentioned in sections3.1and3.2, evaluating the righthand side of(3.1)−(3.4)requires dif- ferentiation of quantities in the spatial coordinate system(x, y, z). In one dimensional situations, the derivative of a functionf(x)at the pointxis defined by the limit
lim
h→0
f(x+h)−f(x)
h . (3.14)
Ifhhas a fixed, non-zero value, rather than approaching zero, the quotientf(x+hh)−f(x) is called a finite difference and gives an approximation to the derivative off atx. Hence, we have
df dx ≈
f(x+h)−f(x)
h . (3.15)
The derivative off at the point xcan also be derived by making use of the Taylor series. The Taylor series expansion forf(x+h)about the pointxis as follows
f(x+h) =f(x) + h 1! df(x) dx + h2 2! d2f(x) dx2 + h3 3! d3f(x) dx3 +. . . (3.16)
By rearranging (3.16) we again arrive at (3.15), where the Taylor series expansion has been truncated from theO
h2d2dxf(2x)
term onwards. This gives rise to a first order accurate finite difference method with a second order error. By increasing the number of terms in the finite difference method it is possible to increase the order of the error and, thereby, increase the accuracy of the derivative approximation.
We will now describe the finite difference methods used byDiffin3dfor evaluating derivatives and carrying out interpolation. In section 3.3.2, we will present the predictor-corrector method used to advance the solution in time.
3.3.1 Differentiation and Interpolation Operators
Diffin3duses a finite difference method with a sixth order error for differentiating the various quantities used in the calculations of the MHD equations. The method returns the derivative of a quantity at a half cell location, thus the returned data is shifted in comparison to the input data. For example, if the input data is centred on the grid cells then the returned results will be values for the cell boundaries. Similarly, for input data located at cell boundaries the returned results will be for the centre of the cell. Whether the data is shifted up or down by half of a grid cell will depend upon the particular difference method employed.
The prescribed method for the partial derivative off(x, y, z) with respect tox, whose result is returned shifted half a grid cell up in relation to the input data, is
∂ ∂x fi+1 2 = a1 4x(fi+1−fi) + b1 4x(fi+2−fi−1) + c1 4x(fi+3−fi−2), (3.17)
wherea1 = 1−3b1−5c1,b1 =−(1 + 120c1)/24andc1 = 3/640. For a 3D grid,irepresents the
array indices in thexdirection, whilej andkwould represent indices in theyandzdirections, respectively. By simply changing the indices in(3.17) fromitojorkand substituting yorz
forx, we define operators for finding the partial derivatives with respect to yorz, respectively. By subtracting1from each of the indices off, we can define an operator which returns the result shifted half a grid cell down from the input data.
As stated in section3.2, each operation must act on quantities at the same spatial location during the evaluation of the right-hand sides of(3.1)−(3.4). Thus, due to the staggering of the grid and the shifted sixth order error derivative method, it is sometimes necessary to interpolate quantities before calculations can take place. For example,eis the conserved quantity in the energy equation,
(3.3), and we know thateis cell centred. Hence, each of the right-hand side terms of(3.3)must also be cell centred before they are finally summed to give the total right-hand side value. If we
Figure 3.4: For the result of∂(evx)/∂xto be cell centred (as in 1), the quantityevxmust be face
centred (as in 2). To derive this quantity from individual staggered quantitiesρ,eandPx(as in 3),
interpolation must be carried out.
expand the first right-hand side term,∇ ·(ev), we have
∂(evx) ∂x + ∂(evy) ∂y + ∂(evz) ∂z . (3.18)
We again consider only the first term,∂(evx)/∂x. The partial differentiation with respect toxwill
shift the result by half a grid cell and we require the result to be cell centred, as shown in figure3.4. Thus, the input values ofevxmust be face centred.vxis derived from the momentum component
Px, which is face centred, butρandeare both cell centred. Therefore, an interpolation method
must be used to shiftρ andeprior tovxbeing derived andevx being calculated. The positions
of each of these intermediary quantities is demonstrated in figure 3.4. Alternatively, Px could
be interpolated to get a cell centred value and then, post-differentiation, a second interpolation would be required to find cell centred values for∂(evx)/∂x. Neither route appears to be more
computationally efficient than the other and in both cases interpolation is required.
For interpolation, the following fifth order accurate method will return the value off shifted half a grid cell up from the input data,
fi+1 2 =
1
2[a2(fi+1+fi) +b2(fi+2+fi−1) +c2(fi+3+fi−2)], (3.19)
wherea2 = 1−b2−c2,b2 =−(1 + 24c2)/8andc2 = 3/128. This operator is independent of
direction and, therefore,i,jandkcan be easily interchanged for interpolation in each of the three directions. Again, equivalent operators exist for returning the result shifted down half a grid cell. The derivations of the differentiation and interpolation methods can be found in appendixA.
We note that the up-shifting differentiation and interpolation methods use the same neighbouring six points to give the result. The only variations between the two methods are the values of
their coefficients{a1, b1, c1}and{a2, b2, c2}. Similarly for the down-shifting methods. Both the
differentiation and interpolation methods have the same order of accuracy and error. Additionally, choosing some of the coefficients to be zero changes the order of accuracy associated with the methods. For the differentiation method, if only c1 is zero, the method reduces to third order
accurate, while if bothc1 andb1are zero the method is only first order accurate. Similarly for the
interpolation method.
As the edge of the domain is reached, the differentiation and interpolation methods can encounter difficulties. For both methods, three gridpoints are needed on either side of the point being calcu- lated and, as the boundaries are approached, the methods will run out of gridpoints on one side. The resolution of this problem will depend upon the type of boundary in operation and will be considered further in section3.5.1.
3.3.2 Advancing the Equations in Time
Once the right handside of(3.1)−(3.4)has been evaluated using the differential and interpolation operators described in section3.3.1, the solution is numerically integrated over a small period of time using an Iterative Multistep (IMS) method. This consists of a predictor method of ordero
and a corrector step of ordero+ 1.
The particular IMS used byDiffin3dis the iterated leapfrog method byHyman(1979). This combines a second order predictor step with a third order corrector step. The method will be applied to each of(3.1)−(3.4)to find values forρ,e,BandPat the next time interval.
In the following, we will setr to be the ratio of the time periods between successive iterations,
r= (tn+1−tn)/(tn−tn−1)wherenis the iteration number. The predicted value of the quantity
f is given by
fn(∗+1) =p1fn−1+ (1−p1)fn+q1
∂fn
∂t , (3.20)
wherep1 = r2, q1 = ∆t(1−r). Here∆t = tn+1−tn. The corrector step makes uses of the
solution found by the predictor step as follows
fn+1 =p2fn−1+ (1−p2)fn+q2 ∂fn ∂t +w2 ∂fn(∗+1) ∂t , (3.21) wherep2 = 2(1 +r)/(2 + 3r),q2= ∆t(1 +r2)/(2 + 3r)andw2 = ∆t(1 +r)/(2 + 3r).
The solution,fn+1, found by the corrector step will then be used by the differentiation and inter-
If used alone, the predictor step can cause problems affecting the solution.Hyman(1979) explains that the odd and even gridpoints are only weakly coupled when conservation laws are integrated, as here. Thus, waves with frequency twice the grid spacing distance can obscure the true solution with high frequency noise. The corrector step acts to couple the gridpoints over 3 consecutive iterations, thereby preventing this weak instability.
For accuracy of the solution, it is necessary that information does not propagate to a point outside of the numerical stencil during a single iteration. If∆xis the distance between consecutive grid cells and∆t is the time between consecutive time steps, then the maximum speed allowed is
M∆x/∆t, where M is the number of gridpoints lying between the point being calculated and the edge of the stencil. For the differentiation and interpolation operators used by Diffin3d
M = 2.5. This is the Courant-Friedrichs-Lewy (CFL) condition (Courant et al. 1928) and is formalised mathematically for a fluid as
max (|v|+cs)≤M∆x/∆t, (3.22)
wherecsis the local sound speed and|v|is the local advection speed. This implies that if the fluid
is moving as a whole under advection with a speed|v|and it causes a disturbance that propagates at the local sound speedcs, then the maximum speed it will move at is the sum of the two individual
speeds. Hence, the chosen time step size must be less than the maximum sum of|v|andcs. For
increased stability,Diffin3dchooses M = 1and, thus,M will be dropped in the continued discussion of the CFL condition below.
For a plasma, the CFL condition must be modified to take into account the Alfv´en speed, vA.
Rather than the local sound speed we use the fast speed,cf =
p
cs2+vA2, thus(3.22)becomes
max (|v|+cf)≤∆x/∆t. (3.23)
We cannot control the speed at which waves move and, therefore, we must ensure the CFL condi- tion is satisfied by choosing a suitable time step. This is itself a problem, since it is impossible to know the exact speeds that will occur in an particular model prior to it being run. We cannot be certain that a time step chosen at the initialisation stage will be satisfactory over the whole time pe- riod of an experiment. Hence,Diffin3dmakes use of variable time steps. Prior to the leapfrog method being applied, the CFL condition is evaluated and the time step chosen accordingly. Thus, the time period between consecutive time steps will vary throughout the simulation.
Rearranging(3.23), we have
∆t
whereCis the Courant number. Following from(3.23)we haveC= 1for a 1D problem. For 3D simulations,C = 1/√3≈0.58. If the value ofCis increased, then inaccuracy is introduced into the solution and, ifCis reduced, diffusive effects become apparent. For the simulations described in this thesis, Diffin3dusesC = 0.3 to keep time truncation errors small and the time step well within the limits of the CFL condition.Diffin3dcalculates
C∆x/
q
max (|v|2+c
f2), (3.25)
with the prescribed value forCto arrive at the time step,∆t, for the particular iteration.
Diffin3duses the CFL condition in addition to similar conditions on the viscous and resistive diffusion. Thus, the choice of∆tarrived at by(3.25)must also satisfy
∆t
(∆x)2fmax (ν, η)≤C, (3.26)
whereν is viscous diffusivity andη is electrical resistivity. f is a factor associated with the arti- ficial diffusion, which will be discussed in the section3.4. For the particular diffusion quenching operator given by(3.30), f is chosen to be 20. If∆t does not satisfy(3.26), then it must be reduced further until it does.
Finally, in determining a suitable value for ∆t, Diffin3d also takes into account gradients in energy and density with respect to time. If these gradients become to steep numerical error may give rise to negative values for these quantities, which is clearly not allowed. Thus, further reduction of ∆tmay be necessary to ensure accurate tracking of sharp changes in energy and density. Further measures, in the form of Newton cooling, can be initialised inDiffin3d to prevent negative energy arising and this will be discussed in section3.5.4.
We note that the restrictions placed on the time step by the CFL and additional gradient conditions usually give∆tsuch that the solution is advanced by less than one whole time unit per iteration.