Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoxArray: From List of Boxes #406

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
}
)

//! 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);
Comment on lines +47 to +48

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

.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())
Loading