From 41d62b8b8b6bfa66ccc436090628f8b6491fa706 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 26 Jun 2020 16:02:14 -0400 Subject: [PATCH] update temp and press compute creation in temperature and similar fixes --- src/fix_box_relax.cpp | 34 ++++++++++++---------------------- src/fix_nph.cpp | 33 +++++++++++---------------------- src/fix_nph_sphere.cpp | 33 +++++++++++---------------------- src/fix_npt.cpp | 33 +++++++++++---------------------- src/fix_npt_sphere.cpp | 33 +++++++++++---------------------- src/fix_nvt.cpp | 18 +++++++----------- src/fix_nvt_sllod.cpp | 17 ++++++----------- src/fix_nvt_sphere.cpp | 17 ++++++----------- src/fix_temp_berendsen.cpp | 3 ++- src/fix_temp_csld.cpp | 3 ++- src/fix_temp_csvr.cpp | 3 ++- 11 files changed, 81 insertions(+), 146 deletions(-) diff --git a/src/fix_box_relax.cpp b/src/fix_box_relax.cpp index 8d6111c0a0..832799831e 100644 --- a/src/fix_box_relax.cpp +++ b/src/fix_box_relax.cpp @@ -18,6 +18,7 @@ #include "fix_box_relax.h" #include #include +#include #include "atom.h" #include "domain.h" #include "update.h" @@ -28,6 +29,7 @@ #include "compute.h" #include "error.h" #include "math_extra.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -317,36 +319,24 @@ FixBoxRelax::FixBoxRelax(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + tcmd += " all temp"; + modify->add_compute(tcmd); tflag = 1; // create a new compute pressure style (virial only) // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[5]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - newarg[4] = (char *) "virial"; - modify->add_compute(5,newarg); - delete [] newarg; + pcmd += " all pressure " + std::string(id_temp) + " virial"; + modify->add_compute(pcmd); pflag = 1; dimension = domain->dimension; diff --git a/src/fix_nph.cpp b/src/fix_nph.cpp index 7148b024de..9251ce384e 100644 --- a/src/fix_nph.cpp +++ b/src/fix_nph.cpp @@ -13,6 +13,7 @@ #include "fix_nph.h" #include +#include #include "modify.h" #include "error.h" @@ -34,35 +35,23 @@ FixNPH::FixNPH(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + tcmd += " all temp"; + modify->add_compute(tcmd); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + pcmd += " all pressure " + std::string(id_temp); + modify->add_compute(pcmd); pcomputeflag = 1; } diff --git a/src/fix_nph_sphere.cpp b/src/fix_nph_sphere.cpp index f64f144f34..25cff4a645 100644 --- a/src/fix_nph_sphere.cpp +++ b/src/fix_nph_sphere.cpp @@ -13,6 +13,7 @@ #include "fix_nph_sphere.h" #include +#include #include "modify.h" #include "error.h" @@ -34,35 +35,23 @@ FixNPHSphere::FixNPHSphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/sphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + tcmd += " all temp/sphere"; + modify->add_compute(tcmd); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + pcmd += " all pressure " + std::string(id_temp); + modify->add_compute(pcmd); pcomputeflag = 1; } diff --git a/src/fix_npt.cpp b/src/fix_npt.cpp index e856fafe2d..6949ead1d6 100644 --- a/src/fix_npt.cpp +++ b/src/fix_npt.cpp @@ -13,6 +13,7 @@ #include "fix_npt.h" #include +#include #include "modify.h" #include "error.h" @@ -34,35 +35,23 @@ FixNPT::FixNPT(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + tcmd += " all temp"; + modify->add_compute(tcmd); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + pcmd += " all pressure " + std::string(id_temp); + modify->add_compute(pcmd); pcomputeflag = 1; } diff --git a/src/fix_npt_sphere.cpp b/src/fix_npt_sphere.cpp index 9cbb17b0ca..d1ff82baba 100644 --- a/src/fix_npt_sphere.cpp +++ b/src/fix_npt_sphere.cpp @@ -13,6 +13,7 @@ #include "fix_npt_sphere.h" #include +#include #include "modify.h" #include "error.h" @@ -34,35 +35,23 @@ FixNPTSphere::FixNPTSphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/sphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + tcmd += " all temp/sphere"; + modify->add_compute(tcmd); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + pcmd += " all pressure " + std::string(id_temp); + modify->add_compute(pcmd); pcomputeflag = 1; } diff --git a/src/fix_nvt.cpp b/src/fix_nvt.cpp index 6f0d4c6c50..7868693b69 100644 --- a/src/fix_nvt.cpp +++ b/src/fix_nvt.cpp @@ -13,9 +13,11 @@ #include "fix_nvt.h" #include +#include #include "group.h" #include "modify.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -33,17 +35,11 @@ FixNVT::FixNVT(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + tcmd += fmt::format(" {} temp",group->names[igroup]); + modify->add_compute(tcmd); tcomputeflag = 1; } diff --git a/src/fix_nvt_sllod.cpp b/src/fix_nvt_sllod.cpp index 138794862a..ccf7aaecaf 100644 --- a/src/fix_nvt_sllod.cpp +++ b/src/fix_nvt_sllod.cpp @@ -26,6 +26,7 @@ #include "fix_deform.h" #include "compute.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -48,18 +49,12 @@ FixNVTSllod::FixNVTSllod(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string cmd = id + std::string("_temp"); + id_temp = new char[cmd.size()+1]; + strcpy(id_temp,cmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/deform"; - - modify->add_compute(3,newarg); - delete [] newarg; + cmd += fmt::format(" {} temp/deform",group->names[igroup]); + modify->add_compute(cmd); tcomputeflag = 1; } diff --git a/src/fix_nvt_sphere.cpp b/src/fix_nvt_sphere.cpp index fed3799011..8773721850 100644 --- a/src/fix_nvt_sphere.cpp +++ b/src/fix_nvt_sphere.cpp @@ -16,6 +16,7 @@ #include "group.h" #include "modify.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -33,17 +34,11 @@ FixNVTSphere::FixNVTSphere(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string cmd = id + std::string("_temp"); + id_temp = new char[cmd.size()+1]; + strcpy(id_temp,cmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/sphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + cmd += fmt::format(" {} temp/sphere",group->names[igroup]); + modify->add_compute(cmd); tcomputeflag = 1; } diff --git a/src/fix_temp_berendsen.cpp b/src/fix_temp_berendsen.cpp index 2f687aeecf..9b385bf96c 100644 --- a/src/fix_temp_berendsen.cpp +++ b/src/fix_temp_berendsen.cpp @@ -25,6 +25,7 @@ #include "modify.h" #include "compute.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -75,7 +76,7 @@ FixTempBerendsen::FixTempBerendsen(LAMMPS *lmp, int narg, char **arg) : id_temp = new char[cmd.size()+1]; strcpy(id_temp,cmd.c_str()); - cmd += group->names[igroup] + std::string(" temp"); + cmd += fmt::format(" {} temp",group->names[igroup]); modify->add_compute(cmd); tflag = 1; diff --git a/src/fix_temp_csld.cpp b/src/fix_temp_csld.cpp index 715d9a8692..f83d593c96 100644 --- a/src/fix_temp_csld.cpp +++ b/src/fix_temp_csld.cpp @@ -31,6 +31,7 @@ #include "compute.h" #include "random_mars.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -84,7 +85,7 @@ FixTempCSLD::FixTempCSLD(LAMMPS *lmp, int narg, char **arg) : id_temp = new char[cmd.size()+1]; strcpy(id_temp,cmd.c_str()); - cmd += group->names[igroup] + std::string(" temp"); + cmd += fmt::format(" {} temp",group->names[igroup]); modify->add_compute(cmd); tflag = 1; diff --git a/src/fix_temp_csvr.cpp b/src/fix_temp_csvr.cpp index aabdcf2bc3..cca204a4b2 100644 --- a/src/fix_temp_csvr.cpp +++ b/src/fix_temp_csvr.cpp @@ -32,6 +32,7 @@ #include "compute.h" #include "random_mars.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -161,7 +162,7 @@ FixTempCSVR::FixTempCSVR(LAMMPS *lmp, int narg, char **arg) : id_temp = new char[cmd.size()+1]; strcpy(id_temp,cmd.c_str()); - cmd += group->names[igroup] + std::string(" temp"); + cmd += fmt::format(" {} temp",group->names[igroup]); modify->add_compute(cmd); tflag = 1;