Move computeSlowForces into stepWork
authorBerk Hess <hess@kth.se>
Thu, 1 Oct 2020 12:02:27 +0000 (12:02 +0000)
committerPaul Bauer <paul.bauer.q@gmail.com>
Thu, 1 Oct 2020 12:02:27 +0000 (12:02 +0000)
Also moved a flag into forcerec and fixed documentation.

src/gromacs/fileio/readinp.cpp
src/gromacs/fileio/readinp.h
src/gromacs/gmxpreprocess/grompp.cpp
src/gromacs/gmxpreprocess/readir.cpp
src/gromacs/gmxpreprocess/readir.h
src/gromacs/gmxpreprocess/tests/readir.cpp

index 10797d31e79af884ba1e09ded56f919f888c25fb..5d497b8cd740c9a518dda0eb1eff25bbfb12770e 100644 (file)
@@ -554,8 +554,11 @@ void printStringNoNewline(std::vector<t_inpfile>* inp, const char* line)
     tmp.append(line);
     get_estr(inp, tmp.c_str(), nullptr);
 }
+
 void setStringEntry(std::vector<t_inpfile>* inp, const char* name, char* newName, const char* def)
 {
+    GMX_RELEASE_ASSERT(newName != nullptr, "Need a valid char buffer");
+
     const char* found = nullptr;
     found             = get_estr(inp, name, def);
     if (found != nullptr)
@@ -563,3 +566,10 @@ void setStringEntry(std::vector<t_inpfile>* inp, const char* name, char* newName
         std::strcpy(newName, found);
     }
 }
+
+std::string setStringEntry(std::vector<t_inpfile>* inp, const std::string& name, const std::string& def)
+{
+    GMX_RELEASE_ASSERT(!name.empty(), "Need a valid string");
+
+    return get_estr(inp, name.c_str(), def.c_str());
+}
index 4ae78cb21a4a88787523195fa433c7b661915cac..b730248664643c1f5ece4026fdd5710e1b0bff68 100644 (file)
@@ -167,4 +167,12 @@ void printStringNoNewline(std::vector<t_inpfile>* inp, const char* line);
 //! Replace for macro STYPE, checks for existing string entry and if possible replaces it
 void setStringEntry(std::vector<t_inpfile>* inp, const char* name, char* newName, const char* def);
 
+/*! Returns a string value and sets the value in \p inp
+ *
+ * The value is either from \p inp when \p name is found or \p def otherwise.
+ *
+ * \note this is a wrapper function for g_estr()
+ */
+std::string setStringEntry(std::vector<t_inpfile>* inp, const std::string& name, const std::string& def);
+
 #endif
index 6fb2264e27c665faf48d9a4ae58a0637e76ac885..6a20af125b0a1626c976586d1df61cec36014e69 100644 (file)
@@ -1762,7 +1762,6 @@ int gmx_grompp(int argc, char* argv[])
         "interpret the output messages before attempting to bypass them with",
         "this option."
     };
-    t_gromppopts*                        opts;
     std::vector<MoleculeInformation>     mi;
     std::unique_ptr<MoleculeInformation> intermolecular_interactions;
     int                                  nvsite, comb;
@@ -1832,10 +1831,10 @@ int gmx_grompp(int argc, char* argv[])
     gmx::MDModules mdModules;
     t_inputrec     irInstance;
     t_inputrec*    ir = &irInstance;
-    snew(opts, 1);
+    t_gromppopts   optsInstance;
+    t_gromppopts*  opts = &optsInstance;
     snew(opts->include, STRLEN);
     snew(opts->define, STRLEN);
-    snew(opts->mtsLevel2Forces, STRLEN);
 
     gmx::LoggerBuilder builder;
     builder.addTargetStream(gmx::MDLogger::LogLevel::Info, &gmx::TextOutputFile::standardOutput());
@@ -2390,8 +2389,6 @@ int gmx_grompp(int argc, char* argv[])
     sfree(opts->wall_atomtype[0]);
     sfree(opts->wall_atomtype[1]);
     sfree(opts->include);
-    sfree(opts->mtsLevel2Forces);
-    sfree(opts);
     for (auto& mol : mi)
     {
         // Some of the contents of molinfo have been stolen, so
index 835eb4c4c67eec0b7afff526d36664433236833f..ad5ee440ff32c9b9884b837cc718702d4d2cf2a6 100644 (file)
@@ -1980,9 +1980,9 @@ void get_ir(const char*     mdparin,
         opts->numMtsLevels = get_eint(&inp, "mts-levels", 2, wi);
         ir->mtsLevels.resize(2);
         gmx::MtsLevel& mtsLevel = ir->mtsLevels[1];
-        setStringEntry(&inp, "mts-level2-forces", opts->mtsLevel2Forces,
-                       "longrange-nonbonded nonbonded pair dihedral");
-        mtsLevel.stepFactor = get_eint(&inp, "mts-level2-factor", 2, wi);
+        opts->mtsLevel2Forces   = setStringEntry(&inp, "mts-level2-forces",
+                                               "longrange-nonbonded nonbonded pair dihedral");
+        mtsLevel.stepFactor     = get_eint(&inp, "mts-level2-factor", 2, wi);
 
         // We clear after reading without dynamics to not force the user to remove MTS mdp options
         if (!EI_DYNAMICS(ir->eI))
index a08b10810cb08fc6371cd14d0881ecf1e42faf80..c4f0434e435fad7100b8af67f8dbc3a8b700c709 100644 (file)
@@ -39,6 +39,8 @@
 #ifndef GMX_GMXPREPROCESS_READIR_H
 #define GMX_GMXPREPROCESS_READIR_H
 
+#include <string>
+
 #include "gromacs/fileio/readinp.h"
 #include "gromacs/math/vectypes.h"
 #include "gromacs/utility/real.h"
@@ -82,23 +84,23 @@ enum
 
 struct t_gromppopts
 {
-    int   warnings;
-    int   nshake;
-    char* include;
-    char* define;
-    bool  bGenVel;
-    bool  bGenPairs;
-    real  tempi;
-    int   seed;
-    int   numMtsLevels;
-    char* mtsLevel2Forces;
-    bool  bOrire;
-    bool  bMorse;
-    char* wall_atomtype[2];
-    char* couple_moltype;
-    int   couple_lam0;
-    int   couple_lam1;
-    bool  bCoupleIntra;
+    int         warnings     = 0;
+    int         nshake       = 0;
+    char*       include      = nullptr;
+    char*       define       = nullptr;
+    bool        bGenVel      = false;
+    bool        bGenPairs    = false;
+    real        tempi        = 0;
+    int         seed         = 0;
+    int         numMtsLevels = 0;
+    std::string mtsLevel2Forces;
+    bool        bOrire           = false;
+    bool        bMorse           = false;
+    char*       wall_atomtype[2] = { nullptr, nullptr };
+    char*       couple_moltype   = nullptr;
+    int         couple_lam0      = 0;
+    int         couple_lam1      = 0;
+    bool        bCoupleIntra     = false;
 };
 
 /*! \brief Initialise object to hold strings parsed from an .mdp file */
index 71771bcccb91c79a7cf599aaf7ca6b265e3a6c36..e2591c7392a193e6b3e28a3671d477882fda26da 100644 (file)
@@ -71,8 +71,7 @@ namespace test
 class GetIrTest : public ::testing::Test
 {
 public:
-    GetIrTest() : opts_(), wi_(init_warning(FALSE, 0)), wiGuard_(wi_)
-
+    GetIrTest() : wi_(init_warning(FALSE, 0)), wiGuard_(wi_)
     {
         snew(opts_.include, STRLEN);
         snew(opts_.define, STRLEN);