[yt-svn] commit/yt: bwkeller: Merged in qobilidop/yt (pull request #1830)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Nov 2 11:42:33 PST 2015
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/d5b7f5d362c5/
Changeset: d5b7f5d362c5
Branch: yt
User: bwkeller
Date: 2015-11-02 19:42:23+00:00
Summary: Merged in qobilidop/yt (pull request #1830)
Alternative Smoothing Kernels (Reissued)
Affected #: 5 files
diff -r 697ca7baf306df33d900376704a185a48ff08723 -r d5b7f5d362c59fd408dbd5fd31a5cfa55c933e01 doc/source/analyzing/fields.rst
--- a/doc/source/analyzing/fields.rst
+++ b/doc/source/analyzing/fields.rst
@@ -374,6 +374,17 @@
"Gas_smoothed_Temperature")``, which in most cases would be aliased to the
field ``("gas", "temperature")`` for convenience.
+Other smoothing kernels besides the cubic spline one are available through a
+keyword argument ``kernel_name`` of the method ``add_smoothed_particle_field``.
+Current available kernel names include:
+
+* ``cubic``, ``quartic``, and ``quintic`` - spline kernels.
+* ``wendland2``, ``wendland4`` and ``wendland6`` - Wendland kernels.
+
+The added smoothed particle field can be accessed by
+``("deposit", "particletype_kernelname_smoothed_fieldname")`` (except for the
+cubic spline kernel, which obeys the naming scheme given above).
+
Computing the Nth Nearest Neighbor
----------------------------------
diff -r 697ca7baf306df33d900376704a185a48ff08723 -r d5b7f5d362c59fd408dbd5fd31a5cfa55c933e01 yt/data_objects/octree_subset.py
--- a/yt/data_objects/octree_subset.py
+++ b/yt/data_objects/octree_subset.py
@@ -165,6 +165,10 @@
`particle_deposit` namespace as `methodname_deposit`. Current
methods include `count`, `simple_smooth`, `sum`, `std`, `cic`,
`weighted_mean`, `mesh_id`, and `nearest`.
+ kernel_name : string, default 'cubic'
+ This is the name of the smoothing kernel to use. Current supported
+ kernel names include `cubic`, `quartic`, `quintic`, `wendland2`,
+ `wendland4`, and `wendland6`.
Returns
-------
@@ -228,6 +232,10 @@
we are able to find and identify all relevant particles.
nneighbors : int, default 64
The number of neighbors to examine during the process.
+ kernel_name : string, default 'cubic'
+ This is the name of the smoothing kernel to use. Current supported
+ kernel names include `cubic`, `quartic`, `quintic`, `wendland2`,
+ `wendland4`, and `wendland6`.
Returns
-------
@@ -313,6 +321,10 @@
`particle_smooth` namespace as `methodname_smooth`.
nneighbors : int, default 64
The number of neighbors to examine during the process.
+ kernel_name : string, default 'cubic'
+ This is the name of the smoothing kernel to use. Current supported
+ kernel names include `cubic`, `quartic`, `quintic`, `wendland2`,
+ `wendland4`, and `wendland6`.
Returns
-------
diff -r 697ca7baf306df33d900376704a185a48ff08723 -r d5b7f5d362c59fd408dbd5fd31a5cfa55c933e01 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -913,7 +913,7 @@
deps, _ = self.field_info.check_derived_fields([name])
self.field_dependencies.update(deps)
- def add_deposited_particle_field(self, deposit_field, method):
+ def add_deposited_particle_field(self, deposit_field, method, kernel_name='cubic'):
"""Add a new deposited particle field
Creates a new deposited field based on the particle *deposit_field*.
@@ -925,8 +925,16 @@
The field name tuple of the particle field the deposited field will
be created from. This must be a field name tuple so yt can
appropriately infer the correct particle type.
- method : one of 'count', 'sum', or 'cic'
- The particle deposition method to use.
+ method : string
+ This is the "method name" which will be looked up in the
+ `particle_deposit` namespace as `methodname_deposit`. Current
+ methods include `count`, `simple_smooth`, `sum`, `std`, `cic`,
+ `weighted_mean`, `mesh_id`, and `nearest`.
+ kernel_name : string, default 'cubic'
+ This is the name of the smoothing kernel to use. It is only used for
+ the `simple_smooth` method and is otherwise ignored. Current
+ supported kernel names include `cubic`, `quartic`, `quintic`,
+ `wendland2`, `wendland4`, and `wendland6`.
Returns
-------
@@ -950,15 +958,17 @@
if method != 'count':
pden = data[ptype, "particle_mass"]
top = data.deposit(pos, [data[(ptype, deposit_field)]*pden],
- method=method)
- bottom = data.deposit(pos, [pden], method=method)
+ method=method, kernel_name=kernel_name)
+ bottom = data.deposit(pos, [pden], method=method,
+ kernel_name=kernel_name)
top[bottom == 0] = 0.0
bnz = bottom.nonzero()
top[bnz] /= bottom[bnz]
d = data.ds.arr(top, input_units=units)
else:
d = data.ds.arr(data.deposit(pos, [data[ptype, deposit_field]],
- method=method))
+ method=method,
+ kernel_name=kernel_name))
return d
name_map = {"cic": "cic", "sum": "nn", "count": "count"}
field_name = "%s_" + name_map[method] + "_%s"
diff -r 697ca7baf306df33d900376704a185a48ff08723 -r d5b7f5d362c59fd408dbd5fd31a5cfa55c933e01 yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -826,34 +826,6 @@
units = "code_length")
return [field_name]
-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))
-
- def _nth_neighbor(field, data):
- pos = data[ptype, coord_name]
- pos.convert_to_units("code_length")
- mass = data[ptype, mass_name]
- mass.convert_to_units("g")
- densities = mass * 0.0
- data.particle_operation(pos, [mass, densities],
- method="density",
- nneighbors = nneighbors,
- kernel_name = kernel_name)
- ones = pos.prod(axis=1) # Get us in code_length**3
- ones[:] = 1.0
- densities /= ones
- # Now some quick unit conversions.
- return densities
- registry.add_field(field_name, function = _nth_neighbor,
- validators = [ValidateSpatial(0)],
- particle_type = True,
- units = "g/cm**3")
- return [field_name]
-
def add_union_field(registry, ptype, field_name, units):
"""
Create a field that is the concatenation of multiple particle types.
diff -r 697ca7baf306df33d900376704a185a48ff08723 -r d5b7f5d362c59fd408dbd5fd31a5cfa55c933e01 yt/geometry/particle_deposit.pxd
--- a/yt/geometry/particle_deposit.pxd
+++ b/yt/geometry/particle_deposit.pxd
@@ -81,6 +81,36 @@
kernel = 0.
return kernel * C
+# Wendland C2
+cdef inline np.float64_t sph_kernel_wendland2(np.float64_t x):
+ cdef np.float64_t kernel
+ cdef np.float64_t C = 21./2/np.pi
+ if x < 1:
+ kernel = (1.-x)**4 * (1+4*x)
+ else:
+ kernel = 0.
+ return kernel * C
+
+# Wendland C4
+cdef inline np.float64_t sph_kernel_wendland4(np.float64_t x):
+ cdef np.float64_t kernel
+ cdef np.float64_t C = 495./32/np.pi
+ if x < 1:
+ kernel = (1.-x)**6 * (1+6*x+35./3*x**2)
+ else:
+ kernel = 0.
+ return kernel * C
+
+# Wendland C6
+cdef inline np.float64_t sph_kernel_wendland6(np.float64_t x):
+ cdef np.float64_t kernel
+ cdef np.float64_t C = 1365./64/np.pi
+ if x < 1:
+ kernel = (1.-x)**8 * (1+8*x+25*x**2+32*x**3)
+ 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.
@@ -92,6 +122,12 @@
return sph_kernel_quartic
elif kernel_name == 'quintic':
return sph_kernel_quintic
+ elif kernel_name == 'wendland2':
+ return sph_kernel_wendland2
+ elif kernel_name == 'wendland4':
+ return sph_kernel_wendland4
+ elif kernel_name == 'wendland6':
+ return sph_kernel_wendland6
else:
raise NotImplementedError
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