Ejemplo n.º 1
0
    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 = tuple(
            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)
Ejemplo n.º 2
0
    def fromMinMax(cls, minPt, maxPt, convertToMeters=1, nDivXYZ=None, grading=None,
                   xAxis=None):
        """Create BlockMeshDict from minimum and maximum point.

        Args:
            minPt: Minimum point of bounding box as (x, y, z).
            maxPt: Maximum point of bounding box as (x, y, z).
            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)
        diagonal2D = tuple(i - j for i, j in zip(maxPt, minPt))[:2]
        _angle = radians(vectormath.angleAnitclockwise(_xAxis[:2], diagonal2D))
        width = cos(_angle) * vectormath.length(diagonal2D)
        length = sin(_angle) * vectormath.length(diagonal2D)
        height = maxPt[2] - minPt[2]

        vertices = tuple(
            vectormath.move(minPt,
                            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)
Ejemplo n.º 3
0
    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))
Ejemplo n.º 4
0
    def fromMinMax(cls,
                   minPt,
                   maxPt,
                   convertToMeters=1,
                   nDivXYZ=None,
                   grading=None,
                   xAxis=None):
        """Create BlockMeshDict from minimum and maximum point.

        Args:
            minPt: Minimum point of bounding box as (x, y, z).
            maxPt: Maximum point of bounding box as (x, y, z).
            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)
        diagonal2D = tuple(i - j for i, j in zip(maxPt, minPt))[:2]
        _angle = radians(vectormath.angleAnitclockwise(_xAxis[:2], diagonal2D))
        width = cos(_angle) * vectormath.length(diagonal2D)
        length = sin(_angle) * vectormath.length(diagonal2D)
        height = maxPt[2] - minPt[2]

        vertices = [
            vectormath.move(
                minPt,
                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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    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(
                bfGeometry.boundaryCondition.refLevels
            )

        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