inducer / inducer/meshpy

segfault with triangle.refine

Open
#10 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
588
Forks
112
Avg merge
9h 38m
Merged PRs (30d)
2

Description

Dear @inducer

I encounter a segfault again when calling `triangle.refine` to refine a generated mesh (maybe, it is my compiler's problem ?)

The codes are posted below. A short description of the codes, I generated mesh from a circle (a small square is within the circle) and I want to further refine the already generated mesh by imposing a more strict refinement_func, and the gdb debug information is posted after the code.

BTW, can i pass more parameters to the `refinement_func` ? for example, the polygon in `refinement_func_square`, so that I could write more compact refinement functions for different regions of the mesh.

Best!

``` python
from __future__ import division

import meshpy.triangle as triangle
import numpy as np
from matplotlib.path import Path

def round_trip_connect(start, end):
return [(i, i+1) for i in range(start, end)] + [(end, start)]

def needs_refinement(tri_points, area):
return bool(area > 0.1)

def needs_refinement2(tri_points, area):
return bool(area > 0.05)

def needs_refinement_square(tri_points, area):
points = [(1, 0), (1, 1), (-1, 1), (-1, -1), (1, -1), (1, 0)]
psquare = Path(points)
center_tri = np.sum(np.array(tri_points), axis=0)/3.
if psquare.contains_point(center_tri):
if bool(area > 0.05):
return True
elif area>0.1:
return True
else:
return False

def main():
points = [(1, 0), (1, 1), (-1, 1), (-1, -1), (1, -1), (1, 0)]
facets = round_trip_connect(0, len(points)-1)

circ_start = len(points)
points.extend(
(3 * np.cos(angle), 3 * np.sin(angle))
for angle in np.linspace(0, 2*np.pi, 30, endpoint=False))
facets.extend(round_trip_connect(circ_start, len(points)-1))

markers = [2,2,2,2,2,2]
markers.extend(list(np.ones(30, dtype='int')))
markers = [int(i) for i in markers]

info = triangle.MeshInfo()
info.set_points(points)
#info.set_holes([(0, 0)])
info.set_facets(facets, facet_markers=markers)

mesh = triangle.build(info, refinement_func=needs_refinement)
mesh = triangle.refine(mesh, refinement_func=needs_refinement2)

mesh_points = np.array(mesh.points)
mesh_tris = np.array(mesh.elements)
mesh_attr = np.array(mesh.point_markers)
print(mesh_attr)

import matplotlib.pyplot as plt
plt.triplot(mesh_points[:, 0], mesh_points[:, 1], mesh_tris)
plt.xlabel('x')
plt.ylabel('y')
plt.show()
#
fig = plt.gcf()
fig.set_size_inches(4.2, 4.2)
#plt.savefig('../../figs/sec5-meshpy-triangle-ex4.pdf')

if __name__ == "__main__":
main()
```

```
(gdb) file python
Reading symbols from python...(no debugging symbols found)...done.
(gdb) run triangle-ex4.py
Starting program: /usr/bin/python triangle-ex4.py
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff60efcdc in reconstruct () from /usr/lib/python3.4/site-packages/MeshPy-2014.1-py3.4-linux-x86_64.egg/meshpy/_triangle.cpython-34m.so
(gdb) bt
#0 0x00007ffff60efcdc in reconstruct () from /usr/lib/python3.4/site-packages/MeshPy-2014.1-py3.4-linux-x86_64.egg/meshpy/_triangle.cpython-34m.so
#1 0x00007ffff60f4e5b in triangulate () from /usr/lib/python3.4/site-packages/MeshPy-2014.1-py3.4-linux-x86_64.egg/meshpy/_triangle.cpython-34m.so
#2 0x00007ffff60d0602 in triangulateWrapper(char*, tMeshInfo&, tMeshInfo&, tMeshInfo&, _object*) () from /usr/lib/python3.4/site-packages/MeshPy-2014.1-py3.4-linux-x86_64.egg/meshpy/_triangle.cpython-34m.so
#3 0x00007ffff60d8ec7 in meshpyboost::python::objects::caller_py_function_impl > >::operator()(_object*, _object*) ()
from /usr/lib/python3.4/site-packages/MeshPy-2014.1-py3.4-linux-x86_64.egg/meshpy/_triangle.cpython-34m.so
#4 0x00007ffff60ff552 in meshpyboost::python::objects::function::call(_object*, _object*) const () from /usr/lib/python3.4/site-packages/MeshPy-2014.1-py3.4-linux-x86_64.egg/meshpy/_triangle.cpython-34m.so
#5 0x00007ffff60ff657 in meshpyboost::detail::function::void_function_ref_invoker0::invoke(meshpyboost::detail::function::function_buffer&)
() from /usr/lib/python3.4/site-packages/MeshPy-2014.1-py3.4-linux-x86_64.egg/meshpy/_triangle.cpython-34m.so
#6 0x00007ffff610cf0d in meshpyboost::python::handle_exception_impl(meshpyboost::function0) () from /usr/lib/python3.4/site-packages/MeshPy-2014.1-py3.4-linux-x86_64.egg/meshpy/_triangle.cpython-34m.so
#7 0x00007ffff60fce7f in function_call () from /usr/lib/python3.4/site-packages/MeshPy-2014.1-py3.4-linux-x86_64.egg/meshpy/_triangle.cpython-34m.so
#8 0x00007ffff79a6ff8 in PyObject_Call (func=func@entry=0x721cf0, arg=arg@entry=0x7ffff7ef6990, kw=kw@entry=0x0) at Objects/abstract.c:2067
#9 0x00007ffff7a57393 in do_call (nk=, na=5, pp_stack=0x7fffffffdd30, func=) at Python/ceval.c:4463
#10 call_function (oparg=, pp_stack=0x7fffffffdd30) at Python/ceval.c:4261
#11 PyEval_EvalFrameEx (f=0x7ffff010f048, throwflag=) at Python/ceval.c:2836
#12 0x00007ffff7a5d859 in PyEval_EvalCodeEx (_co=0x7ffffffe9670, _co@entry=0x7ffff7e4a660, globals=0x7ffff7e48db0, locals=0x7ffff010f1c0, args=0x7ffff7eaadc8, argcount=170096, argcount@entry=1, kws=0x29fe0,
kwcount=0, defs=0x7ffff7e496f0, defcount=4, kwdefs=0x0, closure=0x0) at Python/ceval.c:3585
#13 0x00007ffff7a5b95f in fast_function (nk=1, na=1, n=, pp_stack=0x7fffffffdf30, func=) at Python/ceval.c:4341
#14 call_function (oparg=, pp_stack=0x7fffffffdf30) at Python/ceval.c:4259
#15 PyEval_EvalFrameEx (f=f@entry=0xc0b0d8, throwflag=throwflag@entry=0) at Python/ceval.c:2836
#16 0x00007ffff7a5c2b2 in fast_function (nk=, na=, n=0, pp_stack=0x7fffffffe050, func=) at Python/ceval.c:4331
#17 call_function (oparg=, pp_stack=0x7fffffffe050) at Python/ceval.c:4259
#18 PyEval_EvalFrameEx (f=0x7ffff7f45438, throwflag=) at Python/ceval.c:2836
#19 0x00007ffff7a5d859 in PyEval_EvalCodeEx (_co=0x7ffffffe9670, _co@entry=0x7ffff7ed6c00, globals=0x0, locals=0x7ffff7f455b0, args=0x0, argcount=170096, argcount@entry=0, kws=0x29fe0, kws@entry=0x0, kwcount=0,
defs=0x0, defcount=0, kwdefs=0x0, closure=0x0) at Python/ceval.c:3585
#20 0x00007ffff7a5d8fb in PyEval_EvalCode (co=co@entry=0x7ffff7ed6c00, globals=globals@entry=0x7ffff7f42508, locals=locals@entry=0x7ffff7f42508) at Python/ceval.c:773
#21 0x00007ffff7a79bb4 in run_mod (mod=mod@entry=0x6fb3a8, filename=filename@entry=0x7ffff7e489b0, globals=globals@entry=0x7ffff7f42508, locals=locals@entry=0x7ffff7f42508, flags=flags@entry=0x7fffffffe2d0,
arena=arena@entry=0x6c8fe0) at Python/pythonrun.c:2180
#22 0x00007ffff7a7bde5 in PyRun_FileExFlags (fp=0x677850, filename_str=, start=, globals=0x7ffff7f42508, locals=0x7ffff7f42508, closeit=1, flags=0x7fffffffe2d0)
at Python/pythonrun.c:2133
#23 0x00007ffff7a7cdb3 in PyRun_SimpleFileExFlags (fp=0x7ffffffe9670, filename=0x7ffff7f393b0 "triangle-ex4.py", closeit=1, flags=0xc38780) at Python/pythonrun.c:1606
#24 0x00007ffff7a9301c in run_file (p_cf=, filename=, fp=) at Modules/main.c:319
#25 Py_Main (argc=-136017680, argv=0x7ffff7f39390) at Modules/main.c:751
#26 0x0000000000400af6 in main ()
(gdb)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.