Fluent UDF函数(转载)
(2014-09-09 16:31:19)
标签:
教育 |
分类: fluent |
1. Data_Valid_P
You can check that the cell values of the variables that appear in
your function are accessible before you compute the function by
using the Data_Valid_P macro.
boolean Data_Valid_P()
Data_Valid_P is defined in the id.h header file, and is included in udf.h. The function returns 1 (true) if the data is valid, and 0 (false) if it is not.
Example
if(!Data_Valid_P())
For example, suppose you read a case file and, in the process, load a UDF. If that function performs a calculation using variables that have not yet been initialized, such as the velocity at interior cells, an error will occur. To avoid this kind of error, an if else condition can be added to your code. If ( if) the data are available, the function can be computed in the normal way. If not ( else), no (or some trivial) calculation can be performed instead. Once the flow field has been initialized, the function can be reinvoked so that the correct calculation can be performed.
2. FLUID_THREAD_P
You can use the FLUID_THREAD_P function to check whether a thread
is a fluid thread. The function returns 1 (true) if the thread you
specify is valid, and 0 (false) if it is not.
boolean FLUID_THREAD_P()
Example
FLUID_THREAD_P(t0)
3. NV_MAG
The utility NV_MAG computes the magnitude of a vector. This is
taken as the square root of the sum of the squares of the vector
components.
NV_MAG(x)
4. NV_MAG2
The utility NV_MAG2 computes the sum of squares of vector
components.
NV_MAG2(x)
5. F_PROFILE
F_PROFILE can be used to store a boundary condition in memory for a given face and thread, and is typically nested within a face loop. See mem.h for the complete macro definition for F_PROFILE.
F_PROFILE is typically used along with DEFINE_PROFILE; the index i that is an argument to DEFINE_PROFILE is the same variable in F_PROFILE.
Macro: F_PROFILE( f, t, i)
Argument types: face_t f
Function returns: void
The arguments of F_PROFILE are f, the index of the face face_t; t, a pointer to the face's thread t; and an integer i. These variables are passed by the FLUENT solver to your UDF.
i is an identifier for the variable that is being set at a particular boundary. For example, an inlet boundary may have a total pressure and a total temperature associated with it (both of which can be described by user-defined functions). One of the inlet boundary variables will be identified in FLUENT by the integer 0, and the other by the integer 1. The values of these integers are set by the solver when you define your boundary conditions using the Boundary Conditions panel in a FLUENT session.
Sample
begin_f_loop(f, t)