Functions for scattering particle data (scalar or vector) onto Eulerian grid fields by averaging contributions within each cell. More...
Modules | |
| Internal Scattering Helpers | |
| Lower-level functions used by the main scattering routines. | |
Functions | |
| PetscErrorCode | ScatterParticleFieldCellMean (UserCtx *user, ParticleFieldId particle_field_id, DM dataDM, Vec countVec, PetscBool recount, Vec meanVec) |
| Cell mean of a particle field: the field summed over each cell's particles, divided by the cell's count. | |
| PetscErrorCode | ScatterParticleFieldToEulerField (UserCtx *user, ParticleFieldId particle_field_id, Vec eulerFieldAverageVec) |
| Scatters a particle field (scalar or vector) to the corresponding Eulerian field average. | |
| PetscErrorCode | ScatterAllParticleFieldsToEulerFields (UserCtx *user) |
| Scatters a predefined set of particle fields to their corresponding Eulerian fields. | |
Functions for scattering particle data (scalar or vector) onto Eulerian grid fields by averaging contributions within each cell.
This file provides a modular set of functions to perform particle-to-grid projection, specifically calculating cell-averaged quantities from particle properties. It assumes a PETSc environment using DMDA for the grids and DMSwarm for particles.
Key Features:
ParticleCount) for normalization.ScatterAllParticleFieldsToEulerFields) to easily scatter a standard set of fields.SETERRQ macro for error reporting to maximize compiler compatibility.Dependencies:
UserCtx struct (defined elsewhere, e.g., "userctx.h") containing pointers to relevant DMs (da, fda), Vecs (ParticleCount, P, Nvert, Ucat, etc.), and the DMSwarm object (swarm)."DMSwarm_CellID" (blockSize=3, type=PETSC_INT) must be registered and populated with the local cell indices for each particle.LOG_ALLOW, etc.) assumed to be defined elsewhere. | PetscErrorCode ScatterParticleFieldCellMean | ( | UserCtx * | user, |
| ParticleFieldId | particle_field_id, | ||
| DM | dataDM, | ||
| Vec | countVec, | ||
| PetscBool | recount, | ||
| Vec | meanVec | ||
| ) |
Cell mean of a particle field: the field summed over each cell's particles, divided by the cell's count.
Implementation of ScatterParticleFieldCellMean().
Zeroes a ghosted accumulator, adds every local particle into its cell with AccumulateParticleField(), sums the ranks' copies into the owners (local-to-global ADD), and divides by countVec with NormalizeGridVectorByCount(); an empty cell's mean is zero. Collective.
| [in] | user | Context holding the swarm and the cell DM da. |
| [in] | particle_field_id | PETSC_REAL particle field to average. |
| [in] | dataDM | DMDA of the mean, with as many DOF as the field has components. |
| [in] | countVec | Global particles-per-cell vector on user->da; only its owned entries are read. |
| [in] | recount | PETSC_TRUE to recount user->ParticleCount (and reset user->lParticleCount) with CalculateParticleCountPerCell() before dividing; countVec is then normally user->ParticleCount. |
| [in,out] | meanVec | Global vector on dataDM receiving the owned means. |
Definition at line 1725 of file interpolation.c.
| PetscErrorCode ScatterParticleFieldToEulerField | ( | UserCtx * | user, |
| ParticleFieldId | particle_field_id, | ||
| Vec | eulerFieldAverageVec | ||
| ) |
Scatters a particle field (scalar or vector) to the corresponding Eulerian field average.
This is the main user-facing function. It determines the target Eulerian DM from the particle catalog, validates the provided eulerFieldAverageVec against the target DM, and then orchestrates the scatter operation by calling ScatterParticleFieldCellMean(), recounting the particles per cell first. The final averaged result is stored IN-PLACE in eulerFieldAverageVec.
| [in] | user | Pointer to UserCtx containing da, fda, swarm, ParticleCount. |
| [in] | particle_field_id | Typed identity of the DMSwarm field. |
| [in,out] | eulerFieldAverageVec | Pre-created Vec associated with the correct target DM (implicitly da or fda). Result stored here. |
Definition at line 1761 of file interpolation.c.
| PetscErrorCode ScatterAllParticleFieldsToEulerFields | ( | UserCtx * | user | ) |
Scatters a predefined set of particle fields to their corresponding Eulerian fields.
This convenience function calls the unified ScatterParticleFieldToEulerField for a standard set of fields ("P", potentially others). It assumes the target Eulerian Vec objects (e.g., user->P, user->Ucat) exist in the UserCtx structure and are correctly associated with their respective DMs (user->da or user->fda). It zeros the target Vecs before scattering.
| [in,out] | user | Pointer to the UserCtx structure containing all required DMs, Vecs (ParticleCount, target Eulerian fields like P, Ucat), and swarm. |
Definition at line 1841 of file interpolation.c.