|
PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
|
#include "ParticleSwarm.h"Go to the source code of this file.
Macros | |
| #define | INTERPOLATION_DISTANCE_TOLERANCE 1.0e-14 |
| #define | __FUNCT__ "InitializeSwarm" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "RegisterSwarmField" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "RegisterParticleFields" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "DetermineVolumetricInitializationParameters" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "InitializeParticleBasicProperties" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "InitializeSwarmFieldValue" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "AssignInitialFieldToSwarm" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "AssignInitialPropertiesToSwarm" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "DistributeParticles" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "FinalizeSwarmSetup" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "CreateParticleSwarm" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "UnpackSwarmFields" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "UpdateSwarmFields" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "IsParticleInsideBoundingBox" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "UpdateParticleWeights" |
| Initializes or loads the particle swarm based on the simulation context. | |
| #define | __FUNCT__ "InitializeParticleSwarm" |
| Initializes or loads the particle swarm based on the simulation context. | |
Functions | |
| PetscErrorCode | InitializeSwarm (UserCtx *user) |
| Initializes the DMSwarm object within the UserCtx structure. | |
| PetscErrorCode | RegisterSwarmField (DM swarm, const char *fieldName, PetscInt fieldDim, PetscDataType dtype) |
| Registers a swarm field without finalizing registration. | |
| PetscErrorCode | RegisterParticleFields (DM swarm) |
| Registers necessary particle fields within the DMSwarm. | |
| static PetscErrorCode | DetermineVolumetricInitializationParameters (UserCtx *user, DMDALocalInfo *info, PetscInt xs_gnode, PetscInt ys_gnode, PetscInt zs_gnode, PetscRandom *rand_logic_i_ptr, PetscRandom *rand_logic_j_ptr, PetscRandom *rand_logic_k_ptr, PetscInt *ci_metric_lnode_out, PetscInt *cj_metric_lnode_out, PetscInt *ck_metric_lnode_out, PetscReal *xi_metric_logic_out, PetscReal *eta_metric_logic_out, PetscReal *zta_metric_logic_out, PetscBool *can_place_in_volume_out) |
| Determines cell selection and intra-cell logical coordinates for volumetric initialization (Mode 1). | |
| static PetscErrorCode | InitializeParticleBasicProperties (UserCtx *user, PetscInt particlesPerProcess, PetscRandom *rand_logic_i, PetscRandom *rand_logic_j, PetscRandom *rand_logic_k, BoundingBox *bboxlist) |
| Initializes basic properties for particles on the local process. | |
| static PetscErrorCode | InitializeSwarmFieldValue (const char *fieldName, PetscInt p, PetscInt fieldDim, PetscReal *fieldData) |
| Helper function to Initialize a given particle’s field value. | |
| static PetscErrorCode | AssignInitialFieldToSwarm (UserCtx *user, const char *fieldName, PetscInt fieldDim) |
| Initializes a generic swarm field with point-level updates. | |
| PetscErrorCode | AssignInitialPropertiesToSwarm (UserCtx *user, PetscInt particlesPerProcess, PetscRandom *rand_phys_x, PetscRandom *rand_phys_y, PetscRandom *rand_phys_z, PetscRandom *rand_logic_i, PetscRandom *rand_logic_j, PetscRandom *rand_logic_k, BoundingBox *bboxlist) |
| Initializes all particle properties in the swarm. | |
| PetscErrorCode | DistributeParticles (PetscInt numParticles, PetscMPIInt rank, PetscMPIInt size, PetscInt *particlesPerProcess, PetscInt *remainder) |
| Distributes particles evenly across MPI processes, handling any remainders. | |
| PetscErrorCode | FinalizeSwarmSetup (PetscRandom *randx, PetscRandom *randy, PetscRandom *randz, PetscRandom *rand_logic_i, PetscRandom *rand_logic_j, PetscRandom *rand_logic_k) |
| Finalizes the swarm setup by destroying random generators and logging completion. | |
| PetscErrorCode | CreateParticleSwarm (UserCtx *user, PetscInt numParticles, PetscInt *particlesPerProcess, BoundingBox *bboxlist) |
| Creates and initializes a Particle Swarm. | |
| PetscErrorCode | UnpackSwarmFields (PetscInt i, const PetscInt64 *PIDs, const PetscReal *weights, const PetscReal *positions, const PetscInt *cellIndices, PetscReal *velocities, PetscInt *LocStatus, Particle *particle) |
| Initializes a Particle struct with data from DMSwarm fields. | |
| PetscErrorCode | UpdateSwarmFields (PetscInt i, const Particle *particle, PetscReal *weights, PetscInt *cellIndices, PetscInt *status_field) |
| Updates DMSwarm fields with data from a Particle struct. | |
| PetscBool | IsParticleInsideBoundingBox (const BoundingBox *bbox, const Particle *particle) |
| Checks if a particle's location is within a specified bounding box. | |
| PetscErrorCode | UpdateParticleWeights (PetscReal *d, Particle *particle) |
| Updates a particle's interpolation weights based on distances to cell faces. | |
| PetscErrorCode | InitializeParticleSwarm (SimCtx *simCtx) |
| Perform particle swarm initialization, particle-grid interaction, and related operations. | |
| #define INTERPOLATION_DISTANCE_TOLERANCE 1.0e-14 |
Definition at line 5 of file ParticleSwarm.c.
| #define __FUNCT__ "InitializeSwarm" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "RegisterSwarmField" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "RegisterParticleFields" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "DetermineVolumetricInitializationParameters" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "InitializeParticleBasicProperties" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "InitializeSwarmFieldValue" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "AssignInitialFieldToSwarm" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "AssignInitialPropertiesToSwarm" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "DistributeParticles" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "FinalizeSwarmSetup" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "CreateParticleSwarm" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "UnpackSwarmFields" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "UpdateSwarmFields" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "IsParticleInsideBoundingBox" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "UpdateParticleWeights" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| #define __FUNCT__ "InitializeParticleSwarm" |
Initializes or loads the particle swarm based on the simulation context.
This function is the central point for setting up the DMSwarm. Its behavior depends on the simulation context (simCtx):
simCtx->particleRestartMode is "init", a new particle population is generated, just like a fresh start. This allows injecting fresh particles into a pre-computed flow field.simCtx->particleRestartMode is "load", the particle state is loaded from restart files corresponding to the StartStep.| [in,out] | simCtx | Pointer to the main SimulationContext, which contains all configuration and provides access to the UserCtx. |
Definition at line 8 of file ParticleSwarm.c.
| PetscErrorCode InitializeSwarm | ( | UserCtx * | user | ) |
Initializes the DMSwarm object within the UserCtx structure.
This function creates the DMSwarm, sets its type and dimension, and configures basic swarm properties.
| [in,out] | user | Pointer to the UserCtx structure containing simulation context. |
Definition at line 18 of file ParticleSwarm.c.
| PetscErrorCode RegisterSwarmField | ( | DM | swarm, |
| const char * | fieldName, | ||
| PetscInt | fieldDim, | ||
| PetscDataType | dtype | ||
| ) |
Registers a swarm field without finalizing registration.
This function calls DMSwarmRegisterPetscDatatypeField for the given field, but does not finalize the registration. The finalization is deferred until all fields have been registered.
| swarm | [in] The DMSwarm object. |
| fieldName | [in] Name of the field to register. |
| fieldDim | [in] Dimension of the field (1 for scalar, 3 for vector, etc.). |
| dtype | [in] The datatype of the swarm field being registered. |
Definition at line 50 of file ParticleSwarm.c.
| PetscErrorCode RegisterParticleFields | ( | DM | swarm | ) |
Registers necessary particle fields within the DMSwarm.
This function registers fields such as position, velocity, CellID, and weight for each particle.
| [in,out] | swarm | The DMSwarm object managing the particle swarm. |
Definition at line 76 of file ParticleSwarm.c.
|
static |
Determines cell selection and intra-cell logical coordinates for volumetric initialization (Mode 1).
This function is called when simCtx->ParticleInitialization == 1. It randomly selects an owned cell on the current MPI rank and then generates random intra-cell logical coordinates [0,1)^3 within that chosen cell.
The process involves:
[0,1) random number with the number of owned cells in that direction.ci/cj/ck_metric_lnode_out) corresponding to the origin of the selected cell, for use with MetricLogicalToPhysical. This conversion uses xs/ys/zs_gnode.xi/eta/zta_metric_logic_out) for MetricLogicalToPhysical are chosen randomly within the [0,1) range.can_place_in_volume_out) indicates if a valid placement could be determined.Important Note on DMDALocalInfo info members (same as for surface init):
info->xs, info->ys, info->ks: Global starting indices of owned cells.info->mx, info->my, info->mz: Number of grid points (nodes) in each local dimension on this process. Therefore, the number of owned cells in a dimension is info->mX - 1 (if info->mX > 0).| [in] | user | Pointer to UserCtx. (Currently not used in this specific helper, but kept for API consistency). |
| [in] | info | Pointer to DMDALocalInfo for the current rank's grid portion. |
| [in] | xs_gnode,ys_gnode,zs_gnode | Local indices (in the ghosted array) of the first owned node. |
| [in] | rand_logic_i_ptr | Pointer to the RNG for i-dimension tasks [0,1). |
| [in] | rand_logic_j_ptr | Pointer to the RNG for j-dimension tasks [0,1). |
| [in] | rand_logic_k_ptr | Pointer to the RNG for k-dimension tasks [0,1). |
| [out] | ci_metric_lnode_out | Pointer to store the local i-node index of the selected cell's origin. |
| [out] | cj_metric_lnode_out | Pointer to store the local j-node index of the selected cell's origin. |
| [out] | ck_metric_lnode_out | Pointer to store the local k-node index of the selected cell's origin. |
| [out] | xi_metric_logic_out | Pointer to store the intra-cell logical xi-coordinate [0,1). |
| [out] | eta_metric_logic_out | Pointer to store the intra-cell logical eta-coordinate [0,1). |
| [out] | zta_metric_logic_out | Pointer to store the intra-cell logical zeta-coordinate [0,1). |
| [out] | can_place_in_volume_out | PETSC_TRUE if placement parameters were successfully determined, PETSC_FALSE otherwise. |
Definition at line 147 of file ParticleSwarm.c.
|
static |
Initializes basic properties for particles on the local process.
This function assigns initial physical positions, Particle IDs (PIDs), and placeholder cell IDs to particles. The method of position initialization depends on simCtx->ParticleInitialization:
The logical coordinates for placement are generated using provided random number generators. These logical coordinates are then transformed to physical coordinates using MetricLogicalToPhysical.
| user | Pointer to the UserCtx structure, containing simulation settings and grid information. |
| particlesPerProcess | The number of particles to initialize on this MPI rank. |
| rand_logic_i | Pointer to a PetscRandom generator for the xi logical coordinate. |
| rand_logic_j | Pointer to a PetscRandom generator for the eta logical coordinate. |
| rand_logic_k | Pointer to a PetscRandom generator for the zeta logical coordinate. |
| bboxlist | (Unused in this function for placement) Pointer to the bounding box list; provided for API consistency but not used for determining initial positions here. Particle positions are determined by logical-to-physical mapping based on rank's owned cells. |
Definition at line 266 of file ParticleSwarm.c.
|
static |
Helper function to Initialize a given particle’s field value.
This function performs conditional, point-level Initialization for a swarm field based on its name. For example, you might want to initialize the "velocity" field to 0.0, but the "temperature" field to a nonzero default (e.g., 300.0). This function can be extended for other fields.
| [in] | fieldName | Name of the swarm field. |
| [in] | p | Particle index. |
| [in] | fieldDim | Dimension of the field. |
| [out] | fieldData | Pointer to the field’s data array. |
Definition at line 470 of file ParticleSwarm.c.
|
static |
Initializes a generic swarm field with point-level updates.
This field-agnostic function retrieves the specified swarm field (which may be scalar or multi-component) and initializes each particle's entry using a helper that performs conditional updates based on the field name.
| [in,out] | user | Pointer to the UserCtx structure containing the swarm. |
| [in] | fieldName | Name of the swarm field to initialize. |
| [in] | fieldDim | Dimension of the field (e.g., 1 for scalar, 3 for vector). |
Definition at line 517 of file ParticleSwarm.c.
| PetscErrorCode AssignInitialPropertiesToSwarm | ( | UserCtx * | user, |
| PetscInt | particlesPerProcess, | ||
| PetscRandom * | rand_phys_x, | ||
| PetscRandom * | rand_phys_y, | ||
| PetscRandom * | rand_phys_z, | ||
| PetscRandom * | rand_logic_i, | ||
| PetscRandom * | rand_logic_j, | ||
| PetscRandom * | rand_logic_k, | ||
| BoundingBox * | bboxlist | ||
| ) |
Initializes all particle properties in the swarm.
This function orchestrates the initialization of particle properties. It first determines the inlet face if surface initialization (Mode 0) is selected by parsing "bcs.dat". Then, it initializes basic particle properties (physical position, Particle ID, and placeholder Cell IDs) by calling InitializeParticleBasicProperties. This call uses the provided rand_logic_i/j/k RNGs, which must be pre-initialized for [0,1). The rand_phys_x/y/z RNGs (physically bounded) are passed but may not be used by InitializeParticleBasicProperties for position setting if all initialization paths use logical-to-physical mapping. Finally, it calls helper functions to initialize other registered swarm fields like "velocity", "weight", and "Psi" (scalar) to default values.
| [in,out] | user | Pointer to the UserCtx structure. |
| [in] | particlesPerProcess | Number of particles assigned to this MPI process. |
| [in] | rand_phys_x | RNG for physical x-coordinates (from InitializeRandomGenerators). |
| [in] | rand_phys_y | RNG for physical y-coordinates (from InitializeRandomGenerators). |
| [in] | rand_phys_z | RNG for physical z-coordinates (from InitializeRandomGenerators). |
| [in] | rand_logic_i | RNG for i-logical dimension tasks [0,1) (from InitializeLogicalSpaceRNGs). |
| [in] | rand_logic_j | RNG for j-logical dimension tasks [0,1) (from InitializeLogicalSpaceRNGs). |
| [in] | rand_logic_k | RNG for k-logical dimension tasks [0,1) (from InitializeLogicalSpaceRNGs). |
| [in] | bboxlist | Array of BoundingBox structures (potentially unused by IPBP). |
Definition at line 587 of file ParticleSwarm.c.
| PetscErrorCode DistributeParticles | ( | PetscInt | numParticles, |
| PetscMPIInt | rank, | ||
| PetscMPIInt | size, | ||
| PetscInt * | particlesPerProcess, | ||
| PetscInt * | remainder | ||
| ) |
Distributes particles evenly across MPI processes, handling any remainders.
This function calculates the number of particles each MPI process should handle, distributing the remainder particles to the first few ranks if necessary.
| [in] | numParticles | Total number of particles to create across all MPI processes. |
| [in] | rank | MPI rank of the current process. |
| [in] | size | Total number of MPI processes. |
| [out] | particlesPerProcess | Number of particles assigned to the current MPI process. |
| [out] | remainder | Remainder particles when dividing numParticles by size. |
Definition at line 678 of file ParticleSwarm.c.
| PetscErrorCode FinalizeSwarmSetup | ( | PetscRandom * | randx, |
| PetscRandom * | randy, | ||
| PetscRandom * | randz, | ||
| PetscRandom * | rand_logic_i, | ||
| PetscRandom * | rand_logic_j, | ||
| PetscRandom * | rand_logic_k | ||
| ) |
Finalizes the swarm setup by destroying random generators and logging completion.
This function cleans up resources by destroying random number generators and LOG_ALLOWs the completion of swarm setup.
| [in] | randx | Random number generator for the x-coordinate. |
| [in] | randy | Random number generator for the y-coordinate. |
| [in] | randz | Random number generator for the z-coordinate. |
| [in] | rand_logic_i | Random number generator for the xi-coordinate. |
| [in] | rand_logic_j | Random number generator for the eta-coordinate. |
| [in] | rand_logic_k | Random number generator for the zeta-coordinate. |
Definition at line 716 of file ParticleSwarm.c.
| PetscErrorCode CreateParticleSwarm | ( | UserCtx * | user, |
| PetscInt | numParticles, | ||
| PetscInt * | particlesPerProcess, | ||
| BoundingBox * | bboxlist | ||
| ) |
Creates and initializes a Particle Swarm.
This function sets up a DMSwarm within the provided UserCtx structure, initializes particle fields, and distributes particles across MPI processes. It ensures that the number of particles is evenly divided among the available MPI ranks. If the total number of particles isn't divisible by the number of processes, the remainder is distributed to the first few ranks.
| [in,out] | user | Pointer to the UserCtx structure containing the simulation context. |
| [in] | numParticles | Total number of particles to create across all MPI processes. |
| [in] | bboxlist | Pointer to an array of BoundingBox structures, one per rank. |
| [in] | particlesPerProcess |
numParticles is a positive integer.control.dat file should contain necessary PETSc options.bboxlist array should be properly populated before calling this function. Definition at line 760 of file ParticleSwarm.c.
| PetscErrorCode UnpackSwarmFields | ( | PetscInt | i, |
| const PetscInt64 * | PIDs, | ||
| const PetscReal * | weights, | ||
| const PetscReal * | positions, | ||
| const PetscInt * | cellIndices, | ||
| PetscReal * | velocities, | ||
| PetscInt * | LocStatus, | ||
| Particle * | particle | ||
| ) |
Initializes a Particle struct with data from DMSwarm fields.
This helper function populates a Particle structure using data retrieved from DMSwarm fields.
| [in] | i | Index of the particle in the DMSwarm. |
| [in] | PIDs | Pointer to the array of particle IDs. |
| [in] | weights | Pointer to the array of particle weights. |
| [in] | positions | Pointer to the array of particle positions. |
| [in] | cellIndices | Pointer to the array of particle cell indices. |
| [in] | velocities | Pointer to the array of particle velocities. |
| [in] | LocStatus | Pointer to the array of cell location status indicators. |
| [out] | particle | Pointer to the Particle struct to initialize. |
0 on success, non-zero on failure. Definition at line 836 of file ParticleSwarm.c.
| PetscErrorCode UpdateSwarmFields | ( | PetscInt | i, |
| const Particle * | particle, | ||
| PetscReal * | weights, | ||
| PetscInt * | cellIndices, | ||
| PetscInt * | status_field | ||
| ) |
Updates DMSwarm fields with data from a Particle struct.
This helper function writes back the modified Particle data to the corresponding DMSwarm fields.
| [in] | i | Index of the particle in the DMSwarm. |
| [in] | particle | Pointer to the Particle struct containing updated data. |
| [in,out] | weights | Pointer to the array of particle weights. |
| [in,out] | cellIndices | Pointer to the array of particle cell indices. |
| [in,out] | LocStatus | Pointer to the array of cell location status indicators. |
0 on success, non-zero on failure. Definition at line 918 of file ParticleSwarm.c.
| PetscBool IsParticleInsideBoundingBox | ( | const BoundingBox * | bbox, |
| const Particle * | particle | ||
| ) |
Checks if a particle's location is within a specified bounding box.
This function determines whether the given particle's location lies inside the provided bounding box. It performs an axis-aligned bounding box (AABB) check by comparing the particle's coordinates to the minimum and maximum coordinates of the bounding box in each dimension (x, y, z).
logging statements are included to provide detailed information about the function's execution.
| [in] | bbox | Pointer to the BoundingBox structure containing minimum and maximum coordinates. |
| [in] | particle | Pointer to the Particle structure containing the particle's location and identifier. |
PETSC_TRUE if the particle is inside the bounding box, PETSC_FALSE otherwise.bbox and particle pointers are valid and non-NULL.LOG_ALLOW_SCOPE variable is used to distinguish between GLOBAL and LOCAL LOG_ALLOW outputs.Definition at line 979 of file ParticleSwarm.c.
| PetscErrorCode UpdateParticleWeights | ( | PetscReal * | d, |
| Particle * | particle | ||
| ) |
Updates a particle's interpolation weights based on distances to cell faces.
This function computes interpolation weights using distances to the six cell faces (d) and updates the weight field of the provided particle.
| [in] | d | Pointer to an array of distances to the six cell faces. |
| [out] | particle | Pointer to the Particle structure whose weights are to be updated. |
Definition at line 1037 of file ParticleSwarm.c.
| PetscErrorCode InitializeParticleSwarm | ( | SimCtx * | simCtx | ) |
Perform particle swarm initialization, particle-grid interaction, and related operations.
This function handles the following tasks:
| [in,out] | user | Pointer to the UserCtx structure containing grid and particle swarm information. |
| [in] | np | Number of particles to initialize in the swarm. |
| [in] | bboxlist | Pointer to an array of BoundingBox structures, one per MPI rank. |
np (number of particles) is positive.bboxlist array must be correctly computed and passed in before calling this function.Definition at line 1103 of file ParticleSwarm.c.