add support for variable names to id introspection in library interface

This commit is contained in:
Axel Kohlmeyer
2020-10-04 06:01:26 -04:00
parent b1cc9949e4
commit 9dfb715296
2 changed files with 18 additions and 3 deletions

View File

@ -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;

View File

@ -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