forked from Nek5000/NekExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNekAccTests.py
301 lines (243 loc) · 9.14 KB
/
NekAccTests.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
from lib.nekTestCase import *
from lib.nekBinBuild import build_nek
from lib.nekBinRun import run_nek
import re
class AccTestCase(NekTestCase):
step_limit = None
log_label = ''
@staticmethod
def get_lines_from_log(label, logfile):
with open(logfile, 'r') as f:
line_list = [l for l in f if re.search(r'\b{0}\b'.format(label), l)]
return line_list
def compare_runs(self):
cls = self.__class__
# First get the output w/o acc
build_nek(
source_root = self.source_root,
usr_file = cls.case_name,
cwd = os.path.join(self.examples_root, cls.example_subdir),
f77 = self.f77.replace('-acc',''),
cc = self.cc.replace('-acc',''),
ifmpi = self.ifmpi,
verbose = self.verbose
)
run_nek(
cwd = os.path.join(self.examples_root, cls.example_subdir),
rea_file = cls.case_name,
ifmpi = self.ifmpi,
log_suffix = self.log_suffix + '.noacc',
n_procs = self.mpi_procs,
step_limit = cls.step_limit,
verbose = self.verbose
)
# Then get the output with ACC
build_nek(
source_root = self.source_root,
usr_file = cls.case_name,
cwd = os.path.join(self.examples_root, cls.example_subdir),
f77 = self.f77.replace('-acc','') + ' -acc -Minfo=accel',
cc = self.cc.replace('-acc','') + ' -acc -Minfo=accel',
ifmpi = self.ifmpi,
verbose = self.verbose
)
run_nek(
cwd = os.path.join(self.examples_root, cls.example_subdir),
rea_file = cls.case_name,
ifmpi = self.ifmpi,
log_suffix = self.log_suffix + '.acc',
n_procs = self.mpi_procs,
step_limit = cls.step_limit,
verbose = self.verbose
)
# Now compare output
logfile_noacc = os.path.join(
self.examples_root,
cls.example_subdir,
'{0}.log.{1}{2}.noacc'.format(cls.case_name, self.mpi_procs, self.log_suffix)
)
logfile_acc = os.path.join(
self.examples_root,
cls.example_subdir,
'{0}.log.{1}{2}.acc'.format(cls.case_name, self.mpi_procs, self.log_suffix)
)
loglines_noacc = self.get_lines_from_log(cls.log_label, logfile_noacc)
loglines_acc = self.get_lines_from_log(cls.log_label, logfile_acc)
self.assertNotEqual(
len(logfile_noacc),
0,
'Could not find the label {0} in the logfile {1}'.format(cls.log_label, logfile_noacc)
)
self.assertNotEqual(
len(loglines_acc),
0,
'Could not find the label {0} in the logfile {1}'.format(cls.log_label, logfile_acc)
)
for (noacc, acc) in zip(loglines_noacc, loglines_acc):
err_msg = 'The lines with/without ACC did not match after this point\n' + \
'\n---- Without ACC -----------------------------------------------------\n' + \
noacc + \
'\n---- With ACC --------------------------------------------------------\n' + \
acc
self.assertEqual(noacc, acc, err_msg)
#===================================================================
# pipe; stenosis.rea
#===================================================================
class Compare_Pipe_Stenosis(AccTestCase):
example_subdir = 'pipe'
case_name = 'stenosis'
step_limit = 10
log_label = 'DIV'
def setUp(self):
n2to3_input = [
'w2dcyl020a',
'stenosis',
'0 ascii output',
'20 input number of levels: (1, 2, 3,... etc.?):',
'0 input z min:',
'10 input z max:',
'1 input gain (0=custom,1=uniform,other=geometric spacing):',
'n This is for CEM: yes or no:',
'v Enter Z (5) boundary condition (P,v,O):',
'O Enter Z (6) boundary condition (v,O):',
'y Formatted .rea file? (y or Y):',
]
self.build_tools(['n2to3', 'genmap'])
self.run_n2to3(n2to3_input)
self.run_genmap()
@pn_pn_serial
def test_PnPn_Serial(self):
self.config_size(lx2='lx1', ly2='ly1', lz2='lz1')
self.compare_runs()
@pn_pn_parallel
def test_PnPn_Parallel(self):
self.config_size(lx2='lx1', ly2='ly1', lz2='lz1')
self.compare_runs()
@pn_pn_2_serial
def test_PnPn2_Serial(self):
self.config_size(lx2='lx1-2', ly2='ly1-2', lz2='lz1-2')
self.compare_runs()
@pn_pn_2_parallel
def test_PnPn2_Parallel(self):
self.config_size(lx2='lx1-2', ly2='ly1-2', lz2='lz1-2')
self.compare_runs()
def tearDown(self):
self.move_logs()
#===================================================================
# solid; solid.rea
#===================================================================
class Compare_Solid(AccTestCase):
example_subdir = 'solid'
case_name = 'solid'
step_limit = None
log_label = 'error'
def setUp(self):
self.build_tools(['genmap'])
self.run_genmap()
@pn_pn_serial
def test_PnPn_Serial(self):
self.config_size(lx2='lx1', ly2='ly1', lz2='lz1')
self.compare_runs()
@pn_pn_parallel
def test_PnPn_Parallel(self):
self.config_size(lx2='lx1', ly2='ly1', lz2='lz1')
self.compare_runs()
@pn_pn_2_serial
def test_PnPn2_Serial(self):
self.config_size(lx2='lx1-2', ly2='ly1-2', lz2='lz1-2')
self.compare_runs()
@pn_pn_2_parallel
def test_PnPn2_Parallel(self):
self.config_size(lx2='lx1-2', ly2='ly1-2', lz2='lz1-2')
self.compare_runs()
def tearDown(self):
self.move_logs()
#===================================================================
# 3dbox: b3d.rea
#===================================================================
class Compare_ThreeDBox(AccTestCase):
example_subdir = '3dbox'
case_name = 'b3d'
step_limit = 10
log_label = 'DIV'
def setUp(self):
self.build_tools(['genbox', 'genmap'])
self.run_genbox()
self.mvn('box', self.__class__.case_name)
self.run_genmap()
@pn_pn_serial
def test_PnPn_Serial(self):
self.config_size(lx2='lx1', ly2='ly1', lz2='lz1')
self.compare_runs()
@pn_pn_parallel
def test_PnPn_Parallel(self):
self.config_size(lx2='lx1', ly2='ly1', lz2='lz1')
self.compare_runs()
@pn_pn_2_serial
def test_PnPn2_Serial(self):
self.config_size(lx2='lx1-2', ly2='ly1-2', lz2='lz1-2')
self.compare_runs()
@pn_pn_2_parallel
def test_PnPn2_Parallel(self):
self.config_size(lx2='lx1-2', ly2='ly1-2', lz2='lz1-2')
self.compare_runs()
def tearDown(self):
self.move_logs()
#===================================================================
# turbChannel; turbChannel.rea
#===================================================================
class Compare_TurbChannel(AccTestCase):
example_subdir = 'turbChannel'
case_name = 'turbChannel'
step_limit = 10
log_label = 'err2'
def setUp(self):
self.build_tools(['genmap'])
self.run_genmap(tol='0.5')
@pn_pn_serial
def test_PnPn_Serial(self):
self.config_size(lx2='lx1', ly2='ly1', lz2='lz1')
self.compare_runs()
@pn_pn_parallel
def test_PnPn_Parallel(self):
self.config_size(lx2='lx1', ly2='ly1', lz2='lz1')
self.compare_runs()
@pn_pn_2_serial
def test_PnPn2_Serial(self):
self.config_size(lx2='lx1-2', ly2='ly1-2', lz2='lz1-2')
self.compare_runs()
@pn_pn_2_parallel
def test_PnPn2_Serial(self):
self.config_size(lx2='lx1-2', ly2='ly1-2', lz2='lz1-2')
self.compare_runs()
def tearDown(self):
self.move_logs()
#===================================================================
# vortex; r1854a.rea
#===================================================================
class Compare_Vortex(AccTestCase):
example_subdir = 'vortex'
case_name = 'r1854a'
step_limit = 10
log_label = 'VMIN'
def setUp(self):
self.build_tools(['genmap'])
self.run_genmap()
@pn_pn_serial
def test_PnPn_Serial(self):
self.config_size(lx2='lx1', ly2='ly1', lz2='lz1')
self.compare_runs()
@pn_pn_parallel
def test_PnPn_Parallel(self):
self.config_size(lx2='lx1', ly2='ly1', lz2='lz1')
self.compare_runs()
@pn_pn_2_serial
def test_PnPn2_Serial(self):
self.config_size(lx2='lx1-2', ly2='ly1-2', lz2='lz1-2')
self.compare_runs()
@pn_pn_2_parallel
def test_PnPn2_Parallel(self):
self.config_size(lx2='lx1-2', ly2='ly1-2', lz2='lz1-2')
self.compare_runs()
def tearDown(self):
self.move_logs()