17 PetscReal diffusivity,
22 PetscFunctionBeginUser;
26 if (cell_vol < 1.0e-14) cell_vol = 1.0e-14;
29 PetscReal delta2 = PetscPowReal(cell_vol, 0.6666667);
30 PetscReal omega = C_model * diffusivity / delta2;
31 PetscReal decay = PetscExpReal(-omega * dt);
33 PetscReal psi_old = *psi_io;
34 *psi_io = mean_val + (psi_old - mean_val) * decay;
37 PetscFunctionReturn(0);
49 DM swarm = user->
swarm;
53 PetscReal C_IEM = 2.0;
55 PetscReal *psi_arr = NULL;
56 PetscReal *diff_arr = NULL;
57 PetscInt *cell_arr = NULL;
59 PetscReal ***grid_mean = NULL;
60 PetscReal ***grid_aj = NULL;
62 PetscBool accessed_eulerian = PETSC_FALSE;
64 const char *fieldName = NULL;
66 PetscFunctionBeginUser;
71 PETSC_COMM_SELF, PETSC_ERR_SUP,
72 "Particle field '%s' has no registered model-update kernel.",
76 ierr = DMSwarmGetLocalSize(swarm, &n_local); CHKERRQ(ierr);
79 PetscFunctionReturn(0);
82 ierr = DMSwarmGetField(swarm, fieldName, NULL, NULL, (
void**)&psi_arr); CHKERRQ(ierr);
89 if (!user->
lPsi || !user->
lAj) {
90 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"UserCtx lPsi or lAj not initialized.");
93 ierr = DMDAVecGetArrayRead(da, user->
lPsi, &grid_mean); CHKERRQ(ierr);
94 ierr = DMDAVecGetArrayRead(da, user->
lAj, &grid_aj); CHKERRQ(ierr);
95 accessed_eulerian = PETSC_TRUE;
98 for (PetscInt p = 0; p < n_local; ++p) {
99 PetscReal p_diff = 0.0;
100 PetscReal p_mean = 0.0;
101 PetscReal p_vol = 1.0;
104 PetscInt i = cell_arr[3*p + 0];
105 PetscInt j = cell_arr[3*p + 1];
106 PetscInt k = cell_arr[3*p + 2];
108 p_diff = diff_arr[p];
109 p_mean = grid_mean[k][j][i];
112 PetscReal jac = grid_aj[k][j][i];
113 p_vol = (jac > 1.0e-14) ? (1.0 / jac) : 1.0e-14;
120 ierr = DMSwarmRestoreField(swarm, fieldName, NULL, NULL, (
void**)&psi_arr); CHKERRQ(ierr);
127 if (accessed_eulerian) {
128 ierr = DMDAVecRestoreArrayRead(da, user->
lPsi, &grid_mean); CHKERRQ(ierr);
129 ierr = DMDAVecRestoreArrayRead(da, user->
lAj, &grid_aj); CHKERRQ(ierr);
135 PetscFunctionReturn(0);
PetscErrorCode UpdateFieldForAllParticles(UserCtx *user, ParticleFieldId field_id)
Internal helper implementation: UpdateFieldForAllParticles().
PetscErrorCode UpdateParticleField(ParticleFieldId field_id, PetscReal dt, PetscReal *psi_io, PetscReal diffusivity, PetscReal mean_val, PetscReal cell_vol, PetscReal C_model)
Internal helper implementation: UpdateParticleField().
PetscErrorCode UpdateAllParticleFields(UserCtx *user)
Implementation of UpdateAllParticleFields().
Header file for Particle related physics modules.
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
const char * ParticleFieldName(ParticleFieldId field_id)
Return the canonical PETSc DMSwarm name for an ID.
ParticleFieldId
Compile-time identity for a persistent solver-particle field.
@ PARTICLE_FIELD_ID_CELL_ID
@ PARTICLE_FIELD_ID_DIFFUSIVITY
unsigned int capabilities
@ PARTICLE_FIELD_CAPABILITY_MODEL_UPDATE
PetscErrorCode ParticleFieldGetDescriptor(ParticleFieldId field_id, const ParticleFieldDescriptor **descriptor)
Return immutable metadata for a valid particle field ID.
const char * canonical_name
Immutable metadata for one persistent particle field.