def __init__(self, nu, scale):
        cell_nums = (int(32 * scale), int(24 * scale))
        E = 100
        vol_tol = 1e-3
        edge_sample_num = 2
        EnvBase.__init__(self, cell_nums, E, nu, vol_tol, edge_sample_num,
                         None)

        # Initial condition.
        control_points_lower = ndarray([[32, 10], [22, 10], [12, 10], [0, 4]
                                        ]) * scale
        control_points_upper = ndarray([[0, 20], [12, 14], [22, 14], [32, 14]
                                        ]) * scale
        self._sample = np.concatenate(
            [control_points_lower.ravel(),
             control_points_upper.ravel()])

        # Initialize the parametric shapes.
        self._parametric_shape_info = [('bezier', 8), ('bezier', 8)]
        # Initialize the node conditions.
        self._node_boundary_info = []
        inlet_velocity = 1.0
        for j in range(cell_nums[1] + 1):
            if control_points_lower[3, 1] < j < control_points_upper[0, 1]:
                self._node_boundary_info.append(((0, j, 0), inlet_velocity))
                self._node_boundary_info.append(((0, j, 1), 0))
        # Initialize the interface.
        self._interface_boundary_type = 'free-slip'

        self._scale = scale
示例#2
0
    def __init__(self, seed, folder):
        np.random.seed(seed)

        cell_nums = (64, 48)
        E = 100
        nu = 0.499
        vol_tol = 1e-3
        edge_sample_num = 2
        EnvBase.__init__(self, cell_nums, E, nu, vol_tol, edge_sample_num,
                         folder)

        # Initialize the parametric shapes.
        self._parametric_shape_info = [('bezier', 8), ('bezier', 8)]
        # Initialize the node conditions.
        self._node_boundary_info = []
        inlet_velocity = 1
        inlet_range = ndarray([0.125, 0.875])
        inlet_lb, inlet_ub = inlet_range * cell_nums[1]
        for j in range(cell_nums[1] + 1):
            if inlet_lb < j < inlet_ub:
                self._node_boundary_info.append(((0, j, 0), inlet_velocity))
                self._node_boundary_info.append(((0, j, 1), 0))
        # Initialize the interface.
        self._interface_boundary_type = 'free-slip'

        # Other data members.
        self._inlet_velocity = inlet_velocity
        self._outlet_velocity = 3 * inlet_velocity
        self._inlet_range = inlet_range
示例#3
0
    def __init__(self, seed, folder):
        np.random.seed(seed)

        cell_nums = (64, 64, 4)
        E = 100
        nu = 0.499
        vol_tol = 1e-2
        edge_sample_num = 2
        EnvBase.__init__(self, cell_nums, E, nu, vol_tol, edge_sample_num,
                         folder)

        # Initialize the parametric shapes.
        self._parametric_shape_info = [('bezier', 11), ('bezier', 11),
                                       ('bezier', 11)]
        # Initialize the node conditions.
        self._node_boundary_info = []

        inlet_range = ndarray([0.4, 0.6])
        outlet_range = 0.8
        cx, cy, _ = self.cell_nums()
        assert cx == cy
        nx, ny, nz = self.node_nums()
        inlet_bd = inlet_range * cx
        outlet_bd = outlet_range * cx
        inlet_velocity = ndarray([1.0, 0.0])
        for j in range(ny):
            for k in range(nz):
                # Set the inlet at i = 0.
                if inlet_bd[0] < j < inlet_bd[1]:
                    self._node_boundary_info.append(
                        ((0, j, k, 0), inlet_velocity[0]))
                    self._node_boundary_info.append(((0, j, k, 1), 0))
                    self._node_boundary_info.append(((0, j, k, 2), 0))

                    self._node_boundary_info.append(
                        ((j, 0, k, 0), inlet_velocity[1]))
                    self._node_boundary_info.append(((j, 0, k, 1), 0))
                    self._node_boundary_info.append(((j, 0, k, 2), 0))
        # Set the top and bottom plane.
        for i in range(nx):
            for j in range(ny):
                for k in [0, nz - 1]:
                    self._node_boundary_info.append(((i, j, k, 2), 0))
        # Initialize the interface.
        self._interface_boundary_type = 'free-slip'

        # Other data members.
        self._inlet_range = inlet_range
        self._outlet_range = outlet_range
        self._inlet_bd = inlet_bd
        self._outlet_bd = outlet_bd
        self._inlet_velocity = inlet_velocity
示例#4
0
    def __init__(self, seed):
        cell_nums = (32, 24)
        E = 100
        nu = 0.499
        vol_tol = 1e-3
        edge_sample_num = 2
        EnvBase.__init__(self, cell_nums, E, nu, vol_tol, edge_sample_num,
                         None)

        np.random.seed(seed)
        # Initialize the parametric shapes.
        self._parametric_shape_info = [('bezier', 8), ('bezier', 8)]
        # Initialize the node conditions.
        self._node_boundary_info = []
        inlet_velocity = 1.0
        for j in range(cell_nums[1] + 1):
            if 4.1 < j < 19.9:
                self._node_boundary_info.append(((0, j, 0), inlet_velocity))
                self._node_boundary_info.append(((0, j, 1), 0))
        # Initialize the interface.
        self._interface_boundary_type = 'free-slip'

        self.__u_weight = np.random.normal(size=(cell_nums[0] + 1,
                                                 cell_nums[1] + 1, 2)).ravel()
示例#5
0
    def __init__(self, seed, folder):
        np.random.seed(seed)

        cell_nums = (32, 32, 16)
        E = 100
        nu = 0.499
        vol_tol = 1e-2
        edge_sample_num = 2
        EnvBase.__init__(self, cell_nums, E, nu, vol_tol, edge_sample_num,
                         folder)

        # Initialize the parametric shapes.
        self._parametric_shape_info = [('polar_bezier-6', 51)]
        # Initialize the node conditions.
        self._node_boundary_info = []

        inlet_radius = 0.3
        outlet_radius = 0.3
        inlet_velocity = 1.0
        outlet_velocity = 2.0
        cx, cy, _ = self.cell_nums()
        assert cx == cy
        nx, ny, nz = self.node_nums()

        def get_bezier(radius):
            bezier = ShapeComposition2d()
            params = np.concatenate(
                [np.full(8, radius) * cx,
                 ndarray([0.5 * cx, 0.5 * cy, 0])])
            bezier.AddParametricShape('polar_bezier', params.size)
            cxy = StdIntArray2d((int(cx), int(cy)))
            bezier.Initialize(cxy, params, True)
            return bezier

        inlet_bezier = get_bezier(inlet_radius)
        outlet_bezier = get_bezier(outlet_radius)

        for i in range(nx):
            for j in range(ny):
                if inlet_bezier.signed_distance((i, j)) > 0:
                    self._node_boundary_info.append(((i, j, 0, 0), 0))
                    self._node_boundary_info.append(((i, j, 0, 1), 0))
                    self._node_boundary_info.append(
                        ((i, j, 0, 2), inlet_velocity))

        # Initialize the interface.
        self._interface_boundary_type = 'free-slip'

        # Compute the target velocity field (for rendering purposes only)
        desired_omega = 2 * outlet_velocity / (cx * outlet_radius)
        target_velocity_field = np.zeros((nx, ny, 3))
        for i in range(nx):
            for j in range(ny):
                if outlet_bezier.signed_distance((i, j)) > 0:
                    x, y = i / cx, j / cy
                    # u = (-(j - ny / 2), (i - nx / 2), 0) * c.
                    # ux_pos = (-j, i + 1, 0) * c.
                    # uy_pos = (-j - 1, i, 0) * c.
                    # curl = (i + 1) * c + (j + 1) * c - i * c - j * c.
                    #      = (i + j + 2 - i - j) * c = 2 * c.
                    # c = outlet_vel / (num_cells[0] * outlet_radius).
                    c = desired_omega / 2
                    target_velocity_field[i, j] = ndarray(
                        [-(y - 0.5) * c, (x - 0.5) * c, 0])

        # Other data members.
        self._inlet_radius = inlet_radius
        self._outlet_radius = outlet_radius
        self._inlet_velocity = inlet_velocity
        self._target_velocity_field = target_velocity_field
        self._inlet_bezier = inlet_bezier
        self._outlet_bezier = outlet_bezier
        self._desired_omega = desired_omega
    def __init__(self, seed, folder):
        np.random.seed(seed)

        cell_nums = (32, 32, 16)
        E = 100
        nu = 0.499
        vol_tol = 1e-2
        edge_sample_num = 2
        EnvBase.__init__(self, cell_nums, E, nu, vol_tol, edge_sample_num,
                         folder)

        # Initialize the parametric shapes.
        self._parametric_shape_info = [
            ('polar_bezier3', 27),
            ('bezier', 11),
            ('bezier', 11),
            ('bezier', 11),
        ]
        upper = ndarray([
            [0.0, 0.7],
            [0.1, 0.7],
            [0.75, 0.9],
            [1.0, 0.9],
        ])
        lower = ndarray([
            [1.0, 0.1],
            [0.75, 0.1],
            [0.1, 0.3],
            [0.0, 0.3],
        ])
        right = ndarray([
            [1.0, 0.65],
            [0.9, 0.6],
            [0.9, 0.4],
            [1.0, 0.35],
        ])
        dir_offset = 0.01
        cx, cy, cz = cell_nums
        cxy = ndarray([cx, cy])
        boundary_bezier = ShapeComposition3d()
        boundary_bezier.AddParametricShape('bezier', 11)
        boundary_bezier.AddParametricShape('bezier', 11)
        boundary_bezier.AddParametricShape('bezier', 11)
        params = np.concatenate([
            ndarray(upper * cxy).ravel(),
            ndarray([0, dir_offset, 1]),
            ndarray(lower * cxy).ravel(),
            ndarray([0, -dir_offset, 1]),
            ndarray(right * cxy).ravel(),
            ndarray([dir_offset, 0, 1]),
        ])
        cxyz = StdIntArray3d((int(cx), int(cy), int(cz)))
        boundary_bezier.Initialize(cxyz, params, True)

        # Initialize the node conditions.
        self._node_boundary_info = []
        nx, ny, nz = cx + 1, cy + 1, cz + 1
        inlet_velocity = 5
        for i in range(nx):
            for j in range(ny):
                for k in [0, cz]:
                    self._node_boundary_info.append(((i, j, k, 2), 0))
        for j in range(ny):
            for k in range(nz):
                if boundary_bezier.signed_distance((0, j, k)) < 0:
                    self._node_boundary_info.append(
                        ((0, j, k, 0), inlet_velocity))

        # Initialize the interface.
        self._interface_boundary_type = 'no-slip'

        # Initialize the target velocity field.
        on_target_field = np.zeros((ny, nz, 3))
        off_target_field = np.zeros((ny, nz, 3))
        z_half = int(cz // 2)
        y_half = int(cy // 2)
        for j in range(ny):
            for k in range(nz):
                # Skip solid nodes.
                if boundary_bezier.signed_distance((nx - 1, j, k)) >= 0:
                    continue
                if j < y_half:
                    # Outlet 1.
                    if k <= z_half:
                        on_target_field[j, k] = ndarray([inlet_velocity, 0, 0])
                        off_target_field[j, k] = ndarray([0, 0, 0])
                    else:
                        on_target_field[j, k] = ndarray([0, 0, 0])
                        off_target_field[j,
                                         k] = ndarray([inlet_velocity, 0, 0])
                else:
                    # Outlet 2.
                    if k <= z_half:
                        on_target_field[j, k] = ndarray([0, 0, 0])
                        off_target_field[j,
                                         k] = ndarray([inlet_velocity, 0, 0])
                    else:
                        on_target_field[j, k] = ndarray([inlet_velocity, 0, 0])
                        off_target_field[j, k] = ndarray([0, 0, 0])

        # Other data members.
        self._inlet_velocity = inlet_velocity
        self._boundary_bezier = boundary_bezier
        self._upper = upper
        self._lower = lower
        self._right = right
        self._dir_offset = dir_offset
        self._on_target_field = on_target_field
        self._off_target_field = off_target_field