MeshPy

Submitted by inducer on Mon, 12/02/2007 - 22:37

MeshPy offers quality triangular and tetrahedral mesh generation for Python. Meshes of this type are chiefly used in finite-element simulation codes, but also have many other applications ranging from computer graphics to robotics.

aps-gun.png
aps-gun.png

The above picture shows a cutaway of a sample mesh generated for an electron gun at the Advanced Photon Source at Argonne National Labs in Illinois.

In order to generate these 2D and 3D meshes, MeshPy provides Python interfaces to two well-regarded mesh generators, Triangle by J. Shewchuk and TetGen by Hang Si. Both are included in the package in slightly modified versions.

MeshPy requires Boost.Python. Parts of this package were written as part of my Diplom thesis. In a former life, this package was called PyAngle.

Obtaining MeshPy

You may download releases from MeshPy’s Python Package Index page, browse the source or directly check out the very latest version using git:

git clone http://git.tiker.net/trees/meshpy.git

Documentation and Support

MeshPy now has documentation available. If you still run into trouble, feel free to post to the support forum.

Example

MeshPy makes scripted mesh generation as easy as never before. This simple code suffices to generate an elementary mesh of a “brick”:

from meshpy.tet import MeshInfo, build

mesh_info = MeshInfo()
mesh_info.set_points([
    (0,0,0), (2,0,0), (2,2,0), (0,2,0),
    (0,0,12), (2,0,12), (2,2,12), (0,2,12),
    ])
mesh_info.set_facets([
    [0,1,2,3],
    [4,5,6,7],
    [0,4,5,1],
    [1,5,6,2],
    [2,6,7,3],
    [3,7,4,0],
    ])
mesh = build(mesh_info)
mesh.write_vtk("test.vtk")

The result of this short script is below:

brick.png
brick.png

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I tried to install meshpy but I am getting the error below. It seems the program does not know what the variable ‘len’ is in the file “foreign_array_wrap.hpp”. I have the boost library installed on Fedora 7. I would appreciate any help or suggestion about how to solve the problem. Thanks Alejandro

python setup.py install

running install running build running build_py running build_ext building ‘meshpy._triangle’ extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DEXTERNAL_TEST=1 -DANSI_DECLARATORS=1 -DTRILIBRARY=1 -I/usr/include/boost/ -I/usr/local/include/python2.5 -c src/cpp/wrap_triangle.cpp -o build/temp.linux-i686-2.5/src/cpp/wrap_triangle.o

cc1plus: warning: command line option “-Wstrict-prototypes” is valid for Ada/C/ObjC but not for C++ cc1plus: warning: command line option “-Wstrict-prototypes” is valid for Ada/C/ObjC but not for C++

src/cpp/foreign_array_wrap.hpp: In static member function ‘static boost::python::api::object::tPODForeignArrayWrapHelper::getitem(FA&, boost::python::tuple)’: src/cpp/foreign_array_wrap.hpp:58: error: there are no arguments to ‘len’ that depend on a template parameter, so a declaration of ‘len’ must be available

src/cpp/foreign_array_wrap.hpp:58: error: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)

src/cpp/foreign_array_wrap.hpp:81: error: ‘len’ was not declared in this scope src/cpp/foreign_array_wrap.hpp:84: error: ‘len’ was not declared in this scope src/cpp/foreign_array_wrap.hpp: In static member function ‘static void::tPODForeignArrayWrapHelper::setitem(FA&, boost::python::tuple, const typename FA::value_type&) [with FA = tForeignArray]’: src/cpp/foreign_array_wrap.hpp:143: instantiated from ‘void exposePODForeignArray(const std::string&) [with T = int]’ src/cpp/wrap_triangle.cpp:233: instantiated from here src/cpp/foreign_array_wrap.hpp:93: error: ‘len’ was not declared in this scope error: command ‘gcc’ failed with exit status 1

Hey there! First of all, if you need support with my software, don’t hesitate to email me. I probably won’t see your comments here. Next, what version of gcc, what version of Boost Python are you using?

Thanks for trying meshpy, Andreas

Post new comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>.
  • You can use Markdown syntax to format and style the text. Also see and Markdown Extra for tables, footnotes, and more.

More information about formatting options