OpenFOAM Development in VSCode with Docker Containers and Git

  • no OF installation required,
  • consistent and isolated developing environment,
  • easy deployment and ability to run applications on different machines,
  • ability to work with different versions on the same machine, etc.
  • Line 1: specifies the Base Images that you wish to use for your Image. I develop based on the official Image of latest version of OpenFOAM-v2006
  • Line 3: installs the applications that you wish to have in the Centos-OS of the image using the command `RUN yum …`
  • Line 4: specifies the user of OpenFOAM. In this case I specify the `ofuser` as the user in the OF bashrc file
  • Line 6: specifies the terminal bash
  • As the source-codes in OF are specified with the file-type extensions of *.C, the intellisense engine fails to comprehend the structure of the code and many useful functionalities of VSCode will be disabled, e.g. code completion, Go to Defenition/Declaration, Inheritance Hieratchy, etc. The tools that could be very useful specially for understanding the source code. To solve this issue, in line 10, I copy a file settings.json into .vscode directory of the OF source code. The content of this file is:
  • Line 12: specifies the name of the container user account. Remember that you can run the container with root access if you replace the ofuser with root. But running MPI applications in root is not encouraged.
  • Usually I copy the .bashrc and .vimrc files of my local host (Possible for Mac/Linux distributions) to have the same vim and bash experience as I have in my host. Lines 15–16 do this.
  • Needless to say that for OF applications, two files of OF bashrc and OF need to be sourced. That is why I add the following two lines to my .bashrc file
source /opt/OpenFOAM/OpenFOAM-v2006/etc/bashrc WM_NCOMPPROCS=4 WM_MPLIB=SYSTEMOPENMPI FOAM_CONFIG_NOUSER=unsetsource /opt/OpenFOAM/
  • Line 18: creates .ssh directory to hold future ssh-keys from the host, required for git version control
  • The last line 19 creates the directory of $USER_RUN that is usually used to track the OF case files.
localHost-> docker run --rm -it -v ~/.ssh:/root/.ssh -v $PWD/ofuser:/OpenFOAM/ofuser-v2006 vscodedockerof:latest bash
  • “— rm” eliminates the container once it is closed,
  • “-it” runs the container in interactive mode through a terminal
  • “-v” mounts a volume from local host to the container: “~/.ssh:/ofuser/.ssh”, mounts the volume “~/.ssh” to “/ofuser/.ssh”, thus the public key copied into your git key registry would be unlocked with the private key copied in “/ofuser/.ssh”, allowing easier git integration in your container. $PWD/ofuser:/OpenFOAM/ofuser-v2006 mounts the volume ofuser in your working directory of your host into ofuser-v2006 working directory of your OF container, thus all your simulations (in run directory) or your modified source codes (in src directory) will be saved in the local machine once you exit the container.




Postdoctoral Researcher in Computational Mechanics, Fluid Dynamics, Scientific Software developer, Machine Learning Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Amazon Athena Overview

Neosemantics 4.0 is out!

Multiple Table Inheritance in Rails

How I set up my 3x2 GB cluster computer for only $40 (and you can too)

My master plan

A brief history of Erlang and Elixir

“respError”: “json: unsupported type: func() (io.ReadCloser, error)”

Script: Using split to use an array of SYS_ID’s

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahmad Amani

Ahmad Amani

Postdoctoral Researcher in Computational Mechanics, Fluid Dynamics, Scientific Software developer, Machine Learning Engineer

More from Medium

Python FastApi Project with VisualCode, testing and debug

Getting started with Docker

How to Change PostgreSQL Data Directory to a separate Hard Drive on Ubuntu 18.04

CI-CD Operations with Github Actions