Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


access mesh topology

  • Hon Fai Choi
    Hon Fai Choi


    I managed to create a mesh with pythonFlu210 from my OpenFOAM input files using:

    mesh = man.createMesh(runTime)

    which returns a mesh container with a fvMesh object.

    I also managed to access the connections between cell, faces, edges and points in the mesh via:




    where index is an integer.
    However, the following calls just return pointer objects ( <Swig Object of type 'Foam::labelListList * ' > ) which I can't access:


    Does this mean that these connections aren't automatically created? If so, which function do I need to call to create them?

    Hon Fai

  • Alexey Petrov
    Alexey Petrov

    Hi Hon Fai,

    The code you are investigating

    mesh = man.createMesh(runTime)

    should produce completely initialized mesh object
    (absolutely the same as if you were writing and executing corresponding C++ code).

    As you could see, from implementation of pythonFlu based solvers, corresponding Python code follows the referenced C++ implementation as close as it is possible. So, once operation is executed without any error, that means that the corresponding output parameter is correct (the same as in C++).

    Also, if you has some values that been printed sounds like - "<Swig Object of type … >" that means that the corresponding value type is not wrapped by pythonFlu yet. Therefore, if you need to analyze some of these values you could ask us (pythonFlu team) to advance the existing pythonFlu wrapping definition on this account (it is not difficult, but each C++ interface need to be mentioned explicitly to produce proper Python wrapping).

    One remark about the Python code you have posted -


    for example. Had better be simplified up to


    (get() function is omitted)
    This will shorten corresponding Python code and provide much closer look with C++ one.


  • Hon Fai Choi
    Hon Fai Choi

    Hi Alexey,

    thanks for the info and tips. It would be nice if the flu-team could wrap the other mesh connection  access functions in the future:


    but I can understand that you have limited resources. So far, everything works nicely and pythonFlu is really useful for me, also to get a better understanding of the data structures of OpenFOAM. So, thanks for the great job!
    I used the mesh.get() because I thought I could only call the mesh member functions from a mesh object. Since there is no documentation, I use the dir() command in Python to see the member functions that I can use for a certain object. The mesh created with 'man.createMesh(runTime)'  seems to be a mesh container and dir(mesh) does not show the mesh member functions. It would be useful if I could somehow also see the inherited member functions of the parent objects, but I haven't figured out yet how to do this in Python.

    It would be great if there could also be an option to read out data from OpenFoam data structures as numpy arrays, but I guess that is easier said than done. Now I have to go through a lot of for loops to transfer OpenFoam vector and other lists to a numpy array, which is probably not so efficient.

    many thanks,
    Hon Fai

  • Alexey Petrov
    Alexey Petrov

    Hi Hon Fai,

    About the mesh introspection functionality  - ok, we will put this task in our list.

    About the pythonFlu API documentation - ye, I agree that there is no detailed description. From other hand, pythonFlu implementation strategy is to follow the referenced C++ API as close, as possible. So, in principle, all the functionality user can call from some C++ object, should be accessible from corresponding pythonFlu one.

    Therefore, do not be lost, start from the official OpenFOAM documentation (http://foam.sourceforge.net/docs/cpp/classes.html, for example) and only if there will be some missing points you can try native Python introspection "dir" functionality.

    To see each method was defined at each class in hierarchy use "List of all members" in the official OpenFOAM C++ doxygen generated documentation. Let's take "Field< Type > Class Template Reference" for example (http://foam.sourceforge.net/docs/cpp/a00570.html) the corresponding distribution of all its methods among its class hierarchy can be found at - http://foam.sourceforge.net/docs/cpp/a12299.html.

    Direct Python introspection can be performed as in the following guide - http://codelab.ferrarihaines.com/archives/194

    About the translation of OpenFOAM data to / from NumPy, I have written to one guy who (I think) were playing with the same stuff as you are. Might be he will share some piece of his experience with us.

    Best regards,