Basilisk

The goal of this material is to provide support to teaching introductory computational fluid mechanics with aid of Basilisk. The studies are based on commented tutorials and a documentation guide extending what is already provided with the package.

Before going over the tutorials, you need some C knowledge. In the future I intend to provide a synthetic version applied to Basilisk students only. For now, the referred one is pretty good.

First steps

The source code for the studies is provided here. The repository keeps a copy of Basilisk at a version that will work with all modified tutorials. It may be eventually updated, but in that case functioning of tutorials will be tested. You will need to clone it then following the steps to compile Basilisk before starting. After building Basilisk, instead of adding variables to your environment, consider sourcing them temporarily with help of source activate.sh using the provided script.

All tutorials are found under src. Just enter the tutorials you want to follow using the command line and run make. This not only will compile, but will also run and post-process results.

Project management

Although Basilisk is a very interesting dialect of C, its documentation is still old-fashioned and lack some structuration. Also sample programs are not written to be easily managed and extended for use in variant cases. Here we propose a structure for creating better projects with Basilisk:

  • A Basilisk project lives in its own folder: one executable means one directory.

  • A simpler Makefile than Basilisk's default one is used for project building.

  • The main file is called app.c and contains a very simple structure as provided in the dummy listing bellow. All the logic of a project, i.e. the events, is implemented in separate header files that are included after Basilisk includes.

// Definitions
#define LEVEL 7
#define ...

// Basilisk includes.
#include "grid/multigrid.h"
#include "run.h"
#include ...  

// Project includes.
#include "project-base.h"
#include "project-init.h"
#include "project-post.h"
#include "project-exec.h"

int main() {
	init_grid(1 << LEVEL);
	...
	run();
}

Parallel computing

Currently I have not tried Basilisk in parallel (actually I did so a few years back but don't really remember the steps). Since there is no dedicated tutorial for going parallel, here are the notes I am taking for writing something in that sense:

  • Tutorial isotropic.c has notes on how to run parallel in some of its parent universities supercomputers. Probably some steps there might be recycled here.

Introductory tutorials

Basilisk basics

ReferenceTutorial
Code01-Tutorial-Basics
NotesBasilisk is a conceptual solver for investigating problems in a Cartesian domain.<br><br>Different steps of the simulations are set by event's, which use a specific syntax do indicate whether they depend on a time or iteration condition. These steps might include setup of initial conditions, storage of intermediate results or solution, grid refinement, etc.<br><br>For iterating over arrays Basilisk provides a foreach()loop extending the C-language.<br><br>A standard Makefile is provided by Basilisk for managing common workflows.<br><br>Check the tips.

Game of life

ReferenceConway’s game of life
Code02-Game-of-life
NotesA simple implementation of Conway's game of life to get used with syntax.

Brusselator

ReferenceCoupled reaction-diffusion equations
Code03-Brusselator
NotesSolves the 2D Brusselator, a theoretical autocatalytic reaction diffusion system. The set of parameters used in the study for the stable Turin points where the ones proposed by Pena2001a [20]. Interesting material for preparing courses extending this to other oscillating systems can be found here.

Ginzburg-Landau

ReferenceThe complex Ginzburg-Landau equation
Code04-Ginzburg-Landau
NotesSolves the complex Ginzburg-Landau equation describing the nonlinear evolution of disturbances near the transition from a stable to unstable state of a system. Additional materials are provided here. It would be a good project to include the term $\alpha$ in the equation and the Laplacian term that goes with it.

Distance field

ReferenceDistance field computation from a 3D model
Code05-Distance-Field
NotesThis can be seen as a particular case of pre-/post-processing. It can prove useful when initializing domains with scanned surfaces in STL or other compatible format. Additional steps must be taken for compilation with rendering (modifications to Makefile). Iteration over dimensions can be done with foreach_dimension().

Wavelet transform

ReferenceWavelet transforms and filtering
Code06-Wavelet-Transform
NotesProvides a tutorial on wavelet transform and associated filters. It is presented as the basis to understand mesh adaptation in Basilisk. Recommended reading of Sweldens1998a [21].

Decaying turbulence

ReferenceDecaying two-dimensional turbulence
Code07-Decaying-Turbulence
NotesFor solving Euler equation with vorticity-stream formulation one uses header file navier-stokes/stream.h. The examples makes a first usage of dimensional quantities for vorticity initialization.

Vortex street

ReferenceBénard–von Kármán Vortex Street for flow around a cylinder
Code08-Vortex-Street
NotesSolves the flow around a solid object using the navier-stokes/centered.h solver and introduced the use of passive scalars (tracer). Notice we modify L0, which among many other magic variables is defined in common.h. Illustrates the use of solid and intersection to accomplish complex domains.

Vortex shedding

ReferenceVortex shedding behind a sphere
Code09-Vortex-Shedding
NotesSolution of Navier-Stokes equations in an adaptive domain embedding an sphere. Vortex detection is made with functionalities from lambda2.h implemented following Jeong1995a [22].

Porous medium

ReferenceStokes flow through a complex 3D porous medium
Code10-Porous-Medium
Notes

Periodic box

ReferenceForced isotropic turbulence in a triply-periodic box
Code11-Periodic-Box
Notes

Two-phase flows

Pulsed atomization

ReferenceAtomisation of a pulsed liquid jet
Code12-Pulsed-Atomisation
Notes

Bubble rising

ReferenceBubble rising in a large tank
Code13-Bubble-Rising
Notes

Rotating cylinder

ReferenceFlow in a rotating bottom-driven cylindrical container
Code14-Rotating-Cylinder
Notes

Moving Tangaroa

ReferenceTwo-phase flow around RV Tangaroa
Code15-Moving-Tangaroa
Notes

Geophysical applications

Indian Tsunami

ReferenceThe 2004 Indian Ocean tsunami
Code16-Indian-Tsunami
Notes

Tohoku Tsunami

ReferenceThe 2011 Tohoku tsunami
Code17-Tohoku-Tsunami
Notes

Train of Solitons

ReferenceBreakup of a rectangular perturbation into a train of solitons
Code18-Train-of-Solitons
Notes

Lee Waves

ReferenceTidally-induced internal lee waves
Code19-Lee-Waves
Notes

Ellipsoidal Shoal

ReferencePeriodic wave propagation over an ellipsoidal shoal
Code20-Ellipsoidal-Shoal
Notes

Ellipsoidal Shoal Multilayer

ReferencePeriodic wave propagation over an ellipsoidal shoal (multilayer)
Code21-Ellipsoidal-Shoal-Multilayer
NotesCheck for source code in current version.

Stokes Wave

Reference3D breaking Stokes wave (multilayer solver)
Code22-Stokes-Wave
Notes

Transcritical Flow

ReferenceTranscritical flow over a bump
Code23-Transcritical-Flow
Notes

Shock Instability

ReferenceA Shallow Water Analogue for the Standing Accretion Shock Instability
Code24-Shock-Instability
Notes

Python interface

Basic usage

ReferencePython interface
Code25-Python-Interface
Notes

Poisson equation

ReferencePoisson problem with Python
Code26-Python-Poisson
Notes

Built-in solvers

Basic component solvers:

It is upon these that the Navier-Stokes equation can be assembled in:

HeaderDescription
navier-stokes/stream.hSolves a 2D incompressible, constant density, constant viscosity Navier-Stokes equation formulated in the vorticity $\omega$. This is and advection-diffusion equation solved with a flux-based advection scheme in advection.h. Given its form, the stream function $\psi$ is solver through the poisson.h solver.
navier-stokes/centered.h
navier-stokes/perfs.hNot a solver by itself, it supports other headers under the Navier-Stokes family to follow performance during solution.

Other equations:

Headers files

FileUsage
common.h
distance.h
embed.hAllow the creation of general shape boundary conditions inside the domain.
fractions.h
lambda2.hDetection of vortex using the criteria by Jeong1995a [22]
run.hA generic time loop which executes until termination (to be avoided!).
tracer.hProvides an event to integrate the advection of tracer elements.
utils.h
view.h
FileUsage
grid/cartesian.h
grid/multigrid.h
grid/octree.h
grid/bitree.h

Data types

  • scalar
  • vector
  • face
  • msgstats convergence statistics of (multigrid?) solver.

Functions

FunctionDefinitionUses
origincommon.hSet the origin of cartesian system.
init_gridgrid/ (overloaded)Level of refinement (size) of initial grid.
size
periodicSet periodic boundary conditions.
statsfutils.hRetrieve statistics of a scalar field.
output_ppmoutput.hGenerate a image and video output.
adapt_waveletgrid/tree-common.hAdaptive grid refinement routine.
runrun.h (overloaded)Generic time loop for events execution.
noiseGenerate random noise in $[-1; 1]$.
swapSwap values of two scalar arrays.
input_stldistance.hRead an STL file as an array of triplets.
bounding_boxdistance.hDetermines the bounding box of inputs (segments or triangles).
distancedistance.hDistance to coordinate.
viewdraw.hSetup of viewing (camera) parameters.
isosurfacedraw.hDisplays an isosurface of a field.
draw_vofdraw.hDisplay VOF reconstructed interfaces.
cleardraw.hRemoves previous objects.
saveview.hDumps image(s) to file.
refine_biquadradicgrid/multigrid-common.h
waveletgrid/multigrid-common.h
inverse_waveletgrid/multigrid-common.h
boundary_level
unrefine
vorticityutils.hComputes the vorticity from a velocity field.