Skip to content

Commit

Permalink
Fill out min and max (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgrote authored Jul 22, 2023
1 parent b284984 commit b63a9e6
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions src/Base/MultiFab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
#include <memory>
#include <string>

namespace {
void check_comp(amrex::MultiFab const & mf, const int comp, std::string const name)
{
if (comp < 0 || comp >= mf.nComp())
throw py::index_error("MultiFab::" + name + " comp out of bounds");
}
void check_nghost(amrex::MultiFab const & mf, const int nghost, std::string const name)
{
if (nghost < 0 || nghost > mf.nGrowVect().min())
throw py::index_error("MultiFab::" + name + " nghost out of bounds");
}
}

void init_MultiFab(py::module &m)
{
Expand Down Expand Up @@ -229,18 +241,38 @@ void init_MultiFab(py::module &m)

/* sizes, etc. */
.def("min",
[](MultiFab const & mf, int comp) { return mf.min(comp); })
.def("min",
py::overload_cast< int, int, bool >(&MultiFab::min, py::const_))
[](MultiFab const & mf, int comp, int nghost, bool local) {
check_comp(mf, comp, "min");
check_nghost(mf, nghost, "min");
return mf.min(comp, nghost, local); },
py::arg("comp") = 0, py::arg("nghost") = 0, py::arg("local") = false,
"Returns the minimum value of the specfied component of the MultiFab."
)
.def("min",
py::overload_cast< Box const &, int, int, bool >(&MultiFab::min, py::const_))
[](MultiFab const & mf, Box const & region, int comp, int nghost, bool local) {
check_comp(mf, comp, "min");
check_nghost(mf, nghost, "min");
return mf.min(region, comp, nghost, local); },
py::arg("region"), py::arg("comp") = 0, py::arg("nghost") = 0, py::arg("local") = false,
"Returns the minimum value of the specfied component of the MultiFab over the region."
)

.def("max",
[](MultiFab const & mf, int comp) { return mf.max(comp); })
.def("max",
py::overload_cast< int, int, bool >(&MultiFab::max, py::const_))
[](MultiFab const & mf, int comp, int nghost, bool local) {
check_comp(mf, comp, "max");
check_nghost(mf, nghost, "max");
return mf.max(comp, nghost, local); },
py::arg("comp") = 0, py::arg("nghost") = 0, py::arg("local") = false,
"Returns the maximum value of the specfied component of the MultiFab."
)
.def("max",
py::overload_cast< Box const &, int, int, bool >(&MultiFab::max, py::const_))
[](MultiFab const & mf, Box const & region, int comp, int nghost, bool local) {
check_comp(mf, comp, "max");
check_nghost(mf, nghost, "max");
return mf.max(region, comp, nghost, local); },
py::arg("region"), py::arg("comp") = 0, py::arg("nghost") = 0, py::arg("local") = false,
"Returns the maximum value of the specfied component of the MultiFab over the region."
)

.def("minIndex", &MultiFab::minIndex)
.def("maxIndex", &MultiFab::maxIndex)
Expand Down

0 comments on commit b63a9e6

Please sign in to comment.