Gnuplot监测OpenFOAM残差和数据


前言

对于只关注定常解的问题,监视残差变化情况从而确认数值计算是否已经收敛是有必要的。这里提供一种使用Gnuplot完成开源CFD平台OpenFOAM的残差和数据监测的一种方法。以OpenFOAM-v2106为例,其计算过程的输出文件如下所示:

diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
diagonal:  Solving for rhoUx, Initial residual = 0, Final residual = 0, No Iterations 0
diagonal:  Solving for rhoUy, Initial residual = 0, Final residual = 0, No Iterations 0
diagonal:  Solving for rhoUz, Initial residual = 0, Final residual = 0, No Iterations 0
smoothSolver:  Solving for Ux, Initial residual = 4.204789075e-08, Final residual = 9.505979759e-12, No Iterations 2
smoothSolver:  Solving for Uy, Initial residual = 8.036520895e-08, Final residual = 3.548072582e-11, No Iterations 2
smoothSolver:  Solving for Uz, Initial residual = 2.057832037e-07, Final residual = 7.249373744e-11, No Iterations 2
diagonal:  Solving for rhoE, Initial residual = 0, Final residual = 0, No Iterations 0
smoothSolver:  Solving for e, Initial residual = 6.505993477e-08, Final residual = 5.28420435e-11, No Iterations 2
DILUPBiCGStab:  Solving for omega, Initial residual = 9.252288093e-08, Final residual = 2.873752782e-12, No Iterations 1
DILUPBiCGStab:  Solving for k, Initial residual = 9.522602907e-07, Final residual = 3.453447618e-10, No Iterations 1
ExecutionTime = 18796.65 s  ClockTime = 19061 s

forces forces1 write:
    Sum of forces
        Total    : (434.6950336 17.45089989 0.006001904507)
        Pressure : (425.5054724 17.48730865 0.005933362413)
        Viscous  : (9.18956119 -0.03640876391 6.85420939e-05)
    Sum of moments
        Total    : (0.0004268137063 0.0008604855189 -1.94903144)
        Pressure : (0.0004013259427 0.0007796865469 -1.980225054)
        Viscous  : (2.548776366e-05 8.079897193e-05 0.03119361418)

一、残差监测

参考CFD-online的一篇tutorial,编写如下Gnuplot脚本

set title "Residuals"
set ylabel 'Residual'
set xlabel 'Iteration'

set logscale y
set format y "%1.0e"

plot "< cat log | grep 'Solving for Ux' | cut -d' ' -f9 | tr -d ','" t 'Ux' w l

pause 1
reread

解读一下最关键的 plot 代码,使用正则表达式从 log 文件中提取所需的 Ux 残差数据并绘图
cat log 读取 log 文件,因此为了检测残差需要将求解器输出重定向至 log 文件
grep ‘Solving for Ux’ 搜索 Ux 残差所在的行
cut -d’ ’ -f9 截取第9个空格之后的内容
tr -d ‘,’ 删除逗号

二、数据监测

示例输出中包含 forces 和 moments 的数据,下面的Gnuplot脚本演示如何监测 x 方向的力,参考一篇CSDN博客

set title "Forces"
set ylabel 'Forces'
set xlabel 'Iteration'

plot "< awk '/Sum of forces/{getline a;print a}' log | cut -d' ' -f14 | tr -d '('" title 'Fx' with lines

pause 1
reread

解读其中最关键的用于抽取数据的正则表达式
awk ‘/Sum of forces/{getline a;print a}’ log 找到 Sum of forces 所在的行的下一行
cut -d’ ’ -f14 截取第14个空格之后的内容
tr -d ‘(’ 删掉左括号


Contact me
Email: 18810577380@163.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值