Commit 5bf8e1bc authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

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.
parent 164537cf
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -384,6 +384,11 @@ class lammps(object):
      ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type)
      return ptr
    if type == 2:
      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
+9 −1
Original line number Diff line number Diff line
@@ -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();