mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/SPATZ.git
synced 2025-06-10 01:55:59 +00:00
47 lines
1.0 KiB
Python
47 lines
1.0 KiB
Python
from abc import abstractmethod
|
|
|
|
|
|
class Advanceable:
|
|
def __init__(self) -> None:
|
|
self.reset()
|
|
|
|
def advance(self, dt: float):
|
|
"""Advances the simulation data in time.
|
|
|
|
Args:
|
|
dt (float): The step in time to make.
|
|
"""
|
|
self.__t += dt
|
|
self._on_step(dt)
|
|
|
|
def advance_to(self, t: float):
|
|
"""Advances the simulation data to a new point in time.
|
|
|
|
Args:
|
|
t (float): The target point in time.
|
|
"""
|
|
assert t > self.__t, 'Advanceable can only move forward in time.'
|
|
|
|
self.advance(t - self.__t)
|
|
|
|
def reset(self):
|
|
"""
|
|
Reset the Avanceable object to its initial state.
|
|
"""
|
|
self.__t = 0
|
|
self._on_reset()
|
|
|
|
@abstractmethod
|
|
def _on_step(self, dt: float):
|
|
pass
|
|
|
|
@abstractmethod
|
|
def _on_reset(self):
|
|
pass
|
|
|
|
def get_time(self) -> float:
|
|
"""
|
|
Returns:
|
|
float: Returns the current time of the Advanceable.
|
|
"""
|
|
return self.__t |