CFD Online Logo CFD Online URL
Home > Forums > FLUENT

Integration of a Custom C++ Model into FLUENT

Register Blogs Members List Search Today's Posts Mark Forums Read

LinkBack Thread Tools Display Modes
Old   February 19, 2006, 18:35
Default Integration of a Custom C++ Model into FLUENT
Syed Haider
Posts: n/a
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).

#ifdef __cplusplus

extern "C"

{ #endif

// ***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*********

#ifdef __cplusplus



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.

Best regards,

Syed I. Haider, PhD, Senior Research Engineer, Georgia Institute of Technology

  Reply With Quote

Old   February 20, 2006, 05:49
Default Re: Integration of a Custom C++ Model into FLUENT
Posts: n/a
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:

#include "udf.h"

extern void Interfacefunction(double*,int*);

real a;
int b;

CX_Message("\na=%g b=%d",a,b);

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) \

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

a=12.34 b=1

Hope it helps,
  Reply With Quote


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Seeking Macroscopic Particle Model in Fluent bzhang7 FLUENT 1 October 26, 2017 03:54
Superlinear speedup in OpenFOAM 13 msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 06: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 Siemens 6 June 24, 2003 20:21

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