Skip to content
Snippets Groups Projects
Commit d7abda65 authored by Florian Zill's avatar Florian Zill
Browse files

[meshlib] introducing typechecked

parent bd16d9f8
No related branches found
No related tags found
1 merge request!134MeshSeries aggregation function
......@@ -5,6 +5,7 @@ from typing import Union
import numpy as np
import pyvista as pv
from ogs import cli
from typeguard import typechecked
class Surface:
......@@ -19,11 +20,8 @@ class Surface:
def material_id(self) -> int:
return self._material_id
def __init__(
self,
input: Union[Path, pv.DataSet],
material_id: int,
):
@typechecked
def __init__(self, input: Union[Path, pv.DataSet], material_id: int):
"""Initialize a surface mesh. Either from pyvista or from a file."""
self._material_id = material_id
......@@ -37,11 +35,6 @@ class Surface:
self.mesh = input
self.filename = Path(tempfile.mkstemp(".vtu", "surface")[1])
pv.save_meshio(self.filename, self.mesh, file_format="vtu")
else:
msg = "{} given, must be either Path or pyvista Dataset.".format(
self.filename
)
raise ValueError(msg)
self.mesh.cell_data["MaterialIDs"] = (
np.ones(self.mesh.n_cells) * self.material_id
......
......@@ -3,6 +3,7 @@ from typing import Optional, Union
import numpy as np
import pyvista as pv
from typeguard import typechecked
from ogstools.propertylib import Property
......@@ -85,7 +86,7 @@ def difference_pairwise(
)
# TODO: let this also return meshes and a property
@typechecked
def difference_matrix(
meshes_1: Union[list, np.ndarray],
meshes_2: Optional[Union[list, np.ndarray]] = None,
......@@ -104,13 +105,7 @@ def difference_matrix(
or all datasets between meshes_1 and meshes_2 for all possible
combinations.
"""
if not isinstance(meshes_1, (list, np.ndarray)):
msg = "mesh1 is neither of type list nor np.ndarray" # type: ignore[unreachable]
raise TypeError(msg)
meshes_1 = np.asarray(meshes_1).flatten()
if not isinstance(meshes_2, (list, np.ndarray)) and meshes_2 is not None:
msg = "mesh2 is neither of type list nor np.ndarray." # type: ignore[unreachable]
raise TypeError(msg)
if meshes_2 is None:
meshes_2 = meshes_1.copy()
meshes_2 = np.asarray(meshes_2).flatten()
......
......@@ -26,6 +26,7 @@ dependencies = [
"ogs>=6.5.1.dev0",
"ogs6py>=0.370",
"tqdm>=4.60",
"typeguard>=4.0.0",
"VTUinterface>=0.704",
]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment