Properly initialize idef in topologies
[alexxy/gromacs.git] / src / gromacs / topology / idef.cpp
index 2274ef87fcdbef1510add66e35d6a01a62bd2fd6..5739cacef04a902c24d2bd984f6823edf3e0ad79 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "gromacs/topology/ifunc.h"
 #include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/txtdump.h"
 
 static void pr_harm(FILE *fp, const t_iparams *iparams, const char *r, const char *kr)
@@ -450,3 +451,40 @@ void pr_idef(FILE *fp, int indent, const char *title, const t_idef *idef,
         }
     }
 }
+
+void init_idef(t_idef *idef)
+{
+    idef->ntypes           = 0;
+    idef->atnr             = 0;
+    idef->functype         = nullptr;
+    idef->iparams          = nullptr;
+    idef->fudgeQQ          = 0.0;
+    idef->iparams_posres   = nullptr;
+    idef->iparams_fbposres = nullptr;
+    for (int f = 0; f < F_NRE; ++f)
+    {
+        idef->il[f].iatoms          = nullptr;
+        idef->il[f].nalloc          = 0;
+        idef->il[f].nr              = 0;
+        idef->il[f].nr_nonperturbed = 0;
+    }
+    idef->cmap_grid.cmapdata      = nullptr;
+    idef->iparams_posres_nalloc   = 0;
+    idef->iparams_fbposres_nalloc = 0;
+    idef->ilsort                  = 0;
+}
+
+void done_idef(t_idef *idef)
+{
+    sfree(idef->functype);
+    sfree(idef->iparams);
+    sfree(idef->iparams_posres);
+    sfree(idef->iparams_fbposres);
+    for (int f = 0; f < F_NRE; ++f)
+    {
+        sfree(idef->il[f].iatoms);
+    }
+
+    sfree(idef->cmap_grid.cmapdata);
+    init_idef(idef);
+}