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.3.tar.gz (56.3 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.3-py3-none-any.whl (51.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyvista_gridder-0.5.3.tar.gz
  • Upload date:
  • Size: 56.3 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.3.tar.gz
Algorithm Hash digest
SHA256 ee991d5d8e5d3f56d4d29b136d51d70cdae55bc877a1af727b65a42a2d3961b9
MD5 28277376ccdedbc3c3cf9133994a1087
BLAKE2b-256 675b4f9b8e5f6477ef931ddfce8b5f42c4ae7aed2792a6449298db86413ae6f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyvista_gridder-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 54e3f0f0c80fb4660b4ca53ea4af468c2cff4f03ab5b509d13a42bb2642804a0
MD5 028f0044a59c7592fb1fd2c6744a1912
BLAKE2b-256 a3cb24a100ff5823230f88236ef9aa9dac99eca1b8ef05b2aab9d73ffa347db3

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