整理Fluent流体UDF中文教程word板Word格式.docx
- 文档编号:5362913
- 上传时间:2023-05-05
- 格式:DOCX
- 页数:171
- 大小:262.73KB
整理Fluent流体UDF中文教程word板Word格式.docx
《整理Fluent流体UDF中文教程word板Word格式.docx》由会员分享,可在线阅读,更多相关《整理Fluent流体UDF中文教程word板Word格式.docx(171页珍藏版)》请在冰点文库上搜索。
离散相模型DEFINE宏的定义包含在dpm.h文件中。
为了方便大家,所有的定义都列于附录A中。
其实udf.h头文件已经包含了dpm.h文件,所以在你的UDF源代码中就不必包含dpm.h文件了。
注意:
在你的源代码中,DEFINE宏的所有参变量必须在同一行,如果将DEFINE声明分为几行就会导致编译错误。
4.2通用解算器DEFINE宏
本节所介绍的DEFINE宏执行了FLUENT中模型相关的通用解算器函数。
表4.2.1提供了FLUENT中DEFINE宏,以及这些宏定义的功能和激活这些宏的面板的快速参考向导。
每一个DEFINE宏的定义都在udf.h头文件中,具体可以参考附录A。
∙DEFINE_ADJUST(4.2.1节)
∙DEFINE_INIT(4.2.2节)
∙DEFINE_ON_DEMAND(4.2.3节)
∙DEFINE_RW_FILE(4.2.4节)
表4.2.1:
通用解算器DEFINE宏的快速参考向导
功能
DEFINE宏
激活该宏的面板
处理变量
DEFINE_ADJUST
User-DefinedFunctionHooks
初始化变量
DEFINE_INIT
异步执行
DEFINE_ON_DEMAND
ExecuteOnDemand
读写变量到……
DEFINE_RW_FILE
Case和data文件
∙4.2.1DEFINE_ADJUST
∙4.2.2DEFINE_INIT
∙4.2.3DEFINE_ON_DEMAND
∙4.2.4DEFINE_RW_FILE
4.2.1DEFINE_ADJUST
功能和使用方法的介绍
DEFINE_ADJUST是一个用于调节和修改FLUENT变量的通用宏。
例如,你可以用DEFINE_ADJUST来修改流动变量(如:
速度,压力)并计算积分。
你可以用它来对某一标量在整个流场上积分,然后在该结果的基础上调节边界条件。
在每一步迭代中都可以执行用DEFINE_ADJUST定义的宏,并在解输运方程之前的每一步迭代中调用它。
参考图3.3.1和3.3.2for可以大致了解一下当DEFINE_ADJUST被调用时FLUENT解的过程
宏
DEFINE_ADJUST(name,d)
参变量类型
Domain*d
返回的功能
void
DEFINE_ADJUST有两个参变量:
name和d。
name是你所指定的UDF的名字。
当你的UDF编译并连接时,你的FLUENT图形用户界面就会显示这个名字,此时你就可以选择它了。
d是FLUENT解算器传给你的UDF的变量。
D是一个指向区域的指针,调节函数被应用于这个区域上。
区域变量提供了存取网格中所有单元和表面的线程。
对于多相流,由解算器传给函数的区域指针是混合层区域指针。
DEFINE_ADJUST函数不返回任何值给解算器。
例子1
下面的UDF名字是adjust,它使用DEFINE_ADJUST对湍流耗散在整个区域上积分。
然后这个值会打印在控制台窗口中。
每一步迭代都会调用这个UDF。
它可以作为解释程序或者编译后的UDF在FLUENT中执行。
/*******************************************************************/
/*积分湍流耗散并将其打印到控制台窗口的UDF*/
/********************************************************************/
#include"
udf.h"
DEFINE_ADJUST(my_adjust,d)
{
Thread*t;
/*Integratedissipation.*/
realsum_diss=0.;
cell_tc;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
sum_diss+=C_D(c,t)*
C_VOLUME(c,t);
end_c_loop(c,t)
}
printf("
Volumeintegralofturbulentdissipation:
%g\n"
sum_diss);
}
例子:
2
下面UDF的名字是adjust_fcn,它用DEFINE_ADJUST指定了某一自定义标量是另一自定义标量的梯度的函数。
该函数在每一次迭代中都会被调用。
它可以作为编译后的UDF在FLUENT中执行。
/*UDFfordefininguser-definedscalarsandtheirgradients*/
DEFINE_ADJUST(adjust_fcn,d)
realK_EL=1.0;
/*Donothingifgradientisn'
tallocatedyet.*/
if(!
Data_Valid_P())
return;
thread_loop_c(t,d)
if(FLUID_THREAD_P(t))
begin_c_loop_all(c,t)
C_UDSI(c,t,1)+=K_EL*NV_MAG2(C_UDSI_G(c,t,0))*C_VOLUME(c,t);
end_c_loop_all(c,t)
ActivatinganAdjustUDFinFLUENT
在为adjustUDF的源代码进行编译和连接之后,你可以在FLUENT中的User-DefinedFunctionHooks面板激活这个函数。
更详细的内容请参阅8.1.1节。
4.2.2DEFINE_INIT
你可以用DEFINE_INIT宏来定义一组解的初始值。
DEFINE_INIT完成和修补一样的功能,只是它以另一种方式——UDF来完成。
每一次初始化时DEFINE_INIT函数都会被执行一次,并在解算器完成默认的初始化之后立即被调用。
因为它是在流场初始化之后被调用的,所以它最常用于设定流动变量的初值。
参考图3.3.1和3.3.2关于FLUENT解过程的介绍可以看出什么时候调用DEFINE_INIT函数。
Macro:
DEFINE_INIT(name,d)
Argumenttypes:
Functionreturns:
DEFINE_INIT有两个参变量:
disapointertothedomainoverwhichtheinitializationfunctionistobeapplied.Thedomainargumentprovidesaccesstoallcellandfacethreadsinthemesh.Formultiphaseflows,thedomainpointerthatispassedtothefunctionbythesolveristhemixture-leveldomainpointer.ADEFINE_INITfunctiondoesnotreturnavaluetothesolver.
例子
下面的UDF名字是my_init_func,它在某一个解中初始化了流动变量。
在解过程开始时它被执行了一次。
/*UDFforinitializingflowfieldvariables*/
/***********************************************************************/
DEFINE_INIT(my_init_function,domain)
realxc[ND_ND];
/*loopoverallcellthreadsinthedomain*/
thread_loop_c(t,domain)
/*loopoverallcells*/
C_CENTROID(xc,c,t);
if(sqrt(ND_SUM(pow(xc[0]-0.5,2.),
pow(xc[1]-0.5,2.),
pow(xc[2]-0.5,2.)))<
0.25)
C_T(c,t)=400.;
else
C_T(c,t)=300.;
end_c_loop_all(c,t)
ThemacroND_SUM(a,b,c)thatisusedintheUDFcomputesthesumofthefirsttwoarguments(2D)orallthreearguments(3D).Itisusefulforwritingfunctionsinvolvingvectoroperationssothatthesamefunctioncanbeusedfor2Dand3D.Fora2Dcase,thethirdargumentisignored.SeeChapter
5foradescriptionofpredefinedsolveraccessmacros(e.g.,C_CENTROID)andChapter
6forutilitymacros(e.g.,ND_SUM).
ActivatinganInitializationUDFinFLUENT
编译并连接UDF源代码之后。
youcanactivatethefunctionintheUser-DefinedFunctionHookspanelinFLUENT.SeeSection
8.1.2formoredetails.
4.2.3DEFINE_ON_DEMAND
你可以使用DEFINE_ON_DEMANDmacrotodefineaUDFtoexecuteondemandinFLUENT,ratherthanhavingFLUENTcallitautomaticallyduringthecalculation.YourUDFwillbeexecutedimmediately,onceitisactivated,butitisnotaccessiblewhilethesolverisiterating.NotethatthedomainpointerdisnotexplicitlypassedasanargumenttoDEFINE_ON_DEMAND.Therefore,ifyouwanttousethedomainvariableinyouron-demandfunction,youwillneedtofirstretrieveitusingtheGet_DomainutilityprovidedbyFluent(shownin例子:
below).SeeSection
6.5.1fordetailsonGet_Domain.
DEFINE_ON_DEMAND(name)
none
ThereisonlyoneargumenttoDEFINE_ON_DEMAND:
name.nameisthenameoftheUDF,specifiedbyyou.当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。
ADEFINE_ON_DEMANDfunctiondoesnotreturnavaluetothesolver.
下面的UDF名字为demand_calc,计算并打印出当前数据场的最小、最大和平均温度。
Itthencomputesatemperaturefunction
andstoresitinuser-definedmemorylocation0(whichisallocatedasdescribedinSection
6.7).OnceyouexecutetheUDF(asdescribedinSection
8.1.3),thefieldvaluesforf(T)willbeavailableinthedrop-downlistsinpostprocessingpanelsinFLUENT.Youcanselectthisfieldbychoosingudm-0intheUserDefinedMemory...category.IfyouwriteadatafileafterexecutingtheUDF,theuser-definedmemoryfieldwillbesavedtothedatafile.TheUDFcanbeexecutedasaninterpretedorcompiledUDFinFLUENT.
/**********************************************************************/
/*UDFtocalculatetemperaturefieldfunctionandstorein*/
/*user-definedmemory.Alsoprintmin,max,avgtemperatures.*/
/**********************************************************************/
DEFINE_ON_DEMAND(on_demand_calc)
Domain*d;
/*declaredomainpointersinceitisnotpasseda*/
/*argumenttoDEFINEmacro*/
realtavg=0.;
realtmax=0.;
realtmin=0.;
realtemp,volume,vol_tot;
d=Get_Domain
(1);
/*GetthedomainusingFluentutility*/
/*Loopoverallcellthreadsinthedomain*/
thread_loop_c(t,d)
/*Computemax,min,volume-averagedtemperature*/
/*Loopoverallcells*/
begin_c_loop(c,t)
volume=C_VOLUME(c,t);
/*getcellvolume*/
temp=C_T(c,t);
/*getcelltemperature*/
if(temp<
tmin||tmin==0.)tmin=temp;
if(temp>
tmax||tmax==0.)tmax=temp;
vol_tot+=volume;
tavg+=temp*volume;
end_c_loop(c,t)
tavg/=vol_tot;
\nTmin=%gTmax=%gTavg=%g\n"
tmin,tmax,tavg);
/*Computetemperaturefunctionandstoreinuser-definedmemory*/
/*(locationindex0)*/
C_UDMI(c,t,0)=(temp-tmin)/(tmax-tmin);
Get_Domainisamacrothatretrievesthepointertoadomain.ItisnecessarytogetthedomainpointerusingthismacrosinceitisnotexplicitlypassedasanargumenttoDEFINE_ON_DEMAND.Thefunction,namedon_demand_calc,doesnottakeanyexplicitarguments.Withinthefunctionbody,thevariablesthataretobeusedbythefunctionaredefinedandinitializedfirst.Followingthevariabledeclarations,aloopingmacroisusedtoloopovereachcellthreadinthedomain.Withinthatloopanotherloopisusedtoloopoverallthecells.Withintheinnerloop,thetotalvolumeandtheminimum,maximum,andvolume-averagedtemperaturearecomputed.ThesecomputedvaluesareprintedtotheFLUENTconsole.Thenasecondloopovereachcellisusedtocomputethefunctionf(T)andstoreitinuser-definedmemorylocation0.RefertoChapter
5foradescriptionofpredefinedsolveraccessmacros(e.g.,C_T)andChapter
6forutilitymacros(e.g.,begin_c_loop).
ActivatinganOn-DemandUDFinFLUENT
Afteryouhavecompiledandlinkedthesourcecodeforyouron-demandUDF,youcanactivatethefunctionintheExecuteOnDemandpanelinFLUENT.SeeSection
8.1.3formoredetails.
4.2.4DEFINE_RW_FILE
你可以使用DEFINE_RW_FILEmacrotodefinecustomizedinformationthatyouwanttobewrittentoacaseordatafile,orreadfromacaseordatafile.Youcansaveandrestorecustomvariablesofanydatatypes(e.g.,integer,real,Boolean,structure)usingDEFINE_RW_FILE.Itisoftenusefultosavedynamicinformation(e.g.,numberofoccurrencesinconditionalsampling)whileyoursolutionisbeingcalculated,whichisanotheruseofthisfunction.Notethatthereadorderandthewriteordermustbethesamewhenyouusethisfunction.
DEFINE_
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 整理 Fluent 流体 UDF 中文 教程 word