def get_geometry(dx_s=0.03, dx_f=0.03, hdx=1.3, r_f=100.0, r_s=100.0, wall_l=4.0, wall_h=2.0, fluid_l=1., fluid_h=2., cube_s=0.25): wall_y1 = np.arange(dx_s, wall_h, dx_s) wall_xlayer = np.ones_like(wall_y1) * 2.0 wall_x1 = [] wall_x2 = [] num_layers = 3 for i in range(num_layers): wall_x1.append(wall_xlayer + i * dx_s) wall_x2.append(wall_xlayer - i * dx_s + wall_l / 4.0) wall_x1, wall_x2 = np.ravel(wall_x1), np.ravel(wall_x2) wall_y1 = np.tile(wall_y1, num_layers) wall_y2 = wall_y1 w_center = np.array([wall_l / 2.0, 0.0]) wall_x3, wall_y3 = get_2d_wall(dx_s, w_center, wall_l, num_layers, False) w_center = np.array([2.5, wall_h + dx_s / 2.0]) wall_x4, wall_y4 = get_2d_wall(dx_s, w_center, 1.0, num_layers) wall_x = np.concatenate([wall_x1, wall_x2, wall_x3, wall_x4]) wall_y = np.concatenate([wall_y1, wall_y2, wall_y3, wall_y4]) r1 = np.ones_like(wall_x) * r_s m1 = r1 * dx_s * dx_s h1 = np.ones_like(wall_x) * dx_s * hdx cs1 = np.zeros_like(wall_x) rad1 = np.ones_like(wall_x) * dx_s wall = get_particle_array(name='wall', x=wall_x, y=wall_y, h=h1, rho=r1, m=m1, cs=cs1, rad_s=rad1) f_center = np.array([3.0 * wall_l / 8.0, wall_h / 2.0]) x2, y2 = get_2d_block(dx_f, fluid_l, fluid_h, f_center) r2 = np.ones_like(x2) * r_f m2 = r2 * dx_f * dx_f h2 = np.ones_like(x2) * dx_f * hdx cs2 = np.zeros_like(x2) rad2 = np.ones_like(x2) * dx_f fluid = get_particle_array(name='fluid', x=x2, y=y2, h=h2, rho=r2, m=m2, cs=cs2, rad_s=rad2) center1 = np.array([wall_l / 8.0 + cube_s / 2.0, wall_h / 4.0 + cube_s / 2.0]) cube1_x, cube1_y = get_2d_block(dx_s, cube_s, cube_s, center1) b1 = np.zeros_like(cube1_x, dtype=int) center2 = np.array([3.0 * wall_l / 4.0 + cube_s / 2.0 + 3.0 * dx_s, wall_h + cube_s / 2.0 + (num_layers + 1) * dx_s]) cube2_x, cube2_y = get_2d_block(dx_s, cube_s, cube_s, center2) b2 = np.ones_like(cube2_x, dtype=int) b = np.concatenate([b1, b2]) x3 = np.concatenate([cube1_x, cube2_x]) y3 = np.concatenate([cube1_y, cube2_y]) r3 = np.ones_like(x3) * r_s * 0.5 m3 = r3 * dx_s * dx_s h3 = np.ones_like(x3) * dx_s * hdx cs3 = np.zeros_like(x3) rad3 = np.ones_like(x3) * dx_s cube = get_particle_array_rigid_body( name='cube', x=x3, y=y3, h=h3, cs=cs3, rho=r3, m=m3, rad_s=rad3, body_id=b) remove_overlap_particles(fluid, wall, dx_s, 2) return fluid, wall, cube
def get_beach_geometry_2d(dx=0.1, l=3.0, h=1.0, flat_l=1.0, angle=45.0, num_layers=3): """ Generates a beach like geometry which is commonly used for simulations related to SPHysics. Parameters ---------- dx : Spacing between the particles l : Total length of the beach h : Height of the wall used at the beach position flat_l : Length of the flat part angle : Angle of the inclined part num_layers : number of layers Returns ------- x : 1d numpy array with x coordinates of the beach y : 1d numpy array with y coordinates of the beach x4 : 1d numpy array with x coordinates of the obstacle y4 : 1d numpy array with y coordinates of the obstacle """ theta = np.pi * angle / 180.0 x1, y1 = get_2d_wall(dx, np.array([(flat_l + dx) / 2.0, 0.]), flat_l, num_layers, False) x2 = np.arange(flat_l - l, 0.0, dx * np.cos(theta)) h2 = (l - flat_l) * np.tan(theta) y2_layer = x2 * np.tan(-theta) x2 = np.tile(x2, num_layers) y2 = [] for i in range(num_layers): y2.append(y2_layer - i * dx) y2 = np.ravel(np.array(y2)) y3 = np.arange(h2 + dx, h + h2, dx) x3_layer = np.ones_like(y3) * (flat_l - l) y3 = np.tile(y3, num_layers) x3 = [] for i in range(num_layers): x3.append(x3_layer - i * dx) x3 = np.ravel(np.array(x3)) x = np.concatenate([x1, x2, x3]) y = np.concatenate([y1, y2, y3]) y4 = np.arange(dx, 2.0 * h, dx) x4_layer = np.ones_like(y4) * flat_l y4 = np.tile(y4, num_layers) x4 = [] for i in range(num_layers): x4.append(x4_layer + i * dx) x4 = np.ravel(np.array(x4)) return x, y, x4, y4
def test_get_2d_wall(self): dx = 0.05 length = 3.0 center = np.array([np.pi, 1.5]) num_layers = 3 up = True x, y = G.get_2d_wall(dx, center, length, num_layers, up) x_test = np.arange(-length / 2.0, length / 2.0, dx) + center[0] y_test = np.ones_like(x_test) * center[1] layer_length = int(len(x) / num_layers) value = 1 if up else -1 assert np.allclose(x_test, x[:len(x_test)]) assert np.allclose(y_test, y[:len(y_test)]) assert np.allclose(x[:layer_length], x[-layer_length:]) assert np.allclose(y[:layer_length], y[-layer_length:] - value * (num_layers - 1) * dx)
def test_get_2d_wall(self): dx = (10.0)**(np.random.uniform(-2, -1)) center = np.random.random_sample(2) length = np.random.randint(50, 200) * dx num_layers = np.random.randint(1, 4) up = np.random.choice([True, False]) x, y = get_2d_wall(dx, center, length, num_layers, up) x_test = np.arange(-length / 2.0, length / 2.0, dx) + center[0] y_test = np.ones_like(x_test) * center[1] layer_length = int(len(x) / num_layers) value = 1 if up else -1 assert np.allclose(x_test, x[:len(x_test)]) assert np.allclose(y_test, y[:len(y_test)]) assert np.allclose(x[:layer_length], x[-layer_length:]) assert np.allclose(y[:layer_length], y[-layer_length:] - value * (num_layers - 1) * dx)
def windtunnel_airfoil_model(dx_wall=0.01, dx_airfoil=0.01, dx_fluid=0.01, r_solid=100.0, r_fluid=100.0, airfoil='2412', hdx=1.1, chord=1.0, h_tunnel=1.0, l_tunnel=10.0): """ Generates a geometry which can be used for wind tunnel like simulations. Parameters ---------- dx_wall : a number which is the dx of the wind tunnel wall dx_airfoil : a number which is the dx of the airfoil used dx_fluid : a number which is the dx of the fluid used r_solid : a number which is the initial density of the solid particles r_fluid : a number which is the initial density of the fluid particles airfoil : 4 or 5 digit string which is the airfoil name hdx : a number which is the hdx for the particle arrays chord : a number which is the chord of the airfoil h_tunnel : a number which is the height of the wind tunnel l_tunnel : a number which is the length of the wind tunnel Returns ------- wall : pysph wcsph particle array for the wind tunnel walls wing : pysph wcsph particle array for the airfoil fluid : pysph wcsph particle array for the fluid """ wall_center_1 = np.array([0.0, h_tunnel / 2.]) wall_center_2 = np.array([0.0, -h_tunnel / 2.]) x_wall_1, y_wall_1 = get_2d_wall(dx_wall, wall_center_1, l_tunnel) x_wall_2, y_wall_2 = get_2d_wall(dx_wall, wall_center_2, l_tunnel) x_wall = np.concatenate([x_wall_1, x_wall_2]) y_wall = np.concatenate([y_wall_1, y_wall_2]) y_wall_1 = y_wall_1 + dx_wall y_wall_2 = y_wall_2 - dx_wall y_wall = np.concatenate([y_wall, y_wall_1, y_wall_2]) y_wall_1 = y_wall_1 + dx_wall y_wall_2 = y_wall_2 - dx_wall y_wall = np.concatenate([y_wall, y_wall_1, y_wall_2]) y_wall_1 = y_wall_1 + dx_wall y_wall_2 = y_wall_2 - dx_wall x_wall = np.concatenate([x_wall, x_wall, x_wall, x_wall]) y_wall = np.concatenate([y_wall, y_wall_1, y_wall_2]) h_wall = np.ones_like(x_wall) * dx_wall * hdx rho_wall = np.ones_like(x_wall) * r_solid mass_wall = rho_wall * dx_wall * dx_wall wall = get_particle_array_wcsph(name='wall', x=x_wall, y=y_wall, h=h_wall, rho=rho_wall, m=mass_wall) if len(airfoil) == 4: x_airfoil, y_airfoil = get_4digit_naca_airfoil(dx_airfoil, airfoil, chord) else: x_airfoil, y_airfoil = get_5digit_naca_airfoil(dx_airfoil, airfoil, chord) x_airfoil = x_airfoil - 0.5 h_airfoil = np.ones_like(x_airfoil) * dx_airfoil * hdx rho_airfoil = np.ones_like(x_airfoil) * r_solid mass_airfoil = rho_airfoil * dx_airfoil * dx_airfoil wing = get_particle_array_wcsph(name='wing', x=x_airfoil, y=y_airfoil, h=h_airfoil, rho=rho_airfoil, m=mass_airfoil) x_fluid, y_fluid = get_2d_block(dx_fluid, 1.6, h_tunnel) h_fluid = np.ones_like(x_fluid) * dx_fluid * hdx rho_fluid = np.ones_like(x_fluid) * r_fluid mass_fluid = rho_fluid * dx_fluid * dx_fluid fluid = get_particle_array_wcsph(name='fluid', x=x_fluid, y=y_fluid, h=h_fluid, rho=rho_fluid, m=mass_fluid) remove_overlap_particles(fluid, wall, dx_wall, 2) remove_overlap_particles(fluid, wing, dx_airfoil, 2) return wall, wing, fluid