/usr/lib/python2.7/dist-packages/PySPH-1.0a4.dev0-py2.7-linux-x86_64.egg/pysph/parallel/tests/simple_reduction.py is in python-pysph 0~20160514.git91867dc-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | import numpy as np
from pysph.base.kernels import CubicSpline
from pysph.base.particle_array import ParticleArray
from pysph.sph.equation import Equation
from pysph.sph.integrator_step import IntegratorStep
from pysph.sph.integrator import EulerIntegrator
from pysph.solver.application import Application
from pysph.solver.solver import Solver
def create_particles():
x = np.linspace(0, 10, 10)
m = np.ones_like(x)
y = np.zeros_like(x)
z = np.zeros_like(x)
h = np.ones_like(x)*0.2
fluid = ParticleArray(name='fluid', x=x, y=y, z=z, m=m, h=h)
fluid.add_constant('total_mass', 0.0)
return [fluid]
class TotalMass(Equation):
def reduce(self, dst):
# Use the dst.array as we want to pass the real particles to do the sum
# passing the carray will send all the particles including ghosts
# which is incorrect.
m = serial_reduce_array(dst.array.m, op='sum')
dst.total_mass[0] = parallel_reduce_array(m, op='sum')
class DummyStepper(IntegratorStep):
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]
err = fluid.total_mass[0] - 10.0
assert abs(err) < 1e-16, "Error: %s"%err
|