You are on page 1of 8

Giacomo Marani 07 / 02 / 2016

How compile or interpret UDF on Fluent.

Object : UDF
All about UDF:

First step, the difference between Interpreted or compiled UDF :

Which compilers work?

On Unix-like machines, GCC is the compiler of choice. On Windows machines,

Microsoft Visual C++ is the compiler of choice (GCC may also work on Windows-
if anyone has firsthand knowledge of this, please share). The free Express Edition
of the Microsoft compiler also works. On remote language it’s usually use UNIX.
For more explication see : .

Now this is very important : User-defined functions (UDFs)Interpreted UDFs

cannot be used while running in parallel with an Infiniband interconnect. The
compiled UDF approach should be used in this case.

If fluent is running on Windows (x64), the compiled udf approach need some
process first. Lots of users find it is hard at the beginning of UDF use. Most of the
time, there is an error:

'nmake' is not recognized as an internal or external command, operable program or

batch file. 'nmake' is not recognized as an internal or external command, operable
program or batch file.

This is just the problem of binding between FLUENT and VC++. To know more
about this problem, firstly please refer to following post :

gives a long solution about how to solve this problem, but my experience following
this did not give me a solution.

Pagina 1
Giacomo Marani 07 / 02 / 2016

So I have to find my own way. Followings are my solution:

1. No matter Microsoft Visual Studio professional or express version, they both

work fine with FLUENT. As long as it has C++, you could bind it with
FLUENT and use it to compile UDF.

2. After installing Microsoft Visual Studio professional or express version, you

could check the Environmental variables from 'my computer ---> properties ----
> advanced tab', on the bottom part u have environment variables and system
variables. Generally on installing, the environmental variables are added for
MSVC, check to make sure that this is added. Generally, you need not do
anything about this.

3. The most important thing is to try to open FLUENT in Visual Studio Command
Prompt, which is in 'Start-All programs-Microsoft Visual Studio-Microsoft
Visual Studio Tools-Visual Studio Command Prompt'. Then type FLUENT in
the command window, FLUENT is starting. Now you can close the Visual
Studio Command Prompt, it does not impact the compiling of UDF.

That is it. Very simple, remember to open FLUENT in the Visual Studio Command
Prompt, you will be always OK.

Pagina 2
Giacomo Marani 07 / 02 / 2016


More About :

Most important, as I already said if you had to use a remote connection, on

launching fluent set parallel:

A) Multiprocessor Machine :

Use FLUENT Launcher to start the 2/3D parallel version of ANSYS FLUENT on a
Windows, Linux, or UNIX machine using 2/4 processes.

1. Select Parallel (Local Machine) under Processing Options.

2. Set Number of Processes to 4.

To show details of the parallel settings, click Show More >>, then go to the
Parallel Settings tab. Note that your Run Types will be Shared Memory on
Local Machine.

3. Click OK.

To start ANSYS FLUENT on a Linux or UNIX machine, type at the command


fluent 2d -t4

If you type fluent at the command prompt, then FLUENT Launcher will appear.

B) Network of Computers :

Check the network connectivity by performing the following steps:

1. In FLUENT Launcher, restore the default settings by clicking the Default


2. Specify 2/3D for Dimension.

3. Select Parallel (Local Machine) under Processing Options.

Pagina 3
Giacomo Marani 07 / 02 / 2016

4. Set the Number of Processes to 2/4.

5. Click the Show More >> button and select the Parallel Settings tab.

• Retain the selection of default in the Interconnects and MPI Types drop-
down lists.

• Select Distributed Memory on a Cluster.

• Make sure that File Containing Machine Names is selected to specify the

• Type the name and location of the hosts text file in the text box below File
Containing Machine Names, or browse and select it using the Browsing
Machine File dialog box. 

Alternatively, you can select Machine Names and type the names of the ma-
chines in the text box.

6. Click OK.

You can also start parallel ANSYS FLUENT by typing the following at the
command prompt:

fluent 3d -t2 -cnf=fluent.hosts

where -cnf indicates the location of the hosts text file. The hosts file is a text file
that contains a list of the computers on which you want to run the parallel job. If the
hosts file is not located in the directory where you are typing the startup command,
you will need to supply the full pathname to the file. For example, the fluent.hosts
file may look like the following:


Pagina 4
Giacomo Marani 07 / 02 / 2016


Note that some lines have a few words in round brackets at the end. These are just
description comments and therefore should NOT be included in your journal file.
To change a line in our journal file to be a comment simply put a semi-colon ; in
front and it will be ignored by fluent.

Steady Example (interpreted udf)

First its recommended to open your cas file in fluent-gui and click Define --> User-
Defined --> Functions --> Interpreted --> Unset File Name then re-save the cas file
before using it in the following journal file templates when submitting jobs to the
queue. Please do not include the contents between the round brackets shown in
either of the following two journal files, as these are just descriptive comments.

- Initialize Domain:
This journal file (sample1.jou) reads cas and dat files with a common prefix ie)
CasDatFileName.cas, CasDatFileName.dat then initializes the computational
domain and runs 1000 iterations:

Note : On the first line “cpp” is for windows, when you run on UNIX or Linux this
must be changed in “gcc”

Pagina 5
Giacomo Marani 07 / 02 / 2016

- Restart Domain:
In this journal file (sample2.jou) the cas and dat files have a different prefix. It
restarts calculations using CasDatFileName.cas and itrCasDatFileName-1000.dat
output from sample1.jou therefore the command to initialize the domain is
commented out using a semicolon as follows:

Unsteady Example (compiled udf):

Please note that you cannot simply upload your libudf directory to sharcnet from
your local workstation, it will not work. You must build it on a sharcnet centos6
machine such as vdi-centos6 as described in the How to Compile a UDF section
First its recommended to open your cas file in fluent-gui and click:

Define --> User-Defined --> Functions --> Interpreted --> (unset Source File Name)
Define --> User-Defined --> Functions --> Compiled --> (add/build or load libudf)
Define --> User-Defined --> Functions --> Manage --> (unload all UDF bibraries)
Define --> User-defined --> Functions --> Manage --> Load (type libudf then click

Pagina 6
Giacomo Marani 07 / 02 / 2016

1) In the following stanza, (bracketed) statements should not be included in the

journal file.
2) Lines with leading semi-colons are optional comment lines and not processed
with fluent.


number physical time steps specified = 1000

maximum number iterations per time step = 40
time step in secs over rides cas file = 0.001
frequency to save dat file solution = 100

Boundary Condition Check

Assuming boundary conditions were defined using interpreted UDF(s) during the
case file construction/setup then its worthwhile to verify such conditions are still
defined before running large jobs. This can be done by first interpreting the UDF
then second reading in the corresponding cas file using "fluent-gui" and then
inspect Define --> Boundary Condition --> Click inlet --> Click Set --> Velocity
Magnitide and these should reference the udf profile velocity profiles defined such
as ie) udf YourProfileName. If this procedure is done with compiled UDF one will
find the boundary conditions are not defined unless either interpreted first or
hooked in, as shown in the Compiled UDF example journal file above.

Pagina 7
Giacomo Marani 07 / 02 / 2016

For all text command :

ANSYS Fluent Text Command List

ANSYS, Inc. Release 15.0

Southpointe November 2013
275 Technology Drive
Canonsburg, PA 15317 ANSYS, Inc. is certified to ISO
(T) 724-746-3304
(F) 724-514-9494

Pagina 8