-
Notifications
You must be signed in to change notification settings - Fork 0
/
template_run.sh
executable file
·171 lines (131 loc) · 4.21 KB
/
template_run.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
# A template script to run all inlists for a given model, in succession
# This assumes you have created a directory called <RUN_DIR> in your work location (e.g. scratch),
# which contains a inlist_folder/ with any extra inlists required for the run
# We cd into that folder, then call base/star
# We cycle the extra inlists to call in base/base_inlist with the base/next_inlist script
# Can handle restarts if you provide the photo
# Once everything is set below and before the dashed line, this program should run everything on its own
RUN_DIR=Schwarzschild
## Which inlist to start with (give number)
inlists=(1_accrete 2_flash 3_relax_tau 4_wind 5_fallback)
START=2
## Which inlist to stop after (5 to go to the end)
STOP=4
## Is it a restart?
RESTART=false
RESTART_PHOTO=photos/ # (path from run directory)
## Save sim files (logs,photos)
SAVEFILES=true
## Your local variables
export OMP_NUM_THREADS=8
export BASE="/home/mesa_mixed_burst/base"
export PYTHON="/home/mesa_mixed_burst/python_scripts"
export SCRATCH="/home/ximun/scratch/mixed_burst_scratch"
## Modules (adapt to your system)
#module load python/3.10.2
#module load scipy-stack/2022a
#module load ffmpeg
#--------------------------------------------------------------------------------------------------
## Functions
save_history () {
cp LOGS/history.data histories/history_$1.data
cp LOGS/mixing_history.data histories/ 2>/dev/null
}
save_logs () {
mkdir -p LOGS/$1
mv LOGS/{*.dat*,*.index} LOGS/$1
}
most_recent_photo () {
ls -tp photos | grep -v / | head -1
}
save_photos () {
mkdir -p photos/$1
most_recent_photo=$(ls -tp photos | grep -v / | head -1)
cp photos/$most_recent_photo photos/$1/last_photo_$most_recent_photo
mv photos/*000 photos/$1
mv photos/x500 photos/$1
}
clean_outputs () {
rm -f LOGS/{*.dat*,*.index}
rm -f photos/{x*,*0}
rm -f png/*.png
}
filetype_exists () {
count=`ls -1 $1 2>/dev/null | wc -l`
if [ $count != 0 ] ; then
true
else
false
fi
}
blank_lines () { yes '' | sed 3q; }
run_one () {
echo "********************** RUNNING "$1
time $BASE/star > terminal_outputs/$1.txt
if filetype_exists png/grid1*.png ; then
images_to_movie "png/grid1*.png" movies/pgstar_$1.mp4
fi
if filetype_exists png/grid2*.png ; then
images_to_movie "png/grid2*.png" movies/pgstar_2_$1.mp4
fi
if [ "$SAVEFILES" = true ] ; then
if filetype_exists LOGS/*.data ; then
save_history $1
save_logs $1
fi
if filetype_exists photos/*000 ; then
save_photos $1
fi
fi
clean_outputs
blank_lines
}
#--------------------------------------------------------------------------------------------------
# Assuming directory has already been initialized within scratch
cd $SCRATCH/$RUN_DIR
mkdir -p models
mkdir -p terminal_outputs
mkdir -p movies
mkdir -p histories
rm -f restart_photo
cp $BASE/base_inlist ./inlist
# For restart from photo
if [ "$RESTART" = true ] ; then
cp $RESTART_PHOTO restart_photo # star will recognize this filename
# Change previous filenames and directories
# won't work for more than 2 restarts
old_name=terminal_outputs/${inlists[$START-1]}.txt
new_name=terminal_outputs/${inlists[$START-1]}_0.txt
mv $old_name $new_name
old_name=movies/pgstar_${inlists[$START-1]}.mp4
new_name=movies/pgstar_${inlists[$START-1]}_0.mp4
mv $old_name $new_name
old_name=LOGS/${inlists[$START-1]}
new_name=LOGS/${inlists[$START-1]}_0
mv $old_name $new_name
old_name=photos/${inlists[$START-1]}
new_name=photos/${inlists[$START-1]}_0
mv $old_name $new_name
fi
echo "*********** START ***********"
date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S"
echo "Run directory: "$RUN_DIR
n=1
for inlist in ${inlists[@]}; do
if [ $n -ge "$START" ] ; then
run_one $inlist
rm -f restart_photo # if there was a restart (can only be at the first inlist), the photo now needs to be deleted
fi
if [ $n -eq "$STOP" ] ; then
break
fi
$BASE/next_inlist
n=$(($n+1))
done
# Clean-up
rm inlist
rm -r png
rm -r .mesa_temp_cache
echo "********** FINISHED *********"
date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S"