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.
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.
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();
}
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.
Reference | Tutorial |
---|
Code | 01-Tutorial-Basics |
Notes | Basilisk 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. |
Reference | Coupled reaction-diffusion equations |
---|
Code | 03-Brusselator |
Notes | Solves 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. |
Reference | The complex Ginzburg-Landau equation |
---|
Code | 04-Ginzburg-Landau |
Notes | Solves 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. |
Reference | Distance field computation from a 3D model |
---|
Code | 05-Distance-Field |
Notes | This 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() . |
Reference | Wavelet transforms and filtering |
---|
Code | 06-Wavelet-Transform |
Notes | Provides 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]. |
Basic component solvers:
It is upon these that the Navier-Stokes equation can be assembled in:
Header | Description |
---|
navier-stokes/stream.h | Solves 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.h | Not a solver by itself, it supports other headers under the Navier-Stokes family to follow performance during solution. |
Other equations:
scalar
vector
face
msgstats
convergence statistics of (multigrid?) solver.
Function | Definition | Uses |
---|
origin | common.h | Set the origin of cartesian system. |
init_grid | grid/ (overloaded) | Level of refinement (size) of initial grid. |
size | | |
periodic | | Set periodic boundary conditions. |
statsf | utils.h | Retrieve statistics of a scalar field. |
output_ppm | output.h | Generate a image and video output. |
adapt_wavelet | grid/tree-common.h | Adaptive grid refinement routine. |
run | run.h (overloaded) | Generic time loop for events execution. |
noise | | Generate random noise in $[-1; 1]$. |
swap | | Swap values of two scalar arrays. |
input_stl | distance.h | Read an STL file as an array of triplets. |
bounding_box | distance.h | Determines the bounding box of inputs (segments or triangles). |
distance | distance.h | Distance to coordinate. |
view | draw.h | Setup of viewing (camera) parameters. |
isosurface | draw.h | Displays an isosurface of a field. |
draw_vof | draw.h | Display VOF reconstructed interfaces. |
clear | draw.h | Removes previous objects. |
save | view.h | Dumps image(s) to file. |
refine_biquadradic | grid/multigrid-common.h | |
wavelet | grid/multigrid-common.h | |
inverse_wavelet | grid/multigrid-common.h | |
boundary_level | | |
unrefine | | |
vorticity | utils.h | Computes the vorticity from a velocity field. |