FEATool Multiphysics  v1.16.5
Finite Element Analysis Toolbox
OpenFOAM CFD Solver

OpenFOAM® is a popular open-source 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 FEATool-OpenFOAM 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 built-in 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.

Basic Use

The FEATool-OpenFOAM 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 non-constant material parameters such as for example temperature dependent density and viscosity, the built-in and FEniCS multiphysics solvers can be used for these types of problems instead.

Control Panel

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

  1. Export - converts and exports the defined FEATool model and mesh to compatible OpenFOAM case/dictionary files
  2. Solve - performs a system/subprocess call to the selected OpenFOAM solver and starts a monitoring process
  3. Import - interpolates and imports the computed solution back into FEATool for postprocessing and visualization

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 real-time. 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.

Edit/Export Case Files

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 re-enable controls .

The Export button allows for OpenFOAM dictionary and case files to be exported for external manual processing, editing, and saving.

Solver Settings

The following solver parameters and settings can be modified and set through the OpenFOAM dialog box and control panel.

Solver Type

Firstly, the Time discretization scheme and main solver type can be selected according to the given problem in the drop-down box. For stationary and steady-state models the following time schemes are available

  • Steady State - steady state scheme which sets all time derivatives to zero.
  • Local Euler - first order implicit pseudo transient local-time stepping scheme for accelerating a solution to steady-state.

and for instationary, transient, and time-dependent problems

  • Euler - first order implicit and bounded transient scheme.
  • Crank-Nicolson - second order implicit and bounded transient scheme.
  • Backward - second order implicit and potentially unbounded transient scheme.

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 Condition

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.

Simulation Settings

The Simulation Settings allow for specifying the following parameters

  • Adaptive time-stepping - enables variable time-stepping schemes.
  • Time step - sets the time step size.
  • End time - prescribes the maximum time of the simulation (end time).
  • Stopping criteria - specifies the stopping criteria for steady state simulations (corresponding to the residualControl parameter).
  • Upwinding - selects the upwinding scheme (numerical stabilization of convective terms).
  • Bounding - selects if divergence (div) and/or gradient (grad) schemes should be bounded/limited.
  • Number of processors - selects the number of concurrent processes when running computations in parallel (defaults to the number of CPU cores/2)

Turbulence Modeling

The Turbulence model drop-down box allow for the

one and two-equation 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.

Command Line Use

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} = { 1e-3 };
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 m-script 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 user-defined custom m-scripts, which can use all other MATLAB functions and toolboxes.

Advanced Use

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 re-imported into FEATool if desired or processed by other external postprocessing tools such as ParaView.

Tutorials

An introductory tutorial with step-by-step 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 m-script 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

Installation

The FEATool-OpenFOAM 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.

Windows

For Microsoft Windows systems it is recommended to install and use the pre-compiled Native-windows/mingw OpenFOAM binaries, which are available from ESI-OpenCFD.

For Windows systems the OpenFOAM installation is expected to be located in the default installation location, that is in the directory

%USERPROFILE%\AppData\Roaming\ESI-OpenCFD\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.

Linux

For Linux systems, please follow the installation instructions and recommended distributions available from the OpenFOAM foundation website website, or alternatively via ESI-OpenCFD. Pre-compiled 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.

MacOS

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 ESI-OpenCFD.

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.

MPI Interface

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.

Verification

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\ESI-OpenCFD\OpenFOAM\v2112
...

Further Information

Further information about OpenFOAM and its usage can be found in the official User Guide, the OpenFOAM wiki, and various guides available on-line such as for example OpenFOAM Tips & Tricks.

References

[1] OpenCFD - List of OpenFOAM® Partners, openfoam.com, 2021.

[2] Application of Detached-Eddy Simulation for Automotive Aerodynamics Development, SAE2009-01-0333, 2009.

[3] F1 turns to AWS to develop next-gen race car, zdnet.com, December 2, 2019.

[4] Aerodynamic Simulation of a 2017 F1 Car with Open-Source CFD Code, Journal of Traffic and Transportation Engineering 6, 155-163, 2018.


"OPENFOAM® is a registered trade mark of OpenCFD Limited, producer and distributor of the OpenFOAM software via www.openfoam.com."