Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add delete method for small time steps #26

Merged
merged 1 commit into from
Feb 29, 2024
Merged
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
43 changes: 43 additions & 0 deletions VTUinterface/vtuIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,14 +1228,57 @@ def append(self, filename, vtu_rename=False):
os.rename(os.path.join(self.folder, tag.attrib['file']), os.path.join(self.folder,
folder, newvtuname))
self.vtufilenames.append(os.path.join(self.folder, folder, newvtuname))
#pvdwriter
root = ET.Element("VTKFile")
root.attrib["type"] = "Collection"
root.attrib["version"] = "0.1"
root.attrib["byte_order"] = "LittleEndian"
root.attrib["compressor"] = "vtkZLibDataCompressor"
collection = ET.SubElement(root,"Collection")
timestepselements = []
for i, timestep in enumerate(self.timesteps):
timestepselements.append(ET.SubElement(collection, "DataSet"))
timestepselements[-1].attrib["timestep"] = str(timestep)
timestepselements[-1].attrib["group"] = ""
timestepselements[-1].attrib["part"] = "0"
timestepselements[-1].attrib["file"] = self.vtufilenames[i]
tree = ET.ElementTree(root)
tree.write(os.path.join(self.folder, self.filename), encoding="ISO-8859-1",
xml_declaration=True, pretty_print=True)

def delete_small_timesteps(self, minimum_ts_size):
"""
appends entries from another PVD file

Parameters
----------
minimum_ts_size : `float`
time stepps smaller than this size will be deleted
"""
tobedeleted = []
for i, timestep in enumerate(self.timesteps):
if i > 0:
j = i-1
while j in tobedeleted:
j = j - 1
delta = timestep - self.timesteps[j]
if delta < minimum_ts_size:
try:
os.remove(self.vtufilenames[i])
except FileNotFoundError:
print("File not found, but will be removed from PVD")
tobedeleted.append(i)
self.timesteps = np.delete(self.timesteps, tobedeleted)
for entry in sorted(tobedeleted, reverse = True):
del self.vtufilenames[entry]
#pvdwriter
root = ET.Element("VTKFile")
root.attrib["type"] = "Collection"
root.attrib["version"] = "0.1"
root.attrib["byte_order"] = "LittleEndian"
root.attrib["compressor"] = "vtkZLibDataCompressor"
collection = ET.SubElement(root,"Collection")
timestepselements = []
for i, timestep in enumerate(self.timesteps):
timestepselements.append(ET.SubElement(collection, "DataSet"))
timestepselements[-1].attrib["timestep"] = str(timestep)
Expand Down
Loading