Skip to main content

Mesh generation using PyVista

Project description

PyVista Gridder

License Stars Pyversions Version Downloads Code style: black

Structured and unstructured mesh generation using PyVista for the Finite-Element (FEM), Finite-Difference (FDM), and Finite-Volume Methods (FVM).

Features

  • Pre-Meshed Geometric Objects: Easily create basic geometric objects with pre-defined meshes, using structured grids whenever possible.
  • Line/Polyline Extrusion: Extrude lines or polylines into 2D structured grids.
  • Surface Extrusion: Extrude surface meshes into volumetric meshes while preserving their original type.
  • 1.5D/2.5D Mesh Creation: Generate meshes by stacking polylines or surfaces, ideal for geological modeling and similar applications.
  • 2D Voronoi Mesh Generation: Create 2D Voronoi meshes from a background mesh, with support for adding constraint points to define custom shapes.
  • Mesh Merging: Combine multiple PyVista meshes into a single mesh and assign cell groups, leaving conformity checks to the user.
  • Additional Utility Functions: Includes tools to manipulate structured and unstructured grids.

Installation

The recommended way to install pyvista-gridder and all its dependencies is through the Python Package Index:

pip install pyvista-gridder --user

Otherwise, clone and extract the package, then run from the package location:

pip install .[full] --user

To test the integrity of the installed package, check out this repository and run:

pytest

Examples

2D structured grid

import numpy as np
import pyvista as pv
import pvgridder as pvg

mesh = (
   pvg.MeshStack2D(pv.Line([-3.14, 0.0, 0.0], [3.14, 0.0, 0.0], resolution=41))
   .add(0.0)
   .add(lambda x, y, z: np.cos(x) + 1.0, 4, group="Layer 1")
   .add(0.5, 2, group="Layer 2")
   .add(0.5, 2, group="Layer 3")
   .add(0.5, 2, group="Layer 4")
   .add(lambda x, y, z: np.full_like(x, 3.4), 4, group="Layer 5")
   .generate_mesh()
)
mesh.plot(show_edges=True, scalars=pvg.get_cell_group(mesh))

anticline

2D Voronoi mesh

import numpy as np
import pyvista as pv
import pvgridder as pvg

smile_radius = 0.64
smile_points = [
   (smile_radius * np.cos(theta), smile_radius * np.sin(theta), 0.0)
   for theta in np.deg2rad(np.linspace(200.0, 340.0, 32))
]
mesh = (
   pvg.VoronoiMesh2D(pvg.Annulus(0.0, 1.0, 16, 32), default_group="Face")
   .add_circle(0.16, plain=False, resolution=16, center=(-0.32, 0.32, 0.0), group="Eye")
   .add_circle(0.16, plain=True, resolution=16, center=(0.32, 0.32, 0.0), group="Eye")
   .add_polyline(smile_points, width=0.05, group="Mouth")
   .generate_mesh()
)
mesh.plot(show_edges=True, scalars=pvg.get_cell_group(mesh))

nightmare-fuel

2.5D geological model

import pyvista as pv
import pvgridder as pvg

terrain = pv.examples.download_crater_topo().extract_subset(
   (500, 900, 400, 800, 0, 0), (10, 10, 1)
)
terrain_delaunay = pvg.Polygon(terrain, celltype="triangle")
terrain = terrain.cast_to_structured_grid().warp_by_scalar("scalar1of1")

mesh = (
   pvg.MeshStack3D(
      pvg.VoronoiMesh2D(terrain_delaunay, preference="point").generate_mesh()
   )
   .add(0.0)
   .add(terrain.translate((0.0, 0.0, -1000.0)), 5, method="log_r", group="Bottom layer")
   .add(500.0, 5, group="Middle layer")
   .add(terrain, 5, method="log", group="Top Layer")
   .generate_mesh()
)
mesh.plot(show_edges=True, scalars=pvg.get_cell_group(mesh))

topographic-terrain

Acknowledgements

This project is supported by Nagra (National Cooperative for the Disposal of Radioactive Waste), Switzerland.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvista_gridder-0.4.2.tar.gz (54.0 kB view details)

Uploaded Source

Built Distribution

pyvista_gridder-0.4.2-py3-none-any.whl (48.9 kB view details)

Uploaded Python 3

File details

Details for the file pyvista_gridder-0.4.2.tar.gz.

File metadata

  • Download URL: pyvista_gridder-0.4.2.tar.gz
  • Upload date:
  • Size: 54.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyvista_gridder-0.4.2.tar.gz
Algorithm Hash digest
SHA256 ab36da58269d3910ff865bb11081fcf7db3b67ace9a2e515e38aa853942db93e
MD5 ac23f039f1a4873d04d714726b9eb1f5
BLAKE2b-256 44dbdc210676f56efbe8c6f36fbf9f1ee4a32358fd74c09824580403e0034182

See more details on using hashes here.

File details

Details for the file pyvista_gridder-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyvista_gridder-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3abb38fb50aa4bc9dbaf344f221ab7ebd094f07ef3e6dbdbb7a799b2dc75572f
MD5 54e275d560bae9e56aa1c7d9bfa940f5
BLAKE2b-256 4a1f011a5e029a3f86379403318782bcff45dfaf106ee0ce885d2982f8896f2c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page