You are on page 1of 21

GTS User Manual For Finite Element Solver

gts team
Princeton Plasma Physics Lab
P.O. Box 451, Princeton, NJ 08543
May 9, 2014

Contents
1
2
3
4
5
6

.
.
.
.
.
.
.
.
.
.
.
.

1
2
3
4
6
7
9
11
11
13
14
17

Appendices
1
Flux Coordiante Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
Numerical integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

19
19
20

First Of All: How To Get The Code . . . . .


Second Of All: How To Run The Code . . . .
GTS Mesh Grids and Safety Factor . . . . . .
Poisson Equation and new gk solver . . . . .
Poisson Equation and new fem solver . . . . .
Finite Elements Method . . . . . . . . . . . .
6.1
C 0 linear elements . . . . . . . . . . .
6.2
C 0 2nd order elements . . . . . . . . .
6.3
C 1 5th order elements . . . . . . . . .
6.4
Find Derivatives . . . . . . . . . . . .
6.5
Boundary Conditon . . . . . . . . . .
6.6
Numerical Difficulty: periodic domain

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

First Of All: How To Get The Code

GTS is under version control at


svn+ssh://svnsrv.pppl.gov/svn/gts
If you do
1) module load subverison
on portal, you can check what are there using command
2) svn list -R svn+ssh://svnsrv.pppl.gov/svn/gts
As a start, you need to check out a working copy for yourself using command
3) svn co svn+ssh://svnsrv.pppl.gov/svn/gts/trunk/GTS
To check your working copy status, go to GT S directory and do
4) svn status -u
To check who did commits, go to GT S directory and do
5) svn log
To check the difference of your working copy against the distribution, do
6) svn diff
To update your working copy with newest changes in the distribution, go to GT S directory and do
1

7) svn update
To commit your changes into the distribution, the easiest way is to go to the parent directory of GT S
and do
8) svn ci GTS -m "your message"
Note: before you commit, you must do svn update after you committed, you must do svn update
again to avoid any future conflicts. To add a new file or directory under GTS dir into svn, go to GTS dir
and do
9) svn
svn
svn
svn

update
add filename/dirname
ci GTS -m "your message"
update

Second Of All: How To Run The Code

GTS runs on hopper and edison at NERSC. The finite element solver starts from input parameter
order
given in the input file with default name
INPUT.d
It sets the order of finite elements to be used throughout the run:
order = 0 original new_gk_solver solver \\
order = 1 linear finite element \\
order = 2 2nd order finite element \\
and is save as
solverobject%order=order
where the solverobject can be either solver1, solver dphi dt, or masssolver defined in
main.F90
There is another variable declared in the solverobject
solverobject%fem%oder
which is set to
solver1%fem%oder=order
as well for solver1 and solver dphi dt when boundary condition will be imposed for poisson equation in
subroutine
petsc_solve
If the solverobject is masssolver, called to find the partial derivative along the coordinate directions a
and/or where (a, ) is the flux coordinates used in GTS, then we set
masssolver%oder=0
which means masssolver doesnt need a boundary condition to proceed in subroutine
petsc_solve
2

Each solverobject has its own set of mesh and elements so that different order of elements can be used
to improve efficiency. If order is set to 1 or greater, then the solverobject is created through calling
new_fem_solver
Otherwise,
new_gk_solver
is to be called as the default solver. In new f em solver, first a triangular mesh is generated through
utility triangle, then finite elements are created on this mesh, and finally the type of matrix and boundary
condition are applied to modify the stiffness matrices. The code returns the successfully created solver
contents if no error has been encountered. The solverobject can be used to solve the fem resulted linear
systems stored in
solverobject%ksp
The rhs is modified according to section 6.5 in subroutine
petsc_solve
depending on the type of boundary condition, which is the second one must-be-set parameter. From
INPUT.d
the boundary is given by
a0 : a_min is the flux surface closest to magnetic axis
a1 : a_max, the outmost flux surface
which set the following 4 type of boundary conditons
bc_type = 0 neumann boundary conditions at both a=a0 and a=a1
bc_type = 1 dirichlet boundary condition at a=a0,
neumann boundary conditions at a=a1
bc_type = 2 dirichlet boundary conditions at both a=a0 and a=a1
bc_type = 3 neumann boundary condition at a=a0,
dirichlet boundary conditions at a=a1
and bc type is passed as an argument to new fem solver. In the case of solver dphi dt is solved, only
homogeneous Dirichlet boundary conditions will be imposed on boundaries at a = a0 and a = a1.
The third important parameter is mat type passed to new fem solver in the same way as that bc type
is argumented. But we dont use it in the current version of finite element solver. It is reserved for future
use.

GTS Mesh Grids and Safety Factor

GTS mesh setup has been described in reference [1]. Here we only record the part important to understand
finite element mesh. The GTS mesh is constructed using modified safety factor q(a), which is used
everywhere in the code. In the magnetic flux coordinates (a, , ), the field lines are straight and the
radial coordinate labels magnetic surface
s

a=
e
where and e are the toroidal flux and its value on the plasma boundary, repectively. Therefore,
a0 a a1,

0 < a0 < a1 1

a0 and a1 are input parameters explained in section (2).


In the poloidal direction, the total number of radial grids, each one representing one flux surface, is
given by the global parameter
3

mpsi
in
INPUT.d
and the grid with grid size (a) is computed and saved in array
mtheta(0:mpsi)
which is uniform on each flux surface, while varying from surface to surface. It is determined so as to
make poloidal arc length l near the midplane correlated with i in the loop
do i=0,mpsi
tdum= ...
mtheta(i)= ... tdum ...
enddo
in code
setup_v2.F90
and the total number of grid on each poloidal plane is evaluated and saved in parameter
mgrid=sum(mtheta+1)
Note that the mesh points are doubly counted when = 2 meets = 0 in mgrid caused by polidal 2
periodicity. By excluding this repeated redundancy, the total number of grids in each poloidal plane is
computed by
neq=sum(mtheta)
where [1 : mtheta(0)] corresponds to boundary at a = a0, and [neq mtheta(mpsi 1) + 1 : neq] corresponds to boundary at a = a1.
Once the 2D mesh was constructed on the = 0 plane, a 3D mesh is constructed by starting from a
grid point, following each (approximate) field line which satisfies
q(a) = const
q(a) is slightly different from the usual safety factor q(a) and makes approximate come back to one of
the grid points on the = 0 plane.
The number of toroidal grids, i.e., the number of poloidal planes,
mzetamax
is chosen as input parameter to give adequate resolution for the parallel structure of the modes.

Poisson Equation and new gk solver

new gk solver uses four-point averaging scheme to solve GK poisson eq.


Generally, with distribution function defined as a 7D function f (x, v, t) of real space x, velocity space
v, and time t, the density can be given as a 3D function of real space x
Z
n(x, t) f (x, v, t)d3 v
(1)
Similarly, we can defined the perturbed ion density and electron density
R
ni (x, t) = R fi (x, v, t)d3 v
ne (x, t) = fe (x, v, t)d3 v
4

(2)

in real space. The quasi-neutrality becomes


ni (x, t) ne (x, t)
But in gyro-kinetic studies, the distribution function is defined at guiding center R, as a 6D function
fgc (R, , vk , t) of guiding center position R, magnetic moment , the parallel velocity vk , and time t.
Thus, the transformation between the particle position x and the guiding center position R should be
applied.
Briefly, we have the guiding center density
Z
ngc (R, t) fgc (R, , vk , t)J ddvk
the potential

the ion density ni

Z
1

(R,
) =
(x)(x R )dxd
2
Z
1

(x) =
(R,
)f0i (R, , vk )(R x + )dRddvk d
2

ni (x) =

the electron density ne


1
ne (x) =
2

1
2

fi (R, , vk )(R x + )dRddvk d

1
fe (R, , vk )(R x + )dRddvk d =
2

fe (x, , vk )ddvk

where is the gyro-radius vector, is the gyro-phase, f0i is assumed to be Maxwellian for ions, and fi
is the perturbed ion distribution function. Using
ni (x, t) =
ni (x, t) + npolarization
=
ni (x, t) n0
i

qi

( )
Ti

and the quasi-neutrality condition, we obtain the most used poission equation
ni (x, t) ne (x, t)
qi
=
( )

Ti
n0
n0

(3)

Instead of solving total potential, one may solve for the turbulence contribution and zonal flow
contribution hi given by
= hi
The equation for is derived by taking flux surface average of the total potential equation (3) and
subtracting this average from (3)
qi
ni h
ni i ne hne i
=
( )

Ti
n0
n0

(4)

An alternate method to solve for electorns is the so called h method. In summary, one way is to
solve the total potential.


qi
nh
qi

ni
T i qi
=
e + hi
(5)
1+
Te Ti
Ti
n0
n0
Te
and the other way is to solve equation for the turbulence potential


T i qi
qi

ni h
ni i nhe hnhe i
1+
=

Te Ti
Ti
n0
n0

(6)

Poisson Equation and new fem solver

new fem solver uses finite elements to solve partial differential GK equation.
Instead of solving integral equation, we can derive and solve the elliptic pde for the total potential .
From the total potential eq (3), we obtain


qi n0

= h
ni i ne
(7)
Bi
More generally, the following GK poisson equation is implemented in the code
!
X
+
g s = b

(8)

where

  
  
mo
ms
eo
Zs
1
1
,
(a)
=

,
g
(a)
=
n
(a) = ee0
2
s
so
me
Te
B
es
mo
 neo
 (a) 
H
P n s  nso  nna
J dd
hi
mo
e
, hi = H J dd
b = s nso neo neo
+ eeo
me
Te
nna
e is the non-adiabatic electron fluctuation density

s specifies the ion species. From now on we assume single ion specie s = 1 for simplicity. In flux coordinate
(a, , ), the second term in eq (8) becomes
(gs )
= (gs )

= J1 a
[J gs a] +

1
J

[J gs ] +

1
J

(9)
[J gs ]

where J represents the flux coordinate Jacobian [a ] . Please refer the Appendix for a
summary of formulae in curved coordinate systems. The first term in (9) can be written as
h
i
a = (b )b a
(10)
a


aa
a
=
+ g
a a + a = a g
in an axis-symmetry system. Similarly, the second term in (9) can be written as
h
i
= (b )b


a

+
=
a a + = a g
g

(11)

and the third term in (9) becomes


1
J

[J gs ] =

h
i

(b )b
gs
[ ] = gs
i
h

2
= gs ||2
[ ] = gs
||
gs

h
i
gs

2
1q
=

||
gs ||2

q

gs
2 2
q 2 || 2

(12)

gs 2
q 2 2 g

Subtituting (10) (11) (12) into (8), the partial differential equation to be solved becomes
+
h

J gs
J1 a
=b

aa
a g

a
g

1
J J gs

a
a g

Here g aa , g a , g represent the coordinate metrics.


If we decompose into 2 parts
= hi +
6

gs 2
q 2 2 g

(13)

Similarly to eq (8) the equation for will be


+

gs = b

gs

dhi
a
da

(14)

with an additional term on the rhs. This addtional term can be extended as follows




P
dhi
dhi
1
1
s gs dhi
a
da a = J a J gs da a a 
J J gs da

dhi a
1

aa

g
g
J gs dhi
J
g
= J1 a
s
da
J
da

Thus eq (14) has a similar form as eq (13) with above additional writing on the right hand side.
solver dphi dt solves the following eq, which is similar to eq (8). The only differences come from
setting = 0, the unknows
t to be solved, and rhs vector b.
(a)

g s

= b,
t

b=

The only boundary condition is Dirichlet type



X Zi
1 nhe
e
ni

neo t
neo t
t Te
i

(15)

= 0 at a = a0 and a = a1.

Finite Elements Method

Finite elements are built upon the reference triangle:


(1(0, 0), 2(1, 0), 3(0, 1))
which is mapped from real triangle:
(x1(a1, 1), x2(a2, 2), x3(a3, 3))
using transformation Jacobian J



J =

from real space x(a, ) to reference space (, )


a
a

(16)

= x = x()
The reverse transformation J 1 is written as
J

from reference space (, ) to real space x(a, )

(17)

x = = (x)
Three types of elements are available in the current version of GTS and are represented by Ni for the ith
base function.
First we introuduce the variational formulation by multiplying quation (13) with base function Ni (i =
1, 2, ) on its both side, integrating over each triangle, and then assembling them together

RR
RR
aa
a
J gs
+

Ni d + R R  J1 a
a g
g  Ni d
1
a

+
J gs i
+
Ni d
a g
g
R R h Jgs
2
(18)

+
Ni d
q 2 2 g
RR
=
bNi d,
i = 1, 2, .
7

d is the 2D differential area in real space. Using the approximated variable and rhs vector b
X
X
=
j Nj , b =
bj Nj
j

the first term in the eq (18) is converted to


RR
RRP
N N J dad

Ni d =

P R jR j j i
Nj Ni J dad j
= j
P
= j Jj mij j

(19)

Similarly, we have for the right-hand-side b term


RR
RRP
bNi d =
b N N J dad
P R jR j j i
Nj Ni J dad bj
= j
P
= j Jj mij bj

(20)

Where J is the flux coordiante Jacobian evaluated at node j and mij is the mass matrix relted to Ni
and Nj . Taking partial integration, the 2nd term on the left of eq (18) becomes


RR
aa

a
J
g
R R J1 a
g
+
g
s
a


 Ni d+
1
a

J gs
g + g
Ni d+
R R hJgs 2 ia

Ni d
2
2 g

R Rq 
aa
a
J
g
g
+
g
= R R J1 a
s
a


 Ni J dad+
1
a

J gs
g + g
Ni J dad+
R R hJgs 2 ia

g
N
J
dad
2
2
i

R Rq i
aa
a
J
g
+
= R R N
s a g
a
g  dad
Ni

J gs g a+
dad
g
R R  gs a

J q2 g Ni dad


RR
R R
a Ni
(21)
i
R R (J gs g aa ) N
a a dad R R J gs g
 a dad
a Ni
Ni

J gs g
J gs g
a dad
dad
R R  gs 
Ni

J q2 g
dad

RR
RR
P
P
i Nj
i Nj
J gs g a N
dad j j
= j j
(J gs g aa ) N
a
a
a dad


RR
R
R
P
P
N
j
i
i Nj
J gs g a N
j j
J gs g N
j j
a dad
dad

RR
P
i Nj
J qg2s g N
j j
dad

P
P
= j (J gs g aa )ij srrij j j J gs g a ij srzij j


P
P
j J gs g a ij szrij j j J gs g ij szzij j


P
j J qg2s g
szzij j
ij

Here srrij , srzij , szrij , and szzij are the stiffness matrices corresponding to operators
Nj Nj
a , . Summing together, we obtain the following linear systems
P
=

{Jj mij


(J gs g aa )ij srrij 2 J gs g a ij srzij J gs g ij szzij


szzij }j
J qg2s g
ij
P
j Jj mij bj , i = 1, 2,

Ni Ni
a , ,

and

(22)

A similar form for equation (14) in section 5 can be given easily. First the additional term on the rhs is


RR 1 
RR 1 
dhi aa
Ni d

J gs dhi
g a Ni d
J a Jgs da g
J

da


RR 1
RR 1 
aa dhi
a dhi
=
J
g
g
N
J
dad

J
g
g
s
i
s
J a
da
J
da  Ni J dad
P RR
P RR
Nj
Nj
a dhi
aa dhi
J gs g da
j
J gs g da
j
a Ni dad
Ni dad
j



 

P
aa dhi
a dhi
sr
J
g
g
sz

J
g
g
ij
s
ij
s
j
j
da
da
j

 RR
P
P 
J1
Ejk k Ni J Jdd + j gs g a dhi
k Ejk ak Ni J Jdd
da
j P

 Pj
R
R
R
R
P
P 
Ejk Ni J dd + j gs g a dhi
Ejk Ni J dd
= j gs g aa dhi
k k
k ak
da
da
j
j





P
P
= j gs g aa dhi
+ gs g a dhi
k (k ak ) Pijk (i, j, k)
da
da
=

P 
j

gs g aa dhi
da

 RR

1
J

where srij and szij are the partial stiffness matrices corresponding to operators aj Ni and j Ni ,
repspectively. The part given in square parentheses is the first option to evaluate this second term each
time the solver is called. The second option follows right away and can be understood by referring section
(6.4). The code can be found in subroutine addh h2bb. Thus we have the second type of linear systems
to be solved
P
{Jj mij
j


(J gs g aa )ij srrij 2 J gs g a ij srzij J gs g ij szzij


J qg2s g
szzij }j
ij

6.1

[=




 
aa dhi
a dhi
J
g
g
{m
J
b

sr
J
g
g

sz
}
s
ij j j
ij
s
ij
j
da
da

j {mij Jj bj



gs g aa dhi
da

(23)


 P
+ gs g a dhi
k (k ak ) Pijk (i, j, k)}
da
j

C 0 linear elements

This set of simplest elements is built upon the three nodes of reference triangle and has continuity across
the element edges:
N1 = 1
N2 =
(24)
N3 =
variable u(x) to be found in real space can be represent by
X
u(x) =
Nj u j

(25)

where uj is the variable u(x) evaluated at triangle node j. With iso-parameter mapping from real triangle
to reference triangle, the coordinates can be written as
P
a = j Nj a j
P
(26)
= j Nj j

Here j refers to the jth node of each triangle. Obvisously, the first order derivative of the base functions
are found to be
N1
N1
= 1
= 1
N2
N2
(27)
= 1
= 0
N3
N3
=
0
=
1

So the Jacobian can be easily computed as


P
P Ni P
P
Nj
Nj
i
J = i ai N
i ai  j j
j j


P P
Ni Nj
i Nj
= i j ai j N

P P
= i j ai j Eij

The inverse Jacobian J 1 is computed below. We start from the following fact
# 
"
 


1 0
1

a
a
=I
J J = a =
0 1

which gives the following two linear sysems. The first one is
# 
"


1
x
=
J
0
y
and the second one is
J

"

0
1

Their solution gives us the four entries in the inverse Jacobian J


#
"
1

= J1
;

a = J
0
#
"
a
1

1
a

= J1
=
;
a

J
0

"
#
0

=
= J1

a
J
;
1
#
"
a
0

= J1 a
a
= J
;
1

Thus the differentition of base functions in real space x(a, ) can be obtained in the following way.
Ni
a
Ni

=
=

Ni

Ni

+
+

Ni

Ni

=
=

Ni 1
Ni
1
J + ( J )
Ni
Ni 1 a
1 a
( J ) + J

Ni
1
i
= J1 ( N
) = J Ei,j j
Ni a
1
i a
= J1 ( N
) = J Ei,j aj

Introducing nw GLL points and weights w(nw) on these points, all the elemental matrices on each triangle
can be written using numerical integration:
Z Z
Z Z
n=nw
X
Ni (n)Nj (n)J(n)w(n)
mij =
Ni Nj dad =
Ni Nj Jdd =
n=1

srrij =

Z Z

Ni Nj
dad =
a a

Z Z

srzij =

Z Z

Ni Nj
dad =
a

Z Z

szzij =

Z Z

Ni Nj
dad =

Z Z

srij =

Z Z

Nj
Ni
dad =
a

Z Z

szij =

Z Z

Nj
dad =
Ni

Z Z

n=nw
X Ni
Ni Nj
Nj
Jdd =
(n)
(n)J(n)w(n)
a a
a
a
n=1

n=nw
X Ni
Ni Nj
Nj
Jdd =
(n)
(n)J(n)w(n)
a
a

n=1

n=nw
X Ni
Nj
Ni Nj
Jdd =
(n)
(n)J(n)w(n)

n=1

Ni

Ni

n=nw
X
Nj
Nj
Ni (n)
Jdd =
(n)J(n)w(n)
a
a
n=1

n=nw
X
Nj
Nj
Ni (n)
Jdd =
(n)J(n)w(n)

n=1

10

6.2

C 0 2nd order elements

This set of elements is built upon the linear elements given in the last section on 6 nodes (3 nodes and 3
edge nodes) of each triangle. All the formation of operators and matrices for the 2nd order elements are
exactly the same as section in 6.1. So well just give the base functions and the corresponding first order
derivatives in the reference space here.
N1
N2
N3
N4
N5
N6

= (1 2)
= 4
= (1 2)
= 4
= (1 2)
= 4

(28)

where = 1 is the N1 , is the N2 , and is the N3 base functions in section 6.1, respectively.
The derivative corresponding to and are
N1

N2

N3

N4

N5

N6

N1

N2

N3

N4

N5

N6

= 1 4
= 4( )
= 1 + 4
= 4
=0
= 4

= 1 4
= 4
=0
= 4
= 1 + 4
= 4( )

(29)

The iso-parameter mapping is used in tranforming from reference space to real space this set of elements.

6.3

C 1 5th order elements

This set of elements is much more complicated than the two sets of elements introuduced in the previous
2 subsections. Here we have 18 base functions built upon the three nodes of each reference triangle, and
2
2
2
each node is related to 6 of them involving ,
a , , a2 , a , and 2 . These 18 base functions are
N1
N2
N3
N4
N5
N6

= 2 (10 152 + 63 + 30( + ))


= 2 (3 2 3 2 + 6)
= 2 (3 2 3 2 + 6)
= 12 2 2 (1 + 2)
= 2 2
= 12 2 2 (1 + 2 )

N7 = 2 (10 15 2 + 6 3 + 15 2 )
N8 = 12 2 (8 + 14 2 6 3 15 2 )
N9 = 21 2 (6 4 3 3 2 + 3)
N10 = 14 2 (2(1 )2 + 5 2 )
N11 = 21 2 (2 + 2 + + 2 )
N12 = 14 2 2 + 21 3 2
N13
N14
N15
N16
N17
N18

(30)

= 2 (10 15 2 + 6 3 + 15 2 )
= 21 2 (6 3 4 3 3 + 3)
= 21 2 (8 + 14 2 6 3 15 2 )
= 41 2 2 + 21 2 3 )
= 12 2 (2 + + 2 + 2 )
= 41 2 (2(1 )2 + 5 2 )

which preseve first order derivative continuity across the element edges. Their derivatives in the reference
space
Ni
Ni
,
, i = 1, 2, , 18

11

are simple algebra and will be omitted here. Check the code for those who are interested in. The most
important numerical issue here is coordinate mapping. Instead of using iso-parameter mapping as we
did in section 6.1 and section 6.2, we use sub-parameter mapping given by C 0 linear element in the
section 6.1, i.e.,
P
a= jN
a
P j j
(31)
= j Nj j

i represents the set of elements given in


to save cost and reduce complexity. Here the base function N

section 6.1 and we renam as Nj to differentiate it from the C 1 elements Ni given in this subsection. If
i can be replaced by the second order elements in secton 6.2.
the precision needs to be increased, the N
Thus the transformation Jacobian wont change from the previous subsections, i.e.,
J=
=
=
=

a
a

P Ni P
P
j
j
i P
N
N
N
i ai
j j
j j
i ai
P Ni Nj
j
i N
N
(

)ai j
Pi,j
i,j Ei,j ai j

i j. We need to differentiate the base functions in real space


Note the bar sign over the above opetator E
x(a, ) as we did previously:
Ni
a
Ni

Ni
i
= N
a + a =
= J1 Eij j
Ni
i
= N
+ =
= J1 Eij aj

Ni 1 y
J

Ni
1 y
( J )

Ni
1 a
( J )

Ni 1 a
J

1 Ni
J (

i
= J1 ( N

yj

j
N

xj

j
N

Ni

Ni

yj

j
N
)

xj

j
N
)

j , thus is different from the Eij in


Apparently, Eij here is a mixed product of derivatives of Ni and N
sections 6.1 and 6.2. However, the mass and stiffness matrices are computed in the same way as we did
ij
in 6.1 with i, j = 1, , 18. We rename them with a bar sign over each matrix just as we did for the E
operator:
m
ij , srr
ij , srz
ij , szz
ij , sr
ij , sz
ij
Besides this, the follwoing transformation matrix is needed to convert the higher order derivative from
reference space to real space before the matrices are assembled. This is not needed in C 0 elements when
only (x) itself is solved. If you insist to have one, then the transformation matrix in such case would
be a matrix with one entry T = [1].
First of all, a new variable U (x) in real space is formed as
U (x) =

18
X

(32)

Nj U j ,

j=1

where
U (x) = (

2
2
2

(x1 ),
(x1 ), 2 (x1 ),
(x1 ), 2 (x1 ),
(x1 ),
a

a
a

{z
}
|
node1

2
2

(x2 ),
(x2 ), 2 (x2 ),
(x2 ), 2 (x2 ),
(x2 ),
a

a
a

{z
}
|

(33)

node2

2
2
2

(x3 ),
(x3 ), 2 (x3 ),
(x3 ), 2 (x3 )
(x3 ),
a

a
a

|
{z
}

)T

node3

and Uj is U (x) evaluated at x = (a, ) on each node. Our problem is converted to solve for U (x).
Once U (x) is solved, we not only have (x) but also we have its first order derivatives and second order

12

derivatives. In the reference space U () has a similar form


U () = (

2
2
2
( 1 ),
( 1 ),
( 1 ), 2 ( 1 ),
( 1 ), 2 ( 1 ),

{z
}
|
node1

2
2
2
( 2 ),
( 2 ),
( 2 ), 2 ( 2 ),
( 2 ), 2 ( 2 ),

|
{z
}

(34)

node2

2
2
2
(3 ),
( 3 ),
( 3 ), 2 ( 3 ),
( 3 ), 2 ()3 ,

|
{z
}

)T

node3

From U (x) to U (), the transformation matrix at each node i is given



1


J11 J12


J21 J22
Ti =
2
J11
2J11 J12


J
J
J
11
21
12 J21 + J11 J22

2

2J21 J22
J21

as:

2
J12
J12 J22
2
J22

It is derived in the following steps.


u

2u
2

2u

2u
2

=
=
=
=
=
=
=
=
=
=
=
=
=
=

u a
u
u
u
a + = a J11 + J12
u a
u
u
u
a + = a J21 + J22
u
u

u
u

u
u
( a J11 + J12 ) = J11 a + J11 a + J12 + J12

u
u a
u
u a
u
J11 a + J12 + J11 ( a a + a ) + J12 ( a + )

u
2u
2u
2 2u
2 2u
J11 a + J12 + J11 a2 + J11 J12 a + J12 J11 a + J12 2
u
u

u
u

u
u
( a J11 + J12 ) = J11 a + J11 a + J12 + J12

u
u a
u
u a
u
J11 a + J12 + J11 ( a a + a ) + J12 ( a + )
2
2
2

u
u
u
2u
u
J11 a + J12 + J11 J21 a2 + J11 J22 a + J12 J21 a + J12 J22 2
u
u

u
u

u
u
( a J21 + J22 ) = J21 a + J21 a + J22 + J22

u
u a
u
u a
u
J21 a + J22 + J21 ( a a + a ) + J22 ( a + )
2
2
2

u
u
u
u
2u
J21 a + J22 + J21 J11 a2 + J21 J12 a + J22 J11 a + J22 J12 2
u
u

u
u

u
u
( a J21 + J22 ) = J21 a + J21 a + J22 + J22

u
u a
u
u a
u
J21 a + J22 + J21 ( a a + a ) + J22 ( a + )
2
2
2
2

u
u
u
2 u
2 u
J21 a + J22 + J21 a2 + J21 J22 a + J22 J21 a + J22 2

Thus on each triangle


U () = T U (x),

T1

T =

T2
T3

mij = T T m
ij T
srrij = T T srr
ij T ,

srzij = T T srz
ij T ,

srij = T T sr
ij T ,

6.4

szzij = T T szz
ij T

szij = T T sz
ij T

Find Derivatives

Given a function f , we find derivatives in real space

f
a

and

f
f
=
a
a
13

using the fact

(35)

Multipying it with base function Ni on both side of the above equaiton and integrating it over each
triangle element
Z Z
Z Z
f
f
Ni d =
Ni d
a
a
i.e.,
Z Z
Z Z
f
f
Ni J dad =
Ni J dad,
a
a
in flux coordinate, we have
Z Z X
Z Z X 
Nj
f
Nj Ni J Jdd =
fj
Ni J Jdd
(36)
a
a
j
j
j
where
f=

f j Nj ,

The derivative

f
a

X
f
=
a
j

f
a

Nj
j

is found by solving the linear system


 
X
X
f
Jj mij
=
Jj srij fj
a j
j
j

with the use of mij and srij matrices. The other way to compute the rhs vector of eq (36) makes use of
operator Pijk
RR 1P
RRP
P
Nj
j fj a Ni J Jdd = Pj fj P J R k
R E1jk k Ni J dad
(37)
= j fj k k
J Ejk Ni J Jdad
P P
= j k fj k Pijk J
In the same way, we can find its derivative by solving the linear system
Z Z X
Z Z X 
Nj
f
Nj Ni J Jdd =
fj
Ni J Jdd
j

j
j

i.e.,
X

Jj mij

or compute the rhs vetor using Pijk


RRP
Nj
j fj Ni J Jdd

=
j

(38)

Jj szij fj

RR 1P
P
= j fj
E a N J dad
P
P J R kR 1jk k i
= j f j k ak
J Ejk Ni J Jda
P P
= j k fj ak Pijk J

(39)

The computing of (37) and (39) are implemented in subroutine f indd xdadxdt. If you just need (37) call
subroutine f indd xda; If you just need (39) call subroutine f indd xdadxdt.

6.5

Boundary Conditon

The solution domain is bounded by two magnetic flux surfaces. One is the innermost flux surface a = a0
and the other one is the outermost flux surface a = a1. Dirichlet boundary condition and Neumann
boundary condition can be specified on either one of these two surfaces. We use a set of array to store
the index of the grid points which sit on boudnaries.
The Dirichlet boundary condition can be imposed by zeroing the row of the matrix with indices on
the boundaries and then set their diagonal entries to 1. The rhs vector will be changed acoordingly by
setting those elements to the real solution. Here is a simple example. Assumping there are 5 grid points
and they are numbered as 1, 2, 3, 4, 5. The linear system is given as

a1 a2 a3 a4 a5
x1
b1
b1 b2 b3 b4 b5 x2 b2

c1 c2 c3 c4 c5 x3 = b3

d1 d2 d3 d4 d5 x4 b4
e1 e2 e3 e4 e5
x5
b5
14

Suppose the boundary points are at 2 and 5, and the Dirichlet bounnday condition is given on these
points, i.e.
x2 = v1
x5 = v2
Then the matrix and rhs are modified in

a1 a2

c1 c2

d1 d2

the following way

a3 a4 a5
x1
x2

c3 c4 c5
x3

d3 d4 d5 x4
1
x5

b1
v2
b3
v4
b5

By solving the above linear system, we immediately get x2 = v1 and x5 = v2. This is unsymmetrical
zeroing. We can do symmetric zeroing to keep the modified matrix symmetrical so that better linear
solver can be applied. It can be explained by continuing zero the corresponding columns, i.e., column 2
and 5, of the row-zeroing modified matrix

b1 a2v1 a5v2
x1
a1 a2 a2 a3 a4 a5 a5

x2 v2

c1 c2 c2 c3 c4 c5 c5 x3 = b3 c2v1 c5v2

d1 d2 d2 d3 d4 d5 d5 x4 v4 d2v1 d5v2
b5
x5
1
i.e.,

a1

c1

d1

a3

a4

c3
d3

c4
d4

x1
x2
x3
x4
x5

b1 a2v1 a5v2
v2
b3 c2v1 c5v2
v4 d2v1 d5v2
b5

Note that the rhs vector b was modified acoordingly.


If Neumann boundary condition is imposed, the correction is much more complicated. We need to start
from the variational form
Z Z
Z
Z Z
Ni gs J dad = J gs Ni n dl
(J Ni ) gs dad
Suppose on the boundary we have
n = (a, )
n is the boundary normal directon pointing away from the solution domain. In the current version of
GTS, this directon is equivalent to a. Thus,
a = (a, )
Using the previous expression for , it becomes
a (

a +
) = (a, )
a

i.e.,
g aa

+ g a
= (a, )
a

Therefore
R
JR gs Ni n dl
a
= R J gs Ni (g aa
a + g
)dl
R
R
aa
aa
aa
a
a
= e1 J gs Ni (g a + g a
)dl + e2 J gs Ni (g
a + g
)dl + e3 J gs Ni (g
a + g
)dl
RI1 + I2 + I3
= J gs Ni (a, )dl
15

where I1 , I2 , and I3 are the linear integral along one of the 3 edges of each triangle, respectively. For
simplicity, we use the C 0 linear elements Ni .
(1) if the boundary falls on edge 1,
N1 = 1
N2 =
N3 =P0
a = P i ai Ni = a1 (1 ) + a2 = a1 + a
21
= i i Ni = 1 (1 ) + 2 = 1 + 21
2
2
2
dl2 = da2 + d2 = a
221 d 2 + 21
d 2 = (
a221 + 21
)d 2 = l21
d 2
The following terms are used to modify the right hand side
R1
rhs(v1 ) = rhs(v1 ) 0 N1 (, 0)J gs l21 d
R1
= rhs(v1 ) 0 (1 )J gs l21 d
rhs(v1 ) 12 J gs l21
R1
rhs(v2 ) = rhs(v2 ) 0 N2 (, 0)J gs l21 d
R1
= rhs(v2 ) 0 ()J gs l21 d
rhs(v2 ) 21 J gs l21
R1
rhs(v3 ) = rhs(v3 ) 0 N3 (, 0)J gs l21 d
R1
= rhs(v3 ) 0 (0)J gs l21 d
= rhs(v3 )
(2) if the boundary falls on edge 2,
N1 = 1 = 0
N1 = 1
N2 =P
a = P i ai Ni = a2 (1 ) + a3 = a2 + a
32
= i i Ni = 2 (1 ) + 3 = 2 + 32
2
2
2
d 2
)d 2 = l32
d 2 = (
a232 + 32
dl2 = da2 + d2 = a
232 d 2 + 32
The following terms are used to modify the right hand side
R1
rhs(v1 ) = rhs(v1 ) 0 N1 (, )J gs l32 d
R1
= rhs(v1 ) 0 (0)J gs l32 d
= rhs(v1 )
R1
rhs(v2 ) = rhs(v2 ) 0 N2 (, )J gs l32 d
R1
= rhs(v2 ) 0 (1 )J gs l32 d
rhs(v2 ) 12 J gs l32
R1
rhs(v3 ) = rhs(v3 ) 0 N3 (, )J gs l32 d
R1
= rhs(v3 ) 0 ()J gs l32 d
rhs(v3 ) 12 J gs l32
(3) if the boundary falls on edge 3,
N1 = 1
N2 = 0
P
N3 =Pa = i ai Ni = a1 (1 ) + a3 = a1 + a
13
= i i Ni = 1 (1 ) + 3 = 1 + 31
2
2
2
dl2 = da2 + d2 = a
213 d 2 + 13
d 2 = (
a213 + 13
)d 2 = l13
d 2

16

The following terms are used to modify the right hand side
R1
rhs(v1 ) = rhs(v1 ) 0 N1 (0, )J gs (l13 )d
R1
= rhs(v1 ) 0 (1 )J gs (l13 )d
rhs(v1 ) 12 J gs (l13 )
R1
rhs(v2 ) = rhs(v2 ) 0 N2 (0, )J gs (l13 )d
R1
= rhs(v2 ) 0 (0)J gs (l13 )d
= rhs(v2 )
R1
rhs(v3 ) = rhs(v3 ) 0 N3 (0, )J gs (l13 )d
R1
= rhs(v3 ) 0 ()J gs (l13 )d
rhs(v3 ) 12 J gs (l13 )
These are implemented in subroutine neumbcf ix.

6.6

Numerical Difficulty: periodic domain

The numerical difficulty comes from the 2 peroidicity in direction when numerical integration is
performed. The value of 2 must be subtracted from whenever the elements has one or two nodes
crossing the = 0, 2 line. This is implemented in subroutine f ixtheta.

17

Bibliography
[1] W. X. Wang et al, Gyro-kinetic silumation of global turbulent transport properties in tokamak experiments, Physcs of Plasma, vol 13, 2006
[2] W. D. Dhaeseleer, Flux coordinates and magnetic field structure, 1991.
[3] G. E. Karniadakis and S. J. Sherwin, Spectral/hp Element Methods for CFD, 1999.

18

Flux Coordiante Basics

We review some important facts here about curved coordiante system that will be needed in the the
derivation of pde equations and in the implementation of finite elements in the flux coordiantes. We list
them here so we will not mention them when we use these facts.
As a start, we introduce the coordinate surface ui = const. ui is perpendicular to the ith surface.
i = 1, 2, 3.
The coordinate curve ui is defined by the intersection of 2 surfaces uj = const, uk = const. On this
curve, duj = duk = 0, j 6= k, j 6= i, k 6= i.
R = R(u1 , u2 , u3 ),
ei =

ei = ui ,

ei =

R
ei ei = ji
ui

1
ej ek
= ej ek
ei ej ek
J

ej ek
R
=
= J ej ek
ui
ei ej ek
X
X
Di = D e i , D j = D e j , D =
Di e i =
D j ej
ei =

du are contravariants. is a covariant vector:


=

i
ui =
e
i
u
ui

1). gradient
= ui

i
=
e
ui
ui

2). divergence
D =
3). laplacian





1
1
1
1
J Di =
J D ei =
J Dj ej ei =
J Dj g ji
i
i
i
i
J u
J u
J u
J u


1
1
1
(J D) =
J D ei =
D =
J ui
J ui
J ui

D
J j ej ei
u

1
=
J ui

4). Jacobian

J =

u1 u2
u3

5). metrics
g aa = a a,

g a = a ,

g = ,

6). the differential arc length


dl(along uj ) dl(i) = kdRk =
while

dR(i) dR(i)

R 1 R 2 R 3
du + 2 du + 3 du = ei dui = J kuj uj kdui
u1
u
u
7). the differential area element
dR(i) =

dS(in ui const)

dS(i)
= kdR(j) R(k)k
R
j
k
= k uRj u
k kdu du
j
k
= kej ek kdu du
= J kei kduj duk
= J kui kduj duk
19

D
J j g ji
u

Numerical integration

The basic problem considered by numerical integration is to compute a definite integral


Z
u()d

(40)

There are many methods of approximating the integral with arbitrary precision. A method which yields
a small error for a small number of evaluations is usually considered superior. Gauss Quadrature is one
of such algorithms.
The integrand is evaluated at a finite set of points called integration points and a weighted sum of
these values is used to approximate the integral. The integration points and weights depend on the
specific method used and the accuracy required from the approximation.
In Gauss quadrature technique, the integrand is represented as a Lagrange polynomial using Q points
i
Q1
X
u() =
u(i )hi () + (u)
i=0

If we substitute it into the integral (40), we obtain a representation of the integral as a summation
Z
where

u()d =

Q1
X

wi u(i ) + R(u)

i=0

R1
wi = 1 hi ()d
R1
R(u) = 1 (u)d

Since u() is represented by a polynomial of order Q 1, we would expect the above relation to be exact
if u() is a polynomial of order Q 1 or less. This would be true if the points are equispaced in the
interval. There is, however, a better choice of abscissae which permits exact integration of polynomials
of higher order than Q 1.
If we ensure that the quadrature formula is exact for polynomials of order k at least, then the formula
is also exact for the next (k 1) order of polynomials.

20

You might also like