Giter VIP home page Giter VIP logo

meshwell's Introduction

Meshwell


Docs Tests PiPy

Project is under active development, stay tuned for improved features, documentation, and releases!

Meshwell is a Python wrapper around GMSH that provides:

(1) a Prism class that simplifies, to the point of automating, the definition of solids from arbitrary (multi)polygons with "buffered" extrusions;

(2) a simple API where such Prisms and regular GMSH OCC objects are specified in an ordered dictionary of mesh priority, and whose keys are then used to label the mesh entities and their interfaces unambiguously;

For instance:

See the documentation for more information and examples. If you encounter a big, you can make an issue so we can improve the software over time. Contributions are also welcome, see open issues for current bugs and requested features.

Background

This code was originally developed to define meshes out of the GDSII descriptions of integrated photonic circuits. A particularity of such devices is rich 2.5D topology, featuring multiple layers of smooth curves in the plane and etching profiles vertically. Maxwell's equations (hence the name) are solved on these geometries to study how light propagates. It is also of critical interest to simulate how this is affected under other physical effects that can be resolved through finite-element or finite-volume analysis.

Related projects

  • gdsfactory: open-source plugin-rich layout software; meshwell is the backend to gplugins' gmsh module
  • femwell: open-source scikit-fem based finite-element simulations, with emphasis on photonics
  • DEVSIM: open-source finite-volume simulator, with emphasis on semiconductor TCAD

Other notable GMSH Python interfaces:

  • gmsh: the gmsh Python API itself has significantly improved over the years
  • pygmsh: manipulate Python objects instead of gmsh entity tags
  • objectgmsh: class wrappers around entities
  • gyptis: uses basic gmsh for photonic geometries

Acknowledgements

  • Simon Bilodeau (Princeton): maintainer
  • Helge Gehring (Google X): beta testing, use cases, bug fixes, improvements
  • Joaquin Matres Abril (Google X): code improvements
  • Niko Savola (Google): beta testing, use cases, bug fixes, improvements

meshwell's People

Contributors

dependabot[bot] avatar helgegehring avatar nikosavola avatar simbilod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

meshwell's Issues

Lower dimensional physicals

A nice feature of the previous iteration of this code was the ability to pass, for instance, 1D objects to a 2D mesh, and have them be conformal and properly tagged as physical. This can replace the current hack for boundary conditions, and allow e.g. sources and monitors to be defined.

This can probably be achieved here with recursive labeled entities

@HelgeGehring

Documentation

  • Add base documentation with examples
  • Improve documentation

Speedup `_add_volume`

Speedup the inner loop in _add_volume.
Ideas to try:

  • Parallelise
  • Numba
  • Pybindings C++

Address interfaces with mesh resolutions

Currently, the mesh resolutions appear to work only for the main given entities and not the generated interfaces.
For example, in

resolutions = {
    "bw": {
        "resolution": 50,
    },
    'substrate': {
        "resolution": 50,
    },
    'bw___substrate': {
        "resolution": 1,
    },
}

The bw___substrate resolution is not taken into account.

Improve API

Collecting possible API improvements:

  • Physical names could be entity attributes, as well as mesh_order, and use instead of OrderedDict?

Parallelize meshing

Seems the meshing is not currently parallelized.
I think this can be done with just gmsh.option.setNumber("General.NumThreads", N). Not sure how parallelized the default algorithms are but should start here.

separate CAD definition and meshing

this would be useful if we wanted to generate multiple different meshes from the same resulting CAD, since sometimes the booleans take a while

Support anisotropic meshes

It is very often the case that the we have thin layers in z with large x-y extent

It would be desirable to have a fine mesh in z, and coarser in x-y in these cases

Things to investigate:

  • Structured extrusions (foregoing some flexibility with sidewalls)
  • Anisotropic remeshing with mmg

Adaptive mesh refinement

It is required for some applications, after the initial meshing, to remesh according to the result of simulations

Earlier versions of this code used callbacks for this, but it is too slow and approximate, because it makes a new mesh every time. Would be great to remesh the existing mesh.

See for example:

The desired API could be similar to above:

  • user gives a grid of (x, y, z, lc) coordinates, with lc the desired "mesh size" at the x, y, z positions;

or

  • user gives a grid of (x, y, z) coordinates where the existing mesh should be split

@SkandanC

gmsh 4.12

New release has added OCC curve orientation, maybe we need to account for that

better visualization

(1) We could wrap the gmsh GUI executable here, and script some useful commands (e.g. coloring entities by physical group)

(2) We could better develop notebook-based visualization

Speedup definition of complex geometries

The current way of defining volumes "bottom-up" works great for small geometries

For geometries with a lot of entities, this can be very slow. We should investigate alternatives to speed this up:

  • See if meshwell object definition can be parallelized
  • Allow a formulation of the CAD through extrusions (ignoring arbitrary side profiles)

@HelgeGehring

Fix tests

New interface breaks old tests, write new tests eventually

Fix using Meshwell in Ray

Meshwell meshing fails for me when running in Ray

    component.to_gmsh(
  File "/usr/local/home/nikosavola/dev/gdsfactory/gdsfactory/component.py", line 2548, in to_gmsh
    return xyz_mesh(padded_component, layer_stack, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/nikosavola/dev/gdsfactory/gdsfactory/simulation/gmsh/xyz_mesh.py", line 145, in xyz_mesh
    mesh_out = model.mesh(
               ^^^^^^^^^^^
  File "/usr/local/home/nikosavola/dev/meshwell/meshwell/model.py", line 289, in mesh
    gmsh.finalize()
  File "/usr/local/home/nikosavola/venv/gdsfactory/lib/python3.11/site-packages/gmsh.py", line 316, in finalize
    signal.signal(signal.SIGINT, oldsig)
  File "/usr/lib/python3.11/signal.py", line 56, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: signal only works in main thread of the main interpreter

The issue is documented in https://gitlab.onelab.info/gmsh/gmsh/-/issues/2399 and the solution is to use new initialization with gmsh.intialize(interruptible=False). This argument however is not in a release version of gmsh.

Faster booleans

We should optimize the loop of cuts to better leverage the OCC parallelization

manual refinement object

Currently, manual refinement is only possible on the physical entities

It would be good to add a new type of Prism/Polysurface that locally changes the mesh resolution settings, without disturbing the "physical" Prisms/Polysurface

Instanciating the intersection of these "refinement physicals" and the actual geometry (defining new _refined physicals) could be a simple hack to achieve this

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.