-
Notifications
You must be signed in to change notification settings - Fork 1
/
RunTurbSim.pl
155 lines (109 loc) · 4.67 KB
/
RunTurbSim.pl
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
# RunTurbSim.pl
# See Marshall Buhl's RunNTM Perl script for help with this script.
# Run a series of TurbSim tests, changing the seed for each case.
# NOTICE
# ------
# Look for the string "USER" for lines that you may want to change.
#-------------------------------------------------------------------
# User-specified paths to programs and files. USER: YOU WILL DEFINITELY NEED TO CHANGE THESE.
#-------------------------------------------------------------------
$turbsim = "TurbSim_x64.exe";
# The TurbSim input/output file name:
$input_file = "C:/Users/lsethura/OPENMDAO/UQ_Scripting/Turbsim_Files_row_0/Turbsim_input_file_8ms_row_0.inp";
# The Directory to place results in:
$rslt_dir = "C:/Users/lsethura/OPENMDAO/UQ_Scripting/Turbsim_Files_row_0";
# The name of the resulting file in the results directory (will be appended with the seed number)
$rslt_file = "Turbsim_input_file_8ms_row_0";
# The extensions of TurbSim output to copy to the results directory:
#@out_ext = ("inp","sum","wnd","cts");
@out_ext = ("bts");
#-------------------------------------------------------------------
# Set the number of seeds to run. Initialize the first seed. USER: YOU MAY WANT TO CHANGE THESE
#-------------------------------------------------------------------
$seed_1 = 20000;
$n_seeds = 30;
#-------------------------------------------------------------------
# Get and save the start time. Initialize other variables
#-------------------------------------------------------------------
$StartTime = date_time();
$n_runs = 0;
$seed_line = 5;
srand($seed_1);
#===================================================================
# Loop through all seeds.
#===================================================================
for $i_seed ( 1..$n_seeds )
{
$ts_root = "${rslt_file}";
#-------------------------------------------------------------------
# Create TurbSim Input File
#-------------------------------------------------------------------
$in_file = "${ts_root}.inp";
open( IN_FILE , ">$in_file" ) or die( "Can't open '$in_file'.\n" );
open( IN_FILE1, "$input_file" ) or die( "Can't open '$input_file'.\n" );
$cnt = 1;
while ( <IN_FILE1> )
{
if ( $cnt == $seed_line )
{
printf ( IN_FILE "%s\t%s\n", "$seed_1", "The first seed" );
}
else
{
print IN_FILE;
}
$cnt++;
} # while <IN_FILE1>
close( IN_FILE );
close( IN_FILE1 );
#-------------------------------------------------------------------
# Run TurbSim
#-------------------------------------------------------------------
print "\n ==============================================\n";
print " TurbSim Seed $i_seed = $seed_1 \n";
print " ==============================================\n";
print " Starting TurbSim on ", date_time(), ".\n";
#system( "$turbsim $ts_root.inp > NUL" );
system "$turbsim $ts_root.inp";
#-------------------------------------------------------------------
# Rename output
#-------------------------------------------------------------------
$root = sprintf( "%s/%s_%s", $rslt_dir, $ts_root, $i_seed);
for $i_r ( 0..$#out_ext )
{
rename( "$ts_root.$out_ext[$i_r]" , "$root.$out_ext[$i_r]" );
}
#-------------------------------------------------------------------
# Get next seed
#-------------------------------------------------------------------
$seed_1 = int($seed_1) + 1;
$n_runs ++;
# End of $i_seed loop
}
#-------------------------------------------------------------------
# Done.
#-------------------------------------------------------------------
print "\n ============================================\n";
if ( $n_runs > 1 )
{
print " After starting on $StartTime, the $n_runs batch runs\n";
print " completed on ", date_time(), ".\n\n";
}
else
{
print " The single batch run completed on ", date_time(), ".\n\n";
}
#-------------------------------------------------------------------
# End of main function.
#-------------------------------------------------------------------
#*******************************************************************
#*******************************************************************
# This routine returns the date and time in the form "dd-Mon-ccyy at hh:mm:ss".
sub date_time
{
my( $sec, $min, $hour, $mday, $mon, $year, $mon_str );
($sec, $min, $hour, $mday, $mon, $year) = localtime;
$mon_str = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon];
return sprintf( "%2.2d-%s-%4.4d at %2.2d:%2.2d:%2.2d", $mday, $mon_str, $year+1900, $hour, $min, $sec );
}
__END__