首先,请浏览我写的第一篇内容,链接如下
https://blog.csdn.net/joshua_shi_t/article/details/124604379
现在,我已经将第一篇中的容器定义文件更新了,安装了GMSH,并且编译安装了OpenFOAM-5,6,7,8,9,v1206,使用source /etc/bashrc &&${OF90} 激活某个版本的OpenFOAM,容器定义文件如下。
siyuan1.DockerFile
# siyuan1.DockerFile centos:8
FROM centos:8
RUN sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-* && \
sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
RUN yum update -y && \
rm -rf /var/cache/yum/*
RUN yum install -y \
tree \
vim \
git \
bzip2 \
wget && \
rm -rf /var/cache/yum/*
RUN echo "basic tools completed !! "
RUN yum install -y \
mesa-libGLU \
libXrender \
libXcursor \
libXft \
libXinerama \
libgomp \
&& \
rm -rf /var/cache/yum/*
RUN echo "gmsh basic libs completed !! "
RUN mkdir -p opt/GMSH/ && \
cd opt/GMSH/ && \
wget http://www.gmsh.info/bin/Linux/gmsh-4.4.0-Linux64.tgz && \
tar -xzvf gmsh-4.4.0-Linux64.tgz && \
rm -rvf gmsh-4.4.0-Linux64.tgz && \
echo "export PATH='$PATH':/opt/GMSH/gmsh-4.4.0-Linux64/bin " >> /etc/bashrc
RUN echo "gmsh 4.4.0 completed !! "
RUN yum install -y \
epel-release \
cmake3 \
make \
patch \
flex \
bison \
zlib-devel \
boost-system \
boost-thread \
readline-devel \
ncurses-devel \
gcc-c++ \
gcc \
openmpi \
openmpi-devel \
boost \
openssl && \
rm -rf /var/cache/yum/*
RUN echo "OpenFOAM tools completed !! "
RUN echo "192.30.255.113 github.com" >> /etc/hosts
RUN echo "export PATH='$PATH':/usr/lib64/openmpi/bin:/usr/lib64/openmpi/bin/mpicc " >> /etc/bashrc
RUN mkdir -p /opt && \
export BUILD_DIR=/opt/OpenFOAM && \
mkdir -p $BUILD_DIR && \
cd $BUILD_DIR && \
git clone https://gitee.com/xinxinzhou1995/OpenFOAM-4.x && \
git clone https://gitee.com/xinxinzhou1995/ThirdParty-4.x
RUN echo "OpenFOAM 4.x download completed !!"
RUN echo "export OF40='source /opt/OpenFOAM/OpenFOAM-4.x/etc/bashrc ' " >> /etc/bashrc && \
cd /opt/OpenFOAM/OpenFOAM-4.x && \
ncount=$(grep -n 'export FOAM_INST_DIR=\$HOME/\$WM_PROJECT' etc/bashrc | cut -f1 --delimiter=':') && \
sed -i "${ncount}d" etc/bashrc && \
ncount=$(($ncount-1)) && \
sed -i "${ncount}a export FOAM_INST_DIR=/opt/\$WM_PROJECT" etc/bashrc && \
source /etc/bashrc && \
${OF40} # &&
# ./Allwmake -j
# RUN echo "OpenFOAM 4.x make completed !! "
RUN mkdir -p /opt && \
export BUILD_DIR=/opt/OpenFOAM && \
mkdir -p $BUILD_DIR && \
cd $BUILD_DIR && \
git clone https://gitee.com/Allenxcw/OpenFOAM-5.x && \
git clone https://gitee.com/Allenxcw/ThirdParty-5.x
RUN echo "OpenFOAM 5.x download completed !!"
RUN echo "export OF50='source /opt/OpenFOAM/OpenFOAM-5.x/etc/bashrc ' " >> /etc/bashrc && \
cd /opt/OpenFOAM/OpenFOAM-5.x && \
ncount=$(grep -n 'export FOAM_INST_DIR=\$HOME/\$WM_PROJECT' etc/bashrc | cut -f1 --delimiter=':') && \
sed -i "${ncount}d" etc/bashrc && \
ncount=$(($ncount-1)) && \
sed -i "${ncount}a export FOAM_INST_DIR=/opt/\$WM_PROJECT" etc/bashrc && \
source /etc/bashrc && \
${OF50} && \
./Allwmake -j
RUN echo "OpenFOAM 5.x make completed !! "
RUN mkdir -p /opt && \
export BUILD_DIR=/opt/OpenFOAM && \
mkdir -p $BUILD_DIR && \
cd $BUILD_DIR && \
git clone https://gitee.com/diyboy/OpenFOAM-6 && \
git clone https://gitee.com/diyboy/ThirdParty-6
RUN echo "OpenFOAM 6.0 download completed !!"
RUN echo "export OF60='source /opt/OpenFOAM/OpenFOAM-6/etc/bashrc ' " >> /etc/bashrc && \
cd /opt/OpenFOAM/OpenFOAM-6 && \
ncount=$(grep -n 'export FOAM_INST_DIR=\$HOME/\$WM_PROJECT' etc/bashrc | cut -f1 --delimiter=':') && \
sed -i "${ncount}d" etc/bashrc && \
ncount=$(($ncount-1)) && \
sed -i "${ncount}a export FOAM_INST_DIR=/opt/\$WM_PROJECT" etc/bashrc && \
source /etc/bashrc && \
${OF60} && \
./Allwmake -j
RUN echo "OpenFOAM 6.0 make completed !! "
RUN mkdir -p /opt && \
export BUILD_DIR=/opt/OpenFOAM && \
mkdir -p $BUILD_DIR && \
cd $BUILD_DIR && \
git clone https://gitee.com/zhouxu2012/OpenFOAM-7 && \
git clone https://gitee.com/zhouxu2012/ThirdParty-7
RUN echo "OpenFOAM 7.0 download completed !!"
RUN echo "export OF70='source /opt/OpenFOAM/OpenFOAM-7/etc/bashrc ' " >> /etc/bashrc && \
cd /opt/OpenFOAM/OpenFOAM-7 && \
ncount=$(grep -n 'export FOAM_INST_DIR=\$HOME/\$WM_PROJECT' etc/bashrc | cut -f1 --delimiter=':') && \
sed -i "${ncount}d" etc/bashrc && \
ncount=$(($ncount-1)) && \
sed -i "${ncount}a export FOAM_INST_DIR=/opt/\$WM_PROJECT" etc/bashrc && \
source /etc/bashrc && \
${OF70} && \
./Allwmake -j
RUN echo "OpenFOAM 7.0 make completed !! "
RUN mkdir -p /opt && \
export BUILD_DIR=/opt/OpenFOAM && \
mkdir -p $BUILD_DIR && \
cd $BUILD_DIR && \
git clone https://gitee.com/zzw0799/OpenFOAM-8 && \
git clone https://gitee.com/zzw0799/ThirdParty-8
RUN echo "OpenFOAM 8.0 download completed !!"
RUN echo "export OF80='source /opt/OpenFOAM/OpenFOAM-8/etc/bashrc ' " >> /etc/bashrc && \
cd /opt/OpenFOAM/OpenFOAM-8 && \
ncount=$(grep -n 'export FOAM_INST_DIR=\$HOME/\$WM_PROJECT' etc/bashrc | cut -f1 --delimiter=':') && \
sed -i "${ncount}d" etc/bashrc && \
ncount=$(($ncount-1)) && \
sed -i "${ncount}a export FOAM_INST_DIR=/opt/\$WM_PROJECT" etc/bashrc && \
source /etc/bashrc && \
${OF80} && \
./Allwmake -j
RUN echo "OpenFOAM 8.0 make completed !! "
RUN mkdir -p /opt && \
export BUILD_DIR=/opt/OpenFOAM && \
mkdir -p $BUILD_DIR && \
cd $BUILD_DIR && \
git clone https://gitee.com/cjthermo/OpenFOAM-9 && \
git clone https://gitee.com/cjthermo/ThirdParty-9
RUN echo "OpenFOAM 9.0 download completed !!"
RUN echo "export OF90='source /opt/OpenFOAM/OpenFOAM-9/etc/bashrc ' " >> /etc/bashrc && \
cd /opt/OpenFOAM/OpenFOAM-9 && \
ncount=$(grep -n 'export FOAM_INST_DIR=\$HOME/\$WM_PROJECT' etc/bashrc | cut -f1 --delimiter=':') && \
sed -i "${ncount}d" etc/bashrc && \
ncount=$(($ncount-1)) && \
sed -i "${ncount}a export FOAM_INST_DIR=/opt/\$WM_PROJECT" etc/bashrc && \
source /etc/bashrc && \
${OF90} && \
./Allwmake -j
RUN echo "OpenFOAM 9.0 make completed !! "
RUN cd /opt/OpenFOAM/ && \
wget https://sourceforge.net/projects/openfoam/files/v2106/OpenFOAM-v2106.tgz && \
wget https://sourceforge.net/projects/openfoam/files/v2106/ThirdParty-v2106.tgz && \
tar -xzvf OpenFOAM-v2106.tgz && \
rm -rvf OpenFOAM-v2106.tgz && \
tar -xzvf ThirdParty-v2106.tgz && \
rm -rvf ThirdParty-v2106.tgz
RUN echo "OpenFOAM v2106 download completed !!"
RUN echo "export OFv2106='source /opt/OpenFOAM/OpenFOAM-v2106/etc/bashrc ' " >> /etc/bashrc && \
cd /opt/OpenFOAM/OpenFOAM-v2106 && \
ncount=$(grep -n 'projectDir=\"\$HOME/OpenFOAM/OpenFOAM-\$WM_PROJECT_VERSION\"' etc/bashrc | cut -f1 --delimiter=':') && \
sed -i "${ncount}d" etc/bashrc && \
ncount=$(($ncount-1)) && \
sed -i ${ncount}'a projectDir="/opt/openfoam/OpenFOAM-\$WM_PROJECT_VERSION"' etc/bashrc && \
source /etc/bashrc && \
${OFv2106} && \
./Allwmake -j
RUN echo "OpenFOAM v2106 make completed !! "
接下来讲一下如何使用容器
1.编译自己写的求解器
export myOFenv2=OF70 &&
myScript2=". /etc/bashrc " &&
myScript2=${myScript2}"&&\${"${myOFenv2}"} " &&
myScript2=${myScript2}"&&wclean "${mySolverPath}" " &&
myScript2=${myScript2}"&&wmake "${mySolverPath}" " &&
myScript2=${myScript2}"&&wclean "${mySolverPath}" " &&
singularity exec ../../../siyuan1.sif /bin/bash -c "${myScript2}"
2.划分网格
myScript2="source /etc/bashrc " &&
myScript2=${myScript2}"&&\${"${myOFenv2}"} " &&
myScript2=${myScript2}"&&/opt/GMSH/gmsh-4.4.0-Linux64/bin/gmsh ./constant/geometry/"${myMsh}".geo -3 -format msh22 " &&
myScript2=${myScript2}"&&gmshToFoam ./constant/geometry/"${myMsh}".msh " &&
myScript2=${myScript2}"&&renumberMesh -overwrite -noFunctionObjects " &&
myScript2=${myScript2}"&&setFields -dict ./system/setFD_aw " &&
myScript2=${myScript2}"&&checkMesh " &&
myScript2=${myScript2}"&&decomposePar -force " &&
singularity exec ${IMAGE_NAME} /bin/bash -c "${myScript2}"
3.运行算例
#!/bin/bash
#SBATCH --job-name=myCase
#SBATCH --partition=64c512g
#SBATCH -N 1
#SBATCH --ntasks-per-node=default
#SBATCH --output=%j.out
#SBATCH --error=%j.err
module purge &&
module --ignore-cache load "openmpi/4.1.1-gcc-9.3.0" &&
IMAGE_NAME=/dssg/home/acct-naoxb/naoxb/tongxin/siyuan1.sif &&
myScript2="source /etc/bashrc " &&
myScript2=${myScript2}"&&\${"${myOFenv2}"} " &&
myScript2=${myScript2}"&&"${myAppBin}" -parallel " &&
echo "begin mpi running " &&
echo "myScript2 is: "${myScript2} &&
echo "myAppBin is: "${myAppBin} &&
mpirun -n ${SLURM_NTASKS} singularity exec ${IMAGE_NAME} /bin/bash -c "${myScript2}" &&
echo "end mpi running " &&
myScript2="source /etc/bashrc " &&
myScript2=${myScript2}"&&\${"${myOFenv2}"} " &&
myScript2=${myScript2}"&&reconstructPar " &&
singularity exec ${IMAGE_NAME} /bin/bash -c "${myScript2}"