Commit 722bfe4d authored by Markus Holzer's avatar Markus Holzer
Browse files

Implemented eq for all boundaries

parent d3e266d6
Pipeline #32570 failed with stage
in 8 minutes and 38 seconds
......@@ -79,11 +79,6 @@ class LbBoundary:
def name(self, new_value):
self._name = new_value
def __eq__(self, other):
if isinstance(other, type(self)):
return self.__dict__ == other.__dict__
return False
# end class Boundary
......@@ -103,7 +98,13 @@ class NoSlip(LbBoundary):
def __call__(self, f_out, f_in, dir_symbol, inv_dir, lb_method, index_field):
return Assignment(f_in(inv_dir[dir_symbol]), f_out(dir_symbol))
def __eq__(self, other):
if not isinstance(other, NoSlip):
return False
return self.name == other.name
# end class NoSlip
......@@ -208,6 +209,13 @@ class UBB(LbBoundary):
else:
return [Assignment(f_in(inv_dir[direction]),
f_out(direction) - vel_term)]
def __eq__(self, other):
if not isinstance(other, UBB):
return False
return self.name == other.name
# end class UBB
......@@ -254,6 +262,13 @@ class SimpleExtrapolationOutflow(LbBoundary):
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]))
def __eq__(self, other):
if not isinstance(other, SimpleExtrapolationOutflow):
return False
return self.name == other.name
# end class SimpleExtrapolationOutflow
......@@ -401,6 +416,12 @@ class ExtrapolationOutflow(LbBoundary):
return AssignmentCollection(boundary_assignments, subexpressions=subexpressions)
def __eq__(self, other):
if not isinstance(other, ExtrapolationOutflow):
return False
return self.name == other.name
# end class ExtrapolationOutflow
......@@ -454,6 +475,11 @@ class FixedDensity(LbBoundary):
return subexpressions + [Assignment(f_in(inv_dir[dir_symbol]),
2 * eq_component - f_out(dir_symbol))]
def __eq__(self, other):
if not isinstance(other, FixedDensity):
return False
return self.name == other.name
# end class FixedDensity
......@@ -489,6 +515,11 @@ class DiffusionDirichlet(LbBoundary):
return [Assignment(f_in(inv_dir[dir_symbol]),
2 * w_dir * self.concentration - f_out(dir_symbol))]
def __eq__(self, other):
if not isinstance(other, DiffusionDirichlet):
return False
return self.name == other.name
# end class DiffusionDirichlet
......@@ -513,6 +544,12 @@ class NeumannByCopy(LbBoundary):
return [Assignment(f_in(inv_dir[dir_symbol]), f_out(inv_dir[dir_symbol])),
Assignment(f_out[neighbour_offset](dir_symbol), f_out(dir_symbol))]
def __eq__(self, other):
if not isinstance(other, NeumannByCopy):
return False
return self.name == other.name
# end class NeumannByCopy
......@@ -545,4 +582,9 @@ class StreamInConstant(LbBoundary):
return [Assignment(f_in(inv_dir[dir_symbol]), self.constant),
Assignment(f_out[neighbour_offset](dir_symbol), self.constant)]
def __eq__(self, other):
if not isinstance(other, StreamInConstant):
return False
return self.name == other.name
# end class StreamInConstant
import numpy as np
import pytest
from lbmpy.boundaries import UBB, NeumannByCopy, NoSlip, StreamInConstant
from lbmpy.boundaries import NoSlip, UBB, SimpleExtrapolationOutflow, ExtrapolationOutflow,\
FixedDensity, DiffusionDirichlet, NeumannByCopy, StreamInConstant
from lbmpy.boundaries.boundaryhandling import LatticeBoltzmannBoundaryHandling
from lbmpy.creationfunctions import create_lb_function
from lbmpy.creationfunctions import create_lb_function, create_lb_method
from lbmpy.geometry import add_box_boundary
from lbmpy.lbstep import LatticeBoltzmannStep
from lbmpy.stencils import get_stencil
from pystencils import create_data_handling, make_slice
......@@ -109,3 +111,42 @@ def test_exotic_boundaries():
step.boundary_handling.set_boundary(StreamInConstant(0), make_slice[0, :])
step.run(100)
assert np.max(step.velocity[:, :, :]) < 1e-13
def test_boundary_utility_functions():
stencil = get_stencil("D2Q9")
method = create_lb_method(stencil=stencil)
noslip = NoSlip("noslip")
assert noslip == NoSlip("noslip")
assert not noslip == NoSlip("test")
ubb = UBB((0, 0), name="ubb")
assert ubb == UBB((0, 0), name="ubb")
assert not noslip == UBB((0, 0), name="test")
simple_extrapolation = SimpleExtrapolationOutflow(normal_direction=stencil[4], stencil=stencil, name="simple")
assert simple_extrapolation == SimpleExtrapolationOutflow(normal_direction=stencil[4],
stencil=stencil, name="simple")
assert not simple_extrapolation == SimpleExtrapolationOutflow(normal_direction=stencil[4],
stencil=stencil, name="test")
outflow = ExtrapolationOutflow(normal_direction=stencil[4], lb_method=method, name="outflow")
assert outflow == ExtrapolationOutflow(normal_direction=stencil[4], lb_method=method, name="outflow")
assert not outflow == ExtrapolationOutflow(normal_direction=stencil[4], lb_method=method, name="test")
density = FixedDensity(density=1.0, name="fixedDensity")
assert density == FixedDensity(density=1.0, name="fixedDensity")
assert not density == FixedDensity(density=1.0, name="test")
diffusion = DiffusionDirichlet(concentration=1.0, name="diffusion")
assert diffusion == DiffusionDirichlet(concentration=1.0, name="diffusion")
assert not diffusion == DiffusionDirichlet(concentration=1.0, name="test")
neumann = NeumannByCopy(name="Neumann")
assert neumann == NeumannByCopy(name="Neumann")
assert not neumann == NeumannByCopy(name="Neumann")
stream = StreamInConstant(constant=1.0, name="stream")
assert stream == StreamInConstant(constant=1.0, name="stream")
assert not stream == StreamInConstant(constant=1.0, name="stream")
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