Python API
Imports
pyAMReX provides the public imports amrex.space1d, amrex.space2d and amrex.space3d, mirroring the compile-time option AMReX_SPACEDIM.
Due to limitations in AMReX, currently, only one of the imports can be used at a time in the same Python process. For example:
import amrex.space3d as amr
A 1D or 2D AMReX run needs its own Python process. Another dimensionality cannot be imported into the same Python process after choosing a specific dimensionality for import.
For brevity, below the 3D APIs are shown. pyAMReX classes and functions follow the same structure as the C++ AMReX APIs.
Base
- class amrex.space3d.Config[source]
- gpu_backend = None
- have_eb: ClassVar[bool] = True
- have_gpu: ClassVar[bool] = False
- have_mpi: ClassVar[bool] = True
- have_omp: ClassVar[bool] = False
- have_simd: ClassVar[bool] = False
- precision: ClassVar[str] = 'DOUBLE'
- precision_particles: ClassVar[str] = 'DOUBLE'
- simd_size: ClassVar[int] = 1
- spacedim: ClassVar[int] = 3
- verbose: ClassVar[int] = 1
- amrex.space3d.finalize(*args, **kwds)
Helper for @overload to raise when called.
- amrex.space3d.initialized() bool[source]
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.
- class amrex.space3d.Arena[source]
-
- has_free_device_memory(sz: SupportsInt | SupportsIndex) bool[source]
Does the device have enough free memory for allocating this much memory? For CPU builds, this always return true.
- property is_device: bool
- property is_device_accessible: bool
- property is_host_accessible: bool
- property is_managed: bool
- property is_pinned: bool
- class amrex.space3d.CoordSys[source]
- class amrex.space3d.CoordSys(arg0: CoordSys)
- class amrex.space3d.DistributionMapping[source]
- class amrex.space3d.DistributionMapping(arg0: DistributionMapping)
- class amrex.space3d.DistributionMapping(arg0: Vector_int)
- class amrex.space3d.DistributionMapping(boxes: BoxArray)
- class amrex.space3d.DistributionMapping(boxes: BoxArray, nprocs: SupportsInt | SupportsIndex)
- ProcessorMap() Vector_int[source]
- property capacity: int
- define(**kwds)
Helper for @overload to raise when called.
- property empty: bool
- property link_count: int
- property size: int
- class amrex.space3d.GeometryData[source]
- CellSize(**kwds)
Helper for @overload to raise when called.
- ProbHi(**kwds)
Helper for @overload to raise when called.
- ProbLo(**kwds)
Helper for @overload to raise when called.
- property coord: int
The Coordinates type.
- property dx: Annotated[list[float], 'FixedSize(3)']
The cellsize for each coordinate direction.
- isPeriodic(**kwds)
Helper for @overload to raise when called.
- property is_periodic: Annotated[list[int], 'FixedSize(3)']
Returns whether the domain is periodic in each coordinate direction.
- class amrex.space3d.Geometry[source]
- class amrex.space3d.Geometry(dom: Box, rb: RealBox, coord: SupportsInt | SupportsIndex, is_per: Annotated[collections.abc.Sequence[SupportsInt | SupportsIndex], 'FixedSize(3)'])
- ProbHi(**kwds)
Helper for @overload to raise when called.
- ProbLength(arg0: SupportsInt | SupportsIndex) float[source]
length of problem domain in specified dimension
- ProbLo(**kwds)
Helper for @overload to raise when called.
- ResetDefaultPeriodicity() None[source]
Reset default periodicity of Geometry class with an Array of int
- ResetDefaultProbDomain() None[source]
Reset default problem domain of Geometry class with a RealBox
- data() GeometryData[source]
Returns non-static copy of geometry’s stored data
- define(dom: Box, rb: RealBox, coord: SupportsInt | SupportsIndex, is_per: Annotated[Sequence[SupportsInt | SupportsIndex], 'FixedSize(3)']) None[source]
Set geometry
- growNonPeriodicDomain(**kwds)
Helper for @overload to raise when called.
- growPeriodicDomain(**kwds)
Helper for @overload to raise when called.
- insideRoundOffDomain(x: SupportsFloat | SupportsIndex, y: SupportsFloat | SupportsIndex, z: SupportsFloat | SupportsIndex) bool[source]
Returns true if a point is inside the roundoff domain. All particles with positions inside the roundoff domain are sure to be mapped to cells inside the Domain() box. Note that the same need not be true for all points inside ProbDomain()
- isPeriodic(**kwds)
Helper for @overload to raise when called.
- outsideRoundOffDomain(x: SupportsFloat | SupportsIndex, y: SupportsFloat | SupportsIndex, z: SupportsFloat | SupportsIndex) bool[source]
Returns true if a point is outside the roundoff domain. All particles with positions inside the roundoff domain are sure to be mapped to cells inside the Domain() box. Note that the same need not be true for all points inside ProbDomain()
- periodicity(**kwds)
Helper for @overload to raise when called.
- class amrex.space3d.Periodicity[source]
- class amrex.space3d.Periodicity(arg0: IntVect3D)
-
- property is_all_periodic: bool
- property is_any_periodic: bool
- static non_periodic() Periodicity[source]
Return the Periodicity object that is not periodic in any direction
- property shift_IntVect: list[IntVect3D]
- class amrex.space3d.RealBox[source]
- class amrex.space3d.RealBox(x_lo: SupportsFloat | SupportsIndex, y_lo: SupportsFloat | SupportsIndex, z_lo: SupportsFloat | SupportsIndex, x_hi: SupportsFloat | SupportsIndex, y_hi: SupportsFloat | SupportsIndex, z_hi: SupportsFloat | SupportsIndex)
- class amrex.space3d.RealBox(a_lo: Annotated[collections.abc.Sequence[SupportsFloat | SupportsIndex], 'FixedSize(3)'], a_hi: Annotated[collections.abc.Sequence[SupportsFloat | SupportsIndex], 'FixedSize(3)'])
- class amrex.space3d.RealBox(bx: Box, dx: Annotated[collections.abc.Sequence[SupportsFloat | SupportsIndex], 'FixedSize(3)'], base: Annotated[collections.abc.Sequence[SupportsFloat | SupportsIndex], 'FixedSize(3)'])
- contains(**kwds)
Helper for @overload to raise when called.
- hi(**kwds)
Helper for @overload to raise when called.
- lo(**kwds)
Helper for @overload to raise when called.
- setHi(**kwds)
Helper for @overload to raise when called.
- setLo(**kwds)
Helper for @overload to raise when called.
- property xhi: Annotated[list[float], 'FixedSize(3)']
- property xlo: Annotated[list[float], 'FixedSize(3)']
- amrex.space3d.AlmostEqual(rb1: RealBox, rb2: RealBox, eps: SupportsFloat | SupportsIndex = 0.0) bool[source]
Determine if two boxes are equal to within a tolerance
Indexing: Box, IntVect and IndexType
Corresponding AMReX documentation.
- amrex.space3d.IntVect
alias of
IntVect3D
- class amrex.space3d.Box(small: IntVect3D, big: IntVect3D)[source]
- class amrex.space3d.Box(small: IntVect3D, big: IntVect3D, typ: IntVect3D)
- class amrex.space3d.Box(small: IntVect3D, big: IntVect3D, t: IndexType)
- class amrex.space3d.Box(small: Annotated[collections.abc.Sequence[SupportsInt | SupportsIndex], 'FixedSize(3)'], big: Annotated[collections.abc.Sequence[SupportsInt | SupportsIndex], 'FixedSize(3)'])
- class amrex.space3d.Box(small: Annotated[collections.abc.Sequence[SupportsInt | SupportsIndex], 'FixedSize(3)'], big: Annotated[collections.abc.Sequence[SupportsInt | SupportsIndex], 'FixedSize(3)'], t: IndexType)
-
- big_end: IntVect3D
- property cell_centered: bool
Returns true if Box is cell-centered in all indexing directions.
- convert(**kwds)
Helper for @overload to raise when called.
- property d_num_pts: float
- enclosed_cells(**kwds)
Helper for @overload to raise when called.
- grow(**kwds)
Helper for @overload to raise when called.
- grow_high(**kwds)
Helper for @overload to raise when called.
- grow_low(**kwds)
Helper for @overload to raise when called.
- hi_vect: IntVect3D
- intersects(b: Box) bool[source]
Returns true if Boxes have non-null intersections. It is an error if the Boxes have different types.
- property is_empty: bool
- property is_square: bool
- length(**kwds)
Helper for @overload to raise when called.
- lo_vect: IntVect3D
- make_slab(direction: SupportsInt | SupportsIndex, slab_index: SupportsInt | SupportsIndex) Box[source]
Flatten the box in one direction.
- property num_pts: int
- property ok: bool
- same_size(b: Box) bool[source]
Returns true is Boxes same size, ie translates of each other,. It is an error if they have different types.
- shift(**kwds)
Helper for @overload to raise when called.
- property size: IntVect3D
- small_end: IntVect3D
- strictly_contains(p: IntVect3D) bool[source]
Returns true if argument is strictly contained within Box.
- surrounding_nodes(**kwds)
Helper for @overload to raise when called.
- property type: IntVect3D
- property volume: int
- class amrex.space3d.BoxArray[source]
- class amrex.space3d.BoxArray(arg0: BoxArray)
- class amrex.space3d.BoxArray(arg0: Box)
- class amrex.space3d.BoxArray(arg0: Vector_Box)
- property capacity: int
- coarsen(**kwds)
Helper for @overload to raise when called.
- coarsenable(**kwds)
Helper for @overload to raise when called.
- convert(**kwds)
Helper for @overload to raise when called.
- property d_numPts: float
- property empty: bool
- enclosed_cells(**kwds)
Helper for @overload to raise when called.
- max_size(**kwds)
Helper for @overload to raise when called.
- property numPts: int
- refine(**kwds)
Helper for @overload to raise when called.
- property size: int
- surroundingNodes(**kwds)
Helper for @overload to raise when called.
- class amrex.space3d.Dim3(arg0: SupportsInt | SupportsIndex, arg1: SupportsInt | SupportsIndex, arg2: SupportsInt | SupportsIndex)[source]
- property x: int
- property y: int
- property z: int
- class amrex.space3d.XDim3(arg0: SupportsFloat | SupportsIndex, arg1: SupportsFloat | SupportsIndex, arg2: SupportsFloat | SupportsIndex)[source]
- property x: float
- property y: float
- property z: float
- class amrex.space3d.IndexType[source]
- class amrex.space3d.IndexType(arg0: IndexType)
- class amrex.space3d.IndexType(arg0: IndexType.CellIndex, arg1: IndexType.CellIndex, arg2: IndexType.CellIndex)
-
- cell_centered(**kwds)
Helper for @overload to raise when called.
- ix_type(**kwds)
Helper for @overload to raise when called.
- node_centered(**kwds)
Helper for @overload to raise when called.
Vectors
- class amrex.space3d.RealVect[source]
- class amrex.space3d.RealVect(arg0: SupportsFloat | SupportsIndex, arg1: SupportsFloat | SupportsIndex, arg2: SupportsFloat | SupportsIndex)
- class amrex.space3d.RealVect(arg0: IntVect3D)
- class amrex.space3d.RealVect(arg0: collections.abc.Sequence[SupportsFloat | SupportsIndex])
- class amrex.space3d.RealVect(arg0: SupportsFloat | SupportsIndex)
-
- ceil() IntVect3D[source]
Return an
IntVectwhose components are the std::ceil of the vector components
- floor() IntVect3D[source]
Return an
IntVectwhose components are the std::floor of the vector components
- max(arg0: RealVect) RealVect[source]
Replace vector with the component-wise maxima of this vector and another
- min(arg0: RealVect) RealVect[source]
Replace vector with the component-wise minima of this vector and another
- property product: float
Product of entries of this vector
- property radSquared: float
Length squared of this vector
- round() IntVect3D[source]
Return an
IntVectwhose components are the std::round of the vector components
- scale(arg0: SupportsFloat | SupportsIndex) RealVect[source]
Multiplify each component of this vector by a scalar
- property sum: float
Sum of the components of this vector
- property vectorLength: float
Length or 2-Norm of this vector
amrex::Vector<T> is implemented for many types, e.g.,
- class amrex.space3d.Vector_Real[source]
- class amrex.space3d.Vector_Real(arg0: Vector_Real)
- class amrex.space3d.Vector_Real(arg0: Iterable)
- class amrex.space3d.Vector_Real
- class amrex.space3d.Vector_Real(arg0: Vector_Real)
-
- count(x: SupportsFloat | SupportsIndex) int[source]
Return the number of times
xappears in the list
- extend(**kwds)
Helper for @overload to raise when called.
- insert(i: SupportsInt | SupportsIndex, x: SupportsFloat | SupportsIndex) None[source]
Insert an item at a given position.
- pop(**kwds)
Helper for @overload to raise when called.
- class amrex.space3d.Vector_int[source]
- class amrex.space3d.Vector_int(arg0: Vector_int)
- class amrex.space3d.Vector_int(arg0: Iterable)
- class amrex.space3d.Vector_int
- class amrex.space3d.Vector_int(arg0: Vector_int)
-
- extend(**kwds)
Helper for @overload to raise when called.
- insert(i: SupportsInt | SupportsIndex, x: SupportsInt | SupportsIndex) None[source]
Insert an item at a given position.
- pop(**kwds)
Helper for @overload to raise when called.
- class amrex.space3d.Vector_string[source]
- class amrex.space3d.Vector_string(arg0: Vector_string)
- class amrex.space3d.Vector_string(arg0: Iterable)
- class amrex.space3d.Vector_string
- class amrex.space3d.Vector_string(arg0: Vector_string)
-
- extend(**kwds)
Helper for @overload to raise when called.
- pop(**kwds)
Helper for @overload to raise when called.
Boundary Conditions
Boundary records describe the mathematical boundary types used for each MultiFab component and coordinate direction. A common cell-centered fill sequence is to fill interior or periodic ghost cells first and then fill physical-domain ghost cells:
sd = amr.Config.spacedim
bc = amr.Vector_BCRec([
amr.BCRec(
lo=[amr.BCType.foextrap] * sd,
hi=[amr.BCType.foextrap] * sd,
)
])
mf.fill_boundary()
amr.fill_domain_boundary(mf, geom, bc)
fill_domain_boundary handles extrapolation and reflection boundary
types. For external Dirichlet values, BCType.ext_dir or
BCType.ext_dir_cc, fill the relevant ghost cells from application
code. PhysBCFunctUser provides a Python callback hook with the same
component-range convention as AMReX FillPatch routines:
def fill_ext_dir(mf, dcomp, ncomp, nghost, time, bccomp):
# Fill external Dirichlet ghost cells for mf components
# [dcomp, dcomp + ncomp).
pass
physbc = amr.PhysBCFunctUser(fill_ext_dir)
physbc(mf, 0, 1, mf.n_grow_vect, 0.0, 0)
In physical boundary functors, dcomp is the first destination
component in the MultiFab and bccomp is the first matching entry
in the Vector_BCRec.
- class amrex.space3d.BCType(value)[source]
Mathematical boundary condition types stored in BCRec.
Common values are BCType.int_dir for interior cells, BCType.foextrap for first-order extrapolation, BCType.reflect_even and BCType.reflect_odd for reflective boundaries, and BCType.ext_dir or BCType.ext_dir_cc for external Dirichlet values supplied by the application.
- class amrex.space3d.PhysBCType(value)[source]
Physical boundary condition categories.
Application code maps these physical categories to mathematical BCType values for each field component and coordinate direction.
- inflow: ClassVar[PhysBCType]
- inflowoutflow: ClassVar[PhysBCType]
- interior: ClassVar[PhysBCType]
- noslipwall: ClassVar[PhysBCType]
- outflow: ClassVar[PhysBCType]
- slipwall: ClassVar[PhysBCType]
- symmetry: ClassVar[PhysBCType]
- class amrex.space3d.BCRec[source]
- class amrex.space3d.BCRec(lo: Annotated[collections.abc.Sequence[SupportsInt | SupportsIndex], 'FixedSize(3)'], hi: Annotated[collections.abc.Sequence[SupportsInt | SupportsIndex], 'FixedSize(3)'])
- class amrex.space3d.BCRec(bx: Box, domain: Box, bc_domain: BCRec)
Boundary condition record for one field component.
A BCRec stores one mathematical boundary type on the low and high side of each coordinate direction. Pass lists of length Config.spacedim for lo and hi, usually using BCType enum values.
- data() list[int][source]
Return all boundary types as low-side entries followed by high-side entries.
- hi(**kwds)
Helper for @overload to raise when called.
- lo(**kwds)
Helper for @overload to raise when called.
- set_hi(dir: SupportsInt | SupportsIndex, bc_type: SupportsInt | SupportsIndex) None[source]
Set the high-side boundary type in one direction.
- Parameters:
dir – Coordinate direction, from 0 to Config.spacedim - 1.
bc_type – BCType or integer boundary value.
- class amrex.space3d.Vector_BCRec[source]
- class amrex.space3d.Vector_BCRec(arg0: Vector_BCRec)
- class amrex.space3d.Vector_BCRec(arg0: Iterable)
- class amrex.space3d.Vector_BCRec
- class amrex.space3d.Vector_BCRec(arg0: Vector_BCRec)
-
- extend(**kwds)
Helper for @overload to raise when called.
- pop(**kwds)
Helper for @overload to raise when called.
- amrex.space3d.setBC(*args, **kwds)
Helper for @overload to raise when called.
- amrex.space3d.fill_domain_boundary(phi: MultiFab, geom: Geometry, bc: Vector_BCRec) None[source]
Fill cell-centered physical-domain ghost cells.
This fills non-periodic ghost cells outside the physical domain for BCType.foextrap, BCType.hoextrap, BCType.hoextrapcc, BCType.reflect_even, and BCType.reflect_odd. It intentionally leaves BCType.ext_dir and BCType.ext_dir_cc unchanged; fill those values from application code, for example with PhysBCFunctUser.
- Parameters:
phi – MultiFab to modify in place. All components are processed.
geom – Geometry defining the physical domain and periodic directions.
bc – Vector_BCRec with one record per component in phi.
Notes
This function fills physical-domain ghost cells only. For multi-box MultiFabs, call phi.fill_boundary() separately when interior or periodic ghost cells also need to be valid.
- class amrex.space3d.PhysBCFunctNoOp[source]
Physical boundary condition functor that does nothing.
Use this with FillPatch-style calls when physical-domain ghost cells do not need additional work, for example in fully periodic domains or when the caller has already filled them.
- class amrex.space3d.CpuBndryFuncFab[source]
Host boundary-fill helper for PhysBCFunct_CpuBndryFuncFab.
The default-constructed helper fills extrapolation and reflection boundaries handled by AMReX, including BCType.foextrap, BCType.hoextrap, BCType.hoextrapcc, BCType.reflect_even, and BCType.reflect_odd. It leaves BCType.ext_dir and BCType.ext_dir_cc unchanged; fill external Dirichlet values separately, for example with PhysBCFunctUser.
- class amrex.space3d.PhysBCFunct_CpuBndryFuncFab[source]
- class amrex.space3d.PhysBCFunct_CpuBndryFuncFab(geom: Geometry, bc: Vector_BCRec, bndry_func: CpuBndryFuncFab)
Physical boundary condition functor using CpuBndryFuncFab.
This wraps amrex::PhysBCFunct<CpuBndryFuncFab>. It applies the boundary types stored in a Vector_BCRec over the physical-domain ghost cells selected by a Geometry.
- define(geom: Geometry, bc: Vector_BCRec, bndry_func: CpuBndryFuncFab) None[source]
Reset the geometry, component BC records, and boundary helper.
- Parameters:
geom – Geometry defining the physical domain and periodic directions.
bc – Vector_BCRec with one record per component.
bndry_func – Boundary-fill helper, usually CpuBndryFuncFab().
- class amrex.space3d.PhysBCFunctUser[source]
- class amrex.space3d.PhysBCFunctUser(callback: collections.abc.Callable[[MultiFab, int, int, IntVect3D, float, int], None])
Physical boundary condition functor implemented in Python.
The callback receives (mf, dcomp, ncomp, nghost, time, bccomp). It should fill the ghost cells of mf that lie outside the physical domain for the requested component range. This is the intended hook for application-supplied external Dirichlet values such as BCType.ext_dir and BCType.ext_dir_cc.
The callback runs on the host after pending AMReX GPU stream work is synchronized. When called from C++, pybind11 acquires the Python GIL before invoking the callback.
Data Containers
amrex::Array4<T> is implemented for many floating point and integer types, e.g.,
- class amrex.space3d.Array4_double[source]
- class amrex.space3d.Array4_double(arg0: Array4_double)
- class amrex.space3d.Array4_double(arg0: Array4_double, arg1: SupportsInt | SupportsIndex)
- class amrex.space3d.Array4_double(arg0: Array4_double, arg1: SupportsInt | SupportsIndex, arg2: SupportsInt | SupportsIndex)
- class amrex.space3d.Array4_double(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64])
- contains(**kwds)
Helper for @overload to raise when called.
- property nComp: int
- property num_comp: int
- property size: int
- to_cupy(copy=False, order='F')[source]
Provide a CuPy view into an Array4.
This includes ngrow guard cells of the box.
Note on the order of indices: By default, this is as in AMReX in Fortran contiguous order, indexing as x,y,z. This has performance implications for use in external libraries such as cupy. The order=”C” option will index as z,y,x and perform better with cupy. https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
- Parameters:
self (amrex.Array4_*) – An Array4 class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
order (string, optional) – F order (default) or C. C is faster with external libraries.
- Returns:
A cupy n-dimensional array.
- Return type:
cupy.array
- Raises:
ImportError – Raises an exception if cupy is not installed
- to_dpnp(copy=False, order='F')[source]
Provide a dpnp view into an Array4.
This includes ngrow guard cells of the box.
Note on the order of indices: By default, this is as in AMReX in Fortran contiguous order, indexing as x,y,z. This has performance implications for use in external libraries such as dpnp. The order=”C” option will index as z,y,x and may perform better. https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
- Parameters:
self (amrex.Array4_*) – An Array4 class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
order (string, optional) – F order (default) or C. C is faster with external libraries.
- Returns:
A dpnp n-dimensional array.
- Return type:
dpnp.array
- Raises:
ImportError – Raises an exception if dpnp is not installed
- to_numpy(copy=False, order='F')[source]
Provide a NumPy view into an Array4.
This includes ngrow guard cells of the box.
Note on the order of indices: By default, this is as in AMReX in Fortran contiguous order, indexing as x,y,z. This has performance implications for use in external libraries such as cupy. The order=”C” option will index as z,y,x and perform better with cupy. https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
- Parameters:
self (amrex.Array4_*) – An Array4 class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
order (string, optional) – F order (default) or C. C is faster with external libraries.
- Returns:
A NumPy n-dimensional array.
- Return type:
np.array
- to_xp(copy=False, order='F')[source]
Provide a NumPy, CuPy or dpnp view into an Array4, depending on amr.Config.have_gpu and amr.Config.gpu_backend .
This function is similar to CuPy’s xp naming suggestion for CPU/GPU agnostic code: https://docs.cupy.dev/en/stable/user_guide/basic.html#how-to-write-cpu-gpu-agnostic-code
This includes ngrow guard cells of the box.
Note on the order of indices: By default, this is as in AMReX in Fortran contiguous order, indexing as x,y,z. This has performance implications for use in external libraries such as cupy. The order=”C” option will index as z,y,x and perform better with cupy. https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
- Parameters:
self (amrex.Array4_*) – An Array4 class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
order (string, optional) – F order (default) or C. C is faster with external libraries.
- Returns:
A NumPy, CuPy or dpnp n-dimensional array.
- Return type:
xp.array
- class amrex.space3d.BaseFab_Real[source]
- class amrex.space3d.BaseFab_Real(arg0: Arena)
- class amrex.space3d.BaseFab_Real(arg0: Box, arg1: SupportsInt | SupportsIndex, arg2: Arena)
- class amrex.space3d.BaseFab_Real(arg0: Box, arg1: SupportsInt | SupportsIndex, arg2: SupportsFloat | SupportsIndex)
- class amrex.space3d.BaseFab_Real(arg0: Box, arg1: SupportsInt | SupportsIndex, arg2: SupportsFloat | SupportsIndex)
- class amrex.space3d.BaseFab_Real(arg0: Array4_double)
- class amrex.space3d.BaseFab_Real(arg0: Array4_double, arg1: IndexType)
- class amrex.space3d.BaseFab_Real(arg0: Array4_double_const)
- class amrex.space3d.BaseFab_Real(arg0: Array4_double_const, arg1: IndexType)
- array() Array4_double[source]
- n_bytes(**kwds)
Helper for @overload to raise when called.
- to_host() BaseFab_Real[source]
- class amrex.space3d.FArrayBox[source]
- class amrex.space3d.FArrayBox(arg0: Arena)
- class amrex.space3d.FArrayBox(arg0: Box, arg1: SupportsInt | SupportsIndex, arg2: Arena)
- class amrex.space3d.FArrayBox(arg0: Box, arg1: SupportsInt | SupportsIndex, arg2: bool, arg3: bool, arg4: Arena)
- class amrex.space3d.FArrayBox(arg0: Box, arg1: SupportsInt | SupportsIndex, arg2: SupportsFloat | SupportsIndex)
- class amrex.space3d.FArrayBox(arg0: Box, arg1: SupportsInt | SupportsIndex, arg2: SupportsFloat | SupportsIndex)
- class amrex.space3d.FArrayBox(arg0: Array4_double)
- class amrex.space3d.FArrayBox(arg0: Array4_double, arg1: IndexType)
- class amrex.space3d.FArrayBox(arg0: Array4_double_const)
- class amrex.space3d.FArrayBox(arg0: Array4_double_const, arg1: IndexType)
- class amrex.space3d.MultiFab[source]
- class amrex.space3d.MultiFab(a: Arena)
- class amrex.space3d.MultiFab(bxs: BoxArray, dm: DistributionMapping, ncomp: SupportsInt | SupportsIndex, ngrow: SupportsInt | SupportsIndex, info: MFInfo, factory: FabFactory_FArrayBox)
- class amrex.space3d.MultiFab(bxs: BoxArray, dm: DistributionMapping, ncomp: SupportsInt | SupportsIndex, ngrow: SupportsInt | SupportsIndex, info: MFInfo)
- class amrex.space3d.MultiFab(bxs: BoxArray, dm: DistributionMapping, ncomp: SupportsInt | SupportsIndex, ngrow: SupportsInt | SupportsIndex)
- class amrex.space3d.MultiFab(bxs: BoxArray, dm: DistributionMapping, ncomp: SupportsInt | SupportsIndex, ngrow: IntVect3D, info: MFInfo)
- class amrex.space3d.MultiFab(bxs: BoxArray, dm: DistributionMapping, ncomp: SupportsInt | SupportsIndex, ngrow: IntVect3D, info: MFInfo, factory: FabFactory_FArrayBox)
- class amrex.space3d.MultiFab(bxs: BoxArray, dm: DistributionMapping, ncomp: SupportsInt | SupportsIndex, ngrow: IntVect3D)
- add(**kwds)
Helper for @overload to raise when called.
- add_product(**kwds)
Helper for @overload to raise when called.
- average_sync(arg0: Periodicity) None[source]
- contains_inf(**kwds)
Helper for @overload to raise when called.
- contains_nan(**kwds)
Helper for @overload to raise when called.
- copy()[source]
Create a copy of this MultiFab, using the same Arena.
- Parameters:
self (amrex.MultiFab) – A MultiFab class in pyAMReX
- Returns:
A copy of this MultiFab.
- Return type:
amrex.MultiFab
- copymf(**kwds)
Helper for @overload to raise when called.
- divi(mf: MultiFab, strt_comp: SupportsInt | SupportsIndex, num_comp: SupportsInt | SupportsIndex, nghost: SupportsInt | SupportsIndex = 0) None[source]
This function divides the values of the cells in mf from the corresponding cells of this MultiFab. mf is required to have the same BoxArray or “valid region” as this MultiFab. The division is done only to num_comp components, starting with component number strt_comp. The parameter nghost specifies the number of boundary cells that will be modified. If nghost == 0, only the valid region of each FArrayBox will be modified. Note, nothing is done to protect against divide by zero.
- divide(**kwds)
Helper for @overload to raise when called.
- dot(**kwds)
Helper for @overload to raise when called.
- imesh(idir, include_ghosts=False)[source]
- Returns the integer mesh along the specified direction with the appropriate centering.
This is the location of the data points in grid cell units.
- selfamrex.MultiFab
A MultiFab class in pyAMReX
- directioninteger
Zero based direction number. In a typical Cartesian case, 0 would be ‘x’ direction.
- include_ghostsbool, default=False
Whether or not ghost cells are included in the mesh.
- invert(**kwds)
Helper for @overload to raise when called.
- lin_comb(a: SupportsFloat | SupportsIndex, x: MultiFab, x_comp: SupportsInt | SupportsIndex, b: SupportsFloat | SupportsIndex, y: MultiFab, y_comp: SupportsInt | SupportsIndex, comp: SupportsInt | SupportsIndex, numcomp: SupportsInt | SupportsIndex, nghost: SupportsInt | SupportsIndex) None[source]
self = a * x + b * y
- max(**kwds)
Helper for @overload to raise when called.
- min(**kwds)
Helper for @overload to raise when called.
- minus(mf: MultiFab, strt_comp: SupportsInt | SupportsIndex, num_comp: SupportsInt | SupportsIndex, nghost: SupportsInt | SupportsIndex = 0) None[source]
This function subtracts the values of the cells in mf from the corresponding cells of this MultiFab. mf is required to have the same BoxArray or “valid region” as this MultiFab. The subtraction is done only to num_comp components, starting with component number strt_comp. The parameter nghost specifies the number of boundary cells that will be modified. If nghost == 0, only the valid region of each FArrayBox will be modified.
- mult(**kwds)
Helper for @overload to raise when called.
- multiply(**kwds)
Helper for @overload to raise when called.
- property n_comp: int
- property n_grow_vect: IntVect3D
Return the grow factor (per direction) that defines the region of definition.
- negate(**kwds)
Helper for @overload to raise when called.
- norm0(**kwds)
Helper for @overload to raise when called.
- norm1(**kwds)
Helper for @overload to raise when called.
- norm2(**kwds)
Helper for @overload to raise when called.
- norminf(arg0: SupportsInt | SupportsIndex, arg1: SupportsInt | SupportsIndex, arg2: bool, arg3: bool) float[source]
- override_sync(arg0: iMultiFab, arg1: Periodicity) None[source]
Helper for @overload to raise when called.
- plus(**kwds)
Helper for @overload to raise when called.
- saxpy(a: SupportsFloat | SupportsIndex, src: MultiFab, srccomp: SupportsInt | SupportsIndex, comp: SupportsInt | SupportsIndex, numcomp: SupportsInt | SupportsIndex, nghost: SupportsInt | SupportsIndex) None[source]
self += a * src
- property shape
Returns the shape of the global array
- Parameters:
self (amrex.MultiFab) – A MultiFab class in pyAMReX
include_ghosts (bool, default=False) – Whether or not ghost cells are included
- property shape_with_ghosts
Returns the shape of the global array including ghost cells
- Parameters:
self (amrex.MultiFab) – A MultiFab class in pyAMReX
- subtract(**kwds)
Helper for @overload to raise when called.
- sum(**kwds)
Helper for @overload to raise when called.
- sum_unique(**kwds)
Helper for @overload to raise when called.
- swap(**kwds)
Helper for @overload to raise when called.
- to_cupy(copy=False, order='F')[source]
Provide a CuPy view into a MultiFab.
This includes ngrow guard cells of each box.
Note on the order of indices: By default, this is as in AMReX in Fortran contiguous order, indexing as x,y,z. This has performance implications for use in external libraries such as cupy. The order=”C” option will index as z,y,x and perform better with cupy. https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
- Parameters:
self (amrex.MultiFab) – A MultiFab class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
order (string, optional) – F order (default) or C. C is faster with external libraries.
- Returns:
A list of CuPy n-dimensional arrays, for each local block in the MultiFab.
- Return type:
list of cupy.array
- Raises:
ImportError – Raises an exception if cupy is not installed
- to_dpnp(copy=False, order='F')[source]
Provide a dpnp view into a MultiFab.
This includes ngrow guard cells of each box.
Note on the order of indices: By default, this is as in AMReX in Fortran contiguous order, indexing as x,y,z. This has performance implications for use in external libraries such as dpnp. The order=”C” option will index as z,y,x and may perform better. https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
- Parameters:
self (amrex.MultiFab) – A MultiFab class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
order (string, optional) – F order (default) or C. C is faster with external libraries.
- Returns:
A list of dpnp n-dimensional arrays, for each local block in the MultiFab.
- Return type:
list of dpnp.array
- Raises:
ImportError – Raises an exception if dpnp is not installed
- to_numpy(copy=False, order='F')[source]
Provide a NumPy view into a MultiFab.
This includes ngrow guard cells of each box.
Note on the order of indices: By default, this is as in AMReX in Fortran contiguous order, indexing as x,y,z. This has performance implications for use in external libraries such as cupy. The order=”C” option will index as z,y,x and perform better with cupy. https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
- Parameters:
self (amrex.MultiFab) – A MultiFab class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
order (string, optional) – F order (default) or C. C is faster with external libraries.
- Returns:
A list of NumPy n-dimensional arrays, for each local block in the MultiFab.
- Return type:
list of numpy.array
- to_xp(copy=False, order='F')[source]
Provide a NumPy, CuPy or dpnp view into a MultiFab, depending on amr.Config.have_gpu and amr.Config.gpu_backend .
This function is similar to CuPy’s xp naming suggestion for CPU/GPU agnostic code: https://docs.cupy.dev/en/stable/user_guide/basic.html#how-to-write-cpu-gpu-agnostic-code
This includes ngrow guard cells of each box.
Note on the order of indices: By default, this is as in AMReX in Fortran contiguous order, indexing as x,y,z. This has performance implications for use in external libraries such as cupy. The order=”C” option will index as z,y,x and perform better with cupy. https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
- Parameters:
self (amrex.MultiFab) – A MultiFab class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
order (string, optional) – F order (default) or C. C is faster with external libraries.
- Returns:
A list of NumPy, CuPy or dpnp n-dimensional arrays, for each local block in the MultiFab.
- Return type:
list of xp.array
- weighted_sync(arg0: MultiFab, arg1: Periodicity) None[source]
- class amrex.space3d.MFInfo[source]
- alloc: bool
- tags: Vector_string
- class amrex.space3d.MFIter(arg0: FabArrayBase)[source]
- class amrex.space3d.MFIter(arg0: FabArrayBase, arg1: MFItInfo)
- class amrex.space3d.MFIter(arg0: MultiFab)
- class amrex.space3d.MFIter(arg0: MultiFab, arg1: MFItInfo)
- class amrex.space3d.MFIter(arg0: iMultiFab)
- class amrex.space3d.MFIter(arg0: iMultiFab, arg1: MFItInfo)
-
- grownnodaltilebox(**kwds)
Helper for @overload to raise when called.
- property index: int
- property is_valid: bool
- property length: int
- tilebox(**kwds)
Helper for @overload to raise when called.
amrex::PODVector<T, Allocator> is implemented for many allocators, e.g.,
- class amrex.space3d.PODVector_real_arena[source]
- class amrex.space3d.PODVector_real_arena(size: SupportsInt | SupportsIndex)
- class amrex.space3d.PODVector_real_arena(other: PODVector_real_arena)
A plain-old-data (POD) vector of ‘real’ elements with ‘arena’ allocation.
- copy_from(arr, offset=0)[source]
Copy array data into this PODVector at an offset.
Writes
self[offset:offset + len(arr)]; the vector is not resized. Values are cast to the vector’s element type.The fastest available copy is used: a direct AMReX copy for PODVector input, and a device-to-device copy for CuPy or dpnp input into device memory. Otherwise, the data is copied through the host with AMReX, so CuPy and dpnp are never required: they are only imported if the data is on such a device.
- Parameters:
self (amrex.PODVector_*) – A PODVector class in pyAMReX
arr (array_like or PODVector) – 1-D data: a PODVector, a NumPy, CuPy or dpnp array, any DLPack producer, or an array-like such as a list.
offset (int, optional) – First element of this vector to write (default: 0).
- Raises:
IndexError – If the data does not fit into this vector at the offset.
ValueError – If the data is not 1-D.
TypeError – If the data is None or on an unsupported device.
Notes
The source must not overlap with the written part of this vector, e.g., it must not be a view into it.
- copy_from_numpy(arr: Annotated[_Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], float64], offset: SupportsInt | SupportsIndex = 0) None[source]
Copy a NumPy array (or array-like) into this PODVector at an offset.
Writes
self[offset:offset + len(arr)]; the vector is not resized. The input is cast to the vector’s element type and made contiguous as needed. The copy into device-only memory uses an AMReX host-to-device copy and does not require CuPy or dpnp. For data of any kind, including device arrays, usecopy_from.- Parameters:
arr (array_like) – 1-D input data in host memory, convertible to a NumPy array.
offset (int, optional) – First element of this vector to write (default: 0).
- Raises:
IndexError – If the data does not fit into this vector at the offset.
- copy_from_podvector(**kwds)
Helper for @overload to raise when called.
- classmethod from_array(arr, copy=True)[source]
Create a PODVector from array data.
The element type and allocator are those of
cls(e.g.,DeviceVector_real,PODVector_int_std); values are cast to the element type. See :meth:`copy_from` for the supported inputs and how the data is copied: CuPy and dpnp are never required.- Parameters:
cls (type) – The PODVector type to construct.
arr (array_like or PODVector) – 1-D data: a PODVector, a NumPy, CuPy or dpnp array, any DLPack producer, or an array-like such as a list.
copy (bool or None, optional) – Like
numpy.asarray: if True (default), always copy. If None, returnarritself if it already is aclsinstance, otherwise copy. If False, returnarritself and raise ValueError if a copy would be needed.
- Returns:
A
clsinstance.- Return type:
PODVector
- Raises:
ValueError – If the data is not 1-D, or if
copy=Falseand a copy is needed.TypeError – If the data is None or on an unsupported device.
- classmethod from_cupy(arr)[source]
Create a new PODVector from a CuPy array (or array-like).
Always copies the data into a newly allocated PODVector. Works for every allocator type. Equivalent to :meth:`from_array`, but requires CuPy. Array-likes on the host are copied without a detour through the device.
- Parameters:
cls (type) – The PODVector type to construct.
arr (array_like) – Input data, convertible to a CuPy array.
- Returns:
A new PODVector with a copy of the data.
- Return type:
PODVector
- classmethod from_dpnp(arr)[source]
Create a new PODVector from a dpnp array (or array-like).
Always copies the data into a newly allocated PODVector. Works for every allocator type. Equivalent to :meth:`from_array`, but requires dpnp. Array-likes on the host are copied without a detour through the device.
- Parameters:
cls (type) – The PODVector type to construct.
arr (array_like) – Input data, convertible to a dpnp array.
- Returns:
A new PODVector with a copy of the data.
- Return type:
PODVector
- static from_numpy(arr: Annotated[_Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], float64]) PODVector_real_arena[source]
Create a new PODVector from a NumPy array (or array-like).
Always copies the data into a newly allocated PODVector. The input is cast to the vector’s element type and made contiguous as needed. The copy into device-only memory uses an AMReX host-to-device copy and does not require CuPy. For data of any kind, including device arrays, use
from_array.- Parameters:
arr (array_like) – Input data in host memory, convertible to a NumPy array.
- Returns:
A new PODVector with a copy of the data.
- Return type:
PODVector
- classmethod from_xp(arr)[source]
Create a new PODVector from a NumPy, CuPy or dpnp array.
Always copies the data into a newly allocated PODVector, like :meth:`from_array`, which supports any of these inputs regardless of the build. Unlike :meth:`to_xp`, a zero-copy view is not possible here because PODVector always owns its memory through its allocator.
This function is similar to CuPy’s xp naming suggestion for CPU/GPU agnostic code: https://docs.cupy.dev/en/stable/user_guide/basic.html#how-to-write-cpu-gpu-agnostic-code
- Parameters:
cls (type) – The PODVector type to construct.
arr (array_like) – Input data (NumPy, CuPy or dpnp array).
- Returns:
A new PODVector with a copy of the data.
- Return type:
PODVector
- reserve(capacity: SupportsInt | SupportsIndex, strategy: GrowthStrategy = 'GrowthStrategy.Poisson') None[source]
- resize(**kwds)
Helper for @overload to raise when called.
- to_cupy(copy=False)[source]
Provide a CuPy view into a PODVector (e.g., RealVector, IntVector).
- Parameters:
self (amrex.PODVector_*) – A PODVector class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A 1D cupy array.
- Return type:
cupy.array
- Raises:
ImportError – Raises an exception if cupy is not installed
- to_device() PODVector_real_std[source]
Copy this vector into a new amrex Gpu::DeviceVector (the arena allocator on GPU, std on CPU), transferring across memory spaces as needed. Mirrors to_host().
- to_dpnp(copy=False)[source]
Provide a dpnp view into a PODVector (e.g., RealVector, IntVector).
- Parameters:
self (amrex.PODVector_*) – A PODVector class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A 1D dpnp array.
- Return type:
dpnp.array
- Raises:
ImportError – Raises an exception if dpnp is not installed
- to_host() PODVector_real_pinned[source]
Copy this vector into a new pinned (host) PODVector. Mirrors to_device().
- to_numpy(copy=False)[source]
Provide a NumPy view into a PODVector (e.g., RealVector, IntVector).
- Parameters:
self (amrex.PODVector_*) – A PODVector class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A 1D NumPy array.
- Return type:
np.array
- to_xp(copy=False)[source]
Provide a NumPy, CuPy or dpnp view into a PODVector (e.g., RealVector, IntVector), depending on amr.Config.have_gpu and amr.Config.gpu_backend .
This function is similar to CuPy’s xp naming suggestion for CPU/GPU agnostic code: https://docs.cupy.dev/en/stable/user_guide/basic.html#how-to-write-cpu-gpu-agnostic-code
- Parameters:
self (amrex.PODVector_*) – A PODVector class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A 1D NumPy, CuPy or dpnp array.
- Return type:
xp.array
- class amrex.space3d.PODVector_int_pinned[source]
- class amrex.space3d.PODVector_int_pinned(size: SupportsInt | SupportsIndex)
- class amrex.space3d.PODVector_int_pinned(other: PODVector_int_pinned)
A plain-old-data (POD) vector of ‘int’ elements with ‘pinned’ allocation.
- copy_from(arr, offset=0)[source]
Copy array data into this PODVector at an offset.
Writes
self[offset:offset + len(arr)]; the vector is not resized. Values are cast to the vector’s element type.The fastest available copy is used: a direct AMReX copy for PODVector input, and a device-to-device copy for CuPy or dpnp input into device memory. Otherwise, the data is copied through the host with AMReX, so CuPy and dpnp are never required: they are only imported if the data is on such a device.
- Parameters:
self (amrex.PODVector_*) – A PODVector class in pyAMReX
arr (array_like or PODVector) – 1-D data: a PODVector, a NumPy, CuPy or dpnp array, any DLPack producer, or an array-like such as a list.
offset (int, optional) – First element of this vector to write (default: 0).
- Raises:
IndexError – If the data does not fit into this vector at the offset.
ValueError – If the data is not 1-D.
TypeError – If the data is None or on an unsupported device.
Notes
The source must not overlap with the written part of this vector, e.g., it must not be a view into it.
- copy_from_numpy(arr: Annotated[_Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], int32], offset: SupportsInt | SupportsIndex = 0) None[source]
Copy a NumPy array (or array-like) into this PODVector at an offset.
Writes
self[offset:offset + len(arr)]; the vector is not resized. The input is cast to the vector’s element type and made contiguous as needed. The copy into device-only memory uses an AMReX host-to-device copy and does not require CuPy or dpnp. For data of any kind, including device arrays, usecopy_from.- Parameters:
arr (array_like) – 1-D input data in host memory, convertible to a NumPy array.
offset (int, optional) – First element of this vector to write (default: 0).
- Raises:
IndexError – If the data does not fit into this vector at the offset.
- copy_from_podvector(**kwds)
Helper for @overload to raise when called.
- classmethod from_array(arr, copy=True)[source]
Create a PODVector from array data.
The element type and allocator are those of
cls(e.g.,DeviceVector_real,PODVector_int_std); values are cast to the element type. See :meth:`copy_from` for the supported inputs and how the data is copied: CuPy and dpnp are never required.- Parameters:
cls (type) – The PODVector type to construct.
arr (array_like or PODVector) – 1-D data: a PODVector, a NumPy, CuPy or dpnp array, any DLPack producer, or an array-like such as a list.
copy (bool or None, optional) – Like
numpy.asarray: if True (default), always copy. If None, returnarritself if it already is aclsinstance, otherwise copy. If False, returnarritself and raise ValueError if a copy would be needed.
- Returns:
A
clsinstance.- Return type:
PODVector
- Raises:
ValueError – If the data is not 1-D, or if
copy=Falseand a copy is needed.TypeError – If the data is None or on an unsupported device.
- classmethod from_cupy(arr)[source]
Create a new PODVector from a CuPy array (or array-like).
Always copies the data into a newly allocated PODVector. Works for every allocator type. Equivalent to :meth:`from_array`, but requires CuPy. Array-likes on the host are copied without a detour through the device.
- Parameters:
cls (type) – The PODVector type to construct.
arr (array_like) – Input data, convertible to a CuPy array.
- Returns:
A new PODVector with a copy of the data.
- Return type:
PODVector
- classmethod from_dpnp(arr)[source]
Create a new PODVector from a dpnp array (or array-like).
Always copies the data into a newly allocated PODVector. Works for every allocator type. Equivalent to :meth:`from_array`, but requires dpnp. Array-likes on the host are copied without a detour through the device.
- Parameters:
cls (type) – The PODVector type to construct.
arr (array_like) – Input data, convertible to a dpnp array.
- Returns:
A new PODVector with a copy of the data.
- Return type:
PODVector
- static from_numpy(arr: Annotated[_Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], int32]) PODVector_int_pinned[source]
Create a new PODVector from a NumPy array (or array-like).
Always copies the data into a newly allocated PODVector. The input is cast to the vector’s element type and made contiguous as needed. The copy into device-only memory uses an AMReX host-to-device copy and does not require CuPy. For data of any kind, including device arrays, use
from_array.- Parameters:
arr (array_like) – Input data in host memory, convertible to a NumPy array.
- Returns:
A new PODVector with a copy of the data.
- Return type:
PODVector
- classmethod from_xp(arr)[source]
Create a new PODVector from a NumPy, CuPy or dpnp array.
Always copies the data into a newly allocated PODVector, like :meth:`from_array`, which supports any of these inputs regardless of the build. Unlike :meth:`to_xp`, a zero-copy view is not possible here because PODVector always owns its memory through its allocator.
This function is similar to CuPy’s xp naming suggestion for CPU/GPU agnostic code: https://docs.cupy.dev/en/stable/user_guide/basic.html#how-to-write-cpu-gpu-agnostic-code
- Parameters:
cls (type) – The PODVector type to construct.
arr (array_like) – Input data (NumPy, CuPy or dpnp array).
- Returns:
A new PODVector with a copy of the data.
- Return type:
PODVector
- reserve(capacity: SupportsInt | SupportsIndex, strategy: GrowthStrategy = 'GrowthStrategy.Poisson') None[source]
- resize(**kwds)
Helper for @overload to raise when called.
- to_cupy(copy=False)[source]
Provide a CuPy view into a PODVector (e.g., RealVector, IntVector).
- Parameters:
self (amrex.PODVector_*) – A PODVector class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A 1D cupy array.
- Return type:
cupy.array
- Raises:
ImportError – Raises an exception if cupy is not installed
- to_device() PODVector_int_std[source]
Copy this vector into a new amrex Gpu::DeviceVector (the arena allocator on GPU, std on CPU), transferring across memory spaces as needed. Mirrors to_host().
- to_dpnp(copy=False)[source]
Provide a dpnp view into a PODVector (e.g., RealVector, IntVector).
- Parameters:
self (amrex.PODVector_*) – A PODVector class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A 1D dpnp array.
- Return type:
dpnp.array
- Raises:
ImportError – Raises an exception if dpnp is not installed
- to_host() PODVector_int_pinned[source]
Copy this vector into a new pinned (host) PODVector. Mirrors to_device().
- to_numpy(copy=False)[source]
Provide a NumPy view into a PODVector (e.g., RealVector, IntVector).
- Parameters:
self (amrex.PODVector_*) – A PODVector class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A 1D NumPy array.
- Return type:
np.array
- to_xp(copy=False)[source]
Provide a NumPy, CuPy or dpnp view into a PODVector (e.g., RealVector, IntVector), depending on amr.Config.have_gpu and amr.Config.gpu_backend .
This function is similar to CuPy’s xp naming suggestion for CPU/GPU agnostic code: https://docs.cupy.dev/en/stable/user_guide/basic.html#how-to-write-cpu-gpu-agnostic-code
- Parameters:
self (amrex.PODVector_*) – A PODVector class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A 1D NumPy, CuPy or dpnp array.
- Return type:
xp.array
Small Matrices and Vectors
- class amrex.space3d.SmallMatrix_6x6_F_SI1_double[source]
- class amrex.space3d.SmallMatrix_6x6_F_SI1_double(arg0: SmallMatrix_6x6_F_SI1_double)
- class amrex.space3d.SmallMatrix_6x6_F_SI1_double(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64])
- property T: SmallMatrix_6x6_F_SI1_double
- property column_size: int
- dot(arg0: SmallMatrix_6x6_F_SI1_double) float[source]
- static identity() SmallMatrix_6x6_F_SI1_double[source]
- property order: str
- property row_size: int
- set_val(arg0: SupportsFloat | SupportsIndex) SmallMatrix_6x6_F_SI1_double[source]
- property size: int
- property starting_index: int
- to_cupy(copy=False, order='F')[source]
Provide a CuPy view into an SmallMatrix.
Note on the order of indices: By default, this is as in AMReX in Fortran contiguous order, indexing as x,y,z. This has performance implications for use in external libraries such as cupy. The order=”C” option will index as z,y,x and perform better with cupy. https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
- Parameters:
self (amrex.SmallMatrix_*) – A SmallMatrix class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
order (string, optional) – F order (default) or C. C is faster with external libraries.
- Returns:
A cupy 2-dimensional array.
- Return type:
cupy.array
- Raises:
ImportError – Raises an exception if cupy is not installed
- to_dpnp(copy=False, order='F')[source]
Provide a dpnp copy of a SmallMatrix.
SmallMatrix data is always host-side: importing into dpnp copies to the device, independent of the copy argument.
- Parameters:
self (amrex.SmallMatrix_*) – A SmallMatrix class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
order (string, optional) – F order (default) or C. C is faster with external libraries.
- Returns:
A dpnp 2-dimensional array.
- Return type:
dpnp.array
- Raises:
ImportError – Raises an exception if dpnp is not installed
- to_numpy(copy=False, order='F')[source]
Provide a NumPy view into an SmallMatrix.
Note on the order of indices: By default, this is as in AMReX in Fortran contiguous order, indexing as x,y,z. This has performance implications for use in external libraries such as cupy. The order=”C” option will index as z,y,x and perform better with cupy. https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
- Parameters:
self (amrex.SmallMatrix_*) – A SmallMatrix class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
order (string, optional) – F order (default) or C. C is faster with external libraries.
- Returns:
A NumPy 2-dimensional array.
- Return type:
np.array
- to_xp(copy=False, order='F')[source]
Provide a NumPy or CuPy view into a SmallMatrix, depending on amr.Config.have_gpu .
This function is similar to CuPy’s xp naming suggestion for CPU/GPU agnostic code: https://docs.cupy.dev/en/stable/user_guide/basic.html#how-to-write-cpu-gpu-agnostic-code
Note on the order of indices: By default, this is as in AMReX in Fortran contiguous order, indexing as x,y,z. This has performance implications for use in external libraries such as cupy. The order=”C” option will index as z,y,x and perform better with cupy. https://github.com/AMReX-Codes/pyamrex/issues/55#issuecomment-1579610074
- Parameters:
self (amrex.SmallMatrix_*) – A SmallMatrix class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
order (string, optional) – F order (default) or C. C is faster with external libraries.
- Returns:
A NumPy or CuPy 2-dimensional array.
- Return type:
xp.array
- transpose_in_place() SmallMatrix_6x6_F_SI1_double[source]
- static zero() SmallMatrix_6x6_F_SI1_double[source]
Utility
- class amrex.space3d.ParmParse(prefix: str = '')[source]
- add(**kwds)
Helper for @overload to raise when called.
- addarr(**kwds)
Helper for @overload to raise when called.
- pretty_print_table() None[source]
Write the table in a pretty way to the ostream. If there are duplicates, only the last one is printed.
- query_int(name: str, ival: SupportsInt | SupportsIndex = 0) tuple[bool, int][source]
queries input values
- amrex.space3d.concatenate(root: str, num: SupportsInt | SupportsIndex, mindigits: SupportsInt | SupportsIndex = 5) str[source]
Builds plotfile name
- amrex.space3d.write_single_level_plotfile(plotfilename: str, mf: MultiFab, varnames: Vector_string, geom: Geometry, time: SupportsFloat | SupportsIndex, level_step: SupportsInt | SupportsIndex, versionName: str = 'HyperCLaw-V1.1', levelPrefix: str = 'Level_', mfPrefix: str = 'Cell', extra_dirs: Vector_string = Ellipsis) None[source]
Writes single level plotfile
- amrex.space3d.write_multi_level_plotfile(plotfilename: str, mf: Sequence[MultiFab], varnames: Sequence[str], geom: Sequence[Geometry], time: SupportsFloat | SupportsIndex, level_steps: Sequence[SupportsInt | SupportsIndex], ref_ratio: Sequence[IntVect3D], versionName: str = 'HyperCLaw-V1.1', levelPrefix: str = 'Level_', mfPrefix: str = 'Cell', extra_dirs: Sequence[str] = Ellipsis) None[source]
Writes a multi-level plotfile: one MultiFab, Geometry and level step per level, and one refinement ratio per coarse level.
- class amrex.space3d.PlotFileData(arg0: str)[source]
- DistributionMap(arg0: SupportsInt | SupportsIndex) DistributionMapping[source]
- get(**kwds)
Helper for @overload to raise when called.
- syncDistributionMap(**kwds)
Helper for @overload to raise when called.
- varNames() Vector_string[source]
AmrCore
Python subclasses implement the AMR callbacks with pyAMReX snake-case names:
make_new_level_from_scratch, make_new_level_from_coarse,
remake_level, clear_level and error_est. The error_est
callback receives a mutable TagBoxArray for the level being tagged. The
tag array is a callback-scoped, non-owning view; mark cells for refinement with
tags.set_val(amr.TagBox.SET, ...) and do not store it for later use.
A particle container can be connected to an AmrCore hierarchy through the
particle metadata broker returned by core.get_par_gdb().
class MyCore(amr.AmrCore):
def make_new_level_from_scratch(self, lev, time, ba, dm):
pass
def make_new_level_from_coarse(self, lev, time, ba, dm):
pass
def remake_level(self, lev, time, ba, dm):
pass
def clear_level(self, lev):
pass
def error_est(self, lev, tags, time, ngrow):
tags.set_val(amr.TagBox.SET)
core = MyCore(rb, 1, n_cell, 0, ref_ratios, is_periodic)
core.init_from_scratch(0.0)
particles = amr.ParticleContainer_2_1_3_1_default(core.get_par_gdb())
- class amrex.space3d.AmrInfo[source]
-
- check_input: bool
- property grid_eff: float
- iterate_on_new_grids: bool
- property max_level: int
- property n_proper: int
- refine_grid_layout: bool
- refine_grid_layout_dims: IntVect3D
- use_fixed_coarse_grids: bool
- property use_fixed_upto_level: int
- use_new_chop: bool
- property verbose: int
- class amrex.space3d.AmrMesh[source]
- class amrex.space3d.AmrMesh(rb: RealBox, max_level_in: SupportsInt | SupportsIndex, n_cell_in: Vector_int, coord: SupportsInt | SupportsIndex, ref_ratios: Vector_IntVect, is_per: Annotated[collections.abc.Sequence[SupportsInt | SupportsIndex], 'FixedSize(3)'])
- property finest_level: int
- geom(lev: SupportsInt | SupportsIndex) Geometry[source]
Return the Geometry stored for AMR level lev.
- property max_level: int
- ref_ratio(**kwds)
Helper for @overload to raise when called.
- set_geometry(lev: SupportsInt | SupportsIndex, geom_in: Geometry) None[source]
Replace the Geometry stored for AMR level lev.
- property verbose: int
- class amrex.space3d.AmrCore[source]
- class amrex.space3d.AmrCore(rb: RealBox, max_level_in: SupportsInt | SupportsIndex, n_cell_in: Vector_int, coord: SupportsInt | SupportsIndex, ref_ratios: Vector_IntVect, is_per: Annotated[collections.abc.Sequence[SupportsInt | SupportsIndex], 'FixedSize(3)'])
- class amrex.space3d.AmrCore(level_0_geom: Geometry, amr_info: AmrInfo)
Base class for Python AMR applications that manage an AMReX mesh hierarchy.
Subclasses must implement
make_new_level_from_scratch,make_new_level_from_coarse,remake_level,clear_levelanderror_est. AMReX calls these Python overrides while creating or regridding levels.error_est(lev, tags, time, ngrow)receives a mutableTagBoxArrayfor the level being tagged. Mark cells withtags.set_val(TagBox.SET, ...)and keep the tag array only for the duration of the callback.- get_par_gdb() AmrParGDB[source]
Return the particle geometry/database broker owned by this AMR core.
The returned
AmrParGDBcan be passed to particle-container constructors ordefinemethods. It is a non-owning view; theAmrCoreis kept alive by the binding while the broker is used from Python.
- class amrex.space3d.TagBox[source]
Cell-tag storage used by
AmrCore.error_est.Use
TagBox.SETto request refinement,TagBox.CLEARto remove a tag andTagBox.BUFfor AMReX-generated buffered tags.
- class amrex.space3d.TagBoxArray(ba: BoxArray, dm: DistributionMapping, ngrow: SupportsInt | SupportsIndex = 0)[source]
- class amrex.space3d.TagBoxArray(ba: BoxArray, dm: DistributionMapping, ngrow: IntVect3D)
Distributed array of
TagBoxobjects used during AMR error estimation.Python
AmrCore.error_estoverrides receive a mutableTagBoxArrayand mark cells withset_val(TagBox.SET, ...). Callback arguments are non-owning views and should not be stored after the override returns.- buffer(nbuf: IntVect3D) None[source]
Grow every SET tag by nbuf cells using AMReX tag-buffer rules.
- property dist_map: DistributionMapping
DistributionMapping defining ownership of this tag array.
- property local_size: int
Number of tag boxes owned by this MPI rank.
- map_periodic_remove_duplicates(geom: Geometry) None[source]
Map tags through periodic boundaries described by geom and remove duplicates.
- property n_grow_vect: IntVect3D
Grow width of the tag storage in each coordinate direction.
- set_val(**kwds)
Helper for @overload to raise when called.
- property size: int
Number of boxes in the global tag layout.
- class amrex.space3d.ParGDBBase[source]
Abstract broker for particle geometry, box arrays and distribution maps.
Particle containers use a
ParGDBBaseto query mesh metadata for each AMR level. Python users usually obtain a concreteAmrParGDBfromAmrCore.get_par_gdb().- dist_map(level: SupportsInt | SupportsIndex) DistributionMapping[source]
Return mesh DistributionMapping for AMR level.
- level_defined(level: SupportsInt | SupportsIndex) bool[source]
Return True if AMR level has valid mesh metadata.
- particle_box_array(level: SupportsInt | SupportsIndex) BoxArray[source]
Return particle BoxArray for AMR level.
- particle_dist_map(level: SupportsInt | SupportsIndex) DistributionMapping[source]
Return particle DistributionMapping for AMR level.
- particle_geom(level: SupportsInt | SupportsIndex) Geometry[source]
Return particle Geometry for AMR level.
- ref_ratio(level: SupportsInt | SupportsIndex) IntVect3D[source]
Return the refinement ratio from level to level + 1.
- set_particle_box_array(level: SupportsInt | SupportsIndex, new_ba: BoxArray) None[source]
Replace the particle BoxArray for AMR level.
- set_particle_dist_map(level: SupportsInt | SupportsIndex, new_dm: DistributionMapping) None[source]
Replace the particle DistributionMapping for AMR level.
Particles
Particle support is implemented for both legacy (AoS+SoA) and pure SoA particle memory layouts in AMReX. Additional runtime attributes (Real or Int) are always in SoA memory layout.
amrex::StructOfArrays<NReal, NInt, Allocator> is implemented for many numbers of Real and Int arguments, and allocators, e.g.,
- class amrex.space3d.StructOfArrays_3_0_idcpu_default[source]
- define(arg0: SupportsInt | SupportsIndex, arg1: SupportsInt | SupportsIndex, arg2: Sequence[str], arg3: Sequence[str]) None[source]
- get_int_data(**kwds)
Helper for @overload to raise when called.
- get_real_data(**kwds)
Helper for @overload to raise when called.
- property has_idcpu: bool
In pure SoA particle layout, idcpu is an array in the SoA
- property int_names: list[str]
Names for the int SoA components
- property num_int_comps: int
Get the number of compile-time + runtime Int components
- property num_particles: int
- property num_real_comps: int
Get the number of compile-time + runtime Real components
- property num_real_particles: int
- property num_total_particles: int
- property real_names: list[str]
Names for the Real SoA components
- resize(new_size: SupportsInt | SupportsIndex, strategy: GrowthStrategy = 'GrowthStrategy.Poisson') None[source]
- property size: int
Get the number of particles
- to_cupy(copy=False)[source]
Provide CuPy views into a StructOfArrays.
- Parameters:
self (amrex.StructOfArrays_*) – A StructOfArrays class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A tuple with real and int components that are each dicts of 1D CuPy arrays. The dictionary key order is the same as in the C++ component order. For pure SoA particle layouts, an additional component idcpu with global particle indices is populated.
- Return type:
namedtuple
- Raises:
ImportError – Raises an exception if cupy is not installed
- to_dpnp(copy=False)[source]
Provide dpnp views into a StructOfArrays.
- Parameters:
self (amrex.StructOfArrays_*) – A StructOfArrays class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A tuple with real and int components that are each dicts of 1D dpnp arrays. The dictionary key order is the same as in the C++ component order. For pure SoA particle layouts, an additional component idcpu with global particle indices is populated.
- Return type:
namedtuple
- Raises:
ImportError – Raises an exception if dpnp is not installed
- to_numpy(copy=False)[source]
Provide NumPy views into a StructOfArrays.
- Parameters:
self (amrex.StructOfArrays_*) – A StructOfArrays class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A tuple with real and int components that are each dicts of 1D NumPy arrays. The dictionary key order is the same as in the C++ component order. For pure SoA particle layouts, an additional component idcpu with global particle indices is populated.
- Return type:
namedtuple
- to_xp(copy=False)[source]
Provide NumPy, CuPy or dpnp views into a StructOfArrays, depending on amr.Config.have_gpu and amr.Config.gpu_backend .
This function is similar to CuPy’s xp naming suggestion for CPU/GPU agnostic code: https://docs.cupy.dev/en/stable/user_guide/basic.html#how-to-write-cpu-gpu-agnostic-code
- Parameters:
self (amrex.StructOfArrays_*) – A StructOfArrays class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A tuple with real and int components that are each dicts of 1D NumPy, CuPy or dpnp arrays. The dictionary key order is the same as in the C++ component order. For pure SoA particle layouts, an additional component idcpu with global particle indices is populated.
- Return type:
namedtuple
amrex::ParticleTile<T_ParticleType, NArrayReal, NArrayInt, Allocator> is implemented for both legacy (AoS+SoA) and pure SoA particle types, many number of Real and Int arguments, and allocators, e.g.,
- class amrex.space3d.ParticleTile_pureSoA_3_0_default[source]
- NAI: ClassVar[int] = 0
- NAR: ClassVar[int] = 3
- define(arg0: SupportsInt | SupportsIndex, arg1: SupportsInt | SupportsIndex, arg2: Sequence[str], arg3: Sequence[str], arg4: Arena) None[source]
- property empty: bool
- get_particle_tile_data() ParticleTileData_pureSoA_3_0[source]
- get_struct_of_arrays() StructOfArrays_3_0_idcpu_default[source]
- property num_int_comps: int
- property num_neighbor_particles: int
- property num_particles: int
- property num_real_comps: int
- property num_real_particles: int
- property num_runtime_int_comps: int
- property num_runtime_real_comps: int
- property num_total_particles: int
- push_back_int(**kwds)
Helper for @overload to raise when called.
- push_back_real(**kwds)
Helper for @overload to raise when called.
- resize(count: SupportsInt | SupportsIndex, strategy: GrowthStrategy = 'GrowthStrategy.Poisson') None[source]
- property size: int
- swap(arg0: ParticleTile_pureSoA_3_0_default) None[source]
amrex::ParticleTileData<T_ParticleType, NArrayReal> is implemented for both legacy (AoS+SoA) and pure SoA particle types, many number of Real and Int arguments, e.g.,
- class amrex.space3d.ParticleTileData_pureSoA_3_0[source]
-
- property m_num_runtime_int: int
- property m_num_runtime_real: int
- property m_size: int
amrex::ParticleContainer_impl<ParticleType, T_NArrayReal, T_NArrayInt, Allocator> is implemented for both legacy (AoS+SoA) and pure SoA particle types, many number of Real and Int arguments, and allocators, e.g.,
- class amrex.space3d.ParticleContainer_2_1_3_1_default[source]
- class amrex.space3d.ParticleContainer_2_1_3_1_default(arg0: Geometry, arg1: DistributionMapping, arg2: BoxArray)
- class amrex.space3d.ParticleContainer_2_1_3_1_default(gdb: ParGDBBase)
- class amrex.space3d.ParticleContainer_2_1_3_1_default(arg0: Vector_Geometry, arg1: Vector_DistributionMapping, arg2: Vector_BoxArray, arg3: Vector_int)
- class amrex.space3d.ParticleContainer_2_1_3_1_default(arg0: Vector_Geometry, arg1: Vector_DistributionMapping, arg2: Vector_BoxArray, arg3: Vector_IntVect)
- ConstIterator
alias of
ParConstIter_2_1_3_1_default
- Define(**kwds)
Helper for @overload to raise when called.
- Iterator
alias of
ParIter_2_1_3_1_default
- OK(lev_min: SupportsInt | SupportsIndex = 0, lev_max: SupportsInt | SupportsIndex = -1, nGrow: SupportsInt | SupportsIndex = 0) bool[source]
- add_int_comp(**kwds)
Helper for @overload to raise when called.
- add_particles(other: ParticleContainer_2_1_3_1_default, local: bool = False) None[source]
- add_particles_at_level(particles: ParticleTile_2_1_3_1_default, level: SupportsInt | SupportsIndex, ngrow: SupportsInt | SupportsIndex = 0) None[source]
- add_real_comp(**kwds)
Helper for @overload to raise when called.
- property byte_spread: Annotated[list[int], 'FixedSize(3)']
- const_iterator(*args, level=None)[source]
Create an iterator over all particle tiles
- Parameters:
self (amrex.ParticleContainer_*) – A ParticleContainer class in pyAMReX
args (deprecated positional argument)
level (int | str, optional) – The MR level. Allowed values are [0:self.finest_level+1) and “all”. If there is more than one MR level, the argument is required.
- Returns:
Iterator over all particle tiles at the specified level.
- Return type:
amrex.ParIter_*
Examples
>>> pc.iterator(level="all") >>> pc.iterator(level=0) # only particles on the the coarsest MR level
- define(gdb: ParGDBBase) None[source]
Define this container from a particle metadata broker.
- define_and_return_particle_tile(lev: SupportsInt | SupportsIndex, grid: SupportsInt | SupportsIndex, tile: SupportsInt | SupportsIndex) ParticleTile_2_1_3_1_default[source]
Define, if necessary, and return the particle tile at
(lev, grid, tile).This is useful when particles are inserted in place into a known AMR tile. The returned tile is owned by the particle container.
- property finest_level: int
- get_particles(level: SupportsInt | SupportsIndex) dict[tuple[int, int], ParticleTile_2_1_3_1_default][source]
- init_one_per_cell(arg0: SupportsFloat | SupportsIndex, arg1: SupportsFloat | SupportsIndex, arg2: SupportsFloat | SupportsIndex, arg3: ParticleInitType_2_1_3_1) None[source]
- init_random(arg0: SupportsInt | SupportsIndex, arg1: SupportsInt | SupportsIndex, arg2: ParticleInitType_2_1_3_1, arg3: bool, arg4: RealBox) None[source]
- init_random_per_box(arg0: SupportsInt | SupportsIndex, arg1: SupportsInt | SupportsIndex, arg2: ParticleInitType_2_1_3_1) None[source]
- property int_soa_names: list[str]
Get the names for the int SoA components
- is_soa_particle: ClassVar[bool] = False
- iterator(*args, level=None)[source]
Create an iterator over all particle tiles
- Parameters:
self (amrex.ParticleContainer_*) – A ParticleContainer class in pyAMReX
args (deprecated positional argument)
level (int | str, optional) – The MR level. Allowed values are [0:self.finest_level+1) and “all”. If there is more than one MR level, the argument is required.
- Returns:
Iterator over all particle tiles at the specified level.
- Return type:
amrex.ParIter_*
Examples
>>> pc.iterator(level="all") >>> pc.iterator(level=0) # only particles on the the coarsest MR level
- make_alike() ParticleContainer_2_1_3_1_default[source]
- num_array_int: ClassVar[int] = 1
- num_array_real: ClassVar[int] = 3
- property num_int_comps: int
The number of compile-time and runtime int components in SoA
- property num_position_components: int
- property num_real_comps: int
The number of compile-time and runtime Real components in SoA
- property num_runtime_int_comps: int
The number of runtime Int components in SoA
- property num_runtime_real_comps: int
The number of runtime Real components in SoA
- num_struct_int: ClassVar[int] = 1
- num_struct_real: ClassVar[int] = 2
- number_of_particles(only_local: bool = False) int[source]
Return the number of valid particles on all MPI ranks, unless only_local is specified.
- number_of_particles_at_level(level: SupportsInt | SupportsIndex, only_valid: bool = True, only_local: bool = False) int[source]
- number_of_particles_in_grid(level: SupportsInt | SupportsIndex, only_valid: bool = True, only_local: bool = False) Vector_Long[source]
- property real_soa_names: list[str]
Get the names for the Real SoA components
- redistribute(**kwds)
Helper for @overload to raise when called.
- property size: int
Return the number of valid particles on all MPI ranks
- to_df(local=True, comm=None, root_rank=0)[source]
Copy all particles into a pandas.DataFrame
- Parameters:
self (amrex.ParticleContainer_*) – A ParticleContainer class in pyAMReX
local (bool) – MPI rank-local particles only
comm (MPI Communicator) – if local is False, this defaults to mpi4py.MPI.COMM_WORLD
root_rank (MPI root rank to gather to) – if local is False, this defaults to 0
- Returns:
A concatenated pandas.DataFrame with particles from all levels.
Returns None if no particles were found.
If local=False, then all ranks but the root_rank will return None.
- total_number_of_particles(only_valid: bool = True, only_local: bool = False) int[source]
Return the number of particles (only valid or including invalid) on all MPI ranks, unless only_local is specified.
- write_plotfile(**kwds)
Helper for @overload to raise when called.
- class amrex.space3d.ParticleContainer_pureSoA_3_0_default[source]
- class amrex.space3d.ParticleContainer_pureSoA_3_0_default(arg0: Geometry, arg1: DistributionMapping, arg2: BoxArray)
- class amrex.space3d.ParticleContainer_pureSoA_3_0_default(gdb: ParGDBBase)
- class amrex.space3d.ParticleContainer_pureSoA_3_0_default(arg0: Vector_Geometry, arg1: Vector_DistributionMapping, arg2: Vector_BoxArray, arg3: Vector_int)
- class amrex.space3d.ParticleContainer_pureSoA_3_0_default(arg0: Vector_Geometry, arg1: Vector_DistributionMapping, arg2: Vector_BoxArray, arg3: Vector_IntVect)
- ConstIterator
alias of
ParConstIter_pureSoA_3_0_default
- Define(**kwds)
Helper for @overload to raise when called.
- Iterator
alias of
ParIter_pureSoA_3_0_default
- OK(lev_min: SupportsInt | SupportsIndex = 0, lev_max: SupportsInt | SupportsIndex = -1, nGrow: SupportsInt | SupportsIndex = 0) bool[source]
- add_int_comp(**kwds)
Helper for @overload to raise when called.
- add_particles(other: ParticleContainer_pureSoA_3_0_default, local: bool = False) None[source]
- add_particles_at_level(particles: ParticleTile_pureSoA_3_0_default, level: SupportsInt | SupportsIndex, ngrow: SupportsInt | SupportsIndex = 0) None[source]
- add_real_comp(**kwds)
Helper for @overload to raise when called.
- property byte_spread: Annotated[list[int], 'FixedSize(3)']
- const_iterator(*args, level=None)[source]
Create an iterator over all particle tiles
- Parameters:
self (amrex.ParticleContainer_*) – A ParticleContainer class in pyAMReX
args (deprecated positional argument)
level (int | str, optional) – The MR level. Allowed values are [0:self.finest_level+1) and “all”. If there is more than one MR level, the argument is required.
- Returns:
Iterator over all particle tiles at the specified level.
- Return type:
amrex.ParIter_*
Examples
>>> pc.iterator(level="all") >>> pc.iterator(level=0) # only particles on the the coarsest MR level
- define(gdb: ParGDBBase) None[source]
Define this container from a particle metadata broker.
- define_and_return_particle_tile(lev: SupportsInt | SupportsIndex, grid: SupportsInt | SupportsIndex, tile: SupportsInt | SupportsIndex) ParticleTile_pureSoA_3_0_default[source]
Define, if necessary, and return the particle tile at
(lev, grid, tile).This is useful when particles are inserted in place into a known AMR tile. The returned tile is owned by the particle container.
- property finest_level: int
- get_particles(level: SupportsInt | SupportsIndex) dict[tuple[int, int], ParticleTile_pureSoA_3_0_default][source]
- init_random(arg0: SupportsInt | SupportsIndex, arg1: SupportsInt | SupportsIndex, arg2: ParticleInitType_pureSoA_3_0, arg3: bool, arg4: RealBox) None[source]
- property int_soa_names: list[str]
Get the names for the int SoA components
- is_soa_particle: ClassVar[bool] = True
- iterator(*args, level=None)[source]
Create an iterator over all particle tiles
- Parameters:
self (amrex.ParticleContainer_*) – A ParticleContainer class in pyAMReX
args (deprecated positional argument)
level (int | str, optional) – The MR level. Allowed values are [0:self.finest_level+1) and “all”. If there is more than one MR level, the argument is required.
- Returns:
Iterator over all particle tiles at the specified level.
- Return type:
amrex.ParIter_*
Examples
>>> pc.iterator(level="all") >>> pc.iterator(level=0) # only particles on the the coarsest MR level
- make_alike() ParticleContainer_pureSoA_3_0_default[source]
- num_array_int: ClassVar[int] = 0
- num_array_real: ClassVar[int] = 3
- property num_int_comps: int
The number of compile-time and runtime int components in SoA
- property num_position_components: int
- property num_real_comps: int
The number of compile-time and runtime Real components in SoA
- property num_runtime_int_comps: int
The number of runtime Int components in SoA
- property num_runtime_real_comps: int
The number of runtime Real components in SoA
- num_struct_int: ClassVar[int] = 0
- num_struct_real: ClassVar[int] = 0
- number_of_particles(only_local: bool = False) int[source]
Return the number of valid particles on all MPI ranks, unless only_local is specified.
- number_of_particles_at_level(level: SupportsInt | SupportsIndex, only_valid: bool = True, only_local: bool = False) int[source]
- number_of_particles_in_grid(level: SupportsInt | SupportsIndex, only_valid: bool = True, only_local: bool = False) Vector_Long[source]
- property real_soa_names: list[str]
Get the names for the Real SoA components
- redistribute(**kwds)
Helper for @overload to raise when called.
- property size: int
Return the number of valid particles on all MPI ranks
- to_df(local=True, comm=None, root_rank=0)[source]
Copy all particles into a pandas.DataFrame
- Parameters:
self (amrex.ParticleContainer_*) – A ParticleContainer class in pyAMReX
local (bool) – MPI rank-local particles only
comm (MPI Communicator) – if local is False, this defaults to mpi4py.MPI.COMM_WORLD
root_rank (MPI root rank to gather to) – if local is False, this defaults to 0
- Returns:
A concatenated pandas.DataFrame with particles from all levels.
Returns None if no particles were found.
If local=False, then all ranks but the root_rank will return None.
- total_number_of_particles(only_valid: bool = True, only_local: bool = False) int[source]
Return the number of particles (only valid or including invalid) on all MPI ranks, unless only_local is specified.
- write_plotfile(**kwds)
Helper for @overload to raise when called.
Likewise for other classes accessible and usable on particle containers:
- class amrex.space3d.ParIter_pureSoA_3_0_default(particle_container: ParticleContainer_pureSoA_3_0_default, level: SupportsInt | SupportsIndex)[source]
- is_soa_particle: ClassVar[bool] = True
- class amrex.space3d.ParConstIter_pureSoA_3_0_default(particle_container: ParticleContainer_pureSoA_3_0_default, level: SupportsInt | SupportsIndex)[source]
- class amrex.space3d.ParticleInitType_2_1_3_1[source]
- property int_array_data: Annotated[list[int], 'FixedSize(1)']
- property int_struct_data: Annotated[list[int], 'FixedSize(1)']
- is_soa_particle: ClassVar[bool] = False
- property real_array_data: Annotated[list[float], 'FixedSize(3)']
- property real_struct_data: Annotated[list[float], 'FixedSize(2)']
- class amrex.space3d.ParticleInitType_pureSoA_3_0[source]
- property int_array_data: Annotated[list[int], 'FixedSize(0)']
- is_soa_particle: ClassVar[bool] = True
- property real_array_data: Annotated[list[float], 'FixedSize(3)']
AoS
This is for the legacy, AoS + SoA particle containers only:
amrex::ArrayOfStructs<T_ParticleType, Allocator> is implemented for many numbers of extra Real and Int arguments, and allocators, e.g.,
- class amrex.space3d.ArrayOfStructs_2_1_default[source]
- back() Particle_2_1[source]
get back member. Problem!!!!! this is perfo
- empty(**kwds)
Helper for @overload to raise when called.
- push_back(arg0: Particle_2_1) None[source]
- to_cupy(copy=False)[source]
Provide CuPy views into a ArrayOfStructs.
- Parameters:
self (amrex.ArrayOfStructs_*) – An ArrayOfStructs class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A tuple with real and int components that are each lists of 1D NumPy arrays.
- Return type:
namedtuple
- Raises:
ImportError – Raises an exception if cupy is not installed
- to_numpy(copy=False)[source]
Provide NumPy views into a ArrayOfStructs.
- Parameters:
self (amrex.ArrayOfStructs_*) – An ArrayOfStructs class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A tuple with real and int components that are each lists of 1D NumPy arrays.
- Return type:
namedtuple
- to_xp(copy=False)[source]
Provide NumPy or CuPy views into a ArrayOfStructs, depending on amr.Config.have_gpu .
This function is similar to CuPy’s xp naming suggestion for CPU/GPU agnostic code: https://docs.cupy.dev/en/stable/user_guide/basic.html#how-to-write-cpu-gpu-agnostic-code
- Parameters:
self (amrex.ArrayOfStructs_*) – An ArrayOfStructs class in pyAMReX
copy (bool, optional) – Copy the data if true, otherwise create a view (default).
- Returns:
A tuple with real and int components that are each lists of 1D NumPy or CuPy arrays.
- Return type:
namedtuple
amrex::Particle<T_NReal, T_NInt> is implemented for many numbers of extra Real and Int arguments, e.g.,
- class amrex.space3d.Particle_2_1[source]
- class amrex.space3d.Particle_2_1(arg0: SupportsFloat | SupportsIndex, arg1: SupportsFloat | SupportsIndex, arg2: SupportsFloat | SupportsIndex)
- class amrex.space3d.Particle_2_1(arg0: SupportsFloat | SupportsIndex, arg1: SupportsFloat | SupportsIndex, arg2: SupportsFloat | SupportsIndex, *args)
- class amrex.space3d.Particle_2_1(arg0: SupportsFloat | SupportsIndex, arg1: SupportsFloat | SupportsIndex, arg2: SupportsFloat | SupportsIndex, **kwargs)
- class amrex.space3d.Particle_2_1(**kwargs)
- NInt: ClassVar[int] = 1
- NReal: ClassVar[int] = 2
- NextID(**kwds)
Helper for @overload to raise when called.
- get_idata(**kwds)
Helper for @overload to raise when called.
- get_rdata(**kwds)
Helper for @overload to raise when called.
- pos(**kwds)
Helper for @overload to raise when called.
- setPos(**kwds)
Helper for @overload to raise when called.
- set_idata(**kwds)
Helper for @overload to raise when called.
- set_rdata(**kwds)
Helper for @overload to raise when called.
- property x: float
- property y: float
- property z: float
I/O
Read back particle data from plotfiles and checkpoints, see Read Back Plotfiles:
- amrex.space3d.read_particles(plotfile, particle_dir='particles', communicate=True, container=None)[source]
Read AMReX particle data from a plotfile/checkpoint into a container.
See
amrex.extensions.ParticleContainer.read_particles()for details.
- class amrex.space3d.ParticleHeader[source]
- class GridEntry[source]
- property count: int
number of particles stored for this grid
- property where: int
byte offset of this grid’s particle data within the data file
- property which: int
index of the binary data file (DATA_XXXXX) holding this grid’s particles
- property convert_ids: bool
whether particle ids need conversion (Version_Two_Dot_One+)
- property dim: int
AMREX_SPACEDIM the file was written with
- property finest_level: int
finest level present in the file
- property grids: list
where each grid’s binary particle data is stored, as a list (levels) of lists of
GridEntry. Grids without particles have a zerocount.- Type:
per level and grid
- property how: str
‘single’ or ‘double’
- Type:
precision the data was written in
- property int_comp_names: Vector_string
names of the integer components (len == num_int)
- property is_checkpoint: bool
True if the file is a checkpoint, False for a plotfile
- property next_id: int
the next particle id to hand out
- property num_int: int
number of integer components
- property num_particles: int
total number of particles in the file
- property num_real: int
excludes the positions)
- Type:
number of real components (pure SoA
- static read(dir: str, file: str) ParticleHeader[source]
Read and parse the
Headerof a particle plotfile/checkpoint.This discovers the on-disk layout (number and names of real/int components, precision, checkpoint flag, …) without constructing a matching ParticleContainer first.
- Parameters:
dir (str) – plotfile/checkpoint directory
file (str) – particle sub-directory name (e.g.
"particle0")
- property real_comp_names: Vector_string
names of the real components (len == num_real)
- property version: str
raw version string of the file format
Embedded Boundaries
Embedded boundary (EB) support in pyAMReX is still minimal. To build pyAMReX with
EB support, you need to add -DAMReX_EB=ON to CMake build options.
- amrex.space3d.EB2_Build(geom: Geometry, required_coarsening_level: SupportsInt | SupportsIndex, max_coarsening_level: SupportsInt | SupportsIndex, ngrow: SupportsInt | SupportsIndex = 4, build_coarse_level_by_coarsening: bool = True, extend_domain_face: bool = True, num_coarsen_opt: SupportsInt | SupportsIndex = 0) None[source]
EB generation
- amrex.space3d.makeEBFabFactory(geom: Geometry, ba: BoxArray, dm: DistributionMapping, ngrow: Vector_int, support: EBSupport) EBFArrayBoxFactory[source]
Make EBFArrayBoxFactory for given Geometry, BoxArray and DistributionMapping