Skip to content
Closed
Changes from all commits
Commits
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
30 changes: 22 additions & 8 deletions pytools/vtk_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand All @@ -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)
Expand Down Expand Up @@ -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 + 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)
)
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
Expand Down