forked from gacevedobolton/myVTKPythonLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
computeSectors.py
149 lines (112 loc) · 4.6 KB
/
computeSectors.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
#coding=utf8
########################################################################
### ###
### Created by Martin Genet, 2012-2016 ###
### ###
### University of California at San Francisco (UCSF), USA ###
### Swiss Federal Institute of Technology (ETH), Zurich, Switzerland ###
### École Polytechnique, Palaiseau, France ###
### ###
########################################################################
import myVTKPythonLibrary as myVTK
########################################################################
def computeSectorsForLV(
farray_rr,
farray_cc,
farray_ll,
n_r=1,
n_c=1,
n_l=1,
iarray_part_id=None,
verbose=0):
myVTK.myPrint(verbose, "*** computeSectorsForLV ***")
n_cells = farray_rr.GetNumberOfTuples()
iarray_sector = myVTK.createIntArray("sector_id", 1, n_cells)
for k_cell in range(n_cells):
if (iarray_part_id is not None) and (int(iarray_part_id.GetTuple1(k_cell)) > 0):
sector_id = -1
else:
rr = farray_rr.GetTuple1(k_cell)
cc = farray_cc.GetTuple1(k_cell)
ll = farray_ll.GetTuple1(k_cell)
k_r = int(rr*n_r/1.000001)
k_c = int(cc*n_c/1.000001)
k_l = int((1.-ll)*n_l/1.000001)
sector_id = k_l * n_c * n_r + k_c * n_r + k_r
iarray_sector.SetTuple1(k_cell, sector_id)
return iarray_sector
########################################################################
def addSectorsToLV(
ugrid_mesh,
n_r=1,
n_c=1,
n_l=1,
verbose=0):
myVTK.myPrint(verbose, "*** addSectorsToLV ***")
iarray_sector = computeSectorsForLV(
farray_rr=ugrid_mesh.GetCellData().GetArray("rr"),
farray_cc=ugrid_mesh.GetCellData().GetArray("cc"),
farray_ll=ugrid_mesh.GetCellData().GetArray("ll"),
n_r=n_r,
n_c=n_c,
n_l=n_l,
iarray_part_id=ugrid_mesh.GetCellData().GetArray("part_id"),
verbose=verbose-1)
ugrid_mesh.GetCellData().AddArray(iarray_sector)
########################################################################
def computeSectorsForBiV(
iarray_regions,
farray_rr,
farray_cc,
farray_ll,
n_r=[1]*3,
n_c=[1]*3,
n_l=[1]*3,
iarray_part_id=None,
verbose=0):
myVTK.myPrint(verbose, "*** computeSectorsForBiV ***")
n_cells = iarray_regions.GetNumberOfTuples()
assert (farray_rr.GetNumberOfTuples() == n_cells)
assert (farray_cc.GetNumberOfTuples() == n_cells)
assert (farray_ll.GetNumberOfTuples() == n_cells)
iarray_sector = myVTK.createIntArray("sector_id", 1, n_cells)
for k_cell in range(n_cells):
if (iarray_part_id is not None) and (int(iarray_part_id.GetTuple1(k_cell)) > 0):
sector_id = -1
else:
region_id = int(iarray_regions.GetTuple1(k_cell))
rr = farray_rr.GetTuple1(k_cell)
cc = farray_cc.GetTuple1(k_cell)
ll = farray_ll.GetTuple1(k_cell)
k_r = int( rr *n_r[region_id]/1.000001)
k_c = int( cc *n_c[region_id]/1.000001)
k_l = int((1.-ll)*n_l[region_id]/1.000001)
sector_id = k_l * n_c[region_id] * n_r[region_id] \
+ k_c * n_r[region_id] \
+ k_r
if (region_id >= 1):
sector_id += n_r[0] * n_c[0] * n_l[0]
if (region_id >= 2):
sector_id += n_r[1] * n_c[1] * n_l[1]
iarray_sector.SetTuple1(k_cell, sector_id)
return iarray_sector
########################################################################
def addSectorsToBiV(
ugrid_mesh,
n_r=[1]*3,
n_c=[1]*3,
n_l=[1]*3,
verbose=0):
myVTK.myPrint(verbose, "*** addSectorsToBiV ***")
iarray_sector = computeSectorsForBiV(
iarray_regions=ugrid_mesh.GetCellData().GetArray("region_id"),
farray_rr=ugrid_mesh.GetCellData().GetArray("rr"),
farray_cc=ugrid_mesh.GetCellData().GetArray("cc"),
farray_ll=ugrid_mesh.GetCellData().GetArray("ll"),
n_r=n_r,
n_c=n_c,
n_l=n_l,
iarray_part_id=ugrid_mesh.GetCellData().GetArray("part_id"),
verbose=verbose-1)
ugrid_mesh.GetCellData().AddArray(iarray_sector)
########################################################################