Adding UDF to fluent.

Fluent have lot of inbuilt functionalities that makes it user friendly and also make it dynamic for usage. Many of us are provided with situations wer we tend to write our own stuffs for computations, data interpretation, plotting and many other operations that control the problem. For such situation we can implement our own UDF (User defined functions) Here is a short gist of how to do it.

User-Defined Function (UDF) Related

How do I learn UDF programming?

There are not to many tutorials out there on this, probably due to the wide variety of things you can do with the UDF interface. The documentation the Fluent provides is pretty good once you know what you are trying to do (chapter 8 of the UDF manual has examples). UDF programming is easier if you have C programming experience, so it is advisable to learn a little C programming, then do some of the simple cases that Fluent provides, then tackle the problem you really want to solve.

How do I create/build/load a UDF?

The simplest way to add a UDF into Fluent is to write your UDF in the C programming language and then use Define -> User-Defined -> Functions to either interpret or compile your UDF. It can then be loaded. Fluent provides good documentation of the UDF interface with numerous examples, so read that before trying too much.

Do I have to use C?

Yes and no. To hook your UDF into Fluent, you’ll probably have to use one of the DEFINE_* macros that Fluent provides, and this is most easily done using C. However, you can write routines that are used in the routines that are defined with the DEFINE_* macros in other languages and then link them together. This requires some knowledge of mixed language programming, Makefiles, the text user interface (TUI), and is not necessarily very portable. An example using Fortran is given in Section 5.4.1 of the Fluent UDF Manual (version 6.3).

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.

My UDF won’t interpret or compile – what is wrong?

The answer depends upon what exactly has happened.

  • If Fluent complains about not being able to find a compiler, then check to make sure that the compiler is properly installed. On Windows machines, 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). During the installation process, you need to select the “register environment variables” option. Failure to do so will likely lead to complaints about things being “not recognized as an internal or external command, operable program or batch file” or missing DLL’s. It is theoretically possible to fix this issue by setting the appropriate environment variables, but keep in mind that even when nmake can be found there still may be DLL issues. The easy path is probably reinstallation of Visual Studio (taking special care to make sure that the command line interface is set up properly), but the reinstallation path is always perilous. If you have long-term experience using Windows you should probably know the risks, and if you don’t you should consult an expert.
  • If you are interpreting, keep in mind that not everything that is supported for compiled UDF’s is supported for interpreted UDF’s. This is true both for the UDF interface and the C language. If you are doing something pretty involved and it fails inexplicably, try compiling to see if that makes a difference.
  • There is also the possibility of coding errors. Keep in mind that your source code gets run through the C preprocessor (to change the Fluent macros into C code), so unintended interactions are very possible.

Why do I get the message “‘nmake’ is not recognized as an internal or external command, operable program or batch file”?

This is a Windows/Visual Studio issue. In order to compile your UDF, Fluent needs to know where the nmake program is located, and it currently can’t find it. If you open up a command window and enter “nmake”, you should probably get the same message. See the previous question/answer.

My UDF interprets/compiles but fails to execute – what is wrong?

This commonly occurs due to a faulty operation of some kind. For example, user-defined memory (UDM) is not allocated until initialization, so attempting to access a UDM variable before initialization can lead to a segmentation fault. Try to isolate the cause, and then look for places where your expectation of what is available may not match reality. Finally, keep in mind that if you do something really bad, you may need to restart Fluent before even a fixed UDF will work.

For more querries visit



  1. 1
    Sara Says:

    My name is Sara and I am trying to creat a UDF for Fluent that will allow me to add a source term within a specific time range. I am a novice when it comes to programming and I am nor sure if what I wrote is correct. I wrote the UDF but it won’t compile in Fluent and I get the following error message: line 8: C_time: undeclared variable. The UDF I have written is as follows:

    /* Adding BTAR Source Term*/

    #include “udf.h”

    DEFINE_SOURCE(cell_x_source, cell, thread, eqn)
    real source;
    real time = C_time(cell,thread);
    if (time >= 0.1)
    source = 10.0;
    else if (time <= 0.2)
    source = 10.0;
    source = 0.0;
    return source;

    Can some one please help me. Thank you

  2. 4
    Meenu Says:

    Hello, I am solving a unsteady state problem in Fluent.
    Question: I want to export the temperature data at all the nodes in the geometry so that I can further analyze it and then again plot contours of the analyzed quantity.

    I can export the nodal data at the end of the process (say t = 100 s)
    by using the file–>export

    But I want to write the temperature data at each time step for all the nodes for further analysis.

    x y time Temperature

    where x, y are the position of the nodes.

    Please help.


    • 5
      Sriram Ragav Says:

      I think you can do transient state analysis in fluent that gives the values for unsteady state solutions… But have have to dig thru the menus to find out that. I am not exactly aware where you can find it.

      Another would be a brut force method where to iterate it not till the steady state is achieved but only till the time you require and then play with the values.

      But I believe if you google transient state analysis, your problem should be solved.

  3. 6
    Hasan Says:

    I am trying to include a UDF in fluent by first compiling and then loading.
    compilation of UDF is quite ok by when I try to load it shows the error message:

    Opening library “libudf”…
    Error: open_udf_library: The system cannot find the file specified.

    I am in this problem for last couple of weeks but failed to get a solution…
    I am using VC++ 2008 edition…
    May be there are some issues related to environment variables-but I have no idea …
    Solution of this problem will be highly appreciated…

    • 7
      Sriram Ragav Says:

      Sorry dude. I have no Idea. But try a different compiler base or compiler directly from fluent. Dont waste time on these things. Your overall problem solution will be affected.

    • 8
      Rajib Says:

      I hope you already solve it. However for anyone who has a problem with this need to share the folder which contains the case and file (in case when fluent running in parallel). And fluent should be run from the visual studio command prompt windows. Thanks.

  4. 9
    Mario Says:

    Hello, im trying to find the source code for INTER HEATING custom law, because i want to modify it to model heat loss at constant temperature, any goods ideas?

    Please help.


    • 10
      Sriram Ragav Says:

      Dude, can you tell me what is INTER HEATING CUSTOM LAW? Never heard of that before. What kind of heat transfer is happening in ur model? This would help to give a better solution. There are several design optimization algorithms available. But the kind of heat transfer is very essential. US Patent 7390078 – Reduction of heat loss in micro-fluid ejection devices. the link is Give me more details and I can help you better.

  5. 11
    Petrut Says:

    I’ve got an error compiling when to load my library via TUI, such as

    use user-defined real gas? [no] y
    User-Defined Realgas Library Name [“”] L1

    Opening user-defined realgas library “L1″…
    Library “L1\ntx86\2d\libudf.dll” opened

    Error: open_udrg_library: couldn’t get real_gas_fcns
    The specified procedure could not be found.

    Error Object: ()

    Do you have any idea about how to eliminate it?

    Thank a lot!

  6. 12
    Floyd Says:

    Hi, I am a novice of UDF, I need to define a time dependent heat source term in a solid zone. Is it possible to do this? If it does, what should I do?

  7. 13
    louiza Says:


    I have a problem runing calcul in Fluent 12.1.2. The error message
    Stack backtrace generated for process id 26546 on signal 1 :
    Check the file fluenterror.log for details.
    Please include this information with any bug report you file on this issue!

    Error: fluent.12.1.2 received a fatal signal (SEGMENTATION VIOLATION).
    Error Object: #f

    in this my UDF i add two other equations of energy via UDS( with convectio, diffusion and source terms).
    Does anybody of you understand the error message and can tell me what it means.

    Thanx in advance!

  8. 14
    raja Says:

    can any one write udf for laser heat source for welding.

  9. 15
    Jozsef Szabo Says:


    I have a file with the x,y,z cordinates of the center of each cell, The file also contains the energy value W/m3 of each cell.

    Does anybody know how to write an udf file to add this to my analysis in fluent or somehow else add this??

  10. 16
    subhasish Says:

    Regarding fluent application in chemical engineering problems,
    post your comment in the above website.

    Successfully managed to compile UDF in MS visual studio. Ask me if you face difficulty.

    • 17
      cg Says:

      Instructions would be helpful because I don’t know whether I did it right. What I did:
      1. Change the file \fluent\ntbin\win64\udf.bat
      => added lines to make udf.bat search in the correct directory where my MS Visual Studio 9.0 is located

      2. Start Fluent
      => Tab “UDF Compiler”: |v| Setup Compilation Environment for UDF (the path under “Win 64” was correct) -> OK

      3. Define -> User Defined > Functions > Compiled …
      => Source Files -> .c -> Add; Library Name: libudf -> Build
      -> Load (=> no error)

      Now I have a local libudf directory in my working directory. It works but I think it should be possible to solve the problem globally (not for every simulation separately).

  11. 18
    sankalpa Says:

    Hi Sriram,

    I am trying to devlope udf for degassing boundry condition. I wounder if you have any example udf for degassing bc case.

    Sankalpa (

RSS Feed for this entry

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: