0% found this document useful (0 votes)
110 views2 pages

Brief Tutorial On Using User-Defined Functions (Udfs) On The Cares Cluster

This document provides instructions for using User-Defined Functions (UDFs) on the CARES computing cluster. It recommends testing UDFs first using interpretation on a desktop before compiling for use on the cluster. The key steps are: 1) write the UDF, 2) test on a desktop if possible, 3) save files to a cluster directory, 4) compile the UDF by adding commands to the .flin file, and 5) hook the UDF by specifying its use in boundary conditions also using .flin file commands. An example UDF and .flin code is provided to demonstrate varying permeability in a porous zone using a UDF.

Uploaded by

Hasrizam86
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views2 pages

Brief Tutorial On Using User-Defined Functions (Udfs) On The Cares Cluster

This document provides instructions for using User-Defined Functions (UDFs) on the CARES computing cluster. It recommends testing UDFs first using interpretation on a desktop before compiling for use on the cluster. The key steps are: 1) write the UDF, 2) test on a desktop if possible, 3) save files to a cluster directory, 4) compile the UDF by adding commands to the .flin file, and 5) hook the UDF by specifying its use in boundary conditions also using .flin file commands. An example UDF and .flin code is provided to demonstrate varying permeability in a porous zone using a UDF.

Uploaded by

Hasrizam86
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Brief tutorial on using User-Defined Functions (UDFs) on the

CARES cluster

0 This is not intended to be a primer on how to write a UDF. There is a plethora of
good information out there on how to write UDFs. Look at the Users Center at
www.fluent.com for some starting points. Specifically, FLUENT has a UDF manual with
many example scripts.

1 - OK, so youve got your UDF. If possible, I would recommend running it in
interpreted mode on your desktop machine first. To do this (on a Windows machine) you
need to have Visual C++installed, or at least have the function nmake available. If your
UDF can be interpreted, it can be run on the cluster. The only difference will be that you
need to compile the function, rather than interpret it. Its a great deal easier to debug a
UDF in interpreted mode than in compiled mode on the cluster.

NOTE, compiled UDFs tend to run faster as well. There are a few more steps, but it isnt
overly difficult.

Compiling a UDF on the cluster.
- Place your *.bash, *.flin, *.cas and *.c file in a directory of your cluster. The *.c
file is your UDF.
------------------------------------------------------------------------------------------------------------
Heres a short, example UDF. Note that all UDFs require the #include udf.h line in
order to work properly.
/ * Vi scous Resi st ance Pr of i l e UDF i n a Por ous Zone */
#i ncl ude " udf . h"
DEFI NE_PROFI LE( end_l ower , t , i )
{
r eal x[ ND_ND] ;
r eal a;
cel l _t c;

begi n_c_l oop( c, t )
{
i f ( ( x[ 2] > 0) && ( x[ 2] < 0. 001) )
a = 2. 7385e+10;
el se
a = 2. 7385e+12;
F_PROFI LE( c, t , i ) = a;
}
end_c_l oop( c, t )
}

- To compile this udf you must add the following line to your *.flin file.

/ def i ne/ user - def i ned/ compi l ed- f unct i ons compi l e " l i budf "
yes " EndCap- Lower 1. c" " " " "

This invokes the compile command for user-defined functions, specifies that youll create
a directory called libudf to hold the associated files and tells FLUENT that the name of
the source code is EndCap-Lower1.c.

If this UDF functions properly, a new directory called libudf will be created within the
directory with your other FLUENT files. These files are then accessed by FLUENT to
perform whatever function you wish to perform with the UDF. For the above example
UDF, the permeability of a porous region is varied. A lower resistance is specified in the
1
st
1mm of a zone, in the z direction.

In order for the UDF to work properly it must be hooked to FLUENT. For each type of
UDF there are different places that the UDF must be hooked, depending on what the
function will actually do. For the above example a fluid zone is being modified to include
the porous media variations just discussed. Thus, we hook the UDF in the boundary
conditions of the loaded *.cas file. The command for this is as follows.

/ def i ne/ boundar y- condi t i ons/ f l ui d por ous no no no yes 0 0 0
0 0 1 no yes no no 1 no 0 no 0 no 0 no 1 no 0 yes yes yes
" udf " " end_l ower : : l i budf " yes yes " udf " " end_l ower : : l i budf "
yes yes " udf " " end_l ower : : l i budf " no no 0 no 0 no 0 0 0 no
no 0 no 0 0 0 no 0. 16

(Note, as written in my *.flin file, this all is on one line. There are different ways to write
it, but this is the method I use).

The important commands in the above line are the
yes yes " udf " " end_l ower : : l i budf "
sections, which tell FLUENT,
- yes, I want to use a profile in the x (y and z) directions for my viscous resistance
(ie permeability)
- yes, I want to specify a udf to use as the profile
- the udf can be found in the udf names already compiled
- the udf name is end_lower in the libudf directory

The other inputs in the above line specify other properties in the porous medium, not
really important for this udf discussion.

And once again, there is a great deal of information out there about specific UDFs that
may be useful to your problem. Find those.

In summary
1 Write your udf.
2 Test/debug your udf on a desktop machine (if possible), using the interpreted method.
3 Save your *.cas, and other files to a separate directory on your CARES account.
4 Compile your udf using text commands in you *flin file
5 Hook your udf using the appropriate text commands in your *flin file.

Good Luck and Happy Computing
- Dustin Crandall 12/2007

You might also like