Skip to content

Commit

Permalink
Add overload for sum_unique (#293)
Browse files Browse the repository at this point in the history
* Update amrex dependency
* Add overload for sum_unique
* Add `sum` overloads

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
  • Loading branch information
RemiLehe and ax3l authored Apr 11, 2024
1 parent 00ffe7c commit 173d739
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cmake/dependencies/AMReX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ option(pyAMReX_amrex_internal "Download & build AMReX" ON)
set(pyAMReX_amrex_repo "https://github.com/AMReX-Codes/amrex.git"
CACHE STRING
"Repository URI to pull and build AMReX from if(pyAMReX_amrex_internal)")
set(pyAMReX_amrex_branch "24.04"
set(pyAMReX_amrex_branch "6c6247554f270a379177ac1453fcfe117b1967ca"
CACHE STRING
"Repository branch for pyAMReX_amrex_repo if(pyAMReX_amrex_internal)")

Expand Down
54 changes: 36 additions & 18 deletions src/Base/MultiFab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,22 @@ void init_MultiFab(py::module &m)
"each FAB in the FabArray, starting at component comp to val.\n"
"Also set the value of nghost boundary cells."
)
.def("set_val",
py::overload_cast< amrex::Real, Box const &, int, int, int >(&FabArray<FArrayBox>::setVal<FArrayBox>),
py::arg("val"), py::arg("region"), py::arg("comp"), py::arg("num_comp"), py::arg("nghost")=0,
"Set the value of num_comp components in the valid region of\n"
"each FAB in the FabArray, starting at component comp, as well\n"
"as nghost boundary cells, to val, provided they also intersect\n"
"with the Box region."
)
.def("set_val",
py::overload_cast< amrex::Real, Box const &, int, int, IntVect const & >(&FabArray<FArrayBox>::setVal<FArrayBox>),
py::arg("val"), py::arg("region"), py::arg("comp"), py::arg("num_comp"), py::arg("nghost"),
"Set the value of num_comp components in the valid region of\n"
"each FAB in the FabArray, starting at component comp, as well\n"
"as nghost boundary cells, to val, provided they also intersect\n"
"with the Box region."
)
.def("set_val",
py::overload_cast< amrex::Real, Box const &, int, int, int >(&FabArray<FArrayBox>::setVal<FArrayBox>),
py::arg("val"), py::arg("region"), py::arg("comp"), py::arg("num_comp"), py::arg("nghost")=0,
"Set the value of num_comp components in the valid region of\n"
"each FAB in the FabArray, starting at component comp, as well\n"
"as nghost boundary cells, to val, provided they also intersect\n"
"with the Box region."
)
.def("set_val",
py::overload_cast< amrex::Real, Box const &, int, int, IntVect const & >(&FabArray<FArrayBox>::setVal<FArrayBox>),
py::arg("val"), py::arg("region"), py::arg("comp"), py::arg("num_comp"), py::arg("nghost"),
"Set the value of num_comp components in the valid region of\n"
"each FAB in the FabArray, starting at component comp, as well\n"
"as nghost boundary cells, to val, provided they also intersect\n"
"with the Box region."
)

.def("abs", py::overload_cast< int, int, int >(&FabArray<FArrayBox>::abs<FArrayBox>),
py::arg("comp"), py::arg("ncomp"), py::arg("nghost")=0
Expand Down Expand Up @@ -507,19 +507,37 @@ void init_MultiFab(py::module &m)
.def("norm2", py::overload_cast< Vector<int> const & >(&MultiFab::norm2, py::const_))

/* simple math */

.def("sum",
//py::overload_cast< int, bool >(&MultiFab::sum, py::const_),
// py::overload_cast< int, bool >(&MultiFab::sum, py::const_),
[](MultiFab const & mf, int comp , bool local) { return mf.sum(comp, local); },
py::arg("comp") = 0, py::arg("local") = false,
"Returns the sum of component 'comp' over the MultiFab -- no ghost cells are included."
)
.def("sum_unique", &MultiFab::sum_unique,
.def("sum",
// py::overload_cast< Box const &, int, bool >(&MultiFab::sum, py::const_),
[](MultiFab const & mf, Box const & region, int comp , bool local) { return mf.sum(region, comp, local); },
py::arg("region"), py::arg("comp") = 0, py::arg("local") = false,
"Returns the sum of component 'comp' in the given 'region'. -- no ghost cells are included."
)
.def("sum_unique",
py::overload_cast< int, bool, Periodicity const& >(&MultiFab::sum_unique, py::const_),
py::arg("comp") = 0,
py::arg("local") = false,
py::arg_v("period", Periodicity::NonPeriodic(), "Periodicity.non_periodic()"),
"Same as sum with local=false, but for non-cell-centered data, this"
"skips non-unique points that are owned by multiple boxes."
)
.def("sum_unique",
py::overload_cast< Box const&, int, bool >(&MultiFab::sum_unique, py::const_),
py::arg("region"),
py::arg("comp") = 0,
py::arg("local") = false,
"Returns the unique sum of component `comp` in the given "
"region. Non-unique points owned by multiple boxes in the MultiFab are"
"only added once. No ghost cells are included. This function does not take"
"periodicity into account in the determination of uniqueness of points."
)

.def("plus",
py::overload_cast< Real, int >(&MultiFab::plus),
Expand Down

0 comments on commit 173d739

Please sign in to comment.