Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
### Bug Fixes

- Eigen version finally fixed to 5.0.0 (latest aka master broken on 28.09.25)
- Fix problems with convergence and indices in MShake

<!-- insertion marker -->
## [v0.6.2](https://github.com/MolarVerse/PQ/releases/tag/v0.6.2) - 2025-08-22
Expand Down
2 changes: 1 addition & 1 deletion include/constraints/mShake.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace constraints

void initMShake();
void initMShakeReferences();
void applyMShake(const double, pq::SimBox &);
void applyMShake(const double, const size_t, pq::SimBox &);
void applyMRattle(pq::SimBox &);

[[nodiscard]] size_t calcNumberOfMShakeMolecules(pq::SimBox &) const;
Expand Down
2 changes: 1 addition & 1 deletion src/constraints/constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void Constraints::_applyShake(SimulationBox &simBox)
void Constraints::_applyMShake(SimulationBox &simulationBox)
{
startTimingsSection("MShake - Shake");
_mShake.applyMShake(_shakeTolerance, simulationBox);
_mShake.applyMShake(_shakeTolerance, _shakeMaxIter, simulationBox);
stopTimingsSection("MShake - Shake");
}

Expand Down
21 changes: 18 additions & 3 deletions src/constraints/mShake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void MShake::initMShakeReferences()
* @param simBox
*
*/
void MShake::applyMShake(const double shakeTolerance, SimulationBox &simBox)
void MShake::applyMShake(const double shakeTolerance, const size_t shakeIterations, SimulationBox &simBox)
{
auto &molecules = simBox.getMolecules();

Expand Down Expand Up @@ -212,11 +212,15 @@ void MShake::applyMShake(const double shakeTolerance, SimulationBox &simBox)
++index_ij;
}

size_t iteration = 0;

while (true)
{
auto converged = true;
index_ij = 0;

iteration++;

/*****************************************
* fill (nBonds x nBonds) m-Shake matrix *
*****************************************/
Expand All @@ -232,7 +236,7 @@ void MShake::applyMShake(const double shakeTolerance, SimulationBox &simBox)

for (size_t k = 0; k < nAtoms - 1; ++k)
{
for (size_t l = 0; l < nAtoms - 1; ++l)
for (size_t l = k + 1; l < nAtoms; ++l)
{
const auto mShakeElement = calcMatrixElement(
{i, j, k, l},
Expand Down Expand Up @@ -331,8 +335,19 @@ void MShake::applyMShake(const double shakeTolerance, SimulationBox &simBox)
}
}

if (!converged)
if (converged)
break;

if (iteration >= shakeIterations)
{
throw customException::MShakeException(
std::format(
"M-Shake did not converge within {} iterations for molecule type {}",
shakeIterations,
moltype
)
);
}
}

for (size_t i = 0; i < nAtoms; ++i)
Expand Down
Loading