Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6d3e4b6
[MDPA] Improve support for Kratos Multiphysics mdpa support
loumalouomega Apr 8, 2026
7fcc014
Refactor type assertions and clean up temporary file handling in MDPA…
loumalouomega Apr 8, 2026
18a9b7c
Fix formatting in _create_component_names function for improved reada…
loumalouomega Apr 8, 2026
843aacc
Several fixes
loumalouomega Apr 8, 2026
f74d82d
Fix formatting in _create_component_names function for improved reada…
loumalouomega Apr 8, 2026
1b1b8b4
Several fixes
loumalouomega Apr 8, 2026
40fcb78
Fix type checking for integer values in read_buffer function
loumalouomega Apr 8, 2026
cf5c8da
fix: Python 3.8 compatibility and CI issues
loumalouomega Apr 8, 2026
a415214
style: run linters (black, flake8) and fix linting errors
loumalouomega Apr 8, 2026
6e7c7f0
style: fix black formatting in paraview-meshio-plugin.py via pre-commit
loumalouomega Apr 8, 2026
7d1efb3
fix: additional Python 3.8 compatibility issues
loumalouomega Apr 8, 2026
d92d462
style: fix isort and black issues
loumalouomega Apr 8, 2026
b0ef37a
style: add future annotations to various modules
loumalouomega Apr 8, 2026
a5ef8b2
style: update format specifiers from repr to str in various files
loumalouomega Apr 8, 2026
941e456
style: fix formatting of smdomain.xml decorator in MeshioReader class
loumalouomega Apr 8, 2026
a37a5a1
style: add exclusion for venv and .tox in flake8 configuration
loumalouomega Apr 8, 2026
1d1725a
style: update dependencies in tox.ini and comment out extras
loumalouomega Apr 8, 2026
6e382bd
style: remove future annotations from multiple files
loumalouomega Apr 8, 2026
5bcb35c
Merge branch 'minor-fixes-main' into improve-mdpa-format-support
loumalouomega Apr 8, 2026
0666fcd
style: remove unnecessary binary print options from Gmsh write functi…
loumalouomega Apr 8, 2026
64212cc
style: format string split for improved readability in test_mdpa.py
loumalouomega Apr 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[flake8]
exclude = venv, .tox
ignore = E203, E266, E501, W503, C901, E741
max-line-length = 88
max-complexity = 18
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ jobs:
- name: Test with tox
run: |
pip install tox
tox -- --cov meshio --cov-report xml --cov-report term
tox -e py${{ matrix.python-version == '3.8' && '38' || '312' }} -- --cov meshio --cov-report xml --cov-report term
- uses: codecov/codecov-action@v3
if: ${{ matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest' }}
13 changes: 8 additions & 5 deletions src/meshio/__about__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
try:
# Python 3.8+
from importlib import metadata
except ImportError:
try:
import importlib_metadata as metadata
except ImportError:
__version__ = "unknown"
metadata = None

try:
__version__ = metadata.version("meshio")
except Exception:

if metadata is not None:
try:
__version__ = metadata.version("meshio")
except Exception:
__version__ = "unknown"
else:
__version__ = "unknown"
2 changes: 1 addition & 1 deletion src/meshio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
write,
write_points_cells,
)
from ._mesh import CellBlock, Mesh
from ._mesh import CellBlock, Mesh, topological_dimension

__all__ = [
"abaqus",
Expand Down
5 changes: 2 additions & 3 deletions src/meshio/_cli/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ def main(argv=None):
help="display version information",
)

subparsers = parent_parser.add_subparsers(
title="subcommands", dest="command", required=True
)
subparsers = parent_parser.add_subparsers(title="subcommands", dest="command")
subparsers.required = True

parser = subparsers.add_parser("convert", help="Convert mesh files", aliases=["c"])
_convert.add_args(parser)
Expand Down
27 changes: 13 additions & 14 deletions src/meshio/_helpers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import annotations

import sys
from pathlib import Path
from typing import Union

import numpy as np
from numpy.typing import ArrayLike

from ._common import error, num_nodes_per_cell
from ._common import num_nodes_per_cell
from ._exceptions import ReadError, WriteError
from ._files import is_buffer
from ._mesh import CellBlock, Mesh
Expand Down Expand Up @@ -57,7 +57,7 @@ def _filetypes_from_path(path: Path) -> list[str]:
return out


def read(filename, file_format: str | None = None):
def read(filename, file_format: Union[str, None] = None):
"""Reads an unstructured mesh with added data.

:param filenames: The files/PathLikes to read from.
Expand All @@ -71,7 +71,7 @@ def read(filename, file_format: str | None = None):
return _read_file(Path(filename), file_format)


def _read_buffer(filename, file_format: str | None):
def _read_buffer(filename, file_format: Union[str, None]):
if file_format is None:
raise ReadError("File format must be given if buffer is used")
if file_format == "tetgen":
Expand All @@ -85,7 +85,7 @@ def _read_buffer(filename, file_format: str | None):
return reader_map[file_format](filename)


def _read_file(path: Path, file_format: str | None):
def _read_file(path: Path, file_format: Union[str, None]):
if not path.exists():
raise ReadError(f"File {path} not found.")

Expand All @@ -110,20 +110,19 @@ def _read_file(path: Path, file_format: str | None):
lst = ", ".join(possible_file_formats)
msg = f"Couldn't read file {path} as either of {lst}"

error(msg)
sys.exit(1)
raise ReadError(msg)


def write_points_cells(
filename,
points: ArrayLike,
cells: dict[str, ArrayLike] | list[tuple[str, ArrayLike] | CellBlock],
point_data: dict[str, ArrayLike] | None = None,
cell_data: dict[str, list[ArrayLike]] | None = None,
cells: Union[dict[str, ArrayLike], list[Union[tuple[str, ArrayLike], CellBlock]]],
point_data: Union[dict[str, ArrayLike], None] = None,
cell_data: Union[dict[str, list[ArrayLike]], None] = None,
field_data=None,
point_sets: dict[str, ArrayLike] | None = None,
cell_sets: dict[str, list[ArrayLike]] | None = None,
file_format: str | None = None,
point_sets: Union[dict[str, ArrayLike], None] = None,
cell_sets: Union[dict[str, list[ArrayLike]], None] = None,
file_format: Union[str, None] = None,
**kwargs,
):
points = np.asarray(points)
Expand All @@ -139,7 +138,7 @@ def write_points_cells(
mesh.write(filename, file_format=file_format, **kwargs)


def write(filename, mesh: Mesh, file_format: str | None = None, **kwargs):
def write(filename, mesh: Mesh, file_format: Union[str, None] = None, **kwargs):
"""Writes mesh together with data to a file.

:params filename: File to write to.
Expand Down
21 changes: 12 additions & 9 deletions src/meshio/_mesh.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import copy
from typing import Union

import numpy as np
from numpy.typing import ArrayLike
Expand Down Expand Up @@ -86,8 +87,8 @@ class CellBlock:
def __init__(
self,
cell_type: str,
data: list | np.ndarray,
tags: list[str] | None = None,
data: Union[list, np.ndarray],
tags: Union[list[str], None] = None,
):
self.type = cell_type
self.data = data
Expand Down Expand Up @@ -117,12 +118,14 @@ class Mesh:
def __init__(
self,
points: ArrayLike,
cells: dict[str, ArrayLike] | list[tuple[str, ArrayLike] | CellBlock],
point_data: dict[str, ArrayLike] | None = None,
cell_data: dict[str, list[ArrayLike]] | None = None,
cells: Union[
dict[str, ArrayLike], list[Union[tuple[str, ArrayLike], CellBlock]]
],
point_data: Union[dict[str, ArrayLike], None] = None,
cell_data: Union[dict[str, list[ArrayLike]], None] = None,
field_data=None,
point_sets: dict[str, ArrayLike] | None = None,
cell_sets: dict[str, list[ArrayLike]] | None = None,
point_sets: Union[dict[str, ArrayLike], None] = None,
cell_sets: Union[dict[str, list[ArrayLike]], None] = None,
gmsh_periodic=None,
info=None,
):
Expand Down Expand Up @@ -234,7 +237,7 @@ def __repr__(self):
def copy(self):
return copy.deepcopy(self)

def write(self, path_or_buf, file_format: str | None = None, **kwargs):
def write(self, path_or_buf, file_format: Union[str, None] = None, **kwargs):
# avoid circular import
from ._helpers import write

Expand Down Expand Up @@ -313,7 +316,7 @@ def read(cls, path_or_buf, file_format=None):
warn("meshio.Mesh.read is deprecated, use meshio.read instead")
return read(path_or_buf, file_format)

def cell_sets_to_data(self, data_name: str | None = None):
def cell_sets_to_data(self, data_name: Union[str, None] = None):
# If possible, convert cell sets to integer cell data. This is possible if all
# cells appear exactly in one group.
default_value = -1
Expand Down
2 changes: 1 addition & 1 deletion src/meshio/dolfin/_dolfin.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _write_cell_data(filename, dim, cell_data):
)

for k, value in enumerate(cell_data):
ET.SubElement(mesh_function, "entity", index=str(k), value=repr(value))
ET.SubElement(mesh_function, "entity", index=str(k), value=str(value))

tree = ET.ElementTree(dolfin)
tree.write(filename)
Expand Down
16 changes: 12 additions & 4 deletions src/meshio/gmsh/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,17 @@ def _read_data(f, tag, data_dict, data_size, is_ascii):
num_components = integer_tags[1]
num_items = integer_tags[2]
if is_ascii:
data = np.fromfile(f, count=num_items * (1 + num_components), sep=" ").reshape(
(num_items, 1 + num_components)
)
# We need to read num_items * (1 + num_components) floats.
# np.fromfile(..., sep=" ") can be flaky if there are newlines or other
# whitespace issues.
# Instead, read the raw string and split it.
data = []
while len(data) < num_items * (1 + num_components):
line = f.readline().decode().split()
if not line:
break
data.extend([float(val) for val in line])
data = np.array(data).reshape((num_items, 1 + num_components))
# The first entry is the node number
data = data[:, 1:]
else:
Expand Down Expand Up @@ -273,7 +281,7 @@ def _write_data(fh, tag, name, data, binary):
tmp.tofile(fh)
fh.write(b"\n")
else:
fmt = " ".join(["{}"] + ["{!r}"] * num_components) + "\n"
fmt = " ".join(["{}"] + ["{!s}"] * num_components) + "\n"
# TODO unify
if num_components == 1:
for k, x in enumerate(data):
Expand Down
Loading
Loading