Skip to content

Commit

Permalink
BoxArray: From List of Boxes (#406)
Browse files Browse the repository at this point in the history
Add a contructor to create a `BoxArray` from a list of `Box`es.

Close #396
  • Loading branch information
ax3l authored Jan 23, 2025
1 parent 7697686 commit f115b24
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/hip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ jobs:
export CXX=$(which clang++)
export CC=$(which clang)
python3 -m pip install -U pip importlib_metadata launchpadlib setuptools wheel
python3 -m pip install -U pip
python3 -m pip install -U build packaging setuptools[core] wheel
python3 -m pip install -U cmake
# "mpic++ --showme" forgets open-pal in Ubuntu 20.04 + OpenMPI 4.0.3
Expand Down
26 changes: 12 additions & 14 deletions src/Base/BoxArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,23 @@ void init_BoxArray(py::module &m) {
}
)

//! Construct an empty BoxArray
// Construct an empty BoxArray
.def(py::init<>())
//.def(py::init< BoxArray const& >())
//.def(py::init< BoxArray const&& >())
// Copy a BoxArray
.def(py::init< BoxArray const & >())

//! Construct a BoxArray from an array of Boxes of size nbox.
// Construct a BoxArray from a single Box.
.def(py::init< Box const & >())
//! Construct a BoxArray from an array of Boxes of size nbox.
.def(py::init< const Box*, int >())
// Construct a BoxArray from a list of Boxes.
.def(py::init([](Vector<Box> bl) {
return BoxArray(bl.dataPtr(), bl.size());
}))

/*
//! Construct a BoxArray from a BoxList.
explicit BoxArray (const BoxList& bl);
explicit BoxArray (BoxList&& bl) noexcept;
// Construct a BoxArray from a BoxList.
//.def(py::init< BoxList const& >())

BoxArray (const BoxArray& rhs, const BATransformer& trans);
BoxArray (BoxList&& bl, IntVect const& max_grid_size);
*/
//BoxArray (const BoxArray& rhs, const BATransformer& trans);
//BoxArray (BoxList&& bl, IntVect const& max_grid_size);

.def_property_readonly("size", &BoxArray::size)
.def_property_readonly("capacity", &BoxArray::capacity)
Expand Down
2 changes: 2 additions & 0 deletions src/Base/Vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "Base/Vector.H"

#include <AMReX_Box.H>
#include <AMReX_Vector.H>

#include <string>
Expand All @@ -25,5 +26,6 @@ void init_Vector(py::module& m)
if constexpr(!std::is_same_v<int, Long>)
make_Vector<Long> (m, "Long");

make_Vector<Box> (m, "Box");
make_Vector<std::string> (m, "string");
}
2 changes: 1 addition & 1 deletion src/pyAMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ PYBIND11_MODULE(amrex_3d_pybind, m) {
init_Periodicity(m);
init_Array4(m);
init_SmallMatrix(m);
init_Vector(m);
init_BoxArray(m);
init_ParmParse(m);
init_CoordSys(m);
init_RealBox(m);
init_Vector(m);
init_Geometry(m);
init_DistributionMapping(m);
init_BaseFab(m);
Expand Down
39 changes: 39 additions & 0 deletions tests/test_boxarray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-

import amrex.space3d as amr


def test_boxarray(std_box):
ba = amr.BoxArray(std_box)

assert ba.size == 1
ba.max_size(32)
assert ba.size == 8

assert not ba.empty
assert ba.numPts == 64**3


def test_boxarray_empty():
ba = amr.BoxArray()

assert ba.size == 0
assert ba.empty
assert ba.numPts == 0


def test_boxarray_list():
bx_1 = amr.Box(amr.IntVect(0, 0, 0), amr.IntVect(31, 31, 31))
bx_2 = amr.Box(amr.IntVect(32, 32, 32), amr.IntVect(63, 63, 63))
bx_3 = amr.Box(amr.IntVect(64, 64, 64), amr.IntVect(95, 95, 95))

box_list = amr.Vector_Box([bx_1, bx_2, bx_3])
ba = amr.BoxArray(box_list)
print(ba)

assert ba.size == 3
assert not ba.empty
assert ba.numPts == 98304

print(ba.d_numPts)
print(ba.ix_type())

0 comments on commit f115b24

Please sign in to comment.