diff --git a/src/library.cpp b/src/library.cpp index 6c8d643453..d8ec849f49 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -4127,7 +4127,7 @@ int lammps_group_name(void *handle, int idx, char *buffer, int buf_size) { \verbatim embed:rst This function checks if the current LAMMPS instance a *category* ID of the given *name* exists. Valid categories are: *compute*\ , *dump*\ , -*fix*\ , *molecule*\ , and *region*\ . +*fix*\ , *molecule*\ , *region*\ , and *variable*\ . \endverbatim * * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. @@ -4168,6 +4168,12 @@ int lammps_has_id(void *handle, const char *category, const char *name) { for (int i=0; i < nregion; ++i) { if (strcmp(name,region[i]->id) == 0) return 1; } + } else if (strcmp(category,"variable") == 0) { + int nvariable = lmp->input->variable->nvar; + char **varnames = lmp->input->variable->names; + for (int i=0; i < nvariable; ++i) { + if (strcmp(name,varnames[i]) == 0) return 1; + } } return 0; } @@ -4199,6 +4205,8 @@ int lammps_id_count(void *handle, const char *category) { return lmp->atom->nmolecule; } else if (strcmp(category,"region") == 0) { return lmp->domain->nregion; + } else if (strcmp(category,"variable") == 0) { + return lmp->input->variable->nvar; } return 0; } @@ -4250,6 +4258,11 @@ int lammps_id_name(void *handle, const char *category, int idx, strncpy(buffer, lmp->domain->regions[idx]->id, buf_size); return 1; } + } else if (strcmp(category,"variable") == 0) { + if ((idx >=0) && (idx < lmp->input->variable->nvar)) { + strncpy(buffer, lmp->input->variable->names[idx], buf_size); + return 1; + } } buffer[0] = '\0'; return 0; diff --git a/src/variable.h b/src/variable.h index 58548bc276..2519bc7ac9 100644 --- a/src/variable.h +++ b/src/variable.h @@ -49,11 +49,13 @@ class Variable : protected Pointers { tagint int_between_brackets(char *&, int); double evaluate_boolean(char *); + public: + int nvar; // # of defined variables + char **names; // name of each variable + private: int me; - int nvar; // # of defined variables int maxvar; // max # of variables following lists can hold - char **names; // name of each variable int *style; // style of each variable int *num; // # of values for each variable int *which; // next available value for each variable