def create_particles(): x1, y1 = create_2D_filled_region(-1, 0, 0, 1, dx) x2, y2 = create_2D_filled_region(0.5, 0, 1.5, 1, dx) u1 = numpy.ones_like(x1) u2 = -numpy.ones_like(x2) rho = numpy.ones_like(x1) * rho0 h = numpy.ones_like(u1) * hdx * dx m = numpy.ones_like(u1) * dx * dx * rho0 fluid1 = get_particle_array_iisph(name='fluid1', x=x1, y=y1, u=u1, rho=rho, m=m, h=h) fluid2 = get_particle_array_iisph(name='fluid2', x=x2, y=y2, u=u2, rho=rho, m=m, h=h) return [fluid1, fluid2]
def setup_properties(self, particles, clean=True): """Setup the particle arrays so they have the right set of properties for this scheme. Parameters ---------- particles : list List of particle arrays. clean : bool If True, removes any unnecessary properties. """ from pysph.base.utils import get_particle_array_iisph dummy = get_particle_array_iisph() props = set(dummy.properties.keys()) for pa in particles: self._ensure_properties(pa, props, clean) for c, v in dummy.constants.items(): if c not in pa.constants: pa.add_constant(c, v) pa.set_output_arrays(dummy.output_property_arrays) if self.has_ghosts: particle_arrays = dict([(p.name, p) for p in particles]) for fluid in self.fluids: pa = particle_arrays[fluid] pa.add_property('orig_idx', type='int')
def get_circular_patch(dx=0.025, **kwargs): """Create the circular patch of fluid.""" name = 'fluid' x,y = mgrid[-1.05:1.05+1e-4:dx, -1.05:1.05+1e-4:dx] x = x.ravel() y = y.ravel() m = ones_like(x)*dx*dx*ro # mass = volume * density even though ro = 1 in this example h = ones_like(x)*hdx*dx rho = ones_like(x) * ro p = ones_like(x) u = -100*x v = 100*y # remove particles outside the circle indices = [] for i in range(len(x)): if sqrt(x[i]*x[i] + y[i]*y[i]) - 1 > 1e-10: indices.append(i) pa = get_particle_array_iisph(x=x, y=y, m=m, rho=rho, h=h, p=p, u=u, v=v, name=name) pa.remove_particles(indices) print("Elliptical drop :: %d particles"%(pa.get_number_of_particles())) return [pa,]
def create_particles(): x1, y1 = create_2D_filled_region(-1, 0, 0, 1, dx) x2, y2 = create_2D_filled_region(0.5, 0, 1.5, 1, dx) x = numpy.concatenate((x1, x2)) y = numpy.concatenate((y1, y2)) u1 = numpy.ones_like(x1) u2 = -numpy.ones_like(x2) u = numpy.concatenate((u1, u2)) rho = numpy.ones_like(u) * rho0 h = numpy.ones_like(u) * hdx * dx m = numpy.ones_like(u) * dx * dx * rho0 pa = get_particle_array_iisph(name='fluid', x=x, y=y, u=u, rho=rho, m=m, h=h) return [ pa, ]
def create_particles(self, nboundary_layers=2, nfluid_offset=2, hdx=1.5, **kwargs): nfluid = self.nfluid xf, yf = self.get_fluid(nfluid_offset) if self.iisph: fluid = get_particle_array_iisph(name='fluid', x=xf, y=yf) else: fluid = get_particle_array_wcsph(name='fluid', x=xf, y=yf) fluid.gid[:] = list(range(fluid.get_number_of_particles())) np = nfluid xb, yb = self.get_wall(nboundary_layers) if self.iisph: boundary = get_particle_array_iisph(name='boundary', x=xb, y=yb) else: boundary = get_particle_array_wcsph(name='boundary', x=xb, y=yb) np += boundary.get_number_of_particles() dx, dy, ro = self.dx, self.dy, self.ro # smoothing length, mass and density fluid.h[:] = numpy.ones_like(xf) * hdx * dx if nfluid_offset == 2: fluid.m[:] = dx * dy * ro * 0.5 else: fluid.m[:] = dx * dy * ro fluid.rho[:] = ro if not self.iisph: fluid.rho0[:] = ro boundary.h[:] = numpy.ones_like(xb) * hdx * dx if nboundary_layers == 2: boundary.m[:] = dx * dy * ro * 0.5 else: boundary.m[:] = dx * dy * ro boundary.rho[:] = ro if not self.iisph: boundary.rho0[:] = ro # create the particles list particles = [fluid, boundary] if self.with_obstacle: xo, yo = create_obstacle(x1=2.5, x2=2.5 + dx, height=0.25, dx=dx) gido = numpy.array(list(range(xo.size)), dtype=numpy.uint32) obstacle = get_particle_array_wcsph(name='obstacle', x=xo, y=yo) obstacle.h[:] = numpy.ones_like(xo) * hdx * dx obstacle.m[:] = dx * dy * 0.5 * ro obstacle.rho[:] = ro if not self.iisph: obstacle.rho0[:] = ro # add the obstacle to the boundary particles boundary.append_parray(obstacle) np += obstacle.get_number_of_particles() # set the gid for the boundary particles boundary.gid[:] = list(range(boundary.get_number_of_particles())) # boundary particles can do with a reduced list of properties # to be saved to disk since they are fixed boundary.set_output_arrays( ['x', 'y', 'rho', 'm', 'h', 'p', 'tag', 'pid', 'gid']) if self.iisph: boundary.add_output_arrays(['V']) print("2D dam break with %d fluid, %d boundary particles" % ( fluid.get_number_of_particles(), boundary.get_number_of_particles())) return particles