One way is to increment the forces of the relevant atoms with forceProviderOutput->forceWithVirial_.force_.
Then, compute the virial contribution of those atoms and forces with a local variable matrix vir.
Then, add this matrix vir to the global virial through forceProviderOutput->forceWithVirial_.addVirialContribution(vir); which takes into account the boolean computeVirial_.