Updating virial in IForceProvider

The IForceProvider::calculateForces has a gmx::ForceProviderOutput as a parameter where I should update the forces of relevant atoms.

Well. We have to update the forceProviderOutput object ForceWithVirial, when the computeVirial_ is true.

How to calculate the virial? Is there a sample code for that calculation?

The virial is formula (28) on this page:
https://manual.gromacs.org/current/reference-manual/algorithms/molecular-dynamics.html#compute-forces

That is what you need to compute and to add to the virial matrix.

Hi,

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_.