sunc with GHub version
This commit is contained in:
@ -13,7 +13,7 @@ Syntax
|
||||
* ID, group-ID are documented in :doc:`compute <compute>` command
|
||||
* count/type = style name of this compute command
|
||||
* mode = {atom} or {bond} or {angle} or {dihedral} or {improper}
|
||||
|
||||
|
||||
Examples
|
||||
""""""""
|
||||
|
||||
|
||||
@ -22,13 +22,14 @@
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
enum{ATOM,BOND,ANGLE,DIHEDRAL,IMPROPER};
|
||||
enum{ATOM, BOND, ANGLE, DIHEDRAL, IMPROPER};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
ComputeCountType::ComputeCountType(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg)
|
||||
ComputeCountType::ComputeCountType(LAMMPS *lmp, int narg, char **arg) :
|
||||
Compute(lmp, narg, arg), count(nullptr), bcount(nullptr), bcount_me(nullptr)
|
||||
{
|
||||
if (narg != 4) error->all(FLERR, "Illegal compute count/type command");
|
||||
if (narg != 4) error->all(FLERR, "Incorrect number of args for compute count/type command");
|
||||
|
||||
// process args
|
||||
|
||||
@ -76,7 +77,7 @@ ComputeCountType::ComputeCountType(LAMMPS *lmp, int narg, char **arg) : Compute(
|
||||
}
|
||||
|
||||
// output vector
|
||||
|
||||
|
||||
vector = new double[size_vector];
|
||||
|
||||
// work vectors
|
||||
@ -110,13 +111,13 @@ double ComputeCountType::compute_scalar()
|
||||
int **bond_type = atom->bond_type;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
int m,nbond;
|
||||
int m, nbond;
|
||||
int count = 0;
|
||||
|
||||
// count broken bonds with bond_type = 0
|
||||
// ignore group setting since 2 atoms in a broken bond
|
||||
// can be arbitrarily far apart
|
||||
|
||||
|
||||
for (int i = 0; i < nlocal; i++) {
|
||||
nbond = num_bond[i];
|
||||
for (m = 0; m < nbond; m++)
|
||||
@ -125,14 +126,13 @@ double ComputeCountType::compute_scalar()
|
||||
|
||||
// sum across procs as bigint, then convert to double
|
||||
// correct for double counting if newton_bond off
|
||||
|
||||
|
||||
bigint bcount_me = count;
|
||||
bigint bcount;
|
||||
MPI_Allreduce(&bcount_me, &bcount, 1, MPI_LMP_BIGINT, MPI_SUM, world);
|
||||
if (force->newton_bond == 0) bcount /= 2;
|
||||
|
||||
if (bcount > MAXDOUBLEINT)
|
||||
error->all(FLERR,"Compute count/type overflow");
|
||||
if (bcount > MAXDOUBLEINT) error->all(FLERR, "Compute count/type overflow");
|
||||
scalar = bcount;
|
||||
return scalar;
|
||||
}
|
||||
@ -167,8 +167,7 @@ void ComputeCountType::compute_vector()
|
||||
}
|
||||
|
||||
for (int m = 0; m < nvec; m++)
|
||||
if (bcount[m] > MAXDOUBLEINT)
|
||||
error->all(FLERR,"Compute count/type overflow");
|
||||
if (bcount[m] > MAXDOUBLEINT) error->all(FLERR, "Compute count/type overflow");
|
||||
for (int m = 0; m < nvec; m++) vector[m] = bcount[m];
|
||||
}
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ class ComputeCountType : public Compute {
|
||||
|
||||
protected:
|
||||
int mode;
|
||||
|
||||
|
||||
int *count;
|
||||
bigint *bcount_me;
|
||||
bigint *bcount;
|
||||
|
||||
@ -95,8 +95,8 @@ typedef int64_t bigint;
|
||||
#define MAXSMALLINT INT_MAX
|
||||
#define MAXTAGINT INT_MAX
|
||||
#define MAXBIGINT INT64_MAX
|
||||
#define MAXDOUBLEINT 9007199254740992 // 2^53
|
||||
|
||||
#define MAXDOUBLEINT (1L<<53)
|
||||
|
||||
#define MPI_LMP_TAGINT MPI_INT
|
||||
#define MPI_LMP_IMAGEINT MPI_INT
|
||||
#define MPI_LMP_BIGINT MPI_LL
|
||||
@ -133,7 +133,7 @@ typedef int64_t bigint;
|
||||
#define MAXSMALLINT INT_MAX
|
||||
#define MAXTAGINT INT64_MAX
|
||||
#define MAXBIGINT INT64_MAX
|
||||
#define MAXDOUBLEINT 9007199254740992 // 2^53
|
||||
#define MAXDOUBLEINT (1L<<53)
|
||||
|
||||
#define MPI_LMP_TAGINT MPI_LL
|
||||
#define MPI_LMP_IMAGEINT MPI_LL
|
||||
|
||||
@ -294,6 +294,60 @@ TEST_F(ComputeGlobalTest, Reduction)
|
||||
EXPECT_DOUBLE_EQ(rep[2], 26);
|
||||
EXPECT_DOUBLE_EQ(rep[3], max[0]);
|
||||
}
|
||||
|
||||
TEST_F(ComputeGlobalTest, Counts)
|
||||
{
|
||||
if (lammps_get_natoms(lmp) == 0.0) GTEST_SKIP();
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("pair_style zero 10.0");
|
||||
command("pair_coeff * *");
|
||||
|
||||
command("variable t1 atom type==1");
|
||||
command("variable t2 atom type==2");
|
||||
command("variable t3 atom type==3");
|
||||
command("variable t4 atom type==4");
|
||||
command("variable t5 atom type==5");
|
||||
command("compute asum all reduce sum v_t1 v_t2 v_t3 v_t4 v_t5");
|
||||
command("compute acnt all count/type atom");
|
||||
command("compute bcnt all count/type bond");
|
||||
command("thermo_style custom c_asum[*] c_acnt[*]");
|
||||
command("run 0 post no");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
auto asum = get_vector("asum");
|
||||
auto acnt = get_vector("acnt");
|
||||
auto bcnt = get_vector("bcnt");
|
||||
auto bbrk = get_scalar("bcnt");
|
||||
|
||||
EXPECT_DOUBLE_EQ(bbrk, 0.0);
|
||||
|
||||
EXPECT_DOUBLE_EQ(asum[0], acnt[0]);
|
||||
EXPECT_DOUBLE_EQ(asum[1], acnt[1]);
|
||||
EXPECT_DOUBLE_EQ(asum[2], acnt[2]);
|
||||
EXPECT_DOUBLE_EQ(asum[3], acnt[3]);
|
||||
EXPECT_DOUBLE_EQ(asum[4], acnt[4]);
|
||||
|
||||
EXPECT_DOUBLE_EQ(bcnt[0], 3.0);
|
||||
EXPECT_DOUBLE_EQ(bcnt[1], 6.0);
|
||||
EXPECT_DOUBLE_EQ(bcnt[2], 3.0);
|
||||
EXPECT_DOUBLE_EQ(bcnt[3], 2.0);
|
||||
EXPECT_DOUBLE_EQ(bcnt[4], 10.0);
|
||||
|
||||
BEGIN_HIDE_OUTPUT();
|
||||
command("delete_bonds all bond 3");
|
||||
command("run 0 post no");
|
||||
END_HIDE_OUTPUT();
|
||||
|
||||
bcnt = get_vector("bcnt");
|
||||
bbrk = get_scalar("bcnt");
|
||||
EXPECT_DOUBLE_EQ(bbrk, 0.0); // should be 3
|
||||
EXPECT_DOUBLE_EQ(bcnt[0], 3.0);
|
||||
EXPECT_DOUBLE_EQ(bcnt[1], 6.0);
|
||||
EXPECT_DOUBLE_EQ(bcnt[2], 3.0); // should be 0
|
||||
EXPECT_DOUBLE_EQ(bcnt[3], 2.0);
|
||||
EXPECT_DOUBLE_EQ(bcnt[4], 10.0);
|
||||
}
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
||||
Reference in New Issue
Block a user