仿真在线:有限元分析咨询与培训中心——Ansys|Fluent|Abaqus|HFSS|SolidWorks|课程培训

Fluent:UDF to compute forces and momentson surface zones and print to file

2017-03-21  by:CAE仿真在線  來源:互聯網

Problem:Currently, Fluent cannot print force/moment data to file, only to screen. Resolution:SYNOPSIS
=========
* UDF and SCHEME interface have been added to compute surface forces/moments and print results to file and/or to the GUI.

* The UDF is a DEFINE_ON_DEMAND type, so that it is always executed at the end of an iteration.

* This UDF has been tested in SERIAL AND PARALLEL and matches FLUENT'S output exactly.

CONTENTS
==========
Instructions, 1 UDF and 1 Scheme file... sample case/data files available from author


INSTRUCTIONS
==============
1. Compile UDF
2. Load case/data
3. Read scheme file fm.scm
This adds a component under Solve->Monitors->Force and Moment Data....
4. Load the UDF
5. Set up case.
6. Under Solve->Monitors->Force and Moment Data....
Pick Print/ Write to send output of Force and Moment computation to GUI and/or files (force.out and moment.out), respectively. Data files are always appended!

NOTE: Computation is done upon execution of the EXECUTE_ON_DEMAND function "force_and_moment"

Pick surfaces (pick walls only!)
Enter coordinates for moment center
Click OK

6. Iterate
7. Click EXECUTE_ON_DEMAND... (force_and_moment) to see tresults (all quantities in SI units).

OUTPUT FORMAT
+++++++++++++++
Forces:

Time Fp(x) Fp(y) Fp(z) Fv(x) Fv(y) Fv(z) Ft(x) Ft(y) Ft(z)

F = Force
p = pressure
v = viscous
t = total
(x) = x-component
(y) = y-component
(z) = z-component

This data is sent to "force.out" if the Check Box "Write to File" is checked in the GUI panel



Moments:

Same as for forces.... Quantities are in N-m. Output sent to file "moment.out".

NOTE: output file have been hardwired into UDF. This is easily modified.



/*************************/
/* UDF SOURCE CODE fm.c */
/*************************/
/* FLUENT UDF to calculate forces and moments about specified point */
/* Uses scheme file: fm.scm */
/* Last tested on FLUENT v6.0.20 */

/* AUTHOR: William Wangard, Ph.D. */
/* Last Modified: January 23, 2003 */


#include "udf.h"

void fm_cross(real a[], real b[], real c[]);

#define FORCE_OUTPUT_FILE "force.out"
#define MOMENT_OUTPUT_FILE "moment.out"
#define MAX_THREADS 200
#define pi 3.1415926
DEFINE_ON_DEMAND(force_and_moment) /* use define function hooks panel in fluent */
{

int i, n, n_threads, thread_n_id, thread_id[MAX_THREADS];
cxboolean fm_write_p, fm_print_p;

Domain *domain = Get_Domain(1);

Thread *thread = NULL;

FILE *force_output_file;
FILE *moment_output_file;

real r[ND_3], origin[ND_3], xc[ND_3];

real Amag, Atot=0., A_thread_part=0.0;

real Force[ND_3], Force_viscous[ND_3], Force_pressure[ND_3],
Force_viscous_tot[ND_3], Force_pressure_tot[ND_3], Force_tot[ND_3], A[ND_3];

real Moment[ND_3], Moment_viscous[ND_3], Moment_pressure[ND_3],
Moment_tot[ND_3], Moment_viscous_tot[ND_3], Moment_pressure_tot[ND_3];

face_t f;



/* get true or false value from solver - panel inputs for print and write */
#if !RP_NODE
fm_write_p = RP_Get_Boolean("fm/write?");
fm_print_p = RP_Get_Boolean("fm/print?");
#endif
host_to_node_boolean_1(fm_write_p);
host_to_node_boolean_1(fm_print_p);

/* get number of surfaces highlighted in panel */
#if !RP_NODE
n_threads= RP_Get_List_Length("fm/surfaces");

for(n=0; n<n_threads; n++)
{
thread_id[n] = RP_Get_List_Ref_Int("fm/surfaces",n);
}
#endif
host_to_node_int_1(n_threads);
for(n=0; n<n_threads; n++)
{
host_to_node_int_1(thread_id[n]);
}

if (!(force_output_file = fopen(FORCE_OUTPUT_FILE,"a")))
Error("unable to open file");

if (!(moment_output_file = fopen(MOMENT_OUTPUT_FILE,"a")))
Error("unable to open file");



/* Initialize forces and moments */
N3V_S(Force,=,0.0);
N3V_S(Force_tot,=,0.0);
N3V_S(Force_viscous,=,0.0);
N3V_S(Force_pressure,=,0.0);
N3V_S(Force_viscous_tot,=,0.0);
N3V_S(Force_pressure_tot,=,0.0);
N3V_S(Moment,=,0.0);
N3V_S(Moment_tot,=,0.0);
N3V_S(Moment_viscous,=,0.0);
N3V_S(Moment_pressure,=,0.0);
N3V_S(Moment_viscous_tot,=,0.0);
N3V_S(Moment_pressure_tot,=,0.0);

N3V_S(origin,=,0.0);
N3V_S(xc,=,0.0);
N3V_S(r,=,0.0);
N3V_S(A,=,0.0);


/* get real value from solver - panel inputs for moment center */
#if !RP_NODE
origin[0] = RP_Get_Real("moment/centerx");
origin[1] = RP_Get_Real("moment/centery");
origin[2] = RP_Get_Real("moment/centerz");
#endif
for(i=0; i<3; i++)
{
host_to_node_real_1(origin[i]);
}
Message0("\n ...Computing moments around (%10.3e, %10.3e, %10.3e)\n", origin[0], origin[1], origin[2]);



#if RP_NODE || !PARALLEL


for (n=0; n<n_threads;++n)
{
/* get id's of threads highlighted in panel */
thread_n_id = thread_id[n];

/* get data for wall n */
thread = Lookup_Thread(domain, thread_n_id);

A_thread_part = 0.0;
begin_f_loop_int(f,thread)
{

F_AREA(A,f,thread);
Amag = N3V_MAG(A);
A_thread_part += Amag;
}
end_f_loop_int(f,thread);


/* Message(" partition %i, thread %i, Area = %10.3e\n", myid, thread_n_id, A_thread_part); */

Atot += A_thread_part;

}

Atot = PRF_GRSUM1(Atot);
if(rp_axi)
Atot = 2*pi*PRF_GRSUM1(Atot);

Message0(" ...Total area of selected threads is %10.3e (m^2)\n", Atot);


/* DO MOMENTS AND FORCES */

/* calculate Mx, My and Mz for each of the selected surfaces (fm/surfaces) */
if (fm_write_p || fm_print_p)
{
for (n=0; n<n_threads;++n)
{
/* get id's of threads highlighted in panel */
thread_n_id = thread_id[n];

/* get data for wall n */
thread = Lookup_Thread(domain, thread_n_id);

begin_f_loop_int(f,thread)
{

F_AREA(A,f,thread);

F_CENTROID(xc,f,thread);
N3V_VV(r,=,xc,-,origin);

N3V_S(Moment_viscous,=,0.0);
N3V_S(Moment_pressure,=,0.0);


/* Get wall shear force and pressure force on face */
N3V_VS(Force_viscous,=,F_STORAGE_R_N3V(f,thread,SV_WALL_SHEAR),*,-1.0);
N3V_VS(Force_pressure, =, A, *, F_P(f,thread));

if (rp_axi)
{
Force_pressure[0] = 2*pi*Force_pressure[0];
Force_viscous[0] = 2*pi*Force_viscous[0];
Force_pressure[1] = 0.0;
Force_viscous[1] = 0.0;
}

/* Compute viscous and pressure moments */
if (rp_axi)
{
Moment_viscous[2] = origin[1]*Force_viscous[0];
Moment_pressure[2] = origin[1]*Force_pressure[0];
}
else
{
fm_cross(Moment_viscous,r,Force_viscous);
fm_cross(Moment_pressure,r,Force_pressure);
}


/* Add forces */
N3V_VV(Force, =, Force_viscous, +, Force_pressure);
N3V_VV(Moment,=, Moment_viscous, +, Moment_pressure);


/* Accumulate viscous/pressure forces */
N3V_V(Force_viscous_tot, +=, Force_viscous);
N3V_V(Force_pressure_tot, +=, Force_pressure);
N3V_V(Force_tot, +=, Force);

N3V_V(Moment_viscous_tot, +=, Moment_viscous);
N3V_V(Moment_pressure_tot, +=, Moment_pressure);
N3V_V(Moment_tot, +=, Moment);


}
end_f_loop_int(f,thread);

}

/* Accumulate terms over all COMPUTE Nodes */
/* This function also passes global summation value to each compute node */
for(i=0;i<3;i++)
{
Force_viscous_tot[i] = PRF_GRSUM1(Force_viscous_tot[i]);
Force_pressure_tot[i] = PRF_GRSUM1(Force_pressure_tot[i]);
Force_tot[i] = PRF_GRSUM1(Force_tot[i]);
Moment_viscous_tot[i] = PRF_GRSUM1(Moment_viscous_tot[i]);
Moment_pressure_tot[i] = PRF_GRSUM1(Moment_pressure_tot[i]);
Moment_tot[i] = PRF_GRSUM1(Moment_tot[i]);
}

}

/* PRINT RESULTS to file ? */

if (fm_print_p)
{
Message0(" time Fp(x) Fp(y) Fp(z) Fv(x) Fv(y) Fv(z) Ft(x) Ft(y) Ft(z)\n");
Message0("%10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e\n",
RP_Get_Real("flow-time"),
Force_pressure_tot[0],
Force_pressure_tot[1],
Force_pressure_tot[2],
Force_viscous_tot[0],
Force_viscous_tot[1],
Force_viscous_tot[2],
Force_tot[0],
Force_tot[1],
Force_tot[2]);

Message0(" time Mp(x) Mp(y) Mp(z) Mv(x) Mv(y) Mv(z) Mt(x) Mt(y) Mt(z)\n");
Message0("%10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e\n",
RP_Get_Real("flow-time"),
Moment_pressure_tot[0],
Moment_pressure_tot[1],
Moment_pressure_tot[2],
Moment_viscous_tot[0],
Moment_viscous_tot[1],
Moment_viscous_tot[2],
Moment_tot[0],
Moment_tot[1],
Moment_tot[2]);

}

/* Write data to file ? */
if (fm_write_p)
{

/* Equivalent to Message0 for file output */
#if RP_NODE
if (I_AM_NODE_ZERO_P)
#endif
{
fprintf(force_output_file,"%10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e\n",
RP_Get_Real("flow-time"),
Force_pressure_tot[0],
Force_pressure_tot[1],
Force_pressure_tot[2],
Force_viscous_tot[0],
Force_viscous_tot[1],
Force_viscous_tot[2],
Force_tot[0],
Force_tot[1],
Force_tot[2]);

fprintf(moment_output_file,"%10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e %10.3e\n",
RP_Get_Real("flow-time"),
Moment_pressure_tot[0],
Moment_pressure_tot[1],
Moment_pressure_tot[2],
Moment_viscous_tot[0],
Moment_viscous_tot[1],
Moment_viscous_tot[2],
Moment_tot[0],
Moment_tot[1],
Moment_tot[2]);

}
}


#endif /* RP_NODE || !PARALLEL */

fclose(force_output_file);
fclose(moment_output_file);
}

void fm_cross(real a[], real b[], real c[])
{

/* Returns a = b x c for 3-vectors ONLY */

a[0] = b[1]*c[2] - b[2]*c[1];
a[1] = b[2]*c[0] - b[0]*c[2];
a[2] = b[0]*c[1] - b[1]*c[0];

return;
}

/********** END OF UDF *****************/


;;;;;;;;;;;;;;;;;;;;;;;;
; SCHEME FILE fm.scm
;;;;;;;;;;;;;;;;;;;;;;;
;; Panel for moment output data
;; works with udf fm.c
;;
(define (make-new-rpvar name default type)
(if (not (rp-var-object name))
(rp-var-define name default type #f)))
;;
;; Create rpvars for udf, assign initial (ie: default) values
;; types: real, boolean, integer, thread-list
;; () is empty list, #f is false (off)
;;


(make-new-rpvar 'fm/print? #f 'boolean)
(make-new-rpvar 'fm/write? #f 'boolean)
(make-new-rpvar 'fm/surfaces '() 'thread-list)
(make-new-rpvar 'moment/centerx 0 'real)
(make-new-rpvar 'moment/centery 0 'real)
(make-new-rpvar 'moment/centerz 0 'real)


;;
;; Create a panel for the udf
;;
(define
gui-define-output-data-panel
;; "panel" is a variable name
;; panel #f - no panel made yet
(let ((panel #f)

;; declare variables - assign values later

(fm/box)
(fm/print?)
(fm/write?)
(fm/surfaces)
(moment/centerx)
(moment/centery)
(moment/centerz)

)

;;;
;;; Function which is called when panel is opened
;;; sets panel variables to values in make-new-rpvar section
;;; default: all options off, no surfaces selected
;;;
(define (update-cb . args) ;update panel fields
(cx-set-toggle-button fm/print?
(rpgetvar 'fm/print?))
(cx-set-toggle-button fm/write?
(rpgetvar 'fm/write?))
(cx-set-real-entry moment/centerx
(rpgetvar 'moment/centerx))
(cx-set-real-entry moment/centery
(rpgetvar 'moment/centery))
(cx-set-real-entry moment/centerz
(rpgetvar 'moment/centerz))
;; get list of surfaces (face threads)
(cx-set-list-items fm/surfaces
(map thread-name
(sort-threads-by-name (get-face-threads))))

)

;;;
;;; Function which is called when OK button is hit.
;;; assigns variable values that were set in panel after clicking "ok"
;;;
(define (apply-cb . args)
(rpsetvar 'fm/print? (cx-show-toggle-button fm/print?))
(rpsetvar 'fm/write? (cx-show-toggle-button fm/write?))
(rpsetvar 'moment/centerx (cx-show-real-entry moment/centerx))
(rpsetvar 'moment/centery (cx-show-real-entry moment/centery))
(rpsetvar 'moment/centerz (cx-show-real-entry moment/centerz))
(rpsetvar 'fm/surfaces
(map thread-name->id
(cx-show-symbol-list-selections fm/surfaces)))

)

(lambda args
;;; if panel does not exist, make panel
(if (not panel)
(let ((table))
(set! panel (cx-create-panel "Force and Moment Settings"
apply-cb update-cb))
;; create table w/o title in panel to enable row by column format
(set! table (cx-create-table panel ""
'border #f
'below 0
'right-of 0))
;;;
;;; Create fm inputs.
;;;
(set! fm/box (cx-create-table table
"Force and Moment Options"
'row 0))
(set! fm/print?
(cx-create-toggle-button fm/box
"Print Results"
'col 1
'row 1))
(set! fm/write?
(cx-create-toggle-button fm/box
"Write Results to file"
'col 1
'row 2))

(set! fm/surfaces
(cx-create-symbol-list
fm/box "Boundary Zones"
'visible-lines 10
'multiple-selections #t
'row 3
'col 1))

(cx-set-list-items fm/surfaces
(map thread-name
(sort-threads-by-name (get-face-threads))))

(set! moment/centerx (cx-create-real-entry fm/box
"x-moment-center"
'row 4
'col 1))
(set! moment/centery (cx-create-real-entry fm/box
"y-moment-center"
'row 4
'col 2))
(set! moment/centerz (cx-create-real-entry fm/box
"z-moment-center"
'row 4
'col 3))


))
;; tell solver to display the panel
(cx-show-panel panel))))


;;;
;;; Add new panel to end of User-Defined menu.
;;; no need to modify here except panel name and menu location
;;;
(cx-add-item "Monitors"
"Force and Moment Data..."
#\U
#f
cx-client?
gui-define-output-data-panel)


;;;;; END OF SCHEME FILE

開放分享:優質有限元技術文章,助你自學成才

相關標簽搜索:Fluent:UDF to compute forces and momentson surface zones and print to file Fluent培訓 Fluent流體培訓 Fluent軟件培訓 fluent技術教程 fluent在線視頻教程 fluent資料下載 fluent分析理論 fluent化學反應 fluent軟件下載 UDF編程代做 Fluent、CFX流體分析 HFSS電磁分析 

編輯
在線報名:
  • 客服在線請直接聯系我們的客服,您也可以通過下面的方式進行在線報名,我們會及時給您回復電話,謝謝!
驗證碼

全國服務熱線

1358-032-9919

廣州公司:
廣州市環市中路306號金鷹大廈3800
電話:13580329919
          135-8032-9919
培訓QQ咨詢:點擊咨詢 點擊咨詢
項目QQ咨詢:點擊咨詢
email:kf@1cae.com




主站蜘蛛池模板: 康拓威技术(深圳)有限公司|Theia镜头代理商|安讯士AXIS摄像机|安讯士监控系统|博世BOSCH监控|博世会议系统|索尼SONY监控|松下PANASONIC监控|三星韩华SAMSUNG监控|霍尼韦尔Honeywell|海康|大华|华为监控|Theia无畸变镜头|AXIS监控|安讯视摄像机 | 油气润滑_稀油润滑_干油润滑-启东中德润滑设备有限公司 | 西安网站建设,西安网站设计制作,西安短视频拍摄_短视频运营就选动力无限网络推广公司 | 温州网络公司_网站建设_网络营销策划_阿里淘宝店铺服务-温州聚欣网络科技有限公司 | 潍坊亿宏重工机械有限公司,破碎机,高性能立磨机,颚式破碎机,锤式破碎机反击式破碎机,重锤式破碎机,高性能反击式破碎机,圆锥式破碎机,给料机系列,链板给料机系列,简易给料机系列,振动给料机 | 卧式球磨机_干法球磨机_尼龙球磨机-无锡市少宏粉体科技有限公司 卧螺离心机-固液分离机-台州春鼎机械制造有限公司 | 上海垃圾房,简易成品环保垃圾房,小区室外垃圾房,上海翼亭智能垃圾房厂家 | 上海祝融起重机械有限公司-德国耶鲁手拉葫芦|耶鲁手拉葫芦|耶鲁手扳葫芦|耶鲁电动葫芦经销代理 | 数字多媒体展厅设计,智慧科技互动企业展馆展厅设计公司-深圳炫之风 | 廊坊纳科新材料技术有限公司--纳科新材料技术有限公司|廊坊纳科新材料|纳科新材料技术 | 九江监控安装_九江安防监控_九江弱电工程公司-九江百信科技有限公司 | 离岸快车 - 专业的海外离岸公司香港公司离岸账户问答平台 | 昆明塑料包装袋|云南塑料包装袋|昆明塑料袋厂家|云南茶叶大米蔬菜种子食品包装袋就来阮门包装有限公司 | 主轴-电主轴-高速电机-高速电主轴厂家|瑞德沃斯品牌 | 推台锯_多片锯_圆木推台锯_方木多片锯_圆木多片锯-河北茂业机械有限公司 | 酒店宾馆一次性用品厂家-酒店洗漱用品,洗浴用品品牌方案-江苏欧佩 | 泊头市特种油泵阀制造有限公司&nbsp;-&nbsp;渣油泵,重油泵,沥青泵,高压齿轮泵,煤焦油泵,导热油泵,三螺杆泵,圆弧齿轮泵,不锈钢齿轮泵, | 徐州护栏,围栏,锌铁丝网围栏安全设施专家徐州铜山区威峰金属护栏厂 | 西安宣传片拍摄,陕西艺景网络科技有限公司资料备份,西安影视公司,视频拍摄制作,抖音视频制作,纪录片拍摄西安短视频摄影团队,西安抖音视频拍摄 | 爬架网@建筑爬架网@冲孔建筑爬架网片@工地冲孔建筑爬架网片@工地冲孔建筑爬架网片厂家@工地冲孔建筑爬架网片生产厂家-安平县诺德金属制品有限公司 | 辣椒烘干机-百信机械提供大中小型辣椒烘干机房设备视频图片厂家价格多少钱 | 素时刻 - 为亿万家庭提供健康饮食 | 行李快递安检机-便携式X光安检仪-行李安检机-液体-爆炸物探测仪-安天下安检设备 | 随州市东正专用汽车有限公司| 专业音响设备|数字功放|舞台音响|ktv音响|会议音响-劳伦士 | 上海喷涂厂|上海喷漆厂|粉末喷涂|平湖喷涂厂|平湖喷漆厂-平湖华梦金属科技有限公司 | 铜陵爱家装饰有限公司官网| 兰州物流公司_兰州货运公司_兰州物流电话上门取货_兰州立辉物流公司 | 卧螺离心机-固液分离机-台州春鼎机械制造有限公司| 江西佛像厂 江西法器厂 江西抚州东乡江弘法器有限公司 东乡江弘法器厂 佛像厂 法器厂 | 山东啤酒箱塑料提手_注塑产品加工_手提绳厂家-淄博浩晨包装制品有限公司 | 南京人才网_南京招聘网_南京人才市场最新招聘信息 | 纸袋机|多层纸袋机|高速纸袋机|无锡市天天友情机械有限公司 | 液压扳手-液压扭力扳手-电动扭矩扳手-气动扭力扳手-波霆机械(上海) | 耐力板厂家_pc耐力板价格_透明耐力板批发-佛山市麦粒建材有限公司 | 上海航空货运,上海空运,东方航空快递,机场物流,航空快运,上海东方航空托运公司 | 随车吊/洒水车/低平板运输车-程力专用汽车股份有限公司 | 艺考培训-中影人教育 【官网】-中国艺考教育的引航者 | 制砂机-合金-耐磨锤头-耐磨衬板-铸造件厂家-巩义市豫园宏宇铸造有限公司 | 塑料植草格_停车场植草格_消防车道植草格厂家_山东朋联建材 | 套丝机_钢管套丝机_螺栓套丝机S8139_螺纹钢套丝机_智能套丝机价格-瑞捷机械设备有限公司 |