Commits

Matt Knepley committed 8af1977

DMPlex: Optimize depth retrieval by storing a pointer to the label
- This is a little unsafe since someone could go in and create a new "depth" label out from under you

Comments (0)

Files changed (3)

include/petsc-private/dmpleximpl.h

 
   /* Labels and numbering */
   DMLabel              labels;            /* Linked list of labels */
+  DMLabel              depthLabel;
   IS                   globalVertexNumbers;
   IS                   globalCellNumbers;
 

src/dm/impls/plex/plex.c

 @*/
 PetscErrorCode DMPlexGetDepth(DM dm, PetscInt *depth)
 {
-  PetscInt       d;
+  DM_Plex       *mesh = (DM_Plex*) dm->data;
+  PetscInt       d    = 0;
   PetscErrorCode ierr;
 
   PetscFunctionBegin;
   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
   PetscValidPointer(depth, 2);
-  ierr   = DMPlexGetLabelSize(dm, "depth", &d);CHKERRQ(ierr);
+  if (!mesh->depthLabel) {
+    ierr = DMPlexGetLabel(dm, "depth", &mesh->depthLabel);CHKERRQ(ierr);
+    if (mesh->depthLabel) {ierr = DMLabelGetNumValues(mesh->depthLabel, &d);CHKERRQ(ierr);}
+  } else {ierr = DMLabelGetNumValues(mesh->depthLabel, &d);CHKERRQ(ierr);}
   *depth = d-1;
   PetscFunctionReturn(0);
 }

src/dm/impls/plex/plexcreate.c

   for (unit = 0; unit < NUM_PETSC_UNITS; ++unit) mesh->scale[unit] = 1.0;
 
   mesh->labels              = NULL;
+  mesh->depthLabel          = NULL;
   mesh->globalVertexNumbers = NULL;
   mesh->globalCellNumbers   = NULL;
   for (d = 0; d < 8; ++d) mesh->hybridPointMax[d] = PETSC_DETERMINE;