:issue:`2813`
+Fix segmentation fault with energy minimization with the group scheme
+---------------------------------------------------------------------
+
+Using energy minimization in combination with the group cutoff scheme
+and domain decomposition could lead to a segmentation fault.
+
+:issue:`2813`
+
Fix possible division by zero in enforced-rotation code
-------------------------------------------------------
const int movedValue = NSGRID_SIGNAL_MOVED_FAC*fr->ns->grid->ncells;
- if (ncg_home_old >= 0)
+ if (ncg_home_old >= 0 && !sort->sorted.empty())
{
+ GMX_RELEASE_ASSERT(sort->sorted.size() == static_cast<size_t>(ncg_home_old),
+ "The sorting buffer should contain the old home charge group indices");
+
std::vector<gmx_cgsort_t> &stationary = sort->stationary;
std::vector<gmx_cgsort_t> &moved = sort->moved;
wallcycle_sub_stop(wcycle, ewcsDD_GRID);
}
+ else
+ {
+ /* With the group scheme the sorting array is part of the DD state,
+ * but it just got out of sync, so mark as invalid by emptying it.
+ */
+ if (ir->cutoff_scheme == ecutsGROUP)
+ {
+ comm->sort->sorted.clear();
+ }
+ }
if (comm->useUpdateGroups)
{