Ubuntu18.04更新至20.04 OpenFOAM无法正常使用
-
然后还想附上一直想发出来的,之前安装三个版本的openfoam历程,欢迎大家修改完善
OpenFOAM安装
Overview
系统版本:Ubuntu18.04 LTS
安装方式:编译安装
安装版本:OpenFOAM-7、foam-extend 4.1、OpenFOAM-V1902
参阅:
多版本共存方式
-
终端输入
gedit $HOME/.bashrc
-
方法1
在文件的最底部重新取一行添加下述两行文字:
alias of3x="source ~/OpenFOAM/OpenFOAM-3.x/etc/bashrc" alias of4x="source ~/OpenFOAM/OpenFOAM-4.x/etc/bashrc"
-
方法2
在文件的最底部添加:
# source $HOME/OpenFOAM/OpenFOAM-7/etc/bashrc source $HOME/foam/foam-extend-4.1/etc/bashrc # source $HOME/OpenFOAM/OpenFOAM-v1912/etc/bashrc
-
方法3 (采用)
source $HOME/OpenFOAM/OpenFOAM-7/etc/bashrc alias of19='source $HOME/OpenFOAM/OpenFOAM-v1912/etc/bashrc' alias fe41='source $HOME/OpenFOAM/foam-extend-4.1/etc/bashrc'
OpenFOAM-7(大致耗时一下午5~6h)
安装of7
-
确保ubuntu可以联网,启动终端,在终端输入(分三次输入,直接全部复制进去):
# 更新软件 sudo apt update # 安装依赖1 sudo apt-get install 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 # 安装依赖2 sudo apt-get install qt4-dev-tools libqt4-dev libqt4-opengl-dev freeglut3-dev libqtwebkit-dev
-
下载OpenFOAM-7.tar以及ThirdParty-7.tar,然后从窗口进入到ubuntu系统的Home文件夹下建立文件夹为OpenFOAM。
-
进入这个OpenFOAM文件夹,将下载的OpenFOAM-7.tar复制进去右键解压缩会出现一个OpenFOAM-7-master的文件夹。去掉master后缀改名为OpenFOAM-7。同样把ThirdParty-7.tar解压缩至此处,去掉master后缀改名为ThirdParty-7文件夹。注意,两个文件夹缺一不可。否则会提示缺少相关文件编译error。
-
配置环境变量:在终端输入
gedit $HOME/.bashrc
会打开一个文件,我们在文件的最底部重新取一行添加下述文字:
source $HOME/OpenFOAM/OpenFOAM-7/etc/bashrc
保存并关闭。关闭终端并打开新的终端的时候,环境变量自动生效。
-
配置并行编译
在OpenFOAM目录下的etc下打开bashrc文件,在其中最底部添加
export WM_NCOMPPROCS=4
表示采用4核并行编译。用户可以随意更改其中的数字。
-
编译OpenFOAM:打开终端,输入(即切换到OpenFOAM-7目录下):
cd $HOME/OpenFOAM/OpenFOAM-7/
然后输入:
./Allwmake
这时候会输出大量的信息,编译开始。编译之后请尝试运行:
blockMesh
/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: 7 \\/ M anipulation | \*---------------------------------------------------------------------------*/ Build : 7 Exec : blockMesh Date : Mar 20 2020 Time : 14:46:02 Host : "veen-zhou" PID : 12641 I/O : uncollated Case : /home/veen/OpenFOAM/OpenFOAM-7 nProcs : 1 sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE). fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 10) allowSystemOperations : Allowing user-supplied system call operations // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
编译安装Paraview
-
终端切换到ThirdParty-7目录下并键入:
sudo apt-get install qt5-default libqt5x11extras5-dev qttools5-dev curl
-
终端键入:
./makeParaView
其中会自动下载ParaView并开始编译,编译过程较长。编译完成后会显示Installation complete for paraview-5.4.0等信息。
-
分四次键入
wmRefresh cd $FOAM_UTILITIES/postProcessing/graphics/PVReaders ./Allwclean ./Allwmake
将会再次开始编译过程。几分钟即编译完成。然后键入paraFoam即可运行。
foam-extend 4.1
安装fe41
-
确保Ubuntu可以联网
# 更新 sudo apt-get update # 安装依赖 sudo apt-get install git-core build-essential binutils-dev cmake flex \ zlib1g-dev qt4-dev-tools libqt4-dev libncurses5-dev curl bison \ libxt-dev rpm mercurial graphviz python python-dev python3 python3-dev
然而这样并不能成功安装,继续安装一些依赖
sudo apt-get install openmpi-bin libopenmpi-dev #Addition: Use system installed OpenMPI sudo apt install curl #Addition: Needed for downloading of ThirdPartyProducts
-
设置一下
echo "export WM_THIRD_PARTY_USE_BISON_27=1" > etc/prefs.sh #Compile bison-2.7 echo "export WM_MPLIB=SYSTEMOPENMPI" >> etc/prefs.sh #Addition: Use system installed OpenMPI echo "export OPENMPI_DIR=/usr" >> etc/prefs.sh #Addition: Use system installed OpenMPI echo "export OPENMPI_BIN_DIR=\$OPENMPI_DIR/bin" >> etc/prefs.sh #Addition: Use system installed OpenMPI See the etc/prefs-sh-EXAMPLE file for more examples on how to do modifications. source etc/bashrc echo "alias fe41='source \$HOME/foam/foam-extend-4.1/etc/bashrc'" >> $HOME/.bashrc
-
编译(四核编译时间大概3~4小时)
./Allwmake.firstInstall
-
测试安装
# Test the installation: # Press CTRL-ALT-T to open an new terminal window fe41 mkdir -p $FOAM_RUN run # 如果下一步没有成功请手动复制 cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity cd cavity blockMesh
运行结果:
/*---------------------------------------------------------------------------*\ | ========= | | | \\ / F ield | foam-extend: Open Source CFD | | \\ / O peration | Version: 4.1 | | \\ / A nd | Web: http://www.foam-extend.org | | \\/ M anipulation | For copyright notice see file Copyright | \*---------------------------------------------------------------------------*/ Build : 4.1-93fffffdb745 Exec : blockMesh Date : Mar 20 2020 Time : 15:47:10 Host : "veen-zhou" PID : 13020 CtrlDict : "/home/veen/foam/foam-extend-4.1/FOAM_RUN/cavity/system/controlDict" Case : /home/veen/foam/foam-extend-4.1/FOAM_RUN/cavity nProcs : 1 sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE). allowSystemOperations : Disallowing user-supplied system call operations // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
安装绿色Paraview
绿色版ParaView安装非常简单,并且在处理网格较多的算例比编译版本的paraFoam要快。用户可以在ParaView官方(或本链接 Paraview-5.8.0)直接下载linux版本的ParaView绿色版,随意解压缩到任意的文件夹,双击打开ParaView/bin/paraview文件即可运行(如下图)。在打开ParaView之后,在任意的OpenFOAM算例下创建一个空文件并命名为case.foam,然后用ParaView打开这个文件即可。
OpenFOAM-V1902
安装of19(编译时间2h)
-
进行系统环境初始化
# 使用root账户 sudo -s # 更新 apt-get update # 安装依赖 apt-get install build-essential flex bison cmake zlib1g-dev libboost-system-dev libboost-thread-dev \ libopenmpi-dev openmpi-bin gnuplot libreadline-dev libncurses-dev libxt-dev \ qt5-default libqt5x11extras5-dev libqt5help5 qtdeclarative5-dev qttools5-dev \ libqtwebkit-dev freeglut3-dev libqt5opengl5-dev texinfo \ libscotch-dev libcgal-dev python python-dev # 退出root exit
-
将下载的安装包解压到OpenFOAM/文件夹下
# 查看系统架构 uname -m # 对于64位系统 source $HOME/OpenFOAM/OpenFOAM-v1912/etc/bashrc WM_LABEL_SIZE=64 # 安装之后发现还是有如下错误: # No completion added for /home/veen/OpenFOAM/OpenFOAM- # v1912/platforms/linux64GccDPInt32Opt/bin... incorrect platform, or not yet compiled? # 解决方案: # 进行bashrc文件的修改 # 打开Home/OpenFOAM/OpenFOAM-v1912//etc/bashrc # 找到export WM_LABEL_SIZE=32 # 修改为WM_LABEL_SIZE=64
-
环境变量修改
echo "alias of1912='source \$HOME/OpenFOAM/OpenFOAM-v1912/etc/bashrc $FOAM_SETTINGS'" >> $HOME/.bashrc # 安装检查 foamSystemCheck
-
继续修改(我也不记得自己改没改了)
cd $WM_PROJECT_DIR export QT_SELECT=qt5
-
进行编译
/Allwmake -j -s -q -l
-
测试安装
# 打开terminal,键入 of1912 blockMesh
出现如下信息即为安装成功
/*---------------------------------------------------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: v1912 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ Build : v1912 OPENFOAM=1912 patch=200316 Arch : "LSB;label=64;scalar=64" Exec : blockMesh Date : Mar 20 2020 Time : 18:40:47 Host : veen-zhou PID : 26190 I/O : uncollated Case : /home/veen/OpenFOAM/OpenFOAM-v1912/tutorials/incompressible/icoFoam/cavity/cavity nProcs : 1 trapFpe: Floating point exception trapping enabled (FOAM_SIGFPE). fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 10) allowSystemOperations : Allowing user-supplied system call operations // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-