Skip to content

Commit

Permalink
Rewrite ParticleForce operator+ to improve performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoFrenner authored Jul 16, 2024
1 parent fe94b6a commit 25ecfd8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/core/Particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,17 @@ struct ParticleForce {

friend ParticleForce operator+(ParticleForce const &lhs,
ParticleForce const &rhs) {
#ifdef ROTATION
return {lhs.f + rhs.f, lhs.torque + rhs.torque};
#else
return lhs.f + rhs.f;
#endif
ParticleForce result = lhs;
result += rhs;
return result;
}

ParticleForce &operator+=(ParticleForce const &rhs) {
return *this = *this + rhs;
f += rhs.f;
#ifdef ROTATION
torque += rhs.torque;
#endif
return *this;
}

/** force. */
Expand Down

0 comments on commit 25ecfd8

Please sign in to comment.