Commit 0902b600 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

add new imbalance module store, which allows to store weights in an atom property

(cherry picked from commit 5405622f3bdacf79e99304fedf473df013656f92)
parent 7f20afe1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include "imbalance_group.h"
#include "imbalance_time.h"
#include "imbalance_neigh.h"
#include "imbalance_store.h"
#include "imbalance_var.h"

#include "fix_store.h"
@@ -247,6 +248,10 @@ void Balance::command(int narg, char **arg)
        imb = new ImbalanceVar(lmp);
        nopt = imb->options(narg-iarg,arg+iarg+2);
        imbalance[nimbalance] = imb;
      } else if (strcmp(arg[iarg+1],"store") == 0) {
        imb = new ImbalanceStore(lmp);
        nopt = imb->options(narg-iarg,arg+iarg+2);
        imbalance[nimbalance] = imb;
      } else {
        error->all(FLERR,"Unknown balance weight method");
      }
+5 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include "imbalance_group.h"
#include "imbalance_time.h"
#include "imbalance_neigh.h"
#include "imbalance_store.h"
#include "imbalance_var.h"

#include "fix_store.h"
@@ -127,6 +128,10 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) :
        imb = new ImbalanceVar(lmp);
        nopt = imb->options(narg-iarg,arg+iarg+2);
        imbalance[nimbalance] = imb;
      } else if (strcmp(arg[iarg+1],"store") == 0) {
        imb = new ImbalanceStore(lmp);
        nopt = imb->options(narg-iarg,arg+iarg+2);
        imbalance[nimbalance] = imb;
      } else {
        error->all(FLERR,"Unknown balance weight method");
      }
+60 −0
Original line number Diff line number Diff line
/* ----------------------------------------------------------------------
   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 "pointers.h"
#include "imbalance_store.h"
#include "atom.h"
#include "error.h"
#include "input.h"

using namespace LAMMPS_NS;

int ImbalanceStore::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);

  return 1;
}

/* -------------------------------------------------------------------- */

void ImbalanceStore::compute(double *weight)
{
  if (_name) {
    int dflag = 0;
    int idx = _lmp->atom->find_custom(_name,dflag);

    // property does not exist
    if (idx < 0 || dflag != 1) return;

    double *prop = _lmp->atom->dvector[idx];
    const int nlocal = _lmp->atom->nlocal;

    for (int i = 0; i < nlocal; ++i)
      prop[i] = weight[i];
  }
}

/* -------------------------------------------------------------------- */

void ImbalanceStore::info(FILE *fp)
{
  if (_name)
    fprintf(fp,"  storing weight in atom property d_%s\n",_name);
}

src/imbalance_store.h

0 → 100644
+42 −0
Original line number Diff line number Diff line
/* -*- c++ -*- ----------------------------------------------------------
   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.
------------------------------------------------------------------------- */

#ifndef LMP_IMBALANCE_STORE_H
#define LMP_IMBALANCE_STORE_H

#include "imbalance.h"

namespace LAMMPS_NS {

class ImbalanceStore : public Imbalance {
 public:
  ImbalanceStore(LAMMPS *lmp) : Imbalance(lmp), _name(0) {};
  virtual ~ImbalanceStore() { delete[] _name; };

  // internal data members
 private:
  char *_name;                  // property name

  // required member functions
 public:
  // parse options. return number of arguments consumed.
  virtual int options(int narg, char **arg);
  // compute per-atom imbalance and apply to weight array
  virtual void compute(double *weight);
  // print information about the state of this imbalance compute (required)
  virtual void info(FILE *fp);
};

}

#endif