Skip to content
Snippets Groups Projects
Commit a132a92f authored by Thibaut Lunet's avatar Thibaut Lunet
Browse files

TL: corrected Rectilinear.toVTR for paraview groups

parent 1874244a
No related branches found
No related tags found
No related merge requests found
Pipeline #253474 passed
...@@ -457,7 +457,7 @@ class Rectilinear(Scalar): ...@@ -457,7 +457,7 @@ class Rectilinear(Scalar):
"""Number of degrees of freedom for one variable""" """Number of degrees of freedom for one variable"""
return np.prod(self.gridSizes) return np.prod(self.gridSizes)
def toVTR(self, baseName, varNames, suffix="{:06d}_t={:1.2f}s"): def toVTR(self, baseName, varNames, idxFormat="{:06d}"):
""" """
Convert all 3D fields stored in binary format (FieldsIO) into a list Convert all 3D fields stored in binary format (FieldsIO) into a list
of VTR files, that can be read later with Paraview or equivalent to of VTR files, that can be read later with Paraview or equivalent to
...@@ -469,10 +469,9 @@ class Rectilinear(Scalar): ...@@ -469,10 +469,9 @@ class Rectilinear(Scalar):
Base name of the VTR file. Base name of the VTR file.
varNames : list[str] varNames : list[str]
Variable names of the fields. Variable names of the fields.
suffix : str, optional idxFormat : str, optional
Formating string for the suffix of the VTR file, containing the Formatting string for the index of the VTR file.
index in first position, and the time in second position. The default is "{:06d}".
The default is "{:06d}_t={:1.2f}s".
Example Example
------- -------
...@@ -486,10 +485,10 @@ class Rectilinear(Scalar): ...@@ -486,10 +485,10 @@ class Rectilinear(Scalar):
assert self.dim == 3, "can only be used with 3D fields" assert self.dim == 3, "can only be used with 3D fields"
from pySDC.helpers.vtkIO import writeToVTR from pySDC.helpers.vtkIO import writeToVTR
template = f"{baseName}_{suffix}" template = f"{baseName}_{idxFormat}"
for i in range(self.nFields): for i in range(self.nFields):
t, u = self.readField(i) _, u = self.readField(i)
writeToVTR(template.format(i, t), u, self.header["coords"], varNames) writeToVTR(template.format(i), u, self.header["coords"], varNames)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# MPI-parallel implementation # MPI-parallel implementation
......
...@@ -184,12 +184,10 @@ def testToVTR(nVar, nX, nY, nZ, nSteps): ...@@ -184,12 +184,10 @@ def testToVTR(nVar, nX, nY, nZ, nSteps):
vtrFiles = glob.glob("testToVTR*.vtr") vtrFiles = glob.glob("testToVTR*.vtr")
assert len(vtrFiles) == file.nFields assert len(vtrFiles) == file.nFields
vtrFiles.sort(key=lambda name: int(name.split("_")[1])) vtrFiles.sort(key=lambda name: int(name.split("_")[-1][:-4]))
for i, vFile in enumerate(vtrFiles): for i, vFile in enumerate(vtrFiles):
uVTR, coords, _ = readFromVTR(vFile) uVTR, coords, _ = readFromVTR(vFile)
tVTR = float(vFile.split("_t=")[-1].split("s.vtr")[0]) _, uFile = file.readField(i)
tFile, uFile = file.readField(i)
assert np.allclose(tFile, tVTR), "mismatch between field times"
assert np.allclose(uFile, uVTR), "mismatch between data" assert np.allclose(uFile, uVTR), "mismatch between data"
for i, (xVTR, xFile) in enumerate(zip(coords, file.header["coords"])): for i, (xVTR, xFile) in enumerate(zip(coords, file.header["coords"])):
assert np.allclose(xVTR, xFile), f"coordinate mismatch in dir. {i}" assert np.allclose(xVTR, xFile), f"coordinate mismatch in dir. {i}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment