#include "ParticleSwarm.h"#include "ParticleInitialConditions.h"#include "ParticleMotion.h"#include "verification_sources.h"Go to the source code of this file.
Data Structures | |
| struct | SeedingCellTable |
| The owned cells a seeding mode places particles in, and which particles each gets. More... | |
| struct | ParticleInlet |
| One inlet face that injects particles. More... | |
Macros | |
| #define | INTERPOLATION_DISTANCE_TOLERANCE 1.0e-14 |
| #define | SEEDING_LOGIC_MARGIN 1.0e-7 |
| #define | SEEDING_FACE_OFFSET 1.0e-6 |
| #define | PARTICLE_INLET_PID_BASE ((PetscInt64)1 << 40) |
| #define | PARTICLE_INLET_PIDS_PER_CELL ((PetscInt64)1 << 10) |
| #define | PARTICLE_PID_LIMIT ((PetscInt64)1 << 53) |
| #define | PARTICLE_INLET_FACE_COUNT 6 |
| #define | PARTICLE_INLET_SUMS 4 |
Functions | |
| PetscErrorCode | InitializeSwarm (UserCtx *user) |
| Implementation of InitializeSwarm(). | |
| PetscErrorCode | RegisterSwarmField (DM swarm, const char *fieldName, PetscInt fieldDim, PetscDataType dtype) |
| Implementation of RegisterSwarmField(). | |
| PetscErrorCode | RegisterParticleFields (DM swarm) |
| Implementation of RegisterParticleFields(). | |
| static void | SeedingCellOrigin (const SeedingCellTable *table, PetscInt c, PetscInt origin[3]) |
Origin node of cell c of a seeding table, cells numbered i fastest. | |
| static void | SeedingLogicalPoint (const PetscReal u[3], PetscInt face, PetscReal logic[3]) |
Logical seeding coordinates from u: each clamped to [0, 1 - SEEDING_LOGIC_MARGIN], and for face >= 0 the normal one replaced by the point just inside that face. | |
| static PetscErrorCode | SeedingMeasureDensity (UserCtx *user, const Cmpnts ***coor, PetscInt face, PetscInt i, PetscInt j, PetscInt k, const PetscReal logic[3], PetscReal *density) |
| Measure density at a logical point: the Jacobian determinant for the volume, or the area element |dx/ds x dx/dt| across the face for a face, with the normal coordinate on the face itself. | |
| static PetscErrorCode | BuildSeedingCellTable (UserCtx *user, const Cmpnts ***coor, PetscInt face, PetscInt numParticles, PetscBool build_bound, SeedingCellTable *table) |
| Decide which particles each owned cell seeds, the same way at every rank layout. | |
| static PetscErrorCode | FreeSeedingCellTable (SeedingCellTable *table) |
| Free the arrays of a SeedingCellTable. | |
| static PetscErrorCode | DrawSeedingPoint (UserCtx *user, const Cmpnts ***coor, const SeedingCellTable *table, PetscInt c, PetscInt64 pid, const VelocityPointInterpolator *velocity, Cmpnts normal, PetscReal flux_bound, 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, Cmpnts *velocity_out) |
| Draw one particle's seeding point inside its cell, uniform in the cell's measure, or on a face in proportion to the flux through it. | |
| static PetscErrorCode | InitializeParticleBasicProperties (UserCtx *user, PetscInt particlesPerProcess) |
| Initialize position-independent particle fields after a particle is created. | |
| static PetscErrorCode | InitializeDefaultParticleFields (DM swarm, PetscInt first, PetscInt end) |
Set local particles first to end - 1 of every field the particle catalog marks PARTICLE_FIELD_CAPABILITY_DEFAULT_INITIALIZE to the field's catalog default. | |
| PetscErrorCode | AssignInitialPropertiesToSwarm (UserCtx *user, PetscInt particlesPerProcess) |
| Implementation of AssignInitialPropertiesToSwarm(). | |
| PetscErrorCode | DistributeParticles (PetscInt numParticles, PetscMPIInt rank, PetscMPIInt size, PetscInt *particlesPerProcess, PetscInt *remainder) |
| Implementation of DistributeParticles(). | |
| static PetscErrorCode | DistributeParticlesByOwnedMeasure (UserCtx *user, PetscInt face, PetscInt numParticles, PetscInt *localCount) |
| Number of particles this rank seeds for volumetric or surface seeding. | |
| PetscErrorCode | CreateParticleSwarm (UserCtx *user, PetscInt numParticles, PetscInt *particlesPerProcess) |
| Implementation of CreateParticleSwarm(). | |
| PetscErrorCode | UnpackSwarmFields (PetscInt i, const PetscInt64 *PIDs, const PetscReal *weights, const PetscReal *positions, const PetscInt *cellIndices, PetscReal *velocities, PetscInt *LocStatus, PetscReal *diffusivity, Cmpnts *diffusivitygradient, PetscReal *psi, Particle *particle) |
| Implementation of UnpackSwarmFields(). | |
| PetscErrorCode | UpdateSwarmFields (PetscInt i, const Particle *particle, PetscReal *positions, PetscReal *velocities, PetscReal *weights, PetscInt *cellIndices, PetscInt *status, PetscReal *diffusivity, Cmpnts *diffusivitygradient, PetscReal *psi) |
| Implementation of UpdateSwarmFields(). | |
| PetscErrorCode | UpdateParticleWeights (PetscReal *d, Particle *particle) |
| Implementation of UpdateParticleWeights(). | |
| PetscErrorCode | InitializeParticleSwarm (SimCtx *simCtx) |
| Implementation of InitializeParticleSwarm(). | |
| PetscErrorCode | ParticleInletsCreate (SimCtx *simCtx) |
| Implementation of ParticleInletsCreate(). | |
| PetscErrorCode | ParticleInletsDestroy (SimCtx *simCtx) |
| Implementation of ParticleInletsDestroy(). | |
| static PetscErrorCode | InjectAtInlet (UserCtx *user, struct ParticleInlet *inlet, const ParticleFieldEvent *event, PetscInt64 first_id, const VelocityPointInterpolator *velocity, PetscReal sums[4]) |
| Add one inlet's particles for this step. | |
| PetscErrorCode | InjectParticlesAtInlets (UserCtx *user) |
| Implementation of InjectParticlesAtInlets(). | |
| struct SeedingCellTable |
The owned cells a seeding mode places particles in, and which particles each gets.
Volumetric seeding uses the rank's owned cells and surface seeding the owned cells that touch the inlet face, so both are a box of cells from origin with n cells per axis (none when the rank owns no part of the target). Cell c, in i-fastest order, seeds the particles with IDs pid_lo[c] to pid_hi[c] - 1.
Definition at line 91 of file ParticleSwarm.c.
| struct ParticleInlet |
One inlet face that injects particles.
Definition at line 1073 of file ParticleSwarm.c.
| Data Fields | ||
|---|---|---|
| BCFace | face | |
| PicurvExpression * | particles_per_cell |
Mean particles per cell the entering fluid carries, in t. |
| ParticleFieldPlan * | plan | This inlet's field values; NULL uses the case's. |
| SeedingCellTable | table | The owned cells on the face; built at the first injection. |
| PetscReal | cells_per_volume | The grid's cells over its volume, set with the table. |
| PetscBool | table_built | |
| #define INTERPOLATION_DISTANCE_TOLERANCE 1.0e-14 |
Definition at line 8 of file ParticleSwarm.c.
| #define SEEDING_LOGIC_MARGIN 1.0e-7 |
Definition at line 104 of file ParticleSwarm.c.
| #define SEEDING_FACE_OFFSET 1.0e-6 |
Definition at line 105 of file ParticleSwarm.c.
| #define PARTICLE_INLET_PID_BASE ((PetscInt64)1 << 40) |
Definition at line 1066 of file ParticleSwarm.c.
| #define PARTICLE_INLET_PIDS_PER_CELL ((PetscInt64)1 << 10) |
Definition at line 1067 of file ParticleSwarm.c.
| #define PARTICLE_PID_LIMIT ((PetscInt64)1 << 53) |
Definition at line 1068 of file ParticleSwarm.c.
| #define PARTICLE_INLET_FACE_COUNT 6 |
Definition at line 1069 of file ParticleSwarm.c.
| #define PARTICLE_INLET_SUMS 4 |
Definition at line 1070 of file ParticleSwarm.c.
| PetscErrorCode InitializeSwarm | ( | UserCtx * | user | ) |
Implementation of InitializeSwarm().
Initializes the DMSwarm object within the UserCtx structure.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/ParticleSwarm.h.
Definition at line 16 of file ParticleSwarm.c.
| PetscErrorCode RegisterSwarmField | ( | DM | swarm, |
| const char * | fieldName, | ||
| PetscInt | fieldDim, | ||
| PetscDataType | dtype | ||
| ) |
Implementation of RegisterSwarmField().
Registers a swarm field without finalizing registration.
Definition at line 37 of file ParticleSwarm.c.
| PetscErrorCode RegisterParticleFields | ( | DM | swarm | ) |
Implementation of RegisterParticleFields().
Registers necessary particle fields within the DMSwarm.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/ParticleSwarm.h.
Definition at line 60 of file ParticleSwarm.c.
|
inlinestatic |
Origin node of cell c of a seeding table, cells numbered i fastest.
Definition at line 108 of file ParticleSwarm.c.
|
inlinestatic |
Logical seeding coordinates from u: each clamped to [0, 1 - SEEDING_LOGIC_MARGIN], and for face >= 0 the normal one replaced by the point just inside that face.
Definition at line 119 of file ParticleSwarm.c.
|
static |
Measure density at a logical point: the Jacobian determinant for the volume, or the area element |dx/ds x dx/dt| across the face for a face, with the normal coordinate on the face itself.
Definition at line 130 of file ParticleSwarm.c.
|
static |
Decide which particles each owned cell seeds, the same way at every rank layout.
Collective. The cells are those volumetric (face < 0) or surface seeding uses, and each cell's measure is its volume or its area on the face, integrated with 2x2x2 Gauss points: exact for the volume (the determinant has degree 2 in each coordinate) and for the area of a planar face, where the points coincide in pairs and give the 2x2 rule.
Particles are stratified over the measure in global cell order (i fastest): with P(c) the measure of all cells before cell c, T the total and N the particle count, cell c seeds the IDs floor(N P(c) / T) to floor(N (P(c) + m_c) / T) - 1, so each cell holds its expected share to within one, the IDs are 0..N-1, and both depend only on the grid. For the result to be identical at any rank layout the measures are summed as integers, each cell's measure quantised against the largest cell (an exact maximum) to 2^Q units, with Q chosen so the total fits 63 bits. P(c) is the sum of the (j,k) rows before the cell's row, from one reduction over the rows, plus the cells before it in its row, from a scan over the ranks sharing the row.
| [in] | user | Grid context. |
| [in] | coor | Ghosted node-coordinate array. |
| [in] | face | -1 for the volume, otherwise the BCFace to seed on. |
| [in] | numParticles | Global particle count. |
| [in] | build_bound | PETSC_TRUE to also tabulate each cell's largest measure density on a 3x3x3 lattice, the envelope DrawSeedingPoint samples against. |
| [out] | table | The owned cells and their particles; free with FreeSeedingCellTable. |
Definition at line 181 of file ParticleSwarm.c.
|
static |
Free the arrays of a SeedingCellTable.
Definition at line 325 of file ParticleSwarm.c.
|
static |
Draw one particle's seeding point inside its cell, uniform in the cell's measure, or on a face in proportion to the flux through it.
Uniform logical coordinates are accepted with probability density / bound, times the inward normal velocity / flux_bound when velocity is given. Every draw is keyed on the run seed, the particle ID and the attempt, so the point depends only on the particle, not on the rank that seeds it. A surface point is put just inside the cell, SEEDING_FACE_OFFSET of the cell from the face, where its velocity is taken.
| [in] | user | Grid context. |
| [in] | coor | Ghosted node-coordinate array. |
| [in] | table | A table built with build_bound set. |
| [in] | c | The cell, an index into the table. |
| [in] | pid | The particle's ID. |
| [in] | velocity | NULL, or for a face table the velocity the swarm would give the point. |
| [in] | normal | The face's inward unit normal, read with velocity. |
| [in] | flux_bound | An upper bound of the inward normal velocity over the face cell, read with velocity. |
| [out] | ci_metric_lnode_out,cj_metric_lnode_out,ck_metric_lnode_out | Origin node of the cell. |
| [out] | xi_metric_logic_out,eta_metric_logic_out,zta_metric_logic_out | Logical point in it. |
| [out] | velocity_out | The point's velocity, set with velocity; or NULL. |
Definition at line 357 of file ParticleSwarm.c.
|
static |
Initialize position-independent particle fields after a particle is created.
Definition at line 410 of file ParticleSwarm.c.
|
static |
Set local particles first to end - 1 of every field the particle catalog marks PARTICLE_FIELD_CAPABILITY_DEFAULT_INITIALIZE to the field's catalog default.
Definition at line 592 of file ParticleSwarm.c.
| PetscErrorCode AssignInitialPropertiesToSwarm | ( | UserCtx * | user, |
| PetscInt | particlesPerProcess | ||
| ) |
Implementation of AssignInitialPropertiesToSwarm().
Initializes all particle properties in the swarm.
Definition at line 620 of file ParticleSwarm.c.
| PetscErrorCode DistributeParticles | ( | PetscInt | numParticles, |
| PetscMPIInt | rank, | ||
| PetscMPIInt | size, | ||
| PetscInt * | particlesPerProcess, | ||
| PetscInt * | remainder | ||
| ) |
Implementation of DistributeParticles().
Distributes particles evenly across MPI processes, handling any remainders.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/ParticleSwarm.h.
Definition at line 671 of file ParticleSwarm.c.
|
static |
Number of particles this rank seeds for volumetric or surface seeding.
Collective. The count is the rank's share of the stratified split BuildSeedingCellTable makes, so a rank seeds in proportion to the volume or inlet area it owns, none if it owns no part of the inlet, and the counts sum to numParticles exactly.
| [in] | user | Finest-level context whose DMDA ownership defines the split. |
| [in] | face | -1 for the volume, otherwise the inlet BCFace. |
| [in] | numParticles | Global particle count. |
| [out] | localCount | Particles this rank seeds. |
Definition at line 705 of file ParticleSwarm.c.
| PetscErrorCode CreateParticleSwarm | ( | UserCtx * | user, |
| PetscInt | numParticles, | ||
| PetscInt * | particlesPerProcess | ||
| ) |
Implementation of CreateParticleSwarm().
Creates the particle swarm, registers its fields and sizes it for this rank's share.
Definition at line 725 of file ParticleSwarm.c.
| PetscErrorCode UnpackSwarmFields | ( | PetscInt | i, |
| const PetscInt64 * | PIDs, | ||
| const PetscReal * | weights, | ||
| const PetscReal * | positions, | ||
| const PetscInt * | cellIndices, | ||
| PetscReal * | velocities, | ||
| PetscInt * | LocStatus, | ||
| PetscReal * | diffusivity, | ||
| Cmpnts * | diffusivitygradient, | ||
| PetscReal * | psi, | ||
| Particle * | particle | ||
| ) |
Implementation of UnpackSwarmFields().
Initializes a Particle struct with data from DMSwarm fields.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/ParticleSwarm.h.
Definition at line 804 of file ParticleSwarm.c.
| PetscErrorCode UpdateSwarmFields | ( | PetscInt | i, |
| const Particle * | particle, | ||
| PetscReal * | positions, | ||
| PetscReal * | velocities, | ||
| PetscReal * | weights, | ||
| PetscInt * | cellIndices, | ||
| PetscInt * | status, | ||
| PetscReal * | diffusivity, | ||
| Cmpnts * | diffusivitygradient, | ||
| PetscReal * | psi | ||
| ) |
Implementation of UpdateSwarmFields().
Updates DMSwarm data arrays from a Particle struct.
Definition at line 887 of file ParticleSwarm.c.
| PetscErrorCode UpdateParticleWeights | ( | PetscReal * | d, |
| Particle * | particle | ||
| ) |
Implementation of UpdateParticleWeights().
Updates a particle's interpolation weights based on distances to cell faces.
Definition at line 960 of file ParticleSwarm.c.
| PetscErrorCode InitializeParticleSwarm | ( | SimCtx * | simCtx | ) |
Implementation of InitializeParticleSwarm().
High-level particle initialization orchestrator for a simulation run.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/ParticleSwarm.h.
Definition at line 1002 of file ParticleSwarm.c.
| PetscErrorCode ParticleInletsCreate | ( | SimCtx * | simCtx | ) |
Implementation of ParticleInletsCreate().
Read the inlets that inject particles from the options database.
Definition at line 1086 of file ParticleSwarm.c.
| PetscErrorCode ParticleInletsDestroy | ( | SimCtx * | simCtx | ) |
Implementation of ParticleInletsDestroy().
Release what ParticleInletsCreate() and InjectParticlesAtInlets() allocated.
Definition at line 1132 of file ParticleSwarm.c.
|
static |
Add one inlet's particles for this step.
| [in,out] | user | Grid context holding the swarm. |
| [in,out] | inlet | The inlet. |
| [in] | event | Time of the step, and the identity keying field draws. |
| [in] | first_id | This step's first face-cell identity. |
| [in] | velocity | The velocity the swarm gives a point, which places the particles. |
| [in,out] | sums | Adds this rank's flow rate [m^3/s], expected and added particles, and Psi added. |
Definition at line 1158 of file ParticleSwarm.c.
| PetscErrorCode InjectParticlesAtInlets | ( | UserCtx * | user | ) |
Implementation of InjectParticlesAtInlets().
Add the particles that entered through each injecting inlet during this step.
Definition at line 1327 of file ParticleSwarm.c.