diff --git a/doc/src/balance.txt b/doc/src/balance.txt index 48293b6497..635e7a9b3d 100644 --- a/doc/src/balance.txt +++ b/doc/src/balance.txt @@ -333,9 +333,10 @@ however, it is sufficient to use just one method. The {group} weight style assigns weight factors to specified "groups"_group.html of particles. The {group} style keyword is followed by the number of groups, then pairs of group IDs and the -corresponding weight factor. If a particle belongs to none of the +corresponding weight factor. If a particle belongs to none of the specified groups, its weight is not changed. If it belongs to multiple groups, its weight is the product of the weight factors. +The weight factors have to be positive. This weight style is useful in combination with pair style "hybrid"_pair_hybrid.html, e.g. when combining a more costly manybody @@ -352,7 +353,8 @@ for all particles. The {factor} setting is then appied as an overall scale factor to all the {neigh} weights which allows tuning of the impact of this style. A {factor} smaller than 1.0 (e.g. 0.8) often results in the best performance, since the number of neighbors is -likely to overestimate the ideal weight. +likely to overestimate the ideal weight. The factor has to be between +0.0 and 2.0. This weight style is useful for systems where there are different cutoffs used for different pairs of interations, or the density @@ -379,7 +381,7 @@ cost then evenly distributed over all the particles owned by that rank. Finally, the {factor} setting is then appied as an overall scale factor to all the {time} weights as a way to fine tune the impact of this weight style. Good {factor} values to use are -typically between 0.5 and 1.2. +typically between 0.5 and 1.2. Allowed are values between 0.0 and 2.0. For the {balance} command the timing data is taken from the preceding run command, i.e. the timings are for the entire previous run. For diff --git a/src/imbalance_group.cpp b/src/imbalance_group.cpp index 54eac47c83..252e64568e 100644 --- a/src/imbalance_group.cpp +++ b/src/imbalance_group.cpp @@ -18,11 +18,12 @@ #include "error.h" using namespace LAMMPS_NS; +#define SMALL 0.001 /* -------------------------------------------------------------------- */ -ImbalanceGroup::ImbalanceGroup(LAMMPS *lmp) : Imbalance(lmp), id(0), factor(0) -{} +ImbalanceGroup::ImbalanceGroup(LAMMPS *lmp) : Imbalance(lmp), + id(0), factor(0), num(0) {} /* -------------------------------------------------------------------- */ @@ -49,6 +50,7 @@ int ImbalanceGroup::options(int narg, char **arg) if (id[i] < 0) error->all(FLERR,"Unknown group in balance weight command"); factor[i] = force->numeric(FLERR,arg[2*i+2]); + if (factor[i] < 0.0) error->all(FLERR,"Illegal balance weight command"); } return 2*num+1; } @@ -70,7 +72,8 @@ void ImbalanceGroup::compute(double *weight) if (imask & bitmask[id[j]]) iweight *= factor[j]; } - weight[i] = iweight; + if (iweight < SMALL) weight[i] = SMALL; + else weight[i] = iweight; } } diff --git a/src/imbalance_neigh.cpp b/src/imbalance_neigh.cpp index d4de27fed4..c1f268df5a 100644 --- a/src/imbalance_neigh.cpp +++ b/src/imbalance_neigh.cpp @@ -22,12 +22,14 @@ #include "error.h" using namespace LAMMPS_NS; +#define SMALL 0.001 /* -------------------------------------------------------------------- */ ImbalanceNeigh::ImbalanceNeigh(LAMMPS *lmp) : Imbalance(lmp) { did_warn = 0; + factor = 1.0; } /* -------------------------------------------------------------------- */ @@ -36,7 +38,8 @@ int ImbalanceNeigh::options(int narg, char **arg) { if (narg < 1) error->all(FLERR,"Illegal balance weight command"); factor = force->numeric(FLERR,arg[0]); - if (factor < 0.0) error->all(FLERR,"Illegal balance weight command"); + if ((factor < 0.0) || (factor > 2.0)) + error->all(FLERR,"Illegal balance weight command"); return 1; } @@ -91,6 +94,7 @@ void ImbalanceNeigh::compute(double *weight) for (int ii = 0; ii < inum; ++ii) { const int i = ilist[ii]; weight[i] *= (1.0-factor) + factor*scale*numneigh[i]; + if (weight[i] < SMALL) weight[i] = SMALL; } } diff --git a/src/imbalance_time.cpp b/src/imbalance_time.cpp index f8ec4343e2..0f99eef255 100644 --- a/src/imbalance_time.cpp +++ b/src/imbalance_time.cpp @@ -20,10 +20,14 @@ #include "error.h" using namespace LAMMPS_NS; +#define SMALL 0.001 /* -------------------------------------------------------------------- */ -ImbalanceTime::ImbalanceTime(LAMMPS *lmp) : Imbalance(lmp) {} +ImbalanceTime::ImbalanceTime(LAMMPS *lmp) : Imbalance(lmp) +{ + factor = 1.0; +} /* -------------------------------------------------------------------- */ @@ -31,7 +35,8 @@ int ImbalanceTime::options(int narg, char **arg) { if (narg < 1) error->all(FLERR,"Illegal balance weight command"); factor = force->numeric(FLERR,arg[0]); - if (factor < 0.0) error->all(FLERR,"Illegal balance weight command"); + if ((factor < 0.0) || (factor > 2.0)) + error->all(FLERR,"Illegal balance weight command"); return 1; } @@ -69,7 +74,10 @@ void ImbalanceTime::compute(double *weight) const double avgcost = allcost/natoms; const double localcost = cost/nlocal; const double scale = (1.0-factor) + factor*localcost/avgcost; - for (int i = 0; i < nlocal; ++i) weight[i] *= scale; + for (int i = 0; i < nlocal; ++i) { + weight[i] *= scale; + if (weight[i] < SMALL) weight[i] = SMALL; + } } // record time up to this point diff --git a/src/imbalance_var.cpp b/src/imbalance_var.cpp index 81c7c4b354..3f1f429a39 100644 --- a/src/imbalance_var.cpp +++ b/src/imbalance_var.cpp @@ -24,10 +24,11 @@ #include "update.h" using namespace LAMMPS_NS; +#define SMALL 0.001 /* -------------------------------------------------------------------- */ -ImbalanceVar::ImbalanceVar(LAMMPS *lmp) : Imbalance(lmp), name(0) {} +ImbalanceVar::ImbalanceVar(LAMMPS *lmp) : Imbalance(lmp), name(0), id(0) {} /* -------------------------------------------------------------------- */ @@ -75,7 +76,10 @@ void ImbalanceVar::compute(double *weight) memory->create(values,nlocal,"imbalance:values"); input->variable->compute_atom(id,all,values,1,0); - for (int i = 0; i < nlocal; ++i) weight[i] *= values[i]; + for (int i = 0; i < nlocal; ++i) { + weight[i] *= values[i]; + if (weight[i] < SMALL) weight[i] = SMALL; + } memory->destroy(values); }