当变量超过任意设定的变量限制时终止fluent模拟【翻译】

时间:2023-11-16 08:04:25

一些时候某个特定的变量(压力,速度,温度等)发散会造成不合理的计算结果。在许多算例,当变量超过某些合理的限制时,自动停止/打断模拟是有帮助的。

解决方法是联合UDF和scheme文件。UDF将会遍历所有的单元并且当任意用户定义的限制被超过时会将标识符开启。接下来的这个算例中我们不希望速度超过1.5m/ s

UDF代码如下:

#include "udf.h"

#include "math.h"

#include "var.h"

DEFINE_ADJUST(interrupt_fcn, d)

{

Thread *t;

cell_t c;

int x = 0;

thread_loop_c(t,d)  /
*遍历所有的计算域*/

{

begin_c_loop(c,t)  
/ *遍历所有的单元*/

{

if(sqrt(C_U(c,t)*C_U(c,t)+C_V(c,t)*C_V(c,t)+C_W(c,t)*C_W(c,t))>1.5)
/ *如果有单元的速度超过1.5m/s*/

{

x=1;   
/ *设置x的值为1*/

break;  /
*跳出循环*/

}

}

end_c_loop(c,t)

break;  /
*跳出对计算域的循环*/

}

x=PRF_GIHIGH1(x); / *
PRF_GIHIGH1计算x的最大值并返回*/

if(x==1)

RP_Set_Integer("interrupt/ flag",1); /
*转换表示符*/

}

Scheme代码:

(rp-var-define 'interrupt/flag 0 'integer #f)

(define (interrupt)

    
(if (> (%rp-var-value 'interrupt/flag) 0)

    
(cx-interrupt)))

步骤如下:


用户读入case/data文件,scheme文件和UDF


挂载“interrupt_fcn”到adjust函数


在Solve-Execute Commands面板输入"(interrupt)"

完成以上步骤,一旦启动fluent进行模拟,scheme文件会在速度超过1.5m/s时打断模拟,结果可以给出即将发散的点/原因。