def test_compute_timestep_without_adaptive(self): # Given. integrator = EulerIntegrator(fluid=EulerStep()) equations = [SHM(dest="fluid", sources=None)] self._setup_integrator(equations=equations, integrator=integrator) # When dt = integrator.compute_time_step(0.1, 0.5) # Then self.assertEqual(dt, None)
def test_compute_timestep_with_dt_adapt_with_invalid_values(self): # Given. self.pa.extend(1) self.pa.align_particles() self.pa.add_property('dt_adapt') self.pa.dt_adapt[:] = [0.0, -2.0] integrator = EulerIntegrator(fluid=EulerStep()) equations = [SHM(dest="fluid", sources=None)] self._setup_integrator(equations=equations, integrator=integrator) # When dt = integrator.compute_time_step(0.1, 0.5) # Then self.assertEqual(dt, None)
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
def test_compute_timestep_with_dt_cfl(self): # Given. self.pa.extend(1) self.pa.align_particles() self.pa.add_property('dt_cfl') self.pa.h[:] = 1.0 self.pa.dt_cfl[:] = [1.0, 2.0] integrator = EulerIntegrator(fluid=EulerStep()) equations = [SHM(dest="fluid", sources=None)] self._setup_integrator(equations=equations, integrator=integrator) # When cfl = 0.5 dt = integrator.compute_time_step(0.1, cfl) # Then expect = cfl * 1.0 / (2.0) self.assertEqual(dt, expect)
def create_solver(self): kernel = CubicSpline(dim=2) integrator = EulerIntegrator(fluid=EulerStep()) dt = 1e-4 tf = 1e-4 solver = Solver(kernel=kernel, dim=2, integrator=integrator, dt=dt, tf=tf) return solver
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
def create_solver(self): kernel = CubicSpline(dim=2) integrator = EulerIntegrator(sand=EulerDEMStep()) dt = 5e-5 print("DT: %s" % dt) tf = 2 solver = Solver(kernel=kernel, dim=2, integrator=integrator, dt=dt, tf=tf, adaptive_timestep=False) return solver
def create_solver(self): ''' Define solver ''' kernel = QuinticSpline(dim=2) integrator = EulerIntegrator(fluid=EulerStep()) solver = Solver(kernel=kernel, dim=2, integrator=integrator, dt=self.dt, tf=self.tf, pfreq=100) return solver
def test_helper_can_be_used_with_stepper_on_gpu(self): # Given. integrator = EulerIntegrator(fluid=StepWithHelper()) equations = [SHM(dest="fluid", sources=None)] self._setup_integrator(equations=equations, integrator=integrator) # When tf = 1.0 dt = tf / 2 def callback(t): pass self._integrate(integrator, dt, tf, callback) # Then if self.pa.gpu is not None: self.pa.gpu.pull('u') u = self.pa.u self.assertEqual(u, -2.0 * self.pa.x)
def create_solver(self): ''' Define solver ''' kernel = WendlandQuintic(dim=2) if self.INT == 'eul': integrator = EulerIntegrator(fluid=EulerStep()) elif self.INT == 'rk4': integrator = RK4Integrator(fluid=RK4Step()) else: raise Exception('Invalid integrator argument') solver = Solver(kernel=kernel, dim=2, integrator=integrator, dt=self.dt, tf=self.tf, pfreq=self.pfreq) return solver
def initialize(self): pass 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]
app = CircularDamBreak() one_time_equations = [ Group( equations=[ CorrectionFactorVariableSmoothingLength(dest='fluid', sources=['fluid',]), InitialTimeSummationDensity(dest='fluid', sources=['fluid',]), SWEOS(dest='fluid'), ], update_nnps=False ) ] from pysph.sph.acceleration_eval import AccelerationEval from pysph.sph.sph_compiler import SPHCompiler kernel = CubicSpline(dim=2) integrator = EulerIntegrator(fluid=EulerStep()) dt = 1e-4; tf = 2 solver = Solver( kernel=kernel, dim=2, integrator=integrator, dt=dt, tf=tf ) part_arr = app.create_particles eqns = app.create_equations() app.setup(solver=solver, equations=eqns, particle_factory=part_arr) a_eval = AccelerationEval( solver.particles, equations=one_time_equations, kernel=CubicSpline(dim=2)) compiler = SPHCompiler(a_eval, None)
fluid, boundary = geom.create_particles(**kw) boundary.x -= 0.1 boundary.y -= 0.1 return [fluid, boundary] # Create the application. app = Application() # Create the kernel kernel = CubicSpline(dim=2) # Create the Integrator. Currently, PySPH supports multi-stage, # predictor corrector and a TVD-RK3 integrators. integrator = EulerIntegrator(fluid=IISPHStep()) # Create a solver. solver = Solver(kernel=kernel, dim=dim, integrator=integrator, dt=dt, tf=tf, adaptive_timestep=True, fixed_h=False) solver.set_print_freq(10) # create the equations equations = [ ##################################################################### # "Predict advection" step as per algorithm 1 in paper. Group(equations=[ NumberDensity(dest='boundary', sources=['boundary']), ]
def __init__(self, all_particles, scheme, domain=None, innerloop=True, updates=True, parallel=False, steps=None, D=0): """The second integrator is a simple Euler-Integrator (accurate enough due to very small time steps; very fast) using EBGSteps. EBGSteps are basically the same as EulerSteps, exept for the fact that they work with an intermediate ebg velocity [eu, ev, ew]. This velocity does not interfere with the actual velocity, which is neseccery to not disturb the real velocity through artificial damping in this step. The ebg velocity is initialized for each inner loop again and reset in the outer loop.""" from math import ceil from pysph.base.kernels import CubicSpline from pysph.sph.integrator_step import EBGStep from compyle.config import get_config from pysph.sph.integrator import EulerIntegrator from pysph.sph.scheme import BeadChainScheme from pysph.sph.equation import Group from pysph.sph.fiber.utils import (HoldPoints, Contact, ComputeDistance) from pysph.sph.fiber.beadchain import (Tension, Bending, ArtificialDamping) from pysph.base.nnps import DomainManager, LinkedListNNPS from pysph.sph.acceleration_eval import AccelerationEval from pysph.sph.sph_compiler import SPHCompiler if not isinstance(scheme, BeadChainScheme): raise TypeError("Scheme must be BeadChainScheme") self.innerloop = innerloop self.dt = scheme.dt self.fiber_dt = scheme.fiber_dt self.domain_updates = updates self.steps = steps self.D = D self.eta0 = scheme.rho0 * scheme.nu # if there are more than 1 particles involved, elastic equations are # iterated in an inner loop. if self.innerloop: # second integrator # self.fiber_integrator = EulerIntegrator(fiber=EBGStep()) steppers = {} for f in scheme.fibers: steppers[f] = EBGStep() self.fiber_integrator = EulerIntegrator(**steppers) # The type of spline has no influence here. It must be large enough # to contain the next particle though. kernel = CubicSpline(dim=scheme.dim) equations = [] g1 = [] for fiber in scheme.fibers: g1.append(ComputeDistance(dest=fiber, sources=[fiber])) equations.append(Group(equations=g1)) g2 = [] for fiber in scheme.fibers: g2.append( Tension(dest=fiber, sources=None, ea=scheme.E * scheme.A)) g2.append( Bending(dest=fiber, sources=None, ei=scheme.E * scheme.Ip)) g2.append( Contact(dest=fiber, sources=scheme.fibers, E=scheme.E, d=scheme.dx, dim=scheme.dim, k=scheme.k, lim=scheme.lim, eta0=self.eta0)) g2.append(ArtificialDamping(dest=fiber, sources=None, d=self.D)) equations.append(Group(equations=g2)) g3 = [] for fiber in scheme.fibers: g3.append(HoldPoints(dest=fiber, sources=None, tag=100)) equations.append(Group(equations=g3)) # These equations are applied to fiber particles only - that's the # reason for computational speed up. particles = [p for p in all_particles if p.name in scheme.fibers] # A seperate DomainManager is needed to ensure that particles don't # leave the domain. if domain: xmin = domain.manager.xmin ymin = domain.manager.ymin zmin = domain.manager.zmin xmax = domain.manager.xmax ymax = domain.manager.ymax zmax = domain.manager.zmax periodic_in_x = domain.manager.periodic_in_x periodic_in_y = domain.manager.periodic_in_y periodic_in_z = domain.manager.periodic_in_z gamma_yx = domain.manager.gamma_yx gamma_zx = domain.manager.gamma_zx gamma_zy = domain.manager.gamma_zy n_layers = domain.manager.n_layers N = self.steps or int(ceil(self.dt / self.fiber_dt)) # dt = self.dt/N self.domain = DomainManager(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, periodic_in_x=periodic_in_x, periodic_in_y=periodic_in_y, periodic_in_z=periodic_in_z, gamma_yx=gamma_yx, gamma_zx=gamma_zx, gamma_zy=gamma_zy, n_layers=n_layers, dt=self.dt, calls_per_step=N) else: self.domain = None # A seperate list for the nearest neighbourhood search is # benefitial since it is much smaller than the original one. nnps = LinkedListNNPS(dim=scheme.dim, particles=particles, radius_scale=kernel.radius_scale, domain=self.domain, fixed_h=False, cache=False, sort_gids=False) # The acceleration evaluator needs to be set up in order to compile # it together with the integrator. if parallel: self.acceleration_eval = AccelerationEval( particle_arrays=particles, equations=equations, kernel=kernel) else: self.acceleration_eval = AccelerationEval( particle_arrays=particles, equations=equations, kernel=kernel, mode='serial') # Compilation of the integrator not using openmp, because the # overhead is too large for those few fiber particles. comp = SPHCompiler(self.acceleration_eval, self.fiber_integrator) if parallel: comp.compile() else: config = get_config() config.use_openmp = False comp.compile() config.use_openmp = True self.acceleration_eval.set_nnps(nnps) # Connecting neighbourhood list to integrator. self.fiber_integrator.set_nnps(nnps)
dim = 2 dt = 1e-2 tf = 1.0 # Create the application. app = Application() # Create the kernel #kernel = Gaussian(dim=dim) kernel = CubicSpline(dim=dim) # Create the Integrator. Currently, PySPH supports multi-stage, # predictor corrector and a TVD-RK3 integrators. integrator = EulerIntegrator(fluid1=IISPHStep(), fluid2=IISPHStep()) # Create a solver. solver = Solver(kernel=kernel, dim=dim, integrator=integrator, dt=dt, tf=tf, adaptive_timestep=True, fixed_h=False) solver.set_print_freq(10) # create the equations # create the equations equations = [ Group(equations=[