FEATool Multiphysics  v1.13
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.

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.

openfoam_dlg_50.png

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.

openfoam_ctrlbtns_50.png

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 grey line shows the convergence criteria at which point the solver will automatically stop (when reached by all solution variables).

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 .

openfoam_edit_dlg_50.png

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

openfoam_solvtyp_50.png

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.

Initial Condition

openfoam_init_50.png

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

openfoam_settings_50.png

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.

Turbulence Modeling

openfoam_turb_dlg_50.png

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.

openfoam_turb_inlet_50.png

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, 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.

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 5, and works by performing system calls to the OpenFOAM solver executables, specifically simpleFoam, pimpleFoam, rhoCentralFoam, potentialFoam, and collapseEdges. It is therefore necessary that these binaries are installed and properly set up so they can be called from system script files (bash scripts on Linux and Mac OSX, and bat/vbs scripts on Windows).

The OpenFOAM binaries are due to licensing and compatibility with various systems currently not included with the FEATool distribution, and must be installed separately (or compiled directly from source code if required). For Microsoft Windows systems it is recommended to install and use the pre-compiled blueCFD-core (2017) binaries from blueCAPE/blueCFD.

For Ubuntu based Linux and Windows Subsystem for Linux (WSL) systems, OpenFOAM can be installed by opening an Ubuntu terminal shell and running the following commands (which automatically also installs any required dependencies)

sudo add-apt-repository http://dl.openfoam.org/ubuntu
sudo sh -c "wget -O - http://dl.openfoam.org/gpg.key | apt-key add -"
sudo apt-get update
sudo apt-get -y install openfoam5

For other systems, please follow the installation instructions and recommended distributions available from the official OpenFOAM https://openfoam.org foundation website.

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:\Program Files\blueCFD-Core-2017
...

For Windows systems the OpenFOAM installation is expected to be located in a program files folder labeled bluecfd as above, and for Linux ans OSX systems /opt/openfoam5 (or location pointed to by a FOAM_APP environment variable).

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 Wolfdynamics OpenFOAM Tips & Tricks.

References

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

[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."