Skip to content

Commit 1fcfaf4

Browse files
committed
Consistently adapt docstrings
1 parent 32c8ce5 commit 1fcfaf4

File tree

10 files changed

+87
-145
lines changed

10 files changed

+87
-145
lines changed

src/biomesh/__init__.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
# See the LICENSE file in the top-level for license information.
44
#
55
# SPDX-License-Identifier: MIT
6-
"""
7-
biomesh
8-
=======
9-
10-
biomesh is a Python package for working with 3D meshes, providing tools for mesh generation, manipulation, and analysis
11-
tailored for finite element simulations of biomechanical applications.
12-
"""
6+
"""Biomesh is a Python package for working with 3D meshes, providing tools for
7+
mesh generation, manipulation, and analysis tailored for finite element
8+
simulations of biomechanical applications."""
139
from . import run_gmsh
1410
import pathlib
1511
from . import mesh
@@ -38,17 +34,14 @@ def combine_colored_stl_files(*stl_files: pathlib.Path) -> meshio.Mesh:
3834
def mesh_colored_stl_files(*stl_files: pathlib.Path, mesh_size: float) -> meshio.Mesh:
3935
"""Generate a mesh from multiple colored STL files.
4036
41-
Parameters
42-
----------
43-
*stl_files : pathlib.Path
44-
Paths to the STL files to be merged.
37+
Args
38+
*stl_files:
39+
Paths to the STL files to be merged.
4540
46-
mesh_size : float
47-
The target size for the mesh elements.
41+
mesh_size:
42+
The target size for the mesh elements.
4843
4944
Returns
50-
-------
51-
meshio.Mesh
5245
The generated mesh.
5346
"""
5447
assert len(stl_files) > 0, "At least one STL file must be provided."

src/biomesh/adapt.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,12 @@ def lin_to_quad(mesh: meshio.Mesh) -> meshio.Mesh:
8080
This function returns a new mesh in which all linear elements (triangles, quadrilaterals, tetrahedra, and hexahedra)
8181
are converted into their corresponding quadratic elements.
8282
83-
Args:
84-
-------
85-
mesh: meshio.Mesh
86-
The input mesh containing linear elements.
83+
Args
84+
mesh:
85+
The input mesh containing linear elements.
8786
8887
Returns:
89-
meshio.Mesh: The modified mesh with quadratic elements.
88+
The modified mesh with quadratic elements.
9089
"""
9190

9291
new_points = [coord for coord in mesh.points]

src/biomesh/fe.py

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,19 @@ def _create_symfem_element(cell_type: str) -> symfem.finite_element.FiniteElemen
3737
def ref_coords(cell_type: str) -> np.ndarray:
3838
"""Return the reference coordinates for the nodes of a given cell type.
3939
40-
Parameters
41-
----------
42-
cell_type : str
43-
The type of the cell. Supported values are:
44-
- "hexahedron": 8-node hexahedral element (cube).
45-
- "tetra": 4-node tetrahedral element.
46-
- "tetra10": 10-node quadratic tetrahedral element.
40+
Args
41+
cell_type:
42+
The type of the cell. Supported values are:
43+
- "hexahedron": 8-node hexahedral element (cube).
44+
- "tetra": 4-node tetrahedral element.
45+
- "tetra10": 10-node quadratic tetrahedral element.
4746
4847
Returns
49-
-------
50-
np.ndarray
5148
An array of shape (n_nodes, 3) containing the reference coordinates
5249
of the nodes for the specified cell type.
5350
5451
Raises
55-
------
56-
ValueError
57-
If the provided cell_type is not supported.
52+
ValueError: If the provided cell_type is not supported.
5853
"""
5954
element = _create_symfem_element(cell_type)
6055
return np.array(element.dof_plot_positions(), dtype=float)[
@@ -68,33 +63,27 @@ def int_points_weights(
6863
"""Compute integration (quadrature) points and weights for given cell type
6964
and number of points.
7065
71-
Parameters
72-
----------
73-
cell_type : str
74-
The type of cell for which to compute integration points and weights.
75-
Supported values are strings starting with "hexahedron" or "tetra".
76-
num_points : int
77-
The number of integration points to use.
78-
Supported values:
66+
Args
67+
cell_type:
68+
The type of cell for which to compute integration points and weights.
69+
Supported values are strings starting with "hexahedron" or "tetra".
70+
num_points
71+
The number of integration points to use.
72+
Supported values:
7973
- For "hexahedron": 1 or 8
8074
- For "tetra": 1 or 4
8175
8276
Returns
83-
-------
84-
tuple[np.ndarray, np.ndarray]
8577
A tuple containing:
8678
- points: np.ndarray of shape (num_points, dim)
8779
The coordinates of the integration points in the reference cell.
8880
- weights: np.ndarray of shape (num_points,)
8981
The corresponding integration weights.
9082
9183
Raises
92-
------
93-
ValueError
94-
If the cell type or number of points is not supported.
84+
ValueError: If the cell type or number of points is not supported.
9585
96-
Examples
97-
--------
86+
Examples:
9887
>>> points, weights = int_points_weights("hexahedron", 8)
9988
>>> points.shape
10089
(8, 3)
@@ -190,28 +179,23 @@ def shape_function_first_derivatives(cell_type: str, xi: np.ndarray) -> np.ndarr
190179
"""Compute the derivatives of shape functions with respect to the reference
191180
coordinates for various cell types.
192181
193-
Parameters
194-
----------
195-
cell_type : str
196-
The type of finite element cell. Supported values are:
197-
- "hexahedron": 8-node trilinear hexahedral element
198-
- "tetra": 4-node linear tetrahedral element
199-
- "tetra10": 10-node quadratic tetrahedral element
200-
xi : np.ndarray
201-
The local (reference) coordinates at which to evaluate the shape function derivatives.
202-
For 3D elements, this should be a 1D array of length 3: [xi, eta, zeta].
182+
Args
183+
cell_type
184+
The type of finite element cell. Supported values are:
185+
- "hexahedron": 8-node trilinear hexahedral element
186+
- "tetra": 4-node linear tetrahedral element
187+
- "tetra10": 10-node quadratic tetrahedral element
188+
xi
189+
The local (reference) coordinates at which to evaluate the shape function derivatives.
190+
For 3D elements, this should be a 1D array of length 3: [xi, eta, zeta].
203191
204192
Returns
205-
-------
206-
np.ndarray
207193
The derivatives of the shape functions with respect to the reference coordinates.
208194
The shape of the returned array is (n_nodes, 3), where n_nodes is the number of nodes
209195
for the specified cell type.
210196
211197
Raises
212-
------
213-
ValueError
214-
If an unsupported cell type is provided.
198+
ValueError: If an unsupported cell type is provided.
215199
"""
216200

217201
if cell_type not in _first_derivative_storage:
@@ -235,17 +219,11 @@ def grad(mesh: meshio.Mesh, phi: np.ndarray) -> np.ndarray:
235219
236220
The gradient is computed at the nodes where it is averaged from the surrounding elements.
237221
238-
Parameters
239-
----------
240-
mesh : meshio.Mesh
241-
The input mesh.
242-
243-
phi : np.ndarray
244-
The scalar field defined at the nodes of the mesh.
222+
Args
223+
mesh: The input mesh.
224+
phi: The scalar field defined at the nodes of the mesh.
245225
246226
Returns
247-
-------
248-
np.ndarray
249227
The gradient of the scalar field at the nodes of the mesh.
250228
"""
251229

src/biomesh/filter.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ def filter_by_cellblock_point_mapping(
2121
original number of points in the mesh. For points included in the filtered cell blocks, the array contains their new
2222
consecutive indices; for points not included, the value is -1.
2323
24-
Args:
25-
mesh: meshio.Mesh
26-
The input mesh object containing points and cell blocks.
24+
Args
25+
mesh:The input mesh object containing points and cell blocks.
2726
28-
filter: Callable[[meshio.CellBlock], bool])
29-
A function that takes a cell block and returns True if it should be included.
27+
filter: A function that takes a cell block and returns True if it should be included.
3028
3129
Returns:
32-
np.ndarray: An array of length `len(mesh.points)` where each entry is the new index of the point if it is included
33-
in the filtered cell blocks, or -1 otherwise.
30+
An array of length `len(mesh.points)` where each entry is the new index of the point if it is included
31+
in the filtered cell blocks, or -1 otherwise.
3432
"""
3533

3634
cell_filter = np.array(
@@ -66,21 +64,15 @@ def filter_by_cellblock(
6664
) -> meshio.Mesh:
6765
"""Filter a mesh to include only cells of specified types.
6866
69-
Parameters
70-
----------
71-
mesh : meshio.Mesh
72-
The input mesh to filter.
73-
filter : Callable[[meshio.CellBlock], bool]
74-
A function that takes a cell block and returns True if it should be included.
67+
Args
68+
mesh: The input mesh to filter.
69+
filter: A function that takes a cell block and returns True if it should be included.
7570
7671
Returns
77-
-------
78-
meshio.Mesh
7972
A new meshio.Mesh object containing only the cells of the specified types,
8073
with unused points removed and point/cell data filtered accordingly.
8174
8275
Notes
83-
-----
8476
- If no cells of the specified types are found, returns an empty mesh with zero points and cells.
8577
"""
8678

@@ -101,15 +93,12 @@ def filter_by_block_ids(mesh: meshio.Mesh, cellblock_ids: np.ndarray) -> meshio.
10193
10294
Given a meshio.Mesh object and an array of cell block indices, this function creates a new mesh containing only the cells from the specified cell blocks and the points referenced by those cells. The point indices are remapped so that the resulting mesh is consistent and compact. Associated point and cell data are also filtered accordingly.
10395
104-
Parameters:
105-
mesh: meshio.Mesh
106-
The input mesh from which to extract cell blocks.
107-
108-
cellblock_ids: np.ndarray
109-
An array of indices specifying which cell blocks to include in the output mesh.
96+
Args:
97+
mesh: The input mesh from which to extract cell blocks.
98+
cellblock_ids: An array of indices specifying which cell blocks to include in the output mesh.
11099
111100
Returns:
112-
meshio.Mesh: A new meshio.Mesh object containing only the specified cell blocks and their associated points and data.
101+
A new meshio.Mesh object containing only the specified cell blocks and their associated points and data.
113102
114103
Notes:
115104
- If cellblock_ids is empty, returns an empty mesh with no points or cells.

src/biomesh/laplace.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,11 @@ def get_cell_stiffness(cell_type: str, nodal_coords: np.ndarray) -> np.ndarray:
2121
"""Computes the element stiffness matrix for a finite element cell for a
2222
simple Laplace problem.
2323
24-
Parameters
25-
----------
26-
cell_type : str
27-
The type of the finite element cell (e.g., 'triangle', 'tetrahedron').
28-
nodal_coords : np.ndarray
29-
An array of shape (num_nodes, dim) containing the coordinates of the cell's nodes.
30-
31-
Returns
32-
-------
33-
np.ndarray
24+
Args:
25+
cell_type: The type of the finite element cell (e.g., 'triangle', 'tetrahedron').
26+
nodal_coords: An array of shape (num_nodes, dim) containing the coordinates of the cell's nodes.
27+
28+
Returns:
3429
The element stiffness matrix of shape (num_nodes, num_nodes) for the given cell.
3530
"""
3631

@@ -91,19 +86,15 @@ def solve_onezero(
9186
"""Solves a Laplace problem on the given mesh with Dirichlet boundary
9287
conditions set to 1 on `one_nodes` and 0 on `zero_nodes`.
9388
94-
Parameters:
95-
mesh: meshio.Mesh
96-
The mesh on which to solve the Laplace problem.
89+
Args:
90+
mesh: The mesh on which to solve the Laplace problem.
9791
98-
one_nodes: np.ndarray
99-
Array of node indices where the Dirichlet boundary condition is set to 1.
92+
one_nodes: Array of node indices where the Dirichlet boundary condition is set to 1.
10093
101-
zero_nodes: np.ndarray
102-
Array of node indices where the Dirichlet boundary condition is set to 0.
94+
zero_nodes: Array of node indices where the Dirichlet boundary condition is set to 0.
10395
10496
Returns:
105-
np.ndarray
106-
Solution array corresponding to the mesh nodes.
97+
Solution array corresponding to the mesh nodes.
10798
"""
10899
dbc_nodes = np.concatenate((np.array(one_nodes), np.array(zero_nodes)))
109100
dbc_values = np.concatenate((np.ones(len(one_nodes)), np.zeros(len(zero_nodes))))

src/biomesh/merge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ def merge(*meshes: meshio.Mesh) -> meshio.Mesh:
1515
into a new meshio.Mesh object. It handles the necessary index adjustments for points and
1616
cells, and ensures that point and cell data are correctly merged and aligned.
1717
18-
Parameters:
19-
*meshes (meshio.Mesh): Variable number of meshio.Mesh objects to merge.
18+
Args:
19+
*meshes: Variable number of meshio.Mesh objects to merge.
2020
2121
Returns:
22-
meshio.Mesh: A new meshio.Mesh object containing the merged data from all input meshes.
22+
A new meshio.Mesh object containing the merged data from all input meshes.
2323
2424
Notes:
2525
- Point and cell data arrays are padded with zeros if not present at other meshes.

src/biomesh/mesh.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,10 @@ def merge_colored_stl(
4040
) -> tuple[meshio.Mesh, list[set[int]]]:
4141
"""Merge multiple colored STL files into a single mesh.
4242
43-
Parameters
44-
----------
45-
*stl_files : str
46-
Paths to the STL files to be merged.
47-
48-
Returns
49-
-------
50-
tuple[meshio.Mesh, list[list[int]]]
43+
Args:
44+
*stl_files: Paths to the STL files to be merged.
45+
46+
Returns:
5147
The merged mesh and the surface ID mapping enclosing the different volumes define by the surface ids.
5248
"""
5349
base_mesh = lnmmeshio.read_mesh(str(base_stl), file_format="mimicsstl")

src/biomesh/reorder.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def build_csr_from_multiple_elements(
2424
) -> sp.csr_array:
2525
"""Build a CSR adjacency matrix from multiple lists of cell connectivity.
2626
27-
n_nodes: total number of nodes
28-
elements_lists: variable number of arrays/lists of elements
27+
Args:
28+
n_nodes: total number of nodes
29+
elements_lists: variable number of arrays/lists of elements
2930
"""
3031
adj = defaultdict(set)
3132

@@ -57,10 +58,11 @@ def reorder(mesh: meshio.Mesh) -> meshio.Mesh:
5758
This function uses the reverse Cuthill-McKee algorithm to find an optimal ordering
5859
of the nodes in the mesh, which is particularly useful for sparse matrices.
5960
60-
Parameters
61-
----------
62-
mesh : meshio.Mesh
63-
The mesh to be reordered.
61+
Args:
62+
mesh: The mesh to be reordered.
63+
64+
Returns:
65+
The mesh with reordered points.
6466
"""
6567
csr_array = build_csr_from_multiple_elements(
6668
len(mesh.points), *mesh.cells_dict.values()

src/biomesh/run_gmsh.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ def remesh_file(
4646
provided surface loops and applying a specified mesh size.
4747
4848
Args:
49-
file_path: pathlib.Path
49+
file_path:
5050
Path to the input mesh file to be remeshed.
5151
52-
surface_loops: list[set[int]]
52+
surface_loops:
5353
List of sets, where each set contains surface IDs to be grouped into a surface loop for volume creation.
5454
55-
mesh_size: float
55+
mesh_size:
5656
Target mesh size to be used for remeshing.
5757
5858
Returns:

0 commit comments

Comments
 (0)