git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@15652 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
88
src/imbalance_var.cpp
Normal file
88
src/imbalance_var.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include <string.h>
|
||||
#include "imbalance_var.h"
|
||||
#include "atom.h"
|
||||
#include "group.h"
|
||||
#include "input.h"
|
||||
#include "variable.h"
|
||||
#include "memory.h"
|
||||
#include "error.h"
|
||||
|
||||
// DEBUG
|
||||
#include "update.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
ImbalanceVar::ImbalanceVar(LAMMPS *lmp) : Imbalance(lmp), name(0) {}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
ImbalanceVar::~ImbalanceVar()
|
||||
{
|
||||
delete [] name;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
int ImbalanceVar::options(int narg, char **arg)
|
||||
{
|
||||
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);
|
||||
init();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void ImbalanceVar::init()
|
||||
{
|
||||
id = input->variable->find(name);
|
||||
if (id < 0) {
|
||||
error->all(FLERR,"Variable name for balance weight does not exist");
|
||||
} else {
|
||||
if (input->variable->atomstyle(id) == 0)
|
||||
error->all(FLERR,"Variable for balance weight has invalid style");
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void ImbalanceVar::compute(double *weight)
|
||||
{
|
||||
const int all = group->find("all");
|
||||
if (all < 0) return;
|
||||
|
||||
double *values;
|
||||
const int nlocal = atom->nlocal;
|
||||
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];
|
||||
|
||||
memory->destroy(values);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void ImbalanceVar::info(FILE *fp)
|
||||
{
|
||||
fprintf(fp," weight variable: %s\n",name);
|
||||
}
|
||||
Reference in New Issue
Block a user