欢迎来到冰点文库! | 帮助中心 分享价值,成长自我!
冰点文库
全部分类
  • 临时分类>
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • ImageVerifierCode 换一换
    首页 冰点文库 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    完整版Fluent流体UDF中文教程word板doc.docx

    • 资源ID:10127127       资源大小:145.39KB        全文页数:142页
    • 资源格式: DOCX        下载积分:3金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要3金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    完整版Fluent流体UDF中文教程word板doc.docx

    1、完整版Fluent流体UDF中文教程word板doc第四章 DEFINE宏本章介绍了Fluent公司所提供的预定义宏,我们需要用这些预定义宏来定义UDF。在这里这些宏就是指DEFINE宏。本章由如下几节组成:4.1 概述 4.2 通用解算器DEFINE宏4.3 模型指定DEFINE宏4.4 多相DEFINE宏4.5 离散相模型DEFINE宏4.1 概述DEFINE宏一般分为如下四类:通用解算器模型指定多相离散相模型(DPM) 对于本章所列出的每一个DEFINE宏,本章都提供了使用该宏的源代码的例子。很多例子广泛的使用了其它章节讨论的宏,如解算器读取(第五章)和utilities (Chapte

    2、r 6)。需要注意的是,并不是本章所有的例子都是可以在FLUENT中执行的完整的函数。这些例子只是演示一下如何使用宏。除了离散相模型DEFINE宏之外的所有宏的定义都包含在udf.h文件中。离散相模型DEFINE宏的定义包含在dpm.h文件中。为了方便大家,所有的定义都列于附录A中。其实udf.h头文件已经包含了dpm.h文件,所以在你的UDF源代码中就不必包含dpm.h文件了。注意:在你的源代码中,DEFINE宏的所有参变量必须在同一行,如果将DEFINE声明分为几行就会导致编译错误。4.2 通用解算器DEFINE宏本节所介绍的DEFINE宏执行了FLUENT中模型相关的通用解算器函数。表

    3、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_ADJUSTUser-Defined Function Hooks初始化变量DEFINE_INITUser-Defined Functi

    4、on Hooks异步执行DEFINE_ON_DEMANDExecute On Demand读写变量到DEFINE_RW_FILEUser-Defined Function HooksCase和data文件4.2.1 DEFINE_ADJUST 4.2.2 DEFINE_INIT 4.2.3 DEFINE_ON_DEMAND 4.2.4 DEFINE_RW_FILE 4.2.1 DEFINE_ADJUST 功能和使用方法的介绍 DEFINE_ADJUST是一个用于调节和修改FLUENT变量的通用宏。例如,你可以用DEFINE_ADJUST来修改流动变量(如:速度,压力)并计算积分。你可以用它来对

    5、某一标量在整个流场上积分,然后在该结果的基础上调节边界条件。在每一步迭代中都可以执行用DEFINE_ADJUST定义的宏,并在解输运方程之前的每一步迭代中调用它。参考图3.3.1 和3.3.2 for可以大致了解一下当DEFINE_ADJUST被调用时FLUENT解的过程宏DEFINE_ADJUST ( name, d)参变量类型Domain *d返回的功能voidDEFINE_ADJUST有两个参变量:name和d。name是你所指定的UDF的名字。当你的UDF编译并连接时,你的FLUENT图形用户界面就会显示这个名字,此时你就可以选择它了。d是FLUENT解算器传给你的UDF的变量。D是一

    6、个指向区域的指针,调节函数被应用于这个区域上。区域变量提供了存取网格中所有单元和表面的线程。对于多相流,由解算器传给函数的区域指针是混合层区域指针。DEFINE_ADJUST函数不返回任何值给解算器。例子1下面的UDF名字是adjust,它使用DEFINE_ADJUST对湍流耗散在整个区域上积分。然后这个值会打印在控制台窗口中。每一步迭代都会调用这个UDF。它可以作为解释程序或者编译后的UDF在FLUENT中执行。/*/* 积分湍流耗散并将其打印到控制台窗口的UDF */*/#include udf.hDEFINE_ADJUST(my_adjust, d) Thread *t; /* Inte

    7、grate dissipation. */ real sum_diss=0.; cell_t c; 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(Volume integral of turbulent dissipation: %gn, sum_diss);例子: 2 下面UDF的名字是adjust_fcn,它用DEFINE_ADJUST指定了某一自定义标量是另一自定义标量的梯度的函数。该函数在每一次迭代中都会被调用。它可以作为编译后的UD

    8、F在FLUENT中执行。 /*/* UDF for defining user-defined scalars and their gradients */*/#include udf.hDEFINE_ADJUST(adjust_fcn, d) Thread *t; cell_t c; real K_EL = 1.0; /* Do nothing if gradient isnt allocated yet. */ if (! Data_Valid_P() return; thread_loop_c (t, d) if (FLUID_THREAD_P(t) begin_c_loop_all (

    9、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) Activating an Adjust UDF in FLUENT 在为adjust UDF的源代码进行编译和连接之后,你可以在FLUENT中的User-Defined Function Hooks 面板激活这个函数。更详细的内容请参阅8.1.1节。4.2.2 DEFINE_INIT 功能和使用方法的介绍 你可以用DEFINE_INIT宏来定义一组解的初始值。DEFINE_INIT 完成和修补一样的功能,只是它以另一种

    10、方式UDF来完成。每一次初始化时DEFINE_INIT函数都会被执行一次,并在解算器完成默认的初始化之后立即被调用。因为它是在流场初始化之后被调用的,所以它最常用于设定流动变量的初值。参考图3.3.1和3.3.2关于FLUENT解过程的介绍可以看出什么时候调用DEFINE_INIT函数。Macro:DEFINE_INIT ( name, d)Argument types:Domain *dFunction returns:voidDEFINE_INIT有两个参变量:name和d。name是你所指定的UDF的名字。当你的UDF编译并连接时,你的FLUENT图形用户界面就会显示这个名字,此时你就可

    11、以选择它了。d是FLUENT解算器传给你的UDF的变量。d is a pointer to the domain over which the initialization function is to be applied. The domain argument provides access to all cell and face threads in the mesh. For multiphase flows, the domain pointer that is passed to the function by the solver is the mixture-level d

    12、omain pointer. A DEFINE_INIT function does not return a value to the solver. 例子下面的UDF名字是my_init_func,它在某一个解中初始化了流动变量。在解过程开始时它被执行了一次。它可以作为解释程序或者编译后的UDF在FLUENT中执行。/*/* UDF for initializing flow field variables */*/#include udf.hDEFINE_INIT(my_init_function, domain) cell_t c; Thread *t; real xcND_ND; /

    13、* loop over all cell threads in the domain */ thread_loop_c (t,domain) /* loop over all cells */ begin_c_loop_all (c,t) C_CENTROID(xc,c,t); if (sqrt(ND_SUM(pow(xc0 - 0.5,2.), pow(xc1 - 0.5,2.), pow(xc2 - 0.5,2.) 0.25) C_T(c,t) = 400.; else C_T(c,t) = 300.; end_c_loop_all (c,t) The macro ND_SUM(a, b,

    14、 c) that is used in the UDF computes the sum of the first two arguments (2D) or all three arguments (3D). It is useful for writing functions involving vector operations so that the same function can be used for 2D and 3D. For a 2D case, the third argument is ignored. See Chapter 5 for a description

    15、of predefined solver access macros (e.g., C_CENTROID) and Chapter 6 for utility macros (e.g., ND_SUM). Activating an Initialization UDF in FLUENT 编译并连接UDF源代码之后。you can activate the function in the User-Defined Function Hooks panel in FLUENT. See Section 8.1.2 for more details. 4.2.3 DEFINE_ON_DEMAND

    16、 功能和使用方法的介绍 你可以使用DEFINE_ON_DEMAND macro to define a UDF to execute on demand in FLUENT, rather than having FLUENT call it automatically during the calculation. Your UDF will be executed immediately, once it is activated, but it is not accessible while the solver is iterating. Note that the domain po

    17、inter d is not explicitly passed as an argument to DEFINE_ON_DEMAND. Therefore, if you want to use the domain variable in your on-demand function, you will need to first retrieve it using the Get_Domain utility provided by Fluent (shown in 例子: below). See Section 6.5.1 for details on Get_Domain. Mac

    18、ro:DEFINE_ON_DEMAND ( name)Argument types:noneFunction returns:voidThere is only one argument to DEFINE_ON_DEMAND: name. name is the name of the UDF, specified by you. 当你的UDF编译和连接时,你为函数所选择的名字会在FLUENT图形用户界面中变得可见,且可被选择。 A DEFINE_ON_DEMAND function does not return a value to the solver. 例子: 下面的UDF名字为de

    19、mand_calc,计算并打印出当前数据场的最小、最大和平均温度。It then computes a temperature function and stores it in user-defined memory location 0 (which is allocated as described in Section 6.7). Once you execute the UDF (as described in Section 8.1.3), the field values for f( T) will be available in the drop-down lists in

    20、postprocessing panels in FLUENT. You can select this field by choosing udm-0 in the User Defined Memory. category. If you write a data file after executing the UDF, the user-defined memory field will be saved to the data file. The UDF can be executed as an interpreted or compiled UDF in FLUENT. /*/

    21、/* UDF to calculate temperature field function and store in */* user-defined memory. Also print min, max, avg temperatures. */ /*/#include udf.hDEFINE_ON_DEMAND(on_demand_calc)Domain *d; /* declare domain pointer since it is not passed a */ /* argument to DEFINE macro */ real tavg = 0.; real tmax =

    22、0.; real tmin = 0.; real temp,volume,vol_tot; Thread *t; cell_t c; d = Get_Domain(1); /* Get the domain using Fluent utility */ /* Loop over all cell threads in the domain */ thread_loop_c(t,d) /* Compute max, min, volume-averaged temperature */ /* Loop over all cells */ begin_c_loop(c,t) volume = C

    23、_VOLUME(c,t); /* get cell volume */ temp = C_T(c,t); /* get cell temperature */ if (temp tmax | tmax = 0.) tmax = temp; vol_tot += volume; tavg += temp*volume; end_c_loop(c,t) tavg /= vol_tot; printf(n Tmin = %g Tmax = %g Tavg = %gn,tmin,tmax,tavg); /* Compute temperature function and store in user-

    24、defined memory*/ /*(location index 0) */ begin_c_loop(c,t) temp = C_T(c,t); C_UDMI(c,t,0) = (temp-tmin)/(tmax-tmin); end_c_loop(c,t) Get_Domain is a macro that retrieves the pointer to a domain. It is necessary to get the domain pointer using this macro since it is not explicitly passed as an argume

    25、nt to DEFINE_ON_DEMAND. The function, named on_demand_calc, does not take any explicit arguments. Within the function body, the variables that are to be used by the function are defined and initialized first. Following the variable declarations, a looping macro is used to loop over each cell thread

    26、in the domain. Within that loop another loop is used to loop over all the cells. Within the inner loop, the total volume and the minimum, maximum, and volume-averaged temperature are computed. These computed values are printed to the FLUENT console. Then a second loop over each cell is used to compu

    27、te the function f( T) and store it in user-defined memory location 0. Refer to Chapter 5 for a description of predefined solver access macros (e.g., C_T) and Chapter 6 for utility macros (e.g., begin_c_loop). Activating an On-Demand UDF in FLUENT After you have compiled and linked the source code fo

    28、r your on-demand UDF, you can activate the function in the Execute On Demand panel in FLUENT. See Section 8.1.3 for more details. 4.2.4 DEFINE_RW_FILE 功能和使用方法的介绍 你可以使用DEFINE_RW_FILE macro to define customized information that you want to be written to a case or data file, or read from a case or data

    29、 file. You can save and restore custom variables of any data types (e.g., integer, real, Boolean, structure) using DEFINE_RW_FILE. It is often useful to save dynamic information (e.g., number of occurrences in conditional sampling) while your solution is being calculated, which is another use of this function. Note that the read order and the write order must be the same when you use this function. Macro:DEFINE_RW_FILE ( na


    注意事项

    本文(完整版Fluent流体UDF中文教程word板doc.docx)为本站会员主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2023 冰点文库 网站版权所有

    经营许可证编号:鄂ICP备19020893号-2


    收起
    展开