Skip to content
Snippets Groups Projects
Commit ea8431f5 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Changed SimpleExtrapolationOutflow to a link-wise approach

parent e14f9152
No related branches found
No related tags found
1 merge request!53Link-Wise Extrapolation Outflow
......@@ -221,10 +221,6 @@ class SimpleExtrapolationOutflow(LbBoundary):
name: optional name of the boundary.
"""
# We need each fluid cell only once, the direction of the outflow is given
# in the constructor.
single_link = True
def __init__(self, normal_direction, stencil, name=None):
if isinstance(normal_direction, str):
normal_direction = direction_string_to_offset(normal_direction, dim=len(stencil[0]))
......@@ -235,17 +231,23 @@ class SimpleExtrapolationOutflow(LbBoundary):
self.normal_direction = normal_direction
super(SimpleExtrapolationOutflow, self).__init__(name)
def __call__(self, f_out, f_in, dir_symbol, inv_dir, lb_method, index_field):
stencil = lb_method.stencil
def get_additional_code_nodes(self, lb_method):
"""Return a list of code nodes that will be added in the generated code before the index field loop.
boundary_assignments = []
for i, stencil_dir in enumerate(stencil):
if all(n == 0 or n == -s for s, n in zip(stencil_dir, self.normal_direction)):
asm = Assignment(f_out[self.normal_direction](i), f_out.center(i))
boundary_assignments.append(asm)
Args:
lb_method: Lattice Boltzmann method. See :func:`lbmpy.creationfunctions.create_lb_method`
print(boundary_assignments)
return boundary_assignments
Returns:
list containing LbmWeightInfo and NeighbourOffsetArrays
"""
return [NeighbourOffsetArrays(lb_method.stencil)]
def __call__(self, f_out, f_in, dir_symbol, inv_dir, lb_method, index_field):
neighbor_offset = NeighbourOffsetArrays.neighbour_offset(dir_symbol, lb_method.stencil)
tangential_offset = tuple(offset - normal for offset, normal in zip(neighbor_offset, self.normal_direction))
return Assignment(f_in.center(inv_dir[dir_symbol]), f_out[tangential_offset](inv_dir[dir_symbol]))
# end class SimpleExtrapolationOutflow
......
......@@ -10,6 +10,7 @@ from lbmpy.creationfunctions import create_lb_method
from lbmpy.advanced_streaming.utility import streaming_patterns
from pystencils.slicing import get_ghost_region_slice
from itertools import product
@pytest.mark.parametrize('stencil', ['D2Q9', 'D3Q27'])
@pytest.mark.parametrize('streaming_pattern', streaming_patterns)
......@@ -19,7 +20,7 @@ def test_pdf_simple_extrapolation(stencil, streaming_pattern):
values_per_cell = len(stencil)
# Field contains exactly one fluid cell
domain_size = (1,) * dim
domain_size = (3,) * dim
for timestep in get_timesteps(streaming_pattern):
dh = create_data_handling(domain_size, default_target='cpu')
lb_method = create_lb_method(stencil=stencil)
......@@ -36,30 +37,31 @@ def test_pdf_simple_extrapolation(stencil, streaming_pattern):
pdf_arr = dh.cpu_arrays[pdf_field.name]
# Set up the domain with artificial PDF values
center = (1,) * dim
# center = (1,) * dim
out_access = AccessPdfValues(stencil, streaming_pattern, timestep, 'out')
for q in range(values_per_cell):
out_access.write_pdf(pdf_arr, center, q, q)
for cell in product(*(range(1,4) for _ in range(dim))):
for q in range(values_per_cell):
out_access.write_pdf(pdf_arr, cell, q, q)
# Do boundary handling
bh(prev_timestep=timestep)
center = np.array(center)
# Check PDF values
in_access = AccessPdfValues(stencil, streaming_pattern, timestep.next(), 'in')
# Inbound in center cell
for q, streaming_dir in enumerate(stencil):
f = in_access.read_pdf(pdf_arr, center, q)
assert f == q
# Outbound in neighbors
for normal_dir in stencil[1:]:
for q, streaming_dir in enumerate(stencil):
neighbor = center + np.array(normal_dir)
if all(n == 0 or n == -s for s, n in zip(streaming_dir, normal_dir)):
f = out_access.read_pdf(pdf_arr, neighbor, q)
assert f == q
for cell in product(*(range(1,4) for _ in range(dim))):
for q in range(values_per_cell):
f = in_access.read_pdf(pdf_arr, cell, q)
assert f == q
# # Outbound in neighbors
# for normal_dir in stencil[1:]:
# for q, streaming_dir in enumerate(stencil):
# neighbor = center + np.array(normal_dir)
# if all(n == 0 or n == -s for s, n in zip(streaming_dir, normal_dir)):
# f = out_access.read_pdf(pdf_arr, neighbor, q)
# assert f == q
def test_extrapolation_outflow_initialization_by_copy():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment