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.5.0.tar.gz (55.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyvista_gridder-0.5.0-py3-none-any.whl (50.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyvista_gridder-0.5.0.tar.gz
  • Upload date:
  • Size: 55.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pyvista_gridder-0.5.0.tar.gz
Algorithm Hash digest
SHA256 78ac7305bf4bbef9b1fd1ca3c52851f9a609fa4acd69dd682bd2cd5ccd7b3e49
MD5 624edc4accb676ba4dbd32b8c8ad1df9
BLAKE2b-256 578f9acb3081ba5d8ed9b7fe80f5aea461f9dfb41a5538a0ff0d1d004663c03c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyvista_gridder-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32d5714580d93785798dcf97082bf833b303520ea91f2ebe8be4be2dae9de31f
MD5 eabc8348c5589bb62999e3e5dc4dd51f
BLAKE2b-256 f378ac14449c69b3cbd02f0912f2f139c9939c029f780e10d69a72ee071d4970

See more details on using hashes here.

Supported by

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