Welcome, Guest
Username: Password: Remember me

TOPIC: Shell script to convert SLF to VTU (with some intermediate steps)

Shell script to convert SLF to VTU (with some intermediate steps) 2 years 2 months ago #41838

  • Renault
  • Renault's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 127
  • Thank you received: 34
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... :laugh:)

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:
pip install meshio

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 B)
The administrator has disabled public write access.

Shell script to convert SLF to VTU (with some intermediate steps) 1 month 3 weeks ago #46057

  • phmusiedlak
  • phmusiedlak's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 3
Hello Renault,

is this still up-to-date ?

In my use meshio is crashing when converting .vtk:
meshio convert r3d00000000 r3d00000000.vtu
...
ValueError: cannot reshape array of size 1 into shape (19184,3)

Pierre-Henri
The administrator has disabled public write access.

Shell script to convert SLF to VTU (with some intermediate steps) 1 month 3 weeks ago #46058

  • Renault
  • Renault's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 127
  • Thank you received: 34
Bonjour Pierre-Henri,

I am guessing from the name of the file that you are using TELEMAC-3D? I have no experience with T3D, if this is the issue I don't think I can help you.

I assume "r3d00000000" is the name of the .vtk file? Is there a particular reason there is no .vtk extension?

Best,
André Renault
The administrator has disabled public write access.

Shell script to convert SLF to VTU (with some intermediate steps) 1 month 3 weeks ago #46059

  • phmusiedlak
  • phmusiedlak's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 3
Hello Renault,

thanks for the reply,

indeed TELEMAC3D - I don't see the use of Paraview for 2D, BlueKenue is robust.

I forgot to put the .vtk in the line written on the forum, but I have launched the meshio command with (meshio convert r3d00000000.vtk r3d00000000.vtu).

Ok, so thanks for caring ^^

Pierre-Henri
The administrator has disabled public write access.

The open TELEMAC-MASCARET template for Joomla!2.5, the HTML 4 version.