Example #1
0
    def test_solver_honors_set_time_step(self):
        # Given
        dt = 0.1
        tf = 1.0
        pfreq = 1
        solver = Solver(integrator=self.integrator,
                        tf=tf,
                        dt=dt,
                        adaptive_timestep=False)
        solver.set_print_freq(pfreq)
        solver.acceleration_evals = [self.a_eval]
        solver.particles = []
        record = []

        def _mock_dump_output():
            # Record the time at which the solver dumped anything
            record.append(solver.t)

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

        # When
        solver.set_time_step(0.2)
        solver.solve(show_progress=False)

        # Then
        expected = np.asarray([0.0, 0.2, 0.4, 0.6, 0.8, 1.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)
Example #2
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
Example #3
0
    def create_solver(self):
        kernel = WendlandQuintic(dim=2)
        self.wdeltap = kernel.kernel(rij=dx, h=hdx * dx)

        integrator = PECIntegrator(bar=SolidMechStep())

        solver = Solver(kernel=kernel, dim=2, integrator=integrator)
        dt = 1e-9
        tf = 2.5e-5
        solver.set_time_step(dt)
        solver.set_final_time(tf)
        return solver
Example #4
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
Example #5
0
    def create_solver(self):
        dim = 3
        kernel = Gaussian(dim=dim)
        # kernel = WendlandQuintic(dim=dim)

        integrator = EPECIntegrator(projectile=SolidMechStep(),
                                    plate=SolidMechStep())
        solver = Solver(kernel=kernel, dim=dim, integrator=integrator)

        dt = 1e-9
        tf = 8e-5
        solver.set_time_step(dt)
        solver.set_final_time(tf)
        solver.set_print_freq(100)
        return solver
Example #6
0
    def create_solver(self):
        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)
        # There is no need to write any output as the test below
        # computes the total mass.
        solver.set_disable_output(True)
        return solver
Example #7
0
    def create_solver(self):
        kernel = Gaussian(dim=2)
        #kernel = WendlandQuintic(dim=2)

        self.wdeltap = kernel.kernel(rij=dx, h=hdx * dx)

        integrator = EPECIntegrator(projectile=SolidMechStep(),
                                    plate=SolidMechStep())
        solver = Solver(kernel=kernel, dim=2, integrator=integrator)

        dt = 1e-9
        tf = 8e-6
        solver.set_time_step(dt)
        solver.set_final_time(tf)
        solver.set_print_freq(100)
        return solver
    def create_solver(self):
        dim = 3
        kernel = CubicSpline(dim=dim)
        # kernel = WendlandQuintic(dim=dim)

        self.wdeltap = kernel.kernel(rij=dx, h=hdx * dx)

        integrator = EPECIntegrator(fluid=WCSPHStep())
        solver = Solver(kernel=kernel, dim=dim, integrator=integrator)

        dt = 1e-9
        tf = 8e-6
        solver.set_time_step(dt)
        solver.set_final_time(tf)
        solver.set_print_freq(100)
        return solver
Example #9
0
    def stage1(self):
        pass


# 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
Example #10
0
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
            IsothermalEOS(dest='solid', sources=None, rho0=rho0, c0=c0),

            # vi,j : requires properties v00, v01, v10, v11
            VelocityGradient2D(dest='solid', sources=['solid',]),
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)
            ])
    ]

# Setup the application and solver.  This also generates the particles.
Example #12
0
# Create the application.
app = Application(domain=domain)

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

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

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

# Setup default parameters.
tf = 5 * np.sqrt(2.0)
solver.set_time_step(1e-3)
solver.set_final_time(tf)

equations = [

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

# Setup the application and solver.  This also generates the particles.
app.setup(solver=solver,
          equations=equations,
          particle_factory=create_particles)