Skip to content

Commit

Permalink
Implement multifab wrapper functionality from WarpX (#370)
Browse files Browse the repository at this point in the history
This adds the code from the WarpX fields.py that allows global indexing
of MultiFabs. This is done by adding `__getitem__` and `__setitem__`
methods for the MultiFab object.

Note that this incorporates the changes from WarpX PR #4370 that had not
been merged in.

This currently only does the get/set without including the ghost cells.
What is needed is a way of specifying inclusion of the ghost cells.
Perhaps this?
```py
mf = MultiFab()
mf[:,5,6]  # without ghost cells
mf[:,5,6] = 2.  # without ghost cells
mf.with_ghosts([slice(None),5,6])  # with ghost cells (in the first dimension)
mf.with_ghosts([slice(None),5,6], 2.)  # with ghost cells
```
Maybe this, using imaginary numbers to refer to ghost cells?
```py
mf[-1j,5,6]  # the first ghost cell on the lower boundary
mf[+1j,5,6]  # the first ghost cell on the upper boundary
mf[(),5,6]  # the full first dimension including ghosts
mf[:,5,6]  # the first dimension without ghosts
```
I prefer this method.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
dpgrote and pre-commit-ci[bot] authored Oct 10, 2024
1 parent 94a4714 commit 9c51d04
Show file tree
Hide file tree
Showing 3 changed files with 481 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/source/usage/compute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ This is how to iterate and potentially compute for all blocks assigned to a loca
:start-after: # Manual: Compute Mfab Detailed START
:end-before: # Manual: Compute Mfab Detailed END

.. tab-item:: Global

.. literalinclude:: ../../../tests/test_multifab.py
:language: python3
:dedent: 4
:start-after: # Manual: Compute Mfab Global START
:end-before: # Manual: Compute Mfab Global END


For a complete physics example that uses CPU/GPU agnostic Python code for computation on fields, see:

Expand Down
Loading

0 comments on commit 9c51d04

Please sign in to comment.