Beispiel #1
0
 def create_solver(self):
     kernel = CubicSpline(dim=2)
     integrator = EPECIntegrator(cylinder = RK2StepRigidBody())
     solver = Solver(kernel=kernel, dim=2, integrator=integrator, tf=0.52, 
                     dt=5e-4, adaptive_timestep=False )
     solver.set_print_freq(10)
     return solver
Beispiel #2
0
    def create_solver(self):
        kernel = CubicSpline(dim=dim)

        integrator = EPECIntegrator(body=RK2StepRigidBody())

        solver = Solver(kernel=kernel, dim=dim, integrator=integrator,
                    dt=dt, tf=tf, adaptive_timestep=False)
        solver.set_print_freq(10)
        return solver
Beispiel #3
0
def main():
    # Create the application.
    app = Application()

    dim = 1
    # Create the kernel
    kernel = CubicSpline(dim=dim)

    # Create the integrator.
    integrator = EulerIntegrator(fluid=DummyStepper())

    solver = Solver(kernel=kernel, dim=dim, integrator=integrator)
    solver.set_time_step(0.1)
    solver.set_final_time(0.1)

    equations = [TotalMass(dest='fluid', sources=['fluid'])]
    app.setup(
        solver=solver, equations=equations, particle_factory=create_particles)
    # There is no need to write any output as the test below
    # computes the total mass.
    solver.set_disable_output(True)
    app.run()

    fluid = solver.particles[0]
    err = fluid.total_mass[0] - 10.0
    assert abs(err) < 1e-16, "Error: %s" % err
Beispiel #4
0
    def configure_solver(self,
                         kernel=None,
                         integrator_cls=None,
                         extra_steppers=None,
                         **kw):
        from pysph.base.kernels import CubicSpline
        if kernel is None:
            kernel = CubicSpline(dim=self.dim)

        steppers = {}
        if extra_steppers is not None:
            steppers.update(extra_steppers)

        from pysph.sph.integrator import EPECIntegrator
        from pysph.sph.integrator_step import SolidMechStep

        cls = integrator_cls if integrator_cls is not None else EPECIntegrator
        step_cls = SolidMechStep
        for name in self.elastic_solids:
            if name not in steppers:
                steppers[name] = step_cls()

        integrator = cls(**steppers)

        from pysph.solver.solver import Solver
        self.solver = Solver(dim=self.dim,
                             integrator=integrator,
                             kernel=kernel,
                             **kw)
Beispiel #5
0
    def configure_solver(self,
                         kernel=None,
                         integrator_cls=None,
                         extra_steppers=None,
                         **kw):
        from pysph.base.kernels import QuinticSpline
        if kernel is None:
            kernel = QuinticSpline(dim=self.dim)
        steppers = {}
        if extra_steppers is not None:
            steppers.update(extra_steppers)

        step_cls = PCISPHStep
        for fluid in self.fluids:
            if fluid not in steppers:
                steppers[fluid] = step_cls(self.show_itercount)

        cls = PCISPHIntegrator if integrator_cls is None else integrator_cls
        integrator = cls(**steppers)

        from pysph.solver.solver import Solver
        self.solver = Solver(dim=self.dim,
                             integrator=integrator,
                             kernel=kernel,
                             output_at_times=[0, 0.2, 0.4, 0.8],
                             **kw)
    def configure_solver(self,
                         kernel=None,
                         integrator_cls=None,
                         extra_steppers=None,
                         **kw):
        from pysph.base.kernels import CubicSpline
        if kernel is None:
            kernel = CubicSpline(dim=self.dim)

        steppers = {}
        if extra_steppers is not None:
            steppers.update(extra_steppers)

        from pysph.sph.integrator import PECIntegrator, TVDRK3Integrator
        from pysph.sph.integrator_step import WCSPHStep, WCSPHTVDRK3Step

        cls = integrator_cls if integrator_cls is not None else PECIntegrator
        step_cls = WCSPHTVDRK3Step if cls is TVDRK3Integrator else WCSPHStep
        for name in self.fluids + self.solids:
            if name not in steppers:
                steppers[name] = step_cls()

        integrator = cls(**steppers)

        from pysph.solver.solver import Solver
        if 'dt' not in kw:
            kw['dt'] = self.get_timestep()
        self.solver = Solver(dim=self.dim,
                             integrator=integrator,
                             kernel=kernel,
                             **kw)
Beispiel #7
0
    def configure_solver(self,
                         kernel=None,
                         integrator_cls=None,
                         extra_steppers=None,
                         **kw):

        from pysph.base.kernels import Gaussian
        if kernel is None:
            kernel = Gaussian(dim=self.dim)

        if hasattr(kernel, 'fkern'):
            self.fkern = kernel.fkern
        else:
            self.fkern = 1.0

        steppers = {}
        if extra_steppers is not None:
            steppers.update(extra_steppers)

        from pysph.sph.integrator import PECIntegrator

        cls = integrator_cls if integrator_cls is not None else PECIntegrator
        step_cls = PECStep
        for name in self.fluids:
            if name not in steppers:
                steppers[name] = step_cls()

        integrator = cls(**steppers)

        from pysph.solver.solver import Solver
        self.solver = Solver(dim=self.dim,
                             integrator=integrator,
                             kernel=kernel,
                             **kw)
Beispiel #8
0
    def configure_solver(self,
                         kernel=None,
                         integrator_cls=None,
                         extra_steppers=None,
                         **kw):
        import pysph.base.kernels as kern
        if kernel is None:
            kernel = kern.QuinticSpline(dim=self.dim)
        steppers = {}
        if extra_steppers is not None:
            steppers.update(extra_steppers)

        step_cls = SISPHStep
        if self.gtvf:
            step_cls = SISPHGTVFStep

        for fluid in self.fluids:
            if fluid not in steppers:
                steppers[fluid] = step_cls()

        if integrator_cls is not None:
            cls = integrator_cls
        else:
            cls = SISPHIntegrator

        integrator = cls(**steppers)

        from pysph.solver.solver import Solver
        self.solver = Solver(dim=self.dim,
                             integrator=integrator,
                             kernel=kernel,
                             **kw)
Beispiel #9
0
    def create_solver(self):
        """Create Solver with min. time step from CFL and viscous step."""
        kernel = CubicSpline(dim=3)
        integrator = EPECIntegrator(fluid=WCSPHStep(),
                                    walls=WCSPHStep(),
                                    ellipsoid=RK2StepRigidBody())

        h = self.hdx * self.dx
        dt_cfl = 0.4 * h / (1.1 * self.co)
        dt_viscous = 0.125 * h**2 / self.nu
        dt = min(dt_viscous, dt_cfl)
        print("dt_cfl: %s" % dt_cfl)
        print("dt_viscous: %s" % dt_viscous)
        print("DT: %s" % dt)
        tf = 12
        solver = Solver(
            kernel=kernel,
            dim=3,
            integrator=integrator,
            dt=dt,
            tf=tf,
            adaptive_timestep=False,
        )

        return solver
Beispiel #10
0
 def create_solver(self):
     kernel = WendlandQuintic(dim=2)
     integrator = PECIntegrator(fluid=TransportVelocityStep())
     solver = Solver(
         kernel=kernel, dim=dim, integrator=integrator,
         dt=dt, tf=tf, adaptive_timestep=False)
     return solver
Beispiel #11
0
 def create_solver(self):
     kernel = QuinticSpline(dim=2)
     integrator = EPECIntegrator(fluid=TransportVelocityStep())
     solver = Solver(
         kernel=kernel, dim=dim, integrator=integrator,
         dt=dt, tf=tf, adaptive_timestep=False,
         output_at_times=[0., 0.08, 0.16, 0.26])
     return solver
Beispiel #12
0
 def create_solver(self):
     kernel = QuinticSpline(dim=2)
     integrator = PECIntegrator(liquid=TransportVelocityStep(),
                                gas=TransportVelocityStep())
     solver = Solver(
         kernel=kernel, dim=dim, integrator=integrator,
         dt=dt, tf=tf, adaptive_timestep=False)
     return solver
Beispiel #13
0
    def create_solver(self):
        kernel = WendlandQuintic(dim=dim)

        integrator = EPECIntegrator(fluid=WCSPHStep(),
                                    obstacle=RK2StepRigidBody(),
                                    boundary=WCSPHStep())
        solver = Solver(kernel=kernel, dim=dim, integrator=integrator,
                        tf=tf, dt=dt, adaptive_timestep=True, n_damp=0)
        return solver
    def configure_solver(self,
                         kernel=None,
                         integrator_cls=None,
                         extra_steppers=None,
                         **kw):
        """Configure the solver to be generated.

        This is to be called before `get_solver` is called.

        Parameters
        ----------

        dim : int
            Number of dimensions.
        kernel : Kernel instance.
            Kernel to use, if none is passed a default one is used.
        integrator_cls : pysph.sph.integrator.Integrator
            Integrator class to use, use sensible default if none is
            passed.
        extra_steppers : dict
            Additional integration stepper instances as a dict.
        **kw : extra arguments
            Any additional keyword args are passed to the solver instance.
        """
        from pysph.base.kernels import QuinticSpline
        from pysph.sph.integrator import PECIntegrator
        if kernel is None:
            kernel = QuinticSpline(dim=self.dim)
        steppers = {}
        if extra_steppers is not None:
            steppers.update(extra_steppers)

        step_cls = EDACTVFStep if self.use_tvf else EDACStep
        cls = integrator_cls if integrator_cls is not None else PECIntegrator

        for fluid in self.fluids:
            if fluid not in steppers:
                steppers[fluid] = step_cls()

        iom = self.inlet_outlet_manager
        if iom is not None:
            iom_stepper = iom.get_stepper(self, cls)
            print(iom_stepper)
            for name in iom_stepper:
                steppers[name] = iom_stepper[name]

        integrator = cls(**steppers)

        from pysph.solver.solver import Solver
        self.solver = Solver(dim=self.dim,
                             integrator=integrator,
                             kernel=kernel,
                             **kw)

        if iom is not None:
            iom.setup_iom(dim=self.dim, kernel=kernel)
Beispiel #15
0
 def create_solver(self):
     kernel = WendlandQuintic(dim=2)
     integrator = PECIntegrator(fluid=VerletSymplecticWCSPHStep())
     solver = Solver(kernel=kernel,
                     dim=dim,
                     integrator=integrator,
                     dt=dt,
                     tf=tf,
                     adaptive_timestep=False)
     return solver
Beispiel #16
0
 def create_solver(self):
     """Set up the default integrator for fiber particles."""
     kernel = QuinticSpline(dim=3)
     integrator = EPECIntegrator(
         fiber1=TransportVelocityStep(),
         fiber2=TransportVelocityStep())
     solver = Solver(
         kernel=kernel, dim=3, integrator=integrator, dt=self.dt,
         tf=self.tf, N=200)
     return solver
 def create_solver(self):
     kernel = CubicSpline(dim=1)
     integrator = SWEIntegrator(fluid=SWEStep())
     tf = 10
     solver = Solver(kernel=kernel,
                     dim=1,
                     integrator=integrator,
                     cfl=0.3,
                     adaptive_timestep=True,
                     tf=tf)
     return solver
Beispiel #18
0
 def create_solver(self):
     kernel = CubicSpline(dim=2)
     integrator = SWEIntegrator(fluid=SWEStep())
     dt = 1e-4
     tf = 1e-4
     solver = Solver(kernel=kernel,
                     dim=2,
                     integrator=integrator,
                     dt=dt,
                     tf=tf)
     return solver
Beispiel #19
0
    def create_solver(self):
        # Create the kernel
        #kernel = Gaussian(dim=2)
        kernel = QuinticSpline(dim=2)

        integrator = PECIntegrator(fluid=WCSPHStep())

        # Create a solver.
        solver = Solver(kernel=kernel, dim=2, integrator=integrator,
                        tf=tf, dt=dt, output_at_times=output_at_times)
        return solver
Beispiel #20
0
    def test_solver_dumps_output_given_output_at_times_landing_exactly(self):
        # Given
        dt = 0.1
        self.integrator.compute_time_step.return_value = dt
        tf = 3.0
        pfreq = 10
        output_at_times = np.concatenate(
            (np.arange(0, 1.21, 0.2), np.arange(1.25, 1.51, 0.05)))
        solver = Solver(integrator=self.integrator,
                        tf=tf,
                        dt=dt,
                        output_at_times=output_at_times)
        solver.set_print_freq(pfreq)
        solver.acceleration_evals = [self.a_eval]
        solver.particles = []

        # When
        record = []
        record_dt = []

        def _mock_dump_output():
            # Record the time at which the solver dumped anything
            record.append(solver.t)
            # This smells but ...
            sd = solver._get_solver_data()
            record_dt.append(sd['dt'])

        solver.dump_output = mock.Mock(side_effect=_mock_dump_output)

        solver.solve(show_progress=False)

        # Then
        expected = np.concatenate(
            (np.arange(0, 1.21, 0.2), np.arange(1.25, 1.49,
                                                0.05), [1.5, 1.7, 2.7, 3.0]))
        error_message = "Expected %s, got %s" % (expected, record)
        self.assertEqual(len(expected), len(record), error_message)
        self.assertTrue(
            np.max(np.abs(expected - record)) < 1e-12, error_message)
        self.assertEqual(33, solver.count)
        # The final timestep should not be a tiny one due to roundoff.
        self.assertTrue(solver.dt > 0.1 * 0.25)

        npt.assert_array_almost_equal([0.1] * len(record_dt),
                                      record_dt,
                                      decimal=12)
 def create_solver(self):
     kernel = CubicSpline(dim=1)
     integrator = SWEIntegrator(fluid=SWEStep())
     tf = 60
     solver = Solver(kernel=kernel,
                     dim=1,
                     integrator=integrator,
                     cfl=0.3,
                     adaptive_timestep=True,
                     output_at_times=[10, 20, 30, 40, 50, 60],
                     tf=tf)
     return solver
Beispiel #22
0
    def create_solver(self):
        kernel = CubicSpline(dim=2)
        integrator = PECIntegrator(fluid=WCSPHStep())

        dt = 5e-6
        tf = 0.0076
        solver = Solver(kernel=kernel,
                        dim=2,
                        integrator=integrator,
                        dt=dt,
                        tf=tf)
        return solver
Beispiel #23
0
 def create_solver(self):
     kernel = CubicSpline(dim=2)
     integrator = SWEIntegrator(inlet=SWEInletOutletStep(), fluid=SWEStep())
     tf = 22.51
     solver = Solver(kernel=kernel,
                     dim=2,
                     integrator=integrator,
                     cfl=0.4,
                     adaptive_timestep=True,
                     output_at_times=(10, 12, 14, 15, 16, 17, 18, 20),
                     tf=tf)
     return solver
Beispiel #24
0
    def create_solver(self):
        kernel = WendlandQuintic(dim=2)

        integrator = EPECIntegrator(fluid=WCSPHStep(),
                                    block=RK2StepRigidBody())
        solver = Solver(kernel=kernel,
                        dim=2,
                        integrator=integrator,
                        tf=tf,
                        dt=dt,
                        adaptive_timestep=False)
        return solver
    def create_solver(self):
        kernel = CubicSpline(dim=2)

        integrator = EPECIntegrator(fluid=WCSPHStep())

        dt = 0.125 * self.dx * self.hdx / (self.co * 1.1) / 2.
        print("DT: %s" % dt)
        tf = 0.5
        solver = Solver(kernel=kernel, dim=2, integrator=integrator, dt=dt,
                        tf=tf, adaptive_timestep=False)

        return solver
Beispiel #26
0
    def create_solver(self):
        kernel = CubicSpline(dim=2)

        integrator = EPECIntegrator(mg=DEMStep(), al=DEMStep())

        dt = 1e-7
        print("DT: %s" % dt)
        tf = 0.0013
        solver = Solver(kernel=kernel, dim=2, integrator=integrator, dt=dt,
                        tf=tf, adaptive_timestep=False)

        return solver
Beispiel #27
0
 def create_solver(self):
     kernel = CubicSpline(dim=2)
     integrator = SWEIntegrator(fluid=SWEStep())
     tf = 1.0
     solver = Solver(kernel=kernel,
                     dim=2,
                     integrator=integrator,
                     cfl=0.3,
                     adaptive_timestep=True,
                     output_at_times=(0.1, 0.2, 0.3),
                     tf=tf)
     return solver
Beispiel #28
0
    def create_solver(self):
        kernel = CubicSpline(dim=2)

        integrator = EulerIntegrator(fluid=EulerStep(),solid=EulerStep())

        dt = 0.125 * 0.125 * self.h / self.c0
        tf = 2
        solver = Solver(kernel=kernel, dim=2, integrator=integrator,
                        dt=dt, tf=tf, adaptive_timestep=True,
                        cfl=0.05, n_damp=50)

        return solver
Beispiel #29
0
    def create_solver(self):
        kernel = CubicSpline(dim=2)
        self.wdeltap = kernel.kernel(rij=dx, h=hdx * dx)

        integrator = PECIntegrator(solid=SolidMechStep())

        solver = Solver(kernel=kernel, dim=2, integrator=integrator)

        dt = 1e-8
        tf = 5e-5
        solver.set_time_step(dt)
        solver.set_final_time(tf)
        solver.set_print_freq(500)
        return solver
Beispiel #30
0
    def test_solver_dumps_output_given_output_at_times(self):
        # Given
        dt = 0.1
        self.integrator.compute_time_step.return_value = dt
        tf = 10.05
        pfreq = 5
        output_at_times = [0.3, 0.35]
        solver = Solver(integrator=self.integrator,
                        tf=tf,
                        dt=dt,
                        output_at_times=output_at_times)
        solver.set_print_freq(pfreq)
        solver.acceleration_eval = self.a_eval
        solver.particles = []

        # When
        record = []
        record_dt = []

        def _mock_dump_output():
            # Record the time at which the solver dumped anything
            record.append(solver.t)
            # This smells but ...
            sd = solver._get_solver_data()
            record_dt.append(sd['dt'])

        solver.dump_output = mock.Mock(side_effect=_mock_dump_output)

        solver.solve(show_progress=False)

        # Then
        expected = np.asarray([0.0, 0.3, 0.35] +
                              np.arange(0.45, 10.1, 0.5).tolist() + [10.05])
        error_message = "Expected %s, got %s" % (expected, record)
        self.assertEqual(len(expected), len(record), error_message)
        self.assertTrue(
            np.max(np.abs(expected - record)) < 1e-12, error_message)
        self.assertEqual(101, solver.count)
        # The final timestep should not be a tiny one due to roundoff.
        self.assertTrue(solver.dt > 0.1 * 0.25)

        npt.assert_array_almost_equal([0.1] * len(record_dt),
                                      record_dt,
                                      decimal=12)
Beispiel #31
0
    def create_solver(self):
        kernel = CubicSpline(dim=2)
        integrator = EPECIntegrator(fluid=EDACStep())

        dt = 0.125 * self.h0 / c0
        self.scheme.configure(h=self.h0)
        solver = Solver(kernel=kernel,
                        dim=2,
                        integrator=integrator,
                        tf=tf,
                        dt=dt)

        return solver
    return [fluid,]

# domain for periodicity
domain = DomainManager(xmin=0, xmax=L, ymin=0, ymax=L,
                      periodic_in_x=True, periodic_in_y=True)

# Create the application.
app = Application(domain=domain)

# Create the kernel
kernel = WendlandQuintic(dim=2)

integrator = EulerIntegrator(fluid=EulerStep())

# Create a solver.
solver = Solver(kernel=kernel, dim=2, integrator=integrator)

# Setup default parameters.
solver.set_time_step(1e-3)
solver.set_final_time(T)

equations = [

    # Update velocities and advect
    Group(
        equations=[
            MixingVelocityUpdate(
                dest='fluid', sources=None, T=T),

            Advect(dest='fluid', sources=None)
            ])
Beispiel #33
0
    pa.set_lb_props( pa.properties.keys() )

    return [pa,]

# create the Application
app = Application()

# kernel
kernel = CubicSpline(dim=2)
wdeltap = kernel.kernel(rij=dx, h=hdx*dx)

# integrator
integrator = PECIntegrator(solid=SolidMechStep())

# Create a solver
solver = Solver(kernel=kernel, dim=2, integrator=integrator)

# default parameters
dt = 1e-8
tf = 5e-5
solver.set_time_step(dt)
solver.set_final_time(tf)
solver.set_print_freq(500)

# add the equations
equations = [

    # Properties computed set from the current state
    Group(
        equations=[
            # p
Beispiel #34
0
        bar.add_property(name)

    return [bar, plate]

# create the Application
app = Application()

# kernel
kernel = WendlandQuintic(dim=2)
wdeltap = kernel.kernel(rij=dx, h=hdx*dx)

# integrator
integrator = PECIntegrator(bar=SolidMechStep())

# Create a solver
solver = Solver(kernel=kernel, dim=2, integrator=integrator)

# default parameters
dt = 1e-9
tf = 2.5e-5
solver.set_time_step(dt)
solver.set_final_time(tf)

# add the equations
equations = [

    # Properties computed set from the current state
    Group(
        equations=[
            # p
            MieGruneisenEOS(dest='bar', sources=None, r0=r0, c0=C, S=S),