diff --git a/src/angle_hybrid.cpp b/src/angle_hybrid.cpp index 0c61970a1f..a015882a15 100644 --- a/src/angle_hybrid.cpp +++ b/src/angle_hybrid.cpp @@ -48,14 +48,7 @@ AngleHybrid::~AngleHybrid() delete[] keywords; } - if (allocated) { - memory->destroy(setflag); - memory->destroy(map); - delete[] nanglelist; - delete[] maxangle; - for (int i = 0; i < nstyles; i++) memory->destroy(anglelist[i]); - delete[] anglelist; - } + deallocate(); } /* ---------------------------------------------------------------------- */ @@ -171,6 +164,22 @@ void AngleHybrid::allocate() for (int m = 0; m < nstyles; m++) anglelist[m] = nullptr; } +/* ---------------------------------------------------------------------- */ + +void AngleHybrid::deallocate() +{ + if (!allocated) return; + + allocated = 0; + + memory->destroy(setflag); + memory->destroy(map); + delete[] nanglelist; + delete[] maxangle; + for (int i = 0; i < nstyles; i++) memory->destroy(anglelist[i]); + delete[] anglelist; +} + /* ---------------------------------------------------------------------- create one angle style for each arg in list ------------------------------------------------------------------------- */ @@ -190,15 +199,7 @@ void AngleHybrid::settings(int narg, char **arg) delete[] keywords; } - if (allocated) { - memory->destroy(setflag); - memory->destroy(map); - delete[] nanglelist; - delete[] maxangle; - for (i = 0; i < nstyles; i++) memory->destroy(anglelist[i]); - delete[] anglelist; - } - allocated = 0; + deallocate(); // allocate list of sub-styles @@ -367,7 +368,7 @@ void AngleHybrid::read_restart(FILE *fp) keywords[m] = new char[n]; if (me == 0) utils::sfread(FLERR, keywords[m], sizeof(char), n, fp, nullptr, error); MPI_Bcast(keywords[m], n, MPI_CHAR, 0, world); - styles[m] = force->new_angle(keywords[m], 0, dummy); + styles[m] = force->new_angle(keywords[m], 1, dummy); styles[m]->read_restart_settings(fp); } } diff --git a/src/angle_hybrid.h b/src/angle_hybrid.h index 474ce89673..a6da29245e 100644 --- a/src/angle_hybrid.h +++ b/src/angle_hybrid.h @@ -42,14 +42,14 @@ class AngleHybrid : public Angle { double single(int, int, int, int) override; double memory_usage() override; - private: + protected: int *map; // which style each angle type points to - int *nanglelist; // # of angles in sub-style anglelists int *maxangle; // max # of angles sub-style lists can store int ***anglelist; // anglelist for each sub-style - void allocate(); + virtual void allocate(); + virtual void deallocate(); }; } // namespace LAMMPS_NS diff --git a/src/dihedral_hybrid.cpp b/src/dihedral_hybrid.cpp index 4ee0ffdad9..3671391f5d 100644 --- a/src/dihedral_hybrid.cpp +++ b/src/dihedral_hybrid.cpp @@ -48,14 +48,7 @@ DihedralHybrid::~DihedralHybrid() delete[] keywords; } - if (allocated) { - memory->destroy(setflag); - memory->destroy(map); - delete[] ndihedrallist; - delete[] maxdihedral; - for (int i = 0; i < nstyles; i++) memory->destroy(dihedrallist[i]); - delete[] dihedrallist; - } + deallocate(); } /* ---------------------------------------------------------------------- */ @@ -172,6 +165,20 @@ void DihedralHybrid::allocate() for (int m = 0; m < nstyles; m++) dihedrallist[m] = nullptr; } +void DihedralHybrid::deallocate() +{ + if (!allocated) return; + + allocated = 0; + + memory->destroy(setflag); + memory->destroy(map); + delete[] ndihedrallist; + delete[] maxdihedral; + for (int i = 0; i < nstyles; i++) memory->destroy(dihedrallist[i]); + delete[] dihedrallist; +} + /* ---------------------------------------------------------------------- create one dihedral style for each arg in list ------------------------------------------------------------------------- */ @@ -191,15 +198,7 @@ void DihedralHybrid::settings(int narg, char **arg) delete[] keywords; } - if (allocated) { - memory->destroy(setflag); - memory->destroy(map); - delete[] ndihedrallist; - delete[] maxdihedral; - for (i = 0; i < nstyles; i++) memory->destroy(dihedrallist[i]); - delete[] dihedrallist; - } - allocated = 0; + deallocate(); // allocate list of sub-styles @@ -365,7 +364,7 @@ void DihedralHybrid::read_restart(FILE *fp) keywords[m] = new char[n]; if (me == 0) utils::sfread(FLERR, keywords[m], sizeof(char), n, fp, nullptr, error); MPI_Bcast(keywords[m], n, MPI_CHAR, 0, world); - styles[m] = force->new_dihedral(keywords[m], 0, dummy); + styles[m] = force->new_dihedral(keywords[m], 1, dummy); styles[m]->read_restart_settings(fp); } } diff --git a/src/dihedral_hybrid.h b/src/dihedral_hybrid.h index b7d4013afe..debc8a9d8d 100644 --- a/src/dihedral_hybrid.h +++ b/src/dihedral_hybrid.h @@ -40,14 +40,15 @@ class DihedralHybrid : public Dihedral { void read_restart(FILE *) override; double memory_usage() override; - private: + protected: int *map; // which style each dihedral type points to int *ndihedrallist; // # of dihedrals in sub-style dihedrallists int *maxdihedral; // max # of dihedrals sub-style lists can store int ***dihedrallist; // dihedrallist for each sub-style - void allocate(); + virtual void allocate(); + virtual void deallocate(); }; } // namespace LAMMPS_NS diff --git a/src/improper_hybrid.cpp b/src/improper_hybrid.cpp index a847b7bc95..5337f062b4 100644 --- a/src/improper_hybrid.cpp +++ b/src/improper_hybrid.cpp @@ -48,14 +48,7 @@ ImproperHybrid::~ImproperHybrid() delete[] keywords; } - if (allocated) { - memory->destroy(setflag); - memory->destroy(map); - delete[] nimproperlist; - delete[] maximproper; - for (int i = 0; i < nstyles; i++) memory->destroy(improperlist[i]); - delete[] improperlist; - } + deallocate(); } /* ---------------------------------------------------------------------- */ @@ -172,6 +165,22 @@ void ImproperHybrid::allocate() for (int m = 0; m < nstyles; m++) improperlist[m] = nullptr; } +/* ---------------------------------------------------------------------- */ + +void ImproperHybrid::deallocate() +{ + if (!allocated) return; + + allocated = 0; + + memory->destroy(setflag); + memory->destroy(map); + delete[] nimproperlist; + delete[] maximproper; + for (int i = 0; i < nstyles; i++) memory->destroy(improperlist[i]); + delete[] improperlist; +} + /* ---------------------------------------------------------------------- create one improper style for each arg in list ------------------------------------------------------------------------- */ @@ -191,15 +200,7 @@ void ImproperHybrid::settings(int narg, char **arg) delete[] keywords; } - if (allocated) { - memory->destroy(setflag); - memory->destroy(map); - delete[] nimproperlist; - delete[] maximproper; - for (i = 0; i < nstyles; i++) memory->destroy(improperlist[i]); - delete[] improperlist; - } - allocated = 0; + deallocate(); // allocate list of sub-styles @@ -357,7 +358,7 @@ void ImproperHybrid::read_restart(FILE *fp) keywords[m] = new char[n]; if (me == 0) utils::sfread(FLERR, keywords[m], sizeof(char), n, fp, nullptr, error); MPI_Bcast(keywords[m], n, MPI_CHAR, 0, world); - styles[m] = force->new_improper(keywords[m], 0, dummy); + styles[m] = force->new_improper(keywords[m], 1, dummy); styles[m]->read_restart_settings(fp); } } diff --git a/src/improper_hybrid.h b/src/improper_hybrid.h index e7cb8383d4..89a4664da2 100644 --- a/src/improper_hybrid.h +++ b/src/improper_hybrid.h @@ -40,14 +40,15 @@ class ImproperHybrid : public Improper { void read_restart(FILE *) override; double memory_usage() override; - private: + protected: int *map; // which style each improper type points to int *nimproperlist; // # of impropers in sub-style improperlists int *maximproper; // max # of impropers sub-style lists can store int ***improperlist; // improperlist for each sub-style - void allocate(); + virtual void allocate(); + virtual void deallocate(); }; } // namespace LAMMPS_NS