diff --git a/.github/workflows/hip.yml b/.github/workflows/hip.yml index abcacaa1..9920751b 100644 --- a/.github/workflows/hip.yml +++ b/.github/workflows/hip.yml @@ -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 diff --git a/src/Base/BoxArray.cpp b/src/Base/BoxArray.cpp index a6b57d87..72b64781 100644 --- a/src/Base/BoxArray.cpp +++ b/src/Base/BoxArray.cpp @@ -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 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) diff --git a/src/Base/Vector.cpp b/src/Base/Vector.cpp index 04337848..ecac1905 100644 --- a/src/Base/Vector.cpp +++ b/src/Base/Vector.cpp @@ -7,6 +7,7 @@ #include "Base/Vector.H" +#include #include #include @@ -25,5 +26,6 @@ void init_Vector(py::module& m) if constexpr(!std::is_same_v) make_Vector (m, "Long"); + make_Vector (m, "Box"); make_Vector (m, "string"); } diff --git a/src/pyAMReX.cpp b/src/pyAMReX.cpp index 226a4989..fd241527 100644 --- a/src/pyAMReX.cpp +++ b/src/pyAMReX.cpp @@ -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); diff --git a/tests/test_boxarray.py b/tests/test_boxarray.py new file mode 100644 index 00000000..efced586 --- /dev/null +++ b/tests/test_boxarray.py @@ -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())