use std::stoX() functions

This commit is contained in:
Axel Kohlmeyer
2024-07-30 03:57:23 -04:00
parent 92cbbaab6a
commit 620af2599b
6 changed files with 19 additions and 18 deletions

View File

@ -13,21 +13,23 @@
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "compute_bond_local.h" #include "compute_bond_local.h"
#include <cmath>
#include <cstring>
#include "atom.h" #include "atom.h"
#include "atom_vec.h" #include "atom_vec.h"
#include "molecule.h"
#include "update.h"
#include "domain.h"
#include "force.h"
#include "bond.h" #include "bond.h"
#include "comm.h" #include "comm.h"
#include "domain.h"
#include "error.h"
#include "force.h"
#include "input.h" #include "input.h"
#include "variable.h"
#include "math_extra.h" #include "math_extra.h"
#include "memory.h" #include "memory.h"
#include "error.h" #include "molecule.h"
#include "update.h"
#include "variable.h"
#include <cmath>
#include <cstring>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -81,7 +83,7 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
vstr[nvar] = utils::strdup(&arg[iarg][2]); vstr[nvar] = utils::strdup(&arg[iarg][2]);
nvar++; nvar++;
} else if (arg[iarg][0] == 'b') { } else if (arg[iarg][0] == 'b') {
int n = atoi(&arg[iarg][1]); int n = std::stoi(&arg[iarg][1]);
if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute bond/local command", arg[iarg]); if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute bond/local command", arg[iarg]);
bstyle[nvalues] = BN; bstyle[nvalues] = BN;
bindex[nvalues++] = n - 1; bindex[nvalues++] = n - 1;

View File

@ -67,7 +67,7 @@ ComputePairLocal::ComputePairLocal(LAMMPS *lmp, int narg, char **arg) :
else if (strcmp(arg[iarg], "dz") == 0) else if (strcmp(arg[iarg], "dz") == 0)
pstyle[nvalues++] = DZ; pstyle[nvalues++] = DZ;
else if (arg[iarg][0] == 'p') { else if (arg[iarg][0] == 'p') {
int n = atoi(&arg[iarg][1]); int n = std::stoi(&arg[iarg][1]);
if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute pair/local command", arg[iarg]); if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute pair/local command", arg[iarg]);
pstyle[nvalues] = PN; pstyle[nvalues] = PN;
pindex[nvalues++] = n - 1; pindex[nvalues++] = n - 1;

View File

@ -191,7 +191,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
int me,nprocs; int me,nprocs;
MPI_Comm_rank(communicator,&me); MPI_Comm_rank(communicator,&me);
MPI_Comm_size(communicator,&nprocs); MPI_Comm_size(communicator,&nprocs);
int color = atoi(arg[iarg+1]); int color = std::stoi(arg[iarg+1]);
MPI_Comm subcomm; MPI_Comm subcomm;
MPI_Comm_split(communicator,color,me,&subcomm); MPI_Comm_split(communicator,color,me,&subcomm);
external_comm = communicator; external_comm = communicator;

View File

@ -484,7 +484,7 @@ void ReaderNative::read_atoms(int n, int nfield, double **fields)
// convert selected fields to floats // convert selected fields to floats
for (int m = 0; m < nfield; m++) for (int m = 0; m < nfield; m++)
fields[i][m] = atof(words[fieldindex[m]].c_str()); fields[i][m] = std::stod(words[fieldindex[m]]);
} }
} }
} }

View File

@ -181,10 +181,10 @@ void Universe::add_world(char *str)
if ((found == 0) || (found == (part.size() - 1))) { if ((found == 0) || (found == (part.size() - 1))) {
valid = false; valid = false;
} else if (found == std::string::npos) { } else if (found == std::string::npos) {
nper = atoi(part.c_str()); nper = std::stoi(part);
} else { } else {
n = atoi(part.substr(0,found).c_str()); n = std::stoi(part.substr(0,found));
nper = atoi(part.substr(found+1).c_str()); nper = std::stoi(part.substr(found+1));
} }
} }
@ -193,8 +193,7 @@ void Universe::add_world(char *str)
if (n < 1 || nper < 1) valid = false; if (n < 1 || nper < 1) valid = false;
if (!valid) if (!valid)
error->universe_all(FLERR,fmt::format("Invalid partition string '{}'", error->universe_all(FLERR, fmt::format("Invalid partition string '{}'", str));
str));
} else nper = nprocs; } else nper = nprocs;
memory->grow(procs_per_world,nworlds+n,"universe:procs_per_world"); memory->grow(procs_per_world,nworlds+n,"universe:procs_per_world");

View File

@ -152,7 +152,7 @@ void WriteCoeff::command(int narg, char **arg)
} }
// parse type number and skip over it // parse type number and skip over it
int type = atoi(str); int type = std::stoi(str);
char *p = str; char *p = str;
while ((*p != '\0') && (*p == ' ')) ++p; while ((*p != '\0') && (*p == ' ')) ++p;
while ((*p != '\0') && isdigit(*p)) ++p; while ((*p != '\0') && isdigit(*p)) ++p;