def arange_long(start, stop=-1): """ Creates a LongArray working same as builtin range with upto 2 arguments both expected to be positive """ if stop == -1: arange = LongArray(start) for i in range(start): arange.data[i] = i return arange else: size = stop - start arange = LongArray(size) for i in range(size): arange.data[i] = start + i return arange
def create_particles(self, **kwargs): fluid_column_height = self.fluid_column_height fluid_column_width = self.fluid_column_width fluid_column_length = self.fluid_column_length container_height = self.container_height container_length = self.container_length container_width = self.container_width obstacle_height = self.obstacle_height obstacle_length = self.obstacle_length obstacle_width = self.obstacle_width obstacle_center_x = self.obstacle_center_x obstacle_center_y = self.obstacle_center_y nboundary_layers = self.nboundary_layers dx = self.dx # get the domain limits ghostlims = nboundary_layers * dx xmin, xmax = 0.0 - ghostlims, container_length + ghostlims zmin, zmax = 0.0 - ghostlims, container_height + ghostlims cw2 = 0.5 * container_width ymin, ymax = -cw2 - ghostlims, cw2 + ghostlims # create all particles eps = 0.1 * dx xx, yy, zz = numpy.mgrid[xmin:xmax + eps:dx, ymin:ymax + eps:dx, zmin:zmax + eps:dx] x = xx.ravel() y = yy.ravel() z = zz.ravel() # create a dummy particle array from which we'll sort pa = get_particle_array_wcsph(name='block', x=x, y=y, z=z) # get the individual arrays indices = [] findices = [] oindices = [] obw2 = 0.5 * obstacle_width obl2 = 0.5 * obstacle_length obh = obstacle_height ocx = obstacle_center_x ocy = obstacle_center_y for i in range(x.size): xi = x[i] yi = y[i] zi = z[i] # fluid if ((0 < xi <= fluid_column_length) and (-cw2 < yi < cw2) and (0 < zi <= fluid_column_height)): findices.append(i) # obstacle if ((ocx - obl2 <= xi <= ocx + obl2) and (ocy - obw2 <= yi <= ocy + obw2) and (0 < zi <= obh)): oindices.append(i) # extract the individual arrays fa = LongArray(len(findices)) fa.set_data(numpy.array(findices)) fluid = pa.extract_particles(fa) fluid.set_name('fluid') if self.with_obstacle: oa = LongArray(len(oindices)) oa.set_data(numpy.array(oindices)) obstacle = pa.extract_particles(oa) obstacle.set_name('obstacle') indices = concatenate((where(y <= -cw2)[0], where(y >= cw2)[0], where(x >= container_length)[0], where(x <= 0)[0], where(z <= 0)[0])) # remove duplicates indices = array(list(set(indices))) wa = LongArray(indices.size) wa.set_data(indices) boundary = pa.extract_particles(wa) boundary.set_name('boundary') # create the particles if self.with_obstacle: particles = [fluid, boundary, obstacle] else: particles = [fluid, boundary] # set up particle properties h0 = self.hdx * dx volume = dx**3 m0 = self.rho0 * volume for pa in particles: pa.m[:] = m0 pa.h[:] = h0 pa.rho[:] = self.rho0 nf = fluid.num_real_particles nb = boundary.num_real_particles if self.with_obstacle: no = obstacle.num_real_particles print( "3D dam break with %d fluid, %d boundary, %d obstacle particles" % (nf, nb, no)) else: print( "3D dam break with %d fluid, %d boundary particles" % (nf, nb)) # load balancing props for the arrays # fluid.set_lb_props(['x', 'y', 'z', 'u', 'v', 'w', 'rho', 'h', 'm', 'gid', # 'x0', 'y0', 'z0', 'u0', 'v0', 'w0', 'rho0']) fluid.set_lb_props(list(fluid.properties.keys())) #boundary.set_lb_props(['x', 'y', 'z', 'rho', 'h', 'm', 'gid', 'rho0']) #obstacle.set_lb_props(['x', 'y', 'z', 'rho', 'h', 'm', 'gid', 'rho0']) boundary.set_lb_props(list(boundary.properties.keys())) # boundary and obstacle particles can do with a reduced list of properties # to be saved to disk since they are fixed boundary.set_output_arrays( ['x', 'y', 'z', 'rho', 'm', 'h', 'p', 'tag', 'pid', 'gid']) if self.with_obstacle: obstacle.set_lb_props(list(obstacle.properties.keys())) obstacle.set_output_arrays( ['x', 'y', 'z', 'rho', 'm', 'h', 'p', 'tag', 'pid', 'gid']) return particles