#include /*I "petscdmplex.h" I*/ /*@C DMPlexGetLocalOffsets - Allocate and populate array of local offsets. Input Parameters: dm - The DMPlex object domain_label - label for DMPlex domain, or NULL for whole domain label_value - Stratum value height - Height of target cells in DMPlex topology dm_field - Index of DMPlex field Output Parameters: num_cells - Number of local cells cell_size - Size of each cell, given by cell_size * num_comp = num_dof num_comp - Number of components per dof l_size - Size of local vector offsets - Allocated offsets array for cells Notes: Allocate and populate array of shape [num_cells, cell_size] defining offsets for each value (cell, node) for local vector of the DMPlex field. All offsets are in the range [0, l_size - 1]. Caller is responsible for freeing the offsets array using PetscFree(). Level: developer .seealso: DMPlexGetClosureIndices(), DMPlexSetClosurePermutationTensor(), DMPlexGetCeedRestriction() @*/ PetscErrorCode DMPlexGetLocalOffsets(DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, PetscInt dm_field, PetscInt *num_cells, PetscInt *cell_size, PetscInt *num_comp, PetscInt *l_size, PetscInt **offsets) { PetscErrorCode ierr; PetscFunctionBeginUser; PetscValidHeaderSpecific(dm, DM_CLASSID, 1); PetscDS ds = NULL; PetscFE fe; PetscSection section; PetscInt dim; PetscInt *restr_indices; const PetscInt *iter_indices; IS iter_is; ierr = DMGetLocalSection(dm, §ion);CHKERRQ(ierr); if (domain_label) { ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); ierr = DMGetFirstLabelEntry_Internal(dm, dm, domain_label, 1, &label_value, dim, NULL, &ds);CHKERRQ(ierr); } // Translate dm_field to ds_field PetscInt ds_field = -1; for (PetscInt i=0; iNds; i++) { if (!domain_label || domain_label == dm->probs[i].label) { ds = dm->probs[i].ds; } if (ds == dm->probs[i].ds) { const PetscInt *arr; PetscInt nf; IS is = dm->probs[i].fields; ierr = ISGetIndices(is, &arr);CHKERRQ(ierr); ierr = ISGetSize(is, &nf);CHKERRQ(ierr); for (PetscInt j=0; j 0) { PetscInt num_cells_support, num_faces, start = -1; const PetscInt *orients, *faces, *cells; ierr = DMPlexGetSupport(dm, c, &cells);CHKERRQ(ierr); ierr = DMPlexGetSupportSize(dm, c, &num_cells_support);CHKERRQ(ierr); if (num_cells_support != 1) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Expected one cell in support of exterior face, but got %D cells", num_cells_support); ierr = DMPlexGetCone(dm, cells[0], &faces);CHKERRQ(ierr); ierr = DMPlexGetConeSize(dm, cells[0], &num_faces);CHKERRQ(ierr); for (PetscInt i=0; i= 0 ? loc : -(loc + 1); } ierr = DMPlexRestoreClosureIndices(dm, section, section, c, PETSC_TRUE, &num_indices, &indices, field_offsets, NULL);CHKERRQ(ierr); } if (cell_offset != restr_size) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_SUP, "Shape mismatch, offsets array of shape (%D, %D) initialized for %D nodes", *num_cells, (*cell_size), cell_offset); if (iter_is) { ierr = ISRestoreIndices(iter_is, &iter_indices);CHKERRQ(ierr); } ierr = ISDestroy(&iter_is);CHKERRQ(ierr); *offsets = restr_indices; ierr = PetscSectionGetStorageSize(section, l_size);CHKERRQ(ierr); PetscFunctionReturn(0); } #if defined(PETSC_HAVE_LIBCEED) #include /*@C DMPlexGetCeedRestriction - Define the libCEED map from the local vector (Lvector) to the cells (Evector) Input Parameters: dm - The DMPlex object domain_label - label for DMPlex domain, or NULL for the whole domain label_value - Stratum value height - Height of target cells in DMPlex topology dm_field - Index of DMPlex field Output Parameters: ERestrict - libCEED restriction from local vector to to the cells Level: developer @*/ PetscErrorCode DMPlexGetCeedRestriction(DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, PetscInt dm_field, CeedElemRestriction *ERestrict) { PetscErrorCode ierr; PetscFunctionBeginUser; PetscValidHeaderSpecific(dm, DM_CLASSID, 1); PetscValidPointer(ERestrict, 2); if (!dm->ceedERestrict) { PetscInt num_cells, cell_size, num_comp, lvec_size, *restr_indices; CeedElemRestriction elem_restr; Ceed ceed; ierr = DMPlexGetLocalOffsets(dm, domain_label, label_value, height, dm_field, &num_cells, &cell_size, &num_comp, &lvec_size, &restr_indices);CHKERRQ(ierr); ierr = DMGetCeed(dm, &ceed);CHKERRQ(ierr); ierr = CeedElemRestrictionCreate(ceed, num_cells, cell_size, num_comp, 1, lvec_size, CEED_MEM_HOST, CEED_COPY_VALUES, restr_indices, &elem_restr);CHKERRQ_CEED(ierr); ierr = PetscFree(restr_indices);CHKERRQ(ierr); dm->ceedERestrict = elem_restr; } *ERestrict = dm->ceedERestrict; PetscFunctionReturn(0); } #endif