Dear FEAP Users,
I have prepared a simple Python script which helps in compressing the VTU files created by FEAP for Paraview. This is already included in the latest version of our NPVI add-on for IGA post-processing (
http://feap.berkeley.edu/forum/index.php?topic=1542.0), but since it could be of use for all the other classical FE users, here is the script:
from paraview.simple import *
import os
import fnmatch
# get the current directory path
cwd = os.getcwd()
# find all the vtu files in the current directory
files = fnmatch.filter(os.listdir(cwd), "*.vtu")
files.sort()
# print the names of the files (to be converted) on the screen
print("Found:")
print(files)
for fileno, entry in enumerate(files):
print("==========")
print("Processing File", fileno + 1, "of", len(files))
# check the file to see if it is already compressed or not
print("Checking: ", entry)
fline = open(entry).readline().rstrip()
if ("compressor" in fline or os.path.isfile("Comp_"+entry)):
print(entry, "is already compressed! skipping to the next file...")
# if already compressed, skip the file
continue
print("Converting: ", entry)
vtu_file = XMLUnstructuredGridReader(FileName=[entry])
# Compressor types:
# 1: vtkZLibDataCompressor, 2: vtkLZ4DataCompressor , 3: vtkLZMADataCompressor
writer = XMLUnstructuredGridWriter \
(FileName=["Comp_"+entry],CompressorType=3,CompressionLevel=9)
writer.DataMode="Binary" # appended, ascii
writer.UpdatePipeline()
print("Done.")
print("==========")
print("***FINISHED***")
The above Python script goes through all the non-compressed VTU files and compresses them.
This usually reduces the final file-size by around 80%. The generated Python script (npvi_vtkcomp.py) can be executed using 'pvpython' or 'pvbatch' included in the Paraview installation in the 'bin' folder. You may want to add this folder to your operating system's path to be able to directly issue 'pvbatch npvi_vtkcomp.py'. Moreover, by default the compressed files have a Prefix 'Comp_'. This can be changed in the code. Using no prefix means that the non-compressed file will be replaced by the compressed one.
Edit: added the possible compressor types