SPATZ/spatz/sensors/pressure/pressure.py
2024-10-08 14:06:54 +02:00

54 lines
1.9 KiB
Python

import math
import numpy as np
from typing import List
from spatz.sensors import Sensor
from spatz.logger import Logger
from spatz.dataset import Dataset
from spatz.simulations.data_source import DataSource
from spatz.transforms import Transform
class PressureSensor(Sensor):
def __init__(self, dataset: DataSource, logger: Logger, transforms: List[Transform] = [], ts_effects=True, delay=0.0):
"""_summary_
Args:
dataset (Dataset): A dataset instance.
logger (Logger): _description_
transforms (List[Transform], optional): Transforms to apply to the sensor outputs. Defaults to [].
ts_effects (bool, optional): If True, adds transsonic effects using a very simple model. Defaults to True.
delay (float, optional): Adds a delay to the pressure measurements. Defaults to 0.0.
"""
super(PressureSensor, self).__init__(dataset, logger, transforms, min_value=0)
self._ts_effects = ts_effects
def set_transsonic_effects(self, active: bool):
self._ts_effects = active
def _get_data(self) -> float:
x = self._dataset.get_static_pressure()
if self._ts_effects:
# Pre-defined constants.
_p = 3e6
sigma = 100
# How far away from transsonic speed (mach 1) are we?
vvec = self._dataset.get_velocity('global')
dv = np.abs(np.linalg.norm(vvec) - self._dataset.get_speed_of_sound())
# Model transsonic effects by a peak at mach 1 which decays the further we are away from it.
ts_eff = _p * math.exp(-0.5* (dv / sigma)**2 ) / (sigma * math.sqrt(2*math.pi))
# Log the values for the transsonic effect.
self._log('ts_effects', ts_eff)
self._log('mach_no', self._dataset.get_mach_number())
self._log('speedofsound', self._dataset.get_speed_of_sound())
x = x + ts_eff
return x