Commit 71e5fd86 authored by Maja Warlich's avatar Maja Warlich
Browse files

Add periodicity to sparse mapping.

parent 3008aeb6
Pipeline #33352 failed with stage
in 8 minutes and 10 seconds
from .mapping import SparseLbBoundaryMapper, SparseLbMapper
from .mapping import SparseLbBoundaryMapper, SparseLbMapper, SparseLbPeriodicityMapper
from .update_rule_sparse import (
create_lb_update_rule_sparse, create_macroscopic_value_getter_sparse,
create_macroscopic_value_setter_sparse, create_symbolic_list)
__all__ = ['SparseLbBoundaryMapper', 'SparseLbMapper', 'create_lb_update_rule_sparse',
__all__ = ['SparseLbBoundaryMapper', 'SparseLbPeriodicityMapper', 'SparseLbMapper', 'create_lb_update_rule_sparse',
'create_macroscopic_value_setter_sparse', 'create_macroscopic_value_getter_sparse',
'create_symbolic_list']
......@@ -22,8 +22,8 @@ def pdf_index(cell_index, direction_index, domain_size):
def inverse_idx(stencil, idx):
return stencil.index(tuple(-d_i for d_i in stencil[idx]))
class SparseLbMapper:
"""Manages the mapping of cell coordinates to indices and back.
......@@ -130,13 +130,13 @@ class SparseLbMapper:
flag_arr = self.flag_array
no_slip_flag = self.no_slip_flag
fluid_boundary_mask = self.ubb_flag | self.fluid_flag | self.density_flag
print("Fuid boundary mask", fluid_boundary_mask)
#print("Fuid boundary mask", fluid_boundary_mask)
#fluid_boundary_mask = self.fluid_flag
print("Flag_arr.shape", flag_arr.shape)
#print("Flag_arr.shape", flag_arr.shape)
result = []
for direction_idx, direction in enumerate(stencil):
print("Direction:", direction_idx, direction)
#print("Direction:", direction_idx, direction)
if all(d_i == 0 for d_i in direction):
assert direction_idx == 0
continue
......@@ -155,15 +155,15 @@ class SparseLbMapper:
at_border = False
for i, x_i in enumerate(inv_neighbor_cell):
if x_i == (ghost_layers - 1): #if inv_neighbor_cell NOT noslip/fuid & one coordinate 0
print("before", inv_neighbor_cell[i])
#print("before", inv_neighbor_cell[i])
inv_neighbor_cell[i] += flag_arr.shape[i] - (2 * ghost_layers)
print("after", inv_neighbor_cell[i])
#print("after", inv_neighbor_cell[i])
at_border = True
test.append(("At Border Else", neighbor_cell_idx, "First"))
elif x_i == flag_arr.shape[i] - ghost_layers:
print("before", inv_neighbor_cell[i])
#print("before", inv_neighbor_cell[i])
inv_neighbor_cell[i] -= flag_arr.shape[i] - (2 * ghost_layers)
print("after", inv_neighbor_cell[i])
#print("after", inv_neighbor_cell[i])
at_border = True
test.append(("At Border Else", neighbor_cell_idx, "Second"))
if at_border:
......@@ -172,14 +172,44 @@ class SparseLbMapper:
result.append(pdf_index(neighbor_cell_idx, direction_idx, len(self)))
else:
raise ValueError("Could not find neighbor for {} direction {}".format(cell, direction))
print(test)
#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_arr.swapaxes(0, 1)
return index_arr
class SparseLbPeriodicityMapper:
def __init__(self, method, pdf_field_sparse, domain_size, periodicity):
self.method = method
self.domain_size = domain_size
def create_index_arr(self, mapping: SparseLbMapper):
stencil = self.method.stencil
print("domain_size:", self.domain_size)
#result = []
for direction_idx, direction in enumerate(stencil):
if all(d_i == 0 for d_i in direction):
assert direction_idx == 0
continue
print("direction:", direction, ", ", direction_idx)
for own_cell_idx, cell in enumerate(mapping.fluid_coordinates):
f_cell = ((cell[0]-direction[0])%self.domain_size[0], (cell[1]-direction[1])%self.domain_size[1])
if direction[1] == 1 and cell[1] == 0:
print("to cell:", cell, "from cell:", f_cell)
elif direction[1] == -1 and cell[1] == self.domain_size[1]-1:
print("to cell:", cell, "from cell:", f_cell)
elif direction[0] == 1 and cell[0] == 0:
print("to cell:", cell, "from cell:", f_cell)
elif direction[0] == -1 and cell[0] == self.domain_size[0]-1:
print("to cell:", cell, "from cell:", f_cell)
class SparseLbBoundaryMapper:
NEIGHBOR_IDX_NAME = 'nidx{}'
DIR_SYMBOL = TypedSymbol("dir", np.int64)
......@@ -231,7 +261,6 @@ class SparseLbBoundaryMapper:
continue
i = 1 if f_dir == "in" else 2
accessor_subs[fa] = pdf_field_sparse.absolute_access((index_field(i),), ())
print("Accessor:", accessor_subs)
self.boundary_eqs = assignments.new_with_substitutions(accessor_subs)
self.boundary_eqs_orig = assignments
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
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