xref: /petsc/src/dm/impls/plex/plexceed.c (revision 52e7713adc381d206404376c852c61b4333aca68)
1f918ec44SMatthew G. Knepley #include <petsc/private/dmpleximpl.h> /*I      "petscdmplex.h"          I*/
2f918ec44SMatthew G. Knepley 
3*52e7713aSMatthew G. Knepley static PetscErrorCode DMGetPoints_Private(DM dm, DMLabel domainLabel, PetscInt labelVal, PetscInt height, IS *pointIS)
4*52e7713aSMatthew G. Knepley {
5*52e7713aSMatthew G. Knepley   PetscInt depth;
6*52e7713aSMatthew G. Knepley   DMLabel  depthLabel;
7*52e7713aSMatthew G. Knepley   IS       depthIS;
8*52e7713aSMatthew G. Knepley 
9*52e7713aSMatthew G. Knepley   PetscFunctionBegin;
10*52e7713aSMatthew G. Knepley   PetscCall(DMPlexGetDepth(dm, &depth));
11*52e7713aSMatthew G. Knepley   PetscCall(DMPlexGetDepthLabel(dm, &depthLabel));
12*52e7713aSMatthew G. Knepley   PetscCall(DMLabelGetStratumIS(depthLabel, depth - height, &depthIS));
13*52e7713aSMatthew G. Knepley   if (domainLabel) {
14*52e7713aSMatthew G. Knepley     IS domainIS;
15*52e7713aSMatthew G. Knepley 
16*52e7713aSMatthew G. Knepley     PetscCall(DMLabelGetStratumIS(domainLabel, labelVal, &domainIS));
17*52e7713aSMatthew G. Knepley     if (domainIS) { // domainIS is non-empty
18*52e7713aSMatthew G. Knepley       PetscCall(ISIntersect(depthIS, domainIS, pointIS));
19*52e7713aSMatthew G. Knepley       PetscCall(ISDestroy(&domainIS));
20*52e7713aSMatthew G. Knepley     } else { // domainIS is NULL (empty)
21*52e7713aSMatthew G. Knepley       *pointIS = NULL;
22*52e7713aSMatthew G. Knepley     }
23*52e7713aSMatthew G. Knepley     PetscCall(ISDestroy(&depthIS));
24*52e7713aSMatthew G. Knepley   } else {
25*52e7713aSMatthew G. Knepley     *pointIS = depthIS;
26*52e7713aSMatthew G. Knepley   }
27*52e7713aSMatthew G. Knepley   PetscFunctionReturn(PETSC_SUCCESS);
28*52e7713aSMatthew G. Knepley }
29*52e7713aSMatthew G. Knepley 
30a2c9b50fSJeremy L Thompson /*@C
31*52e7713aSMatthew G. Knepley   DMPlexGetLocalOffsets - Allocate and populate array of local offsets for each cell closure.
32*52e7713aSMatthew G. Knepley 
33*52e7713aSMatthew G. Knepley   Not collective
34a2c9b50fSJeremy L Thompson 
35a2c9b50fSJeremy L Thompson   Input Parameters:
36a1cb98faSBarry Smith +  dm - The `DMPLEX` object
37a1cb98faSBarry Smith .  domain_label - label for `DMPLEX` domain, or NULL for whole domain
38a1cb98faSBarry Smith .  label_value - Stratum value
39a1cb98faSBarry Smith .  height - Height of target cells in `DMPLEX` topology
40a1cb98faSBarry Smith -  dm_field - Index of `DMPLEX` field
41a2c9b50fSJeremy L Thompson 
42a2c9b50fSJeremy L Thompson   Output Parameters:
43a1cb98faSBarry Smith +  num_cells - Number of local cells
44a1cb98faSBarry Smith .  cell_size - Size of each cell, given by cell_size * num_comp = num_dof
45a1cb98faSBarry Smith .  num_comp - Number of components per dof
46a1cb98faSBarry Smith .  l_size - Size of local vector
47a1cb98faSBarry Smith -  offsets - Allocated offsets array for cells
48a2c9b50fSJeremy L Thompson 
49a2c9b50fSJeremy L Thompson   Level: developer
50a2c9b50fSJeremy L Thompson 
51a1cb98faSBarry Smith   Notes:
52a1cb98faSBarry Smith   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].
53a1cb98faSBarry Smith 
54a1cb98faSBarry Smith    Caller is responsible for freeing the offsets array using `PetscFree()`.
55a1cb98faSBarry Smith 
56*52e7713aSMatthew G. Knepley .seealso: [](chapter_unstructured), `DMPlexGetLocalOffsetsSupport()`, `DM`, `DMPLEX`, `DMLabel`, `DMPlexGetClosureIndices()`, `DMPlexSetClosurePermutationTensor()`, `DMPlexGetCeedRestriction()`
57a2c9b50fSJeremy L Thompson @*/
58d71ae5a4SJacob Faibussowitsch 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)
59d71ae5a4SJacob Faibussowitsch {
60a2c9b50fSJeremy L Thompson   PetscDS         ds = NULL;
61a2c9b50fSJeremy L Thompson   PetscFE         fe;
62a2c9b50fSJeremy L Thompson   PetscSection    section;
637a17eebaSJed Brown   PetscInt        dim, ds_field = -1;
64a2c9b50fSJeremy L Thompson   PetscInt       *restr_indices;
65a2c9b50fSJeremy L Thompson   const PetscInt *iter_indices;
66a2c9b50fSJeremy L Thompson   IS              iter_is;
67a2c9b50fSJeremy L Thompson 
685f80ce2aSJacob Faibussowitsch   PetscFunctionBeginUser;
695f80ce2aSJacob Faibussowitsch   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
709566063dSJacob Faibussowitsch   PetscCall(DMGetLocalSection(dm, &section));
719566063dSJacob Faibussowitsch   PetscCall(DMGetDimension(dm, &dim));
727a17eebaSJed Brown   {
737a17eebaSJed Brown     IS              field_is;
747a17eebaSJed Brown     const PetscInt *fields;
757a17eebaSJed Brown     PetscInt        num_fields;
765f80ce2aSJacob Faibussowitsch 
779566063dSJacob Faibussowitsch     PetscCall(DMGetRegionDS(dm, domain_label, &field_is, &ds));
78a2c9b50fSJeremy L Thompson     // Translate dm_field to ds_field
799566063dSJacob Faibussowitsch     PetscCall(ISGetIndices(field_is, &fields));
809566063dSJacob Faibussowitsch     PetscCall(ISGetSize(field_is, &num_fields));
817a17eebaSJed Brown     for (PetscInt i = 0; i < num_fields; i++) {
827a17eebaSJed Brown       if (dm_field == fields[i]) {
837a17eebaSJed Brown         ds_field = i;
84a2c9b50fSJeremy L Thompson         break;
85a2c9b50fSJeremy L Thompson       }
86a2c9b50fSJeremy L Thompson     }
879566063dSJacob Faibussowitsch     PetscCall(ISRestoreIndices(field_is, &fields));
88a2c9b50fSJeremy L Thompson   }
8963a3b9bcSJacob Faibussowitsch   PetscCheck(ds_field != -1, PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Could not find dm_field %" PetscInt_FMT " in DS", dm_field);
90a2c9b50fSJeremy L Thompson 
91*52e7713aSMatthew G. Knepley   PetscCall(DMGetPoints_Private(dm, domain_label, label_value, height, &iter_is));
92a2c9b50fSJeremy L Thompson   if (iter_is) {
939566063dSJacob Faibussowitsch     PetscCall(ISGetLocalSize(iter_is, num_cells));
949566063dSJacob Faibussowitsch     PetscCall(ISGetIndices(iter_is, &iter_indices));
95a2c9b50fSJeremy L Thompson   } else {
96a2c9b50fSJeremy L Thompson     *num_cells   = 0;
97a2c9b50fSJeremy L Thompson     iter_indices = NULL;
98a2c9b50fSJeremy L Thompson   }
99a2c9b50fSJeremy L Thompson 
100a2c9b50fSJeremy L Thompson   {
101a2c9b50fSJeremy L Thompson     PetscDualSpace dual_space;
102a2c9b50fSJeremy L Thompson     PetscInt       num_dual_basis_vectors;
1035f80ce2aSJacob Faibussowitsch 
1049566063dSJacob Faibussowitsch     PetscCall(PetscDSGetDiscretization(ds, ds_field, (PetscObject *)&fe));
1059566063dSJacob Faibussowitsch     PetscCall(PetscFEGetHeightSubspace(fe, height, &fe));
1067c48043bSMatthew G. Knepley     PetscCheck(fe, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Height %" PetscInt_FMT " is invalid for DG coordinates", height);
1079566063dSJacob Faibussowitsch     PetscCall(PetscFEGetDualSpace(fe, &dual_space));
1089566063dSJacob Faibussowitsch     PetscCall(PetscDualSpaceGetDimension(dual_space, &num_dual_basis_vectors));
1099566063dSJacob Faibussowitsch     PetscCall(PetscDualSpaceGetNumComponents(dual_space, num_comp));
11063a3b9bcSJacob Faibussowitsch     PetscCheck(num_dual_basis_vectors % *num_comp == 0, PETSC_COMM_SELF, PETSC_ERR_SUP, "No support for number of dual basis vectors %" PetscInt_FMT " not divisible by %" PetscInt_FMT " components", num_dual_basis_vectors, *num_comp);
111a2c9b50fSJeremy L Thompson     *cell_size = num_dual_basis_vectors / *num_comp;
112a2c9b50fSJeremy L Thompson   }
113a2c9b50fSJeremy L Thompson   PetscInt restr_size = (*num_cells) * (*cell_size);
1149566063dSJacob Faibussowitsch   PetscCall(PetscMalloc1(restr_size, &restr_indices));
115a2c9b50fSJeremy L Thompson   PetscInt cell_offset = 0;
116a2c9b50fSJeremy L Thompson 
117*52e7713aSMatthew G. Knepley   PetscInt P = (PetscInt)PetscPowReal(*cell_size, 1.0 / (dim - height));
118a2c9b50fSJeremy L Thompson   for (PetscInt p = 0; p < *num_cells; p++) {
119a2c9b50fSJeremy L Thompson     PetscBool flip = PETSC_FALSE;
120a2c9b50fSJeremy L Thompson     PetscInt  c    = iter_indices[p];
121a2c9b50fSJeremy L Thompson     PetscInt  num_indices, *indices;
122a2c9b50fSJeremy L Thompson     PetscInt  field_offsets[17]; // max number of fields plus 1
1239566063dSJacob Faibussowitsch     PetscCall(DMPlexGetClosureIndices(dm, section, section, c, PETSC_TRUE, &num_indices, &indices, field_offsets, NULL));
124a2c9b50fSJeremy L Thompson     if (height > 0) {
125a2c9b50fSJeremy L Thompson       PetscInt        num_cells_support, num_faces, start = -1;
126a2c9b50fSJeremy L Thompson       const PetscInt *orients, *faces, *cells;
1279566063dSJacob Faibussowitsch       PetscCall(DMPlexGetSupport(dm, c, &cells));
1289566063dSJacob Faibussowitsch       PetscCall(DMPlexGetSupportSize(dm, c, &num_cells_support));
1295f80ce2aSJacob Faibussowitsch       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);
1309566063dSJacob Faibussowitsch       PetscCall(DMPlexGetCone(dm, cells[0], &faces));
1319566063dSJacob Faibussowitsch       PetscCall(DMPlexGetConeSize(dm, cells[0], &num_faces));
1329371c9d4SSatish Balay       for (PetscInt i = 0; i < num_faces; i++) {
1339371c9d4SSatish Balay         if (faces[i] == c) start = i;
1349371c9d4SSatish Balay       }
1355f80ce2aSJacob Faibussowitsch       PetscCheck(start >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, "Could not find face %" PetscInt_FMT " in cone of its support", c);
1369566063dSJacob Faibussowitsch       PetscCall(DMPlexGetConeOrientation(dm, cells[0], &orients));
137a2c9b50fSJeremy L Thompson       if (orients[start] < 0) flip = PETSC_TRUE;
138a2c9b50fSJeremy L Thompson     }
139a2c9b50fSJeremy L Thompson 
140a2c9b50fSJeremy L Thompson     for (PetscInt i = 0; i < *cell_size; i++) {
141a2c9b50fSJeremy L Thompson       PetscInt ii = i;
142a2c9b50fSJeremy L Thompson       if (flip) {
143a2c9b50fSJeremy L Thompson         if (*cell_size == P) ii = *cell_size - 1 - i;
144a2c9b50fSJeremy L Thompson         else if (*cell_size == P * P) {
145a2c9b50fSJeremy L Thompson           PetscInt row = i / P, col = i % P;
146a2c9b50fSJeremy L Thompson           ii = row + col * P;
14763a3b9bcSJacob Faibussowitsch         } 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);
148a2c9b50fSJeremy L Thompson       }
149a2c9b50fSJeremy L Thompson       // Essential boundary conditions are encoded as -(loc+1), but we don't care so we decode.
150a2c9b50fSJeremy L Thompson       PetscInt loc                 = indices[field_offsets[dm_field] + ii * (*num_comp)];
151a2c9b50fSJeremy L Thompson       restr_indices[cell_offset++] = loc >= 0 ? loc : -(loc + 1);
152a2c9b50fSJeremy L Thompson     }
1539566063dSJacob Faibussowitsch     PetscCall(DMPlexRestoreClosureIndices(dm, section, section, c, PETSC_TRUE, &num_indices, &indices, field_offsets, NULL));
154a2c9b50fSJeremy L Thompson   }
15563a3b9bcSJacob Faibussowitsch   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);
1569566063dSJacob Faibussowitsch   if (iter_is) PetscCall(ISRestoreIndices(iter_is, &iter_indices));
1579566063dSJacob Faibussowitsch   PetscCall(ISDestroy(&iter_is));
158a2c9b50fSJeremy L Thompson 
159a2c9b50fSJeremy L Thompson   *offsets = restr_indices;
1609566063dSJacob Faibussowitsch   PetscCall(PetscSectionGetStorageSize(section, l_size));
1613ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
162a2c9b50fSJeremy L Thompson }
163a2c9b50fSJeremy L Thompson 
164*52e7713aSMatthew G. Knepley /*@C
165*52e7713aSMatthew G. Knepley   DMPlexGetLocalOffsetsSupport - Allocate and populate arrays of local offsets for each face support.
166*52e7713aSMatthew G. Knepley 
167*52e7713aSMatthew G. Knepley   Not collective
168*52e7713aSMatthew G. Knepley 
169*52e7713aSMatthew G. Knepley   Input Parameters:
170*52e7713aSMatthew G. Knepley +  dm - The `DMPLEX` object
171*52e7713aSMatthew G. Knepley .  domain_label - label for `DMPLEX` domain, or NULL for whole domain
172*52e7713aSMatthew G. Knepley -  label_value - Stratum value
173*52e7713aSMatthew G. Knepley 
174*52e7713aSMatthew G. Knepley   Output Parameters:
175*52e7713aSMatthew G. Knepley +  num_faces - Number of local, non-boundary faces
176*52e7713aSMatthew G. Knepley .  num_comp - Number of components per dof
177*52e7713aSMatthew G. Knepley .  l_size - Size of local vector
178*52e7713aSMatthew G. Knepley .  offsetsNeg - Allocated offsets array for cells on the inward normal side of each face
179*52e7713aSMatthew G. Knepley -  offsetsPos - Allocated offsets array for cells on the outward normal side of each face
180*52e7713aSMatthew G. Knepley 
181*52e7713aSMatthew G. Knepley   Level: developer
182*52e7713aSMatthew G. Knepley 
183*52e7713aSMatthew G. Knepley   Notes:
184*52e7713aSMatthew G. Knepley   Allocate and populate array of shape [num_cells, num_comp] defining offsets for each cell for local vector of the `DMPLEX` field. All offsets are in the range [0, l_size - 1].
185*52e7713aSMatthew G. Knepley 
186*52e7713aSMatthew G. Knepley    Caller is responsible for freeing the offsets array using `PetscFree()`.
187*52e7713aSMatthew G. Knepley 
188*52e7713aSMatthew G. Knepley .seealso: [](chapter_unstructured), `DMPlexGetLocalOffsets()`, `DM`, `DMPLEX`, `DMLabel`, `DMPlexGetClosureIndices()`, `DMPlexSetClosurePermutationTensor()`, `DMPlexGetCeedRestriction()`
189*52e7713aSMatthew G. Knepley @*/
190*52e7713aSMatthew G. Knepley PetscErrorCode DMPlexGetLocalOffsetsSupport(DM dm, DMLabel domain_label, PetscInt label_value, PetscInt *num_faces, PetscInt *num_comp, PetscInt *l_size, PetscInt **offsetsNeg, PetscInt **offsetsPos)
191*52e7713aSMatthew G. Knepley {
192*52e7713aSMatthew G. Knepley   PetscDS         ds = NULL;
193*52e7713aSMatthew G. Knepley   PetscFV         fv;
194*52e7713aSMatthew G. Knepley   PetscSection    section;
195*52e7713aSMatthew G. Knepley   PetscInt        dim, height = 1, dm_field = 0, ds_field = 0, Nf, NfInt = 0, cell_size, restr_size;
196*52e7713aSMatthew G. Knepley   PetscInt       *restr_indices_neg, *restr_indices_pos;
197*52e7713aSMatthew G. Knepley   const PetscInt *iter_indices;
198*52e7713aSMatthew G. Knepley   IS              iter_is;
199*52e7713aSMatthew G. Knepley 
200*52e7713aSMatthew G. Knepley   PetscFunctionBeginUser;
201*52e7713aSMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
202*52e7713aSMatthew G. Knepley   PetscCall(DMGetLocalSection(dm, &section));
203*52e7713aSMatthew G. Knepley   PetscCall(DMGetDimension(dm, &dim));
204*52e7713aSMatthew G. Knepley   PetscCall(DMGetRegionDS(dm, domain_label, NULL, &ds));
205*52e7713aSMatthew G. Knepley 
206*52e7713aSMatthew G. Knepley   PetscCall(DMGetPoints_Private(dm, domain_label, label_value, height, &iter_is));
207*52e7713aSMatthew G. Knepley   if (iter_is) {
208*52e7713aSMatthew G. Knepley     PetscCall(ISGetIndices(iter_is, &iter_indices));
209*52e7713aSMatthew G. Knepley     PetscCall(ISGetLocalSize(iter_is, &Nf));
210*52e7713aSMatthew G. Knepley     for (PetscInt p = 0, Ns; p < Nf; ++p) {
211*52e7713aSMatthew G. Knepley       PetscCall(DMPlexGetSupportSize(dm, iter_indices[p], &Ns));
212*52e7713aSMatthew G. Knepley       if (Ns == 2) ++NfInt;
213*52e7713aSMatthew G. Knepley     }
214*52e7713aSMatthew G. Knepley     *num_faces = NfInt;
215*52e7713aSMatthew G. Knepley   } else {
216*52e7713aSMatthew G. Knepley     *num_faces   = 0;
217*52e7713aSMatthew G. Knepley     iter_indices = NULL;
218*52e7713aSMatthew G. Knepley   }
219*52e7713aSMatthew G. Knepley 
220*52e7713aSMatthew G. Knepley   PetscCall(PetscDSGetDiscretization(ds, ds_field, (PetscObject *)&fv));
221*52e7713aSMatthew G. Knepley   PetscCall(PetscFVGetNumComponents(fv, num_comp));
222*52e7713aSMatthew G. Knepley   cell_size  = *num_comp;
223*52e7713aSMatthew G. Knepley   restr_size = (*num_faces) * cell_size;
224*52e7713aSMatthew G. Knepley   PetscCall(PetscMalloc1(restr_size, &restr_indices_neg));
225*52e7713aSMatthew G. Knepley   PetscCall(PetscMalloc1(restr_size, &restr_indices_pos));
226*52e7713aSMatthew G. Knepley   PetscInt face_offset_neg = 0, face_offset_pos = 0;
227*52e7713aSMatthew G. Knepley 
228*52e7713aSMatthew G. Knepley   for (PetscInt p = 0; p < Nf; ++p) {
229*52e7713aSMatthew G. Knepley     const PetscInt  face = iter_indices[p];
230*52e7713aSMatthew G. Knepley     PetscInt        num_indices, *indices;
231*52e7713aSMatthew G. Knepley     PetscInt        field_offsets[17]; // max number of fields plus 1
232*52e7713aSMatthew G. Knepley     const PetscInt *supp;
233*52e7713aSMatthew G. Knepley     PetscInt        Ns;
234*52e7713aSMatthew G. Knepley 
235*52e7713aSMatthew G. Knepley     PetscCall(DMPlexGetSupport(dm, face, &supp));
236*52e7713aSMatthew G. Knepley     PetscCall(DMPlexGetSupportSize(dm, face, &Ns));
237*52e7713aSMatthew G. Knepley     // Ignore boundary faces
238*52e7713aSMatthew G. Knepley     //   TODO check for face on parallel boundary
239*52e7713aSMatthew G. Knepley     if (Ns == 2) {
240*52e7713aSMatthew G. Knepley       // Essential boundary conditions are encoded as -(loc+1), but we don't care so we decode.
241*52e7713aSMatthew G. Knepley       PetscCall(DMPlexGetClosureIndices(dm, section, section, supp[0], PETSC_TRUE, &num_indices, &indices, field_offsets, NULL));
242*52e7713aSMatthew G. Knepley       for (PetscInt i = 0; i < cell_size; i++) {
243*52e7713aSMatthew G. Knepley         const PetscInt loc                   = indices[field_offsets[dm_field] + i * (*num_comp)];
244*52e7713aSMatthew G. Knepley         restr_indices_neg[face_offset_neg++] = loc >= 0 ? loc : -(loc + 1);
245*52e7713aSMatthew G. Knepley       }
246*52e7713aSMatthew G. Knepley       PetscCall(DMPlexRestoreClosureIndices(dm, section, section, supp[0], PETSC_TRUE, &num_indices, &indices, field_offsets, NULL));
247*52e7713aSMatthew G. Knepley       PetscCall(DMPlexGetClosureIndices(dm, section, section, supp[1], PETSC_TRUE, &num_indices, &indices, field_offsets, NULL));
248*52e7713aSMatthew G. Knepley       for (PetscInt i = 0; i < cell_size; i++) {
249*52e7713aSMatthew G. Knepley         const PetscInt loc                   = indices[field_offsets[dm_field] + i * (*num_comp)];
250*52e7713aSMatthew G. Knepley         restr_indices_pos[face_offset_pos++] = loc >= 0 ? loc : -(loc + 1);
251*52e7713aSMatthew G. Knepley       }
252*52e7713aSMatthew G. Knepley       PetscCall(DMPlexRestoreClosureIndices(dm, section, section, supp[1], PETSC_TRUE, &num_indices, &indices, field_offsets, NULL));
253*52e7713aSMatthew G. Knepley     }
254*52e7713aSMatthew G. Knepley   }
255*52e7713aSMatthew G. Knepley   PetscCheck(face_offset_neg == restr_size, PETSC_COMM_SELF, PETSC_ERR_SUP, "Shape mismatch, neg offsets array of shape (%" PetscInt_FMT ", %" PetscInt_FMT ") initialized for %" PetscInt_FMT " nodes", *num_faces, cell_size, face_offset_neg);
256*52e7713aSMatthew G. Knepley   PetscCheck(face_offset_pos == restr_size, PETSC_COMM_SELF, PETSC_ERR_SUP, "Shape mismatch, pos offsets array of shape (%" PetscInt_FMT ", %" PetscInt_FMT ") initialized for %" PetscInt_FMT " nodes", *num_faces, cell_size, face_offset_pos);
257*52e7713aSMatthew G. Knepley   if (iter_is) PetscCall(ISRestoreIndices(iter_is, &iter_indices));
258*52e7713aSMatthew G. Knepley   PetscCall(ISDestroy(&iter_is));
259*52e7713aSMatthew G. Knepley 
260*52e7713aSMatthew G. Knepley   *offsetsNeg = restr_indices_neg;
261*52e7713aSMatthew G. Knepley   *offsetsPos = restr_indices_pos;
262*52e7713aSMatthew G. Knepley   PetscCall(PetscSectionGetStorageSize(section, l_size));
263*52e7713aSMatthew G. Knepley   PetscFunctionReturn(PETSC_SUCCESS);
264*52e7713aSMatthew G. Knepley }
265*52e7713aSMatthew G. Knepley 
266a2c9b50fSJeremy L Thompson #if defined(PETSC_HAVE_LIBCEED)
267f918ec44SMatthew G. Knepley   #include <petscdmplexceed.h>
268f918ec44SMatthew G. Knepley 
269a2c9b50fSJeremy L Thompson /*@C
270a2c9b50fSJeremy L Thompson   DMPlexGetCeedRestriction - Define the libCEED map from the local vector (Lvector) to the cells (Evector)
271a2c9b50fSJeremy L Thompson 
272a2c9b50fSJeremy L Thompson   Input Parameters:
273a1cb98faSBarry Smith +  dm - The `DMPLEX` object
274a1cb98faSBarry Smith .  domain_label - label for `DMPLEX` domain, or NULL for the whole domain
275a1cb98faSBarry Smith .  label_value - Stratum value
276a1cb98faSBarry Smith .  height - Height of target cells in `DMPLEX` topology
277a1cb98faSBarry Smith -  dm_field - Index of `DMPLEX` field
278a2c9b50fSJeremy L Thompson 
279a1cb98faSBarry Smith   Output Parameter:
280a1cb98faSBarry Smith .  ERestrict - libCEED restriction from local vector to to the cells
281a2c9b50fSJeremy L Thompson 
282a2c9b50fSJeremy L Thompson   Level: developer
283a1cb98faSBarry Smith 
284a1cb98faSBarry Smith .seealso: [](chapter_unstructured), `DM`, `DMPLEX`, `DMLabel`, `DMPlexGetLocalOffsets()`
285a2c9b50fSJeremy L Thompson @*/
286d71ae5a4SJacob Faibussowitsch PetscErrorCode DMPlexGetCeedRestriction(DM dm, DMLabel domain_label, PetscInt label_value, PetscInt height, PetscInt dm_field, CeedElemRestriction *ERestrict)
287d71ae5a4SJacob Faibussowitsch {
288f918ec44SMatthew G. Knepley   PetscFunctionBeginUser;
289f918ec44SMatthew G. Knepley   PetscValidHeaderSpecific(dm, DM_CLASSID, 1);
29021066fe8SJed Brown   PetscValidPointer(ERestrict, 6);
291f918ec44SMatthew G. Knepley   if (!dm->ceedERestrict) {
292a2c9b50fSJeremy L Thompson     PetscInt            num_cells, cell_size, num_comp, lvec_size, *restr_indices;
293a2c9b50fSJeremy L Thompson     CeedElemRestriction elem_restr;
294f918ec44SMatthew G. Knepley     Ceed                ceed;
295f918ec44SMatthew G. Knepley 
2969566063dSJacob Faibussowitsch     PetscCall(DMPlexGetLocalOffsets(dm, domain_label, label_value, height, dm_field, &num_cells, &cell_size, &num_comp, &lvec_size, &restr_indices));
2979566063dSJacob Faibussowitsch     PetscCall(DMGetCeed(dm, &ceed));
2989566063dSJacob Faibussowitsch     PetscCallCEED(CeedElemRestrictionCreate(ceed, num_cells, cell_size, num_comp, 1, lvec_size, CEED_MEM_HOST, CEED_COPY_VALUES, restr_indices, &elem_restr));
2999566063dSJacob Faibussowitsch     PetscCall(PetscFree(restr_indices));
300a2c9b50fSJeremy L Thompson     dm->ceedERestrict = elem_restr;
301f918ec44SMatthew G. Knepley   }
302f918ec44SMatthew G. Knepley   *ERestrict = dm->ceedERestrict;
3033ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
304f918ec44SMatthew G. Knepley }
305f918ec44SMatthew G. Knepley 
306f918ec44SMatthew G. Knepley #endif
307