


{"id":398566,"date":"2024-12-27T02:15:40","date_gmt":"2024-12-27T02:15:40","guid":{"rendered":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/ansys-udf-linking-matlab\/"},"modified":"2024-12-27T02:15:40","modified_gmt":"2024-12-27T02:15:40","slug":"ansys-udf-linking-matlab","status":"publish","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/ansys-udf-linking-matlab\/","title":{"rendered":"Ansys UDF (Linking MATLAB)"},"content":{"rendered":"<p>&lt;p&gt;Hi all,&lt;\/p&gt;&lt;p&gt;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&#8217;t have a solution.&nbsp;&nbsp;&lt;\/p&gt;&lt;p&gt;&lt;span style=&#8221;text-decoration: underline;&#8221;&gt;<strong>Error Message<\/strong>&lt;\/span&gt;&lt;\/p&gt;&lt;p&gt;Copyright 1987-2024 ANSYS, Inc. All Rights Reserved.&lt;\/p&gt;&lt;p&gt;Compiler and linker: Microsoft Visual C++&lt;\/p&gt;&lt;p&gt;# Generating ud_io1.h&lt;\/p&gt;&lt;p&gt;Testcode.c&lt;\/p&gt;&lt;p&gt;# Generating udf_names.c because of makefile Testcode.obj&lt;\/p&gt;&lt;p&gt;udf_names.c&lt;\/p&gt;&lt;p&gt;# Linking libudf.dll because of makefile user_nt.udf udf_names.obj Testcode.obj&lt;\/p&gt;&lt;p&gt;Creating library libudf.lib and object libudf.exp&lt;\/p&gt;&lt;p&gt;Testcode.obj : error LNK2019: unresolved external symbol engEvalString referenced in function matlab_test&lt;\/p&gt;&lt;p&gt;Testcode.obj : error LNK2019: unresolved external symbol engOpen referenced in function matlab_test&lt;\/p&gt;&lt;p&gt;Testcode.obj : error LNK2019: unresolved external symbol engClose referenced in function matlab_test&lt;\/p&gt;&lt;p&gt;libudf.dll : fatal error LNK1120: 3 unresolved externals&lt;\/p&gt;&lt;p&gt;NMAKE : U1077: &#8216;link -nologo \/Libpath:&#8221;C:\\PROGRA~1\\ANSYSI~1\\ANSYSS~1\\v242\\fluent&#8221;\\fluent24.2.0\\win64\\3d_node \/Libpath:&#8221;C:\\PROGRA~1\\ANSYSI~1\\ANSYSS~1\\v242\\fluent&#8221;\\fluent24.2.0\\multiport\\win64\\mpi\\shared \/dll \/out:libudf.dll udf_names.obj Testcode.obj mport.lib fl_mpi2420.lib &#8216; : return code &#8216;0x460&#8242;&lt;\/p&gt;&lt;p&gt;Stop.&lt;\/p&gt;&lt;p&gt;<strong>&lt;span style=&#8221;text-decoration: underline;&#8221;&gt;UDF Code&lt;\/span&gt;<\/strong>&lt;\/p&gt;&lt;p&gt;#include &#8220;udf.h&#8221; \/\/ Fluent UDF header&lt;br&gt;#include &#8220;engine.h&#8221; \/\/ MATLAB Engine header&lt;br&gt;#include &lt;stdio.h&gt;&lt;\/p&gt;&lt;p&gt;\/\/ Example UDF using MATLAB Engine&lt;br&gt;DEFINE_EXECUTE_AT_END(matlab_test)&lt;br&gt;{&lt;br&gt;&nbsp; &nbsp; Engine *ep = engOpen(NULL); \/\/ Open MATLAB engine&lt;br&gt;&nbsp; &nbsp; if (ep == NULL)&lt;br&gt;&nbsp; &nbsp; {&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; Message(&#8220;Error: Unable to start MATLAB engine.\\n&#8221;);&lt;br&gt;&nbsp; &nbsp; &nbsp; &nbsp; return;&lt;br&gt;&nbsp; &nbsp; }&lt;\/p&gt;&lt;p&gt;&nbsp; &nbsp; Message(&#8220;MATLAB engine started successfully.\\n&#8221;);&lt;\/p&gt;&lt;p&gt;&nbsp; &nbsp; \/\/ Example MATLAB engine command&lt;br&gt;&nbsp; &nbsp; engEvalString(ep, &#8220;disp(&#8216;Hello from MATLAB Engine!&#8217;);&#8221;);&lt;\/p&gt;&lt;p&gt;&nbsp; &nbsp; engClose(ep); \/\/ Close MATLAB engine&lt;br&gt;&nbsp; &nbsp; Message(&#8220;MATLAB engine closed successfully.\\n&#8221;);&lt;br&gt;}&lt;\/p&gt;<\/p>\n","protected":false},"template":"","class_list":["post-398566","topic","type-topic","status-publish","hentry","topic-tag-fluent-ansys-1","topic-tag-udf","topic-tag-udferror"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_forum_id":["27792"],"_bbp_topic_id":["398566"],"_bbp_subscription":["281137","199"],"_bbp_author_ip":["2601:410:4280:4e80:d0a2:e819:3fd9:7e12"],"_bbp_last_reply_id":["404165"],"_bbp_last_active_id":["404165"],"_bbp_last_active_time":["2025-01-08 18:44:52"],"_bbp_reply_count":["2"],"_bbp_reply_count_hidden":["0"],"_bbp_voice_count":["2"],"_bbp_engagement":["281137","199"],"_btv_view_count":["384"],"_bbp_topic_status":["unanswered"]},"test":"emmanuel-akoruiowa-edu"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/398566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/398566\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=398566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}