UDF Training- Petrodanesh



Comments



Description

2011ANSYS FLUENT GUIDE Advanced FLUENT User-Defined Functions You can access and manipulate almost every solver data and fully control the solution process in UDF-s written in C programming Language. Saeed Sadeghi ([email protected]) Pardad Pardad Petro Danesh Petro Danesh (www.petrodanesh.ir) (www.petrodanesh.ir) | Confidential 1/12/2011 Introduction 2 Table of Contents 1 Introduction .................................................................................................................................... 4 2 User Access to the FLUENT Solver................................................................................................... 4 3 C Programming ................................................................................................................................ 5 4 Cfd Programming in FLUENT ........................................................................................................... 7 5 UDF Basics ....................................................................................................................................... 7 6 Using UDFs in the Solvers ................................................................................................................ 8 7 Data structure overview.................................................................................................................. 8 7.1 The Domain ............................................................................................................................. 8 7.2 The Threads ............................................................................................................................. 9 7.3 Cell and Face Datatypes .......................................................................................................... 9 7.4 Some Additional info on Faces ................................................................................................ 9 8 Fluent UDF Data Structure Summary ............................................................................................ 10 9 Geometry Macros ......................................................................................................................... 11 10 Cell Field Variable Macros ......................................................................................................... 12 11 Face Field Variable Macros ....................................................................................................... 13 12 Looping and Thread Macros...................................................................................................... 14 13 Macros ....................................................................................................................................... 15 13.1 DEFINE Macros ...................................................................................................................... 15 13.2 Othe UDF Applications .......................................................................................................... 16 14 User Defined Memories ............................................................................................................ 17 15 User Defined Scalars.................................................................................................................. 18 16 Interpreted vs. Compiled UDF’s ................................................................................................ 19 17 UDF Technical Support .............................................................................................................. 19 18 Example: Parabolic Inlet Velocity Profile .................................................................................. 20 18.1 Step 1: Prepare the Source Code .......................................................................................... 20 18.2 Step 3: Interpret or Compile the UDF ................................................................................... 20 18.3 Step 4: Activate the UDF ....................................................................................................... 21 18.4 Steps 5 and 6: Run the Calculations ...................................................................................... 21 18.5 Numerical Solution of the Example ....................................................................................... 21 19 Example: Checking Effect of Porous Zone on Momentum Equation ........................................ 22 19.1 Using Fluent Built-in Porous Zone ......................................................................................... 22 19.2 Using Momentum Source Terms........................................................................................... 23 20 Example: Modeling Fuel Cell ..................................................................................................... 24 Saeed Sadeghi ([email protected]) Pardad Petro Danesh (www.petrodanesh.ir) Introduction 3 20.1 Preparation............................................................................................................................ 24 20.2 Mesh ...................................................................................................................................... 24 20.3 General Settings .................................................................................................................... 24 20.4 Models ................................................................................................................................... 25 20.5 Materials ............................................................................................................................... 25 20.6 Boundary Conditions ............................................................................................................. 26 20.6.1 Setting Velocity Inlet ..................................................................................................... 29 20.6.2 Pressure Outlet.............................................................................................................. 29 20.7 Writing UDF ........................................................................................................................... 30 20.7.1 Compiling the UDF......................................................................................................... 32 20.8 Checking Oxygen Mass Balance ............................................................................................ 37 21 Fluent Frequently Asked Questions .......................................................................................... 39 21.1 My UDF won't interpret or compile - what is wrong? .......................................................... 39 21.2 How to Set Environment Variables ....................................................................................... 39 21.2.1 On Windows 32 Bit ........................................................................................................ 39 21.2.2 On Windows 64 Bit ........................................................................................................ 39 Saeed Sadeghi ([email protected]) Pardad Petro Danesh (www.petrodanesh.ir) Introduction 4 1 Introduction • What is a User Defined Function? o A UDF is a routine (programmed by the user) written in C which can be dynamically linked with the solver.petrodanesh. control blocks. source terms.  Standard C functions • e.  Customization of boundary conditions. exponential. etc.  Pre-Defined Macros • Allows access to field variable. • Why build UDF’s? o Standard interface cannot be programmed to anticipate all needs. material properties.g. material property.com) Pardad Petro Danesh (www.ir) . and cell geometry data.. trigonometric.  Adjust functions (once per iteration)  Execute on Demand functions  Solution Initialization 2 User Access to the FLUENT Solver Saeed Sadeghi (msaeedsadeghi@gmail. etc. reaction rates. do-loops. file i/o. -.com) Pardad Petro Danesh (www. 2 */ • pointer is a special kind of variable that contains the memory address. Z are enumeration constants 0. enum. i++ is “pors-increment”. /* declaring ‘niter’ and ‘a’ as integers */ float dx[10]. the array index always starts from dx[0] */ enum { X. then increment I by 1 (i=i+) -. not content. use the current value of j. /* ‘dx’ is a real array with 10 members. >. o Comments can be inserted anywhere between /* and */ o Variables must be explicitly declared (unlike in FORTRAN) o Compound statements must be enclosed by { } o Functions have the following format: return-value-type function-name (parameter-list) { function body } o Macros are defined in the header files. <=. ip = &a. != ++ increment. >=. • Pointers are also used to point to the beginning of an array o Thus pointers are used to address arrays in C • Array variables can be defined using the notation name[size]. Y. Y. of another variable • Pointers are declared using the * notation: int *ip. *ip). % (modulus) <. Z }. ==. /* &a returns the address of variable a */ printf(“content of address pointed to by ip = %d\n”. then decrement j by 1 (j=j-1) += addition assignment: Saeed Sadeghi (msaeedsadeghi@gmail. *. Boolean: int niter. double. int *ip.petrodanesh. /. use the current value of I in the expression. they can be used just like functions • Built-in data types: int. /* ip is declared as a pointer to integer */ • We can make a pointer point to the address of predefined variable as follows: int a=1. float. C Programming 5 3 C Programming • Basic syntax rules: o Each statement must be terminated with a semicolon .ir) . /* X.decrement: j—post-decrement. 1. where name is the variable name and size is an integer which defines the number of elements in the array (from 0 to size-1) • Operators = (assignment) +. a. true Saeed Sadeghi (msaeedsadeghi@gmail. Conditional operator ( ? : ) ( condition ? operand a : operand b ) example: false real At = (rp_axi ? At*2*M_PI : At ). if ( … ) <statement>. */ *= multiplication assignment. /* it means agg = agg + single. k<NUM. else if ( … ) <statement>. C Programming 6 agg += single. if ( … ) <statement>. k++ ) <statement>. -= subtraction assignment.ir) . /= division assignment • Basic control structures if ( … ) <statement>.petrodanesh. else <statement>. While loops: While ( … ) <statement>. For Loops: for ( k=0.com) Pardad Petro Danesh (www. etc. source terms) to individual cells and cell faces in fluid and boundary zones. o How to access field data for cells (and faces): pressure. multiphase.  Thread and variable references are automatically passed to UDF when assigned to boundary in GUI.. o In a UDF. reactions kinetics.  e. face normal directions (vectors). • Position of each face is available to calculate and assign spatially varying properties. etc.. face areas.g. the neighbors.petrodanesh.  Face centroids. • How to implement user’s own governing equations in the finite-volume framework of FLUENT solver 5 UDF Basics • UDF’s assigns values (e. zones are referred to as threads.. o How to efficiently loop through these cells or faces in the codes • How to sypply customized source terms. and dynamic mesh. and fluid properties. boundary data. Cfd Programming in FLUENT 7 4 Cfd Programming in FLUENT • We (as CFD programmers in FLUENT) want to know how FLUENT organizes data so that we know: o How to access mesh information for a particular cell zone or a face zone  Cell centroids. a face-loop macro visits 563 faces on face zone 3 (velocity-inlet). boundary conditions. density. etc.g. velocity. etc. • Values returned to the solver by UDFs must be in SI units. Saeed Sadeghi ([email protected]) .com) Pardad Petro Danesh (www. to the solver • How to modify the behaviors or specific model parameters for various physical models as in turbulence. cell volumes. o A looping macro is used to access individual cells belonging to a thread. etc. ir) . Using UDFs in the Solvers 8 6 Using UDFs in the Solvers • The basic steps for using UDFs in FLUENT are as follows: STEP 1: Create a file containing the UDF source code STEP 2: Start the solver and read in your case/data files STEP 3: Interpret or Compile the UDF STEP 4: Assign the UDF to the appropriate variable and zone in BC panel. STEP 5: Set the UDF update frequency in the Iterate panel.petrodanesh. It includes: o All fluid zones (‘fluid threads’) o All solid zones (‘solid threads’) o All boundary zones (‘boundary threads’) • Cell: cell is the computational unit.1 The Domain • Domain is the set of connectivity and hierarchy info for the entire data structure in a given problem for single phase flows.com) Pardad Petro Danesh (www. a Thread represents a fluid or solid or boundary zone • Multiphase simulations (singlephase simulations use single domain only) o Each phase has its own “Domain-structure” o Geometric and common property information are shared among ‘sub-domains’ Saeed Sadeghi (msaeedsadeghi@gmail. STEP 6: Run the calculation 7 Data structure overview 7. conservation equations are solved over each cell • Face: direction in the outward normal • Threads: represent the collection of cells or faces. com) Pardad Petro Danesh (www. which can be accessed by using cell threads • Boundary or internal faces can be accessed by using face threads 7. connectivity. etc. store structured information about the mesh.3 Cell and Face Datatypes • Control volumes of fluid and solid zones are also called ‘cells’ in FLUENT o The data structure for the cell zones is typed as ‘cell_t’ (the cell thread index) o The data structure for the cell faces is typed as ‘face_t’ (the face thread index) • A fluid or solid zone is called a cell zone. models. all in one place o Users identify zones through the ID’s o Zone/Thread-ID and Threads are correlated through UDF macro’s 7.4 Some Additional info on Faces • Each Control volume has a finite number of faces o Faces on the boundary are also typed ‘face_t’. property. ‘solid’ and each ‘boundary’ zones are identified as ‘zones’ and their datatype is Thread • ‘zone’ and ‘Thread’ terms are often used interchangeably • Some further details about Zone/Thread ID and Thread-datatype: o Zones are identified at mesh level with an integer ID in the Define/Boundary Condition panel o Threads.2 The Threads • A Thread is a sub-set of the Domain structure • Individual ‘fluid’. their ensemble are listed as boundary face- threads with the o fluid & solid cell-threads under Define- o Boundary_Condition panel o Those faces which are inside the flow-domain and do not o share any external boundary are not accessible from GUI o (because you do not need them) o They can still be accessed from User-Defined-Functions Saeed Sadeghi (msaeedsadeghi@gmail. a Fluent-specific datatype.petrodanesh. Data structure overview 9 o Multiphase UDF will be discussed later 7.ir) . the Lookup_Thread macro can retrieve the thread pointer Int ID = 7. given a thread pointer tf. Thread pointer provides the leading address of the thread (zone) Saeed Sadeghi (msaeedsadeghi@gmail. the data structure for faces is typed as ‘face_t' (the face thread index) Type Example Declaration Domain *d d is a pointer to domain thread Thread *t t is a pointer to thread Cell_t *c c is cell thread index Face_t f f is a face thread index Node *node node is pointer to a node • Each thread (zone) has a unique integer ID available in the boundary condition panel (or can be listed by the list-zone TUI command: /grid/modify-zones/list-zones) • Given a correct ID. Thread *tf = Lookup_Thread (domain.petrodanesh.ir) . we can access the members belonging to the zone without any problem. • Once we have the correct pointer (for a specific zone). the zone ID can be retrieved ID = THREAD_ID(tf).com) Pardad Petro Danesh (www. ID). • Conversely. Fluent UDF Data Structure Summary 10 8 Fluent UDF Data Structure Summary • The data structure for accessing a cell zone is typed as ‘cell_t’ (the cell thread index). (nn is a node pointer) • NODE_Y(nn) Node y-coord.com) Pardad Petro Danesh (www. z . y. t) x. c. returns time step size Saeed Sadeghi ([email protected]) . returns actual time • int time_step. t) Volume of a 2D cell (Depth is 1m in 2D. z – coords of face centroid • F_AREA(A. t) Number of nodes in a cell • C_NFACES(c.petrodanesh. returns time step number • RP_GET_Real(“physical-time-step”). • NODE_Z(nn) Node z-coord. Geometry Macros 11 9 Geometry Macros • C_NNODES(c. of faces in a cell • F_NNODES(f. • real flow_time(). t) Volume of a cell • C_VOLUME_2D(c. f. f. y. t) Area vector of a face • NV_MAG(A) Area-magnitude • C_VOLUME(c. t) No. t) x. t) No.coords of cell centroid • F_CENTROID(x. of nodes in face • C_CENTROID(x. 2*π m in axi-symmetric solver) • NODE_X(nn) Node x-coord. t).t). Cell Field Variable Macros 12 10 Cell Field Variable Macros C_R(c.t).t).i). effective viscosity C_K_L(c. effective thermal conductivity C_CP(C c.t. velocity derivative C_MU_L(c.t). density C_P(c.t). specific heat C_RGAS(c.t).t). velocity derivative C_DVDX(c.t. UDM scalars C_DUDX(c.t).i). velocity derivative C_DWDY(c. species mass fraction C_UDSI(c.t.t).t). turbulent thermal conductivity C_K_EFF(c. laminar species diffusivity C_DIFF_EFF(c.t). laminar viscosity C_MU_T(c.t).t). velocity derivative C_DVDY(c. gas constant C_DIFF_L(c.ir) . effective species diffusivity Saeed Sadeghi (msaeedsadeghi@gmail. u-velocity C_V(c. t).t).t).t). pressure C_U(c.t). velocity derivative C_DUDY(c. UDS scalars C_UDMI(c.i).com) Pardad Petro Danesh (www. tke dissipation C_YI(c.t).petrodanesh.t).t). velocity derivative C_DYDZ(c. enthalpy C_K(c. velocity derivative C_DVDZ(c.t). w-velocity C_T(c.t). v-velocity C_W(c.t). temperature C_H(c. turbulent viscosity C_MU_EFF(c.t). laminar thermal conductivity C_K_T(c.t).t). velocity derivative C_DWDX(c. turbulent KE C_D(c. velocity derivative C_DWDZ(c. t).com) Pardad Petro Danesh (www. enthalpy F_K(f. UDS scalars F_UMI(f. t). F_R(f. only at exterior boundaries. v-velocity F_W(f. t). t). t). t). t).petrodanesh. t). Mass flux across face f. u-velocity F_V(f. turbulent KE F_D(f. UDM scalars F_FLUX(f. Face Field Variable Macros 13 11 Face Field Variable Macros • Face field variables are only available when using the segregated solver and generally. species mass fraction F_UDSI(f. t).ir) . temperature F_H(f. Saeed Sadeghi (msaeedsadeghi@gmail. defined out of domain at boundaries. density F_P(f. tke dissipation F_YI(f. w-velocity F_T(f. t). t). pressure F_U(f. t). t). loop that steps through all face threads in domain } begin_c_loop(c. defines a cell face_t f. defines a face Specialized variable types Thread *t... t. Saeed Sadeghi (msaeedsadeghi@gmail. Loop that steps through all faces in a thread } C_face_loop(f. returns zone integer ID of thread pointer Code enclosed in { } is executed in loop. ID). loop that steps through all cell threads in domain } thread_loop_f(t.. pointer to collection of all threads thread_loop_c(t.petrodanesh. t) { ………. Looping and Thread Macros 14 12 Looping and Thread Macros cell_t c. pointer to a thread used for referencing Domain *d.com) Pardad Petro Danesh (www. Loop that visits all faces of cell c in thread t } Thread *tf = Lookup_Thread(domain.... d) { . return thread pointer of integer ID of zone THREAD_ID(tf)...ir) . Loop that steps through all cells in a thread } end_c_loop befing_f_loop(c. n) { ………. t) { ………. d) { ……….. rr. defines an ‘execute-on-demand’ function DEFINE_RW_FILE(name. 13.t0.1 DEFINE Macros • Any UDF you write must begin with a DEFINE_ macro: o 18 general purpose macros and 13 DPM-related macros (not listed).face.cell.face.thread.ds.cell. defines heat flux DEFINE_PROPERTY(name. general purpose UDF called every iteration DEFINE_INIT(name. defines vol.face.mw.thread.Inc/src/directory.domain). reaction rates DEFINE_SCAT_PHASE_FUNC(name.rr). defines variable time step size for unsteady problems Saeed Sadeghi ([email protected]_t).ir) . defines scattering phase function for DOM DEFINE_DELTAT(name.cell. • dpm.c0.index).  Depends upon relevant variables and macros needed in your UDF. • Macros are defined in header files.thread. defines boundary profiles DEFINE_SOURCE(name.cell. defines UDS transient terms DEFINE_SR_RATE(name.index).thread. DEFINE_ADJUST(name.face.index).petrodanesh.thread.h for DPM variable access • A list of often used macros is provided in the UDF User’s Guide.thread.h” o The header files must be accessible in your path. looping capabilities.yi.. o The udf.com) Pardad Petro Danesh (www. defines material properties DEFINE_DIFFUSIVITY(name. cell information. etc.r.cell. defines UDF and species diffusivities DEFINE_UDS_FLUX(name.thread).cir).thread.h” header files may need to be included.  #include “udf. Macros 15 13 Macros • Macros are pre-defined (Fluent) functions: o Allows definition of UDF functionality and function name (DEFINE_ macro) o Allow access to field variables.h header file must be included in your source code. defines surface reaction rates DEFINE_VR_RATE(name.thread.mw. o Other “.thread.yi. e.r. customize reads/writes to case/data files DEFINE PROFILE(name. defines UDS flux terms DEFINE_UDS_UNSTEADY(name.g.face).index). defines source terms DEFINE_HEAT_FLUX(name.index). UDF used to initialize field variables DEFINE_ON_DEMAND(name). domain).index).face.domain).  Typically stored in Fluent.cid. UDFs can be used for: o Initialization  Executes once per initialization o Adjust  Executes every iteration o Wall Heat Flux  Defines fluid-side diffusive and radiative wall heat fluxes in terms of heat transfer coefficients  Applies to all walls o User Defined Surface and Volumetric Reactions o Read-Write to/from case and data files  Read order and Write order must be same. defines NOx production and destruction rates 13.com) Pardad Petro Danesh (www. cell. defines turbulent flame speed DEFINE_NOX_RATE(name. nox). cell. turbflamespeed. Macros 16 DEFINE_TURBULENT_VISCOSIT(name. source). thread).ir) . source terms and material properties. thread.petrodanesh. o Execute-on-Demand capability  Not accessible during solve Saeed Sadeghi ([email protected] Othe UDF Applications • In addition to defining boundary values. thread. cell. defines procedure for calculating turbulent viscosity DEFINE_TURB_PREMIX_SOURCE(name. o Can be accessed by UDFs:  C_UDMI(cell. index). thread. Saeed Sadeghi (msaeedsadeghi@gmail. /User Defined Memories 17 14 User Defined Memories • User-allocated memory o Up to 500 field variables can be defined.ir) . o Information is stored in data file.petrodanesh. o Can be accessed for post-processing. thread. index).  F_UDMI(face.com) Pardad Petro Danesh (www. com) Pardad Petro Danesh (www.. • Define as constant or with UDF..petrodanesh. index)  ‘case’ statement can be used to associate multiple flux and transient functions with each UDS.. Saeed Sadeghi (msaeedsadeghi@gmail. o Example  Can be used to determine magnetic and/or electric field in a fluid zone. face. thread. N scalars ∂t ∂x i ∂x i  k  • User Specifies: Define  Models  User-Defined Scalars… o Number of User-Defined Scalars o Flux Function F  DEFINE_UDS_FLUX(name. cell. User Defined Scalars 18 15 User Defined Scalars • FLUNET can solve (up to 50) generic transport equations for User Defined Scalars: ∂φk ∂  ∂φk  +  Fi φk − Γ =  S= φk k 1. o Boundary Conditions for each UDS.  ‘case’ statement needed to define UDF diffusivities for each UDS.. • User must also specify: o Source terms o Diffusivity.  Specified Flux or Specified Value.ir) . index)  DEFINE_UDS_UNSTEADY(name. thread. implementation (writing C code). Compiled UDF’s • Functions can either be read in and interpreted at run time or compiled and grouped into a shared library that is linked with the standard FLUENT executable. Saeed Sadeghi (msaeedsadeghi@gmail. structure references etc. o Support will be limited to guidance related to communication between a UDF and the FLUENT solver.  Efficient way to run UDF’s. • Interpreted vs. 17 UDF Technical Support • Because UDF’s can be very complicated.com) Pardad Petro Danesh (www. mixed mode arithmetic. compiled code o Interpreter  Interpreter is a large program that sits in the computer’s memory. does not assume responsibility for the accuracy or stability of solutions obtained using UDFs that are user-generated.g.petrodanesh.ir) . Fluent Inc. compilation and debugging of C source code. and function design verification will remain the responsibility of the UDF author. execution of the UDF.  A consulting option is available for complex projects.  Executes code on a “line by line” basis instantaneously  Advantages – does not need a separate compiler  Disadvantage – slow and takes up space in memory o Compiler (refer to User’s Guide for instructions)  Code is translated “once” into machine language (object modules). Interpreted vs. o Other aspects of the UDF development process that include conceptual function design. Uses Makefiles  Creates “shared libraries” which are linked with the rest of the solver  Overcomes interpreter limitations e. Compiled UDF’s 19 16 Interpreted vs. o The macro begin_f_loop loops over all faces f. o thread and nv are arguments of the DEFINE_PROFILE macro. Example: Parabolic Inlet Velocity Profile 20 18 Example: Parabolic Inlet Velocity Profile • We would like to impose a parabolic inlet velocity to the 2D elbow shown.com) Pardad Petro Danesh (www.2 Step 3: Interpret or Compile the UDF Define  User-Defined  Functions  Define  User-Defined  Functions  Interpreted… Compiled… • Add the UDF source code to the Source • Add the UDF source code to the Source File Name list.1 Step 1: Prepare the Source Code • The DEFINE_PROFILE macro allows the function inlet_x_velocity to be defined. display in the FLUENT console. • You can also unload a library if needed. respectively. pointed by thread. • Click Build to create UDF library. • The x velocity is to be specified as   y 2  u= ( y ) 20 1 −      0. which are used to identify the zone and variable being defined. 18. o All UDFs begin with a DEFINE_ macro. • The F_CENTROID macro assigns cell position vector to x[].petrodanesh. Define  User-Defined  Functions  Manage… Saeed Sadeghi ([email protected]   y =0 18. files list. • The assembly language code will • Click Load to load the library.ir) . • Click Interpret. • The F_PROFILE macro applies the velocity component to face f. o inlet_x_velocity will be identifiable in solver GUI. Notice the imposed parabolic profile. o This setting controls how often (either iterations or time steps if unsteady) the UDF profile is updated.ir) . Example: Parabolic Inlet Velocity Profile 21 18. 18. Saeed Sadeghi (msaeedsadeghi@gmail. • Switch from Constant to the UDF function in the X_Velocity drop-down list.5 Numerical Solution of the Example • The figure at the right shows the velocity field through the 2D elbow. • Run the calculation as usual. • The bottom figure shows the velocity vectors at the inlet.3 Step 4: Activate the UDF • Open the boundary condition panel for the surface to which you would like to apply the UDF. 18.4 Steps 5 and 6: Run the Calculations • You can change the UDF Profile Update Interval in the Iterate panel (default value is 1).com) Pardad Petro Danesh (www.petrodanesh. 1 Using Fluent Built-in Porous Zone  File  Read  Case Read a mesh file  Define  Boundary Conditions  Select fluid zone then Click Set to enter the fluid zone parameters. The problem solved here involves gas flow through a channel using FLUENT in two different ways to validate it.68e6 (1/m2) in both directions. In the first one we use porous zone parameters and in the second one we write a UDF includes momentum source terms for porous zone pressure drop.4 at the end of this Porous Zone Tab. set the Velocity inlet equal to 1 (m/s) on the inlet velocity magnitude normal to boundary.  To solve the case. 19. Saeed Sadeghi ([email protected]) . involve modeling the flow through porous media.petrodanesh. This tutorial illustrates how to set up and solve a problem involving gas flow through porous media. go to: Solve  Iterate… Number of Iterations = 1000  After convergence we can display results as follows. catalyst beds and packing. Example: Checking Effect of Porous Zone on Momentum Equation 22 19 Example: Checking Effect of Porous Zone on Momentum Equation Many industrial applications such as filters. Figure 19-1: Static pressure in the channel (Pascal). set the Viscous Resistance equal to 5.  Check the “Porous Zone” to enable porous zone  On Porous zone.  Change the Fluid Porosity from 1 to 0.com) Pardad Petro Danesh (www.  For inlet condition. t).t). mu = C_MU_L(c. return s2.dS..com) Pardad Petro Danesh (www.eqn) { real source. dS[eqn] = -(mu*i_permeability).h" #define por_gdl 0. mu.c. Example: Checking Effect of Porous Zone on Momentum Equation 23 19..ir) .t.68e6 // Inverse Permeability (1/m^2) #define urf 0.4 #define i_permeability 5. u = C_U(c. v = C_V(c. } Figure 19-2: Static pressure in the channel (Pascal). DEFINE_SOURCE(xmom_src. u.t).2 Using Momentum Source Terms #include "udf.c.dS. v. s2 = s2*(1-urf) + source*urf. s2=0.t).t. } DEFINE_SOURCE(ymom_src. Saeed Sadeghi ([email protected] // under relaxation factor for stability of momentum source term real s1=0. source = -(mu*v*i_permeability). dS[eqn] = -(mu*i_permeability).eqn) { real source. return s1. s1 = s1*(1-urf) + source*urf.petrodanesh. source = -(mu*u*i_permeability). mu. mu = C_MU_L(c. com) Pardad Petro Danesh (www. Note: The Display Options are enabled by default. Retain the default settings for the solver. (b) Click Scale to scale the mesh. Example: Modeling Fuel Cell 24 20 Example: Modeling Fuel Cell 20. This will ensure that the quality of the mesh has not been compromised. or smooth and swap). Scale the mesh  General  Scale… (a) Select mm (millimeter) from the Mesh Was Created In drop-down list in the Scaling group box. convert to polyhedral. 20.ir) . Therefore. Saeed Sadeghi (msaeedsadeghi@gmail. add zones. Read the mesh file File  Read  Mesh 2. merge. Check the mesh  General  Check ANSYS FLUENT will perform various checks on the mesh and report the progress in the ANSYS FLUENT console window.. once you read in the mesh. 20. scale. 3.1 Preparation Use FLUENT Launcher to start 2D version of ANSYS FLUENT. 4.3 General Settings  Define  Models  Solver 1. it will be displayed in the embedded graphics windows.2 Mesh 1. (c) Close the Scale Mesh dialog box.e. separate.petrodanesh. fuse.  General  Check Note: It is a good idea to check the mesh after you manipulate it (i. Check the mesh. Ensure that the minimum volume reported is a positive number. 5 Materials  Define  Materials… 1. 20. Example: Modeling Fuel Cell 25 20.4 Models  Define  Models  Species  Transport & Reaction… (a) Enable Species Transport (b) Click OK to Close the Species Model box. (c) FLUENT will notify that “Available material properties or method have changed. Click OK to close the dialog box. Please confirm the property values before continuing”. Revise the properties for the mixture materials.com) Pardad Petro Danesh (www.petrodanesh.  Define  Material  Mixture Saeed Sadeghi ([email protected]) . ir) .6 Boundary Conditions  Define  Operating Conditions Because the effect of gravity can be neglected. You can add or remove species from the mixture material as necessary using the Species dialog box. Retain the default selections from the Selected Species selection list. Saeed Sadeghi (msaeedsadeghi@gmail. Example: Modeling Fuel Cell 26 (a) Click the Edit… button to the right of the Mixture Species drop-down list to open Species dialog box.com) Pardad Petro Danesh (www. (b) Click Change/Create to accept the material property settings.petrodanesh. ii. Click OK to close the Species dialog box. (c) Close the Create/Edit Materials dialog box. Retain setting in Operating Conditions and Click OK to Close the dialog box. i. 20. (e) Click Ok to save data. by clicking on the Set button (b) Check Porous zone radio button to enable porous zone. Example: Modeling Fuel Cell 27  Define  Boundary Conditions (a) Set Boundary condition for gdl fluid zone. (d) Set the porosity of the porous zone. These parameters are inverse of permeability (1/m^2).petrodanesh. Fluent uses these values for calculating momentum source term due to the porous zone.ir) . Saeed Sadeghi (msaeedsadeghi@gmail. (c) Set value for Viscous Resistance in both directions.com) Pardad Petro Danesh (www. ir) .com) Pardad Petro Danesh (www.petrodanesh. (h) Set viscous resistance variables for both directions. here. Example: Modeling Fuel Cell 28 (f) Set Boundary condition for cl fluid zone. (i) Now you should set porosity for cl porous zone that is equal to 0.1. by clicking on the Set button (g) Check the porous zone button to enable the cl porous zone. Saeed Sadeghi (msaeedsadeghi@gmail. 20.03 (m/s). you will see the Velocity inlet dialog box.2 Pressure Outlet (a) Click on the outlet to set outlet conditions. species mass fraction.com) Pardad Petro Danesh (www. Fluent will automatically calculate the mass fraction of the last specie. that is entering the domain normal to the boundary face.6.ir) . (c) Click the Species Tab to set mass fraction of species. Example: Modeling Fuel Cell 29 20. (b) Set Velocity magnitude equal to 0. Saeed Sadeghi ([email protected]. temperature. that is equal to 1 minus sum of the mass fraction of the other species. which can be used to specify inlet conditions such as inlet velocity.1 Setting Velocity Inlet (a) By selecting inlet at Boundary Condition dialog box and Clicking on set button. etc.6. K this is known within Fluent #define zita_cat 2.02e-3 // Cathalyst layer thickness [m] #define L 71. (d) To prevent solution damage by reverse flows. #define alpha_cat 2.89e-5 /* mass diffusivity of water */ #define diff_n2 2.65e4 // C/kmol #define h_cl 0. // kg/kmol Saeed Sadeghi (msaeedsadeghi@gmail. #define phi_sol 0. #define C_ref_o2 1.ir) .e3 #define V_oc 1.1 #define por_gdl 0.com) Pardad Petro Danesh (www.88e-5 /* mass diffusivity of nitrogen */ #define i_h2o 0 #define i_o2 1 #define i_n2 2 #define mw_h2o 18. (e) For this.681e10 // (1/m^2) #define R UNIVERSAL_GAS_CONSTANT // 8.12e-3 // Channel Length [m] #define diff_o2 3. we have chosen inlet species mass fraction for the outlet condition. (c) Click set button to enter Pressure Outlet dialog box.7 Writing UDF #include "udf.68e6 //5. to specify pressure at the outlet of the fuel cell. #define F 9. 20.petrodanesh.207 #define j_ref_cat 20.3143 kJ/kmol. #define phi_mem 0.4 #define i_permeability 5.2348e-5 /* mass diffusivity of oxygen */ #define diff_h2o 3. (f) Leave the other parameters by default and click OK. // kg/kmol #define mw_o2 32. #define lambda_cat 1.h" #define por_cl 0. Example: Modeling Fuel Cell 30 (b) Select pressure outlet on the right side of the boundary conditions dialog box. we should specify outlet conditions near to real condition. c.t.por_cl. F).t)/(4.x/L).dS.0. return Reraction_Rate_cat. *(1. Reraction_Rate_cat.i_o2).c.0.*F) *por_cl.t. i0_over_C_ref=0. C_o2. } DEFINE_SOURCE(O2_src. // Option 2 from Fluent FC manual // Reraction_Rate_cat = (zita_cat*j_ref_cat)*pow(C_o2/C_ref_o2.t). i. Khakbaz-Kermani C_CENTROID(xyz. y=xyz[1].*F) *por_cl. source.ir) . C_o2 = C_YI(c.com) Pardad Petro Danesh (www.petrodanesh.dS. //eta_cat = phi_sol-phi_mem-V_oc. source = +mw_h2o*R_cat(c.t. Saeed Sadeghi (msaeedsadeghi@gmail. %f\n".8*1e4. i0_over_C_ref. T = C_T(c. } DEFINE_SOURCE(H2O_src. // this is local current density dS[eqn] = 0.current)= -4. // kg/kmol enum{ current }.R_cat(c.eqn) { real source. i=C_UDMI(c. x . //Butler-Volmer Ref.c. source = -mw_o2*R_cat(c. // Option 1 Reraction_Rate_cat = 100000. real R_cat(cell_t c.eqn) { real source. x=xyz[0]. T.y.lambda_cat)*(exp(- alpha_cat*F*eta_cat/(R*T))). %f.lambda_cat)*(exp(- alpha_cat*F*eta_cat/(R*T))). // Option 0 // Reraction_Rate_cat = 10000. Example: Modeling Fuel Cell 31 #define mw_n2 28. // Option 3 // Reraction_Rate_cat = (zita_cat*j_ref_cat)*pow(C_o2/C_ref_o2.t). return source.*F /mw_o2 *source *h_cl.t). xyz[ND_ND].mw_o2. Khakbaz-Kermani eta_cat = R*T / (alpha_cat*F) * log(i/C_o2/i0_over_C_ref).// (kg/kmol)()/(C/kmol) //Message("%f. Thread *t) { // this routine returns Reraction_Rate_cat as "R_cat" real eta_cat. //[A/m^2] Ref.t. C_UDMI(c.current). z. %f. //z=xyz[2].t)/(2.0 .t. %f. Saeed Sadeghi (msaeedsadeghi@gmail. Example: Modeling Fuel Cell 32 dS[eqn] = 0. case 2: diff = diff_n2*por_cl*sqrt(por_cl).0.ir) . t. break. } 20. i) { real diff.c. } return diff. } DEFINE_DIFFUSIVITY(mix_diff.petrodanesh.eqn) { real source. return source. switch (i) { case 0: diff = diff_h2o*por_cl*sqrt(por_cl). case 1: diff = diff_o2*por_cl*sqrt(por_cl).com) Pardad Petro Danesh (www.*F) )*R_cat(c. c. break. return source. break.7.0. default: diff = 0. source = ( -mw_o2/(4.*F) + mw_h2o/(2.dS.1 Compiling the UDF  Define  User-Defined  Functions  Compiled  Add the UDF source files and headers if needed. } DEFINE_SOURCE(MASS_src.t.t) *por_cl. dS[eqn] = 0.0. Example: Modeling Fuel Cell 33  Build the UDF and then click on Load to load the Library that is named libudf. H2O_src.  By loading the library.  Now the fluent creates library libudf. object libudf. MASS_src.petrodanesh.  Note that the UDF source files should be in the directory that contains your case and data files.lib. …”.ir) .com) Pardad Petro Danesh (www. fluent command window show all defined functions. Here it shows “O2_src.exp and other required files. Saeed Sadeghi (msaeedsadeghi@gmail. Click OK to build the library.  You can load the library if fluent reveal no error and the message “Done” have seen at the end of the commend window.  Go to: Define  User-Defined  Memory… then set the number of UDM-s. click Edit in front of Mass equation.ir) .  Now you should hook functions to its specified equation. Saeed Sadeghi (msaeedsadeghi@gmail. Else an error will appear that an libudf is in use. such as H2O.  On the Source Terms Tab.  On the cl fluid zone. check Source Terms.  We have used a UDM in the UDF. so we should specify a UDM for it. be sure to unload it in the Manage dialog box. … .com) Pardad Petro Danesh (www.  Repeat this procedure for the other equations.  Then add a source and select MASS_src and click ok to add the source term on solution.petrodanesh. O2. Example: Modeling Fuel Cell 34  If you have build and load a udf before. Example: Modeling Fuel Cell 35  Fluent enables the energy equation by enabling Species Transport equation. Solve  Monitors  Residual. Solve  Initialize  Solution Initialize. To prevent solving this equation go to Solve  Solution Controls and click on Energy in Equations box.petrodanesh. we don’t need the energy equation. uncheck print.com) Pardad Petro Danesh (www.  So. In this example. And to show residual on the residual window.ir) . Compute from inlet and click on Init to specify its condition to all domains.  To prevent printing on command window. check the plot box.  To have a good initial guess for better and time saving convergence. Saeed Sadeghi (msaeedsadeghi@gmail. we can specify the conditions of inlet to the all domain.  You can change Residual criteria and Residual window settings. Figure 20-1: Scaled Residuals Figure 20-2: Mass fraction of H2O on top and bottom walls Saeed Sadeghi ([email protected]) . Solve  Iterate. specify the number iterations and start iteration by clicking on iterate.com) Pardad Petro Danesh (www. Example: Modeling Fuel Cell 36  On iterate window.petrodanesh. Domain *d = Get_Domain(1).inlet_ID). sum). /////////////////////////// sum =0. int cl_ID = 2.t_inlet).t_inlet) *F_YI(f.*F) *por_cl*C_VOLUME(c. sum).cl_ID). cell_t c. Message("inlet = %f *e-6(kg/s)\n".t_inlet) { F_AREA(A.e6.. /////////////////////////// sum = 0.outlet_ID). } end_f_loop(f. int outlet_ID = 6. Message("outlet= %f *e-6(kg/s)\n".t_outlet).e6. Thread *t_inlet = Lookup_Thread (d.ir) . begin_f_loop(f.f.i_o2)*1. sum).t_cl)/(4. } end_c_loop(f. we should calculate the rate of oxygen mass enters the domain at the inlet (kg/s). Message("porous= %f *e-6(kg/s)\n". int inlet_ID = 7.8 Checking Oxygen Mass Balance To check Oxygen mass balance. Thread *t_cl = Lookup_Thread (d.t_inlet). the rate of oxygen mass consumes at the catalyst layer (kg/s).t_outlet) *F_YI(f.t_inlet. Example: Modeling Fuel Cell 37 20. begin_c_loop(c..t_cl)*1.com) Pardad Petro Danesh (www. /////////////////////////// sum =0. face_t f. sum += F_FLUX(f. } Saeed Sadeghi ([email protected]_outlet). } end_f_loop(f. So.t_cl) { sum += -mw_o2*R_cat(c. sum += F_FLUX(f.t_cl).t_outlet) { F_AREA(A. and the rate of oxygen mass exits the domain from outlet.f.e6. we should add a macro to the end of previous UDF as follows: DEFINE_ON_DEMAND(data) { real A[ND_ND].petrodanesh.. begin_f_loop(f.i_o2)*1. real sum. Thread *t_outlet = Lookup_Thread (d.t_outlet. Result is written below: inlet = -5. • F_YI(f.petrodanesh.t_inlet). For example at the beginning. • The array A is defined in ND_ND dimension to reserve area.t_inlet). returns the mass flow rate the face f of the thread t_inlet. • sum is defined to summarize value of cells in a group cells (Threads) • inlet_ID. loops throw all faces of the Thread t_inlet that its ID is 7.153047 *e-6(kg/s) porous= -0. is used to write mass flow rate of Oxygen on the fluent command window. outlet_ID and cl_ID are the number of zone that can be found in Boundary Conditions dialog box. it can be executed. • Get_Domain(1) specifies the domain to the 1 to d which is defined as Domain pointer • Lookup_Thread (d. returns mass fraction of the specie that its ID is i_o2 of the face f of the thread t_inlet. • F_FLUX(f. returns area of the face f of thread t_inlet.ir) . Example: Modeling Fuel Cell 38 • The macro “DEFINE_ON_DEMAN” executes when we want.com) Pardad Petro Danesh (www. • ND_ND is a Fluent macro that is equal to 2 in 2-dimensioanl and 3 in 3-dimensional case.ID) is defined to find the Thread which its ID number is equal to inlet_D. • With face_t and cell_t we can define variables that reserves face and cell data.721122 *e-6(kg/s) outlet= 5.i_o2). outlet_ID and cl_ID.f. • F_AREA(A.589597 *e-6(kg/s) Saeed Sadeghi (msaeedsadeghi@gmail. intermediate and at the end of solution.t_inlet). • Message(“…\n”. • begin_f_loop(f.t_inlet.…). If you are doing something pretty involved and it fails inexplicably. Failure to do so will likely lead to complaints about things being "not recognized as an internal or external command. If you have long term experience using Windows you should probably know the risks. keep in mind that not everything that is supported for compiled UDF's is supported for interpreted UDF's. deselect other components) • Then.BAT” • Go to the FLUENT install add: “C:\Program Files\ANSYS Inc\v121\fluent\ntbin\win64\” • And double click “setenv. 21. During the installation process.inc\ntbin\ntx86\” • And double click “setenv.BAT” • Then go the FLUENT install address: “C:\fluent. deselect other components) • Then.2.1 My UDF won't interpret or compile .what is wrong? The answer depends upon what exactly has happened. Go to this address: “C:\Program Files\Microsoft Visual Studio\VC98\bin\” • Double click “VCVARS32. it’s better to install Visual Studio 2005 (Just install Visual C++. Keep in mind that your source code gets run through the C preprocessor (to change the Fluent macros into C code). On Windows machines. so unintended interactions are very possible. • If Fluent complains about not being able to find a compiler. try compiling to see if that makes a difference. • If you are interpreting.exe” 21. but keep in mind that even when nmake can be found there still may be DLL issues.exe” Saeed Sadeghi ([email protected] How to Set Environment Variables 21.1 On Windows 32 Bit • If you are using Windows 32 bit. it is possible to install the Visual C++ compiler without fully setting up the command line compiler (which Fluent needs to be able to find). It is theoretically possible to fix this issue by setting the appropriate environment variables.com) Pardad Petro Danesh (www. but the reinstallation path is always perilous. The easy path is probably reinstallation of Visual Studio (taking special care to make sure that the command line interface is set up properly). and if you don't you should consult an expert.2. Go to this address: “C:\Program Files (x86)\Microsoft Visual Studio 9.2 On Windows 64 Bit • If you are using Window 64 Bit. it’s better to install Visual Studio 2008 (Just install Visual C++. then check to make sure that the compiler is properly installed.ir) . Fluent Frequently Asked Questions 39 21 Fluent Frequently Asked Questions 21. you need to select the "register environment variables" option. This is true both for the UDF interface and the C language.0\VC\bin\” • Double click “vcvars32. • There is also the possibility of coding errors. operable program or batch file" or missing DLL's.petrodanesh.
Copyright © 2024 DOKUMEN.SITE Inc.