Skip to content

Commit 9e43482

Browse files
authored
Merge pull request #3 from ogourgue/suaeda
Suaeda
2 parents 75d73a4 + 7d7b4b6 commit 9e43482

File tree

5 files changed

+229
-70
lines changed

5 files changed

+229
-70
lines changed

ca2tel_voronoi_age.py

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -142,27 +142,34 @@ def voronoi_age(X, Y, STATE, AGE, x, y, tri):
142142
bb = np.zeros((nproc, 4))
143143
for i in range(nproc):
144144
# Bounding box coordinates.
145-
xmin = np.min(x_list[i])
146-
xmax = np.max(x_list[i])
147-
ymin = np.min(y_list[i])
148-
ymax = np.max(y_list[i])
145+
if x_list[i].shape[0] > 0:
146+
xmin = np.min(x_list[i])
147+
xmax = np.max(x_list[i])
148+
ymin = np.min(y_list[i])
149+
ymax = np.max(y_list[i])
149150
# Bounding box indices.
150-
try:imin = int(np.argwhere(X <= xmin)[-1])
151-
except:imin = 0
152-
try:imax = int(np.argwhere(X >= xmax)[0])
153-
except:imax = len(X) - 1
154-
try:jmin = int(np.argwhere(Y <= ymin)[-1])
155-
except:jmin = 0
156-
try:jmax = int(np.argwhere(Y >= ymax)[0])
157-
except:jmax = len(Y) - 1
151+
if x_list[i].shape[0] > 0:
152+
try:imin = int(np.argwhere(X <= xmin)[-1])
153+
except:imin = 0
154+
try:imax = int(np.argwhere(X >= xmax)[0])
155+
except:imax = len(X) - 1
156+
try:jmin = int(np.argwhere(Y <= ymin)[-1])
157+
except:jmin = 0
158+
try:jmax = int(np.argwhere(Y >= ymax)[0])
159+
except:jmax = len(Y) - 1
158160
# Extended Cellular Automaton coordinates.
159-
X_list.append(np.ascontiguousarray(X[imin:imax + 1]))
160-
Y_list.append(np.ascontiguousarray(Y[jmin:jmax + 1]))
161+
if x_list[i].shape[0] > 0:
162+
X_list.append(np.ascontiguousarray(X[imin:imax + 1]))
163+
Y_list.append(np.ascontiguousarray(Y[jmin:jmax + 1]))
164+
else:
165+
X_list.append(np.array([]))
166+
Y_list.append(np.array([]))
161167
# Add bounding box indices to bounding box array.
162-
bb[i, 0] = imin
163-
bb[i, 1] = imax
164-
bb[i, 2] = jmin
165-
bb[i, 3] = jmax
168+
if x_list[i].shape[0] > 0:
169+
bb[i, 0] = imin
170+
bb[i, 1] = imax
171+
bb[i, 2] = jmin
172+
bb[i, 3] = jmax
166173

167174
# Save local intermediate files.
168175
for i in range(nproc):
@@ -204,14 +211,18 @@ def voronoi_age(X, Y, STATE, AGE, x, y, tri):
204211
STATE_list = []
205212
AGE_list = []
206213
for i in range(nproc):
207-
imin = bb[i, 0]
208-
imax = bb[i, 1]
209-
jmin = bb[i, 2]
210-
jmax = bb[i, 3]
211-
STATE_list.append(np.ascontiguousarray(STATE[imin:imax + 1,
214+
if np.sum(bb[i, :]) > 0:
215+
imin = bb[i, 0]
216+
imax = bb[i, 1]
217+
jmin = bb[i, 2]
218+
jmax = bb[i, 3]
219+
STATE_list.append(np.ascontiguousarray(STATE[imin:imax + 1,
220+
jmin:jmax + 1]))
221+
AGE_list.append(np.ascontiguousarray(AGE[imin:imax + 1,
212222
jmin:jmax + 1]))
213-
AGE_list.append(np.ascontiguousarray(AGE[imin:imax + 1,
214-
jmin:jmax + 1]))
223+
else:
224+
STATE_list.append(np.zeros((0, 0)))
225+
AGE_list.append(np.zeros((0, 0)))
215226

216227
# Primary processor partition.
217228
STATE_loc = STATE_list[0]
@@ -246,11 +257,18 @@ def voronoi_age(X, Y, STATE, AGE, x, y, tri):
246257
tri_local_fn = './tmp_ca2tel/tri_local_%d.txt' % rank
247258

248259
# Load local mesh partition.
249-
X_loc = np.loadtxt(X_local_fn)
250-
Y_loc = np.loadtxt(Y_local_fn)
251-
x_loc = np.loadtxt(x_local_fn)
252-
y_loc = np.loadtxt(y_local_fn)
253-
tri_loc = np.loadtxt(tri_local_fn, dtype = int)
260+
if STATE_loc.shape != (0, 0):
261+
X_loc = np.loadtxt(X_local_fn)
262+
Y_loc = np.loadtxt(Y_local_fn)
263+
x_loc = np.loadtxt(x_local_fn)
264+
y_loc = np.loadtxt(y_local_fn)
265+
tri_loc = np.loadtxt(tri_local_fn, dtype = int)
266+
else:
267+
X_loc = np.array([])
268+
Y_loc = np.array([])
269+
x_loc = np.array([])
270+
y_loc = np.array([])
271+
tri_loc = np.array([], dtype = int)
254272

255273
# Voronoi age.
256274
age_loc = voronoi_age(X_loc, Y_loc, STATE_loc, AGE_loc, x_loc, y_loc,
@@ -286,12 +304,16 @@ def voronoi_age(X, Y, STATE, AGE, x, y, tri):
286304
# Load local intermediate files.
287305
glo2loc_local_fn = './tmp_ca2tel/glo2loc_local_%d.txt' % i
288306
ext2loc_local_fn = './tmp_ca2tel/ext2loc_local_%d.txt' % i
289-
glo2loc = np.loadtxt(glo2loc_local_fn, dtype = int)
290-
ext2loc = np.loadtxt(ext2loc_local_fn, dtype = int)
307+
if age_list[i].shape[0] > 0:
308+
glo2loc = np.loadtxt(glo2loc_local_fn, dtype = int)
309+
ext2loc = np.loadtxt(ext2loc_local_fn, dtype = int)
310+
else:
311+
glo2loc = np.array([], dtype = int)
312+
ext2loc = np.array([], dtype = int)
291313
# Reconstruction
292314
age[glo2loc] = age_list[i][ext2loc]
293315

294316
# Save intermediate file.
295317
np.savetxt(age_global_fn, age)
296318

297-
MPI.Finalize()
319+
MPI.Finalize()

ca2tel_voronoi_coverage.py

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -140,27 +140,34 @@ def voronoi_coverage(X, Y, STATE, x, y, tri):
140140
bb = np.zeros((nproc, 4))
141141
for i in range(nproc):
142142
# Bounding box coordinates.
143-
xmin = np.min(x_list[i])
144-
xmax = np.max(x_list[i])
145-
ymin = np.min(y_list[i])
146-
ymax = np.max(y_list[i])
143+
if x_list[i].shape[0] > 0:
144+
xmin = np.min(x_list[i])
145+
xmax = np.max(x_list[i])
146+
ymin = np.min(y_list[i])
147+
ymax = np.max(y_list[i])
147148
# Bounding box indices.
148-
try:imin = int(np.argwhere(X <= xmin)[-1])
149-
except:imin = 0
150-
try:imax = int(np.argwhere(X >= xmax)[0])
151-
except:imax = len(X) - 1
152-
try:jmin = int(np.argwhere(Y <= ymin)[-1])
153-
except:jmin = 0
154-
try:jmax = int(np.argwhere(Y >= ymax)[0])
155-
except:jmax = len(Y) - 1
149+
if x_list[i].shape[0] > 0:
150+
try:imin = int(np.argwhere(X <= xmin)[-1])
151+
except:imin = 0
152+
try:imax = int(np.argwhere(X >= xmax)[0])
153+
except:imax = len(X) - 1
154+
try:jmin = int(np.argwhere(Y <= ymin)[-1])
155+
except:jmin = 0
156+
try:jmax = int(np.argwhere(Y >= ymax)[0])
157+
except:jmax = len(Y) - 1
156158
# Extended Cellular Automaton coordinates.
157-
X_list.append(np.ascontiguousarray(X[imin:imax + 1]))
158-
Y_list.append(np.ascontiguousarray(Y[jmin:jmax + 1]))
159+
if x_list[i].shape[0] > 0:
160+
X_list.append(np.ascontiguousarray(X[imin:imax + 1]))
161+
Y_list.append(np.ascontiguousarray(Y[jmin:jmax + 1]))
162+
else:
163+
X_list.append(np.array([]))
164+
Y_list.append(np.array([]))
159165
# Add bounding box indices to bounding box array.
160-
bb[i, 0] = imin
161-
bb[i, 1] = imax
162-
bb[i, 2] = jmin
163-
bb[i, 3] = jmax
166+
if x_list[i].shape[0] > 0:
167+
bb[i, 0] = imin
168+
bb[i, 1] = imax
169+
bb[i, 2] = jmin
170+
bb[i, 3] = jmax
164171

165172
# Save local intermediate files.
166173
for i in range(nproc):
@@ -200,12 +207,15 @@ def voronoi_coverage(X, Y, STATE, x, y, tri):
200207
# Input variable for each partition.
201208
STATE_list = []
202209
for i in range(nproc):
203-
imin = bb[i, 0]
204-
imax = bb[i, 1]
205-
jmin = bb[i, 2]
206-
jmax = bb[i, 3]
207-
STATE_list.append(np.ascontiguousarray(STATE[imin:imax + 1,
208-
jmin:jmax + 1]))
210+
if np.sum(bb[i, :]) > 0:
211+
imin = bb[i, 0]
212+
imax = bb[i, 1]
213+
jmin = bb[i, 2]
214+
jmax = bb[i, 3]
215+
STATE_list.append(np.ascontiguousarray(STATE[imin:imax + 1,
216+
jmin:jmax + 1]))
217+
else:
218+
STATE_list.append(np.zeros((0, 0)))
209219

210220
# Primary processor partition.
211221
STATE_loc = STATE_list[0]
@@ -236,11 +246,18 @@ def voronoi_coverage(X, Y, STATE, x, y, tri):
236246
tri_local_fn = './tmp_ca2tel/tri_local_%d.txt' % rank
237247

238248
# Load local mesh partition.
239-
X_loc = np.loadtxt(X_local_fn)
240-
Y_loc = np.loadtxt(Y_local_fn)
241-
x_loc = np.loadtxt(x_local_fn)
242-
y_loc = np.loadtxt(y_local_fn)
243-
tri_loc = np.loadtxt(tri_local_fn, dtype = int)
249+
if STATE_loc.shape != (0, 0):
250+
X_loc = np.loadtxt(X_local_fn)
251+
Y_loc = np.loadtxt(Y_local_fn)
252+
x_loc = np.loadtxt(x_local_fn)
253+
y_loc = np.loadtxt(y_local_fn)
254+
tri_loc = np.loadtxt(tri_local_fn, dtype = int)
255+
else:
256+
X_loc = np.array([])
257+
Y_loc = np.array([])
258+
x_loc = np.array([])
259+
y_loc = np.array([])
260+
tri_loc = np.array([], dtype = int)
244261

245262
# Voronoi coverage.
246263
cov_loc = voronoi_coverage(X_loc, Y_loc, STATE_loc, x_loc, y_loc, tri_loc)
@@ -275,12 +292,16 @@ def voronoi_coverage(X, Y, STATE, x, y, tri):
275292
# Load local intermediate files.
276293
glo2loc_local_fn = './tmp_ca2tel/glo2loc_local_%d.txt' % i
277294
ext2loc_local_fn = './tmp_ca2tel/ext2loc_local_%d.txt' % i
278-
glo2loc = np.loadtxt(glo2loc_local_fn, dtype = int)
279-
ext2loc = np.loadtxt(ext2loc_local_fn, dtype = int)
295+
if cov_list[i].shape[0] > 0:
296+
glo2loc = np.loadtxt(glo2loc_local_fn, dtype = int)
297+
ext2loc = np.loadtxt(ext2loc_local_fn, dtype = int)
298+
else:
299+
glo2loc = np.array([], dtype = int)
300+
ext2loc = np.array([], dtype = int)
280301
# Reconstruction
281302
cov[glo2loc] = cov_list[i][ext2loc]
282303

283304
# Save intermediate file.
284305
np.savetxt(cov_global_fn, cov)
285306

286-
MPI.Finalize()
307+
MPI.Finalize()

tel2ca_interpolation.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def interpolation(x, y, f, tri, X, Y):
9898
Y_global_fn = './tmp_tel2ca/Y_global.txt'
9999
F_global_fn = './tmp_tel2ca/F_global.txt'
100100
part_fn = './tmp_tel2ca/part.txt'
101+
empty_fn = './tmp_tel2ca/empty.txt'
101102

102103
# Test if mesh partitioning files are already available.
103104
ready = False
@@ -200,18 +201,30 @@ def interpolation(x, y, f, tri, X, Y):
200201
# Save partition file.
201202
np.savetxt(part_fn, np.array([mpi_nx, mpi_ny]), fmt = '%d')
202203

204+
# Save empty sub-domain file.
205+
empty = np.zeros(nproc, dtype = bool)
206+
for i in range(nproc):
207+
empty[i] = (len(x_list[i]) == 0)
208+
np.savetxt(empty_fn, empty, fmt = '%d')
209+
203210
# Primary processor decomposes input variable for each partition and sends
204211
# partitions to secondary processors.
205212
if rank == 0:
206213

207214
# Load global input variable.
208215
f = np.loadtxt(f_global_fn)
209216

217+
# Load empty sub-domain file.
218+
empty = np.loadtxt(empty_fn, dtype = bool)
219+
210220
# Load local global node index files.
211221
glo_list = []
212222
for i in range(nproc):
213223
glo_local_fn = './tmp_tel2ca/glo_local_%d.txt' % i
214-
glo_list.append(np.loadtxt(glo_local_fn, dtype = int))
224+
if not empty[i]:
225+
glo_list.append(np.loadtxt(glo_local_fn, dtype = int))
226+
else:
227+
glo_list.append(np.array([], dtype = int))
215228

216229
# Input variable for each partition.
217230
f_list = []
@@ -244,9 +257,14 @@ def interpolation(x, y, f, tri, X, Y):
244257
Y_local_fn = './tmp_tel2ca/Y_local_%d.txt' % rank
245258

246259
# Load local mesh partition.
247-
x_loc = np.loadtxt(x_local_fn)
248-
y_loc = np.loadtxt(y_local_fn)
249-
tri_loc = np.loadtxt(tri_local_fn, dtype = int)
260+
if f_loc.shape[0] > 0:
261+
x_loc = np.loadtxt(x_local_fn)
262+
y_loc = np.loadtxt(y_local_fn)
263+
tri_loc = np.loadtxt(tri_local_fn, dtype = int)
264+
else:
265+
x_loc = np.array([])
266+
y_loc = np.array([])
267+
tri_loc = np.array([], dtype = int)
250268
X_loc = np.loadtxt(X_local_fn)
251269
Y_loc = np.loadtxt(Y_local_fn)
252270

@@ -286,4 +304,4 @@ def interpolation(x, y, f, tri, X, Y):
286304
# Save intermediate file.
287305
np.savetxt(F_global_fn, F)
288306

289-
MPI.Finalize()
307+
MPI.Finalize()
12.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)