def expand_y(self, dist): """Expand blockMeshDict boundingbox for dist in y and -y directions.""" _y_axis = self.y_axis for i in (0, 1, 5, 4): self.vertices[i] = vectormath.move( self.vertices[i], vectormath.scale(_y_axis, -dist)) for i in (3, 2, 6, 7): self.vertices[i] = vectormath.move(self.vertices[i], vectormath.scale(_y_axis, dist))
def expandZ(self, dist): """Expand blockMeshDict boundingbox for dist in z and -z directions.""" _zAxis = (0, 0, 1) for i in (0, 1, 2, 3): self.vertices[i] = vectormath.move(self.vertices[i], vectormath.scale(_zAxis, -dist)) for i in (4, 5, 6, 7): self.vertices[i] = vectormath.move(self.vertices[i], vectormath.scale(_zAxis, dist))
def expandY(self, dist): """Expand blockMeshDict boundingbox for dist in y and -y directions.""" _zAxis = (0, 0, 1) _yAxis = vectormath.crossProduct(_zAxis, self.xAxis) for i in (0, 1, 5, 4): self.vertices[i] = vectormath.move(self.vertices[i], vectormath.scale(_yAxis, -dist)) for i in (3, 2, 6, 7): self.vertices[i] = vectormath.move(self.vertices[i], vectormath.scale(_yAxis, dist))
def expand_x(self, dist): """Expand blockMeshDict boundingbox for dist in x and -x directions.""" _x_axis = self.x_axis for i in (0, 3, 7, 4): self.vertices[i] = vectormath.move( self.vertices[i], vectormath.scale(_x_axis, -dist)) for i in (1, 2, 6, 5): self.vertices[i] = vectormath.move(self.vertices[i], vectormath.scale(_x_axis, dist))
def expandX(self, dist): """Expand blockMeshDict boundingbox for dist in x and -x directions.""" _xAxis = (self.xAxis[0], self.xAxis[1], 0) if len(self.xAxis) == 2 \ else self.xAxis for i in (0, 3, 7, 4): self.vertices[i] = vectormath.move(self.vertices[i], vectormath.scale(_xAxis, -dist)) for i in (1, 2, 6, 5): self.vertices[i] = vectormath.move(self.vertices[i], vectormath.scale(_xAxis, dist))
def __calculate2dPoints(v, o, n, w): # project point p = vectormath.project(v, o, n) # move the projected point backwards for half of the width t = vectormath.scale(vectormath.normalize(vectormath.subtract(v, p)), w / 2.0) return vectormath.move(p, t)
def from_min_max(cls, min_pt, max_pt, convertToMeters=1, n_div_xyz=None, grading=None, x_axis=None): """Create BlockMeshDict from minimum and maximum point. Args: min_pt: Minimum point of bounding box as (x, y, z). max_pt: Maximum point of bounding box as (x, y, z). convertToMeters: Scaling factor for the vertex coordinates. n_div_xyz: Number of divisions in (x, y, z) as a tuple (default: 5, 5, 5). grading: A simpleGrading (default: simpleGrading(1, 1, 1)). x_axis: An optional tuple that indicates the x_axis direction (default: (1, 0)). """ _x_axis = vectormath.normalize((x_axis[0], x_axis[1], 0) if x_axis else (1, 0, 0)) _z_axis = (0, 0, 1) _y_axis = vectormath.cross_product(_z_axis, _x_axis) diagonal2_d = tuple(i - j for i, j in zip(max_pt, min_pt))[:2] _angle = radians( vectormath.angle_anitclockwise(_x_axis[:2], diagonal2_d)) width = cos(_angle) * vectormath.length(diagonal2_d) length = sin(_angle) * vectormath.length(diagonal2_d) height = max_pt[2] - min_pt[2] vertices = [ vectormath.move( min_pt, vectormath.sums((vectormath.scale(_x_axis, i * width), vectormath.scale(_y_axis, j * length), vectormath.scale(_z_axis, k * height)))) for i in range(2) for j in range(2) for k in range(2) ] return cls.from_vertices(vertices, convertToMeters, n_div_xyz, grading, x_axis)
def fromOriginAndSize(cls, origin, width, length, height, convertToMeters=1, nDivXYZ=None, grading=None, xAxis=None): """Create BlockMeshDict from BFBlockGeometries. Args: origin: Minimum point of bounding box as (x, y, z). width: Width in x direction. length: Length in y direction. height: Height in y direction. convertToMeters: Scaling factor for the vertex coordinates. nDivXYZ: Number of divisions in (x, y, z) as a tuple (default: 5, 5, 5). grading: A simpleGrading (default: simpleGrading(1, 1, 1)). xAxis: An optional tuple that indicates the xAxis direction (default: (1, 0)). """ _xAxis = vectormath.normalize((xAxis[0], xAxis[1], 0) if xAxis else (1, 0, 0)) _zAxis = (0, 0, 1) _yAxis = vectormath.crossProduct(_zAxis, _xAxis) vertices = [ vectormath.move( origin, vectormath.sums((vectormath.scale(_xAxis, i * width), vectormath.scale(_yAxis, j * length), vectormath.scale(_zAxis, k * height)))) for i in range(2) for j in range(2) for k in range(2) ] return cls.fromVertices(vertices, convertToMeters, nDivXYZ, grading, xAxis)
def fromGeometriesWindVectorAndParameters(cls, name, geometries, windVector, tunnelParameters, roughness, meshingParameters=None, Zref=None, convertToMeters=1): """Create a windTunnel based on size, wind speed and wind direction.""" # butterfly geometries geos = tuple(cls.__checkInputGeometry(geo) for geo in geometries) # update boundary condition of wall geometries for bfGeometry in geometries: bfGeometry.boundaryCondition = WindTunnelWallBoundaryCondition() tp = tunnelParameters # find xAxis # project wind vector to XY Plane windVector = (windVector[0], windVector[1], 0) zAxis = (0, 0, 1) xAxis = vm.crossProduct(windVector, zAxis) yAxis = vm.normalize(windVector) # get size of bounding box from blockMeshDict minPt, maxPt = calculateMinMaxFromBFGeometries(geos, xAxis) _blockMeshDict = BlockMeshDict.fromMinMax(minPt, maxPt, convertToMeters, xAxis=xAxis) # scale based on wind tunnel parameters ver = _blockMeshDict.vertices height = _blockMeshDict.height v0 = vm.move(ver[0], vm.scale(yAxis, -tp.windward * height)) v0 = vm.move(v0, vm.scale(xAxis, -tp.side * height)) v1 = vm.move(ver[1], vm.scale(yAxis, -tp.windward * height)) v1 = vm.move(v1, vm.scale(xAxis, tp.side * height)) v2 = vm.move(ver[2], vm.scale(yAxis, tp.leeward * height)) v2 = vm.move(v2, vm.scale(xAxis, tp.side * height)) v3 = vm.move(ver[3], vm.scale(yAxis, tp.leeward * height)) v3 = vm.move(v3, vm.scale(xAxis, -tp.side * height)) v4 = vm.move(v0, vm.scale(zAxis, tp.top * height)) v5 = vm.move(v1, vm.scale(zAxis, tp.top * height)) v6 = vm.move(v2, vm.scale(zAxis, tp.top * height)) v7 = vm.move(v3, vm.scale(zAxis, tp.top * height)) # create inlet, outlet, etc ablConditions = ABLConditions.fromInputValues( flowSpeed=vm.length(windVector), z0=roughness, flowDir=vm.normalize(windVector), zGround=_blockMeshDict.minZ) _order = (range(4), ) inlet = BFBlockGeometry( 'inlet', (v0, v1, v5, v4), _order, ((v0, v1, v5, v4), ), WindTunnelInletBoundaryCondition(ablConditions)) outlet = BFBlockGeometry('outlet', (v2, v3, v7, v6), _order, ((v2, v3, v7, v6), ), WindTunnelOutletBoundaryCondition()) rightSide = BFBlockGeometry('rightSide', (v1, v2, v6, v5), _order, ((v1, v2, v6, v5), ), WindTunnelTopAndSidesBoundaryCondition()) leftSide = BFBlockGeometry('leftSide', (v3, v0, v4, v7), _order, ((v3, v0, v4, v7), ), WindTunnelTopAndSidesBoundaryCondition()) top = BFBlockGeometry('top', (v4, v5, v6, v7), _order, ((v4, v5, v6, v7), ), WindTunnelTopAndSidesBoundaryCondition()) ground = BFBlockGeometry( 'ground', (v3, v2, v1, v0), (range(4), ), ((v3, v2, v1, v0), ), WindTunnelGroundBoundaryCondition(ablConditions)) # return the class wt = cls(name, inlet, outlet, (rightSide, leftSide), top, ground, geometries, roughness, meshingParameters, Zref, convertToMeters) return wt