Skip to content

Commit fd62455

Browse files
committed
Improve documentation and README
1 parent 11831af commit fd62455

File tree

2 files changed

+82
-9
lines changed

2 files changed

+82
-9
lines changed

README.md

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![pipeline](https://github.com/TUM-LNM/biomesh/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/TUM-LNM/biomesh/actions/workflows/build_and_test.yml)
44

5-
## Installation
5+
## :rocket: Installation
66

77
biomesh can be installed via pip as
88

@@ -16,27 +16,100 @@ If you want to generate a mesh with Gmsh, you also need to install the gmsh pyth
1616
pip install gmsh
1717
```
1818

19-
## Usage
19+
## :book: Usage
2020

21-
To generate a finite element mesh from multiple colored stl-files, you simply need to do
21+
`biomesh` is composed of multiple utilities for working with complex biomechanical geometries. Below
22+
are some common workflows
23+
24+
### Generate a mesh from colored STL files
25+
26+
Colored STL-files (e.g., exported from Materialize 3-Matic) can be used to generate a volume mesh.
27+
Although STL color encoding is not standardized, some software packages embed surface Ids in unused
28+
byte fields. `biomesh` leverages this to extract surface information.
29+
30+
:point_right: Generating a mesh from stl-files requires the `gmsh` Python package.
2231

2332
```python
2433
import biomesh
2534

26-
# note, this requires gmsh to be installed (pip install gmsh)
2735
mesh = biomesh.mesh_colored_stl_files(
2836
"path/to/part1.stl",
2937
"path/to/part2.stl",
3038
"path/to/part3.stl",
3139
mesh_size=2.0
3240
)
33-
# alternatively, you can also just use meshio to load a mesh: mesh = meshio.read("path/to/mesh.vtu")
41+
```
42+
43+
Alternatively, you can load the meshes from any format supported by [meshio](https://github.com/nschloe/meshio):
44+
45+
```python
46+
import meshio
47+
48+
meshio.read("path/to/mesh.vtu")
49+
```
50+
51+
### Convert linear to quadratic elements
3452

35-
# make all elements quadratic
53+
Convert linear elements in your mesh to quadratic ones:
54+
55+
```python
3656
mesh = biomesh.lin_to_quad(mesh)
57+
```
58+
59+
### Reorder mesh nodes
60+
61+
Finite element solvers often benefit from reducing bandwidth in the system matrix. `biomesh` provides
62+
a node reordering algorithm based on Cuthill-McKee's algorithm to improve efficiency:
3763

38-
# reorder nodes to reduce bandwidth of matrix
64+
```python
3965
mesh = biomesh.reorder(mesh)
4066
```
4167

42-
The nodes of all stl-files are matched. Each stl-file will be considered as an own volume.
68+
### Merge multiple meshes
69+
70+
Combine several meshes into a single mesh object:
71+
72+
```python
73+
mesh_all = biomesh.merge(mesh1, mesh2, mesh3)
74+
```
75+
76+
:warning: Overlapping points are **not** automatically merged.
77+
78+
### Filtera mesh
79+
80+
Extract a subset of a mesh using flexible filters. For example, filtering by cell type:
81+
82+
```python
83+
# keep only hexahedral cells
84+
filter_hex = lambda block : block.type == 'hexahedron'
85+
mesh_filtered = biomesh.filter.by_cellblock(mesh, filter_hex)
86+
87+
# Get point mapping from old -> new Ids
88+
point_mapping = biomesh.filter.points_map_by_cellblock(mesh, filter_hex)
89+
```
90+
91+
### Solve simple Laplace problem
92+
93+
`biomesh` can also solve basic Laplace problems, commonly used to estimate fiber directions with
94+
rule based methods.
95+
96+
```python
97+
dbc_nodes = np.array([0, 1, 2, 4])
98+
dbc_values = np.array([0.0, 0.0, 1.0, 1.0])
99+
100+
phi = biomesh.solve(mesh, dbc_nodes, dbc_values)
101+
102+
# or equivalently
103+
phi = biomesh.solve_onezero(mesh, np.array([2, 4]), np.array([0, 1]))
104+
```
105+
106+
The result `phi` is the solution vector of the Laplace problem.
107+
108+
### Finite Element Utilities
109+
110+
`biomesh.fe` provides helper functions for finite element analysis. For example, compute the nodal
111+
averaged gradient of a scalar field:
112+
113+
```python
114+
grad_phi = biomesh.fe.grad(mesh, phi)
115+
```

biomesh/reorder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def build_csr_from_multiple_elements(
5050
return sp.csr_array((data, indices, indptr), shape=(n_nodes, n_nodes))
5151

5252

53-
def reorder(mesh: meshio.Mesh) -> None:
53+
def reorder(mesh: meshio.Mesh) -> meshio.Mesh:
5454
"""Reorder the nodes of a mesh in-place to minimize the bandwidth of the
5555
adjacency matrix.
5656

0 commit comments

Comments
 (0)