How to add options to OpenFOAM applications

A (testing) application needs to do additional work depending on a simulation / test case. The decision to do additional work is decided by an option passed to the application.

Step-by-step guide

This guide was written for OpenFOAM-dev. It might work on FOAM-extend too (if so, please add it to the tags of this article).

  1. Extend the argument list object (argList) with a new boolean option.
  2. Check if the boolean option is in the argument list when executing a conditional code block.

Boolean / switch options in OpenFOAM are not read from the input stream. Their existence is simply checked by the lookup function. Don’t try to use optionLookup or optionLookupOrDefault, they always return false.

Adding options in the OpenFOAM potentialFoam solver

     "Name of the pressure field"
     "Initialise U boundary conditions"
 #include "setRootCase.H"
 #include "createTime.H"
 #include "createMesh.H"
 // Optionally write Phi
 if (args.optionFound("writePhi"))

See also