Git Product home page Git Product logo

pydistmesh's Introduction

PyDistMesh: A Simple Mesh Generator in Python

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, fig = dm.distmesh2d(fd, dm.huniform, 0.2, (-1,-1,1,1))
    >>> fig.savefig("output.png")
    
  • 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, fig = dm.distmesh2d(fd, fh, 0.05, (-1,-1,1,1),
    ...                          [(-1,-1),(-1,1),(1,-1),(1,1)])
    >>> fig.savefig("output.png")
    

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, fig = 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, fig = 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.

Installing

Install pydistmesh:

$ python setup.py install

Building from Source/Setup for Development

You may want to do this if you are developing for pydistmesh or have made modifications.

Install pydistmesh in develop mode:

$ python setup.py develop

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)

pydistmesh's People

Contributors

bfroehle avatar bitjockey42 avatar lukeolson avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.