diff --git a/lbmpy/boundaries/boundaryconditions.py b/lbmpy/boundaries/boundaryconditions.py index f6dd1bd5dd6c025b12f7efc5c0b5ded73e0497fc..d863e7b67dd64b6af19eac805ed39188e2e3a537 100644 --- a/lbmpy/boundaries/boundaryconditions.py +++ b/lbmpy/boundaries/boundaryconditions.py @@ -79,6 +79,14 @@ class LbBoundary: def name(self, new_value): self._name = new_value + def __hash__(self): + return hash(self.name) + + def __eq__(self, other): + if not isinstance(other, type(self)): + return False + return self.__dict__ == other.__dict__ + # end class Boundary @@ -99,15 +107,6 @@ 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 __hash__(self): - return hash(self.name) - - def __eq__(self, other): - if not isinstance(other, NoSlip): - return False - return self.__dict__ == other.__dict__ - - # end class NoSlip @@ -213,15 +212,6 @@ class UBB(LbBoundary): return [Assignment(f_in(inv_dir[direction]), f_out(direction) - vel_term)] - def __hash__(self): - return hash(self.name) - - def __eq__(self, other): - if not isinstance(other, UBB): - return False - return self.__dict__ == other.__dict__ - - # end class UBB @@ -269,15 +259,6 @@ class SimpleExtrapolationOutflow(LbBoundary): return Assignment(f_in.center(inv_dir[dir_symbol]), f_out[tangential_offset](inv_dir[dir_symbol])) - def __hash__(self): - return hash(self.name) - - def __eq__(self, other): - if not isinstance(other, SimpleExtrapolationOutflow): - return False - return self.__dict__ == other.__dict__ - - # end class SimpleExtrapolationOutflow @@ -425,15 +406,6 @@ class ExtrapolationOutflow(LbBoundary): return AssignmentCollection(boundary_assignments, subexpressions=subexpressions) - def __hash__(self): - return hash(self.name) - - def __eq__(self, other): - if not isinstance(other, ExtrapolationOutflow): - return False - return self.__dict__ == other.__dict__ - - # end class ExtrapolationOutflow @@ -487,15 +459,6 @@ class FixedDensity(LbBoundary): return subexpressions + [Assignment(f_in(inv_dir[dir_symbol]), 2 * eq_component - f_out(dir_symbol))] - def __hash__(self): - return hash(self.name) - - def __eq__(self, other): - if not isinstance(other, FixedDensity): - return False - return self.__dict__ == other.__dict__ - - # end class FixedDensity @@ -530,15 +493,6 @@ class DiffusionDirichlet(LbBoundary): return [Assignment(f_in(inv_dir[dir_symbol]), 2 * w_dir * self.concentration - f_out(dir_symbol))] - def __hash__(self): - return hash(self.name) - - def __eq__(self, other): - if not isinstance(other, DiffusionDirichlet): - return False - return self.__dict__ == other.__dict__ - - # end class DiffusionDirichlet @@ -562,15 +516,6 @@ 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 __hash__(self): - return hash(self.name) - - def __eq__(self, other): - if not isinstance(other, NeumannByCopy): - return False - return self.__dict__ == other.__dict__ - - # end class NeumannByCopy @@ -603,12 +548,4 @@ class StreamInConstant(LbBoundary): return [Assignment(f_in(inv_dir[dir_symbol]), self.constant), Assignment(f_out[neighbour_offset](dir_symbol), self.constant)] - def __hash__(self): - return hash(self.name) - - def __eq__(self, other): - if not isinstance(other, StreamInConstant): - return False - return self.__dict__ == other.__dict__ - # end class StreamInConstant diff --git a/lbmpy_tests/test_boundary_handling.py b/lbmpy_tests/test_boundary_handling.py index 9be3e4e85fb42056962639d9dfb83cb34f1cd792..13f6880efbe1d4bccd0dedb49a32cf30618976eb 100644 --- a/lbmpy_tests/test_boundary_handling.py +++ b/lbmpy_tests/test_boundary_handling.py @@ -120,33 +120,45 @@ def test_boundary_utility_functions(): noslip = NoSlip("noslip") assert noslip == NoSlip("noslip") assert not noslip == NoSlip("test") + assert not noslip == UBB((0, 0), name="ubb") + + assert noslip.name == "noslip" + noslip.name = "test name setter" + assert noslip.name == "test name setter" ubb = UBB((0, 0), name="ubb") assert ubb == UBB((0, 0), name="ubb") assert not noslip == UBB((0, 0), name="test") + assert not ubb == NoSlip("noslip") 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") + assert not simple_extrapolation == NoSlip("noslip") 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") + assert not outflow == simple_extrapolation density = FixedDensity(density=1.0, name="fixedDensity") assert density == FixedDensity(density=1.0, name="fixedDensity") assert not density == FixedDensity(density=1.0, name="test") + assert not density == UBB((0, 0), name="ubb") diffusion = DiffusionDirichlet(concentration=1.0, name="diffusion") assert diffusion == DiffusionDirichlet(concentration=1.0, name="diffusion") assert not diffusion == DiffusionDirichlet(concentration=1.0, name="test") + assert not diffusion == density neumann = NeumannByCopy(name="Neumann") assert neumann == NeumannByCopy(name="Neumann") assert not neumann == NeumannByCopy(name="test") + assert not neumann == diffusion stream = StreamInConstant(constant=1.0, name="stream") assert stream == StreamInConstant(constant=1.0, name="stream") assert not stream == StreamInConstant(constant=1.0, name="test") + assert not stream == noslip