Source code for g3d.mesh.modules.channel

"""channel (single-block) mesh module"""
from typing import Any

from g3d.defs import G3DWorld
from g3d.defs import NodeDistribution
from g3d.defs import BlockFace
from g3d.defs import AngleType
from g3d.defs import FaceOrientation
from g3d.defs import INTFTypes
from g3d.defs import DIMMode

from g3d.mesh.modules import BlockModule

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

from g3d.calc import EmbeddedCFlow
from g3d.calc import G3DChannelFlowCalculator


[docs] class ChannelModule(BlockModule): def __init__(self, *args: Any, **kwargs: Any) -> None: self._dy_wall = 1.e-3 # height of first cell in wall normal direction self._check_dim() super().__init__(*args, **kwargs) def _initialize_module(self, **kwargs: Any) -> None: super()._initialize_module(**kwargs) def _set_default(self) -> None: super()._set_default() self._calculator = EmbeddedCFlow() def _set_code_type(self) -> None: super()._set_code_type() g3d_world = G3DWorld() g3d_world.info.code_sub_description = 'channel flow module' def _check_dim(self) -> None: g3d_world = G3DWorld() if g3d_world.options.dim_mode == DIMMode.G2D or g3d_world.options.dim_mode == DIMMode.G2D_AXISYMM: self._z1 = 0. # lower z-coordinate self._z2 = 1. # upper z-coordinate self._nk = 2 @property def flow_data(self) -> G3DChannelFlowCalculator: """ :return: """ return self._calculator.channel_flow @property def u_tau(self) -> float: """ :return: """ return self._calculator.channel_flow.u_tau @u_tau.setter def u_tau(self, val: float) -> None: self._calculator.channel_flow.u_tau = val @property def rho(self) -> float: """ :return: """ return self._calculator.channel_flow.rho @rho.setter def rho(self, val: float) -> None: self._calculator.channel_flow.ho = val @property def tau_w(self) -> float: """ :return: """ return self._calculator.channel_flow.tau_w @tau_w.setter def tau_w(self, val: float) -> None: self._calculator.channel_flow.tau_w = val @property def Re(self) -> float: """ :return: """ return self._calculator.channel_flow.Re @Re.setter def Re(self, val: float) -> None: self._calculator.channel_flow.Re = val @property def Re_tau(self) -> float: """ :return: """ return self._calculator.channel_flow.Re_tau @Re_tau.setter def Re_tau(self, val: float) -> None: self._calculator.channel_flow.Re_tau = val @property def M(self) -> float: """ :return: """ return self._calculator.channel_flow.M @M.setter def M(self, val: float) -> None: self._calculator.channel_flow.M = val @property def delta(self) -> float: """ :return: """ return self._calculator.channel_flow.delta @delta.setter def delta(self, val: float) -> None: self._calculator.channel_flow.delta = val @property def L(self) -> float: """ :return: """ return self._calculator.channel_flow.L @L.setter def L(self, val: float) -> None: self._calculator.channel_flow.L = val @property def H(self) -> float: """ :return: """ return self._calculator.channel_flow.H @H.setter def H(self, val: float) -> None: self._calculator.channel_flow.H = val @property def W(self) -> float: """ :return: """ return self._calculator.channel_flow.W @W.setter def W(self, val: float) -> None: self._calculator.channel_flow.W = val @property def dx(self) -> float: """ :return: """ return self._calculator.channel_flow.L / (self._ni - 1) @property def dx_p(self) -> float: """ :return: """ return self.plusify(self.dx) @property def dy_p(self) -> float: """ :return: """ return self.plusify(self._dy_wall) @property def dz(self) -> float: """ :return: """ self._check_dim() return self._calculator.channel_flow.W / (self._nk - 1) @property def dz_p(self) -> float: """ :return: """ return self.plusify(self.dz)
[docs] def plusify(self, d: float) -> float: """ :param d: :return: """ return d * self._plusify_factor()
[docs] def de_plusify(self, d: float) -> float: """ :param d: :return: """ return d / self._plusify_factor()
def _plusify_factor(self) -> float: return (self._calculator.channel_flow.rho * self._calculator.channel_flow.u_tau / self._calculator.channel_flow.mu)
[docs] def print(self) -> None: self._calculator.channel_flow.print() print() print(' dx+ = %.2f (dx = %.3e m)' % (self.dx_p, self.dx)) print(' dy+ = %.2f (dy = %.3e m)' % (self.dy_p, self._dy_wall)) print(' dz+ = %.2f (dz = %.3e m)' % (self.dz_p, self.dz)) print()
def _generate_mesh(self) -> None: self._check_dim() g3d_world = G3DWorld() delta = self._calculator.channel_flow.delta L = self._calculator.channel_flow.L W = self._calculator.channel_flow.W self._x1 = 0.0 # left-end x-coordinate self._x2 = L # right-end x-coordinate self._y1 = -delta # lower y-coordinate self._y2 = delta # upper y-coordinate self._z1 = -0.5 * W # lower z-coordinate self._z2 = 0.5 * W # upper z-coordinate if g3d_world.options.dim_mode == DIMMode.G2D or g3d_world.options.dim_mode == DIMMode.G2D_AXISYMM: self._z1 = 0. # lower z-coordinate self._z2 = 1. # upper z-coordinate # ===================================================================== # Allocate block # ===================================================================== b1 = Block(self._ni, self._nj, self._nk) self.add_Block(b1) # ===================================================================== # Define coordinates # ===================================================================== c111 = Coord(self._x1, self._y1, self._z1) c211 = Coord(self._x2, self._y1, self._z1) c121 = Coord(self._x1, self._y2, self._z1) c221 = Coord(self._x2, self._y2, self._z1) # ===================================================================== # Define block edges # ===================================================================== ex1 = Edge([1, 1, 1, 1, self._ni], c111, c211, distribute=NodeDistribution.CURVE_2) b1.add_Edge(ex1) ex2 = Edge([1, self._nj, 1, 1, self._ni], c121, c221, distribute=NodeDistribution.CURVE_2) b1.add_Edge(ex2) c111m = Coord(c111, ialt=AngleType.IALT_2, alpha=0., beta=0., shape_factor=delta, spacing=self._dy_wall) c121m = Coord(c121, ialt=AngleType.IALT_2, alpha=0., beta=0., shape_factor=delta, spacing=self._dy_wall) ex3 = Edge([1, 1, 1, 3, self._nj], c111m, c121m, distribute=NodeDistribution.CURVE_4, stretch_rate=2.) b1.add_Edge(ex3) c211m = Coord(c211, ialt=AngleType.IALT_2, alpha=0., beta=0., shape_factor=delta, spacing=self._dy_wall) c221m = Coord(c221, ialt=AngleType.IALT_2, alpha=0., beta=0., shape_factor=delta, spacing=self._dy_wall) ex4 = Edge([self._ni, 1, 1, 3, self._nj], c211m, c221m, distribute=NodeDistribution.CURVE_4, stretch_rate=2.) b1.add_Edge(ex4) # ===================================================================== # Fill the KLOW plane with nodes # ===================================================================== b1.fill_Face(BlockFace.KLOW) # ===================================================================== # Extrude 2D face in K direction # ===================================================================== c112 = Coord(self._x1, self._y1, self._z2) e_ext = Edge(self._nk, c111, c112, distribute=NodeDistribution.CURVE_2) b1.extrude_Face(b1.get_Face(BlockFace.KLOW, FaceOrientation.INWARD_FACING_NORMAL), e_ext) def _add_boundaries(self) -> None: # ===================================================================== # Populate boundary list placeholders # ===================================================================== g3d_world = G3DWorld() L = self._calculator.channel_flow.L W = self._calculator.channel_flow.W for b in self._blocks: faceA = b.get_Face(BlockFace.ILOW, FaceOrientation.OUTWARD_FACING_NORMAL) faceA.delta.x = L faceB = b.get_Face(BlockFace.IHIGH, FaceOrientation.INWARD_FACING_NORMAL) self.add_Intf(faceA, faceB, intf_type=INTFTypes.TRANSPERINT) if g3d_world.options.dim_mode == DIMMode.G3D: faceA = b.get_Face(BlockFace.KLOW, FaceOrientation.OUTWARD_FACING_NORMAL) faceA.delta.z = W faceB = b.get_Face(BlockFace.KHIGH, FaceOrientation.INWARD_FACING_NORMAL) self.add_Intf(faceA, faceB, intf_type=INTFTypes.TRANSPERINT) self.add_BC(b.get_Face(BlockFace.JHIGH), tag='channel-wall') self.add_BC(b.get_Face(BlockFace.JLOW), tag='channel-wall')