From 50af20d194ee86de6f873ab48493d81c72d79389 Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sun, 1 Sep 2019 23:31:31 -0600 Subject: [PATCH] bond/react: remember reaction counts allow restart files to restore cumutative reaction counts --- doc/src/fix_bond_react.txt | 9 ++++--- src/USER-MISC/fix_bond_react.cpp | 42 ++++++++++++++++++++++++++++++++ src/USER-MISC/fix_bond_react.h | 9 +++++++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/doc/src/fix_bond_react.txt b/doc/src/fix_bond_react.txt index 3f428e2103..5aff35787d 100644 --- a/doc/src/fix_bond_react.txt +++ b/doc/src/fix_bond_react.txt @@ -392,10 +392,11 @@ local command. [Restart, fix_modify, output, run start/stop, minimize info:] -No information about this fix is written to "binary restart -files"_restart.html, aside from internally-created per-atom -properties. None of the "fix_modify"_fix_modify.html options are -relevant to this fix. +Cumulative reaction counts for each reaction are written to "binary +restart files"_restart.html. These values are associated with the +reaction name (react-ID). Additionally, internally-created per-atom +properties are stored to allow for smooth restarts. None of the +"fix_modify"_fix_modify.html options are relevant to this fix. This fix computes one statistic for each {react} argument that it stores in a global vector, of length 'number of react arguments', that diff --git a/src/USER-MISC/fix_bond_react.cpp b/src/USER-MISC/fix_bond_react.cpp index b38a3468c2..07f009360a 100644 --- a/src/USER-MISC/fix_bond_react.cpp +++ b/src/USER-MISC/fix_bond_react.cpp @@ -87,6 +87,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : MPI_Comm_size(world,&nprocs); newton_bond = force->newton_bond; + restart_global = 1; attempted_rxn = 0; force_reneighbor = 1; next_reneighbor = -1; @@ -388,6 +389,10 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : id_fix3 = NULL; statted_id = NULL; custom_exclude_flag = 0; + + // used to store restart info + set = new Set[nreacts]; + memset(set,0,nreacts*sizeof(Set)); } /* ---------------------------------------------------------------------- */ @@ -471,6 +476,7 @@ FixBondReact::~FixBondReact() delete [] statted_id; delete [] guess_branch; delete [] pioneer_count; + delete [] set; if (group) { char **newarg; @@ -3100,6 +3106,42 @@ void FixBondReact::unpack_reverse_comm(int n, int *list, double *buf) } } +/* ---------------------------------------------------------------------- + write Set data to restart file +------------------------------------------------------------------------- */ + +void FixBondReact::write_restart(FILE *fp) +{ + set[0].nreacts = nreacts; + for (int i = 0; i < nreacts; i++) { + set[i].reaction_count_total = reaction_count_total[i]; + int n = strlen(rxn_name[i]) + 1; + strncpy(set[i].rxn_name,rxn_name[i],n); + } + + if (me == 0) { + int size = nreacts*sizeof(Set); + fwrite(&size,sizeof(int),1,fp); + fwrite(set,sizeof(Set),nreacts,fp); + } +} + +/* ---------------------------------------------------------------------- + use selected state info from restart file to restart the Fix +------------------------------------------------------------------------- */ + +void FixBondReact::restart(char *buf) +{ + Set *set_restart = (Set *) buf; + for (int i = 0; i < set_restart[0].nreacts; i++) { + for (int j = 0; j < nreacts; j++) { + if (strcmp(set_restart[i].rxn_name,rxn_name[j]) == 0) { + reaction_count_total[j] = set_restart[i].reaction_count_total; + } + } + } +} + /* ---------------------------------------------------------------------- memory usage of local atom-based arrays ------------------------------------------------------------------------- */ diff --git a/src/USER-MISC/fix_bond_react.h b/src/USER-MISC/fix_bond_react.h index 1ac8d624a9..2be20cf8ec 100644 --- a/src/USER-MISC/fix_bond_react.h +++ b/src/USER-MISC/fix_bond_react.h @@ -170,6 +170,15 @@ class FixBondReact : public Fix { void unlimit_bond(); void limit_bond(int); void dedup_mega_gloves(int); //dedup global mega_glove + virtual void write_restart(FILE *); + virtual void restart(char *buf); + + struct Set { + int nreacts; + char rxn_name[256]; + int reaction_count_total; + }; + Set *set; // DEBUG