PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
|
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. | |
Macros | |
#define | __FUNCT__ "InterpolateAllFieldsToSwarm" |
Interpolates a cell-centered field (scalar or vector) onto DMSwarm particles, converting the cell-center data to corner data first, then looping over particles. | |
#define | __FUNCT__ "ScatterAllParticleFieldsToEulerFields" |
Interpolates a cell-centered field (scalar or vector) onto DMSwarm particles, converting the cell-center data to corner data first, then looping over particles. | |
Functions | |
PetscErrorCode | GetScatterTargetInfo (UserCtx *user, const char *particleFieldName, DM *targetDM, PetscInt *expected_dof) |
Determines the target Eulerian DM and expected DOF for scattering a given particle field. | |
PetscErrorCode | ScatterParticleFieldToEulerField (UserCtx *user, const char *particleFieldName, 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. | |
PetscErrorCode | CalculateParticleCountPerCell (UserCtx *user) |
Counts particles in each cell of the DMDA 'da' and stores the result in user->ParticleCount. | |
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.user->da
for scalars, user->fda
for vectors) based on standard field names ("P", "Nvert", "Ucat", "Ucont","Psi").user->P
, user->Ucat
,user->Psi) in place.
Provides a high-level wrapper function (
ScatterAllParticleFieldsToEulerFields) to easily scatter a standard set of fields.
Uses only the base
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. #define __FUNCT__ "InterpolateAllFieldsToSwarm" |
Interpolates a cell-centered field (scalar or vector) onto DMSwarm particles, converting the cell-center data to corner data first, then looping over particles.
Steps: 1) Check that the Vec has blockSize=1 or 3 (scalar vs. vector). 2) Map the cell-centered Vec to a local array (fieldGlobal -> localPtr). 3) Allocate a corner array (cornerPtr) via Allocate3DArray(...), sized (zm+1, ym+1, xm+1). 4) Convert from cell-centers to corners via InterpolateFieldFromCenterToCorner(...). 5) Restore the cell-centered array. 6) Retrieve DMSwarm fields: "DMSwarm_CellID", "weight", and swarmOutFieldName. 7) Loop over local particles, clamp i/j/k, skip or zero out if out of range, read (a1,a2,a3). 8) Call InterpolateEulerFieldToSwarmForParticle(...) with cornerPtr to do final Interpolatetion. 9) Restore swarm fields, free the corner array.
[in] | user | User context with:
|
[in] | fieldGlobal | Vec with blockSize=1 or 3, storing the cell-centered field. |
[in] | fieldName | Human-readable field name for logging (e.g. "velocity"). |
[in] | swarmOutFieldName | Name of the DMSwarm field where Interpolatetion results go. |
Definition at line 1647 of file interpolation.c.
#define __FUNCT__ "ScatterAllParticleFieldsToEulerFields" |
Interpolates a cell-centered field (scalar or vector) onto DMSwarm particles, converting the cell-center data to corner data first, then looping over particles.
Steps: 1) Check that the Vec has blockSize=1 or 3 (scalar vs. vector). 2) Map the cell-centered Vec to a local array (fieldGlobal -> localPtr). 3) Allocate a corner array (cornerPtr) via Allocate3DArray(...), sized (zm+1, ym+1, xm+1). 4) Convert from cell-centers to corners via InterpolateFieldFromCenterToCorner(...). 5) Restore the cell-centered array. 6) Retrieve DMSwarm fields: "DMSwarm_CellID", "weight", and swarmOutFieldName. 7) Loop over local particles, clamp i/j/k, skip or zero out if out of range, read (a1,a2,a3). 8) Call InterpolateEulerFieldToSwarmForParticle(...) with cornerPtr to do final Interpolatetion. 9) Restore swarm fields, free the corner array.
[in] | user | User context with:
|
[in] | fieldGlobal | Vec with blockSize=1 or 3, storing the cell-centered field. |
[in] | fieldName | Human-readable field name for logging (e.g. "velocity"). |
[in] | swarmOutFieldName | Name of the DMSwarm field where Interpolatetion results go. |
Definition at line 1647 of file interpolation.c.
PetscErrorCode GetScatterTargetInfo | ( | UserCtx * | user, |
const char * | particleFieldName, | ||
DM * | targetDM, | ||
PetscInt * | expected_dof | ||
) |
Determines the target Eulerian DM and expected DOF for scattering a given particle field.
Based on hardcoded rules mapping particle field names to user context DMs (da/fda). This function encapsulates the policy of where different fields should be scattered.
[in] | user | Pointer to the UserCtx containing da and fda. |
[in] | particleFieldName | Name of the particle field (e.g., "P", "Ucat"). |
[out] | targetDM | Pointer to store the determined target DM (da or fda). |
[out] | expected_dof | Pointer to store the expected DOF (1 or 3) for this field. |
Based on hardcoded rules mapping particle field names ("P", "Nvert", "Ucat", "Ucont") to user context DMs (user->da
or user->fda
). This function encapsulates the policy of where different fields should be scattered. Modify this function to add rules for custom fields.
[in] | user | Pointer to the UserCtx containing required DMs (da , fda ). |
[in] | particleFieldName | Name of the particle field. |
[out] | targetDM | Pointer to store the determined target DM (user->da or user->fda ). |
[out] | expected_dof | Pointer to store the expected DOF (1 or 3) for this field. |
PETSC_ERR_ARG_NULL
if required inputs are NULL.PETSC_ERR_ARG_WRONG
if particleFieldName
is not recognized. Definition at line 1784 of file interpolation.c.
PetscErrorCode ScatterParticleFieldToEulerField | ( | UserCtx * | user, |
const char * | particleFieldName, | ||
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 based on the particleFieldName
, validates the provided eulerFieldAverageVec
against the target DM, and then orchestrates the scatter operation by calling the internal helper function ScatterParticleFieldToEulerField_Internal
. The final averaged result is stored IN-PLACE in eulerFieldAverageVec
.
[in] | user | Pointer to UserCtx containing da, fda, swarm, ParticleCount. |
[in] | particleFieldName | Name of the field in the DMSwarm (e.g., "P", "Ucat"). |
[in,out] | eulerFieldAverageVec | Pre-created Vec associated with the correct target DM (implicitly da or fda). Result stored here. |
This is the primary user-facing function for scattering a single field. It determines the target Eulerian DM (user->da
or user->fda
) based on the particleFieldName
, validates that the provided eulerFieldAverageVec
is compatible with that target DM, and then orchestrates the scatter operation by calling an internal helper function. The final averaged result is stored IN-PLACE in the eulerFieldAverageVec
.
[in] | user | Pointer to UserCtx containing da , fda , swarm , ParticleCount . |
[in] | particleFieldName | Name of the field in the DMSwarm (e.g., "Psi", "Ucat"). |
[in,out] | eulerFieldAverageVec | Pre-created Vec associated with the correct target DM (implicitly da or fda ). Result stored here. This vector should be zeroed by the caller if desired before this function (e.g., using VecSet ). The wrapper ScatterAllParticleFieldsToEulerFields handles this zeroing. |
Definition at line 2151 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 . |
This convenience function calls the unified ScatterParticleFieldToEulerField
for a standard set of fields (currently just "Psi", others commented out). It assumes the target Eulerian Vec objects (e.g., user->Psi
, user->Ucat
) exist in the UserCtx structure and are correctly associated with their respective DMs (user->da
or user->fda
).
IMPORTANT: It zeros the target Vecs before scattering. Ensure user->ParticleCount
has been computed accurately before calling this function, reflecting the current particle distribution.
[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 2235 of file interpolation.c.
PetscErrorCode CalculateParticleCountPerCell | ( | UserCtx * | user | ) |
Counts particles in each cell of the DMDA 'da' and stores the result in user->ParticleCount.
Zeros the user->ParticleCount vector, then iterates through local particles. Reads the GLOBAL cell index (I, J, K) stored in the "DMSwarm_CellID" field. Uses DMDAVecGetArray to access the local portion of the count vector and increments the count at the global index (I, J, K) if it belongs to the local patch (including ghosts).
[in,out] | user | Pointer to the UserCtx structure containing da, swarm, and ParticleCount. |
Definition at line 714 of file ParticleMotion.c.