Skip to content
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

MultiFab: Overload += *= /=, etc. #372

Open
ax3l opened this issue Oct 1, 2024 · 3 comments
Open

MultiFab: Overload += *= /=, etc. #372

ax3l opened this issue Oct 1, 2024 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ax3l
Copy link
Member

ax3l commented Oct 1, 2024

For pyAMReX' MultiFab, we can overload the operators += *= /=, etc. to call the underlying optimized, element-wise AMReX functions.

Similar for [...] and other set-all ellipsis, we should specialize to AMReX' setVal.

@RemiLehe @roelof-groenewald @dpgrote @atmyers et al.: should we always operate on valid and guard cells for those?

@ax3l ax3l added the enhancement New feature or request label Oct 1, 2024
@ax3l
Copy link
Member Author

ax3l commented Oct 1, 2024

If have the feeling, if we implemented #370 guards via mf.grow() / mf.with_guard_cells() then we would also have a clear answer for the guard/non-guard question here.

mf = MultiFab()  # from somewhere
mf *= 2.  # on valid cells

mf.with_guard_cells()
mf *= 2.0  # on valid and guard cells

@ax3l
Copy link
Member Author

ax3l commented Oct 1, 2024

@roelof-groenewald mentioned today that including guard cells by default is sensible for all but depositions.

@ax3l ax3l added the help wanted Extra attention is needed label Oct 1, 2024
@ax3l
Copy link
Member Author

ax3l commented Oct 3, 2024

We are looking to in-place update the value of each cell, in each component, including guard cells.
For that, we would implement:

  • __iadd__(self, v)
  • __isub__(self, v)
  • __imul__(self, v)
  • __itruediv__(self, v)
  • __ifloordiv__(self, v) (for //=)
  • __imod__(self, v) (for %)
  • __ipow__(self, v)

Example:

        .def("__iadd__",
             [](MultiFab & self, amrex::Real v) { /* ... */ },
             py::is_operator(),
             "Adds in-place to the value of each cell, in each component, including guard cells."
        )

We need to implement scalar and other multifabs for v.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant