pyop2.types package¶
Submodules¶
pyop2.types.access module¶
- class pyop2.types.access.Access(value)¶
Bases:
IntEnum
An enumeration.
- READ = 1¶
- WRITE = 2¶
- RW = 3¶
- INC = 4¶
- MIN = 5¶
- MAX = 6¶
- pyop2.types.access.READ = Access.READ¶
The
Global
,Dat
, orMat
is accessed read-only.
- pyop2.types.access.WRITE = Access.WRITE¶
The
Global
,Dat
, orMat
is accessed write-only, and OP2 is not required to handle write conflicts.
- pyop2.types.access.RW = Access.RW¶
The
Global
,Dat
, orMat
is accessed for reading and writing, and OP2 is not required to handle write conflicts.
- pyop2.types.access.INC = Access.INC¶
The kernel computes increments to be summed onto a
Global
,Dat
, orMat
. OP2 is responsible for managing the write conflicts caused.
- pyop2.types.access.MIN = Access.MIN¶
The kernel contributes to a reduction into a
Global
using amin
operation. OP2 is responsible for reducing over the different kernel invocations.
- pyop2.types.access.MAX = Access.MAX¶
The kernel contributes to a reduction into a
Global
using amax
operation. OP2 is responsible for reducing over the different kernel invocations.
pyop2.types.dat module¶
- class pyop2.types.dat.AbstractDat(dataset, data=None, dtype=None, name=None)¶
Bases:
DataCarrier
,EmptyDataMixin
,ABC
OP2 vector data. A
Dat
holds values on every element of aDataSet
.oIf a
Set
is passed as thedataset
argument, rather than aDataSet
, theDat
is created with a defaultDataSet
dimension of 1.If a
Dat
is passed as thedataset
argument, a copy is returned.It is permissible to pass None as the data argument. In this case, allocation of the data buffer is postponed until it is accessed.
Note
If the data buffer is not passed in, it is implicitly initialised to be zero.
When a
Dat
is passed topyop2.op2.par_loop()
, the map via which indirection occurs and the access descriptor are passed by calling theDat
. For instance, if aDat
namedD
is to be accessed for reading via aMap
namedM
, this is accomplished byD(pyop2.READ, M)
The
Map
through which indirection occurs can be indexed using the index notation described in the documentation for theMap
. Direct access to a Dat is accomplished by omitting the path argument.Dat
objects support the pointwise linear algebra operations+=
,*=
,-=
,/=
, where*=
and/=
also support multiplication / division by a scalar.- property dataset¶
DataSet
on which the Dat is defined.
- property dim¶
The shape of the values for each element of the object.
- property cdim¶
The scalar number of values for each member of the object. This is the product of the dim tuple.
- property data¶
Numpy array containing the data values.
With this accessor you are claiming that you will modify the values you get back. If you only need to look at the values, use
data_ro()
instead.This only shows local values, to see the halo values too use
data_with_halos()
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_with_halos¶
A view of this
Dat
s data.This accessor marks the
Dat
as dirty, seedata()
for more details on the semantics.With this accessor, you get to see up to date halo values, but you should not try and modify them, because they will be overwritten by the next halo exchange.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_ro¶
Numpy array containing the data values. Read-only.
With this accessor you are not allowed to modify the values you get back. If you need to do so, use
data()
instead.This only shows local values, to see the halo values too use
data_ro_with_halos()
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_ro_with_halos¶
A view of this
Dat
s data.This accessor does not mark the
Dat
as dirty, and is a read only view, seedata_ro()
for more details on the semantics.With this accessor, you get to see up to date halo values, but you should not try and modify them, because they will be overwritten by the next halo exchange.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_wo¶
Numpy array containing the data values that is only valid for writing to.
This only shows local values, to see the halo values too use
data_wo_with_halos()
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_wo_with_halos¶
Return a write-only view of all the data values.
This method, unlike
data_with_halos()
, avoids a halo exchange if the halo is dirty.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- save(filename)¶
Write the data array to file
filename
in NumPy format.
- load(filename)¶
Read the data stored in file
filename
into a NumPy array and store the values in_data()
.
- property shape¶
- property dtype¶
The Python type of the data.
- property nbytes¶
Return an estimate of the size of the data associated with this
Dat
in bytes. This will be the correct size of the data payload, but does not take into account the (presumably small) overhead of the object and its metadata.Note that this is the process local memory usage, not the sum over all MPI processes.
- zero(subset=None)¶
Zero the data associated with this
Dat
- Parameters:
subset – A
Subset
of entries to zero (optional).
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- copy(other, subset=None)¶
Copy the data in this
Dat
into another.- Parameters:
other – The destination
Dat
subset – A
Subset
of elements to copy (optional)
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- inner(other)¶
Compute the l2 inner product of the flattened
Dat
- Parameters:
other – the other
Dat
to compute the inner product against. The complex conjugate of this is taken.
- property norm¶
Compute the l2 norm of this
Dat
Note
This acts on the flattened data (see also
inner()
).
- global_to_local_begin(access_mode)¶
Begin a halo exchange from global to ghosted representation.
- Parameters:
access_mode – Mode with which the data will subsequently be accessed.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- global_to_local_end(access_mode)¶
End a halo exchange from global to ghosted representation.
- Parameters:
access_mode – Mode with which the data will subsequently be accessed.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- local_to_global_begin(insert_mode)¶
Begin a halo exchange from ghosted to global representation.
- Parameters:
insert_mode – insertion mode (an access descriptor)
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- local_to_global_end(insert_mode)¶
End a halo exchange from ghosted to global representation.
- Parameters:
insert_mode – insertion mode (an access descriptor)
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- frozen_halo(access_mode)¶
Temporarily disable halo exchanges inside a context manager.
- Parameters:
access_mode – Mode with which the data will subsequently be accessed.
This is useful in cases where one is repeatedly writing to a
Dat
with the same access descriptor since the intermediate updates can be skipped.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- freeze_halo(access_mode)¶
Disable halo exchanges.
- Parameters:
access_mode – Mode with which the data will subsequently be accessed.
Note that some bookkeeping is needed when freezing halos. Prefer to use the
Dat.frozen_halo()
context manager.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- unfreeze_halo()¶
Re-enable halo exchanges.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- class pyop2.types.dat.DatView(dat, index)¶
Bases:
AbstractDat
An indexed view into a
Dat
.This object can be used like a
Dat
but the kernel will only see the requested index, rather than the full data.- Parameters:
dat – The
Dat
to create a view into.index – The component to select a view of.
- property cdim¶
The scalar number of values for each member of the object. This is the product of the dim tuple.
- property dim¶
The shape of the values for each element of the object.
- property shape¶
- property halo_valid¶
- property dat_version¶
- property data¶
Numpy array containing the data values.
With this accessor you are claiming that you will modify the values you get back. If you only need to look at the values, use
data_ro()
instead.This only shows local values, to see the halo values too use
data_with_halos()
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_ro¶
Numpy array containing the data values. Read-only.
With this accessor you are not allowed to modify the values you get back. If you need to do so, use
data()
instead.This only shows local values, to see the halo values too use
data_ro_with_halos()
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_wo¶
Numpy array containing the data values that is only valid for writing to.
This only shows local values, to see the halo values too use
data_wo_with_halos()
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_with_halos¶
A view of this
Dat
s data.This accessor marks the
Dat
as dirty, seedata()
for more details on the semantics.With this accessor, you get to see up to date halo values, but you should not try and modify them, because they will be overwritten by the next halo exchange.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_ro_with_halos¶
A view of this
Dat
s data.This accessor does not mark the
Dat
as dirty, and is a read only view, seedata_ro()
for more details on the semantics.With this accessor, you get to see up to date halo values, but you should not try and modify them, because they will be overwritten by the next halo exchange.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_wo_with_halos¶
Return a write-only view of all the data values.
This method, unlike
data_with_halos()
, avoids a halo exchange if the halo is dirty.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- class pyop2.types.dat.Dat(*args, **kwargs)¶
Bases:
AbstractDat
,VecAccessMixin
- class pyop2.types.dat.MixedDat(mdset_or_dats)¶
Bases:
AbstractDat
,VecAccessMixin
A container for a bag of
Dat
s.Initialized either from a
MixedDataSet
, aMixedSet
, or an iterable ofDataSet
s and/orSet
s, where all theSet
s are implcitly upcast toDataSet
smdat = op2.MixedDat(mdset) mdat = op2.MixedDat([dset1, ..., dsetN])
or from an iterable of
Dat
smdat = op2.MixedDat([dat1, ..., datN])
- property dat_version¶
- increment_dat_version()¶
- property dtype¶
The NumPy dtype of the data.
- property data¶
Numpy arrays containing the data excluding halos.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_with_halos¶
Numpy arrays containing the data including halos.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_ro¶
Numpy arrays with read-only data excluding halos.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_ro_with_halos¶
Numpy arrays with read-only data including halos.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_wo¶
Numpy arrays with read-only data excluding halos.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property data_wo_with_halos¶
Numpy arrays with read-only data including halos.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property halo_valid¶
Does this Dat have up to date halos?
- global_to_local_begin(access_mode)¶
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- global_to_local_end(access_mode)¶
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- local_to_global_begin(insert_mode)¶
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- local_to_global_end(insert_mode)¶
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- freeze_halo(access_mode)¶
Disable halo exchanges.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- unfreeze_halo()¶
Re-enable halo exchanges.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- zero(subset=None)¶
Zero the data associated with this
MixedDat
.- Parameters:
subset – optional subset of entries to zero (not implemented).
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property nbytes¶
Return an estimate of the size of the data associated with this
MixedDat
in bytes. This will be the correct size of the data payload, but does not take into account the (presumably small) overhead of the object and its metadata.Note that this is the process local memory usage, not the sum over all MPI processes.
- copy(other, subset=None)¶
Copy the data in this
MixedDat
into another.- Parameters:
other – The destination
MixedDat
subset – Subsets are not supported, this must be
None
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- inner(other)¶
Compute the l2 inner product.
- Parameters:
other – the other
MixedDat
to compute the inner product against
- vec_context(access)¶
A context manager scattering the arrays of all components of this
MixedDat
into a contiguousPETSc.Vec
and reverse scattering to the original arrays when exiting the context.- Parameters:
access – Access descriptor: READ, WRITE, or RW.
Note
The
Vec
obtained from this context is in the correct order to be left multiplied by a compatibleMixedMat
. In parallel it is not just a concatenation of the underlyingDat
s.
pyop2.types.data_carrier module¶
- class pyop2.types.data_carrier.DataCarrier¶
Bases:
ABC
Abstract base class for OP2 data.
Actual objects will be
DataCarrier
objects of rank 0 (Global
), rank 1 (Dat
), or rank 2 (Mat
)- property dtype¶
The Python type of the data.
- property ctype¶
The c type of the data.
- property name¶
User-defined label.
- property dim¶
The shape tuple of the values for each element of the object.
- property cdim¶
The scalar number of values for each member of the object. This is the product of the dim tuple.
- increment_dat_version()¶
- class pyop2.types.data_carrier.EmptyDataMixin(data, dtype, shape)¶
Bases:
ABC
A mixin for
Dat
andGlobal
objects that takes care of allocating data on demand if the user has passed nothing in.Accessing the
_data
property allocates a zeroed data array if it does not already exist.
- class pyop2.types.data_carrier.VecAccessMixin(petsc_counter=None)¶
Bases:
ABC
- property dat_version¶
- abstract vec_context(access)¶
- property vec¶
Context manager for a PETSc Vec appropriate for this Dat.
You’re allowed to modify the data you get back from this view.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property vec_wo¶
Context manager for a PETSc Vec appropriate for this Dat.
You’re allowed to modify the data you get back from this view, but you cannot read from it.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property vec_ro¶
Context manager for a PETSc Vec appropriate for this Dat.
You’re not allowed to modify the data you get back from this view.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
pyop2.types.dataset module¶
- class pyop2.types.dataset.DataSet(*args, **kwargs)¶
Bases:
ObjectCached
PyOP2 Data Set
Set used in the op2.Dat structures to specify the dimension of the data.
- property dim¶
The shape tuple of the values for each element of the set.
- property cdim¶
The scalar number of values for each member of the set. This is the product of the dim tuple.
- property name¶
Returns the name of the data set.
- property set¶
Returns the parent set of the data set.
- property scalar_lgmap¶
- property unblocked_lgmap¶
A PETSc LGMap mapping process-local indices to global indices for this
DataSet
with a block size of 1.
- property field_ises¶
A list of PETSc ISes defining the global indices for each set in the DataSet.
Used when extracting blocks from matrices for solvers.
- property local_ises¶
A list of PETSc ISes defining the local indices for each set in the DataSet.
Used when extracting blocks from matrices for assembly.
- property layout_vec¶
A PETSc Vec compatible with the dof layout of this DataSet.
- property dm¶
- class pyop2.types.dataset.GlobalDataSet(*args, **kwargs)¶
Bases:
DataSet
A proxy
DataSet
for use in aSparsity
where the matrix hasGlobal
rows or columns.- Parameters:
global – The
Global
on which this object is based.
- property dim¶
The shape tuple of the values for each element of the set.
- property cdim¶
The scalar number of values for each member of the set. This is the product of the dim tuple.
- property name¶
Returns the name of the data set.
- property set¶
Returns the parent set of the data set.
- property size¶
The number of local entries in the Dataset (1 on rank 0)
- property unblocked_lgmap¶
A PETSc LGMap mapping process-local indices to global indices for this
DataSet
with a block size of 1.
- property local_ises¶
A list of PETSc ISes defining the local indices for each set in the DataSet.
Used when extracting blocks from matrices for assembly.
- property layout_vec¶
A PETSc Vec compatible with the dof layout of this DataSet.
- property dm¶
- class pyop2.types.dataset.MixedDataSet(*args, **kwargs)¶
Bases:
DataSet
A container for a bag of
DataSet
s.Initialized either from a
MixedSet
and an iterable or iterator ofdims
of corresponding lengthmdset = op2.MixedDataSet(mset, [dim1, ..., dimN])
or from a tuple of
Set
s and an iterable ofdims
of corresponding lengthmdset = op2.MixedDataSet([set1, ..., setN], [dim1, ..., dimN])
If all
dims
are to be the same, they can also be given as anint
for either of above invocationsmdset = op2.MixedDataSet(mset, dim) mdset = op2.MixedDataSet([set1, ..., setN], dim)
Initialized from a
MixedSet
without explicitly specifyingdims
they default to 1mdset = op2.MixedDataSet(mset)
Initialized from an iterable or iterator of
DataSet
s and/orSet
s, whereSet
s are implicitly upcast toDataSet
s of dim 1mdset = op2.MixedDataSet([dset1, ..., dsetN])
- Parameters:
arg – a
MixedSet
or an iterable or a generator expression ofSet
s orDataSet
s or a mixture of bothdims – None (the default) or an
int
or an iterable or generator expression ofint
s, which must be of same length as arg
Warning
When using generator expressions for
arg
ordims
, these must terminate or else will cause an infinite loop.- property dim¶
The shape tuple of the values for each element of the sets.
- property cdim¶
The sum of the scalar number of values for each member of the sets. This is the sum of products of the dim tuples.
- property name¶
Returns the name of the data sets.
- property set¶
Returns the
MixedSet
thisMixedDataSet
is defined on.
- property layout_vec¶
A PETSc Vec compatible with the dof layout of this MixedDataSet.
- property lgmap¶
A PETSc LGMap mapping process-local indices to global indices for this
MixedDataSet
.
pyop2.types.glob module¶
- class pyop2.types.glob.SetFreeDataCarrier(dim, data=None, dtype=None, name=None)¶
Bases:
DataCarrier
,EmptyDataMixin
- property shape¶
- property dtype¶
The Python type of the data.
- property data_ro¶
Data array.
- property data_wo¶
- property data¶
Data array.
- property data_with_halos¶
- property data_ro_with_halos¶
- property data_wo_with_halos¶
- property halo_valid¶
- copy(other, subset=None)¶
Copy the data in this
SetFreeDataCarrier
into another.- Parameters:
other – The destination
Global
subset – A
Subset
of elements to copy (optional)
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- property split¶
- property nbytes¶
Return an estimate of the size of the data associated with this
Global
in bytes. This will be the correct size of the data payload, but does not take into account the overhead of the object and its metadata. This renders this method of little statistical significance, however it is included to make the interface consistent.
- inner(other)¶
- class pyop2.types.glob.Global(dim, data=None, dtype=None, name=None, comm=None)¶
Bases:
SetFreeDataCarrier
,VecAccessMixin
OP2 global value.
When a
Global
is passed to apyop2.op2.par_loop()
, the access descriptor is passed by calling theGlobal
. For example, if aGlobal
namedG
is to be accessed for reading, this is accomplished by:G(pyop2.READ)
It is permissible to pass None as the data argument. In this case, allocation of the data buffer is postponed until it is accessed.
Note
If the data buffer is not passed in, it is implicitly initialised to be zero.
- property dataset¶
- duplicate()¶
Return a deep copy of self.
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- zero(subset=None)¶
This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- global_to_local_begin(access_mode)¶
Dummy halo operation for the case in which a
Global
forms part of aMixedDat
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- global_to_local_end(access_mode)¶
Dummy halo operation for the case in which a
Global
forms part of aMixedDat
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- local_to_global_begin(insert_mode)¶
Dummy halo operation for the case in which a
Global
forms part of aMixedDat
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- local_to_global_end(insert_mode)¶
Dummy halo operation for the case in which a
Global
forms part of aMixedDat
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- frozen_halo(access_mode)¶
Dummy halo operation for the case in which a
Global
forms part of aMixedDat
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- freeze_halo(access_mode)¶
Dummy halo operation for the case in which a
Global
forms part of aMixedDat
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- unfreeze_halo()¶
Dummy halo operation for the case in which a
Global
forms part of aMixedDat
.This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. You can set PYOP2_SPMD_STRICT=1 in your environment to try and catch non-collective calls.
- class pyop2.types.glob.Constant(dim, data=None, dtype=None, name=None, comm=None)¶
Bases:
SetFreeDataCarrier
OP2 constant value.
When a
Constant
is passed to apyop2.op2.par_loop()
, the access descriptor is alwaysAccess.READ
. Used in cases where collective functionality is not required, or is not desirable. For example: objects with no associated mesh and do not have a communicator.- duplicate()¶
Return a deep copy of self.
pyop2.types.halo module¶
- class pyop2.types.halo.Halo¶
Bases:
ABC
A description of a halo associated with a
pyop2.types.set.Set
.The halo object describes which
pyop2.types.set.Set
elements are sent where, and whichpyop2.types.set.Set
elements are received from where.- abstract property comm¶
The MPI communicator for this halo.
- abstract property local_to_global_numbering¶
The mapping from process-local to process-global numbers for this halo.
- abstract global_to_local_begin(dat, insert_mode)¶
Begin an exchange from global (assembled) to local (ghosted) representation.
- Parameters:
dat – The
pyop2.types.dat.Dat
to exchange.insert_mode – The insertion mode.
- abstract global_to_local_end(dat, insert_mode)¶
Finish an exchange from global (assembled) to local (ghosted) representation.
- Parameters:
dat – The
pyop2.types.dat.Dat
to exchange.insert_mode – The insertion mode.
- abstract local_to_global_begin(dat, insert_mode)¶
Begin an exchange from local (ghosted) to global (assembled) representation.
- Parameters:
dat – The
pyop2.types.dat.Dat
to exchange.insert_mode – The insertion mode.
- abstract local_to_global_end(dat, insert_mode)¶
Finish an exchange from local (ghosted) to global (assembled) representation.
- Parameters:
dat – The
pyop2.types.dat.Dat
to exchange.insert_mode – The insertion mode.
pyop2.types.map module¶
- class pyop2.types.map.Map(iterset, toset, arity, values=None, name=None, offset=None, offset_quotient=None)¶
Bases:
object
OP2 map, a relation between two
Set
objects.Each entry in the
iterset
maps toarity
entries in thetoset
. When a map is used in apyop2.op2.par_loop()
, it is possible to use Python index notation to select an individual entry on the right hand side of this map. There are three possibilities:No index. All
arity
Dat
entries will be passed to the kernel.An integer:
some_map[n]
. Then
th entry of the map result will be passed to the kernel.
- dtype = dtype('int32')¶
- property split¶
- property iterset¶
Set
mapped from.
- property toset¶
Set
mapped to.
- property arity¶
Arity of the mapping: number of toset elements mapped to per iterset element.
- property arities¶
Arity of the mapping: number of toset elements mapped to per iterset element.
- Return type:
tuple
- property values¶
Mapping array.
This only returns the map values for local points, to see the halo points too, use
values_with_halo()
.
- property values_with_halo¶
Mapping array.
This returns all map values (including halo points), see
values()
if you only need to look at the local points.
- property name¶
User-defined label
- property offset¶
The vertical offset.
- property offset_quotient¶
The offset quotient.
- class pyop2.types.map.PermutedMap(map_, permutation)¶
Bases:
Map
Composition of a standard
Map
with a constant permutation.- Parameters:
map – The map to permute.
permutation – The permutation of the map indices.
Where normally staging to element data is performed as
local[i] = global[map[i]]
With a
PermutedMap
we instead getlocal[i] = global[map[permutation[i]]]
This might be useful if your local kernel wants data in a different order to the one that the map provides, and you don’t want two global-sized data structures.
- class pyop2.types.map.ComposedMap(*maps_, name=None)¶
Bases:
Map
Composition of :class:`Map`s, :class:`PermutedMap`s, and/or :class:`ComposedMap`s.
- Parameters:
maps – The maps to compose.
Where normally staging to element data is performed as
local[i] = global[map[i]]
With a
ComposedMap
we instead getlocal[i] = global[maps_[0][maps_[1][maps_[2][...[i]]]]]
This might be useful if the map you want can be represented by a composition of existing maps.
- property values¶
Mapping array.
This only returns the map values for local points, to see the halo points too, use
values_with_halo()
.
- class pyop2.types.map.MixedMap(*args, **kwargs)¶
Bases:
Map
,ObjectCached
A container for a bag of
Map
s.- Parameters:
maps (iterable) – Iterable of
Map
s
- property iterset¶
MixedSet
mapped from.
- property toset¶
MixedSet
mapped to.
- property arity¶
Arity of the mapping: total number of toset elements mapped to per iterset element.
- property arities¶
Arity of the mapping: number of toset elements mapped to per iterset element.
- Return type:
tuple
- property values¶
Mapping arrays excluding data for halos.
This only returns the map values for local points, to see the halo points too, use
values_with_halo()
.
- property values_with_halo¶
Mapping arrays including data for halos.
This returns all map values (including halo points), see
values()
if you only need to look at the local points.
- property name¶
User-defined labels
- property offset¶
Vertical offsets.
- property offset_quotient¶
Offsets quotient.
pyop2.types.mat module¶
pyop2.types.set module¶
- class pyop2.types.set.Set(size, name=None, halo=None, comm=None, constrained_size=0)¶
Bases:
object
OP2 set.
- Parameters:
size (integer or list of four integers.) – The size of the set.
name (string) – The name of the set (optional).
halo – An exisiting halo to use (optional).
When the set is employed as an iteration space in a
pyop2.op2.par_loop()
, the extent of any local iteration space within each set entry is indicated in brackets. See the example inpyop2.op2.par_loop()
for more details.The size of the set can either be an integer, or a list of four integers. The latter case is used for running in parallel where we distinguish between:
CORE (owned and not touching halo)
OWNED (owned, touching halo)
EXECUTE HALO (not owned, but executed over redundantly)
NON EXECUTE HALO (not owned, read when executing in the execute halo)
If a single integer is passed, we assume that we’re running in serial and there is no distinction.
The division of set elements is:
[0, CORE) [CORE, OWNED) [OWNED, GHOST)
Halo send/receive data is stored on sets in a
Halo
.- property indices¶
Returns iterator.
- property core_size¶
Core set size. Owned elements not touching halo elements.
- property constrained_size¶
- property size¶
Set size, owned elements.
- property total_size¶
Set size including ghost elements.
- property sizes¶
Set sizes: core, owned, execute halo, total.
- property core_part¶
- property owned_part¶
- property name¶
User-defined label
- property halo¶
Halo
associated with this Set
- property partition_size¶
Default partition size
- property layers¶
Return None (not an
ExtrudedSet
).
- intersection(other)¶
- union(other)¶
- difference(other)¶
- symmetric_difference(other)¶
- class pyop2.types.set.GlobalSet(comm=None)¶
Bases:
Set
- property core_size¶
Core set size. Owned elements not touching halo elements.
- property size¶
Set size, owned elements.
- property total_size¶
Total set size, including halo elements.
- property sizes¶
Set sizes: core, owned, execute halo, total.
- property name¶
User-defined label
- property halo¶
Halo
associated with this Set
- property partition_size¶
Default partition size
- class pyop2.types.set.ExtrudedSet(parent, layers, extruded_periodic=False)¶
Bases:
Set
OP2 ExtrudedSet.
- Parameters:
parent (a
Set
.) – The parentSet
to build thisExtrudedSet
on top oflayers (an integer, indicating the number of layers for every entity, or an array of shape (parent.total_size, 2) giving the start and one past the stop layer for every entity. An entry
a, b = layers[e, ...]
means that the layers for entitye
run over [a, b).) – The number of layers in thisExtrudedSet
.
The number of layers indicates the number of time the base set is extruded in the direction of the
ExtrudedSet
. As a result, there arelayers-1
extruded “cells” in an extruded set.- property parent¶
- property layers¶
The layers of this extruded set.
- property layers_array¶
- class pyop2.types.set.Subset(superset, indices)¶
Bases:
ExtrudedSet
OP2 subset.
- Parameters:
- property superset¶
Returns the superset Set
- property indices¶
Returns the indices pointing in the superset.
- property owned_indices¶
Return the indices that correspond to the owned entities of the superset.
- property layers_array¶
- intersection(other)¶
- union(other)¶
- difference(other)¶
- symmetric_difference(other)¶
- class pyop2.types.set.SetPartition(set, offset, size)¶
Bases:
object
- class pyop2.types.set.MixedSet(*args, **kwargs)¶
Bases:
Set
,ObjectCached
A container for a bag of
Set
s.- Parameters:
sets (iterable) – Iterable of
Set
s orExtrudedSet
s
- property core_size¶
Core set size. Owned elements not touching halo elements.
- property constrained_size¶
Set size, owned constrained elements.
- property size¶
Set size, owned elements.
- property total_size¶
Total set size, including halo elements.
- property sizes¶
Set sizes: core, owned, execute halo, total.
- property name¶
User-defined labels.
- property layers¶
Numbers of layers in the extruded mesh (or None if this MixedSet is not extruded).