CFD Online Logo CFD Online URL
Home > Forums > OpenFOAM

SWIG wrappers interactive OpenFOAM

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

LinkBack Thread Tools Display Modes
Old   February 17, 2009, 06:47
Default Dear all, being not too fluen
New Member
Mariam Winkler
Join Date: Mar 2009
Posts: 4
Rep Power: 10
mariam is on a distinguished road
Dear all,
being not too fluent in C, I had tried to wrap the OpenFOAM functions in order to use it from python. While this helped me substantially with other simulation software, I was unable to get a working OpenFOAM wrapper. Unfortunately I failed at the very basic GeometricField classes.

I was happy to read Ivor in thread, who mentioned that he was working on such a wrapper. Can I find somewhere Ivor's wrapper or the code it is based on, for helping my OpenFOAM experience with a more user-friendly programming environment? Assuming that it is quite some work to wrap all OpenFOAM classes, I'm also interested to contribute some parts, probably related to, but not limited to turbomachinery. However, as I said, I couldn't get started on my own and I need help with the basic SWIG interface setup.

mariam is offline   Reply With Quote

Old   February 17, 2009, 06:51
Default Since OpenFOAM makes extensive
Senior Member
Mark Olesen
Join Date: Mar 2009
Posts: 802
Rep Power: 21
olesen will become famous soon enough
Since OpenFOAM makes extensive use of C++ templates, I can imagine that wrapping them with SWIG might require a fair amount of attention.

A quick google turned up this as a starting point for you:
olesen is offline   Reply With Quote

Old   February 17, 2009, 07:03
Default Mark, yes the templates are th
New Member
Mariam Winkler
Join Date: Mar 2009
Posts: 4
Rep Power: 10
mariam is on a distinguished road
Mark, yes the templates are the cause of my problems. But apparently Ivor and Hrv have built a wrapper despite of the difficulties.
I am less asking about advice how to solve each individual problem (have worked with SWIG and templates a lot, but never had similar problems). Rather I hope I can build upon previous code.

mariam is offline   Reply With Quote

Old   February 17, 2009, 10:38
Default Hello, I've wrapped the Geo
Etienne Lorriaux
Join Date: Mar 2009
Location: Compiegne, France
Posts: 43
Rep Power: 10
elorriaux is on a distinguished road

I've wrapped the GeometricField with swig :

template<class> class PatchField, class GeoMesh>
class GeometricField{
const IOobject&,
const GeoMesh::Mesh&

%template(volScalarField) GeometricField<scalar,fvpatchfield,volmesh>;
%template(volVectorField) GeometricField<vector,fvpatchfield,volmesh>;
%template(surfaceScalarField) GeometricField<scalar,fvspatchfield,surfacemesh>;
%template(surfaceVectorField) GeometricField<vector,fvspatchfield,surfacemesh>;

It seems to work, i'm able to run icoFoam and I'm getting the same results than the original solver.

But swig is too limited, i'm thinking to switch to boost. For the moment, i'm able to run almost everything i need with swig wrappers (great difficulties with the dytnamicFvMesh class), but i fear that i will we locked with this project in the future.

Note that i'm working with OF-1.4.1-dev for this wrapping project, i've not upgraded my wrappers to 1.5-dev yet.

elorriaux is offline   Reply With Quote

Old   February 19, 2009, 07:40
Default Mariam, Etienne! I'm working o
Johan Spång
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 35
Rep Power: 10
josp is on a distinguished road
Mariam, Etienne! I'm working on some boost-python wrapping of OpenFOAM. But I have a different approach in that I have embedded an interactive python prompt into parallel runs of OpenFOAM. So OpenFOAM is still started as usual with foamJob -p solverName

It's possible to inspect the properties of (say) a scalarField at runtime and use all the great python tools like numpy/pylab to process the data.

I think boost-python is a more suitable tool but swig will probably work aswell.

I wrapped volScalarField like this:
/* Foam volScalarField */

"volScalarField", "__doc__ volScalarField",
init <const GeometricField<

Still, embedding/extending or plain extending does not really matter since the wrapping procedure is the same. I'll upload the code (very early development) somewhere as soon as I can!

Best wishes

josp is offline   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
OpenFOAM users in Munich OpenFOAM benutzer in M%c3%bcnchen jaswi OpenFOAM 0 August 3, 2007 13:11
A new Howto on the OpenFOAM Wiki Compiling OpenFOAM under Unix mbeaudoin OpenFOAM Installation 2 April 28, 2006 08:54
Vehicle Thermal Management Interactive Course CD adapco Group Marketing Siemens 0 March 14, 2002 12:47
SMARTFIRE: A new interactive fire field modelling CFD code. John Ewer Main CFD Forum 0 July 7, 1998 03:46

All times are GMT -4. The time now is 13:51.