"""BlockRegion class definition"""
from typing import Any
import os
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.defs import FunctionByPass
from g3d.mesh.geo.region import PrismRegion
from g3d.mesh.geo import Coord
[docs]
class BlockRegion(PrismRegion):
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self._width = 1.
def _set_default(self) -> Any:
super()._set_default()
self._tag = 'block_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 BlockRegion:
# if caught by a super class, the child class instance of copy will be used
args_stat[i] = 0
self.copy(arg)
elif type(arg) is PrismRegion:
args_stat[i] = 0
super().copy(arg)
return args_stat
[docs]
def set_from_key_value(self, key: str, value: Any) -> bool:
if super().set_from_key_value(key, value):
return True
elif key == 'width' or key == 'w':
self._width = value
return True
return False
@property
def width(self) -> float:
"""
:return:
"""
return self._width
@width.setter
def width(self, val: float) -> None:
self._width = val
[docs]
def copy(self, r: 'BlockRegion') -> None:
super().copy(r)
self._width = r.width
[docs]
def coord_is_in_region(self, c: Coord) -> bool:
"""
:param c:
:return:
"""
return False