Hi all,
I thought I would share my workflow to auto-generate *.vtu files from *.slf files using the built-in converter.py as well as the
meshio Python package. This has the disadvantage of creating intermediate *.vtk files, which are deleted at the end. However, the *.vtu files are more compact while the *.vtk format is legacy (just like the *.slf format was meant to be replaced, but still lives on...
)
Known bugs/improvements include:
- I'd like for the xargs command to delete *.vtk files immediately after conversion, in order to save space, but I haven't taken the time to figure that out yet.
- The converter.py script *could* also be run in "shell parallel" with xargs, but each process generates a file named stb.cas in the working directory and this leads to conflicts between processes. There may be a way to select the name for the stb.cas file or to generate temp directories to avoid conflicts, but I haven't figured that out yet.
- This script uses perl rename which does not overwrite existing files by default; this can probably be changed but (surprise) I haven't bothered to do that.
To use this script, copy the below text into slf2vtu.sh and move it to a common reference location (I'd suggest $HOMETEL/scripts, but I don't know if this is a good idea). Before running, install the meshio Python package using pip or whatever it takes:
The script can then be run using the desired *.slf files as arguments:
/path/to/slf2vtu.sh file1.slf file2.slf *.slf
Comments are interspersed:
#!/bin/bash
# Change the next line to source /path/to/pysource.sh
source $HOME/telemac.sh
# Create a folder, if not already existent, for *.vtu files.
mkdir -p vtu
# This commented-out line doesn't work because stb.cas gets deleted/overwritten by each new process
# Otherwise, would be nice to run multiple converter processes concurrently
#ls -1 *.slf|xargs -I@ -P 12 -n 1 converter.py srf2vtk @ vtu/@.vtk
for i in "$@"
do converter.py srf2vtk $i vtu/$i.vtk
done
# Trim out ".slf" and replace with "-"
rename 's/\.slf/-/g' vtu/*.slf*
# Before continuing, make sure you install meshio
#pip install meshio
ls -1 vtu/*.vtk|xargs -I@ -P 12 -n 1 meshio convert @ @.vtu
# Next line is an artifact from trying to delete the current vtk file
#&& rm @
# Trim out double extension from new vtu files
rename 's/\.vtk//g' vtu/*.vtk.vtu
# Clean up vtk files
rm vtu/*.vtk
Improvements are more than welcome! Long live FOSS