Under the microscope: Computational Fluid Dynamic simulations using OpenFOAM

This CFD tutorial gives you an introduction to: a) simulating a simpler fluid motion scenario using OpenFOAM, while b) allowing an easily reproducible research environment using Docker.

In an earlier article we introduced the general main steps for investigating fluid motion using the computational fluid dynamics methodology. Within this article we dive deeper into how to conduct the simulation step, using OpenFOAM running on Docker.

Intro to OpenFOAM

OpenFOAM is an open-source package that includes numerical solvers that can be performed on the Navier-Stokes equations to get an approximate solution. OF also has geometry and meshing capability, which is beyond the scope of this article.

Intro to Docker

By using Docker, the aspiring researcher gains an isolated environment that can be reproduced (exactly), which is good for science and good for your mind -- instead of having to understand cross-platform issues you can focus on understanding the fluid dynamics of your investigation.

OpenFOAM: within Docker

A long-term user of OpenFOAM has generously made available a Docker script that easily creates a Docker image [1], which OpenFOAM can be executed upon, once this image is run within a Docker container (see above link for more instructions about how to make a Docker image):

sudo docker container run -ti --rm -v $HOME/cfd/openfoam/openfoam-data:/data -w /data openfoam:latest

OpenFOAM: simulating a case

After this container is launched, the user can then run a simplified, short 'case'. This case represents the abstracted flow scenario that will be simulated. For example, if we copy an OpenFOAM tutorial then examine it's file structure, using the following commands within the running container:

cd $FOAM_RUN
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily .
cd pitzDaily
tree

You then see the breakdown of the case into more granular components (e.g. directories & files). Before a simulation can be done, first generate the meshed geometry by executing a meshing application within OpenFOAM's collection [2]:

blockMesh

Then select a particular solution method (i.e. solver) to use on the case. In this instance the SIMPLE algorithm application is selected and simulation started by executing:

simpleFoam

Once you achieve convergence (within approximately 300 iterations) you can then analyse your simulation results using post-processing software such as ParaView [3], which can be installed on your normal (host) operating system for ease-of-use.

Conclusion

In this article you were introduced to conducting your first computational fluid dynamics simulation using OpenFOAM, which was run on Docker. More technical information was deliberately omitted to keep this article very accessible. If you are interested in continuing to explore CFD using OpenFOAM there are more comprehensive tutorials available on OpenFOAM's website [4].

References

[1] OpenFOAM Dockerfiles:
https://github.com/jakobhaervig/openfoam-dockerfiles

[2] OpenFOAM User Guide:
https://doc.cfd.direct/openfoam/user-guide-v10/index

[3] ParaView:
https://www.paraview.org/

[4] OpenFOAM Tutorial Guide:
https://www.openfoam.com/documentation/tutorial-guide