/* Set the velocities of vsites, shells and frozen atoms to zero */
for (i = 0; i < mdatoms->homenr; i++)
{
- if (mdatoms->ptype[i] == eptVSite || mdatoms->ptype[i] == eptShell)
+ if (mdatoms->ptype[i] == eptShell)
{
clear_rvec(v[i]);
}
stateGpu->waitCoordinatesReadyOnHost(AtomLocality::Local);
}
+ // We only need to calculate virtual velocities if we are writing them in the current step
+ const bool needVirtualVelocitiesThisStep =
+ (vsite != nullptr)
+ && (do_per_step(step, ir->nstvout) || checkpointHandler->isCheckpointingStep());
+
if (vsite != nullptr)
{
// Virtual sites need to be updated before domain decomposition and forces are calculated
wallcycle_start(wcycle, ewcVSITECONSTR);
- vsite->construct(state->x, ir->delta_t, state->v, state->box);
+ // md-vv calculates virtual velocities once it has full-step real velocities
+ vsite->construct(state->x,
+ state->v,
+ state->box,
+ (!EI_VV(inputrec->eI) && needVirtualVelocitiesThisStep)
+ ? VSiteOperation::PositionsAndVelocities
+ : VSiteOperation::Positions);
wallcycle_stop(wcycle, ewcVSITECONSTR);
}
mdlog,
fplog,
wcycle);
+ if (vsite != nullptr && needVirtualVelocitiesThisStep)
+ {
+ // Positions were calculated earlier
+ wallcycle_start(wcycle, ewcVSITECONSTR);
+ vsite->construct(state->x, state->v, state->box, VSiteOperation::Velocities);
+ wallcycle_stop(wcycle, ewcVSITECONSTR);
+ }
}
/* ######## END FIRST UPDATE STEP ############## */