Installation/Windows/Outdated/Cross Compiling OpenFOAM 1.7 in Linux For Windows with MinGW

From OpenFOAMWiki
< Installation‎ | Windows‎ | Outdated
Revision as of 12:35, 2 November 2013 by Wyldckat (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The parent page of this page is Tip Cross Compiling OpenFOAM in Linux For Windows with MinGW - please visit it for more information.

Contents

1 Introduction

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

These patches are a continuation of the ones for OpenFOAM 1.6.0 (see Cross Compiling OpenFOAM 1.6 in Linux For Windows with MinGW). These are now based on Symscape's "v11" patch for OpenFOAM 1.6.x available here. For a brief description on the differences between the patches on this page and the ones on Symscape's page, see the Introduction chapter page on the parent page.

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 (some instructions exist for Open MPI in this section). Currently you can cross-compile using mingw-w64 for both 32 and 64 bit versions and mingw32 for 32bit version. These enable you to build OpenFOAM 1.7.0 for Windows 32 and 64 bit versions, from Linux 32 and 64bit architectures. See the chapter Notes on what doesn't work and why, for information on things that don't work properly.

Versions these patches apply to: OF version 17.png

Other versions and common information to all MinGW cross-compiled versions is available in the page Tip Cross Compiling OpenFOAM in Linux For Windows with MinGW.

Support for this page is available at OpenFOAM's forum here.


2 Get OpenFOAM packages

  1. In your Linux machine, open a terminal window (example) and create the folder $HOME/OpenFOAM:
    mkdir $HOME/OpenFOAM
    cd $HOME/OpenFOAM
  2. Get OpenFOAM-1.7.0.gtgz and ThirdParty-1.7.0.gtgz from the OpenFOAM's sourceforge.net project page and copy/move them to the folder $HOME/OpenFOAM. If you want direct download from the terminal, then do:
    wget http://downloads.sourceforge.net/foam/OpenFOAM-1.7.0.gtgz?use_mirror=mesh
    wget http://downloads.sourceforge.net/foam/ThirdParty-1.7.0.gtgz?use_mirror=mesh
  3. Extract both files, by running in a terminal:
    tar xzf OpenFOAM-1.7.0.gtgz
    tar xzf ThirdParty-1.7.0.gtgz


3 Things needed for properly cross-compiling OpenFOAM 1.7.0

The following packages should allow you to both build OpenFOAM for Linux and Windows:

  • The packages needed in Linux (these are Ubuntu 10.04 package names) are: w3m flex build-essential binutils-dev libreadline5-dev wget zlib1g-dev texinfo byacc bison.
  • The packages required for building the code documentation are: doxygen graphviz texlive-latex-base qt4-dev-tools.
  • For the x86_64 Linux platform, you might will also need: gcc-multilib
  • Packages that might be useful sooner or later: git-core python-dev libqt4-dev


4 Applying patches

  1. Copy/move the PatchesNBatches170.tar.gz file into the $HOME/OpenFOAM folder. Then unpack it by running:
    tar -xzf PatchesNBatches170.tar.gz
  2. A new folder is created, named pnb17. Now to apply the patches, run from the $HOME/OpenFOAM folder:
    patch -p0 < pnb17/OpenFOAM-1.7.0_patch
    patch -p0 < pnb17/ThirdParty-1.7.0_patch
  3. Still have to do some chmodding, for the new scripts to run properly. Run the following lines in the terminal:
    chmod 744 $HOME/OpenFOAM/OpenFOAM-1.7.0/bin/tutowin
    chmod 744 $HOME/OpenFOAM/OpenFOAM-1.7.0/bin/foamDiff
    chmod 744 $HOME/OpenFOAM/OpenFOAM-1.7.0/bin/backupSourceFolder
    chmod 744 $HOME/OpenFOAM/OpenFOAM-1.7.0/bin/backupFullFolder
    chmod 744 $HOME/OpenFOAM/OpenFOAM-1.7.0/bin/chtMultiRegionFixK
    chmod 744 $HOME/OpenFOAM/OpenFOAM-1.7.0/bin/fixPatchExeNames
    chmod 744 $HOME/OpenFOAM/OpenFOAM-1.7.0/multiBuilder
    find $HOME/OpenFOAM/OpenFOAM-1.7.0/ -name "Allwmake" | xargs chmod +x
    find $HOME/OpenFOAM/OpenFOAM-1.7.0/ -name "Allclean" | xargs chmod +x
    chmod 744 $HOME/OpenFOAM/ThirdParty-1.7.0/AllwcleanRegEx
    chmod 744 $HOME/OpenFOAM/ThirdParty-1.7.0/AllwcleanZLib
    chmod 744 $HOME/OpenFOAM/ThirdParty-1.7.0/AllwmakeMinGWScotch
    chmod 744 $HOME/OpenFOAM/ThirdParty-1.7.0/AllwmakeRegEx
    chmod 744 $HOME/OpenFOAM/ThirdParty-1.7.0/AllwmakeZLib
    chmod 744 $HOME/OpenFOAM/ThirdParty-1.7.0/build-mingw44
    chmod 744 $HOME/OpenFOAM/ThirdParty-1.7.0/build-mingw45
    chmod 744 $HOME/OpenFOAM/ThirdParty-1.7.0/build-pexports
    chmod 744 $HOME/OpenFOAM/ThirdParty-1.7.0/fixSystemMingw
    chmod 744 $HOME/OpenFOAM/ThirdParty-1.7.0/genMPICH2stubs
    chmod 744 $HOME/OpenFOAM/ThirdParty-1.7.0/getMinGWBin
    chmod 744 $HOME/OpenFOAM/ThirdParty-1.7.0/makeGcc
  4. There is a small glitch in the file $HOME/OpenFOAM/OpenFOAM-1.7.0/wmake/wmakeVerifyExeDependencies. Please edit it with a text editor and change the first line from this:
    #!/bin/sh 
     
    To this:
    #!/bin/bash 
     
  5. The most recent address for mingw-w64's SVN has changed. Therefore, edit the files ThirdParty-1.7.0/build-mingw44 and ThirdParty-1.7.0/build-mingw45, then search for the line:
    MINGW64_URL="http://mingw-w64.svn.sourceforge.net/viewvc/mingw-w64/branches/releases/v1.0/?view=tar"

    Replace with this one:

    MINGW64_URL="http://mingw-w64.svn.sourceforge.net/viewvc/mingw-w64/stable/v1.x/?view=tar"
  6. The address for mingw-regex has changed. Therefore, edit the file ThirdParty-1.7.0/AllwmakeRegEx, then search for the line:
    REGEXURL="http://downloads.sourceforge.net/project/mingw/UserContributed/regex/mingw-regex-2.5.1/${REGEXFILE}?use_mirror=mesh"

    Replace with this one:

    REGEXURL="http://downloads.sourceforge.net/mingw/UserContributed/regex/mingw-regex-2.5.1/${REGEXFILE}"
  7. If you're using Cygwin, then follow the next step in ThirdParty-1.7.0/build-mingw44 and ThirdParty-1.7.0/build-mingw45 - search for:
    index.html?view=tar

    And replace with:

    index.html@view=tar



5 Getting Windows version of MPICH2 into the ThirdParty-1.7.0 folder in Linux

With these patches there is only one way to compile OpenFOAM with MPICH2 and it's done automatically by the script Allwmake.

So this chapter is only relevant in case you want to update the headers and definition files from 1.2.1p1 to another MPICH2 version:

  1. Download and install in Windows the MPICH2, any other version than 1.2.1p1 from here. Install both 32 and 64bit versions, if you wish to build OpenFOAM for both architectures.
  2. You will also have to download the source code package from that page/folder.
  3. Create the folder $HOME/OpenFOAM/ThirdParty-1.7.0/mpich2-version/source/arch/include in your Linux set up (example and depending on the architectures you may want):
    mkdir -p $HOME/OpenFOAM/ThirdParty-1.7.0/mpich2-1.2.1p1/source/i686/include
    mkdir -p $HOME/OpenFOAM/ThirdParty-1.7.0/mpich2-1.2.1p1/source/x86_64/include
  4. From the installed MPICH2 in Windows, you will need to copy the following files from the include folder: mpi.h mpio.h mpicxx.h. And copy those files to the folder $HOME/OpenFOAM/ThirdParty-1.7.0/mpich2-version/source/arch/include.
  5. Then copy the files mpi.def mpich2.def from the source code package into the folder $HOME/OpenFOAM/ThirdParty-1.7.0/mpich2-version/source.
  6. Now to use a version of MPICH2 other than 1.2.1p1, then edit the file $HOME/OpenFOAM/OpenFOAM-1.7.1/etc/settings.sh and find the line that has mpi_version=mpich2-1.2.1p1 and change to the version you want, as shown here.

The Allwmake script at the folder ThirdParty-1.7.0 will take care of the rest.


6 Tweaking environment options

In this chapter you will set-up the desired OpenFOAM MinGW(-w64) environment, depending on the targeted architectures and Windows versions. These patches provide functionality with two extra mingw-w64 cross-compilers: Ubuntu's version and mingw-w64 project's ready to be used builds.

In order for you to do an informed choice, here is the brief details for each cross-compiler version:

  • mingw32: allows you to build a 32bit version, that should work in any Windows version. The cross-compiler will have to be built, following the instructions in this tutorial that you are reading. It comes with two choices for gcc version: 4.4.4 or 4.5.0. It's simple to do, but it takes 5 to 90min to build, depending on your machine and operating system (Linux or Windows+Cygwin).
  • mingw-w64: allows you to build either 32 or 64bit versions and should work in any Windows version. The mingw-w64 source is downloaded directly from it's stable SVN repository. It comes with two choices for gcc version: 4.4.4 or 4.5.0. The cross-compiler will have to be built, just like with mingw32.
  • mingw32msvc: this is the Ubuntu version's nomenclature (it came from Debian) and allows you to build either 32 or 64bit versions, but it does not work in any Windows version. The resulting 64bit build will not work in Windows Vista/7 x64, due to an issue with gcc 4.4.x + mingw-w64 builds, that has already been fixed in gcc 4.5.x. This version doesn't require building, but it requires downloading and installation by you. More information on this is provided along the tutorial. Note: the nomenclature other Linux distributions are using was unknown when these patches were made, so you'll have to research and adapt to suit your distribution.
  • w64-mingw32: this is mingw-w64 version, from its project page. This provides the bleeding edge version of mingw-w64 stable 1.0 version, along with the latest pre-release version of gcc 4.5.x. Doesn't require building from source and a script is provided with these patches to aid the retrieval and installation of the latest stable build version, for both Linux and Cygwin. The resulting OpenFOAM build should work in any Windows version. The only disadvantage is that you cannot forget to do the changes indicated in the tutorial section related to this cross-compiler.


Now, here is the list of environment versions available with these patches and the steps for activating them:

  1. Choose which version you want to use:
    • Custom builds:
    mingw32: for getting a 32bit version of OpenFOAM, using gcc + mingw;
    mingw-w32: for getting a 32bit version of OpenFOAM, using gcc + mingw-w64;
    mingw-w64: for getting a 64bit version of OpenFOAM, using gcc + mingw-w64;
    • Using Ubuntu's 10.04 builds of mingw-w64: (unknown at the time the patches were made if other distributions use the same nomenclature)
    i586-mingw32msvc: for getting a 32bit version of OpenFOAM, using system's gcc + mingw-w64;
    amd64-mingw32msvc: for getting a 64bit version of OpenFOAM, using system's gcc + mingw-w64;
    • Using builds available at mingw-w64's sourceforge.net project page [1]:
    i686-w64-mingw32: for getting a 32bit version of OpenFOAM, using the latest pre-built gcc + mingw-w64;
    x86_64-w64-mingw32: for getting a 64bit version of OpenFOAM, using the latest pre-built gcc + mingw-w64;

    Variants of the "bashrc" file that is inside the folder $HOME/OpenFOAM/OpenFOAM-1.7.0/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 custom gcc, mingw32, MPI with MPICH2, Opt, DP, 32
    bashrc-mingw-w32 
    configured for custom gcc, mingw-w32, MPI with MPICH2, Opt, DP, 32
    bashrc-mingw-w32-prof 
    configured for custom gcc, mingw-w32, No MPI, Prof, DP, 32 (untested)
    bashrc-mingw-w32S 
    configured for custom gcc, mingw-w32, MPI with MPICH2, Opt, SP, 32
    bashrc-mingw-w64 
    configured for custom gcc, mingw-w64, MPI with MPICH2, Opt, DP, 64
    bashrc-mingw-w64-prof 
    configured for custom gcc, mingw-w64, No MPI, Prof, DP, 64 (untested)
    NOTE: the following 3 versions were tested but the 64bit version didn't work in Windows Vista/7 x64:
    bashrc-i586-mingw32msvc 
    configured for system's gcc, mingw-w32, MPI with MPICH2, Opt, DP, 32
    bashrc-i586-mingw32msvcS 
    configured for system's gcc, mingw-w32, MPI with MPICH2, Opt, SP, 32
    bashrc-amd64-mingw32msvc 
    configured for system's gcc, mingw-w64, MPI with MPICH2, Opt, DP, 64
    NOTE: for this last one above, you will possibly need to install the mingw-w64 version for Ubuntu 10.04 available by Pali here, because Ubuntu's initial version doesn't have the compiler amd64-mingw32msvc-g++. See bug report here.
    NOTE: the following 3 versions were tested, both 32 and 64 bit versions work in Windows Vista/7 x64, but require some additional tweaking for them to work properly:
    bashrc-i686-w64-mingw32 
    configured for gcc-4.5.1 (or more recent), mingw-w32, MPI with MPICH2, Opt, DP, 32
    bashrc-i686-w64-mingw32S 
    configured for gcc-4.5.1 (or more recent), mingw-w32, MPI with MPICH2, Opt, SP, 32
    bashrc-x86_64-w64-mingw32 
    configured for gcc-4.5.1 (or more recent), mingw-w64, MPI with MPICH2, Opt, DP, 64
  2. 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:
    . $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc-mingw-w32

    WARNING: sometimes the leading dot doesn't work, so use the following instead:

    source $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc-mingw-w32

    Optional: in case you want to have access to all versions without having to edit again the file $HOME/.bashrc, then instead of adding that line above, add one or more of these:

    alias of170-mingw32='. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc-mingw32'
    alias of170-mingw-w32S='. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc-mingw-w32S'
    alias of170-mingw-w32D='. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc-mingw-w32'
    alias of170-mingw-w64='. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc-mingw-w64'
    alias of170-i586Dsys='. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc-i586-mingw32msvc'
    alias of170-i586Ssys='. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc-i586-mingw32msvcS'
    alias of170-x64sys='. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/amd64-mingw32msvc'
    alias of170-i686Dmingw='. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc-i686-w64-mingw32'
    alias of170-i686Smingw='. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc-i686-w64-mingw32S'
    alias of170-x64mingw='. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc-x86_64-w64-mingw32'
    alias of170-linux='export WM_ARCH_OPTION=32; . $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc'
    alias of170-linux64='. $HOME/OpenFOAM/OpenFOAM-1.7.0/etc/bashrc'
    Now, whenever you start a new terminal, run one of the alias commands; for example:
    of170-i686Dmingw

    NOTE: Feel free to change the alias names to something more short and to your liking!


7 Build the cross compiler

In this version of patches for OpenFOAM 1.7.0, there are three types of MinGW cross-compilers, as already mentioned in the previous section Tweaking environment options:

For all of these possibilities, start a new terminal. In case you chose to use the alias method, activate the OpenFOAM environment by running the respective alias command, as demonstrated before.

7.1 Using custom built MinGW cross-compilers

This section is only valid for WM_COMPILER: mingw32 mingw-w32 mingw-w64.

  1. Go to the ThirdParty-1.7.0 folder, in your new terminal:
    cd $WM_THIRD_PARTY_DIR
  2. Now you have to build the cross-compiler. You can now choose which version of gcc you wish to build mingw(-w64) with. The two possibilities available are:
    • to build with gcc 4.4.x version, run:
      ./build-mingw44
    • to build with gcc 4.5.x version, run:
      ./build-mingw45
      NOTE: 64bit builds of OpenFOAM provided by the resulting gcc-4.5.x+mingw-w64, require the tweak mentioned in the section Essential Tweak for gcc 4.5.x and OpenFOAM 1.7.0.

    NOTE: updates are bound to be done to the packages that these scripts use. More information, see section Building mingw cross-compilers.
  3. If no error messages appear while running the script, then you should now be ready to go to the next chapter: Cross-Compile OpenFOAM in Linux for Windows.

7.2 Using system build of MinGW cross-compilers

Valid for WM_COMPILER: i586-mingw32msvc amd64-mingw32msvc

As said before, if you intend to build the 64bit cross-compiler version, install the system's package related to this; then first check if the file amd64-mingw32msvc-g++ exists:. Reason: see bug report for Ubuntu here. Fix: install the mingw-w64 version for Ubuntu 10.04 available by Pali here. If you can't get it to work, you better choose one of the other solutions.

If you do have the necessary system cross-compilers, there is only one additional step necessary to do - run this:

cd $WM_THIRD_PARTY_DIR
./fixSystemMingw

This command will check if your system compiler is properly configured for building OpenFOAM. If not, it will provide you with instructions to fix the header files in some float.h files. Without following these instructions, you will not be able to build OpenFOAM.

7.3 Using mingw-w64 automatic builds of MinGW cross-compilers

Valid for WM_COMPILER: i686-w64-mingw32 x86_64-w64-mingw32

You simply have to run the script getMinGWBin available in the folder ThirdParty-1.7.0:

cd $WM_THIRD_PARTY_DIR
./getMinGWBin

This script will search for the latest available pre-built version of the mingw-w64 compiler defined by the bashrc-compiler script for you Linux machine, whether it's i?86 or x86_64! It should also work in Cygwin. Keep in mind that you must do the Essential Tweak for gcc 4.5.x and OpenFOAM 1.7.0!

NOTE: this script getMinGWBin needs the application w3m, a text based browser, to be installed.

7.3.1 Essential Tweak for gcc 4.5.x and OpenFOAM 1.7.0

There is a tweak that is necessary to be done for OpenFOAM 1.7.0 and gcc 4.5.x (the version that usually comes from mingw-w64's project). The reason for this tweak is in the bug shown here.

With the OpenFOAM environment active (as explained in the second item of the chapter Tweaking environment options), run these commands:

cd $WM_DIR/rules
sed -i -e 's=-O2 -DNDEBUG=-O2 -DNDEBUG -fno-strict-aliasing=' "$WM_ARCH$WM_COMPILER/c++Opt"


8 Cross-Compile OpenFOAM in Linux for Windows

  1. 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). Go to the project folder as so:
    cd $WM_PROJECT_DIR
  2. You are now in the folder OpenFOAM-1.7.0 and should run Allwmake:
    ./Allwmake
    This will build the entire OpenFOAM package. This does not include: Paraview, OpenMPI and code documentation.
  3. Optional - If you want to build the code documentation, after OpenFOAM is built, run:
    wmake all doc

    This only needs to be built once, since it's the same for all architectures.

    In the chapter Creating a compact help file for the code documentation is explained how to finish this step.

  4. Optional - If you want to be able to run the tutorial cases that need custom applications to be built, run:
    wmake all tutorials

    The applications will be cross-compiled and put in the folder $HOME/OpenFOAM/$USER-1.7.0/application/bin/$WM_OPTIONS, or $FOAM_USER_APPBIN for short.

  5. Building the mesh conversion utility ccm26ToFoam is now done automatically, when compared with the previous patch versions. If for any reason you do not wish for it to be built, edit the file $FOAM_APP/Allwmake and remove or comment the lines that have:
    wmake all utilities/mesh/conversion/Optional
  6. For testing MPICH2, as described in this page's parent page, chapter Using MPICH2 with OpenFOAM in Windows, the parallel test application will be built automatically. The built executable will be placed in the folder $HOME/OpenFOAM/$USER-1.7.0/application/bin/$WM_OPTIONS, or $FOAM_USER_APPBIN for short.

NOTE: In case you wish to build multiple architectures, see the section Building sequentially multiple architectures with multiBuilder.


9 Copying the files to your Windows installation

This procedure is split into three sections in this chapter:

9.1 Final preparations

The following steps are needed for you to be able to use some of the tutorials that require a case sensitive file system:

  1. Make a copy of the original tutorials into your OpenFOAM dedicated user folder:
    cp -r $FOAM_TUTORIALS $FOAM_RUN/..
  2. Fix the chtMultiRegion* tutorials:
    cd $FOAM_RUN/../tutorials
    chtMultiRegionFixK heatTransfer/chtMultiRegionFoam/multiRegionHeater
    chtMultiRegionFixK heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater
    chtMultiRegionFixK heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeater
  3. Fix the STL in the motorBike case so that if you have to use to foamToVTK in Windows, there won't be any problems:
    cd $FOAM_RUN/../tutorials/incompressible/simpleFoam/motorBike
    chmod 744 fixForWindows
    ./fixForWindows
  4. Fix the tutorial nozzleFlow2D case:
    cd $FOAM_RUN/../tutorials/multiphase/interFoam/les/nozzleFlow2D
    nano Allrun

    Or instead of nano, you can use your favorite text editor: vi, gedit, kate, kwrite, mousepad.

    Now, right after the line:
    runApplication blockMesh
    Add these lines:
    if [ "$WM_PRECISION_OPTION" = "DP" ]; then
      firstiter=1e-008
    else
      firstiter=1e-08
    fi
    Then there are two lines bellow that need changing too:
        cp -r 1e-08/polyMesh/* constant/polyMesh
        rm -rf 1e-08
    Change them to this:
        cp -r ${firstiter}/polyMesh/* constant/polyMesh
        rm -rf ${firstiter}


The following steps are required due to a minor glitch in the patches:

  1. Go into the library folders of each build:
    cd $FOAM_LIBBIN
    cp libgnurx-0.dll libregex.dll
    This was necessary due to an issue in blockMesh, which has a patched option for building the profiling version which explicitly involves libregex.


Finally, if you are planing on running in Windows Vista or 7, you will need to simply run:
fixPatchExeNames
Why? Because Windows has an heuristic that forces the need for administrative powers for running applications that have "patch" in their names. This script will rename the offending files and create scripts that redirect control to the renamed files. For more information about this script, see section Fix file names of applications that have "patch" in their name.

9.2 Packing up and leaving for Windows

  1. The folders from $HOME/OpenFOAM that you have to copy are:
    • OpenFOAM-1.7.0/applications/bin/$WM_OPTIONS
    • OpenFOAM-1.7.0/etc
    • OpenFOAM-1.7.0/bin
    • OpenFOAM-1.7.0/lib/$WM_OPTIONS
    • OpenFOAM-1.7.0/doc/Guides-a4 or OpenFOAM-1.7.0/doc/Guides-usletter (optional)
    • OpenFOAM-1.7.0/doc/Doxygen/qt_qch or OpenFOAM-1.7.0/doc/Doxygen/html (optional, see the chapter Creating a compact help file for the code documentation for more information)
    • ThirdParty-1.7.0/platforms/$WM_ARCH$WM_COMPILER/mpich2-1.2.1p1 (or one of the versions you chose)
    • ThirdParty-1.7.0/mpich2-1.2.1p1/source (optional)
    • ThirdParty-1.7.0/platforms/$WM_OPTIONS (optional - provides additional the Scotch binaries)
    • $USER-1.7.0/tutorials (optional, created in the section Final preparations)
    • $USER-1.7.0/applications/bin/$WM_OPTIONS (created in step 5 of the chapter Cross-Compile OpenFOAM in Linux for Windows)

    You can get all of the essentials listed above in a nice little package, by running at $HOME/OpenFOAM:
    tar -chjf OpenFOAM.$WM_OPTIONS.tar.bz2 OpenFOAM-1.7.0/applications/bin/$WM_OPTIONS \
    OpenFOAM-1.7.0/etc OpenFOAM-1.7.0/bin OpenFOAM-1.7.0/lib/$WM_OPTIONS \
    OpenFOAM-1.7.0/doc/Guides-a4 ThirdParty-1.7.0/platforms/$WM_ARCH$WM_COMPILER/mpich2-1.2.1p1 \
    $USER-1.7.0/applications/bin/$WM_OPTIONS $USER-1.7.0/tutorials ThirdParty-1.7.0/mpich2-1.2.1p1/source

    Or for an even smaller package:

    tar --lzma -chf OpenFOAM.$WM_OPTIONS.tar.lzma OpenFOAM-1.7.0/applications/bin/$WM_OPTIONS \
    OpenFOAM-1.7.0/etc OpenFOAM-1.7.0/bin OpenFOAM-1.7.0/lib/$WM_OPTIONS \
    OpenFOAM-1.7.0/doc/Guides-a4 ThirdParty-1.7.0/platforms/$WM_ARCH$WM_COMPILER/mpich2-1.2.1p1 \
    $USER-1.7.0/applications/bin/$WM_OPTIONS $USER-1.7.0/tutorials ThirdParty-1.7.0/mpich2-1.2.1p1/source
  2. Optional - In case you have built more than one OpenFOAM version (mingw32 mingw-w32 mingw-w64 and so on), pack the whole bin and lib folders as so:

    tar --lzma -chf OpenFOAM.mingw.tar.lzma OpenFOAM-1.7.0/applications/bin \
    OpenFOAM-1.7.0/etc OpenFOAM-1.7.0/bin OpenFOAM-1.7.0/lib \
    OpenFOAM-1.7.0/doc/Guides-a4 \
    $USER-1.7.0/applications/bin $USER-1.7.0/tutorials ThirdParty-1.7.0/mpich2-1.2.1p1/source

9.3 Setting up shop in Windows

  1. In order to recreate a folder base similar to the Linux setup (namely $HOME/OpenFOAM), 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 nor have any installed, a suggestion is 7zip, available here.
  2. Unpack the PatchesNBatches170.tar.gz file to your OpenFOAM base folder in Windows. The following files should be copied from the folder pnb17 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.7.0 folder that came from Linux to ofuser-1.7.0. 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
  3. In order to get MPICH2 batch file to run in this command line, you'll have to copy the file pnb17\gompi.bat to the folder OpenFOAM-1.7.0\bin. MPICH2 will only work properly if you install it in Windows. Now, you have (at least) two possible solutions:
    1. 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, copy from 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 (depending on architectures an as examples):
      • ThirdParty-1.7.0\mpich2-1.2.1p1\platforms\linuxmingw32DPOpt\bin
      • ThirdParty-1.7.0\mpich2-1.2.1p1\platforms\linuxmingw-w32SPOpt\bin
      • ThirdParty-1.7.0\mpich2-1.2.1p1\platforms\linuxmingw-w32DPOpt\bin
      • ThirdParty-1.7.0\mpich2-1.2.1p1\platforms\linuxmingw-w64DPOpt\bin - this should have the 64bit version of MPICH2
    2. Or instead of copying, 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
      ;C:\Program Files\MPICH2\bin
      to the end of line that starts with:
      set PATH=%PATH%;
      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
      ;C:\Program Files\MPICH2\bin
      or
      ;C:\Program Files (x86)\MPICH2\bin
      accordingly to the desired version.
  4. In order to get Paraview batch file to run in this command line, you'll have to copy the file pnb17\paraFoam.bat to the folder OpenFOAM-1.7.0\bin. Paraview should be installed in, or copied to, one of the following folders, according to the versions installed (these are only some of the possible versions):
    ThirdParty-1.7.0\platforms\linuxmingw32\paraview-3.8.0
    ThirdParty-1.7.0\platforms\linuxmingw-w32\paraview-3.8.0
    ThirdParty-1.7.0\platforms\linuxmingw-w64\paraview-3.8.0
    The Paraview binaries themselves should be inside the folder bin. For example, for mingw32 the Paraview binaries should be inside the folder ThirdParty-1.7.0\platforms\linuxmingw32\paraview-3.8.0\bin.
    For more information on how to build Paraview for Windows with OpenFOAM file handling, see the chapter Building Paraview in Windows in the parent page.
  5. Tip: with some tweaking of the OpenFOAM scripts in the folder OpenFOAM-1.7.0\bin, it is possible to run OpenFOAM with 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. Additionally, instead of sourcing OpenFOAM's bashrc file the same way it's done in Linux, you can copy the file pnb17/sourceOF into your home folder in MSys and add to the end of the $HOME/.bashrc file:
    . sourceOF
    This script will provide you with a similar menu to the one for the Windows Command Line.


10 Creating a compact help file for the code documentation

Things changed between the versions 1.6 and 1.7.0 of OpenFOAM, in regard to code documentation. It has become more cumbersome and now is more dependent of helper JavaScript functions. The patches provided in this wiki do not disable the JavaScript scripts, which usually don't work in compressed help files.

Along with these changes, a decision was made for the patches (the CHM version didn't look as good as it did with OpenFOAM 1.6) and now the help files are pre-compiled using Qt's help file generation and management technology, along with Doxygen's ready to be used options. But since both build options are still available, there are two sections in this chapter and you only have to follow one of them, if any of them. You can always resort to the online code documentation version provided in OpenFOAM's website if you want to save some disk space.

The sections available in this chapter are:

10.1 Creating a Qt QCH/QHC files for the code documentation

As described in the introduction of this chapter, this is now the preferred method of generation of the compressed code documentation files. The reasons are:

  • It's compiled while still in Linux, thus being a lot faster than compiling to CHM in Windows;
  • Although not as small as the CHM counterpart (it's about 20MiB larger), it doesn't require the html files to be transported to and finally erased in Windows;
  • It looks nicer and has tabs!

Now, although the necessary files can come in the transport package from Linux, it isn't enough to simply have them in your new OpenFOAM installation. It requires you to install Nokia's Qt for Windows. The steps for getting the Qt based OpenFOAM code documentation ready are:

  1. Download and install Qt - Note: You only need the LGPL version and download/install the Framework.
  2. After it is installed, copy the following files from Qt's bin folder, into the OpenFOAM's folder OpenFOAM-1.7.0/doc/Doxygen/qt_qch:
    assistant.exe
    mingwm10.dll #if you installed the minGW version
    QtCLucene4.dll
    QtCore4.dll
    QtGui4.dll
    QtHelp4.dll
    QtNetwork4.dll
    QtSql4.dll
    QtWebKit4.dll
    QtXml4.dll
    plugins\sqldrivers
    plugins\sqldrivers\qsqlite4.dll
    plugins\sqldrivers\qsqlodbc4.dll
  3. Now copy the file pnb17/codeHelp.bat from the patches folder, into the OpenFOAM's bin folder OpenFOAM-1.7.0/bin.
  4. Edit the newly copied file OpenFOAM-1.7.0/bin/codeHelp.bat and change in the line:
    PUSHD %WM_PROJECT_DIR%\doc\Doxygen\html
    To:
    PUSHD %WM_PROJECT_DIR%\doc\Doxygen\qt_qch
  5. Now start the DOS_Mode.bat batch file and run codeHelp.bat.
  6. Tip: if you want to create a local batch file in the qt_qch folder, simply copy the file pnb17/codeHelp.bat into the qt_qch folder, then edit the new copy and remove the lines that start with PUSHD and POPD.

NOTE: the same way it doesn't in CHM, the top right search box in the first page doesn't work in Qt's Assistant application.

10.2 Creating a Compiled HTML (CHM) file for the code documentation

As described in the chapter 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.

  1. When you packed the files for transport from Linux to Windows (see Copying the files to your Windows installation), you should have included the OpenFOAM-1.7.0/doc/Doxygen/html folder, and it should be available in your Windows installation. So, check if you have the files index.hhp, index.hhc and index.hhk in the folder OpenFOAM-1.7.0\doc\Doxygen\html. If:
  2. Get and install the HTML Help Workshop, which is available here, so you can use it to compile the HTML files into a single CHM file.
  3. Now launch the OpenFOAM Command Window (run DOS_Mode.bat). Do:
    cd OpenFOAM-1.7.0\doc\Doxygen
    subst K: .

    This will make the folder OpenFOAM-1.7.0\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.

  4. 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.
  5. 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 +47000 files that exist inside the html folder.
  6. Run the Compile command (File->Compile). It will take some time to compile. Hopefully it won't crash.
  7. If it hasn't crashed, then you will have a brand new ~200MiB [2] index.chm file, with added index and search functions. Keep in mind that the original uncompressed files are well over 500MiB! NOTE: the Search 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.
  8. Cleaning up:
    • In the Command Window that you opened a while ago, remove the virtual drive letter, by running:
      subst K: /D
      You can now close that command window.
    • Copy the index.chm file to a safe place, and remove the html folder in OpenFOAM-1.7.0\doc\Doxygen. WARNING: to remove the +47000 files that exist therein, will take a very long time.


11 Notes on what doesn't work and why

11.1 libscotch is limited in Windows

The library libscotch can't handle compression in Windows, due to nonexistent native Windows pipe and fork functions. MSys and Cygwin have these implemented, but effort has not been invested in re-implementing them here. Nonetheless, this feature doesn't seem necessary for OpenFOAM for to work with libscotch.

11.2 Symbolic links in the tutorials

In case you didn't notice, this is something already fixed through the instructions in the section Packing up and leaving for Windows . But to reinforce the idea, here is what you need to do to copy the tutorials properly to Windows, you must use the command (or similar):

tar -chjf ../tutorials.tar.bz2 tutorials

at the folder $HOME/OpenFOAM/OpenFOAM-1.7.0 or $HOME/OpenFOAM/$USER-1.7.0, depending if you didn't or did follow the instructions in the section Final preparations. 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.

11.3 Open MPI in Windows

Building Open MPI with Microsoft's Visual Studio for running in Windows has been around since the version 1.3.3. But building Open MPI with the mingw (cross-)compilers is not possible for versions (at least) below 1.4.2... well, at least not without some serious patching up of OpenMPI's code to not be so restrictive on which compiler to use for Windows.

Nonetheless, it's expected that building with Microsoft's preferred software compiler, Open MPI will give the best performance. So, if you already feel OK with building OpenFOAM with an updated MPICH2, then:

  • Follow Open MPI's instructions on how to build with CMake + Visual Studio.
  • Copy the resulting build into the folder $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/openmpi-1.4.1.
  • Change the variable WM_MPLIB from MPICH to OpenMPI in the $WM_PROJECT_DIR/etc/bashrc-version.
  • Follow the instructions in the section Generating DLL interfaces for gcc, and apply it to the dll files in the folder $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/openmpi-1.4.1/lib.
  • Some more tweaking might be necessary in the files OpenFOAM-1.7.0/etc/settings.sh and ThirdParty-1.7.0/Allwmake, but this hasn't tested yet.
  • Run Allwmake as instructed in the chapter Cross-Compile OpenFOAM in Linux for Windows.

And voilá, you should be able to use OpenMPI in Windows, along with OpenFOAM. Keep in mind that further tweaking will be needed to the gompi.bat file in the Windows installation, as well as setvars.bat, because they are tuned to work with MPICH2 and those options used might not work for OpenMPI.

11.4 Cross-compiled versions with mingw-w64 compiler take longer to start applications

This is a nuisance of gcc+mingw-w64, which isn't fixed yet. It's probably associated to the large quantity of functions and methods lodged in all of OpenFOAM's libraries, which makes Windows take a long time (around 12s on a E8400 Intel processor) to start applications, but it seems that it's only slow to start the first time it is executed. Either way, you can see the explanations in the analogous section for the 1.6 version of this tutorial.

11.5 Some tutorials don't work in Windows

This should no longer be an issue! Except if you need to modify an application which is part of the tutorial. In that case, you will need to make the modification it in Linux, then cross-compile it and copy it back to Windows.

Now, if by any chance you are unable to run an OpenFOAM tweaked original tutorial case properly under Windows, after following all of the instructions in this tutorial, then:

  • check the list at Tutorials known to work with blueCFD, to see if your non-working tutorial is already listed there;
  • visit this dedicated thread for issues related to these patches and post your issue.

11.6 Tutorial scripts don't work in Windows

Actually they do work, but only if you use the 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:

sh Allrun

11.7 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:

  1. Install the resource kit that should be in your Windows CD/DVD.
  2. Download the version that came with the Windows 98 resource kit from here, and put it in the base folder of your OpenFOAM installation.


12 Notes on added functionalities with these patches

These notes list added functionality to both the original OpenFOAM 1.7.0 version and to Symscape's patches (see the Introduction chapter to know which version).

12.1 chtMultiRegionFoam and chtMultiRegionSimpleFoam slightly different in Windows

This is simply an updated version of the note made for the previous 1.6 version of these patches, in the section chtMultiRegionFoam doesn't work properly. The instructions listed there were replicated to also work for the new 1.7.0 solver chtMultiRegionSimpleFoam. Additionally, as you might have noticed in the section Final preparations, a script was added to aid the adaptation of the tutorials that use these two solvers. That script is described in the next section chtMultiRegionFixK for adapting multiRegion cases.

12.2 chtMultiRegionFixK for adapting multiRegion cases

This script was created to aid the adaptation of the tutorial cases that work with chtMultiRegion* solvers. It has to be executed while in a case sensitive file system. Basically it replaces all relevant K field entries with KK and renames those very same files. It's meant to be executed on a copy of the tutorial, otherwise you will damage the original tutorials, thus no longer working as intended in Linux.

To use it, simply run:
chtMultiRegionFixK path/of/the/folder/of/the/multiRegion/case

12.3 foamToVTK binary VTK files now functional in Windows

After some thorough investigation on Stack Overflow, this answered question was found C++ change newline from CR+LF to LF. And after going through foamToVTK's source code, it was finally found were it needed to be fixed. So, with these patches, foamToVTK should work at 100% with binary files as intended!

12.4 Building ccm26ToFoam

As mentioned before in step 5 of the chapter Cross-Compile OpenFOAM in Linux for Windows, building ccm26ToFoam is now a default option in the applications/Allwmake script. When compared with the previous patches version for OpenFOAM 1.6, those changes were no longer needed, since it was fixed little after OpenFOAM 1.7.0 was released [3].

12.5 Keeping track of symbolic links in tutorials

Running the script tutowin at the folder $HOME/OpenFOAM/OpenFOAM-1.7.0, 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.7.0, this is already done by these patches. So you can use tutowin for future updates.

12.6 Changes in settings.sh

The script settings.sh has been a bit tweaked. The mingw cross-compilers were added (a generic option, based on how these patches setup things). The dummy libPstream has been added as an MPI library named NONE, so libPstream will be added to the library search path. MPICH version was updated. And a new variable was added: WM_SCOTCH_PLATFORMS_DIR, which contains the path to the target install directory for scotch.

12.7 Changed how Scotch is built

Multiple changes were made to Scotch's Makefiles and make settings added for each version added by this script. And pre-calculated structure dimensions are set for mingw builds, when using this patched version, since the original Scotch library requires that an executable to be executed natively (i.e., in this case, under Windows) to calculate the sizes of structures. And as mentioned in the previous section Changes in settings.sh, the variable WM_SCOTCH_PLATFORMS_DIR is used for installing each architecture build of Scotch libraries and executables. This was necessary, because OpenFOAM's original 1.7.0 source version doesn't take into account multiple architecture builds of libscotch.

12.8 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 makeThirdPartyFunctions tools script available in the $HOME/OpenFOAM/ThirdParty-1.7.0/tools.

12.9 Building mingw cross-compilers

After initial problems with Ubuntu's mingw-w64 cross-compilers and then with mingw-w64's "ready to use" gcc 4.5.x, the old build-scripts (the ones in the patches for OpenFOAM 1.6) were remade into two build scripts, for helping with building the mingw and mingw-w64 cross-compilers.

The two scripts are build-mingw44 and build-mingw45, for gcc 4.4.x and gcc 4.5.x respectively. These rely on the settings defined in bashrc-version, so they will automatically build the desired mingw or mingw-w32/64 version. The bashrc-version files contemplated by these scripts are: bashrc-mingw32 bashrc-mingw-w32 bashrc-mingw32S bashrc-mingw64

Since you might want to update the packages used by the build scripts, you should edit the script you have chosen and check/change accordingly:

  • Near the beginning of these two scripts, you will find these variables:
    #GNU GCC and company
    GCCVERSION="gcc-4.5.0"
    GMPVERSION="gmp-4.3.2"
    MPFRVERSION="mpfr-2.4.2"
    MPCVERSION="mpc-0.8.2" #'''build-mingw45''' only
    BINUTILSVERSION="binutils-2.20.1"
     
    #MinGW versions
    MINGW32RTVERSION="mingwrt-3.18"
    W32APIVERSION="w32api-3.14"

    NOTE: Mingw-w64 doesn't need a version because these scripts will always retrieve the latest stable 1.0 version directly from SVN.

    Check if they those versions still exist or if newer ones exist, by browsing the links provided a few lines below the version variables:

    GNU_URL="ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/${GCCVERSION}/${GCC_TARFILE}"
    GMP_URL="ftp://ftp.gnu.org/gnu/gmp/${GMP_TARFILE}"
    MPFR_URL="ftp://ftp.gnu.org/gnu/mpfr/${MPFR_TARFILE}"
    MPC_URL="http://www.multiprecision.org/mpc/download/${MPC_TARFILE}"
    BINUTILS_URL="ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/binutils/releases/${BINUTILS_TARFILE}"
     
    MINGW64_URL="http://mingw-w64.svn.sourceforge.net/viewvc/mingw-w64/branches/releases/v1.0/?view=tar" #changes here only required if new stable version is launched
     
    #MinGW versions
    MINGW32RT_URL="http://downloads.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/MinGW-RT/${MINGW32RTVERSION}/${MINGW32RT_TARFILE}?use_mirror=mesh"
    W32API_URL="http://downloads.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/Win32-API/${W32APIVERSION}/${W32API_TARFILE}?use_mirror=mesh"

    The respective addresses for checking available versions:

    NOTE: You can also change the URLs, in case you can find a closer server to you!

12.9.1 Making gcc 4.4.x + mingw have a dynamic libstdc++

Initially there were issues with gcc 4.5.0, but the resulting build did work in Windows Vista/7 x64. This was because as of gcc 4.5.0, mingw-w64 can provide a DLL of libstdc++. This was also great, because it reduced the size footprint of the build down to about half the size of a build with an original gcc 4.4.x + mingw-w64 cross-compiler.

But since OpenFOAM 1.7.0 didn't work at 100% with gcc 4.5.0, a little tweak was searched and found in order to add the feature of a DLL libstdc++ to gcc 4.4.x. This neat feature was found on this post on MinGW's Nabble. It wasn't implemented has indicated, since we wanted it after gcc was already built. So, you can reuse it in other projects by getting the function createSTDCPPShared() in the build-mingw44 script.

12.10 Building the Linux compilers based on the same version used with mingw-w64

With these patches, a modified script of OpenFOAM's 1.6 makeGcc is available. It's meant for building the available gcc-version folders that have been made available by build-mingw44 and build-mingw45, so results can be compared between the Linux version and the Windows version of OpenFOAM.

To use it, run:
cd $WM_THIRD_PARTY_DIR
./makeGcc gcc-4.4.4
Or gcc-4.5.0, depending on which build-mingw4? you used.

12.11 Building sequentially multiple architectures with multiBuilder

A helper script named multiBuilder was developed for building various architectures of OpenFOAM. It was only tested with building the various bashrc-version scripts that are made available by these patches. It is meant to be used in a clean environment; in other words, it requires that the chosen method of sourcing OpenFOAM's bashrc file is with the alias method.

To use this script:

  1. Edit $WM_PROJECT_DIR/multiBuilder with your favorite editor.
  2. Go to the end of the script and remove the comment character # from the lines of the desired architecture versions to be built sequentially. For example, for building mingw-w32 and mingw-w64 (and assuming you already prepared the cross-compilers with one of the build-mingw4? scripts), it should look like this:
    # buildIt bashrc-mingw32
     
    buildIt bashrc-mingw-w32
    # buildIt bashrc-mingw-w32S
    buildIt bashrc-mingw-w64
     
    # buildIt bashrc-i586-mingw32msvc
    # buildIt bashrc-i586-mingw32msvcS
    # buildIt bashrc-amd64-mingw32msvc
     
    # buildIt bashrc-i686-w64-mingw32
    # buildIt bashrc-i686-w64-mingw32S
    # buildIt bashrc-x86_64-w64-mingw32
  3. Then, in a clean environment terminal (no OpenFOAM variable must be set), run multiBuilder from the folder OpenFOAM-1.7.0. For example:
    cd $HOME/OpenFOAM/OpenFOAM-1.7.0
    ./multiBuilder
  4. A log for each build version is kept in the folder $HOME/OpenFOAM/buildLogs, with relevant date and time of the build start. It also keeps track of how long it takes to build each version. It will also build the solvers and utilities that exist in the tutorials!

12.12 Allwmake for tutorials

Some tutorials in OpenFOAM have custom solvers and utilities dedicated for them. But since building for Windows requires cross-compiling while still in Linux, an Allwmake script was created for the tutorials folder. It is indicated in the chapter Cross-Compile OpenFOAM in Linux for Windows how to use it.

12.13 Getting MPICH2 automatically in Linux

A script named get-mpich2 already existed in the patches for OpenFOAM 1.6 for creating a library link object for MPICH2MPI.DLL. The script was renamed to genMPICH2stubs and modified to simply generate the library interface for the MPICH2 primary library. 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, see the chapter Getting Windows version of MPICH2 into the ThirdParty-1.7.0 folder in Linux.

12.14 Generating DLL interfaces for gcc

A script named build-pexports was created, as legacy from the scripts available from the patches for OpenFOAM 1.6. This script will build the binary named pexports and install it in the folder:
$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_COMPILER_ARCH/pexports-0.44-1/bin
This binary is executable under Linux and it will allow you to generate definition files for already built DLL files. Then you can use the definition files for creating the library interface for gcc to use. Original instructions for using pexports can be found here at MinGW's website. To run it and make it available on your current terminal (which already has an OpenFOAM environment working with your chosen bashrc-version), run:
cd $WM_THIRD_PARTY_DIR
./build-pexports
export PATH=$PATH:$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_COMPILER_ARCH/pexports-0.44-1/bin
Now, for using it with MPICH2 or OpenMPI or any other DLL, go to the folder that has the DLL (in Linux). As an example, for mpich2.dll run:
pexports -o mpich2.dll > libmpi.def
WM_DLLTOOL=`echo $WM_CC | sed s/gcc/dlltool/`
$WM_DLLTOOL -U -d libmpi.def -l libmpi.a

Now, in case the dll file isn't in the right place, you can move the libmpi.a file to somewhere visible to OpenFOAM's build process... probably to the folder $MPI_ARCH_PATH/lib.

12.15 Compiling HTML files into CHM and QCH/QHC

In the patches for 1.6, it was optional to build the documentation and then convert HTML to CHM in Windows. In these new patches, when documentation is built, it already creates the files needed for building CHM and also builds the Qt's compressed help file for the same documentation. Modifications were made to Doxyfile and Allwmake in the doc/Doxygen folder; the file openfoam-code.qhcp is added by these patches, so it can finalize the build process of the Qt's help files. See chapter Creating a compact help file for the code documentation for more information.

12.16 Creating new patches

$WM_PROJECT_DIR/bin/foamDiff is a script created specifically for creating these patches, without requiring to cleanup the binaries and lnInclude folders. 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:

OpenFOAM-1.7.0
OpenFOAM-1.7.0-orig
ThirdParty-1.7.0
ThirdParty-1.7.0-orig

Then use foamDiff while in the folder $HOME/OpenFOAM like so:

foamDiff OpenFOAM-1.7.0 OpenFOAM-1.7.0-orig OpenFOAM-1.7.0_patch_new
foamDiff ThirdParty-1.7.0 ThirdParty-1.7.0-orig ThirdParty-1.7.0_patch_new

Legend: foamDiff <FolderNew> <FolderOrig> <patch_name>

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

12.18 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:

  • backupFullFolder the_folder
    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.7.0 and OpenFOAM-1.7.0, but should work with any folder.
  • backupSourceFolder the_folder
    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.7.0 and OpenFOAM-1.7.0, but should work with any folder that exists in the workspace of OpenFOAM.

12.19 Smart library loading

This was developed back in February 2010, but it was only fully implemented in these patches for OpenFOAM 1.7.0. This method is required for a particular reason:

  • building applications in Linux allows setting a list of libraries that must be used by it, as well as other libraries that are hinted to be loaded when the application starts;
  • this does not bode well with Windows restrictive DLL loading mechanism - the DLL is either strictly needed or it simply isn't loaded.

Symscape's approach on this issue has been to add an initialization method to the extra libraries, and then that method is called from the applications that need them. For example, the RAS turbulence model libraries need to be forcefully loaded for those models to be available; otherwise, only the basic internal models of the main library will be available. This was also used in the patches for OpenFOAM 1.6 provided in this group of cross-compiling tutorials. This approach has a downside: any library that hasn't been detected as necessary to be forcefully loaded, will result in the desired solver/utility not to work as intended.

So, in an attempt to prevent missing libraries in Windows, a Smart library loading was implemented. Basically, in setRootCase.H it is included the new file forceLoadLibraries.H, which will in turn load the list of libraries that is set into the variable LIBS_TO_LOAD defined at build time. This variable is defined by running the new script wmakeVerifyExeDependencies, which will compare the list of libraries defined to be loaded, against the libraries that should be loaded, and then change the options file for that application. Then when wmake is executed again, the new options will be used to update the build.

For more information about this, see that script and the modified Allwmake in the applications folder.

Advantages of this method:

  • doesn't need modifications in the identified libraries.
  • doesn't need specific modifications for each affected solver/utility.

Disadvantages to this method:

  • it needs to build the application twice, for it to be defined properly.
  • a couple of utilities still need modification of the code, because they don't include setRootCase.H.

12.20 Chemistry related solvers now work

This is an issue with the previous patches for OpenFOAM 1.6, but it no longer is an issue with the new patches! There was a bug in the patch for Random.C that now has been fixed.

12.21 Resolution of paths is now fixed

There were issues in the previous patches for OpenFOAM 1.6 when expanding paths based on internal variables and folder definitions, such as:
FOAM_CASE
~/
~OpenFOAM
~user
The fixed files are:
src/OpenFOAM/global/argList/argList.C
src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C
src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C
src/OpenFOAM/db/IOobject/IOobject.C

12.22 Version information added to the built binaries

A resource file with version information is compiled and added to all of OpenFOAM's built DLLs and EXEs. The base resource file is OpenFOAM-1.7.0/src/OSspecific/MSwindows/res/OFversion.rc. If you wish, you can change/add/remove information to this file. NOTE: This only applies to Windows.

This allows for a better identification of the binaries of OpenFOAM while in Windows. But it is still far from perfect, since no binaries are identified independently in their added properties for Windows recognition. All of them only have the basic information. This is something that still needs improving.

The automatic adaptation to the current version and compilation are all made in the file OpenFOAM-1.7.0/Allwmake.

12.23 Fix file names of applications that have "patch" in their name

There apparently is an undocumented heuristic in Windows Vista/7 to automatically assume that executables that have "patch" in their file name, are automatically required to need administrative powers to execute them. In order to fix this, the fixPatchExeNames script was added to help rename these executables files and add scripts (shell and batch scripts) that redirect user interface to the renamed executables.


13 History

Wyldckat 15:35, 10 November 2010 (CET) - Updated patches for 1.7.0. Small fix for building libscotch in single-core machines. Also added a note about wmakeVerifyExeDependencies.

Wyldckat 16:37, 7 September 2010 (CEST) - Patches for 1.7.0 have been updated. There were a couple of glitches that needed fixing for a proper clean build. These were tested with OpenSUSE 11.1 x64 and custom mingw-w64.

Wyldckat 20:10, 6 September 2010 (CEST) - Added information and step for running fixPatchExeNames.

Wyldckat 21:11, 5 September 2010 (CEST) - Added information about adding version information to the binaries.

Wyldckat 22:05, 4 September 2010 (CEST) - Proofreading and fixes to page complete.

Wyldckat 13:30, 2 September 2010 (CEST) - The first release version of this page is finally complete. But it still needs some proofreading...

Wyldckat 21:11, 1 September 2010 (CEST) - Finally got some time for finishing this page, but at this moment it isn't complete yet... Hopefully in the next 24 hours this will be finished. And although the page isn't fully complete and checked, the patches are already up!

Wyldckat 22:39, 31 July 2010 (UTC) - Page development has stalled due to technical difficulties with existing pre-built mingw-w64 cross-compilers.

Wyldckat 15:48, 22 July 2010 (UTC) - Page created... content will be inserted periodically over the next hours...