Skip to main content

PyDistMesh is a simple Python code for generating unstructured triangular and tetrahedral meshes using signed distance functions. It intends to have the same functionality as and similar interface to the MATLAB-based DistMesh. Like DistMesh, upon which it is based, PyDistMesh is distributed under the GNU GPL.

2-D Examples

  • Uniform Mesh on Unit Circle:

    >>> import distmesh as dm
    >>> import numpy as np
    >>> fd = lambda p: np.sqrt((p**2).sum(1))-1.0
    >>> p, t = dm.distmesh2d(fd, dm.huniform, 0.2, (-1,-1,1,1))
  • Rectangle with circular hole, refined at circle boundary:

    >>> import distmesh as dm
    >>> fd = lambda p: dm.ddiff(dm.drectangle(p,-1,1,-1,1),
    ...                         dm.dcircle(p,0,0,0.5))
    >>> fh = lambda p: 0.05+0.3*dm.dcircle(p,0,0,0.5)
    >>> p, t = dm.distmesh2d(fd, fh, 0.05, (-1,-1,1,1),
    ...                      [(-1,-1),(-1,1),(1,-1),(1,1)])

3-D Examples

  • 3-D Unit ball:

    >>> import distmesh as dm
    >>> import numpy as np
    >>> fd = lambda p: np.sqrt((p**2).sum(1))-1.0
    >>> p, t = dm.distmeshnd(fd, dm.huniform, 0.2, (-1,-1,-1, 1,1,1))
  • Cylinder with hole:

    >>> import distmesh as dm
    >>> import numpy as np
    >>> def fd10(p):
    ...     r, z = np.sqrt(p[:,0]**2 + p[:,1]**2), p[:,2]
    ...     d1, d2, d3 = r-1.0, z-1.0, -z-1.0
    ...     d4, d5 = np.sqrt(d1**2+d2**2), np.sqrt(d1**2+d3**2)
    ...     d = dm.dintersect(dm.dintersect(d1, d2), d3)
    ...     ix = (d1>0)*(d2>0); d[ix] = d4[ix]
    ...     ix = (d1>0)*(d3>0); d[ix] = d5[ix]
    ...     return dm.ddiff(d, dm.dsphere(p, 0,0,0, 0.5))
    >>> def fh10(p):
    ...     h1 = 4*np.sqrt((p**2).sum(1))-1.0
    ...     return np.minimum(h1, 2.0)
    >>> p, t = dm.distmeshnd(fd10, fh10, 0.1, (-1,-1,-1, 1,1,1))

Demos

For a quick demonstration, run:

$ python -m distmesh.demo2d

or:

$ python -m distmesh.demond

Dependencies

PyDistMesh is compatible with both Python 2 and Python 3. (The author has only tested it in Python 2.7 and Python 3.2). It requires several common Python packages:

Building the package requires a C compiler and LAPACK. Cython, if available, can be used to rebuild the extension module bindings.

References

The DistMesh algorithm is described in the following two references. If you use the algorithm in a program or publication, please acknowledge its authors by adding a reference to the first paper below.

  • P.-O. Persson, G. Strang, A Simple Mesh Generator in MATLAB. SIAM Review, Volume 46 (2), pp. 329-345, June 2004 (PDF)

  • P.-O. Persson, Mesh Generation for Implicit Geometries. Ph.D. thesis, Department of Mathematics, MIT, Dec 2004 (PDF)

Release files for PyDistMesh 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyDistMesh 1.2
File Size Uploaded
PyDistMesh-1.2.tar.gz 53.9 kB Details

Release files / PyDistMesh-1.2.tar.gz

Download URL PyDistMesh-1.2.tar.gz
Size 53.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f45010037c312f21f742ec83e640eda314455f4428a9c46567f128c82600d986
BLAKE2b-256 checksum
How to use checksums
393cfef5c2f4882128e093ec308c2c0c29a37a1f5001a03423863728b0c8c000
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.2 This release

1 release file

1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page