PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
ParticleMotion.h
Go to the documentation of this file.
1/**
2 * @file ParticleMotion.h
3 * @brief Header file for Particle Motion and migration related functions.
4 *
5 * This file contains declarations of functions responsible for moving and migrating particle swarms within a simulation using PETSc's DMSwarm.
6 */
7
8 #ifndef PARTICLE_MOTION_H
9 #define PARTICLE_MOTION_H
10
11// Include necessary headers
12#include <petsc.h> // PETSc library header
13#include <petscdmswarm.h> // PETSc DMSwarm header
14#include <stdbool.h>
15#include <petscsys.h> // For PetscRealloc
16#include <math.h>
17#include "variables.h" // Common type definitions
18#include "logging.h" // Logging macros and definitions
19#include "walkingsearch.h" // Walking search function for particle migration
20
21/**
22 * @brief Generates two independent standard normal random variables N(0,1)
23 * using the Box-Muller transform.
24 *
25 * @param[in] rnd The PETSc Random context (Uniform [0,1)).
26 * @param[out] n1 First Gaussian number.
27 * @param[out] n2 Second Gaussian number.
28 *
29 * @return PetscErrorCode
30 */
31PetscErrorCode GenerateGaussianNoise(PetscRandom rnd, PetscReal *n1, PetscReal *n2);
32
33/**
34 * @brief Calculates the stochastic displacement vector (Brownian motion) for a single particle.
35 * Equation: dX_stoch = sqrt(2 * Gamma_eff * dt) * N(0,1)
36 *
37 * @param[in] user Pointer to UserCtx (access to dt and BrownianMotionRNG).
38 * @param[in] diff_eff The effective diffusivity (Gamma + Gamma_t) at the particle's location.
39 * @param[out] displacement Pointer to a Cmpnts struct to store the resulting (dx, dy, dz).
40 *
41 * @return PetscErrorCode
42 */
43PetscErrorCode CalculateBrownianDisplacement(UserCtx *user, PetscReal diff_eff, Cmpnts *displacement);
44
45/**
46 * @brief Updates a particle's position based on its velocity and the timestep dt (stored in user->dt).
47 *
48 * @param[in] user Pointer to your UserCtx (must contain user->dt).
49 * @param[in,out] particle Pointer to the particle struct (contains, pos,vel,diffusivity etc).
50 *
51 * @return PetscErrorCode Returns 0 on success, or an error code on failure.
52 */
53PetscErrorCode UpdateParticlePosition(UserCtx *user, Particle *particle);
54
55/**
56 * @brief Loops over all local particles in the DMSwarm, updating their positions
57 * based on velocity and the global timestep user->dt.
58 * @param[in,out] user Pointer to UserCtx (must contain dt).
59 *
60 * @return PetscErrorCode Returns 0 on success, or an error code on failure.
61 */
62 PetscErrorCode UpdateAllParticlePositions(UserCtx *user);
63
64/**
65 * @brief Checks for particles outside the physical domain boundaries and removes them
66 * using DMSwarmRemovePointAtIndex.
67 *
68 * This function iterates through all particles local to the current MPI rank.
69 * It checks if a particle's position (x, y, or z) is outside the specified
70 * physical domain boundaries [xMin, xMax], [yMin, yMax], [zMin, zMax].
71 *
72 * If a particle is found out of bounds, it is removed using DMSwarmRemovePointAtIndex.
73 * NOTE: Removing points changes the indices of subsequent points in the iteration.
74 * Therefore, it's crucial to iterate BACKWARDS or carefully manage indices
75 * after a removal. Iterating backwards is generally safer.
76 *
77 * @param user Pointer to the UserCtx structure.
78 * @param[out] removedCountLocal Pointer to store the number of particles removed *on this rank*.
79 * @param[out] removedCountGlobal Pointer to store the total number of particles removed *across all ranks*.
80 * @param[in] bboxlist An array of BoundingBox structures for ALL MPI ranks, indexed 0 to (size-1).
81 * This array must be up-to-date and available on all ranks.
82 *
83 * @return PetscErrorCode 0 on success, non-zero on failure.
84 */
86 PetscInt *removedCountLocal,
87 PetscInt *removedCountGlobal,
88 const BoundingBox *bboxlist);
89
90/**
91 * @brief Removes particles that have been definitively flagged as LOST by the location algorithm.
92 *
93 * This function is the designated cleanup utility. It should be called after the
94 * `LocateAllParticlesInGrid` orchestrator has run and every particle's status
95 * has been definitively determined.
96 *
97 * It iterates through all locally owned particles and checks their `DMSwarm_location_status`
98 * field. If a particle's status is `LOST`, it is permanently removed from the simulation
99 * using `DMSwarmRemovePointAtIndex`.
100 *
101 * This approach centralizes the removal logic, making the `DMSwarm_location_status`
102 * the single source of truth for a particle's validity, which is more robust than
103 * relying on secondary geometric checks (like bounding boxes).
104 *
105 * @param[in,out] user Pointer to the UserCtx structure containing the swarm.
106 * @param[out] removedCountLocal Pointer to store the number of particles removed on this rank.
107 * @param[out] removedCountGlobal Pointer to store the total number of particles removed across all ranks.
108 * @param[out] removedScalarSumGlobal Optional, may be NULL: the sum of `Psi` over every
109 * particle removed on any rank. With a 0/1 label and micromixing off, it
110 * counts the removed particles that carried the label.
111 *
112 * @return PetscErrorCode 0 on success, or a non-zero PETSc error code on failure.
113 */
114PetscErrorCode CheckAndRemoveLostParticles(UserCtx *user,
115 PetscInt *removedCountLocal,
116 PetscInt *removedCountGlobal,
117 PetscReal *removedScalarSumGlobal);
118
119/**
120 * @brief Defines the basic migration pattern for particles within the swarm.
121 *
122 * This function establishes the migration pattern that dictates how particles
123 * move between different MPI ranks in the simulation. It initializes a migration
124 * list where each particle is assigned a target rank based on predefined conditions.
125 * The migration pattern can be customized to implement various migration behaviors.
126 *
127 * @param[in,out] user Pointer to the UserCtx structure containing simulation context.
128 *
129 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
130 */
132
133/**
134 * @brief Performs the basic migration of particles based on the defined migration pattern.
135 *
136 * This function updates the positions of particles within the swarm by migrating them
137 * to target MPI ranks as specified in the migration list. It handles the migration process
138 * by setting the 'DMSwarm_rank' field for each particle and invokes the DMSwarm migration
139 * mechanism to relocate particles across MPI processes. After migration, it cleans up
140 * allocated resources and ensures synchronization across all MPI ranks.
141 *
142 * @param[in,out] user Pointer to the UserCtx structure containing simulation context.
143 *
144 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
145 */
146PetscErrorCode PerformBasicMigration(UserCtx* user);
147
148/**
149 * @brief Identifies particles leaving the local bounding box and finds their target neighbor rank.
150 *
151 * Iterates local particles, checks against local bounding box. If outside, checks
152 * the pre-computed immediate neighbors (user->neighbors) using the global bboxlist
153 * to see if the particle landed in one of them. Populates the migrationList.
154 * Does NOT handle particles leaving the global domain (assumes CheckAndRemove was called).
155 *
156 * @param user Pointer to the UserCtx (contains local bbox and neighbors).
157 * @param bboxlist Array of BoundingBox structs for all ranks (for checking neighbor boxes).
158 * @param migrationList Pointer to an array of MigrationInfo structs (output, allocated/reallocated by this func).
159 * @param migrationCount Pointer to the number of particles marked for migration (output).
160 * @param listCapacity Pointer to the current allocated capacity of migrationList (in/out).
161 *
162 * @return PetscErrorCode 0 on success, non-zero on failure.
163 */
165 const BoundingBox *bboxlist,
166 MigrationInfo **migrationList,
167 PetscInt *migrationCount,
168 PetscInt *listCapacity);
169
170/**
171 * @brief Writes migration destinations into the DMSwarm rank field for marked particles.
172 *
173 * This helper consumes the migration list produced by `IdentifyMigratingParticles`
174 * and updates each selected particle's destination rank so that a subsequent
175 * `PerformMigration` call can transfer ownership correctly.
176 *
177 * @param[in,out] user Context containing the swarm and migration rank field.
178 * @param[in] migrationList Array of migration directives (local index + destination rank).
179 * @param[in] migrationCount Number of valid entries in `migrationList`.
180 * @return PetscErrorCode 0 on success.
181 */
182PetscErrorCode SetMigrationRanks(UserCtx* user, const MigrationInfo *migrationList, PetscInt migrationCount);
183
184/**
185 * @brief Performs particle migration based on the pre-populated DMSwarmPICField_rank field.
186 *
187 * Assumes SetMigrationRanks has already been called to mark particles with their target ranks.
188 * Calls DMSwarmMigrate to execute the communication and removal of un-migrated particles.
189 *
190 * @param user Pointer to the UserCtx structure containing the swarm.
191 *
192 * @return PetscErrorCode 0 on success, non-zero on failure.
193 */
194PetscErrorCode PerformMigration(UserCtx *user);
195
196/**
197 * @brief Counts particles in each cell of the DMDA 'da' and stores the result in user->ParticleCount.
198 *
199 * Assumes user->ParticleCount is a pre-allocated global vector associated with user->da
200 * and initialized to zero before calling this function (though it resets it internally).
201 * Assumes particle 'DMSwarm_CellID' field contains local cell indices.
202 *
203 * @param[in,out] user Pointer to the UserCtx structure containing da, swarm, and ParticleCount.
204 * @return PetscErrorCode Returns 0 on success, non-zero on failure.
205 */
206PetscErrorCode CalculateParticleCountPerCell(UserCtx *user);
207
208/**
209 * @brief Resizes a swarm collectively to a target global particle count.
210 *
211 * The target is divided by quotient and remainder so every rank receives either
212 * `floor(N_target / nranks)` or one additional entry. Resizing establishes the
213 * storage layout; callers initialize or overwrite particle fields afterwards.
214 *
215 * @param[in,out] swarm Swarm object to resize.
216 * @param[in] N_target Target global particle count.
217 * @return PetscErrorCode 0 on success.
218 */
219PetscErrorCode ResizeSwarmGlobally(DM swarm, PetscInt N_target);
220
221/**
222 * @brief Checks particle count in the reference file and resizes the swarm if needed.
223 *
224 * Reads the specified field file (e.g., position) into a temporary Vec to determine
225 * the number of particles (`N_file`) represented in that file for the given timestep.
226 * Compares `N_file` with the current swarm size (`N_current`). If they differ,
227 * resizes the swarm globally (adds or removes particles) to match `N_file`.
228 * The resized population is balanced across the communicator before field input.
229 *
230 * @param[in,out] user Pointer to the UserCtx structure containing the DMSwarm.
231 * @param[in] ti Time index for constructing the file name.
232 * @param[in] ext File extension (e.g., "dat").
233 *
234 * @return PetscErrorCode 0 on success, non-zero on critical failure.
235 */
236PetscErrorCode PreCheckAndResizeSwarm(UserCtx *user, PetscInt ti, const char *ext);
237
238/**
239 * @brief Performs one full cycle of particle migration: identify, set ranks, and migrate.
240 *
241 * This function encapsulates the three main steps of migrating particles between MPI ranks:
242 * 1. Identify particles on the local rank that need to move based on their current
243 * positions and the domain decomposition (`bboxlist`).
244 * 2. Determine the destination rank for each migrating particle.
245 * 3. Perform the actual migration using PETSc's `DMSwarmMigrate`.
246 * It also calculates and logs the global number of particles migrated.
247 *
248 * @param user Pointer to the UserCtx structure.
249 * @param bboxlist Array of BoundingBox structures defining the spatial domain of each MPI rank.
250 * @param migrationList_p Pointer to a pointer for the MigrationInfo array. This array will be
251 * allocated/reallocated by `IdentifyMigratingParticles` if necessary.
252 * The caller is responsible for freeing this list eventually.
253 * @param migrationCount_p Pointer to store the number of particles identified for migration
254 * on the local rank. This is reset to 0 after migration for the current cycle.
255 * @param migrationListCapacity_p Pointer to store the current capacity of the `migrationList_p` array.
256 * @param currentTime Current simulation time (used for logging).
257 * @param step Current simulation step number (used for logging).
258 * @param migrationCycleName A descriptive name for this migration cycle (e.g., "Preliminary Sort", "Main Loop")
259 * for logging purposes.
260 * @param[out] globalMigrationCount_out Pointer to store the total number of particles migrated
261 * across all MPI ranks during this cycle.
262 * @return PetscErrorCode 0 on success, non-zero on failure.
263 */
264PetscErrorCode PerformSingleParticleMigrationCycle(UserCtx *user, const BoundingBox *bboxlist,
265 MigrationInfo **migrationList_p, PetscInt *migrationCount_p,
266 PetscInt *migrationListCapacity_p,
267 PetscReal currentTime, PetscInt step, const char *migrationCycleName,
268 PetscInt *globalMigrationCount_out);
269
270
271/**
272 * @brief Re-initializes the positions of particles currently on this rank if this rank owns
273 * part of the designated inlet surface.
274 *
275 * This function is intended for `user->ParticleInitialization == 0` (Surface Initialization mode)
276 * and is typically called after an initial migration step (e.g., in `PerformInitialSetup`).
277 * It ensures that all particles that should originate from the inlet surface and are now
278 * on the correct MPI rank are properly distributed across that rank's portion of the inlet.
279 *
280 * @param user Pointer to the UserCtx structure, containing simulation settings and grid information.
281 * @param currentTime Current simulation time (used for logging).
282 * @param step Current simulation step number (used for logging).
283 * @return PetscErrorCode 0 on success, non-zero on failure.
284 */
285PetscErrorCode ReinitializeParticlesOnInletSurface(UserCtx *user, PetscReal currentTime, PetscInt step);
286
287/**
288 * @brief Creates a sorted snapshot of all Particle IDs (PIDs) from a raw data array.
289 * @ingroup ParticleUtils
290 *
291 * This function is a crucial helper for the migration process. It captures the state of
292 * which particles are on the current MPI rank *before* migration occurs by taking a
293 * pointer to the swarm's raw PID data array. The resulting sorted array can then be used
294 * with an efficient binary search to quickly identify newcomer particles after migration.
295 *
296 * This function does NOT call DMSwarmGetField/RestoreField. It is the caller's
297 * responsibility to acquire the `pid_field` pointer before calling and restore it afterward.
298 *
299 * @param[in] pid_field A read-only pointer to the raw array of PIDs for the local swarm.
300 * @param[in] n_local The number of particles currently on the local rank.
301 * @param[out] pids_snapshot_out A pointer to a `PetscInt64*` array. This function will
302 * allocate memory for this array, and the caller is
303 * responsible for freeing it with `PetscFree()` when it
304 * is no longer needed.
305 *
306 * @return PetscErrorCode 0 on success, or a non-zero PETSc error code on failure.
307 */
308PetscErrorCode GetLocalPIDSnapshot(const PetscInt64 pid_field[],
309 PetscInt n_local,
310 PetscInt64 **pids_snapshot_out);
311
312/**
313 * @brief Safely adds a new migration task to a dynamically sized list.
314 *
315 * This utility function manages a dynamic array of MigrationInfo structs. It appends
316 * a new entry to the list and automatically doubles the array's capacity using
317 * `PetscRealloc` if the current capacity is exceeded. This prevents buffer overflows
318 * and avoids the need to know the number of migrating particles in advance.
319 *
320 * @param[in,out] migration_list_p A pointer to the MigrationInfo array pointer. The function
321 * will update this pointer if the array is reallocated.
322 * @param[in,out] capacity_p A pointer to an integer holding the current allocated
323 * capacity of the list (in number of elements). This will be
324 * updated upon reallocation.
325 * @param[in,out] count_p A pointer to an integer holding the current number of
326 * items in the list. This will be incremented by one.
327 * @param[in] particle_local_idx The local index (from 0 to nlocal-1) of the particle
328 * that needs to be migrated.
329 * @param[in] destination_rank The target MPI rank for the particle.
330 *
331 * @return PetscErrorCode 0 on success, or a non-zero PETSc error code on failure (e.g., from memory allocation).
332 */
333PetscErrorCode AddToMigrationList(MigrationInfo **migration_list_p,
334 PetscInt *capacity_p,
335 PetscInt *count_p,
336 PetscInt particle_local_idx,
337 PetscMPIInt destination_rank);
338
339/**
340 * @brief Identifies newly arrived particles after migration and flags them for a location search.
341 * @ingroup ParticleMotion
342 *
343 * This function is a critical component of the iterative migration process managed by
344 * the main particle settlement orchestrator (e.g., `SettleParticles`). After a
345 * `DMSwarmMigrate` call, each rank's local particle list is a new mix of resident
346 * particles and newly received ones. This function's job is to efficiently identify
347 * these "newcomers" and set their `DMSwarm_location_status` field to `NEEDS_LOCATION`.
348 *
349 * This ensures that in the subsequent pass of the migration `do-while` loop, only the
350 * newly arrived particles are processed by the expensive location algorithm, preventing
351 * redundant work on particles that are already settled on the current rank.
352 *
353 * The identification is done by comparing the PIDs of particles currently on the rank
354 * against a "snapshot" of PIDs taken *before* the migration occurred.
355 *
356 * @param[in] swarm The DMSwarm object, which has just completed a migration.
357 * @param[in] n_local_before The number of particles that were on this rank *before* the
358 * migration was performed.
359 * @param[in] pids_before A pre-sorted array of the PIDs that were on this rank before
360 * the migration. This is used for fast lookups.
361 *
362 * @return PetscErrorCode 0 on success, or a non-zero PETSc error code on failure.
363 *
364 * @note This function assumes the `pids_before` array is sorted in ascending order to
365 * enable the use of an efficient binary search.
366 */
367PetscErrorCode FlagNewcomersForLocation(DM swarm,
368 PetscInt n_local_before,
369 const PetscInt64 pids_before[]);
370
371
372/**
373 * @brief Fast-path migration for restart particles using preloaded Cell IDs.
374 *
375 * This function provides an optimized migration path specifically for particles
376 * loaded from restart files. Unlike the standard `LocateAllParticlesInGrid()`
377 * which performs expensive walking searches, this function leverages the fact that
378 * restart particles already have valid global Cell IDs loaded from disk.
379 *
380 * **How It Works:**
381 * 1. Iterates through all local particles.
382 * 2. For each particle with a valid Cell ID (ci, cj, ck):
383 * - Calls `FindOwnerOfCell(ci, cj, ck)` to determine the correct rank.
384 * - If owner differs from current rank, adds to migration list.
385 * - If owner matches current rank, the existing `ACTIVE_AND_LOCATED` status is preserved.
386 * 3. Uses existing `SetMigrationRanks()` and `PerformMigration()` infrastructure.
387 * 4. Achieves **single-pass direct migration** (no multi-hop, no walking searches).
388 *
389 * @param[in,out] user Pointer to UserCtx containing the swarm and RankCellInfoMap.
390 * The function updates particle status fields and performs migration.
391 *
392 * @return PetscErrorCode 0 on success, non-zero on failure.
393 *
394 * @note Testing status:
395 * Direct coverage currently focuses on restart fast-path ownership transfer.
396 * Non-restart multi-pass migration behavior remains part of the next
397 * simulation-core test backlog.
398 */
399PetscErrorCode MigrateRestartParticlesUsingCellID(UserCtx *user);
400
401/**
402 * @brief Orchestrates the complete particle location and migration process for one timestep.
403 * @ingroup ParticleLocation
404 *
405 * This function is the master orchestrator for ensuring every particle is on its correct
406 * MPI rank and has a valid host cell index. It is designed to be called once per
407 * timestep after particle positions have been updated.
408 *
409 * The function uses a robust, iterative "Guess and Verify" strategy within a
410 * do-while loop to handle complex particle motion across processor boundaries,
411 * especially on curvilinear grids.
412 *
413 * 1. **State Snapshot:** At the start of each pass, it captures a list of all Particle IDs (PIDs)
414 * on the current rank.
415 * 2. **"Guess" (Heuristic):** For particles that are "lost" (no valid host cell),
416 * it first attempts a fast, bounding-box-based guess to find a potential new owner rank.
417 * 3. **"Verify" (Robust Walk):** For all other particles, or if the guess fails,
418 * it uses a robust cell-walking algorithm (`LocateParticleOrFindMigrationTarget`)
419 * that determines the particle's status: located locally, needs migration, or is lost.
420 * 4. **Migration:** After identifying all migrating particles on a pass, it performs the
421 * MPI communication using the `SetMigrationRanks` and `PerformMigration` helpers.
422 * 5. **Newcomer Flagging:** After migration, it uses the PID snapshot from step 1 to
423 * efficiently identify newly arrived particles and flag them for location on the next pass.
424 * 6. **Iteration:** The process repeats in a `do-while` loop until a pass occurs where
425 * no particles migrate, ensuring the entire swarm is in a stable, consistent state.
426 *
427 * @param[in,out] user Pointer to the UserCtx, containing the swarm and all necessary
428 * domain topology information (bboxlist, RankCellInfoMap, etc.).
429 * @param[in] bboxlist An array of BoundingBox structures for ALL MPI ranks, indexed 0 to (size-1).
430 * This array must be up-to-date and available on all ranks.
431 * @return PetscErrorCode 0 on success, or a non-zero PETSc error code on failure.
432 *
433 * @note Testing status:
434 * Direct unit coverage currently pins the prior-cell fast path and the
435 * local guess-then-verify path. Multi-pass migration, newcomer flagging,
436 * and several lost/migration edge cases are still targeted for future
437 * bespoke tests.
438 */
439PetscErrorCode LocateAllParticlesInGrid(UserCtx *user,BoundingBox *bboxlist);
440
441/**
442 * @brief Marks all local particles as `NEEDS_LOCATION` for the next settlement pass.
443 *
444 * This function is designed to be called at the end of a full timestep, after all
445 * particle-based calculations are complete. It prepares the swarm for the next
446 * timestep by ensuring that after the next position update, every particle will be
447 * re-evaluated by the LocateAllParticlesInGrid orchestrator.
448 *
449 * It iterates through all locally owned particles and sets their
450 * `DMSwarm_location_status` field to `NEEDS_LOCATION`.
451 *
452 * @param[in,out] user Pointer to the UserCtx containing the swarm.
453 * @return PetscErrorCode 0 on success, or a non-zero PETSc error code on failure.
454 */
455PetscErrorCode ResetAllParticleStatuses(UserCtx *user);
456
457 #endif // PARTICLE_MOTION_H
PetscErrorCode GenerateGaussianNoise(PetscRandom rnd, PetscReal *n1, PetscReal *n2)
Generates two independent standard normal random variables N(0,1) using the Box-Muller transform.
PetscErrorCode CheckAndRemoveLostParticles(UserCtx *user, PetscInt *removedCountLocal, PetscInt *removedCountGlobal, PetscReal *removedScalarSumGlobal)
Removes particles that have been definitively flagged as LOST by the location algorithm.
PetscErrorCode ResizeSwarmGlobally(DM swarm, PetscInt N_target)
Resizes a swarm collectively to a target global particle count.
PetscErrorCode AddToMigrationList(MigrationInfo **migration_list_p, PetscInt *capacity_p, PetscInt *count_p, PetscInt particle_local_idx, PetscMPIInt destination_rank)
Safely adds a new migration task to a dynamically sized list.
PetscErrorCode SetMigrationRanks(UserCtx *user, const MigrationInfo *migrationList, PetscInt migrationCount)
Writes migration destinations into the DMSwarm rank field for marked particles.
PetscErrorCode CheckAndRemoveOutOfBoundsParticles(UserCtx *user, PetscInt *removedCountLocal, PetscInt *removedCountGlobal, const BoundingBox *bboxlist)
Checks for particles outside the physical domain boundaries and removes them using DMSwarmRemovePoint...
PetscErrorCode GetLocalPIDSnapshot(const PetscInt64 pid_field[], PetscInt n_local, PetscInt64 **pids_snapshot_out)
Creates a sorted snapshot of all Particle IDs (PIDs) from a raw data array.
PetscErrorCode MigrateRestartParticlesUsingCellID(UserCtx *user)
Fast-path migration for restart particles using preloaded Cell IDs.
PetscErrorCode UpdateAllParticlePositions(UserCtx *user)
Loops over all local particles in the DMSwarm, updating their positions based on velocity and the glo...
PetscErrorCode CalculateParticleCountPerCell(UserCtx *user)
Counts particles in each cell of the DMDA 'da' and stores the result in user->ParticleCount.
PetscErrorCode CalculateBrownianDisplacement(UserCtx *user, PetscReal diff_eff, Cmpnts *displacement)
Calculates the stochastic displacement vector (Brownian motion) for a single particle.
PetscErrorCode LocateAllParticlesInGrid(UserCtx *user, BoundingBox *bboxlist)
Orchestrates the complete particle location and migration process for one timestep.
PetscErrorCode UpdateParticlePosition(UserCtx *user, Particle *particle)
Updates a particle's position based on its velocity and the timestep dt (stored in user->dt).
PetscErrorCode ResetAllParticleStatuses(UserCtx *user)
Marks all local particles as NEEDS_LOCATION for the next settlement pass.
PetscErrorCode DefineBasicMigrationPattern(UserCtx *user)
Defines the basic migration pattern for particles within the swarm.
PetscErrorCode PerformSingleParticleMigrationCycle(UserCtx *user, const BoundingBox *bboxlist, MigrationInfo **migrationList_p, PetscInt *migrationCount_p, PetscInt *migrationListCapacity_p, PetscReal currentTime, PetscInt step, const char *migrationCycleName, PetscInt *globalMigrationCount_out)
Performs one full cycle of particle migration: identify, set ranks, and migrate.
PetscErrorCode ReinitializeParticlesOnInletSurface(UserCtx *user, PetscReal currentTime, PetscInt step)
Re-initializes the positions of particles currently on this rank if this rank owns part of the design...
PetscErrorCode IdentifyMigratingParticles(UserCtx *user, const BoundingBox *bboxlist, MigrationInfo **migrationList, PetscInt *migrationCount, PetscInt *listCapacity)
Identifies particles leaving the local bounding box and finds their target neighbor rank.
PetscErrorCode FlagNewcomersForLocation(DM swarm, PetscInt n_local_before, const PetscInt64 pids_before[])
Identifies newly arrived particles after migration and flags them for a location search.
PetscErrorCode PreCheckAndResizeSwarm(UserCtx *user, PetscInt ti, const char *ext)
Checks particle count in the reference file and resizes the swarm if needed.
PetscErrorCode PerformBasicMigration(UserCtx *user)
Performs the basic migration of particles based on the defined migration pattern.
PetscErrorCode PerformMigration(UserCtx *user)
Performs particle migration based on the pre-populated DMSwarmPICField_rank field.
Logging utilities and macros for PETSc-based applications.
Main header file for a complex fluid dynamics solver.
Defines a 3D axis-aligned bounding box.
Definition variables.h:197
A 3D point or vector with PetscScalar components.
Definition variables.h:121
Information needed to migrate a single particle between MPI ranks.
Definition variables.h:235
Defines a particle's core properties for Lagrangian tracking.
Definition variables.h:208
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1074
Header file for particle location functions using the walking search algorithm.