|February 19, 2006, 18:35||
Integration of a Custom C++ Model into FLUENT
Hi fellow CFD practitioners:
We are trying to integrate a custom heat exchanger model into FLUENT 6.2.16 in a 64-bit Windows XP environment using the User Defined Function (UDF) approach. We have developed the steady-state heat exchanger model as a hierarchy of C++ classes and have compiled and tested it using Microsoft Visual C++ 6.0. Having the impression that the FLUENT compiler is strictly designed to handle UDFs only written in C, we tried the following C-interface between the FLUENT UDF DEFINE macro and the C++ heat exchanger model (being used as wrapper function).
// ***START:*Defning Interfacing C-Wrapper Function*********
void CFunction_Design_HX(double, int, double, double, double, double, int, double*, double*, double*); // Suitable to C return parameters
// ***END:***Defning Interfacing C-Wrapper Function*********
However, FLUENT did not compile the UDF, apparently because it did not recognize the .cpp files of the heat exchanger model, even wrapped underneath the extern "C" layer.
Then, we tried a second route of integrating the C++ heat exchanger model as a PRECOMPILED object (.obj file). Even though, we have followed the integration process documented in Sections 8.3 and 8.4 of the FLUENT UDF manual, we have encountered many problems mainly due to the way the manual has mixed the Makefile parameters and dynamics between UNIX and Windows. We have done a lot of trial and error and now feel that we need to approach the wider CFD community for any guidance. Integrating the heat exchanger model to FLUENT is very critical for our research as it will be called once per iteration to adjust the solver variables (p, v, T). We would also like recommendations on a suitable FLUENT DEFINE marco for passing multiple parameters back and forth.
Does anybody have any experience with the C++/FLUENT integration issues? What would be the best way of achieving the integration? We will greatly appreciate any feed back in this regard.
Many thanks in advance.
Syed I. Haider, PhD, Senior Research Engineer, Georgia Institute of Technology
|February 20, 2006, 05:49||
Re: Integration of a Custom C++ Model into FLUENT
To call C++ function from a udf i would compile the cpp poject as seperate dll, define an "C"interface funtion and call this funtion from the udf. Here is short explanation how to do it:
First the interface funtion of your cpp file:
extern "C" __declspec( dllexport ) void __cdecl Interfacefunction(double* a, int* b)
I saved this function as "project1.cpp" and compiled it from the comand line with
cl project1.cpp /LD
Copy the resulting dll into your windows\system32 directory.
And now the Udf:
extern void Interfacefunction(double*,int*);
To build the libudf.dll you will have to modify the makefile. You will have to include the project1.lib in the linking stage:
link $(LIBS) /dll /out:$(TARGET) \
$(OBJECTS) $(FLUENT_LIB) $(DLL_LIB)
and define DLL_LIB somewhere at the top of your makefile. In my case it is
DLL_LIB = "C:\Programme\Microsoft Visual C++ Toolkit 2003\project1.lib"
Loading the dll into fluent and executing "call_interface" you will get
Hope it helps,
|Thread||Thread Starter||Forum||Replies||Last Post|
|Superlinear speedup in OpenFOAM 13||msrinath80||OpenFOAM Running, Solving & CFD||18||March 3, 2015 06:36|
|Seeking Macroscopic Particle Model in Fluent||bzhang7||FLUENT||0||May 27, 2009 13:36|
|About Aspen and Fluent Integration!||xfish||FLUENT||0||March 24, 2005 22:51|
|UDF of Zimont model in fluent||Z||Main CFD Forum||0||February 17, 2005 04:07|
|Covert Star-CD model to FLUENT||Lam||CD-adapco||6||June 24, 2003 20:21|