Skip to content

Commit 4a5532e

Browse files
committed
Merge AMReX-Codes:development into EZoni:v25.05
2 parents b9188bf + 1005983 commit 4a5532e

File tree

13 files changed

+336
-37
lines changed

13 files changed

+336
-37
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
requires = [
33
"setuptools>=42",
44
"wheel",
5-
"cmake>=3.24.0,<4.0.0",
5+
"cmake>=3.24.0",
66
"packaging>=23",
77
]
88
build-backend = "setuptools.build_meta"

src/Base/BoxArray.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,30 +120,27 @@ void init_BoxArray(py::module &m) {
120120
//! \brief Grow each Box in the BoxArray on the high end
121121
//! by n_cell cells in the idir direction.
122122
BoxArray& growHi (int idir, int n_cell);
123-
//! \brief Apply surroundingNodes(Box) to each Box in BoxArray.
124-
//! See the documentation of Box for details.
125-
BoxArray& surroundingNodes ();
126-
//!
123+
*/
124+
127125
//! \brief Apply surroundingNodes(Box,int) to each Box in
128126
//! BoxArray. See the documentation of Box for details.
129-
BoxArray& surroundingNodes (int dir);
130-
*/
127+
.def("surroundingNodes",
128+
py::overload_cast<>(&BoxArray::surroundingNodes))
129+
.def("surroundingNodes",
130+
py::overload_cast<int>(&BoxArray::surroundingNodes))
131131

132132
//! Apply Box::enclosedCells() to each Box in the BoxArray.
133133
.def("enclosed_cells",
134134
py::overload_cast<>(&BoxArray::enclosedCells))
135135
.def("enclosed_cells",
136136
py::overload_cast<int>(&BoxArray::enclosedCells))
137137

138+
//! Convert nodality of each box in the BoxArray
139+
.def("convert",
140+
py::overload_cast< IndexType >(&BoxArray::convert))
141+
.def("convert",
142+
py::overload_cast< IntVect const &>(&BoxArray::convert))
138143
/*
139-
//! Apply Box::convert(IndexType) to each Box in the BoxArray.
140-
BoxArray& convert (IndexType typ);
141-
142-
BoxArray& convert (const IntVect& typ);
143-
144-
//! Apply function (*fp)(Box) to each Box in the BoxArray.
145-
BoxArray& convert (Box (*fp)(const Box&));
146-
147144
//! Apply Box::shift(int,int) to each Box in the BoxArray.
148145
BoxArray& shift (int dir, int nzones);
149146

src/Base/MultiFab.H

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,31 @@ factory :
493493
;
494494
}
495495

496+
py_MultiFab
497+
.def("copymf",
498+
[](T &self, T const &src, int srccomp, int dstcomp, int numcomp, int nghost) {
499+
T::Copy(self, src, srccomp, dstcomp, numcomp, nghost);
500+
},
501+
py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
502+
"Copy from src to self including nghost ghost cells.\n"
503+
"The two MultiFabs MUST have the same underlying BoxArray. The copy is local"
504+
)
505+
;
506+
507+
// TODO: Missing in iMultiFab https://github.com/AMReX-Codes/amrex/issues/4317
508+
if constexpr (std::is_same_v<T, MultiFab>) {
509+
py_MultiFab
510+
.def("copymf",
511+
[](T &self, T const &src, int srccomp, int dstcomp, int numcomp, IntVect const &nghost) {
512+
T::Copy(self, src, srccomp, dstcomp, numcomp, nghost);
513+
},
514+
py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"),
515+
"Copy from src to self including nghost ghost cells.\n"
516+
"The two MultiFabs MUST have the same underlying BoxArray. The copy is local"
517+
)
518+
;
519+
}
520+
496521
py_MultiFab
497522
.def("subtract",
498523
[](T & self, T const & src, int srccomp, int comp, int numcomp, int nghost) {

src/Base/MultiFab.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,5 @@ void init_MultiFab(py::module &m, py::class_< amrex::MFIter > & py_MFIter)
105105

106106
m.def("copy_mfab", py::overload_cast< MultiFab &, MultiFab const &, int, int, int, int >(&MultiFab::Copy), py::arg("dst"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"))
107107
.def("copy_mfab", py::overload_cast< MultiFab &, MultiFab const &, int, int, int, IntVect const & >(&MultiFab::Copy), py::arg("dst"), py::arg("src"), py::arg("srccomp"), py::arg("dstcomp"), py::arg("numcomp"), py::arg("nghost"));
108+
108109
}

src/Particle/ParticleContainer.cpp

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Copyright 2022 The AMReX Community
22
*
3-
* Authors: Ryan Sandberg, Axel Huebl
3+
* Authors: Ryan Sandberg, Axel Huebl, Andrew Myers
44
* License: BSD-3-Clause-LBNL
55
*/
66
#include "ParticleContainer.H"
@@ -14,21 +14,70 @@ namespace
1414
{
1515
using namespace amrex;
1616

17-
// Note - this function MUST be consistent with AMReX_Particle.H
18-
Long unpack_id (uint64_t idcpu) {
19-
Long r = 0;
17+
py::object pack_ids (py::array_t<uint64_t> idcpus,
18+
py::array_t<amrex::Long> ids)
19+
{
20+
if (idcpus.ndim() != 1) {
21+
throw std::runtime_error("Input should be 1-D NumPy array");
22+
}
23+
24+
auto buf = idcpus.request();
25+
auto buf2 = ids.request();
26+
if (buf.size != buf2.size) {
27+
throw std::runtime_error("sizes do not match!");
28+
}
29+
30+
int N = idcpus.shape()[0];
31+
for (int i = 0; i < N; i++) {
32+
uint64_t* idcpus_ptr = (uint64_t*) buf.ptr;
33+
amrex::Long* ids_ptr = (amrex::Long*) buf2.ptr;
34+
particle_impl::pack_id(idcpus_ptr[i], ids_ptr[i]);
35+
}
36+
return py::cast<py::none>(Py_None);
37+
}
2038

21-
uint64_t sign = idcpu >> 63; // extract leftmost sign bit
22-
uint64_t val = ((idcpu >> 24) & 0x7FFFFFFFFF); // extract next 39 id bits
39+
py::object pack_cpus (py::array_t<uint64_t> idcpus,
40+
py::array_t<int> cpus)
41+
{
42+
if (idcpus.ndim() != 1) {
43+
throw std::runtime_error("Input should be 1-D NumPy array");
44+
}
45+
46+
auto buf = idcpus.request();
47+
auto buf2 = cpus.request();
48+
if (buf.size != buf2.size) {
49+
throw std::runtime_error("sizes do not match!");
50+
}
51+
52+
int N = idcpus.shape()[0];
53+
for (int i = 0; i < N; i++) {
54+
uint64_t* idcpus_ptr = (uint64_t*) buf.ptr;
55+
int* cpus_ptr = (int*) buf2.ptr;
56+
particle_impl::pack_cpu(idcpus_ptr[i], cpus_ptr[i]);
57+
}
58+
return py::cast<py::none>(Py_None);
59+
}
2360

24-
Long lval = static_cast<Long>(val); // bc we take -
25-
r = (sign) ? lval : -lval;
26-
return r;
61+
Long unpack_id (uint64_t idcpu) {
62+
return particle_impl::unpack_id(idcpu);
2763
}
2864

29-
// Note - this function MUST be consistent with AMReX_Particle.H
3065
int unpack_cpu (uint64_t idcpu) {
31-
return static_cast<int>(idcpu & 0x00FFFFFF);
66+
return particle_impl::unpack_cpu(idcpu);
67+
}
68+
69+
uint64_t make_invalid (uint64_t idcpu) {
70+
particle_impl::make_invalid(idcpu);
71+
return idcpu;
72+
}
73+
74+
uint64_t make_valid (uint64_t idcpu) {
75+
particle_impl::make_valid(idcpu);
76+
return idcpu;
77+
}
78+
79+
bool is_valid (const uint64_t idcpu) {
80+
return particle_impl::is_valid(idcpu);
3281
}
3382
}
3483

@@ -61,6 +110,11 @@ void init_ParticleContainer(py::module& m) {
61110
init_ParticleContainer_WarpX(m);
62111

63112
// for particle idcpu arrays
113+
m.def("pack_ids", &pack_ids);
114+
m.def("pack_cpus", &pack_cpus);
64115
m.def("unpack_ids", py::vectorize(unpack_id));
65116
m.def("unpack_cpus", py::vectorize(unpack_cpu));
117+
m.def("make_invalid", make_invalid);
118+
m.def("make_valid", make_valid);
119+
m.def("is_valid", is_valid);
66120
}

src/amrex/space1d/__init__.pyi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,15 @@ from amrex.space1d.amrex_1d_pybind import (
294294
initialize,
295295
initialize_when_MPMD,
296296
initialized,
297+
is_valid,
297298
lbound,
298299
length,
300+
make_invalid,
301+
make_valid,
299302
max,
300303
min,
304+
pack_cpus,
305+
pack_ids,
301306
refine,
302307
size,
303308
ubound,
@@ -558,11 +563,16 @@ __all__ = [
558563
"initialize",
559564
"initialize_when_MPMD",
560565
"initialized",
566+
"is_valid",
561567
"lbound",
562568
"length",
569+
"make_invalid",
570+
"make_valid",
563571
"max",
564572
"min",
565573
"os",
574+
"pack_cpus",
575+
"pack_ids",
566576
"refine",
567577
"register_AoS_extension",
568578
"register_Array4_extension",
@@ -590,4 +600,4 @@ def d_decl(x, y, z):
590600

591601
__author__: str = "Axel Huebl, Ryan T. Sandberg, Shreyas Ananthan, David P. Grote, Revathi Jambunathan, Edoardo Zoni, Remi Lehe, Andrew Myers, Weiqun Zhang"
592602
__license__: str = "BSD-3-Clause-LBNL"
593-
__version__: str = "25.04"
603+
__version__: str = "25.05-4-g793ea9f71759"

src/amrex/space1d/amrex_1d_pybind/__init__.pyi

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,15 @@ __all__ = [
293293
"initialize",
294294
"initialize_when_MPMD",
295295
"initialized",
296+
"is_valid",
296297
"lbound",
297298
"length",
299+
"make_invalid",
300+
"make_valid",
298301
"max",
299302
"min",
303+
"pack_cpus",
304+
"pack_ids",
300305
"refine",
301306
"size",
302307
"ubound",
@@ -4956,6 +4961,10 @@ class BoxArray:
49564961
def coarsenable(self, arg0: IntVect1D, arg1: int) -> bool: ...
49574962
@typing.overload
49584963
def coarsenable(self, arg0: IntVect1D, arg1: IntVect1D) -> bool: ...
4964+
@typing.overload
4965+
def convert(self, arg0: IndexType) -> BoxArray: ...
4966+
@typing.overload
4967+
def convert(self, arg0: IntVect1D) -> BoxArray: ...
49594968
def define(self, arg0: Box) -> None: ...
49604969
@typing.overload
49614970
def enclosed_cells(self) -> BoxArray: ...
@@ -4973,6 +4982,10 @@ class BoxArray:
49734982
@typing.overload
49744983
def refine(self, arg0: IntVect1D) -> BoxArray: ...
49754984
def resize(self, arg0: int) -> None: ...
4985+
@typing.overload
4986+
def surroundingNodes(self) -> BoxArray: ...
4987+
@typing.overload
4988+
def surroundingNodes(self, arg0: int) -> BoxArray: ...
49764989
@property
49774990
def capacity(self) -> int: ...
49784991
@property
@@ -4985,7 +4998,7 @@ class BoxArray:
49854998
def size(self) -> int: ...
49864999

49875000
class Config:
4988-
amrex_version: typing.ClassVar[str] = "25.04"
5001+
amrex_version: typing.ClassVar[str] = "25.05-4-g793ea9f71759"
49895002
gpu_backend = None
49905003
have_eb: typing.ClassVar[bool] = False
49915004
have_gpu: typing.ClassVar[bool] = False
@@ -6753,6 +6766,22 @@ class MultiFab(FabArray_FArrayBox):
67536766
A copy of this MultiFab.
67546767

67556768
"""
6769+
@typing.overload
6770+
def copymf(
6771+
self, src: MultiFab, srccomp: int, dstcomp: int, numcomp: int, nghost: int
6772+
) -> None:
6773+
"""
6774+
Copy from src to self including nghost ghost cells.
6775+
The two MultiFabs MUST have the same underlying BoxArray. The copy is local
6776+
"""
6777+
@typing.overload
6778+
def copymf(
6779+
self, src: MultiFab, srccomp: int, dstcomp: int, numcomp: int, nghost: IntVect1D
6780+
) -> None:
6781+
"""
6782+
Copy from src to self including nghost ghost cells.
6783+
The two MultiFabs MUST have the same underlying BoxArray. The copy is local
6784+
"""
67566785
def divi(
67576786
self, mf: MultiFab, strt_comp: int, num_comp: int, nghost: int = 0
67586787
) -> None:
@@ -20016,6 +20045,13 @@ class iMultiFab(FabArray_IArrayBox):
2001620045
amrex.MultiFab
2001720046
A copy of this MultiFab.
2001820047

20048+
"""
20049+
def copymf(
20050+
self, src: iMultiFab, srccomp: int, dstcomp: int, numcomp: int, nghost: int
20051+
) -> None:
20052+
"""
20053+
Copy from src to self including nghost ghost cells.
20054+
The two MultiFabs MUST have the same underlying BoxArray. The copy is local
2001920055
"""
2002020056
def divi(
2002120057
self, mf: iMultiFab, strt_comp: int, num_comp: int, nghost: int = 0
@@ -20489,6 +20525,7 @@ def initialized() -> bool:
2048920525
Returns true if there are any currently-active and initialized AMReX instances (i.e. one for which amrex::Initialize has been called, and amrex::Finalize has not). Otherwise false.
2049020526
"""
2049120527

20528+
def is_valid(arg0: int) -> bool: ...
2049220529
@typing.overload
2049320530
def lbound(arg0: Box) -> Dim3: ...
2049420531
@typing.overload
@@ -20597,8 +20634,16 @@ def length(arg0: Array4_uint_const) -> Dim3: ...
2059720634
def length(arg0: Array4_ulong_const) -> Dim3: ...
2059820635
@typing.overload
2059920636
def length(arg0: Array4_ulonglong_const) -> Dim3: ...
20637+
def make_invalid(arg0: int) -> int: ...
20638+
def make_valid(arg0: int) -> int: ...
2060020639
def max(arg0: RealVect, arg1: RealVect) -> RealVect: ...
2060120640
def min(arg0: RealVect, arg1: RealVect) -> RealVect: ...
20641+
def pack_cpus(
20642+
arg0: numpy.ndarray[numpy.uint64], arg1: numpy.ndarray[numpy.int32]
20643+
) -> typing.Any: ...
20644+
def pack_ids(
20645+
arg0: numpy.ndarray[numpy.uint64], arg1: numpy.ndarray[numpy.int64]
20646+
) -> typing.Any: ...
2060220647
@typing.overload
2060320648
def refine(arg0: Dim3, arg1: IntVect1D) -> Dim3: ...
2060420649
@typing.overload
@@ -20684,5 +20729,5 @@ def write_single_level_plotfile(
2068420729

2068520730
__author__: str = "Axel Huebl, Ryan T. Sandberg, Shreyas Ananthan, David P. Grote, Revathi Jambunathan, Edoardo Zoni, Remi Lehe, Andrew Myers, Weiqun Zhang"
2068620731
__license__: str = "BSD-3-Clause-LBNL"
20687-
__version__: str = "25.04"
20732+
__version__: str = "25.05-4-g793ea9f71759"
2068820733
IntVect = IntVect1D

src/amrex/space2d/__init__.pyi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,15 @@ from amrex.space2d.amrex_2d_pybind import (
318318
initialize,
319319
initialize_when_MPMD,
320320
initialized,
321+
is_valid,
321322
lbound,
322323
length,
324+
make_invalid,
325+
make_valid,
323326
max,
324327
min,
328+
pack_cpus,
329+
pack_ids,
325330
refine,
326331
size,
327332
ubound,
@@ -606,11 +611,16 @@ __all__ = [
606611
"initialize",
607612
"initialize_when_MPMD",
608613
"initialized",
614+
"is_valid",
609615
"lbound",
610616
"length",
617+
"make_invalid",
618+
"make_valid",
611619
"max",
612620
"min",
613621
"os",
622+
"pack_cpus",
623+
"pack_ids",
614624
"refine",
615625
"register_AoS_extension",
616626
"register_Array4_extension",
@@ -638,4 +648,4 @@ def d_decl(x, y, z):
638648

639649
__author__: str = "Axel Huebl, Ryan T. Sandberg, Shreyas Ananthan, David P. Grote, Revathi Jambunathan, Edoardo Zoni, Remi Lehe, Andrew Myers, Weiqun Zhang"
640650
__license__: str = "BSD-3-Clause-LBNL"
641-
__version__: str = "25.04"
651+
__version__: str = "25.05-4-g793ea9f71759"

0 commit comments

Comments
 (0)