From b97fdf904a76ca23d7abcb4cbdd9e17d27db3eeb Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Wed, 16 Jan 2008 15:23:32 -0500 Subject: [PATCH] Introduce SimulationLogQuantity as dt-dependent quantity base. --- src/log.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/log.py b/src/log.py index f2f2937..ffdc48b 100644 --- a/src/log.py +++ b/src/log.py @@ -31,6 +31,21 @@ class LogQuantity: +class SimulationLogQuantity(LogQuantity): + """A source of loggable scalars that needs to know the simulation timestep.""" + + def __init__(self, dt, name, unit=None, description=None): + LogQuantity.__init__(self, name, unit, description) + + self.dt = dt + + def set_dt(self, dt): + self.dt = dt + + + + + class CallableLogQuantityAdapter(LogQuantity): """Adapt a 0-ary callable as a L{LogQuantity}.""" def __init__(self, callable, name, unit=None, description=None): @@ -639,17 +654,13 @@ def add_general_quantities(mgr): -class SimulationTime(LogQuantity): +class SimulationTime(SimulationLogQuantity): """Record (monotonically increasing) simulation time.""" def __init__(self, dt, name="t_sim", start=0): - LogQuantity.__init__(self, name, "s", "Simulation Time") - self.dt = dt + SimulationLogQuantity.__init__(self, dt, name, "s", "Simulation Time") self.t = 0 - def set_dt(self, dt): - self.dt = dt - def __call__(self): result = self.t self.t += self.dt @@ -658,15 +669,11 @@ class SimulationTime(LogQuantity): -class Timestep(LogQuantity): +class Timestep(SimulationLogQuantity): """Record the magnitude of the simulated time step.""" def __init__(self, dt, name="dt"): - LogQuantity.__init__(self, name, "s", "Simulation Timestep") - self.dt = dt - - def set_dt(self, dt): - self.dt = dt + SimulationLogQuantity.__init__(self, dt, name, "s", "Simulation Timestep") def __call__(self): return self.dt @@ -676,8 +683,9 @@ class Timestep(LogQuantity): def set_dt(mgr, dt): """Set the simulation timestep on L{LogManager} C{mgr} to C{dt}.""" - mgr.quantity_data["dt"].quantity.set_dt(dt) - mgr.quantity_data["t_sim"].quantity.set_dt(dt) + for qdat in mgr.quantity_data.itervalues(): + if isinstance(qdat.quantity, SimulationLogQuantity): + qdat.quantity.set_dt(dt) -- GitLab