没有合适的资源?快使用搜索试试~ 我知道了~
首页Ansys 2022 R1 Fluent 用户定义函数手册解析
Ansys 2022 R1 Fluent 用户定义函数手册解析
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 70 下载量 62 浏览量
更新于2024-07-06
7
收藏 14.26MB PDF 举报
"Ansys_2022 R1 Fluent UDF Manual 提供了关于如何定制Ansys Fluent软件的详细指南,特别关注用户定义的函数(UDF)的开发和应用。该手册由ANSYS公司在2022年1月发布,是用于版本2022 R1的更新。它涵盖了流体动力学模拟、UDF编程以及如何增强Fluent求解器的功能。"
在Ansys Fluent中,用户定义的函数(UDF)是扩展软件功能的关键工具,允许用户自定义物理模型、边界条件、源项等。通过UDF,工程师和研究人员能够解决特定的工程问题,模拟复杂流动现象,或实现特定的计算需求。以下是一些关键的知识点:
1. **UDF基础知识**:了解UDF的基本结构,包括头文件、源文件和初始化函数。头文件定义了函数原型和宏,源文件包含实际的函数实现,而初始化函数则在Fluent启动时调用,用于注册UDF。
2. **数据类型和函数库**:掌握Fluent中的数据类型,如REAL、INTEGER和VECTOR,以及如何使用内置的库函数进行数学运算和流体动力学相关的计算。
3. **流体动力学模型**:学习如何通过UDF创建新的流体模型,如湍流模型、化学反应模型或多相流模型。这涉及到编写处理速度、压力、温度和浓度等物理量的函数。
4. **边界条件**:UDF可以用于定义独特的边界条件,例如非标准的入口条件、壁面行为或远场条件。这使得用户能够模拟不常见的流场情况。
5. **源项**:UDF也可用于添加自定义源项,例如反应源项、对流源项或扩散源项,这在处理化学反应、颗粒输运或热量产生等问题时非常有用。
6. **编程语言**:Ansys Fluent的UDF主要基于C语言,因此熟悉C语言的基本语法和结构对于编写UDF至关重要。
7. **调试和测试**:理解如何在Fluent环境中编译、加载和测试UDF,以及如何使用Fluent的输出结果进行调试。
8. **性能优化**:学习如何优化UDF代码以提高计算效率,这可能涉及到并行化处理、内存管理和减少不必要的计算。
9. **错误处理和日志记录**:在编写UDF时,了解如何正确处理错误和异常,以及如何记录和分析运行日志,这对于诊断问题和改进代码至关重要。
10. **案例研究和示例**:手册通常会提供各种UDF示例,这些例子可以帮助初学者快速上手,并理解UDF在实际问题中的应用。
Ansys_2022 R1 Fluent UDF Manual是学习和开发UDF的重要参考资料,它提供了全面的技术细节和实用的指导,使用户能够充分利用Fluent的灵活性和强大功能,以适应各种复杂的工程和科研挑战。
2.7.7.4. Hooking a DEFINE_BATTERY_PARAMETER_ECM UDF to Ansys Fluent .............. 297
2.7.8. DEFINE_BATTERY_PARAMETER_NTGK ..................................................................... 297
2.7.8.1. Description ............................................................................................................ 297
2.7.8.2. Usage .................................................................................................................... 297
2.7.8.3. Example ................................................................................................................ 298
2.7.8.4. Hooking a DEFINE_BATTERY_PARAMETER_NTGK UDF to Ansys Fluent ............. 298
2.7.9. DEFINE_BATTERY_PROPERTY .................................................................................. 298
2.7.9.1. Description ............................................................................................................ 298
2.7.9.2. Usage .................................................................................................................... 298
2.7.9.3. Example ................................................................................................................ 299
2.7.9.4. Hooking a DEFINE_BATTERY_PROPERTY UDF to Ansys Fluent ........................... 299
2.8. User-Defined Scalar (UDS) Transport Equation DEFINE Macros ............................................... 299
2.8.1. Introduction ................................................................................................................... 300
2.8.1.1. Diffusion Coefficient UDFs ..................................................................................... 300
2.8.1.2. Flux UDFs .............................................................................................................. 300
2.8.1.3. Unsteady UDFs ...................................................................................................... 300
2.8.1.4. Source Term UDFs .................................................................................................. 300
2.8.1.5. Fixed Value Boundary Condition UDFs .................................................................... 301
2.8.1.6. Wall, Inflow, and Outflow Boundary Condition UDFs ............................................... 301
2.8.2. DEFINE_ANISOTROPIC_DIFFUSIVITY ................................................................... 301
2.8.2.1. Description ............................................................................................................ 301
2.8.2.2. Usage .................................................................................................................... 301
2.8.2.3. Example ................................................................................................................ 302
2.8.2.4. Hooking an Anisotropic Diffusivity UDF to Ansys Fluent .......................................... 303
2.8.3. DEFINE_UDS_FLUX .................................................................................................... 303
2.8.3.1. Description ............................................................................................................ 303
2.8.3.2. Usage .................................................................................................................... 303
2.8.3.3. Example ................................................................................................................ 305
2.8.3.4. Hooking a UDS Flux Function to Ansys Fluent ......................................................... 306
2.8.4. DEFINE_UDS_UNSTEADY ........................................................................................... 306
2.8.4.1. Description ............................................................................................................ 306
2.8.4.2. Usage .................................................................................................................... 307
2.8.4.3. Example ................................................................................................................ 307
2.8.4.4. Hooking a UDS Unsteady Function to Ansys Fluent ................................................. 308
3. Additional Macros for Writing UDFs ............................................................................................. 309
3.1. Introduction ........................................................................................................................... 309
3.2. Data Access Macros ................................................................................................................. 311
3.2.1. Axisymmetric Considerations for Data Access Macros ...................................................... 311
3.2.2. Node Macros .................................................................................................................. 311
3.2.2.1. Node Position ........................................................................................................ 312
3.2.2.2. Number of Nodes in a Face (F_NNODES) ................................................................ 312
3.2.3. Cell Macros .................................................................................................................... 312
3.2.3.1. Cell Centroid (C_CENTROID) ................................................................................. 312
3.2.3.2. Cell Volume (C_VOLUME) ....................................................................................... 313
3.2.3.3. Number of Faces (C_NFACES) and Nodes (C_NNODES) in a Cell ............................. 313
3.2.3.4. Cell Face Index (C_FACE) ....................................................................................... 313
3.2.3.5. Cell Face Thread (C_FACE_THREAD) ..................................................................... 314
3.2.3.6. Flow Variable Macros for Cells ................................................................................ 314
3.2.3.6.1. Species Fractions Calculations with the Non- and Partially- Premixed Mod-
els .............................................................................................................................. 315
3.2.3.7. Gradient (G) and Reconstruction Gradient (RG) Vector Macros ................................ 316
Release 2022 R1 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.xvi
Customization Manual
3.2.3.8. Previous Time Step Macros ..................................................................................... 321
3.2.3.9. Derivative Macros .................................................................................................. 323
3.2.3.10. Material Property Macros ..................................................................................... 323
3.2.3.11. Reynolds Stress Model Macros ............................................................................. 325
3.2.3.12. VOF Multiphase Model Macro .............................................................................. 325
3.2.4. Face Macros ................................................................................................................... 326
3.2.4.1. Face Centroid (F_CENTROID) ............................................................................... 326
3.2.4.2. Face Area Vector (F_AREA) .................................................................................... 326
3.2.4.3. Flow Variable Macros for Boundary Faces ............................................................... 327
3.2.4.4. Flow Variable Macros at Interior and Boundary Faces .............................................. 328
3.2.5. Connectivity Macros ....................................................................................................... 328
3.2.5.1. Adjacent Cell Index (F_C0, F_C1) .......................................................................... 329
3.2.5.2. Adjacent Cell Thread (THREAD_T0, THREAD_T1) .................................................. 330
3.2.5.3. Interior Face Geometry (INTERIOR_FACE_GEOMETRY) ....................................... 330
3.2.5.4. Boundary Face Geometry (BOUNDARY_FACE_GEOMETRY) ................................... 331
3.2.5.5. Boundary Face Thread (BOUNDARY_FACE_THREAD) ............................................. 331
3.2.5.6. Boundary Secondary Gradient Source (BOUNDARY_SECONDARY_GRADI-
ENT_SOURCE) ................................................................................................................. 331
3.2.6. Special Macros ............................................................................................................... 332
3.2.6.1.Thread Pointer for Zone ID (Lookup_Thread) ...................................................... 332
3.2.6.2. Zone ID (THREAD_ID) ........................................................................................... 334
3.2.6.3. Domain Pointer (Get_Domain) ............................................................................ 334
3.2.6.4. Set Boundary Condition Value (F_PROFILE) ......................................................... 335
3.2.6.5. THREAD_SHADOW(t) ......................................................................................... 336
3.2.7. Time-Sampled Data ........................................................................................................ 337
3.2.8. Model-Specific Macros ................................................................................................... 339
3.2.8.1. DPM Macros .......................................................................................................... 339
3.2.8.2. NOx Macros ........................................................................................................... 345
3.2.8.3. Dynamic Mesh Macros ........................................................................................... 347
3.2.8.4. Battery Model Macros ............................................................................................ 347
3.2.9. NIST Real Gas Saturation Properties ................................................................................ 348
3.2.9.1. Saturation Curves for Single-Species ...................................................................... 348
3.2.9.2. Saturation Curves for Multi-Species (UDF 1) ............................................................ 349
3.2.9.3. Saturation Curves for Multi-Species (UDF 2) ............................................................ 350
3.2.9.3.1. Using Multi-Species User-Defined Function (UDF2) ........................................ 351
3.2.9.3.2. Example Multi-Species User-Defined Function (UDF2) .................................... 351
3.2.10. NIST Real Gas UDF Access Macro for Multi-Species Mixtures .......................................... 352
3.2.10.1. Description .......................................................................................................... 352
3.2.10.2. Using get_prop_NIST_msp ............................................................................ 354
3.2.10.3. Error Handling ..................................................................................................... 355
3.2.10.4. Example .............................................................................................................. 355
3.2.11. User-Defined Scalar (UDS) Transport Equation Macros ................................................... 357
3.2.11.1. Set_User_Scalar_Name ............................................................................... 357
3.2.11.2. F_UDSI ............................................................................................................. 358
3.2.11.3. C_UDSI ............................................................................................................. 358
3.2.11.4. Reserving UDS Variables ...................................................................................... 359
3.2.11.5. Reserve_User_Scalar_Vars ...................................................................... 359
3.2.11.6. Unreserving UDS Variables ................................................................................... 359
3.2.11.7. N_UDS ................................................................................................................ 360
3.2.12. User-Defined Memory (UDM) Macros ............................................................................ 360
3.2.12.1. Set_User_Memory_Name ............................................................................... 360
xvii
Release 2022 R1 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
3.2.12.2. Set_User_Node_Memory_Name .................................................................... 361
3.2.12.3. F_UDMI ............................................................................................................. 361
3.2.12.4. C_UDMI ............................................................................................................. 362
3.2.12.5. N_UDMI ............................................................................................................. 362
3.2.12.6. Example UDF that Utilizes UDM and UDS Variables ............................................... 363
3.2.12.7. Reserving UDM Variables Using Reserve_User_Memory_Vars ..................... 364
3.2.12.8. Example 1 ............................................................................................................ 365
3.2.12.9. Example 2 ............................................................................................................ 366
3.2.12.10. Unreserving UDM Variables ................................................................................ 367
3.3. Looping Macros ...................................................................................................................... 367
3.3.1. Looping Over Cell Threads in a Domain (thread_loop_c) ........................................... 368
3.3.2. Looping Over Face Threads in a Domain (thread_loop_f) .......................................... 368
3.3.3. Looping Over Cells in a Cell Thread (begin...end_c_loop) ....................................... 368
3.3.4. Looping Over Faces in a Face Thread (begin...end_f_loop) .................................... 369
3.3.5. Looping Over Faces of a Cell (c_face_loop) ................................................................ 369
3.3.6. Looping Over Nodes of a Cell (c_node_loop) ............................................................... 370
3.3.7. Looping Over Nodes of a Face (f_node_loop) ............................................................. 370
3.3.8. Overset Mesh Looping Macros ........................................................................................ 370
3.3.8.1. Looping Over Overset Interface Cell Threads (thread_loop_overset_c) ......... 371
3.3.8.2. Looping Over Active Overset Cells in a Cell Thread (begin...end_c_loop_active,
begin…end_c_loop_solve) ....................................................................................... 371
3.3.8.2.1. Example 1 ..................................................................................................... 372
3.3.8.2.2. Example 2 ..................................................................................................... 372
3.3.8.3. Looping Over Faces in a Face Thread with Overset Mesh (be-
gin...end_f_loop_active) ..................................................................................... 372
3.3.8.3.1. Example ....................................................................................................... 373
3.3.9. Multiphase Looping Macros ........................................................................................... 374
3.3.9.1. Looping Over Phase Domains in Mixture (sub_domain_loop) ............................ 374
3.3.9.2. Looping Over Phase Threads in Mixture (sub_thread_loop) .............................. 375
3.3.9.3. Looping Over Phase Cell Threads in Mixture (mp_thread_loop_c) ..................... 376
3.3.9.4. Looping Over Phase Face Threads in Mixture (mp_thread_loop_f) .................... 376
3.3.10. Advanced Multiphase Macros ....................................................................................... 377
3.3.10.1. Phase Domain Pointer (DOMAIN_SUB_DOMAIN) ................................................. 377
3.3.10.2. Phase-Level Thread Pointer (THREAD_SUB_THREAD) .......................................... 378
3.3.10.3. Phase Thread Pointer Array (THREAD_SUB_THREADS) ........................................ 379
3.3.10.4. Mixture Domain Pointer (DOMAIN_SUPER_DOMAIN) .......................................... 379
3.3.10.5. Mixture Thread Pointer (THREAD_SUPER_THREAD) ............................................ 379
3.3.10.6. Domain ID (DOMAIN_ID) .................................................................................... 380
3.3.10.7. Phase Domain Index (PHASE_DOMAIN_INDEX) .................................................. 380
3.4. Vector and Dimension Macros ................................................................................................. 380
3.4.1. Macros for Dealing with Two and Three Dimensions ........................................................ 381
3.4.1.1. RP_2D and RP_3D ............................................................................................... 381
3.4.2. The ND Macros ............................................................................................................... 381
3.4.2.1. ND_ND ................................................................................................................. 381
3.4.2.2. ND_SUM ............................................................................................................... 382
3.4.2.3. ND_SET ............................................................................................................... 382
3.4.3. The NV Macros ............................................................................................................... 382
3.4.3.1. NV_V .................................................................................................................... 382
3.4.3.2. NV_VV ................................................................................................................. 382
3.4.3.3. NV_V_VS ............................................................................................................. 382
3.4.3.4. NV_VS_VS ........................................................................................................... 383
Release 2022 R1 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.xviii
Customization Manual
3.4.4. Vector Operation Macros ................................................................................................ 383
3.4.4.1.Vector Magnitude Using NV_MAG and NV_MAG2 ................................................... 383
3.4.4.2. Dot Product ........................................................................................................... 383
3.4.4.3. Cross Product ........................................................................................................ 384
3.5.Time-Dependent Macros ......................................................................................................... 384
3.6. Scheme Macros ...................................................................................................................... 386
3.6.1. Defining a Scheme Variable in the Text Interface ............................................................. 386
3.6.2. Accessing a Scheme Variable in the Text Interface ........................................................... 387
3.6.3. Changing a Scheme Variable to Another Value in the Text Interface ................................. 387
3.6.4. Accessing a Scheme Variable in a UDF ............................................................................. 387
3.7. Input/Output Functions .......................................................................................................... 388
3.7.1. Message ...................................................................................................................... 389
3.7.2. Error .......................................................................................................................... 389
3.7.3.The par_fprintf_head and par_fprintf Functions ............................................. 390
3.7.3.1. par_fprintf_head ......................................................................................... 390
3.7.3.2. par_fprintf .................................................................................................... 390
3.8. Miscellaneous Macros ............................................................................................................. 391
3.8.1. Data_Valid_P() ...................................................................................................... 391
3.8.2. FLUID_THREAD_P() .................................................................................................. 391
3.8.3. Get_Report_Definition_Values ....................................................................... 392
3.8.4. M_PI ............................................................................................................................ 394
3.8.5. NULLP & NNULLP ...................................................................................................... 394
3.8.6. N_UDM .......................................................................................................................... 395
3.8.7. N_UDS .......................................................................................................................... 395
3.8.8. SQR(k) ........................................................................................................................ 395
3.8.9. UNIVERSAL_GAS_CONSTANT ..................................................................................... 395
4. Interpreting UDFs .......................................................................................................................... 397
4.1. Introduction ........................................................................................................................... 397
4.1.1. Location of the udf.h File ............................................................................................. 397
4.1.2. Limitations ..................................................................................................................... 398
4.2. Interpreting a UDF Source File Using the Interpreted UDFs Dialog Box ..................................... 399
4.3. Common Errors Made While Interpreting A Source File ............................................................ 401
5. Compiling UDFs ............................................................................................................................. 403
5.1. Introduction ........................................................................................................................... 404
5.1.1. Location of the udf.h File ............................................................................................. 405
5.1.2. Compilers ...................................................................................................................... 405
5.2. Compiling a UDF Using the GUI ............................................................................................... 407
5.3. Compile a UDF Using the TUI ................................................................................................... 411
5.3.1. Set Up the Directory Structure ........................................................................................ 412
5.3.1.1. Windows Systems .................................................................................................. 412
5.3.1.2. Linux Systems ........................................................................................................ 413
5.3.2. Build the UDF Library ..................................................................................................... 415
5.3.2.1. Windows Systems .................................................................................................. 415
5.3.2.2. Linux Systems ........................................................................................................ 417
5.3.3. Load the UDF Library ...................................................................................................... 418
5.4. Link Precompiled Object Files From Non-Ansys Fluent Sources ................................................ 418
5.4.1.Windows Systems ........................................................................................................... 418
5.4.2. Linux Systems ................................................................................................................ 419
5.4.3. Example: Link Precompiled Objects to Ansys Fluent ........................................................ 420
5.5. Load and Unload Libraries Using the UDF Library Manager Dialog Box ..................................... 423
5.5.1. Load the UDF Library ...................................................................................................... 423
xix
Release 2022 R1 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.
Customization Manual
5.5.2. Unload the UDF Library .................................................................................................. 424
5.6. Common Errors When Building and Loading a UDF Library ...................................................... 425
5.6.1. Windows Distributed Parallel .......................................................................................... 426
5.7. Special Considerations for Parallel Ansys Fluent ....................................................................... 426
6. Hooking UDFs to Ansys Fluent ...................................................................................................... 427
6.1. Hooking General Purpose UDFs ............................................................................................... 427
6.1.1. Hooking DEFINE_ADJUST UDFs ................................................................................... 427
6.1.2. Hooking DEFINE_DELTAT UDFs ................................................................................... 429
6.1.3. Hooking DEFINE_EXECUTE_AT_END UDFs ................................................................. 430
6.1.4. Hooking DEFINE_EXECUTE_AT_EXIT UDFs ............................................................... 431
6.1.5. Hooking DEFINE_INIT UDFs ....................................................................................... 433
6.1.6. Hooking DEFINE_ON_DEMAND UDFs ............................................................................ 435
6.1.7. Hooking DEFINE_RW_FILE and DEFINE_RW_HDF_FILE UDFs ................................. 436
6.1.8. User-Defined Memory Storage ....................................................................................... 438
6.2. Hooking Model-Specific UDFs ................................................................................................. 438
6.2.1. Hooking DEFINE_ANISOTROPIC_CONDUCTIVITY UDFs ........................................... 440
6.2.2. Hooking DEFINE_CHEM_STEP UDFs ............................................................................ 442
6.2.3. Hooking DEFINE_CPHI UDFs ....................................................................................... 443
6.2.4. Hooking DEFINE_DIFFUSIVITY UDFs ........................................................................ 446
6.2.5. Hooking DEFINE_DOM_DIFFUSE_REFLECTIVITY UDFs ........................................... 448
6.2.6. Hooking DEFINE_DOM_SOURCE UDFs .......................................................................... 450
6.2.7. Hooking DEFINE_DOM_SPECULAR_REFLECTIVITY UDFs ......................................... 451
6.2.8. Hooking DEFINE_EC_RATE UDFs ................................................................................ 453
6.2.9. Hooking DEFINE_EC_KINETICS_PARAMETER UDFs .................................................. 455
6.2.10. Hooking DEFINE_EDC_MDOT UDFs ............................................................................ 457
6.2.11. Hooking DEFINE_EDC_SCALES UDFs ........................................................................ 458
6.2.12. Hooking DEFINE_EMISSIVITY_WEIGHTING_FACTOR UDFs .................................. 460
6.2.13. Hooking DEFINE_FLAMELET_PARAMETERS UDFs .................................................... 462
6.2.14. Hooking DEFINE_GAP_MODEL_SOURCE UDFs ........................................................... 464
6.2.15. Hooking DEFINE_GRAY_BAND_ABS_COEFF UDFs .................................................... 465
6.2.16. Hooking DEFINE_HEAT_FLUX UDFs .......................................................................... 466
6.2.17. Hooking DEFINE_IGNITE_SOURCE UDFs ................................................................. 467
6.2.18. Hooking DEFINE_MASS_TR_PROPERTY UDFs ........................................................... 468
6.2.19. Hooking DEFINE_NET_REACTION_RATE UDFs ........................................................ 470
6.2.20. Hooking DEFINE_NOX_RATE UDFs ............................................................................ 472
6.2.21. Hooking DEFINE_PERFORATED_CD UDFs ................................................................. 474
6.2.22. Hooking DEFINE_PDF_TABLE UDFs .......................................................................... 477
6.2.23. Hooking DEFINE_PR_RATE UDFs .............................................................................. 478
6.2.24. Hooking DEFINE_PRANDTL UDFs .............................................................................. 480
6.2.25. Hooking DEFINE_PROFILE UDFs .............................................................................. 481
6.2.25.1. Hooking Profiles for UDS Equations ...................................................................... 483
6.2.26. Hooking DEFINE_PROPERTY UDFs ............................................................................ 486
6.2.27. Hooking DEFINE_REACTING_CHANNEL_BC UDFs .................................................... 487
6.2.28. Hooking DEFINE_REACTING_CHANNEL_SOLVER UDFs ........................................... 487
6.2.29. Hooking DEFINE_RELAX_TO_EQUILIBRIUM UDFs .................................................. 489
6.2.30. Hooking DEFINE_SBES_BF UDFs .............................................................................. 490
6.2.31. Hooking DEFINE_SCAT_PHASE_FUNC UDFs ............................................................. 494
6.2.32. Hooking DEFINE_SOLAR_INTENSITY UDFs ............................................................. 495
6.2.33. Hooking DEFINE_SOLIDIFICATION_PARAMS UDFs ................................................ 497
6.2.34. Hooking DEFINE_SOURCE UDFs ................................................................................. 498
6.2.35. Hooking DEFINE_SOOT_MASS_RATES UDFs ............................................................. 500
Release 2022 R1 - © ANSYS, Inc. All rights reserved. - Contains proprietary and confidential information
of ANSYS, Inc. and its subsidiaries and affiliates.xx
Customization Manual
剩余817页未读,继续阅读
点击了解资源详情
点击了解资源详情
点击了解资源详情
2021-08-31 上传
2022-07-15 上传
2022-01-16 上传
2022-06-30 上传
2022-09-19 上传
少年小鱼
- 粉丝: 32
- 资源: 528
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功