Difference between revisions of "Installation/Windows/Outdated/Tip Cross Compiling OpenFOAM in Linux For Windows with MinGW"

From OpenFOAMWiki
(Introduction)
(List of known binaries for Windows: Added another link to Nishit Joseph's builds)
(23 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Introduction ==
+
= Introduction =
This is an exhaustive step by step guide on how to '''<u>fully</u>''' cross-compile OpenFOAM in Linux for Windows, for both 32 and 64 bits architectures (from and to), using the patches available [[:Media:PatchesNBatches.tar.gz|here]]. '''NOTE''': for cross-compiling in Cygwin for Windows, see the section [[#Using_Cygwin_for_cross-compiling_OpenFOAM|Using Cygwin for cross-compiling OpenFOAM]].
+
This is an exhaustive step by step guide on how to '''<u>fully</u>''' cross-compile OpenFOAM in Linux for Windows, for both 32 and 64 bits architectures (from and to), using the patches made available in each respective page. '''NOTE''': for cross-compiling in Cygwin for Windows, see the page [[Tip Using Cygwin for cross-compiling OpenFOAM|Using Cygwin for cross-compiling OpenFOAM]].
  
These patches were initially based on [http://www.symscape.com Symscape's] "v3" patch for OpenFOAM 1.5.x available [http://www.symscape.com/openfoam-1-5-x-on-windows here], but the latest version is based on [http://www.symscape.com Symscape's] "v9" patch for OpenFOAM 1.6.x available [http://www.symscape.com/openfoam-1-6-x-on-windows here]. These differ substantially from those patches. The build scripts for [http://www.mingw.org mingw] and [http://www.cadforte.com mingw-w64] were also based on the [http://www.symscape.com/files/articles/openfoam-windows/build-mingw build-mingw] script available on the 1.5.x and 1.6.x links.
+
These patches were initially based on [http://www.symscape.com Symscape's] "v3" patch for OpenFOAM 1.5.x available [http://www.symscape.com/openfoam-1-5-x-on-windows here], but as development evolves, occasional updates are made based on the latest patches by Symscape. Symscape's patches differ substantially from the patches available on this wiki; the main differences of the patches on this wiki are:
 +
*these aim to build OpenFOAM up to 100% of its original capabilities;
 +
*these also build most Third Party tools that OpenFOAM can use directly (Scotch, Metis);
 +
*provide additional scripts for building OpenFOAM and the maintenance of these patches;
 +
*target only Windows - Symscape's patches also have changes for Mac OS X;
 +
*these patches are only released for each major release of OpenFOAM - Symscape's patches are updated every 2-3 months.
 +
The build scripts for [http://www.mingw.org mingw] and [http://sourceforge.net/projects/mingw-w64/ mingw-w64] were also based on the [http://www.symscape.com/files/articles/openfoam-windows/build-mingw build-mingw] script available on the 1.5.x and 1.6.x links.
  
With this guide and available patches, you should be able to cross-compile the '''whole and complete''' OpenFOAM libraries and applications, using MPICH2 instead of Open MPI for parallel computing. You can cross-compile using [http://www.mingw.org mingw32] and/or [http://www.cadforte.com mingw-w64]. These enable you to build OpenFOAM 1.6 for Windows 32 and 64 bit versions, from Linux 32 and 64bit architectures. See the chapter [[#Notes on what doesn't work and why|Notes on what doesn't work and why]], for information on things that don't work properly.
+
With this guide and available patches, you should be able to cross-compile the '''whole and complete''' OpenFOAM libraries and applications, using MPICH2 instead of Open MPI for parallel computing. You can cross-compile using [http://www.mingw.org mingw32] and/or [http://sourceforge.net/projects/mingw-w64/ mingw-w64].
  
Versions these patches apply to:
+
= Patch versions =
{{version1.6}}
+
With the release of OpenFOAM 1.7 and the separate evolution of the patches for each OpenFOAM version, the once single wiki page will now branch into 3 parts:
 
+
<ul>
Support for this page is available at OpenFOAM's forum [http://www.cfd-online.com/Forums/openfoam-installation-windows/72813-cross-compiling-openfoam-1-6-linux-windows-32-64bits-mingw-w64.html here].
+
<li>This page will have the relevant information for all patch versions</li>
 
+
<li>One page for each patch version:<br><ul>
== Get OpenFOAM packages ==
+
<li>[[Tip Cross Compiling OpenFOAM 1.6 in Linux For Windows with MinGW]]{{version1.6}}</li>
<ol>
+
<li>[[Tip Cross Compiling OpenFOAM 1.7 in Linux For Windows with MinGW]]{{version1.7}}</li>
<li>In your Linux machine, open a terminal window ([http://en.wikipedia.org/wiki/Konsole example]) and create the folder '''$HOME/OpenFOAM''':
+
</ul></li>
<bash>mkdir $HOME/OpenFOAM
+
cd $HOME/OpenFOAM</bash>
+
</li>
+
<li>Get '''OpenFOAM-1.6.General.gtgz''' and '''ThirdParty-1.6.General.gtgz''' from the [http://www.opencfd.co.uk/openfoam/other.html OpenCFD's website] and copy/move them to the folder '''$HOME/OpenFOAM'''. If you want direct download from the terminal, then do:
+
<bash>wget http://downloads.sourceforge.net/foam/OpenFOAM-1.6.General.gtgz?use_mirror=mesh
+
wget http://downloads.sourceforge.net/foam/ThirdParty-1.6.General.gtgz?use_mirror=mesh</bash></li>
+
<li>Extract both files, by running in a terminal:
+
<bash>tar xzf OpenFOAM-1.6.General.gtgz
+
tar xzf ThirdParty-1.6.General.gtgz</bash></li>
+
</ol>
+
 
+
== Things needed for properly cross-compiling OpenFOAM 1.6 ==
+
*The packages needed in Linux (these are Ubuntu package names) are: '''flex git git-core build-essential python-dev libqt4-dev libreadline5-dev wget zlib1g-dev texinfo byacc bison'''.
+
*For the x86_64 Linux platform, you will also need: '''gcc-multilib'''
+
*The packages required for documentation are: '''doxygen graphviz'''.
+
The reference script for installing most of theses packages was [http://www.cfd-online.com/Forums/openfoam-installation/67998-install-openfoam-1-6-building-source-how.html#post228429 this].
+
 
+
== Using a specific gcc version for building the wmake binaries (Optional) ==
+
This is optional, because the current patch will use the system's gcc for building them (more specifically '''gcc''' as compiler name).
+
 
+
#Edit '''$HOME/.bashrc''' and add the following line to the end of it:<bash>. $HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc</bash>'''WARNING''': sometimes the leading dot doesn't work, so use the following instead:<bash>source $HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc</bash>'''NOTE''':You might want to edit '''$HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc''' and set the Linux architecture correctly, namely '''WM_ARCH_OPTION''' to '''32''' or '''64'''.<br><br>
+
#Two possibilities are now available:
+
##Use the system's gcc - edit '''$HOME/OpenFOAM/OpenFOAM-1.6/etc/settings.sh''' and change '''compilerInstall=OpenFOAM''' to '''compilerInstall=System'''.
+
##Or use the gcc that comes with the '''ThirdParty-1.6.General.gtgz''' package - again, two choices:
+
###You can compile the gcc by running the following line:<bash>(cd $HOME/OpenFOAM/ThirdParty-1.6 && makeGcc gcc-4.3.3)</bash>
+
###Or by getting the available compiled version for your Linux version ( [http://www.opencfd.co.uk/openfoam/linux.html ThirdParty-1.6.linuxGcc.gtgz] or [http://www.opencfd.co.uk/openfoam/linux64.html ThirdParty-1.6.linux64Gcc.gtgz] from [http://www.opencfd.co.uk OpenCFD's website]).
+
#Launch a new terminal and run the following line, thus building '''wmkdep''' and '''dirToString''':<bash>(cd $HOME/OpenFOAM/OpenFOAM-1.6/wmake/src && make)</bash>
+
 
+
== Applying patches ==
+
<ol>
+
<li>Copy/move the [[:Media:PatchesNBatches.tar.gz|PatchesNBatches.tar.gz]] file into the '''$HOME/OpenFOAM''' folder. Then unpack it by running:
+
<bash>tar -xzf PatchesNBatches.tar.gz</bash></li>
+
<li>A new folder is created, named '''pnb'''. Now to apply the patches, run from the '''$HOME/OpenFOAM''' folder:<bash>patch -p0 < pnb/OpenFOAM-1.6_patch
+
patch -p0 < pnb/ThirdParty-1.6_patch</bash></li>
+
<li>Still have to do some '''chmod'''''ding'', for new scripts to run properly. Run the following lines in the terminal:
+
<bash>chmod 744 $HOME/OpenFOAM/ThirdParty-1.6/build-mingw32
+
chmod 744 $HOME/OpenFOAM/ThirdParty-1.6/build-mingw-w32
+
chmod 744 $HOME/OpenFOAM/ThirdParty-1.6/build-mingw-w64
+
chmod 744 $HOME/OpenFOAM/ThirdParty-1.6/build-mingw-w64-45
+
chmod 744 $HOME/OpenFOAM/ThirdParty-1.6/makeGcc44
+
chmod 744 $HOME/OpenFOAM/ThirdParty-1.6/get-mpich2
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/src/mingwFunctions
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/src/Allclean
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc-mingw32
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc-mingw-w32
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc-mingw-w32-prof
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc-mingw-w32S
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc-mingw-w64
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc-mingw-w64-45
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc-mingw-w64-prof
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/applications/utilities/parallelProcessing/Allwmake
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/bin/tutowin
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/bin/foamDiff
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/bin/backupSourceFolder
+
chmod 744 $HOME/OpenFOAM/OpenFOAM-1.6/bin/backupFullFolder
+
</bash></li>
+
</ol>
+
 
+
== Getting Windows version of MPICH2 into the '''ThirdParty-1.6''' folder in Linux ==
+
There are two ways of getting OpenFOAM to compile with MPICH2:
+
#Use the '''get-mpich2''' script - the current patch has the include files and library definition files necessary to be able to link OpenFOAM to MPICH2. No need for changes, unless you want to build with a version of MPICH2 different from 1.1.1p1.
+
#Copy MPICH2 files from a Windows Installation. Three steps for this part:
+
#*Download and install in Windows the MPICH2, version 1.1.1p1 Win32 IA32 from [http://www.mcs.anl.gov/research/projects/mpich2/downloads/tarballs/1.1.1p1/ here]. Also get and install the 64bit version, if you wish to build OpenFOAM for Windows x64.
+
#*Create the folder '''$HOME/OpenFOAM/ThirdParty-1.6/mpich2-1.1.1p1''' in your Linux set up:<bash>mkdir $HOME/OpenFOAM/ThirdParty-1.6/mpich2-1.1.1p1</bash>
+
#*Copy the folders '''bin''', '''include''' and '''lib''' from the installed version of MPICH2 in Windows, into the folder '''ThirdParty-1.6/mpich2-1.1.1p1''' in Linux.
+
::The '''Allwmake''' script at the folder '''ThirdParty-1.6''' will take care of the rest. For now, the tough part is that, this way, you can only build one version of OpenFOAM (32 or 64bit) at a time.
+
In the [[#Tweaking environment options|next chapter]], you will learn how to configure the variable that is responsible for these two choices.
+
 
+
== Tweaking environment options ==
+
<ol>
+
<li>Choose which version you want to use:
+
:'''mingw32''': for getting a 32bit version of OpenFOAM, that builds on Linux i?86, using mingw;
+
:'''mingw-w32''': for getting a 32bit version of OpenFOAM, that builds on Linux i686 and x86_64, using mingw-w64;
+
:'''mingw-w64''': for getting a 64bit version of OpenFOAM, that builds on Linux i686 and x86_64, using mingw-w64;
+
 
+
Variants of the "bashrc" file that is inside the folder '''$HOME/OpenFOAM/OpenFOAM-1.6/etc''', have been created, to meet the most likely options. These are:
+
:;sample - <bashrc-version> : configured for <compiler>, <mingw version>, <MPI option>, <WM_COMPILE_OPTION>, <WM_ARCH_OPTION>
+
:;bashrc-mingw32 : configured for gcc-4.3.3, mingw32, MPI with MPICH2, Opt, DP, 32
+
:;bashrc-mingw-w32 : configured for gcc-4.4.2, mingw-w32, MPI with MPICH2, Opt, DP, 32
+
:;bashrc-mingw-w32-prof : configured for gcc-4.4.2, mingw-w32, No MPI, Prof, DP, 32
+
:;bashrc-mingw-w32S : configured for gcc-4.4.2, mingw-w32, MPI with MPICH2, Opt, SP, 32
+
:;bashrc-mingw-w64 : configured for gcc-4.4.2, mingw-w64, MPI with MPICH2, Opt, DP, 64
+
:;bashrc-mingw-w64-prof : configured for gcc-4.4.2, mingw-w64, No MPI, Prof, DP, 64
+
:;bashrc-mingw-w64-45 : configured for gcc-4.5.0, mingw-w64, MPI with MPICH2, Opt, DP, 64</li>
+
<li>After choosing the version you wish to build, edit the file '''$HOME/.bashrc''' and add to the end of it, a line analogous to the following line:
+
<bash>. $HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc-mingw32</bash>
+
'''WARNING''': sometimes the leading dot doesn't work, so use the following instead:
+
<bash>source $HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc-mingw32</bash></li>
+
<li>Before launching a new terminal, edit the picked file '''$HOME/OpenFOAM/OpenFOAM-1.6/etc/bashrc-''mingw version'''''. You have two additional variables that are configurable and non standard to the original OpenFOAM version:
+
*'''WM_PSTREAMLINK''' - this variable allows control over the linking method that is with the '''Pstream''' library. Two options are available:
+
*#If set to '''DONTLINKTOPSTREAM''', then depending on the variable '''WM_MPLIB''' being set to '''NONE''' or '''MPICH''', then OpenFOAM will be statically linked with that version; that means that it will only run without MPI capabilities or only run with MPICH2 installed, respectively.
+
*#If '''LINKTOPSTREAM''', then DLLs of the library Pstream are created, both '''dummy''' and '''MPICH2''' versions; this allows you to choose which version to use in Windows, without rebuilding OpenFOAM again. This way you get 2 versions of OpenFOAM with just one build, which is useful for various installation environments.
+
 
+
*'''WM_GETMPICH2''' - this variable controls whether MPICH2 is setup automatically or manually (see [[#Getting Windows version of MPICH2 into the ThirdParty-1.6 folder in Linux|Getting Windows version of MPICH2 into the '''ThirdParty-1.6''' folder in Linux]]). The two options are:
+
*#If set to '''GETMPICH2''', then '''wget''' is used for downloading the MPICH2 installation packages, and Wine will be used to unpack the '''".msi"''' files.
+
*#If '''DONTGETMPICH2''', then the script will assume that MPICH2 was set up manually.</li>
+
<li>Optional - If you want to use a version of MPICH2 other than '''1.1.1p1''', then edit the file '''$HOME/OpenFOAM/OpenFOAM-1.6/etc/settings.sh''' and find the line that has '''mpi_version=mpich2-1.1.1p1''' and change to the <u>version</u> you want, as shown [http://www.mcs.anl.gov/research/projects/mpich2/downloads/tarballs/ here].</li>
+
</ol>
+
 
+
== Build the cross compiler ==
+
<ol>
+
<li>Open a new terminal window or tab, so the edited file '''$HOME/.bashrc''' is executed, thus setting up the chosen OpenFOAM development environment (see [[#Tweaking environment options|Tweaking environment options]]).</li>
+
<li>Now go to the '''ThirdParty-1.6''' folder, in your new terminal:<bash>cd $WM_THIRD_PARTY_DIR</bash></li>
+
<li>Now you have to build the cross-compiler. Accordingly to the version you picked, you have type one of the following versions:
+
*to build the '''mingw32''' version, run:<bash>./build-mingw32 gcc-4.3.3</bash>
+
*to build the '''mingw-w32''' version, run:<bash>./build-mingw-w32</bash>
+
*to build the '''mingw-w64''' version, run:<bash>./build-mingw-w64</bash>
+
*to build the '''mingw-w64-45''' version, run:<bash>./build-mingw-w64-45</bash>
+
 
+
Alternatively, you can run:<bash>./makeGcc gcc-4.3.3</bash>
+
This will launch the respective '''''build-mingw*''''' script, according to the environment settings, but '''gcc-4.3.3''' will only be used for '''mingw32'''; and the script '''build-mingw-w64-45''' isn't called from '''makeGcc'''.
+
<br><br>
+
'''NOTE''': updates are bound to be done to the packages that these scripts use. Therefore, you should edit the script you have chosen, and check accordingly:
+
<ul><li>mingw32 - search for:
+
<bash>BINUTILS_ARCHIVE="binutils-2.19.1-src.tar.gz"
+
MINGW_ARCHIVE="mingwrt-3.15.2-mingw32-dev.tar.gz"
+
W32API_ARCHIVE="w32api-3.13-mingw32-dev.tar.gz"
+
REGEX_ARCHIVE="mingw-libgnurx-2.5.1-bin.tar.gz"
+
REGEX2_ARCHIVE="mingw-libgnurx-2.5.1-dev.tar.gz"</bash>
+
And check if they still exist or newer exists, on their [http://sourceforge.net/projects/mingw/files/ website].
+
 
+
'''WARNING''' Glitches in '''build-mingw32''' have been found - these will be fixed in a future patch version: in case you are unable to build the cross-compiler, then you need to do the following fixes:
+
*edit the build-mingw32 script;
+
*go to the line 64, that has <bash>TARGET=mingw32</bash>and change to <bash>TARGET=i686-pc-mingw32</bash>
+
*add in the next line: <bash>GCCVERSION=$1</bash>
+
These fixes will enable '''gmp''' to be properly built and for '''zlib''' to be properly available for usage with this cross-compiled version of OpenFOAM.</li>
+
<li>mingw-w?? - search for:
+
<bash>MINGW64PACKAGE="mingw-w64-src_4.4.1-1"</bash>
+
And check [http://sourceforge.net/projects/mingw-w64/files/ here] for new versions. Usually the package is around 80MB in size.
+
The line:
+
<bash>MINGW64PACKAGE2="mingw-w64-crt-release-1.0"</bash>
+
Relates to the stable run-time source version, available at [http://www.cadforte.com cadforte]. For the package '''mingw-w64-src_4.4.1-1''', this was necessary, because this wasn't the stable version yet. You can change either variables; you might even want to comment '''MINGW64PACKAGE2''' and related items to it, if you deem the package indicated in '''MINGW64PACKAGE''' to be stable enough.
+
 
+
'''NOTE''': if cadforte is offline, then search for the source snapshots available [http://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-snapshot/ here], and you might need to change two lines at '''build-mingw-w??''' that have:
+
<bash>MINGW64_URL2="http://www.cadforte.com/downloads/crt/stable_branch"
+
(...)
+
cp -rf mingw-w64/trunk/* mingw/</bash>
+
To:
+
<bash>MINGW64_URL2=MINGW64_URL
+
(...)
+
cp -rf mingw-w64/* mingw/</bash>
+
The ellipsis (...) indicated that there are dozens of lines separating the two lines to be changed.
+
</li>
+
 
</ul>
 
</ul>
</ol>
 
  
== Cross-Compile OpenFOAM in Linux for Windows ==
+
Support for these patches is available at OpenFOAM's forum [http://www.cfd-online.com/Forums/openfoam-installation-windows/72813-cross-compiling-openfoam-1-6-linux-windows-32-64bits-mingw-w64.html here].
<ol><li>Open a new terminal window or tab, so it will reset environment variables and add the newly built cross-compiling gcc into the executable path variable (see [[#Tweaking environment options|Tweaking environment options]]). Go to the project folder as so:
+
<bash>cd $WM_PROJECT_DIR</bash></li>
+
<li>Go to the folder "OpenFOAM-1.6" and run "Allwmake":
+
<bash>./Allwmake</bash>
+
This will build the entire OpenFOAM package. This does not include: '''Paraview''', '''ccm26ToFoam''', '''OpenMPI''' and code documentation.</li>
+
<li>Optional - If you want to create a '''CHM''' file in Windows, which will have the whole documentation in a single Compressed HTML '''index.chm''' file, then copy the file at the folder '''pnb''', as such:
+
<bash>cp ../pnb/Doxyfile ./doc/Doxygen/</bash>
+
Now, to recompile the code documentation, you should have added '''doc''' to '''./Allwmake''', as so:
+
<bash>./Allwmake doc</bash>
+
  
Or, after '''./Allwmake''' is all done, run:
+
= Information common to all patch versions =
<bash>./doc/Allwmake</bash>
+
== Building Paraview in Windows ==
 +
Since ParaView 3.8.0 was released [http://www.paraview.org/paraview/resources/software.html], it no longer seems necessary to put effort into building ParaView with MPICH2 and the native OpenFOAM reader. Kitware now provides ParaView with (and without) MS-MPI for parallel functionality, and the plugin from [[Contrib Parallelized Native OpenFOAM Reader for ParaView|here]] is already integrated.
  
In the chapter [[#Creating a Compiled HTML file for the code documentation|Creating a Compiled HTML file for the code documentation]] is explained how to finish this step.
+
Either way, in case you really want to build ParaView, the following instructions are the ones initially written on this wiki page:
</li>
+
<li>Optional - To build the mesh conversion utility '''ccm26ToFoam''', just run:
+
<bash>$FOAM_APP/utilities/mesh/conversion/Optional/Allwmake</bash>
+
 
+
The rest is done automatically, including downloading the libraries used for handling '''ccm''' files, and patching where necessary.</li>
+
<li>Optional, but essential for testing MPICH2, as described in the chapter [[#Using MPICH2 with OpenFOAM in Windows|Using MPICH2 with OpenFOAM in Windows]] - Build the parallel test application:
+
<bash>cd $WM_PROJECT_DIR
+
wmake applications/test/parallel</bash>
+
 
+
The built executable will be placed in the folder '''$HOME/OpenFOAM/$USER-1.6/application/bin/$WM_OPTIONS''', or '''$FOAM_USER_APPBIN''' for short.</li>
+
</ol>
+
 
+
== Copying the files to your Windows installation ==
+
<ol><li>The folders from '''$HOME/OpenFOAM''' that you have to copy are:
+
*'''OpenFOAM-1.6/applications/bin/$WM_OPTIONS'''
+
*'''OpenFOAM-1.6/etc'''
+
*'''OpenFOAM-1.6/bin'''
+
*'''OpenFOAM-1.6/tutorials'''
+
*'''OpenFOAM-1.6/lib/$WM_OPTIONS'''
+
*'''OpenFOAM-1.6/doc''' (optional)
+
*'''ThirdParty-1.6/mpich2-1.1.1p1/platforms/$WM_OPTIONS''' (or one of the versions you chose)
+
*'''ThirdParty-1.6/mpich2-1.1.1p1/source''' (optional, only if '''get-mpich2''' is used)
+
*'''$USER-1.6/applications/bin/$WM_OPTIONS''' (created in step 5 of the chapter [[#Cross-Compile OpenFOAM in Linux for Windows|Cross-Compile OpenFOAM in Linux for Windows]])
+
 
+
You can get all of these in a nice little package, by running at '''$HOME/OpenFOAM''':
+
<bash>tar -chjf OpenFOAM.$WM_OPTIONS.tar.bz2 OpenFOAM-1.6/applications/bin/$WM_OPTIONS \
+
OpenFOAM-1.6/etc OpenFOAM-1.6/bin OpenFOAM-1.6/tutorials OpenFOAM-1.6/lib/$WM_OPTIONS \
+
OpenFOAM-1.6/doc ThirdParty-1.6/mpich2-1.1.1p1/platforms/$WM_OPTIONS \
+
$USER-1.6/applications/bin/$WM_OPTIONS ThirdParty-1.6/mpich2-1.1.1p1/source</bash>
+
 
+
Or for an even smaller package:
+
<bash>tar --lzma -chf OpenFOAM.$WM_OPTIONS.tar.lzma OpenFOAM-1.6/applications/bin/$WM_OPTIONS \
+
OpenFOAM-1.6/etc OpenFOAM-1.6/bin OpenFOAM-1.6/tutorials OpenFOAM-1.6/lib/$WM_OPTIONS \
+
OpenFOAM-1.6/doc ThirdParty-1.6/mpich2-1.1.1p1/platforms/$WM_OPTIONS \
+
$USER-1.6/applications/bin/$WM_OPTIONS ThirdParty-1.6/mpich2-1.1.1p1/source</bash>
+
</li><li>
+
'''Optional''' - In case you have built more than one OpenFOAM version ('''mingw32''' '''mingw-w32''' '''mingw-w64'''), pack the whole '''bin''' and '''lib''' folders as so:
+
<bash>tar --lzma -chf OpenFOAM.mingw.tar.lzma OpenFOAM-1.6/applications/bin OpenFOAM-1.6/etc \
+
OpenFOAM-1.6/bin OpenFOAM-1.6/tutorials OpenFOAM-1.6/lib OpenFOAM-1.6/doc \
+
ThirdParty-1.6/mpich2-1.1.1p1/platforms $USER-1.6/applications/bin</bash></li>
+
<li>In order to recreate a folder base folder similar to the Linux setup, do the following steps:
+
*Copy the resulting compressed file to your Windows installation.
+
*Create a folder named '''OpenFOAM''', wherever you wish to have OpenFOAM running in Windows.
+
*Copy/Move the file compressed file into that folder.
+
*Unpack it using a compatible application. In case you don't know or have any, a suggestion is 7zip, available [http://www.7zip.org here].
+
</li>
+
<li>Unpack the [[:Media:PatchesNBatches.tar.gz|PatchesNBatches.tar.gz]] file to your OpenFOAM base folder in Windows. The following files should be copied from the folder '''pnb''' to the base folder OpenFOAM:
+
:'''DOS_Mode.bat'''
+
:'''setvars.bat'''
+
These two will help you setup the Windows Command Line environment for running OpenFOAM in Windows.
+
 
+
Edit '''setvars.bat''' and change the lines:
+
:'''set USER=ofuser'''
+
:'''set USERNAME=ofuser'''
+
to your Linux user name... Or change the '''$USER-1.6''' you have that came from Linux, to '''ofuser-1.6'''.
+
 
+
You can also choose which '''Pstream''' version to run. Find the following lines inside '''setvars.bat''':
+
:'''rem PICK ONE: dummy or MPICH'''
+
:'''rem set WM_MPLIB=dummy'''
+
:'''set WM_MPLIB=MPICH'''
+
And remove/add the comment word '''rem''' as you wish.
+
 
+
Now, to launch the command line, simply double-click on the file '''DOS_Mode.bat'''. In case you have built more than one version, a menu will show asking which version to use. NOTE: if the menu shows but doesn't stop, see the section [[#DOS_Mode.bat won't allow choosing which version to use | '''DOS_Mode.bat''' won't allow choosing which version to use]]</li>
+
<li>In order to get MPICH2 batch file to run in this command line, you'll have to copy the file '''pnb\gompi.bat''' to the folder '''OpenFOAM-1.6\bin'''.
+
 
+
MPICH2 will only work properly if you install it in Windows. If you used '''get-mpich2''' script in Linux (see [[#Getting Windows version of MPICH2 into the ThirdParty-1.6 folder in Linux|Getting Windows version of MPICH2 into the '''ThirdParty-1.6''' folder in Linux]]), you should have the installation file(s) in the folder '''ThirdParty-1.6\mpich2-1.1.1p1\source''', that came with the compressed file that has the cross-compiled OpenFOAM.
+
 
+
Now, you have (at least) two possible solutions:
+
<ol><li>Replicate the structure as in Linux - After installing MPICH2 in Windows, you can copy the binary folder to the respective version of cross-compiled OpenFOAM. For example '''C:\Program Files\MPICH2\bin''' or '''C:\Program Files (x86)\MPICH2\bin''' for the 32bit version in Windows x64.
+
The targeted folders to hold the contents of the MPICH2 '''bin''' folder, are:
+
*'''ThirdParty-1.6\mpich2-1.1.1p1\platforms\linuxmingw32DPOpt\bin'''
+
*'''ThirdParty-1.6\mpich2-1.1.1p1\platforms\linuxmingw-w32SPOpt\bin'''
+
*'''ThirdParty-1.6\mpich2-1.1.1p1\platforms\linuxmingw-w32DPOpt\bin'''
+
*'''ThirdParty-1.6\mpich2-1.1.1p1\platforms\linuxmingw-w64DPOpt\bin''' - this should have the 64bit version of MPICH2
+
</li>
+
<li>Edit the file '''setvars.bat''' and add the '''bin''' folder of your MPICH2 installation to the '''PATH''' variable near the end of the batch file. For example, add <bash>;C:\Program Files\MPICH2\bin</bash> to the end of line that starts with: <bash>set PATH=%PATH%;</bash>
+
'''CAUTION''': on Windows x64, this solution will require additional tweaking to the '''setvars.bat''', in case you want to run both versions (32 and 64bit) of OpenFOAM, in order to add <bash>;C:\Program Files\MPICH2\bin</bash>or<bash>;C:\Program Files (x86)\MPICH2\bin</bash> accordingly to the desired version.
+
</li></ol>
+
<li>In order to get Paraview batch file to run in this command line, you'll have to copy the file '''pnb\paraFoam.bat''' to the folder '''OpenFOAM-1.6\bin'''.
+
Paraview should be installed in, or copied to, one of the following folders, according to the versions installed:
+
:'''ThirdParty-1.6\paraview-3.6.1\platforms\linuxmingw32'''
+
:'''ThirdParty-1.6\paraview-3.6.1\platforms\linuxmingw-w32'''
+
:'''ThirdParty-1.6\paraview-3.6.1\platforms\linuxmingw-w64'''
+
The Paraview binaries themselves should be inside the folder '''bin'''. For example, for '''mingw32''' the Paraview binaries should be inside the folder '''ThirdParty-1.6\paraview-3.6.1\platforms\linuxmingw32\bin'''.<br>For more information on how to build Paraview for Windows with OpenFOAM file handling, see the chapter [[#Building Paraview in Windows|Building Paraview in Windows]].
+
</li>
+
<li>'''Tip''': with some tweaking of the OpenFOAM scripts in the folder '''OpenFOAM-1.6\bin''', it is possible to run OpenFOAM with [http://www.mingw.org/wiki/MSYS MSys]. This way you have more functionalities and a near Linux experience with OpenFOAM. And for MPICH2, you might want to make a copy of '''mpiexec.exe''' to '''mpirun.exe'''.
+
</li>
+
</ol>
+
 
+
== Building Paraview in Windows ==
+
 
<ol><li>This is a pain to do, and yet, quite simple once you get the handle of it. Nonetheless, here won't be described the full building procedure. You can follow the tutorial available [[Contrib Parallelized Native OpenFOAM Reader for ParaView|here]] in this wiki and use that plug-in for reading '''.foam''' files directly from Paraview, without building the original plug-ins that come with OpenFOAM and be able to handle large and/or parallelized cases.
 
<ol><li>This is a pain to do, and yet, quite simple once you get the handle of it. Nonetheless, here won't be described the full building procedure. You can follow the tutorial available [[Contrib Parallelized Native OpenFOAM Reader for ParaView|here]] in this wiki and use that plug-in for reading '''.foam''' files directly from Paraview, without building the original plug-ins that come with OpenFOAM and be able to handle large and/or parallelized cases.
  
Line 290: Line 54:
 
'''CAUTION''': the MSys terminal version will make your password visible on screen!</li>
 
'''CAUTION''': the MSys terminal version will make your password visible on screen!</li>
 
<li>Test the parallel system. For that, you'll have to:
 
<li>Test the parallel system. For that, you'll have to:
#In the OpenFOAM terminal, go to the folder '''ofuser-1.6''' (or '''$USER-1.6''') and unpack the test case [[:File:PTestCase.tar.gz?|PTestCase.tar.gz?]];
+
#In the OpenFOAM terminal, go to the folder '''ofuser-1.6''' (or '''$USER-1.6''') and unpack the test case [[:Media:PTestCase.tar.gz|PTestCase.tar.gz]];
 
#Go into the '''pTestCase''' case folder;
 
#Go into the '''pTestCase''' case folder;
 
#Type:<bash>gompi parallelTest</bash>It will test communications between two instances of '''parallelTest.exe'''. If successful, it should display something like this:
 
#Type:<bash>gompi parallelTest</bash>It will test communications between two instances of '''parallelTest.exe'''. If successful, it should display something like this:
Line 351: Line 115:
 
</ol>
 
</ol>
  
== Creating a Compiled HTML file for the code documentation ==
+
= Miscellaneous information =
As described in the chapter [[#Cross-Compile OpenFOAM in Linux for Windows|Cross-Compile OpenFOAM in Linux for Windows]], you can created a Compiled HTML file of the code documentation, from the '''Doxygen''' files re-compiled in that chapter. Keep in mind that this is an optional feature. The code documentation can prove useful in situations where the manuals prove to be insufficient to explain the more intrinsic details about the case dictionaries.
+
== Differences between mingw32 and mingw-w32 versions ==
<ol><li>When you packed the files for transport from Linux to Windows (see [[#Copying the files to your Windows installation|Copying the files to your Windows installation]]), you should have included the '''OpenFOAM-1.6/doc''' folder, and it should be available in your Windows installation.
+
[http://www.mingw.org/wiki/MinGW MinGW] is the true name of '''mingw32'''. As for '''mingw-w32''' (32bit version of '''mingw-w64'''), as cited from [http://www.cadforte.com/index.html here (dead link)]:
So, check if you have the files '''index.hhp''', '''index.hhc''' and '''index.hhk''' in the folder '''OpenFOAM-1.6\doc\Doxygen\html'''. If:
+
<blockquote>Mingw-w64 began as a spin-off from the mingw.org project, with the original intent of building for 64-bit targets.</blockquote>
*Only these 3 files seem to be missing, you'll have to go back to the chapter [[#Cross-Compile OpenFOAM in Linux for Windows|Cross-Compile OpenFOAM in Linux for Windows]] and follow the steps that talk about code documentation.
+
Nonetheless, '''mingw-w64''' has retro-compatibility with the 32bit MinGW version, thus enabling a 2-in-1 build package for 32 and 64bit Windows systems.
*No files exist in that folder, go back to the chapter [[#Copying the files to your Windows installation|Copying the files to your Windows installation]] and check if you copied the '''doc''' folder.</li>
+
<li>Get and install the HTML Help Workshop, which is available [http://www.microsoft.com/downloads/details.aspx?FamilyID=00535334-c8a6-452f-9aa0-d597d16580cc&displaylang=en here], so you can use it to compile the HTML files into a single CHM file.</li>
+
<li>Now launch the OpenFOAM Command Window (run '''DOS_Mode.bat'''). Do:
+
<bash>cd OpenFOAM-1.6\doc\Doxygen
+
subst K: .</bash>
+
This will make the folder '''OpenFOAM-1.6\doc\Doxygen''' be also a virtual drive, letter '''K'''. Use another letter if that is already occupied. Don't close the command window.
+
  
'''NOTE''':This step is required, because HTML Help Workshop is a very old application (copyright 1996-1999) and is very ''picky'' and simple application. So long path names aren't very tolerable.
+
The main difference between '''mingw32''' and '''mingw-w32''', is that MinGW is a stable and proven build tool and run-time for Windows, while the mingw-w64 project is still under fierce development and only in October 29th of 2010 they released their first stable version. Therefore, it is only estimated that the '''mingw32''' version could provide less headaches than '''mingw-w32'''.
</li>
+
<li>Launch the application HTML Help Workshop from Windows. On the window HTML Help Workshop, go to the menu command File->Open and open the file '''K:\html\index.hhp'''.</li>
+
<li>Optional - you can change the target path and name for the '''index.chm''' file in the left side bar, that appears when you open the project. Double click on the line '''Compiled file=index.chm'''.
+
As said before, keep paths simple. Best advice would be '''..\index.chm''', since it is a short relative path, and will be away from the +46700 files that exist inside the '''html''' folder.</li>
+
<li>Run the Compile command (File->Compile). It will take some time to compile. Hopefully it won't crash.</li>
+
<li>If it hasn't crashed, then you will have a brand new 74MiB [http://en.wikipedia.org/wiki/Mebibyte] '''index.chm''' file, with added index and search functions.
+
'''NOTE''': the '''<u>S</u>earch for''' edit box in the top right of the page won't work. Use the left side bar that comes with the '''index.chm''' help window.</li>
+
<li>Cleaning up:
+
*In the Command Window that you opened a while ago, remove the virtual drive letter, by running:<bash>subst K: /D</bash>You can now close that command window.
+
*Copy the '''index.chm''' file to a safe place, and remove the '''html''' folder in '''OpenFOAM-1.6\doc\Doxygen'''. '''WARNING''': to remove the +46700 files that exist therein, will take a very long time.</li>
+
</ol>
+
  
== Notes on what doesn't work and why ==
+
== Using Cygwin for cross-compiling OpenFOAM ==
=== chtMultiRegionFoam doesn't work properly ===
+
For cross-compiling in Cygwin for Windows, see the page [[Tip Using Cygwin for cross-compiling OpenFOAM|Using Cygwin for cross-compiling OpenFOAM]].
The solver '''chtMultiRegionFoam''' now does work properly on Windows, but you have to do some tweaking to the files that refer to the file '''K'''. This is due to a file name conflict of '''k''' and '''K'''. The field name '''K''' is hard-coded in the executable, and it isn't changeable via the case files '''changeDictionaryDict'''. But the current patches take care of this, by defining for the Windows build that the K field is written on the '''KK''' file.
+
  
The changes necessary to the naming of the field '''K''', on the '''chtMultiRegionFoam''' cases, taking as an example the tutorial case '''heatTransfer/chtMultiRegionFoam/multiRegionHeater''':
+
= Other Important Links =
<ul>
+
<li>If at the folder '''0''' there is only one file '''k''' or '''K''' and no '''KK''', then you need to rename the '''K''' file to '''KK''' before packaging in Linux.</li>
+
<li>Inside the folder '''system''', there are 5 folders of the regions of the heater, namely: '''bottomAir heater leftSolid rightSolid topAir'''. For each region, edit the '''changeDictionaryDict''' file, and change (only when found):
+
<bash>neighbourFieldName T;
+
K              K;
+
(...)
+
}
+
  
K
+
== List of known building instructions ==
{
+
This is a list of links of build instructions of cross-compiled and natively compiled versions of OpenFOAM, using '''mingw''' and/or '''mingw-w64''':
</bash>
+
*[http://www.symscape.com Symscape's] cross-compilations:
To:
+
**OpenFOAM 1.4.1 mingw32 version [http://www.symscape.com/openfoam-on-windows]
<bash>neighbourFieldName T;
+
**OpenFOAM 1.5.x mingw32 version [http://www.symscape.com/openfoam-1-5-x-on-windows]
K              KK;
+
**OpenFOAM 1.6.x mingw32 (no MPI) version [http://www.symscape.com/openfoam-1-6-x-on-windows] and OpenFOAM 1.6.x mingw-64 (with MS-MPI) version [http://www.symscape.com/openfoam-1-6-x-on-windows-64-mpi]
(...)
+
**OpenFOAM 1.7.x mingw-64 (with MS-MPI) version [http://www.symscape.com/openfoam-1-7-x-on-windows-64-mpi]
}
+
**OpenFOAM 2.0.x mingw-64 (with MS-MPI) version [http://www.symscape.com/openfoam-2-0-x-on-windows-64-mpi]
 +
**OpenFOAM 2.1.x mingw-64 (with MS-MPI) version [http://www.symscape.com/openfoam-2-1-x-on-windows-64-mpi]
 +
*[http://sourceforge.net/users/apostol Julian's] OpenFOAM 1.5 files for native build in Windows [http://sourceforge.net/projects/openfoam-mswin/files/] with mingw32 and CodeBlocks (instructions included inside files)
 +
*[http://www.bluecape.com.pt blueCAPE's] cross-compilations:
 +
**OpenFOAM 1.5.x mingw32 version with MPICH1 [http://www.cfd-online.com/Forums/openfoam-installation/57248-openfoam-mingw-crosscompiler-hosted-linux-6.html#post206728] and MPICH2 [http://www.cfd-online.com/Forums/openfoam-installation/57248-openfoam-mingw-crosscompiler-hosted-linux-7.html#post206729]
 +
**OpenFOAM 1.6 and 1.7.0 mingw32, mingw-w32 and mingw-w64 (all with MPICH2)... is this tutorial you are reading...
 +
**OpenFOAM 2.0.x and 2.1.x mingw32, mingw-w32 and mingw-w64 with Open-MPI, MPICH2 and MS-MPI: [http://code.google.com/p/bluecfd-singlecore/wiki/CrossCompilingOpenFOAM20]
 +
*[http://www.geocities.co.jp/SiliconValley-SantaClara/1183/ Yuu Kasuga's] blog (in Japanese). It use to have a few entries about cross-compiling and using OpenFOAM in Windows. Only recover link so far is for OpenFOAM 1.7.x using Symscape's patches: [http://www.geocities.jp/penguinitis2002/study/OpenFOAM/OpenFOAM-1_7_x-win64-mpich.html]
 +
*[http://www1.parkcity.ne.jp/kojani/index_en.html Kojani's] blog (available in English, Japanese and Korean). Provides instructions and source code for compiling OpenFOAM 1.7.1 directly on Windows while using MSys: [http://www1.parkcity.ne.jp/kojani/of-171_en.html]
  
KK
+
== List of known binaries for Windows ==
{
+
Distributable binaries:
</bash></li>
+
*Free: [http://sourceforge.net/users/apostol Julian's] OpenFOAM for MS windows binary release - OpenFOAM 1.5 built natively in Windows [http://sourceforge.net/projects/openfoam-mswin/] using mingw32 and CodeBlocks (note: development seems to have been dropped)
<li>While still inside the folder of each region, also edit the files '''fvSchemes''' and change (where needed):
+
*Free: On [http://www.geocities.co.jp/SiliconValley-SantaClara/1183/study/OpenFOAM/OpenFOAM-1_6-win32.html Yuu Kasuga's] blog (in Japanese) is a short tutorial on how to install and use the unofficial [http://sourceforge.net/projects/openfoam16wi32/ openfoam16wi32 project at SourceForge], which provides OpenFOAM 1.6 32bit binaries for Windows.
<bash>laplacian(KK,T) Gauss linear limited 0.333;</bash>
+
*Free: Nishit Joseph's builds:
To:
+
** [https://sourceforge.net/projects/openfoam-170/ OpenFOAM 1.7.0 for Windows 32 bit], based on this wiki page. Support thread for this build available here: [http://www.cfd-online.com/Forums/openfoam-installation-windows/82980-openfoam-1-7-0-win32.html OpenFOAM-1.7.0 for Win32]
<bash>laplacian(K,T) Gauss linear limited 0.333;</bash></li>
+
** [http://sourceforge.net/projects/openfoam21win64/ OpenFOAM-2.1.x for Win64], based on Symscape's instructions but built with Open-MPI. Support thread for this build available here: [http://www.cfd-online.com/Forums/openfoam-installation-windows-mac/109100-windows-x64-binaries-openfoam-2-1-x-using-openmpi.html Windows (x64) Binaries for OpenFOAM-2.1.x using OpenMPI]
<li>Edit the file '''Allrun''' at the base of the case folder, and change:
+
*Free: [http://www.bluecape.com.pt blueCAPE's] blueCFD-SingleCore: OpenFOAM 2.0.x and 2.1.x for Windows XP, Vista and 7, both 32 and 64bit [http://code.google.com/p/bluecfd-singlecore/]
<bash>rm -f 0*/$i/{cp,K,rho}</bash>
+
*Free: [http://www.building-engineering.de/index.php?lang=en Tian Building Engineering] provides 64bit Single Precision binaries at their download section [http://www.building-engineering.de/index.php?lang=en&Itemid=139]
To:
+
*Free: [http://www.ods-engineering.com ODS Engineering] also provides 64bit binaries, but it's unknown which precision [http://www.ods-engineering.com/downloads] - Note: it requires registration.
<bash>rm -f 0*/$i/{cp,KK,rho}</bash></li>
+
*Paid: [http://www.symscape.com Symscape's] OpenFlow: OpenFOAM for Windows [http://www.symscape.com/product/openflow]
</li>
+
*Paid: [http://www.bluecape.com.pt blueCAPE's] blueCFD: OpenFOAM for Windows XP, Vista and 7, both 32 and 64bit [http://www.bluecape.com.pt/blueCFD]
</ul>
+
*Unknown status: [http://www.scai.fraunhofer.de Fraunhofer SCAI] project - Porting Open Source HPC Software to Microsoft Windows Platforms [http://www.scai.fraunhofer.de/openmshpc/softwarepakete/openfoam.html] - availability is unknown, but a contact page exists [http://www.scai.fraunhofer.de/openmshpc/kontakt.html]
  
The source code change that was implemented, and that you should keep in mind when making your OpenFOAM applications was done in the files:
+
== List of benchmarks on Windows ==
<bash>OpenFOAM-1.6/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H
+
OpenFOAM-1.6-1/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/createSolidFields.H</bash>
+
And just modified the reference to '''K''' like this:
+
<cpp>#if defined( WIN32 ) || defined( WIN64 )
+
                    "KK",
+
#else
+
                    "K",
+
#endif
+
</cpp>
+
  
=== '''motorBike''' case and '''foamToVTK''' in Windows ===
+
Benchmarks and run-times running OpenFOAM cross-compiled with mingw:
If you want to use '''foamToVTK''' on the tutorial case '''motorBike''', you will have to run the script '''fixToWindows''' available at the '''motorBike''' case, so it can fix the surface names with "%" in the STL file and in some of the case dictionaries. The script can be executed on MSys or on Linux.
+
 
+
=== '''motorBike''' case in the package '''OpenFOAM-1.6.General.gtgz''' doesn't work well ===
+
The '''motorBike''' case available with the original 1.6 package doesn't work properly. These patches will not fix it. Please get the [http://www.opencfd.co.uk/openfoam/download.html#download OpenFOAM 1.6.x git version], if you want a working '''motorBike''' case.
+
 
+
=== '''foamToVTK''' made '''.vtk''' files that Paraview can't read ===
+
This is likely still a bug that occurs in creating binary VTK files in Windows. Please use the switch '''-ascii''' for creating these files:
+
<bash>foamToVTK -ascii</bash>
+
 
+
Additionally, sometimes the folder '''0''' (the start time for the simulation), doesn't have valid mesh information. For these situations, use the switch '''-time''' or '''-latestTime''', for retrieving specific time snapshots. For example, for 500s, use:
+
<bash>foamToVTK -time 500</bash>
+
For the latest time snapshot, use:
+
<bash>foamToVTK -latestTime</bash>
+
 
+
=== Can't build cross-compiler version '''mingw32''' in Linux x86_64 ===
+
With the build script for mingw32, that comes in these patches, can't build its cross-compiler under Linux x86_64.
+
 
+
'''Solution''': please use the mingw-w32 version, or try to fix the '''build-mingw32''' script yourself!
+
 
+
=== '''libscotch''' is limited in Windows ===
+
The library '''libscotch''' can't handle compression in Windows, due to nonexistent native Windows '''pipe''' and '''fork''' functions. [http://www.mingw.org/wiki/MSYS MSys] and [http://www.cygwin.com Cygwin] have these implemented, but effort has not been invested in re-implementing them here.
+
 
+
=== Fast memory allocation issues in Windows ===
+
'''Hoard''' and '''fbsdmalloc''' are not enabled for the '''mingw''' versions.
+
 
+
'''Solution''':There is a native build '''winhoard''' library [http://www.cs.umass.edu/~emery/hoard/using.html#Windows online], but effort was not put into this for now. An implementation of '''fbsdmalloc''' wasn't found for '''mingw''' nor native Windows.
+
 
+
=== Symbolic links in the tutorials ===
+
To copy the tutorials properly to Windows, use the command:
+
<bash>tar -chjf ../tutorials.tar.bz2 tutorials</bash>
+
at the folder '''$HOME/OpenFOAM/OpenFOAM-1.6'''. The '''h''' switch will make copies of the symbolically linked folders and files, thus removing the symbolic links. You can then uncompress the '''tutorials.tar.bz2''' file in your Windows installation.
+
 
+
=== Building OpenFOAM with gcc-4.4.? and gcc-4.5.0 ===
+
To get OpenFOAM to build with gcc-4.4.? and gcc-4.5.0, I used the information available [http://www.cfd-online.com/Forums/openfoam-installation/65039-openfoam-1-5-solaris-compilation-problem-calling-octreedatapoint-constructor.html#post218073 here].
+
 
+
=== Open MPI in Windows ===
+
Building Open MPI with the '''mingw''' cross-compilers was not tested. References to it currently running in Windows using '''mingw''' have not been found.
+
 
+
'''Solution''': For MPI functionality, MPICH2 is used in these patches.
+
 
+
=== Cross-compiled version mingw-w64 takes longer to start applications ===
+
After some investigation, it seems that due to [http://www.cadforte.com mingw-w64] still being in fierce development (still considered somewhat like ''beta''), the '''mingw-w64''' version of OpenFOAM takes about 12 seconds (much more if executed in virtual machines) to start each application in Windows x64. The 32bit versions take 3 seconds or less, depending the machine type (virtual or real). During that period, the [http://en.wikipedia.org/wiki/Windows_Task_Manager Task Manager] shows that the memory is being slowly filled.
+
Profiling '''blockMesh''' was also tested, to try to isolate the problem (see [[#Profiling OpenFOAM applications with mingw cross-compiled version|Profiling OpenFOAM applications with '''mingw''' cross-compiled version]]), but the statically built profiling version of '''blockMesh''', ''booted'' in less than a second. So, there are at least two possible of the conclusions:
+
*The OpenFOAM libraries do some matrix allocations and/or re-allocations, when they are loaded by the applications;
+
*The mingw-w64 version still has issues with loading multiple DLLs from within DLLs and '''all that'''...
+
 
+
=== Some tutorials don't work in Windows ===
+
Some tutorials require building auxiliary executables or libraries. These have to be cross-compiled in Linux.
+
<br>
+
{{version1.6}} The tutorials are:
+
<bash>basic\potentialFoam\cylinder
+
compressible\rhoCentralFoam\biconic25-55Run35
+
heatTransfer\buoyantPisoFoam\hotRoom
+
incompressible\MRFSimpleFoam
+
incompressible\simpleSRFFoam
+
lagrangian\rhoPisoTwinParcelFoam
+
multiphase\interDyMFoam\ras\sloshingTank3D6DoF
+
multiphase\interFoam\MRFInterFoam</bash>
+
 
+
=== Tutorial scripts don't work in Windows ===
+
Actually, they work, but only if you use the [http://www.mingw.org/wiki/MSYS MSys] terminal. If you want to stick to the Windows Command Line, then use the '''sh.exe''' executable that comes with MSys (should be visible in the search PATH, i.e., add the MSys '''bin''' folder to the '''setvars.bat''' file). For example, running the '''Allrun''' script in a tutorial case, do like so:
+
<bash>sh Allrun</bash>
+
 
+
=== DOS_Mode.bat won't allow choosing which version to use ===
+
Apparently, '''choice.exe''' isn't installed by default on all Windows versions. You have two choices:
+
#Install the resource kit that should be in your Windows CD/DVD.
+
#Download the version that came with the Windows 98 resource kit from [ftp://ftp.microsoft.com/Services/TechNet/samples/PS/Win98/Reskit/SCRPTING/CHOICE.EXE here], and put it in the base folder of your OpenFOAM installation.
+
 
+
== Notes on added functionalities with these patches ==
+
 
+
=== Building '''ccm26ToFoam''' ===
+
'''ccm26ToFoam''' builds properly with these patches, because the fixes in the git version are also in these patches; the missing Make files for the ccm26io library are also in a patch file created in the '''ThirdParty-1.6''' folder. The '''Make''' files came from [http://www.cfd-online.com/Forums/openfoam-bugs/62300-of15-libccmio-thus-ccm26tofoam-do-not-compile.html this post].
+
To build '''ccm26ToFoam''', run the script in Linux:
+
<bash>$FOAM_APP/utilities/mesh/conversion/Optional/Allwmake</bash>
+
 
+
=== Keeping track of symbolic links in tutorials ===
+
Running the script '''tutowin''' at the folder '''$HOME/OpenFOAM/OpenFOAM-1.6''', you will be shown the tutorial folders that are symbolically linked. Use this list as a reference to where you should create '''README''' files, indicating where folders will be copied from. For the tutorials available in the OpenFOAM 1.6, this is already done by these patches. So you can use '''tutowin''' for future updates.
+
 
+
=== Changes in '''settings.sh''' ===
+
The script '''settings.sh''' has been modified quite a bit. The '''platform''' build names for '''gcc''' have been changed to include the architecture, and '''gcc-4.4.2''' has been added to the list of compilers. The '''dummy''' '''libPstream''' has been added as an MPI library named '''NONE''', so '''libPstream''' will be added to the library search path.
+
 
+
=== Building locally with multiple cores ===
+
The '''bashrc-*''' scripts have integrated in them the automatic selection of how many cores to use to build. This was copied from the '''makeGcc''' build script available in the '''$HOME/OpenFOAM/ThirdParty-1.6'''.
+
 
+
=== Building '''mingw''' cross-compilers ===
+
Build scripts have been added to the folder '''$HOME/OpenFOAM/ThirdParty-1.6''', to aid in building '''mingw32''', '''mingw-w32''' and '''mingw-w64''' cross-compilers.
+
 
+
=== Getting MPICH2 automatically in Linux ===
+
A script named '''get-mpich2''' for creating a library link object for '''MPICH2MPI.DLL'''. This way it doesn't need to download the files into your Linux machine nor does it need Wine to unpack. To update the definition files and header files, check the contents of the folder '''ThirdParty-1.6/mpich2-1.1.1p1''' and see what header files are needed and copy them from an MPICH2 installation folder in your Windows machine. The definition files were retrieved from the source package of MPICH2.
+
 
+
The other hypothesis, is to install MPICH2 firstly in Windows and copy the files to your Linux+OpenFOAM setup (see [[#Getting Windows version of MPICH2 into the ThirdParty-1.6 folder in Linux|Getting Windows version of MPICH2 into the '''ThirdParty-1.6''' folder in Linux]]).
+
 
+
=== Compiling HTML files into CHM ===
+
'''Doxyfile''' is available as a separate file, inside the package [[:Media:PatchesNBatches.tar.gz|PatchesNBatches.tar.gz]]. See chapter [[#Creating a Compiled HTML file for the code documentation|Creating a Compiled HTML file for the code documentation]] for more information.
+
 
+
=== Creating new patches ===
+
'''$HOME/OpenFOAM/OpenFOAM-1.6/bin/foamDiff''' is a script created specifically for creating these patches, without requiring to cleanup the binaries and '''''lnIncludes'''''. It requires that you have a second ''mint condition'' folder with the original files. In other words, your '''$HOME/OpenFOAM''' folder should have, for example, the folders:
+
<bash>OpenFOAM-1.6
+
OpenFOAM-1.6-orig
+
ThirdParty-1.6
+
ThirdParty-1.6-orig</bash>
+
 
+
Then use '''foamDiff''' from the folder '''$HOME/OpenFOAM''' as so:
+
<bash>foamDiff OpenFOAM-1.6 OpenFOAM-1.6-orig OpenFOAM-1.6_patch_new
+
foamDiff ThirdParty-1.6 ThirdParty-1.6-orig ThirdParty-1.6_patch_new</bash>
+
Legend: '''foamDiff <FolderNew> <FolderOrig> <patch_name>'''
+
 
+
=== MPFR 2.4.1 was missing 3 files ===
+
The '''mpfr-2.4.1''' folder that comes with the original '''ThirdParty-1.6.General.gtgz''' package is missing 3 files: '''log2.c''', '''log1p.c''' and '''log10.c'''. These are added by the patches.
+
 
+
=== Profiling OpenFOAM applications with '''mingw''' cross-compiled version ===
+
Profiling with '''mingw''' isn't as clean as with Linux, since '''mingw''' doesn't support DLL profiling. So some tweaks have been made to make it possible to build fully static executables... but for now, only '''blockMesh''' and '''potentialFoam''' are working with the '''Prof''' option. See the '''options''' file in the '''Make''' folder on each of these application source code folders, to see what needs to be done on the other applications.
+
 
+
=== Backing up development folders ===
+
Although OpenFOAM already comes with scripts for packing the source codes and builds, it doesn't suit every type of backing up solution. These patches give you two additional scripts for backing up:
+
 
<ul>
 
<ul>
<li><bash>backupFullFolder the_folder</bash>
+
<li>{{version1.4.1}} icoDyMFoam (movingCone) OpenFOAM tutorial [http://www.symscape.com/openfoam-on-windows#comment-129]</li>
This will do a full backup of your folder to the file '''the_folder.Full.mingw.(date).tar.bz2''' where '''(date)''' is the date of when you do the backup. It is designed to do a full backup of the folders '''ThirdParty-1.6''' and '''OpenFOAM-1.6''', but should work with any folder.</li>
+
<li>{{version1.4.1}} Xoodles pitzDaily3D OpenFOAM tutorial [http://www.symscape.com/openfoam-on-windows#comment-131]</li>
<li><bash>backupSourceFolder the_folder</bash>
+
<li>{{version1.6}} simpleFoam motorBike OpenFOAM tutorial from 1.6.x, running with OpenFOAM 1.6 [http://joomla.bluecape.com.pt/index.php?option=com_mamblog&Itemid=43&task=show&action=view&id=40&Itemid=43&lang=en]</li>
This will do a backup of only the source files of your folder to the file '''the_folder.Source.mingw.(date).tar.lzma''' where '''(date)''' is the date of when you do the backup. It is designed to do a full backup of only the files that are source codes and aren't downloadable without additional independent patching, without the need to remove files and folders from your builds. Once again, this script is designed to work with the folders '''ThirdParty-1.6''' and '''OpenFOAM-1.6''', but should work with any folder that exists in the ''workspace of OpenFOAM''.</li>
+
<li>{{version1.7}} simpleFoam motorBike OpenFOAM tutorial from 1.6.x, running with OpenFOAM 1.6 in Linux and 1.7.0 in Windows [http://joomla.bluecape.com.pt/index.php?option=com_mamblog&Itemid=43&task=show&action=view&id=40&Itemid=43&lang=en]</li>
 +
<li>{{version2.0}}{{version2.1}} simpleFoam motorBike OpenFOAM tutorial from 2.0.x, running with OpenFOAM 2.0.x and 2.1.x in Linux and in Windows [http://code.google.com/p/bluecfd-singlecore/wiki/Runtimes202_211]</li>
 
</ul>
 
</ul>
  
== Miscellaneous information ==
+
== Tutorials known to work on Windows ==
=== Differences between mingw32 and mingw-w32 versions ===
+
Tutorials known to work with cross-compiled versions of OpenFOAM:
[http://www.mingw.org/wiki/MinGW MinGW] is the true name of '''mingw32'''. As for '''mingw-w32''' (32bit version of '''mingw-w64'''), as cited from [http://www.cadforte.com/index.html here]:
+
<blockquote>Mingw-w64 began as a spin-off from the mingw.org project, with the original intent of building for 64-bit targets.</blockquote>
+
Nonetheless, '''mingw-w64''' still has retro-compatibility with the 32bit MinGW version, thus enabling a 2-in-1 build package for 32 and 64bit Windows systems.
+
 
+
The main difference between '''mingw32''' and '''mingw-w32''', is that MinGW is a stable and proven build tool and run-time for Windows, while the mingw-w64 project is still under fierce development and has only recently (20091029) released their [http://www.cadforte.com/downloads.html#crtstable first stable version]. Therefore, it is only estimated that the '''mingw32''' version should provide less headaches than '''mingw-w32'''.
+
 
+
=== Using Cygwin for cross-compiling OpenFOAM  ===
+
In Cygwin 1.5, [http://cygwin.com/faq/faq-nochunks.html#faq.using.case-sensitive managed mounts] were introduced. After some testing, it was discovered that OpenFOAM has some very long path names, which aren't handled properly by Cygwin's managed mounts, due to path size limit [http://www.cfd-online.com/Forums/openfoam-news-announcements-other/70063-cross-compiling-openfoam-1-6-linux-windows-32-64bits-mingw-w64.html#post236797].
+
 
+
As of Cygwin 1.7 (now stable, since 23rd of December of 2009) [http://cygwin.com/faq/faq-nochunks.html#faq.using.case-sensitive managed mounts] were dropped and POSIX mounts were introduced [http://cygwin.com/1.7/cygwin-ug-net/using.html#mount-table], as well as file paths increased to 4096 characters [http://cygwin.com/1.7/cygwin-ug-net/ov-new1.7.html]. The POSIX mount relies on a hidden feature of Windows [http://support.microsoft.com/kb/929110], that enables NTFS POSIX compatibility system, also used by Interix's SFU/SUA [http://en.wikipedia.org/wiki/Interix], thus enabling full case sensitivity for files.
+
 
+
In other words, as of Cygwin 1.7, it is possible to compile and cross-compile OpenFOAM directly in Windows, without major reconstruction of the files and structure of the source code. Nonetheless, the whole build system has to be done under Cygwin's layer, because the flag [http://support.microsoft.com/kb/929110 '''obcaseinsensitive'''] doesn't actually make all of Windows applications aware of full file name case sensitivity.
+
 
+
'''CAUTION''': following the steps on this section, could make your Windows installation unstable [http://en.wikipedia.org/wiki/Microsoft_Windows_Services_for_UNIX#Known_problems]... use at your own risk! In case you find file names that differ only in letter case, these will only be accessible by using Cygwin's shell. (So far by my experience, only the file system got a bit slower - [[User:Wyldckat|Wyldckat]] 19 January 2010 (UTC))
+
 
+
==== Setting it up ====
+
So, without further ado, here is the step-by-step on setting it all up:
+
<ol>
+
<li>Download Cygwin 1.7 setup executable, available at [http://www.cygwin.com/ www.cygwin.com].</li>
+
<li>Run the setup program and install the following packages: '''autoconf automake binutils bison byacc diffutils patch doxygen flex gcc-core gcc-g++ git make python readline texinfo wget'''<br>Other suggested packages: '''bzip2 gitk liblzma rxvt vim'''<br>'''NOTE''':If you forget any package, run again this setup program, because it is how the packages for Cygwin are managed!</li>
+
<li>Run (Winkey + R) '''regedit''' and set the following dword to 0:<cpp>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\kernel\ObCaseInsensitive</cpp></li>
+
<li>Reboot your Windows machine.</li>
+
<li>Launch a Cygwin shell (either "Cygwin Bash Shell" or "rxvt" will do). At first run, it will setup your shell environment.</li>
+
<li>Now, your home folder must have been also created, based on your Windows user name. In case your user name has spaces in it, edit the file '''/etc/passwd''' (either with '''vim''' or with a Windows editor with UTF8 editing capability (I recommend [http://www.flos-freeware.ch/notepad2.html Notepad2] - [[User:Wyldckat|Wyldckat]])) and edit the line that has your user name. For example, for John Smith, change:<bash>John Smith:unused:1023:553:MACHINE\John Smith,S-2-8-41-4232284298-346061587-833252115-1023:/home/John Smith:/bin/bash</bash>to<bash>John Smith:unused:1023:553:MACHINE\John Smith,S-2-8-41-4232284298-346061587-833252115-1023:/home/jsmith:/bin/bash</bash></li>
+
<li>Now close the previous shell window and start a new one. Do:<bash>mkdir OpenFOAM
+
echo export TEMP=/tmp >> ~/.bashrc
+
echo export TMP=/tmp >> ~/.bashrc</bash></li>
+
<li>Create two folders on your harddrive, one to work as the base of your OpenFOAM installation, another to be a folder for temporary data. Edit the file '''/etc/fstab''' and add two lines, similar to these:<bash>D:/o /home/jsmith/OpenFOAM ntfs binary,posix=1 0 0
+
D:/dump /tmp ntfs binary,posix=1 0 0</bash>In this example, '''D:/o''' is the folder where OpenFOAM will be installed for real, and '''D:/TEMP''' is the folder for temporary files. The latter is needed for the application '''patch''' to work properly!<br>'''NOTE''': Try to keep names short, so there won't be problems ''down the road'' with path names that are too long!</li>
+
<li>Close the old shell window and open a new one, so changes are applied. Do:<bash>ln -s /usr/bin/cpp /lib/cpp</bash>This is required for '''wmake''' to work properly.</li>
+
<li>Now... now just follow the instructions from the start of this cross-compiling tutorial.</li>
+
</ol>
+
 
+
==== Notes on using Cygwin ====
+
Things to keep in mind, while following the tutorial:
+
 
<ul>
 
<ul>
<li>Edit the OpenFOAM files '''$WM_PROJECT_DIR/etc/bashrc*''' before launching them. Find:<bash># Detect system type and set environment variables appropriately
+
<li>{{version1.6}}{{version1.7}} [http://www.bluecape.com.pt blueCAPE's] list [http://joomla.bluecape.com.pt/index.php?option=com_mamblog&Itemid=43&task=show&action=view&id=44&Itemid=43&lang=en]</li>
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
<li>{{version2.0}}{{version2.1}} [http://www.bluecape.com.pt blueCAPE's] list [http://code.google.com/p/bluecfd-singlecore/wiki/KnownWorkingTutorials]</li>
export WM_ARCH=`uname -s`
+
 
+
case $WM_ARCH in
+
Linux)
+
    WM_ARCH=linux
+
</bash>and change '''Linux)''' to '''*)'''. This way, the environment will be set in Cygwin as if it were Linux.</li>
+
<li>Before running '''./Allwmake''', do first:<bash>cd $WM_PROJECT_DIR
+
wclean all</bash>In order to remove old '''lnInclude''' links, because Cygwin isn't 100% like Linux.</li>
+
<li>The cross-compiler '''mingw32''' version didn't build, due to the lack of a ''working'' '''langinfo.h''' header in Cygwin. On the other hand, '''mingw-w32/w64''' worked just fine!</li>
+
<li>On the chapter [[#Copying the files to your Windows installation|Copying the files to your Windows installation]], on the step about '''DOS_Mode.bat''', you just need to copy/move the two batch files to the base installation of OpenFOAM. You'll only need to edit the user name and whether to use '''dummy''' or '''MPICH2'''. But most importantly, on that chapter... you no longer need to ''pack and leave'', because you are already ''here''!</li>
+
<li>If you want to use the original scripts of OpenFOAM, you can setup an [http://www.mingw.org/wiki/MSYS MSys] environment that mounts similarly to your Cygwin '''/etc/fstab''', and edit your home folder and user name at the MSys installation, and you will have a triple environment in Windows, that uses the same OpenFOAM folder:
+
#Cygwin for development (doesn't have a proper path translation for the resulting cross-compiled OpenFOAM applications);
+
#MSys for using OpenFOAM scripts and applications, thus having a ''near Linux experience'' with OpenFOAM;
+
#'''DOS_Mode.bat''' for having a Windows Command Line and going ''old-DOS-school''.</li>
+
 
</ul>
 
</ul>
  
==== Working with OpenFOAM 1.6.x and Cygwin ====
+
== Forums for more information ==
Although the patches listed on this page are for OpenFOAM 1.6, you can actually use git in Cygwin and use the [http://www.symscape.com/openfoam-1-6-x-on-windows patches available by Symscape].
+
Threads at CFD-Online Forum for OpenFOAM, for discussing and questions about this page:
You will have to configure the global variables for git like this:
+
*Announcement of this page [http://www.cfd-online.com/Forums/openfoam-news-announcements-other/70063-cross-compiling-openfoam-1-6-linux-windows-32-64bits-mingw-w64.html]
<bash>git config --global core.ignorecase false
+
*Announcement of the patches for the 1.7 version [http://www.cfd-online.com/Forums/openfoam-news-announcements-other/79842-cross-compiling-openfoam-1-7-0-linux-windows-32-64bits-mingw-w64.html]
git config --global core.fileMode true
+
*Support for this page is available [http://www.cfd-online.com/Forums/openfoam-installation-windows/72813-cross-compiling-openfoam-1-6-linux-windows-32-64bits-mingw-w64.html here].
git config --global core.symlinks true</bash>
+
And then you can do a '''git clone''':
+
<bash>cd $HOME/OpenFOAM
+
git clone git://repo.or.cz/OpenFOAM-1.6.x.git</bash>
+
And so you have the most recent OpenFOAM 1.6.x source code available directly in your Windows machine, without the need of a second machine with Linux.
+
If you do a manual cross-over of the patches given here and the ones by Symscape, you will be able to cross-compile the latest OpenFOAM 1.6.x, without massive re-engineering of the OpenFOAM source code under Windows.
+
  
==== Advantages and Disadvantages with using Cygwin for cross-compiling ====
+
= History =
Advantages:
+
Note to readers and editors: feel free to update this page. You can use this [[#History|History]] section for helping other readers stay updated on major changes.
*You can develop and execute all directly in Windows, without having to go back and forth from/to Linux.
+
*Save disk space (at least, 3GB for Linux installation plus 3GB for development of OpenFOAM).
+
*Faster development process, including debugging where necessary (either ''old school'' or GDB with MinGW/MSys).
+
*Use the same tools used in Linux to build OpenFOAM, so no need to create project files or makefiles.
+
*You still get a MinGW build of OpenFOAM, without link to Cygwin, thus removing the overhead of Cygwin.
+
*If you want OpenFOAM applications that are fully case sensitive under Windows, you can do it if you build it under Cygwin! Although, the necessary changes aren't available with [[:Media:PatchesNBatches.tar.gz|these patches]] and you will have to deal with the overhead of Cygwin's translation layer.
+
  
Disadvantages:
+
[[User:Wyldckat|Wyldckat]] 20:45, 7 November 2012 (CET) - Updated the "Important Links" section
*Your Windows system ''might'' become unstable, although it seemed unlikely so far ([[User:Wyldckat|Wyldckat]] 19 January 2010 (UTC)).
+
*Using an IDE for code development, will require that the IDE is re-compiled (not cross-compiled) under Cygwin, with full file name case sensitivity turned on, in order to be able to fully access all files. Although you still will be able to edit files with Windows editors, as long as there aren't two similar files on the same folder.
+
*It is about 2 times slower to cross-compile OpenFOAM for Windows in Cygwin, than in Linux (even if virtualization is used!), and 2 to 3 times slower to build the cross-compilers. So, you will need a ''quad-core machine'' in Windows+Cygwin, while you only need ''dual-core machine'' in Linux, to achieve nearly the same building speed.
+
  
== Other Important Links ==
+
[[User:Wyldckat|Wyldckat]] 10:15, 20 December 2011 (CET) - Updated the "Important Links" section
This is a list of links of build instructions of cross-compiled and natively compiled versions of OpenFOAM, using '''mingw''' and/or '''mingw-w64''':
+
*[http://www.symscape.com Symscape's] cross-compiled OpenFOAM 1.4.1 mingw32 version [http://www.symscape.com/openfoam-on-windows]
+
*[http://www.symscape.com Symscape's] cross-compiled OpenFOAM 1.5.x mingw32 version [http://www.symscape.com/openfoam-1-5-x-on-windows]
+
*[http://www.bluecape.com.pt blueCAPE's] cross-compiled OpenFOAM 1.5.x mingw32 version with MPICH1 [http://www.cfd-online.com/Forums/openfoam-installation/57248-openfoam-mingw-crosscompiler-hosted-linux-6.html#post206728] and MPICH2 [http://www.cfd-online.com/Forums/openfoam-installation/57248-openfoam-mingw-crosscompiler-hosted-linux-7.html#post206729]
+
*[http://sourceforge.net/users/apostol Julian's] OpenFOAM 1.5 files for native build in Windows [http://sourceforge.net/projects/openfoam-mswin/files/] with mingw32 and CodeBlocks (instructions included inside files)
+
*[http://www.symscape.com Symscape's] cross-compiled OpenFOAM 1.6.x mingw32 version [http://www.symscape.com/openfoam-1-6-x-on-windows]
+
*[http://www.bluecape.com.pt blueCAPE's] cross-compiled OpenFOAM 1.6 mingw32, mingw-w32 and mingw-w64... is this tutorial you are reading...
+
  
Distributable binaries:
+
[[User:Wyldckat|Wyldckat]] 15:13, 1 September 2010 (CEST) - Updated the "Important Links" section.
*Free: [http://sourceforge.net/users/apostol Julian's] OpenFOAM for MS windows binary release by  - OpenFOAM 1.5 built nativelly in Windows [http://sourceforge.net/projects/openfoam-mswin/] using mingw32 and CodeBlocks
+
*Paid: [http://www.symscape.com Symscape's] OpenFlow: OpenFOAM for Windows [http://www.symscape.com/product/openflow]
+
*Paid: [http://www.bluecape.com.pt blueCAPE's] blueCFD: OpenFOAM for Windows XP and Vista, both 32 and 64bit [http://www.bluecape.com.pt/blueCFD]
+
  
Benchmarks and run-times running OpenFOAM cross-compiled with mingw:
+
[[User:Wyldckat|Wyldckat]] 15:46, 22 July 2010 (UTC) - Changes complete to this wiki page. Still have to create the page for the 1.7 version...
*{{version1.4.1}} icoDyMFoam (movingCone) OpenFOAM tutorial [http://www.symscape.com/openfoam-on-windows#comment-129]
+
*{{version1.4.1}} Xoodles pitzDaily3D OpenFOAM tutorial [http://www.symscape.com/openfoam-on-windows#comment-131]
+
*{{version1.6}} simpleFoam motorBike OpenFOAM tutorial [http://joomla.bluecape.com.pt/index.php?option=com_mamblog&Itemid=43&task=show&action=view&id=40&Itemid=43&lang=en]
+
  
Tutorials known to work with cross-compiled versions of OpenFOAM:
+
[[User:Wyldckat|Wyldckat]] 11:31, 22 July 2010 (UTC) - Changes have begun to be made to this wiki page to incorporate the patches for OpenFOAM 1.7. Most of the content has branched into separate pages.
*{{version1.6}} [http://www.bluecape.com.pt blueCAPE's] list [http://joomla.bluecape.com.pt/index.php?option=com_mamblog&Itemid=43&task=show&action=view&id=44&Itemid=43&lang=en]
+
 
+
Threads at CFD-Online Forum for OpenFOAM, for discussing and questions about this page:
+
*Announcement of this page [http://www.cfd-online.com/Forums/openfoam-news-announcements-other/70063-cross-compiling-openfoam-1-6-linux-windows-32-64bits-mingw-w64.html]
+
  
== History ==
 
 
[[User:Wyldckat|Wyldckat]] 14:34, 18 February 2010 (UTC) - Glitches were found in build-mingw32, and the fix is now provided inline with the tutorial.
 
[[User:Wyldckat|Wyldckat]] 14:34, 18 February 2010 (UTC) - Glitches were found in build-mingw32, and the fix is now provided inline with the tutorial.
 +
A bit later, a thread has been added to give support to this page.
  
 
[[User:Wyldckat|Wyldckat]] 20:25, 19 January 2010 (UTC) - Updates to patches and wiki page:
 
[[User:Wyldckat|Wyldckat]] 20:25, 19 January 2010 (UTC) - Updates to patches and wiki page:
Line 673: Line 216:
  
 
[[User:Wyldckat|Wyldckat]] 18:21, 11 November 2009 (UTC) - First version of this step by step wiki page
 
[[User:Wyldckat|Wyldckat]] 18:21, 11 November 2009 (UTC) - First version of this step by step wiki page
 +
 +
[[Category:OpenFOAM on Windows OS]]

Revision as of 22:11, 9 November 2012

1 Introduction

This is an exhaustive step by step guide on how to fully cross-compile OpenFOAM in Linux for Windows, for both 32 and 64 bits architectures (from and to), using the patches made available in each respective page. NOTE: for cross-compiling in Cygwin for Windows, see the page Using Cygwin for cross-compiling OpenFOAM.

These patches were initially based on Symscape's "v3" patch for OpenFOAM 1.5.x available here, but as development evolves, occasional updates are made based on the latest patches by Symscape. Symscape's patches differ substantially from the patches available on this wiki; the main differences of the patches on this wiki are:

  • these aim to build OpenFOAM up to 100% of its original capabilities;
  • these also build most Third Party tools that OpenFOAM can use directly (Scotch, Metis);
  • provide additional scripts for building OpenFOAM and the maintenance of these patches;
  • target only Windows - Symscape's patches also have changes for Mac OS X;
  • these patches are only released for each major release of OpenFOAM - Symscape's patches are updated every 2-3 months.

The build scripts for mingw and mingw-w64 were also based on the build-mingw script available on the 1.5.x and 1.6.x links.

With this guide and available patches, you should be able to cross-compile the whole and complete OpenFOAM libraries and applications, using MPICH2 instead of Open MPI for parallel computing. You can cross-compile using mingw32 and/or mingw-w64.

2 Patch versions

With the release of OpenFOAM 1.7 and the separate evolution of the patches for each OpenFOAM version, the once single wiki page will now branch into 3 parts:

Support for these patches is available at OpenFOAM's forum here.

3 Information common to all patch versions

3.1 Building Paraview in Windows

Since ParaView 3.8.0 was released [1], it no longer seems necessary to put effort into building ParaView with MPICH2 and the native OpenFOAM reader. Kitware now provides ParaView with (and without) MS-MPI for parallel functionality, and the plugin from here is already integrated.

Either way, in case you really want to build ParaView, the following instructions are the ones initially written on this wiki page:

  1. This is a pain to do, and yet, quite simple once you get the handle of it. Nonetheless, here won't be described the full building procedure. You can follow the tutorial available here in this wiki and use that plug-in for reading .foam files directly from Paraview, without building the original plug-ins that come with OpenFOAM and be able to handle large and/or parallelized cases. On that tutorial page, you also have a link to an already built version of Paraview 3.4.0 with the plug-in. This way it is less one thing to worry about building.
  2. Tips for building a 64bit version of Paraview - Follow the instructions available here and here. This way you can get Visual Studio Express to build x64 applications and also build Qt 64bit for Windows, as well as Paraview with the multi-platform plug-in!

3.2 Using MPICH2 with OpenFOAM in Windows

This is valid for each computer with Windows, where you installed the cross-compiled OpenFOAM. Be advised that you should install OpenFOAM in an identical folder path on each machine, or in a network shared drive. User accounts of the same name and password will reduce the complexity of your system. Currently we haven't tested running with different user accounts.

NOTE: these steps depend on the MPICH2 version you choose to run, namely 32 or 64bit. So you might need to do them every time you need different architectures. Nonetheless, the SMPD service seemed to be compatible with both versions.

The steps are:

  1. Go to into your administrative account (if your user account doesn't have administrative capabilities) and:
    1. Open a command line (Start->Run... or Winkey+R and run cmd.exe).
    2. Go to the bin folder where MPICH2 is installed (e.g. cd C:\Program Files\MPICH2\bin).
    3. Type:
      smpd -install
      to install the MPICH2 smpd service.
  2. Go back to your OpenFOAM user account.
    1. Now run the OpenFOAM terminal (double click on the file DOS_Mode.bat).
    2. Type:
      mpiexec.exe -register

      And when it asks your user name just press Enter key; and when it asks your user password, introduce your password... it'll ask you twice to make sure. This will allow future calls to mpiexec to be done without requiring password. MPICH will encrypt your password into the Windows Registry, so it should be safe.

      CAUTION: the MSys terminal version will make your password visible on screen!
    3. Test the parallel system. For that, you'll have to:
      1. In the OpenFOAM terminal, go to the folder ofuser-1.6 (or $USER-1.6) and unpack the test case PTestCase.tar.gz;
      2. Go into the pTestCase case folder;
      3. Type:
        gompi parallelTest
        It will test communications between two instances of parallelTest.exe. If successful, it should display something like this:
      C:\Program Files\blueCFD\ofuser-1.6\PTestCase>mpiexec -n 2 -genvlist HOME,PATH,
      USERNAME,WM_PROJECT_DIR,WM_PROJECT_INST_DIR,WM_OPTIONS,FOAM_LIBBIN,FOAM_APPBIN,
      FOAM_USER_APPBIN,MPI_BUFFER_SIZE parallelTest -parallel
      /*---------------------------------------------------------------------------*\
      | =========                 |                                                 |
      | \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
      |  \\    /   O peration     | Version:  1.6                                   |
      |   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
      |    \\/     M anipulation  |                                                 |
      \*---------------------------------------------------------------------------*/
      /*   Windows 32 and 64 bit porting by blueCAPE: http://www.bluecape.com.pt   *\
      |  Based on Windows porting (1.5.x v3) by Symscape: http://www.symscape.com/  |
      \*---------------------------------------------------------------------------*/
      Build  : 1.6-f802ff2d6c5a
      Exec   : C:\Program Files\blueCFD\ofuser-1.6\applications\bin\linuxmingw-w32DP
      Opt\parallelTest.exe -parallel
      Date   : Oct 23 2009
      Time   : 16:21:16
      Host   : THE_MACHINE
      PID    : 712
      Case   : C:/Program Files/blueCFD/ofuser-1.6/pTestCase
      nProcs : 2
      Slaves :
      1
      (
      THE_MACHINE.5024
      )
      
      Pstream initialized with:
          floatTransfer     : 0
          nProcsSimpleSum   : 0
          commsType         : nonBlocking
      
      // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
      Create time
      
      [1]
      Starting transfers
      [1]
      [1] slave sending to master 0
      [1] slave receiving from master 0
      [0]
      Starting transfers
      [0]
      [0] master receiving from slave 1
      [0] (0 1 2)
      [0] master sending to slave 1
      End
      
      [1] (0 1 2)
      Finalising parallel run
      

4 Miscellaneous information

4.1 Differences between mingw32 and mingw-w32 versions

MinGW is the true name of mingw32. As for mingw-w32 (32bit version of mingw-w64), as cited from here (dead link):

Mingw-w64 began as a spin-off from the mingw.org project, with the original intent of building for 64-bit targets.

Nonetheless, mingw-w64 has retro-compatibility with the 32bit MinGW version, thus enabling a 2-in-1 build package for 32 and 64bit Windows systems.

The main difference between mingw32 and mingw-w32, is that MinGW is a stable and proven build tool and run-time for Windows, while the mingw-w64 project is still under fierce development and only in October 29th of 2010 they released their first stable version. Therefore, it is only estimated that the mingw32 version could provide less headaches than mingw-w32.

4.2 Using Cygwin for cross-compiling OpenFOAM

For cross-compiling in Cygwin for Windows, see the page Using Cygwin for cross-compiling OpenFOAM.

5 Other Important Links

5.1 List of known building instructions

This is a list of links of build instructions of cross-compiled and natively compiled versions of OpenFOAM, using mingw and/or mingw-w64:

  • Symscape's cross-compilations:
    • OpenFOAM 1.4.1 mingw32 version [2]
    • OpenFOAM 1.5.x mingw32 version [3]
    • OpenFOAM 1.6.x mingw32 (no MPI) version [4] and OpenFOAM 1.6.x mingw-64 (with MS-MPI) version [5]
    • OpenFOAM 1.7.x mingw-64 (with MS-MPI) version [6]
    • OpenFOAM 2.0.x mingw-64 (with MS-MPI) version [7]
    • OpenFOAM 2.1.x mingw-64 (with MS-MPI) version [8]
  • Julian's OpenFOAM 1.5 files for native build in Windows [9] with mingw32 and CodeBlocks (instructions included inside files)
  • blueCAPE's cross-compilations:
    • OpenFOAM 1.5.x mingw32 version with MPICH1 [10] and MPICH2 [11]
    • OpenFOAM 1.6 and 1.7.0 mingw32, mingw-w32 and mingw-w64 (all with MPICH2)... is this tutorial you are reading...
    • OpenFOAM 2.0.x and 2.1.x mingw32, mingw-w32 and mingw-w64 with Open-MPI, MPICH2 and MS-MPI: [12]
  • Yuu Kasuga's blog (in Japanese). It use to have a few entries about cross-compiling and using OpenFOAM in Windows. Only recover link so far is for OpenFOAM 1.7.x using Symscape's patches: [13]
  • Kojani's blog (available in English, Japanese and Korean). Provides instructions and source code for compiling OpenFOAM 1.7.1 directly on Windows while using MSys: [14]

5.2 List of known binaries for Windows

Distributable binaries:

5.3 List of benchmarks on Windows

Benchmarks and run-times running OpenFOAM cross-compiled with mingw:

  • OF version 141.png icoDyMFoam (movingCone) OpenFOAM tutorial [23]
  • OF version 141.png Xoodles pitzDaily3D OpenFOAM tutorial [24]
  • OF version 16.png simpleFoam motorBike OpenFOAM tutorial from 1.6.x, running with OpenFOAM 1.6 [25]
  • OF version 17.png simpleFoam motorBike OpenFOAM tutorial from 1.6.x, running with OpenFOAM 1.6 in Linux and 1.7.0 in Windows [26]
  • OF Version 20.png OF Version 21.png simpleFoam motorBike OpenFOAM tutorial from 2.0.x, running with OpenFOAM 2.0.x and 2.1.x in Linux and in Windows [27]

5.4 Tutorials known to work on Windows

Tutorials known to work with cross-compiled versions of OpenFOAM:

5.5 Forums for more information

Threads at CFD-Online Forum for OpenFOAM, for discussing and questions about this page:

  • Announcement of this page [30]
  • Announcement of the patches for the 1.7 version [31]
  • Support for this page is available here.

6 History

Note to readers and editors: feel free to update this page. You can use this History section for helping other readers stay updated on major changes.

Wyldckat 20:45, 7 November 2012 (CET) - Updated the "Important Links" section

Wyldckat 10:15, 20 December 2011 (CET) - Updated the "Important Links" section

Wyldckat 15:13, 1 September 2010 (CEST) - Updated the "Important Links" section.

Wyldckat 15:46, 22 July 2010 (UTC) - Changes complete to this wiki page. Still have to create the page for the 1.7 version...

Wyldckat 11:31, 22 July 2010 (UTC) - Changes have begun to be made to this wiki page to incorporate the patches for OpenFOAM 1.7. Most of the content has branched into separate pages.

Wyldckat 14:34, 18 February 2010 (UTC) - Glitches were found in build-mingw32, and the fix is now provided inline with the tutorial. A bit later, a thread has been added to give support to this page.

Wyldckat 20:25, 19 January 2010 (UTC) - Updates to patches and wiki page:

  • fixes made based on Symscape's version v9 for 1.6.x, because many of the solvers that use LES and RAS turbulence models need their libraries to be forced to load under Windows.
  • chtMultiRegionFoam now works, with KK instead of K for Windows builds.
  • Instructions on how to get OpenFOAM 1.6.x directly from repository using git under cygwin.
  • reconstructParMesh wasn't being built because it wasn't in the respective Allwmake script.
  • Linking OpenFOAM to MPICH2 no longer requires Wine to work straight out of the boxed up patch.
  • Added link to tutorials that are known to work with these patches.

Wyldckat 22:20, 22 November 2009 (UTC) - Added information about cross-compiling in Cygwin

Wyldckat 01:41, 21 November 2009 (UTC) - Added thread link for discussion about this page

Wyldckat 18:20, 19 November 2009 (UTC) - Added info on cross-compiling with MPICH2, without Wine nor copying from Windows

Wyldckat 11:58, 18 November 2009 (UTC) - Added info about using CHOICE.EXE with DOS_Mode.bat

Wyldckat 18:21, 11 November 2009 (UTC) - First version of this step by step wiki page