petsc4py.PETSc.DMSwarm#
- class petsc4py.PETSc.DMSwarm#
Bases:
DM
A
DM
object used to represent arrays of data (fields) of arbitrary type.Enumerations
Swarm collection types.
Swarm migration types.
Swarm PIC layout types.
Swarm types.
Methods Summary
addNPoints
(npoints)Add space for a number of new points in the
DMSwarm
.addPoint
()Add space for one new point in the
DMSwarm
.Apply a collection method and gather points in neighbor ranks.
Reset the
DMSwarm
to the size prior to callingcollectViewCreate
.copyPoint
(pi, pj)Copy point pi to point pj in the
DMSwarm
.create
([comm])Create an empty DM object and set its type to
DM.Type.SWARM
.createGlobalVectorFromField
(fieldname)Create a global
Vec
object associated with a given field.createLocalVectorFromField
(fieldname)Create a local
Vec
object associated with a given field.destroyGlobalVectorFromField
(fieldname)Destroy the global
Vec
object associated with a given field.destroyLocalVectorFromField
(fieldname)Destroy the local
Vec
object associated with a given field.Finalize the registration of fields to a
DMSwarm
.getField
(fieldname)Return arrays storing all entries associated with a field.
Return the local length of fields registered.
getSize
()Return the total length of fields registered.
Initiate the registration of fields to a
DMSwarm
.insertPointUsingCellDM
(layoutType, fill_param)Insert point coordinates within each cell.
migrate
([remove_sent_points])Relocate points defined in the
DMSwarm
to other MPI ranks.projectFields
(dm, fieldnames, vecs[, mode])registerField
(fieldname, blocksize[, dtype])Register a field to a
DMSwarm
with a native PETSc data type.Remove the last point from the
DMSwarm
.removePointAtIndex
(index)Remove a specific point from the
DMSwarm
.restoreField
(fieldname)Restore accesses associated with a registered field.
setCellDM
(dm)setLocalSizes
(nlocal, buffer)Set the length of all registered fields on the
DMSwarm
.setPointCoordinates
(coordinates[, ...])Set point coordinates in a
DMSwarm
from a user-defined list.setPointCoordinatesCellwise
(coordinates)Insert point coordinates within each cell.
setPointsUniformCoordinates
(min, max, npoints)Set point coordinates in a
DMSwarm
on a regular (ijk) grid.setType
(dmswarm_type)Set particular flavor of
DMSwarm
.Setup up a
DMSwarm
point sort context.Return whether the sort context is up-to-date.
Return the number of points in a cell.
Create an array of point indices for all points in a cell.
Return the sizes associated with a
DMSwarm
point sorting context.Invalidate the
DMSwarm
point sorting context.vectorDefineField
(fieldname)Set the fields from which to define a
Vec
object.viewFieldsXDMF
(filename, fieldnames)Write a selection of
DMSwarm
fields to an XDMF3 file.viewXDMF
(filename)Write this
DMSwarm
fields to an XDMF3 file.Methods Documentation
- addPoint()#
Add space for one new point in the
DMSwarm
.Not collective.
See also
Source code at petsc4py/PETSc/DMSwarm.pyx:319
- Return type:
- collectViewCreate()#
Apply a collection method and gather points in neighbor ranks.
Collective.
See also
Source code at petsc4py/PETSc/DMSwarm.pyx:447
- Return type:
- collectViewDestroy()#
Reset the
DMSwarm
to the size prior to callingcollectViewCreate
.Collective.
See also
Source code at petsc4py/PETSc/DMSwarm.pyx:459
- Return type:
- copyPoint(pi, pj)#
Copy point pi to point pj in the
DMSwarm
.Not collective.
- Parameters:
- Return type:
See also
- create(comm=None)#
Create an empty DM object and set its type to
DM.Type.SWARM
.Collective.
DMs are the abstract objects in PETSc that mediate between meshes and discretizations and the algebraic solvers, time integrators, and optimization algorithms.
- Parameters:
comm (Comm | None) – MPI communicator, defaults to
Sys.getDefaultComm
.- Return type:
- createGlobalVectorFromField(fieldname)#
Create a global
Vec
object associated with a given field.Collective.
The vector must be returned to the
DMSwarm
using a matching call todestroyGlobalVectorFromField
.
- createLocalVectorFromField(fieldname)#
Create a local
Vec
object associated with a given field.Collective.
The vector must be returned to the
DMSwarm
using a matching call todestroyLocalVectorFromField
.
- destroyGlobalVectorFromField(fieldname)#
Destroy the global
Vec
object associated with a given field.Collective.
- destroyLocalVectorFromField(fieldname)#
Destroy the local
Vec
object associated with a given field.Collective.
- finalizeFieldRegister()#
Finalize the registration of fields to a
DMSwarm
.Collective.
Source code at petsc4py/PETSc/DMSwarm.pyx:167
- Return type:
- getCellDM()#
Return
DM
cell attached toDMSwarm
.Collective.
See also
Source code at petsc4py/PETSc/DMSwarm.pyx:488
- Return type:
- getField(fieldname)#
Return arrays storing all entries associated with a field.
Not collective.
The returned array contains underlying values of the field.
The array must be returned to the
DMSwarm
using a matching call torestoreField
.- Parameters:
fieldname (str) – The textual name to identify this field.
- Returns:
numpy.ndarray
– The type of the entries in the array will match the type of the field.blocksize (
int
) – The number of data items per point
- Return type:
See also
- getLocalSize()#
Return the local length of fields registered.
Not collective.
See also
Source code at petsc4py/PETSc/DMSwarm.pyx:400
- Return type:
- getSize()#
Return the total length of fields registered.
Collective.
See also
Source code at petsc4py/PETSc/DMSwarm.pyx:414
- Return type:
- initializeFieldRegister()#
Initiate the registration of fields to a
DMSwarm
.Collective.
After all fields have been registered, you must call
finalizeFieldRegister
.Source code at petsc4py/PETSc/DMSwarm.pyx:153
- Return type:
- insertPointUsingCellDM(layoutType, fill_param)#
Insert point coordinates within each cell.
Not collective.
- Parameters:
layout_type – Method used to fill each cell with the cell DM.
fill_param (int) – Parameter controlling how many points per cell are added (the meaning of this parameter is dependent on the layout type).
layoutType (PICLayoutType)
- Return type:
See also
- migrate(remove_sent_points=False)#
Relocate points defined in the
DMSwarm
to other MPI ranks.Collective.
- Parameters:
remove_sent_points (bool) – Flag indicating if sent points should be removed from the current MPI rank.
- Return type:
See also
- projectFields(dm, fieldnames, vecs, mode=None)#
Project a set of
DMSwarm
fields onto the cellDM
.Collective.
- Parameters:
- Return type:
See also
- registerField(fieldname, blocksize, dtype=ScalarType)#
Register a field to a
DMSwarm
with a native PETSc data type.Collective.
- Parameters:
- Return type:
See also
- removePoint()#
Remove the last point from the
DMSwarm
.Not collective.
See also
Source code at petsc4py/PETSc/DMSwarm.pyx:349
- Return type:
- restoreField(fieldname)#
Restore accesses associated with a registered field.
Not collective.
See also
- setCellDM(dm)#
-
Collective.
See also
- setLocalSizes(nlocal, buffer)#
Set the length of all registered fields on the
DMSwarm
.Not collective.
- Parameters:
- Return type:
See also
- setPointCoordinates(coordinates, redundant=False, mode=None)#
Set point coordinates in a
DMSwarm
from a user-defined list.Collective.
- Parameters:
redundant (bool) – If set to
True
, it is assumed that coordinates are only valid on rank 0 and should be broadcast to other ranks.mode (InsertMode | None) – Indicates whether to append points to the swarm (
InsertMode.ADD
), or override existing points (InsertMode.INSERT
).
- Return type:
See also
- setPointCoordinatesCellwise(coordinates)#
Insert point coordinates within each cell.
Not collective.
Point coordinates are defined over the reference cell.
- Parameters:
coordinates (Sequence[float]) – The coordinates (defined in the local coordinate system for each cell) to insert.
- Return type:
See also
- setPointsUniformCoordinates(min, max, npoints, mode=None)#
Set point coordinates in a
DMSwarm
on a regular (ijk) grid.Collective.
- Parameters:
min (Sequence[float]) – Minimum coordinate values in the x, y, z directions (array of length
dim
).max (Sequence[float]) – Maximum coordinate values in the x, y, z directions (array of length
dim
).npoints (Sequence[int]) – Number of points in each spatial direction (array of length
dim
).mode (InsertMode | None) – Indicates whether to append points to the swarm (
InsertMode.ADD
), or override existing points (InsertMode.INSERT
).
- Return type:
See also
- sortGetAccess()#
Setup up a
DMSwarm
point sort context.Not collective.
The point sort context is used for efficient traversal of points within a cell.
You must call
sortRestoreAccess
when you no longer need access to the sort context.See also
Source code at petsc4py/PETSc/DMSwarm.pyx:700
- Return type:
- sortGetIsValid()#
Return whether the sort context is up-to-date.
Not collective.
Returns the flag associated with a
DMSwarm
point sorting context.See also
Source code at petsc4py/PETSc/DMSwarm.pyx:774
- Return type:
- sortGetNumberOfPointsPerCell(e)#
Return the number of points in a cell.
Not collective.
See also
- sortGetPointsPerCell(e)#
Create an array of point indices for all points in a cell.
Not collective.
See also
- sortGetSizes()#
Return the sizes associated with a
DMSwarm
point sorting context.Not collective.
- Returns:
- Return type:
See also
- sortRestoreAccess()#
Invalidate the
DMSwarm
point sorting context.Not collective.
See also
Source code at petsc4py/PETSc/DMSwarm.pyx:718
- Return type:
- vectorDefineField(fieldname)#
Set the fields from which to define a
Vec
object.Collective.
The field will be used when
DM.createLocalVec
, orDM.createGlobalVec
is called.See also
- viewFieldsXDMF(filename, fieldnames)#
Write a selection of
DMSwarm
fields to an XDMF3 file.Collective.
- Parameters:
- Return type:
See also