-
Notifications
You must be signed in to change notification settings - Fork 10
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
Optionally keep guard cells #30
Conversation
Should be fine for single-null geometries. Double-null is trickier because the second pair of divertor targets (y-boundries) is in the middle of the grid. I've got a PR coming soon for BOUT-dev to load those y-boundary cells from grid files, which shows the logic needed. It would probably be easier to implement here if we saved global |
Ah yes I meant double-null geometries.
That would make it easier but would also be a breaking change... Relates to #3 |
Codecov Report
@@ Coverage Diff @@
## master #30 +/- ##
==========================================
+ Coverage 48.03% 51.62% +3.59%
==========================================
Files 6 6
Lines 254 277 +23
Branches 51 56 +5
==========================================
+ Hits 122 143 +21
- Misses 122 123 +1
- Partials 10 11 +1
Continue to review full report at Codecov.
|
xbout/load.py
Outdated
@@ -151,31 +155,82 @@ def _arrange_for_concatenation(filepaths, nxpe=1, nype=1): | |||
return paths_grid, concat_dims | |||
|
|||
|
|||
def _trim(ds, ghosts={}, keep_guards=True): | |||
def _trim(ds, ghosts, guards={}, keep_guards={}, nxpe=1, nype=1): |
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.
=None
rather than ={}
as a default argument. This does mean you then need to check if it's None
, and if so set a default
xbout/load.py
Outdated
lower = None | ||
else: | ||
lower = max(ghosts[dim], guards[dim]) | ||
elif ghosts.get(dim, False): |
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.
ghosts[dim]
is optional here, but required above (max(ghosts[dim], guards[dim]
)
Might just need documenting?
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.
Technically this is fine because you would never have a dimension which has guard cells but no ghost cells, but it should be made consistent for clarity and ease of testing.
elif ghosts.get(dim, False): | ||
upper = -ghosts[dim] | ||
else: | ||
upper = None |
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.
The logic for upper
is almost the same as for lower
-- is it possible to pull out into a helper function?
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.
Probably - I'll have a go
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.
As they are not completely identical, it might be more trouble that its worth
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 managed to factor this out, so do you think this is ready to merge now @ZedThree ?
What are the differences between "ghost" and "guard" cells? |
I was using the definitions: Ghost cells - internal boundary cells around a processor which are not at the edge of the domain, only used for communication, duplicated between processors. Guard cells - external boundary cells around a processor which are at the edge of the domain. Might be physically-meaningful for certain bcs, for example Debye sheath. So you might want to keep guard cells in your output but you'll never want to keep ghost cells. |
Ah, ok. In BOUT++ we usually use "guard cells" to mean what you call "ghost cells", and "boundaries" to mean "guard cells", although not always consistently, unfortunately. We also always have the same number of guard cells as boundary cells. We may need to be a bit careful here. |
Okay, sounds like I should change the names here to match BOUT conventions (even if they're not rigorously adhered to). I'll also add a clear explanation of the difference to the docs somewhere (probably just the docstring of the functions which have |
Thanks @TomNicholas and @ZedThree . I think if this naming is documented somewhere then we can try to make it consistent across the code and documentation. |
_trim was missing a required argument.
Since _trim is a private method, and in the only place it is used all the arguments are passed, it is clearer not to handle default arguments.
In BOUT++ there are always the same number of guard cells and boundary cells in a given direction, so do not need to specify the number of boundary cells separately.
Merge master into #30 to fix conflicts in making boundary cells optional
Hello @TomNicholas! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-07-26 12:26:59 UTC |
guards : dict | ||
Number of guard cells along each dimension, e.g. {'x': 2, 't': 0} | ||
keep_boundaries : dict | ||
Whether or not to preserve the boundary cells along each dimension, e.g. |
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.
Just for reference, nxpe
, nype
aren't documented here
Also, I guess guards
and keep_boundaries
are optional, although that is somewhat obvious from the signature (if you're familiar with the syntax!)
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've added nxpe
and nype
to the docstring.
guards
and keep_boundaries
aren't optional. The foo(*, a, b)
syntax means that a
and b
are required keyword arguments. I found it recently and quite like it because I think long sequences of positional arguments are bug-prone, but it's still nice to use required arguments sometimes - for example here it's an internal-implementation-only function which isn't called with default arguments, so no need to have the handling for default arguments (that would be needed if we had something like guards=None
).
Merge master into #30 to fix conflicts in making boundary cells optional
Optionally keep guard cells
This adds options
keep_xguards
andkeep_yguards
toopen_boutdataset
, which will stop the preprocessing function from trimming the cells at the edges of the domain. Addresses #19It works by inferring the location of the dump file within the whole domain using the number of the dump file and know of the overall processor splitting in each direction.
This isn't finished though - some of the tests need to be rewritten as their use of fixtures is pretty dodgy (I think there was a better way to do them with pytest that I didn't know about when I wrote them, but I'll have a look and push to this branch).
It also assumes there are only boundary cells at the outer edges of the domain, so I think it might not yet work with geometries which have a private flux region? This might break my nice logic in
_infer_contains_guards()
...(Note to self: this works with the master branch of xarray rather than with my PR)