Actual source code: plexglvis.c
petsc-3.14.1 2020-11-03
1: #include <petsc/private/glvisviewerimpl.h>
2: #include <petsc/private/petscimpl.h>
3: #include <petsc/private/dmpleximpl.h>
4: #include <petscbt.h>
5: #include <petscdmplex.h>
6: #include <petscsf.h>
7: #include <petscds.h>
9: typedef struct {
10: PetscInt nf;
11: VecScatter *scctx;
12: } GLVisViewerCtx;
14: static PetscErrorCode DestroyGLVisViewerCtx_Private(void *vctx)
15: {
16: GLVisViewerCtx *ctx = (GLVisViewerCtx*)vctx;
17: PetscInt i;
21: for (i=0;i<ctx->nf;i++) {
22: VecScatterDestroy(&ctx->scctx[i]);
23: }
24: PetscFree(ctx->scctx);
25: PetscFree(vctx);
26: return(0);
27: }
29: static PetscErrorCode DMPlexSampleGLVisFields_Private(PetscObject oX, PetscInt nf, PetscObject oXfield[], void *vctx)
30: {
31: GLVisViewerCtx *ctx = (GLVisViewerCtx*)vctx;
32: PetscInt f;
36: for (f=0;f<nf;f++) {
37: VecScatterBegin(ctx->scctx[f],(Vec)oX,(Vec)oXfield[f],INSERT_VALUES,SCATTER_FORWARD);
38: VecScatterEnd(ctx->scctx[f],(Vec)oX,(Vec)oXfield[f],INSERT_VALUES,SCATTER_FORWARD);
39: }
40: return(0);
41: }
43: /* for FEM, it works for H1 fields only and extracts dofs at cell vertices, discarding any other dof */
44: PetscErrorCode DMSetUpGLVisViewer_Plex(PetscObject odm, PetscViewer viewer)
45: {
46: DM dm = (DM)odm;
47: Vec xlocal,xfield,*Ufield;
48: PetscDS ds;
49: IS globalNum,isfield;
50: PetscBT vown;
51: char **fieldname = NULL,**fec_type = NULL;
52: const PetscInt *gNum;
53: PetscInt *nlocal,*bs,*idxs,*dims;
54: PetscInt f,maxfields,nfields,c,totc,totdofs,Nv,cum,i;
55: PetscInt dim,cStart,cEnd,vStart,vEnd;
56: GLVisViewerCtx *ctx;
57: PetscSection s;
61: DMGetDimension(dm,&dim);
62: DMPlexGetDepthStratum(dm,0,&vStart,&vEnd);
63: DMPlexGetHeightStratum(dm,0,&cStart,&cEnd);
64: PetscObjectQuery((PetscObject)dm,"_glvis_plex_gnum",(PetscObject*)&globalNum);
65: if (!globalNum) {
66: DMPlexCreateCellNumbering_Internal(dm,PETSC_TRUE,&globalNum);
67: PetscObjectCompose((PetscObject)dm,"_glvis_plex_gnum",(PetscObject)globalNum);
68: PetscObjectDereference((PetscObject)globalNum);
69: }
70: ISGetIndices(globalNum,&gNum);
71: PetscBTCreate(vEnd-vStart,&vown);
72: for (c = cStart, totc = 0; c < cEnd; c++) {
73: if (gNum[c-cStart] >= 0) {
74: PetscInt i,numPoints,*points = NULL;
76: totc++;
77: DMPlexGetTransitiveClosure(dm,c,PETSC_TRUE,&numPoints,&points);
78: for (i=0;i<numPoints*2;i+= 2) {
79: if ((points[i] >= vStart) && (points[i] < vEnd)) {
80: PetscBTSet(vown,points[i]-vStart);
81: }
82: }
83: DMPlexRestoreTransitiveClosure(dm,c,PETSC_TRUE,&numPoints,&points);
84: }
85: }
86: for (f=0,Nv=0;f<vEnd-vStart;f++) if (PetscLikely(PetscBTLookup(vown,f))) Nv++;
88: DMCreateLocalVector(dm,&xlocal);
89: VecGetLocalSize(xlocal,&totdofs);
90: DMGetLocalSection(dm,&s);
91: PetscSectionGetNumFields(s,&nfields);
92: for (f=0,maxfields=0;f<nfields;f++) {
93: PetscInt bs;
95: PetscSectionGetFieldComponents(s,f,&bs);
96: maxfields += bs;
97: }
98: PetscCalloc7(maxfields,&fieldname,maxfields,&nlocal,maxfields,&bs,maxfields,&dims,maxfields,&fec_type,totdofs,&idxs,maxfields,&Ufield);
99: PetscNew(&ctx);
100: PetscCalloc1(maxfields,&ctx->scctx);
101: DMGetDS(dm,&ds);
102: if (ds) {
103: for (f=0;f<nfields;f++) {
104: const char* fname;
105: char name[256];
106: PetscObject disc;
107: size_t len;
109: PetscSectionGetFieldName(s,f,&fname);
110: PetscStrlen(fname,&len);
111: if (len) {
112: PetscStrcpy(name,fname);
113: } else {
114: PetscSNPrintf(name,256,"Field%D",f);
115: }
116: PetscDSGetDiscretization(ds,f,&disc);
117: if (disc) {
118: PetscClassId id;
119: PetscInt Nc;
120: char fec[64];
122: PetscObjectGetClassId(disc, &id);
123: if (id == PETSCFE_CLASSID) {
124: PetscFE fem = (PetscFE)disc;
125: PetscDualSpace sp;
126: PetscDualSpaceType spname;
127: PetscInt order;
128: PetscBool islag,continuous,H1 = PETSC_TRUE;
130: PetscFEGetNumComponents(fem,&Nc);
131: PetscFEGetDualSpace(fem,&sp);
132: PetscDualSpaceGetType(sp,&spname);
133: PetscStrcmp(spname,PETSCDUALSPACELAGRANGE,&islag);
134: if (!islag) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Unsupported dual space");
135: PetscDualSpaceLagrangeGetContinuity(sp,&continuous);
136: PetscDualSpaceGetOrder(sp,&order);
137: if (continuous && order > 0) { /* no support for high-order viz, still have to figure out the numbering */
138: PetscSNPrintf(fec,64,"FiniteElementCollection: H1_%DD_P1",dim);
139: } else {
140: if (!continuous && order) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Discontinuous space visualization currently unsupported for order %D",order);
141: H1 = PETSC_FALSE;
142: PetscSNPrintf(fec,64,"FiniteElementCollection: L2_%DD_P%D",dim,order);
143: }
144: PetscStrallocpy(name,&fieldname[ctx->nf]);
145: bs[ctx->nf] = Nc;
146: dims[ctx->nf] = dim;
147: if (H1) {
148: nlocal[ctx->nf] = Nc * Nv;
149: PetscStrallocpy(fec,&fec_type[ctx->nf]);
150: VecCreateSeq(PETSC_COMM_SELF,Nv*Nc,&xfield);
151: for (i=0,cum=0;i<vEnd-vStart;i++) {
152: PetscInt j,off;
154: if (PetscUnlikely(!PetscBTLookup(vown,i))) continue;
155: PetscSectionGetFieldOffset(s,i+vStart,f,&off);
156: for (j=0;j<Nc;j++) idxs[cum++] = off + j;
157: }
158: ISCreateGeneral(PetscObjectComm((PetscObject)xlocal),Nv*Nc,idxs,PETSC_USE_POINTER,&isfield);
159: } else {
160: nlocal[ctx->nf] = Nc * totc;
161: PetscStrallocpy(fec,&fec_type[ctx->nf]);
162: VecCreateSeq(PETSC_COMM_SELF,Nc*totc,&xfield);
163: for (i=0,cum=0;i<cEnd-cStart;i++) {
164: PetscInt j,off;
166: if (PetscUnlikely(gNum[i] < 0)) continue;
167: PetscSectionGetFieldOffset(s,i+cStart,f,&off);
168: for (j=0;j<Nc;j++) idxs[cum++] = off + j;
169: }
170: ISCreateGeneral(PetscObjectComm((PetscObject)xlocal),totc*Nc,idxs,PETSC_USE_POINTER,&isfield);
171: }
172: VecScatterCreate(xlocal,isfield,xfield,NULL,&ctx->scctx[ctx->nf]);
173: VecDestroy(&xfield);
174: ISDestroy(&isfield);
175: ctx->nf++;
176: } else if (id == PETSCFV_CLASSID) {
177: PetscInt c;
179: PetscFVGetNumComponents((PetscFV)disc,&Nc);
180: PetscSNPrintf(fec,64,"FiniteElementCollection: L2_%DD_P0",dim);
181: for (c = 0; c < Nc; c++) {
182: char comp[256];
183: PetscSNPrintf(comp,256,"%s-Comp%D",name,c);
184: PetscStrallocpy(comp,&fieldname[ctx->nf]);
185: bs[ctx->nf] = 1; /* Does PetscFV support components with different block size? */
186: nlocal[ctx->nf] = totc;
187: dims[ctx->nf] = dim;
188: PetscStrallocpy(fec,&fec_type[ctx->nf]);
189: VecCreateSeq(PETSC_COMM_SELF,totc,&xfield);
190: for (i=0,cum=0;i<cEnd-cStart;i++) {
191: PetscInt off;
193: if (PetscUnlikely(gNum[i])<0) continue;
194: PetscSectionGetFieldOffset(s,i+cStart,f,&off);
195: idxs[cum++] = off + c;
196: }
197: ISCreateGeneral(PetscObjectComm((PetscObject)xlocal),totc,idxs,PETSC_USE_POINTER,&isfield);
198: VecScatterCreate(xlocal,isfield,xfield,NULL,&ctx->scctx[ctx->nf]);
199: VecDestroy(&xfield);
200: ISDestroy(&isfield);
201: ctx->nf++;
202: }
203: } else SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONG,"Unknown discretization type for field %D",f);
204: } else SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Missing discretization for field %D",f);
205: }
206: } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Needs a DS attached to the DM");
207: PetscBTDestroy(&vown);
208: VecDestroy(&xlocal);
209: ISRestoreIndices(globalNum,&gNum);
211: /* create work vectors */
212: for (f=0;f<ctx->nf;f++) {
213: VecCreateMPI(PetscObjectComm((PetscObject)dm),nlocal[f],PETSC_DECIDE,&Ufield[f]);
214: PetscObjectSetName((PetscObject)Ufield[f],fieldname[f]);
215: VecSetBlockSize(Ufield[f],bs[f]);
216: VecSetDM(Ufield[f],dm);
217: }
219: /* customize the viewer */
220: PetscViewerGLVisSetFields(viewer,ctx->nf,(const char**)fec_type,dims,DMPlexSampleGLVisFields_Private,(PetscObject*)Ufield,ctx,DestroyGLVisViewerCtx_Private);
221: for (f=0;f<ctx->nf;f++) {
222: PetscFree(fieldname[f]);
223: PetscFree(fec_type[f]);
224: VecDestroy(&Ufield[f]);
225: }
226: PetscFree7(fieldname,nlocal,bs,dims,fec_type,idxs,Ufield);
227: return(0);
228: }
230: typedef enum {MFEM_POINT=0,MFEM_SEGMENT,MFEM_TRIANGLE,MFEM_SQUARE,MFEM_TETRAHEDRON,MFEM_CUBE,MFEM_PRISM,MFEM_UNDEF} MFEM_cid;
232: MFEM_cid mfem_table_cid[4][7] = { {MFEM_POINT,MFEM_UNDEF,MFEM_UNDEF ,MFEM_UNDEF ,MFEM_UNDEF ,MFEM_UNDEF,MFEM_UNDEF},
233: {MFEM_POINT,MFEM_UNDEF,MFEM_SEGMENT,MFEM_UNDEF ,MFEM_UNDEF ,MFEM_UNDEF,MFEM_UNDEF},
234: {MFEM_POINT,MFEM_UNDEF,MFEM_SEGMENT,MFEM_TRIANGLE,MFEM_SQUARE ,MFEM_UNDEF,MFEM_UNDEF},
235: {MFEM_POINT,MFEM_UNDEF,MFEM_SEGMENT,MFEM_UNDEF ,MFEM_TETRAHEDRON,MFEM_PRISM,MFEM_CUBE } };
237: MFEM_cid mfem_table_cid_unint[4][9] = { {MFEM_POINT,MFEM_UNDEF,MFEM_UNDEF ,MFEM_UNDEF ,MFEM_UNDEF ,MFEM_UNDEF,MFEM_PRISM,MFEM_UNDEF,MFEM_UNDEF},
238: {MFEM_POINT,MFEM_UNDEF,MFEM_SEGMENT,MFEM_UNDEF ,MFEM_UNDEF ,MFEM_UNDEF,MFEM_PRISM,MFEM_UNDEF,MFEM_UNDEF},
239: {MFEM_POINT,MFEM_UNDEF,MFEM_SEGMENT,MFEM_TRIANGLE,MFEM_SQUARE ,MFEM_UNDEF,MFEM_PRISM,MFEM_UNDEF,MFEM_UNDEF},
240: {MFEM_POINT,MFEM_UNDEF,MFEM_SEGMENT,MFEM_UNDEF ,MFEM_TETRAHEDRON,MFEM_UNDEF,MFEM_PRISM,MFEM_UNDEF,MFEM_CUBE } };
242: static PetscErrorCode DMPlexGetPointMFEMCellID_Internal(DM dm, DMLabel label, PetscInt minl, PetscInt p, PetscInt *mid, PetscInt *cid)
243: {
244: DMLabel dlabel;
245: PetscInt depth,csize,pdepth,dim;
249: DMPlexGetDepthLabel(dm,&dlabel);
250: DMLabelGetValue(dlabel,p,&pdepth);
251: DMPlexGetConeSize(dm,p,&csize);
252: DMPlexGetDepth(dm,&depth);
253: DMGetDimension(dm,&dim);
254: if (label) {
255: DMLabelGetValue(label,p,mid);
256: *mid = *mid - minl + 1; /* MFEM does not like negative markers */
257: } else *mid = 1;
258: if (depth >=0 && dim != depth) { /* not interpolated, it assumes cell-vertex mesh */
259: if (dim < 0 || dim > 3) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Dimension %D",dim);
260: if (csize > 8) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_SUP,"Found cone size %D for point %D",csize,p);
261: if (depth != 1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_SUP,"Found depth %D for point %D. You should interpolate the mesh first",depth,p);
262: *cid = mfem_table_cid_unint[dim][csize];
263: } else {
264: if (csize > 6) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cone size %D for point %D",csize,p);
265: if (pdepth < 0 || pdepth > 3) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_SUP,"Depth %D for point %D",csize,p);
266: *cid = mfem_table_cid[pdepth][csize];
267: }
268: return(0);
269: }
271: static PetscErrorCode DMPlexGetPointMFEMVertexIDs_Internal(DM dm, PetscInt p, PetscSection csec, PetscInt *nv, PetscInt vids[])
272: {
273: PetscInt dim,sdim,dof = 0,off = 0,i,q,vStart,vEnd,numPoints,*points = NULL;
277: DMPlexGetDepthStratum(dm,0,&vStart,&vEnd);
278: DMGetDimension(dm,&dim);
279: sdim = dim;
280: if (csec) {
281: PetscInt sStart,sEnd;
283: DMGetCoordinateDim(dm,&sdim);
284: PetscSectionGetChart(csec,&sStart,&sEnd);
285: PetscSectionGetOffset(csec,vStart,&off);
286: off = off/sdim;
287: if (p >= sStart && p < sEnd) {
288: PetscSectionGetDof(csec,p,&dof);
289: }
290: }
291: if (!dof) {
292: DMPlexGetTransitiveClosure(dm,p,PETSC_TRUE,&numPoints,&points);
293: for (i=0,q=0;i<numPoints*2;i+= 2)
294: if ((points[i] >= vStart) && (points[i] < vEnd))
295: vids[q++] = points[i]-vStart+off;
296: DMPlexRestoreTransitiveClosure(dm,p,PETSC_TRUE,&numPoints,&points);
297: } else {
298: PetscSectionGetOffset(csec,p,&off);
299: PetscSectionGetDof(csec,p,&dof);
300: for (q=0;q<dof/sdim;q++) vids[q] = off/sdim + q;
301: }
302: *nv = q;
303: return(0);
304: }
306: static PetscErrorCode GLVisCreateFE(PetscFE femIn,char name[32],PetscFE *fem)
307: {
308: DM K;
309: PetscSpace P;
310: PetscDualSpace Q;
311: PetscQuadrature q,fq;
312: PetscInt dim,deg,dof;
313: DMPolytopeType ptype;
314: PetscBool isSimplex,isTensor;
315: PetscBool continuity = PETSC_FALSE;
316: PetscDTNodeType nodeType = PETSCDTNODES_GAUSSJACOBI;
317: PetscBool endpoint = PETSC_TRUE;
318: MPI_Comm comm;
319: PetscErrorCode ierr;
322: comm = PetscObjectComm((PetscObject)femIn);
323: PetscFEGetBasisSpace(femIn,&P);
324: PetscFEGetDualSpace(femIn,&Q);
325: PetscDualSpaceGetDM(Q,&K);
326: DMGetDimension(K,&dim);
327: PetscSpaceGetDegree(P,°,NULL);
328: PetscSpaceGetNumComponents(P,&dof);
329: DMPlexGetCellType(K,0,&ptype);
330: switch (ptype) {
331: case DM_POLYTOPE_QUADRILATERAL:
332: case DM_POLYTOPE_HEXAHEDRON:
333: isSimplex = PETSC_FALSE; break;
334: default:
335: isSimplex = PETSC_TRUE; break;
336: }
337: isTensor = isSimplex ? PETSC_FALSE : PETSC_TRUE;
338: /* Create space */
339: PetscSpaceCreate(comm,&P);
340: PetscSpaceSetType(P,PETSCSPACEPOLYNOMIAL);
341: PetscSpacePolynomialSetTensor(P,isTensor);
342: PetscSpaceSetNumComponents(P,dof);
343: PetscSpaceSetNumVariables(P,dim);
344: PetscSpaceSetDegree(P,deg,PETSC_DETERMINE);
345: PetscSpaceSetUp(P);
346: /* Create dual space */
347: PetscDualSpaceCreate(comm,&Q);
348: PetscDualSpaceSetType(Q,PETSCDUALSPACELAGRANGE);
349: PetscDualSpaceLagrangeSetTensor(Q,isTensor);
350: PetscDualSpaceLagrangeSetContinuity(Q,continuity);
351: PetscDualSpaceLagrangeSetNodeType(Q,nodeType,endpoint,0);
352: PetscDualSpaceSetNumComponents(Q,dof);
353: PetscDualSpaceSetOrder(Q,deg);
354: PetscDualSpaceCreateReferenceCell(Q,dim,isSimplex,&K);
355: PetscDualSpaceSetDM(Q,K);
356: DMDestroy(&K);
357: PetscDualSpaceSetUp(Q);
358: /* Create quadrature */
359: if (isSimplex) {
360: PetscDTStroudConicalQuadrature(dim, 1,deg+1,-1,+1,&q);
361: PetscDTStroudConicalQuadrature(dim-1,1,deg+1,-1,+1,&fq);
362: } else {
363: PetscDTGaussTensorQuadrature(dim, 1,deg+1,-1,+1,&q);
364: PetscDTGaussTensorQuadrature(dim-1,1,deg+1,-1,+1,&fq);
365: }
366: /* Create finite element */
367: PetscFECreate(comm,fem);
368: PetscSNPrintf(name,32,"L2_T1_%DD_P%D",dim,deg);
369: PetscObjectSetName((PetscObject)*fem,name);
370: PetscFESetType(*fem,PETSCFEBASIC);
371: PetscFESetNumComponents(*fem,dof);
372: PetscFESetBasisSpace(*fem,P);
373: PetscFESetDualSpace(*fem,Q);
374: PetscFESetQuadrature(*fem,q);
375: PetscFESetFaceQuadrature(*fem,fq);
376: PetscFESetUp(*fem);
377: /* Cleanup */
378: PetscSpaceDestroy(&P);
379: PetscDualSpaceDestroy(&Q);
380: PetscQuadratureDestroy(&q);
381: PetscQuadratureDestroy(&fq);
382: return(0);
383: }
385: /*
386: ASCII visualization/dump: full support for simplices and tensor product cells. It supports AMR
387: Higher order meshes are also supported
388: */
389: static PetscErrorCode DMPlexView_GLVis_ASCII(DM dm, PetscViewer viewer)
390: {
391: DMLabel label;
392: PetscSection coordSection,parentSection;
393: Vec coordinates,hovec;
394: const PetscScalar *array;
395: PetscInt bf,p,sdim,dim,depth,novl,minl;
396: PetscInt cStart,cEnd,vStart,vEnd,nvert;
397: PetscMPIInt size;
398: PetscBool localized,isascii;
399: PetscBool enable_mfem,enable_boundary,enable_ncmesh,view_ovl = PETSC_FALSE;
400: PetscBT pown,vown;
401: PetscErrorCode ierr;
402: PetscContainer glvis_container;
403: PetscBool cellvertex = PETSC_FALSE, periodic, enabled = PETSC_TRUE;
404: PetscBool enable_emark,enable_bmark;
405: const char *fmt;
406: char emark[64] = "",bmark[64] = "";
411: PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
412: if (!isascii) SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"Viewer must be of type VIEWERASCII");
413: MPI_Comm_size(PetscObjectComm((PetscObject)viewer),&size);
414: if (size > 1) SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"Use single sequential viewers for parallel visualization");
415: DMGetDimension(dm,&dim);
417: /* get container: determines if a process visualizes is portion of the data or not */
418: PetscObjectQuery((PetscObject)viewer,"_glvis_info_container",(PetscObject*)&glvis_container);
419: if (!glvis_container) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_PLIB,"Missing GLVis container");
420: {
421: PetscViewerGLVisInfo glvis_info;
422: PetscContainerGetPointer(glvis_container,(void**)&glvis_info);
423: enabled = glvis_info->enabled;
424: fmt = glvis_info->fmt;
425: }
427: /* Users can attach a coordinate vector to the DM in case they have a higher-order mesh
428: DMPlex does not currently support HO meshes, so there's no API for this */
429: PetscObjectQuery((PetscObject)dm,"_glvis_mesh_coords",(PetscObject*)&hovec);
430: PetscObjectReference((PetscObject)hovec);
431: if (!hovec) {
432: DM cdm;
433: PetscFE disc;
434: PetscClassId classid;
436: DMGetCoordinateDM(dm,&cdm);
437: DMGetField(cdm,0,NULL,(PetscObject*)&disc);
438: PetscObjectGetClassId((PetscObject)disc,&classid);
439: if (classid == PETSCFE_CLASSID) {
440: DM hocdm;
441: PetscFE hodisc;
442: Vec vec;
443: Mat mat;
444: char name[32],fec_type[64];
446: GLVisCreateFE(disc,name,&hodisc);
447: DMClone(cdm,&hocdm);
448: DMSetField(hocdm,0,NULL,(PetscObject)hodisc);
449: PetscFEDestroy(&hodisc);
450: DMCreateDS(hocdm);
452: DMGetCoordinates(dm,&vec);
453: DMCreateGlobalVector(hocdm,&hovec);
454: DMCreateInterpolation(cdm,hocdm,&mat,NULL);
455: MatInterpolate(mat,vec,hovec);
456: MatDestroy(&mat);
457: DMDestroy(&hocdm);
459: PetscSNPrintf(fec_type,sizeof(fec_type),"FiniteElementCollection: %s", name);
460: PetscObjectSetName((PetscObject)hovec,fec_type);
461: }
462: }
464: DMPlexGetHeightStratum(dm,0,&cStart,&cEnd);
465: DMPlexGetGhostCellStratum(dm,&p,NULL);
466: if (p >= 0) cEnd = p;
467: DMPlexGetDepthStratum(dm,0,&vStart,&vEnd);
468: DMGetPeriodicity(dm,&periodic,NULL,NULL,NULL);
469: DMGetCoordinatesLocalized(dm,&localized);
470: if (periodic && !localized && !hovec) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Coordinates need to be localized");
471: DMGetCoordinateSection(dm,&coordSection);
472: DMGetCoordinateDim(dm,&sdim);
473: DMGetCoordinatesLocal(dm,&coordinates);
474: if (!coordinates && !hovec) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Missing local coordinates vector");
476: /*
477: a couple of sections of the mesh specification are disabled
478: - boundary: the boundary is not needed for proper mesh visualization unless we want to visualize boundary attributes or we have high-order coordinates in 3D (topologically)
479: - vertex_parents: used for non-conforming meshes only when we want to use MFEM as a discretization package
480: and be able to derefine the mesh (MFEM does not currently have to ability to read ncmeshes in parallel)
481: */
482: enable_boundary = PETSC_FALSE;
483: enable_ncmesh = PETSC_FALSE;
484: enable_mfem = PETSC_FALSE;
485: enable_emark = PETSC_FALSE;
486: enable_bmark = PETSC_FALSE;
487: /* I'm tired of problems with negative values in the markers, disable them */
488: PetscOptionsBegin(PetscObjectComm((PetscObject)dm),((PetscObject)dm)->prefix,"GLVis PetscViewer DMPlex Options","PetscViewer");
489: PetscOptionsBool("-viewer_glvis_dm_plex_enable_boundary","Enable boundary section in mesh representation",NULL,enable_boundary,&enable_boundary,NULL);
490: PetscOptionsBool("-viewer_glvis_dm_plex_enable_ncmesh","Enable vertex_parents section in mesh representation (allows derefinement)",NULL,enable_ncmesh,&enable_ncmesh,NULL);
491: PetscOptionsBool("-viewer_glvis_dm_plex_enable_mfem","Dump a mesh that can be used with MFEM's FiniteElementSpaces",NULL,enable_mfem,&enable_mfem,NULL);
492: PetscOptionsBool("-viewer_glvis_dm_plex_overlap","Include overlap region in local meshes",NULL,view_ovl,&view_ovl,NULL);
493: PetscOptionsString("-viewer_glvis_dm_plex_emarker","String for the material id label",NULL,emark,emark,sizeof(emark),&enable_emark);
494: PetscOptionsString("-viewer_glvis_dm_plex_bmarker","String for the boundary id label",NULL,bmark,bmark,sizeof(bmark),&enable_bmark);
495: PetscOptionsEnd();
496: if (enable_bmark) enable_boundary = PETSC_TRUE;
498: MPI_Comm_size(PetscObjectComm((PetscObject)dm),&size);
499: if (enable_ncmesh && size > 1) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Not supported in parallel");
500: DMPlexGetDepth(dm,&depth);
501: if (enable_boundary && depth >= 0 && dim != depth) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Mesh must be interpolated. "
502: "Alternatively, run with -viewer_glvis_dm_plex_enable_boundary 0");
503: if (enable_ncmesh && depth >= 0 && dim != depth) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Mesh must be interpolated. "
504: "Alternatively, run with -viewer_glvis_dm_plex_enable_ncmesh 0");
505: if (depth >=0 && dim != depth) { /* not interpolated, it assumes cell-vertex mesh */
506: if (depth != 1) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unsupported depth %D. You should interpolate the mesh first",depth);
507: cellvertex = PETSC_TRUE;
508: }
510: /* Identify possible cells in the overlap */
511: novl = 0;
512: pown = NULL;
513: if (size > 1) {
514: IS globalNum = NULL;
515: const PetscInt *gNum;
516: PetscBool ovl = PETSC_FALSE;
518: PetscObjectQuery((PetscObject)dm,"_glvis_plex_gnum",(PetscObject*)&globalNum);
519: if (!globalNum) {
520: if (view_ovl) {
521: ISCreateStride(PetscObjectComm((PetscObject)dm),cEnd-cStart,0,1,&globalNum);
522: } else {
523: DMPlexCreateCellNumbering_Internal(dm,PETSC_TRUE,&globalNum);
524: }
525: PetscObjectCompose((PetscObject)dm,"_glvis_plex_gnum",(PetscObject)globalNum);
526: PetscObjectDereference((PetscObject)globalNum);
527: }
528: ISGetIndices(globalNum,&gNum);
529: for (p=cStart; p<cEnd; p++) {
530: if (gNum[p-cStart] < 0) {
531: ovl = PETSC_TRUE;
532: novl++;
533: }
534: }
535: if (ovl) {
536: /* it may happen that pown get not destroyed, if the user closes the window while this function is running.
537: TODO: garbage collector? attach pown to dm? */
538: PetscBTCreate(cEnd-cStart,&pown);
539: for (p=cStart; p<cEnd; p++) {
540: if (gNum[p-cStart] < 0) continue;
541: else {
542: PetscBTSet(pown,p-cStart);
543: }
544: }
545: }
546: ISRestoreIndices(globalNum,&gNum);
547: }
549: /* return if this process is disabled */
550: if (!enabled) {
551: PetscViewerASCIIPrintf(viewer,"MFEM mesh v1.1\n");
552: PetscViewerASCIIPrintf(viewer,"\ndimension\n");
553: PetscViewerASCIIPrintf(viewer,"%D\n",dim);
554: PetscViewerASCIIPrintf(viewer,"\nelements\n");
555: PetscViewerASCIIPrintf(viewer,"%D\n",0);
556: PetscViewerASCIIPrintf(viewer,"\nboundary\n");
557: PetscViewerASCIIPrintf(viewer,"%D\n",0);
558: PetscViewerASCIIPrintf(viewer,"\nvertices\n");
559: PetscViewerASCIIPrintf(viewer,"%D\n",0);
560: PetscViewerASCIIPrintf(viewer,"%D\n",sdim);
561: PetscBTDestroy(&pown);
562: VecDestroy(&hovec);
563: return(0);
564: }
566: if (enable_mfem) {
567: if (periodic && !hovec) { /* we need to generate a vector of L2 coordinates, as this is how MFEM handles periodic meshes */
568: PetscInt vpc = 0;
569: char fec[64];
570: PetscInt vids[8] = {0,1,2,3,4,5,6,7};
571: PetscInt hexv[8] = {0,1,3,2,4,5,7,6}, tetv[4] = {0,1,2,3};
572: PetscInt quadv[8] = {0,1,3,2}, triv[3] = {0,1,2};
573: PetscInt *dof = NULL;
574: PetscScalar *array,*ptr;
576: PetscSNPrintf(fec,sizeof(fec),"FiniteElementCollection: L2_T1_%DD_P1",dim);
577: if (cEnd-cStart) {
578: PetscInt fpc;
580: DMPlexGetConeSize(dm,cStart,&fpc);
581: switch(dim) {
582: case 1:
583: vpc = 2;
584: dof = hexv;
585: break;
586: case 2:
587: switch (fpc) {
588: case 3:
589: vpc = 3;
590: dof = triv;
591: break;
592: case 4:
593: vpc = 4;
594: dof = quadv;
595: break;
596: default:
597: SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unhandled case: faces per cell %D",fpc);
598: break;
599: }
600: break;
601: case 3:
602: switch (fpc) {
603: case 4: /* TODO: still need to understand L2 ordering for tets */
604: vpc = 4;
605: dof = tetv;
606: SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unhandled tethraedral case");
607: break;
608: case 6:
609: if (cellvertex) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unhandled case: vertices per cell %D",fpc);
610: vpc = 8;
611: dof = hexv;
612: break;
613: case 8:
614: if (!cellvertex) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unhandled case: faces per cell %D",fpc);
615: vpc = 8;
616: dof = hexv;
617: break;
618: default:
619: SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unhandled case: faces per cell %D",fpc);
620: break;
621: }
622: break;
623: default:
624: SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Unhandled dim");
625: break;
626: }
627: DMPlexReorderCell(dm,cStart,vids);
628: }
629: if (!dof) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_PLIB,"Missing dofs");
630: VecCreateSeq(PETSC_COMM_SELF,(cEnd-cStart-novl)*vpc*sdim,&hovec);
631: PetscObjectSetName((PetscObject)hovec,fec);
632: VecGetArray(hovec,&array);
633: ptr = array;
634: for (p=cStart;p<cEnd;p++) {
635: PetscInt csize,v,d;
636: PetscScalar *vals = NULL;
638: if (PetscUnlikely(pown && !PetscBTLookup(pown,p-cStart))) continue;
639: DMPlexVecGetClosure(dm,coordSection,coordinates,p,&csize,&vals);
640: if (csize != vpc*sdim && csize != vpc*sdim*2) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unsupported closure size %D (vpc %D, sdim %D)",csize,vpc,sdim);
641: for (v=0;v<vpc;v++) {
642: for (d=0;d<sdim;d++) {
643: ptr[sdim*dof[v]+d] = vals[sdim*vids[v]+d];
644: }
645: }
646: ptr += vpc*sdim;
647: DMPlexVecRestoreClosure(dm,coordSection,coordinates,p,&csize,&vals);
648: }
649: VecRestoreArray(hovec,&array);
650: }
651: }
652: /* if we have high-order coordinates in 3D, we need to specify the boundary */
653: if (hovec && dim == 3) enable_boundary = PETSC_TRUE;
655: /* header */
656: PetscViewerASCIIPrintf(viewer,"MFEM mesh v1.1\n");
658: /* topological dimension */
659: PetscViewerASCIIPrintf(viewer,"\ndimension\n");
660: PetscViewerASCIIPrintf(viewer,"%D\n",dim);
662: /* elements */
663: minl = 1;
664: label = NULL;
665: if (enable_emark) {
666: PetscInt lminl = PETSC_MAX_INT;
668: DMGetLabel(dm,emark,&label);
669: if (label) {
670: IS vals;
671: PetscInt ldef;
673: DMLabelGetDefaultValue(label,&ldef);
674: DMLabelGetValueIS(label,&vals);
675: ISGetMinMax(vals,&lminl,NULL);
676: ISDestroy(&vals);
677: lminl = PetscMin(ldef,lminl);
678: }
679: MPIU_Allreduce(&lminl,&minl,1,MPIU_INT,MPI_MIN,PetscObjectComm((PetscObject)dm));
680: if (minl == PETSC_MAX_INT) minl = 1;
681: }
682: PetscViewerASCIIPrintf(viewer,"\nelements\n");
683: PetscViewerASCIIPrintf(viewer,"%D\n",cEnd-cStart-novl);
684: for (p=cStart;p<cEnd;p++) {
685: PetscInt vids[8];
686: PetscInt i,nv = 0,cid = -1,mid = 1;
688: if (PetscUnlikely(pown && !PetscBTLookup(pown,p-cStart))) continue;
689: DMPlexGetPointMFEMCellID_Internal(dm,label,minl,p,&mid,&cid);
690: DMPlexGetPointMFEMVertexIDs_Internal(dm,p,(localized && !hovec) ? coordSection : NULL,&nv,vids);
691: DMPlexReorderCell(dm,p,vids);
692: PetscViewerASCIIPrintf(viewer,"%D %D",mid,cid);
693: for (i=0;i<nv;i++) {
694: PetscViewerASCIIPrintf(viewer," %D",vids[i]);
695: }
696: PetscViewerASCIIPrintf(viewer,"\n");
697: }
699: /* boundary */
700: PetscViewerASCIIPrintf(viewer,"\nboundary\n");
701: if (!enable_boundary) {
702: PetscViewerASCIIPrintf(viewer,"%D\n",0);
703: } else {
704: DMLabel perLabel;
705: PetscBT bfaces;
706: PetscInt fStart,fEnd,*fcells;
708: DMPlexGetHeightStratum(dm,1,&fStart,&fEnd);
709: PetscBTCreate(fEnd-fStart,&bfaces);
710: DMPlexGetMaxSizes(dm,NULL,&p);
711: PetscMalloc1(p,&fcells);
712: DMGetLabel(dm,"glvis_periodic_cut",&perLabel);
713: if (!perLabel && localized) { /* this periodic cut can be moved up to DMPlex setup */
714: DMCreateLabel(dm,"glvis_periodic_cut");
715: DMGetLabel(dm,"glvis_periodic_cut",&perLabel);
716: DMLabelSetDefaultValue(perLabel,1);
717: for (p=cStart;p<cEnd;p++) {
718: DMPolytopeType cellType;
719: PetscInt dof;
721: DMPlexGetCellType(dm,p,&cellType);
722: PetscSectionGetDof(coordSection,p,&dof);
723: if (dof) {
724: PetscInt uvpc, v,csize,cellClosureSize,*cellClosure = NULL,*vidxs = NULL;
725: PetscScalar *vals = NULL;
727: uvpc = DMPolytopeTypeGetNumVertices(cellType);
728: if (dof%sdim) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Incompatible number of cell dofs %D and space dimension %D",dof,sdim);
729: DMPlexVecGetClosure(dm,coordSection,coordinates,p,&csize,&vals);
730: DMPlexGetTransitiveClosure(dm,p,PETSC_TRUE,&cellClosureSize,&cellClosure);
731: for (v=0;v<cellClosureSize;v++)
732: if (cellClosure[2*v] >= vStart && cellClosure[2*v] < vEnd) {
733: vidxs = cellClosure + 2*v;
734: break;
735: }
736: if (!vidxs) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Missing vertices");
737: for (v=0;v<uvpc;v++) {
738: PetscInt s;
740: for (s=0;s<sdim;s++) {
741: if (PetscAbsScalar(vals[v*sdim+s]-vals[v*sdim+s+uvpc*sdim])>PETSC_MACHINE_EPSILON) {
742: DMLabelSetValue(perLabel,vidxs[2*v],2);
743: }
744: }
745: }
746: DMPlexRestoreTransitiveClosure(dm,p,PETSC_TRUE,&cellClosureSize,&cellClosure);
747: DMPlexVecRestoreClosure(dm,coordSection,coordinates,p,&csize,&vals);
748: }
749: }
750: if (dim > 1) {
751: PetscInt eEnd,eStart;
753: DMPlexGetDepthStratum(dm,1,&eStart,&eEnd);
754: for (p=eStart;p<eEnd;p++) {
755: const PetscInt *cone;
756: PetscInt coneSize,i;
757: PetscBool ispe = PETSC_TRUE;
759: DMPlexGetCone(dm,p,&cone);
760: DMPlexGetConeSize(dm,p,&coneSize);
761: for (i=0;i<coneSize;i++) {
762: PetscInt v;
764: DMLabelGetValue(perLabel,cone[i],&v);
765: ispe = (PetscBool)(ispe && (v==2));
766: }
767: if (ispe && coneSize) {
768: PetscInt ch, numChildren;
769: const PetscInt *children;
771: DMLabelSetValue(perLabel,p,2);
772: DMPlexGetTreeChildren(dm,p,&numChildren,&children);
773: for (ch = 0; ch < numChildren; ch++) {
774: DMLabelSetValue(perLabel,children[ch],2);
775: }
776: }
777: }
778: if (dim > 2) {
779: for (p=fStart;p<fEnd;p++) {
780: const PetscInt *cone;
781: PetscInt coneSize,i;
782: PetscBool ispe = PETSC_TRUE;
784: DMPlexGetCone(dm,p,&cone);
785: DMPlexGetConeSize(dm,p,&coneSize);
786: for (i=0;i<coneSize;i++) {
787: PetscInt v;
789: DMLabelGetValue(perLabel,cone[i],&v);
790: ispe = (PetscBool)(ispe && (v==2));
791: }
792: if (ispe && coneSize) {
793: PetscInt ch, numChildren;
794: const PetscInt *children;
796: DMLabelSetValue(perLabel,p,2);
797: DMPlexGetTreeChildren(dm,p,&numChildren,&children);
798: for (ch = 0; ch < numChildren; ch++) {
799: DMLabelSetValue(perLabel,children[ch],2);
800: }
801: }
802: }
803: }
804: }
805: }
806: for (p=fStart;p<fEnd;p++) {
807: const PetscInt *support;
808: PetscInt supportSize;
809: PetscBool isbf = PETSC_FALSE;
811: DMPlexGetSupportSize(dm,p,&supportSize);
812: if (pown) {
813: PetscBool has_owned = PETSC_FALSE, has_ghost = PETSC_FALSE;
814: PetscInt i;
816: DMPlexGetSupport(dm,p,&support);
817: for (i=0;i<supportSize;i++) {
818: if (PetscLikely(PetscBTLookup(pown,support[i]-cStart))) has_owned = PETSC_TRUE;
819: else has_ghost = PETSC_TRUE;
820: }
821: isbf = (PetscBool)((supportSize == 1 && has_owned) || (supportSize > 1 && has_owned && has_ghost));
822: } else {
823: isbf = (PetscBool)(supportSize == 1);
824: }
825: if (!isbf && perLabel) {
826: const PetscInt *cone;
827: PetscInt coneSize,i;
829: DMPlexGetCone(dm,p,&cone);
830: DMPlexGetConeSize(dm,p,&coneSize);
831: isbf = PETSC_TRUE;
832: for (i=0;i<coneSize;i++) {
833: PetscInt v,d;
835: DMLabelGetValue(perLabel,cone[i],&v);
836: DMLabelGetDefaultValue(perLabel,&d);
837: isbf = (PetscBool)(isbf && v != d);
838: }
839: }
840: if (isbf) {
841: PetscBTSet(bfaces,p-fStart);
842: }
843: }
844: /* count boundary faces */
845: for (p=fStart,bf=0;p<fEnd;p++) {
846: if (PetscUnlikely(PetscBTLookup(bfaces,p-fStart))) {
847: const PetscInt *support;
848: PetscInt supportSize,c;
850: DMPlexGetSupportSize(dm,p,&supportSize);
851: DMPlexGetSupport(dm,p,&support);
852: for (c=0;c<supportSize;c++) {
853: const PetscInt *cone;
854: PetscInt cell,cl,coneSize;
856: cell = support[c];
857: if (pown && PetscUnlikely(!PetscBTLookup(pown,cell-cStart))) continue;
858: DMPlexGetCone(dm,cell,&cone);
859: DMPlexGetConeSize(dm,cell,&coneSize);
860: for (cl=0;cl<coneSize;cl++) {
861: if (cone[cl] == p) {
862: bf += 1;
863: break;
864: }
865: }
866: }
867: }
868: }
869: minl = 1;
870: label = NULL;
871: if (enable_bmark) {
872: PetscInt lminl = PETSC_MAX_INT;
874: DMGetLabel(dm,bmark,&label);
875: if (label) {
876: IS vals;
877: PetscInt ldef;
879: DMLabelGetDefaultValue(label,&ldef);
880: DMLabelGetValueIS(label,&vals);
881: ISGetMinMax(vals,&lminl,NULL);
882: ISDestroy(&vals);
883: lminl = PetscMin(ldef,lminl);
884: }
885: MPIU_Allreduce(&lminl,&minl,1,MPIU_INT,MPI_MIN,PetscObjectComm((PetscObject)dm));
886: if (minl == PETSC_MAX_INT) minl = 1;
887: }
888: PetscViewerASCIIPrintf(viewer,"%D\n",bf);
889: for (p=fStart;p<fEnd;p++) {
890: if (PetscUnlikely(PetscBTLookup(bfaces,p-fStart))) {
891: const PetscInt *support;
892: PetscInt supportSize,c,nc = 0;
894: DMPlexGetSupportSize(dm,p,&supportSize);
895: DMPlexGetSupport(dm,p,&support);
896: if (pown) {
897: for (c=0;c<supportSize;c++) {
898: if (PetscLikely(PetscBTLookup(pown,support[c]-cStart))) {
899: fcells[nc++] = support[c];
900: }
901: }
902: } else for (c=0;c<supportSize;c++) fcells[nc++] = support[c];
903: for (c=0;c<nc;c++) {
904: const DMPolytopeType *faceTypes;
905: DMPolytopeType cellType;
906: const PetscInt *faceSizes,*cone;
907: PetscInt vids[8],*faces,st,i,coneSize,cell,cl,nv,cid = -1,mid = -1;
909: cell = fcells[c];
910: DMPlexGetCone(dm,cell,&cone);
911: DMPlexGetConeSize(dm,cell,&coneSize);
912: for (cl=0;cl<coneSize;cl++)
913: if (cone[cl] == p)
914: break;
915: if (cl == coneSize) continue;
917: /* face material id and type */
918: DMPlexGetPointMFEMCellID_Internal(dm,label,minl,p,&mid,&cid);
919: PetscViewerASCIIPrintf(viewer,"%D %D",mid,cid);
920: /* vertex ids */
921: DMPlexGetCellType(dm,cell,&cellType);
922: DMPlexGetPointMFEMVertexIDs_Internal(dm,cell,(localized && !hovec) ? coordSection : NULL,&nv,vids);
923: DMPlexGetRawFaces_Internal(dm,cellType,vids,NULL,&faceTypes,&faceSizes,(const PetscInt**)&faces);
924: st = 0;
925: for (i=0;i<cl;i++) st += faceSizes[i];
926: DMPlexInvertCell(faceTypes[cl],faces + st);
927: for (i=0;i<faceSizes[cl];i++) {
928: PetscViewerASCIIPrintf(viewer," %d",faces[st+i]);
929: }
930: PetscViewerASCIIPrintf(viewer,"\n");
931: DMPlexRestoreRawFaces_Internal(dm,cellType,vids,NULL,&faceTypes,&faceSizes,(const PetscInt**)&faces);
932: bf -= 1;
933: }
934: }
935: }
936: if (bf) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Remaining boundary faces %D",bf);
937: PetscBTDestroy(&bfaces);
938: PetscFree(fcells);
939: }
941: /* mark owned vertices */
942: vown = NULL;
943: if (pown) {
944: PetscBTCreate(vEnd-vStart,&vown);
945: for (p=cStart;p<cEnd;p++) {
946: PetscInt i,closureSize,*closure = NULL;
948: if (PetscUnlikely(!PetscBTLookup(pown,p-cStart))) continue;
949: DMPlexGetTransitiveClosure(dm,p,PETSC_TRUE,&closureSize,&closure);
950: for (i=0;i<closureSize;i++) {
951: const PetscInt pp = closure[2*i];
953: if (pp >= vStart && pp < vEnd) {
954: PetscBTSet(vown,pp-vStart);
955: }
956: }
957: DMPlexRestoreTransitiveClosure(dm,p,PETSC_TRUE,&closureSize,&closure);
958: }
959: }
961: /* vertex_parents (Non-conforming meshes) */
962: parentSection = NULL;
963: if (enable_ncmesh) {
964: DMPlexGetTree(dm,&parentSection,NULL,NULL,NULL,NULL);
965: }
966: if (parentSection) {
967: PetscInt vp,gvp;
969: for (vp=0,p=vStart;p<vEnd;p++) {
970: DMLabel dlabel;
971: PetscInt parent,depth;
973: if (PetscUnlikely(vown && !PetscBTLookup(vown,p-vStart))) continue;
974: DMPlexGetDepthLabel(dm,&dlabel);
975: DMLabelGetValue(dlabel,p,&depth);
976: DMPlexGetTreeParent(dm,p,&parent,NULL);
977: if (parent != p) vp++;
978: }
979: MPIU_Allreduce(&vp,&gvp,1,MPIU_INT,MPI_SUM,PetscObjectComm((PetscObject)dm));
980: if (gvp) {
981: PetscInt maxsupp;
982: PetscBool *skip = NULL;
984: PetscViewerASCIIPrintf(viewer,"\nvertex_parents\n");
985: PetscViewerASCIIPrintf(viewer,"%D\n",vp);
986: DMPlexGetMaxSizes(dm,NULL,&maxsupp);
987: PetscMalloc1(maxsupp,&skip);
988: for (p=vStart;p<vEnd;p++) {
989: DMLabel dlabel;
990: PetscInt parent;
992: if (PetscUnlikely(vown && !PetscBTLookup(vown,p-vStart))) continue;
993: DMPlexGetDepthLabel(dm,&dlabel);
994: DMPlexGetTreeParent(dm,p,&parent,NULL);
995: if (parent != p) {
996: PetscInt vids[8] = { -1, -1, -1, -1, -1, -1, -1, -1 }; /* silent overzealous clang static analyzer */
997: PetscInt i,nv,ssize,n,numChildren,depth = -1;
998: const PetscInt *children;
1000: DMPlexGetConeSize(dm,parent,&ssize);
1001: switch (ssize) {
1002: case 2: /* edge */
1003: nv = 0;
1004: DMPlexGetPointMFEMVertexIDs_Internal(dm,parent,localized ? coordSection : NULL,&nv,vids);
1005: PetscViewerASCIIPrintf(viewer,"%D",p-vStart);
1006: for (i=0;i<nv;i++) {
1007: PetscViewerASCIIPrintf(viewer," %D",vids[i]);
1008: }
1009: PetscViewerASCIIPrintf(viewer,"\n");
1010: vp--;
1011: break;
1012: case 4: /* face */
1013: DMPlexGetTreeChildren(dm,parent,&numChildren,&children);
1014: for (n=0;n<numChildren;n++) {
1015: DMLabelGetValue(dlabel,children[n],&depth);
1016: if (!depth) {
1017: const PetscInt *hvsupp,*hesupp,*cone;
1018: PetscInt hvsuppSize,hesuppSize,coneSize;
1019: PetscInt hv = children[n],he = -1,f;
1021: PetscArrayzero(skip,maxsupp);
1022: DMPlexGetSupportSize(dm,hv,&hvsuppSize);
1023: DMPlexGetSupport(dm,hv,&hvsupp);
1024: for (i=0;i<hvsuppSize;i++) {
1025: PetscInt ep;
1026: DMPlexGetTreeParent(dm,hvsupp[i],&ep,NULL);
1027: if (ep != hvsupp[i]) {
1028: he = hvsupp[i];
1029: } else {
1030: skip[i] = PETSC_TRUE;
1031: }
1032: }
1033: if (he == -1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_SUP,"Vertex %D support size %D: hanging edge not found",hv,hvsuppSize);
1034: DMPlexGetCone(dm,he,&cone);
1035: vids[0] = (cone[0] == hv) ? cone[1] : cone[0];
1036: DMPlexGetSupportSize(dm,he,&hesuppSize);
1037: DMPlexGetSupport(dm,he,&hesupp);
1038: for (f=0;f<hesuppSize;f++) {
1039: PetscInt j;
1041: DMPlexGetCone(dm,hesupp[f],&cone);
1042: DMPlexGetConeSize(dm,hesupp[f],&coneSize);
1043: for (j=0;j<coneSize;j++) {
1044: PetscInt k;
1045: for (k=0;k<hvsuppSize;k++) {
1046: if (hvsupp[k] == cone[j]) {
1047: skip[k] = PETSC_TRUE;
1048: break;
1049: }
1050: }
1051: }
1052: }
1053: for (i=0;i<hvsuppSize;i++) {
1054: if (!skip[i]) {
1055: DMPlexGetCone(dm,hvsupp[i],&cone);
1056: vids[1] = (cone[0] == hv) ? cone[1] : cone[0];
1057: }
1058: }
1059: PetscViewerASCIIPrintf(viewer,"%D",hv-vStart);
1060: for (i=0;i<2;i++) {
1061: PetscViewerASCIIPrintf(viewer," %D",vids[i]-vStart);
1062: }
1063: PetscViewerASCIIPrintf(viewer,"\n");
1064: vp--;
1065: }
1066: }
1067: break;
1068: default:
1069: SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Don't know how to deal with support size %D",ssize);
1070: }
1071: }
1072: }
1073: PetscFree(skip);
1074: }
1075: if (vp) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Unexpected %D hanging vertices",vp);
1076: }
1077: PetscBTDestroy(&pown);
1078: PetscBTDestroy(&vown);
1080: /* vertices */
1081: if (hovec) { /* higher-order meshes */
1082: const char *fec;
1083: PetscInt i,n,s;
1085: PetscViewerASCIIPrintf(viewer,"\nvertices\n");
1086: PetscViewerASCIIPrintf(viewer,"%D\n",vEnd-vStart);
1087: PetscViewerASCIIPrintf(viewer,"nodes\n");
1088: PetscObjectGetName((PetscObject)hovec,&fec);
1089: PetscViewerASCIIPrintf(viewer,"FiniteElementSpace\n");
1090: PetscViewerASCIIPrintf(viewer,"%s\n",fec);
1091: PetscViewerASCIIPrintf(viewer,"VDim: %D\n",sdim);
1092: PetscViewerASCIIPrintf(viewer,"Ordering: 1\n\n"); /*Ordering::byVDIM*/
1093: VecGetArrayRead(hovec,&array);
1094: VecGetLocalSize(hovec,&n);
1095: if (n%sdim) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Size of local coordinate vector %D incompatible with space dimension %D",n,sdim);
1096: for (i=0;i<n/sdim;i++) {
1097: for (s=0;s<sdim;s++) {
1098: PetscViewerASCIIPrintf(viewer,fmt,PetscRealPart(array[i*sdim+s]));
1099: }
1100: PetscViewerASCIIPrintf(viewer,"\n");
1101: }
1102: VecRestoreArrayRead(hovec,&array);
1103: } else {
1104: VecGetLocalSize(coordinates,&nvert);
1105: PetscViewerASCIIPrintf(viewer,"\nvertices\n");
1106: PetscViewerASCIIPrintf(viewer,"%D\n",nvert/sdim);
1107: PetscViewerASCIIPrintf(viewer,"%D\n",sdim);
1108: VecGetArrayRead(coordinates,&array);
1109: for (p=0;p<nvert/sdim;p++) {
1110: PetscInt s;
1111: for (s=0;s<sdim;s++) {
1112: PetscReal v = PetscRealPart(array[p*sdim+s]);
1114: PetscViewerASCIIPrintf(viewer,fmt,PetscIsInfOrNanReal(v) ? 0.0 : v);
1115: }
1116: PetscViewerASCIIPrintf(viewer,"\n");
1117: }
1118: VecRestoreArrayRead(coordinates,&array);
1119: }
1120: VecDestroy(&hovec);
1121: return(0);
1122: }
1124: PetscErrorCode DMPlexView_GLVis(DM dm, PetscViewer viewer)
1125: {
1128: DMView_GLVis(dm,viewer,DMPlexView_GLVis_ASCII);
1129: return(0);
1130: }