complete implementation for group based imbalance class
(cherry picked from commit 8ff0085cba)
This commit is contained in:
@ -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;
|
||||
};
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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:
|
||||
|
||||
Reference in New Issue
Block a user