complete implementation for group based imbalance class

(cherry picked from commit 8ff0085cba)
This commit is contained in:
Axel Kohlmeyer
2016-08-03 13:43:39 -04:00
parent a5d38c0875
commit 34b34d8410
3 changed files with 47 additions and 8 deletions

View File

@ -31,7 +31,7 @@ class Imbalance {
public:
// parse options. return number of arguments consumed.
virtual int options(LAMMPS *lmp, int narg, char **arg) = 0;
// compute per-atom imbalance and apply to weight array
// compute and apply weigh factors to local atom array
virtual void compute(LAMMPS *lmp, double *weights) = 0;
};

View File

@ -14,14 +14,51 @@
#include "pointers.h"
#include "imbalance_group.h"
#include "atom.h"
#include "error.h"
#include "force.h"
#include "group.h"
using namespace LAMMPS_NS;
int ImbalanceGroup::options(LAMMPS *lmp, int narg, char **arg)
{
return 0;
Error *error = lmp->error;
Force *force = lmp->force;
Group *group = lmp->group;
if (narg < 3) error->all(FLERR,"Illegal balance weight command");
_num = force->inumeric(FLERR,arg[0]);
if (_num < 1) error->all(FLERR,"Illegal balance weight command");
if (2*_num+1 > narg) error->all(FLERR,"Illegal balance weight command");
_id = new int[_num];
_factor = new double[_num];
for (int i = 0; i < _num; ++i) {
_id[i] = group->find(arg[2*i+1]);
if (_id[i] < 0)
error->all(FLERR,"Unknown group in balance weight command");
_factor[i] = force->numeric(FLERR,arg[2*i+2]);
}
return _num;
}
void ImbalanceGroup::compute(LAMMPS *lmp, double *weight)
{
const int * const mask = lmp->atom->mask;
const int * const bitmask = lmp->group->bitmask;
const int nlocal = lmp->atom->nlocal;
if (_num == 0) return;
for (int i = 0; i < nlocal; ++i) {
const int imask = mask[i];
double iweight = weight[i];
for (int j = 0; j < _num; ++j) {
if (imask & bitmask[_id[j]])
iweight *= _factor[j];
}
weight[i] = iweight;
}
}

View File

@ -19,14 +19,16 @@
namespace LAMMPS_NS {
class ImbalanceGroup : public Imbalance {
public:
ImbalanceGroup() : Imbalance() {};
virtual ~ImbalanceGroup() {};
// disallow copy constructor and assignment operator
public:
ImbalanceGroup() : Imbalance(), _num(0), _id(0), _factor(0) {};
virtual ~ImbalanceGroup() { delete[] _id; delete[] _factor; };
// internal data members
private:
ImbalanceGroup(const ImbalanceGroup &) {};
ImbalanceGroup &operator=(const ImbalanceGroup &) {return *this;};
int _num; // number of groups with weights
int *_id; // list numerical id's of groups
double *_factor; // list if group weight factors
// required member functions
public: