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)
Beispiel #2
0
    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)
Beispiel #3
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
    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