Skip to content

Commit

Permalink
MultiFab: Iterate via Array4
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Mar 9, 2022
1 parent e524ba9 commit 24584b0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/Base/MultiFab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ void init_MultiFab(py::module &m) {
.def("is_nodal",
py::overload_cast< int >(&FabArrayBase::is_nodal, py::const_))

.def_property_readonly("nComp", &FabArrayBase::nComp)
.def_property_readonly("num_comp", &FabArrayBase::nComp)
.def_property_readonly("size", &FabArrayBase::size)
;

py::class_< FArrayBox >(m, "FArrayBox");

py::class_< FabArray<FArrayBox>, FabArrayBase >(m, "FabArray_FArrayBox");

//py::class_< MFIterWrapper >(m, "MFIterWrapper");
py::class_< MFIter >(m, "MFIter")
.def("__repr__",
Expand Down Expand Up @@ -94,6 +94,13 @@ void init_MultiFab(py::module &m) {
*/
;

py::class_< FabArray<FArrayBox>, FabArrayBase >(m, "FabArray_FArrayBox")
//.def("array", py::overload_cast< const MFIter& >(&FabArray<FArrayBox>::array))
//.def("const_array", &FabArray<FArrayBox>::const_array)
.def("array", [](FabArray<FArrayBox> & fa, MFIter const & mfi) {return fa.array(mfi);})
.def("const_array", [](FabArray<FArrayBox> & fa, MFIter const & mfi) {return fa.const_array(mfi);})
;

py::class_< MultiFab, FabArray<FArrayBox> >(m, "MultiFab")
.def("__repr__",
[](MultiFab const & mf) {
Expand Down
29 changes: 22 additions & 7 deletions tests/test_multifab.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,28 @@ def test_mfab_loop(mfab, nghost):
for mfi in mfab:
print(mfi)
bx = mfi.tilebox()
#marr = mfab.array(mfi) # Array4: add __array_interface__ here

#for i, j, k in bx:
# mar[i, j, k, 0] = 10.0 * i
# mar[i, j, k, 1] = 10.0 * j
# mar[i, j, k, 2] = 10.0 * k
# print(i,j,k)
marr = mfab.array(mfi) # Array4: add __array_interface__ here

print(mfab)
print(mfab.num_comp)
print(mfab.size)
print(marr.size)
print(marr.nComp)

# slow, index by index assignment
for i, j, k in bx:
#print(i,j,k)
marr[i, j, k] = 10.0 * i
#marr[i, j, k, 0] = 10.0 * i
#marr[i, j, k, 1] = 10.0 * j
#marr[i, j, k, 2] = 10.0 * k

# fast, range based assignment
# TODO

# challenge: offset from our index space for...
# extra test: numpy assignment
# extra test: cupy assignment


def test_mfab_simple(mfab):
Expand Down

0 comments on commit 24584b0

Please sign in to comment.