Source code for g3d.mesh.modules.block

"""single-block mesh module"""
from typing import Any, Union

from g3d.defs import G3DWorld
from g3d.defs import NodeDistribution
from g3d.defs import BlockFace

from g3d.mesh.modules import MeshModule

from g3d.mesh.geo import Coord
from g3d.mesh.geo import Edge
from g3d.mesh.geo import Block


[docs] class BlockModule(MeshModule): def __init__(self, *args: Any, **kwargs: Any) -> None: super().__init__(*args, **kwargs) self._ni = 1 # number of nodes in I-direction self._nj = 1 # number of nodes in J-direction self._nk = 2 # number of nodes in K-direction (set to 2 for 2D-meshes) self._x1 = 0.0 # left-end x-coordinate self._x2 = 1.0 # right-end x-coordinate self._y1 = 0.0 # lower y-coordinate self._y2 = 1.0 # upper y-coordinate self._z1 = 0.0 # lower z-coordinate self._z2 = 1.0 # upper z-coordinate self._dx_wall = -1 # height of first cell in wall normal direction self._dy_wall = -1 # height of first cell in wall normal direction self._dz_wall = -1 # height of first cell in wall normal direction # (-1 gives equidistant cell size) self._nj_wall_offset = 0 # j-index of wall offset edge self._stretch_rate_x = 2.0 # cell stretch rate in the x-direction self._stretch_rate_y = 2.0 # cell stretch rate in the y-direction self._stretch_rate_z = 2.0 # cell stretch rate in the z-direction def _initialize_module(self, **kwargs: Any) -> None: super()._initialize_module(**kwargs) def _set_code_type(self) -> None: super()._set_code_type() g3d_world = G3DWorld() g3d_world.info.code_sub_description = 'single-block mesh module' @property def ni(self) -> int: """ :return: """ return self._ni @ni.setter def ni(self, val: int) -> None: self._ni = val @property def nj(self) -> int: """ :return: """ return self._nj @nj.setter def nj(self, val: int) -> None: self._nj = val @property def nk(self) -> int: """ :return: """ return self._nk @nk.setter def nk(self, val: int) -> None: self._nk = val @property def x1(self) -> float: """ :return: """ return self._x1 @x1.setter def x1(self, val: float) -> None: self._x1 = val @property def x2(self) -> float: """ :return: """ return self._x2 @x2.setter def x2(self, val: float) -> None: self._x2 = val @property def y1(self) -> float: """ :return: """ return self._y1 @y1.setter def y1(self, val: float) -> None: self._y1 = val @property def y2(self) -> float: """ :return: """ return self._y2 @y2.setter def y2(self, val: float) -> None: self._y2 = val @property def z1(self) -> float: """ :return: """ return self._z1 @z1.setter def z1(self, val: float) -> None: self._z1 = val @property def z2(self) -> float: """ :return: """ return self._z2 @z2.setter def z2(self, val: float) -> None: self._z2 = val @property def dx_wall(self) -> Union[float, int]: """ :return: """ return self._dx_wall @dx_wall.setter def dx_wall(self, val: Union[float, int]) -> None: self._dx_wall = val @property def dy_wall(self) -> Union[float, int]: """ :return: """ return self._dy_wall @dy_wall.setter def dy_wall(self, val: Union[float, int]) -> None: self._dy_wall = val @property def dz_wall(self) -> Union[float, int]: """ :return: """ return self._dz_wall @dz_wall.setter def dz_wall(self, val: Union[float, int]) -> None: self._dz_wall = val @property def stretch_rate_x(self) -> float: """ :return: """ return self._stretch_rate_x @stretch_rate_x.setter def stretch_rate_x(self, val: float) -> None: self._stretch_rate_x = val @property def stretch_rate_y(self) -> float: """ :return: """ return self._stretch_rate_y @stretch_rate_y.setter def stretch_rate_y(self, val: float) -> None: self._stretch_rate_y = val @property def stretch_rate_z(self) -> float: """ :return: """ return self._stretch_rate_z @stretch_rate_z.setter def stretch_rate_z(self, val: float) -> None: self._stretch_rate_z = val def _generate_mesh(self) -> None: # ===================================================================== # Allocate block # ===================================================================== b1 = Block(self._ni, self._nj, self._nk) self.add_Block(b1) # ===================================================================== # Define coordinates # ===================================================================== c11 = Coord(self._x1, self._y1, self._z1) c12 = Coord(self._x1, self._y2, self._z1) c13 = Coord(self._x1, self._y2, self._z2) c14 = Coord(self._x1, self._y1, self._z2) c21 = Coord(self._x2, self._y1, self._z1) c22 = Coord(self._x2, self._y2, self._z1) c23 = Coord(self._x2, self._y2, self._z2) c24 = Coord(self._x2, self._y1, self._z2) # ===================================================================== # Define block edges # ===================================================================== c12m = Coord(c12, spacing=self._dz_wall) c13m = Coord(c13, spacing=self._dz_wall) e11 = Edge([1, self._nj, 1, 5, self._nk], c12m, c13m, distribute=NodeDistribution.CURVE_2, stretch_rate=self._stretch_rate_z) b1.add_Edge(e11) c13m = Coord(c13, spacing=self._dy_wall) c14m = Coord(c14, spacing=self._dy_wall) e12 = Edge([1, self._nj, self._nk, 4, self._nj], c13m, c14m, distribute=NodeDistribution.CURVE_2, stretch_rate=self._stretch_rate_y) b1.add_Edge(e12) c11m = Coord(c11, spacing=self._dz_wall) c14m = Coord(c14, spacing=self._dz_wall) e13 = Edge([1, 1, self._nk, 6, self._nk], c14m, c11m, distribute=NodeDistribution.CURVE_2, stretch_rate=self._stretch_rate_z) b1.add_Edge(e13) c11m = Coord(c11, spacing=self._dy_wall) c12m = Coord(c12, spacing=self._dy_wall) e14 = Edge([1, 1, 1, 3, self._nj], c11m, c12m, distribute=NodeDistribution.CURVE_2, stretch_rate=self._stretch_rate_y) b1.add_Edge(e14) # ===================================================================== c22m = Coord(c22, spacing=self._dz_wall) c23m = Coord(c23, spacing=self._dz_wall) e21 = Edge([self._ni, self._nj, 1, 5, self._nk], c22m, c23m, distribute=NodeDistribution.CURVE_2, stretch_rate=self._stretch_rate_z) b1.add_Edge(e21) c23m = Coord(c23, spacing=self._dy_wall) c24m = Coord(c24, spacing=self._dy_wall) e22 = Edge([self._ni, self._nj, self._nk, 4, self._nj], c23m, c24m, distribute=NodeDistribution.CURVE_2, stretch_rate=self._stretch_rate_y) b1.add_Edge(e22) c21m = Coord(c21, spacing=self._dz_wall) c24m = Coord(c24, spacing=self._dz_wall) e23 = Edge([self._ni, 1, self._nk, 6, self._nk], c24m, c21m, distribute=NodeDistribution.CURVE_2, stretch_rate=self._stretch_rate_z) b1.add_Edge(e23) c21m = Coord(c21, spacing=self._dy_wall) c22m = Coord(c22, spacing=self._dy_wall) e24 = Edge([self._ni, 1, 1, 3, self._nj], c21m, c22m, distribute=NodeDistribution.CURVE_2, stretch_rate=self._stretch_rate_y) b1.add_Edge(e24) # ===================================================================== c11m = Coord(c11, spacing=self._dx_wall) c21m = Coord(c21, spacing=self._dx_wall) ei1 = Edge([1, 1, 1, 1, self._ni], c11m, c21m, distribute=NodeDistribution.CURVE_2, stretch_rate=self._stretch_rate_x) b1.add_Edge(ei1) c12m = Coord(c12, spacing=self._dx_wall) c22m = Coord(c22, spacing=self._dx_wall) ei2 = Edge([1, self._nj, 1, 1, self._ni], c12m, c22m, distribute=NodeDistribution.CURVE_2, stretch_rate=self._stretch_rate_x) b1.add_Edge(ei2) c13m = Coord(c13, spacing=self._dx_wall) c23m = Coord(c23, spacing=self._dx_wall) ei3 = Edge([1, self._nj, self._nk, 1, self._ni], c13m, c23m, distribute=NodeDistribution.CURVE_2, stretch_rate=self._stretch_rate_x) b1.add_Edge(ei3) c14m = Coord(c14, spacing=self._dx_wall) c24m = Coord(c24, spacing=self._dx_wall) ei4 = Edge([1, 1, self._nk, 1, self._ni], c14m, c24m, distribute=NodeDistribution.CURVE_2, stretch_rate=self._stretch_rate_x) b1.add_Edge(ei4) # ===================================================================== # Fill block faces and volume # ===================================================================== for b in self._blocks: b.fill_Face(BlockFace.ILOW) b.fill_Face(BlockFace.IHIGH) b.fill_Face(BlockFace.JLOW) b.fill_Face(BlockFace.JHIGH) b.fill_Face(BlockFace.KLOW) b.fill_Face(BlockFace.KHIGH) b.fill() def _add_boundaries(self) -> None: # ===================================================================== # Fill block faces and populate boundary placeholders # ===================================================================== for b in self._blocks: self.add_BC(b.get_Face(BlockFace.JLOW), tag='walls') self.add_BC(b.get_Face(BlockFace.JHIGH), tag='walls') self.add_BC(b.get_Face(BlockFace.KLOW), tag='walls') self.add_BC(b.get_Face(BlockFace.KHIGH), tag='walls') self.add_IO(b.get_Face(BlockFace.ILOW), tag='inlet') self.add_IO(b.get_Face(BlockFace.IHIGH), tag='outlet')