Skip to content

Commit f631aa6

Browse files
committed
WIP: Try hotfixing
1 parent 5770594 commit f631aa6

3 files changed

Lines changed: 36 additions & 22 deletions

File tree

yt/data_objects/index_subobjects/grid_patch.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,25 @@ def deposit(
373373
# octree deposit routines, so we reverse it here to match the
374374
# convention there
375375

376-
# append a dummy dimension because we are only depositing onto
377-
# one grid
378-
nvals = tuple(self.ActiveDimensions[::-1]) + (1,)
379-
if vector_field:
376+
nvals = tuple(self.ActiveDimensions[::-1])
377+
scalar_as_vector = (
378+
not vector_field
379+
and method != "count"
380+
and fields is not None
381+
and len(fields) > 0
382+
and getattr(fields[0], "ndim", 0) == 1
383+
)
384+
if scalar_as_vector:
385+
fields = [np.ascontiguousarray(f.reshape(f.shape[0], 1)) for f in fields]
386+
387+
use_vector_path = vector_field or scalar_as_vector
388+
# Append a dummy grid dimension because we only deposit onto one grid.
389+
# For vector fields, append an additional vector-component dimension.
390+
if use_vector_path:
380391
vec_size = fields[0].shape[-1] if fields else 1
381-
nvals = nvals + (vec_size,)
392+
op = cls(nvals + (1, vec_size), kernel_name)
382393
else:
383-
vec_size = 1
384-
385-
op = cls(nvals, kernel_name)
394+
op = cls(nvals + (1,), kernel_name)
386395

387396
op.initialize()
388397
if positions.size > 0:
@@ -392,12 +401,16 @@ def deposit(
392401
return
393402
# Fortran-ordered, so transpose.
394403
vals = vals.transpose()
395-
# squeeze dummy dimension(s) we appended above
396-
if vector_field:
397-
new_shape = (vec_size, *self.ActiveDimensions)
404+
if use_vector_path:
405+
# (vec, 1, Nx, Ny, Nz) -> (Nx, Ny, Nz, vec)
406+
vals = np.squeeze(vals, axis=1)
407+
vals = np.moveaxis(vals, 0, -1)
408+
if scalar_as_vector:
409+
vals = np.squeeze(vals, axis=-1)
398410
else:
399-
new_shape = self.ActiveDimensions
400-
return vals.reshape(new_shape)
411+
# (1, Nx, Ny, Nz) -> (Nx, Ny, Nz)
412+
vals = np.squeeze(vals, axis=0)
413+
return vals
401414

402415
def select_blocks(self, selector):
403416
mask = self._get_selector_mask(selector)

yt/data_objects/static_output.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,6 @@ def add_deposited_particle_field(
18841884
ptype, deposit_field = deposit_field[0], deposit_field[1]
18851885
else:
18861886
raise RuntimeError
1887-
18881887
if weight_field is None:
18891888
weight_field = (ptype, "particle_mass")
18901889
units = self.field_info[ptype, deposit_field].output_units
@@ -1923,13 +1922,16 @@ def _deposit_field(data):
19231922
fields = [data[ptype, deposit_field]]
19241923
if method == "weighted_mean":
19251924
fields.append(data[ptype, weight_field])
1926-
fields = [np.ascontiguousarray(f) for f in fields]
1925+
# Cython deposition kernels operate on float64 buffers.
1926+
fields = [np.ascontiguousarray(f, dtype="float64") for f in fields]
19271927
d = data.deposit(
19281928
pos,
19291929
fields,
19301930
method=method,
19311931
kernel_name=kernel_name,
1932-
vector_field=vector_field,
1932+
# Count deposition tracks number of particles per cell and
1933+
# should remain scalar even if the source field is vector-valued.
1934+
vector_field=vector_field and method != "count",
19331935
)
19341936

19351937
d = data.ds.arr(d, units=units)

yt/geometry/particle_deposit.pyx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ from yt.utilities.lib.misc_utilities import OnceIndirect
2626
cdef append_axes(np.ndarray arr, int naxes):
2727
if arr.ndim == naxes:
2828
return arr
29-
for _ in range((naxes - arr.ndim)):
30-
arr = np.expand_dims(arr)
29+
arr = np.expand_dims(arr, axis=tuple(range(arr.ndim, naxes)))
3130
return arr
3231

3332
cdef class ParticleDepositOperation:
@@ -58,7 +57,7 @@ cdef class ParticleDepositOperation:
5857
nf = len(fields)
5958

6059
# Convert scalar fields into vector fields of length 1
61-
fields = [append_axes(field, 2) for field in fields]
60+
fields = [append_axes(field, 1) for field in fields]
6261

6362
# Make sure all of them have the same length
6463
nvec = 1
@@ -140,7 +139,7 @@ cdef class ParticleDepositOperation:
140139
nf = len(fields)
141140

142141
# Convert scalar fields into vector fields of length 1
143-
fields = [append_axes(field, 2) for field in fields]
142+
fields = [append_axes(field, 1) for field in fields]
144143

145144
# Make sure all of them have the same length
146145
nvec = 1
@@ -382,11 +381,11 @@ cdef class CICDeposit(ParticleDepositOperation):
382381
cdef np.float64_t[:,:,:,:,:] field
383382
cdef public object ofield
384383
def initialize(self):
385-
if not all(_ > 1 for _ in self.nvals[:-1]):
384+
if not all(_ > 1 for _ in self.nvals[:3]):
386385
from yt.utilities.exceptions import YTBoundsDefinitionError
387386
raise YTBoundsDefinitionError(
388387
"CIC requires minimum of 2 zones in all spatial dimensions.",
389-
self.nvals[:-1])
388+
self.nvals[:3])
390389
self.field = append_axes(
391390
np.zeros(self.nvals, dtype="float64", order='F'), 5)
392391

0 commit comments

Comments
 (0)