def boundary_conditions(self, hx, hy): where = (hx == hy) self.set_node( where, NTEquilibriumVelocity( multifield((0.01 * (hx - self.gy / 2)**2, 0.0), where))) self.set_node((hx > 10) & (hy < 5), NTFullBBWall)
def boundary_conditions(self, hx, hy): # set walls walls = (hx == -2) # set to all false y_wall = np.random.randint(0, 2) if y_wall == 0: print("y wall") walls = (hy == 0) | (hy == self.gy - 1) | walls # x bottom #x_wall = np.random.randint(0,2) #if x_wall == 1: # walls = (hx == self.gx - 1) | walls self.set_node(walls, self.bc) self.set_node((hx == 0) & np.logical_not(walls), NTEquilibriumVelocity(self.vel)) # set open boundarys self.set_node((hx == self.gx - 1) & np.logical_not(walls), NTEquilibriumDensity(1)) boundary = self.make_boundary(hx) self.set_node(boundary, self.bc) # save geometry (boundary, velocity, pressure) solid = np.array(boundary | walls, dtype=np.float32) solid = np.expand_dims(solid, axis=-1) velocity = np.concatenate(2 * [np.zeros_like(solid, dtype=np.float32)], axis=-1) velocity[:, 0] = self.vel pressure = np.array((hx == self.gx - 1) & np.logical_not(walls), dtype=np.float32) pressure = np.expand_dims(pressure, axis=-1) geometry = np.concatenate([solid, velocity, pressure], axis=-1) np.save(self.config.checkpoint_file + "_geometry", geometry)
def boundary_conditions(self, hx, hy): where = (hx == hy) self.set_node( where, NTEquilibriumVelocity( multifield((0.01 * (hx - self.gy / 2)**2, 0.0), where))) where = ((hx == 5) & (hy == 7)) self.set_node(where, NTEquilibriumDensity(DynamicValue(0.1 * S.gx))) # Interpolated time series. data = np.linspace(0, 50, 10) where = ((hx == 5) & (hy == 8)) self.set_node( where, NTEquilibriumDensity( DynamicValue(0.1 * S.gx * LinearlyInterpolatedTimeSeries(data, 40)))) # Same underlying data, but different time step. where = ((hx == 5) & (hy == 9)) self.set_node( where, NTEquilibriumDensity( DynamicValue(0.1 * S.gx * LinearlyInterpolatedTimeSeries(data, 30)))) self.set_node((hx > 10) & (hy < 5), NTFullBBWall)
def boundary_conditions(self, hx, hy): # restore from old dir or make new geometry if self.config.restore_geometry: restore_boundary_conditions = np.load(train_sim_dir[:-10] + "flow_geometry.npy") where_boundary = restore_boundary_conditions[...,0].astype(np.bool) where_velocity = np.logical_or(restore_boundary_conditions[...,1].astype(np.bool), restore_boundary_conditions[...,2].astype(np.bool)) if len(np.where(where_velocity)[0]) == 0: velocity = (0.0,0.0) else: velocity = (restore_boundary_conditions[np.where(where_velocity)[0][0], np.where(where_velocity)[1][0], 1], restore_boundary_conditions[np.where(where_velocity)[0][0], np.where(where_velocity)[1][0], 2]) where_density = restore_boundary_conditions[...,3].astype(np.bool) density = 1.0 #self.force = (restore_boundary_conditions[0,0,4], restore_boundary_conditions[0,0,5]) else: where_boundary = geometry_boundary_conditions(hx, hy, [self.gx, self.gy]) where_velocity, velocity = velocity_boundary_conditions(hx, hy, [self.gx, self.gy]) where_density, density = density_boundary_conditions(hx, hy, [self.gx, self.gy]) #self.force = force # set boundarys self.set_node(where_boundary, bc) # set velocities self.set_node(where_velocity, NTEquilibriumVelocity(velocity)) #self.set_node(where_velocity, NTZouHeVelocity(velocity)) # set densitys self.set_node(where_density, NTDoNothing) # save geometry save_geometry = make_geometry_input(where_boundary, velocity, where_velocity, density, where_density) np.save(train_sim_dir + "_geometry.npy", save_geometry)
def boundary_conditions(self, hx, hy, hz): # restore from old dir or make new geometry if self.config.restore_geometry: restore_boundary_conditions = np.load(train_sim_dir[:-10] + "flow_geometry.npy") where_boundary = restore_boundary_conditions[...,0].astype(np.bool) where_velocity = np.logical_or(restore_boundary_conditions[...,1].astype(np.bool), restore_boundary_conditions[...,2].astype(np.bool), restore_boundary_conditions[...,3].astype(np.bool)) vel_ind = np.where(where_velocity) velocity = restore_boundary_conditions[vel_ind[0][0], vel_ind[1][0], vel_ind[2][0], :] velocity = (velocity[1], velocity[2], velocity[3]) where_density = restore_boundary_conditions[...,4].astype(np.bool) density = 1.0 else: where_boundary = geometry_boundary_conditions(hx, hy, hz, [self.gx, self.gy, self.gz]) where_velocity, velocity = velocity_boundary_conditions(hx, hy, hz, [self.gx, self.gy, self.gz]) where_density, density = density_boundary_conditions(hx, hy, hz, [self.gx, self.gy, self.gz]) # set boundarys self.set_node(where_boundary, bc) # set velocities self.set_node(where_velocity, NTEquilibriumVelocity(velocity)) #self.set_node(where_velocity, NTZouHeVelocity(velocity)) # set densitys self.set_node(where_density, NTDoNothing) # save geometry save_geometry = make_geometry_input(where_boundary, velocity, where_velocity, density, where_density) np.save(train_sim_dir + "_geometry.npy", save_geometry)
def boundary_conditions(self, hx, hy): walls = (hy == 0) | (hy == self.gy - 1) self.set_node(walls, self.bc) H = self.config.lat_ny hhy = S.gy - self.bc.location self.set_node( (hx == 0) & np.logical_not(walls), NTEquilibriumVelocity( DynamicValue(4.0 * self.max_v / H**2 * hhy * (H - hhy), 0.0))) self.set_node((hx == self.gx - 1) & np.logical_not(walls), NTEquilibriumDensity(1)) L = self.config.vox_size model = self.load_vox_file(self.config.vox_filename) model = np.pad(model, ((L / 2, L / 2), (L, 6 * L)), 'constant', constant_values=False) self.set_node(model, self.bc) # save boundary geometry_array = model.astype(np.uint8) geometry_array = geometry_array[1:-1, L / 2 + 1:5 * L / 2 + 1] geometry_array = np.expand_dims(geometry_array, axis=-1) np.save(self.config.output + "_boundary", geometry_array)
def boundary_conditions(self, hx, hy, hz): where = np.logical_and((hx == hy), (hy == hz)) self.set_node( where, NTEquilibriumVelocity( multifield((0.01 * (hy - self.gy / 2)**2, 0.03 * (hz - self.gz / 2)**2, 0.0), where))) self.set_node((hx > 10) & (hy < 5) & (hz < 7), NTFullBBWall)
def boundary_conditions(self, hx, hy, hz): wall_map = (hz == 0) | (hz == self.gz - 1) | (hx == 0) | (hx == self.gx - 1) inflow_map = np.logical_not(wall_map) & (hy == 0) outflow_map = np.logical_not(wall_map) & (hy == self.gy - 1) self.set_node(wall_map, NTFullBBWall) self.set_node(inflow_map, NTEquilibriumVelocity((0.0, self.max_v, 0.0))) self.set_node(outflow_map, NTGradFreeflow)
def boundary_conditions(self, hx, hy, hz): wall_map = (hx == 0) | (hx == self.gx - 1) | (hy == 0) | (hy == self.gy - 1) self.set_node(wall_map, self.wall_bc) self.set_node((hz == 0) & np.logical_not(wall_map), NTEquilibriumVelocity((0.0, 0.0, 0.1))) self.set_node((hx == self.gx - 1) & np.logical_not(wall_map), NTEquilibriumDensity(1)) L = self.config.vox_size model = self.load_vox_file(self.config.vox_filename) model = np.pad(model, ((L, 8 * L / 4), (L / 2, L / 2), (L / 2, L / 2)), 'constant', constant_values=False) np.save(self.config.output + "_boundary", model) self.set_node(model, self.wall_bc)
def boundary_conditions(self, hx, hy): #walls = (hy == 0) | (hy == self.gy - 1) walls = (hy == -2) self.set_node(walls, self.bc) #hhy = S.gy - self.bc.location self.set_node((hx == 0) & np.logical_not(walls), NTEquilibriumVelocity((self.max_v, 0.0))) self.set_node((hx == self.gx - 1) & np.logical_not(walls), NTEquilibriumDensity(1)) l = L / 4 # Full bounce-back. For N box nodes, effective size is N+1. if self.bc.location == 0.5: eff_D = D - 1 # Half-way bounce-back. For N box nodes, effective size is N-2. else: eff_D = D + 2 box = ((hx > l - eff_D / 2.0) & (hx <= l + eff_D / 2.0) & (hy > (H - eff_D) / 2.0) & (hy <= (H + eff_D) / 2.0)) self.set_node(box, self.bc)
def boundary_conditions(self, hx, hy): # set walls walls = (hx == -2) # set to all false y_wall = np.random.randint(0,2) if y_wall == 0: walls = (hy == 0) | walls # x bottom x_wall = np.random.randint(0,2) if x_wall == 1: walls = (hx == self.gx - 1) | walls self.set_node(walls, self.bc) self.set_node((hx == 0) & np.logical_not(walls), NTEquilibriumVelocity(self.vel)) # set open boundarys self.set_node((hx == self.gx - 1) & np.logical_not(walls), NTEquilibriumDensity(1)) boundary = self.make_boundary(hx) self.set_node(boundary, self.bc)