+/* This routine is very similar to add_ifunc, but vsites interactions
+ * have more work to do than other kinds of interactions, and the
+ * complex way nral (and thus vector contents) depends on ftype
+ * confuses static analysis tools unless we fuse the vsite
+ * atom-indexing organization code with the ifunc-adding code, so that
+ * they can see that nral is the same value. */
+static gmx_inline void
+add_ifunc_for_vsites(t_iatom *tiatoms, gmx_ga2la_t ga2la,
+ int nral, gmx_bool bHomeA,
+ int a, int a_gl, int a_mol,
+ const t_iatom *iatoms,
+ t_ilist *il)
+{
+ t_iatom *liatoms;
+
+ if (il->nr+1+nral > il->nalloc)
+ {
+ il->nalloc = over_alloc_large(il->nr+1+nral);
+ srenew(il->iatoms, il->nalloc);
+ }
+ liatoms = il->iatoms + il->nr;
+ il->nr += 1 + nral;
+
+ /* Copy the type */
+ tiatoms[0] = iatoms[0];
+
+ if (bHomeA)
+ {
+ /* We know the local index of the first atom */
+ tiatoms[1] = a;
+ }
+ else
+ {
+ /* Convert later in make_local_vsites */
+ tiatoms[1] = -a_gl - 1;
+ }
+
+ for (int k = 2; k < 1+nral; k++)
+ {
+ int ak_gl = a_gl + iatoms[k] - a_mol;
+ if (!ga2la_get_home(ga2la, ak_gl, &tiatoms[k]))
+ {
+ /* Copy the global index, convert later in make_local_vsites */
+ tiatoms[k] = -(ak_gl + 1);
+ }
+ // Note that ga2la_get_home always sets the third parameter if
+ // it returns TRUE
+ }
+ for (int k = 0; k < 1+nral; k++)
+ {
+ liatoms[k] = tiatoms[k];
+ }
+}
+