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

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

View File

@ -217,7 +217,7 @@ int ComputeDihedralLocal::compute_dihedrals(int flag)
// loop over all atoms and their dihedrals
m = n = 0;
m = 0;
for (atom2 = 0; atom2 < nlocal; atom2++) {
if (!(mask[atom2] & groupbit)) continue;
@ -306,7 +306,7 @@ int ComputeDihedralLocal::compute_dihedrals(int flag)
if (pstr) input->variable->internal_set(pvar,phi);
}
for (n = 0; n < nvalues; n++) {
for (int n = 0; n < nvalues; n++) {
switch (bstyle[n]) {
case PHI:
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
double t;
if (keflag) {
if (temperature->invoked_scalar != update->ntimestep)
t = temperature->compute_scalar();
else t = temperature->scalar;
temperature->compute_scalar();
}
if (dimension == 3) {
inv_volume = 1.0 / (domain->xprd * domain->yprd * domain->zprd);
virial_compute(3,3);
if (keflag)
scalar = (temperature->dof * boltz * t +
scalar = (temperature->dof * boltz * temperature->scalar +
virial[0] + virial[1] + virial[2]) / 3.0 * inv_volume * nktv2p;
else
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);
virial_compute(2,2);
if (keflag)
scalar = (temperature->dof * boltz * t +
scalar = (temperature->dof * boltz * temperature->scalar +
virial[0] + virial[1]) / 2.0 * inv_volume * nktv2p;
else
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 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++)
if (mask[i] & groupbit) {

View File

@ -276,7 +276,7 @@ void ComputeTempSphere::compute_vector()
// point particles will not contribute rotation due to radius = 0
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) {
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) {
if (iarg+2 > narg) error->all(FLERR,"Illegal create_atoms command");
delete [] vstr;
int n = strlen(arg[iarg+1]) + 1;
vstr = new char[n];
strcpy(vstr,arg[iarg+1]);
vstr = utils::strdup(arg[iarg+1]);
varflag = 1;
iarg += 2;
} else if (strcmp(arg[iarg],"set") == 0) {
if (iarg+3 > narg) error->all(FLERR,"Illegal create_atoms command");
if (strcmp(arg[iarg+1],"x") == 0) {
delete [] xstr;
int n = strlen(arg[iarg+2]) + 1;
xstr = new char[n];
strcpy(xstr,arg[iarg+2]);
xstr = utils::strdup(arg[iarg+2]);
} else if (strcmp(arg[iarg+1],"y") == 0) {
delete [] ystr;
int n = strlen(arg[iarg+2]) + 1;
ystr = new char[n];
strcpy(ystr,arg[iarg+2]);
ystr = utils::strdup(arg[iarg+2]);
} else if (strcmp(arg[iarg+1],"z") == 0) {
delete [] zstr;
int n = strlen(arg[iarg+2]) + 1;
zstr = new char[n];
strcpy(zstr,arg[iarg+2]);
zstr = utils::strdup(arg[iarg+2]);
} else error->all(FLERR,"Illegal create_atoms command");
iarg += 3;
} 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++)
if ((boundary[idim][0] == 0 && boundary[idim][1]) ||
(boundary[idim][0] && boundary[idim][1] == 0))
for (auto &bdim : boundary)
if ((bdim[0] == 0 && bdim[1]) ||
(bdim[0] && bdim[1] == 0))
error->all(FLERR,"Both sides of boundary must be periodic");
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)
{
int m = 0;
for (int idim = 0; idim < 3; idim++) {
for (int iside = 0; iside < 2; iside++) {
if (boundary[idim][iside] == 0) str[m++] = 'p';
else if (boundary[idim][iside] == 1) str[m++] = 'f';
else if (boundary[idim][iside] == 2) str[m++] = 's';
else if (boundary[idim][iside] == 3) str[m++] = 'm';
for (auto &bdim : boundary) {
for (auto &bside : bdim) {
if (bside == 0) str[m++] = 'p';
else if (bside == 1) str[m++] = 'f';
else if (bside == 2) str[m++] = 's';
else if (bside == 3) str[m++] = 'm';
}
str[m++] = ' ';
}