Beispiel #1
0
    def setup_solver(self):

        s = self.solver

        # Add the default operations

        s.add_operation(
            solver.SPHOperation(sph.TaitEquation.withargs(1, 1),
                                on_types=[Fluids, Solids],
                                updates=['p', 'cs'],
                                id='eos'))

        s.add_operation(
            solver.SPHIntegration(sph.SPHDensityRate,
                                  on_types=[Fluids, Solids],
                                  from_types=[Fluids, Solids],
                                  updates=['rho'],
                                  id='density_rate'))

        s.add_operation(
            solver.SPHIntegration(sph.SPHPressureGradient.withargs(dim=2),
                                  on_types=[Fluids],
                                  from_types=[Fluids, Solids],
                                  updates=['u', 'v'],
                                  id='pgrad'))

        s.add_operation(
            solver.SPHIntegration(sph.MonaghanArtificialVsicosity,
                                  on_types=[Fluids],
                                  from_types=[Fluids, Solids],
                                  updates=['u', 'v', 'w'],
                                  id='avisc'))
Beispiel #2
0
    def setUp(self):
        """
        Setup a default simulation in 2D. The setup consists of four particles
        on a circle of radius 2/pi. The particles are constrained to move
        along the circle with forcing functions defined in 
        pysph/sph/funcs/external_forces.pyx 
        
        With the choice of radius and unit magnitude of velocity, the particles
        move by pi/2 radians in 1 second. 

        """
        self.r = r = 2. / numpy.pi
        self.x = x = numpy.array([1.0, 0.0, -1.0, 0.0])
        self.y = y = numpy.array([0.0, 1.0, 0.0, -1.0])

        x *= r
        y *= r

        p = numpy.zeros_like(x)
        e = numpy.zeros_like(x)
        h = numpy.ones_like(x)

        self.pa = pa = base.get_particle_array(x=x,
                                               y=y,
                                               p=p,
                                               e=e,
                                               h=h,
                                               name='tmp')

        self.particles = particles = base.Particles(arrays=[pa])
        self.kernel = base.CubicSplineKernel(dim=2)

        circlex = solver.SPHIntegration(sph.MoveCircleX,
                                        from_types=[Fluids],
                                        on_types=[Fluids],
                                        updates=['x', 'y'],
                                        id='circlex')

        circley = solver.SPHIntegration(sph.MoveCircleY,
                                        from_types=[Fluids],
                                        on_types=[Fluids],
                                        updates=['x', 'y'],
                                        id='circley')

        self.calcx = circlex.get_calcs(particles, self.kernel)
        self.calcy = circley.get_calcs(particles, self.kernel)

        self.calcs = []
        self.calcs.extend(self.calcx)
        self.calcs.extend(self.calcy)

        self.integrator = Integrator(particles=particles, calcs=self.calcs)

        self.setup()
Beispiel #3
0
    def setUp(self):
        """ A Dummy fluid solver is created with the following operations

        (i)  -- Equation of State
        (ii) -- Density Rate
        (iii)-- Momentum Equation Pressure Gradient
        (iv) -- Momentum Equation Viscosity 
        
        """
        self.kernel = kernel = base.CubicSplineKernel(dim=2)

        self.solver = s = solver.Solver(dim=2,
                                        integrator_type=solver.EulerIntegrator)

        s.default_kernel = kernel

        self.particles = base.Particles(arrays=[base.get_particle_array()])

        # Create some replacement operations

        self.visc = solver.SPHIntegration(sph.MorrisViscosity,
                                          on_types=[Fluids],
                                          from_types=[Fluids, Solids],
                                          updates=['u', 'v'],
                                          id='visc')

        self.summation_density = solver.SPHOperation(sph.SPHRho,
                                                     on_types=[Fluids, Solids],
                                                     updates=['rho'],
                                                     id='sd')
Beispiel #4
0
    def setUp(self):

        parrays = []

        for i in range(np):
            x = numpy.array([x0[i]])
            y = numpy.array([y0[i]])
            z = numpy.array([z0[i]])
            h = numpy.array([h0[i]])

            mi = numpy.array([m[i]])

            name = 'array' + str(i)
            pa = base.get_particle_array(name=name, x=x, y=y, z=z, h=h, m=mi)

            parrays.append(pa)

        self.parrays = parrays

        self.particles = base.Particles(arrays=parrays)

        kernel = base.CubicSplineKernel(dim=3)

        self.solver = s = solver.Solver(dim=3,
                                        integrator_type=solver.EulerIntegrator)

        # NBodyForce operation

        s.add_operation(
            solver.SPHIntegration(sph.NBodyForce.withargs(eps=eps),
                                  on_types=[Fluids],
                                  from_types=[Fluids],
                                  updates=['u', 'v', 'w'],
                                  id='nbody_force'))

        # position stepping

        s.add_operation_step([Fluids])

        # time step and final time

        s.set_final_time(tf)
        s.set_time_step(dt)

        # setup the integrator

        s.setup_integrator(self.particles)
Beispiel #5
0
s.default_kernel = kernel

#Tait equation
s.add_operation(solver.SPHOperation(
        
        sph.TaitEquation.withargs(co=25.0, ro=1.0), 
        on_types=[Fluid], 
        updates=['p','cs'],
        id='eos', kernel=kernel)

                )

#continuity equation
s.add_operation(solver.SPHIntegration(
            
            sph.SPHDensityRate.withargs(), from_types=[Fluid], 
            on_types=[Fluid],
            updates=['rho'], id='density', kernel=kernel)

                )

#momentum equation
s.add_operation(solver.SPHIntegration(

    sph.MomentumEquation.withargs(alpha=0.0, beta=0.0,),
    on_types=[Fluid], 
    from_types=[Fluid], 
    updates=['u','v'], id='mom')

                )
Beispiel #6
0
app.particles = particles

s = solver.Solver(dim=2, integrator_type=solver.EulerIntegrator)

#Equation of state
s.add_operation(
    solver.SPHOperation(sph.TaitEquation.withargs(co=25.0, ro=1.0),
                        on_types=[Fluid, Solid],
                        updates=['p', 'cs'],
                        id='eos'))

#Continuity equation
s.add_operation(
    solver.SPHIntegration(sph.SPHDensityRate.withargs(),
                          from_types=[Fluid, Solid],
                          on_types=[Fluid, Solid],
                          updates=['rho'],
                          id='density'))

#momentum equation, no viscosity
s.add_operation(
    solver.SPHIntegration(sph.MomentumEquation.withargs(alpha=0.0, beta=0.0),
                          on_types=[Fluid],
                          from_types=[Fluid, Solid],
                          updates=['u', 'v'],
                          id='mom'))

#Gravity force
s.add_operation(
    solver.SPHIntegration(sph.GravityForce.withargs(gy=-9.81),
                          on_types=[Fluid],
Beispiel #7
0
                                    updates=['div'],
                                    id='vdivergence'),
                before=False,
                id='density')

s.add_operation(solver.SPHOperation(sph.ADKEConductionCoeffUpdate.withargs(
    g1=g1, g2=g2),
                                    on_types=[Fluid],
                                    from_types=[Fluid],
                                    updates=['q'],
                                    id='qcoeff'),
                before=False,
                id='vdivergence')

# add the artificial heat term after the energy equation

s.add_operation(solver.SPHIntegration(sph.ArtificialHeat.withargs(eta=0.1),
                                      on_types=[Fluid],
                                      from_types=[Fluid],
                                      updates=['e'],
                                      id='aheat'),
                before=False,
                id="enr")

s.set_final_time(0.15)
s.set_time_step(3e-4)

app.set_solver(s)

app.run()
Beispiel #8
0
print "Number of cells: ", len(particles.cell_manager.cells_dict)

s = solver.Solver(dim=2, integrator_type=solver.PredictorCorrectorIntegrator)

#Equation of state
s.add_operation(
    solver.SPHOperation(sph.TaitEquation.withargs(hks=False, co=co, ro=ro),
                        on_types=[Fluid, Solid],
                        updates=['p', 'cs'],
                        id='eos'), )

#Continuity equation
s.add_operation(
    solver.SPHIntegration(sph.SPHDensityRate.withargs(hks=False),
                          on_types=[Fluid, Solid],
                          from_types=[Fluid, Solid],
                          updates=['rho'],
                          id='density'))

#momentum equation
s.add_operation(
    solver.SPHIntegration(sph.MomentumEquation.withargs(alpha=alpha,
                                                        beta=0.0,
                                                        hks=False),
                          on_types=[Fluid],
                          from_types=[Fluid, Solid],
                          updates=['u', 'v'],
                          id='mom'))

#s.add_operation(solver.SPHIntegration(
Beispiel #9
0
s = solver.Solver(dim=2, integrator_type=solver.PredictorCorrectorIntegrator)

# Equation of state

s.add_operation(
    solver.SPHOperation(sph.TaitEquation(co=co, ro=ro),
                        on_types=[Fluid],
                        updates=['p', 'cs'],
                        id='eos'))

# Continuity equation

s.add_operation(
    solver.SPHIntegration(sph.SPHDensityRate(),
                          on_types=[Fluid],
                          from_types=[Fluid, DummyFluid],
                          updates=['rho'],
                          id='density'))

# momentum equation

s.add_operation(
    solver.SPHIntegration(sph.MomentumEquation(alpha=alpha, beta=0.0),
                          on_types=[Fluid],
                          from_types=[Fluid, DummyFluid],
                          updates=['u', 'v'],
                          id='mom'))

# monaghan boundary force

s.add_operation(
Beispiel #10
0
    def setUp(self):
        """ The setup consists of two fluid particle arrays, each
        having one particle. The fluids are acted upon by an external
        vector force and gravity.

        Comparison is made with the PySPH integration of the system.
        
        """

        x1 = numpy.array([
            -0.5,
        ])
        y1 = numpy.array([
            1.0,
        ])

        x2 = numpy.array([
            0.5,
        ])
        y2 = numpy.array([
            1.0,
        ])

        tmpx1 = numpy.ones_like(x1)
        tmpx2 = numpy.ones_like(x2)

        self.f1 = base.get_particle_array(name="fluid1",
                                          x=x1,
                                          y=y1,
                                          tmpx=tmpx1)
        self.f2 = base.get_particle_array(name="fluid2",
                                          x=x2,
                                          y=y2,
                                          tmpx=tmpx2)

        self.particles = base.Particles(arrays=[self.f1, self.f2])
        self.kernel = kernel = base.CubicSplineKernel(dim=2)

        gravity = solver.SPHIntegration(sph.GravityForce.withargs(gy=-10.0),
                                        on_types=[Fluid],
                                        updates=['u', 'v'],
                                        id='gravity')

        force = solver.SPHIntegration(sph.GravityForce.withargs(gx=-10.0),
                                      on_types=[Fluid],
                                      updates=['u', 'v'],
                                      id='force')

        position = solver.SPHIntegration(
            sph.PositionStepping,
            on_types=[Fluid],
            updates=['x', 'y'],
            id='step',
        )

        gravity.calc_type = sph.CLCalc
        force.calc_type = sph.CLCalc
        position.calc_type = sph.CLCalc

        gravity_calcs = gravity.get_calcs(self.particles, kernel)
        force_calcs = force.get_calcs(self.particles, kernel)
        position_calcs = position.get_calcs(self.particles, kernel)

        self.calcs = calcs = []
        calcs.extend(gravity_calcs)
        calcs.extend(force_calcs)
        calcs.extend(position_calcs)

        self.integrator = CLIntegrator(self.particles, calcs)

        self.ctx = ctx = cl.create_some_context()
        self.integrator.setup_integrator(ctx)
        self.queue = calcs[0].queue

        self.dt = 0.1
        self.nsteps = 10
Beispiel #11
0
    def test_calc(self):

        function = sph.GravityForce.withargs(gy=-9.81)
        operation = solver.SPHIntegration(function=function,
                                          on_types=[Solid, Fluid],
                                          updates=['u', 'v'],
                                          id='gravity')

        calcs = operation.get_calcs(particles=self.particles,
                                    kernel=self.kernel)

        ncalcs = len(calcs)
        self.assertEqual(ncalcs, 2)

        # Test for the first calc
        # dnum, dest = (0, fluid)

        calc1 = calcs[0]
        self.assertEqual(calc1.dnum, 0)
        self.assertEqual(calc1.dest, self.fluid)

        # nsrcs = 0

        sources = calc1.sources
        nsrcs = len(sources)
        self.assertEqual(nsrcs, 0)

        # integrates == True

        self.assertEqual(calc1.integrates, True)

        # GravityForce does not require neighbors
        self.assertEqual(calc1.nbr_info, False)

        # updates = ['u','v']

        updates = calc1.updates
        nupdates = len(calc1.updates)

        self.assertEqual(nupdates, 2)
        self.assertEqual(updates, ['u', 'v'])

        # Test for the second calc
        # dnum, dest = (0, solid)

        calc = calcs[1]
        self.assertEqual(calc.dnum, 1)
        self.assertEqual(calc.dest, self.solid)

        # nsrcs = 0

        sources = calc.sources
        nsrcs = len(sources)
        self.assertEqual(nsrcs, 0)

        # integrates = True

        self.assertEqual(calc.integrates, True)

        # updates = ['u','v']

        updates = calc.updates
        nupdates = len(calc.updates)
        self.assertEqual(nupdates, 2)
        self.assertEqual(updates, ['u', 'v'])
Beispiel #12
0
    def setUp(self):
        """ A simple simulation in 2D with boundary particles spaced with a
        distance dp. The fluid particles are in a row just above as shown
        in the fgure. 

                   dx
                  o   o   o   o   o
            x x x x x x x x x x x x x x x  

        Y
        |  Z
        | /
        |/___ X
            

        Expected Behavior:
        -------------------
        The Monaghan Boundary force is defned such that a particle moving 
        parallel to the wall experiences a constant force.
        Each fluid particle can be thought of successive instances of a 
        moving particle and hence each of them should experience the same
        force.

        """

        #fluid particle spacing
        self.dx = dx = 0.1

        #solid particle spacing
        self.dp = dp = 0.05

        #the fluid properties
        xf = numpy.array([-.2, -.1, 0.0, 0.1, 0.2])
        yf = numpy.array([dp, dp, dp, dp, dp])
        hf = numpy.ones_like(xf) * 2 * dx
        mf = numpy.ones_like(xf) * dx
        cs = numpy.ones_like(xf)
        rhof = numpy.ones_like(xf)

        self.fluid = base.get_particle_array(x=xf,
                                             y=yf,
                                             h=hf,
                                             m=mf,
                                             rho=rhof,
                                             cs=cs,
                                             ax=mf,
                                             ay=mf,
                                             az=mf,
                                             name='fluid',
                                             type=Fluid)

        l = base.Line(base.Point(-0.35), 0.70, 0.0)
        g = base.Geometry('line', lines=[l], is_closed=False)
        g.mesh_geometry(dp)
        self.solid = g.get_particle_array(re_orient=True)

        self.particles = particles = base.Particles(
            arrays=[self.fluid, self.solid])

        self.kernel = kernel = base.CubicSplineKernel(dim=2)

        self.solver = solver.Solver(kernel.dim, solver.EulerIntegrator)

        self.solver.add_operation(
            solver.SPHIntegration(sph.MonaghanBoundaryForce.withargs(delp=dp),
                                  from_types=[Solid],
                                  on_types=[Fluid],
                                  updates=['u', 'v', 'w'],
                                  id='boundary'))

        self.solver.setup_integrator(particles)

        self.integrator = self.solver.integrator