Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Ansys UDF (Linking MATLAB)

    • Emmanuel-akor
      Subscriber

      Hi all,

      I am working on the 3D-1D coupling of airflow in the airway tree. As such I need to couple my 3D model in Ansys Fluent with my 1D model in MATLAB. The 1D model will serve as my user-defined boundary condition for the 3D model outlets. I have attempted running a sample .c code for my udf but have been unable to get my code to compile. I am using visual studio as my compiler. Under environmental variables, i have added the PATH (C:\Program Files\MATLAB\R2023b\bin\win64 and C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\bin\Hostx64\x64) , INCLUDE (C:\Program Files\MATLAB\R2023a\extern\include), and LIB (C:\Program Files\MATLAB\R2023a\extern\lib\win64\microsoft) for MATLAB. I believe I have done everything i need to do but I still end up with error messages below. It seems as though the compiler isnt finding the MATLAB LIB although i have specified it under environmental variables. Any help with this would be very much appreciated. I have tried alot of online suggestions and spent two long weeks trying to figure this out and still don't have a solution.  

      Error Message

      Copyright 1987-2024 ANSYS, Inc. All Rights Reserved.

      Compiler and linker: Microsoft Visual C++

      # Generating ud_io1.h

      Testcode.c

      # Generating udf_names.c because of makefile Testcode.obj

      udf_names.c

      # Linking libudf.dll because of makefile user_nt.udf udf_names.obj Testcode.obj

      Creating library libudf.lib and object libudf.exp

      Testcode.obj : error LNK2019: unresolved external symbol engEvalString referenced in function matlab_test

      Testcode.obj : error LNK2019: unresolved external symbol engOpen referenced in function matlab_test

      Testcode.obj : error LNK2019: unresolved external symbol engClose referenced in function matlab_test

      libudf.dll : fatal error LNK1120: 3 unresolved externals

      NMAKE : U1077: 'link -nologo /Libpath:"C:\PROGRA~1\ANSYSI~1\ANSYSS~1\v242\fluent"\fluent24.2.0\win64\3d_node /Libpath:"C:\PROGRA~1\ANSYSI~1\ANSYSS~1\v242\fluent"\fluent24.2.0\multiport\win64\mpi\shared /dll /out:libudf.dll udf_names.obj Testcode.obj mport.lib fl_mpi2420.lib ' : return code '0x460'

      Stop.

      UDF Code

      #include "udf.h" // Fluent UDF header
      #include "engine.h" // MATLAB Engine header
      #include

      // Example UDF using MATLAB Engine
      DEFINE_EXECUTE_AT_END(matlab_test)
      {
          Engine *ep = engOpen(NULL); // Open MATLAB engine
          if (ep == NULL)
          {
              Message("Error: Unable to start MATLAB engine.\n");
              return;
          }

          Message("MATLAB engine started successfully.\n");

          // Example MATLAB engine command
          engEvalString(ep, "disp('Hello from MATLAB Engine!');");

          engClose(ep); // Close MATLAB engine
          Message("MATLAB engine closed successfully.\n");
      }

    • Rob
      Forum Moderator

      Nothing in the UDF manual so I'm a little stuck. Have a look for "Matlab" on here and and the other bits of the system (Search at the top of the page) as it's bound to have come up before. 

    • Emmanuel-akor
      Subscriber

      Okay, will do. thank you. 

Viewing 2 reply threads
  • You must be logged in to reply to this topic.