Part 2: Open Source CFD Software Packages
Open-Source CFD Software Packages - Good Enough and Free
There are many advantages to using open-source software. In addition to being free to use and distribute, open-source software provides users the license to modify source code as-needed. In some cases, online user communities exist that support user learning and code development.
Open-source CFD solvers are no different. Some of the most common include OpenFOAM, SU2, Palabos, Fire Dynamics Simulator and MFIX. OpenFOAM is by far the most widely used and will be the focus of most of this discussion.
OpenFOAM (OF) has gained considerable credibility in recent years through verification and validation studies performed by a growing user base. An increasing number of universities and corporations are also using OF, both independently and in conjunction with other commercial codes. Skimming the agendas of previous OF User Conferences one sees that companies such as Mercedes Benz, BASF, BMW, Volkswagen, and Intel are among those with a presence. This is not surprising, as it is such large companies with inherently large simulation workloads that stand to benefit the most from freeware licensing.
Free? Check. Accurate? Check. Customizable? Check. Applicable to numerous types of fluids problems? Check. So, what’s the catch?
OpenFOAM is a great tool for computational fluid dynamics with heavy use in academia. But there are some drawbacks which continue to keep it from becoming prevalent in industry.
OpenFOAM Background
OpenFOAM, originally simply “FOAM”, is a package of finite-volume based numerical algorithms originally developed by Henry Weller’s CFD group at London’s Imperial College in 1989. FOAM stands for Field Operations and Manipulation. An interesting note is that Mr. Weller and colleagues had the foresight to utilize C++ at the time, rather than the more prevalent engineering programming language FORTRAN, to take advantage of its object-oriented abilities. Good thinking. OpenFOAM was then made open-source when Weller and colleagues founded OpenCFD Ltd. which was then acquired by Silicon Graphics International (SGI) and later ESI. Meanwhile, the OpenFOAM copyright was transferred to the OpenFOAM Foundation Ltd.
Both of these organizations provide OpenFOAM related software packages and tutorial downloads. The code base is the same for both. The software release cycles are a bit different, as is the “numbering” of the software versions. So you may find that one version or the other has (or doesn’t have) one of the features you are looking for. The Foundation typically releases versions once or twice a year, with release numbers like 4.0, 5.0, 6.0 (current version). OpenCFD has a similar release schedule, but the version numbering is different and is based on year and month of release to prevent confusion (currently on v1806, or June 2018).
Linux and Windows Versions
OF is natively a Linux-based program, meaning you will need to use a Linux based operating system such as Ubuntu, Fedora, or Redhat Linux Enterprise, or you will need to run OF through a virtual machine within Windows. It goes without saying that some knowledge or background in Linux will come in handy when using OF.
A key step toward broadening the OF user base was recently taken when Microsoft implemented the ability to run a Linux Bash Shell as an application within Windows 10. Once this app is installed, Windows users can download, install, and run native OF through the app directly from the Windows desktop. More on this method can be found here.
Prior to this, Windows users wanting to run OF were required to “dual boot” their PCs and run Ubuntu on startup. This requires partitioning of your hard drive so that the Windows and Ubuntu file storage systems are separate. Thankfully with Windows Linux Bash Shell you can access OF files directly from within Windows and edit them via your favorite Windows text editor.
OpenCFD has also released a Windows “containerized” version of OpenFOAM. This version works outside of the Linux environment via Docker technology which containerizes the source code into an application that Windows 7, 8, or 10 can run.
Once installed, first time users may be surprised to find that what they have actually acquired is a directory structure containing a volume of text files (called dictionaries or dicts). Those preferring a standard GUI directing workflow from model setup and meshing to running the simulation to post-processing should look elsewhere. Perhaps take a look at an OF wrapper such as those discussed here. Instead, users interact with OF through a text editor of their choice and processes are launched via executable files from the Linux command line.
Workflow and Physics Capabilities
Though somewhat intimidating, setting up a simple problem isn’t that difficult and is made easier if you can find a tutorial where the setup is similar to your problem. Quite a few tutorials are available within the library, and hopefully one fits the bill. The typical workflow is to next copy a tutorial directory over to a local working folder for your project. This allows you to modify the mesh, boundary conditions, fluid properties, etc., in the local project folder without risking any impact to the original download package.
OpenFOAM is capable of quite a lot right out of the box. It can solve for transient or steady-state flows, turbulent or laminar flows, Newtonian or non-Newtonian fluids, multi-phase flows (Lagrangian particles and Eulerian/VOF), reacting flows, and passive scalars, to name a few. And while C++ programming skills are not required to use these features, they do make it less challenging. In general, each built-in solver is tailored for a specific type of problem. This means you will need to know a priori what type of physics are present in your application and what type of finite-volume based numerical algorithm is best suited for solving said physics. A brief list of some of the more common solvers and their associated physics is shown below.
Assigning the appropriate solver settings within this environment is a critical aspect of successful simulation and can be a challenge even for the most experienced CFD engineers.
All this can be a bit daunting, but each directory can be treated as an organizational bucket and each “dictionary” file within the bucket is not overly complex. In general, you will only need to modify fluid properties and inlet/outlet boundary conditions for each case, once you have typical solver settings configured to your liking. This will be handy for users who repetitively solve the same types of problems where entire case/project directory structures can be re-used again and again without changing anything except for the mesh.
Meshing
The lack of an easy-to-use and highly functioning built-in meshing utility is currently a stumbling block for all open-source CFD programs, including OF. The built-in mesh utility, blockMesh, is passable for elementary geometries such as rectangular ducts but is practically useless for anything more complex. The additional utility, snappyHexMesh, provides the ability to read surface geometry files in STL format as bodies to be tested in a virtual wind tunnel. Refinements and cleanup are required to arrive at a decent mesh. The process is laborious and time consuming, especially for complicated cases with small features. No utility is included that can implement meshes on internal flow problems where geometries are created in a typical 3D solid modeling environment.
OF does, however, include several converter utilities that will convert meshes from other software packages into the required mesh file structure. This, for us, has been the easiest and fastest way to get a high-quality mesh into OF. However, it requires access to a 3rd party mesh generation software. Notable built-in converters include ccmToFoam and fluentMeshToFoam, which obviously convert Siemens’ STAR-CCM+ and ANSYS Fluent meshes to OF format. Other common meshing tools, such as Pointwise and Gmsh have the ability to directly export to OpenFOAM mesh file format. It is also recommended that after running such utilities, the resulting mesh be checked to ensure the conversion was successful. More options are discussed in the OpenCFD documentation. We should note, though, that we have experienced unexplained solver stability issues after converting from commercial software meshes using the built-in converters.
Solving and Post-Processing
Once you have a meshed geometry and the physics models and solver settings are ready to go, one navigates to the case directory and types the solver keyword, such as simpleFoam into the command line terminal. That’s it. Your case should be running. You will likely see residuals for each iteration popping up in the command line/terminal window as the solver runs. Or you can have them written to a log file instead.
One particular strength of OF is that it allows for “decomposing” your problem and running in parallel on multiple processors, or even across multiple CPU nodes on a network. With OF, a decomposeParDict file must be set up within the system directory. This file allows the user to specify how many processors will be used and how the domain will be assigned to each processing core. Once the dictionary is ready, the “decomposePar” routine is called and breaks up the model into the divisions specified. Once the simulation is complete the user must call the “recompose” routine before post processing. Though these routines do take time, the simulation time on large problems can be greatly reduced through parallelization.
New versions of OF have added a routine called foamMonitor that allows for conservation equation residuals to be plotted interactively by typing a second command into the terminal after the job is launched. There are a few other setup steps needed for this to work correctly, but once working, it performs well. Unfortunately, this will not work inside of Windows 10 due to the inability of the Ubuntu bash to display the plot.
In general, we have found that OF solvers are robust. For stubborn problems, the ability to tweak numerous solver settings such as under-relaxation factors and the orders of discretization and time marching schemes can always help.
OpenFOAM comes packaged with an open-source post-processing software called ParaView. ParaView capabilities include most standard scientific visualizations such as contour plots, vector plots, streamlines, and line plots. Data extraction along lines and points can be implemented. Easy switching between time-step results allows for animation creation. An example of a ParaView-produced streamlines based on the Ahmed Body reference problem is shown below. It should be noted that ParaView is available in a free, stand-alone Windows version, which is actually what we use. Alternatively, users can export OF results to a 3rd party commercial software such as Ensight or FieldView (license required) in order to post-process model results in the package of your choice.
Conclusions
OpenFOAM is a great tool for computational fluid dynamics. The following are its obvious strengths:
Tons of capabilities and multiple solvers that can be applied to numerous types of flow problems
A product that has been developed and refined over the last two decades (at least) by those specializing in solving computational fluid dynamics problems
Many advantages typical of open-source software such as broad user base, tutorials and example problems online, and the ability to customize the code base to your liking
Increased acceptance in academia and industry
It costs nothing!
But there are some drawbacks, which may be holding it back from becoming more widespread/mainstream, including:
A steep learning curve combined with the need for a somewhat advanced user expertise in determining what important physics to solve and how to best match those physics with numerical algorithms
The need for a Linux based operating system OR some version of OF for Windows that may or may not have all of the native OF capabilities/utilities (such as plotting interactive residuals, for example). Knowledge of some basic Linux commands for file manipulation is very helpful.
The lack of a high-performance built-in meshing utility
The need to learn an additional post-processing software package
Extra time is required to setup and analyze model results due to the disconnected work flow as compared to workflow optimized commercial software solutions that feature all-in-one packages of pre-processing, solve, post-processing. This is perhaps the biggest deal-breaker for CFD consultants such as ourselves.
If you are interested in learning more, we highly recommend the two-part tutorial on getting started with OpenFOAM by Professor Mark Kimber of the University of Texas A&M embedded below. If you’re looking for a consultant to help you with OpenFOAM troubleshooting, training, or simulations, contact us, and we’ll provide whatever level of support you need. If you’re in or near the UK and need someone local, you can reach out to Robin Knowles at CFD Engine for help.