liu_shaobo

导航

 

OpenFOAM(Open Source Field Operation and Manipulation)开源的场运算和处理软件,和商用的CFD软件Ansys Fluent,CFX类似。

OpenFOAM安装参考
https://openfoamwiki.net/index.php/Installation/Linux/OpenFOAM-v1906/CentOS_SL_RHEL

 系统:CentOS-7.6 x86_64

1、安装OpenFOAM依赖

# yum install -y autoconf automake gcc glibc gcc-c++ gcc-gfortran git libgcc libstdc++ cmake bison flex patch
# yum install -y boost-devel gmp-devel gstreamer-plugins-base-devel libXi-devel libXinerama-devel libXrandr-devel libXrender-devel \
libXt-devel mpfr-devel ncurses-devel python-devel qt-devel readline-devel zlib-devel

 

2、下载OpenFOAM并解压

# mkdir -p /data/OpenFOAM
# cd /data/OpenFOAM
# wget -c https://sourceforge.net/projects/openfoam/files/v2006/OpenFOAM-v2006.tgz?use_mirror=nchc -O OpenFOAM-v2006.tgz
# wget -c https://sourceforge.net/projects/openfoam/files/v2006/ThirdParty-v2006.tgz?use_mirror=nchc -O ThirdParty-v2006.tgz
# tar zxvf OpenFOAM-v2006.tgz
# tar zxvf ThirdParty-v2006.tgz

 

3、修改安装路径和其他编译环境

# sed -i 's/$HOME/\/data/g' OpenFOAM-v2006/etc/bashrc

修改其他细节

# sed -i 's#\(default_gcc_version=\)gcc-4.8.5#\1gcc-7.2.0#' OpenFOAM-v2006/etc/config.sh/compiler
# sed -i 's#gmp-system#gmp-6.1.2#' OpenFOAM-v2006/etc/config.sh/compiler
# sed -i 's#mpfr-system#mpfr-4.0.1#' OpenFOAM-v2006/etc/config.sh/compiler
# sed -i 's#mpc-system#mpc-1.1.0#' OpenFOAM-v2006/etc/config.sh/compiler
# sed -i 's#\(cmake_version=\)cmake-system#\1cmake-3.12.4#' OpenFOAM-v2006/etc/config.sh/cmake
# sed -i 's=\(^unset WM_ARCH_OPTION\)=#\1=' OpenFOAM-v2006/etc/config.sh/settings

 

加载OpenFOAM环境变量

# source /data/OpenFOAM/OpenFOAM-v2006/etc/bashrc WM_COMPILER_TYPE=ThirdParty WM_COMPILER=Gcc72 WM_MPLIB=OPENMPI WM_ARCH_OPTION=64
# echo "alias of2006='source /data/OpenFOAM/OpenFOAM-v2006/etc/bashrc $FOAM_SETTINGS'" >> $HOME/.bashrc

 

使用别名来管理多OpenFOAM版本

# of2006

加载环境变量时,可能会看到如下消息,需求编译Gcc版本

===============================================================================
Warning in /data/OpenFOAM/OpenFOAM-v2006/etc/config.sh/settings:
Cannot find 'Gcc72' compiler installation
/data/OpenFOAM/ThirdParty-v2006/platforms/linux64/gcc-7.2.0

Either install this compiler version, or use the system compiler by setting
WM_COMPILER_TYPE to 'system' in $WM_PROJECT_DIR/etc/bashrc.
===============================================================================


4、获取编译GCC和binutils的脚本

# cd $WM_THIRD_PARTY_DIR
# wget https://raw.githubusercontent.com/wyldckat/scripts4OpenFOAM3rdParty/master/getGcc
# wget https://raw.github.com/wyldckat/ThirdParty-2.0.x/binutils/getBinutils
# wget https://raw.github.com/wyldckat/ThirdParty-2.0.x/binutils/makeBinutils
# chmod +x get* make*

 

编译Gcc 7.2.0

# sed -i 's#gccPACKAGE.tar.bz2#gccPACKAGE.tar.gz#' getGcc
# ./getGcc gcc-7.2.0 gmp-6.1.2 mpfr-4.0.1 mpc-1.1.0
# ./makeGcc
# wmRefresh

 

编译GNU Binutils

# ./getBinutils
# ./makeBinutils gcc-7.2.0

 

5、编译Cmake
ParaView 5.6.0需要较新的CMake3.0以上版本,而CGAL也需要CMake;

# cd $WM_THIRD_PARTY_DIR
# wget https://raw.github.com/wyldckat/scripts4OpenFOAM3rdParty/master/getCmake
# chmod +x getCmake
# sed -i -e 's#2.8#3.12#' -e 's#version}.3#version}.4#' getCmake
# ./getCmake
# ./makeCmake cmake-3.12.4 > log.makeCM 2>&1
# wmRefresh

 

6、编译OpenFOAM

# foamSystemCheck
# cd $WM_PROJECT_DIR
# ./Allwmake -j -s -l

 

7、测试OpenFOAM

# cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily .
# cd pitzDaily

生成几何结构网格

# blockMesh

求解

# simpleFoam

 

8、并行运算,使用cavity算例举例

# cp -r /data/OpenFOAM/OpenFOAM-v2006/tutorials/incompressible/icoFoam/cavityMappingTest .
# cd cavityMappingTest/
# ./Allrun-parallel 

备注:
如果需要修改计算的CPU数量,修改算例中decomposeParDict文件的numberOfSubdomains参数,这个等于CPU核数;

 

 
posted on 2020-08-09 11:53  liu_shaobo  阅读(2463)  评论(0编辑  收藏  举报