simplify and avoid direct access to the list of computes in Modify

This commit is contained in:
Axel Kohlmeyer
2024-01-21 11:50:17 -05:00
parent 5ece2139e8
commit 5b80899fa4
4 changed files with 51 additions and 134 deletions

View File

@ -29,24 +29,11 @@ using namespace LAMMPS_NS;
Integrate::Integrate(LAMMPS *lmp, int /*narg*/, char ** /*arg*/) : Pointers(lmp)
{
elist_global = elist_atom = nullptr;
vlist_global = vlist_atom = cvlist_atom = nullptr;
external_force_clear = 0;
}
/* ---------------------------------------------------------------------- */
Integrate::~Integrate()
{
delete [] elist_global;
delete [] elist_atom;
delete [] vlist_global;
delete [] vlist_atom;
delete [] cvlist_atom;
}
/* ---------------------------------------------------------------------- */
void Integrate::init()
{
if (lmp->citeme) lmp->citeme->flush();
@ -74,43 +61,18 @@ void Integrate::init()
void Integrate::ev_setup()
{
delete [] elist_global;
delete [] elist_atom;
delete [] vlist_global;
delete [] vlist_atom;
delete [] cvlist_atom;
elist_global = elist_atom = nullptr;
vlist_global = vlist_atom = cvlist_atom = nullptr;
elist_global.clear();
elist_atom.clear();
vlist_global.clear();
vlist_atom.clear();
cvlist_atom.clear();
nelist_global = nelist_atom = 0;
nvlist_global = nvlist_atom = ncvlist_atom = 0;
for (int i = 0; i < modify->ncompute; i++) {
if (modify->compute[i]->peflag) nelist_global++;
if (modify->compute[i]->peatomflag) nelist_atom++;
if (modify->compute[i]->pressflag) nvlist_global++;
if (modify->compute[i]->pressatomflag & 1) nvlist_atom++;
if (modify->compute[i]->pressatomflag & 2) ncvlist_atom++;
}
if (nelist_global) elist_global = new Compute*[nelist_global];
if (nelist_atom) elist_atom = new Compute*[nelist_atom];
if (nvlist_global) vlist_global = new Compute*[nvlist_global];
if (nvlist_atom) vlist_atom = new Compute*[nvlist_atom];
if (ncvlist_atom) cvlist_atom = new Compute*[ncvlist_atom];
nelist_global = nelist_atom = 0;
nvlist_global = nvlist_atom = ncvlist_atom = 0;
for (int i = 0; i < modify->ncompute; i++) {
if (modify->compute[i]->peflag)
elist_global[nelist_global++] = modify->compute[i];
if (modify->compute[i]->peatomflag)
elist_atom[nelist_atom++] = modify->compute[i];
if (modify->compute[i]->pressflag)
vlist_global[nvlist_global++] = modify->compute[i];
if (modify->compute[i]->pressatomflag & 1)
vlist_atom[nvlist_atom++] = modify->compute[i];
if (modify->compute[i]->pressatomflag & 2)
cvlist_atom[ncvlist_atom++] = modify->compute[i];
for (const auto &icompute : modify->get_compute_list()) {
if (icompute->peflag) elist_global.push_back(icompute);
if (icompute->peatomflag) elist_atom.push_back(icompute);
if (icompute->pressflag) vlist_global.push_back(icompute);
if (icompute->pressatomflag & 1) vlist_atom.push_back(icompute);
if (icompute->pressatomflag & 2) cvlist_atom.push_back(icompute);
}
}
@ -137,7 +99,7 @@ void Integrate::ev_setup()
void Integrate::ev_set(bigint ntimestep)
{
int i,flag;
int flag;
int tdflag = 0;
if (output->any_time_dumps &&
@ -145,15 +107,14 @@ void Integrate::ev_set(bigint ntimestep)
flag = 0;
int eflag_global = 0;
for (i = 0; i < nelist_global; i++)
if (elist_global[i]->matchstep(ntimestep)) flag = 1;
for (auto &icompute : elist_global) icompute->matchstep(ntimestep);
if (flag) eflag_global = ENERGY_GLOBAL;
flag = 0;
int eflag_atom = 0;
for (i = 0; i < nelist_atom; i++)
if (elist_atom[i]->matchstep(ntimestep)) flag = 1;
if (flag || (tdflag && nelist_atom)) eflag_atom = ENERGY_ATOM;
for (auto &icompute : elist_atom)
if (icompute->matchstep(ntimestep)) flag = 1;
if (flag || (tdflag && (elist_atom.size() > 0))) eflag_atom = ENERGY_ATOM;
if (eflag_global) update->eflag_global = ntimestep;
if (eflag_atom) update->eflag_atom = ntimestep;
@ -161,21 +122,21 @@ void Integrate::ev_set(bigint ntimestep)
flag = 0;
int vflag_global = 0;
for (i = 0; i < nvlist_global; i++)
if (vlist_global[i]->matchstep(ntimestep)) flag = 1;
for (auto &icompute : vlist_global)
if (icompute->matchstep(ntimestep)) flag = 1;
if (flag) vflag_global = virial_style;
flag = 0;
int vflag_atom = 0;
for (i = 0; i < nvlist_atom; i++)
if (vlist_atom[i]->matchstep(ntimestep)) flag = 1;
if (flag || (tdflag && nvlist_atom)) vflag_atom = VIRIAL_ATOM;
for (auto &icompute : vlist_atom)
if (icompute->matchstep(ntimestep)) flag = 1;
if (flag || (tdflag && (vlist_atom.size() > 0))) vflag_atom = VIRIAL_ATOM;
flag = 0;
int cvflag_atom = 0;
for (i = 0; i < ncvlist_atom; i++)
if (cvlist_atom[i]->matchstep(ntimestep)) flag = 1;
if (flag || (tdflag && ncvlist_atom)) cvflag_atom = VIRIAL_CENTROID;
for (auto &icompute : cvlist_atom)
if (icompute->matchstep(ntimestep)) flag = 1;
if (flag || (tdflag && (cvlist_atom.size() > 0))) cvflag_atom = VIRIAL_CENTROID;
if (vflag_global) update->vflag_global = ntimestep;
if (vflag_atom || cvflag_atom) update->vflag_atom = ntimestep;

View File

@ -15,13 +15,13 @@
#define LMP_INTEGRATE_H
#include "pointers.h"
#include "compute.h"
namespace LAMMPS_NS {
class Integrate : protected Pointers {
public:
Integrate(class LAMMPS *, int, char **);
~Integrate() override;
virtual void init();
virtual void setup(int flag) = 0;
virtual void setup_minimal(int) = 0;
@ -36,13 +36,8 @@ class Integrate : protected Pointers {
int virial_style; // compute virial explicitly or implicitly
int external_force_clear; // clear forces locally or externally
int nelist_global, nelist_atom; // # of PE,virial computes to check
int nvlist_global, nvlist_atom, ncvlist_atom;
class Compute **elist_global; // lists of PE,virial Computes
class Compute **elist_atom;
class Compute **vlist_global;
class Compute **vlist_atom;
class Compute **cvlist_atom;
// lists of PE,virial Computes
std::vector<Compute *> elist_global, elist_atom, vlist_global, vlist_atom, cvlist_atom;
int pair_compute_flag; // 0 if pair->compute is skipped
int kspace_compute_flag; // 0 if kspace->compute is skipped

View File

@ -74,9 +74,6 @@ Min::Min(LAMMPS *lmp) : Pointers(lmp)
alpha_final = 0.0;
abcflag = 0;
elist_global = elist_atom = nullptr;
vlist_global = vlist_atom = cvlist_atom = nullptr;
nextra_global = 0;
fextra = nullptr;
@ -95,12 +92,6 @@ Min::Min(LAMMPS *lmp) : Pointers(lmp)
Min::~Min()
{
delete[] elist_global;
delete[] elist_atom;
delete[] vlist_global;
delete[] vlist_atom;
delete[] cvlist_atom;
delete[] fextra;
memory->sfree(xextra_atom);
@ -757,43 +748,18 @@ void Min::modify_params(int narg, char **arg)
void Min::ev_setup()
{
delete[] elist_global;
delete[] elist_atom;
delete[] vlist_global;
delete[] vlist_atom;
delete[] cvlist_atom;
elist_global = elist_atom = nullptr;
vlist_global = vlist_atom = cvlist_atom = nullptr;
elist_global.clear();
elist_atom.clear();
vlist_global.clear();
vlist_atom.clear();
cvlist_atom.clear();
nelist_global = nelist_atom = 0;
nvlist_global = nvlist_atom = ncvlist_atom = 0;
for (int i = 0; i < modify->ncompute; i++) {
if (modify->compute[i]->peflag) nelist_global++;
if (modify->compute[i]->peatomflag) nelist_atom++;
if (modify->compute[i]->pressflag) nvlist_global++;
if (modify->compute[i]->pressatomflag & 1) nvlist_atom++;
if (modify->compute[i]->pressatomflag & 2) ncvlist_atom++;
}
if (nelist_global) elist_global = new Compute*[nelist_global];
if (nelist_atom) elist_atom = new Compute*[nelist_atom];
if (nvlist_global) vlist_global = new Compute*[nvlist_global];
if (nvlist_atom) vlist_atom = new Compute*[nvlist_atom];
if (ncvlist_atom) cvlist_atom = new Compute*[ncvlist_atom];
nelist_global = nelist_atom = 0;
nvlist_global = nvlist_atom = ncvlist_atom = 0;
for (int i = 0; i < modify->ncompute; i++) {
if (modify->compute[i]->peflag)
elist_global[nelist_global++] = modify->compute[i];
if (modify->compute[i]->peatomflag)
elist_atom[nelist_atom++] = modify->compute[i];
if (modify->compute[i]->pressflag)
vlist_global[nvlist_global++] = modify->compute[i];
if (modify->compute[i]->pressatomflag & 1)
vlist_atom[nvlist_atom++] = modify->compute[i];
if (modify->compute[i]->pressatomflag & 2)
cvlist_atom[ncvlist_atom++] = modify->compute[i];
for (const auto &icompute : modify->get_compute_list()) {
if (icompute->peflag) elist_global.push_back(icompute);
if (icompute->peatomflag) elist_atom.push_back(icompute);
if (icompute->pressflag) vlist_global.push_back(icompute);
if (icompute->pressatomflag & 1) vlist_atom.push_back(icompute);
if (icompute->pressatomflag & 2) cvlist_atom.push_back(icompute);
}
}
@ -816,16 +782,15 @@ void Min::ev_setup()
void Min::ev_set(bigint ntimestep)
{
int i,flag;
int flag;
int eflag_global = 1;
for (i = 0; i < nelist_global; i++)
elist_global[i]->matchstep(ntimestep);
for (auto &icompute : elist_global) icompute->matchstep(ntimestep);
flag = 0;
int eflag_atom = 0;
for (i = 0; i < nelist_atom; i++)
if (elist_atom[i]->matchstep(ntimestep)) flag = 1;
for (auto &icompute : elist_atom)
if (icompute->matchstep(ntimestep)) flag = 1;
if (flag) eflag_atom = ENERGY_ATOM;
if (eflag_global) update->eflag_global = update->ntimestep;
@ -834,20 +799,20 @@ void Min::ev_set(bigint ntimestep)
flag = 0;
int vflag_global = 0;
for (i = 0; i < nvlist_global; i++)
if (vlist_global[i]->matchstep(ntimestep)) flag = 1;
for (auto &icompute : vlist_global)
if (icompute->matchstep(ntimestep)) flag = 1;
if (flag) vflag_global = virial_style;
flag = 0;
int vflag_atom = 0;
for (i = 0; i < nvlist_atom; i++)
if (vlist_atom[i]->matchstep(ntimestep)) flag = 1;
for (auto &icompute : vlist_atom)
if (icompute->matchstep(ntimestep)) flag = 1;
if (flag) vflag_atom = VIRIAL_ATOM;
flag = 0;
int cvflag_atom = 0;
for (i = 0; i < ncvlist_atom; i++)
if (cvlist_atom[i]->matchstep(ntimestep)) flag = 1;
for (auto &icompute : cvlist_atom)
if (icompute->matchstep(ntimestep)) flag = 1;
if (flag) cvflag_atom = VIRIAL_CENTROID;
if (vflag_global) update->vflag_global = update->ntimestep;

View File

@ -15,6 +15,7 @@
#define LMP_MIN_H
#include "pointers.h" // IWYU pragma: export
#include "compute.h"
namespace LAMMPS_NS {
@ -102,13 +103,8 @@ class Min : protected Pointers {
int max_vdotf_negatif; // maximum iteration with v.f > 0.0
int abcflag; // when 1 use ABC-FIRE variant instead of FIRE, default 0
int nelist_global, nelist_atom; // # of PE,virial computes to check
int nvlist_global, nvlist_atom, ncvlist_atom;
class Compute **elist_global; // lists of PE,virial Computes
class Compute **elist_atom;
class Compute **vlist_global;
class Compute **vlist_atom;
class Compute **cvlist_atom;
// lists of PE,virial Computes
std::vector<Compute *> elist_global, elist_atom, vlist_global, vlist_atom, cvlist_atom;
int triclinic; // 0 if domain is orthog, 1 if triclinic
int pairflag;