mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/SPATZ.git
synced 2025-09-29 05:17:33 +00:00
Major rework using rocketpy
This commit is contained in:
47
spatz/simulations/advanceable.py
Normal file
47
spatz/simulations/advanceable.py
Normal file
@@ -0,0 +1,47 @@
|
||||
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
|
Reference in New Issue
Block a user