Skip to content

Commit f115b24

Browse files
authored
BoxArray: From List of Boxes (#406)
Add a contructor to create a `BoxArray` from a list of `Box`es. Close #396
1 parent 7697686 commit f115b24

File tree

5 files changed

+56
-16
lines changed

5 files changed

+56
-16
lines changed

.github/workflows/hip.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ jobs:
4242
export CXX=$(which clang++)
4343
export CC=$(which clang)
4444
45-
python3 -m pip install -U pip importlib_metadata launchpadlib setuptools wheel
45+
python3 -m pip install -U pip
46+
python3 -m pip install -U build packaging setuptools[core] wheel
4647
python3 -m pip install -U cmake
4748
4849
# "mpic++ --showme" forgets open-pal in Ubuntu 20.04 + OpenMPI 4.0.3

src/Base/BoxArray.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,23 @@ void init_BoxArray(py::module &m) {
2929
}
3030
)
3131

32-
//! Construct an empty BoxArray
32+
// Construct an empty BoxArray
3333
.def(py::init<>())
34-
//.def(py::init< BoxArray const& >())
35-
//.def(py::init< BoxArray const&& >())
34+
// Copy a BoxArray
35+
.def(py::init< BoxArray const & >())
3636

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

42-
/*
43-
//! Construct a BoxArray from a BoxList.
44-
explicit BoxArray (const BoxList& bl);
45-
explicit BoxArray (BoxList&& bl) noexcept;
44+
// Construct a BoxArray from a BoxList.
45+
//.def(py::init< BoxList const& >())
4646

47-
BoxArray (const BoxArray& rhs, const BATransformer& trans);
48-
49-
BoxArray (BoxList&& bl, IntVect const& max_grid_size);
50-
*/
47+
//BoxArray (const BoxArray& rhs, const BATransformer& trans);
48+
//BoxArray (BoxList&& bl, IntVect const& max_grid_size);
5149

5250
.def_property_readonly("size", &BoxArray::size)
5351
.def_property_readonly("capacity", &BoxArray::capacity)

src/Base/Vector.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "Base/Vector.H"
99

10+
#include <AMReX_Box.H>
1011
#include <AMReX_Vector.H>
1112

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

29+
make_Vector<Box> (m, "Box");
2830
make_Vector<std::string> (m, "string");
2931
}

src/pyAMReX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ PYBIND11_MODULE(amrex_3d_pybind, m) {
102102
init_Periodicity(m);
103103
init_Array4(m);
104104
init_SmallMatrix(m);
105+
init_Vector(m);
105106
init_BoxArray(m);
106107
init_ParmParse(m);
107108
init_CoordSys(m);
108109
init_RealBox(m);
109-
init_Vector(m);
110110
init_Geometry(m);
111111
init_DistributionMapping(m);
112112
init_BaseFab(m);

tests/test_boxarray.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import amrex.space3d as amr
4+
5+
6+
def test_boxarray(std_box):
7+
ba = amr.BoxArray(std_box)
8+
9+
assert ba.size == 1
10+
ba.max_size(32)
11+
assert ba.size == 8
12+
13+
assert not ba.empty
14+
assert ba.numPts == 64**3
15+
16+
17+
def test_boxarray_empty():
18+
ba = amr.BoxArray()
19+
20+
assert ba.size == 0
21+
assert ba.empty
22+
assert ba.numPts == 0
23+
24+
25+
def test_boxarray_list():
26+
bx_1 = amr.Box(amr.IntVect(0, 0, 0), amr.IntVect(31, 31, 31))
27+
bx_2 = amr.Box(amr.IntVect(32, 32, 32), amr.IntVect(63, 63, 63))
28+
bx_3 = amr.Box(amr.IntVect(64, 64, 64), amr.IntVect(95, 95, 95))
29+
30+
box_list = amr.Vector_Box([bx_1, bx_2, bx_3])
31+
ba = amr.BoxArray(box_list)
32+
print(ba)
33+
34+
assert ba.size == 3
35+
assert not ba.empty
36+
assert ba.numPts == 98304
37+
38+
print(ba.d_numPts)
39+
print(ba.ix_type())

0 commit comments

Comments
 (0)