Introduction to Compressible Navier Stokes Solver (CNS)

What's new

Prerequisites

Problem statement

We only briefly describe the non dimensional Euler equations in 2D

$$\frac{\partial}{\partial t}\vec{U}+\frac{\partial}{\partial x_j}\vec{F}^c_j(U)= 0,$$

where $\vec{U}$ are the conserved flow variables and $\vec{F}^c_x$ are the convective fluxes, i.e. $$\vec{U} = \begin{pmatrix} \rho \\ \rho u_i \\ \rho E \end{pmatrix} , \quad \textrm{and} \quad \vec{F}^c_i = \begin{pmatrix} \rho u_i\\ \rho u_i u_j + \frac{1}{\gamma \textit{Mach}^2}p \delta_{ij}\\ u_j (\rho E+p) \end{pmatrix}.$$

Note:

In our non dimensional equations, we introduce $\textit{Mach}$.

These Quick Start tutorials are aimed to show some of the main features of the compressible flow solver (Compressible Navier-Stokes (CNS)) in the BoSSS framework.

Note, that BoSSS uses a C# code based input data and interprets these in the REPL fashion.

This gives us more flexibility in the way how we can start a simulation.

We can have the traditional way of defining an input file, where we define all important parameters in C# code, or we can also use some predefined functions in the framework to generate our input data and manipulate them interactively in the BoSSSpad.

As an example, we will simulate the well known isentropic vortex for the Euler equations.

Isentropic vortex

Note

  1. This tutorial can be found in the source code repository as as IsentropicVortex.ipynb. One can directly load this into Jupyter to interactively work with the following code examples.
  2. In the following line, the reference to BoSSSpad.dll is required. You must either set #r "BoSSSpad.dll" to something which is appropirate for your computer (e.g. C:\Program Files (x86)\FDY\BoSSS\bin\Release\net5.0\BoSSSpad.dll if you installed the binary distribution), or, if you are working with the source code, you must compile BoSSSpad and put it side-by-side to this worksheet file (from the original location in the repository, you can use the scripts getbossspad.sh, resp. getbossspad.bat).

We start with creating a database and loading the namespace.

In BoSSS, every solver requires a so-called Control Object at startup. This is (an instance of) a special class, for each solver which contains all solver settings. For the CNS-solver used in this example, the respective control object class is CNSControl. The class ControlExamples provides some predefined control sets for different typical test cases, i.a. the isentropic vortex.

A control object can be passed in different ways:

For the isentropic vortex, you have to specify

Now, we have a set of input data stored in our variable c and we can have a look at different parameters directly via \code{BoSSSpad}.

How to define/change input data

In this section we will walk you through the most important parameters for running the test case.

We start with the grid and use the ability of BoSSS to generate simple grids with its own mesh generator.

Once we start the simulation, the control object c is parsed and the grid defined by the GridFunc is generated on the fly and stored in the database. Here, we defined a delegate function which returns a uniform cartesian grid.

First, we have to define a 1-D array, which spans from -10 to 10 and is divided into the number of cells, which we previously set to int noOfCellsPerDirection = 20.

The function Grid2D.Cartesian2DGrid generates a uniform 2-D grid out of this array by using it for x and y direction Additionally we specify periodic boundary conditions in x and y direction by setting

periodicX: true and periodicY: true.

The CNS solver is able to solve the Euler and the compressible Navier-Stokes equations. By setting

we only use the convective fluxes, i.e the Euler equations, and set it to

Note: here, Optimized means, that this is the HLLC flux should be used, but implemented in an performance-optimized version.

Further Settings:

As initial conditions, we choose the analytical solution, which can be found in various publications, e.g. Hu (2006).

The Mach number is set in the following:

Further, we have to define a simulation time, i.e

Finally, we need a time stepping scheme

...of order...

...to run the simulation.

These are all predefined input values, which were set by calling ControlExamples_Subsonic.IsentropicVortex(...).

Since we are in the interactive mode, we can change them directly.

For example, we can reduce the order of our timestepping scheme to 3,

because we only use DG order 2:

Or we can change the Mach number to

Run a simulation

We adjusted our input values and now we can run a simulation.

In the interactive mode, we can simply call Run() on the control object, which will execute the solver. This is not the typicall way of running a solver in BoSSS, and only appropriate for small computations which obly take seconds or minutes; it also does not allow parallel execution. For more complex simulations, one can use the Workflow Mamagement (see respective tutorial) to run the computation outside of the Jupyter notebook, either in a (parallel) background process and even on other computers/servers, resp. HPC (High Performance Computing) clusters.

The Run() command finally returns a session info, which carries some basic information on the solver run (mainly where ist was stored).

Execution in Console mode

We can also run this simulation in the traditional way, which most of you are familiar with from other academical codes.

We define an input file, which is nothing else than the above C# code.

We can run it by calling

CNS.exe -c IsentropicVortex.cs.

You can find the input file in ControlExamples folder in the doc directory.

Postprocessing

We saved our data in the database and lastly we want to postprocess it, i.e visualize the individual fields like density, momentum or pressure.

Note:

If you have run the simulation in the console mode, you now have to start the BoSSSpad.

In our example, we find the corresponding session in our first database as first session

To convert data to the Tecplot format, we just need to export it (in order to run the command delete the comment)

We can open the folder directly by using (works only in BoSSSPad)

... where we find the files with our data.

For more information about our databases and useful commands for postprocessing, we refer to our tutorials about the database and the database command overview.