forked from ImperialCollegeLondon/multifluids_icferst
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenpvtu.py
executable file
·45 lines (37 loc) · 1.31 KB
/
genpvtu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
import os
import sys
import tempfile
import vtk
import fluidity.diagnostics.debug as debug
import fluidity.diagnostics.filehandling as filehandling
import fluidity.diagnostics.fluiditytools as fluiditytools
import fluidity.diagnostics.vtutools as vtktools
if not len(sys.argv) == 2:
print("Usage: genpvtu basename")
sys.exit(1)
basename = sys.argv[1]
debug.dprint("vtu basename: " + basename)
nPieces = fluiditytools.FindMaxVtuId(basename) + 1
debug.dprint("Number of pieces: " + str(nPieces))
# Write to a temporary directory so that the first piece isn't overwritten
tempDir = tempfile.mkdtemp()
# Create the parallel writer
writer = vtk.vtkXMLPUnstructuredGridWriter()
writer.SetNumberOfPieces(nPieces)
writer.WriteSummaryFileOn()
pvtuName = basename + ".pvtu"
writer.SetFileName(os.path.join(tempDir, pvtuName))
# Load in the first piece, so that the parallel writer has something to do (and
# knows which fields we have)
pieceName = fluiditytools.VtuFilenames(basename, 0)[0]
pieceVtu = vtktools.vtu(pieceName)
if vtk.vtkVersion.GetVTKMajorVersion() <= 5:
writer.SetInput(0, pieceVtu.ugrid)
else:
writer.SetInputData(0, pieceVtu.ugrid)
# Write
writer.Write()
# Move the output back and clean up
filehandling.Move(os.path.join(tempDir, pvtuName), pvtuName)
filehandling.Rmdir(tempDir, force = True)