#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) { PetscDS ds = NULL; PetscFE fe; PetscSection section; PetscInt dim, ds_field = -1; PetscInt *restr_indices; const PetscInt *iter_indices; IS iter_is; PetscFunctionBeginUser; PetscValidHeaderSpecific(dm, DM_CLASSID, 1); PetscCall(DMGetLocalSection(dm, §ion)); PetscCall(DMGetDimension(dm, &dim)); { IS field_is; const PetscInt *fields; PetscInt num_fields; PetscCall(DMGetRegionDS(dm, domain_label, &field_is, &ds)); // Translate dm_field to ds_field PetscCall(ISGetIndices(field_is, &fields)); PetscCall(ISGetSize(field_is, &num_fields)); for (PetscInt i=0; i 0) { PetscInt num_cells_support, num_faces, start = -1; const PetscInt *orients, *faces, *cells; PetscCall(DMPlexGetSupport(dm, c, &cells)); PetscCall(DMPlexGetSupportSize(dm, c, &num_cells_support)); PetscCheck(num_cells_support == 1,PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Expected one cell in support of exterior face, but got %" PetscInt_FMT " cells", num_cells_support); PetscCall(DMPlexGetCone(dm, cells[0], &faces)); PetscCall(DMPlexGetConeSize(dm, cells[0], &num_faces)); for (PetscInt i=0; i= 0,PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, "Could not find face %" PetscInt_FMT " in cone of its support", c); PetscCall(DMPlexGetConeOrientation(dm, cells[0], &orients)); if (orients[start] < 0) flip = PETSC_TRUE; } for (PetscInt i = 0; i < *cell_size; i++) { PetscInt ii = i; if (flip) { if (*cell_size == P) ii = *cell_size - 1 - i; else if (*cell_size == P*P) { PetscInt row = i / P, col = i % P; ii = row + col * P; } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP, "No support for flipping point with cell size %" PetscInt_FMT " != P (%" PetscInt_FMT ") or P^2", *cell_size, P); } // Essential boundary conditions are encoded as -(loc+1), but we don't care so we decode. PetscInt loc = indices[field_offsets[dm_field] + ii*(*num_comp)]; restr_indices[cell_offset++] = loc >= 0 ? loc : -(loc + 1); } PetscCall(DMPlexRestoreClosureIndices(dm, section, section, c, PETSC_TRUE, &num_indices, &indices, field_offsets, NULL)); } PetscCheck(cell_offset == restr_size,PETSC_COMM_SELF, PETSC_ERR_SUP, "Shape mismatch, offsets array of shape (%" PetscInt_FMT ", %" PetscInt_FMT ") initialized for %" PetscInt_FMT " nodes", *num_cells, (*cell_size), cell_offset); if (iter_is) PetscCall(ISRestoreIndices(iter_is, &iter_indices)); PetscCall(ISDestroy(&iter_is)); *offsets = restr_indices; PetscCall(PetscSectionGetStorageSize(section, l_size)); 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) { 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; PetscCall(DMPlexGetLocalOffsets(dm, domain_label, label_value, height, dm_field, &num_cells, &cell_size, &num_comp, &lvec_size, &restr_indices)); PetscCall(DMGetCeed(dm, &ceed)); PetscCallCEED(CeedElemRestrictionCreate(ceed, num_cells, cell_size, num_comp, 1, lvec_size, CEED_MEM_HOST, CEED_COPY_VALUES, restr_indices, &elem_restr)); PetscCall(PetscFree(restr_indices)); dm->ceedERestrict = elem_restr; } *ERestrict = dm->ceedERestrict; PetscFunctionReturn(0); } #endif