Fluent udf-am内部培训资料

上传人:jiups****uk12 文档编号:40500349 上传时间:2018-05-26 格式:PDF 页数:130 大小:1.23MB
返回 下载 相关 举报
Fluent udf-am内部培训资料_第1页
第1页 / 共130页
Fluent udf-am内部培训资料_第2页
第2页 / 共130页
Fluent udf-am内部培训资料_第3页
第3页 / 共130页
Fluent udf-am内部培训资料_第4页
第4页 / 共130页
Fluent udf-am内部培训资料_第5页
第5页 / 共130页
点击查看更多>>
资源描述

《Fluent udf-am内部培训资料》由会员分享,可在线阅读,更多相关《Fluent udf-am内部培训资料(130页珍藏版)》请在金锄头文库上搜索。

1、Making “User Defined Functions” Work for YouAnirudh Mukhopadhyay2002 Fluent Users Group Meeting2UGM 2002Agenda?General Introduction to User Defined Functions?Introduction to C Programming?Fluent Data Structure and Macro-s?Interpreted / Compiled UDF?UDF Hooks - DEFINE macro-s?User Defined Scalars and

2、 Memories?UDF for Discrete Phase and Multiphase Flows?UDF for Parallel FLUENT?Miscellaneous Functions / Macros3UGM 2002Why Build UDFs?Standard interface can not be programmed to anticipate all needs?Customization of boundary conditions, source terms, reaction rates (volume and surface), properties?S

3、olution initialization?Adjust functions (once per iteration)?Solve for user defined scalars?Modify model specific parameters?Many more.?Limitations?Not all solution variables or solver models can be accessed by UDFs?Example: Cannot change specific heat (would require additional solver capabilities)4

4、UGM 2002User Access to Fluent Solver?Fluent is so designed that the user can access the solver at some strategic instances during the solution processFlow Diagram of FLUENT SolversSegregated Solver Coupled SolverInitializeBegin LoopExit LoopRepeatCheckConvergenceUpdate PropertiesSolve EddyDissipatio

5、nSolve TurbulenceKinetic EnergySolve SpeciesSolve EnergySolve Mass Continuity;Update VelocitySolve U-MomentumSolve V-MomentumSolve W-MomentumSolve MassMomentum /* Global scope: variables defined outside the function body for use by all functions which follow the definition*/ int my-function(int x)/*

6、 Function declaration (integer type)*/ /* C functions are enclosed by curly braces (.)*/ /* All C statements must end with a semicolon (;) */int y,z; /* Local scope: Declare data type for variables y, z variables defined within the function body are local to the function*/y = 11; /* Set y = 11*/z =

7、a*(x+y)*PI; /* Compute z*/printf(“z = %d”,z);/* Print output to screen*/return z; /* Return integer value*/ /* Right curly brace closes body of function*/?If a function is defined with a specific type, it should return a value of the same type (using the return statement)8UGM 2002Compilers?C compile

8、rs include a library of standard math, I/O, and utility functions which can be used in your C code?Common I/O functions?scanf (.)- formatted read (like FORTRAN READ)?printf(.)- formatted print (like FORTRAN WRITE)?Common math functions?sin (x)- sine function?cos (x)- cosine function?exp (x)- exponen

9、tial function?sqrt(x)- square root function?For the UDF compiler, all of the standard functions are defined in the file udf.h?NOTE:NOTE:you do not need a copy ofyou do not need a copy of udf udf.h when you compile your UDF;.h when you compile your UDF; the solver gets this from the Fluent.Inc/fluent

10、6.x/the solver gets this from the Fluent.Inc/fluent6.x/srcsrc/ directory/ directory9UGM 2002Comparison with FORTRAN?C functions are similar to FORTRAN function subroutines/*A simple C function*/ C An equivalent FORTRAN functionint myfunction(int x) INTEGER FUNCTION MYFUNCTION(X)int y,z; INTEGER X,Y,

11、Zy = 11; Y = 11z = x+y; Z = X+Yprintf(“z = %d”,z); WRITE (*,100) Zreturn z; MYFUNCTION = Z100 FORMAT(“Z = “,I5) END?Arithmetic operators=assignment+addition-subtraction*multiplication/division%modulo +increment -decrement?Logical operators greater than =greater than or equal to =equal to !=not equal

12、 to10UGM 2002C Data Types?The UDF interpreter supports standard C data types?int,long -integer data types?float,double, real -floating point (real) data types?char -character data type?Functions which do not return values are given the type voidvoid myfunction(int x) . /*No return needed*/?C also al

13、lows you to create “user-defined” types using typedeftypedef struct list int a; float b; int c;typedef struct list mylist; /* mylist is of type structure list*/mylist x,y,z; /* x,y,z are “struct list” type */11UGM 2002Pointers and Arrays?Pointers can also point to the beginning of an array?Thus poin

14、ters are strongly connected to arrays in C?Arrays of variables can be defined using the notation namesize where name is the variable name and size is an integer which defines the number of elements in the array?Some examplesint a10; float radii5; a0 = 1; radii4 = 3.14159265;content of address pointe

15、d to by ip = 1?A pointer is the variable that contains the address of another variable?Pointers are defined using the * notation int *ip; /* a pointer to an integer variable */?We can make a pointer point to the address of predefined variable as follows: int a=1; int *ip; ip = /* Notes about C array

16、s:Notes about C arrays: The index of C arrays start at 0The index of C arrays start at 012UGM 2002/* C code */if (q != 1) a = 0; b = 1;if (x ”?where your architecture may be ultra, hp700 etc. in the libudf directory and you will see # building library in ultra/2d # building library in ultra/3d?Run the solver and cli

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号