Source code for g3d.flow.domain.flow_region

"""FlowRegion class definition"""
import os
from typing import Any

if os.environ.get('__USE_CUDA', '0') == '1':
    import cupy as np
    from cupy import ndarray
else:
    import numpy as np
    from numpy import ndarray

from g3d.mesh.geo import IJKRegion

from g3d.defs import FunctionByPass

from g3d.gas import Gas
from g3d.flow.vars import Cons
from g3d.flow.vars import Auxv
from g3d.flow.vars import Post
from g3d.flow.vars import VGrad


[docs] class FlowRegion(IJKRegion): """definition of class FlowRegion, extends IJKRegion""" def __init__(self, *args: Any, **kwargs: Any) -> None: self._gas = Gas() self._cons = Cons() self._auxv = Auxv() self._post = Post() self._vgrad = VGrad() super().__init__(*args, **kwargs) def _set_default(self) -> None: super()._set_default() self._tag = 'flow_region' def _set_from_args(self, *args: Any, **kwargs: Any) -> ndarray: bps = self._get_function_evaluate_status(**kwargs) if bps is FunctionByPass.SELF: args_stat = np.ones(len(args)) else: args_stat = super()._set_from_args(*args) if bps in [FunctionByPass.EVALUATE, FunctionByPass.SELF]: if np.sum(args_stat) > 0: for i in range(len(args)): if args_stat[i] == 1: arg = args[i] if type(arg) is FlowRegion: args_stat[i] = 0 self.copy(arg) if type(arg) is IJKRegion: args_stat[i] = 0 super().copy(arg) elif type(arg) is Gas: args_stat[i] = 0 self._gas.copy(arg) elif type(arg) is Cons: args_stat[i] = 0 self._cons.copy(arg) elif type(arg) is Auxv: args_stat[i] = 0 self._auxv.copy(arg) elif type(arg) is Post: args_stat[i] = 0 self._post.copy(arg) elif type(arg) is VGrad: args_stat[i] = 0 self._vgrad.copy(arg) return args_stat
[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 if self._gas.set_from_key_value(key, value): return True if self._cons.set_from_key_value(key, value): return True if self._auxv.set_from_key_value(key, value): return True if self._post.set_from_key_value(key, value): return True if self._vgrad.set_from_key_value(key, value): return True if key in ['gas', 'cons', 'auxv', 'post', 'vgrad', 'region']: self._set_from_args(value) return True return False
@property def gas(self) -> Gas: """gas model Returns ------- Gas allocated gas model """ return self._gas @gas.setter def gas(self, g: Gas) -> None: self._gas = g @property def cons(self) -> Cons: """conservative variable object Returns ------- Cons allocated conservative variable object """ return self._cons @cons.setter def cons(self, c: Cons) -> None: self._cons = c @property def auxv(self) -> Auxv: """primitive variable object Returns ------- Auxv allocated primitive variable object """ return self._auxv @auxv.setter def auxv(self, a: Auxv) -> None: self._auxv = a @property def post(self) -> Post: """postprocessing variable object Returns ------- Post allocated postprocessing variable object """ return self._post @post.setter def post(self, p: Post) -> None: self._post = p @property def vgrad(self) -> VGrad: """velocity gradient object Returns ------- VGrad allocated velocity gradient object """ return self._vgrad @vgrad.setter def vgrad(self, v: VGrad) -> None: self._vgrad = v
[docs] def set_from_gas(self, g: Gas) -> None: """copies data from provided Gas object Parameters ---------- g : Gas gas model """ self._gas.copy(g)
[docs] def set_from_cons(self, c: Cons) -> None: """copies data from provided conservative variable object Parameters ---------- c : Cons instance of conservative variable """ self._cons.copy(c)
[docs] def set_from_auxv(self, a: Auxv) -> None: """copies data from provided primitive variable object Parameters ---------- a : Auxv instance of primitive variable """ self._auxv.copy(a)
[docs] def set_from_post(self, p: Post) -> None: """copies data from provided postprocessing variable object Parameters ---------- p : Post instance of postprocessing variable """ self._post.copy(p)
[docs] def set_from_vgrad(self, v: VGrad) -> None: """copies data from provided velocity gradient object Parameters ---------- v : VGrad instance of velocity gradient """ self._vgrad.copy(v)
[docs] def copy(self, r: 'FlowRegion') -> None: """copies data from prototype FlowRegion object Parameters ---------- r : FlowRegion prototype object - instance of class FlowRegion """ super().copy(r) if type(r) is FlowRegion: # ensures the parent call to copy with Region as input works self._gas.copy(r.gas) self._cons.copy(r.cons) self._auxv.copy(r.auxv) self._post.copy(r.post) self._vgrad.copy(r.vgrad)