add ability to retrieve the number of local rows for computes returning local data

this is done supporting the combination of type == 2 with style == 0,
i.e. a local scalar, which is not available in C++ (but there one can
access the compute style data member directly. for the python interface,
the pointer is automatically dereferenced and returned as a c_int.
This commit is contained in:
Axel Kohlmeyer 2018-04-19 18:37:15 -04:00
parent 164537cf37
commit 5bf8e1bc5b
2 changed files with 17 additions and 4 deletions

View File

@ -384,9 +384,14 @@ class lammps(object):
ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type)
return ptr
if type == 2:
self.lib.lammps_extract_compute.restype = POINTER(POINTER(c_double))
ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type)
return ptr
if style == 0:
self.lib.lammps_extract_compute.restype = POINTER(c_int)
ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type)
return ptr[0]
else:
self.lib.lammps_extract_compute.restype = POINTER(POINTER(c_double))
ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type)
return ptr
return None
# extract fix info

View File

@ -480,10 +480,13 @@ void *lammps_extract_atom(void *ptr, char *name)
compute's internal data structure for the entity
caller should cast it to (double *) for a scalar or vector
caller should cast it to (double **) for an array
for per-atom or local data, returns a pointer to the
for per-atom or local vector/array data, returns a pointer to the
compute's internal data structure for the entity
caller should cast it to (double *) for a vector
caller should cast it to (double **) for an array
for local data, accessing scalar data for the compute (type = 0),
returns a pointer that should be cast to (int *) which points to
an int with the number of local rows, i.e. the length of the local array.
returns a void pointer to the compute's internal data structure
for the entity which the caller can cast to the proper data type
returns a NULL if id is not recognized or style/type not supported
@ -541,6 +544,11 @@ void *lammps_extract_compute(void *ptr, char *id, int style, int type)
if (style == 2) {
if (!compute->local_flag) return NULL;
if (type == 0) {
if (compute->invoked_local != lmp->update->ntimestep)
compute->compute_local();
return (void *) &compute->size_local_rows;
}
if (type == 1) {
if (compute->invoked_local != lmp->update->ntimestep)
compute->compute_local();