CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Fluent-Matlab Linking (https://www.cfd-online.com/Forums/fluent/224857-fluent-matlab-linking.html)

mohammadreza75 March 5, 2020 17:06

Fluent-Matlab Linking
 
Hello,

I want to run Fluent with Matlab and read a journal file with it. so I write this command in Matlab file:

system('"D:\program file\Ansys 18.2\ANSYS Inc\v182\fluent\ntbin\win64\fluent.exe" 2d -t5 -i ******');

where ****** is the name of my journal file.

The journal file contains a UDF compiling step. when I run Fluent in my system without using Matlab everything works fine, but when I using the Matlab, Fluent can't compile the UDF file properly.

What's the problem?

thanks,

vinerm March 6, 2020 03:29

Fluent in Matlab
 
Fluent requires access to C compiler for compilation of UDF. This has to be made available when starting Fluent from within Matlab. I am not sure Matlab is up for it. So, there are at least two solutions

1. Compile the UDF a priori and let Fluent load it
2. Interpret the UDF, provided the UDF does not have elements that require compilation, such as structures

Though not directly relevant, may I know the objective of linking Matlab and Fluent?

mohammadreza75 March 6, 2020 05:38

Quote:

Originally Posted by vinerm (Post 760662)
Fluent requires access to C compiler for compilation of UDF. This has to be made available when starting Fluent from within Matlab. I am not sure Matlab is up for it. So, there are at least two solutions

1. Compile the UDF a priori and let Fluent load it
2. Interpret the UDF, provided the UDF does not have elements that require compilation, such as structures

Though not directly relevant, may I know the objective of linking Matlab and Fluent?

Thanks, vinerm.

I have a CFD optimization problem so I want to link them.
Do you know how I can compile a UDF with Visual Studio before using it in Fluent?
I try it but VS could not compile a UDF.

vinerm March 6, 2020 05:58

UDF compilation
 
VS is required to compile the UDF but VS alone cannot do it. Solution is to start Fluent from the VS Command Prompt and then compile it. Once compiled, you can use it any time.

mohammadreza75 March 6, 2020 06:14

Quote:

Originally Posted by vinerm (Post 760694)
VS is required to compile the UDF but VS alone cannot do it. Solution is to start Fluent from the VS Command Prompt and then compile it. Once compiled, you can use it any time.

I have a parameter in the UDF that must be changed in the optimization procedure so, in every iteration, I have a different UDF!:(:confused:

vinerm March 6, 2020 08:12

Little more work
 
Then, you have to start VS Command Prompt from Matlab and start Fluent from within that.

Another option is to ensure that Fluent can find VS compiler. Fluent uses a file udf.bat that has paths given for VS compiler. If the path in the file is correct, Fluent started from anywhere can compile a UDF. If it is not, then Fluent has to be started from within VS prompt.

A more sophisticated solution would be to define that variable as rp-var in Fluent. UDF can pick value of rp-var. That way, you don't have to compile the UDF again and again. Same UDF will work with different values of variable; that's the objective of coding, isn't it :)

AlexanderZ March 9, 2020 01:11

use rpvar as parameter, so you don't need to recompile your code


All times are GMT -4. The time now is 23:41.