Periodic Hill

This tutorial will describe how to run a case from scratch, the procedure is illustrated throuugh a relatively simple example involving incompressible laminar flow in a two-dimensional periodic hill domain. The implementation is loosely based on the case presented by Mellen et al. [Mellen2000]. A thorough review for this case can be found in the ERCOFTAC knowledge base wiki.

Before You Begin

This tutorial assumes that you have installed NekRS in your home directory and have setup your PATH. You can either follow the example with the files in the fdlf directory within examples directory of nekRS, or create it within a directory of your choice.

If you have chosen to create the example as following along, you will need to compile the Nek5000 tool genbox for the initial mesh generation. Please follow the instructions in the Building the Nek5000 Tool Scripts section.

Mesh generation

This tutorial will use a simple box mesh generated by genbox, save the following to a new file hillp.box:

-3                     spatial dimension (will create box.re2)
1                      number of fields
#
#    comments: two dimensional periodic hill
#
#========================================================
#
Box                                       hillp
-22 8 -1                                  Nelx  Nely Nelz
0.0 9.0 1.                                x0 x1 ratio
0.0 0.1 0.25 0.5 1.5 2.5 2.75 2.9 3.0     y0 y1 ... y8
0.0 1.0 1.0                               z0 z1 ratio
P  ,P  ,W  ,W  ,P  ,P                     BC's:  (cbx0, cbx1, cby0, cby1, cbz0, cbz1)

For this mesh 22 uniform elements are specified in the stream-wise (x) direction. 8 non-uniform elements are specified in the span-wise (y) direction in order to resolve the boundary layers, and a single element in the z-direction. The boundary conditions are periodic in the x-direction and no-slip in the y. Additional details on generating meshes using genbox can be found here.

Now we create the mesh by running:

$ genbox

On input provide the input file name (e.g. hillp.box). The tool will produce a binary mesh and boundary data file box.re2 which should be renamed to hillp.re2.

User Defined Functions file (.udf)

The UDF file allows the user to interact with the solver, to get started create a file hillp.udf in the current directory.

Modify mesh

For a periodic hill, we will need to modify the geometry. Let \({\bf x} := (x,y)\) denote the old geometry, and \({\bf x}' := (x',y')\) denote the new geometry. For a domain with \(y\in [0,3]\) and \(x\in [0,9]\) the following function will map the straight pipe geometry to a periodic hill:

\[y'(x,y) = y + C(3-y)\Big\{1+\tanh\big[B(|x-A|-B)\big]\Big\} .\]

where \(A=4.5, B=3.5, C=1/6\). We have chosen these constants so that the height of the hill (our reference length), \(h=1\). Note that, as \(y \longrightarrow 3\), the perturbation, goes to zero. So that near \(y = 3\), the mesh recovers its original form.

In NekRS we can specify this through UDF_Setup in the .udf file:

for(int i{0}; i < mesh -> Nlocal; ++i) {
    const dfloat argx{B * (std::abs(x[i] - A) - B)};
    const dfloat A1{C * (1. + std::tanh(argx))};
    y[i] = y[i] + A1 * (3. - y[i]);
  }

By modifying the mesh in UDF_Setup, the modification is applied to the GLL points directly. This allows the mesh to conform to the specified profile to \(N^{th}\)-order accuracy. The deformed mesh with the GLL points is shown in Fig. 7 below.

per_mesh

Fig. 7 Modified box mesh graded

Initial & boundary conditions

The next step is to specify the initial conditions. This can be done by adding the following to UDF_Setup:

  for(int n{0}; n < mesh -> Nlocal; ++n) {
    U[n + 0 * nrs->fieldOffset] = 1.0;
    U[n + 1 * nrs->fieldOffset] = 0.0;
    U[n + 2 * nrs->fieldOffset] = 0.0;
  }

For walls and periodic boundaries, nothing needs to be specified in the user file, so scalarDirichletConditions and scalarNeumannConditions do not need to be defined.

Control parameters

The control parameters for any case are given in the .par file. For this case, using any text editor, create a new file called hillp.par and type in the following:

[GENERAL]
polynomialOrder = 7
stopAt = endTime
endTime  = 200
variableDT = yes
dt = targetCFL = 0.4 + initial=1e-1
checkpointControl = steps
checkpointInterval = 20
constFlowRate = meanVelocity=1.0 + direction=X

[PROBLEMTYPE]
equation = navierstokes

[VELOCITY]
residualTol = 1e-8
density = 1
viscosity = -100

We have set the calculation to stop at the physical time of \(T=200\) (endTime=200) which is roughly 22 flow-thru time units (based on the bulk velocity \(u_b\) and length of periodic pitch, \(L=9\)). The step size is allowed to adjust to match the target CFL, with an initial size of 1e-1.

To drive the flow, a forced flow rate in the x-direction is applied such that bulk velocity \(u_b=1\). This is accomplished with the highlighted line.

Warning

The forced flow rate options are only intended for use with periodic boundaries!

In choosing viscosity = -100 we are actually setting the Reynolds number. This assumes that \(\rho \times u_b \times h = 1\) where \(u_b\) denotes the bulk velocity and \(h\) the hill height.

Additional details on the names of keys in the .par file can be found here.

Compilation and running

With the hillp.udf file created, you should now be all set to compile and run your case! As a final check, you should have the following files:

If for some reason you encountered an insurmountable error and were unable to generate any of the required files, you may use the provided links to download them. After confirming that you have all three, you are now ready to run:

$ nrsbmpi hillp 4

This will run the Just-in-Time (JIT) compiler and then launch an MPI job using 4 ranks. The output will be redirected to logfile.

Post-processing the results

Once execution is completed your directory should now contain multiple checkpoint files that look like this:

hillp.f00001
hillp.f00002
...

The preferred mode for data visualization and analysis with Nek5000 is to use Visit/Paraview. If Paraview is in your PATH you can run:

$ paraview hillp.nek5000

n the viewing window one can visualize the flow-field as depicted in Fig. 8.

per_flow

Fig. 8 Visualization of the steady-state flow field. Vectors represent velocity. Colors represent velocity magnitude. Note, velocity vectors are equal size and not scaled by magnitude.