Skip to content

Commit

Permalink
Remove kinetic energy contribution from virtual sites (#4839)
Browse files Browse the repository at this point in the history
Fixes #4838

Description of changes:
- fix virtual sites regression introduced in ESPResSo 4.2.0
- update description of `MASS` and `ROTATIONAL_INERTIA` features
  • Loading branch information
kodiakhq[bot] authored Dec 14, 2023
2 parents 898b4cb + c759ee8 commit 504fd38
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
8 changes: 4 additions & 4 deletions doc/sphinx/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,15 @@ General features
- ``THERMOSTAT_PER_PARTICLE`` Allows setting a per-particle friction
coefficient for the Langevin and Brownian thermostats.

- ``ROTATIONAL_INERTIA`` Allows to set the eigenvalues for rotational inertia matrix of particles
- ``ROTATIONAL_INERTIA`` Allows particles to have individual rotational inertia matrix eigenvalues.
When not built in, all eigenvalues are unity in simulation units.

- ``EXTERNAL_FORCES`` Allows to define an arbitrary constant force for each particle
individually. Also allows to fix individual coordinates of particles,
keep them at a fixed position or within a plane.

- ``MASS`` Allows particles to have individual masses. Note that some analysis
procedures have not yet been adapted to take the masses into account
correctly.
- ``MASS`` Allows particles to have individual masses.
When not built in, all masses are unity in simulation units.

.. seealso:: :attr:`espressomd.particle_data.ParticleHandle.mass`

Expand Down
2 changes: 1 addition & 1 deletion src/core/energy_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ inline double translational_kinetic_energy(Particle const &p) {
*/
inline double rotational_kinetic_energy(Particle const &p) {
#ifdef ROTATION
return p.can_rotate()
return (p.can_rotate() and not p.is_virtual())
? 0.5 * (hadamard_product(p.omega(), p.omega()) * p.rinertia())
: 0.0;
#else
Expand Down
19 changes: 18 additions & 1 deletion src/core/unit_tests/energy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define BOOST_TEST_MODULE tests
#define BOOST_TEST_MODULE energy calculation
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

Expand Down Expand Up @@ -69,6 +69,23 @@ BOOST_AUTO_TEST_CASE(rotational_kinetic_energy_) {
0.5 * (hadamard_product(p.omega(), p.omega()) * p.rinertia());
BOOST_CHECK_EQUAL(rotational_kinetic_energy(p), expected);
}

// virtual particle
{
#ifdef VIRTUAL_SITES

Particle p;
#ifdef ROTATIONAL_INERTIA
p.rinertia() = {1., 2., 3.};
#endif
p.set_virtual(true);
p.omega() = {3., 4., 5.};
p.set_can_rotate_all_axes();

auto const expected = 0.;
BOOST_CHECK_EQUAL(rotational_kinetic_energy(p), expected);
#endif
}
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/python/espressomd/particle_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class ParticleHandle(ScriptInterfaceHelper):
rinertia: (3,) array_like of :obj:`float`
The particle rotational inertia.
Sets the diagonal elements of this particles rotational inertia
Sets the diagonal elements of this particle's rotational inertia
tensor. These correspond with the inertial moments along the
coordinate axes in the particle's co-rotating coordinate system.
When the particle's quaternions are set to ``[1, 0, 0, 0,]``, the
Expand Down

0 comments on commit 504fd38

Please sign in to comment.