FEATool Multiphysics
v1.16.1
Finite Element Analysis Toolbox

OpenFOAM® is a popular opensource Finite Volume Method (FVM) based Computational Fluid Dynamics (CFD) solver, and features a wide selection of solvers for incompressible, compressible, laminar, and turbulent flow regimes. The OpenFOAM code base is widely used in academia, as well as in industry by for example Volkswagen and Audi in automotive engineering applications [1,2], and in Formula 1 racing to model and optimize aerodynamics [3,4].
The FEAToolOpenFOAM CFD solver integration makes it easy and convenient to perform advanced CFD simulations within a fully integrated GUI directly in MATLAB. OpenFOAM includes solvers specially designed and tuned for flow problems which can yield a magnitude or more speedup and memory efficiency compared to MATLAB's builtin direct solver. This simultaneously allows for both significantly larger simulations and faster results.
Note that the OpenFOAM binaries are not included with the FEATool distribution as every system and OS needs specific versions for compatibility, and they must therefore be installed separately. See the installation section below for information on how to install OpenFOAM.
The FEAToolOpenFOAM solver integration supports single physics models created with either of the applicable physics modes
To use the OpenFOAM solver for a model with one of these physics modes, press the toolbar button in Solve Mode, instead of the default solve button. This will open the OpenFOAM solver settings and control panel.
Note that the OpenFOAM solvers currently do not support models with multiple subdomains, or nonconstant material parameters such as for example temperature dependent density and viscosity, the builtin and FEniCS multiphysics solvers can be used for these types of problems instead.
The OpenFOAM control panel and solver settings dialog box allows one to use OpenFOAM to solve CFD problems.
In the lower control button panel the Solve button will start the automatic solution process with the chosen settings. This means that the following steps are performed in sequence
While the solution process is running the Stop button will halt/pause the solver and plot the current solution state, while the Cancel button terminates the solution process and discards the current solution (note that it can take some time for the solver register a halt event and to stop). If the Close automatically checkbox is marked, the OpenFOAM control panel will be automatically closed after the solution process has finished, and FEATool will switch to Postprocessing Mode.
During the solution process one can also switch between the Log and Convergence tabs to see and monitor the solver output log and convergence plots in realtime. In the Convergence tab the error norm for the solution variables such as velocities, pressure, and turbulence quantities are plotted after each iteration and time step. A horizontal dashed gray line shows the convergence criteria at which point the solver will automatically stop (when reached by all solution variables). Note that for parallel simulations the convergence plots can be somewhat irregular due to the unordered log file output from parallel runs.
The Edit button in the control panel opens a new dialog box where OpenFOAM dictionary and case files can be viewed and edited (select the dictionary file to view/edit in the left hand side tree list). Note that manually editing OpenFOAM case files will lock the settings controls (due to potential mismatches between manual input and the controls). Open the View/Edit dialog box again and press the Cancel button to clear/reset case files unlock and reenable controls .
The Export button allows for OpenFOAM dictionary and case files to be exported for external manual processing, editing, and saving.
The following solver parameters and settings can be modified and set through the OpenFOAM dialog box and control panel.
Firstly, the Time discretization scheme and main solver type can be selected according to the given problem in the dropdown box. For stationary and steadystate models the following time schemes are available
and for instationary, transient, and timedependent problems
By default the simpleFoam OpenFOAM solver will be used for incompressible flow problems with fixed time steps and pimpleFoam if adaptive time stepping is selected. For compressible flow type problems the rhoCentralFoam solver is used instead. The selected OpenFOAM solver can be changed manually in the Solver edit field. Note that by manually changing the solver to an unsupported type, you must also ensure that all OpenFOAM dictionaries are defined and set up currectly for the solver to run.
Initial conditions can be specified as either constant or subdomain expressions for the solution variables using the Expression dialog box (equivalent to specifying the corresponding fields in the Subdomain Settings dialog box). Alternatively, a Potential flow solution can also be computed (with potentialFoam) and used as an initial condition, or if a previously computed Solution exists it can be used instead.
The Simulation Settings allow for specifying the following parameters
The Turbulence model dropdown box allow for the
one and twoequation RANS turbulence models to be selected (in addition to the default Laminar (no turbulence model) option).
Inlet conditions for the turbulent quantities should typically be prescribed for all inlets of the domain. One can either set the turbulence quantities directly in the turbulence inlet conditions dialog box.
Or if not known, the turbulent quantities k and epsilon/omega can be estimated from the turbulent intensity \(I_{turb}\) (1%  10% recommended), and \(l_{turb}\) length scale for the turbulent eddies (default 8% of the boundary length) as
\[ \begin{aligned} & k = 3/2\cdot (\mathbf{u}\cdot I_{turb})^2 \\ & \epsilon = C_{\mu}^{3/4}\cdot k^{3/2}/l_{turb} \\ & \omega = C_{\mu}^{1/4}\cdot k^{1/2}/l_{turb} \end{aligned} \]
where \(C_{\mu} = 0.09\) is a turbulence modeling constant. The Recompute button will calculate the turbulent inlet quantities after changing the turbulent intensity and/or length scale.
The Wall functions setting allows for enabling and disabling standard wall functions which are typically used with meshes and grids that can not sufficiently resolve the turbulent boundary layers.
The openfoam function can be used instead of solvestat and solvetime functions to solve CFD problems with OpenFOAM on the MATLAB Command Line Interface (CLI). The following is an example of laminar steady flow in a channel solved with OpenFOAM
fea.sdim = {'x','y'}; fea.grid = rectgrid(50,10,[0,2.5;0,0.5]); fea = addphys(fea,@navierstokes); fea.phys.ns.eqn.coef{1,end} = { 1 }; fea.phys.ns.eqn.coef{2,end} = { 1e3 }; fea.phys.ns.bdr.sel(4) = 2; fea.phys.ns.bdr.coef{2,end}{1,4} = '2/3*0.3'; fea.phys.ns.bdr.sel(2) = 4; fea = parsephys(fea); fea = parseprob(fea); % Alternative to calling: fea.sol.u = solvestat( fea ); fea.sol.u = openfoam( fea ); postplot(fea,'surfexpr','sqrt(u^2+v^2)')
The model parameters used here are taken from the ex_navierstokes1 example script model. The mscript examples listed in the OpenFOAM tutorials section similarly allow for using the OpenFOAM solver instead of the default solver. Furthermore, the openfoam function can also be embedded in userdefined custom mscripts, which can use all other MATLAB functions and toolboxes.
The OpenFOAM solvers are capable of performing large scale simulations on parallel clusters, and although technically possible to use FEATool to do this, for memory and stability reasons it is not advised to do this from within the MATLAB environment.
For large scale simulations it is recommended to first export a FEATool model with the openfoam export command or using the Export button in the OpenFOAM settings and control panel dialog box. This will generate corresponding OpenFOAM case files, with which one can manually launch the OpenFOAM solver without MATLAB (consult the OpenFOAM documentation for a full explanation how to use OpenFOAM as a stand alone solver). Solutions can then be reimported into FEATool if desired or processed by other external postprocessing tools such as ParaView.
An introductory tutorial with stepbystep instructions of how to set up and solve a turbulent backwards facing step flow problem using the external OpenFOAM solver is available in the tutorial section
which also can be run directly in the FEATool GUI by selecting Model Examples and Tutorials... > Fluid Dynamics > Turbulent Flow Over a Backwards Facing Step from the File menu.
In addition, a more advanced model of coupling an OpenFOAM flow field solution with a FEATool Multiphysics temperature field calculation is also available
Although not directly illustrating use of the OpenFOAM solver, the majority of the fluid dynamics tutorials available in the File > Model Examples and Tutorials... > Fluid Dynamics menu also allow for using OpenFOAM.
The following mscript models, found in the in the examples directory of the FEATool installation folder, feature a 'solver', 'openfoam'
input parameter which can be used to directly enable the OpenFOAM solver
The FEAToolOpenFOAM solver integration has been extensively tested and verified with OpenFOAM version 2112, and works by performing system calls to the OpenFOAM solver executables, specifically simpleFoam, pimpleFoam, rhoCentralFoam, potentialFoam, collapseEdges, and decomposePar. It is therefore necessary that these binaries are installed and properly set up so they can be called from system script files (bash shell scripts on Linux and MacOS, and bat/vbs scripts on Windows).
The OpenFOAM binaries are not included with the FEATool distribution as every system and OS needs specific versions for compatibility, and they must therefore be installed separately.
For Microsoft Windows systems it is recommended to install and use the precompiled Nativewindows/mingw OpenFOAM binaries, which are available from ESIOpenCFD.
For Windows systems the OpenFOAM installation is expected to be located in the default installation location, that is in the directory
%USERPROFILE%\AppData\Roaming\ESIOpenCFD\OpenFOAM
in a subfolder with the version number, for example labeled v2112. If OpenFOAM is installed in another directory, an environment variable named FOAM_APP can be defined with the correct location so that the solver can be found.
Note that running OpenFOAM via Docker containers or Windows subsystem for Linux (WSL) is currently not supported.
For Linux systems, please follow the installation instructions and recommended distributions available from the OpenFOAM foundation website website, or alternatively via ESIOpenCFD. Precompiled packages are available for several Linux distributions such as Debian, Ubuntu, SUSE, RedHat etc. Alternatively, the solver binaries can also be compiled from source.
For linux systems OpenFOAM is expected to be installed in, or have a symbolic link to, the folder /opt/openfoam
. Alternatively, one can also assign the OpenFOAM installation folder location by setting the environment variable FOAM_APP.
Note that running OpenFOAM via Docker containers is not supported.
For MacOS systems OpenFOAM needs to be compiled from source and installed in the folder /opt/openfoam
. Alternatively, one can also redirect to /opt/openfoam via a symbolic link, or assign the OpenFOAM installation folder location by defining an environment variable named FOAM_APP.
The OpenFOAM source code and compilation instructions are available from either the OpenFOAM foundation website, or alternatively via ESIOpenCFD.
As an alternative to compiling from source, one can also install MATLAB, FEATool, and OpenFOAM in a VMWare or VirtualBox virtual machine running Ubuntu Linux. Note that running OpenFOAM via Docker containers is not supported.
Depending on how OpenFOAM was installed, one might also have to install the Message Passing Interface (MPI) libraries separately to enable parallel computations. It is recommended to use Microsoft MPI for Windows systems, and MPICH for Linux and MacOS systems.
Select System Info... from the Help menu to verify that the OpenFOAM installation can be found by FEATool. This will open a dialog box with details for the current system and FEATool configuration. Find the line item labeled OpenFOAM: and verify that it points to your OpenFOAM installation folder, for example
... OpenFOAM: C:\Users\User0\AppData\Roaming\ESIOpenCFD\OpenFOAM\v2112 ...
Further information about OpenFOAM and its usage can be found in the official User Guide, the OpenFOAM wiki, and various guides available online such as for example OpenFOAM Tips & Tricks.
[1] OpenCFD  List of OpenFOAM® Partners, openfoam.com, 2021.
[2] Application of DetachedEddy Simulation for Automotive Aerodynamics Development, SAE2009010333, 2009.
[3] F1 turns to AWS to develop nextgen race car, zdnet.com, December 2, 2019.
[4] Aerodynamic Simulation of a 2017 F1 Car with OpenSource CFD Code, Journal of Traffic and Transportation Engineering 6, 155163, 2018.
"OPENFOAM® is a registered trade mark of OpenCFD Limited, producer
and distributor of the OpenFOAM software via www.openfoam.com."