Ansys Assistant will be unavailable on the Learning Forum starting January 30. An upgraded version is coming soon. We apologize for any inconvenience and appreciate your patience. Stay tuned for updates.
Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Manual “Building and Loading a UDF Library” with C++ files

    • aleksandr.zhadkovskii
      Subscriber

      Hi all!

      I've created a .lib library using primarily C++, and now I am trying to use it in Ansys Fluent (25R1). However, I am not sure if I can build my C++ files manually.

      As I understand, I can compile and link .cpp files containing appropriate DEFINE_ function using the GUI. However, when trying to compile a UDF using TUI, I am getting errors on the step where I must use nmake in each directory. I am using the compiler included in the MS Visual Studio Community 2022. 

      Following Ansys Fluent UDF Manual, I've created the needed directory structure (fig. 1). 

      I've changed user_nt files as stated. An example of one user_nt file is shown below (for the node; this is all the text that is inside the file):

      FLUENT_INC=D:\Program Files\ANSYS Inc\v251\fluent
      FLUENT_ARCH=win64
      CSOURCES = $(SRC)interpolate_csv_data.cpp
      HSOURCES = 
      VERSION = 3dpp_node
      PARALLEL_NODE = msmpi
      USER_OBJECTS = fpi_combined.lib

      Here is my interpolate_csv_data.cpp file at the moment:

      #include "udf.h"
      DEFINE_ON_DEMAND(interpolate_csv_data)
      {
          Message("Successfull call!");
      }

      While using nmake, I am getting the following errors:

      # Generating ud_io1.h
              resolve.exe -udf ..\..\src\interpolate_csv_data.cpp -head_file ud_io1.h
              cl -nologo /c /DUDF_EXPORTING /DUDF_NT /DWIN64 /EHa /wd4224  -I.  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\win64\3dpp_node  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\main  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\addon-wrapper  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\io  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\species  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\pbns  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\numerics  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\sphysics  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\storage  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\mphase  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\bc  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\models  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\material  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\amg  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\util  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\mesh  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\udf  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\ht  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\dx  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\turbulence  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\acoustics  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\parallel  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\etc  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\ue  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\dpm  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\dbns  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\cortex\src  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\client\src  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\tgrid\src  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\multiport\src  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\multiport\mpi_wrapper\src  -I"D:\Program Files\ANSYS Inc\v251\fluent"\include  ..\..\src\interpolate_csv_data.cpp
      interpolate_csv_data.cpp
      D:\Program Files\ANSYS Inc\v251\fluent\fluent25.1.0\src\main\config.h(122): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      D:\Program Files\ANSYS Inc\v251\fluent\fluent25.1.0\src\main\config.h(122): error C2059: syntax error: ':'
      D:\Program Files\ANSYS Inc\v251\fluent\fluent25.1.0\src\main\config.h(122): error C2143: syntax error: missing ';' before 'constant'
      D:\Program Files\ANSYS Inc\v251\fluent\fluent25.1.0\src\main\config.h(122): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\stdarg.h(16): error C2143: syntax error: missing ';' before '{'
      C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\stdarg.h(16): error C2447: '{': missing function header (old-style formal list?)
      NMAKE : fatal error U1077: 'cl -nologo /c /DUDF_EXPORTING /DUDF_NT /DWIN64 /EHa /wd4224  -I.  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\win64\3dpp_node  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\main  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\addon-wrapper  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\io  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\species  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\pbns  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\numerics  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\sphysics  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\storage  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\mphase  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\bc  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\models  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\material  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\amg  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\util  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\mesh  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\udf  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\ht  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\dx  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\turbulence  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\acoustics  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\parallel  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\etc  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\ue  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\dpm  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\src\dbns  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\cortex\src  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\client\src  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\tgrid\src  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\multiport\src  -I"D:\Program Files\ANSYS Inc\v251\fluent"\fluent25.1.0\multiport\mpi_wrapper\src  -I"D:\Program Files\ANSYS Inc\v251\fluent"\include  ..\..\src\interpolate_csv_data.cpp' : return code '0x2'
      Stop.

      Did I miss something? As I understand, the problem is Makefile files are set up in such a way that there is no distinction between .c and .cpp files. The compiler sees my file is .cpp and is trying to build all files using C++ standards and failing to do so because Ansys UDF headers are written in plain C. Is there a workaround to fix this issue? Or is the only way to rewrite my .lib file in C or create some kind of C bridge?.

      Could this issue be caused by compiler flags used to build my .lib file? As I see it, the building process hasn't advanced enough to the steps where this would matter, but I may be wrong.

      Right now I am not sure what to do next, so any help would be appreciated.

    • Rob
      Forum Moderator

      You'll need to refer to the UDF manual. Is there a reason for not using the built in CLANG compiler? 

      • aleksandr.zhadkovskii
        Subscriber

        Hi Rob!

        I am trying to link and use a precompiled object in my UDF program, following the UDF manual. I was following Section 5 of it; however, right now I am stuck at trying to link all objects in the directory (Section 5.3.2.1, bullet point 2). 

        I am using a non-built-in compiler only for convenience, as I am more familiar with it and my .lib file is built using MSVC.

    • Rob
      Forum Moderator

      Have you checked config.h - there's a set of warnings/errors in your post. 

      We're very limited in what we can cover on UDFs on the public Forum so I'm a little stuck. 

      • aleksandr.zhadkovskii
        Subscriber

        Yes, I checked them. I cannot seem to find anything wrong. Moreover, it will be strange, as these are Ansys's native files (they are located in the Ansys installation folder).

        For a change, I've tried changing my .cpp file to just .c (fortunately, nothing needs to be changed for that but the filename), but the problem persists, so my first guess on the origin of the problem could be wrong.

        I am trying to check several things, such as system environment variables and path values, but I haven't found out the cause yet.

        In any way, thank you for your help.

    • Rob
      Forum Moderator

      Can you compile in Fluent? Just checking any of the process is working properly. That might help narrow down the problem. I always use CLANG on Win10/11 and LINUX just works. A colleague uses CLANG scripts but we can't share those on the Forum. 

      • aleksandr.zhadkovskii
        Subscriber

        Yes, both C and C++ files compile just fine without a built-in compiler function inside Fluent. Sadly, I believe there is no way to add precompiled objects using Fluent GUI.

        I've tried using clang just to compile plain C/C++ script files (same insides as in the original post), but I am getting some errors. Maybe you can give me a hint as to what could be wrong? I was trying to follow this post: How to build a Fluent UDF library by command line on Windows using the Clang compiler provided with Fluent? | Ansys Knowledge.

        I am using the same file structure as in the original post. I've added the file "sconstruct" from the ansys udf directory (without changes) and created the "user.txt" file with the following contents:

        FLUENT_INC="D:/Program Files/ANSYS Inc/v251/fluent"
        FLUENT_ARCH="win64"
        FLUENT_UDF_CLANG="builtin"
        FLUENT_UDF_COMPILER="MSVC"
        GPU_SUPPORT="off"
        FLUENT_RELEASE="fluent25.1.0"

        CSOURCES = "(SRC)interpolate_csv_data.c"
        HSOURCES = ""
        VERSION = "3dpp_node"
        PARALLEL_NODE = "msmpi"

        After that, I tried to run both scons_builtin.bat and scons_default.bat (I put them inside my 3dpp_node directory; these files are from \ANSYS Inc\v251\fluent\fluent25.1.0\src\udf), but I got "Fluent version is not supported". I am getting a nudge that this problem is caused by a wrongly defined user file?

        • aleksandr.zhadkovskii
          Subscriber

           

          I’ve realised using scons_builtint is not correct, so I’ve added “\ANSYS Inc\v251\commonfiles\CPython\3_10\winx64\Release\python\Scripts” to PATH and then tried to use scons in the 3dpp_node directory, but I’m still getting this “Fluent version not supported” error.

           

    • Rob
      Forum Moderator

      And at the very limits of what I can say (and beyond what I know). Did you set the    -D RP_CONFIG_2D_HOST    or _3D_NODE or some combination of in the compile command to set the config.h  ?  I'm afraid it's over to the wider community from here. 

      • aleksandr.zhadkovskii
        Subscriber

        Actually, that helped. I believe I haven't seen this in the UDF manual (or did I miss it?). I've changed the following in the Ansys-provided Makefile (addition is in bold):

        CFLAGS = /c /DUDF_EXPORTING /DUDF_NT /DWIN64 /EHa /wd4224 /DRP_CONFIG_3D_NODE

        Now I don't get errors with relation to the config.h. NMake successfully passes the "# Generating ud_io1.h"; "# Generating udf_names.c because of makefile interpolate_csv_data.obj" steps. That being said, I am getting new errors during the linking process:

        # Linking libudf.dll because of makefile user_nt.udf udf_names.obj interpolate_csv_data.obj
                link -nologo  /dll   /out:libudf.dll  udf_names.obj interpolate_csv_data.obj
           Creating library libudf.lib and object libudf.exp
        interpolate_csv_data.obj : error LNK2019: unresolved external symbol __imp__CX_Message referenced in function _interpolate_csv_data
        interpolate_csv_data.obj : error LNK2019: unresolved external symbol __imp__Mpt_Lock referenced in function _interpolate_csv_data
        interpolate_csv_data.obj : error LNK2019: unresolved external symbol __imp__Mpt_Unlock referenced in function _interpolate_csv_data
        libudf.dll : fatal error LNK1120: 3 unresolved externals
        NMAKE : fatal error U1077: 'link -nologo  /dll   /out:libudf.dll  udf_names.obj interpolate_csv_data.obj    ' : return code '0x460'
        Stop.

        I tried to change the contents of the .cpp file (I've added Domain* domain; domain = Get_Domain(1);) and after this change I am getting similar errors (unresolved external symbol __imp_Get_Domain referenced in function interpolate_csv_data). Looks like the linker doesn't see standard Fluent functions. I'll check all my paths again and try to change makefile and will see if it will help.

         
         
         
Viewing 4 reply threads
  • You must be logged in to reply to this topic.
[bingo_chatbox]