![Fluent流體UDF中文教程.word板_第1頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-6/20/973facb9-2cdd-4c6c-a2d5-f5af8c5793af/973facb9-2cdd-4c6c-a2d5-f5af8c5793af1.gif)
![Fluent流體UDF中文教程.word板_第2頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-6/20/973facb9-2cdd-4c6c-a2d5-f5af8c5793af/973facb9-2cdd-4c6c-a2d5-f5af8c5793af2.gif)
![Fluent流體UDF中文教程.word板_第3頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-6/20/973facb9-2cdd-4c6c-a2d5-f5af8c5793af/973facb9-2cdd-4c6c-a2d5-f5af8c5793af3.gif)
![Fluent流體UDF中文教程.word板_第4頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-6/20/973facb9-2cdd-4c6c-a2d5-f5af8c5793af/973facb9-2cdd-4c6c-a2d5-f5af8c5793af4.gif)
![Fluent流體UDF中文教程.word板_第5頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-6/20/973facb9-2cdd-4c6c-a2d5-f5af8c5793af/973facb9-2cdd-4c6c-a2d5-f5af8c5793af5.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、第四章 define宏本章介紹了fluent公司所提供的預(yù)定義宏,我們需要用這些預(yù)定義宏來(lái)定義udf。在這里這些宏就是指define宏。本章由如下幾節(jié)組成: 4.1 概述 4.2 通用解算器define宏 4.3 模型指定define宏 4.4 多相define宏 4.5 離散相模型define宏4.1 概述define宏一般分為如下四類: 通用解算器 模型指定 多相 離散相模型(dpm) 對(duì)于本章所列出的每一個(gè)define宏,本章都提供了使用該宏的源代碼的例子。很多例子廣泛的使用了其它章節(jié)討論的宏,如解算器讀?。ǖ谖逭拢┖蛈tilities (chapter 6)。需要注意的是,并不是本章所
2、有的例子都是可以在fluent中執(zhí)行的完整的函數(shù)。這些例子只是演示一下如何使用宏。除了離散相模型define宏之外的所有宏的定義都包含在udf.h文件中。離散相模型define宏的定義包含在dpm.h文件中。為了方便大家,所有的定義都列于附錄a中。其實(shí)udf.h頭文件已經(jīng)包含了dpm.h文件,所以在你的udf源代碼中就不必包含dpm.h文件了。注意:在你的源代碼中,define宏的所有參變量必須在同一行,如果將define聲明分為幾行就會(huì)導(dǎo)致編譯錯(cuò)誤。4.2 通用解算器define宏本節(jié)所介紹的define宏執(zhí)行了fluent中模型相關(guān)的通用解算器函數(shù)。表 4.2.1提供了fluent中def
3、ine宏,以及這些宏定義的功能和激活這些宏的面板的快速參考向?qū)?。每一個(gè)define宏的定義都在udf.h頭文件中,具體可以參考附錄a。 define_adjust (4.2.1節(jié)) define_init (4.2.2節(jié)) define_on_demand (4.2.3節(jié)) define_rw_file (4.2.4節(jié)) 表4.2.1:通用解算器define宏的快速參考向?qū)Чδ躣efine宏激活該宏的面板處理變量define_adjustuser-defined function hooks初始化變量define_inituser-defined function hooks異步執(zhí)行defin
4、e_on_demandexecute on demand讀寫(xiě)變量到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是一個(gè)用于調(diào)節(jié)和修改fluent變量的通用宏。例如,你可以用define_adjust來(lái)修改流動(dòng)變量(如:速度,壓力)并計(jì)算積分。你可以用它來(lái)對(duì)某一標(biāo)量在整個(gè)流場(chǎng)上積分,然后在
5、該結(jié)果的基礎(chǔ)上調(diào)節(jié)邊界條件。在每一步迭代中都可以執(zhí)行用define_adjust定義的宏,并在解輸運(yùn)方程之前的每一步迭代中調(diào)用它。參考圖3.3.1 和3.3.2 for可以大致了解一下當(dāng)define_adjust被調(diào)用時(shí)fluent解的過(guò)程宏define_adjust ( name, d)參變量類型domain *d返回的功能voiddefine_adjust有兩個(gè)參變量:name和d。name是你所指定的udf的名字。當(dāng)你的udf編譯并連接時(shí),你的fluent圖形用戶界面就會(huì)顯示這個(gè)名字,此時(shí)你就可以選擇它了。d是fluent解算器傳給你的udf的變量。d是一個(gè)指向區(qū)域的指針,調(diào)節(jié)函數(shù)被應(yīng)用
6、于這個(gè)區(qū)域上。區(qū)域變量提供了存取網(wǎng)格中所有單元和表面的線程。對(duì)于多相流,由解算器傳給函數(shù)的區(qū)域指針是混合層區(qū)域指針。define_adjust函數(shù)不返回任何值給解算器。例子1下面的udf名字是adjust,它使用define_adjust對(duì)湍流耗散在整個(gè)區(qū)域上積分。然后這個(gè)值會(huì)打印在控制臺(tái)窗口中。每一步迭代都會(huì)調(diào)用這個(gè)udf。它可以作為解釋程序或者編譯后的udf在fluent中執(zhí)行。/*/* 積分湍流耗散并將其打印到控制臺(tái)窗口的udf */*/#include udf.hdefine_adjust(my_adjust, d) thread *t; /* integrate dissipatio
7、n. */ 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指定了某一自定義標(biāo)量是另一自定義標(biāo)量的梯度的函數(shù)。該函數(shù)在每一次迭代中都會(huì)被調(diào)用。它可以作為編譯后的udf在fluent中執(zhí)行。 /*/
8、* 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 (c,t) c_udsi(c,t,
9、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的源代碼進(jìn)行編譯和連接之后,你可以在fluent中的user-defined function hooks 面板激活這個(gè)函數(shù)。更詳細(xì)的內(nèi)容請(qǐng)參閱8.1.1節(jié)。4.2.2 define_init 功能和使用方法的介紹 你可以用define_init宏來(lái)定義一組解的初始值。define_init 完成和修補(bǔ)一樣的功能,只是它以另一種方式udf來(lái)完成。每一次初始化時(shí)
10、define_init函數(shù)都會(huì)被執(zhí)行一次,并在解算器完成默認(rèn)的初始化之后立即被調(diào)用。因?yàn)樗窃诹鲌?chǎng)初始化之后被調(diào)用的,所以它最常用于設(shè)定流動(dòng)變量的初值。參考圖3.3.1和3.3.2關(guān)于fluent解過(guò)程的介紹可以看出什么時(shí)候調(diào)用define_init函數(shù)。macro:define_init ( name, d)argument types:domain *dfunction returns:voiddefine_init有兩個(gè)參變量:name和d。name是你所指定的udf的名字。當(dāng)你的udf編譯并連接時(shí),你的fluent圖形用戶界面就會(huì)顯示這個(gè)名字,此時(shí)你就可以選擇它了。d是fluent解算
11、器傳給你的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 domain pointer. a
12、 define_init function does not return a value to the solver. 例子下面的udf名字是my_init_func,它在某一個(gè)解中初始化了流動(dòng)變量。在解過(guò)程開(kāi)始時(shí)它被執(zhí)行了一次。它可以作為解釋程序或者編譯后的udf在fluent中執(zhí)行。/*/* udf for initializing flow field variables */*/#include udf.hdefine_init(my_init_function, domain) cell_t c; thread *t; real xcnd_nd; /* loop over all
13、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, c) that is used
14、 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 of predefined so
15、lver 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 pointer d is not e
17、xplicitly 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. macro:define_on_dem
18、and ( 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. 當(dāng)你的udf編譯和連接時(shí),你為函數(shù)所選擇的名字會(huì)在fluent圖形用戶界面中變得可見(jiàn),且可被選擇。 a define_on_demand function does not return a value to the solver. 例子: 下面的udf名字為demand_calc,計(jì)算并打印出
19、當(dāng)前數(shù)據(jù)場(chǎng)的最小、最大和平均溫度。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 postprocessing p
20、anels 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. /*/ /* udf to calcul
21、ate 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 = 0.; real tmin =
22、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_volume(c,t); /*
23、 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-defined memory*/
24、 /*(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 argument to define_on_
25、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 in the domain. w
26、ithin 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 compute the function
27、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 for your on-demand
28、 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 file. you can s
29、ave 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
30、 that the read order and the write order must be the same when you use this function. macro:define_rw_file ( name, fp)argument types:file *fpfunction returns:voidthere are two arguments to define_rw_file: name and fp. name is the name of the udf, specified by you. 當(dāng)你的udf編譯和連接時(shí),你為函數(shù)所選擇的名字會(huì)在fluent圖形用戶
31、界面中變得可見(jiàn),且可被選擇。 fp is a variable that is passed by the fluent solver to your udf. fp is a pointer to the file to or from which you are writing or reading. a define_rw_file function does not return a value to the solver. ! do not use the fwrite macro in define_rw_file functions that are running on win
32、dows platforms. use fprintf instead. 例子: the following c source code contains 例子:s of functions that write information to a data file and read it back. these functions are concatenated into a single file that can be executed as interpreted or compiled in fluent. /*/* udfs that increment a variable,
33、write it to a data file */* and read it back in */*/#include udf.hint kount = 0; /* define global variable kount */define_adjust(demo_calc, domain) kount+; printf(kount = %dn,kount);define_rw_file(writer, fp) printf(writing udf data to data file.n); fprintf(fp, %d,kount); /* write out kount to data
34、file */define_rw_file(reader, fp) printf(reading udf data from data file.n); fscanf(fp, %d,&kount); /* read kount from data file */at the top of the listing, the integer kount is defined and initialized to zero. the first function ( demo_calc)ltindexdemo_calc is an adjust function that increments th
35、e value of kount at each iteration, since the adjust function is called once per iteration. (see section 4.2.1 for more information about adjust functions.) the second function ( writer) instructs fluent to write the current value of kount to the data file, when the data file is saved. the third fun
36、ction ( reader) instructs fluent to read the value of kount from the data file, when the data file is read. the functions work together as follows. if you run your calculation for, say, 10 iterations ( kount has been incremented to a value of 10) and save the data file, then the current value of kou
37、nt (10) will be written to your data file. if you read the data back into fluent and continue the calculation, kount will start at a value of 10 and will be incremented at each iteration. note that you can save as many static variables as you want, but you must be sure to read them in the same order
38、 in which they are written. activating a read/write case or data file udf in fluent after you have compiled and linked the source code for your read/write udf, you can activate the function in the user-defined function hooks panel in fluent. see section 8.1.4 for more details. 4.3 模型指定define宏本節(jié)所介紹的d
39、efine宏用于set parameters for a particular model in fluent. table 4.3.1 provides a quick reference guide to the define macros, the functions they are used to define, and the panel where they are activated in fluent. definitions of each define macro are listed in the udf.h header file. for your convenie
40、nce, the definitions are also provided in appendix a. define_deltat (section 4.3.1) define_diffusivity (section 4.3.2) define_heat_flux (section 4.3.3) define_nox_rate (section 4.3.4) define_profile (section 4.3.5) define_property(section 4.3.6) define_scat_phase_func (section 4.3.7) define_source (
41、section 4.3.8) define_sr_rate (section 4.3.9) define_turb_premix_source (section 4.3.10) define_turbulent_viscosity (section 4.3.11) define_uds_flux (section 4.3.12) define_uds_unsteady (section 4.3.13) define_vr_rate (section 4.3.14) table 4.3.1: quick reference guide for model-specific define macr
42、osvariabledefine macropanel activated inspecies mass fractiondefine_profileboundary condition(e.g., velocity inlet)velocity at a boundarydefine_profileboundary conditionpressure at a boundarydefine_profileboundary conditionboundary temperaturedefine_profileboundary conditionturbulent kinetic energyd
43、efine_profileboundary conditionturbulent dissipation ratedefine_profileboundary conditionmass sourcedefine_sourceboundary conditionmomentum sourcedefine_sourceboundary conditionenergy sourcedefine_sourceboundary conditionturbulent k.e. sourcedefine_sourceboundary conditionturb. dissipation rate sour
44、cedefine_sourceboundary conditionuds or species mass diffusivitydefine_diffusivitymaterialsturbulent viscositydefine_turbulent_viscosityviscous modelheat fluxdefine_heat_fluxboundary conditiondensitydefine_propertymaterialsviscositydefine_propertymaterialsmass diffusivitydefine_propertymaterialsther
45、mal conductivitydefine_propertymaterialsabsorption coefficientdefine_propertymaterialsscattering coefficientdefine_propertymaterialslaminar flow speeddefine_propertymaterialsrate of straindefine_propertymaterialsscattering phase functiondefine_scat_phase_funcmaterialssurface reaction ratedefine_sr_r
46、ateuser-defined functionhooksvolume reaction ratedefine_vr_rateuser-defined functionhooksturbulent premixed sourcedefine_turb_premix_sourceuser-defined functionhooksscalar flux functiondefine_uds_fluxuser-defined scalarsscalar unsteady functiondefine_uds_unsteadyuser-defined scalarscenter of gravity
47、 motiondefine_cg_motiondynamic zonesgrid motiondefine_grid_motiondynamic zonesgeometry deformationdefine_geomdynamic zonesnox formation ratedefine_nox_ratenox modeltime step (for timedefine_deltatiteratedependent solutions) 4.3.1 define_deltat 4.3.2 define_diffusivity 4.3.3 define_heat_flux 4.3.4 de
48、fine_nox_rate 4.3.5 define_profile 4.3.6 define_property 4.3.7 define_scat_phase_func 4.3.8 define_source 4.3.9 define_sr_rate 4.3.10 define_turb_premix_source 4.3.11 define_turbulent_viscosity 4.3.12 define_uds_flux 4.3.13 define_uds_unsteady 4.3.14 define_vr_rate 4.3.1 define_deltat 功能和使用方法的介紹 你可以
49、使用define_deltat宏來(lái)控制時(shí)間相關(guān)問(wèn)題解的時(shí)間步長(zhǎng)。this macro can only be used if the adaptive time-stepping method option has been activated in the iterate panel in fluent. macro:define_deltat ( name, domain)argument types:domain *domainfunction returns:realthere are two arguments to define_deltat: name and domain. n
50、ame is the name of the udf, specified by you. 當(dāng)你的udf編譯和連接時(shí),你為函數(shù)所選擇的名字會(huì)在fluent圖形用戶界面中變得可見(jiàn),且可被選擇。 domain is passed by the fluent solver to your udf. your udf will need to return the real value of the physical time step to the solver. 例子: 下面的udf名字為mydeltat, is a simple function that shows how you can u
51、se define_deltat to change the value of the time step in a simulation. first, rp_get_real is used to get the value of the current simulation time ( flow_time). then, for the first 0.5 seconds of the calculation, a time step of 0.1 is set. a time step of 0.2 is set for the remainder of the simulation. the time step variable is then returned to the solver. see section 6.9 for details on rp_get_real. /*/* udf that changes the time step value for a time-dependent solution */*/#include udf.hdefine_deltat(mydeltat, domain) real time_step; real f
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 受傷補(bǔ)助申請(qǐng)書(shū)
- 助學(xué)金申請(qǐng)書(shū)范文大全
- 社區(qū)治安運(yùn)行管理實(shí)施細(xì)則
- 2024-2025學(xué)年浙江省溫州市高一(上)期末地理試卷(A卷)
- 2024-2025學(xué)年天津市河西區(qū)高二上學(xué)期11月期中考試物理試題(解析版)
- 2024-2025學(xué)年山東省聯(lián)考高一上學(xué)期12月月考物理試題(解析版)
- 2024-2025學(xué)年山東省濱州市高一上學(xué)期期末模擬考試物理試題(二)(解析版)
- 2024-2025學(xué)年安徽省廬巢聯(lián)盟高一上學(xué)期第二次月考物理試卷(解析版)
- 江蘇省鎮(zhèn)江市丹陽(yáng)市2024-2025學(xué)年高三上學(xué)期11月期中考試物理試題
- 電競(jìng)酒店的綠色能源利用與環(huán)保體驗(yàn)
- 蘭溪市排水防澇提升雨污管網(wǎng)修復(fù)改造初步設(shè)計(jì)文本
- 2024-2030年中國(guó)永磁電機(jī)市場(chǎng)現(xiàn)狀分析及前景趨勢(shì)預(yù)測(cè)報(bào)告
- 翁愷C語(yǔ)言課件下載
- 2024-2025學(xué)年人教版八年級(jí)上冊(cè)地理期末測(cè)試卷(一)(含答案)
- DB3209T 1236-2023 西蘭花采后處理與貯運(yùn)技術(shù)規(guī)程
- 《液壓缸與設(shè)計(jì)》課件
- 山東省物流工程師職稱考試參考試題庫(kù)-上(單選題)
- GB/T 44546-2024建筑用裝配式集成吊頂通用技術(shù)要求
- 心腦血管疾病預(yù)防課件
- DB35T 1036-2023 10kV及以下電力用戶業(yè)擴(kuò)工程技術(shù)規(guī)范
- 《油藏工程》課后習(xí)題答案
評(píng)論
0/150
提交評(píng)論