OpenFOAM on Windows
For the latest version of our Windows patch for OpenFOAM® visit "OpenFOAM 2.1.x on Windows 64-bit with MS MPI".
OpenFOAM is a versatile open-source multi-physics simulation toolbox. It can simulate fluid flow (CFD), solid dynamics and electromagnetics (CEM). OpenFOAM was originally developed for Unix platforms, such as Linux, and until now there has not been a method for producing a native Windows version.
Are you looking for a GUI driven, integrated simulation environment for Windows, Linux, and Mac incorporating a selection of the RANS OpenFOAM solvers and various import/export filters? Then try our Caedium RANS Flow add-on.
OpenFOAM is developed by OpenCFD Ltd., which is led by Henry Weller. The software and any derivatives (such as the work described here) are freely available under the GNU General Public License.
OpenFOAM Windows Port
There are a number of issues to address for a Windows version of OpenFOAM:
- OpenFOAM is dependent on a Unix build environment using tools such as bash scripts, make and flex.
- Some source filenames within OpenFOAM are identical except for upper and lower case differences (e.g., "vector.H", "Vector.H"). Windows does not, by default, differentiate between such names. Also, these names can clash with standard system filenames such as "vector.h".
- OpenFOAM makes system calls to Unix specific functions such as getenv.
- OpenFOAM has a cyclic dependency between its Pstream and OpenFOAM libraries.
One option to build and run OpenFOAM on Windows is to use Cygwin, which emulates a Linux environment for building and running Linux programs. To overcome filename clashes all names likely to clash must be changed.
While Cygwin is an option (as demonstrated by "The Unofficial OpenFOAM Cygwin Port" and "OpenFOAM extensions") for those that don't have access to a Linux computer, it comes with the overhead of slower runtime speed and is complex to configure.
A cross compiler allows compilation of source code on one computer-OS pair (such as Intel-Linux) that is destined to execute on another computer-OS pair (such as Intel-Windows). A Windows cross compiler (combining gcc and MinGW) running on Linux can use the OpenFOAM build environment with only minor modifications and requires no special treatment for the filename clashing issues.
By initially focusing on a serial (rather than parallel) version of OpenFOAM, the cyclic library dependency can be avoided by compiling the dummy Pstream files as part of the OpenFOAM library.
The remaining task is to provide the native Windows system calls to mimic the current native Unix system calls that OpenFOAM uses. Within the structure of the src/OpenFOAM library is the OSspecific directory that contains a Unix directory and is also where a new directory, MSwindows, will house the native Windows source code.
Once compiled the executables and libraries produced by a Windows cross compiler will not require any Linux emulation (such as Cygwin) and will run as fast as any other native Windows application.
A drawback of this cross compiler approach is the inability to build a new executable using the OpenFOAM libraries under Windows unless you are willing to enable the case sensitive file system option. Another option would be to combine the modifications described here with those in "The Unofficial OpenFOAM Cygwin Port" for a Windows build environment.
The following steps are required to produce a native Windows version of OpenFOAM 1.4.1 using a cross compiler:
- Configure, build, install and test a MinGW cross compiler for Windows running on Linux. I used the build-mingw script
#include_next <float.h>to the end of
"lib/gcc/mingw32/4.2.3/include/float.h" and remove it from
"mingw32/include/float.h" to include the right "float.h".
- Install the OpenFOAM 1.4.1 source distribution on Linux.
- Remove all lnInclude directories using wcleanLnIncludeAll in the OpenFOAM installation directory. Thanks to Jason Dale for pointing out this problem.
- Remove the directory src/OpenFOAM/OSspecific - it has to be out of the OpenFOAM source tree completely. It will be recreated by the patch.
- Patch (using the Linux patch command) the OpenFOAM 1.4.1 source distribution with our MinGW Windows modifications [last updated April 3, 2008 to v5].
- Copy wmkdep and dirToString from wmake/rules/linuxGcc to wmake/rules/linuxmingw32.
- Modify and source the .OpenFOAM-1.4.1/bashrc-mingw32 script to match your OpenFOAM 1.4.1 source location.
- Build using Allwmake in the OpenFOAM-1.4.1 directory on Linux.
- Transfer the OpenFOAM executables (applications/bin/linuxmingw32DPOpt/*.exe) and libraries (lib/linuxmingw32DPOpt/*.dll) to the Windows computer.
- Launch a Windows command prompt to run OpenFOAM.
On the Windows computer ensure the following:
- The WM_PROJECT_DIR and WM_PROJECT_USER_DIR variables are set.
- The .OpenFOAM-1.4.1 directory from the original source distribution is within the WM_PROJECT_DIR.
- The PATH variable is set to include the OpenFOAM executable and library locations.
With this method of building OpenFOAM for Windows the following features (there maybe more) are unavailable:
- job control scripts in bin (such as foamSolverSweeps)
- FoamX (the OpenFOAM pre-processor)
The following libraries are unlikely to build:
- metis and any dependents
You may need to copy foamFlex++ from a Linux OpenFOAM build to the MinGW build (applications/bin/linuxmingw32DPOpt).
OpenFOAM is a registered trademark of OpenCFD and is unaffiliated with Symscape.