pydistmesh
pydistmesh copied to clipboard
Is 1D mesh generation possible using dishmeshnd ?
This is more of a question than an issue. I seen on this presentation that 1D mesh generation is possible with the MATLAB code (page 20, http://www2.imm.dtu.dk/~apek/DGFEMCourse2009/Lecture06.pdf). Is this also possible with pydistmesh?
@danieljfarrell I don't think 1-d currently works, because we use the Delaunay triangulation routines provided in SciPy. Here SciPy wraps Qhull which is for 2-d, 3-d, and higher.
>>> import numpy as np
>>> from distmesh import distmeshnd
>>> d = lambda p: np.sqrt((p**2).sum(1))-1.0
>>> h = lambda p: np.sqrt((p**2).sum(1))+1.0
>>> p, t = distmeshnd(d, h, 0.1, [-1, 1])
Plotting only supported in dimensions 2 and 3.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/distmesh/_distmeshnd.py", line 125, in distmeshnd
t = spspatial.Delaunay(p).vertices # List of triangles
File "qhull.pyx", line 996, in scipy.spatial.qhull.Delaunay.__init__ (scipy/spatial/qhull.c:4496)
File "qhull.pyx", line 166, in scipy.spatial.qhull._construct_delaunay (scipy/spatial/qhull.c:1536)
ValueError: Need at least 2-D data to triangulate
Certainly we could implement our own simple 1-d delaunay triangulation --- should be pretty simple! In 1-D the triangulation algorithm just needs to sort the points and return a list of consecutive indices in the sorted points. For instance, something like t = p.argsort(); t = np.vstack((t[:-1], t[1:])).T
. Feel free to play around and submit a pull request.