Commit ef82fc53 authored by Maja Warlich's avatar Maja Warlich
Browse files

Add test case.

parent c9453ace
Pipeline #35771 failed with stage
in 6 minutes and 52 seconds
......@@ -188,7 +188,6 @@ class SparseLbMapper:
index_array = np.array(result, dtype=np.uint32)
index_arr = index_array.reshape([len(stencil) - 1, len(self.fluid_coordinates)])
#index_arr = index_array.reshape([len(stencil) - 1, len(self.fluid_coordinates)-self._num_ghost_cells])
index_arr = index_arr.swapaxes(0, 1)
return index_arr
......@@ -199,16 +198,19 @@ class SparseLbMapper:
# Dann initial velocities in sparsen vector schreiben
fluid_cell_arr = self.coordinates
arr = fluid_cell_arr[:self.num_fluid_cells]
sparse_vel_arr = full_vel_arr[arr['x'], arr['y']]
if (len(self._flag_arr.shape) == 3):
sparse_vel_arr = full_vel_arr[arr['x'], arr['y'], arr['z']]
elif (len(self._flag_arr.shape) == 2):
sparse_vel_arr = full_vel_arr[arr['x'], arr['y']]
return sparse_vel_arr
class SparseLbPeriodicityMapper:
DIR_SYMBOL = TypedSymbol("dir", np.int64)
DIR_SYMBOL = TypedSymbol("dir", np.uint32)
def __init__(self, mapping: SparseLbMapper, dh, pdf_field_sparse):
index_field = Field.create_generic("idx", spatial_dimensions=1, index_dimensions=1, dtype=np.int64)
index_field = Field.create_generic("idx", spatial_dimensions=1, index_dimensions=1, dtype=np.uint32)
self.pdf_field_sparse = pdf_field_sparse
self.index_field = index_field
self.mapping = mapping
......@@ -226,8 +228,9 @@ class SparseLbPeriodicityMapper:
if self._dirty:
self.create_periodic_index_array()
self.create_kernel()
for i_a in self._index_arrays:
self._kernel(f=f, idx=i_a)
#for i_a in self._index_arrays:
#self._kernel(f=f, idx=i_a)
self._kernel(f=f, idx=self._index_arrays)
@property
def get_kernel(self):
......@@ -241,18 +244,10 @@ class SparseLbPeriodicityMapper:
self._ghost_cells = self.mapping._coordinate_arr[:self.mapping.num_fluid_cells][border_bool]
return
def get_pdf_read_idx(self, read, ghost, write, direction, direction_idx):
if self.flag_arr[tuple(read)] & self.no_slip_flag: # Read cell is no-slip!
raise ValueError("Read Cell is solid!")
return pdf_index(self.mapping.cell_idx(tuple(read)), direction_idx, len(self.mapping))
def get_assignment(self, direction, cell, bool_slice):
cell_idx = self.mapping.cell_idx(cell)
direction_idx = self.mapping.stencil.index(direction)
inv_neighbor_cell = [(cell_i - 2*dir_i*int(bs_i))%ds_i for cell_i, dir_i, ds_i, bs_i in zip(cell, direction, self.domain_size, bool_slice)]
inv_ghost_cell = [(cell_i - dir_i*int(bs_i))%ds_i for cell_i, dir_i, ds_i, bs_i in zip(cell, direction, self.domain_size, bool_slice)]
#print("write:", cell, "read:", tuple(inv_neighbor_cell))
pdf_read_idx = self.get_pdf_read_idx(inv_neighbor_cell, inv_ghost_cell, cell, direction, direction_idx)
pdf_read_idx = pdf_index(self.mapping.cell_idx(tuple(read)), direction_idx, len(self.mapping))
pdf_write_idx = pdf_index(cell_idx, direction_idx, len(self.mapping))
return [pdf_write_idx, pdf_read_idx]
......@@ -274,17 +269,20 @@ class SparseLbPeriodicityMapper:
# block_direction: where to put this part of index_array (which block to send to...)
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))
result[direction_idx-1][block_index-1].append(self.get_assignment(direction, cell, bool_slice))
result[block_index-1][direction_idx-1].append(self.get_assignment(direction, cell, bool_slice))
#print("Goes into", direction_idx-1, block_index-1)
# Flatten result array:
flattened_result = []
#print(result)
for block in result:
for i_a in block:
if (i_a):
flattened_result.append(np.array(i_a))
flattened_result = np.array(flattened_result)
for pair in i_a:
flattened_result.append(np.array(pair, dtype=np.uint32))
flattened_result = np.array(flattened_result, dtype=np.uint32)
self._index_arrays = flattened_result
self._dirty = False
#print(flattened_result)
return flattened_result
def assignments(self):
......@@ -357,7 +355,7 @@ class SparseLbCommunicationMapper:
for direction_idx, direction in enumerate(stencil):
if all(d_i == 0 for d_i in direction): # Direction (0,0) irrelevant
continue
print("\n New direction:", direction, ", ", direction_idx)
#print("\n New direction:", direction, ", ", direction_idx)
periodic_slice_coord = [[int((ds_i-1)*(1+dir_i)/2-dir_i)] if dir_i != 0 else [] for i, (dir_i, ds_i) in enumerate(zip(direction, self.domain_size))]
for cell in self.border_cells:
bool_slice = [cell_i in slice_i for (cell_i, slice_i) in zip(cell, periodic_slice_coord)]
......@@ -368,7 +366,7 @@ 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))
cell_idx = self.mapping.cell_idx(cell)
print(cell, cell_idx)
#print(cell, cell_idx)
result[block_index-1][direction_idx-1].append(pdf_index(cell_idx, direction_idx, len(self.mapping)))
#print("Goes into", block_index-1, direction_idx-1)
self._send_packages = result
......@@ -381,7 +379,7 @@ class SparseLbCommunicationMapper:
for direction_idx, direction in enumerate(stencil):
if all(d_i == 0 for d_i in direction): # Direction (0,0) irrelevant
continue
print("\n New direction:", direction, ", ", direction_idx)
#print("\n New direction:", direction, ", ", direction_idx)
periodic_slice_coord = [[int((ds_i-1)*(1-dir_i)/2)] if dir_i != 0 else [] for (dir_i, ds_i) in zip(direction, self.domain_size)]
for cell in self.ghost_cells: # Fluid and solid ghost cells
bool_slice = [cell_i in slice_i for (cell_i, slice_i) in zip(cell, periodic_slice_coord)]
......@@ -395,7 +393,7 @@ class SparseLbCommunicationMapper:
#future_pull_cell = [(cell_i + dir_i) for cell_i, dir_i, bs_i in zip(cell, direction, bool_slice)]
cell_idx = self.mapping.cell_idx(cell)
cell_idx = self.mapping.cell_idx(cell)
print(cell, cell_idx)
#print(cell, cell_idx)
result[block_index-1][direction_idx-1].append(pdf_index(cell_idx, direction_idx, len(self.mapping)))
#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)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment