The details of the system where the OpenFOAM code was compiled are the following:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 10 (buster)
Release: 10
Codename: buster
$ uname -a
Linux n107353 4.19.0-16-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 GNU/Linux
develop.openfoam.com/Development/openfoam/blob/develop/doc/Build.md
develop.openfoam.com/Development/ThirdParty-common/blob/develop/BUILD.md
Several packages are required by the installation. Most of them should already
exist in a standard installation but, for example, rpm
does not.
sudo apt install git-core build-essential cmake curl
sudo apt install mpi-default-bin mpi-default-dev openmpi-bin libopenmpi-dev
sudo apt install qt5-default qttools5-dev libqt5x11extras5-dev
sudo apt install install flex bison gnuplot libreadline-dev libncurses-dev \
libboost-dev libboost-system-dev libboost-thread-dev zlib1g-dev libxt-dev
sudo apt install libcgal-dev libscotch-dev libptscotch-dev
sudo apt install python python-dev python3 python3-dev
sudo apt install paraview libvtk6-dev
sudo apt install binutils-dev libiberty-dev graphviz
sudo apt install time
## Optional
sudo apt install python3-mshr python3-pygalmesh
sudo apt install libqt5webkit5-dev libqt5opengl5-dev python-qtpy
First one must define the OpenFOAM root folder where the installation
will be performed. This path will be stored in shell variable OFDIR
.
Note that the user must have write permissions to that directory.
The following commands will create a root folder for OpenFOAM in
/opt/OpenFOAM
and will change its ownership to that of the user
performing the installation (which may be changed after OpenFOAM is
installed).
OFDIR=/opt/OpenFOAM
sudo mkdir -p $OFDIR
sudo chown -R $USER:$(id -gn $USER) $OFDIR
Download the OpenFOAM source code
cd $OFDIR
git clone https://develop.openfoam.com/Development/openfoam.git \
--single-branch -b OpenFOAM-v2012 \
OpenFOAM-v2012
git clone https://develop.openfoam.com/Development/ThirdParty-common.git \
--single-branch -b v2012 \
ThirdParty-v2012
#rm -rf OpenFOAM-v2012/.git
#rm -rf ThirdParty-v2012/.git
The current version of etc/bashrc
should set WM_PROJECT_DIR
and
WM_THIRD_PARTY_DIR
to the paths in OFDIR
. Check installation paths,
namely:
WM_PROJECT_DIR
should point to$OFDIR/OpenFOAM-v2012
WM_THIRD_PARTY_DIR
should point to$OFDIR/ThirdParty-v2012
WM_PROJECT_USER_DIR
should point to$HOME/OpenFOAM/$USER-v2012
- alias
foam
should cd into$WM_PROJECT_DIR
- alias
run
should cd into$HOME/OpenFOAM/$USER-v2012/run
source ${OFDIR}/OpenFOAM-v2012/etc/bashrc
echo $WM_PROJECT_DIR
echo $WM_THIRD_PARTY_DIR
echo $WM_PROJECT_USER_DIR
alias foam
alias run
source ${OFDIR}/OpenFOAM-v2012/etc/bashrc WM_COMPILER_TYPE=system WM_COMPILER=Gcc
Start with the example file prefs.sh
which is part of OpenFOAM. Note that
there are default options that should be removed therein.
cp $WM_PROJECT_DIR/etc/config.sh/example/prefs.sh $WM_PROJECT_DIR/etc/
sed "s/\(.*export[[:space:]]*WM_COMPILER_TYPE=.*\)/#\1/g" -i $WM_PROJECT_DIR/etc/prefs.sh
sed "s/\(.*export[[:space:]]*WM_COMPILER=.*\)/#\1/g" -i $WM_PROJECT_DIR/etc/prefs.sh
sed "s/\(.*export[[:space:]]*WM_MPLIB=.*\)/#\1/g" -i $WM_PROJECT_DIR/etc/prefs.sh
Optional: use system compiler
cat <<EOF >>$WM_PROJECT_DIR/etc/prefs.sh
export WM_COMPILER_TYPE=system
export WM_COMPILER=Gcc
export WM_COMPILER_DIR=$(dirname $(dirname $(which gcc)))
EOF
Optional: use system OpenMPI
cat <<EOF >>$WM_PROJECT_DIR/etc/prefs.sh
export WM_MPLIB=SYSTEMOPENMPI
export OPENMPI_DIR=$(dirname $(dirname $(which mpicc)))
export OPENMPI_BIN_DIR=$(dirname $(which mpicc))
export OPENMPI_LIB_DIR="\$(\$OPENMPI_BIN_DIR/mpicc --showme:libdirs)"
export OPENMPI_INCLUDE_DIR="\$(\$OPENMPI_BIN_DIR/mpicc --showme:incdirs)"
export OPENMPI_COMPILE_FLAGS="\$(\$OPENMPI_BIN_DIR/mpicc --showme:compile)"
export OPENMPI_LINK_FLAGS="\$(\$OPENMPI_BIN_DIR/mpicc --showme:link)"
EOF
Optional: FOAMY HEX MESH
echo "export FOAMY_HEX_MESH=yes" >> $WM_PROJECT_DIR/etc/prefs.sh
Optional: use system-installed paraview (much faster installation):
cat <<EOF >>$WM_PROJECT_DIR/etc/prefs.sh
export PARAVIEW_SYSTEM=1
export PARAVIEW_DIR=$(dirname $(dirname $(which paraview)))
export PARAVIEW_BIN_DIR=$(dirname $(which paraview))
EOF
Optional: set environmental variable for Qt to compile ParaView (one may add these even if the ParaView used is the one from the system)
cat <<EOF >>$WM_PROJECT_DIR/etc/prefs.sh
export QT_SELECT=qt5
export QT_DIR=$(dirname $(dirname $(which qmake)))
export QT_BIN_DIR=$(dirname $(which qmake))
EOF
Optional: use system Python installation
cat <<EOF >>$WM_PROJECT_DIR/etc/prefs.sh
export PYTHON_SYSTEM=1
export PYTHON_DIR=$(dirname $(dirname $(which python)))
export PYTHON_BIN_DIR=$(dirname $(which python))
EOF
Optional: set python includes and libraries for swak4foam
cat <<EOF >>$WM_PROJECT_DIR/etc/prefs.sh
export SWAK_PYTHON2_INCLUDE="\$(python-config --cflags)"
export SWAK_PYTHON2_LINK="\$(python-config --ldflags)"
export SWAK_PYTHON3_INCLUDE="\$(python3-config --cflags)"
export SWAK_PYTHON3_LINK="\$(python3-config --ldflags)"
EOF
Optional: 64-bit integer support to allow for 9E+18 cells instead of 2E+9
echo "export WM_LABEL_SIZE=64" >> $WM_PROJECT_DIR/etc/prefs.sh
Optional: set environment to compile Cuda solvers
export CUDA_ARCH=sm_30
echo "export CUDA_ARCH=sm_30" >> $WM_PROJECT_DIR/etc/prefs.sh
unalias of2012
cat <<EOF > $OFDIR/of2012_envars.sh
#!/bin/bash
#
# openfoamwiki.net/index.php/Installation/Working_with_the_Shell
# develop.openfoam.com/Development/openfoam/blob/develop/doc/Build.md
#
OFDIR=$(echo $OFDIR)
[ -v BASH_ALIASES[of2012] ] && unalias of2012
function of2012 {
. \$OFDIR/OpenFOAM-v2012/etc/bashrc
export FOAM_USER_SRC=\$WM_PROJECT_USER_DIR/src
}
of2012
echo -e "
OpenFOAM environment variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OFDIR = \$OFDIR
WM_PROJECT_DIR = \$WM_PROJECT_DIR
WM_THIRD_PARTY_DIR = \$WM_THIRD_PARTY_DIR
FOAM_TUTORIALS = \$FOAM_TUTORIALS
FOAM_USER_APPBIN = \$FOAM_USER_APPBIN
FOAM_USER_LIBBIN = \$FOAM_USER_LIBBIN
FOAM_USER_SRC = \$FOAM_USER_SRC
FOAM_RUN = \$FOAM_RUN
OpenFOAM aliases
~~~~~~~~~~~~~~~~
\$(type of2012)
\$(alias foam)
\$(alias run)
\$(alias app)
\$(alias sol)
\$(alias tut)
\$(alias util)
"
EOF
Make of2012_envars.sh
script executable and source it.
chmod +x $OFDIR/of2012_envars.sh
. $OFDIR/of2012_envars.sh
. $OFDIR/of2012_envars.sh
wmRefresh
cd $WM_THIRD_PARTY_DIR
./Allwmake 2>&1 | tee -a log.Allwmake1
https://gforge.inria.fr/frs/download.php/file/38187/scotch_6.0.9.tar.gz
tar -xvf scotch_6.0.9.tar.gz
wget http://algo2.iti.kit.edu/schulz/software_releases/KaHIP_2.12.tar.gz
tar -xvf KaHIP_2.12.tar.gz
mv KaHIP_v2.12 kahip-2.12
wget http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/metis-5.1.0.tar.gz
tar -xvf metis-5.1.0.tar.gz
wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.bz2
tar -xvf boost_1_66_0.tar.bz2
wget https://github.com/CGAL/cgal/releases/download/releases%2FCGAL-4.12.2/CGAL-4.12.2.tar.xz
tar -xvf CGAL-4.12.2.tar.xz
wget http://www.fftw.org/fftw-3.3.7.tar.gz
tar -xvf fftw-3.3.7.tar.gz
./Allwmake 2>&1 | tee -a log.Allwmake2
grep --color=auto -i error $WM_THIRD_PARTY_DIR/log.Allwmake2
./Allwmake 2>&1 | tee -a log.Allwmake3
grep --color=auto -i error $WM_THIRD_PARTY_DIR/log.Allwmake3
Note: run the grep
commands to check the logs for compilation errors.
This assumes the computer has 4 cores available, thus the compilation is made
using those cores (through the -j4
option). Though the compilation commands
work with any number of cores, it is more efficient to request a number not
higher than the available cores in the machine.
. $OFDIR/of2012_envars.sh
wmRefresh
cd $WM_PROJECT_DIR
./Allwmake -j4 2>&1 | tee -a log.Allwmake1
./Allwmake 2>&1 | tee -a log.Allwmake2
Compilation errors may be checked with
grep --color=auto -i error $WM_PROJECT_DIR/log.Allwmake2
. $OFDIR/of2012_envars.sh
wmRefresh
cd $WM_THIRD_PARTY_DIR
#wget https://portal.nersc.gov/svn/visit/trunk/third_party/libccmio-2.6.1.tar.gz -O libccmio-2.6.1.tar.gz
wget http://downloads.sourceforge.net/project/foam-extend/ThirdParty/libccmio-2.6.1.tar.gz -O libccmio-2.6.1.tar.gz
tar -xvf libccmio-2.6.1.tar.gz
./makeCCMIO 2>&1 | tee -a log.makeCCMIO1
wmRefresh
cd $WM_PROJECT_DIR
./Allwmake 2>&1 | tee -a log.Allwmake3
grep --color=auto -i error $WM_THIRD_PARTY_DIR/log.Allwmake3
The following commands will add the necessary functions to the of2012_envars.sh
environmental variables script, in order to use OpenFOAM with the
system-installed ParaView.
cat <<EOF >> $OFDIR/of2012_envars.sh
## ParaView: use system version
alias paraFoam="paraFoam -builtin"
function paraFoamGenCaseFile {
caseFile="\$(basename \$(pwd)).foam"
touch \$caseFile
#paraview \$caseFile
}
echo -e "
paraFoam using system-installed paraview
~~~~~~~~~
\$(alias paraFoam)
"
EOF
Assuming the machine has 4 cores (option -j4
).
. $OFDIR/of2012_envars.sh
wmRefresh
cd $WM_THIRD_PARTY_DIR
./makeParaView -python -mpi -python-lib /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 2>&1 | tee -a log.makeParaView1
cd $WM_PROJECT_DIR
./Allwmake -j4 2>&1 | tee -a log.Allwmake4
grep --color=auto -i error $WM_PROJECT_DIR/log.Allwmake4
cd $FOAM_UTILITIES/postProcessing/graphics/PVReaders
./Allwclean
./Allwmake 2>&1 | tee -a log.Allwmake1
grep --color=auto -i error $FOAM_UTILITIES/postProcessing/graphics/PVReaders/log.Allwmake1
For details check:
- OpenFOAMwiki page:
openfoamwiki.net/index.php/Installation/swak4Foam
WARNING: Errors are expected while compiling, e.g.,
swak4Foam-0.4.0/Libraries/swakStateMachine/PluginFunctions/isStateFunctionPlugin.C
due to a missing dependency FaFieldValueExpressionDriver.H
.
This is easily solved by recompiling swak4foam
.
First load the OpenFOAM environmental variables by sourcing of2012_envars.sh
and
assure mercurial software management tool is installed, as this is required to
obtain the latest version of swak4foam
:
. $OFDIR/of2012_envars.sh
wmRefresh
sudo apt-get install mercurial
After, download swak4foam
into the third-party software path
cd $WM_THIRD_PARTY_DIR/
hg clone http://hg.code.sf.net/p/openfoam-extend/swak4Foam -u develop swak4Foam
Set python includes and libraries for swak4foam
cat <<EOF >$WM_THIRD_PARTY_DIR/swak4Foam/swakConfiguration
# swak4Foam configuration
export SWAK_PYTHON2_INCLUDE="$(python-config --cflags)"
export SWAK_PYTHON2_LINK="$(python-config --ldflags)"
export SWAK_PYTHON3_INCLUDE="$(python3-config --cflags)"
export SWAK_PYTHON3_LINK="$(python-config --ldflags)"
export SWAK_USER_PLUGINS=\$WM_THIRD_PARTY_DIR/swak4Foam/Examples/UserPlugins/swakTestFunctionPlugins
export SWAK_COMPILE_GRAMMAR_OPTION="-O1"
EOF
Compile swak4foam
and recompile OpenFOAM
cd $WM_THIRD_PARTY_DIR/swak4Foam
./maintainanceScripts/compileRequirements.sh
export PATH=$WM_THIRD_PARTY_DIR/swak4Foam/privateRequirements/bin:$PATH
## Use 4 CPUs in the compilation process
export WM_NCOMPPROCS=4
./Allwmake 2>&1 | tee -a log.Allwmake1
./Allwmake 2>&1 | tee -a log.Allwmake2
grep --color=auto -i error $WM_THIRD_PARTY_DIR/swak4Foam/log.Allwmake2
cd $WM_PROJECT_DIR
./Allwmake 2>&1 | tee -a log.Allwmake4
grep --color=auto -i error $WM_PROJECT_DIR/log.Allwmake4
cat <<EOF >> $OFDIR/of2012_envars.sh
## Swak4Foam
SWAK4FOAM_SRC=\$WM_THIRD_PARTY_DIR/swak4Foam/Libraries
export SWAK4FOAM_SRC
echo -e "
Swak4Foam
~~~~~~~~~
SWAK4FOAM_SRC = \$SWAK4FOAM_SRC
"
EOF
For details check:
- OpenFOAMwiki page:
http://openfoamwiki.net/index.php/Contrib/PyFoam#Downloads
- pyFoam python page:
http://pypi.org/project/PyFoam/#files
. $OFDIR/of2012_envars.sh
cd $WM_THIRD_PARTY_DIR/
hg clone http://hg.code.sf.net/p/openfoam-extend/PyFoam PyFoam
cd PyFoam
export PYFOAM_DIR=$WM_THIRD_PARTY_DIR/PyFoam
if [ -z $PYTHONPATH ]; then
export PYTHONPATH=$PYFOAM_DIR/lib/python2.7/site-packages
else
export PYTHONPATH=$PYFOAM_DIR/lib/python2.7/site-packages:$PYTHONPATH
fi
mkdir -p $PYFOAM_DIR/lib/python2.7/site-packages
cd $PYFOAM_DIR
python setup.py install --prefix=$PYFOAM_DIR --record files.txt
cat <<EOF >> $OFDIR/of2012_envars.sh
## PyFoam
export PYFOAM_DIR=\$WM_THIRD_PARTY_DIR/PyFoam
function PF {
export PATH=\$PYFOAM_DIR/bin:\$PATH
export PYTHONPATH=\$PYFOAM_DIR/lib/python2.7/site-packages:\$PYTHONPATH
export PYTHONPATH=\$PYTHONPATH:\$(dirname \$(find /usr/lib -name "vtkCommonCorePython*.so") | xargs | sed -e 's/ */:/g')
export PYTHONPATH=\$PYTHONPATH:\$(python -c "import sys; print(':'.join(sys.path))")
}
PF
echo -e "
pyFoam installation
~~~~~~~~~~~~~~~~~~~
PYFOAM_DIR = \$PYFOAM_DIR
\$(which pyFoamVersion.py)
"
EOF
. $OFDIR/of2012_envars.sh
run
pyFoamVersion.py
OpenFOAM has several executables which are not needed for general use
of a Linux system. Hence, before starting any OpenFOAM calculation,
the installation may be activated by sourcing the of2012_envars.sh
script,
. /opt/OpenFOAM/of2012_envars.sh
which loads the several environmental variables required to run OpenFOAM and its tools.
First certify that the several user areas are created:
mkdir -p $FOAM_RUN
mkdir -p $FOAM_USER_APPBIN
mkdir -p $FOAM_USER_LIBBIN
mkdir -p $FOAM_USER_SRC
Afterwards perform simple checks:
run
foamInstallationTest
Commands to run the pitzDaily
tutorial in your personal user OpenFOAM folder:
. /opt/OpenFOAM/of2012_envars.sh
run
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily ./
cd pitzDaily
blockMesh
simpleFoam
paraFoam