I was trying to install Helix-OS on my Arch Linux at 2019 with ZSH and GCC 8.1 and because it is quite old it recommends OpenFOAM-4.1.
Naturally, there is no package for older OpenFOAM on AUR, so it need to be built from the sources and of course we have to solve some compatibility issues and here is a collection of fixes found on the internet :)
Note that using the folder names with sufix 4.1 for version 4.1 would help some of the scripts.
mkdir -p $HOME/OpenFOAM
cd $HOME/OpenFOAM
git clone https://github.com/OpenFOAM/OpenFOAM-4.x OpenFOAM-4.1
cd $HOME/OpenFOAM/OpenFOAM-4.1
git checkout version-4.1
git clone https://github.com/OpenFOAM/ThirdParty-4.x ThirdParty-4.1
cd $HOME/OpenFOAM/ThirdParty-4.1
git checkout version-4.1
According to wiki if your are using ZSH instead BASH, you should:
sudo pacman -S bash-completion
autoload bashcompinit
bashcompinit
Following the tips by jianlunliu:
vim $HOME/OpenFOAM/OpenFOAM-4.1/etc/config.sh/aliases
And replace the line 73:
[ "$(type -t wmRefresh)" = "alias" ] && unalias wmRefresh || unset wmRefresh
With:
[ "$(type wmRefresh | awk '{print $4}')" = "alias" ] && unalias wmRefresh || unset wmRefresh
And then you can source without errors:
source $HOME/OpenFOAM/OpenFOAM-4.1/etc/bashrc
OK, now to compile with GCC 9.1 we need to fix some things:
First, this post lead us to these commits:
Edit fileStat.C and include sysmacros.h:
vim $HOME/OpenFOAM/OpenFOAM-4.1/src/OSspecific/POSIX/fileStat.C
31gjo
#include <sys/sysmacros.h>
Secondly, this post lead us to these commits:
vim $HOME/OpenFOAM/OpenFOAM-4.1/etc/config.sh/compiler
And after Gcc61, following the same syntax, add Gcc81:
Gcc91)
gcc_version=gcc-9.1.0
;;
And comment the line 550 in PacketListI.H:
vim $HOME/OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H
449gji//
And substitute std::bad_cast with const std::bad_cast& in typeInfo.H:
sed -i -- 's/std::bad_cast)/const std::bad_cast&)/g' $HOME/OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/db/typeInfo/typeInfo.H
this posts lead us to these commits:
vim $HOME/OpenFOAM/OpenFOAM-4.1/src/thermophysicalModels/specie/reaction/Reactions/Reaction/ReactionI.H
And comment out the following block from line 35 to 39:
template<class ReactionThermo>
inline word& Reaction<ReactionThermo>::name()
{
return name_;
}
As stated in this thread there is an error with CV2D.H and to solve it we could get a newer version for that piece of code:
wget https://raw.githubusercontent.com/OpenFOAM/OpenFOAM-7/109ba3c8d53a8fa1e97854b168a16970aaeea951/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/CV2D.H -P $HOME/OpenFOAM/OpenFOAM-4.1/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh
All the dependencies could be installed from aur:
yay -S --needed cgal parmetis scotch bzip2 boost flex paraview
Now it should compile right following the official guide
In order to use the system paraview instead of build it again, put that on your zshrc. In my case I have a separated file for aliases so I put it in there.
echo "OPEN FOAM 4.1:" >> $HOME/.aliases
echo "alias OF4x="source $HOME/OpenFOAM/OpenFOAM-4.1/etc/bashrc" >> $HOME/.aliases
echo "alias paraFoam='paraFoam -builtin'" >> $HOME/.aliases