diff --git a/src/compute_variable.cpp b/src/compute_variable.cpp new file mode 100644 index 0000000000..0acfd27e4f --- /dev/null +++ b/src/compute_variable.cpp @@ -0,0 +1,67 @@ +/* ---------------------------------------------------------------------- + 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; +} diff --git a/src/compute_variable.h b/src/compute_variable.h new file mode 100644 index 0000000000..1f48d3b5de --- /dev/null +++ b/src/compute_variable.h @@ -0,0 +1,34 @@ +/* ---------------------------------------------------------------------- + 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 diff --git a/src/compute_variable_atom.cpp b/src/compute_variable_atom.cpp index 2db88251f4..46457b6b0c 100644 --- a/src/compute_variable_atom.cpp +++ b/src/compute_variable_atom.cpp @@ -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 } /* ---------------------------------------------------------------------- */ diff --git a/src/style.h b/src/style.h index 6c0c637101..f2e17b0b7f 100644 --- a/src/style.h +++ b/src/style.h @@ -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"