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}.$$
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.
IsentropicVortex.ipynb
.
One can directly load this into Jupyter to interactively work with the following code examples.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
).#r "BoSSSpad.dll"
using System;
using System.Collections.Generic;
using System.Linq;
using ilPSP;
using ilPSP.Utils;
using BoSSS.Platform;
using BoSSS.Foundation;
using BoSSS.Foundation.Grid;
using BoSSS.Foundation.Grid.Classic;
using BoSSS.Foundation.IO;
using BoSSS.Solution;
using BoSSS.Solution.Control;
using BoSSS.Solution.GridImport;
using BoSSS.Solution.Statistic;
using BoSSS.Solution.Utils;
using BoSSS.Solution.Gnuplot;
using BoSSS.Application.BoSSSpad;
using BoSSS.Application.XNSE_Solver;
using static BoSSS.Application.BoSSSpad.BoSSSshell;
Init();
We start with creating a database and loading the namespace.
/// We create, resp. open a \BoSSS database:
var myDatabase = CreateTempDatabase();
Creating database 'C:\Users\jenkinsci\AppData\Local\Temp\1860746156'.
using CNS;
typeof(CNS.CNSProgram).Assembly.Location
C:\Gitlab-Runner\builds\PYSUsL3w\1\kummer\bosss-public\src\L4-application\PublicTestRunner\bin\Release\net6.0\CNS.dll
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:
CNS.exe --control path-to-controle-file
.CNS.exe --control 'cs:CNS.ControlExamples_Subsonic.IsentropicVortex( ...further-args... )'
.For the isentropic vortex, you have to specify
// use the predsefined IsentropicVortex example as a foundation for a control object
int noOfCellsPerDirection = 20;
var c = ControlExamples_Subsonic.IsentropicVortex(myDatabase.Path,
noOfCellsPerDirection,2,1.0);
c.savetodb = true;
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}.
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.
c.GridFunc = delegate {
double[] nodes = GenericBlas.Linspace(-10, 10, noOfCellsPerDirection + 1);
var grid = Grid2D.Cartesian2DGrid(nodes, nodes,
periodicX: true, periodicY: true);
return grid;
};
The CNS solver is able to solve the Euler and the compressible Navier-Stokes equations. By setting
c.ActiveOperators
we only use the convective fluxes, i.e the Euler equations, and set it to
c.ConvectiveFluxType
Note: here, Optimized means, that this is the HLLC flux should be used, but implemented in an performance-optimized version.
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:
c.MachNumber
Further, we have to define a simulation time, i.e
c.Endtime
Finally, we need a time stepping scheme
c.ExplicitScheme
...of order...
c.ExplicitOrder
...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:
c.ExplicitOrder = 3;
c.ExplicitOrder
Or we can change the Mach number to
c.MachNumber = 0.7;
c.MachNumber
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.
c.PrintInterval = 5;
var SI = c.Run();
Session ID: 48807517-0cd0-455a-a4c3-7f161c11743f, DB path: 'C:\Users\jenkinsci\AppData\Local\Temp\1860746156' Session directory 'C:\Users\jenkinsci\AppData\Local\Temp\1860746156\sessions\48807517-0cd0-455a-a4c3-7f161c11743f'. Grid repartitioning method: METIS Grid repartitioning options: Number of cell Weights: 0 Starting time step #5... done. PhysTime: 4E-02, dt: 1E-02 Starting time step #10... done. PhysTime: 9E-02, dt: 1E-02 Starting time step #15... done. PhysTime: 1.4E-01, dt: 1E-02 Starting time step #20... done. PhysTime: 1.9E-01, dt: 1E-02 Starting time step #25... done. PhysTime: 2.4E-01, dt: 1E-02 Starting time step #30... done. PhysTime: 2.9E-01, dt: 1E-02 Starting time step #35... done. PhysTime: 3.4E-01, dt: 1E-02 Starting time step #40... done. PhysTime: 3.9E-01, dt: 1E-02 Starting time step #45... done. PhysTime: 4.4E-01, dt: 1E-02 Starting time step #50... done. PhysTime: 4.9E-01, dt: 1E-02 Starting time step #55... done. PhysTime: 5.4E-01, dt: 1E-02 Starting time step #60... done. PhysTime: 5.9E-01, dt: 1E-02 Starting time step #65... done. PhysTime: 6.4E-01, dt: 1E-02 Starting time step #70... done. PhysTime: 6.9E-01, dt: 1E-02 Starting time step #75... done. PhysTime: 7.4E-01, dt: 1E-02 Starting time step #80... done. PhysTime: 7.9E-01, dt: 1E-02 Starting time step #85... done. PhysTime: 8.4E-01, dt: 1E-02 Starting time step #90... done. PhysTime: 8.9E-01, dt: 1E-02 Starting time step #95... done. PhysTime: 9.4E-01, dt: 1E-02 Starting time step #100... done. PhysTime: 9.9E-01, dt: 1E-02 Starting time step #105... done. PhysTime: 1.04E00, dt: 1E-02 Starting time step #110... done. PhysTime: 1.09E00, dt: 1E-02 Starting time step #115... done. PhysTime: 1.14E00, dt: 1E-02 Starting time step #120... done. PhysTime: 1.19E00, dt: 1E-02 Starting time step #125... done. PhysTime: 1.24E00, dt: 1E-02 Starting time step #130... done. PhysTime: 1.29E00, dt: 1E-02 Starting time step #135... done. PhysTime: 1.34E00, dt: 1E-02 Starting time step #140... done. PhysTime: 1.39E00, dt: 1E-02 Starting time step #145... done. PhysTime: 1.44E00, dt: 1E-02 Starting time step #150... done. PhysTime: 1.49E00, dt: 1E-02 Starting time step #155... done. PhysTime: 1.54E00, dt: 1E-02 Starting time step #160... done. PhysTime: 1.59E00, dt: 1E-02 Starting time step #165... done. PhysTime: 1.64E00, dt: 1E-02 Starting time step #170... done. PhysTime: 1.69E00, dt: 1E-02 Starting time step #175... done. PhysTime: 1.74E00, dt: 1E-02 Starting time step #180... done. PhysTime: 1.79E00, dt: 1E-02 Starting time step #185... done. PhysTime: 1.84E00, dt: 1E-02 Starting time step #190... done. PhysTime: 1.89E00, dt: 1E-02 Starting time step #195... done. PhysTime: 1.94E00, dt: 1E-02 Starting time step #200... done. PhysTime: 1.99E00, dt: 1E-02 Removing tag: NotTerminated
The Run() command finally returns a session info, which carries some basic information on the solver run (mainly where ist was stored).
SI
IsentropivVortex_Mach=0.2_cells=20_p=2_flux=OptimizedHLLC empty-session-name 12/05/2023 01:54:02 48807517...
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.
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.
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
//myDatabase.Sessions.First();
To convert data to the Tecplot format, we just need to export it (in order to run the command delete the comment)
//myDatabase.Sessions.First().Export().Do()
We can open the folder directly by using (works only in BoSSSPad)
//myDatabase.Sessions.First().Export().Do()
... 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.