Example #1
0
void ImbalanceVar::init()
{
  Error *error = _lmp->error;
  Variable *variable = _lmp->input->variable;

  if (_name) {
    _id = variable->find(_name);
    if (_id < 0) {
      error->all(FLERR,"Variable name for balance weight does not exist");
    } else {
      if (variable->atomstyle(_id) == 0)
        error->all(FLERR,"Variable for balance weight has invalid style");
    }
  }
}
Example #2
0
int ImbalanceVar::options(int narg, char **arg)
{
  Error *error = _lmp->error;

  if (narg < 1) error->all(FLERR,"Illegal balance weight command");
  int len = strlen(arg[0])+1;
  _name = new char[len];
  memcpy(_name,arg[0],len);
  this->init();

  return 1;
}
Example #3
0
int ImbalanceGroup::options(int narg, char **arg)
{
  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 2*_num+1;
}
Example #4
0
int main(int narg, char **arg)
{
  int n;
  char str[128];

  // setup MPI

  MPI_Init(&narg,&arg);
  MPI_Comm comm = MPI_COMM_WORLD;

  int me,nprocs;
  MPI_Comm_rank(comm,&me);
  MPI_Comm_size(comm,&nprocs);

  Memory *memory = new Memory(comm);
  Error *error = new Error(comm);

  // command-line args

  if (narg != 4) error->all("Syntax: lmpqst Niter in.lammps in.quest");

  int niter = atoi(arg[1]);
  n = strlen(arg[2]) + 1;
  char *lammps_input = new char[n];
  strcpy(lammps_input,arg[2]);
  n = strlen(arg[3]) + 1;
  char *quest_input = new char[n];
  strcpy(quest_input,arg[3]);

  // instantiate LAMMPS

  LAMMPS *lmp = new LAMMPS(0,NULL,MPI_COMM_WORLD);

  // create simulation in LAMMPS from in.lammps

  lmp->input->file(lammps_input);

  // make info avaiable to callback function

  Info info;
  info.me = me;
  info.memory = memory;
  info.lmp = lmp;
  info.quest_input = quest_input;

  // set callback to Quest inside fix external

  int ifix = lmp->modify->find_fix("2");
  FixExternal *fix = (FixExternal *) lmp->modify->fix[ifix];
  fix->set_callback(quest_callback,&info);

  // run LAMMPS for Niter
  // each time it needs forces, it will invoke quest_callback

  sprintf(str,"run %d",niter);
  lmp->input->one(str);

  // clean up

  delete lmp;

  delete memory;
  delete error;

  delete [] lammps_input;
  delete [] quest_input;

  MPI_Finalize();
}