PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
ParticlePhysics.h
Go to the documentation of this file.
1/**
2 * @file ParticlePhysics.h
3 * @brief Header file for Particle related physics modules.
4 *
5 * This file contains declarations of functions responsible for solving for fields in the particle swarms within a simulation using PETSc's DMSwarm.
6 */
7
8 #ifndef PARTICLE_PHYSICS_H
9 #define PARTICLE_PHYSICS_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
19#include "logging.h" // Logging macros and definitions
20#include "walkingsearch.h" // Walking search function for particle migration
21
22/**
23 * @brief Updates a single particle's field based on its state and physics model.
24 *
25 * Implements the IEM (Interaction by Exchange with the Mean) model for scalar mixing.
26 * Physics: dPsi/dt = -Omega * (Psi - Psi_mean)
27 * Solution: Psi_new = Psi_mean + (Psi_old - Psi_mean) * exp(-Omega * dt)
28 *
29 * @param field_id Typed particle-field identity.
30 * @param dt Time
31 * @param psi_io Pointer
32 * @param diffusivity Particle
33 * @param mean_val Local
34 * @param delta2 Squared mixing length: the host cell volume to the power 2/3, the volume
35 * floored at 1e-14 first.
36 * @param C_model Model
37 * @return PetscErrorCode 0 on success.
38 */
39PetscErrorCode UpdateParticleField(ParticleFieldId field_id,
40 PetscReal dt,
41 PetscReal *psi_io,
42 PetscReal diffusivity,
43 PetscReal mean_val,
44 PetscReal delta2,
45 PetscReal C_model);
46
47
48/**
49 * @brief Loops over all local particles and updates a specified field.
50 *
51 * This function orchestrates the update of a single particle field across the entire
52 * local swarm. It gets access to the necessary particle data arrays and calls the
53 * `UpdateParticleField` kernel for each particle.
54 *
55 * For Psi the IEM target is the host cell's limited linear reconstruction
56 * m + zeta g . (x - x_c): m and x_c are the cell's Psi mean and particle centroid weighted by
57 * each particle's relaxation weight 1 - exp(-omega_p dt), so every cell's Psi total is kept
58 * whatever the particles' rates; g is the gradient of the plain cell means; zeta in [0, 1] keeps
59 * every target within the extrema of all particles' Psi at the start of the step, so Psi stays
60 * within them. Collective for Psi.
61 *
62 * @param[in,out] user Pointer to the UserCtx containing the swarm and simulation context.
63 * @param[in] field_id Typed identity of the field to update.
64 *
65 * @return PetscErrorCode 0 on success.
66 */
67PetscErrorCode UpdateFieldForAllParticles(UserCtx *user, ParticleFieldId field_id);
68
69
70/**
71 * @brief Orchestrates the update of all physical properties for particles.
72 *
73 * This function serves as the top-level entry point for updating particle-specific
74 * physical quantities after their position and the surrounding fluid velocity are known.
75 * It calls a sequence of more specific update routines for each property.
76 *
77 * For example, it can be configured to update:
78 * - Particle kinetic energy (stored in "Psi")
79 * - Particle accumulated shear stress
80 * - Particle temperature
81 * - etc.
82 *
83 * @param[in,out] user Pointer to the UserCtx containing the swarm and simulation context.
84 *
85 * @return PetscErrorCode 0 on success.
86 */
87PetscErrorCode UpdateAllParticleFields(UserCtx *user);
88
89/**
90 * @brief Computes the effective diffusivity scalar field (Gamma_eff) on the Eulerian grid.
91 *
92 * This function calculates the total diffusivity used to drive the stochastic
93 * motion of particles (Scalar FDF). It combines molecular diffusion and
94 * turbulent diffusion.
95 *
96 * Formula:
97 * Gamma_eff = nu/Sc + nu_t/Sc_t
98 *
99 * Where:
100 * - nu = 1/Re (kinematic viscosity)
101 * - nu_t (eddy viscosity from LES/RANS model)
102 * - Sc (molecular Schmidt number)
103 * - Sc_t (turbulent Schmidt number)
104 *
105 * @note If turbulence models are disabled, nu_t is assumed to be 0.
106 * @note This function updates the local ghost values of lDiffusivity at the end
107 * to ensure gradients can be computed correctly at subdomain boundaries.
108 *
109 * @param[in,out] user Pointer to the user context containing grid data and simulation parameters.
110 *
111 * @return PetscErrorCode 0 on success.
112 */
113PetscErrorCode ComputeEulerianDiffusivity(UserCtx *user);
114
115/**
116 * @brief Computes the Eulerian gradient of the effective diffusivity field.
117 *
118 * Reads the scalar diffusivity field and writes a vector gradient field used by
119 * particle stochastic transport updates.
120 *
121 * @param[in,out] user Pointer to user context containing diffusivity vectors.
122 * @return PetscErrorCode 0 on success.
123 */
124PetscErrorCode ComputeEulerianDiffusivityGradient(UserCtx *user);
125
126#endif // PARTICLE_PHYSICS_H
PetscErrorCode UpdateFieldForAllParticles(UserCtx *user, ParticleFieldId field_id)
Loops over all local particles and updates a specified field.
PetscErrorCode ComputeEulerianDiffusivity(UserCtx *user)
Computes the effective diffusivity scalar field (Gamma_eff) on the Eulerian grid.
PetscErrorCode ComputeEulerianDiffusivityGradient(UserCtx *user)
Computes the Eulerian gradient of the effective diffusivity field.
PetscErrorCode UpdateAllParticleFields(UserCtx *user)
Orchestrates the update of all physical properties for particles.
PetscErrorCode UpdateParticleField(ParticleFieldId field_id, PetscReal dt, PetscReal *psi_io, PetscReal diffusivity, PetscReal mean_val, PetscReal delta2, PetscReal C_model)
Updates a single particle's field based on its state and physics model.
Logging utilities and macros for PETSc-based applications.
Typed identities and metadata for persistent solver-particle fields.
ParticleFieldId
Compile-time identity for a persistent solver-particle field.
Main header file for a complex fluid dynamics solver.
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1157
Header file for particle location functions using the walking search algorithm.