Skip to content

Commit 8f89524

Browse files
committed
Add restart validation bash script
1 parent 7c29ab3 commit 8f89524

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# ------------------------------------------------------------------------------------------------ #
2+
# T. Kattmann, 28.09.2021, restart_validation.sh
3+
#
4+
# This script validates that the steady restarts work perfectly in SU2.
5+
# For the primal-only restart and the primal restart for the adjoint.
6+
# ------------------------------------------------------------------------------------------------ #
7+
8+
# Prepare useful variable-strings that run primal and adjoint code
9+
code_dir="/home/kat7rng/1__SU2-code/1__Vanilla-SU2/bin"
10+
num_cores=1
11+
config="species3_primitiveVenturi.cfg"
12+
adapt_config="adapt_fluid.cfg"
13+
# Iteration number at which to compare restart with full iter. Note this value is the actual screen iteration number, so for FullIter we have to set ITER=compare_iter+1.
14+
compare_iter=10
15+
echo "ITER: $compare_iter"
16+
compare_iter_plus1=$((compare_iter + 1))
17+
18+
# ITER for SingleZone-steady, OUTER_ITER for multizone-steady
19+
iter_string="ITER"
20+
21+
run_command_primal=" mpirun -n $num_cores $code_dir/SU2_CFD $adapt_config"
22+
run_command_adjoint=" mpirun -n $num_cores $code_dir/SU2_CFD_AD $adapt_config"
23+
24+
echo $run_command_primal
25+
echo $run_command_adjoint
26+
27+
# Extract MESH_FILENAME= name from the provided $config . This is necessary in order to link it into the folders
28+
# The "^" in the grep signals the beginning of the line so that commented out lines are disregarded ( https://unix.stackexchange.com/questions/60994/how-to-grep-lines-which-does-not-begin-with-or )
29+
# The cut command extract everyhing between the first and next "="-char ( https://stackoverflow.com/questions/15148796/get-string-after-character )
30+
# The xargs command trims any unnecessary whitespaces from the string ( https://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable )
31+
mesh=$(grep "^MESH_FILENAME=" $config | cut -d "=" -f2 | xargs)
32+
echo $mesh
33+
34+
# set folder names
35+
FullIter_dir="1__FullIter"
36+
FullMinus1Iter_dir="2__FullMinus1Iter"
37+
PrimalRestart_dir="3__PrimalRestart"
38+
AdjointRestart_dir="4__AdjointRestart"
39+
40+
echo "Deleting old folders for a fresh test."
41+
rm -r $FullIter_dir $FullMinus1Iter_dir $PrimalRestart_dir $AdjointRestart_dir
42+
43+
link_config="ln -s ../*.cfg ."
44+
echo $link_config
45+
link_mesh="ln -s ../$mesh"
46+
echo $link_mesh
47+
48+
link_restart0="ln -s ../$FullMinus1Iter_dir/restart.csv solution.csv"
49+
link_restart1="ln -s ../$FullMinus1Iter_dir/restart.csv solution.csv"
50+
51+
# ------------------------------------------------------------------------------------------------ #
52+
# Run FullIter and FullMinus1Iter in parallel
53+
54+
mkdir $FullIter_dir
55+
cd $FullIter_dir
56+
$link_config
57+
$link_mesh
58+
# Change ITER number. The ^ ensures that the string start at the beginning of the line, such that other *ITER= are not changed
59+
sed "s/^$iter_string=.*/$iter_string=$compare_iter_plus1/g" $config > $adapt_config
60+
echo "Running full primal."
61+
$run_command_primal > CFD.log &
62+
cd ..
63+
64+
mkdir $FullMinus1Iter_dir
65+
cd $FullMinus1Iter_dir
66+
$link_config
67+
$link_mesh
68+
# Change ITER number
69+
sed "s/^$iter_string=.*/$iter_string=$compare_iter/g" $config > $adapt_config
70+
echo "Running full-1 primal."
71+
$run_command_primal > CFD.log
72+
cd ..
73+
74+
# ------------------------------------------------------------------------------------------------ #
75+
# Run primal and adjoint restart in parallel
76+
77+
mkdir $PrimalRestart_dir
78+
cd $PrimalRestart_dir
79+
$link_config
80+
$link_mesh
81+
$link_restart0
82+
$link_restart1
83+
# Change ITER number to 1
84+
sed "s/^$iter_string=.*/$iter_string=1/g" $config > $adapt_config
85+
sed -i "s/RESTART_SOL=.*/RESTART_SOL= YES/g" $adapt_config
86+
#sed -i "s/RESTART_ITER=.*/RESTART_ITER= $compare_iter/g" $adapt_config # only applies to unsteady simulations
87+
echo "Running restarted primal."
88+
$run_command_primal > CFD.log &
89+
cd ..
90+
91+
mkdir $AdjointRestart_dir
92+
cd $AdjointRestart_dir
93+
$link_config
94+
$link_mesh
95+
$link_restart0
96+
$link_restart1
97+
# Change ITER number
98+
sed "s/^$iter_string=.*/$iter_string=1/g" $config > $adapt_config
99+
echo "Running adjoint."
100+
$run_command_adjoint > CFD_AD.log
101+
cd ..
102+
103+
104+
# ------------------------------------------------------------------------------------------------ #
105+
# Postproces results: Print residuals to screen. Remove delimiter using sed and the xargs cuts unnecessary spaces
106+
delimiter=","
107+
remove_delimiter="sed "s/$delimiter//g""
108+
history_file="history.csv"
109+
tail -n 1 $FullIter_dir/$history_file | $remove_delimiter | xargs > output.txt
110+
tail -n 1 $PrimalRestart_dir/$history_file | $remove_delimiter | xargs >> output.txt
111+
delimiter="|"
112+
remove_delimiter="sed "s/$delimiter//g""
113+
# retrieve line number
114+
adj_lineNumber=$(sed -n '/rms_Flow/=' $AdjointRestart_dir/CFD_AD.log)
115+
# $((..)) necessary to expand number
116+
sed -n $((adj_lineNumber + 2))p $AdjointRestart_dir/CFD_AD.log | $remove_delimiter | xargs >> output.txt
117+
cat output.txt

0 commit comments

Comments
 (0)