simplify code by appling varargs messages and warnings

This commit is contained in:
Axel Kohlmeyer
2021-05-05 18:19:12 -04:00
parent 8fd0595f1b
commit 22e93468d6
48 changed files with 162 additions and 181 deletions

View File

@ -72,7 +72,7 @@ void DumpAtomGZ::openfile()
++numfiles;
} else {
if (remove(nameslist[fileidx]) != 0) {
error->warning(FLERR, fmt::format("Could not delete {}", nameslist[fileidx]));
error->warning(FLERR, "Could not delete {}", nameslist[fileidx]);
}
delete[] nameslist[fileidx];
nameslist[fileidx] = utils::strdup(filecurrent);

View File

@ -80,7 +80,7 @@ void DumpAtomZstd::openfile()
++numfiles;
} else {
if (remove(nameslist[fileidx]) != 0) {
error->warning(FLERR, fmt::format("Could not delete {}", nameslist[fileidx]));
error->warning(FLERR, "Could not delete {}", nameslist[fileidx]);
}
delete[] nameslist[fileidx];
nameslist[fileidx] = utils::strdup(filecurrent);

View File

@ -74,7 +74,7 @@ void DumpCFGGZ::openfile()
++numfiles;
} else {
if (remove(nameslist[fileidx]) != 0) {
error->warning(FLERR, fmt::format("Could not delete {}", nameslist[fileidx]));
error->warning(FLERR, "Could not delete {}", nameslist[fileidx]);
}
delete[] nameslist[fileidx];
nameslist[fileidx] = utils::strdup(filecurrent);

View File

@ -82,7 +82,7 @@ void DumpCFGZstd::openfile()
++numfiles;
} else {
if (remove(nameslist[fileidx]) != 0) {
error->warning(FLERR, fmt::format("Could not delete {}", nameslist[fileidx]));
error->warning(FLERR, "Could not delete {}", nameslist[fileidx]);
}
delete[] nameslist[fileidx];
nameslist[fileidx] = utils::strdup(filecurrent);

View File

@ -72,7 +72,7 @@ void DumpCustomGZ::openfile()
++numfiles;
} else {
if (remove(nameslist[fileidx]) != 0) {
error->warning(FLERR, fmt::format("Could not delete {}", nameslist[fileidx]));
error->warning(FLERR, "Could not delete {}", nameslist[fileidx]);
}
delete[] nameslist[fileidx];
nameslist[fileidx] = utils::strdup(filecurrent);

View File

@ -79,7 +79,7 @@ void DumpCustomZstd::openfile()
++numfiles;
} else {
if (remove(nameslist[fileidx]) != 0) {
error->warning(FLERR, fmt::format("Could not delete {}", nameslist[fileidx]));
error->warning(FLERR, "Could not delete {}", nameslist[fileidx]);
}
delete[] nameslist[fileidx];
nameslist[fileidx] = utils::strdup(filecurrent);

View File

@ -72,7 +72,7 @@ void DumpLocalGZ::openfile()
++numfiles;
} else {
if (remove(nameslist[fileidx]) != 0) {
error->warning(FLERR, fmt::format("Could not delete {}", nameslist[fileidx]));
error->warning(FLERR, "Could not delete {}", nameslist[fileidx]);
}
delete[] nameslist[fileidx];
nameslist[fileidx] = utils::strdup(filecurrent);

View File

@ -79,7 +79,7 @@ void DumpLocalZstd::openfile()
++numfiles;
} else {
if (remove(nameslist[fileidx]) != 0) {
error->warning(FLERR, fmt::format("Could not delete {}", nameslist[fileidx]));
error->warning(FLERR, "Could not delete {}", nameslist[fileidx]);
}
delete[] nameslist[fileidx];
nameslist[fileidx] = utils::strdup(filecurrent);

View File

@ -213,11 +213,10 @@ void EwaldDisp::init()
error->all(FLERR,"Cannot (yet) use 'electron' units with dipoles");
if (qsqsum == 0.0 && bsbsum == 0.0 && M2 == 0.0)
error->all(FLERR,"Cannot use Ewald/disp solver "
"on system with no charge, dipole, or LJ particles");
error->all(FLERR,"Cannot use Ewald/disp solver on system without "
"charged, dipole, or LJ particles");
if (fabs(qsum) > SMALL && comm->me == 0)
error->warning(FLERR,fmt::format("System is not charge neutral, "
"net charge = {:.8g}",qsum));
error->warning(FLERR,"System is not charge neutral, net charge = {:.8g}",qsum);
if (!function[1] && !function[2]) dispersionflag = 0;
if (!function[3]) dipoleflag = 0;

View File

@ -1085,8 +1085,8 @@ void MSM::set_grid_global()
*p_cutoff = cutoff;
if (me == 0)
error->warning(FLERR,fmt::format("Adjusting Coulombic cutoff for "
"MSM, new cutoff = {:.8}", cutoff));
error->warning(FLERR,"Adjusting Coulombic cutoff for "
"MSM, new cutoff = {:.8}", cutoff);
}
if (triclinic == 0) {

View File

@ -1362,8 +1362,8 @@ void PPPMDisp::init_coeffs()
err = bmax/amax;
if (err > 1.0e-4 && comm->me == 0)
error->warning(FLERR,fmt::format("Estimated error in splitting of "
"dispersion coeffs is {}",err));
error->warning(FLERR,"Estimated error in splitting of "
"dispersion coeffs is {}",err);
// set B
B = new double[nsplit*n+nsplit];

View File

@ -287,8 +287,8 @@ void FixDeposit::init()
double separation = MAX(2.0*maxradinsert,maxradall+maxradinsert);
if (sqrt(nearsq) < separation && comm->me == 0)
error->warning(FLERR,fmt::format("Fix deposit near setting < possible "
"overlap separation {}",separation));
error->warning(FLERR,"Fix deposit near setting < possible "
"overlap separation {}",separation);
}
}

View File

@ -85,8 +85,8 @@ void BondFENE::compute(int eflag, int vflag)
// if r > 2*r0 something serious is wrong, abort
if (rlogarg < 0.1) {
error->warning(FLERR,fmt::format("FENE bond too long: {} {} {} {}",
update->ntimestep,atom->tag[i1],atom->tag[i2],sqrt(rsq)));
error->warning(FLERR,"FENE bond too long: {} {} {} {}",
update->ntimestep,atom->tag[i1],atom->tag[i2],sqrt(rsq));
if (rlogarg <= -3.0) error->one(FLERR,"Bad FENE bond");
rlogarg = 0.1;
}

View File

@ -378,15 +378,15 @@ void BondTable::read_table(Table *tb, char *file, char *keyword)
}
if (ferror) {
error->warning(FLERR, fmt::format("{} of {} force values in table are inconsistent with -dE/dr.\n"
" Should only be flagged at inflection points",ferror,tb->ninput));
error->warning(FLERR, "{} of {} force values in table are inconsistent with -dE/dr.\n"
"WARNING: Should only be flagged at inflection points",ferror,tb->ninput);
}
// warn if data was read incompletely, e.g. columns were missing
if (cerror) {
error->warning(FLERR, fmt::format("{} of {} lines in table were incomplete or could not be"
" parsed completely",cerror,tb->ninput));
error->warning(FLERR, "{} of {} lines in table were incomplete or could not be"
" parsed completely",cerror,tb->ninput);
}
}

View File

@ -171,9 +171,8 @@ namespace LAMMPS_NS
auto pair_map = lmp->force->pair_map;
if (pair_map->find(plugin->name) != pair_map->end()) {
if (lmp->comm->me == 0)
lmp->error->warning(FLERR,fmt::format("Overriding built-in pair "
"style {} from plugin",
plugin->name));
lmp->error->warning(FLERR,"Overriding built-in pair "
"style {} from plugin",plugin->name);
}
(*pair_map)[plugin->name] = (Force::PairCreator)plugin->creator.v1;
@ -181,9 +180,8 @@ namespace LAMMPS_NS
auto bond_map = lmp->force->bond_map;
if (bond_map->find(plugin->name) != bond_map->end()) {
if (lmp->comm->me == 0)
lmp->error->warning(FLERR,fmt::format("Overriding built-in bond "
"style {} from plugin",
plugin->name));
lmp->error->warning(FLERR,"Overriding built-in bond "
"style {} from plugin",plugin->name);
}
(*bond_map)[plugin->name] = (Force::BondCreator)plugin->creator.v1;
@ -191,9 +189,8 @@ namespace LAMMPS_NS
auto angle_map = lmp->force->angle_map;
if (angle_map->find(plugin->name) != angle_map->end()) {
if (lmp->comm->me == 0)
lmp->error->warning(FLERR,fmt::format("Overriding built-in angle "
"style {} from plugin",
plugin->name));
lmp->error->warning(FLERR,"Overriding built-in angle "
"style {} from plugin",plugin->name);
}
(*angle_map)[plugin->name] = (Force::AngleCreator)plugin->creator.v1;
@ -201,9 +198,8 @@ namespace LAMMPS_NS
auto dihedral_map = lmp->force->dihedral_map;
if (dihedral_map->find(plugin->name) != dihedral_map->end()) {
if (lmp->comm->me == 0)
lmp->error->warning(FLERR,fmt::format("Overriding built-in dihedral "
"style {} from plugin",
plugin->name));
lmp->error->warning(FLERR,"Overriding built-in dihedral "
"style {} from plugin",plugin->name);
}
(*dihedral_map)[plugin->name] = (Force::DihedralCreator)plugin->creator.v1;
@ -211,9 +207,8 @@ namespace LAMMPS_NS
auto improper_map = lmp->force->improper_map;
if (improper_map->find(plugin->name) != improper_map->end()) {
if (lmp->comm->me == 0)
lmp->error->warning(FLERR,fmt::format("Overriding built-in improper "
"style {} from plugin",
plugin->name));
lmp->error->warning(FLERR,"Overriding built-in improper "
"style {} from plugin",plugin->name);
}
(*improper_map)[plugin->name] = (Force::ImproperCreator)plugin->creator.v1;
@ -221,9 +216,8 @@ namespace LAMMPS_NS
auto compute_map = lmp->modify->compute_map;
if (compute_map->find(plugin->name) != compute_map->end()) {
if (lmp->comm->me == 0)
lmp->error->warning(FLERR,fmt::format("Overriding built-in compute "
"style {} from plugin",
plugin->name));
lmp->error->warning(FLERR,"Overriding built-in compute "
"style {} from plugin",plugin->name);
}
(*compute_map)[plugin->name] = (Modify::ComputeCreator)plugin->creator.v2;
@ -231,9 +225,8 @@ namespace LAMMPS_NS
auto fix_map = lmp->modify->fix_map;
if (fix_map->find(plugin->name) != fix_map->end()) {
if (lmp->comm->me == 0)
lmp->error->warning(FLERR,fmt::format("Overriding built-in fix "
"style {} from plugin",
plugin->name));
lmp->error->warning(FLERR,"Overriding built-in fix "
"style {} from plugin",plugin->name);
}
(*fix_map)[plugin->name] = (Modify::FixCreator)plugin->creator.v2;
@ -241,9 +234,8 @@ namespace LAMMPS_NS
auto region_map = lmp->domain->region_map;
if (region_map->find(plugin->name) != region_map->end()) {
if (lmp->comm->me == 0)
lmp->error->warning(FLERR,fmt::format("Overriding built-in region "
"style {} from plugin",
plugin->name));
lmp->error->warning(FLERR,"Overriding built-in region "
"style {} from plugin",plugin->name);
}
(*region_map)[plugin->name] = (Domain::RegionCreator)plugin->creator.v2;
@ -251,9 +243,8 @@ namespace LAMMPS_NS
auto command_map = lmp->input->command_map;
if (command_map->find(plugin->name) != command_map->end()) {
if (lmp->comm->me == 0)
lmp->error->warning(FLERR,fmt::format("Overriding built-in command "
"style {} from plugin",
plugin->name));
lmp->error->warning(FLERR,"Overriding built-in command "
"style {} from plugin",plugin->name);
}
(*command_map)[plugin->name] = (Input::CommandCreator)plugin->creator.v1;

View File

@ -387,10 +387,9 @@ int FixQEq::CG( double *b, double *x )
}
if ((comm->me == 0) && (loop >= maxiter))
error->warning(FLERR,fmt::format("Fix qeq CG convergence failed ({}) "
"after {} iterations at step {}",
sqrt(sig_new)/b_norm,loop,
update->ntimestep));
error->warning(FLERR,"Fix qeq CG convergence failed ({}) after {} "
"iterations at step {}",sqrt(sig_new)/b_norm,loop,
update->ntimestep);
return loop;
}

View File

@ -155,8 +155,8 @@ void FixQEqDynamic::pre_force(int /*vflag*/)
}
if ((comm->me == 0) && (iloop >= maxiter))
error->warning(FLERR,fmt::format("Charges did not converge at step "
"{}: {}",update->ntimestep,enegchk));
error->warning(FLERR,"Charges did not converge at step {}: {}",
update->ntimestep,enegchk);
if (force->kspace) force->kspace->qsum_qsq();
}

View File

@ -215,8 +215,8 @@ void FixQEqFire::pre_force(int /*vflag*/)
}
if ((comm->me == 0) && (iloop >= maxiter))
error->warning(FLERR,fmt::format("Charges did not converge at step "
"{}: {}",update->ntimestep,enegchk));
error->warning(FLERR,"Charges did not converge at step {}: {}",
update->ntimestep,enegchk);
if (force->kspace) force->kspace->qsum_qsq();
}

View File

@ -697,8 +697,8 @@ void FixRigid::init()
if (modify->fix[i]->rigid_flag) rflag = 1;
if (rflag && (modify->fmask[i] & POST_FORCE) &&
!modify->fix[i]->rigid_flag)
error->warning(FLERR,fmt::format("Fix {} alters forces after fix "
"rigid",modify->fix[i]->id));
error->warning(FLERR,"Fix {} alters forces after fix rigid",
modify->fix[i]->id);
}
}

View File

@ -548,8 +548,8 @@ void FixRigidSmall::init()
if (modify->fix[i]->rigid_flag) rflag = 1;
if (rflag && (modify->fmask[i] & POST_FORCE) &&
!modify->fix[i]->rigid_flag)
error->warning(FLERR,fmt::format("Fix {} alters forces after fix "
"rigid",modify->fix[i]->id));
error->warning(FLERR,"Fix {} alters forces after fix rigid",
modify->fix[i]->id);
}
}

View File

@ -629,7 +629,7 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
// NB: LAMMPS coding guidelines prefer cstdio so we are intentionally
// foregoing reading with getline
if (comm->me == 0) {
error->message(FLERR, fmt::format("INFO: About to read data file: {}", filename));
error->message(FLERR, "INFO: About to read data file: {}", filename);
}
// Data file lines hold two floating point numbers.
@ -645,7 +645,7 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
numEntries = inputLines.size();
if (comm->me == 0) {
error->message(FLERR, fmt::format("INFO: Read {} lines from file", numEntries));
error->message(FLERR, "INFO: Read {} lines from file", numEntries);
}
@ -670,34 +670,23 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
test_sscanf = sscanf(inputLines.at(i).c_str()," %f , %f ",&f1, &f2);
if (test_sscanf == 2)
{
//if (comm->me == 0) {
// error->message(FLERR, fmt::format("INFO: f1 = {}, f2 = {}", f1, f2));
//}
data[VOLUME][i] = (double)f1;
data[PRESSURE_CORRECTION][i] = (double)f2;
if (i == 1)
{
// second entry is used to compute the validation interval used below
stdVolumeInterval = data[VOLUME][i] - data[VOLUME][i-1];
//if (comm->me == 0) {
// error->message(FLERR, fmt::format("INFO: standard volume interval computed: {}", stdVolumeInterval));
//}
}
else if (i > 1)
{
// after second entry, all intervals are validated
currVolumeInterval = data[VOLUME][i] - data[VOLUME][i-1];
//if (comm->me == 0) {
// error->message(FLERR, fmt::format("INFO: current volume interval: {}", currVolumeInterval));
//}
if (fabs(currVolumeInterval - stdVolumeInterval) > volumeIntervalTolerance) {
if (comm->me == 0) {
message = fmt::format("Bad volume interval. Spline analysis requires uniform"
if (comm->me == 0)
error->warning(FLERR,"Bad volume interval. Spline analysis requires uniform"
" volume distribution, found inconsistent volume"
" differential, line {} of file {}\n\tline: {}",
" differential, line {} of file {}\nWARNING:\tline: {}",
lineNum, filename, inputLines.at(i));
error->warning(FLERR, message);
}
badInput = true;
numBadVolumeIntervals++;
}
@ -706,12 +695,10 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
}
else
{
if (comm->me == 0) {
message = fmt::format("Bad input format: did not find 2 comma separated numeric"
" values in line {} of file {}\n\tline: {}",
if (comm->me == 0)
error->warning(FLERR,"Bad input format: did not find 2 comma separated numeric"
" values in line {} of file {}\nWARNING:\tline: {}",
lineNum, filename, inputLines.at(i));
error->warning(FLERR, message);
}
badInput = true;
}
if (badInput)
@ -721,7 +708,7 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
}
if (numBadVolumeIntervals > 0 && comm->me == 0) {
error->message(FLERR, fmt::format("INFO: total number bad volume intervals = {}", numBadVolumeIntervals));
error->message(FLERR, "INFO: total number bad volume intervals = {}", numBadVolumeIntervals);
}
}
else {
@ -729,7 +716,7 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
}
if (badInput && comm->me == 0) {
error->warning(FLERR,fmt::format("Bad volume / pressure-correction data: {}\nSee details above", filename));
error->warning(FLERR,"Bad volume / pressure-correction data: {}\nSee details above", filename);
}
if (p_basis_type == BASIS_LINEAR_SPLINE)
@ -752,9 +739,6 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
}
int FixBocs::build_linear_splines(double **data) {
//if (comm->me == 0) {
//error->message(FLERR, fmt::format("INFO: entering build_linear_splines, spline_length = {}", spline_length));
//}
splines = (double **) calloc(NUM_LINEAR_SPLINE_COLUMNS,sizeof(double *));
splines[VOLUME] = (double *) calloc(spline_length,sizeof(double));
splines[PRESSURE_CORRECTION] = (double *) calloc(spline_length,sizeof(double));
@ -766,7 +750,7 @@ int FixBocs::build_linear_splines(double **data) {
}
if (comm->me == 0) {
error->message(FLERR, fmt::format("INFO: leaving build_linear_splines, spline_length = {}", spline_length));
error->message(FLERR, "INFO: leaving build_linear_splines, spline_length = {}", spline_length);
}
return spline_length;
@ -774,9 +758,6 @@ int FixBocs::build_linear_splines(double **data) {
int FixBocs::build_cubic_splines(double **data)
{
//if (comm->me == 0) {
//error->message(FLERR, fmt::format("INFO: entering build_cubic_splines, spline_length = {}", spline_length));
//}
int n = spline_length;
double *a, *b, *d, *h, *alpha, *c, *l, *mu, *z;
// 2020-07-17 ag:
@ -867,7 +848,7 @@ int FixBocs::build_cubic_splines(double **data)
memory->destroy(z);
if (comm->me == 0) {
error->message(FLERR, fmt::format("INFO: leaving build_cubic_splines, numSplines = {}", numSplines));
error->message(FLERR, "INFO: leaving build_cubic_splines, numSplines = {}", numSplines);
}
// Tell the caller how many splines we created

View File

@ -920,20 +920,17 @@ void PairMesoCNT::read_data(FILE *fp, double **data,
// warn if data was read incompletely, e.g. columns were missing
if (cerror)
error->warning(FLERR,fmt::format("{} of {} lines were incomplete or could "
"not be parsed completely in pair table: {}",
cerror,ninput*ninput,file));
error->warning(FLERR,"{} of {} lines were incomplete or could not be parsed "
"completely in pair table: {}",cerror,ninput*ninput,file);
// warn if spacing between data points is not constant
if (sxerror)
error->warning(FLERR,fmt::format("{} spacings in first column were different "
" from first spacing in pair table: {}",
sxerror,file));
error->warning(FLERR,"{} spacings in first column were different from "
"first spacing in pair table: {}",sxerror,file);
if (syerror)
error->warning(FLERR,fmt::format("{} spacings in second column were different "
" from first spacing in pair table: {}",
syerror,file));
error->warning(FLERR,"{} spacings in second column were different from "
"first spacing in pair table: {}",syerror,file);
}
/* ----------------------------------------------------------------------

View File

@ -349,8 +349,7 @@ void PairAGNI::read_file(char *filename)
params[curparam].gwidth = 0.0;
wantdata = curparam;
curparam = -1;
} else error->warning(FLERR,fmt::format("Ignoring unknown tag '{}' "
"in AGNI potential file.",tag));
} else error->warning(FLERR,"Ignoring unknown tag '{}' in AGNI potential file.",tag);
} else {
if (params && wantdata >=0) {
if ((int)values.count() == params[wantdata].numeta + 2) {

View File

@ -389,9 +389,8 @@ void ChangeBox::command(int narg, char **arg)
bigint nblocal = atom->nlocal;
MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world);
if (natoms != atom->natoms && comm->me == 0)
error->warning(FLERR,fmt::format("Lost atoms via change_box: "
"original {} current {}",
atom->natoms,natoms));
error->warning(FLERR,"Lost atoms via change_box: original {} "
"current {}", atom->natoms,natoms);
}
/* ----------------------------------------------------------------------

View File

@ -655,18 +655,16 @@ double Comm::get_comm_cutoff()
maxcommcutoff = MAX(maxcommcutoff,maxbondcutoff);
} else {
if ((me == 0) && (maxbondcutoff > maxcommcutoff))
error->warning(FLERR,fmt::format("Communication cutoff {} is shorter "
"than a bond length based estimate of "
"{}. This may lead to errors.",
maxcommcutoff,maxbondcutoff));
error->warning(FLERR,"Communication cutoff {} is shorter than a bond "
"length based estimate of {}. This may lead to errors.",
maxcommcutoff,maxbondcutoff);
}
// print warning if neighborlist cutoff overrides user cutoff
if ((me == 0) && (update->setupflag == 1)) {
if ((cutghostuser > 0.0) && (maxcommcutoff > cutghostuser))
error->warning(FLERR,fmt::format("Communication cutoff adjusted to {}",
maxcommcutoff));
error->warning(FLERR,"Communication cutoff adjusted to {}",maxcommcutoff);
}
return maxcommcutoff;

View File

@ -186,8 +186,7 @@ void ComputeCNAAtom::compute_peratom()
int nerrorall;
MPI_Allreduce(&nerror,&nerrorall,1,MPI_INT,MPI_SUM,world);
if (nerrorall && comm->me == 0)
error->warning(FLERR,fmt::format("Too many neighbors in CNA for {} "
"atoms",nerrorall));
error->warning(FLERR,"Too many neighbors in CNA for {} atoms",nerrorall);
// compute CNA for each atom in group
// only performed if # of nearest neighbors = 12 or 14 (fcc,hcp)
@ -345,8 +344,7 @@ void ComputeCNAAtom::compute_peratom()
MPI_Allreduce(&nerror,&nerrorall,1,MPI_INT,MPI_SUM,world);
if (nerrorall && comm->me == 0)
error->warning(FLERR,fmt::format("Too many common neighbors in CNA {} "
"times", nerrorall));
error->warning(FLERR,"Too many common neighbors in CNA: {}x", nerrorall);
}
/* ----------------------------------------------------------------------

View File

@ -354,9 +354,8 @@ void DisplaceAtoms::command(int narg, char **arg)
bigint nblocal = atom->nlocal;
MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world);
if (natoms != atom->natoms && comm->me == 0)
error->warning(FLERR,fmt::format("Lost atoms via displace_atoms: "
"original {} current {}",
atom->natoms,natoms));
error->warning(FLERR,"Lost atoms via displace_atoms: original {} "
"current {}",atom->natoms,natoms);
}
/* ----------------------------------------------------------------------

View File

@ -258,6 +258,20 @@ void Error::warning(const std::string &file, int line, const std::string &str)
if (logfile) fputs(mesg.c_str(),logfile);
}
/* ----------------------------------------------------------------------
forward vararg version to single string version
------------------------------------------------------------------------- */
void Error::_warning(const std::string &file, int line, fmt::string_view format,
fmt::format_args args)
{
try {
warning(file,line,fmt::vformat(format, args));
} catch (fmt::format_error &e) {
warning(file,line,e.what());
}
}
/* ----------------------------------------------------------------------
called by one proc in world, typically proc 0
write message to screen and logfile (if logflag is set)
@ -271,6 +285,20 @@ void Error::message(const std::string &file, int line, const std::string &str)
if (logfile) fputs(mesg.c_str(),logfile);
}
/* ----------------------------------------------------------------------
forward vararg version to single string version
------------------------------------------------------------------------- */
void Error::_message(const std::string &file, int line, fmt::string_view format,
fmt::format_args args)
{
try {
message(file,line,fmt::vformat(format, args));
} catch (fmt::format_error &e) {
message(file,line,e.what());
}
}
/* ----------------------------------------------------------------------
shutdown LAMMPS
called by all procs in one world

View File

@ -31,12 +31,13 @@ class Error : protected Pointers {
void universe_warn(const std::string &, int, const std::string &);
[[ noreturn ]] void all(const std::string &, int, const std::string &);
[[ noreturn ]] void one(const std::string &, int, const std::string &);
template <typename S, typename... Args>
void all(const std::string &file, int line, const S &format,
Args&&... args) {
_all(file, line, format, fmt::make_args_checked<Args...>(format, args...));
}
[[ noreturn ]] void one(const std::string &, int, const std::string &);
template <typename S, typename... Args>
void one(const std::string &file, int line, const S &format,
Args&&... args) {
@ -44,7 +45,16 @@ class Error : protected Pointers {
}
void warning(const std::string &, int, const std::string &);
template <typename S, typename... Args>
void warning(const std::string &file, int line, const S &format, Args&&... args) {
_warning(file, line, format, fmt::make_args_checked<Args...>(format, args...));
}
void message(const std::string &, int, const std::string &);
template <typename S, typename... Args>
void message(const std::string &file, int line, const S &format, Args&&... args) {
_message(file, line, format, fmt::make_args_checked<Args...>(format, args...));
}
[[ noreturn ]] void done(int = 0); // 1 would be fully backwards compatible
int get_numwarn() const { return numwarn; }
@ -70,6 +80,8 @@ class Error : protected Pointers {
fmt::format_args args);
[[ noreturn ]] void _one(const std::string &, int, fmt::string_view,
fmt::format_args args);
void _warning(const std::string &, int, fmt::string_view, fmt::format_args args);
void _message(const std::string &, int, fmt::string_view, fmt::format_args args);
};
}

View File

@ -336,7 +336,7 @@ double KSpace::estimate_table_accuracy(double q2_over_sqrt, double spr)
int nctb = force->pair->ncoultablebits;
if (comm->me == 0) {
if (nctb)
error->message(FLERR,fmt::format(" using {}-bit tables for long-range coulomb",nctb));
error->message(FLERR," using {}-bit tables for long-range coulomb",nctb);
else
error->message(FLERR," using polynomial approximation for long-range coulomb");
}

View File

@ -88,6 +88,5 @@ void NTopoAngleAll::build()
int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all && (me == 0))
error->warning(FLERR,fmt::format("Angle atoms missing at step {}",
update->ntimestep));
error->warning(FLERR,"Angle atoms missing at step {}",update->ntimestep);
}

View File

@ -89,6 +89,5 @@ void NTopoAnglePartial::build()
int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all && (me == 0))
error->warning(FLERR,fmt::format("Angle atoms missing at step {}",
update->ntimestep));
error->warning(FLERR,"Angle atoms missing at step {}",update->ntimestep);
}

View File

@ -109,6 +109,5 @@ void NTopoAngleTemplate::build()
int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all && (me == 0))
error->warning(FLERR,fmt::format("Angle atoms missing at step {}",
update->ntimestep));
error->warning(FLERR,"Angle atoms missing at step {}",update->ntimestep);
}

View File

@ -81,6 +81,5 @@ void NTopoBondAll::build()
int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all && (me == 0))
error->warning(FLERR,fmt::format("Bond atoms missing at step {}",
update->ntimestep));
error->warning(FLERR,"Bond atoms missing at step {}",update->ntimestep);
}

View File

@ -82,6 +82,5 @@ void NTopoBondPartial::build()
int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all && (me == 0))
error->warning(FLERR,fmt::format("Bond atoms missing at step {}",
update->ntimestep));
error->warning(FLERR,"Bond atoms missing at step {}",update->ntimestep);
}

View File

@ -100,6 +100,5 @@ void NTopoBondTemplate::build()
int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all && (me == 0))
error->warning(FLERR,fmt::format("Bond atoms missing at step {}",
update->ntimestep));
error->warning(FLERR,"Bond atoms missing at step {}",update->ntimestep);
}

View File

@ -94,6 +94,5 @@ void NTopoDihedralAll::build()
int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all && (me == 0))
error->warning(FLERR,fmt::format("Dihedral atoms missing at step {}",
update->ntimestep));
error->warning(FLERR,"Dihedral atoms missing at step {}",update->ntimestep);
}

View File

@ -96,6 +96,5 @@ void NTopoDihedralPartial::build()
int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all && (me == 0))
error->warning(FLERR,fmt::format("Dihedral atoms missing at step {}",
update->ntimestep));
error->warning(FLERR,"Dihedral atoms missing at step {}",update->ntimestep);
}

View File

@ -115,6 +115,5 @@ void NTopoDihedralTemplate::build()
int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all && (me == 0))
error->warning(FLERR,fmt::format("Dihedral atoms missing at step {}",
update->ntimestep));
error->warning(FLERR,"Dihedral atoms missing at step {}",update->ntimestep);
}

View File

@ -94,6 +94,5 @@ void NTopoImproperAll::build()
int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all && (me == 0))
error->warning(FLERR,fmt::format("Improper atoms missing at step {}",
update->ntimestep));
error->warning(FLERR,"Improper atoms missing at step {}",update->ntimestep);
}

View File

@ -98,6 +98,5 @@ void NTopoImproperPartial::build()
int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all && me == 0)
error->warning(FLERR,fmt::format("Improper atoms missing at step {}",
update->ntimestep));
error->warning(FLERR,"Improper atoms missing at step {}",update->ntimestep);
}

View File

@ -115,6 +115,5 @@ void NTopoImproperTemplate::build()
int all;
MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world);
if (all && (me == 0))
error->warning(FLERR,fmt::format("Improper atoms missing at step {}",
update->ntimestep));
error->warning(FLERR,"Improper atoms missing at step {}",update->ntimestep);
}

View File

@ -458,25 +458,23 @@ void PairTable::read_table(Table *tb, char *file, char *keyword)
}
if (ferror)
error->warning(FLERR,fmt::format("{} of {} force values in table {} are "
"inconsistent with -dE/dr.\n Should "
"only be flagged at inflection points",
ferror,tb->ninput,keyword));
error->warning(FLERR,"{} of {} force values in table {} are inconsistent "
"with -dE/dr.\nWARNING: Should only be flagged at "
"inflection points",ferror,tb->ninput,keyword);
// warn if re-computed distance values differ from file values
if (rerror)
error->warning(FLERR,fmt::format("{} of {} distance values in table {} "
"with relative error\n over {} to "
"re-computed values",
rerror,tb->ninput,EPSILONR,keyword));
error->warning(FLERR,"{} of {} distance values in table {} with relative "
"error\nWARNING: over {} to re-computed values",
rerror,tb->ninput,EPSILONR,keyword);
// warn if data was read incompletely, e.g. columns were missing
if (cerror)
error->warning(FLERR,fmt::format("{} of {} lines in table {} were "
"incomplete\n or could not be parsed "
"completely",cerror,tb->ninput,keyword));
error->warning(FLERR,"{} of {} lines in table {} were incomplete\n"
"WARNING: or could not be parsed completely",
cerror,tb->ninput,keyword);
}
/* ----------------------------------------------------------------------

View File

@ -275,8 +275,8 @@ TextFileReader *PotentialFileReader::open_potential(const std::string &path) {
}
}
if (unit_convert != utils::NOCONVERT)
lmp->error->warning(FLERR, fmt::format("Converting {} in {} units to {} "
"units", filetype, units, unit_style));
lmp->error->warning(FLERR, "Converting {} in {} units to {} units",
filetype, units, unit_style);
return new TextFileReader(filepath, filetype);
}
return nullptr;

View File

@ -694,9 +694,8 @@ void ReadRestart::header()
} else if (flag == NPROCS) {
nprocs_file = read_int();
if (nprocs_file != comm->nprocs && me == 0)
error->warning(FLERR,fmt::format("Restart file used different # of "
"processors: {} vs. {}",nprocs_file,
comm->nprocs));
error->warning(FLERR,"Restart file used different # of processors: "
"{} vs. {}",nprocs_file,comm->nprocs);
// don't set procgrid, warn if different

View File

@ -419,9 +419,8 @@ bigint Thermo::lost_check()
if ((maxwarn > 0) && (warnbefore == 0) && (ntotal[1] > maxwarn)) {
warnbefore = 1;
if (comm->me == 0)
error->message(FLERR,fmt::format("WARNING: Too many warnings: {} vs {}. All "
"future warnings will be suppressed",
ntotal[1],maxwarn));
error->message(FLERR,"WARNING: Too many warnings: {} vs {}. All "
"future warnings will be suppressed",ntotal[1],maxwarn);
}
error->set_allwarn(ntotal[1]);
@ -443,8 +442,8 @@ bigint Thermo::lost_check()
// warning message
if (me == 0)
error->warning(FLERR,fmt::format("Lost atoms: original {} current {}",
atom->natoms,ntotal[0]));
error->warning(FLERR,"Lost atoms: original {} current {}",
atom->natoms,ntotal[0]);
// reset total atom count

View File

@ -305,9 +305,8 @@ void Update::set_units(const char *style)
// check if timestep was changed from default value
if (!dt_default && (comm->me == 0)) {
error->warning(FLERR,fmt::format("Changing timestep from {:.6} to {:.6} "
"due to changing units to {}",
dt_old, dt, unit_style));
error->warning(FLERR,"Changing timestep from {:.6} to {:.6} due to "
"changing units to {}", dt_old, dt, unit_style);
}
dt_default = 1;
}

View File

@ -1200,16 +1200,14 @@ FILE *utils::open_potential(const std::string &name, LAMMPS *lmp,
&& (*auto_convert & REAL2METAL)) {
*auto_convert = REAL2METAL;
} else {
error->one(FLERR, "Potential file {} requires {} units "
"but {} units are in use", name,
units, unit_style);
error->one(FLERR, "Potential file {} requires {} units but {} units "
"are in use", name, units, unit_style);
return nullptr;
}
}
if ((*auto_convert != NOCONVERT) && (me == 0))
error->warning(FLERR, fmt::format("Converting potential file in "
"{} units to {} units",
units, unit_style));
error->warning(FLERR, "Converting potential file in {} units to {} "
"units", units, unit_style);
}
return fopen(filepath.c_str(), "r");
}