diff --git a/src/.gitignore b/src/.gitignore index 7b645ee347..cc792388a6 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -217,6 +217,8 @@ /fix_rheo.h /fix_rheo_pressure.cpp /fix_rheo_pressure.h +/fix_rheo_stress.cpp +/fix_rheo_stress.h /fix_rheo_thermal.cpp /fix_rheo_thermal.h /fix_rheo_viscosity.cpp diff --git a/src/RHEO/fix_rheo_stress.cpp b/src/RHEO/fix_rheo_stress.cpp new file mode 100644 index 0000000000..b391527f1c --- /dev/null +++ b/src/RHEO/fix_rheo_stress.cpp @@ -0,0 +1,137 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. + ------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing authors: Joel Clemmer (SNL) +----------------------------------------------------------------------- */ + +#include "fix_rheo_stress.h" + +#include "atom.h" +#include "comm.h" +#include "compute.h" +#include "domain.h" +#include "fix_store_atom.h" +#include "group.h" +#include "error.h" +#include "modify.h" +#include "update.h" + +#include +#include + +using namespace LAMMPS_NS; +using namespace FixConst; + +/* ---------------------------------------------------------------------- */ + +FixRHEOStress::FixRHEOStress(LAMMPS *lmp, int narg, char **arg) : + id_compute(nullptr), id_fix(nullptr), stress_compute(nullptr), store_fix(nullptr), Fix(lmp, narg, arg) +{ + if (narg != 3) error->all(FLERR,"Illegal fix rheo/stress command"); + comm_forward = 6; +} + +/* ---------------------------------------------------------------------- */ + +FixRHEOStress::~FixRHEOStress() +{ + modify->delete_compute(id_compute); + modify->delete_fix(id_fix); +} + +/* ---------------------------------------------------------------------- */ + +void FixRHEOStress::post_constructor() +{ + id_fix = utils::strdup(std::string(id) + "_store"); + store_fix = dynamic_cast(modify->add_fix(fmt::format("{} {} STORE/ATOM d_pxx d_pyy d_pzz d_pxy d_pxz d_pyz", id_fix, group->names[igroup]))); + array_atom = store_fix->astore; + + id_compute = utils::strdup(std::string(id) + "_compute"); + stress_compute = modify->add_compute(fmt::format("{} {} stress/atom NULL ke pair bond", id_compute, group->names[igroup])); +} + +/* ---------------------------------------------------------------------- */ + +int FixRHEOStress::setmask() +{ + int mask = 0; + mask |= PRE_FORCE; + mask |= END_OF_STEP; + return mask; +} + +/* ---------------------------------------------------------------------- */ + +void FixRHEOStress::init() +{ + stress_compute->addstep(update->ntimestep+1); +} + +/* ---------------------------------------------------------------------- */ + +void FixRHEOStress::pre_force(int vflag) +{ + // add pre-force and forward to ghosts (not done in store/atom) + comm->forward_comm(this); +} + +/* ---------------------------------------------------------------------- */ + +void FixRHEOStress::end_of_step() +{ + stress_compute->compute_peratom(); + + // copy compute to fix property atom + double **saved_stress = store_fix->astore; + double **stress = stress_compute->array_atom; + + int ntotal = atom->nlocal+atom->nghost; + for (int i = 0; i < ntotal; i++) + for (int a = 0; a < 6; a++) + saved_stress[i][a] = stress[i][a]; + + stress_compute->addstep(update->ntimestep + 1); +} + +/* ---------------------------------------------------------------------- */ + +int FixRHEOStress::pack_forward_comm(int n, int *list, double *buf, + int /*pbc_flag*/, int * /*pbc*/) +{ + int i, j, a, m; + double **saved_stress = store_fix->astore; + + m = 0; + for (i = 0; i < n; i++) { + j = list[i]; + for (a = 0; a < 6; a++) + buf[m++] = saved_stress[j][a]; + } + return m; +} + +/* ---------------------------------------------------------------------- */ + +void FixRHEOStress::unpack_forward_comm(int n, int first, double *buf) +{ + int i, a, m, last; + double **saved_stress = store_fix->astore; + + m = 0; + last = first + n; + for (i = first; i < last; i++) + for (a = 0; a < 6; a++) + saved_stress[i][a] = buf[m++]; +} diff --git a/src/RHEO/fix_rheo_stress.h b/src/RHEO/fix_rheo_stress.h new file mode 100644 index 0000000000..4bf522793f --- /dev/null +++ b/src/RHEO/fix_rheo_stress.h @@ -0,0 +1,48 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef FIX_CLASS +// clang-format off +FixStyle(rheo/stress,FixRHEOStress); +// clang-format on +#else + +#ifndef LMP_FIX_RHEO_STRESS_H +#define LMP_FIX_RHEO_STRESS_H + +#include "fix.h" + +namespace LAMMPS_NS { + +class FixRHEOStress : public Fix { + public: + FixRHEOStress(class LAMMPS *, int, char **); + ~FixRHEOStress() override; + void post_constructor() override; + int setmask() override; + void init() override; + void pre_force(int) override; + void end_of_step() override; + int pack_forward_comm(int, int *, double *, int, int *) override; + void unpack_forward_comm(int, int, double *) override; + + private: + char *id_compute, *id_fix; + class Compute *stress_compute; + class FixStoreAtom *store_fix; +}; + +} // namespace LAMMPS_NS + +#endif +#endif diff --git a/src/RHEO/pair_rheo_tension.cpp b/src/RHEO/pair_rheo_tension.cpp index 5899c87e3e..824f496161 100644 --- a/src/RHEO/pair_rheo_tension.cpp +++ b/src/RHEO/pair_rheo_tension.cpp @@ -109,8 +109,8 @@ void PairRHEOTension::compute(int eflag, int vflag) int nmax = atom->nmax; if (nmax_store <= nmax) { - memory->grow(c_tension, nmax, "atom:rheo_c_tension"); - memory->grow(n_tension, nmax, 3, "atom:rheo_n_tension"); + memory->grow(ct, nmax, "atom:rheo_c_tension"); + memory->grow(nnt_tension, nmax, 3, "atom:rheo_n_tension"); nmax_store = atom->nmax; } @@ -153,8 +153,6 @@ void PairRHEOTension::compute(int eflag, int vflag) dWij = compute_kernel->dWij; dWji = compute_kernel->dWji; - - f[i][0] += ft[0]; f[i][1] += ft[1]; f[i][2] += ft[2]; @@ -173,10 +171,8 @@ void PairRHEOTension::compute(int eflag, int vflag) if (vflag_fdotr) virial_fdotr_compute(); - if (compute_interface) { - comm->reverse_comm(this); - comm->forward_comm(this); - } + comm->reverse_comm(this); + comm->forward_comm(this); } /* ---------------------------------------------------------------------- diff --git a/src/RHEO/pair_rheo_tension.h b/src/RHEO/pair_rheo_tension.h index 9b75b05ebd..d1799b65e7 100644 --- a/src/RHEO/pair_rheo_tension.h +++ b/src/RHEO/pair_rheo_tension.h @@ -33,9 +33,9 @@ class PairRHEOTension : public Pair { void setup() override; void init_style() override; double init_one(int, int) override; + int pack_forward_comm(int, int *, double *, int, int *) override; void unpack_forward_comm(int, int, double *) override; int pack_reverse_comm(int, int, double *) override; - int pack_reverse_comm(int, int, double *) override; void unpack_reverse_comm(int, int *, double *) override; protected: