"""Boundary condition modifiers"""
import os
from typing import Any
if os.environ.get('__USE_CUDA', '0') == '1':
import cupy as np
else:
import numpy as np
from g3d.gas import Gas
from g3d.defs import G3DRamp
from g3d.defs import RampType
from .boundaries import BoCo
[docs]
class BCMod(BoCo):
"""Definition of class BCMode, extends class BoCo: used for boundary condition modification"""
def __init__(self, *args: Any, **kwargs: Any) -> None:
self._p0 = 0.
self._t0 = 0
super().__init__(*args, **kwargs)
def _set_default(self) -> None:
super()._set_default()
self._tag = 'g3d_boco_ramp'
self._ramp = G3DRamp()
[docs]
def set_from_key_value(self, key: str, value: Any) -> bool:
"""Sets data from key-value pair input
Parameters
----------
key: str :
keyword
value: Any :
value corresponding to keyword
Returns
-------
bool
status - True if key is found in list of valid keywords
"""
if super().set_from_key_value(key, value):
return True
elif self._ramp.set_from_key_value(key, value):
return True
return False
@property
def type(self) -> Any:
"""Ramp type
Returns
-------
RampType
ramp type
"""
return self._ramp.type
@type.setter
def type(self, val: Any) -> None:
if type(val) is RampType:
self._ramp.type = val
@property
def start_val(self) -> float:
"""Ramp start value
Returns
-------
float
start value
"""
return self._ramp.start_val
@start_val.setter
def start_val(self, val: float) -> None:
self._ramp.start_val = val
@property
def end_val(self) -> float:
"""Ramp end value
Returns
-------
float
end value
"""
return self._ramp.end_val
@end_val.setter
def end_val(self, val: float) -> None:
self._ramp.end_val = val
@property
def start_iter(self) -> int:
"""Ramp start iteration
Returns
-------
int
start iteration
"""
return self._ramp.start_iter
@start_iter.setter
def start_iter(self, val: int) -> None:
self._ramp.start_iter = val
@property
def end_iter(self) -> int:
"""Ramp end iteration
Returns
-------
int
end iteration
"""
return self._ramp.end_iter
@end_iter.setter
def end_iter(self, val: int) -> None:
self._ramp.end_iter = val
[docs]
def evaluate(self, gas: Gas) -> None:
"""Evaluates ramp
Parameters
----------
gas : Gas :
gas model
"""
val = self._ramp.get_val()
if self._ramp.type is RampType.MACH:
self.bc_update_speed_of_sound(gas)
vel = val * self._auxv.c
ref = np.sqrt(self._auxv.uiui())
self._auxv.u *= vel / ref
self._auxv.v *= vel / ref
self._auxv.w *= vel / ref
self.bc_update_conservative(gas)
elif self._ramp.type is RampType.PRESSURE:
self._auxv.p = val
self.bc_update_conservative(gas)
elif self._ramp.type is RampType.TOTAL_PRESSURE:
self._p0 = val
elif self._ramp.type is RampType.TOTAL_TEMPERATURE:
self._t0 = val