前面的例子中,计算工作都是利用Scheme完成的。本案例演示利用Scheme构建界面,利用UDF执行计算。其中核心内容在于Scheme与UDF之间的数据交换。
本案例实际上只包含了将Scheme数据传递给Fluent,目前并没有搞清楚如何将UDF计算完成的数据传递给Scheme。
完成的界面如下图所示。
点击按钮Add后,能将A与B的和输出到TUI窗口中。
注:虽然说Scheme的功能足够强大,但是UDF在Fluent中毕竟更加灵活,也能够实现更多的功能。
代码如下所示。
;RP Variable Create Function
(define (make-new-rpvar name default type)
(if (not (rp-var-object name))
(rp-var-define name default type #f)))
;RP Variable Declarations
(make-new-rpvar 'myudf/real 0.0 'real)
(make-new-rpvar 'myudf/int 0 'int)
(make-new-rpvar 'myudf/result 0.0 'real)
;Dialog Box Definition
(define gui-dialog-box
;Let Statement, Local Variable Declarations
(let ((dialog-box #f)
(table)
(myudf/box1)
(myudf/box2)
(myudf/box3)
(myudf/real)
(myudf/int)
)
;Update-CB Function, Invoked When Dialog Box Is Opened
(define (update-cb . args)
(cx-set-integer-entry myudf/int (rpgetvar 'myudf/int))
(cx-set-real-entry myudf/real (rpgetvar 'myudf/real))
)
;Apply-CB Function, Invoked When "OK" Button Is Clicked
(define (apply-cb . args)
(rpsetvar 'myudf/real (cx-show-real-entry myudf/real))
(rpsetvar 'myudf/int (cx-show-integer-entry myudf/int))
)
;Button-CB Function, Invoked When "Test Button" Is Clicked
(define (button-cb . args)
(rpsetvar 'myudf/real (cx-show-real-entry myudf/real))
(rpsetvar 'myudf/int (cx-show-integer-entry myudf/int))
(%run-udf-apply 1)
)
;Args Function, Used For Interface Setup, Required For Apply-CB, Update-CB, and Button-CB Sections
(lambda args
(if (not dialog-box)
(let ()
(set! dialog-box (cx-create-panel "myUDF Dialog Box" apply-cb update-cb))
(set! table (cx-create-table dialog-box "" 'border #f 'below 0 'right-of 0))
(set! myudf/box1 (cx-create-table table "Simple Data Inputs" 'row 0 'col 0))
(set! myudf/int (cx-create-integer-entry myudf/box1 "Input A:" 'row 2))
(set! myudf/real (cx-create-real-entry myudf/box1 "Input B:" 'row 3))
(cx-create-button table "Add" 'activate-callback button-cb 'row 1)
) ;End Of Let Statement
) ;End Of If Statement
;Call To Open Dialog Box
(cx-show-panel dialog-box)
) ;End Of Args Function
) ;End Of Let Statement
) ;End Of GUI-Dialog-Box Definition
(gui-dialog-box)
UDF代码如下所示。
#include "udf.h"
DEFINE_EXECUTE_FROM_GUI(check, libudf, mode)
{
//Variable Declarations
int iNumber = RP_Get_Integer("myudf/int");
float RNumber = RP_Get_Real("myudf/real");
float result = iNumber + RNumber;
if(mode == 1){
Message("%d + % f = %f n",iNumber, RNumber ,result);
}
else
{
Message("Error!n");
}
}
本篇文章来源于微信公众号: CFD之道
评论前必须登录!
注册