-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfix_surf_id.py
executable file
·55 lines (40 loc) · 1.6 KB
/
fix_surf_id.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
#!/usr/bin/env python
import numpy as np
import os
from vtk.util.numpy_support import vtk_to_numpy as v2n
from vtk.util.numpy_support import numpy_to_vtk as n2v
from get_database import Database, input_args
from vtk_functions import read_geo, write_geo
def main(db, geometries):
for geo in geometries:
print('Fixing geometry ' + geo)
folder_out = os.path.join(db.fpath_gen, 'surfaces', geo)
f_all = os.path.join(folder_out, 'all_exterior.vtp')
f_wall = os.path.join(folder_out, 'wall.vtp')
read_all = read_geo(f_all).GetOutput()
read_wall = read_geo(f_wall).GetOutput()
# read indices
fid_all = v2n(read_all.GetCellData().GetArray('BC_FaceID'))
eid_all = v2n(read_all.GetCellData().GetArray('GlobalElementID'))
eid_wall = v2n(read_wall.GetCellData().GetArray('GlobalElementID'))
# find wall indices in all_exterior
index = np.argsort(eid_all)
search = np.searchsorted(eid_all[index], eid_wall)
ind_wall = index[search]
wall_id = np.unique(fid_all[ind_wall])
assert wall_id.shape[0] == 1, 'wall BC_FaceID not unique'
if wall_id[0] == 0:
print(' Nothing to do')
continue
# change id
fid_all[ind_wall] = 0
# export
out_array = n2v(fid_all)
out_array.SetName('BC_FaceID')
read_all.GetCellData().RemoveArray('BC_FaceID')
read_all.GetCellData().AddArray(out_array)
write_geo(f_all, read_all)
if __name__ == '__main__':
descr = 'Fix wrong surface id'
d, g, _ = input_args(descr)
main(d, g)