Skip to content

Commit

Permalink
Adding SPHFunction read requirements as a class defined function.
Browse files Browse the repository at this point in the history
Each function defines it's read and write requirements separately.
  • Loading branch information
kunal-puri committed Apr 29, 2011
1 parent e96d0ef commit b47a162
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 53 deletions.
26 changes: 22 additions & 4 deletions source/pysph/sph/funcs/adke_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ cdef class ADKESmoothingUpdate(ADKEPilotRho):
self.cl_kernel_src_file = "adke_funcs.cl"
self.cl_kernel_function_name = "ADKESmoothingUpdate"

def set_src_dst_reads(self):

self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','m','rho'] )
self.dst_reads.extend( ['x','y','z','tag'] )

cpdef eval(self, KernelBase kernel, DoubleArray output1,
DoubleArray output2, DoubleArray output3):
""" Evaluate the store the results in the output arrays """
Expand Down Expand Up @@ -147,12 +155,16 @@ cdef class SPHVelocityDivergence(SPHFunctionParticle):
self.id = "vdivergence"
self.tag = "vdivergence"

self.src_reads.extend( ['u','v','w'] )
self.dst_reads.extend( ['u','v','w'] )

self.cl_kernel_src_file = "adke_funcs.cl"
self.cl_kernel_function_name = "SPHVelocityDivergence"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','h','u','v','w','m'] )
self.dst_reads.extend( ['x','y','z','h','u','v','w','rho','tag'] )

cdef void eval_nbr(self, size_t source_pid, size_t dest_pid,
KernelBase kernel, double *nr):
""" Compute the contribution from source_pid on dest_pid.
Expand All @@ -166,7 +178,6 @@ cdef class SPHVelocityDivergence(SPHFunctionParticle):
"""

cdef double ha = self.d_h.data[dest_pid]
cdef double hb = self.s_h.data[source_pid]

Expand Down Expand Up @@ -232,6 +243,13 @@ cdef class ADKEConductionCoeffUpdate(SPHVelocityDivergence):

self.cl_kernel_function_name = "ADKEConductionCoeffUpdate"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','h','u','v','w','m'] )
self.dst_reads.extend( ['x','y','z','h','u','v','w','rho','cs','tag'] )

cpdef eval(self, KernelBase kernel, DoubleArray output1,
DoubleArray output2, DoubleArray output3):
""" Evaluate the store the results in the output arrays Note
Expand Down
40 changes: 31 additions & 9 deletions source/pysph/sph/funcs/basic_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ cdef class SPH(CSPHFunctionParticle):
self.cl_kernel_src_file = "basic_funcs.clt"
self.cl_kernel_function_name = "SPH"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','h','m','rho',self.prop_name] )
self.dst_reads.extend( ['x','y','z','h','tag'] )

cpdef setup_arrays(self):
""" Setup the arrays required to read data from source and dest. """

Expand Down Expand Up @@ -129,6 +136,13 @@ cdef class SPHSimpleGradient(SPHFunctionParticle):
self.cl_kernel_src_file = "basic_funcs.cl"
self.cl_kernel_function_name = "SPHSimpleGradient"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','h','m','rho',self.prop_name] )
self.dst_reads.extend( ['x','y','z','h','tag'] )

cpdef setup_arrays(self):
""" Setup the arrays required to read data from source and dest. """

Expand All @@ -138,9 +152,6 @@ cdef class SPHSimpleGradient(SPHFunctionParticle):
self.d_prop = self.dest.get_carray(self.prop_name)
self.s_prop = self.source.get_carray(self.prop_name)

self.src_reads.append(self.prop_name)
self.dst_reads.append(self.prop_name)

cdef void eval_nbr(self, size_t source_pid, size_t dest_pid,
KernelBase kernel, double *nr):
"""
Expand Down Expand Up @@ -227,6 +238,13 @@ cdef class SPHGradient(SPHFunctionParticle):
self.cl_kernel_src_file = "basic_funcs.cl"
self.cl_kernel_function_name = "SPHGradient"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','h','m','rho',self.prop_name] )
self.dst_reads.extend( ['x','y','z','h','tag'] )

cpdef setup_arrays(self):
""" Setup the arrays required to read data from source and dest. """

Expand All @@ -236,9 +254,6 @@ cdef class SPHGradient(SPHFunctionParticle):
self.d_prop = self.dest.get_carray(self.prop_name)
self.s_prop = self.source.get_carray(self.prop_name)

self.src_reads.append(self.prop_name)
self.dst_reads.append(self.prop_name)

cdef void eval_nbr(self, size_t source_pid, size_t dest_pid,
KernelBase kernel, double *nr):
""" Perform an SPH interpolation of the property `prop_name`
Expand Down Expand Up @@ -323,6 +338,13 @@ cdef class SPHLaplacian(SPHFunctionParticle):
self.cl_kernel_src_file = "basic_funcs.cl"
self.cl_kernel_function_name = "SPHLaplacian"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','h','m','rho',self.prop_name] )
self.dst_reads.extend( ['x','y','z','h','tag',self.prop_name] )

cpdef setup_arrays(self):
""" Setup the arrays required to read data from source and dest. """

Expand All @@ -331,9 +353,6 @@ cdef class SPHLaplacian(SPHFunctionParticle):
self.s_prop = self.source.get_carray(self.prop_name)
self.d_prop = self.dest.get_carray(self.prop_name)

self.src_reads.append(self.prop_name)
self.dst_reads.append(self.prop_name)

cdef void eval_nbr(self, size_t source_pid, size_t dest_pid,
KernelBase kernel, double *nr):
"""
Expand Down Expand Up @@ -411,6 +430,9 @@ cdef class CountNeighbors(SPHFunctionParticle):
SPHFunctionParticle.__init__(self, source, dest, setup_arrays = True)
self.id = 'nbrs'

def set_src_dst_reads(self):
pass

cdef void eval_single(self, size_t dest_pid,
KernelBase kernel, double *result):
result[0] += self.nbr_locator.get_nearest_particles(dest_pid).length
Expand Down
21 changes: 19 additions & 2 deletions source/pysph/sph/funcs/boundary_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,17 @@ cdef class MonaghanBoundaryForce(SPHFunctionParticle):
self.s_ny = self.source.get_carray("ny")
self.s_nz = self.source.get_carray("nz")



def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','h','m','rho'] )
self.src_reads.extend( ['tx','ty','tz','nx','ny','nz','cs'] )

self.dst_reads.extend( ['x','y','z','h','m','cs','tag'] )

cdef void eval_nbr(self, size_t source_pid, size_t dest_pid,
KernelBase kernel, double *nr):
""" Perform the boundary force computation """
Expand All @@ -61,10 +70,12 @@ cdef class MonaghanBoundaryForce(SPHFunctionParticle):
self._dst.y = self.d_y.data[dest_pid]
self._dst.z = self.d_z.data[dest_pid]

cdef cPoint norm = cPoint(self.s_nx.data[source_pid], self.s_ny.data[source_pid],
cdef cPoint norm = cPoint(self.s_nx.data[source_pid],
self.s_ny.data[source_pid],
self.s_nz.data[source_pid])

cdef cPoint tang = cPoint(self.s_tx.data[source_pid], self.s_ty.data[source_pid],
cdef cPoint tang = cPoint(self.s_tx.data[source_pid],
self.s_ty.data[source_pid],
self.s_tz.data[source_pid])

cs = self.d_cs.data[dest_pid]
Expand Down Expand Up @@ -125,6 +136,9 @@ cdef class BeckerBoundaryForce(SPHFunctionParticle):
self.cl_kernel_src_file = "boundary_funcs.cl"
self.cl_kernel_function_name = "BeckerBoundaryForce"

def set_src_dst_reads(self):
pass

cdef void eval_nbr(self, size_t source_pid, size_t dest_pid,
KernelBase kernel, double *nr):
"""
Expand Down Expand Up @@ -213,6 +227,9 @@ cdef class LennardJonesForce(SPHFunctionParticle):
self.cl_kernel_src_file = "boundary_funcs.cl"
self.cl_kernel_function_name = "LennardJonesForce"

def set_src_dst_reads(self):
pass

cdef void eval_nbr(self, size_t source_pid, size_t dest_pid,
KernelBase kernel, double *nr):
"""
Expand Down
20 changes: 17 additions & 3 deletions source/pysph/sph/funcs/density_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ cdef class SPHRho(CSPHFunctionParticle):
self.cl_kernel_src_file = "density_funcs.clt"
self.cl_kernel_function_name = "SPHRho"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','h','m'] )
self.dst_reads.extend( ['x','y','z','h','tag'] )

cdef void eval_nbr_csph(self, size_t source_pid, size_t dest_pid,
KernelBase kernel, double *nr, double *dnr):
""" Compute the contribution from source_pid on dest_pid. """
Expand Down Expand Up @@ -89,12 +96,19 @@ cdef class SPHDensityRate(SPHFunctionParticle):
self.id = 'densityrate'
self.tag = "density"

self.src_reads.extend( ['u','v','w'] )
self.dst_reads.extend( ['u','v','w'] )

self.cl_kernel_src_file = "density_funcs.cl"
self.cl_kernel_function_name = "SPHDensityRate"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','h','m'] )
self.dst_reads.extend( ['x','y','z','h','tag'] )

self.src_reads.extend( ['u','v','w'] )
self.dst_reads.extend( ['u','v','w'] )

cdef void eval_nbr(self, size_t source_pid, size_t dest_pid,
KernelBase kernel, double *nr):
""" Compute the contribution of particle at source_pid on particle at
Expand Down
42 changes: 31 additions & 11 deletions source/pysph/sph/funcs/energy_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ cdef class EnergyEquationNoVisc(SPHFunctionParticle):
self.id = 'energyeqn'
self.tag = "energy"

self.src_reads.extend( ['u','v','w','p'] )
self.dst_reads.extend( ['u','v','w','p'] )

self.cl_kernel_src_file = "energy_funcs.cl"
self.cl_kernel_function_name = "EnergyEquationNoVisc"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','h','m','rho'] )
self.dst_reads.extend( ['x','y','z','h','rho','tag'] )

self.src_reads.extend( ['u','v','w','p'] )
self.dst_reads.extend( ['u','v','w','p'] )

cdef void eval_nbr(self, size_t source_pid, size_t dest_pid,
KernelBase kernel, double *nr):
Expand Down Expand Up @@ -107,11 +114,18 @@ cdef class EnergyEquationAVisc(SPHFunctionParticle):
self.id = 'energyavisc'
self.tag = "energy"

self.src_reads.extend( ['u','v','w','p','cs'] )
self.dst_reads.extend( ['u','v','w','p','cs'] )

self.cl_kernel_src_file = "energy_funcs.cl"
self.cl_kernel_function_name = "EnergyEquationAVisc"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','h','m','rho'] )
self.dst_reads.extend( ['x','y','z','h','rho','tag'] )

self.src_reads.extend( ['u','v','w','p','cs'] )
self.dst_reads.extend( ['u','v','w','p','cs'] )

cdef void eval_nbr(self, size_t source_pid, size_t dest_pid,
KernelBase kernel, double *nr):
Expand Down Expand Up @@ -222,15 +236,21 @@ cdef class EnergyEquation(SPHFunctionParticle):
self.id = 'energyequation'
self.tag = "energy"

self.src_reads.extend( ['u','v','w','p','cs'] )
self.dst_reads.extend( ['u','v','w','p','cs'] )

self.cl_kernel_src_file = "energy_funcs.cl"
self.cl_kernel_function_name = "EnergyEquation"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.src_reads.extend( ['x','y','z','h','m','rho'] )
self.dst_reads.extend( ['x','y','z','h','rho','tag'] )

self.src_reads.extend( ['u','v','w','p','cs'] )
self.dst_reads.extend( ['u','v','w','p','cs'] )

cdef void eval_nbr(self, size_t source_pid, size_t dest_pid,
KernelBase kernel, double *nr):

KernelBase kernel, double *nr):

cdef cPoint vab, rab
cdef double Pa, Pb, rhoa, rhob, rhoab, mb
Expand Down
17 changes: 12 additions & 5 deletions source/pysph/sph/funcs/eos_funcs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ cdef class IdealGasEquation(SPHFunction):
self.id = 'idealgas'
self.tag = "state"

self.dst_reads.extend( ['e','rho', 'p'] )

self.cl_kernel_src_file = "eos_funcs.cl"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.dst_reads.extend( ['e','rho'] )

cdef void eval_single(self, size_t dest_pid, KernelBase kernel,
double* result):

cdef double Pa = self.d_p.data[dest_pid]
cdef double ea = self.d_e.data[dest_pid]
cdef double rhoa = self.d_rho.data[dest_pid]
cdef double gamma = self.gamma
Expand Down Expand Up @@ -75,10 +78,14 @@ cdef class TaitEquation(SPHFunction):
self.id = 'tait'
self.tag = "state"

self.dst_reads.append('rho')

self.cl_kernel_src_file = "eos_funcs.cl"

def set_src_dst_reads(self):
self.src_reads = []
self.dst_reads = []

self.dst_reads.extend( ['rho'] )

cdef void eval_single(self, size_t dest_pid, KernelBase kernel,
double* result):

Expand Down
4 changes: 2 additions & 2 deletions source/pysph/sph/funcs/external_force.clt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ __kernel void NBodyForce(%(kernel_args)s)

// The term `dest_id` will be suitably defined at this point.

REAL4 pa = (REAL4)( d_x[dest_id],d_y[dest_id], d_z[dest_id], d_h[dest_id] );
REAL4 pa = (REAL4)( d_x[dest_id],d_y[dest_id], d_z[dest_id], 0.0F );
REAL4 rba;
REAL invr, force_mag;

Expand All @@ -37,7 +37,7 @@ __kernel void NBodyForce(%(kernel_args)s)
// SPH innermost loop code goes here. The index `src_id` will
// be available and looped over, this index.

REAL4 pb = (REAL4)( s_x[src_id],s_y[src_id],s_z[src_id],s_h[src_id] );
REAL4 pb = (REAL4)( s_x[src_id],s_y[src_id],s_z[src_id], 0.0F );
rba = pb - pa;

invr = 1.0F/( length(rba) + eps );
Expand Down
Loading

0 comments on commit b47a162

Please sign in to comment.