个人的网站学习记录
ANSYS System Coupling
ANSYS低版本下命令行运行System Coupling进行流固耦合计算。

在用命令行运行SystemCoupling之前,需要先在Workbench平台上设置好Transient Structural、Fluid(Fluent)和Systemcoupling三个模块,并分别导出文件structural.datfluidFlow.cascoupling.sci(名字可以不用按照这个取,关键是有这三个类型的文件)。之后需要新建三个文件夹Structural_CmdLine,Fluid_CmdLine,Coupling_CmdLine,并把上述的三个文件分别放入。

另外在Fluid_CmdLine文件夹下还要再新建一个journal文件,用于Fluent相应的操作,包含以下内容:

file/start-transcript "Solution 1.trn"
file set-batch-options , yes ,
file/read-case/fluidFlow.cas
s i i
(sc-solve)
wcd FLUENTRestart.cas.gz
exit
ok

Run the initial analyse(Windows)

"C:\Program Files\ANSYS Inc\v182\aisol\workbench.bat" -cmd ansys.services.systemcoupling.exe -inputFile coupling.sci
在这之后会启动Systemcoupling.exe并在目录下生成`scServer.scs`,需要记住端口号和`hostname`之后重新开启两个CMD分别用于运行Fluent和ANSYS,如下:
"C:\Program Files\ANSYS Inc\v182\fluent\ntbin\win64\fluent.exe" 3ddp -hidden -driver null -scport=62391 -schost=DESKTOP-szj -scname="Solution 1" -i fluidFlow.jou>FLUENT.out
"C:\Program Files\ANSYS Inc\v182\ansys\bin\winx64\ANSYS182.exe" -b -scport 62391 -schost DESKTOP-szj -scname "Solution" -i ..\structural.dat -o ANSYS.out

Restart the anslyse(Windows)

重算之前,需要准备一些必要的文件,首先是journal文件需修改并含有以下内容:

file/start-transcript "Solution 2.trn"
file set-batch-options , yes ,
rcd/fluidFlow-1-00050.cas   ##依据实际情况选择要重新开始的计算点
(sc-solve)
exit
ok

其次是在structural.dat文件的基础上新建文件structuralRestart.dat,需包含 以下内容:

/batch
/solu
/gst,on,on
antype,4,rest,50,1,continue  ##依据实际情况选择重新开始的计算点
solve
save
finish
/exit

之后便可以在某个计算保存点重新计算了:

"C:\Program Files\ANSYS Inc\v182\aisol\workbench.bat" -cmd ansys.services.systemcoupling.exe -inputFile coupling.sci  –resultFile scResult_01_000050.scr
"C:\Program Files\ANSYS Inc\v182\fluent\ntbin\win64\fluent.exe" 3ddp -hidden -driver null -scport=64965 -schost=DESKTOP-szj -scname="Solution 1"  -i  fluidFlowRestart.jou>FLUENTRestart.out
"C:\Program Files\ANSYS Inc\v182\ansys\bin\winx64\ANSYS182.exe" -b -scport 64965 -schost DESKTOP-szj -scname "Solution" -i structuralRestart.dat -o ANSYSRestart.out

后处理

后处理可以在CFD-POST中进行,只需要在导入结果时,勾选select Keep current cases loaded,取消勾选Open in new view

Details Something small enough to escape casual notice.

Linux sh脚本

#!/bin/bash
COUPLING=coupling.sci
STRUCTURALDATA=structural.dat
JOURNAL=fluidFlow.jou
Version=3d   ## Set Dimension of Fluent
LOG_FILE=run.log  ## fluent run log file
ERR_FILE=run.err  ## fluent run error file
PBS_O_WORKDIR=~/fsi   ##需要在家目录下新建fsi目录
#echo "--- Starting job at:`date`"
# number of processors for Ansys
NPA=1
#the number of processors for Fluent
NPF=1
# make sure I'm the only one that can read my output
#umask 0077

cd ${PBS_O_WORKDIR}
mkdir Structural Fluid Coupling
# Start coupling program
mv ${COUPLING} Coupling/
cd Coupling/
/usr/ansys_inc/v182/aisol/.workbench -cmd ansys.services.systemcoupling.exe -inputFile ${COUPLING} &

# Wait until scServer.scs is created
TIMEOUT=60
while [ ! -f scServer.scs -a $TIMEOUT -gt 0 ]; do
    TIMEOUT=$((TIMEOUT-1))
    sleep 2
done                            
if [ -f scServer.scs ]; then
    # Parse the data in scServer.scs
    readarray JOB < ${PBS_O_WORKDIR}/Coupling/scServer.scs
    HOSTPORT=(${JOB[0]//@/ })

    # Run Fluent
    mv ${PBS_O_WORKDIR}/${JOURNAL} ${PBS_O_WORKDIR}/*.cas*  ${PBS_O_WORKDIR}/Fluid/
    cd ${PBS_O_WORKDIR}/Fluid/
    fluent ${Version} -g -t${NPF} -driver null -ssh -scport=${HOSTPORT[0]} -schost=${HOSTPORT[1]} -scname="${JOB[4]}" -i ${JOURNAL} 1> ${LOG_FILE} 2> ${ERR_FILE} &

    # Run Ansys
    mv ${PBS_O_WORKDIR}/${STRUCTURALDATA} ${PBS_O_WORKDIR}/Structural/
    cd ${PBS_O_WORKDIR}/Structural/
    ansys182 -b -scport=${HOSTPORT[0]} -schost=${HOSTPORT[1]} -scname="${JOB[2]}" -i ${STRUCTURALDATA} -o ansys.out -np ${NPA}
fi
echo "--- Job finished at:`date`"                                                   

注意

  1. 在windows下用默认文本编辑器编辑sh脚本时,由于其换行符为\r\n,转到Linux平台运行sh时会出现错误,此时需要用dos2unix工具转换,或者用非默认文本编辑器编辑
  2. 经过测试,分配给Fluent的核数不能是偶数,否则计算过程会出现问题
总逻辑核数 结构求解器使用核数 Fluent使用核数 精度 CPU时间
8 1 7 3d 24.54
8 3 5 3ddp 19.17
8 1 7 3ddp 27.3
8 4 4 不行
7 2 5 3d 19.03
7 3 4 不行

PBS脚本

#!/bin/bash
 
#PBS -q post1                 
#PBS -N fsi_test           
#PBS -l nodes=1:ppn=3   
#PBS -l walltime=9600:00:00
#PBS -V
#PBS -o job.log
#PBS -e job.err
###PBS -j oe
###PBS -m ae -M szj818@qq.com
 
COUPLING=coupling.sci
STRUCTURALDATA=structural.dat
JOURNAL=fluidFlow.jou
Version=3d   ## Set Dimension of Fluent
LOG_FILE=run.log  ## fluent & ansys run log file
ERR_FILE=run.err  ## fluent & ansys run error file
 
echo "--- This job is:$PBS_JOBNAME(${PBS_JOBID%.*})@$PBS_QUEUE" 
echo "--- Current working directory is:${PBS_O_WORKDIR}"
#echo "--- Running on ${nprocs} processes (cores) on the following nodes:" && cat $PBS_NODEFILE | uniq
echo "--- Starting job at:`date`"
 
# number of processors for Ansys
NPA=2
# Automatically calculate the number of processors left over for Fluent
NP=$(cat ${PBS_NODEFILE} | wc -l)
NP=$((NP*2))
NPF=$((NP-NPA))
 
# make sure I'm the only one that can read my output
#umask 0077
 
cd $PBS_O_WORKDIR
mkdir Structural  Fluid  Coupling
# Start coupling program
mv $COUPLING Coupling/
cd Coupling/
/cluster/apps/ansys/18.2/ansys_inc/v182/aisol/.workbench -cmd ansys.services.systemcoupling.exe -inputFile ${COUPLING} &
 
# Wait until scServer.scs is created
TIMEOUT=60
while [ ! -f scServer.scs -a $TIMEOUT -gt 0 ]; do
    TIMEOUT=$((TIMEOUT-1))
    sleep 2
done
 
if [ -f scServer.scs ]; then
 
    # Parse the data in scServer.scs
    readarray JOB < $PBS_O_WORKDIR/Coupling/scServer.scs
    HOSTPORT=(${JOB[0]//@/ })
 
    # Run Fluent
    mv $PBS_O_WORKDIR/$JOURNAL $PBS_O_WORKDIR/*.cas*  $PBS_O_WORKDIR/Fluid/
    cd $PBS_O_WORKDIR/Fluid/
    fluent $Version -g -t${NPF} -driver null -ssh -scport=${HOSTPORT[0]} -schost=${HOSTPORT[1]} -scname="${JOB[4]}" -i ${JOURNAL} 1> $LOG_FILE 2> $ERR_FILE &
 
    # Run Ansys
    mv $PBS_O_WORKDIR/$STRUCTURALDATA $PBS_O_WORKDIR/Structural/
    cd $PBS_O_WORKDIR/Structural/
    ansys182 -b -scport=${HOSTPORT[0]} -schost=${HOSTPORT[1]} -scname="${JOB[2]}" -i ${STRUCTURALDATA} -o ansys.out -np ${NPA}
 
fi
 
echo "--- Job finished at:`date`"
qstat | grep $PBS_JOBNAME | awk '{print "--- Total CPU hours:"$4}'
date >> $HOME/sun/fluent_flag
 

附上算例文件及源码链接

参考文献

  1. 官方ANSYS18.2 SystemCoupling Tutorial
  2. sun.ac.za—-Fluid-Structure Interaction

最后修改于 2019-11-07