From 7e4e7f335879b73a89a3ffee242351a7592313af Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 24 Apr 2024 19:53:41 -0700 Subject: [PATCH] `MultiFab`: Static to Member Math Methods Replace `static` member functions that with regular member functions that take store the result/destination in `self`. --- src/Base/MultiFab.cpp | 74 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/src/Base/MultiFab.cpp b/src/Base/MultiFab.cpp index b86d26ff..875450ee 100644 --- a/src/Base/MultiFab.cpp +++ b/src/Base/MultiFab.cpp @@ -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 &, Real, FabArray const &, int, int, int, IntVect const & >(&FabArray::template Saxpy), - 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 &, Real, FabArray const &, int, int, int, IntVect const & >(&FabArray::template Xpay), - 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 &, Real, FabArray const &, int, Real, FabArray const &, int, int, int, IntVect const & >(&FabArray::template LinComb), - py::arg("dst"), + .def("saxpy", + [](FabArray & dst, Real a, FabArray const & x, int x_comp, int dst_comp, int ncomp, IntVect const & nghost) + { + FabArray::Saxpy(dst, a, x, x_comp, dst_comp, ncomp, nghost); + }, + py::arg("a"), py::arg("x"), py::arg("x_comp"), py::arg("dst_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" + "dst_comp : starting component of y\n" + "ncomp : number of components\n" + "nghost : number of ghost cells" + ) + .def("xpay", + [](FabArray & dst, Real a, FabArray const & x, int x_comp, int dst_comp, int ncomp, IntVect const & nghost) + { + FabArray::Xpay(dst, a, x, x_comp, dst_comp, ncomp, nghost); + }, + py::arg("a"), py::arg("x"), py::arg("xcomp"), py::arg("dst_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" + "dst_comp : starting component of y\n" + "ncomp : number of components\n" + "nghost : number of ghost cells" + ) + .def("lin_comb", + []( + FabArray & dst, + Real a, FabArray const & x, int x_comp, + Real b, FabArray const & y, int y_comp, + int dst_comp, int ncomp, IntVect const & nghost) + { + FabArray::LinComb(dst, a, x, x_comp, b, y, y_comp, dst_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" + "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" + "dstcomp : int\n" + " starting component of destination\n" + "numcomp : int\n" + " number of components\n" + "nghost : int\n" + " number of ghost cells" ) .def("sum",