-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Octree ghost zones — reloaded #2425
Changes from 59 commits
333436c
6ce0416
2b0baa3
8cf8a56
ab4410e
b7c0c2f
8da0a17
adb21ba
bc077f4
266ac1f
0d8bf3a
59923e2
6d091d5
08fe5a9
d6b508b
fb6462a
d23b9a1
5859895
cac9d19
dbeccb8
2ddaebb
3c20d53
1265769
41f0501
a39b4e7
463cd9a
295695e
9c04156
7c8fe2f
c42a2fb
7a7807d
4fa0a57
9b4e5c7
b5b2bfa
c3262c7
5e5af6f
7266517
9fc52df
8ec0354
aa2605d
11285a0
6fde2e5
b918389
7978ddc
86a314e
6d4adf8
d4ecca3
6c318dc
236134b
550e887
0fc5131
f7d9e4a
9ca0d0e
a92d477
58f4384
0bf76b2
19058d8
6d2b439
f21e058
3c8b75c
13e5dfa
d97eb12
b199540
8ecce95
c033f18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import os | ||
import numpy as np | ||
import weakref | ||
import warnings | ||
from collections import defaultdict | ||
from glob import glob | ||
|
||
|
@@ -9,6 +10,7 @@ | |
setdefaultattr | ||
from yt.geometry.oct_geometry_handler import \ | ||
OctreeIndex | ||
|
||
from yt.geometry.geometry_handler import \ | ||
YTDataChunk | ||
from yt.data_objects.static_output import \ | ||
|
@@ -179,9 +181,24 @@ def included(self, selector): | |
class RAMSESDomainSubset(OctreeSubset): | ||
|
||
_domain_offset = 1 | ||
_block_reorder = "F" | ||
_block_order = "F" | ||
|
||
def fill(self, fd, fields, selector, file_handler): | ||
_base_domain = None | ||
|
||
def __init__(self, base_region, domain, ds, over_refine_factor=1, num_ghost_zones=0, | ||
base_grid=None): | ||
super(RAMSESDomainSubset, self).__init__(base_region, domain, ds, over_refine_factor, num_ghost_zones) | ||
|
||
cphyc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self._base_grid = base_grid | ||
|
||
if num_ghost_zones > 0: | ||
if not all(ds.periodicity): | ||
warnings.warn('Ghost zones will wrongly assume the domain to be periodic.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason this is not a logger warning ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I changed it to raise a |
||
# Create a base domain *with no self._base_domain.fwidth | ||
base_domain = RAMSESDomainSubset(ds.all_data(), domain, ds, over_refine_factor) | ||
self._base_domain = base_domain | ||
|
||
def _fill_no_ghostzones(self, fd, fields, selector, file_handler): | ||
ndim = self.ds.dimensionality | ||
# Here we get a copy of the file, which we skip through and read the | ||
# bits we want. | ||
|
@@ -197,13 +214,85 @@ def fill(self, fd, fields, selector, file_handler): | |
# Initializing data container | ||
for field in fields: | ||
tr[field] = np.zeros(cell_count, 'float64') | ||
|
||
fill_hydro(fd, file_handler.offset, | ||
file_handler.level_count, levels, cell_inds, | ||
file_handler.level_count, | ||
[self.domain_id-1], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. had to swim back to understand what this argument represents. It's probably obvious after a while but I don't think an inline comment would hurt ! (or explicit keyword syntax ? but I don't know if that's supported for Cython functions) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made the name of the variable explicit here and below (the next |
||
levels, cell_inds, | ||
file_inds, ndim, all_fields, fields, tr, | ||
oct_handler) | ||
return tr | ||
|
||
def _fill_with_ghostzones(self, fd, fields, selector, file_handler, num_ghost_zones): | ||
ndim = self.ds.dimensionality | ||
ncpu = self.ds.parameters['ncpu'] | ||
# Here we get a copy of the file, which we skip through and read the | ||
# bits we want. | ||
oct_handler = self.oct_handler | ||
all_fields = [f for ft, f in file_handler.field_list] | ||
fields = [f for ft, f in fields] | ||
tr = {} | ||
cphyc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
cell_count = selector.count_octs(self.oct_handler, self.domain_id) * self.nz**ndim | ||
|
||
levels, cell_inds, file_inds, domains = self.oct_handler.file_index_octs_with_ghost_zones( | ||
selector, self.domain_id, cell_count) | ||
|
||
# Initializing data container | ||
for field in fields: | ||
tr[field] = np.zeros(cell_count, 'float64') | ||
fill_hydro(fd, file_handler.offset, | ||
file_handler.level_count, | ||
list(range(ncpu)), | ||
levels, cell_inds, | ||
file_inds, ndim, all_fields, fields, tr, | ||
oct_handler, | ||
domains=domains) | ||
return tr | ||
|
||
@property | ||
def fwidth(self): | ||
fwidth = super(RAMSESDomainSubset, self).fwidth | ||
if self._num_ghost_zones > 0: | ||
fwidth = fwidth.reshape(-1, 8, 3) | ||
n_oct = fwidth.shape[0] | ||
new_fwidth = np.zeros((n_oct, self.nz**3, 3), dtype=fwidth.dtype) | ||
new_fwidth[:, :, :] = fwidth[:, 0:1, :] | ||
fwidth = new_fwidth.reshape(-1, 3) | ||
cphyc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return fwidth | ||
|
||
@property | ||
def fcoords(self): | ||
num_ghost_zones = self._num_ghost_zones | ||
if num_ghost_zones == 0: | ||
return super(RAMSESDomainSubset, self).fcoords | ||
|
||
oh = self.oct_handler | ||
cphyc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
indices = oh.fill_index(self.selector).reshape(-1, 8) | ||
oinds, cinds = oh.fill_octcellindex_neighbours(self.selector) | ||
|
||
oinds = oinds.reshape(-1, 64) | ||
cinds = cinds.reshape(-1, 64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing... oct_index and cell_index ? Am I right ? if so, could you use those names instead ? if not, all the more reason to have better names ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, I changed the names. |
||
|
||
inds = indices[oinds, cinds] | ||
|
||
fcoords = self.ds.arr( | ||
oh.fcoords(self.selector)[inds].reshape(-1, 3), | ||
'unitary') | ||
|
||
return fcoords | ||
|
||
def fill(self, fd, fields, selector, file_handler): | ||
if self._num_ghost_zones == 0: | ||
return self._fill_no_ghostzones(fd, fields, selector, file_handler) | ||
else: | ||
cphyc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return self._fill_with_ghostzones(fd, fields, selector, file_handler, self._num_ghost_zones) | ||
|
||
def retrieve_ghost_zones(self, ngz, fields, smoothed=False): | ||
new_subset = RAMSESDomainSubset(self.base_region, self.domain, self.ds, num_ghost_zones=ngz, base_grid=self) | ||
|
||
return new_subset | ||
|
||
class RAMSESIndex(OctreeIndex): | ||
|
||
def __init__(self, ds, dataset_type='ramses'): | ||
|
@@ -260,7 +349,9 @@ def _identify_base_chunk(self, dobj): | |
base_region = getattr(dobj, "base_region", dobj) | ||
if len(domains) > 1: | ||
mylog.debug("Identified %s intersecting domains", len(domains)) | ||
subsets = [RAMSESDomainSubset(base_region, domain, self.dataset) | ||
subsets = [RAMSESDomainSubset( | ||
base_region, domain, self.dataset, | ||
num_ghost_zones=dobj._num_ghost_zones) | ||
for domain in domains] | ||
dobj._chunk_info = subsets | ||
dobj._current_chunk = list(self._chunk_all(dobj))[0] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like getting rid of the conditional! Nice.