def configure_scheme(self): tf = 2.5 kw = dict(tf=tf, output_at_times=[0.4, 0.6, 0.8, 1.0]) if self.options.scheme == 'wcsph': self.scheme.configure(h0=self.h, hdx=self.hdx) kernel = WendlandQuintic(dim=2) from pysph.sph.integrator import EPECIntegrator kw.update( dict(integrator_cls=EPECIntegrator, kernel=kernel, adaptive_timestep=True, n_damp=50, fixed_h=False)) elif self.options.scheme == 'aha': self.scheme.configure(h0=self.h) kernel = QuinticSpline(dim=2) dt = 0.125 * self.h / co kw.update(dict(kernel=kernel, dt=dt)) print("dt = %f" % dt) elif self.options.scheme == 'edac': self.scheme.configure(h=self.h) kernel = QuinticSpline(dim=2) dt = 0.125 * self.h / co kw.update(dict(kernel=kernel, dt=dt)) print("dt = %f" % dt) self.scheme.configure_solver(**kw)
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 create_solver(self): kernel = QuinticSpline(dim=2) integrator = PECIntegrator(fluid=TransportVelocityStep()) solver = Solver( kernel=kernel, dim=dim, integrator=integrator, dt=dt, tf=tf, adaptive_timestep=False) return solver
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
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)
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 = QuinticSpline(dim=2) integrator = PECIntegrator(fluid=VerletSymplecticWCSPHStep()) solver = Solver(kernel=kernel, dim=dim, integrator=integrator, dt=dt, tf=tf, adaptive_timestep=False) return solver
def configure_scheme(self): scheme = self.scheme h0 = self.hdx * self.dx if self.options.scheme == 'tvf': scheme.configure(pb=self.options.pb_factor*p0, nu=self.nu, h0=h0) elif self.options.scheme == 'wcsph': scheme.configure(hdx=self.hdx, nu=self.nu, h0=h0) elif self.options.scheme == 'edac': scheme.configure(h=h0, nu=self.nu, pb=self.options.pb_factor*p0) kernel = QuinticSpline(dim=2) scheme.configure_solver(kernel=kernel, tf=self.tf, dt=self.dt)
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
def _get_sph_evaluator(self, array): if not hasattr(self, '_sph_eval'): from pysph.tools.sph_evaluator import SPHEvaluator equations = [ ComputeAveragePressure(dest='fluid', sources=['fluid']) ] dm = self.create_domain() sph_eval = SPHEvaluator( arrays=[array], equations=equations, dim=2, kernel=QuinticSpline(dim=2), domain_manager=dm ) self._sph_eval = sph_eval return self._sph_eval
def test_invalid_kwarg_raises_error(self): # Given x = np.linspace(0, 1, 10) pa = get_particle_array(name='fluid', x=x) equations = [SummationDensity(dest='fluid', sources=['fluid'])] kernel = QuinticSpline(dim=1) a_eval = AccelerationEval([pa], equations, kernel=kernel) a_helper = AccelerationEvalCythonHelper(a_eval) # When/Then integrator = PECIntegrator(f=WCSPHStep()) self.assertRaises(RuntimeError, IntegratorCythonHelper, integrator, a_helper)
def create_solver(self): kernel = QuinticSpline(dim=2) integrator = Integrator(fluid=TransportVelocityStep(), obstacle=TwoStageRigidBodyStep()) solver = Solver(kernel=kernel, dim=2, integrator=integrator, tf=tf, dt=dt, adaptive_timestep=False, output_at_times=[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]) return solver
def configure_scheme(self): scheme = self.scheme self.iom = self._create_inlet_outlet_manager() scheme.inlet_outlet_manager = self.iom pfreq = 100 kernel = QuinticSpline(dim=2) self.iom.update_dx(self.dx) scheme.configure(h=self.h, nu=self.nu) scheme.configure_solver(kernel=kernel, tf=self.tf, dt=self.dt, pfreq=pfreq, n_damp=0)
def configure_scheme(self): scheme = self.scheme h0 = self.hdx * self.dx pfreq = 50 kernel = QuinticSpline(dim=2) self.iom.update_dx(self.dx) if self.options.scheme == 'edac': scheme.configure(h=h0, nu=self.nu, pb=p0) scheme.configure_solver(kernel=kernel, tf=self.tf, dt=self.dt, pfreq=pfreq, n_damp=0)
def _get_force_evaluator(self): from pysph.solver.utils import load from pysph.base.kernels import QuinticSpline from pysph.tools.sph_evaluator import SPHEvaluator from pysph.sph.equation import Group from pysph.sph.wc.transport_velocity import ( SetWallVelocity, MomentumEquationPressureGradient, SolidWallNoSlipBC, VolumeSummation, MomentumEquationViscosity) data = load(self.output_files[0]) solid = data['arrays']['solid'] fluid = data['arrays']['fluid'] prop = [ 'awhat', 'auhat', 'avhat', 'wg', 'vg', 'ug', 'V', 'uf', 'vf', 'wf', 'wij', 'vmag' ] for p in prop: solid.add_property(p) fluid.add_property(p) equations = [ Group(equations=[ SetWallVelocity(dest='fluid', sources=['solid']), VolumeSummation(dest='fluid', sources=['fluid', 'solid']), VolumeSummation(dest='solid', sources=['fluid', 'solid']), ], real=False), Group( equations=[ # Pressure gradient terms MomentumEquationPressureGradient( dest='solid', sources=['fluid', 'solid'], pb=p0), MomentumEquationViscosity(dest='solid', sources=['fluid', 'solid'], nu=self.nu), SolidWallNoSlipBC(dest='solid', sources=['fluid'], nu=self.nu), ], real=True), ] sph_eval = SPHEvaluator(arrays=[solid, fluid], equations=equations, dim=2, kernel=QuinticSpline(dim=2)) return sph_eval
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 configure_solver(self, kernel=None, integrator_cls=None, extra_steppers=None, **kw): """Configure the solver to be generated. Parameters ---------- 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 if kernel is None: kernel = QuinticSpline(dim=self.dim) steppers = {} if extra_steppers is not None: steppers.update(extra_steppers) step_cls = CRKSPHStep for fluid in self.fluids: if fluid not in steppers: steppers[fluid] = step_cls() if integrator_cls is not None: cls = integrator_cls print("warning: CRKSPHIntegrator is not being used") else: cls = CRKSPHIntegrator 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 setUp(self): dx = 0.1 x = np.arange(-5*dx, 0.0, dx) m = np.ones_like(x) h = np.ones_like(x)*dx*1.5 p = np.ones_like(x)*5.0 self.inlet_pa = get_particle_array(name='inlet', x=x, m=m, h=h, p=p) # Empty particle array. self.dest_pa = get_particle_array(name='fluid') props = ['ioid', 'disp'] for p in props: for pa_arr in [self.dest_pa, self.inlet_pa]: pa_arr.add_property(p) self.dx = dx self.kernel = QuinticSpline(dim=1) self.inletinfo = InletInfo('inlet', normal=[-1., 0., 0.], refpoint=[-dx/2, 0., 0.]) self.inletinfo.length = 0.5
def configure_solver(self, kernel=None, integrator_cls=None, extra_steppers=None, **kw): """Configure the solver to be generated. Parameters ---------- 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_step import TransportVelocityStep 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 = TransportVelocityStep for fluid in self.fluids: if fluid not in steppers: steppers[fluid] = step_cls() cls = integrator_cls if integrator_cls is not None else PECIntegrator integrator = cls(**steppers) from pysph.solver.solver import Solver self.solver = Solver(dim=self.dim, integrator=integrator, kernel=kernel, **kw)
def configure_scheme(self): scheme = self.scheme h0 = self.hdx * self.dx pfreq = 100 kernel = QuinticSpline(dim=2) if self.options.scheme == 'tvf': scheme.configure(pb=self.options.pb_factor * p0, nu=self.nu, h0=h0) elif self.options.scheme == 'wcsph': scheme.configure(hdx=self.hdx, nu=self.nu, h0=h0) elif self.options.scheme == 'edac': scheme.configure(h=h0, nu=self.nu, pb=self.options.pb_factor * p0) elif self.options.scheme == 'iisph' or self.options.scheme == 'pcisph': scheme.configure(nu=self.nu) pfreq = 10 elif self.options.scheme == 'crksph': scheme.configure(h0=h0, nu=self.nu) elif self.options.scheme == 'gtvf': scheme.configure(pref=10*p0, p0=p0, nu=self.nu, h0=h0) scheme.configure_solver(kernel=kernel, tf=self.tf, dt=self.dt, pfreq=pfreq)
def _plot_cd_vs_t(self): from pysph.solver.utils import iter_output, load from pysph.tools.sph_evaluator import SPHEvaluator from pysph.sph.equation import Group from pysph.base.kernels import QuinticSpline from pysph.sph.wc.transport_velocity import ( SetWallVelocity, MomentumEquationPressureGradient, SolidWallNoSlipBC, SolidWallPressureBC, VolumeSummation) data = load(self.output_files[0]) solid = data['arrays']['solid'] fluid = data['arrays']['fluid'] x, y = solid.x.copy(), solid.y.copy() cx = 0.5 * L cy = 0.5 * H inside = np.sqrt((x - cx)**2 + (y - cy)**2) <= a dest = solid.extract_particles(inside.nonzero()[0]) # We use the same equations for this as the simulation, except that we # do not include the acceleration terms as these are externally # imposed. The goal of these is to find the force of the fluid on the # cylinder, thus, gx=0.0 is used in the following. equations = [ Group(equations=[ VolumeSummation(dest='fluid', sources=['fluid', 'solid']), VolumeSummation(dest='solid', sources=['fluid', 'solid']), ], real=False), Group(equations=[ SetWallVelocity(dest='solid', sources=['fluid']), ], real=False), Group(equations=[ SolidWallPressureBC(dest='solid', sources=['fluid'], gx=0.0, b=1.0, rho0=rho0, p0=p0), ], real=False), Group( equations=[ # Pressure gradient terms MomentumEquationPressureGradient(dest='fluid', sources=['solid'], gx=0.0, pb=pb), SolidWallNoSlipBC(dest='fluid', sources=['solid'], nu=nu), ], real=True), ] sph_eval = SPHEvaluator(arrays=[dest, fluid], equations=equations, dim=2, kernel=QuinticSpline(dim=2)) t, cd = [], [] for sd, fluid in iter_output(self.output_files, 'fluid'): fluid.remove_property('vmag2') t.append(sd['t']) sph_eval.update_particle_arrays([dest, fluid]) sph_eval.evaluate() Fx = np.sum(-fluid.au * fluid.m) cd.append(Fx / (nu * rho0 * Umax)) t, cd = list(map(np.asarray, (t, cd))) # Now plot the results. import matplotlib matplotlib.use('Agg') from matplotlib import pyplot as plt plt.figure() plt.plot(t, cd) plt.xlabel('$t$') plt.ylabel(r'$C_D$') fig = os.path.join(self.output_dir, "cd_vs_t.png") plt.savefig(fig, dpi=300) plt.close() return t, cd
class TestQuinticSpline3D(TestGaussian3D): kernel_factory = staticmethod(lambda: QuinticSpline(dim=3)) def test_simple(self): self.check_kernel_at_origin(66.0 * 3.0 / (359.0 * np.pi))
class TestQuinticSpline2D(TestCubicSpline2D): kernel_factory = staticmethod(lambda: QuinticSpline(dim=2)) def test_simple(self): self.check_kernel_at_origin(66.0 * 7.0 / (478.0 * np.pi))
class TestQuinticSpline1D(TestCubicSpline1D): kernel_factory = staticmethod(lambda: QuinticSpline(dim=1)) def test_simple(self): self.check_kernel_at_origin(0.55)
def configure_scheme(self): tf = 2.5 kw = dict( tf=tf, output_at_times=[0.4, 0.6, 0.8, 1.0] ) if self.options.scheme == 'wcsph': dt = 0.125 * self.h / co self.scheme.configure(h0=self.h, hdx=self.hdx) kernel = WendlandQuintic(dim=2) from pysph.sph.integrator import PECIntegrator kw.update( dict( integrator_cls=PECIntegrator, kernel=kernel, adaptive_timestep=True, n_damp=50, fixed_h=False, dt=dt ) ) elif self.options.scheme == 'aha': self.scheme.configure(h0=self.h) kernel = QuinticSpline(dim=2) dt = 0.125 * self.h / co kw.update( dict( kernel=kernel, dt=dt ) ) print("dt = %f" % dt) elif self.options.scheme == 'edac': self.scheme.configure(h=self.h) kernel = QuinticSpline(dim=2) dt = 0.125 * self.h / co kw.update( dict( kernel=kernel, dt=dt ) ) print("dt = %f" % dt) elif self.options.scheme == 'iisph': kernel = QuinticSpline(dim=2) dt = 0.125 * 10 * self.h / co kw.update( dict( kernel=kernel, dt=dt, adaptive_timestep=True ) ) print("dt = %f" % dt) elif self.options.scheme == 'gtvf': scheme = self.scheme kernel = QuinticSpline(dim=2) dt = 0.125 * self.h / co kw.update(dict(kernel=kernel, dt=dt)) scheme.configure(pref=B*gamma, h0=self.h) print("dt = %f" % dt) elif self.options.scheme == 'sisph': dt = 0.125*self.h/vref kernel = QuinticSpline(dim=2) print("SISPH dt = %f" % dt) kw.update(dict(kernel=kernel)) self.scheme.configure_solver( dt=dt, tf=tf, adaptive_timestep=False, pfreq=10, ) self.scheme.configure_solver(**kw)
def _plot_force_vs_t(self): from pysph.solver.utils import iter_output, load from pysph.tools.sph_evaluator import SPHEvaluator from pysph.sph.equation import Group from pysph.base.kernels import QuinticSpline from pysph.sph.wc.transport_velocity import ( MomentumEquationPressureGradient, SummationDensity, SetWallVelocity) data = load(self.output_files[0]) solid = data['arrays']['solid'] fluid = data['arrays']['fluid'] prop = [ 'awhat', 'auhat', 'avhat', 'wg', 'vg', 'ug', 'V', 'uf', 'vf', 'wf', 'wij', 'vmag', 'pavg', 'nnbr', 'auf', 'avf', 'awf' ] for p in prop: solid.add_property(p) fluid.add_property(p) # We find the force of the solid on the fluid and the opposite of that # is the force on the solid. Note that the assumption is that the solid # is far from the inlet and outlet so those are ignored. print(self.nu, p0, self.dc, rho) equations = [ Group(equations=[ SummationDensity(dest='fluid', sources=['fluid', 'solid']), SummationDensity(dest='solid', sources=['fluid', 'solid']), SetWallVelocity(dest='solid', sources=['fluid']), ], real=False), Group( equations=[ # Pressure gradient terms MomentumEquationPressureGradient(dest='solid', sources=['fluid'], pb=p0), SolidWallNoSlipBCReverse(dest='solid', sources=['fluid'], nu=self.nu), ], real=True), ] sph_eval = SPHEvaluator(arrays=[solid, fluid], equations=equations, dim=2, kernel=QuinticSpline(dim=2)) t, cd, cl = [], [], [] import gc print(self.dc, self.dx, self.nu) print('fxf', 'fxp', 'fyf', 'fyp', 'cd', 'cl', 't') for sd, arrays in iter_output(self.output_files[:]): fluid = arrays['fluid'] solid = arrays['solid'] for p in prop: solid.add_property(p) fluid.add_property(p) t.append(sd['t']) sph_eval.update_particle_arrays([solid, fluid]) sph_eval.evaluate() fxp = sum(solid.m * solid.au) fyp = sum(solid.m * solid.av) fxf = sum(solid.m * solid.auf) fyf = sum(solid.m * solid.avf) fx = fxf + fxp fy = fyf + fyp cd.append(fx / (0.5 * rho * umax**2 * self.dc)) cl.append(fy / (0.5 * rho * umax**2 * self.dc)) print(fxf, fxp, fyf, fyp, cd[-1], cl[-1], t[-1]) gc.collect() t, cd, cl = list(map(np.asarray, (t, cd, cl))) # Now plot the results. import matplotlib matplotlib.use('Agg') from matplotlib import pyplot as plt plt.figure() plt.plot(t, cd, label=r'$C_d$') plt.plot(t, cl, label=r'$C_l$') plt.xlabel(r'$t$') plt.ylabel('cd/cl') plt.legend() plt.grid() fig = os.path.join(self.output_dir, "force_vs_t.png") plt.savefig(fig, dpi=300) plt.close() return t, cd, cl