use portable functions from platform and utils namespaces

This commit is contained in:
Axel Kohlmeyer
2021-10-07 12:22:16 -04:00
parent c8ff66e07f
commit a818be585d
6 changed files with 49 additions and 58 deletions

View File

@ -303,7 +303,7 @@ FixColvars::FixColvars(LAMMPS *lmp, int narg, char **arg) :
me = comm->me;
root2root = MPI_COMM_NULL;
conf_file = strdup(arg[3]);
conf_file = utils::strdup(arg[3]);
rng_seed = 1966;
unwrap_flag = 1;
@ -319,22 +319,22 @@ FixColvars::FixColvars(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR,"Missing argument to keyword");
if (0 == strcmp(arg[iarg], "input")) {
inp_name = strdup(arg[iarg+1]);
inp_name = utils::strdup(arg[iarg+1]);
} else if (0 == strcmp(arg[iarg], "output")) {
out_name = strdup(arg[iarg+1]);
out_name = utils::strdup(arg[iarg+1]);
} else if (0 == strcmp(arg[iarg], "seed")) {
rng_seed = utils::inumeric(FLERR,arg[iarg+1],false,lmp);
} else if (0 == strcmp(arg[iarg], "unwrap")) {
unwrap_flag = utils::logical(FLERR,arg[iarg+1],false,lmp);
} else if (0 == strcmp(arg[iarg], "tstat")) {
tmp_name = strdup(arg[iarg+1]);
tmp_name = utils::strdup(arg[iarg+1]);
} else {
error->all(FLERR,"Unknown fix colvars parameter");
}
++iarg; ++iarg;
}
if (!out_name) out_name = strdup("out");
if (!out_name) out_name = utils::strdup("out");
/* initialize various state variables. */
tstat_id = -1;
@ -359,10 +359,10 @@ FixColvars::FixColvars(LAMMPS *lmp, int narg, char **arg) :
FixColvars::~FixColvars()
{
memory->sfree(conf_file);
memory->sfree(inp_name);
memory->sfree(out_name);
memory->sfree(tmp_name);
delete[] conf_file;
delete[] inp_name;
delete[] out_name;
delete[] tmp_name;
memory->sfree(comm_buf);
if (proxy) {
@ -430,17 +430,15 @@ void FixColvars::one_time_init()
// create and initialize the colvars proxy
if (me == 0) {
if (screen) fputs("colvars: Creating proxy instance\n",screen);
if (logfile) fputs("colvars: Creating proxy instance\n",logfile);
utils::logmesg(lmp,"colvars: Creating proxy instance\n");
#ifdef LAMMPS_BIGBIG
if (screen) fputs("colvars: cannot handle atom ids > 2147483647\n",screen);
if (logfile) fputs("colvars: cannot handle atom ids > 2147483647\n",logfile);
utils::logmesg(lmp,"colvars: cannot handle atom ids > 2147483647\n");
#endif
if (inp_name) {
if (strcmp(inp_name,"NULL") == 0) {
memory->sfree(inp_name);
delete[] inp_name;
inp_name = nullptr;
}
}
@ -458,8 +456,7 @@ void FixColvars::one_time_init()
}
}
proxy = new colvarproxy_lammps(lmp,inp_name,out_name,
rng_seed,t_target,root2root);
proxy = new colvarproxy_lammps(lmp,inp_name,out_name,rng_seed,t_target,root2root);
proxy->init(conf_file);
num_coords = (proxy->modify_atom_positions()->size());

View File

@ -19,19 +19,19 @@
#include "pair_mdpd.h"
#include "atom.h"
#include "citeme.h"
#include "comm.h"
#include "error.h"
#include "force.h"
#include "memory.h"
#include "neigh_list.h"
#include "neighbor.h"
#include "random_mars.h"
#include "update.h"
#include <cmath>
#include <ctime>
#include "atom.h"
#include "comm.h"
#include "update.h"
#include "force.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "random_mars.h"
#include "citeme.h"
#include "memory.h"
#include "error.h"
using namespace LAMMPS_NS;
@ -218,11 +218,9 @@ void PairMDPD::settings(int narg, char **arg)
// initialize Marsaglia RNG with processor-unique seed
if (seed <= 0) {
struct timespec time;
clock_gettime( CLOCK_REALTIME, &time );
seed = time.tv_nsec; // if seed is non-positive, get the current time as the seed
}
if (seed <= 0)
seed = (int) (platform::walltime() * 1073741824.0);
delete random;
random = new RanMars(lmp,(seed + comm->me) % 900000000);

View File

@ -18,19 +18,19 @@
------------------------------------------------------------------------- */
#include "pair_tdpd.h"
#include <cmath>
#include <ctime>
#include "atom.h"
#include "comm.h"
#include "update.h"
#include "force.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "random_mars.h"
#include "citeme.h"
#include "memory.h"
#include "error.h"
#include "atom.h"
#include "citeme.h"
#include "comm.h"
#include "error.h"
#include "force.h"
#include "memory.h"
#include "neigh_list.h"
#include "neighbor.h"
#include "random_mars.h"
#include "update.h"
#include <cmath>
using namespace LAMMPS_NS;
@ -240,11 +240,9 @@ void PairTDPD::settings(int narg, char **arg)
// initialize Marsaglia RNG with processor-unique seed
if (seed <= 0) {
struct timespec time;
clock_gettime( CLOCK_REALTIME, &time );
seed = time.tv_nsec; // if seed is non-positive, get the current time as the seed
}
if (seed <= 0)
seed = (int) (platform::walltime() * 1073741824.0);
delete random;
random = new RanMars(lmp,(seed + comm->me) % 900000000);

View File

@ -495,7 +495,7 @@ void FixTMD::readfile(char *file)
delete [] buffer;
if (me == 0) {
if (compressed) pclose(fp);
if (compressed) platform::pclose(fp);
else fclose(fp);
}

View File

@ -32,7 +32,6 @@
#include "text_file_reader.h"
#include "utils.h"
#include <cctype>
#include <cmath>
#include <cstring>
#include <exception>
@ -161,11 +160,10 @@ namespace ReaxFF {
if (values.count() < 9)
THROW_ERROR("Invalid force field file format");
auto element = values.next_string();
int len = MIN(element.size(),3); // truncate stored element symbol if necessary
for (j = 0; j < len; ++j)
sbp[i].name[j] = toupper(element[j]);
sbp[i].name[len] = '\0';
// copy element symbol in uppercase and truncate stored element symbol if necessary
auto element = utils::uppercase(values.next_string());
strncpy(sbp[i].name,element.c_str(),4);
sbp[i].name[4] = '\0';
sbp[i].r_s = values.next_double();
sbp[i].valency = values.next_double();

View File

@ -528,12 +528,12 @@ void NEB::readfile(char *file, int flag)
if (flag == 0) {
if (me_universe == 0) {
if (compressed) pclose(fp);
if (compressed) platform::pclose(fp);
else fclose(fp);
}
} else {
if (me == 0 && ireplica) {
if (compressed) pclose(fp);
if (compressed) platform::pclose(fp);
else fclose(fp);
}
}