simplify and modernize code a little

This commit is contained in:
Axel Kohlmeyer
2021-09-15 23:15:14 -04:00
parent 272badfa7f
commit 94f83c172a
7 changed files with 23 additions and 35 deletions

View File

@ -665,7 +665,7 @@ void Atom::set_atomflag_defaults()
void Atom::create_avec(const std::string &style, int narg, char **arg, int trysuffix) void Atom::create_avec(const std::string &style, int narg, char **arg, int trysuffix)
{ {
delete [] atom_style; delete[] atom_style;
if (avec) delete avec; if (avec) delete avec;
atom_style = nullptr; atom_style = nullptr;
avec = nullptr; avec = nullptr;
@ -689,11 +689,9 @@ void Atom::create_avec(const std::string &style, int narg, char **arg, int trysu
std::string estyle = style + "/"; std::string estyle = style + "/";
if (sflag == 1) estyle += lmp->suffix; if (sflag == 1) estyle += lmp->suffix;
else estyle += lmp->suffix2; else estyle += lmp->suffix2;
atom_style = new char[estyle.size()+1]; atom_style = utils::strdup(estyle);
strcpy(atom_style,estyle.c_str());
} else { } else {
atom_style = new char[style.size()+1]; atom_style = utils::strdup(style);
strcpy(atom_style,style.c_str());
} }
// if molecular system: // if molecular system:

View File

@ -217,7 +217,7 @@ int ComputeDihedralLocal::compute_dihedrals(int flag)
// loop over all atoms and their dihedrals // loop over all atoms and their dihedrals
m = n = 0; m = 0;
for (atom2 = 0; atom2 < nlocal; atom2++) { for (atom2 = 0; atom2 < nlocal; atom2++) {
if (!(mask[atom2] & groupbit)) continue; if (!(mask[atom2] & groupbit)) continue;
@ -306,7 +306,7 @@ int ComputeDihedralLocal::compute_dihedrals(int flag)
if (pstr) input->variable->internal_set(pvar,phi); if (pstr) input->variable->internal_set(pvar,phi);
} }
for (n = 0; n < nvalues; n++) { for (int n = 0; n < nvalues; n++) {
switch (bstyle[n]) { switch (bstyle[n]) {
case PHI: case PHI:
ptr[n] = 180.0*phi/MY_PI; ptr[n] = 180.0*phi/MY_PI;

View File

@ -237,18 +237,16 @@ double ComputePressure::compute_scalar()
// invoke temperature if it hasn't been already // invoke temperature if it hasn't been already
double t;
if (keflag) { if (keflag) {
if (temperature->invoked_scalar != update->ntimestep) if (temperature->invoked_scalar != update->ntimestep)
t = temperature->compute_scalar(); temperature->compute_scalar();
else t = temperature->scalar;
} }
if (dimension == 3) { if (dimension == 3) {
inv_volume = 1.0 / (domain->xprd * domain->yprd * domain->zprd); inv_volume = 1.0 / (domain->xprd * domain->yprd * domain->zprd);
virial_compute(3,3); virial_compute(3,3);
if (keflag) if (keflag)
scalar = (temperature->dof * boltz * t + scalar = (temperature->dof * boltz * temperature->scalar +
virial[0] + virial[1] + virial[2]) / 3.0 * inv_volume * nktv2p; virial[0] + virial[1] + virial[2]) / 3.0 * inv_volume * nktv2p;
else else
scalar = (virial[0] + virial[1] + virial[2]) / 3.0 * inv_volume * nktv2p; scalar = (virial[0] + virial[1] + virial[2]) / 3.0 * inv_volume * nktv2p;
@ -256,7 +254,7 @@ double ComputePressure::compute_scalar()
inv_volume = 1.0 / (domain->xprd * domain->yprd); inv_volume = 1.0 / (domain->xprd * domain->yprd);
virial_compute(2,2); virial_compute(2,2);
if (keflag) if (keflag)
scalar = (temperature->dof * boltz * t + scalar = (temperature->dof * boltz * temperature->scalar +
virial[0] + virial[1]) / 2.0 * inv_volume * nktv2p; virial[0] + virial[1]) / 2.0 * inv_volume * nktv2p;
else else
scalar = (virial[0] + virial[1]) / 2.0 * inv_volume * nktv2p; scalar = (virial[0] + virial[1]) / 2.0 * inv_volume * nktv2p;

View File

@ -171,7 +171,7 @@ void ComputeTempDeform::compute_vector()
double *h_ratelo = domain->h_ratelo; double *h_ratelo = domain->h_ratelo;
double massone, t[6]; double massone, t[6];
for (int i = 0; i < 6; i++) t[i] = 0.0; for (auto &ti : t) ti = 0.0;
for (int i = 0; i < nlocal; i++) for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) { if (mask[i] & groupbit) {

View File

@ -276,7 +276,7 @@ void ComputeTempSphere::compute_vector()
// point particles will not contribute rotation due to radius = 0 // point particles will not contribute rotation due to radius = 0
double massone,inertiaone,t[6]; double massone,inertiaone,t[6];
for (int i = 0; i < 6; i++) t[i] = 0.0; for (auto &ti : t) ti = 0.0;
if (mode == ALL) { if (mode == ALL) {
for (int i = 0; i < nlocal; i++) for (int i = 0; i < nlocal; i++)

View File

@ -176,28 +176,20 @@ void CreateAtoms::command(int narg, char **arg)
} else if (strcmp(arg[iarg],"var") == 0) { } else if (strcmp(arg[iarg],"var") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal create_atoms command"); if (iarg+2 > narg) error->all(FLERR,"Illegal create_atoms command");
delete [] vstr; delete [] vstr;
int n = strlen(arg[iarg+1]) + 1; vstr = utils::strdup(arg[iarg+1]);
vstr = new char[n];
strcpy(vstr,arg[iarg+1]);
varflag = 1; varflag = 1;
iarg += 2; iarg += 2;
} else if (strcmp(arg[iarg],"set") == 0) { } else if (strcmp(arg[iarg],"set") == 0) {
if (iarg+3 > narg) error->all(FLERR,"Illegal create_atoms command"); if (iarg+3 > narg) error->all(FLERR,"Illegal create_atoms command");
if (strcmp(arg[iarg+1],"x") == 0) { if (strcmp(arg[iarg+1],"x") == 0) {
delete [] xstr; delete [] xstr;
int n = strlen(arg[iarg+2]) + 1; xstr = utils::strdup(arg[iarg+2]);
xstr = new char[n];
strcpy(xstr,arg[iarg+2]);
} else if (strcmp(arg[iarg+1],"y") == 0) { } else if (strcmp(arg[iarg+1],"y") == 0) {
delete [] ystr; delete [] ystr;
int n = strlen(arg[iarg+2]) + 1; ystr = utils::strdup(arg[iarg+2]);
ystr = new char[n];
strcpy(ystr,arg[iarg+2]);
} else if (strcmp(arg[iarg+1],"z") == 0) { } else if (strcmp(arg[iarg+1],"z") == 0) {
delete [] zstr; delete [] zstr;
int n = strlen(arg[iarg+2]) + 1; zstr = utils::strdup(arg[iarg+2]);
zstr = new char[n];
strcpy(zstr,arg[iarg+2]);
} else error->all(FLERR,"Illegal create_atoms command"); } else error->all(FLERR,"Illegal create_atoms command");
iarg += 3; iarg += 3;
} else if (strcmp(arg[iarg],"rotate") == 0) { } else if (strcmp(arg[iarg],"rotate") == 0) {

View File

@ -1884,9 +1884,9 @@ void Domain::set_boundary(int narg, char **arg, int flag)
} }
} }
for (int idim = 0; idim < 3; idim++) for (auto &bdim : boundary)
if ((boundary[idim][0] == 0 && boundary[idim][1]) || if ((bdim[0] == 0 && bdim[1]) ||
(boundary[idim][0] && boundary[idim][1] == 0)) (bdim[0] && bdim[1] == 0))
error->all(FLERR,"Both sides of boundary must be periodic"); error->all(FLERR,"Both sides of boundary must be periodic");
if (boundary[0][0] == 0) xperiodic = 1; if (boundary[0][0] == 0) xperiodic = 1;
@ -1988,12 +1988,12 @@ void Domain::print_box(const std::string &prefix)
void Domain::boundary_string(char *str) void Domain::boundary_string(char *str)
{ {
int m = 0; int m = 0;
for (int idim = 0; idim < 3; idim++) { for (auto &bdim : boundary) {
for (int iside = 0; iside < 2; iside++) { for (auto &bside : bdim) {
if (boundary[idim][iside] == 0) str[m++] = 'p'; if (bside == 0) str[m++] = 'p';
else if (boundary[idim][iside] == 1) str[m++] = 'f'; else if (bside == 1) str[m++] = 'f';
else if (boundary[idim][iside] == 2) str[m++] = 's'; else if (bside == 2) str[m++] = 's';
else if (boundary[idim][iside] == 3) str[m++] = 'm'; else if (bside == 3) str[m++] = 'm';
} }
str[m++] = ' '; str[m++] = ' ';
} }