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

Only iterate fluid cells

parent fe8b3f4d
No related branches found
No related tags found
No related merge requests found
......@@ -31,7 +31,7 @@ class SparseLbMapper:
flag_arr: integer array where each bit corresponds to a boundary or 'fluid'
"""
def __init__(self, stencil, flag_arr, fluid_flag, no_slip_flag, ubb_flag, density_flag):
def __init__(self, stencil, domain_size, flag_arr, fluid_flag, no_slip_flag, ubb_flag, density_flag):
self._flag_arr = flag_arr
self._coordinate_arr = None
self._sorter = None # array of indices that sort _coordinate_arr
......@@ -43,6 +43,7 @@ class SparseLbMapper:
self.boundary_mask = density_flag | ubb_flag
self._num_fluid_cells = None
self.stencil = stencil
self.domain_size = domain_size
@property
......@@ -129,11 +130,15 @@ class SparseLbMapper:
fluid_boundary_mask = self.ubb_flag | self.fluid_flag | self.density_flag
result = []
print("flag:", self.flag_array)
fucking_counter = 0
for direction_idx, direction in enumerate(stencil):
if all(d_i == 0 for d_i in direction):
assert direction_idx == 0
continue
for own_cell_idx, cell in enumerate(self.fluid_coordinates):
if (cell[0] == 0 or cell[0] == self.domain_size[0]-1 or cell[1] == 0 or cell[1] == self.domain_size[1]-1):
fucking_counter += 1
continue #ignore fluid cells at the border ...
domain_size = (len(self.flag_array), len(self.flag_array[0]))
test = []
inv_neighbor_cell = np.array([cell_i - dir_i for cell_i, dir_i in zip(cell, direction)])
......@@ -166,7 +171,7 @@ class SparseLbMapper:
#print(test)
index_array = np.array(result, dtype=np.uint32)
index_arr = index_array.reshape([len(stencil) - 1, self.num_fluid_cells])
index_arr = index_array.reshape([len(stencil) - 1, self.num_fluid_cells-fucking_counter])
index_arr = index_arr.swapaxes(0, 1)
return index_arr
......@@ -174,10 +179,16 @@ class SparseLbMapper:
class SparseLbPeriodicityMapper:
def __init__(self, method, mapping: SparseLbMapper, domain_size, periodicity):
def __init__(self, method, mapping: SparseLbMapper, dh):
self.method = method
self.mapping = mapping
self.domain_size = domain_size
self.domain_size = dh.shape
self.periodicity = dh.periodicity
self.flag_arr = mapping._flag_arr
self.fluid_flag = mapping.fluid_flag
self.no_slip_flag = mapping.no_slip_flag
self.density_flag = mapping.density_flag
self.ubb_flag = mapping.ubb_flag
def cell_idx(self, coordinate: Tuple[int, ...]) -> np.uint32:
"""Maps from coordinates (x,y,z) or (x,y) tuple to the list index. Raises ValueError if coordinate not found."""
......@@ -190,6 +201,117 @@ class SparseLbPeriodicityMapper:
return self.mapping._sorter[left]
def create_index_arr(self): # erstellt index arrays für ALLE fluid Zellen, die sich am Rand der domain befinden.
# ein index array für alle Werte, die innerhalb des Blocks verschickt werden
# jeweils ein index array für Werte, die zu jeweils verschiedenen benachbarten Blocks geschickt werden (wenn verschiedene Kerne verschiedene Blöcke innerhalb einer Domain bearbeiten)
stencil = self.method.stencil
print("domain_size:", self.domain_size)
result = []
inner = []
write = [0,0]
fluid_boundary_mask = self.fluid_flag | self.ubb_flag | self.density_flag
for direction_idx, direction in enumerate(stencil):
if all(d_i == 0 for d_i in direction) or direction_idx < 5:#(direction_idx != 5 and direction_idx != 1) or direction_idx < 5: # direction (0,0) irrelevant
continue
print("\n New direction:", direction, ", ", direction_idx)
for pos in range(0,2): # einmal für x, einmal für y Richtung ...
print("pos is ", pos)
sop = (pos+1)%2
if direction[pos] != 0:
# periodic/parallel: wird an anderen Block geschickt/periodisch gewrappt
print("(periodic:)")
index_array = []
coord = int((self.domain_size[pos]-1)*(1-direction[pos])/2)
print("first")
start = 1 if direction[sop] == 1 else 0
end = self.domain_size[sop]-1 if direction[sop] == -1 else self.domain_size[sop]
for i in range(start, end):
write = [0,0]
write[pos] = coord
write[sop] = i
if not (self.flag_arr[tuple(write)] & self.fluid_flag):
continue
read = [(write_i - dir_i)%ds_i for write_i, dir_i, ds_i in zip(write, direction, self.domain_size)]
if self.flag_arr[tuple(read)] & self.no_slip_flag:
print("Read cell is a no_slip. Hmpf.")
# "Die Zelle "write" bekommt ihren neuen Wert der jeweiligen direction von der Zelle "read"
print("write:", write, "read:", read)
#write_idx = self.cell_idx(tuple(write))
#read_idx = self.cell_idx(tuple(read))
#index_array.append((direction_idx, pdf_index(write_idx, direction_idx, len(self.mapping)), pdf_index(read_idx, direction_idx, len(self.mapping))))
index_array.append([direction_idx, write, read]) #nur zu debug Zwecken
result.append(tuple(index_array))
# inner: wird zwischen benachbarten Zellen *im gleichen Block* geschickt
print("(inner:)")
pos_bound = int((self.domain_size[pos]-1)*(1+direction[pos])/2)
pos_mid = pos_bound+direction[pos]*(-self.domain_size[pos]+1)
sop_position = [int((self.domain_size[sop]-1)*(1+direction[sop])/2)] if direction[sop] != 0 else [0, self.domain_size[sop]-1]
#print("pos_bound:", pos_bound, "pos_mid", pos_mid, "sop_position:", sop_position)
print("second")
for b in sop_position:
for i in range(pos_bound, pos_mid, -direction[pos]):
write = [0,0]
write[pos] = i
write[sop] = b
if not (self.flag_arr[tuple(write)] & self.fluid_flag):
continue
read = [write_i - dir_i for write_i, dir_i in zip(write, direction)]
if self.flag_arr[tuple(read)] & self.no_slip_flag:
print("Read cell is a no_slip. Hmpf.")
print("write:", write, "read:", read)
inner.append([direction_idx, write, read])
if direction[pos] == 0: #spricht directions 1, 2, 3 und 4 an
# inner: wird zwischen benachbarte Zellen *im gleichen Block* geschickt
print("(inner:)")
print("third")
pos_low = 1
pos_high = self.domain_size[pos]-1
sop_position = int((self.domain_size[sop]-1)*(1+direction[sop])/2)
#print("pos_low:", pos_low, "pos_high:", pos_high, "sop_position:", sop_position)
for i in range(pos_low, pos_high):
write = [0,0]
write[pos] = i
write[sop] = sop_position
if not (self.flag_arr[tuple(write)] & self.fluid_flag):
continue
read = [write_i - dir_i for write_i, dir_i in zip(write, direction)]
if self.flag_arr[tuple(read)] & self.no_slip_flag:
print("Read cell is a no_slip. Hmpf.")
print("write:", write, "read:", read)
inner.append([direction_idx, write, read])
write = [int((self.domain_size[0]-1)*(1-direction[0])/2),int((self.domain_size[1]-1)*(1-direction[1])/2)]
if not (self.flag_arr[tuple(write)] & self.fluid_flag):
continue
read = [(write_i - dir_i)%ds_i for write_i, dir_i, ds_i in zip(write, direction, self.domain_size)]
#write_idx = self.cell_idx(tuple(write))
#read_idx = self.cell_idx(tuple(read))
#index_array.append((direction_idx, pdf_index(write_idx, direction_idx, len(self.mapping)), pdf_index(read_idx, direction_idx, len(self.mapping))))
index_array = []
index_array.append([direction_idx, write, read]) #nur zu debug Zwecken
result.append(tuple(index_array))
print("(Ecke) write:", write, "read:", read)
# result enthält *mehrere* index arrays
#result = list(dict.fromkeys(result)) # entferne doppelte index_arrays: speziell Ecken der Domain
# result ist eine liste von tuples von tuples --> [((...), (...)), ((...), (...), (...))]
#print(result)
# wandel result in list_result (liste von liste von listen) um: -->[[[...], [...]], [[...], [...], [...]]]
list_result = []
for index_array in result:
list_index_array = []
for write_read_pair in index_array:
list_index_array.append(list(write_read_pair))
list_result.append(list_index_array)
# zu den periodischen/parralel-orientierten index_arrays kommt noch der index array für die Werte, die nur innerhalb des Blocks verschickt werden:
list_result.append(inner)
print("start")
for index_array in list_result:
print(index_array)
print("end")
return list_result
def create_index_arr_old(self): # erstellt index arrays für ALLE fluid Zellen, die sich am Rand der domain befinden.
# ein index array für alle Werte, die innerhalb des Blocks verschickt werden
# jeweils ein index array für Werte, die zu jeweils verschiedenen benachbarten Blocks geschickt werden (wenn verschiedene Kerne verschiedene Blöcke innerhalb einer Domain bearbeiten)
stencil = self.method.stencil
......@@ -372,8 +494,9 @@ class SparseLbBoundaryMapper:
assert direction_idx == 0
continue
for own_cell_idx, cell in enumerate(mapping.fluid_coordinates):
inv_neighbor_cell = np.array([cell_i - dir_i for cell_i, dir_i in zip(cell, direction)])
if mapping.flag_array[tuple(inv_neighbor_cell)] & boundary_mask:
#inv_neighbor_cell = np.array([cell_i - dir_i for cell_i, dir_i in zip(cell, direction)])
inv_neighbor_cell = [(write_i - dir_i)%ds_i for write_i, dir_i, ds_i in zip(cell, direction, mapping.domain_size)]
if mapping.flag_array[tuple(inv_neighbor_cell)] & boundary_mask:
write = pdf_index(own_cell_idx, direction_idx, len(mapping))
read = pdf_index(own_cell_idx, inverse_idx(stencil, direction_idx), len(mapping))
result.append([direction_idx, write, read])
......
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