From ec0cec7ef7fd58ef05c339ef71b2006eabbc8a61 Mon Sep 17 00:00:00 2001 From: volodia99 Date: Wed, 25 Sep 2024 15:37:03 +0200 Subject: [PATCH 1/3] BUG: correct vtk reader when 2D vtk_slice in spherical geometry --- pytools/vtk_io.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pytools/vtk_io.py b/pytools/vtk_io.py index 1f693318..39144827 100644 --- a/pytools/vtk_io.py +++ b/pytools/vtk_io.py @@ -243,13 +243,13 @@ def _load_hydro(self, fh): # Reconstruct the spherical coordinate system if self.geometry == "spherical": if is2d: - r = np.sqrt(xcart[:, 0, 0] ** 2 + ycart[:, 0, 0] ** 2) + r = np.sqrt(xcart[:, 0, 0] ** 2 + zcart[:, 0, 0] ** 2) phi = np.unwrap( - np.arctan2(zcart[0, self.ny // 2, :], xcart[0, self.ny // 2, :]) + np.arctan2(ycart[0, self.ny // 2, :], xcart[0, self.ny // 2, :]) ) theta = np.arccos( ycart[0, :, 0] - / np.sqrt(xcart[0, :, 0] ** 2 + ycart[0, :, 0] ** 2) + / np.sqrt(xcart[0, :, 0] ** 2 + zcart[0, :, 0] ** 2) ) else: r = np.sqrt( From 2e3005210a4d5de9e133f6b484f1ab496a060177 Mon Sep 17 00:00:00 2001 From: volodia99 Date: Wed, 25 Sep 2024 15:57:11 +0200 Subject: [PATCH 2/3] BUG: small correction in vtk reader --- pytools/vtk_io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytools/vtk_io.py b/pytools/vtk_io.py index 39144827..83160e1f 100644 --- a/pytools/vtk_io.py +++ b/pytools/vtk_io.py @@ -248,7 +248,7 @@ def _load_hydro(self, fh): np.arctan2(ycart[0, self.ny // 2, :], xcart[0, self.ny // 2, :]) ) theta = np.arccos( - ycart[0, :, 0] + zcart[0, :, 0] / np.sqrt(xcart[0, :, 0] ** 2 + zcart[0, :, 0] ** 2) ) else: From bd11e8b176d9a820b151f2035914bc79e682d100 Mon Sep 17 00:00:00 2001 From: volodia99 Date: Fri, 11 Oct 2024 16:32:07 +0200 Subject: [PATCH 3/3] vtk io add new vtk format --- pytools/vtk_io.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/pytools/vtk_io.py b/pytools/vtk_io.py index 83160e1f..d192930b 100644 --- a/pytools/vtk_io.py +++ b/pytools/vtk_io.py @@ -68,6 +68,7 @@ def _load_header(self, fh, geometry=None): elif line.startswith("FIELD"): # Idefix >= 0.8 nfield = int(line.split()[2]) + self.idefix_vtk_format = 0 for _ in range(nfield): d = fh.readline().decode("utf-8") if d.startswith("GEOMETRY"): @@ -88,6 +89,8 @@ def _load_header(self, fh, geometry=None): self.t = np.fromfile(fh, dt, 1) elif d.startswith("PERIODICITY"): self.periodicity = np.fromfile(fh, dtype=dint, count=3).astype(bool) + elif d.startswith("IDEFIX_VTK_FORMAT"): + self.idefix_vtk_format = np.fromfile(fh, dtype=dint, count=1).item() else: warnings.warn("Found unknown field %s" % d) fh.readline() # skip extra linefeed (empty line) @@ -243,14 +246,25 @@ def _load_hydro(self, fh): # Reconstruct the spherical coordinate system if self.geometry == "spherical": if is2d: - r = np.sqrt(xcart[:, 0, 0] ** 2 + zcart[:, 0, 0] ** 2) - phi = np.unwrap( - np.arctan2(ycart[0, self.ny // 2, :], xcart[0, self.ny // 2, :]) - ) - theta = np.arccos( - zcart[0, :, 0] - / np.sqrt(xcart[0, :, 0] ** 2 + zcart[0, :, 0] ** 2) - ) + if self.idefix_vtk_format>=1: + r = np.sqrt(xcart[:, 0, 0] ** 2 + zcart[:, 0, 0] ** 2) + phi = np.unwrap( + np.arctan2(ycart[0, self.ny // 2, :], xcart[0, self.ny // 2, :]) + ) + theta = np.arccos( + zcart[0, :, 0] + / np.sqrt(xcart[0, :, 0] ** 2 + zcart[0, :, 0] ** 2) + ) + else: + r = np.sqrt(xcart[:, 0, 0] ** 2 + ycart[:, 0, 0] ** 2) + phi = np.unwrap( + np.arctan2(zcart[0, self.ny // 2, :], xcart[0, self.ny // 2, :]) + ) + theta = np.arccos( + ycart[0, :, 0] + / np.sqrt(xcart[0, :, 0] ** 2 + ycart[0, :, 0] ** 2) + ) + else: r = np.sqrt( xcart[:, 0, 0] ** 2 + ycart[:, 0, 0] ** 2 + zcart[:, 0, 0] ** 2