From aca7126cfe7524ffab21f401d8af8eaf562a57fc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 12 Mar 2022 09:23:36 -0500 Subject: [PATCH] use newer APIs to access list of fixes in Modify class --- src/LATBOLTZ/fix_lb_fluid.cpp | 38 ++++++++++++++++---------------- src/LATBOLTZ/fix_lb_momentum.cpp | 8 +++---- src/LATBOLTZ/fix_lb_momentum.h | 2 +- src/LATBOLTZ/fix_lb_viscous.cpp | 19 +++++++--------- src/LATBOLTZ/fix_lb_viscous.h | 1 + 5 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/LATBOLTZ/fix_lb_fluid.cpp b/src/LATBOLTZ/fix_lb_fluid.cpp index 6f0e9f2cdb..7b6e67fba0 100644 --- a/src/LATBOLTZ/fix_lb_fluid.cpp +++ b/src/LATBOLTZ/fix_lb_fluid.cpp @@ -173,6 +173,9 @@ FixLbFluid::FixLbFluid(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) if (lmp->citeme) lmp->citeme->add(cite_fix_lbfluid); + // we require continuous time stepping + time_depend = 1; + if (narg < 6) error->all(FLERR, "Illegal fix lb/fluid command"); if (comm->style != 0) @@ -730,16 +733,20 @@ int FixLbFluid::setmask() void FixLbFluid::init(void) { + if (modify->get_fix_by_style("lb/fluid").size() > 1) + error->all(FLERR, "Only one fix lb/fluid at a time is supported"); + + if (modify->get_fix_by_style("dt/reset").size() > 1) + error->all(FLERR, "Fix lb/fluid is not compatible with fix dt/reset"); + //-------------------------------------------------------------------------- // Check to see if the MD timestep has changed between runs. //-------------------------------------------------------------------------- double dt_lb_now; dt_lb_now = nevery * (update->dt); - if (fabs(dt_lb_now - dt_lb) > 1.0e-12) { - error->warning( - FLERR, "Timestep change between runs with the same lb/fluid. Unphysical results may occur"); - } + if (fabs(dt_lb_now - dt_lb) > 1.0e-12) + error->warning(FLERR, "Timestep changed between runs. Must re-issue fix lb/fluid command."); //-------------------------------------------------------------------------- // Make sure the size of the simulation domain has not changed @@ -788,11 +795,12 @@ void FixLbFluid::init(void) // Check if the lb/viscous fix is also called: //-------------------------------------------------------------------------- groupbit_viscouslb = 0; - for (int i = 0; i < modify->nfix; i++) { - if (strcmp(modify->fix[i]->style, "lb/viscous") == 0) { - fixviscouslb = 1; - groupbit_viscouslb = group->bitmask[modify->fix[i]->igroup]; - } + auto fixlbv = modify->get_fix_by_style("lb/viscous"); + if (fixlbv.size() > 0) { + if (fixlbv.size() > 1) + error->all(FLERR, "More than one fix lb/viscous at a time is not supported"); + fixviscouslb = 1; + groupbit_viscouslb = group->bitmask[fixlbv[0]->igroup]; } // Warn if the fluid force is not applied to any of the particles. @@ -4489,22 +4497,16 @@ void FixLbFluid::calc_MPT(double &totalmass, double totalmomentum[3], double &Ta int FixLbFluid::adjust_dof_fix() /* Based on same private method in compute class */ { /* altered to return fix_dof */ - Fix **fix = modify->fix; - int nfix = modify->nfix; - int fix_dof = 0; - for (int i = 0; i < nfix; i++) - if (fix[i]->dof_flag) fix_dof += fix[i]->dof(igroup); + for (auto &ifix : modify->get_fix_list()) + if (ifix->dof_flag) fix_dof += ifix->dof(igroup); return fix_dof; } double FixLbFluid::dof_compute() /* Based on same protected member of compute_temp class */ { /* with extra_dof variable replaced by its default domain->dimension */ - //int fix_dof = adjust_dof_fix(); double dof; - //double dof = domain->dimension * (group->count(igroup)); - //dof -= fix_dof; // CM can tranfer to lb fluid so no constraint requiring removal of 1 domain->dimension if (setdof) dof = setdof; @@ -4513,8 +4515,6 @@ double FixLbFluid::dof_compute() /* Based on same protected member of compute_te dof = 3.0 * dof; } - //std::cout << dof << std::endl; - double tfactor; if (dof > FLT_EPSILON) tfactor = force->mvv2e / (dof * force->boltz); diff --git a/src/LATBOLTZ/fix_lb_momentum.cpp b/src/LATBOLTZ/fix_lb_momentum.cpp index 486d26662f..e64a50a3a9 100644 --- a/src/LATBOLTZ/fix_lb_momentum.cpp +++ b/src/LATBOLTZ/fix_lb_momentum.cpp @@ -35,7 +35,8 @@ using namespace FixConst; /* ---------------------------------------------------------------------- */ -FixLbMomentum::FixLbMomentum(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) +FixLbMomentum::FixLbMomentum(LAMMPS *lmp, int narg, char **arg) : + Fix(lmp, narg, arg), fix_lb_fluid(nullptr) { if (narg < 4) error->all(FLERR, "Illegal fix lb/momentum command"); nevery = utils::inumeric(FLERR, arg[3], false, lmp); @@ -84,9 +85,8 @@ void FixLbMomentum::init() if ((count = group->count(igroup)) == 0) error->warning(FLERR, "Fix lb/momentum group has no atoms: Only fluid momentum affected"); - for (int ifix = 0; ifix < modify->nfix; ifix++) - if (strcmp(modify->fix[ifix]->style, "lb/fluid") == 0) - fix_lb_fluid = (FixLbFluid *) modify->fix[ifix]; + auto ifix = modify->get_fix_by_style("lb/fluid"); + if (ifix.size() > 0) fix_lb_fluid = (FixLbFluid *) ifix[0]; count ? masstotal = group->mass(igroup) : 0; } diff --git a/src/LATBOLTZ/fix_lb_momentum.h b/src/LATBOLTZ/fix_lb_momentum.h index 1ef7b2caae..51eaed4df5 100644 --- a/src/LATBOLTZ/fix_lb_momentum.h +++ b/src/LATBOLTZ/fix_lb_momentum.h @@ -1,6 +1,6 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://www.lammps.org/, Sandia National Laboratories + https://www.lammps.org/, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract diff --git a/src/LATBOLTZ/fix_lb_viscous.cpp b/src/LATBOLTZ/fix_lb_viscous.cpp index 7cd9d05927..687f138784 100644 --- a/src/LATBOLTZ/fix_lb_viscous.cpp +++ b/src/LATBOLTZ/fix_lb_viscous.cpp @@ -36,22 +36,19 @@ FixLbViscous::FixLbViscous(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, a int groupbit_lb_fluid = 0; - for (int ifix = 0; ifix < modify->nfix; ifix++) - if (strcmp(modify->fix[ifix]->style, "lb/fluid") == 0) { - fix_lb_fluid = (FixLbFluid *) modify->fix[ifix]; - groupbit_lb_fluid = group->bitmask[modify->fix[ifix]->igroup]; - } - - if (groupbit_lb_fluid == 0) + auto ifix = modify->get_fix_by_style("lb/fluid"); + if (ifix.size() > 0) { + fix_lb_fluid = (FixLbFluid *) ifix[0]; + groupbit_lb_fluid = group->bitmask[ifix[0]->igroup]; + } else { error->all(FLERR, "the lb/fluid fix must also be used if using the lb/viscous fix"); + } int *mask = atom->mask; int nlocal = atom->nlocal; for (int j = 0; j < nlocal; j++) { if ((mask[j] & groupbit) && !(mask[j] & groupbit_lb_fluid)) - error->one( - FLERR, - "to apply a fluid force onto an atom, the lb/fluid fix must be used for that atom."); + error->one(FLERR, "Atoms must be in the fix lb/fluid group to apply a fluid force to them"); } } @@ -70,7 +67,7 @@ int FixLbViscous::setmask() void FixLbViscous::init() { - if (utils::strmatch(update->integrate_style,"^respa")) + if (utils::strmatch(update->integrate_style, "^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } diff --git a/src/LATBOLTZ/fix_lb_viscous.h b/src/LATBOLTZ/fix_lb_viscous.h index 8f8f323e64..d4891369af 100644 --- a/src/LATBOLTZ/fix_lb_viscous.h +++ b/src/LATBOLTZ/fix_lb_viscous.h @@ -27,6 +27,7 @@ namespace LAMMPS_NS { class FixLbViscous : public Fix { public: FixLbViscous(class LAMMPS *, int, char **); + int setmask() override; void init() override; void setup(int) override;