-
Notifications
You must be signed in to change notification settings - Fork 9
/
serial_regression.py
executable file
·221 lines (179 loc) · 6.99 KB
/
serial_regression.py
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env python
# \file parallel_regression.py
# \brief Python script for automated regression testing of HiFiLES examples
# \author - Original code: Aniket C. Aranake, Alejandro Campos, Thomas D. Economon.
# - Current development: Aerospace Computing Laboratory (ACL) directed
# by Prof. Jameson. (Aero/Astro Dept. Stanford University).
# \version 1.0.0
#
# HiFiLES (High Fidelity Large Eddy Simulation).
# Copyright (C) 2013 Aerospace Computing Laboratory.
import sys,time, os, subprocess, datetime, signal, os.path
class testcase:
def __init__(self,tag_in):
datestamp = time.strftime("%Y%m%d", time.gmtime())
self.tag = "%s_%s"%(tag_in,datestamp) # Input, string tag that identifies this run
# Configuration file path/filename
self.cfg_dir = "/home/fpalacios"
self.cfg_file = "default.cfg"
# The test condition. These must be set after initialization
self.test_iter = 1
self.test_vals = []
# These can be optionally varied
self.HiFiLES_dir = "/home/fpalacios"
self.HiFiLES_exec = "default"
self.timeout = 300
self.tol = 0.001
self.outputdir = "/home/fpalacios"
def run_test(self):
passed = True
exceed_tol = False
timed_out = False
iter_missing = True
start_solver = True
# Adjust the number of iterations in the config file
self.do_adjust_iter()
# Assemble the shell command to run HiFiLES
self.HiFiLES_exec = os.path.join("$HIFILES_RUN", self.HiFiLES_exec)
command_base = "%s %s > outputfile"%(self.HiFiLES_exec, self.cfg_file)
command = "%s"%(command_base)
# Run HiFiLES
os.chdir(os.path.join('./',self.cfg_dir))
start = datetime.datetime.now()
print("\nPath at terminal when executing this file")
print(command)
process = subprocess.Popen(command, shell=True) # This line launches HiFiLES
while process.poll() is None:
time.sleep(0.1)
now = datetime.datetime.now()
if (now - start).seconds> self.timeout:
try:
process.kill()
os.system('killall %s' % self.HiFiLES_exec) # In case of parallel execution
except AttributeError: # popen.kill apparently fails on some versions of subprocess... the killall command should take care of things!
pass
timed_out = True
passed = False
# Examine the output
f = open('outputfile','r')
output = f.readlines()
delta_vals = []
sim_vals = []
if not timed_out:
start_solver = False
for line in output:
if not start_solver: # Don't bother parsing anything before --Setting initial conditions---
if line.find('Setting initial conditions') > -1:
start_solver=True
else: # Found the --Setting initial conditions--- line; parse the input
raw_data = line.split()
try:
iter_number = int(raw_data[0])
data = raw_data[1:] # Take the last 4 columns for comparison
except ValueError:
continue
except IndexError:
continue
if iter_number == self.test_iter: # Found the iteration number we're checking for
iter_missing = False
if not len(self.test_vals)==len(data): # something went wrong... probably bad input
print "Error in test_vals!"
passed = False
break
for j in range(len(data)):
sim_vals.append( float(data[j]) )
delta_vals.append( abs(float(data[j])-self.test_vals[j]) )
if delta_vals[j] > self.tol:
exceed_tol = True
passed = False
break
else:
iter_missing = True
if not start_solver:
passed = False
if iter_missing:
passed = False
print '=========================================================\n'
if passed:
print "%s: PASSED"%self.tag
else:
print "%s: FAILED"%self.tag
print 'execution command: %s'%command
if timed_out:
print 'ERROR: Execution timed out. timeout=%d'%self.timeout
if exceed_tol:
print 'ERROR: Difference between computed input and test_vals exceeded tolerance. TOL=%f'%self.tol
if not start_solver:
print 'ERROR: The code was not able to get to the "Begin solver" section.'
if iter_missing:
print 'ERROR: The iteration number %d could not be found.'%self.test_iter
print 'test_iter=%d, test_vals: '%self.test_iter,
for j in self.test_vals:
print '%f '%j,
print '\n',
print 'sim_vals: ',
for j in sim_vals:
print '%f '%j,
print '\n',
print 'delta_vals: ',
for j in delta_vals:
print '%f '%j,
print '\n'
os.chdir('../../../')
return passed
def do_adjust_iter(self):
# Read the cfg file
self.cfg_file = os.path.join(os.environ['HIFILES_HOME'], self.cfg_dir, self.cfg_file)
file_in = open(self.cfg_file, 'r')
lines = file_in.readlines()
file_in.close()
# Rewrite the file with a .autotest extension
self.cfg_file = "%s.autotest"%self.cfg_file
file_out = open(self.cfg_file,'w')
for line in lines:
if line.find("EXT_ITER")==-1:
file_out.write(line)
else:
file_out.write("EXT_ITER=%d\n"%(self.test_iter+1))
file_out.close()
if __name__=="__main__":
'''This program runs HiFiLES and ensures that the output matches specified values. This will be used to do nightly checks to make sure nothing is broken. '''
# Build HiFiLES_CFD in serial using the right Makefile.in
# Note that we are hard-coding this for enrico at the moment
# This will eventually be a call to the autoconf stuff
os.chdir(os.environ['HIFILES_HOME'])
os.system('cp makefiles/makefile.enrico_serial.in ./makefile.in')
os.system('make clean')
os.system('make')
os.chdir(os.environ['HIFILES_RUN'])
if not os.path.exists("./HiFiLES"):
print 'Could not build HiFiLES'
sys.exit(1)
os.chdir(os.environ['HIFILES_HOME'])
##########################
### Compressible N-S ###
##########################
# Cylinder
cylinder = testcase('cylinder')
cylinder.cfg_dir = "testcases/navier-stokes/cylinder"
cylinder.cfg_file = "input_cylinder_visc"
cylinder.test_iter = 25
cylinder.test_vals = [0.273009,1.178080,1.268071,15.483935,8.855743,9.092093]
cylinder.HiFiLES_exec = "HiFiLES"
cylinder.timeout = 1600
cylinder.tol = 0.00001
passed1 = cylinder.run_test()
# Taylor-Green vortex
tgv = testcase('tgv')
tgv.cfg_dir = "testcases/navier-stokes/Taylor_Green_vortex"
tgv.cfg_file = "input_TGV_SD_hex"
tgv.test_iter = 25
tgv.test_vals = [0.00013215,0.05076817,0.05076814,0.06456282,0.07476870,0.00000000,0.00000000,0.00000000]
tgv.HiFiLES_exec = "HiFiLES"
tgv.timeout = 1600
tgv.tol = 0.00001
passed2 = tgv.run_test()
if (passed1 and passed2):
sys.exit(0)
else:
sys.exit(1)