[yt-svn] commit/yt: 16 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Aug 19 10:09:29 PDT 2015
16 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/6ffc343b3b1b/
Changeset: 6ffc343b3b1b
Branch: yt
User: qobilidop
Date: 2015-07-31 03:01:02+00:00
Summary: rename sph_kernel to sph_kernel_cubic
Affected #: 1 file
diff -r c8e5a56dfd3a968b318524fbd31f2550083d646b -r 6ffc343b3b1b61587a87bc843e1a4fa5b05cb8c4 yt/geometry/particle_deposit.pxd
--- a/yt/geometry/particle_deposit.pxd
+++ b/yt/geometry/particle_deposit.pxd
@@ -38,7 +38,7 @@
# Standard SPH kernel for use with the Grid method #
####################################################
-cdef inline np.float64_t sph_kernel(np.float64_t x) nogil:
+cdef inline np.float64_t sph_kernel_cubic(np.float64_t x) nogil:
cdef np.float64_t kernel
if x <= 0.5:
kernel = 1.-6.*x*x*(1.-x)
https://bitbucket.org/yt_analysis/yt/commits/fbcd9699a3fc/
Changeset: fbcd9699a3fc
Branch: yt
User: qobilidop
Date: 2015-07-31 20:22:53+00:00
Summary: update sph_kernel related codes
Affected #: 3 files
diff -r 6ffc343b3b1b61587a87bc843e1a4fa5b05cb8c4 -r fbcd9699a3fc37907b7deab8e48c20fc753a0d94 yt/geometry/particle_deposit.pyx
--- a/yt/geometry/particle_deposit.pyx
+++ b/yt/geometry/particle_deposit.pyx
@@ -25,9 +25,11 @@
OctreeContainer, OctInfo
cdef class ParticleDepositOperation:
- def __init__(self, nvals):
+ def __init__(self, nvals, kernel='cubic'):
self.nvals = nvals
self.update_values = 0 # This is the default
+ if kernel == 'cubic':
+ self.sph_kernel = sph_kernel_cubic
def initialize(self, *args):
raise NotImplementedError
@@ -227,7 +229,7 @@
dist = idist[0] + idist[1] + idist[2]
# Calculate distance in multiples of the smoothing length
dist = sqrt(dist) / fields[0]
- self.temp[gind(i,j,k,dim) + offset] = sph_kernel(dist)
+ self.temp[gind(i,j,k,dim) + offset] = self.sph_kernel(dist)
kernel_sum += self.temp[gind(i,j,k,dim) + offset]
# Having found the kernel, deposit accordingly into gdata
for i from ib0[0] <= i <= ib1[0]:
@@ -492,4 +494,3 @@
return self.onnfield
deposit_nearest = NNParticleField
-
diff -r 6ffc343b3b1b61587a87bc843e1a4fa5b05cb8c4 -r fbcd9699a3fc37907b7deab8e48c20fc753a0d94 yt/geometry/particle_smooth.pxd
--- a/yt/geometry/particle_smooth.pxd
+++ b/yt/geometry/particle_smooth.pxd
@@ -22,7 +22,7 @@
from fp_utils cimport *
from oct_container cimport Oct, OctAllocationContainer, OctreeContainer
-from .particle_deposit cimport sph_kernel, gind
+from .particle_deposit cimport sph_kernel_cubic, gind
cdef extern from "platform_dep.h":
void *alloca(int)
diff -r 6ffc343b3b1b61587a87bc843e1a4fa5b05cb8c4 -r fbcd9699a3fc37907b7deab8e48c20fc753a0d94 yt/geometry/particle_smooth.pyx
--- a/yt/geometry/particle_smooth.pyx
+++ b/yt/geometry/particle_smooth.pyx
@@ -74,7 +74,7 @@
opos[2] = ipos[2]
cdef class ParticleSmoothOperation:
- def __init__(self, nvals, nfields, max_neighbors):
+ def __init__(self, nvals, nfields, max_neighbors, kernel='cubic'):
# This is the set of cells, in grids, blocks or octs, we are handling.
cdef int i
self.nvals = nvals
@@ -83,6 +83,8 @@
self.neighbors = <NeighborList *> malloc(
sizeof(NeighborList) * self.maxn)
self.neighbor_reset()
+ if kernel == 'cubic':
+ self.sph_kernel = sph_kernel_cubic
def initialize(self, *args):
raise NotImplementedError
@@ -630,7 +632,7 @@
# Usually this density has been computed
dens = fields[2][pn]
if dens == 0.0: continue
- weight = mass * sph_kernel(sqrt(r2) / hsml) / dens
+ weight = mass * self.sph_kernel(sqrt(r2) / hsml) / dens
# Mass of the particle times the value
for fi in range(self.nfields - 3):
val = fields[fi + 3][pn]
@@ -756,7 +758,7 @@
for pn in range(self.curn):
mass = fields[0][self.neighbors[pn].pn]
r2 = self.neighbors[pn].r2
- lw = sph_kernel(sqrt(r2) / hsml)
+ lw = self.sph_kernel(sqrt(r2) / hsml)
dens += mass * lw
weight = (4.0/3.0) * 3.1415926 * hsml**3
fields[1][offset] = dens/weight
https://bitbucket.org/yt_analysis/yt/commits/86a255585521/
Changeset: 86a255585521
Branch: yt
User: qobilidop
Date: 2015-07-31 22:23:18+00:00
Summary: add cython declaration
Affected #: 2 files
diff -r fbcd9699a3fc37907b7deab8e48c20fc753a0d94 -r 86a25558552167f15ebbc18e8e0e2e1d9cf6bd6f yt/geometry/particle_deposit.pxd
--- a/yt/geometry/particle_deposit.pxd
+++ b/yt/geometry/particle_deposit.pxd
@@ -48,8 +48,10 @@
kernel = 0.
return kernel
+ctypedef np.float64_t (*kernel_func) (np.float64_t)
cdef class ParticleDepositOperation:
# We assume each will allocate and define their own temporary storage
+ cdef kernel_func sph_kernel
cdef public object nvals
cdef public int update_values
cdef void process(self, int dim[3], np.float64_t left_edge[3],
diff -r fbcd9699a3fc37907b7deab8e48c20fc753a0d94 -r 86a25558552167f15ebbc18e8e0e2e1d9cf6bd6f yt/geometry/particle_smooth.pxd
--- a/yt/geometry/particle_smooth.pxd
+++ b/yt/geometry/particle_smooth.pxd
@@ -32,8 +32,10 @@
np.int64_t pn # Particle number
np.float64_t r2 # radius**2
+ctypedef np.float64_t (*kernel_func) (np.float64_t)
cdef class ParticleSmoothOperation:
# We assume each will allocate and define their own temporary storage
+ cdef kernel_func sph_kernel
cdef public object nvals
cdef np.float64_t DW[3]
cdef int nfields
https://bitbucket.org/yt_analysis/yt/commits/30959c9d6d7b/
Changeset: 30959c9d6d7b
Branch: yt
User: qobilidop
Date: 2015-07-31 22:50:13+00:00
Summary: add alternative sph kernels
Affected #: 1 file
diff -r 86a25558552167f15ebbc18e8e0e2e1d9cf6bd6f -r 30959c9d6d7b622d8b03f9c1f6ed70719091f12e yt/geometry/particle_deposit.pxd
--- a/yt/geometry/particle_deposit.pxd
+++ b/yt/geometry/particle_deposit.pxd
@@ -48,6 +48,38 @@
kernel = 0.
return kernel
+########################################################
+# Alternative SPH kernels for use with the Grid method #
+########################################################
+
+# quartic spline
+cdef np.float64_t Cquartic = 5.**6/512/np.pi
+cdef inline np.float64_t sph_kernel_quartic(np.float64_t x) nogil:
+ cdef np.float64_t kernel
+ if x < 1:
+ kernel = (1.-x)**4
+ if x < 3./5:
+ kernel -= 5*(3./5-x)**4
+ if x < 1./5:
+ kernel += 10*(1./5-x)**4
+ else:
+ kernel = 0.
+ return kernel * Cquartic
+
+# quintic spline
+cdef np.float64_t Cquintic = 3.**7/40/np.pi
+cdef inline np.float64_t sph_kernel_quintic(np.float64_t x) nogil:
+ cdef np.float64_t kernel
+ if x < 1:
+ kernel = (1.-x)**5
+ if x < 2./3:
+ kernel -= 6*(2./3-x)**5
+ if x < 1./3:
+ kernel += 15*(1./3-x)**5
+ else:
+ kernel = 0.
+ return kernel * Cquintic
+
ctypedef np.float64_t (*kernel_func) (np.float64_t)
cdef class ParticleDepositOperation:
# We assume each will allocate and define their own temporary storage
https://bitbucket.org/yt_analysis/yt/commits/aac66a174d71/
Changeset: aac66a174d71
Branch: yt
User: qobilidop
Date: 2015-08-01 00:29:50+00:00
Summary: add get_kernel_func and some minor adjustments
Affected #: 4 files
diff -r 30959c9d6d7b622d8b03f9c1f6ed70719091f12e -r aac66a174d711fd15df2bd4c2d0870ac3aaeba79 yt/geometry/particle_deposit.pxd
--- a/yt/geometry/particle_deposit.pxd
+++ b/yt/geometry/particle_deposit.pxd
@@ -80,7 +80,20 @@
kernel = 0.
return kernel * Cquintic
+# I don't know the way to use a dict in a cdef class.
+# So in order to mimic a registry functionality,
+# I manually created a function to lookup the kernel functions.
ctypedef np.float64_t (*kernel_func) (np.float64_t)
+cdef inline kernel_func get_kernel_func(str kernel_name):
+ if kernel_name == 'cubic':
+ return sph_kernel_cubic
+ elif kernel_name == 'quartic':
+ return sph_kernel_quartic
+ elif kernel_name == 'quintic':
+ return sph_kernel_quintic
+ else:
+ raise NotImplementedError
+
cdef class ParticleDepositOperation:
# We assume each will allocate and define their own temporary storage
cdef kernel_func sph_kernel
diff -r 30959c9d6d7b622d8b03f9c1f6ed70719091f12e -r aac66a174d711fd15df2bd4c2d0870ac3aaeba79 yt/geometry/particle_deposit.pyx
--- a/yt/geometry/particle_deposit.pyx
+++ b/yt/geometry/particle_deposit.pyx
@@ -25,11 +25,10 @@
OctreeContainer, OctInfo
cdef class ParticleDepositOperation:
- def __init__(self, nvals, kernel='cubic'):
+ def __init__(self, nvals, kernel_name='cubic'):
self.nvals = nvals
self.update_values = 0 # This is the default
- if kernel == 'cubic':
- self.sph_kernel = sph_kernel_cubic
+ self.sph_kernel = get_kernel_func(kernel_name)
def initialize(self, *args):
raise NotImplementedError
diff -r 30959c9d6d7b622d8b03f9c1f6ed70719091f12e -r aac66a174d711fd15df2bd4c2d0870ac3aaeba79 yt/geometry/particle_smooth.pxd
--- a/yt/geometry/particle_smooth.pxd
+++ b/yt/geometry/particle_smooth.pxd
@@ -22,7 +22,7 @@
from fp_utils cimport *
from oct_container cimport Oct, OctAllocationContainer, OctreeContainer
-from .particle_deposit cimport sph_kernel_cubic, gind
+from .particle_deposit cimport kernel_func, get_kernel_func, gind
cdef extern from "platform_dep.h":
void *alloca(int)
@@ -32,7 +32,6 @@
np.int64_t pn # Particle number
np.float64_t r2 # radius**2
-ctypedef np.float64_t (*kernel_func) (np.float64_t)
cdef class ParticleSmoothOperation:
# We assume each will allocate and define their own temporary storage
cdef kernel_func sph_kernel
diff -r 30959c9d6d7b622d8b03f9c1f6ed70719091f12e -r aac66a174d711fd15df2bd4c2d0870ac3aaeba79 yt/geometry/particle_smooth.pyx
--- a/yt/geometry/particle_smooth.pyx
+++ b/yt/geometry/particle_smooth.pyx
@@ -74,7 +74,7 @@
opos[2] = ipos[2]
cdef class ParticleSmoothOperation:
- def __init__(self, nvals, nfields, max_neighbors, kernel='cubic'):
+ def __init__(self, nvals, nfields, max_neighbors, kernel_name='cubic'):
# This is the set of cells, in grids, blocks or octs, we are handling.
cdef int i
self.nvals = nvals
@@ -83,8 +83,7 @@
self.neighbors = <NeighborList *> malloc(
sizeof(NeighborList) * self.maxn)
self.neighbor_reset()
- if kernel == 'cubic':
- self.sph_kernel = sph_kernel_cubic
+ self.sph_kernel = get_kernel_func(kernel_name)
def initialize(self, *args):
raise NotImplementedError
https://bitbucket.org/yt_analysis/yt/commits/5845bbe0a829/
Changeset: 5845bbe0a829
Branch: yt
User: qobilidop
Date: 2015-08-01 02:21:23+00:00
Summary: update OctreeSubset
Affected #: 3 files
diff -r aac66a174d711fd15df2bd4c2d0870ac3aaeba79 -r 5845bbe0a829298e7266691625236e890dfb3fdf yt/data_objects/octree_subset.py
--- a/yt/data_objects/octree_subset.py
+++ b/yt/data_objects/octree_subset.py
@@ -141,7 +141,8 @@
self._domain_ind = di
return self._domain_ind
- def deposit(self, positions, fields = None, method = None):
+ def deposit(self, positions, fields = None, method = None,
+ kernel_name='cubic'):
r"""Operate on the mesh, in a particle-against-mesh fashion, with
exclusively local input.
@@ -176,7 +177,8 @@
raise YTParticleDepositionNotImplemented(method)
nz = self.nz
nvals = (nz, nz, nz, (self.domain_ind >= 0).sum())
- op = cls(nvals) # We allocate number of zones, not number of octs
+ # We allocate number of zones, not number of octs
+ op = cls(nvals, kernel_name)
op.initialize()
mylog.debug("Depositing %s (%s^3) particles into %s Octs",
positions.shape[0], positions.shape[0]**0.3333333, nvals[-1])
@@ -192,7 +194,8 @@
return np.asfortranarray(vals)
def smooth(self, positions, fields = None, index_fields = None,
- method = None, create_octree = False, nneighbors = 64):
+ method = None, create_octree = False, nneighbors = 64,
+ kernel_name = 'cubic'):
r"""Operate on the mesh, in a particle-against-mesh fashion, with
non-local input.
@@ -258,7 +261,7 @@
nz = self.nz
mdom_ind = self.domain_ind
nvals = (nz, nz, nz, (mdom_ind >= 0).sum())
- op = cls(nvals, len(fields), nneighbors)
+ op = cls(nvals, len(fields), nneighbors, kernel_name)
op.initialize()
mylog.debug("Smoothing %s particles into %s Octs",
positions.shape[0], nvals[-1])
@@ -335,7 +338,7 @@
nz = self.nz
mdom_ind = self.domain_ind
nvals = (nz, nz, nz, (mdom_ind >= 0).sum())
- op = cls(nvals, len(fields), nneighbors)
+ op = cls(nvals, len(fields), nneighbors, kernel_name)
op.initialize()
mylog.debug("Smoothing %s particles into %s Octs",
positions.shape[0], nvals[-1])
diff -r aac66a174d711fd15df2bd4c2d0870ac3aaeba79 -r 5845bbe0a829298e7266691625236e890dfb3fdf yt/geometry/particle_deposit.pyx
--- a/yt/geometry/particle_deposit.pyx
+++ b/yt/geometry/particle_deposit.pyx
@@ -25,7 +25,7 @@
OctreeContainer, OctInfo
cdef class ParticleDepositOperation:
- def __init__(self, nvals, kernel_name='cubic'):
+ def __init__(self, nvals, kernel_name):
self.nvals = nvals
self.update_values = 0 # This is the default
self.sph_kernel = get_kernel_func(kernel_name)
diff -r aac66a174d711fd15df2bd4c2d0870ac3aaeba79 -r 5845bbe0a829298e7266691625236e890dfb3fdf yt/geometry/particle_smooth.pyx
--- a/yt/geometry/particle_smooth.pyx
+++ b/yt/geometry/particle_smooth.pyx
@@ -74,7 +74,7 @@
opos[2] = ipos[2]
cdef class ParticleSmoothOperation:
- def __init__(self, nvals, nfields, max_neighbors, kernel_name='cubic'):
+ def __init__(self, nvals, nfields, max_neighbors, kernel_name):
# This is the set of cells, in grids, blocks or octs, we are handling.
cdef int i
self.nvals = nvals
https://bitbucket.org/yt_analysis/yt/commits/765dcc75fb31/
Changeset: 765dcc75fb31
Branch: yt
User: qobilidop
Date: 2015-08-01 03:26:47+00:00
Summary: update YTCoveringGridBase.deposit
Affected #: 1 file
diff -r 5845bbe0a829298e7266691625236e890dfb3fdf -r 765dcc75fb318604f6e1d5f0bddacbc72a6cca55 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -682,11 +682,13 @@
def RightEdge(self):
return self.right_edge
- def deposit(self, positions, fields = None, method = None):
+ def deposit(self, positions, fields = None, method = None,
+ kernel_name = 'cubic'):
cls = getattr(particle_deposit, "deposit_%s" % method, None)
if cls is None:
raise YTParticleDepositionNotImplemented(method)
- op = cls(self.ActiveDimensions.prod()) # We allocate number of zones, not number of octs
+ # We allocate number of zones, not number of octs
+ op = cls(self.ActiveDimensions.prod(), kernel_name)
op.initialize()
op.process_grid(self, positions, fields)
vals = op.finalize()
@@ -1787,5 +1789,3 @@
else:
mylog.error("Problem uploading.")
return upload_id
-
-
https://bitbucket.org/yt_analysis/yt/commits/96d96166f9d5/
Changeset: 96d96166f9d5
Branch: yt
User: qobilidop
Date: 2015-08-01 03:29:22+00:00
Summary: update AMRGridPatch.deposit
Affected #: 1 file
diff -r 765dcc75fb318604f6e1d5f0bddacbc72a6cca55 -r 96d96166f9d5dccffab93dad4c78c5baa3ac9dd6 yt/data_objects/grid_patch.py
--- a/yt/data_objects/grid_patch.py
+++ b/yt/data_objects/grid_patch.py
@@ -330,12 +330,14 @@
def particle_operation(self, *args, **kwargs):
raise NotImplementedError
- def deposit(self, positions, fields = None, method = None):
+ def deposit(self, positions, fields = None, method = None,
+ kernel_name = 'cubic'):
# Here we perform our particle deposition.
cls = getattr(particle_deposit, "deposit_%s" % method, None)
if cls is None:
raise YTParticleDepositionNotImplemented(method)
- op = cls(self.ActiveDimensions.prod()) # We allocate number of zones, not number of octs
+ # We allocate number of zones, not number of octs
+ op = cls(self.ActiveDimensions.prod(), kernel_name)
op.initialize()
op.process_grid(self, positions, fields)
vals = op.finalize()
https://bitbucket.org/yt_analysis/yt/commits/5ba0cf798853/
Changeset: 5ba0cf798853
Branch: yt
User: qobilidop
Date: 2015-08-01 03:31:34+00:00
Summary: update UnstructuredMesh.deposit
Affected #: 1 file
diff -r 96d96166f9d5dccffab93dad4c78c5baa3ac9dd6 -r 5ba0cf79885315416f3aae97753d8f4eebd805e3 yt/data_objects/unstructured_mesh.py
--- a/yt/data_objects/unstructured_mesh.py
+++ b/yt/data_objects/unstructured_mesh.py
@@ -105,13 +105,15 @@
def select_tcoords(self, dobj):
raise NotImplementedError
- def deposit(self, positions, fields = None, method = None):
+ def deposit(self, positions, fields = None, method = None,
+ kernel_name = 'cubic'):
raise NotImplementedError
# Here we perform our particle deposition.
cls = getattr(particle_deposit, "deposit_%s" % method, None)
if cls is None:
raise YTParticleDepositionNotImplemented(method)
- op = cls(self.ActiveDimensions.prod()) # We allocate number of zones, not number of octs
+ # We allocate number of zones, not number of octs
+ op = cls(self.ActiveDimensions.prod(), kernel_name)
op.initialize()
op.process_grid(self, positions, fields)
vals = op.finalize()
@@ -200,4 +202,3 @@
else:
self._last_count = mask.sum()
return mask
-
https://bitbucket.org/yt_analysis/yt/commits/fbdcba1fa6bd/
Changeset: fbdcba1fa6bd
Branch: yt
User: qobilidop
Date: 2015-08-01 03:38:23+00:00
Summary: update ARTIORootMeshSubset.deposit
Affected #: 1 file
diff -r 5ba0cf79885315416f3aae97753d8f4eebd805e3 -r fbdcba1fa6bd38c933e6af6774582af78e3ad042 yt/frontends/artio/data_structures.py
--- a/yt/frontends/artio/data_structures.py
+++ b/yt/frontends/artio/data_structures.py
@@ -133,7 +133,8 @@
tr = dict((field, v) for field, v in zip(fields, tr))
return tr
- def deposit(self, positions, fields = None, method = None):
+ def deposit(self, positions, fields = None, method = None,
+ kernel_name = 'cubic'):
# Here we perform our particle deposition.
if fields is None: fields = []
cls = getattr(particle_deposit, "deposit_%s" % method, None)
@@ -141,7 +142,8 @@
raise YTParticleDepositionNotImplemented(method)
nz = self.nz
nvals = (nz, nz, nz, self.ires.size)
- op = cls(nvals) # We allocate number of zones, not number of octs
+ # We allocate number of zones, not number of octs
+ op = cls(nvals, kernel_name)
op.initialize()
mylog.debug("Depositing %s (%s^3) particles into %s Root Mesh",
positions.shape[0], positions.shape[0]**0.3333333, nvals[-1])
https://bitbucket.org/yt_analysis/yt/commits/6b95fcf05351/
Changeset: 6b95fcf05351
Branch: yt
User: qobilidop
Date: 2015-08-02 08:26:16+00:00
Summary: update add_volume_weighted_smoothed_field
Affected #: 1 file
diff -r fbdcba1fa6bd38c933e6af6774582af78e3ad042 -r 6b95fcf05351b3e703f5bf6437bc82c45a6bcd16 yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -766,8 +766,12 @@
def add_volume_weighted_smoothed_field(ptype, coord_name, mass_name,
smoothing_length_name, density_name, smoothed_field, registry,
- nneighbors = None):
- field_name = ("deposit", "%s_smoothed_%s" % (ptype, smoothed_field))
+ nneighbors = None, kernel_name = 'cubic'):
+ if kernel_name == 'cubic':
+ field_name = ("deposit", "%s_smoothed_%s" % (ptype, smoothed_field))
+ else:
+ field_name = ("deposit", "%s_%s_smoothed_%s" % (ptype, kernel_name,
+ smoothed_field))
field_units = registry[ptype, smoothed_field].units
def _vol_weight(field, data):
pos = data[ptype, coord_name]
@@ -789,7 +793,8 @@
# volume_weighted smooth operations return lists of length 1.
rv = data.smooth(pos, [mass, hsml, dens, quan],
method="volume_weighted",
- create_octree=True)[0]
+ create_octree=True,
+ kernel_name=kernel_name)[0]
rv[np.isnan(rv)] = 0.0
# Now some quick unit conversions.
rv = data.apply_units(rv, field_units)
https://bitbucket.org/yt_analysis/yt/commits/f0cd370e51f7/
Changeset: f0cd370e51f7
Branch: yt
User: qobilidop
Date: 2015-08-02 08:31:53+00:00
Summary: update add_density_kernel
Affected #: 1 file
diff -r 6b95fcf05351b3e703f5bf6437bc82c45a6bcd16 -r f0cd370e51f7f4f7c4c41bc670bd6a3dbea5c1ae yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -821,8 +821,12 @@
units = "code_length")
return [field_name]
-def add_density_kernel(ptype, coord_name, mass_name, registry, nneighbors = 64):
- field_name = (ptype, "smoothed_density")
+def add_density_kernel(ptype, coord_name, mass_name, registry, nneighbors = 64,
+ kernel_name = 'cubic'):
+ if kernel_name == 'cubic':
+ field_name = (ptype, "smoothed_density")
+ else:
+ field_name = (ptype, "%s_smoothed_density" % (kernel_name))
field_units = registry[ptype, mass_name].units
def _nth_neighbor(field, data):
pos = data[ptype, coord_name]
@@ -832,7 +836,8 @@
densities = mass * 0.0
data.particle_operation(pos, [mass, densities],
method="density",
- nneighbors = nneighbors)
+ nneighbors = nneighbors,
+ kernel_name = kernel_name)
ones = pos.prod(axis=1) # Get us in code_length**3
ones[:] = 1.0
densities /= ones
https://bitbucket.org/yt_analysis/yt/commits/6a1290e3ea63/
Changeset: 6a1290e3ea63
Branch: yt
User: qobilidop
Date: 2015-08-02 10:44:32+00:00
Summary: tweak kernel functions
Affected #: 1 file
diff -r f0cd370e51f7f4f7c4c41bc670bd6a3dbea5c1ae -r 6a1290e3ea636563d3f2e2a00db2b9ded1d7f361 yt/geometry/particle_deposit.pxd
--- a/yt/geometry/particle_deposit.pxd
+++ b/yt/geometry/particle_deposit.pxd
@@ -53,9 +53,9 @@
########################################################
# quartic spline
-cdef np.float64_t Cquartic = 5.**6/512/np.pi
-cdef inline np.float64_t sph_kernel_quartic(np.float64_t x) nogil:
+cdef inline np.float64_t sph_kernel_quartic(np.float64_t x):
cdef np.float64_t kernel
+ cdef np.float64_t C = 5.**6/512/np.pi
if x < 1:
kernel = (1.-x)**4
if x < 3./5:
@@ -64,12 +64,12 @@
kernel += 10*(1./5-x)**4
else:
kernel = 0.
- return kernel * Cquartic
+ return kernel * C
# quintic spline
-cdef np.float64_t Cquintic = 3.**7/40/np.pi
-cdef inline np.float64_t sph_kernel_quintic(np.float64_t x) nogil:
+cdef inline np.float64_t sph_kernel_quintic(np.float64_t x):
cdef np.float64_t kernel
+ cdef np.float64_t C = 3.**7/40/np.pi
if x < 1:
kernel = (1.-x)**5
if x < 2./3:
@@ -78,7 +78,7 @@
kernel += 15*(1./3-x)**5
else:
kernel = 0.
- return kernel * Cquintic
+ return kernel * C
# I don't know the way to use a dict in a cdef class.
# So in order to mimic a registry functionality,
https://bitbucket.org/yt_analysis/yt/commits/b91f68d4d272/
Changeset: b91f68d4d272
Branch: yt
User: qobilidop
Date: 2015-08-03 18:50:21+00:00
Summary: fix a bug in the artio frontend
Affected #: 1 file
diff -r 6a1290e3ea636563d3f2e2a00db2b9ded1d7f361 -r b91f68d4d2726a9ed1b46a4bdb21ffc5a4d26328 yt/frontends/artio/setup.py
--- a/yt/frontends/artio/setup.py
+++ b/yt/frontends/artio/setup.py
@@ -19,7 +19,8 @@
depends=artio_sources +
["yt/utilities/lib/fp_utils.pxd",
"yt/geometry/oct_container.pxd",
- "yt/geometry/selection_routines.pxd"])
+ "yt/geometry/selection_routines.pxd",
+ "yt/geometry/particle_deposit.pxd"])
config.make_config_py() # installs __config__.py
#config.make_svn_version_py()
return config
https://bitbucket.org/yt_analysis/yt/commits/6a02dfe8980f/
Changeset: 6a02dfe8980f
Branch: yt
User: qobilidop
Date: 2015-08-03 19:49:39+00:00
Summary: fix particle_operation: add kwarg
Affected #: 1 file
diff -r b91f68d4d2726a9ed1b46a4bdb21ffc5a4d26328 -r 6a02dfe8980faf70b67f647c7c497d126aa75850 yt/data_objects/octree_subset.py
--- a/yt/data_objects/octree_subset.py
+++ b/yt/data_objects/octree_subset.py
@@ -283,7 +283,7 @@
return vals
def particle_operation(self, positions, fields = None,
- method = None, nneighbors = 64):
+ method = None, nneighbors = 64, kernel_name = 'cubic'):
r"""Operate on particles, in a particle-against-particle fashion.
This uses the octree indexing system to call a "smoothing" operation
https://bitbucket.org/yt_analysis/yt/commits/cfc98fddd9d7/
Changeset: cfc98fddd9d7
Branch: yt
User: bwkeller
Date: 2015-08-19 17:09:19+00:00
Summary: Merged in qobilidop/yt (pull request #1670)
Alternative Smoothing Kernels
Affected #: 11 files
diff -r d5816147380b81418aec9ccc7ac0f551e8ddce21 -r cfc98fddd9d791464330adf166d4229749dab22c yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -682,11 +682,13 @@
def RightEdge(self):
return self.right_edge
- def deposit(self, positions, fields = None, method = None):
+ def deposit(self, positions, fields = None, method = None,
+ kernel_name = 'cubic'):
cls = getattr(particle_deposit, "deposit_%s" % method, None)
if cls is None:
raise YTParticleDepositionNotImplemented(method)
- op = cls(self.ActiveDimensions.prod()) # We allocate number of zones, not number of octs
+ # We allocate number of zones, not number of octs
+ op = cls(self.ActiveDimensions.prod(), kernel_name)
op.initialize()
op.process_grid(self, positions, fields)
vals = op.finalize()
@@ -1787,5 +1789,3 @@
else:
mylog.error("Problem uploading.")
return upload_id
-
-
diff -r d5816147380b81418aec9ccc7ac0f551e8ddce21 -r cfc98fddd9d791464330adf166d4229749dab22c yt/data_objects/grid_patch.py
--- a/yt/data_objects/grid_patch.py
+++ b/yt/data_objects/grid_patch.py
@@ -330,12 +330,14 @@
def particle_operation(self, *args, **kwargs):
raise NotImplementedError
- def deposit(self, positions, fields = None, method = None):
+ def deposit(self, positions, fields = None, method = None,
+ kernel_name = 'cubic'):
# Here we perform our particle deposition.
cls = getattr(particle_deposit, "deposit_%s" % method, None)
if cls is None:
raise YTParticleDepositionNotImplemented(method)
- op = cls(self.ActiveDimensions.prod()) # We allocate number of zones, not number of octs
+ # We allocate number of zones, not number of octs
+ op = cls(self.ActiveDimensions.prod(), kernel_name)
op.initialize()
op.process_grid(self, positions, fields)
vals = op.finalize()
diff -r d5816147380b81418aec9ccc7ac0f551e8ddce21 -r cfc98fddd9d791464330adf166d4229749dab22c yt/data_objects/octree_subset.py
--- a/yt/data_objects/octree_subset.py
+++ b/yt/data_objects/octree_subset.py
@@ -141,7 +141,8 @@
self._domain_ind = di
return self._domain_ind
- def deposit(self, positions, fields = None, method = None):
+ def deposit(self, positions, fields = None, method = None,
+ kernel_name='cubic'):
r"""Operate on the mesh, in a particle-against-mesh fashion, with
exclusively local input.
@@ -176,7 +177,8 @@
raise YTParticleDepositionNotImplemented(method)
nz = self.nz
nvals = (nz, nz, nz, (self.domain_ind >= 0).sum())
- op = cls(nvals) # We allocate number of zones, not number of octs
+ # We allocate number of zones, not number of octs
+ op = cls(nvals, kernel_name)
op.initialize()
mylog.debug("Depositing %s (%s^3) particles into %s Octs",
positions.shape[0], positions.shape[0]**0.3333333, nvals[-1])
@@ -192,7 +194,8 @@
return np.asfortranarray(vals)
def smooth(self, positions, fields = None, index_fields = None,
- method = None, create_octree = False, nneighbors = 64):
+ method = None, create_octree = False, nneighbors = 64,
+ kernel_name = 'cubic'):
r"""Operate on the mesh, in a particle-against-mesh fashion, with
non-local input.
@@ -258,7 +261,7 @@
nz = self.nz
mdom_ind = self.domain_ind
nvals = (nz, nz, nz, (mdom_ind >= 0).sum())
- op = cls(nvals, len(fields), nneighbors)
+ op = cls(nvals, len(fields), nneighbors, kernel_name)
op.initialize()
mylog.debug("Smoothing %s particles into %s Octs",
positions.shape[0], nvals[-1])
@@ -280,7 +283,7 @@
return vals
def particle_operation(self, positions, fields = None,
- method = None, nneighbors = 64):
+ method = None, nneighbors = 64, kernel_name = 'cubic'):
r"""Operate on particles, in a particle-against-particle fashion.
This uses the octree indexing system to call a "smoothing" operation
@@ -335,7 +338,7 @@
nz = self.nz
mdom_ind = self.domain_ind
nvals = (nz, nz, nz, (mdom_ind >= 0).sum())
- op = cls(nvals, len(fields), nneighbors)
+ op = cls(nvals, len(fields), nneighbors, kernel_name)
op.initialize()
mylog.debug("Smoothing %s particles into %s Octs",
positions.shape[0], nvals[-1])
diff -r d5816147380b81418aec9ccc7ac0f551e8ddce21 -r cfc98fddd9d791464330adf166d4229749dab22c yt/data_objects/unstructured_mesh.py
--- a/yt/data_objects/unstructured_mesh.py
+++ b/yt/data_objects/unstructured_mesh.py
@@ -105,13 +105,15 @@
def select_tcoords(self, dobj):
raise NotImplementedError
- def deposit(self, positions, fields = None, method = None):
+ def deposit(self, positions, fields = None, method = None,
+ kernel_name = 'cubic'):
raise NotImplementedError
# Here we perform our particle deposition.
cls = getattr(particle_deposit, "deposit_%s" % method, None)
if cls is None:
raise YTParticleDepositionNotImplemented(method)
- op = cls(self.ActiveDimensions.prod()) # We allocate number of zones, not number of octs
+ # We allocate number of zones, not number of octs
+ op = cls(self.ActiveDimensions.prod(), kernel_name)
op.initialize()
op.process_grid(self, positions, fields)
vals = op.finalize()
@@ -200,4 +202,3 @@
else:
self._last_count = mask.sum()
return mask
-
diff -r d5816147380b81418aec9ccc7ac0f551e8ddce21 -r cfc98fddd9d791464330adf166d4229749dab22c yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -766,8 +766,12 @@
def add_volume_weighted_smoothed_field(ptype, coord_name, mass_name,
smoothing_length_name, density_name, smoothed_field, registry,
- nneighbors = None):
- field_name = ("deposit", "%s_smoothed_%s" % (ptype, smoothed_field))
+ nneighbors = None, kernel_name = 'cubic'):
+ if kernel_name == 'cubic':
+ field_name = ("deposit", "%s_smoothed_%s" % (ptype, smoothed_field))
+ else:
+ field_name = ("deposit", "%s_%s_smoothed_%s" % (ptype, kernel_name,
+ smoothed_field))
field_units = registry[ptype, smoothed_field].units
def _vol_weight(field, data):
pos = data[ptype, coord_name]
@@ -789,7 +793,8 @@
# volume_weighted smooth operations return lists of length 1.
rv = data.smooth(pos, [mass, hsml, dens, quan],
method="volume_weighted",
- create_octree=True)[0]
+ create_octree=True,
+ kernel_name=kernel_name)[0]
rv[np.isnan(rv)] = 0.0
# Now some quick unit conversions.
rv = data.apply_units(rv, field_units)
@@ -816,8 +821,12 @@
units = "code_length")
return [field_name]
-def add_density_kernel(ptype, coord_name, mass_name, registry, nneighbors = 64):
- field_name = (ptype, "smoothed_density")
+def add_density_kernel(ptype, coord_name, mass_name, registry, nneighbors = 64,
+ kernel_name = 'cubic'):
+ if kernel_name == 'cubic':
+ field_name = (ptype, "smoothed_density")
+ else:
+ field_name = (ptype, "%s_smoothed_density" % (kernel_name))
field_units = registry[ptype, mass_name].units
def _nth_neighbor(field, data):
pos = data[ptype, coord_name]
@@ -827,7 +836,8 @@
densities = mass * 0.0
data.particle_operation(pos, [mass, densities],
method="density",
- nneighbors = nneighbors)
+ nneighbors = nneighbors,
+ kernel_name = kernel_name)
ones = pos.prod(axis=1) # Get us in code_length**3
ones[:] = 1.0
densities /= ones
diff -r d5816147380b81418aec9ccc7ac0f551e8ddce21 -r cfc98fddd9d791464330adf166d4229749dab22c yt/frontends/artio/data_structures.py
--- a/yt/frontends/artio/data_structures.py
+++ b/yt/frontends/artio/data_structures.py
@@ -133,7 +133,8 @@
tr = dict((field, v) for field, v in zip(fields, tr))
return tr
- def deposit(self, positions, fields = None, method = None):
+ def deposit(self, positions, fields = None, method = None,
+ kernel_name = 'cubic'):
# Here we perform our particle deposition.
if fields is None: fields = []
cls = getattr(particle_deposit, "deposit_%s" % method, None)
@@ -141,7 +142,8 @@
raise YTParticleDepositionNotImplemented(method)
nz = self.nz
nvals = (nz, nz, nz, self.ires.size)
- op = cls(nvals) # We allocate number of zones, not number of octs
+ # We allocate number of zones, not number of octs
+ op = cls(nvals, kernel_name)
op.initialize()
mylog.debug("Depositing %s (%s^3) particles into %s Root Mesh",
positions.shape[0], positions.shape[0]**0.3333333, nvals[-1])
diff -r d5816147380b81418aec9ccc7ac0f551e8ddce21 -r cfc98fddd9d791464330adf166d4229749dab22c yt/frontends/artio/setup.py
--- a/yt/frontends/artio/setup.py
+++ b/yt/frontends/artio/setup.py
@@ -19,7 +19,8 @@
depends=artio_sources +
["yt/utilities/lib/fp_utils.pxd",
"yt/geometry/oct_container.pxd",
- "yt/geometry/selection_routines.pxd"])
+ "yt/geometry/selection_routines.pxd",
+ "yt/geometry/particle_deposit.pxd"])
config.make_config_py() # installs __config__.py
#config.make_svn_version_py()
return config
diff -r d5816147380b81418aec9ccc7ac0f551e8ddce21 -r cfc98fddd9d791464330adf166d4229749dab22c yt/geometry/particle_deposit.pxd
--- a/yt/geometry/particle_deposit.pxd
+++ b/yt/geometry/particle_deposit.pxd
@@ -38,7 +38,7 @@
# Standard SPH kernel for use with the Grid method #
####################################################
-cdef inline np.float64_t sph_kernel(np.float64_t x) nogil:
+cdef inline np.float64_t sph_kernel_cubic(np.float64_t x) nogil:
cdef np.float64_t kernel
if x <= 0.5:
kernel = 1.-6.*x*x*(1.-x)
@@ -48,8 +48,55 @@
kernel = 0.
return kernel
+########################################################
+# Alternative SPH kernels for use with the Grid method #
+########################################################
+
+# quartic spline
+cdef inline np.float64_t sph_kernel_quartic(np.float64_t x):
+ cdef np.float64_t kernel
+ cdef np.float64_t C = 5.**6/512/np.pi
+ if x < 1:
+ kernel = (1.-x)**4
+ if x < 3./5:
+ kernel -= 5*(3./5-x)**4
+ if x < 1./5:
+ kernel += 10*(1./5-x)**4
+ else:
+ kernel = 0.
+ return kernel * C
+
+# quintic spline
+cdef inline np.float64_t sph_kernel_quintic(np.float64_t x):
+ cdef np.float64_t kernel
+ cdef np.float64_t C = 3.**7/40/np.pi
+ if x < 1:
+ kernel = (1.-x)**5
+ if x < 2./3:
+ kernel -= 6*(2./3-x)**5
+ if x < 1./3:
+ kernel += 15*(1./3-x)**5
+ else:
+ kernel = 0.
+ return kernel * C
+
+# I don't know the way to use a dict in a cdef class.
+# So in order to mimic a registry functionality,
+# I manually created a function to lookup the kernel functions.
+ctypedef np.float64_t (*kernel_func) (np.float64_t)
+cdef inline kernel_func get_kernel_func(str kernel_name):
+ if kernel_name == 'cubic':
+ return sph_kernel_cubic
+ elif kernel_name == 'quartic':
+ return sph_kernel_quartic
+ elif kernel_name == 'quintic':
+ return sph_kernel_quintic
+ else:
+ raise NotImplementedError
+
cdef class ParticleDepositOperation:
# We assume each will allocate and define their own temporary storage
+ cdef kernel_func sph_kernel
cdef public object nvals
cdef public int update_values
cdef void process(self, int dim[3], np.float64_t left_edge[3],
diff -r d5816147380b81418aec9ccc7ac0f551e8ddce21 -r cfc98fddd9d791464330adf166d4229749dab22c yt/geometry/particle_deposit.pyx
--- a/yt/geometry/particle_deposit.pyx
+++ b/yt/geometry/particle_deposit.pyx
@@ -25,9 +25,10 @@
OctreeContainer, OctInfo
cdef class ParticleDepositOperation:
- def __init__(self, nvals):
+ def __init__(self, nvals, kernel_name):
self.nvals = nvals
self.update_values = 0 # This is the default
+ self.sph_kernel = get_kernel_func(kernel_name)
def initialize(self, *args):
raise NotImplementedError
@@ -227,7 +228,7 @@
dist = idist[0] + idist[1] + idist[2]
# Calculate distance in multiples of the smoothing length
dist = sqrt(dist) / fields[0]
- self.temp[gind(i,j,k,dim) + offset] = sph_kernel(dist)
+ self.temp[gind(i,j,k,dim) + offset] = self.sph_kernel(dist)
kernel_sum += self.temp[gind(i,j,k,dim) + offset]
# Having found the kernel, deposit accordingly into gdata
for i from ib0[0] <= i <= ib1[0]:
@@ -493,4 +494,3 @@
return self.onnfield
deposit_nearest = NNParticleField
-
diff -r d5816147380b81418aec9ccc7ac0f551e8ddce21 -r cfc98fddd9d791464330adf166d4229749dab22c yt/geometry/particle_smooth.pxd
--- a/yt/geometry/particle_smooth.pxd
+++ b/yt/geometry/particle_smooth.pxd
@@ -22,7 +22,7 @@
from fp_utils cimport *
from oct_container cimport Oct, OctAllocationContainer, OctreeContainer
-from .particle_deposit cimport sph_kernel, gind
+from .particle_deposit cimport kernel_func, get_kernel_func, gind
cdef extern from "platform_dep.h":
void *alloca(int)
@@ -34,6 +34,7 @@
cdef class ParticleSmoothOperation:
# We assume each will allocate and define their own temporary storage
+ cdef kernel_func sph_kernel
cdef public object nvals
cdef np.float64_t DW[3]
cdef int nfields
diff -r d5816147380b81418aec9ccc7ac0f551e8ddce21 -r cfc98fddd9d791464330adf166d4229749dab22c yt/geometry/particle_smooth.pyx
--- a/yt/geometry/particle_smooth.pyx
+++ b/yt/geometry/particle_smooth.pyx
@@ -74,7 +74,7 @@
opos[2] = ipos[2]
cdef class ParticleSmoothOperation:
- def __init__(self, nvals, nfields, max_neighbors):
+ def __init__(self, nvals, nfields, max_neighbors, kernel_name):
# This is the set of cells, in grids, blocks or octs, we are handling.
cdef int i
self.nvals = nvals
@@ -83,6 +83,7 @@
self.neighbors = <NeighborList *> malloc(
sizeof(NeighborList) * self.maxn)
self.neighbor_reset()
+ self.sph_kernel = get_kernel_func(kernel_name)
def initialize(self, *args):
raise NotImplementedError
@@ -630,7 +631,7 @@
# Usually this density has been computed
dens = fields[2][pn]
if dens == 0.0: continue
- weight = mass * sph_kernel(sqrt(r2) / hsml) / dens
+ weight = mass * self.sph_kernel(sqrt(r2) / hsml) / dens
# Mass of the particle times the value
for fi in range(self.nfields - 3):
val = fields[fi + 3][pn]
@@ -756,7 +757,7 @@
for pn in range(self.curn):
mass = fields[0][self.neighbors[pn].pn]
r2 = self.neighbors[pn].r2
- lw = sph_kernel(sqrt(r2) / hsml)
+ lw = self.sph_kernel(sqrt(r2) / hsml)
dens += mass * lw
weight = (4.0/3.0) * 3.1415926 * hsml**3
fields[1][offset] = dens/weight
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list