Source code for wolfgpu.toy_datasets

from enum import Enum
import numpy as np
from .simple_simulation import SimulationDuration, TimeStepStrategy, SimpleSimulation, BoundaryConditionsTypes

[docs] def make_closed_pool(width, height, pos_x, pos_y, pool_width, pool_height, wall_height=10, mode = "cube") -> SimpleSimulation: """ Make a cube of water, surrounded by empty space, surrounded by walls, surrounded by empty space. The problem will be pool_width by pool_height but it will be placed onto a grid (width*height) at (pos_x,pos_y) """ assert width >= 6*2, "sim must be wide enough to fit everything inside it" assert height >= 6*2 # Make the cube of water surrounded by a wall. shape = (pool_width, pool_height) # Surround the swimming pool by a wall, 2 meshes wide bathymetry = np.zeros(shape, np.float32) bathymetry[ 2:-2, 2:-2 ] = wall_height bathymetry[ 4:-4, 4:-4 ] = 0 # And now, we drop the small pool inside the big simulation sim = SimpleSimulation(width, height) sim.param_dx = 1.0 sim.param_dy = 1.0 sim.h = np.zeros(sim.shape, np.float32) sim.bathymetry = np.zeros(sim.shape, np.float32) sim.nap = np.zeros(sim.shape, np.uint8) sim.qx = np.zeros(sim.shape, np.float32) sim.qy = np.zeros(sim.shape, np.float32) if mode == "cube": h = np.zeros(shape, np.float32) cube_width = pool_width // 4 cube_height = pool_height // 3 assert cube_width >= 1, "widths are too small, can't build the cube of water." assert cube_height >= 1, "heights are too small, can't build the cube of water." h[pool_width//2 -cube_width//2 :pool_width//2 +cube_width//2, pool_height//2-cube_height//2:pool_height//2+cube_height//2] = 1.0 elif mode == "filled": h = np.zeros(shape, np.float32) h[4:-4, 4:-4] = 1.0 sim.h[pos_x:pos_x+pool_width, pos_y:pos_y+pool_height] = h sim.bathymetry[pos_x:pos_x+pool_width, pos_y:pos_y+pool_height] = bathymetry sim.nap[pos_x:pos_x+pool_width, pos_y:pos_y+pool_height] = 1 sim.manning = np.full(sim.shape, 0.04, np.float32) return sim
[docs] def make_cube_drop(width, height, water_cube_height=10.0) -> SimpleSimulation: sim = SimpleSimulation(width, height) sim.param_dx, sim.param_dy = 1.0, 1.0 sim._param_nx, sim._param_ny = width, height sim.param_duration = SimulationDuration.from_steps(10000) shape = (sim._param_nx, sim._param_ny) sim.nap = np.zeros(shape, dtype=np.uint8) sim.nap[ 2:-2, 2:-2] = True sim._h = np.ones(shape, dtype=np.float32) * 0.0 mx = sim._param_nx // 2 nx = sim._param_nx // 4 my = sim._param_ny // 2 ny = sim._param_ny // 4 sim._h[ mx-nx:mx+nx, my-ny:my+ny] = water_cube_height sim._qx = np.zeros(shape, dtype=np.float32) sim._qy = np.zeros(shape, dtype=np.float32) sim._bathymetry = np.zeros(shape, dtype=np.float32) sim._bathymetry[:, 0:2] = 100 sim._bathymetry[:, sim._param_ny-2:sim._param_ny] = 100 sim._bathymetry[0:2, :] = 100 sim._bathymetry[sim._param_nx-2:sim._param_nx, :] = 100 sim.manning = np.ones(shape, dtype=np.float32)*0.4 return sim
[docs] class WallDirection(Enum):
[docs] HORIZONTAL = 1
[docs] VERTICAL = 2
[docs] HORIZONTAL_AND_VERTICAL = 3
[docs] def make_swimming_pool(width, height, water_depth, wall: WallDirection) -> SimpleSimulation: assert not (wall is None and water_depth > 0), "If no walls, then no water" sim = SimpleSimulation(width, height) sim._param_nx, sim._param_ny = width, height sim.param_dx, sim.param_dy = 1.0, 1.0 shape = (sim._param_nx, sim._param_ny) sim.nap = np.zeros(shape, dtype=np.uint8) sim.nap[ 1:sim._param_nx-1, 1:sim._param_ny-1] = 1 sim._h = np.zeros(shape, dtype=np.float32) sim._qx = np.zeros(shape, dtype=np.float32) sim._qy = np.zeros(shape, dtype=np.float32) sim._bathymetry = np.zeros(shape, dtype=np.float32) if wall == WallDirection.HORIZONTAL: sim._h[1:sim._param_nx-1, 2:sim._param_ny-2] = water_depth elif wall == WallDirection.VERTICAL: sim._h[2:sim._param_nx-2, 1:sim._param_ny] = water_depth elif wall == WallDirection.HORIZONTAL_AND_VERTICAL: sim._h[2:sim._param_nx-2, 2:sim._param_ny-2] = water_depth if wall in (WallDirection.HORIZONTAL, WallDirection.HORIZONTAL_AND_VERTICAL): sim._bathymetry[:, 0:2] = 100 sim._bathymetry[:, sim._param_ny-2:sim._param_ny] = 100 if wall in (WallDirection.VERTICAL, WallDirection.HORIZONTAL_AND_VERTICAL): sim._bathymetry[0:2, :] = 100 sim._bathymetry[sim._param_nx-2:sim._param_nx, :] = 100 sim._manning = np.ones(shape, dtype=np.float32)*0.4 return sim