CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Fluent UDF and Scheme Programming (
-   -   Running Fluent from Python: UDF Compilation problems (

Ames November 12, 2020 10:10

Running Fluent from Python: UDF Compilation problems
Hi all!

I am working on a 2D model in Ansys Fluent, which eventually I want to couple with a 1D model written in Python (multi-scale modelling). Therefore I am trying to run Fluent from Python. In Python I am able to launch Fluent as a server via a system command:

FluentArgs = 'fluent 2ddp -aas'
os.system(FluentPath + " " + FluentArgs)

Then I am able to connect Python with the Fluent server. The implementation is similar to the implementation for the Matlab-Fluent coupling as described in 6) by Sorin. I have first implemented it in Matlab, but I did get the same problem as with Python as described below. I switched to Python for the coupling with the 1D model.

I can drive Fluent by sending a journal file (via DoMenuCommand) to the Fluent Server, so that the server runs a certain case. But now I am trying to compile a UDF (written in C), but I receive the following error:

“ ‘nmake’ is not recognized as an internal or external command, operable program or batch file “

I know that this error has something to do with my UDF code not being compiled, as the nmake.exe file cannot be found. I have come across this problem before when I was trying to compile a UDF code from Fluent’s GUI and I have managed to solve this problem by installing Microsoft Visual Studio Community 2017 and running Fluent from Visual Studio’s Command Prompt, as has been suggested on several forums here.

As I am launching Fluent now as a server from Python, I don’t know how to solve this ‘nmake’ error. Does anyone have experience with running Fluent from Python and compiling UDF code in a Windows os?

I am working in Windows 10 (64-bit), Python 3.7 and I have installed Microsoft Visual Studio Community 2017. For Fluent I am using the Workbench’s student version 2020R2.

Any suggestions are welcome. Thanks for your help!

Edit: I am able to start Fluent from the Windows cmd and compile a UDF. However, when starting Fluent as a server from Python or from MS Visual Studio, I receive the same error about 'stdio.h: no such file or directory'.

AlexanderZ November 15, 2020 23:35

I recommend you to change UDF, so you would not recompile it again.
you may read parameters from file or define rpvars and control values from journal

Ames November 16, 2020 03:26

Hi Alexander,

Thanks for your help! I will look into it to see if I can make it work for my case.

So if I understand it correctly, you mean by changing the UDF, replacing it by txt-files prescribing values at certain time points?
And what do you mean by recompiling? When I try to build a library and load the UDF into my case, I do make sure that the libary (libudf or something like that) does not exist yet.

/define/user-defined/compiled-functions compile libudf2 yes "3WK.c" "" ""
/define/user-defined/compiled-functions load libudf2

AlexanderZ November 16, 2020 04:35

lets start with this question:
why do you need to compile UDF for each new case?

Ames November 16, 2020 04:51

You are right that I don't need to compile the UDF for each new case, as the parameters etc. in the UDF will remain the same for all cases (for now). I am using the UDF to set the pressure at the outlet based on the flow at the outlet (Windkessel model).

However, is it possible to compile the UDF once from Python? So that I can load the same library for different cases.

I really appreciate your help!

AlexanderZ November 16, 2020 06:12

if the code is the same for cases, you don't need to compile UDF each time.
Compile once without python. Then you may just load precompiled library using python.

I don't know how to compile UDF from fluent aas

All times are GMT -4. The time now is 20:17.