Last active
April 7, 2023 10:44
-
-
Save tbhaxor/f5e919c3b2174386305e05ab4bcf7189 to your computer and use it in GitHub Desktop.
Utility script to run the athena computations and generate movie
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
problem="" | |
output_directory="." | |
framerate=5 | |
skip_simulation=false | |
git_base=$(git rev-parse --show-toplevel) | |
athenapk_exe="$git_base/build/bin/athenaPK" | |
# Parse command-line arguments | |
while [[ $# -gt 0 ]]; do | |
case "$1" in | |
--problem | -p) | |
shift | |
problem=$1 | |
if [[ ! -f "$problem" ]]; then | |
echo "[x] Invalid problem: '$problem'" | |
exit 1 | |
fi | |
;; | |
--output | -o) | |
shift | |
output_directory="${1%/}" | |
output_directory=$(realpath -m "$output_directory") | |
;; | |
--framerate | -r) | |
shift | |
if [[ ! "$1" =~ ^[0-9]+$ ]]; then | |
echo "Framerate must be an integer" >&2 | |
exit 1 | |
fi | |
framerate=$1 | |
;; | |
--skip-computation | -s) | |
shift | |
skip_simulation=true | |
;; | |
*) | |
echo "usage: $0 --problem PROBLEM --output OUTPUT_DIRECTORY [--framerate 5]" | |
echo "Arguments" | |
echo -e "\t--problem PROBLEM, -p PROBLEM\n\t\tProblem statement (*.in files)" | |
echo -e "\t--output OUTPUT_DIRECTORY, -o OUTPUT_DIRECTORY\n\t\tOutput directory to store the phdf files" | |
echo -e "\t--framerate FRAMERATE, -r FRAMERATE\n\t\tGIF movie frame rate in fps (default: 5)" | |
echo -e "\t --skip-computation, -s\n\t\tSkip the computation and regenerate movie only (default: false)" | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
function moviegen() { | |
if [[ ! -d "$output_directory" ]]; then | |
return 1 | |
fi | |
if [[ ! -d "$output_directory/movie" ]]; then | |
mkdir "$output_directory/movie" | |
fi | |
cd "$output_directory/movie" | |
python "$git_base/external/parthenon/scripts/python/packages/parthenon_tools/parthenon_tools/movie2d.py" prim "$output_directory"/*.phdf | |
ffmpeg -framerate "$framerate" -pattern_type glob -i '*.png' -vf "scale=800:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" out.gif -y | |
ffmpeg -framerate "$framerate" -pattern_type glob -i '*.png' -c:v libx264 -pix_fmt yuv420p out.mp4 -y | |
xdg-open "$output_directory/movie/out.gif" | |
xdg-open "$output_directory/movie/out.mp4" | |
} | |
if $skip_simulation; then | |
moviegen | |
exit 0 | |
fi | |
set -ex | |
rm -rf "$output_directory" | |
mkdir --parents "$output_directory" | |
if "$athenapk_exe" -i "$problem" -d "$output_directory"; then | |
moviegen | |
else | |
echo "Failed" >&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment