Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Issues compiling UDF in ANSYS Fluent – UDF not being read correctly?

    • Rosa Spence
      Subscriber

      I am attempting to use user defined functions to define the Launder Sharma low reynolds number turbulence model. The source code has been written and published in a paper from 2013, I have made no adaptations to the code provided, however I am getting a host of errors related to unknown type names and undeclared identifiers. Before all the errors is a warning that the MSVC compiler 'cl' could not be found and may need to be installed separately with visual studio. I then attempted to trouble shoot the problem by trying the sample UDF code from the ansys user guide (included below), as a control guide. However I am still getting the compiler warning and 3 errors. Any suggestions on what could be causing the issue, is it a compiler issue as I think?

      Thank you

      Sample code from ANSYS User Guide:
      #include "udf.h"
      #define C2 100.0
      DEFINE_SOURCE(xmom_source, c, t, dS, eqn)
      {
      real x[ND_ND];
      real con, source;
       
      C_CENTROID(x, c, t);
      con = C2 * 0.5 * C_R(c, t) * x[1];
       
      source = -con * fabs(C_U(c, t)) * C_U(c, t);
      dS[eqn] = -2. * con * fabs(C_U(c, t));
       
      return source;
      }

       

      Errors within fluent :

      udf_names.c(6,8): warning: type specifier missing, defaults to 'int' [-Wimplicit-int]

      extern DEFINE_SOURCE(xmom_source, c, t, dS, eqn);

      ~~~~~~ ^

      udf_names.c(6,22): error: a parameter list without types is only allowed in a function definition

      extern DEFINE_SOURCE(xmom_source, c, t, dS, eqn);

      ^

      udf_names.c(8,28): error: use of undeclared identifier 'xmom_source'

      {"xmom_source", (void(*)())xmom_source, UDF_TYPE_SOURCE},

      ^

      udf_names.c(10,46): error: invalid application of 'sizeof' to an incomplete type 'UDF_Data []'

      __declspec(dllexport) int n_udf_data = sizeof(udf_data)/sizeof(UDF_Data);

      ^~~~~~~~~~

      11 warnings and 3 errors generated.

      scons: *** [udf_names.obj] Error 1

      scons: building terminated because of errors.

       

      Done.

    • Federico
      Ansys Employee

      Are you using Fluent's built-in compiler or is your UDF compiled prior to reading it in Fluent?

      • Rosa Spence
        Subscriber

        I am using Fluents build in compiler

        • Federico
          Ansys Employee

          If you get a compiler error/warning, then you should troubleshoot this issue before the subsequent errors/warnings. Your UDF code looks fine to me, but for some reason, it appears that the script is not compiled correctly. 

          Are you following these steps here to Build and Load the UDF? 5.2. Compiling a UDF Using the GUI (ansys.com)

          Do you get any errors when loading the UDF?

    • Rosa Spence
      Subscriber

      I am following the steps outlined in the user guide, I believe the source file is in the same folder that holds the case and data files (the cas.h5 and dat.h5 files?). I cannot load the UDF as it is not successfully built, in the previous step.

      • Federico
        Ansys Employee

        Can you copy and paste the entire error "MSVC compiler 'cl' could not be found" here?

        • Rosa Spence
          Subscriber

          Below is the section of the console output with the compiler warnings:

          scons: Reading SConscript files ...

          scons: warning: Could not find MSVC compiler 'cl', it may need to be installed separately with Visual Studio

          File "U:\Dissertation\Mesh convergenced 0AOA_files\dp0\FFF-21\Fluent\libudf\win64\2ddp_host\SConstruct", line 8, in

          scons: warning: Could not find MSVC compiler 'cl', it may need to be installed separately with Visual Studio

          File "U:\Dissertation\Mesh convergenced 0AOA_files\dp0\FFF-21\Fluent\libudf\win64\2ddp_host\SConstruct", line 18, in

          Compiler used is "C:\PROGRA~1\ANSYSI~1\v212\fluent"\ntbin\clang\bin\clang-cl

          Linker used is "C:\PROGRA~1\ANSYSI~1\v212\fluent"\ntbin\clang\bin\lld-link

          scons: warning: Could not find MSVC compiler 'cl', it may need to be installed separately with Visual Studio

           

    • Federico
      Ansys Employee

       

      I just tested the UDF on my end, and it runs fine. Make sure your script .c is located in the working directory.

      If the above is correct, I would argue this is probably an installation issue.

       

      • Rosa Spence
        Subscriber

        Thank you for your help, I appreciate it. I also think its an installation issue.

    • MangeshANSYS
      Ansys Employee

      Hello

      Please avoid any spaces in path where case and data files and UDF files are stored. That should resolve the issue

       

      i.e. DO NOT USE something like this which has spaces and special characters

      U:\Projects and Activities\Fan & motor\my CFD Project\fan

       

       

      instead use a PATH with only letters, numbers and underscores

      U:\Projects_and_Activities\Fan_n_motor\my_CFD_Project\fan

       

Viewing 4 reply threads
  • The topic ‘Issues compiling UDF in ANSYS Fluent – UDF not being read correctly?’ is closed to new replies.