def test_gyre_collision(): """Regression test for Mclaury coefficient""" bndg = IO.BoundaryData('particle_model/tests/data/gyre_boundary.vtu') system = System.System(bndg, coeff=1.0, temporal_cache=temp_cache('gyre_0.vtu')) from math import pi pos = numpy.array((0.8, 0.45, 0.0)) vel = numpy.array((2.0 * pi, 0.0, 0.0)) part = Particles.Particle((pos, vel), delta_t=0.001, parameters=PAR1, system=system) for i in range(100): del i part.update(method="AdamsBashforth2") assert part.pos[0] < 1.0 assert part.pos[1] < 1.0 assert part.pos[0] > 0.0 assert part.pos[1] > 0.0 assert len(part.collisions) == 1 assert part.collisions[0].pos[0] == 1.0 assert abs(Collision.mclaury_mass_coeff(part.collisions[0]) - 16.444037345317486) < 1.0e-8
def test_stokes_terminal_velocity(): """Test stokes terminal""" bndc = IO.BoundaryData('particle_model/tests/data/boundary_circle.vtu') system = System.System(bndc, base_name='particle_model/tests/data/circle', gravity=numpy.array((0.0, -1.0, 0.0)), rho=0.0, viscosity=1.0) diameter = 1e-3 delta_t = 1.0e-8 par = ParticleBase.PhysicalParticle(diameter=diameter, drag=DragModels.stokes_drag, rho=1.0) pos = numpy.zeros((1, 3)) vel = numpy.zeros((1, 3)) bucket = Particles.ParticleBucket(pos, vel, 0.0, delta_t=delta_t, parameters=par, system=system) bucket.run(100*delta_t, write=False, method="RungeKutta4") assert abs(bucket.time - 100*delta_t) < 1.0e-8 assert all(abs(bucket.particles[0].vel - numpy.array((0, -1.0/18./system.viscosity*par.diameter**2, 0))) < 1.e-8)
def test_picker_linear_3d(tmpdir): """Test vtk picker in 3D.""" pos = ((0.5, 0.5, 0.5), (0.25, 0.75, 0.25)) err = numpy.array((1.0e-8, 1.0e-8, 1.0e-8)) fname = tmpdir.join('linear3D.vtu').strpath print(fname) def vel(pos): """ Fluid velocity""" return numpy.array((pos[0], pos[1], pos[2])) def pres(pos): """ Fluid pressure""" return pos[0] IO.make_unstructured_grid(MESH3D, vel, pres, 0.0, fname) system = System.System(temporal_cache=temp_cache('linear3D.vtu', tmpdir.strpath)) part = Particles.Particle((0, 0), system=system) for point in pos: fluid_velocity, grad_p = part.picker(point, 0.0) assert all(abs(fluid_velocity - vel(point)) < err) assert all(grad_p == numpy.array((1.0, 0.0, 0.0)))
def __init__(self, X, V, time=0, delta_t=1.0e-3, parameters=ParticleBase.PhysicalParticle(), system=System.System(), field_data=None, online=True, **kwargs): """Initialize the bucket Args: X (float): Initial particle positions. V (float): Initial velocities """ logger.info("Initializing ParticleBucket") field_data = field_data or {} self.system = system ### pick only points which are actually in our test box live = system.in_system(X, len(X), time) X = X.compress(live, axis=0) V = V.compress(live, axis=0) self.particles = [] self.dead_particles = [] self.parameters = parameters for _, (dummy_pos, dummy_vel) in enumerate(zip(X, V)): par = Particle((dummy_pos, dummy_vel, time, delta_t), system=self.system, parameters=parameters.randomize(), **kwargs) if par.pure_lagrangian: par.vel = par.picker(par.pos, time)[0] for name, value in field_data.items(): par.fields[name] = copy.deepcopy(value[_]) if self.system.temporal_cache: dummy_u, dummy_p = par.get_fluid_properties() if dummy_u is not None: self.particles.append(par) else: self.particles.append(par) self.time = time self.delta_t = delta_t self._online = online self.solid_pressure_gradient = numpy.zeros((len(self.particles), 3)) for particle, gsp in zip(self, self.solid_pressure_gradient): particle.solid_pressure_gradient = gsp self.redistribute()
def __init__(self, data, parameters=ParticleBase.PhysicalParticle(), system=System.System(), **kwargs): super(Particle, self).__init__(*data, **kwargs) self.collisions = [] self.parameters = parameters self.pure_lagrangian = self.parameters.pure_lagrangian() self.system = system self.solid_pressure_gradient = numpy.zeros(3) self.volume = self.parameters.get_volume() self.pos_callbacks = kwargs.get('pos_callbacks', []) self.vel_callbacks = kwargs.get('vel_callbacks', [])
def test_particle_bucket_step_do_nothing(): """ Test initializing a full particle bucket.""" from numpy import zeros bndc = IO.BoundaryData('particle_model/tests/data/boundary_circle.vtu') system = System.System(bndc, base_name='particle_model/tests/data/circle') num = 1 pres = zeros((num, 3)) vel = zeros((num, 3)) bucket = Particles.ParticleBucket(pres, vel, 0.0, delta_t=0.5, system=system) bucket.run(5.0, write=False) assert bucket.time == 5.0 assert all(bucket.particles[0].pos == 0.0) assert all(bucket.particles[0].vel == 0.0)
def test_coefficient_of_restitution(): """Test of coefficient of restitution parameter.""" pos = numpy.array((0.95, 0.5, 0.0)) vel = numpy.array((1.0, 0.0, 0.0)) system = System.System(BOUNDARY, coeff=0.5, temporal_cache=temp_cache()) part = Particles.Particle((pos, vel), delta_t=0.1, parameters=PAR0, system=system) part.update() assert all(abs(part.pos-numpy.array((0.975, 0.5, 0))) < 1.0e-8) assert all(part.vel == numpy.array((-0.5, 0, 0))) assert part.time == 0.1 assert len(part.collisions) == 1 assert all(part.collisions[0].pos == numpy.array((1., 0.5, 0.))) assert part.collisions[0].time == 0.05 assert all(part.collisions[0].vel == numpy.array((1., 0., 0.))) assert part.collisions[0].angle == numpy.pi/2.0
reader = vtk.vtkXMLUnstructuredGridReader() reader.SetFileName(self.ldir+'/'+self.fname) reader.Update() locator = vtk.vtkCellLocator() locator.SetDataSet(reader.GetOutput()) locator.BuildLocator() return ([[0.0, self.fname, reader.GetOutput(), locator], [1.0, self.fname, reader.GetOutput(), locator]], 0.0, [['Velocity', 'Pressure'], ['Velocity', 'Pressure']]) BOUNDARY = IO.BoundaryData('particle_model/tests/data/rightward_boundary.vtu') BOUNDARY3D = IO.BoundaryData('particle_model/tests/data/cube_boundary.vtu') SYSTEM = System.System(BOUNDARY, coeff=1.0, temporal_cache=temp_cache(), rho=1.0e3, ) SYSTEM3D = System.System(BOUNDARY3D, coeff=1.0, temporal_cache=temp_cache('cube_0.vtu')) MESH = IO.GmshMesh() MESH.read('particle_model/tests/data/Structured.msh') MESH3D = IO.GmshMesh() MESH3D.read('particle_model/tests/data/Structured_cube.msh') PAR0 = ParticleBase.PhysicalParticle(diameter=1.0e32,rho=1.0) PAR1 = ParticleBase.PhysicalParticle(diameter=100.0e-4,rho=1.0e3) def test_tests(): """ Test test structure with a minimal test.""" assert 1