From 28ae62e04003b1def7b726cdb85345055281f3bb Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Mon, 26 Oct 2020 13:42:44 +0100 Subject: [PATCH] Fix the Ventilation time units bug. --- cara/models.py | 2 +- cara/tests/test_known_quantities.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cara/models.py b/cara/models.py index 1dff7bd4..1e2ca4bc 100644 --- a/cara/models.py +++ b/cara/models.py @@ -74,7 +74,7 @@ class PeriodicHEPA(Ventilation): duration = self.duration / 60. # If the HEPA is off, no air is being exchanged - if time % self.period < (self.period - self.duration): + if (time % period) < (period - duration): return 0 return self.q_air_mech / room.volume diff --git a/cara/tests/test_known_quantities.py b/cara/tests/test_known_quantities.py index 206c5f05..8976a558 100644 --- a/cara/tests/test_known_quantities.py +++ b/cara/tests/test_known_quantities.py @@ -1,6 +1,6 @@ +import numpy as np import numpy.testing as npt import pytest -from numpy import linspace import cara.models as models @@ -60,7 +60,6 @@ def baseline_periodic_hepa(): def test_r0(baseline_model): - saturated = 2.909312e-01 ts = [0, 4, 5, 7, 10] concentrations = [baseline_model.concentration(t) for t in ts] npt.assert_allclose( @@ -71,14 +70,18 @@ def test_r0(baseline_model): def test_periodic_window(baseline_periodic_window, baseline_room): - ts = linspace(0, 9 * 60, 9) + # Interesting transition times for a period of 120 and duration of 15. + ts = [0, 14/60, 15/60, 16/60, 119/60, 120/60, 121/60, 239/60, 240/60] aes = [baseline_periodic_window.air_exchange(baseline_room, t) for t in ts] - answers = [0, 0, 0, 0, 0, 0, 0, 514.76 / 75, 0] + rate = 6.86347 + answers = [0, 0, 0, 0, rate, 0, 0, rate, 0] npt.assert_allclose(aes, answers, rtol=1e-5) def test_periodic_hepa(baseline_periodic_hepa, baseline_room): - ts = linspace(0, 9 * 60, 9) + # Interesting transition times for a period of 120 and duration of 15. + ts = [0, 14 / 60, 15 / 60, 16 / 60, 119 / 60, 120 / 60, 121 / 60, 239 / 60, 240 / 60] + rate = 514.74 / 75 aes = [baseline_periodic_hepa.air_exchange(baseline_room, t) for t in ts] - answers = [0, 0, 0, 0, 0, 0, 0, 514.74 / 75, 0] + answers = [0, 0, 0, 0, rate, 0, 0, rate, 0] npt.assert_allclose(aes, answers, rtol=1e-5)