additional fix external hooks for calling programs
This commit is contained in:
@ -30,7 +30,7 @@ enum{PF_CALLBACK,PF_ARRAY};
|
||||
|
||||
FixExternal::FixExternal(LAMMPS *lmp, int narg, char **arg) :
|
||||
Fix(lmp, narg, arg),
|
||||
fexternal(NULL)
|
||||
fexternal(NULL), caller_vector(NULL)
|
||||
{
|
||||
if (narg < 4) error->all(FLERR,"Illegal fix external command");
|
||||
|
||||
@ -62,6 +62,11 @@ FixExternal::FixExternal(LAMMPS *lmp, int narg, char **arg) :
|
||||
atom->add_callback(0);
|
||||
|
||||
user_energy = 0.0;
|
||||
|
||||
// optional vector of values provided by caller
|
||||
// vector_flag and size_vector are setup via set_vector_length()
|
||||
|
||||
caller_vector = NULL;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -73,6 +78,7 @@ FixExternal::~FixExternal()
|
||||
atom->delete_callback(id,0);
|
||||
|
||||
memory->destroy(fexternal);
|
||||
delete [] caller_vector;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -167,10 +173,15 @@ void FixExternal::min_post_force(int vflag)
|
||||
post_force(vflag);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// "set" methods caller can invoke directly
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
caller invokes this method to set its contribution to global energy
|
||||
do not just return if eflag_global is not set
|
||||
input script could access this quantity via compute_scalar()
|
||||
unlike other energy/virial set methods:
|
||||
do not just return if eflag_global is not set
|
||||
b/c input script could access this quantity via compute_scalar()
|
||||
even if eflag is not set on a particular timestep
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
@ -220,6 +231,34 @@ void FixExternal::set_virial_peratom(double **caller_virial)
|
||||
vatom[i][j] = caller_virial[i][j];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
caller invokes this method to set length of vector of values
|
||||
assume all vector values are extensive, could make this an option
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void FixExternal::set_vector_length(int n)
|
||||
{
|
||||
delete [] caller_vector;
|
||||
|
||||
vector_flag = 1;
|
||||
size_vector = n;
|
||||
extvector = 1;
|
||||
|
||||
caller_vector = new double[n];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
caller invokes this method to set Index value in vector
|
||||
index ranges from 1 to N inclusive
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void FixExternal::set_vector(int index, double value)
|
||||
{
|
||||
if (index >= size_vector)
|
||||
error->all(FLERR,"Invalid set_vector index in fix external");
|
||||
caller_vector[index-1] = value;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
potential energy of added force
|
||||
up to user to set it via set_energy()
|
||||
@ -230,6 +269,16 @@ double FixExternal::compute_scalar()
|
||||
return user_energy;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
arbitrary value computed by caller
|
||||
up to user to set it via set_vector()
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
double FixExternal::compute_vector(int n)
|
||||
{
|
||||
return caller_vector[n];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
memory usage of local atom-based array
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user