Introduction to simulations

Download Report

Transcript Introduction to simulations

Lectures 9 & 10
Introduction to Simulations
Introduction to MHD Simulation
Categories of Partial Differential Equations
•
Partial Differential Equations are usually classified into three categories
based on the characteristics or curves of information propagation.
– Hyperbolic equations – e.g. a wave equation where v=const. is the velocity of
propagation.
2
2
u
2  u
v
2
t
x 2
– Parabolic equations- e.g. a diffusion equation where D is the diffusion coefficient.
u
  u 
  D 
t
x  x 
– Elliptic equations – e.g. Poisson equation where r is the source term. For r=0 we
have Laplace's equation.
 2u  2u
 2  r x, y 
2
x
y
•
The first two examples are initial value problems – they tell how a system
evolves in time and are solved by integrating forward in time.
•
The third is a boundary value problem - there the system must give the
solution everywhere simultaneously. (You can’t integrate in from the
boundary like you integrate forward in time).
•
In global MHD modeling we interested in solving a set of hyperbolic
equations at the Sun, heliosphere and magnetosphere and an elliptic
equation in the ionosphere.
Boundary Value Problems
•
•
Stable solutions to boundary value problems are usually easy to achieve.
Most effort is on making them efficient.
These become the solution of a number of simultaneous algebraic
equations.
2
2

u

u
Consider a solution to

 r x, y 
•
Represent u(x,y) by its values at specific points where D is the grid spacing
•
x 2
y 2
x j  x0  jD
j  0,1,...J
yl  y0  lD l  0,1,...L
•
Substitute into the Poisson equation and let uj,l=u(xj.yl)
u j 1,l  2u j ,l  u j 1,l
D
2

u j ,l 1  2u j ,l  u j ,l 1
D
2
 r j ,l
u j 1,l  u j 1,l  u j ,l 1  4u j ,l  D2 r j ,l
Solutions to Boundary Value Problems
• This can be converted into a matrix equation following
the prescription in Press (1986) page 618 and the
resulting matrix can be inverted.
• Define i  jL  1  l for j=0,1…J, and l=0,1,….,L. In this
way i increases most rapidly along the columns
representing y values.
• The equation now becomes
ui  L1  ui L1  ui 1  ui 1  4ui  D2 ri
• The points j=0,j=J, l=0, and l=L are the boundaries
where either the function or its derivative are specified.
• This gives an equation of the form A  u  b and can be
solved by a number of inversion techniques.
A Note on Conservation Laws
• Consider a quantity that can be moved from place to
place.

• Let f be the flux of this quantity
 – i.e. if we have an
element of area A then f   A is the amount of the
quantity passing the area element per unit time.
• Consider a volume V of space, bounded by a surface
S.
• If s is the density of the substance then the total
amount in the volume is  s dV
V
• The rate
 at which material is lost through the surface
is  f  dA
S
 
d
s dV   f  dA

dt V
S
Flux Conservation Continued
 
d
s dV   f  dA

dt V
S
– Use Gauss’ theorem
 s

V  t    f dV  0
– An equation of the preceding form means that the
quantity whose density is s is conserved.

s
   f
t
Flux-Conservative Initial Value Problems
•
•
•
Many initial value problems can be written in flux-conservative form where u
and F are vectors. F is called
flux.
 
 the conservative
u
F u 

t
x
The simplest general flux-conservative equation is the advection equation
with a constant velocity v
u
u
 v
t
x
The solution of this equation is a wave propagating in the positive xdirection where f is some function.
u  f x  vt
•
Let's try the most straightforward approach and select equal points in x and
t
x j  x0  jDx
t n  t0  nDt
j  0,1,...J
n  0,1,...N
Flux-Conservative Initial Value Problems –
The Advection Problem 2
•
Forward Euler differencing – First order accurate in time- can calculate
quantities at n+1 knowing only previous quantities.
u
t
•
j ,n
Dt
 O(Dt )
Second order approximation in space using only quantities know at time n.
u
x
•

u nj 1  u nj

u nj1  u nj1
j ,n
2Dx
 O(Dx 2 )
The resulting approximation in the advective equation called Forward Time
Centered Space (FTCS) becomes
u nj 1  u nj
Dt
 u nj1  u nj1 

  v
 2Dx 


• Too bad it doesn't work!
Flux Conservative Initial Value Problems:
Stability
•
The FTSC approach is an explicit scheme – i.e. ujn+1 can be calculated
from things already known.
•
Assume that the coefficients of the difference equations are slowly varying.
In that case the independent solutions (eigenmodes) of the difference
equations have the form u nj   n eikjDx where k is a real spatial wave number
and    k  is a complex number.
•
The difference equations will have an exponentially growing mode if
•
•
The number ξ is called the amplification factor at a given wave number k.
Substitute the equation for ξ into the FTCS equation and get
 k   1  i
•
 k   1
vDt
sin kDx
Dx
FTCS is unconditionally unstable because the absolute value of ξ is always
greater than one.
Flux Conservative Initial Value Problems: The
Courant Condition

1 n
u j 1  u nj1
• Let u 
2
n
j
equation to give
u nj 1 

and substitute into the advection
1 n
vDt n
u j 1  u nj1 
u j 1  u nj1
2
Dx




(Lax Method)
•The amplification factor becomes
vDt
  cos kDx  i
sin kDx
Dx
•The stability requirement gives
v Dt
 1. This is called the
Dx
Courant-Friedrichs-Lewy stability criterion. Information propagates
with a maximum velocity of v. If the differencing scheme requires
information from too far away to propagate to a given point it will
be unstable. Therefore Dt must not be too large.
Flux-Conservative Initial Value Problems: The
Courant Condition 2
•
•
How does replacing ujn in the time derivative by its average lead to stable
solutions?
Rewrite the equations for the Lax method as
u nj 1  u nj
Dt
•
 u nj1  u nj1  1  u nj1  2u nj  u nj1 
 

  v
 2Dx  2 

Dt




This is the FTCS representation for the equation
u
u Dx 
 v

t
x 2Dt
2
•
•
•
•
The extra term is a diffusion term – we call this adding numerical dissipation
or numerical viscosity.
From the amplification factor unless v Dt  Dx   1 and the wave amplitude
decreases. This is better than spurious increases.
Finite-difference schemes also can exhibit dispersion or phase errors. Even
if v Dt  Dx the amplification factor is   e ikDx . At each time step the modes
get multiplied by different phase factors depending on their value of k.
Eventually the wave packet disperses.
The Lax method is first order in time. Other methods have second order or
higher in both time and space. Higher order in time allows larger time steps.
Flux-Conservative Initial Value Problems:
Shocks and Upwind Differencing
• Numerical viscosity tends to control the formation of spurious shocks
• In space physics shocks are physically real.
• For wave equations propagation (amplitude or phase) errors are
usually the most troublesome but for advection transport errors are
important.
• For example in the Lax scheme j propagates to j+1 and j-1 in the
next time step. If v is positive the propagation is only in the plus
direction.
• One way to deal with transport errors is to use upwind differencing.
This uses the fact that depending on the sign of v an advected
quantity propagates in one direction.
u nj 1  u nj
Dt
u nj 1  u nj
Dt
n
n


u

u
j 1
n j
n
 v j
, v j  0
 Dx



 u nj1  u nj

n

 v
, v j  0
 Dx



n
j
• This is useful where advected variables pass through a shock.
An Example of an Implicit Scheme
• Consider the parabolic diffusion equation in one spatial
dimension
u   u 
 D 

t  x   x 
• This can be written in flux-conservative form if
u
F  D
x
• Let D be a constant.
u
 2u
D 2
t
x
An Implicit Scheme 2
• Difference it explicitly
u nj1 u nj
Dt
 u nj1  2u nj  u nj1 
 D

2
Dx 


• Note that the right hand side has a second derivative
that has been differenced.
• This time the amplification factor is
 kDx 
  1  D x 2 sin 

 2 
4 DD t
2
and stability is achieved for
2 DDt
1
2
Dx
• The maximum time step is related to the2 time it takes to
diffuse across the width of a cell or   
D
An Implicit Scheme 3
• Since we usually are interested in physical phenomena
on scales much larger than Dx this would require us to
take too many time steps.
• We need to take larger time steps but larger time steps
will not work for small scale phenomena.
• We might be ok if we could figure out a way to do
something that works on large scales at the expense of
small scales.
 u nj11  2u nj 1  u nj11 
• Consider u nj 1  u nj
Dt
 D

D x 
2


• This is same as before except that everything on the
right is at time n+1.
• This is an implicit scheme in which you must solve a
set of simultaneous equations at each timestep for ujn+1
An Implicit Scheme 4
• At large scales the amplification factor becomes

1
 kDx 
1  4 sin 2 

2


• This is unconditionally stable at any time step size!
• The details of the small-scale evolution of the initial
conditions are inaccurate.
• This is first order accurate but higher order schemes are
possible.
• The biggest drawback of this approach is that you
frequently have to invert very big matrices to solve the
linear equations.
• Some modern approaches combine implicit and explicit
approaches. (The solar code used for the flux
cancellation model is semi-implicit.)
• The two MHD codes we will use in this class are explicit.
The Magnetohydrodynamic Equations
• Macroscopic plasma properties are governed by basic
conservation laws for mass, momentum and energy in a fluid.
Mass
Momentum
Energy*
Faraday’s Law
Gauss’ Law
Ohm’s Law
Ampere’s Law

r
   ( r v )
t

  

r v
   ( r v v  p I ) + j  B
t
  
e
1
p
   [(e  p ) v ] + j  E
e  r v2 
t
2
 1


B
   E
t

B  0


 
E   v  B   j    j2
 1

j
B
0
 

5
 p 




v


p



p


v



1
j

E




* Some solve for a pressure equation
3
 t

Properties of MHD
 
• In ideal MHD the field is frozen-in ( v  E  B ) provided 
B2
is small.
• MHD is useful for a wide variety of problems because
basically it is a statement of mass, momentum and
energy conservation.
• Information is propaged by three MHD wave modes.
• MHD equations allow us to capture shock waves
(important in the supersonic solar wind).
• The inclusion of resistivity () allows us to break the
frozen-in approximation and study magnetic
reconnection.
MHD wave modes
• Alfvén speed: ca 
B2
0 r
P
• Sound speed: cs 
r
• Intermediate (Alfvén) wave v ph  c A cos   k  B / kB
• Fast and slow waves:
v ph
2
1 2 2
 (cs  c A )  (cs2  c A2 ) 2  4cs2c A2 cos 2 

2
Reconnection
– As long as frozen in flux holds plasmas can mix along flux tubes
but not across them.
 When two plasma regimes interact a thin boundary will separate
the plasma
 The magnetic field on either side of the boundary will be tangential
to the boundary (e.g. a current sheet forms).
– If the conductivity is finite and there is no flow Faraday’s law and
Ampere’s law give a diffusion
equation

2
B
t

1
0s
 Bx
z 2
 Magnetic field diffuses down the field gradient toward the central
plane where it annihilates with oppositely directed flux diffusing
from the other side.
 This reduces the field gradient and the whole process stops but not
until magnetic field energy has been converted into heat via Joule
heating (the resulting pressure increase is what is needed to
balance the decrease in magnetic field pressure).
Reconnection 2
– For the process to continue flow must transport
magnetic flux toward the boundary at the rate at
which it is being annihilated.
EY
JY
2l
EY
 An electric field in the Ey (E y  u z 0 Bx 0) direction will
provide this in flow.
 In the center of the current sheet B=0 and Ohm’s law gives
Ey  jy s
 If the current sheet has a thickness 2l Ampere’s law gives
j y  Bx 0  0 l
Reconnection 3
 Equating the EY expressions
l  1 0s u z 0 
 Thus the current sheet thickness adjusts to produce a
balance between diffusion and convection. This means
we have very thin current sheets.
 There is no way for the plasma to escape this
system. However, if the diffusion is limited in extent then
flows can move the plasma out through the sides.
Reconnection 4
– When the diffusion is limited in space annihilation is
replaced by reconnection
 Field lines flow into the diffusion region from the top and
bottom
 Instead of being annihilated the field lines move out the
sides.
 In the process they are “cut” and “reconnected” to different
partners.
 Plasma originally on different flux tubes, coming from
different places finds itself on a single flux tube in violation of
frozen in flux.
 The boundary which originally had Bx only now has Bz as
well.
– Reconnection allows previously unconnected regions
to exchange plasma and hence mass, energy and
momentum.
 Although MHD breaks down in the diffusion region, plasma
is accelerated in the convection region where MHD is still
valid.
Z
X
Toward a Self-Consistent Solution
Solving the MHD Equations – Magnetospheric
Boundary Conditions
• The MHD equations are solved as an
initial value problem.
• Solar wind parameters enter the
upstream edge of the simulation and
interact with fields and plasmas in the
simulation box.
• Boundary conditions at the
downstream edge, the north and south
edges and the east and west edges are
set to approximate infinity.
–Downstream- y  x  0 where
y represents the parameters in the
MHD equations.
– The bow shock frequently passes
through the side and top and
bottom boundaries. Here setting
the derivative approximately
parallel to the shock to zero works
well.
Solving the MHD Equations: The Inner
(Ionosphere) Boundary
• Map field aligned currents
( J ) from the inner boundary to the
||
ionosphere.
•
Using current continuity the relationship
between the ionospheric potential and the
parallel current is
Magnetosphere
V 
 F  B
B2
J ||
Inner
Boundary
    F   J || sin I
•
Use mapped FAC and conductivity model
to solve for the ionospheric potential F.
– For a scalar conductance (S) the potential
2
becomes  F  j S
– This is Poisson's equation and can be
solved as a boundary value problem.
•
B
Map the potential back to inner boundary
and use it to determine boundary condition
for the perpendicular flow.
Ionosphere
 F
J ||
Ionospheric conductance
• The dense regions of the ionosphere (the D, E and F regions)
contain concentrations of free electrons and ions. These mobile
charges make the ionosphere highly conducting.
• Electrical currents can be generated in the ionosphere.
• The ionosphere is collisional. Assume that it has an electric field
but for now no magnetic field. The ion and electron equations of


motion will be
qE  mi inui


 eE  me en ue
where  in is the ion neutral collision frequency and  en is the
electron neutral collision frequency.
– For this simple case the current
will
be related to the electric


  ui  ue 

field by
j  s 0 E  e

ne


where s 0 is a scalar conductivity.
• If there is a magnetic field there are magnetic field terms
in the

momentum equation. In a coordinate system with B along the
s P s H 0 
z-axis the conductivity becomes a tensor.


s  s H
 0

sP
0
0
s 0 
• Specific conductivity – along the magnetic field
 1
1 



m

m
i i 
 e e
s 0  e 2 ne 
• Pedersen conductivity – in the direction of the applied electric
field

i
1
1 


2
2
2
2



m



m
e
e
i
i
i 
 e
s P  e 2 ne 
e
• Hall conductivity – in the direction perpendicular to the applied
field
 

1
1 

s H  e 2 ne  2 e 2
 2 i 2



m



m
e
e
i
i
i 
 e
where  e and  i are the total electron and ion momentum transfer
collision frequencies and  e and i are the electron and ion
gyrofrequencies.
• The Hall conductivity is important only in the D and E regions.
• The specific conductivity is very important for magnetosphere
and ionosphere physics. If s 0   all field lines would be
equipotentials.
– Electric fields generated in the ionosphere (magnetosphere) would
map along magnetic field lines into the magnetosphere
(ionosphere)
•
•

  

Assume ageneralized Ohm’s law of the form j  s  E  u  B
and that u  0
The total current density in the ionosphere is

 



B E
j  s 0 E  s P E  s H
B
•
where  and refer to perpendicular and parallel to the
magnetic field.
Space plasmas
so
 are quasi-neutral





  J     s  E    s 0 E
s P
s   
s H
where
•
•
 0
s H 

sP 
j

The current continuity equation can be written    s  E  
s
where s is along the magnetic field.
Integrate along the magnetic field line from the bottom of the
ionosphere to infinity. Since the field lines
are
 nearly 
s



equipotentials we can write j       s  ds E       E 
where the perpendicular height integrated conductivity tensor
 P  H 
is



0



 H

P



Ionospheric Conductance Model
• Solar EUV ionization
– Empirical model- [Moen and Brekke, 1993]
• Diffuse auroral precipitation
– Strong pitch angle scattering at the inner boundary of simulation[Kennel and Petschek, 1966]
• Electron precipitation associated with upward fieldaligned currents
(Knight, [1972] relationship- FE  DF j
where FE is the energy flux to the ionosphere, DFis the
parallel potential difference, and j is the parallel current
density.)
• Ionospheric
Pedersen
conductance
viewed from dusk.
• Note the large daynight asymmetry.
This results from
ionization by solar
EUV radiation.
• Ionospheric Hall and
Pedersen conductance
from a simulation of the
magnetosphere during a
prolonged period with
southward IMF.
• The white lines show the
ionospheric convection
pattern.
• Precipitation from the
magnetosphere
enhances both the Hall
and Pedersen
conductances at night.
Pedersen Conductance
Hall Conductance
Solving MHD Equations: Grids
• A wide
variety of grids are
used.
–The grid left is from the model
Jimmy Raeder and Mostafa El
Alaoui used a non-uniform
Cartesian grid.
–The BATSRUS code from the
University of Michigan uses a
Cartesian mesh which is run time
adaptive.
–Ogino uses a uniform Cartesian
grid with 108 cells.
–Linker uses a non-uniform
spherical grid.
–Lyon uses an unstructured
spherical grid.
Solving the MHD Equations: Resistivity
• The ideal MHD equations are nondissipative.
• Numerical resistivity occurs in all codes
caused by the averaging errors inherent in
the numerical process.
• Most of the MHD modes add dissipation
terms to the ideal MHD equations. Some
form of dissipation is necessary if
phenomena like reconnection, in which ideal
MHD breaks down, are to be included in the
simulation.
•The resistivity models can depend on the
physical parameters. For instance in the
Raeder-El Alaoui global MHD code the
resistivity has a threshold in current density
and then is proportional to the currrent
2
density squared (    J ).
Solving the MHD Equations: Spatial
Differencing for Gas Dynamics
• A conservative finite difference
method to solve the gas dynamics
part of the MHD equations. This is the
procedure used in the Raeder-El
Alaoui code.
U
   F(U )
t
• The flux-limiting procedure applies
diffusion only in the regions where it
is necessary to balance dispersive
effects.
fi 1 , j
2
U

t
f
i
1
2
f
1
i , j
2
(U )  f
Dx
1
i , j
2
(U )
f

i, j
1
2
(U )  f
Dy
i, j
1
2
(U )
1
 ( F (U i )  F (U i 1 ))
2
1
 ( vi  vi 1  ci  ci 1 )(U i 1  U i )
4
Solving the MHD Equations: Time Stepping
•
An explicit conservative predictorcorrector scheme for time
stepping (second order accurate):
•
Dt max  
U
   F(U )
t
U
n
1
2
1
 U  Dt. F(U n )
2
n
U n 1  U n  Dt. F(U
Stability criterion (CourantFriedrichs-Lewy, CFL):
n
1
2
)
•
•
min( Dx, Dy , Dz )
v  vms
This must be satisfied everywhere
in the simulation domain.
Since characteristic velocity is the
Alfvén velocity the Courant
condition is important near the
Earth where the Alfvén becomes
large and the time step becomes
small.
Solving the MHD Equations: The Field
Equations
•
Place the magnetic field
components on the center of the
cell faces
( B x ) i  1 , j ,k ; ( B y ) i , j  1 ,k ; ( B z ) i , j ,k  1
2
•
2
2
Place the electric field
components on the centers of the
cell edges
( E x ) i , j  1 ,k  1 ; ( E y ) i  1 , j ,k  1 ; ( E z ) i  1 , j  1 ,k
2
2
2

2
2
2


Bx i  12 , j ,k  E y i  12 , j ,k  12  E y i  12 , j ,k  12 Dz
t
 E z i  1 , j  1 ,k  E z i  1 , j  1 ,k Dy

2
2
2
2

Divergence of B Control
• 8-wave scheme – adds source terms to the MHD
equations so that magnetic monopoles are advected with
the velocity of the plasma.

• Diffusive control – adds the gradient of   B to the
induction equations, so that the error in   B is diffused
away.
• Hyperbolic correction adds
extra scalar equation to

propagate error in   B with preset speed.

• Projection scheme eliminates the   B errors after each

2
time step by solving a Poisson equation      B and
 
B
projecting to a divergence free solution   B  
• Constrained transport
use a special discretization that

the conserves   B to round off.
Some Examples of Global MHD Simulations:
The Earth's Magnetosphere
• A simulation
of the Earth's
magnetosphere during a large
magnetospheric substorm
using the Raeder- El Alaoui
code.
• The thermal pressure in the
noon-midnight meridian
plane.
•This snapshot was taken at
the time of the substorm
onset.
Some Examples of Global MHD Simulations:
Planetary Magnetospheres
•
•
•
The temperature of the
plasma in Jupiter's
magnetosphere during an
interval in which the IMF
was northward.
This simulation used the
Ogino-Walker MHD code.
For this calculation the
MHD equations were
advanced on a uniform
Cartesian grid with ~108
cells.
At Jupiter the model must
include atmospherically
driven corotation and allow
plasma from Io's
volcanoes to populate the
magnetosphere.
Some Examples of Global MHD Simulations:
The Heliosphere
• The temperature (color
spectrogram) and
magnetic field lines of an
expanding coronal mass
ejection.
• This calculation was done
using the BATSRUS code
developed at the
University of Michigan.
This code uses an
adaptive grid.
Some Examples of Global MHD Models:
Modeling the Sun
• Magnetic field lines in the
solar corona.
• This simulations uses a
semi-implicit code
developed by Jon Linker
and colleagues at SAIC.
• The simulation was run on
a spherical grid system.