diff --git a/tests/test_sewer.py b/tests/test_sewer.py index 0ca4a289..3299c789 100644 --- a/tests/test_sewer.py +++ b/tests/test_sewer.py @@ -91,6 +91,26 @@ def test_make_discharge(self): d3 = {"volume": 7, "phosphate": 7 * 2 / 9, "temperature": 10} self.assertDictAlmostEqual(d3, sewer.sewer_tank.storage, 15) + def test_sewer_overrides(self): + sewer = Sewer(name="", capacity=10, pipe_timearea={0: 0.3, 1: 0.7}) + sewer.apply_overrides( + { + "capacity": 3, + "chamber_area": 2, + "chamber_floor": 3.5, + "pipe_time": 8.4, + "pipe_timearea": {0: 0.5, 1: 0.5}, + } + ) + self.assertEqual(sewer.capacity, 3) + self.assertEqual(sewer.sewer_tank.capacity, 3) + self.assertEqual(sewer.chamber_area, 2) + self.assertEqual(sewer.sewer_tank.area, 2) + self.assertEqual(sewer.chamber_floor, 3.5) + self.assertEqual(sewer.sewer_tank.datum, 3.5) + self.assertEqual(sewer.pipe_time, 8.4) + self.assertEqual(sewer.pipe_timearea, {0: 0.5, 1: 0.5}) + if __name__ == "__main__": unittest.main() diff --git a/wsimod/nodes/sewer.py b/wsimod/nodes/sewer.py index 545495c1..b49546be 100644 --- a/wsimod/nodes/sewer.py +++ b/wsimod/nodes/sewer.py @@ -4,6 +4,8 @@ @author: bdobson Converted to totals on 2022-05-03 """ +from typing import Any, Dict + from wsimod.core import constants from wsimod.nodes.nodes import Node from wsimod.nodes.tanks import QueueTank @@ -113,6 +115,33 @@ def __init__( # Mass balance self.mass_balance_ds.append(lambda: self.sewer_tank.ds()) + def apply_overrides(self, overrides: Dict[str, Any] = {}): + """Apply overrides to the sewer. + + Enables a user to override any of the following parameters: + capacity, chamber_area, chamber_floor, pipe_time, pipe_timearea. + + Args: + overrides (dict, optional): Dictionary of overrides. Defaults to {}. + """ + self.capacity = overrides.pop("capacity", self.capacity) + self.chamber_area = overrides.pop("chamber_area", self.chamber_area) + self.chamber_floor = overrides.pop("chamber_floor", self.chamber_floor) + self.sewer_tank.capacity = self.capacity + self.sewer_tank.area = self.chamber_area + self.sewer_tank.datum = self.chamber_floor + + self.pipe_time = overrides.pop("pipe_time", self.pipe_time) + if "pipe_timearea" in overrides.keys(): + pipe_timearea_sum = sum([v for k, v in overrides["pipe_timearea"].items()]) + if pipe_timearea_sum != 1: + print( + "ERROR: the sum of pipe_timearea in the overrides dict \ + is not equal to 1, please check it" + ) + self.pipe_timearea = overrides.pop("pipe_timearea", self.pipe_timearea) + super().apply_overrides(overrides) + def push_check_sewer(self, vqip=None): """Generic push check, simply looks at excess.