| 1 | '''NOTE: THIS IS A WORK IN PROGRESS''' |
| 2 | |
| 3 | = OpenFOAM - Build Instructions |
| 4 | [[PageOutline]] |
| 5 | |
| 6 | |
| 7 | '''OpenFOAM''' is free, open-source software for computational fluid dynamics. |
| 8 | * [http://www.openfoam.org OpenFOAM Foundation] |
| 9 | * [http://www.openfoam.com OpenCFD Ltd] - owner of the trademark OpenFOAM |
| 10 | |
| 11 | OpenFOAM releases are scheduled every six months in June and December. |
| 12 | Releases designated OpenFOAM+ contain client-sponsored developments of which much has been transferred to, but not released in the OpenFOAM Foundation branch. |
| 13 | |
| 14 | == Preliminaries == |
| 15 | * Follow build instructions from here: |
| 16 | * http://www.openfoam.com/code/build-guide.php |
| 17 | * http://www.openfoam.org/download/git.php |
| 18 | |
| 19 | * There are, roughly, two components to OpenFOAM: |
| 20 | * the actual CFD code FOAM -- definitely to be compiled with ICC |
| 21 | * the GUI analysis tools, based on !ParaView (using the Qt GUI toolkit) |
| 22 | |
| 23 | * All OpenFOAM applications do parallel communication through the Pstream library only.\\ So using any underlying message passing library (MPI, etc.) is just a matter of replacing Pstream. [https://openfoamwiki.net/index.php/Installation/HowTo_Pstream more...] |
| 24 | |
| 25 | * Some of the !ThirdParty packages need to be built first. These third party sources are required, but are not bundled. The source tarballs could be expanded in the !ThirdParty-${VERSION} directory, but we use installed modules instead. |
| 26 | * Boost - 1.61.0 works |
| 27 | * CGAL |
| 28 | * GMP - 6.1.1 works |
| 29 | * MPFR - 3.1.3 works |
| 30 | * METIS - 5.1.0 is expected [http://glaros.dtc.umn.edu/gkhome/metis/metis/download METIS Official Website] |
| 31 | |
| 32 | {{{ #!sh |
| 33 | ### set env. variables we will use |
| 34 | |
| 35 | VERSION=3.0.1 |
| 36 | INST_DIR=/homeb/zam/${USER}/my_OpenFOAM |
| 37 | |
| 38 | mkdir $INST_DIR |
| 39 | cd $INST_DIR |
| 40 | }}} |
| 41 | |
| 42 | == Download & Extract == |
| 43 | Source packages are available from the download section of the OpenFOAM website: |
| 44 | * http://www.openfoam.org/download/source.php |
| 45 | * https://github.com/OpenFOAM |
| 46 | |
| 47 | The source code must be unpacked into the top-level directory of the final installation. |
| 48 | |
| 49 | {{{ #!sh |
| 50 | ### download OpenFOAM |
| 51 | |
| 52 | wget https://downloads.sourceforge.net/project/foam/foam/${VERSION}/OpenFOAM-${VERSION}.tgz |
| 53 | wget https://downloads.sourceforge.net/project/foam/foam/${VERSION}/ThirdParty-${VERSION}.tgz |
| 54 | |
| 55 | # extract OpenFOAM |
| 56 | tar -xzf OpenFOAM-${VERSION}.tgz -C $INST_DIR |
| 57 | tar -xzf ThirdParty-${VERSION}.tgz -C $INST_DIR |
| 58 | }}} |
| 59 | |
| 60 | == Setup OpenFOAM == |
| 61 | |
| 62 | === Patch === |
| 63 | |
| 64 | Patch $INST_DIR/OpenFOAM-${VERSION}/etc/bashrc |
| 65 | {{{ #!sh |
| 66 | ### bashrc |
| 67 | |
| 68 | + foamInstall=${INST_DIR} |
| 69 | + : ${WM_COMPILER:=Gcc}; export WM_COMPILER |
| 70 | + : ${WM_MPLIB:=SYSTEMOPENMPI}; export WM_MPLIB |
| 71 | }}} |
| 72 | * Instead of setting variable in bashrc, they can be set via environment variables before you call bashrc later. |
| 73 | * {{{export FOAM_INST_DIR=...}}} overwrites foamInstall |
| 74 | * {{{export WM_COMPILER=...}}}, default is Gcc, should be set to **Icc** |
| 75 | * {{{export WM_MPLIB=...}}}, default is SYSTEMOPENMPI, should be set to **EASYBUILDMPI** |
| 76 | |
| 77 | Patch $INST_DIR/OpenFOAM-${VERSION}/etc/config/settings.sh |
| 78 | {{{ #!sh |
| 79 | ### settings.sh |
| 80 | Linux) |
| 81 | ... |
| 82 | x86_64) |
| 83 | ... |
| 84 | 64) |
| 85 | WM_ARCH=linux64 |
| 86 | export WM_COMPILER_LIB_ARCH=64 |
| 87 | + export WM_CC=${CC} |
| 88 | + export WM_CXX=${CXX} |
| 89 | + export WM_CFLAGS="${CFLAGS} -fPIC" |
| 90 | + export WM_CXXFLAGS="${CXXFLAGS} -fPIC" |
| 91 | + export WM_LDFLAGS= |
| 92 | |
| 93 | }}} |
| 94 | {{{ #!sh |
| 95 | ### settings.sh |
| 96 | |
| 97 | + #unset MPI_ARCH_PATH MPI_HOME FOAM_MPI_LIBBIN |
| 98 | |
| 99 | + EASYBUILDMPI) |
| 100 | + export FOAM_MPI=mpi |
| 101 | + ;; |
| 102 | }}} |
| 103 | |
| 104 | Patch $INST_DIR/OpenFOAM-${VERSION}/wmake/rules |
| 105 | {{{ #!sh |
| 106 | ### linux64Gcc/c, linux64Icc/c |
| 107 | + cc = ${MPICC} |
| 108 | |
| 109 | ### linux64Gcc/c++, linux64Icc/c++ |
| 110 | + CC = ${MPICXX} -std=c++0x -fp-trap=common -fp-model precise |
| 111 | |
| 112 | ### linux64Gcc/cOpt, linux64Icc/cOpt |
| 113 | + cOPT = ${CFLAGS} |
| 114 | |
| 115 | ### linux64Gcc/c++Opt, linux64Icc/c++Opt |
| 116 | + cOPT = ${CXXFLAGS} |
| 117 | }}} |
| 118 | |
| 119 | === Set Environment === |
| 120 | |
| 121 | The environment must be set up according to where the source code directories are located. |
| 122 | {{{ #!sh |
| 123 | VERSION=3.0.1 |
| 124 | INST_DIR=/homeb/zam/${USER}/my_OpenFOAM # must not end with a '/' |
| 125 | cd $INST_DIR |
| 126 | |
| 127 | # load modules |
| 128 | module --force purge |
| 129 | module load Stages/Devel |
| 130 | module load Intel/2017.0.098-GCC-5.4.0 |
| 131 | module load IntelMPI/2017.0.098 |
| 132 | module load flex/2.5.39 # flex 2.6.0 causes errors |
| 133 | module load Boost/1.61.0-Intel-2017.0.098 |
| 134 | module load MPFR/3.1.5-Intel-2017.0.098 |
| 135 | module load GMP/6.1.2-Intel-2017.0.098 |
| 136 | module load CGAL/4.8.2-Intel-2017.0.098 |
| 137 | module load METIS/5.1.0-Intel-2017.0.098 |
| 138 | |
| 139 | # configure environment |
| 140 | export FOAM_INST_DIR=$INST_DIR |
| 141 | export WM_COMPILER=Icc |
| 142 | export WM_MPLIB=EASYBUILDMPI |
| 143 | export MPICC=mpicc |
| 144 | export MPICXX=mpiicpc |
| 145 | export CC=icc |
| 146 | export CXX=icpc |
| 147 | export CFLAGS="-no-prec-div -O3 -xHost -fp-model precise -diag-disable 654 -diag-disable 1125" |
| 148 | export CXXFLAGS="-O3 -xHost -fp-model precise -diag-disable 654 -diag-disable 1125 -DMPICH_SKIP_MPICXX" |
| 149 | |
| 150 | export WM_NCOMPPROCS=8 # parallel build |
| 151 | export WM_LABEL_SIZE=32 # 32bit for labels/indices - relevant for METIS (if 64 needed patch METIS first) |
| 152 | |
| 153 | # load environment |
| 154 | source OpenFOAM-${VERSION}/etc/bashrc |
| 155 | foam |
| 156 | foamSystemCheck |
| 157 | }}} |
| 158 | |
| 159 | * build with Intel 2017.1.138: [[OpenFOAM/config_Intel-2017.1.138]] |
| 160 | * build with Stage/2016a [[OpenFOAM/config_2016a]] |
| 161 | * build with Stage/2016a + Score-P [[OpenFOAM/config_2016a_ScoreP]] |
| 162 | |
| 163 | == Setup !ThirdParty == |
| 164 | |
| 165 | OpenFOAM has configs which set where it expects to find its "third party" packages. |
| 166 | There are in {{{$FOAM_ETC/config/}}} as various shell scripts. |
| 167 | |
| 168 | The top-level ./Allwmake will build Scotch, but not CGAL, Boost, GMP, and MPFR.\\Those packages need to be built separately, and installed into the appropriate directory. |
| 169 | |
| 170 | === CGAL === |
| 171 | Patch $INST_DIR/OpenFOAM-${VERSION}/etc/config/CGAL.sh |
| 172 | {{{ #!sh |
| 173 | ### CGAL.sh |
| 174 | |
| 175 | + boost_version=$EBVERSIONBOOST |
| 176 | + cgal_version=$EBVERSIONCGAL |
| 177 | |
| 178 | + export BOOST_ARCH_PATH=$EBROOTBOOST |
| 179 | + export CGAL_ARCH_PATH=$EBROOTCGAL |
| 180 | }}} |
| 181 | * Boost -installed as module Boost/1.61.0-Intel-2017.0.098 |
| 182 | * GMP - installed as module GMP/6.1.2-Intel-2017.0.098 |
| 183 | * MPFR - installed as module MPFR/3.1.5-Intel-2017.0.098 |
| 184 | |
| 185 | === METIS === |
| 186 | Patch $INST_DIR/OpenFOAM-${VERSION}/etc/config/metis.sh |
| 187 | {{{ #!sh |
| 188 | # metis.sh |
| 189 | |
| 190 | + export METIS_ARCH_PATH=$EBROOTMETIS |
| 191 | }}} |
| 192 | {{{ #!sh |
| 193 | # $WM_THIRD_PARTY_DIR/Allwmake |
| 194 | |
| 195 | + if [ -d "$METIS_ARCH_PATH" ] # if [ -d "$METIS_VERSION" ] |
| 196 | + then |
| 197 | + if [ -f $METIS_ARCH_PATH/include/metis.h \ |
| 198 | + -a -r $METIS_ARCH_PATH/lib/libmetis.so ] |
| 199 | + then |
| 200 | + cp $METIS_ARCH_PATH/lib/libmetis.so $FOAM_EXT_LIBBIN |
| 201 | + echo " metis header in $METIS_ARCH_PATH/include" |
| 202 | + echo " metis libs in $FOAM_EXT_LIBBIN" |
| 203 | }}} |
| 204 | * ATTENTION: metis.h |
| 205 | * METIS library's IDXTYPEWIDTH must fit to $WM_LABEL_SIZE (for METIS/5.1.0-Intel-2017.0.098: IDXTYPEWIDTH=32) |
| 206 | * METIS library's REALTYPEWIDTH must fit to $WM_PRECISION_OPTION (for METIS/5.1.0-Intel-2017.0.098: REALTYPEWIDTH=64) |
| 207 | |
| 208 | |
| 209 | === Scotch === |
| 210 | Scotch decomposition which requires no geometric input from the user and attempts to minimise the number of processor boundaries. |
| 211 | |
| 212 | Patch $WM_THIRD_PARTY_DIR/etc/wmakeFiles/scotch/Makefile.inc.i686_pc_linux2.shlib-OpenFOAM-64Int32 |
| 213 | {{{ #!sh |
| 214 | # scotch/Makefile.inc.i686_pc_linux2.shlib-OpenFOAM-64Int32 |
| 215 | + AR = ${CC} |
| 216 | + CCS = ${CC} |
| 217 | + CCP = ${MPICC} |
| 218 | + CCD = ${MPICC} |
| 219 | + CFLAGS = -O3 -xHost -fp-model precise -DCOMMON_FILE_COMPRESS_GZ -DCOMMON_RANDOM_FIXED_SEED -DSCOTCH_RENAME -Drestrict=__restrict |
| 220 | }}} |
| 221 | |
| 222 | Copy source to required location. |
| 223 | {{{ #!sh |
| 224 | |
| 225 | source $INST_DIR/OpenFOAM-${VERSION}/etc/config/scotch.sh |
| 226 | |
| 227 | mkdir -p $SCOTCH_ARCH_PATH |
| 228 | cp -a $WM_THIRD_PARTY_DIR/scotch_6.0.3/* $SCOTCH_ARCH_PATH |
| 229 | }}} |
| 230 | |
| 231 | |
| 232 | == Build OpenFOAM == |
| 233 | {{{ #!sh |
| 234 | |
| 235 | # cd $WM_PROJECT_DIR |
| 236 | foam |
| 237 | |
| 238 | # clean if this is a rebuild |
| 239 | wclean all |
| 240 | |
| 241 | # build wmake |
| 242 | ./wmake/makeWmake |
| 243 | |
| 244 | # build OpenFOAM (except Qt & ParaView) |
| 245 | ./Allwmake |
| 246 | }}} |
| 247 | |
| 248 | == Build Tools == |
| 249 | |
| 250 | === Qt === |
| 251 | The '''<tt>makeQt</tt>''' script seems to fail. Run it once till it fails. Then, cd to the qt build directory and modify <tt>config.status</tt> so that gcc and g++ are used. Also add CFLAGS and CXXFLAGS as needed. |
| 252 | |
| 253 | Build and install: |
| 254 | ./config.status |
| 255 | make -j 8 |
| 256 | make install |
| 257 | |
| 258 | === ParaView === |
| 259 | * Must be built from source because OpenFOAM has !ParaView modules that need to be built, requiring !ParaView headers. |
| 260 | * Read https://github.com/OpenFOAM/ThirdParty-dev/blob/master/README.org |
| 261 | ** In particular: <blockquote>The ParaView-4.3.1/4.4.0 source-pack provided by KitWare will not build and install correctly without a minor correction: lines 653-656 must be removed or commented from file ThirdParty-dev/ParaView-4.?.?/Qt/Components/CMakeLists.txt after unpacking and renaming the ParaView-4.?.? directory. This is because the file ui_pqExportStateWizard.h referred to in the lines 653-656 … does not exist and cannot be installed causing the build and installation to fail.</blockquote> |
| 262 | ** And the fix to <tt>VTK/IO/Geometry/vtkSTLReader.cxx</tt> |
| 263 | |
| 264 | == References == |
| 265 | * flex 2.6.0 |
| 266 | * 2.6.0 causes errors: undefined reference to `yyFlexLexer::yywrap()' |
| 267 | * https://www.cfd-online.com/Forums/openfoam-installation/163986-building-openfoam-3-0-archlinux.html |
| 268 | * -fp-model precise |
| 269 | * Disables optimizations that are not value-safe on floating-point data. |
| 270 | * https://www.nccs.nasa.gov/images/FloatingPoint_consistency.pdf |
| 271 | * -DMPICH_SKIP_MPICXX |
| 272 | * https://www.cfd-online.com/Forums/openfoam/90965-errors-building-openfoam-2-0-0-icc-sgi-mpt-2-03-a.html#post317630 |
| 273 | * https://sourceforge.net/p/openfoam-extend/foam-extend-3.1/ci/90bbdada8b322e227528311326783a80a1e26b35/#diff-4 |
| 274 | * -diag-disable 654 |
| 275 | * hide warning !#654: |
| 276 | * -diag-disable 1125 |
| 277 | * hide warning !#1125: function "..." is hidden by "..." -- virtual function override intended? |