Commit 4f1710bf authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@492 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent aba05c2c
Loading
Loading
Loading
Loading
+67 −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 "mpi.h"
#include "string.h"
#include "stdlib.h"
#include "compute_variable.h"
#include "input.h"
#include "variable.h"
#include "error.h"

using namespace LAMMPS_NS;

enum{INDEX,LOOP,EQUAL,WORLD,UNIVERSE,ULOOP,ATOM};  // also in variable.cpp

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

ComputeVariable::ComputeVariable(LAMMPS *lmp, int narg, char **arg) : 
  Compute(lmp, narg, arg)
{
  if (narg != 4) error->all("Illegal compute variable command");

  // store variable name

  int n = strlen(arg[3]) + 1;
  varname = new char[n];
  strcpy(varname,arg[3]);

  scalar_flag = 1;
  extensive = 0;
}

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

ComputeVariable::~ComputeVariable()
{
  delete [] varname;
}

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

void ComputeVariable::init()
{
  // check if variable exists

  int ivariable = input->variable->find(varname);
  if (ivariable < 0)
    error->all("Could not find compute variable name");
}

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

double ComputeVariable::compute_scalar()
{
  scalar = atof(input->variable->retrieve(varname));
  return scalar;
}

src/compute_variable.h

0 → 100644
+34 −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.
------------------------------------------------------------------------- */

#ifndef COMPUTE_VARIABLE_H
#define COMPUTE_VARIABLE_H

#include "compute.h"

namespace LAMMPS_NS {

class ComputeVariable : public Compute {
 public:
  ComputeVariable(class LAMMPS *, int, char **);
  ~ComputeVariable();
  void init();
  double compute_scalar();

 private:
  char *varname;
};

}

#endif
+3 −3
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@

using namespace LAMMPS_NS;

enum{INDEX,LOOP,EQUAL,WORLD,UNIVERSE,ULOOP,ATOM};  // also in variable.cpp

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

ComputeVariableAtom::ComputeVariableAtom(LAMMPS *lmp, int narg, char **arg) :
@@ -53,13 +55,11 @@ ComputeVariableAtom::~ComputeVariableAtom()

void ComputeVariableAtom::init()
{
  // set ivariable used by this compute
  // set ivariable used by this compute and check if it exists

  ivariable = input->variable->find(varname);
  if (ivariable < 0)
    error->all("Could not find compute variable name");

  // test if variable of correct ATOM type
}

/* ---------------------------------------------------------------------- */
+3 −0
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ CommandStyle(write_restart,WriteRestart)
#include "compute_temp_partial.h"
#include "compute_temp_ramp.h"
#include "compute_temp_region.h"
#include "compute_variable.h"
#include "compute_variable_atom.h"
#endif

@@ -100,6 +101,7 @@ ComputeStyle(temp,ComputeTemp)
ComputeStyle(temp/partial,ComputeTempPartial)
ComputeStyle(temp/ramp,ComputeTempRamp)
ComputeStyle(temp/region,ComputeTempRegion)
ComputeStyle(variable,ComputeVariable)
ComputeStyle(variable/atom,ComputeVariableAtom)
#endif

@@ -301,6 +303,7 @@ RegionStyle(union,RegUnion)

// style files for optional packages

//#include "style_asphere.h"
#include "style_class2.h"
#include "style_dpd.h"
#include "style_granular.h"