DMSwarm (Particle Methods)

DMSwarm manages particle-based methods including particle-in-cell (PIC), smoothed particle hydrodynamics (SPH), and general particle simulations.

Overview

DMSwarm provides:

  • Dynamic particle creation and migration
  • Field registration for particle data
  • Particle-mesh coupling
  • Particle migration across MPI processes
  • Support for PIC and general particle methods
  • Cell-based particle management

Basic Usage Pattern

using PETSc, MPI

# Initialize MPI and PETSc
MPI.Init()
petsclib = PETSc.getlib()
PETSc.initialize(petsclib)

# Create a DMSwarm in PIC mode
swarm = LibPETSc.DMCreate(petsclib, MPI.COMM_WORLD)
LibPETSc.DMSetType(petsclib, swarm, LibPETSc.DMSWARM)
# Set the geometric/topological dimension for the swarm (required)
LibPETSc.DMSetDimension(petsclib, swarm, 1)

# Set swarm type to PIC
LibPETSc.DMSwarmSetType(petsclib, swarm, LibPETSc.DMSWARM_PIC)

# Create background mesh (here we use a 1D DMDA for simplicity)
da = LibPETSc.DMDACreate1d(petsclib, MPI.COMM_WORLD, LibPETSc.DM_BOUNDARY_NONE, 10, 1, 1, C_NULL)

# Set the cell DM for PIC
LibPETSc.DMSwarmSetCellDM(petsclib, swarm, da)

# Register a particle field `velocity` with blocksize 3 (x,y,z components)
LibPETSc.DMSwarmRegisterPetscDatatypeField(
    petsclib, swarm,
    "velocity", 3, LibPETSc.PETSC_DOUBLE
)

# Finalize field registration
LibPETSc.DMSwarmFinalizeFieldRegister(petsclib, swarm)

# Set number of particles
nparticles = 100
LibPETSc.DMSwarmSetLocalSizes(petsclib, swarm, nparticles, 0)

# Access and set particle data using DMSwarmGetField / DMSwarmRestoreField.
# `DMSwarmGetField` returns the block size, the data type and a raw pointer to the
# field storage (blocksize * nparticles entries); wrap it with `unsafe_wrap`.
blocksize, dtype, ptr = LibPETSc.DMSwarmGetField(petsclib, swarm, "velocity")
@assert dtype == LibPETSc.PETSC_DOUBLE
data = unsafe_wrap(Array, Ptr{Float64}(ptr), blocksize * nparticles)
# Initialize velocity values
for i in eachindex(data)
    data[i] = 0.1 * i
end
# Restore the field when done (unlocks internal storage)
LibPETSc.DMSwarmRestoreField(petsclib, swarm, "velocity", blocksize, dtype)

# Cleanup
LibPETSc.DMDestroy(petsclib, swarm)
LibPETSc.DMDestroy(petsclib, da)

# Finalize PETSc and MPI
PETSc.finalize(petsclib)
MPI.Finalize()

DMSwarm Functions

PETSc.LibPETSc.DMSwarmAddCellDM — Method
DMSwarmAddCellDM(petsclib::PetscLibType, sw::AbstractPetscDM, celldm::DMSwarmCellDM)

Adds a cell DM to the DMSWARM

Collective

Input Parameters:

  • sw - a DMSWARM
  • celldm - the DMSwarmCellDM

Level: beginner

See also: DM, DMSWARM, DMSwarmSetType(), DMSwarmPushCellDM(), DMSwarmSetCellDM(), DMSwarmMigrate()

External Links

source
PETSc.LibPETSc.DMSwarmAddNPoints — Method
DMSwarmAddNPoints(petsclib::PetscLibType, dm::AbstractPetscDM, npoints::PetscInt)

Add space for a number of new points in the DMSWARM

Not Collective

Input Parameters:

  • dm - a DMSWARM
  • npoints - the number of new points to add

Level: beginner

See also: DM, DMSWARM, DMSwarmAddPoint()

External Links

source
PETSc.LibPETSc.DMSwarmAddPoint — Method
DMSwarmAddPoint(petsclib::PetscLibType, dm::AbstractPetscDM)

Add space for one new point in the DMSWARM

Not Collective

Input Parameter:

  • dm - a DMSWARM

Level: beginner

See also: DM, DMSWARM, DMSwarmAddNPoints()

External Links

source
PETSc.LibPETSc.DMSwarmCollectViewCreate — Method
DMSwarmCollectViewCreate(petsclib::PetscLibType, dm::AbstractPetscDM)

Applies a collection method and gathers points in neighbour ranks into the DMSWARM

Collective

Input Parameter:

  • dm - the DMSWARM

Level: advanced

See also: DM, DMSWARM, DMSwarmCollectViewDestroy(), DMSwarmSetCollectType()

External Links

source
PETSc.LibPETSc.DMSwarmComputeLocalSize — Method
DMSwarmComputeLocalSize(petsclib::PetscLibType, sw::AbstractPetscDM, N::PetscInt, density::Ptr{Cvoid})

Compute the local number and distribution of particles based upon a density function

Not Collective

Input Parameters:

  • sw - The DMSWARM
  • N - The target number of particles
  • density - The density field for the particle layout, normalized to unity

Level: advanced

See also: DMSWARM, DMSwarmComputeLocalSizeFromOptions()

External Links

source
PETSc.LibPETSc.DMSwarmComputeMoments — Method
DMSwarmComputeMoments(petsclib::PetscLibType, sw::AbstractPetscDM, coordinate::String, weight::String, moments::Vector{PetscReal})

Compute the first three particle moments for a given field

Noncollective

Input Parameters:

  • sw - the DMSWARM
  • coordinate - the coordinate field name
  • weight - the weight field name

Output Parameter:

  • moments - the field moments

Level: intermediate

See also: DM, DMSWARM, DMPlexComputeMoments()

External Links

source
PETSc.LibPETSc.DMSwarmCopyPoint — Method
DMSwarmCopyPoint(petsclib::PetscLibType, dm::AbstractPetscDM, pi::PetscInt, pj::PetscInt)

Copy point pj to point pi in the DMSWARM

Not Collective

Input Parameters:

  • dm - a DMSWARM
  • pi - the index of the point to copy
  • pj - the point index where the copy should be located

Level: beginner

See also: DM, DMSWARM, DMSwarmRemovePoint()

External Links

source
PETSc.LibPETSc.DMSwarmCreateGlobalVectorFromField — Method
vec::PetscVec = DMSwarmCreateGlobalVectorFromField(petsclib::PetscLibType, dm::AbstractPetscDM, fieldname::String)

Creates a Vec object sharing the array associated with a given field

Collective

Input Parameters:

  • dm - a DMSWARM
  • fieldname - the textual name given to a registered field

Output Parameter:

  • vec - the vector

Level: beginner

See also: DM, DMSWARM, DMSwarmRegisterPetscDatatypeField(), DMSwarmDestroyGlobalVectorFromField()

External Links

source
PETSc.LibPETSc.DMSwarmCreateGlobalVectorFromFields — Method
vec::PetscVec = DMSwarmCreateGlobalVectorFromFields(petsclib::PetscLibType, dm::AbstractPetscDM, Nf::PetscInt, fieldnames::String)

Creates a Vec object sharing the array associated with a given field set

Collective

Input Parameters:

  • dm - a DMSWARM
  • Nf - the number of fields
  • fieldnames - the textual names given to the registered fields

Output Parameter:

  • vec - the vector

Level: beginner

See also: DM, DMSWARM, DMSwarmRegisterPetscDatatypeField(), DMSwarmDestroyGlobalVectorFromFields()

External Links

source
PETSc.LibPETSc.DMSwarmCreateLocalVectorFromField — Method
vec::PetscVec = DMSwarmCreateLocalVectorFromField(petsclib::PetscLibType, dm::AbstractPetscDM, fieldname::String)

Creates a Vec object sharing the array associated with a given field

Collective

Input Parameters:

  • dm - a DMSWARM
  • fieldname - the textual name given to a registered field

Output Parameter:

  • vec - the vector

Level: beginner

See also: DM, DMSWARM, DMSwarmRegisterPetscDatatypeField(), DMSwarmDestroyLocalVectorFromField()

External Links

source
PETSc.LibPETSc.DMSwarmCreateLocalVectorFromFields — Method
vec::PetscVec = DMSwarmCreateLocalVectorFromFields(petsclib::PetscLibType, dm::AbstractPetscDM, Nf::PetscInt, fieldnames::String)

Creates a Vec object sharing the array associated with a given field set

Collective

Input Parameters:

  • dm - a DMSWARM
  • Nf - the number of fields
  • fieldnames - the textual names given to the registered fields

Output Parameter:

  • vec - the vector

Level: beginner

See also: DM, DMSWARM, DMSwarmRegisterPetscDatatypeField(), DMSwarmDestroyLocalVectorFromField()

External Links

source
PETSc.LibPETSc.DMSwarmCreateMassMatrixSquare — Method
mass::PetscMat = DMSwarmCreateMassMatrixSquare(petsclib::PetscLibType, dmCoarse::AbstractPetscDM, dmFine::AbstractPetscDM)

Creates the block-diagonal of the square, M^Tp Mp, of the particle mass matrix M_p

Collective

Input Parameters:

  • dmCoarse - a DMSWARM
  • dmFine - a DMPLEX

Output Parameter:

  • mass - the square of the particle mass matrix

Level: advanced

See also: DM, DMSWARM, DMCreateMassMatrix()

External Links

source
PETSc.LibPETSc.DMSwarmCreatePointPerCellCount — Method
ncells::PetscInt,count::Ptr{PetscInt} = DMSwarmCreatePointPerCellCount(petsclib::PetscLibType, sw::AbstractPetscDM)

Count the number of points within all cells in the cell DM

Not Collective

Input Parameter:

  • sw - the DMSWARM

Output Parameters:

  • ncells - the number of cells in the cell DM (optional argument, pass NULL to ignore)
  • count - array of length ncells containing the number of points per cell

Level: beginner

See also: DMSWARM, DMSwarmSetType(), DMSwarmSetCellDM(), DMSwarmType

External Links

source
PETSc.LibPETSc.DMSwarmDestroyGlobalVectorFromField — Method
vec::PetscVec = DMSwarmDestroyGlobalVectorFromField(petsclib::PetscLibType, dm::AbstractPetscDM, fieldname::String)

Destroys the Vec object which share the array associated with a given field

Collective

Input Parameters:

  • dm - a DMSWARM
  • fieldname - the textual name given to a registered field

Output Parameter:

  • vec - the vector

Level: beginner

See also: DM, DMSWARM, DMSwarmRegisterPetscDatatypeField(), DMSwarmCreateGlobalVectorFromField()

External Links

source
PETSc.LibPETSc.DMSwarmDestroyGlobalVectorFromFields — Method
vec::PetscVec = DMSwarmDestroyGlobalVectorFromFields(petsclib::PetscLibType, dm::AbstractPetscDM, Nf::PetscInt, fieldnames::String)

Destroys the Vec object which share the array associated with a given field set

Collective

Input Parameters:

  • dm - a DMSWARM
  • Nf - the number of fields
  • fieldnames - the textual names given to the registered fields

Output Parameter:

  • vec - the vector

Level: beginner

See also: DM, DMSWARM, DMSwarmRegisterPetscDatatypeField(), DMSwarmCreateGlobalVectorFromField()

External Links

source
PETSc.LibPETSc.DMSwarmDestroyLocalVectorFromField — Method
vec::PetscVec = DMSwarmDestroyLocalVectorFromField(petsclib::PetscLibType, dm::AbstractPetscDM, fieldname::String)

Destroys the Vec object which share the array associated with a given field

Collective

Input Parameters:

  • dm - a DMSWARM
  • fieldname - the textual name given to a registered field

Output Parameter:

  • vec - the vector

Level: beginner

See also: DM, DMSWARM, DMSwarmRegisterPetscDatatypeField(), DMSwarmCreateLocalVectorFromField()

External Links

source
PETSc.LibPETSc.DMSwarmDestroyLocalVectorFromFields — Method
vec::PetscVec = DMSwarmDestroyLocalVectorFromFields(petsclib::PetscLibType, dm::AbstractPetscDM, Nf::PetscInt, fieldnames::String)

Destroys the Vec object which share the array associated with a given field set

Collective

Input Parameters:

  • dm - a DMSWARM
  • Nf - the number of fields
  • fieldnames - the textual names given to the registered fields

Output Parameter:

  • vec - the vector

Level: beginner

See also: DM, DMSWARM, DMSwarmRegisterPetscDatatypeField(), DMSwarmCreateLocalVectorFromFields()

External Links

source
PETSc.LibPETSc.DMSwarmDuplicate — Method
nsw::PetscDM = DMSwarmDuplicate(petsclib::PetscLibType, sw::AbstractPetscDM)

Creates a new DMSWARM with the same fields and cell DMs but no particles

Collective

Input Parameter:

  • sw - the DMSWARM

Output Parameter:

  • nsw - the new DMSWARM

Level: beginner

See also: DM, DMSWARM, DMSwarmCreate(), DMClone()

External Links

source
PETSc.LibPETSc.DMSwarmFinalizeFieldRegister — Method
DMSwarmFinalizeFieldRegister(petsclib::PetscLibType, dm::AbstractPetscDM)

Finalizes the registration of fields to a DMSWARM

Collective

Input Parameter:

  • dm - a DMSWARM

Level: beginner

See also: DM, DMSWARM, DMSwarmInitializeFieldRegister(), DMSwarmRegisterPetscDatatypeField(), DMSwarmRegisterUserStructField(), DMSwarmRegisterUserDatatypeField()

External Links

source
PETSc.LibPETSc.DMSwarmGetCellDM — Method
dm::PetscDM = DMSwarmGetCellDM(petsclib::PetscLibType, sw::AbstractPetscDM)

Fetches the active cell DM

Collective

Input Parameter:

  • sw - a DMSWARM

Output Parameter:

  • dm - the active DM for the DMSWARM

Level: beginner

See also: DM, DMSWARM, DMSwarmSetCellDM()

External Links

source
PETSc.LibPETSc.DMSwarmGetCellDMActive — Method
celldm::DMSwarmCellDM = DMSwarmGetCellDMActive(petsclib::PetscLibType, sw::AbstractPetscDM)

Returns the active cell DM for a DMSWARM

Collective

Input Parameter:

  • sw - a DMSWARM

Output Parameter:

  • celldm - the active DMSwarmCellDM

Level: beginner

See also: DM, DMSWARM, DMSwarmCellDM, DMSwarmSetType(), DMSwarmAddCellDM(), DMSwarmSetCellDM(), DMSwarmMigrate()

External Links

source
PETSc.LibPETSc.DMSwarmGetCellDMByName — Method
celldm::DMSwarmCellDM = DMSwarmGetCellDMByName(petsclib::PetscLibType, sw::AbstractPetscDM, name::String)

Get a DMSwarmCellDM from its name

Not collective

Input Parameters:

  • sw - a DMSWARM
  • name - the name

Output Parameter:

  • celldm - the DMSwarmCellDM

Level: beginner

See also: DM, DMSWARM, DMSwarmSetCellDM(), DMSwarmGetCellDMNames()

External Links

source
PETSc.LibPETSc.DMSwarmGetCellDMNames — Method
Ndm::PetscInt,celldms::Vector{String} = DMSwarmGetCellDMNames(petsclib::PetscLibType, sw::AbstractPetscDM)

Get the list of cell DM names

Not collective

Input Parameter:

  • sw - a DMSWARM

Output Parameters:

  • Ndm - the number of DMSwarmCellDM in the DMSWARM
  • celldms - the name of each DMSwarmCellDM

Level: beginner

See also: DM, DMSWARM, DMSwarmSetCellDM(), DMSwarmGetCellDMByName()

External Links

source
PETSc.LibPETSc.DMSwarmGetCellSwarm — Method
DMSwarmGetCellSwarm(petsclib::PetscLibType, sw::AbstractPetscDM, cellID::PetscInt, cellswarm::AbstractPetscDM)

Extracts a single cell from the DMSWARM object, returns it as a single cell DMSWARM. The cell DM is filtered for fields of that cell, and the filtered DM is used as the cell DM of the new swarm object.

Noncollective

Input Parameters:

  • sw - the DMSWARM
  • cellID - the integer id of the cell to be extracted and filtered
  • cellswarm - The DMSWARM to receive the cell

Level: beginner

See also: DM, DMSWARM, DMSwarmRestoreCellSwarm()

External Links

source
PETSc.LibPETSc.DMSwarmGetCoordinateFunction — Method
coordFunc::Ptr{Cvoid} = DMSwarmGetCoordinateFunction(petsclib::PetscLibType, sw::AbstractPetscDM)

Get the function setting initial particle positions, if it exists

Not Collective

Input Parameter:

  • sw - the DMSWARM

Output Parameter:

  • coordFunc - the function setting initial particle positions, or NULL, see PetscSimplePointFn for the calling sequence

Level: intermediate

See also: DMSWARM, DMSwarmSetCoordinateFunction(), DMSwarmGetVelocityFunction(), DMSwarmInitializeCoordinates(), PetscSimplePointFn

External Links

source
PETSc.LibPETSc.DMSwarmGetField — Method
blocksize::PetscInt,type::PetscDataType,data::Ptr{Cvoid} = DMSwarmGetField(petsclib::PetscLibType, dm::AbstractPetscDM, fieldname::String)

Get access to the underlying array storing all entries associated with a registered field

Not Collective, No Fortran Support

Input Parameters:

  • dm - a DMSWARM
  • fieldname - the textual name to identify this field

Output Parameters:

  • blocksize - the number of each data type
  • type - the data type
  • data - pointer to raw array

Level: beginner

See also: DM, DMSWARM, DMSwarmRestoreField()

External Links

source
PETSc.LibPETSc.DMSwarmGetFieldInfo — Method
blocksize::PetscInt,type::PetscDataType = DMSwarmGetFieldInfo(petsclib::PetscLibType, dm::AbstractPetscDM, fieldname::String)

Return the block size and data type of a registered DMSWARM field without accessing its data.

Not Collective

Input Parameters:

  • dm - a DMSWARM
  • fieldname - the name of the registered field

Output Parameters:

  • blocksize - the number of entries of type per particle, or NULL
  • type - the PetscDataType of a single entry, or NULL

Level: intermediate

See also: DM, DMSWARM, DMSwarmGetField(), DMSwarmRestoreField(), DMSwarmRegisterPetscDatatypeField()

External Links

source
PETSc.LibPETSc.DMSwarmGetLocalSize — Method
nlocal::PetscInt = DMSwarmGetLocalSize(petsclib::PetscLibType, dm::AbstractPetscDM)

Retrieves the local length of fields registered

Not Collective

Input Parameter:

  • dm - a DMSWARM

Output Parameter:

  • nlocal - the length of each registered field

Level: beginner

See also: DM, DMSWARM, DMSwarmGetSize(), DMSwarmSetLocalSizes()

External Links

source
PETSc.LibPETSc.DMSwarmGetMigrateType — Method
mtype::DMSwarmMigrateType = DMSwarmGetMigrateType(petsclib::PetscLibType, dm::AbstractPetscDM)

Get the style of point migration

Logically Collective

Input Parameter:

  • dm - the DMSWARM

Output Parameter:

  • mtype - The migration type, see DMSwarmMigrateType

Level: intermediate

See also: DM, DMSWARM, DMSwarmMigrateType, DMSwarmMigrate()

External Links

source
PETSc.LibPETSc.DMSwarmGetNumSpecies — Method
Ns::PetscInt = DMSwarmGetNumSpecies(petsclib::PetscLibType, sw::AbstractPetscDM)

Get the number of particle species

Not Collective

Input Parameter:

  • sw - the DMSWARM

Output Parameters:

  • Ns - the number of species

Level: intermediate

See also: DMSWARM, DMSwarmSetNumSpecies(), DMSwarmSetType(), DMSwarmType

External Links

source
PETSc.LibPETSc.DMSwarmGetSize — Method
n::PetscInt = DMSwarmGetSize(petsclib::PetscLibType, dm::AbstractPetscDM)

Retrieves the total length of fields registered

Collective

Input Parameter:

  • dm - a DMSWARM

Output Parameter:

  • n - the total length of each registered field

Level: beginner

See also: DM, DMSWARM, DMSwarmGetLocalSize(), DMSwarmSetLocalSizes()

External Links

source
PETSc.LibPETSc.DMSwarmGetType — Method
stype::DMSwarmType = DMSwarmGetType(petsclib::PetscLibType, sw::AbstractPetscDM)

Get particular flavor of DMSWARM

Collective

Input Parameter:

  • sw - the DMSWARM

Output Parameter:

  • stype - the DMSWARM type (e.g. DMSWARM_PIC)

Level: advanced

See also: DM, DMSWARM, DMSwarmSetMigrateType(), DMSwarmSetCollectType(), DMSwarmType, DMSWARM_PIC, DMSWARM_BASIC

External Links

source
PETSc.LibPETSc.DMSwarmGetVelocityFunction — Method
velFunc::Ptr{Cvoid} = DMSwarmGetVelocityFunction(petsclib::PetscLibType, sw::AbstractPetscDM)

Get the function setting initial particle velocities, if it exists

Not Collective

Input Parameter:

  • sw - the DMSWARM

Output Parameter:

  • velFunc - the function setting initial particle velocities, or NULL, see PetscSimplePointFn for the calling sequence

Level: intermediate

See also: DMSWARM, DMSwarmSetVelocityFunction(), DMSwarmGetCoordinateFunction(), DMSwarmInitializeVelocities(), PetscSimplePointFn

External Links

source
PETSc.LibPETSc.DMSwarmInitializeFieldRegister — Method
DMSwarmInitializeFieldRegister(petsclib::PetscLibType, dm::AbstractPetscDM)

Initiates the registration of fields to a DMSWARM

Collective

Input Parameter:

  • dm - a DMSWARM

Level: beginner

See also: DM, DMSWARM, DMSwarmFinalizeFieldRegister(), DMSwarmRegisterPetscDatatypeField(), DMSwarmRegisterUserStructField(), DMSwarmRegisterUserDatatypeField()

External Links

source
PETSc.LibPETSc.DMSwarmInitializeVelocities — Method
DMSwarmInitializeVelocities(petsclib::PetscLibType, sw::AbstractPetscDM, sampler::Ptr{Cvoid}, v0::Vector{PetscReal})

Set the initial velocities of particles using a distribution.

Collective

Input Parameters:

  • sw - The DMSWARM object
  • sampler - A function which uniformly samples the velocity PDF
  • v0 - The velocity scale for nondimensionalization for each species

Level: advanced

See also: DMSWARM, DMSwarmComputeLocalSize(), DMSwarmInitializeCoordinates(), DMSwarmInitializeVelocitiesFromOptions()

External Links

source
PETSc.LibPETSc.DMSwarmInitializeVelocitiesFromOptions — Method
DMSwarmInitializeVelocitiesFromOptions(petsclib::PetscLibType, sw::AbstractPetscDM, v0::Vector{PetscReal})

Set the initial velocities of particles using a distribution determined from options.

Collective

Input Parameters:

  • sw - The DMSWARM object
  • v0 - The velocity scale for nondimensionalization for each species

Level: advanced

See also: DMSWARM, DMSwarmComputeLocalSize(), DMSwarmInitializeCoordinates(), DMSwarmInitializeVelocities()

External Links

source
PETSc.LibPETSc.DMSwarmInsertPointsUsingCellDM — Method
DMSwarmInsertPointsUsingCellDM(petsclib::PetscLibType, dm::AbstractPetscDM, layout_type::DMSwarmPICLayoutType, fill_param::PetscInt)

Insert point coordinates within each cell

Not Collective

Input Parameters:

  • dm - the DMSWARM
  • layout_type - method used to fill each cell with the cell DM
  • fill_param - parameter controlling how many points per cell are added (the meaning of this parameter is dependent on the layout type)

Level: beginner

See also: DMSWARM, DMSwarmPICLayoutType, DMSwarmSetType(), DMSwarmSetCellDM(), DMSwarmType

External Links

source
PETSc.LibPETSc.DMSwarmMigrate — Method
DMSwarmMigrate(petsclib::PetscLibType, dm::AbstractPetscDM, remove_sent_points::PetscBool)

Relocates points defined in the DMSWARM to other MPI-ranks

Collective

Input Parameters:

  • dm - the DMSWARM
  • remove_sent_points - flag indicating if sent points should be removed from the current MPI-rank

Level: advanced

See also: DM, DMSWARM, DMSwarmSetMigrateType()

External Links

source
PETSc.LibPETSc.DMSwarmProjectFields — Method
DMSwarmProjectFields(petsclib::PetscLibType, sw::AbstractPetscDM, dm::AbstractPetscDM, nfields::PetscInt, fieldnames::String, fields::Vector{<:AbstractPetscVec}, mode::ScatterMode)

Project a set of swarm fields onto another DM

Collective

Input Parameters:

  • sw - the DMSWARM
  • dm - the DM, or NULL to use the cell DM
  • nfields - the number of swarm fields to project
  • fieldnames - the textual names of the swarm fields to project
  • fields - an array of Vec's of length nfields
  • mode - if SCATTER_FORWARD then map particles to the continuum, and if SCATTER_REVERSE map the continuum to particles

Level: beginner

See also: DMSWARM, DMSwarmSetType(), DMSwarmSetCellDM(), DMSwarmType

External Links

source
PETSc.LibPETSc.DMSwarmProjectGradientFields — Method
DMSwarmProjectGradientFields(petsclib::PetscLibType, sw::AbstractPetscDM, dm::AbstractPetscDM, nfields::PetscInt, fieldnames::String, fields::Vector{<:AbstractPetscVec}, mode::ScatterMode)

Project the gradient of continuum fields on a mesh onto particle fields in a DMSWARM, or the reverse

Collective

Input Parameters:

  • sw - the DMSWARM
  • dm - the continuum DM (a DMPLEX); if NULL the swarm's cell DM is used
  • nfields - the number of fields to project
  • fieldnames - the names of the swarm fields to receive (or supply) the gradient
  • fields - the corresponding mesh Vec objects
  • mode - SCATTER_FORWARD to project mesh field gradients to particles, SCATTER_REVERSE to project particle values back to the mesh

Level: intermediate

See also: DMSWARM, DMPLEX, DMSwarmProjectFields(), DMSwarmVectorDefineFields(), DMSwarmCreateGlobalVectorFromField()

External Links

source
PETSc.LibPETSc.DMSwarmRegisterPetscDatatypeField — Method
DMSwarmRegisterPetscDatatypeField(petsclib::PetscLibType, dm::AbstractPetscDM, fieldname::String, blocksize::PetscInt, type::PetscDataType)

Register a field to a DMSWARM with a native PETSc data type

Collective

Input Parameters:

  • dm - a DMSWARM
  • fieldname - the textual name to identify this field
  • blocksize - the number of each data type
  • type - a valid PETSc data type (PETSC_CHAR, PETSC_SHORT, PETSC_INT, PETSC_FLOAT, PETSC_REAL, PETSC_LONG)

Level: beginner

See also: DM, DMSWARM, DMSwarmRegisterUserStructField(), DMSwarmRegisterUserDatatypeField()

External Links

source
PETSc.LibPETSc.DMSwarmRegisterUserDatatypeField — Method
DMSwarmRegisterUserDatatypeField(petsclib::PetscLibType, dm::AbstractPetscDM, fieldname::String, size::Csize_t, blocksize::PetscInt)

Register a user defined data type to a DMSWARM

Collective

Input Parameters:

  • dm - a DMSWARM
  • fieldname - the textual name to identify this field
  • size - the size in bytes of the user data type
  • blocksize - the number of each data type

Level: beginner

See also: DM, DMSWARM, DMSwarmRegisterPetscDatatypeField(), DMSwarmRegisterUserStructField()

External Links

source
PETSc.LibPETSc.DMSwarmRegisterUserStructField — Method
DMSwarmRegisterUserStructField(petsclib::PetscLibType, dm::AbstractPetscDM, fieldname::String, size::Csize_t)

Register a user defined struct to a DMSWARM

Collective

Input Parameters:

  • dm - a DMSWARM
  • fieldname - the textual name to identify this field
  • size - the size in bytes of the user struct of each data type

Level: beginner

See also: DM, DMSWARM, DMSwarmRegisterPetscDatatypeField(), DMSwarmRegisterUserDatatypeField()

External Links

source
PETSc.LibPETSc.DMSwarmRemap — Method
DMSwarmRemap(petsclib::PetscLibType, sw::AbstractPetscDM)

Project the swarm fields onto a new set of particles

Collective

Input Parameter:

  • sw - The DMSWARM object

Level: beginner

See also: DMSWARM, DMSwarmMigrate(), DMSwarmCrate()

External Links

source
PETSc.LibPETSc.DMSwarmReplace — Method
DMSwarmReplace(petsclib::PetscLibType, dm::AbstractPetscDM, ndm::AbstractPetscDM)

Replace the internal state of a DMSWARM with that of another DMSWARM, sharing the underlying particle data and destroying the source DM.

Collective

Input Parameters:

  • dm - the destination DMSWARM, whose current contents are discarded
  • ndm - pointer to the source DMSWARM; destroyed and set to NULL on return

Level: developer

See also: DM, DMSWARM, DMSwarmDuplicate(), DMDestroy()

External Links

source
PETSc.LibPETSc.DMSwarmRestoreCellSwarm — Method
DMSwarmRestoreCellSwarm(petsclib::PetscLibType, sw::AbstractPetscDM, cellID::PetscInt, cellswarm::AbstractPetscDM)

Restores a DMSWARM object obtained with DMSwarmGetCellSwarm(). All fields are copied back into the parent swarm.

Noncollective

Input Parameters:

  • sw - the parent DMSWARM
  • cellID - the integer id of the cell to be copied back into the parent swarm
  • cellswarm - the cell swarm object

Level: beginner

See also: DM, DMSWARM, DMSwarmGetCellSwarm()

External Links

source
PETSc.LibPETSc.DMSwarmRestoreField — Method
data::Ptr{Cvoid} = DMSwarmRestoreField(petsclib::PetscLibType, dm::AbstractPetscDM, fieldname::String, blocksize::PetscInt, type::PetscDataType)

Restore access to the underlying array storing all entries associated with a registered field

Not Collective

Input Parameters:

  • dm - a DMSWARM
  • fieldname - the textual name to identify this field

Output Parameters:

  • blocksize - the number of each data type
  • type - the data type
  • data - pointer to raw array

Level: beginner

See also: DM, DMSWARM, DMSwarmGetField()

External Links

source
PETSc.LibPETSc.DMSwarmSetCellDM — Method
DMSwarmSetCellDM(petsclib::PetscLibType, sw::AbstractPetscDM, dm::AbstractPetscDM)

Attaches a DM to a DMSWARM

Collective

Input Parameters:

  • sw - a DMSWARM
  • dm - the DM to attach to the DMSWARM

Level: beginner

See also: DM, DMSWARM, DMSwarmSetType(), DMSwarmGetCellDM(), DMSwarmMigrate()

External Links

source
PETSc.LibPETSc.DMSwarmSetCellDMActive — Method
DMSwarmSetCellDMActive(petsclib::PetscLibType, sw::AbstractPetscDM, name::String)

Activates a cell DM for a DMSWARM

Collective

Input Parameters:

  • sw - a DMSWARM
  • name - name of the cell DM to active for the DMSWARM

Level: beginner

See also: DM, DMSWARM, DMSwarmCellDM, DMSwarmSetType(), DMSwarmAddCellDM(), DMSwarmSetCellDM(), DMSwarmMigrate()

External Links

source
PETSc.LibPETSc.DMSwarmSetCoordinateFunction — Method
DMSwarmSetCoordinateFunction(petsclib::PetscLibType, sw::AbstractPetscDM, coordFunc::Ptr{Cvoid})

Set the function setting initial particle positions

Not Collective

Input Parameters:

  • sw - the DMSWARM
  • coordFunc - the function setting initial particle positions, see PetscSimplePointFn for the calling sequence

Level: intermediate

See also: DMSWARM, DMSwarmGetCoordinateFunction(), DMSwarmSetVelocityFunction(), DMSwarmInitializeCoordinates(), PetscSimplePointFn

External Links

source
PETSc.LibPETSc.DMSwarmSetLocalSizes — Method
DMSwarmSetLocalSizes(petsclib::PetscLibType, sw::AbstractPetscDM, nlocal::PetscInt, buffer::PetscInt)

Sets the length of all registered fields on the DMSWARM

Not Collective

Input Parameters:

  • sw - a DMSWARM
  • nlocal - the length of each registered field
  • buffer - the length of the buffer used to efficient dynamic re-sizing

Level: beginner

See also: DM, DMSWARM, DMSwarmGetLocalSize()

External Links

source
PETSc.LibPETSc.DMSwarmSetMigrateType — Method
DMSwarmSetMigrateType(petsclib::PetscLibType, dm::AbstractPetscDM, mtype::DMSwarmMigrateType)

Set the style of point migration

Logically Collective

Input Parameters:

  • dm - the DMSWARM
  • mtype - The migration type, see DMSwarmMigrateType

Level: intermediate

See also: DM, DMSWARM, DMSwarmMigrateType, DMSwarmGetMigrateType(), DMSwarmMigrate()

External Links

source
PETSc.LibPETSc.DMSwarmSetNumSpecies — Method
DMSwarmSetNumSpecies(petsclib::PetscLibType, sw::AbstractPetscDM, Ns::PetscInt)

Set the number of particle species

Not Collective

Input Parameters:

  • sw - the DMSWARM
  • Ns - the number of species

Level: intermediate

See also: DMSWARM, DMSwarmGetNumSpecies(), DMSwarmSetType(), DMSwarmType

External Links

source
PETSc.LibPETSc.DMSwarmSetPointCoordinates — Method
DMSwarmSetPointCoordinates(petsclib::PetscLibType, sw::AbstractPetscDM, npoints::PetscInt, coor::Vector{PetscReal}, redundant::PetscBool, mode::InsertMode)

Set point coordinates in a DMSWARM from a user defined list

Collective

Input Parameters:

  • sw - the DMSWARM
  • npoints - the number of points to insert
  • coor - the coordinate values
  • redundant - if set to PETSC_TRUE, it is assumed that npoints and coor are only valid on rank 0 and should be broadcast to other ranks
  • mode - indicates whether to append points to the swarm (ADD_VALUES), or over-ride existing points (INSERT_VALUES)

Level: beginner

See also: DMSWARM, DMSwarmSetType(), DMSwarmSetCellDM(), DMSwarmType, DMSwarmSetPointsUniformCoordinates()

External Links

source
PETSc.LibPETSc.DMSwarmSetPointCoordinatesCellwise — Method
DMSwarmSetPointCoordinatesCellwise(petsclib::PetscLibType, dm::AbstractPetscDM, npoints::PetscInt, xi::Vector{PetscReal})

Insert point coordinates (defined over the reference cell) within each cell

Not Collective

Input Parameters:

  • dm - the DMSWARM
  • npoints - the number of points to insert in each cell
  • xi - the coordinates (defined in the local coordinate system for each cell) to insert

Level: beginner

See also: DMSWARM, DMSwarmSetCellDM(), DMSwarmInsertPointsUsingCellDM()

External Links

source
PETSc.LibPETSc.DMSwarmSetPointsUniformCoordinates — Method
DMSwarmSetPointsUniformCoordinates(petsclib::PetscLibType, sw::AbstractPetscDM, min::Vector{PetscReal}, max::Vector{PetscReal}, npoints::Vector{PetscInt}, mode::InsertMode)

Set point coordinates in a DMSWARM on a regular (ijk) grid

Collective

Input Parameters:

  • sw - the DMSWARM
  • min - minimum coordinate values in the x, y, z directions (array of length dim)
  • max - maximum coordinate values in the x, y, z directions (array of length dim)
  • npoints - number of points in each spatial direction (array of length dim)
  • mode - indicates whether to append points to the swarm (ADD_VALUES), or over-ride existing points (INSERT_VALUES)

Level: beginner

See also: DM, DMSWARM, DMSwarmSetType(), DMSwarmSetCellDM(), DMSwarmType

External Links

source
PETSc.LibPETSc.DMSwarmSetType — Method
DMSwarmSetType(petsclib::PetscLibType, sw::AbstractPetscDM, stype::DMSwarmType)

Set particular flavor of DMSWARM

Collective

Input Parameters:

  • sw - the DMSWARM
  • stype - the DMSWARM type (e.g. DMSWARM_PIC)

Level: advanced

See also: DM, DMSWARM, DMSwarmSetMigrateType(), DMSwarmSetCollectType(), DMSwarmType, DMSWARM_PIC, DMSWARM_BASIC

External Links

source
PETSc.LibPETSc.DMSwarmSetVelocityFunction — Method
DMSwarmSetVelocityFunction(petsclib::PetscLibType, sw::AbstractPetscDM, velFunc::Ptr{Cvoid})

Set the function setting initial particle velocities

Not Collective

Input Parameters:

  • sw - the DMSWARM
  • velFunc - the function setting initial particle velocities, see PetscSimplePointFn for the calling sequence

Level: intermediate

See also: DMSWARM, DMSwarmGetVelocityFunction(), DMSwarmSetCoordinateFunction(), DMSwarmInitializeVelocities(), PetscSimplePointFn

External Links

source
PETSc.LibPETSc.DMSwarmVectorDefineField — Method
DMSwarmVectorDefineField(petsclib::PetscLibType, dm::AbstractPetscDM, fieldname::String)

Sets the field from which to define a Vec object when DMCreateLocalVector(), or DMCreateGlobalVector() is called

Collective

Input Parameters:

  • dm - a DMSWARM
  • fieldname - the textual name given to each registered field

Level: beginner

See also: DM, DMSWARM, DMSwarmVectorDefineFields(), DMSwarmVectorGetField(), DMSwarmRegisterPetscDatatypeField(), DMCreateGlobalVector(), DMCreateLocalVector()

External Links

source
PETSc.LibPETSc.DMSwarmVectorDefineFields — Method
DMSwarmVectorDefineFields(petsclib::PetscLibType, sw::AbstractPetscDM, Nf::PetscInt, fieldnames::String)

Sets the fields from which to define a Vec object when DMCreateLocalVector(), or DMCreateGlobalVector() is called

Collective, No Fortran support

Input Parameters:

  • sw - a DMSWARM
  • Nf - the number of fields
  • fieldnames - the textual name given to each registered field

Level: beginner

See also: DM, DMSWARM, DMSwarmVectorDefineField(), DMSwarmVectorGetField(), DMSwarmRegisterPetscDatatypeField(), DMCreateGlobalVector(), DMCreateLocalVector()

External Links

source
PETSc.LibPETSc.DMSwarmVectorGetField — Method
Nf::PetscInt,fieldnames::Vector{String} = DMSwarmVectorGetField(petsclib::PetscLibType, sw::AbstractPetscDM)

Gets the fields from which to define a Vec object when DMCreateLocalVector(), or DMCreateGlobalVector() is called

Not collective

Input Parameter:

  • sw - a DMSWARM

Output Parameters:

  • Nf - the number of fields
  • fieldnames - the textual name given to each registered field, or NULL if it has not been set

Level: beginner

See also: DM, DMSWARM, DMSwarmVectorDefineField(), DMSwarmRegisterPetscDatatypeField(), DMCreateGlobalVector(), DMCreateLocalVector()

External Links

source
PETSc.LibPETSc.DMSwarmViewFieldsXDMF — Method
DMSwarmViewFieldsXDMF(petsclib::PetscLibType, dm::AbstractPetscDM, filename::String, nfields::PetscInt, field_name_list::String)

Write a selection of DMSwarm fields to an XDMF3 file

Collective

Input Parameters:

  • dm - the DMSWARM
  • filename - the file name of the XDMF file (must have the extension .xmf)
  • nfields - the number of fields to write into the XDMF file
  • field_name_list - array of length nfields containing the textual name of fields to write

Level: beginner

See also: DM, DMSWARM, DMSwarmViewXDMF()

External Links

source
PETSc.LibPETSc.DMSwarmViewXDMF — Method
DMSwarmViewXDMF(petsclib::PetscLibType, dm::AbstractPetscDM, filename::String)

Write DMSWARM fields to an XDMF3 file

Collective

Input Parameters:

  • dm - the DMSWARM
  • filename - the file name of the XDMF file (must have the extension .xmf)

Level: beginner

See also: DM, DMSWARM, DMSwarmViewFieldsXDMF()

External Links

source