make more use of std::string and fmtlib where beneficial
This commit is contained in:
@ -18,6 +18,7 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "tokenizer.h"
|
#include "tokenizer.h"
|
||||||
|
#include "fmt/format.h"
|
||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
|
|
||||||
@ -215,12 +216,9 @@ void AtomVecHybrid::process_args(int narg, char **arg)
|
|||||||
for (int idup = 0; idup < ndupfield; idup++) {
|
for (int idup = 0; idup < ndupfield; idup++) {
|
||||||
char *dup = (char *) dupfield[idup];
|
char *dup = (char *) dupfield[idup];
|
||||||
ptr = strstr(concat_grow,dup);
|
ptr = strstr(concat_grow,dup);
|
||||||
if (ptr && strstr(ptr+1,dup)) {
|
if ((ptr && strstr(ptr+1,dup)) && (comm->me == 0))
|
||||||
char str[128];
|
error->warning(FLERR,fmt::format("Peratom {} is in multiple sub-styles "
|
||||||
sprintf(str,"Peratom %s is in multiple sub-styles - "
|
"- must be used consistently",dup));
|
||||||
"must be used consistently",dup);
|
|
||||||
if (comm->me == 0) error->warning(FLERR,str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] concat_grow;
|
delete [] concat_grow;
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
#include "comm.h"
|
#include "comm.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "fmt/format.h"
|
||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
|
|
||||||
@ -184,11 +185,9 @@ void ComputeCNAAtom::compute_peratom()
|
|||||||
|
|
||||||
int nerrorall;
|
int nerrorall;
|
||||||
MPI_Allreduce(&nerror,&nerrorall,1,MPI_INT,MPI_SUM,world);
|
MPI_Allreduce(&nerror,&nerrorall,1,MPI_INT,MPI_SUM,world);
|
||||||
if (nerrorall && comm->me == 0) {
|
if (nerrorall && comm->me == 0)
|
||||||
char str[128];
|
error->warning(FLERR,fmt::format("Too many neighbors in CNA for {} "
|
||||||
sprintf(str,"Too many neighbors in CNA for %d atoms",nerrorall);
|
"atoms",nerrorall),0);
|
||||||
error->warning(FLERR,str,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// compute CNA for each atom in group
|
// compute CNA for each atom in group
|
||||||
// only performed if # of nearest neighbors = 12 or 14 (fcc,hcp)
|
// only performed if # of nearest neighbors = 12 or 14 (fcc,hcp)
|
||||||
@ -345,11 +344,9 @@ void ComputeCNAAtom::compute_peratom()
|
|||||||
// warning message
|
// warning message
|
||||||
|
|
||||||
MPI_Allreduce(&nerror,&nerrorall,1,MPI_INT,MPI_SUM,world);
|
MPI_Allreduce(&nerror,&nerrorall,1,MPI_INT,MPI_SUM,world);
|
||||||
if (nerrorall && comm->me == 0) {
|
if (nerrorall && comm->me == 0)
|
||||||
char str[128];
|
error->warning(FLERR,fmt::format("Too many common neighbors in CNA {} "
|
||||||
sprintf(str,"Too many common neighbors in CNA %d times",nerrorall);
|
"times", nerrorall));
|
||||||
error->warning(FLERR,str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
|
|||||||
@ -147,12 +147,9 @@ void ComputeGroupGroup::init()
|
|||||||
|
|
||||||
if (kspaceflag) {
|
if (kspaceflag) {
|
||||||
kspace_correction();
|
kspace_correction();
|
||||||
if (fabs(e_correction) > SMALL && comm->me == 0) {
|
if ((fabs(e_correction) > SMALL) && (comm->me == 0))
|
||||||
char str[128];
|
error->warning(FLERR,"Both groups in compute group/group have a net charge; "
|
||||||
sprintf(str,"Both groups in compute group/group have a net charge; "
|
"the Kspace boundary correction to energy will be non-zero");
|
||||||
"the Kspace boundary correction to energy will be non-zero");
|
|
||||||
error->warning(FLERR,str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// recheck that group 2 has not been deleted
|
// recheck that group 2 has not been deleted
|
||||||
|
|||||||
@ -32,6 +32,7 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "math_const.h"
|
#include "math_const.h"
|
||||||
|
#include "fmt/format.h"
|
||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
using namespace MathConst;
|
using namespace MathConst;
|
||||||
@ -715,11 +716,8 @@ void ComputeOrientOrderAtom::init_clebsch_gordan()
|
|||||||
|
|
||||||
double ComputeOrientOrderAtom::factorial(int n)
|
double ComputeOrientOrderAtom::factorial(int n)
|
||||||
{
|
{
|
||||||
if (n < 0 || n > nmaxfactorial) {
|
if (n < 0 || n > nmaxfactorial)
|
||||||
char str[128];
|
error->all(FLERR,fmt::format("Invalid argument to factorial {}", n));
|
||||||
sprintf(str, "Invalid argument to factorial %d", n);
|
|
||||||
error->all(FLERR, str);
|
|
||||||
}
|
|
||||||
|
|
||||||
return nfac_table[n];
|
return nfac_table[n];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
#include "comm.h"
|
#include "comm.h"
|
||||||
#include "force.h"
|
#include "force.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "fmt/format.h"
|
||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
|
|
||||||
@ -58,11 +59,9 @@ void DumpMovie::openfile()
|
|||||||
fp = popen(moviecmd,"w");
|
fp = popen(moviecmd,"w");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL)
|
||||||
char str[128];
|
error->one(FLERR,fmt::format("Failed to open FFmpeg pipeline to "
|
||||||
sprintf(str,"Failed to open FFmpeg pipeline to file %s",filename);
|
"file {}",filename));
|
||||||
error->one(FLERR,str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
#include "update.h"
|
#include "update.h"
|
||||||
#include "force.h"
|
#include "force.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
@ -25,6 +26,7 @@
|
|||||||
#include "comm.h"
|
#include "comm.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "fmt/format.h"
|
||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
using namespace FixConst;
|
using namespace FixConst;
|
||||||
@ -224,15 +226,13 @@ void FixHalt::end_of_step()
|
|||||||
// soft/continue halt -> trigger timer to break from run loop
|
// soft/continue halt -> trigger timer to break from run loop
|
||||||
// print message with ID of fix halt in case multiple instances
|
// print message with ID of fix halt in case multiple instances
|
||||||
|
|
||||||
char str[128];
|
std::string message = fmt::format("Fix halt condition for fix-id {} met on "
|
||||||
sprintf(str,"Fix halt condition for fix-id %s met on step "
|
"step {} with value {}",
|
||||||
BIGINT_FORMAT " with value %g",
|
id, update->ntimestep, attvalue);
|
||||||
id, update->ntimestep, attvalue);
|
|
||||||
|
|
||||||
if (eflag == HARD) {
|
if (eflag == HARD) {
|
||||||
error->all(FLERR,str);
|
error->all(FLERR,message);
|
||||||
} else if (eflag == SOFT || eflag == CONTINUE) {
|
} else if (eflag == SOFT || eflag == CONTINUE) {
|
||||||
if (comm->me == 0 && msgflag == YESMSG) error->message(FLERR,str);
|
if (comm->me == 0 && msgflag == YESMSG) error->message(FLERR,message);
|
||||||
timer->force_timeout();
|
timer->force_timeout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "domain.h"
|
#include "domain.h"
|
||||||
#include "atom.h"
|
#include "atom.h"
|
||||||
@ -32,6 +33,7 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "fmt/format.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@ -123,11 +125,9 @@ void Group::assign(int narg, char **arg)
|
|||||||
for (i = 0; i < nlocal; i++) mask[i] &= bits;
|
for (i = 0; i < nlocal; i++) mask[i] &= bits;
|
||||||
|
|
||||||
if (dynamic[igroup]) {
|
if (dynamic[igroup]) {
|
||||||
int n = strlen("GROUP_") + strlen(names[igroup]) + 1;
|
std::string fixID = "GROUP_";
|
||||||
char *fixID = new char[n];
|
fixID += names[igroup];
|
||||||
sprintf(fixID,"GROUP_%s",names[igroup]);
|
modify->delete_fix(fixID.c_str());
|
||||||
modify->delete_fix(fixID);
|
|
||||||
delete [] fixID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] names[igroup];
|
delete [] names[igroup];
|
||||||
@ -492,27 +492,23 @@ void Group::assign(int narg, char **arg)
|
|||||||
// if group is already dynamic, delete existing FixGroup
|
// if group is already dynamic, delete existing FixGroup
|
||||||
|
|
||||||
if (dynamic[igroup]) {
|
if (dynamic[igroup]) {
|
||||||
int n = strlen("GROUP_") + strlen(names[igroup]) + 1;
|
std::string fixID = "GROUP_";
|
||||||
char *fixID = new char[n];
|
fixID += names[igroup];
|
||||||
sprintf(fixID,"GROUP_%s",names[igroup]);
|
modify->delete_fix(fixID.c_str());
|
||||||
modify->delete_fix(fixID);
|
|
||||||
delete [] fixID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamic[igroup] = 1;
|
dynamic[igroup] = 1;
|
||||||
|
|
||||||
int n = strlen("GROUP_") + strlen(names[igroup]) + 1;
|
std::string fixID = "GROUP_";
|
||||||
char *fixID = new char[n];
|
fixID += names[igroup];
|
||||||
sprintf(fixID,"GROUP_%s",names[igroup]);
|
|
||||||
|
|
||||||
char **newarg = new char*[narg];
|
char **newarg = new char*[narg];
|
||||||
newarg[0] = fixID;
|
newarg[0] = (char *)fixID.c_str();
|
||||||
newarg[1] = arg[2];
|
newarg[1] = arg[2];
|
||||||
newarg[2] = (char *) "GROUP";
|
newarg[2] = (char *) "GROUP";
|
||||||
for (int i = 3; i < narg; i++) newarg[i] = arg[i];
|
for (int i = 3; i < narg; i++) newarg[i] = arg[i];
|
||||||
modify->add_fix(narg,newarg);
|
modify->add_fix(narg,newarg);
|
||||||
delete [] newarg;
|
delete [] newarg;
|
||||||
delete [] fixID;
|
|
||||||
|
|
||||||
// style = static
|
// style = static
|
||||||
// remove dynamic FixGroup if necessary
|
// remove dynamic FixGroup if necessary
|
||||||
@ -522,11 +518,9 @@ void Group::assign(int narg, char **arg)
|
|||||||
if (narg != 2) error->all(FLERR,"Illegal group command");
|
if (narg != 2) error->all(FLERR,"Illegal group command");
|
||||||
|
|
||||||
if (dynamic[igroup]) {
|
if (dynamic[igroup]) {
|
||||||
int n = strlen("GROUP_") + strlen(names[igroup]) + 1;
|
std::string fixID = "GROUP_";
|
||||||
char *fixID = new char[n];
|
fixID += names[igroup];
|
||||||
sprintf(fixID,"GROUP_%s",names[igroup]);
|
modify->delete_fix(fixID.c_str());
|
||||||
modify->delete_fix(fixID);
|
|
||||||
delete [] fixID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamic[igroup] = 0;
|
dynamic[igroup] = 0;
|
||||||
@ -546,15 +540,10 @@ void Group::assign(int narg, char **arg)
|
|||||||
MPI_Allreduce(&rlocal,&all,1,MPI_DOUBLE,MPI_SUM,world);
|
MPI_Allreduce(&rlocal,&all,1,MPI_DOUBLE,MPI_SUM,world);
|
||||||
|
|
||||||
if (me == 0) {
|
if (me == 0) {
|
||||||
if (dynamic[igroup]) {
|
if (dynamic[igroup])
|
||||||
if (screen) fprintf(screen,"dynamic group %s defined\n",names[igroup]);
|
utils::logmesg(lmp,fmt::format("dynamic group {} defined\n",names[igroup]));
|
||||||
if (logfile) fprintf(logfile,"dynamic group %s defined\n",names[igroup]);
|
else
|
||||||
} else {
|
utils::logmesg(lmp,fmt::format("{:.15g} atoms in group {}\n",all,names[igroup]));
|
||||||
if (screen)
|
|
||||||
fprintf(screen,"%.15g atoms in group %s\n",all,names[igroup]);
|
|
||||||
if (logfile)
|
|
||||||
fprintf(logfile,"%.15g atoms in group %s\n",all,names[igroup]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user