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 _set_pressure_bc(self, hx, hy, hz, wall_map): pressure_bc = NTEquilibriumDensity not_wall = np.logical_not(wall_map) if self.config.flow_direction == 'z': inlet_map = (hz == 0) & not_wall outlet_map = (hz == self.gz - 1) & not_wall elif self.config.flow_direction == 'y': inlet_map = (hy == 0) & not_wall outlet_map = (hy == self.gy - 1) & not_wall else: inlet_map = (hx == 0) & not_wall outlet_map = (hx == self.gx - 1) & not_wall pressure = self.pressure_delta * sin(S.time * omega) self.set_node(inlet_map, pressure_bc(DynamicValue(1.0 + 3.0 * pressure / 2.0))) self.set_node(outlet_map, pressure_bc(DynamicValue(1.0 - 3.0 * pressure / 2.0))) print 'Re = %.2f' % (self.max_v * self.channel_width(self.config) / 2.0 / visc) print 'Wo = %.2f' % (self.channel_width(self.config) / 2.0 * sqrt(omega / visc)) print 'dP = %.8e' % self.pressure_delta # The oscillation period (in lattice time units) should be significantly longer # than the length of the pipe (in lattice length units) in order for the # compressibility effects of LBM to be minimized. print 'T = %.2f' % (2 * np.pi / omega)
def boundary_conditions(self, hx, hy): land = np.logical_and # Set walls. self.set_node(hy == 0, self.wall_bc) self.set_node(hy == self.gy - 1, self.wall_bc) not_wall = land(hy > 0, hy < self.gy - 1) width = self.channel_width(self.config) radius = width / 2.0 radius_sq = radius**2 # Add 0.5 to the grid symbols to indicate that the node is located in the # middle of the grid cell. # The velocity vector direction matches the flow orientation vector. where = (hx == self.gx - 1) & not_wall self.set_node(where, self.pressure_bc(1.0)) if self.config.velocity == "equation": vv = self.max_v * (1.0 - (S.gy + 0.5 - radius)**2 / radius_sq)* \ Piecewise((S.time / 5000, S.time < 5000),(1.0, True)) self.set_node(land(not_wall, hx == 0), self.velocity_bc(DynamicValue(vv, 0.0))) elif self.config.velocity == "spatial_array": vx = self.max_v * (1 - (hy + 0.5 - radius)**2 / radius_sq) where = (hx == 0) & not_wall self.set_node(where, self.velocity_bc(DynamicValue( \ SpatialArray(vx, index="x", where=where)* \ Piecewise((S.time / 5000, S.time < 5000),(1.0, True)), 0.0)))
def boundary_conditions(self, hx, hy): self.set_node( (hx == 5) & (hy == 0), NTEquilibriumDensity( DynamicValue(LinearlyInterpolatedTimeSeries(sin_timeseries, 8)))) self.set_node( (hx == 6) & (hy == 0), NTEquilibriumDensity( DynamicValue( LinearlyInterpolatedTimeSeries(cos_timeseries, 1.61)))) self.set_node( (hx == 7) & (hy == 0), NTEquilibriumDensity( DynamicValue( 2.0 * LinearlyInterpolatedTimeSeries(sin_timeseries, 4))))
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 __init__(self, config): super(poiseuille.PoiseuilleSim, self).__init__(config) if config.drive == 'force': channel_width = self.subdomain.channel_width(config) accel = (sin(S.time) * self.subdomain.max_v * (8.0 * config.visc) / channel_width**2) force_vec = (accel, 0.0) if config.horizontal else (0.0, accel) self.add_body_force(DynamicValue(*force_vec))
def __init__(self, config): super(FourRollsMill, self).__init__(config) ny, nx = self.config.lat_ny, self.config.lat_nx kx, ky, ksq, k = TaylorGreenSubdomain.get_k(config, nx, ny) f = ksq * config.visc * config.max_v accel_vec = (-f * ky / k * sin(ky * S.gy) * cos(kx * S.gx), +f * kx / k * sin(kx * S.gx) * cos(ky * S.gy)) self.add_body_force(DynamicValue(*accel_vec))
def _set_pressure_bc(self, hx, hy): """Adds pressure boundary conditions at the ends of the pipe.""" pressure_bc = NTEquilibriumDensity if self.config.horizontal: pressure = (self.max_v * sin(S.time) * (8.0 * self.config.visc) / (self.channel_width(self.config)**2) * S.gx) not_wall = (hy > 0) & (hy < self.gy - 1) self.set_node(not_wall & (hx == 0), pressure_bc(DynamicValue(1.0 + 3.0 * pressure/2.0))) self.set_node(not_wall & (hx == self.gx - 1), pressure_bc(DynamicValue(1.0 - 3.0 * pressure/2.0))) else: pressure = (self.max_v * sin(S.time) * (8.0 * self.config.visc) / (self.channel_width(self.config)**2) * S.gy) not_wall = (hx > 0) & (hx < self.gx - 1) self.set_node(not_wall & (hy == 0), pressure_bc(DynamicValue(1.0 + 3 * pressure/2.0))) self.set_node(not_wall & (hy == self.gy - 1), pressure_bc(DynamicValue(1.0 - 3 * pressure/2.0)))
def boundary_conditions(self, hx, hy): walls = (hy == 0) | (hy == self.gy - 1) self.set_node(walls, self.bc) 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 = 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)