72 DM swarm = user->
swarm;
74 PetscReal current_time = user->
simCtx->
ti;
77 const PetscReal *pos_arr;
78 const PetscReal *vel_arr;
81 PetscFunctionBeginUser;
84 ierr = DMSwarmGetLocalSize(swarm, &n_local); CHKERRQ(ierr);
86 PetscFunctionReturn(0);
90 ierr = DMSwarmGetField(swarm,
"position", NULL, NULL, (
void**)&pos_arr); CHKERRQ(ierr);
91 ierr = DMSwarmGetField(swarm,
"velocity", NULL, NULL, (
void**)&vel_arr); CHKERRQ(ierr);
94 ierr = DMSwarmGetField(swarm, fieldName, NULL, NULL, (
void**)&psi_arr); CHKERRQ(ierr);
97 for (PetscInt p = 0; p < n_local; ++p) {
99 Cmpnts current_pos = {pos_arr[3*p + 0], pos_arr[3*p + 1], pos_arr[3*p + 2]};
100 Cmpnts current_vel = {vel_arr[3*p + 0], vel_arr[3*p + 1], vel_arr[3*p + 2]};
104 ierr =
UpdateParticleField(fieldName, current_time, current_pos, current_vel, &psi_arr[p]); CHKERRQ(ierr);
108 ierr = DMSwarmRestoreField(swarm,
"position", NULL, NULL, (
void**)&pos_arr); CHKERRQ(ierr);
109 ierr = DMSwarmRestoreField(swarm,
"velocity", NULL, NULL, (
void**)&vel_arr); CHKERRQ(ierr);
110 ierr = DMSwarmRestoreField(swarm, fieldName, NULL, NULL, (
void**)&psi_arr); CHKERRQ(ierr);
115 PetscFunctionReturn(0);
PetscErrorCode UpdateFieldForAllParticles(UserCtx *user, const char *fieldName)
Loops over all local particles and updates a specified field.
PetscErrorCode UpdateParticleField(const char *fieldName, PetscReal t, Cmpnts pos, Cmpnts vel, PetscReal *psi_io)
Updates a single particle's field based on its state and the specified field name.
PetscErrorCode UpdateAllParticleFields(UserCtx *user)
Orchestrates the update of all physical properties for particles.
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...