diff --git a/ogstools/meshlib/ip_mesh.py b/ogstools/meshlib/ip_mesh.py index 12a9ca64f8536a4022fa2cb121705e595637de93..cf24ab647b1aced1f72a359ffb4dd0b9986c7a0e 100644 --- a/ogstools/meshlib/ip_mesh.py +++ b/ogstools/meshlib/ip_mesh.py @@ -1,5 +1,4 @@ from pathlib import Path -from tempfile import mkdtemp from typing import TypeVar import numpy as np @@ -197,10 +196,10 @@ def to_ip_point_cloud(mesh: Mesh) -> pv.UnstructuredGrid: for key in bad_keys: if key in _mesh.field_data: _mesh.field_data.remove(key) - tempdir = mkdtemp(prefix="to_ip_point_cloud") - input_file = Path(tempdir) / "ipDataToPointCloud_input.vtu" + parentpath = Path() if mesh.filepath is None else mesh.filepath.parent + input_file = parentpath / "ipDataToPointCloud_input.vtu" _mesh.save(input_file) - output_file = Path(tempdir) / "ip_mesh.vtu" + output_file = parentpath / "ip_mesh.vtu" ogs.cli.ipDataToPointCloud(i=str(input_file), o=str(output_file)) return pv.XMLUnstructuredGridReader(output_file).read() diff --git a/ogstools/meshlib/mesh.py b/ogstools/meshlib/mesh.py index 8a617c65407aaebc958c68dd6e918cc3a2413155..3cc720a78d9d43223681c0968551c60cbcd3d45d 100644 --- a/ogstools/meshlib/mesh.py +++ b/ogstools/meshlib/mesh.py @@ -27,6 +27,8 @@ class Mesh(pv.UnstructuredGrid): Contains additional data and functions mainly for postprocessing. """ + filepath: Path | None = None + # pylint: disable=C0116 @copy_method_signature(data_processing.difference) def difference(self, *args: Any, **kwargs: Any) -> Any: @@ -94,6 +96,7 @@ class Mesh(pv.UnstructuredGrid): else: mesh = cls(pv.read(filepath)) + mesh.filepath = Path(filepath).with_suffix(".vtu") return mesh @classmethod diff --git a/ogstools/meshlib/mesh_series.py b/ogstools/meshlib/mesh_series.py index 9c2c78721b63ee3e97d19c868dc1addcbea533a3..23e43eaf9c4f08d255b8f4cf197633928d89e964 100644 --- a/ogstools/meshlib/mesh_series.py +++ b/ogstools/meshlib/mesh_series.py @@ -245,6 +245,10 @@ class MeshSeries: mesh = Mesh(self.mesh_func(pv_mesh)) if lazy_eval: self._mesh_cache[timevalue] = mesh + if self._data_type == "pvd": + mesh.filepath = Path(self.timestep_files[data_timestep]) + else: + mesh.filepath = Path(self.filepath) return mesh def rawdata_file(self) -> Path | None: