[ANSYS, Inc. Logo] return to home search
next up previous contents index

5.3.2 Build the UDF Library

After you have set up the folder structure and put the files in the proper places, you can compile and build the shared library using the TUI.



Windows Systems


1.   Using a text editor, edit every user_nt.udf file in each version folder to set the following parameters: SOURCES, VERSION, and PARALLEL_NODE.


   
SOURCES = the user-defined source file(s) to be compiled.
  Use the prefix $(SRC) before each filename. For example,
  $(SRC)udfexample.c for one file, and
  $(SRC)udfexample1.c $(SRC)udfexample2.c for two files.
   
VERSION = the version of the solver you are running which will be the
  name of the build folder where user_nt.udf is located.
  ( 2d, 3d, 2ddp, 3ddp, 2d_host, 2d_node, 3d_host, 3d_node,
  2ddp_host, 2ddp_node, 3ddp_host, or 3ddp_node).
   


PARALLEL_NODE = the parallel communications library.
  Specify none for a serial version of the solver or one of
  the following:
  smpi: parallel using shared memory (for multiprocessor
  machines)
  vmpi: parallel using shared memory or network with vendor
  MPI software
  net: parallel using network communicator with RSHD
  software

figure   

If you are using a parallel version of the solver, be sure to edit both copies of user_nt.udf (the one in the host folder and the one in the node folder), and specify the appropriate SOURCE, VERSION, and PARALLEL_NODE in each file. Set PARALLEL_NODE = none for the host version and one of the other options smpi, vmpi, net, nmpi for the node version depending on which message passing method you are going to use.

An excerpt from a sample user_nt.udf file is shown below:

    # Replace text in " " (and remove quotes)
    #  | indicates a choice
    #  note: $(SRC) is defined in the makefile

    SOURCES = $(SRC)udfexample.c
    VERSION = 2d
    PARALLEL_NODE = none

2.   In the Visual Studio command prompt window, go to each version folder (e.g., \libudf\ntx86\2d\), and type nmake as shown in the following example.

C:\users\user_name\work_dir\libudf\ntx86\2d>nmake

The following messages will be displayed:

Microsoft (R) Program Maintenance Utility Version 7.10.3077
Copyright (C) Microsoft Corporation.  All rights reserved.        
cl /c /Za /DUDF_EXPORTING 
 -Ic:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\ntx86\2d 
 -Ic:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\src  
 -Ic:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\cortex\src 
 -Ic:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\client\src 
 -Ic:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\tgrid\src 
 -Ic:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\multiport\src  
     ..\..\src\udfexample.c
Microsoft (R) 32-bit C/C++ Standard Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

udfexample.c
# Generating udf_names.c because of makefile udfexample.obj
        cl /c /Za /DUDF_EXPORTING
 -Ic:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\ntx86\2d 
 -Ic:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\src 
 -Ic:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\cortex\src
 -Ic:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\client\src 
 -Ic:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\tgrid\src  
 -Ic:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\multiport\src  
     udf_names.c
Microsoft (R) 32-bit C/C++ Standard Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

udf_names.c
# Linking libudf.dll because of makefile user_nt.udf 
udf_names.obj udfexample.obj
link  /Libpath:c:\Program Files\ANSYS Inc\v120\fluent\fluent12.0.9\ntx86\2d 
      /dll  
 /out:libudf.dl
l  udf_names.obj udfexample.obj   fl1209s.lib
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation.  All rights reserved.

   Creating library libudf.lib and object libudf.exp

C:\Program Files\ANSYS Inc\v120\fluent\ntbin\ntx86\libudf\ntx86\2d>

figure   

Note that if there are problems with the build, you can do a complete rebuild by typing nmake clean and then nmake again.



UNIX and Linux Systems


1.   Using a text editor, edit the file makefile in your src directory to set the following two parameters: SOURCES and FLUENT_INC.


   
SOURCES = the name of your source file(s) (e.g., udfexample.c)
  Multiple sources can be specified by using a space delimiter
  (e.g., udfexample1.c udfexample2.c)
FLUENT_INC = the path to your release directory
   

2.   If your architecture is irix6.5 , make the following additional change to the makefile.

(a)   Find the following line in the makefile:

    CFLAGS_IRIX6R10=        -KPIC -ansi -fullwarn -O -n32

(b)   Change -ansi to -xansi:

    CFLAGS_IRIX6R10=        -KPIC -xansi -fullwarn -O -n32

For all other architectures, do not make any further changes to the makefile.

An excerpt from a sample makefile is shown below:

#-----------------------------------------------------------#
# makefile for user defined functions.
#
#-----------------------------------------------------------#
#-----------------------------------------------------------#
# User modifiable section.
#-----------------------------------------------------------#
SOURCES= udfexample1.c
FLUENT_INC= / path /ansys_inc/v120/fluent
# Precompiled User Object files (for example .o files from .f
sources)
USER_OBJECTS=

#-----------------------------------------------------------#
# Build targets (do not modify below this line).
#-----------------------------------------------------------#
.
.
.

Note that in the previous example, path represents the directory where you installed ANSYS FLUENT.

3.   In your library directory (e.g., libudf), execute the Makefile by typing a command that begins with make and includes the architecture of the machine you will run ANSYS FLUENT on, which you identified in a previous step. For example, for the Linux ( lnx86) architecture type:

    make "FLUENT_ARCH=lnx86"

ANSYS FLUENT will build a shared library for each version you created a directory for (Section  5.3.1) and will display messages about the compile/build process in the console. You can view the compilation history in the log file that is saved in your working directory.

For example, when compiling/building a shared library for a source file named profile.c and a UDF library named libudf on a Linux architecture, the console messages may include the following:

    Working...
    for d in lnx86[23]*; do \
       ( \
         cd $d; \
         for f in ../../src*.[ch] ../../src/makefile; do \
           if [ ! -f 'basename $f' ]; then \
             echo "# linking to " $f "in" $d; \
             ln -s $f .; \
           fi; \
         done; \
         echo ""; \
         echo "# building library in" $d; \
         make -k>makelog 2>&1; \
         cat makelog; \
       ) \
    done
    # linking to ...   myudf.c in lnx86/2d

    # building library in lnx86/2d
    make[1]: Entering directory ..../udf_names.c
    # Generating udf_names 
    make[2]: Entering directory ..../profile.c
    make libudf.so ...
    # Compiling udf_names.o ...
    # Compiling profile.o ...
    # Linking libudf.so ...
    make[2]: Leaving directory ..../udf_names.c
    make[1]: Leaving directory ..../profile.c

    You can also see the 'log'-file in 
    the working directory for compilation history
    Done.


next up previous contents index Previous: 5.3.1 Set Up the
Up: 5.3 Compile a UDF
Next: 5.3.3 Load the UDF
Release 12.0 © ANSYS, Inc. 2009-01-14