Skip to main content

Create meshes from segmented imaging data for finite element simulations using Gmsh.

Project description

biomesh

pipeline

:rocket: Installation

biomesh can be installed via pip as

pip install biomesh

If you want to generate a mesh with Gmsh, you also need to install the gmsh python library as

pip install gmsh

:book: Usage

biomesh is composed of multiple utilities for working with complex biomechanical geometries. Below are some common workflows

Generate a mesh from colored STL files

Colored STL-files (e.g., exported from Materialise 3-matic) can be used to generate a volume mesh. Although STL color encoding is not standardized, some software packages embed surface IDs in unused byte fields. biomesh leverages this to extract surface information.

:point_right: Generating a mesh from stl-files requires the gmsh Python package.

import biomesh

mesh = biomesh.mesh_colored_stl_files(
    "path/to/part1.stl",
    "path/to/part2.stl",
    "path/to/part3.stl",
    mesh_size=2.0
)

Alternatively, you can load the meshes from any format supported by meshio:

import meshio

meshio.read("path/to/mesh.vtu")

Convert linear to quadratic elements

Convert linear elements in your mesh to quadratic ones:

mesh = biomesh.lin_to_quad(mesh)

Reorder mesh nodes

Finite element solvers often benefit from reducing bandwidth in the system matrix. biomesh provides a node reordering algorithm based on Cuthill-McKee's algorithm to improve efficiency:

mesh = biomesh.reorder(mesh)

Merge multiple meshes

Combine several meshes into a single mesh object:

mesh_all = biomesh.merge(mesh1, mesh2, mesh3)

:warning: Overlapping points are not automatically merged.

Filter a mesh

Extract a subset of a mesh using flexible filters. For example, filtering by cell type:

# keep only hexahedral cells
filter_hex = lambda block : block.type == 'hexahedron'
mesh_filtered = biomesh.filter.by_cellblock(mesh, filter_hex)

# Get point mapping from old -> new IDs
point_mapping = biomesh.filter.points_map_by_cellblock(mesh, filter_hex)

Solve simple Laplace problem

biomesh can also solve basic Laplace problems, commonly used to estimate fiber directions with rule based methods.

dbc_nodes = np.array([0, 1, 2, 4])
dbc_values = np.array([0.0, 0.0, 1.0, 1.0])

phi = biomesh.solve(mesh, dbc_nodes, dbc_values)

# or equivalently
phi = biomesh.solve_onezero(mesh, np.array([2, 4]), np.array([0, 1]))

The result phi is the solution vector of the Laplace problem.

Finite Element Utilities

biomesh.fe provides helper functions for finite element analysis. For example, compute the nodal averaged gradient of a scalar field:

grad_phi = biomesh.fe.grad(mesh, phi)

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

biomesh-0.5.0.tar.gz (99.3 kB view details)

Uploaded Source

Built Distribution

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

biomesh-0.5.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: biomesh-0.5.0.tar.gz
  • Upload date:
  • Size: 99.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for biomesh-0.5.0.tar.gz
Algorithm Hash digest
SHA256 b7f3475e27d8f4d1e355123a28296d29e0a1a7bcaf1a9db96c113febfa803414
MD5 c445bdc637002ebd74e72bd2ab531486
BLAKE2b-256 9bca8405bc469b245975a7875d03b91ae9360ec1188f9e79bcf89fe123f4273d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: biomesh-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for biomesh-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4418b22b8c2abbb8a66b74f799eb22eb682d98e411a750ac1773a526146e0778
MD5 d3cffd86ff31eae3deeeb0d80a73e3fa
BLAKE2b-256 bf1678ad6b26bfc1fc5389fc33f53188f63797b607629d3f7de451a1ef919cbf

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