CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   SWIG wrappers interactive OpenFOAM (https://www.cfd-online.com/Forums/openfoam/60702-swig-wrappers-interactive-openfoam.html)

mariam February 17, 2009 05:47

Dear all, being not too fluen
 
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 http://www.cfd-online.com/OpenFOAM_D...s/1/10942.html, 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

olesen February 17, 2009 05:51

Since OpenFOAM makes extensive
 
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:

http://www.salome-platform.org/forum...11&thread=1564

mariam February 17, 2009 06:03

Mark, yes the templates are th
 
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.

Thanks
Mariam

elorriaux February 17, 2009 09:38

Hello, I've wrapped the Geo
 
Hello,

I've wrapped the GeometricField with swig :

template<class> class PatchField, class GeoMesh>
class GeometricField{
public:
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.

Etienne.

josp February 19, 2009 06:40

Mariam, Etienne! I'm working o
 
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 */

class_<volscalarfield>
(
"volScalarField", "__doc__ volScalarField",
init <const GeometricField<
double,fvPatchField,volMesh>&
>()
);


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

/Johan


All times are GMT -4. The time now is 00:11.