版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、UDFs for a User-Defined Scalar1. IntroductionANSYS Fluent solves the transport equation for a user-defined scalar (UDS) in the same way as it solves the transport equation for a scalar in the core equations, such as a species mass fraction. The UDS capability can be used to implement a wide range of
2、 physical models in magneto-hydrodynamics, electromagnetics, and more.In this tutorial you will learn to solve a general scalar diffusion equation with the possible types ofboundary condition (BC) at the boundary (or a part of the boundary) of the domain.The possible types of boundary conditions are
3、 as follows:Dirichlet BC: = D0Neumann BC: (/n) = q0Mixed BC: (/n) = hC( )Here, D0, q0, hC, and are constant values.This tutorial demonstrates how to do the following:Set the user defined scalar values.Compile the UDF.Postprocess the resulting data.2.PrerequisitesThis tutorial is written with the ass
4、umption that you have completed Tutorial 1 from ANSYS Fluent Tu- torial Guide, and that you are familiar with the ANSYS Fluent navigation pane and menu structure. Some steps in the setup and solution procedure will not be shown explicitly.For more details about user-defined functions (UDF) refer to
5、the ANSYS Fluent UDF Manual.3. Problem DescriptionAs shown in the problem illustration, the problem is a 2D rectangle, with constant flux, constant value, and mixed boundary conditions along the boundary edges.Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential info
6、rmation of ANSYS, Inc. and its subsidiaries and affiliates.1UDFs for a User-Defined ScalarFor the problem, = 0.162 W/(m K)Cp = Specific heat of the material 1650 J/(kg K) = 550oChC = 20 W/(m2K)Figure 1:Problem Schematic4. Preparation1.Copy the files (laplace.msh.gz,mixedbc.c, and transientMixedBC.c)
7、 to the working folder.Use Fluent Launcher to start the 2D version of ANSYS Fluent.Enable Double-Precision in the Options list.2.3.Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.2Setup and Solution4
8、.Click the UDF Compiler tab and ensure that the Setup Compilation Environment for UDF is enabled.NoteThe path to the .bat fie which is required to compile the UDF will be displayed as soonas you enable Setup Compilation Environment for UDF.If the UDF Compiler tab does not appear in the Fluent Launch
9、er dialog box by default, click the Show More Options button to view the additional settings.5. Setup and Solution5.1. Mesh Read the mesh file (laplace.msh.gz).File Read Mesh.NoteAs the mesh file is read, ANSYS Fluent will report the progress in the console.Figure 2:Mesh Display5.2. GeneralSettings1
10、.Retain the default solver settings.GeneralRelease 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.3UDFs for a User-Defined Scalar2.Check the mesh.General CheckNoteANSYS Fluent will perform various checks on
11、 the mesh and will report the progress inthe console. Ensure that the reported minimum volume is a positive number.5.3. User-Defined Functions1.Set the UDS value.Define User-Defined Scalars.a. Enter 1for Number of User-Defined Scalars.b. Select none from Flux Function drop-down list.c.Click OK to cl
12、ose User-Defined Scalars dialog box.NoteClick OK in the Information dialog box that appears informing you of the change in the material properties or methods.Compile the UDF (mixedbc.c).Define User-Defined Functions Compiled.2.Click the Add. button in the Source Files section to open the Select File
13、 dialog.1.Select the file mixedbc.c.2.Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.4Setup and Solution3.Click Build.NoteA Warning dialog box will appear, warning you to make sure that the UDF sour
14、ce files are in the same folder that contains the case and data files. Click OK to close the Warning dialog box.You can view the compilation history in the log file that is saved in your working folder.4.Click Load to load the library.5.4. MaterialsMaterials air Create/Edit.Create a new material (ma
15、ple).1. Retain the default values for Density and Viscosity.2. Click Edit. for UDS Diffusivity and enter 0.162 for the Coefficient and close the UDS Diffusion Coefficients dialog box.Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and
16、its subsidiaries and affiliates.5UDFs for a User-Defined Scalar3. Enter maple for the Name.4. Click Change/Create.NoteA Question dialog box appears, asking you whether to overwrite air. Click Yes.Close the Create/Edit Materials dialog box.5.5.5. Boundary Conditions1.Set the boundary conditions for t
17、opwall.Boundary Conditions topwall Edit.a. Click the UDS tab.b. Select Specified Value from the User Scalar 0 drop-down list in the User-Defined Scalar Boundary Condition group box.c. Enter 80 for UDS Scalar 0 in the User-Defined Scalar Boundary Value group box.d. Click OK to close the Wall dialog b
18、ox.2.Set the boundary conditions for leftwall.Boundary Conditions leftwall Edit.a.Click the UDS tab.Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.6Setup and Solutionb.Ensure that Specified Value is
19、 selected from the User Scalar 0 drop-down list in the User-Defined Scalar Boundary Condition group box.c. Retain 0 for UDS Scalar 0 in the User-Defined Scalar Boundary Value group box.d. Click OK to close the Wall dialog box.Set the boundary conditions for rightwall.3.Boundary Conditions rightwall
20、Edit.a. Click the UDS tab and select Specified Value from the User Scalar 0 drop-down list in the User- Defined Scalar Boundary Condition group box.b. Select udf scalarMixedBC:libudf from the User Scalar 0 drop-down list in the User-Defined Scalar Boundary Value group box.c.Click OK to close the Wal
21、l dialog box.4.Set the similar boundary conditions for bottomwall as set for rightwall.NoteThe following equation gives mixed boundary condition for rightwall and bottomwall.Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsi
22、diaries and affiliates.7UDFs for a User-Defined Scalarwhere, = UDS diffusivity 0.162hC = 20 = 5505.6. Solution for Steady-State SolverDeselect the Flow equation.1.Solution Controls Equations.Disable Check Convergence foruds-0.2.Monitors Residuals Edit.3.Define a point monitor.Surface Point.a.Retain
23、0.025 for x0 (m) and 0.05 for y0 (m).b. Enter middlepoint for the Name.c. Click Create and close Point Surface dialog box.4.Enable the plotting of the point monitor.Monitors (Surface Monitors) Create.a. Enable Plot and Write.b. Retain the selection of Iteration from the X Axis and Get Data Every dro
24、p-down lists.Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.8Setup and Solutionc.Select Sum from the Report Type drop-down list.d.Select User Defined Scalars. and Scalar-0 from the Field Variable dr
25、op-down lists.e. Select middlepoint from the Surfaces list.f. Click OK to close the Surface Monitor dialog box.5.Initialize the solution.Solution Initialization InitializeNoteHybrid Initialization is the default Initialization Method in ANSYS Fluent. Refer to the section 28.11 Hybrid Initialization,
26、 in the ANSYS Fluent Users Guide.Save the initial case file (laplace.cas.gz).File Write Case.6.7.Start the calculation for 50 iterations.Run Calculation CalculateNoteAs the value of remains constant after 40 iterations (Figure 3: Scaled Residuals (p. 9) and Figure 4: Monitor Plot (p. 10), you can co
27、nsider that the solution is converged.Figure 3:Scaled ResidualsRelease 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.9UDFs for a User-Defined ScalarFigure 4:Monitor PlotSave the data file (laplace.dat.gz).
28、8.File Write Data.5.7. Postprocessing Display the contours of .Graphics and Animations Contours Set Up.a. Select User Defined Scalars. and Scalar-0 from the Contours of drop-down lists.b. Click Display and close the Contours dialog box.Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprie
29、tary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.10Setup and SolutionFigure 5: Contours of Since the problem is partially set up in the steady case, here only the unique steps for the setupof the unsteady solver are mentioned.5.8.UnsteadyUDSSolverThe unsteady diff
30、usion problem represented by equation shown in Appendix B: Unsteady Solver (p. 17), over the same rectangular domain is solved by a first-order implicit formulation. The boundary condition is also unchanged. The initial condition is = 80 through the domain.Read the case file laplace.cas.gz.File Read
31、 Case.1.2.Enable the transient solver.General TransientCompile the UDF (transientMixedBC.c).Define User-Defined Functions Compiled.3.a. Click Add. and select the source file, transientMixedBC.c.b. Enter libudf1 for the Library Name.c. Click Build to build the library.NoteA Warning dialog box opens,
32、asking you to ensure that the UDF source files are in the same folder that contains the case and data files. Click OK.Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.11UDFs for a User-Defined Scalard
33、.Click Load to load the newly created UDF library.4.Select first-order unsteady UDF.Define User-Defined Scalars.a. Retain Number of User-Defined Scalars to 1.b. Retain the selection of none from Flux Function drop-down list.c.Select unst1stOrder:libudf1 from Unsteady Function drop-down list.d.Click
34、OK to close User-Defined Scalars dialog box.Initialize the solution by setting User Scalar 0 to 80.5.Solution Initialization InitializeEnter 10 for Autosave Every (Time Steps).6.Calculation Activities7.Set the time-stepping parameters.Run CalculationEnter 0.1 s for Time Step Size. Enter 200 for Numb
35、er of Time Steps.Enter 40 for Max Iterations/Time Step.Click Calculate.a.b.c.d.Display the contours of at t = 1 s.8.a.Read the data file (laplace-1-00010.dat).File Read Data.b.Select User Defined Scalars. and Scalar-0 from the Contours of drop-down lists.Graphics and Animations Contours Set Up.c.Cli
36、ck Display (Figure 6: Contours of at t = 1 s (p. 13) ).Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.12Setup and SolutionFigure 6: Contours of at t = 1 s9.Similarly, display contours of at t = 3 s,
37、 t = 4 s, and t = 5 s by reading appropriate data files.NoteThe diffusion of into the domain due to high in the ambient is clearly visible viathe mixed (convective) boundarycondition.Figure 7: Contours of at t = 3 sRelease 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential
38、 information of ANSYS, Inc. and its subsidiaries and affiliates.13UDFs for a User-Defined ScalarFigure 8: Contours of at t = 4 sFigure 9: Contours of at t = 5s6. Appendix A: Steady-State SolverConsider a steady-state scalar equation with constant and zero source term (S = 0) as follows: . () = 0This
39、 is the Laplaces equation. Solving the Laplacess equation using the ANSYS Fluent UDS solver does not necessarily require user-defined functions (UDFs). You can activate the UDS from the graphical user interface. ANSYS Fluent UDS provides only Dirichlet and Neumann conditions for the boundaries. Henc
40、e, you need to use the UDF to apply the mixed boundary condition for the UDS equation.Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.14Appendix A: Steady-State SolverFormulation of the Mixed Boundar
41、y ConditionFigure 10:Mixed Boundary ConditionFor a generic cell c0 adjacent to the boundary, the diffusive flux across the boundary face f of the cell is expressed as follows:Using the mid-point rule of surface integral, the diffusive flux can be approximated as:In ANSYS Fluent, the diffusive flux i
42、s approximated in two parts:1. The primary gradient is evaluated implicitly along the line connecting the cell centroid c0 to the centroid face f.2. It is corrected by a secondary gradient (or cross diffusion) term evaluated explicitly by the gradient obtainedfrom the previous iteration ().Release 1
43、6.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.15UDFs for a User-Defined ScalarANSYS Fluent provides you with two macros: BOUNDARY_FACE_GEOMETRY(f, t, A, ds, es, A_by_es, dr0): a macro which defines the nece
44、ssary geometrical variables of the cell. BOUNDARY_SECONDARY_GRADIENT_SOURCE(source, SV_UDSI_G(i), dG, es, A_by_es, k): a macro which calculates the secondary gradient term in the above equation.If you designate the secondary gradient term in the above equation as 0, andAbe, equations can be written
45、as:asf can be expressed as follows:The mixed boundary condition for the UDS is ready to be specified by boundary profile f in the equation above through the UDF macro DEFINED_PROFILE().UDF CodeThe UDF code for steady state is as follows:/*/* Implementation of the mixed boundary condition for a UDS (
46、or multiple):/* q = hC ( phi - PHI_inf)*/*/*/#include udf.h#include sg.h /* needed for the boundary and secondary gradient macros */*=*/#define CP 1650.0 /* heat capacity for maple in (J/kg K) */ #define HTC 20.0 /* heat transfer coefficient for the problem */ #define TINF 550 /* ambient temperature
47、 of the problem */*=*/* Names of the user-defined scalar to be used */ enumphi1, N_REQUIRED_UDS;Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.16Appendix B: Unsteady SolverDEFINE_PROFILE(scalarMixed
48、BC, thread, nv)/*constants must be specified correctly for the mixed BC */ real hC, PHI1_inf;/* = */face_t f;real AND_ND, dGND_ND, dr0ND_ND, esND_ND, dr, A_by_es; real Af;real beta0, gamma; real temp1, temp2; Thread *t0=thread-t0;hC=HTC; PHI1_inf=TINF;begin_f_loop(f, thread)/* identify the cell thre
49、ad adjecent to the face thread f */ cell_t c0 = F_C0(f, thread);BOUNDARY_FACE_GEOMETRY(f, thread, A, dr, es, A_by_es, dr0); Af=NV_MAG(A);gamma=C_UDST_DIFF(c0, t0, phi1);if (NULLP(T_STORAGE_R_NV(t0, SV_UDST_G(phi1)beta0=0; /*if gradient is not allocated and stored yet, bypass the following macro (it
50、happenswhen case/data files are being read */ elseBOUNDARY_SECONDARY_GRADIENT_SOURCE(beta0, SV_UDSI_G(phi1), dG,es, A_by_es, gamma);/* temporary variables used in the profile expression */ temp1=gamma*A_by_es/dr;temp2=hC*Af;F_PROFILE(f, thread, nv)= (temp1*C_UDSI(c0, t0, phi1)- beta0 + temp2*PHI1_in
51、f)/(temp2 + temp1);end_f_loop(f, thread)7.Appendix B:UnsteadySolverThe unsteady user-defined scalar equation is as follows:It has to be solved with the same boundary conditions and given initial condition. When the transient term is ()/t, ANSYS Fluent can readily handle this unsteady UDS term when y
52、ou enable the unsteady solver (either first or second-order). But if the transient term of the users equation is not the same as the given form, you must supply the unsteady term through the DEFINE_UDS_UNSTEADY() macro.For example, in the above equation, c is a variable. For an unsteady heat conduct
53、ion problem in dimen- sional form it represents cp of the solid material.Release 16.0 - SASIP,Inc. All rights reserved.- Contains proprietary and confidential information of ANSYS, Inc. and its subsidiaries and affiliates.17UDFs for a User-Defined ScalarFirst-Order Unsteady FormulationIn finite-volu
54、me methods, the transient term is first approximated by first or second-order finite-difference expression, then integrated with respect to the cell volume. The ANSYS Fluent solver expects this tran- sient term to be moved to the right-hand side of the governing equation and included in the discretized equation as a source term.The first-order finite-difference backward differencing approximation gives:where,n = the value of at the current time leveln-1 = the value a
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年房地产金融产品的营销与推广
- 神经发育技术
- 光伏组件知识培训课件
- 2026广东汕尾市陆河县应急管理局招聘综合应急救援队员5人备考题库有答案详解
- 【数学】2025-2026学年人教版九年级数学上册期末测试题
- 母乳喂养问题处理试题及答案2026年
- 2025 小学二年级科学上册科学与人文的融合教育课件
- 2026春学年外研新版英语八下Unit1随堂小测
- 2026年智能耳放项目项目建议书
- 2026年重力储能技术创新项目公司成立分析报告
- 固态电池技术在新能源汽车领域的产业化挑战与对策研究
- 手术部(室)医院感染控制标准WST855-2025解读课件
- 二氧化硅气凝胶的制备技术
- 湖南省岳阳市平江县2024-2025学年高二上学期期末考试语文试题(解析版)
- 2024-2025学年湖北省武汉市江汉区七年级(下)期末数学试卷
- 常规体检指标讲解
- 建筑工程生产管理培训
- 新人教版高中数学必修第二册-第八章 立体几何初步 章末复习【课件】
- 仓库物料效期管理制度
- GB/T 157-2025产品几何技术规范(GPS)圆锥的锥度与锥角系列
- T/CCT 017-2024中低温煤焦油
评论
0/150
提交评论