-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun_tests.py
73 lines (64 loc) · 3.2 KB
/
run_tests.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
import os, json, sys, shutil
import numpy as np
def run_tests(proj_dir, work_dir, task_list):
for task_name in task_list:
try:
config_path = proj_dir + 'testing/' + task_name + '_test/run_config.json'
with open(config_path, 'r') as file_read:
config_data = json.load(file_read)
dim = str(config_data['DIM'])
youngModulus = str(config_data['youngModulus'])
poissonRatio = str(config_data['poissonRatio'])
except Exception as e:
print('Something wrong with config file: ', e)
sys.exit(0)
raw_mesh_dir = proj_dir + 'raw_meshes/' + dim + 'D/' + task_name + '.k'
prep_mesh_task_dir = proj_dir + 'testing/' + task_name + '_test/' + task_name + '_mesh/'
results_dir = work_dir + 'fem_results/' + dim + 'D/' + task_name
#final_results
if os.path.exists(results_dir + '/output/'):
shutil.rmtree(results_dir + '/output/')
os.mkdir(results_dir + '/output/')
else:
if not os.path.exists(work_dir + 'fem_results/'):
os.mkdir(work_dir + 'fem_results/')
if not os.path.exists(work_dir + 'fem_results/' + dim + 'D/'):
os.mkdir(work_dir + 'fem_results/' + dim + 'D/')
if not os.path.exists(results_dir):
os.mkdir(results_dir)
os.mkdir(results_dir + '/output/')
########################################
main_exe = 'build-FEMproject-Desktop_x86_windows_msvc2019_pe_64bit-Release/testing/testing.exe'
os.system(proj_dir + main_exe + ' ' + task_name + ' ' + proj_dir + ' ' + prep_mesh_task_dir + ' ' +
results_dir + ' ' + poissonRatio + ' ' + youngModulus)
eps = 1e-5
x_res = []
y_res = []
z_res = []
with open(results_dir + '/results.vtk', 'r') as res_file:
for line in res_file:
if 'displacements' in line:
line = res_file.readline()
while line != '\n':
x_res.append(float(line.split(' ')[0]))
y_res.append(float(line.split(' ')[1]))
z_res.append(float(line.split(' ')[2]))
line = res_file.readline()
x_test = []
y_test = []
z_test = []
with open(proj_dir + 'testing/' + task_name + '_test/results.vtk', 'r') as res_file:
for line in res_file:
if 'displacements' in line:
line = res_file.readline()
while line != '\n':
x_test.append(float(line.split(' ')[0]))
y_test.append(float(line.split(' ')[1]))
z_test.append(float(line.split(' ')[2]))
line = res_file.readline()
if np.linalg.norm(np.array(x_res) - np.array(x_test)) < eps and \
np.linalg.norm(np.array(y_res) - np.array(y_test)) < eps and \
np.linalg.norm(np.array(z_res) - np.array(z_test)) < eps:
print('Test for ' + task_name + ' completed successfuly')
else:
print('Test for ' + task_name + ' failed!!!')