Twenty Two
Twenty Two
Contents
1 Introduction 3
2 Quick Start 4
2.1 Download and Initial Build . . . . . . ... . ... .4
4 Simulation Capabilities 14
2 Chapter 0 — CONTENTS
5 Nek5000 Variables 26
6 Nek5000 Usage 32
7 Timestepping 38
Chapter 1. Introduction
cd nek5_svn/trunk/tools
maketools all
which will put the tools genbox, genmap, n2to3, postx, prex, and
pretex in the top-level /bin directory (and will create /bin if it does
not exist). It may be necessary to edit the maketools file to change
the compilers (eg, to pgf77/pgcc or ifort/icc). However, the default
1
gfortran/gcc is generally fine.
In addition to the compiled tools, there are numerous scripts in
nek5_svn/trunk/tools/scripts
cd
mkdir eddy
cd eddy cp ~/
nek5_svn/examples/eddy/* . cp ~/
nek5_svn/trunk/nek/makenek .
Modify makenek. If you do not have mpi installed on your system, edit makenek, uncomment
the IFMPI="false" flag, and change the Fortran and C compilers
according to what is available on your machine. (Most any Fortran
compiler save g77 or g95 will work.) If you have mpi installed on your
system or have made the prescribed changes to makenek, the eddy
problem can be compiled as follows
which, if all works properly, will generate the executable nek5000 using
eddy uv.usr to provide user-supplied initial conditions and analysis.
Note that if you encountered a problem during a prior attempt to build
the code you should type
makenek clean;
makenek eddy uv
nekpbs eddy uv 4
or equivalently
where, because of the nekb script, logfile is linked to the .log file
of the given simulation. If the run has completed, the above grep
command should yield lines like
postx
To see the vorticity at the final time, load the last output file,
eddy uv.fld12, by clicking/typing the following in the postx win dow:
Plotting the error: For this case, the error has been written to eddy uv.fld11 by making a call
to outpost() in the userchk() routine in eddy uv.usr.
The error in the velocity components is stored in the velocity-field
locations and can be viewed with postx through the following
sequence:
click type comment
1. SET TIME 2. 11 load fld11
SET QUANTITY
3.VELOCITY
4. MAGNITUDE
5. PLOT
which will copy the requisite eddy uv case files to eddy new. Next,
edit SIZE and change the two lines defining lx1 and lxd from
to
makenek eddy_new
nekb eddy_new
will show a much smaller error (ÿ 10ÿ9 ) than the lx1=8 case.
Note that one normally would not use a restart file for the eddy
prob lem, which is really designed as a convergence study (see
Section ??). The purpose here, however, was two-fold, namely,
to illustrate a change of order and its impact on the error, and to
demonstrate the frequently-used restart procedure.
Machine Translated by Google
Each simulation is defined by three files, the .rea file, the .usr
file, and the SIZE file. In addition, there is a derived .map file
that is generated from the .rea file by running genmap. Suppose
you are doing a calculation called “shear.” The key files
defining the prob lem would be shear.rea, shear.map, and
shear.usr. SIZE controls (at compile time) the polynomial
degree used in the simulation, as well as the space dimension d = 2 or 3.
This chapter provides an introduction to the basic files required
to set up a Nek5000 simulation.
lx2 = lx1 or lx1-2. This determines the formulation for the Navier
Stokes solver (ie, the choice between the lPN –lPN or lPN
– lPNÿ2 methods) and the approximation order for the
pressure, lx2-1.
ÿu=0 , (4.2)
It should be noted that Nek5000 can solve not only the above fully
coupled system, but also various subsets of these equations. Namely,
Nek5000 recognizes the following subsets.
2. Fluid flow and heat transfer only; ie, the momentum, conti
nuity and energy equations only.
8. Transient heat transfer; ie, the energy equation only with prescribed
steady or unsteady velocity.
4.2 Geometry 17
ÿ(ÿtu
' + u · ÿu ' + u ' ÿu) = ÿÿp ' + µÿ2u ÿ ÿ·u ' = 0,(4.5)
i i i i i, i
4.2 Geometry
4.2.1 Conventions and Restrictions
twenty two
Chapter 4 — Simulation Capabilities
4.3.2 Temperature
The three types of boundary conditions applicable to the temper ature are:
essential (Dirichlet) boundary condition in which the
temperature is specified; natural (Neumann) boundary condition in
which the heat flux is specified; and mixed (Robin) boundary condition in
which the heat flux is dependent on the temperature on the
For segments that constitute the boundary ÿÿ boundary. ' ÿ ÿÿ '
f s
(refer to Fig. 2.1), one of the above three types of boundary conditions
must be assigned to the temperature.
The boundary conditions for the passive scalar fields are analogous
to those used for the temperature field. Thus, the temperature
boundary condition menu will reappear for each passive scalar field
so that the user can specify an independent set of boundary conditions
for each passive scalar field. The terminology and restrictions
of the temperature equations are retained for the passive scalars,
so that it is the responsibility of the user to convert the notation
of the passive scalar parameters to their thermal analogues. For
example, in the context of mass transfer, the user should recognize
that the values specified for temperature and heat flux will represent
concentration and mass flux, respectively.
twenty four
Chapter 4 — Simulation Capabilities
y and z.
• f(t), the body force per unit mass term can vary with time,
space, temperature and passive scalars.
• qvol, the volumetric heat generation, can vary with time, space
and temperature.
• hc, the convection heat transfer coefficient, can vary with time,
space and temperature.
This chapter identifies data layout within Nek5000 along with key
variables that are typically interrogated for analysis.
Ef E
ÿ e, ÿ = ÿt := [ ÿ e, (5.1)
ÿf := [
e=1 e=1
e
where u ijk are the basis coefficients (typically, the unknown
velocity or temperature values); hi(r), hj (s), hk(t) are the Nth-order
1-D Lagrange polynomials based on the GLL1 points; and ˆ r := ( r,
ÿ1, 1]3 . are the coordinates in the canonical reference element,s, t)
ÿ := [ (There should be no confusion with t, the time variable, as
the distinction will be clear from context.) Here , we also assume
that x := (x, y, z) ÿ ÿ e is given by the isoparametric mapping,
N N N
e
x|ÿe = x = X XX k=0 j=0 i=0
e
x ijkhi(r) hj (s) hk(t). (5.3)
ˆ
That is, ÿe is the image of ÿ under the polynomial mapping (5.3).
We further assume that the mapping is invertible, which implies
that angles at the corners in ÿe are bounded away from 0 and 180
degrees. Because of the polynomial map (5.3), it is also important
that the edges of ÿe be smooth. Corners can be accommodated if
they coincide with element vertices.
include 'SIZE'
include 'TOTAL'
real vx(lx1,ly1,lz1,lelt)
call my_routine(u(1,1,1,e),...)
In addition, one can access the contents of, say, vx via the following
loop structure:
include 'SIZE'
include 'TOTAL'
:
:
Machine Translated by Google
n = nx1*ny1*nz1*nelv
sum=0
do i=1,n
sum = sum+vx(i,1,1,1) enddo
after then endo statement in the preceding code segment. In this case,
the entire operation could also be written as
n = nx1*ny1*nz1*nelv sum
= glsum(vx,n) ! global sum
Rÿ u dV
u¯ := (5.4)
Rÿ 1 dV
would be computed as
n = nx1*ny1*nz1*nelv ubar
= glsc2(bm1,vx,n)/volvm1
Here, the 'm1' suffix refers to Mesh 1, which is where velocity and
temperature are represented. Because Nek5000 supports a discon tinous
pressure of order N ÿ 2 (for the lPN ÿ lPNÿ2 formulation), there is also a
set of variables represented on Mesh 2. Specifically, the pressure has a
declaration of the form
Machine Translated by Google
5.2 Variables 29
real pr(lx2,ly2,lz2,lelv)
xm1(lx1,ly1,lz1,lelv) ! x on mesh 1
ym1(lx1,ly1,lz1,lelv) ! etc. zm1(lx1,ly1,lz1,lelv)
xm2(lx2,ly2,lz2,lelv) ! x on mesh 2
ym2(lx2,ly2,lz2,lelv) ! etc. zm2(lx2,ly2,lz2,lelv)
bm1(lx1,ly1,lz1,lelv) ! B on mesh 1
bm2(lx2,ly2,lz2,lelv) ! B on mesh 2
5.2 Variables
This section provides a listing of several of the key variables in
Nek5000. We begin with the principal dependent variables
followed by independent variables, although it worth remarking
that geometry is a dependent variable in the case of free-surface
and other moving-mesh simulations .
Velocity: vx(lx1,ly1,lz1,lelv), vy(lx1,ly1,lz1,lelv), vz(lx1,ly1,lz1,lelv)
subroutine my_flux_calc
common /mystuff/ tx(lx1,ly1,lz1,lelt) $ ,
ty(lx1,ly1,lz1,lelt) $ , tz(lx1,ly1,lz1,lelt)
integer e,f
nface = 2*ndim
a = 0.
s = 0.
call gradm1(tx,ty,tz,t) ! grad T do e=1,nelv
do f=1,nface if (cbc(f,e,2).eq.'t ') then call
facind(i0,i1 ,j0,j1,k0,k1,nx1,ny1,nz1,f) l=0
s = s + (unx(l,1,f,e)*tx(i,j,k,e) +
$ uny(l,1,f,e)*ty(i,j,k,e) + unz
$ (l,1,f,e)*tz(i,j,k,e))*area(l,1,f,e) a = a + area(l,1,f,e)
enddo
enddo
enddo
endif
Machine Translated by Google
5.2 Variables 31
enddo
enddo
a=glsum(a,1) !Sum across processors
s=glsum(s,1)
abar = s/a if
(nid.eq.0) write(6,1) istep,time,s,a,abar 1 format(i9,1p4e13
.5,'net flux')
return
end
Machine Translated by Google
c-----------------------------------------
c IC EXAMPLE 1.
subroutine useric(ix,iy,iz,eg) include
'SIZE'
include 'NEKUSE'
include 'TOTAL'
integer e,eg
ux=0
uy=0
uz=cos(.5*pi*x)*cos(.5*pi*y) temp=0
return
end
c-----------------------------------------
Machine Translated by Google
c-----------------------------------------
c IC EXAMPLE 2.
subroutine useric(ix,iy,iz,eg) include
'SIZE'
include 'NEKUSE'
include 'TOTAL'
integer e,eg
uy=0
uz=cos(.5*pi*x)*cos(.5*pi*y) elseif
(ifield.eq.2) then ! Set temperature ic
temp=0
else
temp=0 ! Set ic for all other passive scalars
endif
return
end
c-----------------------------------------
Notice that all passive scalars are set by defining temp. Different
passive scalar assigments are discriminated by the value of ifield,
which is set to 2 for temperature, 3 for the next passive scalar, etc.
(Precise usage of usic can be found via grep -i usic *.f in nek5 svn/
trunk/nek.)
Machine Translated by Google
c-----------------------------------------
c BC EXAMPLE 1.
subroutine userbc(ix,iy,iz,iside,eg) include 'SIZE'
include 'NEKUSE'
include 'TOTAL'
integer e,eg
ux=0
uy=0
uz=cos(.5*pi*x)*cos(.5*pi*y) temp=0
return
end
c-----------------------------------------
Machine Translated by Google
c-----------------------------------------
c BC EXAMPLE 2. Illustrating dereference of a previously
c computed BC.
subroutine userbc(ix,iy,iz,iside,eg) include 'SIZE'
include 'NEKUSE'
include 'TOTAL'
integer e,eg
uy=0
uz=u3(ix,iy,iz,e) elseif
(ifield.eq.2) then ! Set temperature bc
temp=0
else
temp=0 !Set bc for all other passive scalars
endif
return
end
c-----------------------------------------
The code snippet below shows a typical way to fill u3() on the
first call.
c-----------------------------------------
subroutine userchk
include 'SIZE'
include 'TOTAL'
n = nx1*ny1*nz1*nelv
x=xm1(i,1,1,1)
y=ym1(i,1,1,1)
u3(i,1,1,1)=cos(.5*pi*x)*cos(.5* pi*y)
enddo
endif
return
end
c-----------------------------------------
c-----------------------------------------
subroutine userchk
include 'SIZE'
include 'TOTAL'
n = nx1*ny1*nz1*nelv
eps = 0.1
omega = 5.0
amp = 1 + eps*sin(omega*time)
do
i=1,nx=xm1(i,1,1,1)
y=ym1(i,1,1,1)
u3(i,1,1,1)=cos(.5*pi*x)* cos(.5*pi*y)*amp enddo
return
end
c-----------------------------------------
c-----------------------------------------
c BC EXAMPLE 3. - time varying boundary condition subroutine
userbc(ix,iy,iz,iside,eg)
include 'SIZE'
include 'NEKUSE'
include 'TOTAL'
integer e,eg
Machine Translated by Google
eps = 0.1
omega = 5.0
amp = 1 + eps*sin(omega*time)
ux=0
uy=0
uz=amp*cos(.5*pi*x)*cos(.5*pi*y)
temp=0
return
end
c-----------------------------------------
Machine Translated by Google
Chapter 7. Timestepping
ÿu 1
+ u ÿu = ÿÿp + ÿ2u in ÿ, (7.1)
ÿt Re
ÿ u = 0 in ÿ,
ÿÿ 1
ÿ2ÿ + f, + c ÿÿ = ÿt in ÿ. (7.2)
Pe
nÿ1
ÿnÿÿ 1 1
= (ÿ2ÿn + ÿ2ÿn ÿ 1 ) (7.
ÿt 2 1P e
1 nÿ1
+ (23 c · ÿÿ| tnÿ1 ÿ 16 c · ÿÿ| tnÿ2 + 5 c · ÿÿ| tnÿ3 )+ (f n + f
12 2
Machine Translated by Google
3ÿ n ÿ 4ÿ nÿ1 + phinÿ2 1
= ÿ c · ÿÿ| ) + f n (7.4) .
2ÿt Pe ÿ2ÿ n ÿ (2 c ÿÿ| tnÿ1 tnÿ2
k k
n
X ÿqÿ nÿq = ÿ X ÿp c ÿÿ| tnÿp
+I , (7.5)
q=0 p=1
coefficients associated
accounts
withfor
the
allapproxi
the implicit
mationcontributions.
of a derivative
Theatterms
time twhere
n based
I n on
ÿq are
known
the values
differentiation
at t nÿq
,
q = 0, . . . k., The terms ÿp are interpolation coefficients required to
approximate a function at time t n based on known values at
Machine Translated by Google
40 Chapter 7 — Timestepping
t nÿp , p = 1, . . . , k. These coefficients are readily determined from any standard approach to polynomial
interpolation at knot points tnÿj ] (j = 0 or 1). A convenient code is the general-purpose [t routine for interpolation/
nÿk
round-off, errors,
..., differentiation
it is probablyweights,
better for
fdlong
weights,
time de
integrations
veloped bytoBengt
use just
Fornberg
the change
[?]. Note
in time
that,
values,
because
ÿ nÿq
of potential
rather than
the time values themselves, to determine the interpolation/differentiation coefficients. Of course, the values of ÿ nÿq
should be computed by summing ÿt nÿj , q, rather than taking the difference , j = 0, . . . t nÿq
:= t nÿq ÿt n
,
ÿt n .
ÿÿ
+ c ÿÿ = 0, ÿt (7.6)
dÿ
= ÿCÿ, dt (7.7)
ÿt
n nÿ1
ÿ =ÿ (23Cÿnÿ1 ÿ 16Cÿnÿ2 + 5Cÿnÿ3 ), (7.8)
ÿ
12
where we have assumed that the timestep size, ÿt, is constant and that the
velocity field c and, hence, C, is time invariant. The sta bility region for AB3
is found by considering the model problem ut = ÿu, inserting this into (7.8)
(ÿ ÿ u, ÿC ÿ ÿ), and solving for the locus of points in the complex (ÿÿt)-plane
such that the magni tude of u is unchanging (see, eg, [?] and Appendix A.)
Figure 7.1
Machine Translated by Google
1 1 1
0 0 0
ÿ1 ÿ1 ÿ1
ÿ1.5 ÿ1 ÿ0.5 0 0.5 ÿ1.5 ÿ1 ÿ0.5 0 0.5 ÿ1.5 ÿ1 ÿ0.5 0 0.5
shows the stability region for AB3 and for BDF3/EXT3. We see
that both schemes enclose a substantial portion of the imaginary
axis near the origin. It is also possible to improve the stability of
BDF2/EXT2 by using a three-term treatment of the second-order
extrapolation. For example, for fixed ÿt, the choice ÿ1 = 8/3,
ÿ2 = ÿ7/3, and ÿ3 = 2/3, will provide a stability region that is
similar to AB3, as seen in the right panel of Fig. 7.1.
The implications of Fig. 7.1 are that, for stability, one must choose
ÿt ÿ zcrit/ max |ÿ|, where zcrit = .7236 for AB3 and .6339 for
BDF3/EXT3. The value of max |ÿ| depends on the spatial dis
cretization and on the computational mesh size. For classical
cen tered finite differences (FD), one has
|c|
max |ÿ| = ÿx ,
|c|
max |ÿ| = ÿ ÿx
42 Chapter 7 — Timestepping
|
c| max |ÿ| = S ,
ÿxmin
Dÿ = 1
ÿ2ÿ + f, (7.9)
Dt Pe
where
Dÿ ÿÿ
:= + c · ÿÿ ÿt (7.10)
Dt
3ÿ n ÿ 4ÿ˜nÿ1 + ÿ˜nÿ2 = 1 n
ÿ2ÿn + f . (7.11)
2ÿt Pe
Note that the domain of ÿ˜nÿq is coincident with ÿ(t n ), whereas the
domain of ÿ(., tnÿq ) must be coincident with ÿ(t nÿq ). This is a subtle
point, but the implications are that spatial discretization of (7.11) can
proceed with the usual weighted residual formalism, that is, by
multiplying (7.11) by a test function v, integrating over ÿ, and restricting
the search (trial) and test spaces to finite dimensional subspaces of H1
(ÿ). 0
Machine Translated by Google
nÿ2
ÿ˜
j
Xnÿ2 j
nÿ1
ÿ˜
j
n
Xnÿ1 j ÿj
_
Xn := xj j
A+ Bÿ = Bgn , (7.13)
Pe 2ÿt
where A is the stiffness matrix, B is the mass matrix, and the right
hand side
n n
4 nÿ1 1 nÿ2
g := B f ÿ˜ + 2ÿt
ÿ
, (7.14)
ÿ˜ 2ÿt
accounts for the data and the values of ÿ at the feet of the charac
teristics.
nÿq
where X j is the foot of the characteristic emanating from xj , as
illustrated in Fig. 7.2. The standard semi-Lagrangian formulation,
suggested by Pironneau and followed by others, is,
Machine Translated by Google
44 Chapter 7 — Timestepping
Here, ÿÿc is defined as the subset of the boundary ÿÿ where c·n <
0, that is, the portion of ÿÿ having incoming velocity characteristics.
(Note that, in practice, one can assign ÿ˜(x, t) = ÿ(x, tnÿq ) on ÿÿc.
PF, verify.)
46 Chapter 7 — Timestepping
ÿÿq
+ c ÿÿ ÿsq = 0, s ÿ [t nÿq , tnÿq+1] (7.16)
k+1
With ÿ := 0, the final result is
k
1
ÿ ÿqÿ˜nÿq , (t n ) = X (7.17)
q=1
Again, the values u˜ nÿq represent the field u at the foot of the
charac teristics. These may be computed using the usual semi-
Lagrangian formulation involving off-grid interpolation, or by the
OIF approach, in which one solves the convective subproblems
where, ÿÿc is defined as the subset of the boundary ÿÿ where u·n < 0.
Note that there should be no confusion in (7.20) between the con vected
field, u˜, and the convecting field, u, which is the solution to (7.19). In
solving (7.20), one treats u˜ as a passive advected vec tor field. Values of
nÿk
u on the interval [t , tn ] are computed by
nÿk nÿk+1 u nÿ1 u
interpolating from the known fields u , ,..., , which
guarantees a divergence-free convecting field in (7.20). Unlike the
convection-diffusion problem, however, one does not have access to , t].
n u, so u is effectively extrapolated on (t nÿ1 One has the option of which
n
iterating between (7.20) and (7.19) to get an estimate of u can ,
then be employed in the interpolation step required when solving (7.20)
on a second (third, etc.) pass. Formally , this should not be required, as
k
the extrapolation-based scheme is O(ÿt However, it may be of interest
) accurate.
in
particularly challenging applica tions. If properly coded, (eg, by relying on
general interpolation routines such as Fornberg's), this Iterative approach
can be included as an option in the OIFS implementation from the outset
with little overhead.
On the other hand, the OIFS formulation does retain a steady state error
that is influenced by ÿt. This is evident from (7.11). Under steady state
ÿ terms= that
nÿ1
conditions, we again have ÿ n but these are not =the . . .,are
to required
balance .
The lefthand side , ÿ˜nÿ1 , and ÿ˜nÿ2 that are of (7.11) inolves weighted
should be no expectation that the lefthand sidedifferences
should by ÿt.
of In
vanish, ÿnfact,
divided
even there
as ÿt
ÿÿ 0, because the lefthand side represents the variation of ÿ as one travels
along the charac teristic. This material derivative will generally be nonzero
and the temporal finite difference scheme will retain an O(ÿt) dependence
even under steady- state conditions. The characteristics-based OIFS
scheme amounts to mixing spatial and temporal discretizations and
Machine Translated by Google
48 Chapter 7 — Timestepping
du
= ÿu.dt
1 k1 k2
ÿt
X ÿqu nÿq = ÿX ÿpu
nÿp . (7.21)
q=0 p=1
u n = (z) nu 0 , (7.22)
Pk1ÿÿt
ÿiqÿ
= q=0 ÿqe . (7.23)
Pk2 ÿipÿ p=1 ÿpe
.
Evaluating (7.23) for 0 ÿ ÿ < 2ÿ yields the locus associated with the
neutral stability curve.
The matlab code below fills a vector ei with complex values on the unit
circle, then creates column vectors exp(q*ei) for q=1,0,-1,-2.
Linear combinations of these column vectors form the numerator
and denominator of (7.23). The matlab plot routine is used to plot the
locus of complex pairs.
Machine Translated by Google
ep = 1.e-13
hold off; plot (yaxis,'k-'); axis square; axis([-1.5 0.5 -1 1]); hold on;
plot (xaxis,'k-');
ab3 = (E*du)./(E*ab3); bdf3ex2 = plot (ab3 ,'r-');
(E*bdf3)./(E*ex2); print -deps ab3bdf3.eps plot (bdf3ex2,'k-');
hold off; plot (yaxis,'k-'); axis square; axis([-1.5 0.5 -1 1]); hold on;
plot (xaxis,'k-');
ab2 = (E*du)./(E*ab2); bdf2ex1 = plot (ab2 ,'r-');
(E*bdf2)./(E*ex1); print -deps ab2bdf2.eps plot (bdf2ex1,'k-');