Skip to content
Snippets Groups Projects
Commit 5a54c024 authored by Maja Warlich's avatar Maja Warlich
Browse files

Parallel index array.

parent 3c9ba6ed
Branches
No related tags found
No related merge requests found
Pipeline #35253 failed
......@@ -304,9 +304,12 @@ class SparseLbCommunicationMapper:
self.flag_arr = mapping._flag_arr
self.domain_size = self.flag_arr.shape
self.no_slip_flag = mapping.no_slip_flag
self._parallel_index_array = None
self._bounce_back_index_array = None
self._send_packages = None
self._receive_here = None
self._received_packages = None
self._send = None
self._kernel = None
self._dirty = True
......@@ -345,6 +348,18 @@ class SparseLbCommunicationMapper:
pdf_cell_idx = pdf_index(cell_idx, direction_idx, len(self.mapping))
return pdf_cell_idx
def _get_assignment_rec(self, direction, cell, neighbor, bool_slice):
cell = tuple(cell)
#direction_idx = self.mapping.stencil.index(direction)
#print("pack:", cell, "neighbor:", tuple(neighbor))
fluid = True
if (self.flag_arr[cell] | self.flag_arr[tuple(neighbor)]) & self.no_slip_flag :
#print("is solid")
fluid = False
#cell_idx = self.mapping.cell_idx(cell)
#pdf_cell_idx = pdf_index(cell_idx, direction_idx, len(self.mapping))
return tuple([fluid, cell, direction])
def create_packages(self):
stencil = self.mapping.stencil
result = [[[] for j in range(0, len(stencil)-1)] for i in range(0, len(stencil)-1)]
......@@ -362,10 +377,11 @@ class SparseLbCommunicationMapper:
neighbor_ghost_cell = [(cell_i + dir_i*int(bs_i)) for cell_i, dir_i, bs_i in zip(cell, direction, bool_slice)]
result[block_index-1][direction_idx-1].append(self._get_assignment(direction, cell, neighbor_ghost_cell, bool_slice))
#print("Goes into", block_index-1, direction_idx-1)
self._send_packages = np.array(result)
self._send_packages = result
return result
def receive_here(self):
self._received_packages = self._send_packages #tmp
stencil = self.mapping.stencil
result = [[[] for j in range(0, len(stencil)-1)] for i in range(0, len(stencil)-1)]
for direction_idx, direction in enumerate(stencil):
......@@ -383,14 +399,14 @@ class SparseLbCommunicationMapper:
block_direction = [int(bp_i)*dir_i for dir_i, bp_i in zip(direction, bool_slice)]
block_index = self.mapping.stencil.index(tuple(block_direction))
future_pull_cell = [(cell_i + dir_i) for cell_i, dir_i, bs_i in zip(cell, direction, bool_slice)]
result[block_index-1][direction_idx-1].append(self._get_assignment(direction, cell, future_pull_cell, bool_slice))
result[block_index-1][direction_idx-1].append(self._get_assignment_rec(direction, cell, future_pull_cell, bool_slice))
#print("Goes into", block_index-1, direction_idx-1)
self._receive_here = np.array(result)
self._receive_here = result
return result
def send(self):
stencil = self.mapping.stencil
send = []
self._send = []
for block in self._send_packages:
block_array = []
for direction in block:
......@@ -398,32 +414,44 @@ class SparseLbCommunicationMapper:
for val in direction:
if val != -1:
block_array.append(val)
send.append(block_array)
return send
self._send.append(block_array)
def create_index_array(self):
#During initialization, somehow receive packages ...
self._received_packages = self._send_packages #tmp
result = []
for block_rec, block_here in zip(self._received_packages, self._receive_here):
i = 0
for dir_rec, dir_here in zip(block_rec, block_here):
self._parallel_index_array = []
self._bounce_back_index_array = []
for block, (block_rec, block_here) in enumerate(zip(self._received_packages, self._receive_here)):
place = 0
for j, (dir_rec, dir_here) in enumerate(zip(block_rec, block_here)):
for val_rec, val_here in zip(dir_rec, dir_here):
print(val_rec, val_here)
if val_here == -1:
dir_idx = j+1
if not val_here[0]:
#print(val_rec, val_here, place, "jump")
place += 1
continue
elif val_rec == -1:
#Problem: Wie komme ich jetzt an die reverse direction der ersatzzelle????
return
elif val_rec == -1: #Nothing will be received, because the sending cell is solid -> bounce-back rule
read = [cell_i + dir_i for cell_i, dir_i in zip(val_here[1], val_here[2])]
#print(val_rec, val_here, place, "bounce back:", read)
if self.flag_arr[tuple(read)] & self.no_slip_flag:
continue
read_idx = self.mapping.cell_idx(tuple(read))
write_idx = self.mapping.cell_idx(val_here[1])
inv_dir_idx = inverse_idx(self.mapping.stencil, dir_idx)
pdf_write_idx = pdf_index(write_idx, dir_idx, len(self.mapping))
pdf_read_idx = pdf_index(read_idx, inv_dir_idx, len(self.mapping))
self._bounce_back_index_array.append([pdf_write_idx, pdf_read_idx])
else:
write_idx = self.mapping.cell_idx(val_here[1])
pdf_write_idx = pdf_index(write_idx, dir_idx, len(self.mapping))
self._parallel_index_array.append([pdf_write_idx, block, place])
#print(val_rec, val_here, place, "default")
place += 1
......
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment