strip style suffixes when writing restart files if suffixes are enabled

This commit is contained in:
Axel Kohlmeyer
2022-11-24 11:51:58 -05:00
parent 4adf3708d4
commit 3ce79f8da3
4 changed files with 17 additions and 16 deletions

View File

@ -925,8 +925,8 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix)
// if yes, pass state info to the Fix so it can reset itself
for (int i = 0; i < nfix_restart_global; i++)
if (strcmp(id_restart_global[i], fix[ifix]->id) == 0 &&
strcmp(style_restart_global[i], fix[ifix]->style) == 0) {
if ((strcmp(id_restart_global[i], fix[ifix]->id) == 0) &&
(utils::strip_style_suffix(fix[ifix]->style, lmp) == style_restart_global[i])) {
fix[ifix]->restart(state_restart_global[i]);
used_restart_global[i] = 1;
fix[ifix]->restart_reset = 1;
@ -1448,9 +1448,10 @@ void Modify::write_restart(FILE *fp)
n = strlen(fix[i]->id) + 1;
fwrite(&n, sizeof(int), 1, fp);
fwrite(fix[i]->id, sizeof(char), n, fp);
n = strlen(fix[i]->style) + 1;
auto fix_style = utils::strip_style_suffix(fix[i]->style, lmp);
n = fix_style.size() + 1;
fwrite(&n, sizeof(int), 1, fp);
fwrite(fix[i]->style, sizeof(char), n, fp);
fwrite(fix_style.c_str(), sizeof(char), n, fp);
}
fix[i]->write_restart(fp);
}

View File

@ -769,7 +769,7 @@ void ReadRestart::header()
argcopy[i] = read_string();
atom->create_avec(style,nargcopy,argcopy,1);
if (comm->me ==0)
utils::logmesg(lmp," restoring atom style {} from restart\n",style);
utils::logmesg(lmp," restoring atom style {} from restart\n",atom->atom_style);
for (int i = 0; i < nargcopy; i++) delete[] argcopy[i];
delete[] argcopy;
delete[] style;

View File

@ -449,7 +449,7 @@ void WriteRestart::header()
// write atom_style and its args
write_string(ATOM_STYLE,atom->atom_style);
write_string(ATOM_STYLE,utils::strip_style_suffix(atom->atom_style,lmp));
fwrite(&atom->avec->nargcopy,sizeof(int),1,fp);
for (int i = 0; i < atom->avec->nargcopy; i++) {
int n = strlen(atom->avec->argcopy[i]) + 1;
@ -542,26 +542,26 @@ void WriteRestart::force_fields()
{
if (force->pair) {
if (force->pair->restartinfo) {
write_string(PAIR,force->pair_style);
write_string(PAIR,utils::strip_style_suffix(force->pair_style,lmp));
force->pair->write_restart(fp);
} else {
write_string(NO_PAIR,force->pair_style);
write_string(NO_PAIR,utils::strip_style_suffix(force->pair_style,lmp));
}
}
if (atom->avec->bonds_allow && force->bond) {
write_string(BOND,force->bond_style);
write_string(BOND,utils::strip_style_suffix(force->bond_style,lmp));
force->bond->write_restart(fp);
}
if (atom->avec->angles_allow && force->angle) {
write_string(ANGLE,force->angle_style);
write_string(ANGLE,utils::strip_style_suffix(force->angle_style,lmp));
force->angle->write_restart(fp);
}
if (atom->avec->dihedrals_allow && force->dihedral) {
write_string(DIHEDRAL,force->dihedral_style);
write_string(DIHEDRAL,utils::strip_style_suffix(force->dihedral_style,lmp));
force->dihedral->write_restart(fp);
}
if (atom->avec->impropers_allow && force->improper) {
write_string(IMPROPER,force->improper_style);
write_string(IMPROPER,utils::strip_style_suffix(force->improper_style,lmp));
force->improper->write_restart(fp);
}
@ -672,12 +672,12 @@ void WriteRestart::write_double(int flag, double value)
byte) into the restart file
------------------------------------------------------------------------- */
void WriteRestart::write_string(int flag, const char *value)
void WriteRestart::write_string(int flag, const std::string &value)
{
int n = strlen(value) + 1;
int n = value.size() + 1;
fwrite(&flag,sizeof(int),1,fp);
fwrite(&n,sizeof(int),1,fp);
fwrite(value,sizeof(char),n,fp);
fwrite(value.c_str(),sizeof(char),n,fp);
}
/* ----------------------------------------------------------------------

View File

@ -62,7 +62,7 @@ class WriteRestart : public Command {
void write_int(int, int);
void write_bigint(int, bigint);
void write_double(int, double);
void write_string(int, const char *);
void write_string(int, const std::string &);
void write_int_vec(int, int, int *);
void write_double_vec(int, int, double *);
};