Hey there,
It’s Robin from CFD Engine & this week I’ve been digging in the OpenFOAM tutorial directory. It’s packed with good stuff if you know what you’re looking for and you know where to look.
I’m guessing your day-to-day CFD is pretty self-similar, but every now & again you’ll need to add some new functionality.
You could puzzle it out from scratch – recommended if you have the time.
You could piece it together from a dozen CFD Online posts (this probably takes longer than starting from scratch).
Or you could go digging in the OpenFOAM tutorials directory.
It’s a HUGE resource. I counted 419 tutorials in v2012 (at least that’s how many system
directories there are), that’s probably more than you’ll ever need.
So, what’s the catch?
Not Really Tutorials
First off, these aren’t really tutorials, there’s no teaching element, they’re more like examples or references. They’re working cases that you can poke around, change & break, to figure out how they work.
If you’re starting from zero, there are better places to look.
They’re also not intended to represent best-practice. They don’t always have the best choice of schemes or mesh resolutions, but they run pretty quickly & demonstrate how to achieve something that you’d otherwise have to figure out on your own.
That said, let’s dig in…
Organisation
You should just be able to cd $FOAM_TUTORIALS
to find them on your system. But it can also be handy to browse & search them online.
At the top level, they’re organised thematically – incompressible
, heat transfer
etc – and then by solver. So, if you know your solver, then that’s not a bad place to start.
multiphase
has the most tutorials with 123, followed by incompressible
& compressible
with 102 & 40 respectively. DNS
& Financial
each only have a single tutorial, so you’re kind of on your own there.
The basic workflow goes like this: copy the tutorial you want, to your working directory (don’t run them in the $FOAM_TUTORIALS
directory, let’s keep that pristine). Then, from inside the case directory, run foamRunTutorials
to make the magic happen.
Once complete, you can dig through the output logs to see what happened & fire up ParaView to see what you’ve got.
Caveats
Some of the larger, longer-running tutorials run on several cores. Of the ones that run in parallel, most run on 4 cores or less, but some need up to 16 cores. It’s worth checking the system/decomposeParDict
before launching, just to make sure you’re not about to overload your machine.
If there’s an ./Allrun
file in the tutorial directory then check it out, they’re a mine of information on how to string a simulation together – what steps & tools are needed & in what order.
Some of them contain a few obscure Unix commands, but they’re just about decipherable with a little help from Google.
My picks
We couldn’t hope to get through all of the tutorials, but here are a handful of my favourites, including why they’re interesting & why you might want to check them out.
The motorBike
one
$FOAM_TUTORIALS/incompressible/simpleFoam/motorBike/
This is my favourite tutorial, partly because it reflects what I do most of the time – low-speed, external aerodynamics – and partly because it’s a great example of how the “mesh-solve-post-pro” stages fit together in OpenFOAM.
In this case, it takes an input OBJ file with loads of named zones, meshes it in snappyHexMesh
(including feature-edge refinement & a simple refinement box), solves it in simpleFoam
(including basic force reporting) and exports some post-pro (including streamlines, cutting planes and EnSight data), all in parallel.
A great starting point for anyone wanting to do something similar. It’s not production ready, but it has a lot going for it. Check it out, if you haven’t already.
The functionObject
one
$FOAM_TUTORIALS/incompressible/pisoFoam/RAS/cavity
I’ve mentioned this one before, but I have to mention it again in case you missed it.
It’s a simple lid-driven cavity case, that’s not particularly interesting in itself. The value comes from the treasure trove of 47 functionObjects
defined in the system
directory. More than you’ll ever need & definitely more than you’ll ever use on a single case – I reckon it spends longer running functionObjects
than solving.
A good reference to help you figure out how to use any new (to you) functionObjects
.
The cfMesh introduction
You might not have this tutorial, it depends on your install method, but it’s worth seeking out (you can get it here). It’s a nice introduction to using cartestianMesh
from the cfMesh module in v2012.
cartesianMesh
is a blazing fast alternative to snappyHexMesh
that runs so quickly you might think it hasn’t worked.
You’ll need the User Guide & a little patience if you’re going to start digging into this one. But, depending on your meshing needs, it could well be worth the effort. It’s a great mesher & there’s an even better version available commercially.
The DES one
$FOAM_TUTORIALS/incompressible/pisoFoam/LES/motorbike
Back to the motorbike again, but this time with added DES. It takes a finer version of the original motorbike, runs it for 500its RANS to get an initial solution & then switches it over to DES to run in pisoFoam
.
It’s a nice simple example of a “RANS-first-then-DES” workflow & what’s required to make it happen in OpenFOAM.
It also includes some runTimePostProcessing
as a little bonus.
It takes a little bit longer to run than most of the tutorials but, if you’re in the market for an LES/DES external aero simulation (&/or run-time post-processing), then it should be time well spent.
snappyHexMesh
examples
$FOAM_TUTORIALS/mesh/snappyHexMesh
snappyHexMesh
can be tricky to get to grips with, but there are a handful of useful examples in this directory. You’ll find things like leak detection, gap detection, how to mesh faceZones
alongside a few other tricks.
The faceZoneRegions
tutorial is an interesting one. It’s not always possible to create a suitable faceZone
(for measuring mass-flow rates etc) after a case is meshed, so it can be really handy to create (& name) the faceZones
you need, right in snappyHexMesh.
It’s not difficult to do, you just might not have done it before. This tutorial gives an example of how to do it, including options for naming the resulting faceZones
.
There is no “how to get 15 layers everywhere” tutorial though – sorry.
Over to you
Do you dig into the tutorials much? Is there a tutorial that you find yourself returning to regularly? There so many that I’ve never even looked at, what am I missing? Which one should I take for a spin next?
Perhaps you’re struggling to find something relevant to your use case? Let me know & I’ll try to point you towards something useful.
Hit reply & let me know.
Until next week, stay safe,