From 240db21054ff8e5445d709caa825d76ee6e3ef57 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 11 Jan 2022 11:46:08 -0500 Subject: [PATCH 01/22] silence possible warnings about missing files on "make clean-all" --- src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 2d651c4986..d23058447a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -439,7 +439,7 @@ clean: clean-all: rm -rf Obj_* - rm style_*.h packages_*.h lmpgitversion.h lmpinstalledpkgs.h + rm -f style_*.h packages_*.h lmpgitversion.h lmpinstalledpkgs.h clean-%: @if [ $@ = "clean-serial" ]; \ From 698256f4fea42bcbbaa350f6e64163a32d3a1adf Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 12 Jan 2022 08:17:54 -0500 Subject: [PATCH 02/22] update fedora singularity image to Fedora 35 --- tools/singularity/{fedora34_mingw.def => fedora35_mingw.def} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename tools/singularity/{fedora34_mingw.def => fedora35_mingw.def} (99%) diff --git a/tools/singularity/fedora34_mingw.def b/tools/singularity/fedora35_mingw.def similarity index 99% rename from tools/singularity/fedora34_mingw.def rename to tools/singularity/fedora35_mingw.def index 8a1f108aec..c2108a378c 100644 --- a/tools/singularity/fedora34_mingw.def +++ b/tools/singularity/fedora35_mingw.def @@ -1,5 +1,5 @@ BootStrap: docker -From: fedora:34 +From: fedora:35 %post dnf -y update @@ -94,7 +94,7 @@ EOF CUSTOM_PROMPT_ENV=/.singularity.d/env/99-zz_custom_prompt.sh cat >$CUSTOM_PROMPT_ENV < Date: Fri, 14 Jan 2022 13:02:15 -0500 Subject: [PATCH 03/22] check return values for errors --- src/MANYBODY/pair_eam_cd.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/MANYBODY/pair_eam_cd.cpp b/src/MANYBODY/pair_eam_cd.cpp index 46d439b879..dc1ec360c6 100644 --- a/src/MANYBODY/pair_eam_cd.cpp +++ b/src/MANYBODY/pair_eam_cd.cpp @@ -499,10 +499,13 @@ void PairEAMCD::read_h_coeff(char *filename) // Seek to end of file, read last part into a buffer and // then skip over lines in buffer until reaching the end. - platform::fseek(fptr, platform::END_OF_FILE); - platform::fseek(fptr, platform::ftell(fptr) - MAXLINE); + if ( (platform::fseek(fptr, platform::END_OF_FILE) < 0) + || (platform::fseek(fptr, platform::ftell(fptr) - MAXLINE) < 0)) + error->one(FLERR,"Failure to seek to end-of-file for reading h(x) coeffs: {}", + utils::getsyserror()); + char *buf = new char[MAXLINE+1]; - fread(buf, 1, MAXLINE, fptr); + utils::sfread(FLERR, buf, 1, MAXLINE, fptr, filename, error); buf[MAXLINE] = '\0'; // must 0-terminate buffer for string processing Tokenizer lines(buf, "\n"); delete[] buf; From 2213eb8d3f090e88d06a977423e8d240e7201d35 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 14 Jan 2022 14:45:12 -0500 Subject: [PATCH 04/22] use enum with symbolic constants instead of numbers --- src/output.cpp | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/output.cpp b/src/output.cpp index a8fda4173d..4156c6fc5e 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -41,6 +41,8 @@ using namespace LAMMPS_NS; #define DELTA 1 #define EPSDT 1.0e-6 +enum {SETUP, WRITE, RESET_DT}; + /* ---------------------------------------------------------------------- initialize all output ------------------------------------------------------------------------- */ @@ -232,7 +234,7 @@ void Output::setup(int memflag) // only do this if dump written or dump has not been written yet if (writeflag || last_dump[idump] < 0) - calculate_next_dump(0,idump,ntimestep); + calculate_next_dump(SETUP,idump,ntimestep); // if dump not written now, use addstep_compute_all() // since don't know what computes the dump will invoke @@ -361,7 +363,7 @@ void Output::setup(int memflag) dump[idump]->write(); last_dump[idump] = ntimestep; - calculate_next_dump(1,idump,ntimestep); + calculate_next_dump(WRITE,idump,ntimestep); if (mode_dump[idump] == 0 && (dump[idump]->clearstep || var_dump[idump])) @@ -468,9 +470,9 @@ void Output::setup(int memflag) for timestep mode, set next_dump for simulation time mode, set next_time_dump and next_dump which flag depends on caller - 0 = from setup() at start of run - 1 = from write() during run each time a dump file is written - 2 = from reset_dt() called from fix dt/reset when it changes timestep size + SETUP = from setup() at start of run + WRITE = from write() during run each time a dump file is written + RESET_DT = from reset_dt() called from fix dt/reset when it changes timestep size ------------------------------------------------------------------------- */ void Output::calculate_next_dump(int which, int idump, bigint ntimestep) @@ -482,13 +484,13 @@ void Output::setup(int memflag) if (every_dump[idump]) { - // which = 0: nextdump = next multiple of every_dump - // which = 1: increment nextdump by every_dump + // which = SETUP: nextdump = next multiple of every_dump + // which = WRITE: increment nextdump by every_dump - if (which == 0) + if (which == SETUP) next_dump[idump] = (ntimestep/every_dump[idump])*every_dump[idump] + every_dump[idump]; - else if (which == 1) + else if (which == WRITE) next_dump[idump] += every_dump[idump]; } else { @@ -510,17 +512,28 @@ void Output::setup(int memflag) if (every_time_dump[idump] > 0.0) { - // which = 0: nexttime = next multiple of every_time_dump - // which = 1: increment nexttime by every_time_dump - // which = 2: no change to previous nexttime (only timestep has changed) + // which = SETUP: nexttime = next multiple of every_time_dump + // which = WRITE: increment nexttime by every_time_dump + // which = RESET_DT: no change to previous nexttime (only timestep has changed) - if (which == 0) + switch (which) { + case SETUP: nexttime = static_cast (tcurrent/every_time_dump[idump]) * every_time_dump[idump] + every_time_dump[idump]; - else if (which == 1) + break; + + case WRITE: nexttime = next_time_dump[idump] + every_time_dump[idump]; - else if (which == 2) + break; + + case RESET_DT: nexttime = next_time_dump[idump]; + break; + + default: + nexttime = 0; + error->all(FLERR,"Unexpected argument to calculate_next_dump"); + } nextdump = ntimestep + static_cast ((nexttime - tcurrent - EPSDT*update->dt) / @@ -541,10 +554,10 @@ void Output::setup(int memflag) } else { - // do not re-evaulate variable for which = 2, leave nexttime as-is + // do not re-evaulate variable for which = RESET_DT, leave nexttime as-is // unless next_time_dump < 0.0, which means variable never yet evaluated - if (which < 2 || next_time_dump[idump] < 0.0) { + if (which < RESET_DT || next_time_dump[idump] < 0.0) { nexttime = input->variable->compute_equal(ivar_dump[idump]); } else nexttime = next_time_dump[idump]; @@ -704,7 +717,7 @@ void Output::reset_dt() // since timestep change affects next step if (next_dump[idump] != ntimestep) - calculate_next_dump(2,idump,update->ntimestep); + calculate_next_dump(RESET_DT,idump,update->ntimestep); if (dump[idump]->clearstep || var_dump[idump]) next_time_dump_any = MIN(next_time_dump_any,next_dump[idump]); From dcb1ddb28272e87d76058c5bc2b7c2d9d90ca48c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 14 Jan 2022 14:55:13 -0500 Subject: [PATCH 05/22] remove redundant code --- src/fix_move.cpp | 63 ++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/src/fix_move.cpp b/src/fix_move.cpp index 72fd9b75d2..f7bc4d3640 100644 --- a/src/fix_move.cpp +++ b/src/fix_move.cpp @@ -522,7 +522,7 @@ void FixMove::initial_integrate(int /*vflag*/) } } - // for wiggle: X = X0 + A sin(w*dt) + // for wiggle: X = X0 + A sin(w*dt) } else if (mstyle == WIGGLE) { double arg = omega_rotate * delta; @@ -578,19 +578,19 @@ void FixMove::initial_integrate(int /*vflag*/) } } - // for rotate by right-hand rule around omega: - // P = point = vector = point of rotation - // R = vector = axis of rotation - // w = omega of rotation (from period) - // X0 = xoriginal = initial coord of atom - // R0 = runit = unit vector for R - // D = X0 - P = vector from P to X0 - // C = (D dot R0) R0 = projection of atom coord onto R line - // A = D - C = vector from R line to X0 - // B = R0 cross A = vector perp to A in plane of rotation - // A,B define plane of circular rotation around R line - // X = P + C + A cos(w*dt) + B sin(w*dt) - // V = w R0 cross (A cos(w*dt) + B sin(w*dt)) + // for rotate by right-hand rule around omega: + // P = point = vector = point of rotation + // R = vector = axis of rotation + // w = omega of rotation (from period) + // X0 = xoriginal = initial coord of atom + // R0 = runit = unit vector for R + // D = X0 - P = vector from P to X0 + // C = (D dot R0) R0 = projection of atom coord onto R line + // A = D - C = vector from R line to X0 + // B = R0 cross A = vector perp to A in plane of rotation + // A,B define plane of circular rotation around R line + // X = P + C + A cos(w*dt) + B sin(w*dt) + // V = w R0 cross (A cos(w*dt) + B sin(w*dt)) } else if (mstyle == ROTATE) { double arg = omega_rotate * delta; @@ -707,10 +707,10 @@ void FixMove::initial_integrate(int /*vflag*/) } } - // for variable: compute x,v from variables - // NOTE: also allow for changes to extra attributes? - // omega, angmom, theta, quat - // only necessary if prescribed motion involves rotation + // for variable: compute x,v from variables + // NOTE: also allow for changes to extra attributes? + // omega, angmom, theta, quat + // only necessary if prescribed motion involves rotation } else if (mstyle == VARIABLE) { @@ -778,21 +778,16 @@ void FixMove::initial_integrate(int /*vflag*/) } else if (vxvarstr) { if (vxvarstyle == EQUAL) v[i][0] = vx; else v[i][0] = velocity[i][0]; - if (rmass) { - x[i][0] += dtv * v[i][0]; - } else { - x[i][0] += dtv * v[i][0]; - } + x[i][0] += dtv * v[i][0]; } else { if (rmass) { dtfm = dtf / rmass[i]; v[i][0] += dtfm * f[i][0]; - x[i][0] += dtv * v[i][0]; } else { dtfm = dtf / mass[type[i]]; v[i][0] += dtfm * f[i][0]; - x[i][0] += dtv * v[i][0]; } + x[i][0] += dtv * v[i][0]; } if (yvarstr && vyvarstr) { @@ -806,21 +801,16 @@ void FixMove::initial_integrate(int /*vflag*/) } else if (vyvarstr) { if (vyvarstyle == EQUAL) v[i][1] = vy; else v[i][1] = velocity[i][1]; - if (rmass) { - x[i][1] += dtv * v[i][1]; - } else { - x[i][1] += dtv * v[i][1]; - } + x[i][1] += dtv * v[i][1]; } else { if (rmass) { dtfm = dtf / rmass[i]; v[i][1] += dtfm * f[i][1]; - x[i][1] += dtv * v[i][1]; } else { dtfm = dtf / mass[type[i]]; v[i][1] += dtfm * f[i][1]; - x[i][1] += dtv * v[i][1]; } + x[i][1] += dtv * v[i][1]; } if (zvarstr && vzvarstr) { @@ -834,21 +824,16 @@ void FixMove::initial_integrate(int /*vflag*/) } else if (vzvarstr) { if (vzvarstyle == EQUAL) v[i][2] = vz; else v[i][2] = velocity[i][2]; - if (rmass) { - x[i][2] += dtv * v[i][2]; - } else { - x[i][2] += dtv * v[i][2]; - } + x[i][2] += dtv * v[i][2]; } else { if (rmass) { dtfm = dtf / rmass[i]; v[i][2] += dtfm * f[i][2]; - x[i][2] += dtv * v[i][2]; } else { dtfm = dtf / mass[type[i]]; v[i][2] += dtfm * f[i][2]; - x[i][2] += dtv * v[i][2]; } + x[i][2] += dtv * v[i][2]; } domain->remap_near(x[i],xold); From ed702b930928584017f70a5d83a4b32304e8e1d5 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 14 Jan 2022 15:58:57 -0500 Subject: [PATCH 06/22] don't allow exceptions to "escape" a destructor --- src/REAXFF/fix_reaxff_species.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/REAXFF/fix_reaxff_species.cpp b/src/REAXFF/fix_reaxff_species.cpp index 4f44cc7c64..bed7fabb20 100644 --- a/src/REAXFF/fix_reaxff_species.cpp +++ b/src/REAXFF/fix_reaxff_species.cpp @@ -246,8 +246,10 @@ FixReaxFFSpecies::~FixReaxFFSpecies() if (posflag && multipos_opened) fclose(pos); } - modify->delete_compute(fmt::format("SPECATOM_{}",id)); - modify->delete_fix(fmt::format("SPECBOND_{}",id)); + try { + modify->delete_compute(fmt::format("SPECATOM_{}",id)); + modify->delete_fix(fmt::format("SPECBOND_{}",id)); + } catch (std::exception &) {} } /* ---------------------------------------------------------------------- */ From 11cc8a6a5928548a186f7b5536d00ff186f5ded0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 14 Jan 2022 15:59:05 -0500 Subject: [PATCH 07/22] whitespace --- src/output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/output.cpp b/src/output.cpp index 4156c6fc5e..6c14900ade 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -475,7 +475,7 @@ void Output::setup(int memflag) RESET_DT = from reset_dt() called from fix dt/reset when it changes timestep size ------------------------------------------------------------------------- */ - void Output::calculate_next_dump(int which, int idump, bigint ntimestep) +void Output::calculate_next_dump(int which, int idump, bigint ntimestep) { // dump mode is by timestep // just set next_dump From e271a54802014cefd7e8d71de3fa9e125540e84a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 14 Jan 2022 20:25:00 -0500 Subject: [PATCH 08/22] re-enable using rerun after the changes from PR #3052 --- src/output.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/output.cpp b/src/output.cpp index a8fda4173d..b2b8011842 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -619,9 +619,8 @@ int Output::check_time_dumps(bigint ntimestep) { next_dump_any = MAXBIGINT; for (int idump = 0; idump < ndump; idump++) - if (last_dump[idump] >= 0) - error->all(FLERR, - "Cannot reset timestep with active dump - must undump first"); + if ((last_dump[idump] >= 0) && !update->whichflag) + error->all(FLERR, "Cannot reset timestep with active dump - must undump first"); if (restart_flag_single) { if (restart_every_single) { From 943fe487b54f165796c77a2e1b2a6b44012f3a9d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 16 Jan 2022 15:36:01 -0500 Subject: [PATCH 09/22] update whitespace and argument formats for longer source lines --- src/molecule.cpp | 222 +++++++++++++++++------------------------------ 1 file changed, 81 insertions(+), 141 deletions(-) diff --git a/src/molecule.cpp b/src/molecule.cpp index 40ca218ecc..d6c839dfc4 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -57,8 +57,7 @@ Molecule::Molecule(LAMMPS *lmp, int narg, char **arg, int &index) : id = utils::strdup(arg[0]); if (!utils::is_id(id)) - error->all(FLERR,"Molecule template ID must have only " - "alphanumeric or underscore characters"); + error->all(FLERR,"Molecule template ID must have only alphanumeric or underscore characters"); // parse args until reach unknown arg (next file) @@ -130,8 +129,7 @@ Molecule::Molecule(LAMMPS *lmp, int narg, char **arg, int &index) : if (me == 0) { fp = fopen(arg[ifile],"r"); if (fp == nullptr) - error->one(FLERR,"Cannot open molecule file {}: {}", - arg[ifile], utils::getsyserror()); + error->one(FLERR,"Cannot open molecule file {}: {}",arg[ifile], utils::getsyserror()); } read(0); if (me == 0) fclose(fp); @@ -496,8 +494,7 @@ void Molecule::read(int flag) if (nmatch != nwant) error->one(FLERR,"Invalid header line format in molecule file"); } catch (TokenizerException &e) { - error->one(FLERR, "Invalid header in molecule file\n" - "{}", e.what()); + error->one(FLERR,"Invalid header in molecule file: {}", e.what()); } } @@ -618,11 +615,9 @@ void Molecule::read(int flag) // Error: Either a too long/short section or a typo in the keyword if (utils::strmatch(keyword,"^[A-Za-z ]+$")) - error->one(FLERR,"Unknown section '{}' in molecule " - "file\n",keyword); + error->one(FLERR,"Unknown section '{}' in molecule file\n",keyword); else error->one(FLERR,"Unexpected line in molecule file " - "while looking for the next " - "section:\n{}",line); + "while looking for the next section:\n{}",line); } keyword = parse_keyword(1,line); } @@ -648,8 +643,7 @@ void Molecule::read(int flag) if (bondflag && specialflag == 0) { if (domain->box_exist == 0) - error->all(FLERR,"Cannot auto-generate special bonds before " - "simulation box is defined"); + error->all(FLERR,"Cannot auto-generate special bonds before simulation box is defined"); if (flag) { special_generate(); @@ -691,8 +685,7 @@ void Molecule::coords(char *line) ValueTokenizer values(utils::trim_comment(line)); if (values.count() != 4) - error->all(FLERR,"Invalid line in Coords section of " - "molecule file: {}",line); + error->all(FLERR,"Invalid line in Coords section of molecule file: {}",line); int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) @@ -707,19 +700,16 @@ void Molecule::coords(char *line) x[iatom][2] *= sizescale; } } catch (TokenizerException &e) { - error->all(FLERR,"Invalid line in Coords section of " - "molecule file: {}\n{}",e.what(),line); + error->all(FLERR,"Invalid line in Coords section of molecule file: {}\n{}",e.what(),line); } for (int i = 0; i < natoms; i++) - if (count[i] == 0) error->all(FLERR,"Atom {} missing in Coords " - "section of molecule file",i+1); + if (count[i] == 0) error->all(FLERR,"Atom {} missing in Coords section of molecule file",i+1); if (domain->dimension == 2) { for (int i = 0; i < natoms; i++) if (x[i][2] != 0.0) - error->all(FLERR,"Z coord in molecule file for atom {} " - "must be 0.0 for 2d-simulation.",i+1); + error->all(FLERR,"Z coord in molecule file for atom {} must be 0.0 for 2d-simulation",i+1); } } @@ -737,8 +727,7 @@ void Molecule::types(char *line) ValueTokenizer values(utils::trim_comment(line)); if (values.count() != 2) - error->all(FLERR,"Invalid line in Types section of " - "molecule file: {}",line); + error->all(FLERR,"Invalid line in Types section of molecule file: {}",line); int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) @@ -748,17 +737,14 @@ void Molecule::types(char *line) type[iatom] += toffset; } } catch (TokenizerException &e) { - error->all(FLERR, "Invalid line in Types section of " - "molecule file: {}\n{}", e.what(),line); + error->all(FLERR,"Invalid line in Types section of molecule file: {}\n{}",e.what(),line); } for (int i = 0; i < natoms; i++) { - if (count[i] == 0) error->all(FLERR,"Atom {} missing in Types " - "section of molecule file",i+1); + if (count[i] == 0) error->all(FLERR,"Atom {} missing in Types section of molecule file",i+1); if ((type[i] <= 0) || (domain->box_exist && (type[i] > atom->ntypes))) - error->all(FLERR,"Invalid atom type {} for atom {} " - "in molecule file",type[i],i+1); + error->all(FLERR,"Invalid atom type {} for atom {} in molecule file",type[i],i+1); ntypes = MAX(ntypes,type[i]); } @@ -777,8 +763,7 @@ void Molecule::molecules(char *line) readline(line); ValueTokenizer values(utils::trim_comment(line)); if (values.count() != 2) - error->all(FLERR,"Invalid line in Molecules section of " - "molecule file: {}",line); + error->all(FLERR,"Invalid line in Molecules section of molecule file: {}",line); int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) @@ -788,19 +773,17 @@ void Molecule::molecules(char *line) // molecule[iatom] += moffset; // placeholder for possible molecule offset } } catch (TokenizerException &e) { - error->all(FLERR, "Invalid line in Molecules section of " - "molecule file: {}\n{}",e.what(),line); + error->all(FLERR,"Invalid line in Molecules section of molecule file: {}\n{}",e.what(),line); } - for (int i = 0; i < natoms; i++) - if (count[i] == 0) error->all(FLERR,"Atom {} missing in Molecules " - "section of molecule file",i+1); - - for (int i = 0; i < natoms; i++) + for (int i = 0; i < natoms; i++) { + if (count[i] == 0) + error->all(FLERR,"Atom {} missing in Molecules section of molecule file",i+1); + } + for (int i = 0; i < natoms; i++) { if (molecule[i] < 0) - error->all(FLERR,"Invalid molecule ID {} for atom {} " - "in molecule file",molecule[i],i+1); - + error->all(FLERR,"Invalid molecule ID {} for atom {} in molecule file",molecule[i],i+1); + } for (int i = 0; i < natoms; i++) nmolecules = MAX(nmolecules,molecule[i]); } @@ -818,23 +801,21 @@ void Molecule::fragments(char *line) ValueTokenizer values(utils::trim_comment(line)); if ((int)values.count() > natoms+1) - error->all(FLERR,"Too many atoms per fragment in Fragments " - "section of molecule file"); + error->all(FLERR,"Too many atoms per fragment in Fragments section of molecule file"); fragmentnames[i] = values.next_string(); while (values.has_next()) { int iatom = values.next_int()-1; if (iatom < 0 || iatom >= natoms) - error->all(FLERR,"Invalid atom ID {} for fragment {} in " - "Fragments section of molecule file", - iatom+1, fragmentnames[i]); + error->all(FLERR,"Invalid atom ID {} for fragment {} in Fragments section of " + "molecule file", iatom+1, fragmentnames[i]); fragmentmask[i][iatom] = 1; } } } catch (TokenizerException &e) { - error->all(FLERR, "Invalid atom ID in Fragments section of " - "molecule file: {}\n{}", e.what(),line); + error->all(FLERR,"Invalid atom ID in Fragments section of " + "molecule file: {}\n{}", e.what(),line); } } @@ -851,8 +832,7 @@ void Molecule::charges(char *line) ValueTokenizer values(utils::trim_comment(line)); if ((int)values.count() != 2) - error->all(FLERR,"Invalid line in Charges section of " - "molecule file: {}",line); + error->all(FLERR,"Invalid line in Charges section of molecule file: {}",line); int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) @@ -862,13 +842,13 @@ void Molecule::charges(char *line) q[iatom] = values.next_double(); } } catch (TokenizerException &e) { - error->all(FLERR, "Invalid line in Charges section of " - "molecule file: {}.\n{}",e.what(),line); + error->all(FLERR,"Invalid line in Charges section of molecule file: {}\n{}",e.what(),line); } - for (int i = 0; i < natoms; i++) - if (count[i] == 0) error->all(FLERR,"Atom {} missing in Charges " - "section of molecule file",i+1); + for (int i = 0; i < natoms; i++) { + if (count[i] == 0) + error->all(FLERR,"Atom {} missing in Charges section of molecule file",i+1); + } } /* ---------------------------------------------------------------------- @@ -885,8 +865,7 @@ void Molecule::diameters(char *line) ValueTokenizer values(utils::trim_comment(line)); if (values.count() != 2) - error->all(FLERR,"Invalid line in Diameters section of " - "molecule file: {}",line); + error->all(FLERR,"Invalid line in Diameters section of molecule file: {}",line); int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) error->all(FLERR,"Invalid atom index in Diameters section of molecule file"); @@ -897,16 +876,14 @@ void Molecule::diameters(char *line) maxradius = MAX(maxradius,radius[iatom]); } } catch (TokenizerException &e) { - error->all(FLERR, "Invalid line in Diameters section of " - "molecule file: {}\n{}",e.what(),line); + error->all(FLERR,"Invalid line in Diameters section of molecule file: {}\n{}",e.what(),line); } for (int i = 0; i < natoms; i++) { - if (count[i] == 0) error->all(FLERR,"Atom {} missing in Diameters " - "section of molecule file",i+1); + if (count[i] == 0) + error->all(FLERR,"Atom {} missing in Diameters section of molecule file",i+1); if (radius[i] < 0.0) - error->all(FLERR,"Invalid atom diameter {} for atom {} " - "in molecule file", radius[i], i+1); + error->all(FLERR,"Invalid atom diameter {} for atom {} in molecule file", radius[i], i+1); } } @@ -923,8 +900,7 @@ void Molecule::masses(char *line) ValueTokenizer values(utils::trim_comment(line)); if (values.count() != 2) - error->all(FLERR,"Invalid line in Masses section of " - "molecule file: {}",line); + error->all(FLERR,"Invalid line in Masses section of molecule file: {}",line); int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) @@ -934,8 +910,7 @@ void Molecule::masses(char *line) rmass[iatom] *= sizescale*sizescale*sizescale; } } catch (TokenizerException &e) { - error->all(FLERR, "Invalid line in Masses section of " - "molecule file: {}\n{}",e.what(),line); + error->all(FLERR,"Invalid line in Masses section of molecule file: {}\n{}",e.what(),line); } for (int i = 0; i < natoms; i++) { @@ -972,15 +947,13 @@ void Molecule::bonds(int flag, char *line) try { ValueTokenizer values(utils::trim_comment(line)); if (values.count() != 4) - error->all(FLERR,"Invalid line in Bonds section of " - "molecule file: {}",line); + error->all(FLERR,"Invalid line in Bonds section of molecule file: {}",line); values.next_int(); itype = values.next_int(); atom1 = values.next_tagint(); atom2 = values.next_tagint(); } catch (TokenizerException &e) { - error->all(FLERR, "Invalid line in Bonds section of " - "molecule file: {}\n{}",e.what(),line); + error->all(FLERR,"Invalid line in Bonds section of molecule file: {}\n{}",e.what(),line); } itype += boffset; @@ -1042,16 +1015,14 @@ void Molecule::angles(int flag, char *line) try { ValueTokenizer values(utils::trim_comment(line)); if (values.count() != 5) - error->all(FLERR,"Invalid line in Angles section of " - "molecule file: {}",line); + error->all(FLERR,"Invalid line in Angles section of molecule file: {}",line); values.next_int(); itype = values.next_int(); atom1 = values.next_tagint(); atom2 = values.next_tagint(); atom3 = values.next_tagint(); } catch (TokenizerException &e) { - error->all(FLERR, "Invalid line in Angles section of " - "molecule file: {}\n{}",e.what(),line); + error->all(FLERR,"Invalid line in Angles section of molecule file: {}\n{}",e.what(),line); } itype += aoffset; @@ -1128,8 +1099,7 @@ void Molecule::dihedrals(int flag, char *line) try { ValueTokenizer values(utils::trim_comment(line)); if (values.count() != 6) - error->all(FLERR,"Invalid line in Dihedrals section of " - "molecule file: {}",line); + error->all(FLERR,"Invalid line in Dihedrals section of molecule file: {}",line); values.next_int(); itype = values.next_int(); @@ -1138,8 +1108,7 @@ void Molecule::dihedrals(int flag, char *line) atom3 = values.next_tagint(); atom4 = values.next_tagint(); } catch (TokenizerException &e) { - error->all(FLERR, "Invalid line in Dihedrals section of " - "molecule file: {}\n{}",e.what(),line); + error->all(FLERR,"Invalid line in Dihedrals section of molecule file: {}\n{}",e.what(),line); } itype += doffset; @@ -1150,8 +1119,7 @@ void Molecule::dihedrals(int flag, char *line) (atom4 <= 0) || (atom4 > natoms) || (atom1 == atom2) || (atom1 == atom3) || (atom1 == atom4) || (atom2 == atom3) || (atom2 == atom4) || (atom3 == atom4)) - error->all(FLERR, - "Invalid atom ID in dihedrals section of molecule file"); + error->all(FLERR,"Invalid atom ID in dihedrals section of molecule file"); if ((itype <= 0) || (domain->box_exist && (itype > atom->ndihedraltypes))) error->all(FLERR,"Invalid dihedral type in Dihedrals section of molecule file"); @@ -1230,8 +1198,7 @@ void Molecule::impropers(int flag, char *line) try { ValueTokenizer values(utils::trim_comment(line)); if (values.count() != 6) - error->all(FLERR,"Invalid line in Impropers section of " - "molecule file: {}",line); + error->all(FLERR,"Invalid line in Impropers section of molecule file: {}",line); values.next_int(); itype = values.next_int(); atom1 = values.next_tagint(); @@ -1239,8 +1206,7 @@ void Molecule::impropers(int flag, char *line) atom3 = values.next_tagint(); atom4 = values.next_tagint(); } catch (TokenizerException &e) { - error->all(FLERR, "Invalid line in Impropers section of " - "molecule file: {}\n{}",e.what(),line); + error->all(FLERR,"Invalid line in Impropers section of molecule file: {}\n{}",e.what(),line); } itype += ioffset; @@ -1251,8 +1217,7 @@ void Molecule::impropers(int flag, char *line) (atom4 <= 0) || (atom4 > natoms) || (atom1 == atom2) || (atom1 == atom3) || (atom1 == atom4) || (atom2 == atom3) || (atom2 == atom4) || (atom3 == atom4)) - error->all(FLERR, - "Invalid atom ID in impropers section of molecule file"); + error->all(FLERR,"Invalid atom ID in impropers section of molecule file"); if ((itype <= 0) || (domain->box_exist && (itype > atom->nimpropertypes))) error->all(FLERR,"Invalid improper type in Impropers section of molecule file"); @@ -1325,15 +1290,14 @@ void Molecule::nspecial_read(int flag, char *line) try { ValueTokenizer values(utils::trim_comment(line)); if (values.count() != 4) - error->all(FLERR,"Invalid line in Special Bond Counts section of " - "molecule file: {}",line); + error->all(FLERR,"Invalid line in Special Bond Counts section of molecule file: {}",line); values.next_int(); c1 = values.next_tagint(); c2 = values.next_tagint(); c3 = values.next_tagint(); } catch (TokenizerException &e) { - error->all(FLERR, "Invalid line in Special Bond Counts section of " - "molecule file: {}\n{}",e.what(),line); + error->all(FLERR,"Invalid line in Special Bond Counts section of " + "molecule file: {}\n{}",e.what(),line); } if (flag) { @@ -1358,8 +1322,7 @@ void Molecule::special_read(char *line) int nwords = values.count(); if (nwords != nspecial[i][2]+1) - error->all(FLERR,"Molecule file special list " - "does not match special count"); + error->all(FLERR,"Molecule file special list does not match special count"); values.next_int(); // ignore @@ -1367,13 +1330,12 @@ void Molecule::special_read(char *line) special[i][m-1] = values.next_tagint(); if (special[i][m-1] <= 0 || special[i][m-1] > natoms || special[i][m-1] == i+1) - error->all(FLERR,"Invalid atom index in Special Bonds " - "section of molecule file"); + error->all(FLERR,"Invalid atom index in Special Bonds section of molecule file"); } } } catch (TokenizerException &e) { - error->all(FLERR, "Invalid line in Special Bonds section of " - "molecule file: {}\n{}",e.what(),line); + error->all(FLERR,"Invalid line in Special Bonds section of " + "molecule file: {}\n{}",e.what(),line); } } @@ -1502,8 +1464,7 @@ void Molecule::shakeflag_read(char *line) shake_flag[i] = values.next_int(); } } catch (TokenizerException &e) { - error->all(FLERR, "Invalid Shake Flags section in molecule file\n" - "{}", e.what()); + error->all(FLERR,"Invalid Shake Flags section in molecule file: {}", e.what()); } for (int i = 0; i < natoms; i++) @@ -1572,8 +1533,7 @@ void Molecule::shakeatom_read(char *line) } } catch (TokenizerException &e) { - error->all(FLERR,"Invalid shake atom in molecule file\n" - "{}", e.what()); + error->all(FLERR,"Invalid shake atom in molecule file: {}", e.what()); } for (int i = 0; i < natoms; i++) { @@ -1642,8 +1602,7 @@ void Molecule::shaketype_read(char *line) error->all(FLERR,"Invalid shake type data in molecule file"); } } catch (TokenizerException &e) { - error->all(FLERR, "Invalid shake type data in molecule file\n", - "{}", e.what()); + error->all(FLERR,"Invalid shake type data in molecule file: {}",e.what()); } for (int i = 0; i < natoms; i++) { @@ -1695,8 +1654,7 @@ void Molecule::body(int flag, int pflag, char *line) } else nword += ncount; } } catch (TokenizerException &e) { - error->all(FLERR, "Invalid body params in molecule file\n", - "{}", e.what()); + error->all(FLERR,"Invalid body params in molecule file: {}", e.what()); } } @@ -1735,8 +1693,7 @@ void Molecule::check_attributes(int flag) if (onemol->rmassflag && !atom->rmass_flag) mismatch = 1; if (mismatch && me == 0) - error->warning(FLERR, - "Molecule attributes do not match system attributes"); + error->warning(FLERR,"Molecule attributes do not match system attributes"); // for all atom styles, check nbondtype,etc @@ -1770,8 +1727,7 @@ void Molecule::check_attributes(int flag) // warn if molecule topology defined but no special settings if (onemol->bondflag && !onemol->specialflag) - if (me == 0) error->warning(FLERR,"Molecule has bond topology " - "but no special bond settings"); + if (me == 0) error->warning(FLERR,"Molecule has bond topology but no special bond settings"); } } @@ -1878,47 +1834,31 @@ void Molecule::allocate() memory->create(special,natoms,maxspecial,"molecule:special"); if (bondflag) { - memory->create(bond_type,natoms,bond_per_atom, - "molecule:bond_type"); - memory->create(bond_atom,natoms,bond_per_atom, - "molecule:bond_atom"); + memory->create(bond_type,natoms,bond_per_atom,"molecule:bond_type"); + memory->create(bond_atom,natoms,bond_per_atom,"molecule:bond_atom"); } if (angleflag) { - memory->create(angle_type,natoms,angle_per_atom, - "molecule:angle_type"); - memory->create(angle_atom1,natoms,angle_per_atom, - "molecule:angle_atom1"); - memory->create(angle_atom2,natoms,angle_per_atom, - "molecule:angle_atom2"); - memory->create(angle_atom3,natoms,angle_per_atom, - "molecule:angle_atom3"); + memory->create(angle_type,natoms,angle_per_atom,"molecule:angle_type"); + memory->create(angle_atom1,natoms,angle_per_atom,"molecule:angle_atom1"); + memory->create(angle_atom2,natoms,angle_per_atom,"molecule:angle_atom2"); + memory->create(angle_atom3,natoms,angle_per_atom,"molecule:angle_atom3"); } if (dihedralflag) { - memory->create(dihedral_type,natoms,dihedral_per_atom, - "molecule:dihedral_type"); - memory->create(dihedral_atom1,natoms,dihedral_per_atom, - "molecule:dihedral_atom1"); - memory->create(dihedral_atom2,natoms,dihedral_per_atom, - "molecule:dihedral_atom2"); - memory->create(dihedral_atom3,natoms,dihedral_per_atom, - "molecule:dihedral_atom3"); - memory->create(dihedral_atom4,natoms,dihedral_per_atom, - "molecule:dihedral_atom4"); + memory->create(dihedral_type,natoms,dihedral_per_atom,"molecule:dihedral_type"); + memory->create(dihedral_atom1,natoms,dihedral_per_atom,"molecule:dihedral_atom1"); + memory->create(dihedral_atom2,natoms,dihedral_per_atom,"molecule:dihedral_atom2"); + memory->create(dihedral_atom3,natoms,dihedral_per_atom,"molecule:dihedral_atom3"); + memory->create(dihedral_atom4,natoms,dihedral_per_atom,"molecule:dihedral_atom4"); } if (improperflag) { - memory->create(improper_type,natoms,improper_per_atom, - "molecule:improper_type"); - memory->create(improper_atom1,natoms,improper_per_atom, - "molecule:improper_atom1"); - memory->create(improper_atom2,natoms,improper_per_atom, - "molecule:improper_atom2"); - memory->create(improper_atom3,natoms,improper_per_atom, - "molecule:improper_atom3"); - memory->create(improper_atom4,natoms,improper_per_atom, - "molecule:improper_atom4"); + memory->create(improper_type,natoms,improper_per_atom,"molecule:improper_type"); + memory->create(improper_atom1,natoms,improper_per_atom,"molecule:improper_atom1"); + memory->create(improper_atom2,natoms,improper_per_atom,"molecule:improper_atom2"); + memory->create(improper_atom3,natoms,improper_per_atom,"molecule:improper_atom3"); + memory->create(improper_atom4,natoms,improper_per_atom,"molecule:improper_atom4"); } if (shakeflag) { @@ -2058,7 +1998,7 @@ void Molecule::skip_lines(int n, char *line, const std::string §ion) readline(line); if (utils::strmatch(utils::trim(utils::trim_comment(line)),"^[A-Za-z ]+$")) error->one(FLERR,"Unexpected line in molecule file while " - "skipping {} section:\n{}",section,line); + "skipping {} section:\n{}",section,line); } } From 0eeb3b203cf84fcde15a6b34f2c239d8045ba33d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 16 Jan 2022 16:50:23 -0500 Subject: [PATCH 10/22] add tests for molecule command --- unittest/formats/test_molecule_file.cpp | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/unittest/formats/test_molecule_file.cpp b/unittest/formats/test_molecule_file.cpp index 2cca7a6832..e802ebfa2c 100644 --- a/unittest/formats/test_molecule_file.cpp +++ b/unittest/formats/test_molecule_file.cpp @@ -176,6 +176,33 @@ TEST_F(MoleculeFileTest, minimal) ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*")); } +TEST_F(MoleculeFileTest, notype) +{ + BEGIN_CAPTURE_OUTPUT(); + command("atom_style atomic"); + command("region box block 0 1 0 1 0 1"); + command("create_box 1 box"); + run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n"); + auto output = END_CAPTURE_OUTPUT(); + ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*")); + TEST_FAILURE(".*ERROR: Create_atoms molecule must have atom types.*", + command("create_atoms 0 single 0.0 0.0 0.0 mol notype 542465");); + } + +TEST_F(MoleculeFileTest, extramass) +{ + BEGIN_CAPTURE_OUTPUT(); + command("atom_style atomic"); + command("region box block 0 1 0 1 0 1"); + command("create_box 1 box"); + run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n" + " Types\n\n 1 1\n Masses\n\n 1 1.0\n"); + command("create_atoms 0 single 0.0 0.0 0.0 mol extramass 73546"); + auto output = END_CAPTURE_OUTPUT(); + ASSERT_THAT(output, MatchesRegex(".*WARNING: Molecule attributes do not match " + "system attributes.*")); +} + TEST_F(MoleculeFileTest, twomols) { BEGIN_CAPTURE_OUTPUT(); From dc6e558191c756b64e9e01fc7505a40328c54491 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 16 Jan 2022 20:20:07 -0500 Subject: [PATCH 11/22] use Tokenizer class to parse bond colors --- src/dump_image.cpp | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/dump_image.cpp b/src/dump_image.cpp index c073d152f8..9aecb58120 100644 --- a/src/dump_image.cpp +++ b/src/dump_image.cpp @@ -1200,11 +1200,11 @@ int DumpImage::modify_param(int narg, char **arg) utils::bounds(FLERR,arg[1],1,atom->ntypes,nlo,nhi,error); // get list of colors + // assign colors in round-robin fashion to types + auto colors = Tokenizer(arg[2],"/").as_vector(); const int ncolors = colors.size(); - // assign colors in round-robin fashion to types - int m = 0; for (int i = nlo; i <= nhi; i++) { colortype[i] = image->color2rgb(colors[m%ncolors].c_str()); @@ -1249,32 +1249,19 @@ int DumpImage::modify_param(int narg, char **arg) int nlo,nhi; utils::bounds(FLERR,arg[1],1,atom->nbondtypes,nlo,nhi,error); - // ptrs = list of ncount colornames separated by '/' + // process list of ncount colornames separated by '/' + // assign colors in round-robin fashion to bond types - int ncount = 1; - char *nextptr; - char *ptr = arg[2]; - while ((nextptr = strchr(ptr,'/'))) { - ptr = nextptr + 1; - ncount++; - } - char **ptrs = new char*[ncount+1]; - ncount = 0; - ptrs[ncount++] = strtok(arg[2],"/"); - while ((ptrs[ncount++] = strtok(nullptr,"/"))); - ncount--; - - // assign each of ncount colors in round-robin fashion to types + auto colors = Tokenizer(arg[2],"/").as_vector(); + const int ncolors = colors.size(); int m = 0; for (int i = nlo; i <= nhi; i++) { - bcolortype[i] = image->color2rgb(ptrs[m%ncount]); + bcolortype[i] = image->color2rgb(colors[m%ncolors].c_str()); if (bcolortype[i] == nullptr) error->all(FLERR,"Invalid color in dump_modify command"); m++; } - - delete [] ptrs; return 3; } From 241a44f1afbed0ccdfb09ede418ea9f0443622ca Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jan 2022 04:56:47 -0500 Subject: [PATCH 12/22] another workaround for rerun --- src/dump.h | 1 + src/output.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dump.h b/src/dump.h index 35da154d7c..482e87a207 100644 --- a/src/dump.h +++ b/src/dump.h @@ -19,6 +19,7 @@ namespace LAMMPS_NS { class Dump : protected Pointers { + friend class Output; public: char *id; // user-defined name of Dump char *style; // style of Dump diff --git a/src/output.cpp b/src/output.cpp index 449077d1fb..1376d365d8 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -632,7 +632,7 @@ int Output::check_time_dumps(bigint ntimestep) { next_dump_any = MAXBIGINT; for (int idump = 0; idump < ndump; idump++) - if ((last_dump[idump] >= 0) && !update->whichflag) + if ((last_dump[idump] >= 0) && !update->whichflag && !dump[idump]->multifile) error->all(FLERR, "Cannot reset timestep with active dump - must undump first"); if (restart_flag_single) { From f0f4a8e6dc20c1c4afbfa3b758acb50a970fbd2d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jan 2022 06:01:32 -0500 Subject: [PATCH 13/22] plug some memory leaks in MSM kspace style(s) --- src/KSPACE/msm.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/KSPACE/msm.cpp b/src/KSPACE/msm.cpp index 2259d2f829..a980be227d 100644 --- a/src/KSPACE/msm.cpp +++ b/src/KSPACE/msm.cpp @@ -626,15 +626,19 @@ void MSM::allocate() gcall->setup(ngcall_buf1,ngcall_buf2); npergrid = 1; + memory->destroy(gcall_buf1); + memory->destroy(gcall_buf2); memory->create(gcall_buf1,npergrid*ngcall_buf1,"msm:gcall_buf1"); memory->create(gcall_buf2,npergrid*ngcall_buf2,"msm:gcall_buf2"); // allocate memory for each grid level for (int n=0; ndestroy3d_offset(qgrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]); memory->create3d_offset(qgrid[n],nzlo_out[n],nzhi_out[n], nylo_out[n],nyhi_out[n],nxlo_out[n],nxhi_out[n],"msm:qgrid"); + memory->destroy3d_offset(egrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]); memory->create3d_offset(egrid[n],nzlo_out[n],nzhi_out[n], nylo_out[n],nyhi_out[n],nxlo_out[n],nxhi_out[n],"msm:egrid"); @@ -654,6 +658,8 @@ void MSM::allocate() gc[n]->setup(ngc_buf1[n],ngc_buf2[n]); npergrid = 1; + memory->destroy(gc_buf1[n]); + memory->destroy(gc_buf2[n]); memory->create(gc_buf1[n],npergrid*ngc_buf1[n],"msm:gc_buf1"); memory->create(gc_buf2[n],npergrid*ngc_buf2[n],"msm:gc_buf2"); } else { @@ -835,11 +841,15 @@ void MSM::deallocate_levels() { if (world_levels) { for (int n=0; n < levels; ++n) { - if (qgrid[n]) + if (qgrid[n]) { memory->destroy3d_offset(qgrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]); + qgrid[n] = nullptr; + } - if (egrid[n]) + if (egrid[n]) { memory->destroy3d_offset(egrid[n],nzlo_out[n],nylo_out[n],nxlo_out[n]); + egrid[n] = nullptr; + } if (gc) { if (gc[n]) { From a02e11040d55e0b99683efd990f374bb446d869d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jan 2022 06:34:57 -0500 Subject: [PATCH 14/22] whitespace --- src/KSPACE/msm.cpp | 78 +++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/KSPACE/msm.cpp b/src/KSPACE/msm.cpp index a980be227d..4415175bf0 100644 --- a/src/KSPACE/msm.cpp +++ b/src/KSPACE/msm.cpp @@ -116,7 +116,7 @@ void MSM::settings(int narg, char **arg) MSM::~MSM() { - delete [] factors; + delete[] factors; deallocate(); if (peratom_allocate_flag) deallocate_peratom(); deallocate_levels(); @@ -867,57 +867,57 @@ void MSM::deallocate_levels() } } - delete [] ngrid; + delete[] ngrid; ngrid = nullptr; memory->destroy(procneigh_levels); - delete [] world_levels; - delete [] active_flag; + delete[] world_levels; + delete[] active_flag; - delete [] gc; - delete [] gc_buf1; - delete [] gc_buf2; - delete [] ngc_buf1; - delete [] ngc_buf2; + delete[] gc; + delete[] gc_buf1; + delete[] gc_buf2; + delete[] ngc_buf1; + delete[] ngc_buf2; - delete [] alpha; - delete [] betax; - delete [] betay; - delete [] betaz; + delete[] alpha; + delete[] betax; + delete[] betay; + delete[] betaz; - delete [] nx_msm; - delete [] ny_msm; - delete [] nz_msm; + delete[] nx_msm; + delete[] ny_msm; + delete[] nz_msm; - delete [] nxlo_in; - delete [] nylo_in; - delete [] nzlo_in; + delete[] nxlo_in; + delete[] nylo_in; + delete[] nzlo_in; - delete [] nxhi_in; - delete [] nyhi_in; - delete [] nzhi_in; + delete[] nxhi_in; + delete[] nyhi_in; + delete[] nzhi_in; - delete [] nxlo_out; - delete [] nylo_out; - delete [] nzlo_out; + delete[] nxlo_out; + delete[] nylo_out; + delete[] nzlo_out; - delete [] nxhi_out; - delete [] nyhi_out; - delete [] nzhi_out; + delete[] nxhi_out; + delete[] nyhi_out; + delete[] nzhi_out; - delete [] delxinv; - delete [] delyinv; - delete [] delzinv; + delete[] delxinv; + delete[] delyinv; + delete[] delzinv; - delete [] qgrid; - delete [] egrid; + delete[] qgrid; + delete[] egrid; - delete [] v0grid; - delete [] v1grid; - delete [] v2grid; - delete [] v3grid; - delete [] v4grid; - delete [] v5grid; + delete[] v0grid; + delete[] v1grid; + delete[] v2grid; + delete[] v3grid; + delete[] v4grid; + delete[] v5grid; world_levels = nullptr; active_flag = nullptr; From 752552e0f82b0a979494b9594a5a77e6ae767a7d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jan 2022 06:39:20 -0500 Subject: [PATCH 15/22] remove duplicate code --- src/KSPACE/msm.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/KSPACE/msm.cpp b/src/KSPACE/msm.cpp index 4415175bf0..09ea775ef4 100644 --- a/src/KSPACE/msm.cpp +++ b/src/KSPACE/msm.cpp @@ -67,33 +67,7 @@ MSM::MSM(LAMMPS *lmp) factors[0] = 2; MPI_Comm_rank(world,&me); - - phi1d = dphi1d = nullptr; - nmax = 0; - part2grid = nullptr; - - g_direct = nullptr; - g_direct_top = nullptr; - - v0_direct = v1_direct = v2_direct = nullptr; - v3_direct = v4_direct = v5_direct = nullptr; - - v0_direct_top = v1_direct_top = v2_direct_top = nullptr; - v3_direct_top = v4_direct_top = v5_direct_top = nullptr; - - ngrid = nullptr; - - alpha = betax = betay = betaz = nullptr; - nx_msm = ny_msm = nz_msm = nullptr; - nxlo_in = nylo_in = nzlo_in = nullptr; - nxhi_in = nyhi_in = nzhi_in = nullptr; - nxlo_out = nylo_out = nzlo_out = nullptr; - nxhi_out = nyhi_out = nzhi_out = nullptr; - delxinv = delyinv = delzinv = nullptr; - qgrid = nullptr; - egrid = nullptr; - v0grid = v1grid = v2grid = v3grid = v4grid = v5grid = nullptr; peratom_allocate_flag = 0; scalar_pressure_flag = 1; From 2e85233b11936c3b12ff8a8f528967d0a7fb5b5a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jan 2022 07:20:28 -0500 Subject: [PATCH 16/22] before changing box settings, it must be initialized at least once otherwise change_box would not really be needed, but commands like boundary can (still) be used --- src/change_box.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/change_box.cpp b/src/change_box.cpp index bbac78ab3d..a79b023ac3 100644 --- a/src/change_box.cpp +++ b/src/change_box.cpp @@ -24,6 +24,7 @@ #include "lattice.h" #include "modify.h" #include "output.h" +#include "update.h" #include #include @@ -201,8 +202,11 @@ void ChangeBox::command(int narg, char **arg) scale[0] = domain->lattice->xlattice; scale[1] = domain->lattice->ylattice; scale[2] = domain->lattice->zlattice; - } - else scale[0] = scale[1] = scale[2] = 1.0; + } else scale[0] = scale[1] = scale[2] = 1.0; + + // enforce initialization if there has not one before + + if (!update->first_update) lmp->init(); // perform sequence of operations // first insure atoms are in current box & update box via shrink-wrap @@ -282,9 +286,7 @@ void ChangeBox::command(int narg, char **arg) } else if (ops[m].style == BOUNDARY) { domain->set_boundary(3,&arg[ops[m].boundindex],1); if (domain->dimension == 2 && domain->zperiodic == 0) - error->all(FLERR, - "Cannot change box z boundary to " - "non-periodic for a 2d simulation"); + error->all(FLERR, "Cannot change box z boundary to non-periodic for a 2d simulation"); domain->set_initial_box(); domain->set_global_box(); domain->set_local_box(); From c1f7685c988998a901d1f56bd4237f736d16f518 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jan 2022 08:30:54 -0500 Subject: [PATCH 17/22] Revert "before changing box settings, it must be initialized at least once" Looking for alternate solution since this change has too many unwanted side effects. This reverts commit 2e85233b11936c3b12ff8a8f528967d0a7fb5b5a. --- src/change_box.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/change_box.cpp b/src/change_box.cpp index a79b023ac3..bbac78ab3d 100644 --- a/src/change_box.cpp +++ b/src/change_box.cpp @@ -24,7 +24,6 @@ #include "lattice.h" #include "modify.h" #include "output.h" -#include "update.h" #include #include @@ -202,11 +201,8 @@ void ChangeBox::command(int narg, char **arg) scale[0] = domain->lattice->xlattice; scale[1] = domain->lattice->ylattice; scale[2] = domain->lattice->zlattice; - } else scale[0] = scale[1] = scale[2] = 1.0; - - // enforce initialization if there has not one before - - if (!update->first_update) lmp->init(); + } + else scale[0] = scale[1] = scale[2] = 1.0; // perform sequence of operations // first insure atoms are in current box & update box via shrink-wrap @@ -286,7 +282,9 @@ void ChangeBox::command(int narg, char **arg) } else if (ops[m].style == BOUNDARY) { domain->set_boundary(3,&arg[ops[m].boundindex],1); if (domain->dimension == 2 && domain->zperiodic == 0) - error->all(FLERR, "Cannot change box z boundary to non-periodic for a 2d simulation"); + error->all(FLERR, + "Cannot change box z boundary to " + "non-periodic for a 2d simulation"); domain->set_initial_box(); domain->set_global_box(); domain->set_local_box(); From 29b5c2659cf8782f79af96f3a684e9cd6cf0bdbe Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jan 2022 09:04:04 -0500 Subject: [PATCH 18/22] source code formatting --- src/KSPACE/msm.cpp | 6 ++---- src/KSPACE/pppm.cpp | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/KSPACE/msm.cpp b/src/KSPACE/msm.cpp index 09ea775ef4..9fd581618f 100644 --- a/src/KSPACE/msm.cpp +++ b/src/KSPACE/msm.cpp @@ -1044,8 +1044,7 @@ void MSM::set_grid_global() } if (flag && gridflag && me == 0) - error->warning(FLERR, - "Number of MSM mesh points changed to be a multiple of 2"); + error->warning(FLERR, "Number of MSM mesh points changed to be a multiple of 2"); // adjust Coulombic cutoff to give desired error (if requested) @@ -1071,8 +1070,7 @@ void MSM::set_grid_global() *p_cutoff = cutoff; if (me == 0) - error->warning(FLERR,"Adjusting Coulombic cutoff for " - "MSM, new cutoff = {:.8}", cutoff); + error->warning(FLERR,"Adjusting Coulombic cutoff for MSM, new cutoff = {:.8}", cutoff); } if (triclinic == 0) { diff --git a/src/KSPACE/pppm.cpp b/src/KSPACE/pppm.cpp index 06d90e5d0e..d531233a3a 100644 --- a/src/KSPACE/pppm.cpp +++ b/src/KSPACE/pppm.cpp @@ -197,11 +197,9 @@ void PPPM::init() error->all(FLERR,"Must redefine kspace_style after changing to triclinic box"); if (domain->triclinic && differentiation_flag == 1) - error->all(FLERR,"Cannot (yet) use PPPM with triclinic box " - "and kspace_modify diff ad"); + error->all(FLERR,"Cannot (yet) use PPPM with triclinic box and kspace_modify diff ad"); if (domain->triclinic && slabflag) - error->all(FLERR,"Cannot (yet) use PPPM with triclinic box and " - "slab correction"); + error->all(FLERR,"Cannot (yet) use PPPM with triclinic box and slab correction"); if (domain->dimension == 2) error->all(FLERR,"Cannot use PPPM with 2d simulation"); From 1c8f427e8a4fbcbebb5504aeb1aa095f6337a339 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jan 2022 09:09:19 -0500 Subject: [PATCH 19/22] detect when MSM::setup() is called before proper initialization and error out --- src/KSPACE/msm.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/KSPACE/msm.cpp b/src/KSPACE/msm.cpp index 9fd581618f..da4a2ad658 100644 --- a/src/KSPACE/msm.cpp +++ b/src/KSPACE/msm.cpp @@ -285,6 +285,11 @@ double MSM::estimate_total_error() void MSM::setup() { + // change_box may trigger MSM::setup() before MSM::init() was called + // error out and request full initialization. + + if (!delxinv) error->all(FLERR, "MSM must be fully initialized for this operation"); + double *prd; double a = cutoff; From 389c35a2d3517573a5b77f96f02dec9ae4aedfb7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jan 2022 09:09:37 -0500 Subject: [PATCH 20/22] use alternate method to create triclinic box for unit test --- unittest/python/python-commands.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index bd8512894f..58a0772510 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -356,18 +356,16 @@ create_atoms 1 single & def test_extract_box_triclinic(self): self.lmp.command("boundary p p p") - self.lmp.command("region box block 0 2 0 2 0 2") + self.lmp.command("region box prism 0 2 0 2 0 2 0.1 0.2 0.3") self.lmp.command("create_box 1 box") - self.lmp.command("change_box all triclinic") - self.lmp.command("change_box all xy final 0.1 yz final 0.2 xz final 0.3") boxlo, boxhi, xy, yz, xz, periodicity, box_change = self.lmp.extract_box() self.assertEqual(boxlo, [0.0, 0.0, 0.0]) self.assertEqual(boxhi, [2.0, 2.0, 2.0]) self.assertEqual(xy, 0.1) - self.assertEqual(yz, 0.2) - self.assertEqual(xz, 0.3) + self.assertEqual(xz, 0.2) + self.assertEqual(yz, 0.3) self.assertEqual(periodicity, [1, 1, 1]) self.assertEqual(box_change, 0) From be7e6d09399b2d7cbfb13565cb4056e46b71e1fb Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 18 Jan 2022 12:21:18 -0500 Subject: [PATCH 21/22] Avoid std::string copies --- src/pair_hybrid_scaled.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pair_hybrid_scaled.cpp b/src/pair_hybrid_scaled.cpp index 5bf593d147..0a4be44be0 100644 --- a/src/pair_hybrid_scaled.cpp +++ b/src/pair_hybrid_scaled.cpp @@ -524,7 +524,7 @@ void PairHybridScaled::write_restart(FILE *fp) int n = scalevars.size(); fwrite(&n, sizeof(int), 1, fp); - for (auto var : scalevars) { + for (auto &var : scalevars) { n = var.size() + 1; fwrite(&n, sizeof(int), 1, fp); fwrite(var.c_str(), sizeof(char), n, fp); From c85cdb2732312e07ffaf5acbeeb83f1caffd1772 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 19 Jan 2022 10:11:16 -0500 Subject: [PATCH 22/22] always fall back to using the .so extension if available in the LAMMPS module folder --- python/lammps/core.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/lammps/core.py b/python/lammps/core.py index fcd5c76ad5..0bc8d0cb3f 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -122,6 +122,9 @@ class lammps(object): for f in os.listdir(winpath)]): lib_ext = ".dll" modpath = winpath + elif any([f.startswith('liblammps') and f.endswith('.so') + for f in os.listdir(modpath)]): + lib_ext = ".so" else: import platform if platform.system() == "Darwin":