(1)安装好ubuntu20.04系统,并确保ubuntu可以联网、确保内存最好在13G以上(内存太小在编译过程中可能会显示内存不足,关键词是终端出现kill字样)。
(2)进入Ubuntu桌面。通过Ctrl+Alt+T启动终端,在终端输入
sudo gedit /etc/apt/sources.list
键入后会要求输入密码。注意,密码并未显示。回车后,出现一个文本编辑器,将内容全部删除,并将下面的内容粘贴进去,并保存
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
(3)依次复制下面所有内容到终端:
sudo apt update
sudo apt-get install -y build-essential flex bison git-core cmake zlib1g-dev libboost-system-dev libboost-thread-dev libopenmpi-dev openmpi-bin gnuplot libreadline-dev libncurses-dev libxt-dev
cd $HOME &&
mkdir OpenFOAM &&
sudo apt update &&
sudo apt-get install -y build-essential flex bison git-core cmake zlib1g-dev libboost-system-dev libboost-thread-dev libopenmpi-dev openmpi-bin gnuplot libreadline-dev libncurses-dev libxt-dev &&
cd OpenFOAM &&
git clone https://e.coding.net/dyfluid/OpenFOAM/OpenFOAM-8.git &&
git clone https://e.coding.net/dyfluid/OpenFOAM/ThirdParty-8.git &&
source OpenFOAM-8/etc/bashrc &&
cd OpenFOAM-8 &&
./Allwmake -j &&
sed -i '$a source $HOME/OpenFOAM/OpenFOAM-8/etc/bashrc' $HOME/.bashrc
这时候会输出大量的信息,中途可能要输入密码,同时并行编译开始(大约需要几十分钟)。编译之后请尝试在终端运行:
blockMesh
如果显示如下信息:
表示安装成功。
- ParaView(后处理工具)安装
2.1. 编译版paraFoam
cd $HOME/OpenFOAM/ThirdParty-8 &&
sudo apt install libqt5x11extras5-dev libxt-dev qt5-default qttools5-dev curl &&
./makeParaView
其中会自动下载ParaView-5.6.3并开始编译,编译过程较长。编译完成后会显示Installation complete for paraview-5.6.3等信息。
wmRefresh &&
cd $FOAM_UTILITIES/postProcessing/graphics/PVReaders &&
./Allwclean &&
./Allwmake
将会再次开始编译过程。几分钟即编译完成。然后键入paraFoam即可运行。
- 多版本共存
不同大厂的OpenFOAM版本各有特性,因此用户可能具有多版本OpenFOAM共存的需求。多版本OpenFOAM共存非常简单。举例说明:如果用户打算在Ubuntu系统上安装OpenFOAM-8以及OpenFOAM-7,可在终端输入:
gedit $HOME/.bashrc
会打开一个文件,在文件的最底部重新取一行添加下述两行文字:
alias of8="source ~/OpenFOAM/OpenFOAM-8/etc/bashrc"
alias of7="source ~/OpenFOAM/OpenFOAM-7/etc/bashrc"
保存并关闭。重新打开新的终端的时候,环境变量自动生效。这时如果用户键入:
of8
则调用OpenFOAM-8环境,类似的,键入:
of7
则调用OpenFOAM-7环境。