Skip to content

Commit

Permalink
MultiFab: Static to Member Math Methods
Browse files Browse the repository at this point in the history
Replace `static` member functions that with regular member functions
that take store the result/destination in `self`.
  • Loading branch information
ax3l committed Jan 28, 2025
1 parent 8e46613 commit 05400d0
Showing 1 changed file with 153 additions and 79 deletions.
232 changes: 153 additions & 79 deletions src/Base/MultiFab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,23 +215,69 @@ void init_MultiFab(py::module &m)
py::arg("comp"), py::arg("ncomp"), py::arg("nghost")
)

.def_static("saxpy",
py::overload_cast< FabArray<FArrayBox> &, Real, FabArray<FArrayBox> const &, int, int, int, IntVect const & >(&FabArray<FArrayBox>::template Saxpy<FArrayBox>),
py::arg("y"), py::arg("a"), py::arg("x"), py::arg("xcomp"), py::arg("ycomp"), py::arg("ncomp"), py::arg("nghost"),
"y += a*x"
)
.def_static("xpay",
py::overload_cast< FabArray<FArrayBox> &, Real, FabArray<FArrayBox> const &, int, int, int, IntVect const & >(&FabArray<FArrayBox>::template Xpay<FArrayBox>),
py::arg("y"), py::arg("a"), py::arg("x"), py::arg("xcomp"), py::arg("ycomp"), py::arg("ncomp"), py::arg("nghost"),
"y = x + a*y"
)
.def_static("lin_comb",
py::overload_cast< FabArray<FArrayBox> &, Real, FabArray<FArrayBox> const &, int, Real, FabArray<FArrayBox> const &, int, int, int, IntVect const & >(&FabArray<FArrayBox>::template LinComb<FArrayBox>),
py::arg("dst"),
.def("saxpy",
[](FabArray<FArrayBox> & dst, Real a, FabArray<FArrayBox> const & x, int x_comp, int self_comp, int ncomp, IntVect const & nghost)
{
FabArray<FArrayBox>::Saxpy(dst, a, x, x_comp, self_comp, ncomp, nghost);
},
py::arg("a"), py::arg("x"), py::arg("x_comp"), py::arg("self_comp"), py::arg("ncomp"), py::arg("nghost"),
"self += a*x\n\n"
"Parameters\n"
"----------\n"
"a : scalar a\n"
"x : FabArray x\n"
"x_comp : starting component of x\n"
"self_comp : starting component of y\n"
"ncomp : number of components\n"
"nghost : number of ghost cells"
)
.def("xpay",
[](FabArray<FArrayBox> & dst, Real a, FabArray<FArrayBox> const & x, int x_comp, int self_comp, int ncomp, IntVect const & nghost)
{
FabArray<FArrayBox>::Xpay(dst, a, x, x_comp, self_comp, ncomp, nghost);
},
py::arg("a"), py::arg("x"), py::arg("xcomp"), py::arg("self_comp"), py::arg("ncomp"), py::arg("nghost"),
"self = x + a*self\n\n"
"Parameters\n"
"----------\n"
"a : scalar a\n"
"x : FabArray x\n"
"x_comp : starting component of x\n"
"self_comp : starting component of y\n"
"ncomp : number of components\n"
"nghost : number of ghost cells"
)
.def("lin_comb",
[](
FabArray<FArrayBox> & dst,
Real a, FabArray<FArrayBox> const & x, int x_comp,
Real b, FabArray<FArrayBox> const & y, int y_comp,
int self_comp, int ncomp, IntVect const & nghost)
{
FabArray<FArrayBox>::LinComb(dst, a, x, x_comp, b, y, y_comp, self_comp, ncomp, nghost);
},
py::arg("a"), py::arg("x"), py::arg("xcomp"),
py::arg("b"), py::arg("y"), py::arg("ycomp"),
py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"dst = a*x + b*y"
py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"self = a*x + b*y\n\n"
"Parameters\n"
"----------\n"
"a : float\n"
" scalar a\n"
"x : FabArray\n"
"xcomp : int\n"
" starting component of x\n"
"b : float\n"
" scalar b\n"
"y : FabArray\n"
"ycomp : int\n"
" starting component of y\n"
"self_comp : int\n"
" starting component of destination\n"
"numcomp : int\n"
" number of components\n"
"nghost : int\n"
" number of ghost cells"
)

.def("sum",
Expand Down Expand Up @@ -745,108 +791,136 @@ void init_MultiFab(py::module &m)
)
//.def_static("dot", py::overload_cast< iMultiFab const&, const MultiFab&, int, MultiFab const&, int, int, int, bool >(&MultiFab::Dot))

.def_static("add",
py::overload_cast< MultiFab &, MultiFab const &, int, int, int, int >(&MultiFab::Add),
py::arg("dst"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"Add src to dst including nghost ghost cells.\n"
.def("add",
[](MultiFab & self, MultiFab const & src, int srccomp, int self_comp, int numcomp, int nghost) {
MultiFab::Add(self, src, srccomp, self_comp, numcomp, nghost);
},
py::arg("src"), py::arg("srccomp"), py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"Add src to self including nghost ghost cells.\n"
"The two MultiFabs MUST have the same underlying BoxArray."
)
.def_static("add",
py::overload_cast< MultiFab &, MultiFab const &, int, int, int, IntVect const & >(&MultiFab::Add),
py::arg("dst"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"Add src to dst including nghost ghost cells.\n"
.def("add",
[](MultiFab & self, MultiFab const & src, int srccomp, int self_comp, int numcomp, IntVect const & nghost) {
MultiFab::Add(self, src, srccomp, self_comp, numcomp, nghost);
},
py::arg("src"), py::arg("srccomp"), py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"Add src to self including nghost ghost cells.\n"
"The two MultiFabs MUST have the same underlying BoxArray."
)

.def_static("subtract",
py::overload_cast< MultiFab &, MultiFab const &, int, int, int, int >(&MultiFab::Subtract),
py::arg("dst"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"Subtract src from dst including nghost ghost cells.\n"
.def("subtract",
[](MultiFab & self, MultiFab const & src, int srccomp, int self_comp, int numcomp, int nghost) {
MultiFab::Subtract(self, src, srccomp, self_comp, numcomp, nghost);
},
py::arg("src"), py::arg("srccomp"), py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"Subtract src from self including nghost ghost cells.\n"
"The two MultiFabs MUST have the same underlying BoxArray."
)
.def_static("subtract",
py::overload_cast< MultiFab &, MultiFab const &, int, int, int, IntVect const & >(&MultiFab::Subtract),
py::arg("dst"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"Subtract src from dst including nghost ghost cells.\n"
.def("subtract",
[](MultiFab & self, MultiFab const & src, int srccomp, int self_comp, int numcomp, IntVect const & nghost) {
MultiFab::Subtract(self, src, srccomp, self_comp, numcomp, nghost);
},
py::arg("src"), py::arg("srccomp"), py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"Subtract src from self including nghost ghost cells.\n"
"The two MultiFabs MUST have the same underlying BoxArray."
)

.def_static("multiply",
py::overload_cast< MultiFab &, MultiFab const &, int, int, int, int >(&MultiFab::Multiply),
py::arg("dst"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"Multiply dst by src including nghost ghost cells.\n"
.def("multiply",
[](MultiFab & self, MultiFab const & src, int srccomp, int self_comp, int numcomp, int nghost) {
MultiFab::Multiply(self, src, srccomp, self_comp, numcomp, nghost);
},
py::arg("src"), py::arg("srccomp"), py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"Multiply self by src including nghost ghost cells.\n"
"The two MultiFabs MUST have the same underlying BoxArray."
)
.def_static("multiply",
py::overload_cast< MultiFab &, MultiFab const &, int, int, int, IntVect const & >(&MultiFab::Multiply),
py::arg("dst"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"Multiply dst by src including nghost ghost cells.\n"
.def("multiply",
[](MultiFab & self, MultiFab const & src, int srccomp, int self_comp, int numcomp, IntVect const & nghost) {
MultiFab::Multiply(self, src, srccomp, self_comp, numcomp, nghost);
},
py::arg("src"), py::arg("srccomp"), py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"Multiply self by src including nghost ghost cells.\n"
"The two MultiFabs MUST have the same underlying BoxArray."
)

.def_static("divide",
py::overload_cast< MultiFab &, MultiFab const &, int, int, int, int >(&MultiFab::Divide),
py::arg("dst"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"Divide dst by src including nghost ghost cells.\n"
.def("divide",
[](MultiFab & self, MultiFab const & src, int srccomp, int self_comp, int numcomp, int nghost) {
MultiFab::Divide(self, src, srccomp, self_comp, numcomp, nghost);
},
py::arg("src"), py::arg("srccomp"), py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"Divide self by src including nghost ghost cells.\n"
"The two MultiFabs MUST have the same underlying BoxArray."
)
.def_static("divide",
py::overload_cast< MultiFab &, MultiFab const &, int, int, int, IntVect const & >(&MultiFab::Divide),
py::arg("dst"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"Divide dst by src including nghost ghost cells.\n"
.def("divide",
[](MultiFab & self, MultiFab const & src, int srccomp, int self_comp, int numcomp, IntVect const & nghost) {
MultiFab::Divide(self, src, srccomp, self_comp, numcomp, nghost);
},
py::arg("src"), py::arg("srccomp"), py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"Divide self by src including nghost ghost cells.\n"
"The two MultiFabs MUST have the same underlying BoxArray."
)

.def_static("swap",
py::overload_cast< MultiFab &, MultiFab &, int, int, int, int >(&MultiFab::Swap),
py::arg("dst"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"Swap from src to dst including nghost ghost cells.\n"
.def("swap",
[](MultiFab & self, MultiFab & src, int srccomp, int self_comp, int numcomp, int nghost) {
MultiFab::Swap(self, src, srccomp, self_comp, numcomp, nghost);
},
py::arg("src"), py::arg("srccomp"), py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"Swap from src to self including nghost ghost cells.\n"
"The two MultiFabs MUST have the same underlying BoxArray.\n"
"The swap is local."
)
.def_static("swap",
py::overload_cast< MultiFab &, MultiFab &, int, int, int, IntVect const & >(&MultiFab::Swap),
py::arg("dst"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"Swap from src to dst including nghost ghost cells.\n"
.def("swap",
[](MultiFab & self, MultiFab & src, int srccomp, int self_comp, int numcomp, IntVect const & nghost) {
MultiFab::Swap(self, src, srccomp, self_comp, numcomp, nghost);
},
py::arg("src"), py::arg("srccomp"), py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"Swap from src to self including nghost ghost cells.\n"
"The two MultiFabs MUST have the same underlying BoxArray.\n"
"The swap is local."
)

.def_static("saxpy",
// py::overload_cast< MultiFab &, Real, MultiFab const &, int, int, int, int >(&MultiFab::Saxpy)
static_cast<void (*)(MultiFab &, Real, MultiFab const &, int, int, int, int)>(&MultiFab::Saxpy),
py::arg("dst"), py::arg("a"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"dst += a*src"
.def("saxpy",
[](MultiFab & self, Real a, MultiFab const & src, int srccomp, int self_comp, int numcomp, int nghost) {
MultiFab::Saxpy(self, a, src, srccomp, self_comp, numcomp, nghost);
},
py::arg("a"), py::arg("src"), py::arg("srccomp"), py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"self += a * src"
)

.def_static("xpay",
// py::overload_cast< MultiFab &, Real, MultiFab const &, int, int, int, int >(&MultiFab::Xpay)
static_cast<void (*)(MultiFab &, Real, MultiFab const &, int, int, int, int)>(&MultiFab::Xpay),
py::arg("dst"), py::arg("a"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"dst = src + a*dst"
.def("xpay",
[](MultiFab & self, Real a, MultiFab const & src, int srccomp, int self_comp, int numcomp, int nghost) {
MultiFab::Xpay(self, a, src, srccomp, self_comp, numcomp, nghost);
},
py::arg("a"), py::arg("src"), py::arg("srccomp"), py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"self = src + a * self"
)

.def_static("lin_comb",
// py::overload_cast< MultiFab &, Real, MultiFab const &, int, Real, MultiFab const &, int, int, int, int >(&MultiFab::LinComb)
static_cast<void (*)(MultiFab &, Real, MultiFab const &, int, Real, MultiFab const &, int, int, int, int)>(&MultiFab::LinComb),
py::arg("dst"),
.def("lin_comb",
[](MultiFab & self, Real a, MultiFab const & x, int x_comp, Real b, MultiFab const & y, int y_comp, int self_comp, int numcomp, int nghost) {
MultiFab::LinComb(self, a, x, x_comp, b, y, y_comp, self_comp, numcomp, nghost);
},
py::arg("a"), py::arg("x"), py::arg("x_comp"),
py::arg("b"), py::arg("y"), py::arg("y_comp"),
py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"dst = a*x + b*y"
py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"self = a * x + b * y"
)

.def_static("add_product",
py::overload_cast< MultiFab &, MultiFab const &, int, MultiFab const &, int, int, int, int >(&MultiFab::AddProduct),
py::arg("dst"),
.def("add_product",
[](MultiFab & self, MultiFab const & src1, int comp1, MultiFab const & src2, int comp2, int self_comp, int numcomp, int nghost) {
MultiFab::AddProduct(self, src1, comp1, src2, comp2, self_comp, numcomp, nghost);
},
py::arg("src1"), py::arg("comp1"),
py::arg("src2"), py::arg("comp2"),
py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
"dst += src1*src2"
py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"self += src1 * src2"
)
.def_static("add_product",
py::overload_cast< MultiFab &, MultiFab const &, int, MultiFab const &, int, int, int, IntVect const & >(&MultiFab::AddProduct),
"dst += src1*src2"
.def("add_product",
[](MultiFab & self, MultiFab const & src1, int comp1, MultiFab const & src2, int comp2, int self_comp, int numcomp, IntVect const & nghost) {
MultiFab::AddProduct(self, src1, comp1, src2, comp2, self_comp, numcomp, nghost);
},
py::arg("src1"), py::arg("comp1"),
py::arg("src2"), py::arg("comp2"),
py::arg("self_comp"), py::arg("numcomp"), py::arg("nghost"),
"self += src1 * src2"
)

/* simple data validity checks */
Expand Down

0 comments on commit 05400d0

Please sign in to comment.