git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@15651 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -23,6 +23,8 @@
|
||||
#include "irregular.h"
|
||||
#include "force.h"
|
||||
#include "kspace.h"
|
||||
#include "modify.h"
|
||||
#include "fix_store.h"
|
||||
#include "rcb.h"
|
||||
#include "error.h"
|
||||
|
||||
@ -35,7 +37,7 @@ enum{LAYOUT_UNIFORM,LAYOUT_NONUNIFORM,LAYOUT_TILED}; // several files
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) :
|
||||
Fix(lmp, narg, arg), fp(NULL)
|
||||
Fix(lmp, narg, arg), balance(NULL), irregular(NULL)
|
||||
{
|
||||
if (narg < 6) error->all(FLERR,"Illegal fix balance command");
|
||||
|
||||
@ -47,7 +49,7 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) :
|
||||
extvector = 0;
|
||||
global_freq = 1;
|
||||
|
||||
// parse arguments
|
||||
// parse required arguments
|
||||
|
||||
int dimension = domain->dimension;
|
||||
|
||||
@ -62,7 +64,8 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) :
|
||||
int iarg = 5;
|
||||
if (lbstyle == SHIFT) {
|
||||
if (iarg+4 > narg) error->all(FLERR,"Illegal fix balance command");
|
||||
if (strlen(arg[iarg+1]) > 3) error->all(FLERR,"Illegal fix balance command");
|
||||
if (strlen(arg[iarg+1]) > 3)
|
||||
error->all(FLERR,"Illegal fix balance command");
|
||||
strcpy(bstr,arg[iarg+1]);
|
||||
nitermax = force->inumeric(FLERR,arg[iarg+2]);
|
||||
if (nitermax <= 0) error->all(FLERR,"Illegal fix balance command");
|
||||
@ -73,22 +76,7 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) :
|
||||
iarg++;
|
||||
}
|
||||
|
||||
// optional args
|
||||
|
||||
outflag = 0;
|
||||
int outarg = 0;
|
||||
fp = NULL;
|
||||
|
||||
while (iarg < narg) {
|
||||
if (strcmp(arg[iarg],"out") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix balance command");
|
||||
outflag = 1;
|
||||
outarg = iarg+1;
|
||||
iarg += 2;
|
||||
} else error->all(FLERR,"Illegal fix balance command");
|
||||
}
|
||||
|
||||
// error check
|
||||
// error checks
|
||||
|
||||
if (lbstyle == SHIFT) {
|
||||
int blen = strlen(bstr);
|
||||
@ -108,37 +96,35 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
// create instance of Balance class
|
||||
// if SHIFT, initialize it with params
|
||||
// process remaining optional args via Balance
|
||||
|
||||
balance = new Balance(lmp);
|
||||
if (lbstyle == SHIFT) balance->shift_setup(bstr,nitermax,thresh);
|
||||
balance->options(iarg,narg,arg);
|
||||
wtflag = balance->wtflag;
|
||||
|
||||
if (balance->varflag && nevery == 0)
|
||||
error->all(FLERR,"Fix balance nevery = 0 cannot be used with weight var");
|
||||
|
||||
// create instance of Irregular class
|
||||
|
||||
irregular = new Irregular(lmp);
|
||||
|
||||
// output file
|
||||
|
||||
if (outflag && comm->me == 0) {
|
||||
fp = fopen(arg[outarg],"w");
|
||||
if (fp == NULL) error->one(FLERR,"Cannot open fix balance output file");
|
||||
}
|
||||
|
||||
// only force reneighboring if nevery > 0
|
||||
|
||||
if (nevery) force_reneighbor = 1;
|
||||
|
||||
// compute initial outputs
|
||||
|
||||
imbfinal = imbprev = balance->imbalance_nlocal(maxperproc);
|
||||
itercount = 0;
|
||||
pending = 0;
|
||||
imbfinal = imbprev = maxloadperproc = 0.0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixBalance::~FixBalance()
|
||||
{
|
||||
if (fp) fclose(fp);
|
||||
delete balance;
|
||||
delete irregular;
|
||||
}
|
||||
@ -155,10 +141,19 @@ int FixBalance::setmask()
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixBalance::post_constructor()
|
||||
{
|
||||
if (wtflag) balance->weight_storage(id);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixBalance::init()
|
||||
{
|
||||
if (force->kspace) kspace_flag = 1;
|
||||
else kspace_flag = 0;
|
||||
|
||||
balance->init_imbalance();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -188,10 +183,11 @@ void FixBalance::setup_pre_exchange()
|
||||
|
||||
// perform a rebalance if threshhold exceeded
|
||||
|
||||
imbnow = balance->imbalance_nlocal(maxperproc);
|
||||
balance->set_weights();
|
||||
imbnow = balance->imbalance_factor(maxloadperproc);
|
||||
if (imbnow > thresh) rebalance();
|
||||
|
||||
// next_reneighbor = next time to force reneighboring
|
||||
// next timestep to rebalance
|
||||
|
||||
if (nevery) next_reneighbor = (update->ntimestep/nevery)*nevery + nevery;
|
||||
}
|
||||
@ -214,15 +210,15 @@ void FixBalance::pre_exchange()
|
||||
domain->reset_box();
|
||||
if (domain->triclinic) domain->lamda2x(atom->nlocal);
|
||||
|
||||
// return if imbalance < threshhold
|
||||
// perform a rebalance if threshhold exceeded
|
||||
// if weight variable is used, wrap weight setting in clear/add compute
|
||||
|
||||
imbnow = balance->imbalance_nlocal(maxperproc);
|
||||
if (imbnow <= thresh) {
|
||||
if (nevery) next_reneighbor = (update->ntimestep/nevery)*nevery + nevery;
|
||||
return;
|
||||
}
|
||||
if (balance->varflag) modify->clearstep_compute();
|
||||
balance->set_weights();
|
||||
if (balance->varflag) modify->addstep_compute(update->ntimestep + nevery);
|
||||
|
||||
rebalance();
|
||||
imbnow = balance->imbalance_factor(maxloadperproc);
|
||||
if (imbnow > thresh) rebalance();
|
||||
|
||||
// next timestep to rebalance
|
||||
|
||||
@ -237,7 +233,7 @@ void FixBalance::pre_exchange()
|
||||
void FixBalance::pre_neighbor()
|
||||
{
|
||||
if (!pending) return;
|
||||
imbfinal = balance->imbalance_nlocal(maxperproc);
|
||||
imbfinal = balance->imbalance_factor(maxloadperproc);
|
||||
pending = 0;
|
||||
}
|
||||
|
||||
@ -262,7 +258,7 @@ void FixBalance::rebalance()
|
||||
|
||||
// output of new decomposition
|
||||
|
||||
if (outflag) balance->dumpout(update->ntimestep,fp);
|
||||
if (balance->outflag) balance->dumpout(update->ntimestep);
|
||||
|
||||
// reset proc sub-domains
|
||||
// check and warn if any proc's subbox is smaller than neigh skin
|
||||
@ -277,8 +273,10 @@ void FixBalance::rebalance()
|
||||
// else allow caller's comm->exchange() to do it
|
||||
|
||||
if (domain->triclinic) domain->x2lamda(atom->nlocal);
|
||||
if (wtflag) balance->fixstore->disable = 0;
|
||||
if (lbstyle == BISECTION) irregular->migrate_atoms(0,1,sendproc);
|
||||
else if (irregular->migrate_check()) irregular->migrate_atoms();
|
||||
if (wtflag) balance->fixstore->disable = 1;
|
||||
if (domain->triclinic) domain->lamda2x(atom->nlocal);
|
||||
|
||||
// invoke KSpace setup_grid() to adjust to new proc sub-domains
|
||||
@ -306,7 +304,7 @@ double FixBalance::compute_scalar()
|
||||
|
||||
double FixBalance::compute_vector(int i)
|
||||
{
|
||||
if (i == 0) return (double) maxperproc;
|
||||
if (i == 0) return maxloadperproc;
|
||||
if (i == 1) return (double) itercount;
|
||||
return imbprev;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user