#include #include <../src/sys/classes/viewer/impls/vtk/vtkvimpl.h> typedef struct { PetscInt nvertices; PetscInt ncells; PetscInt nconn; /* number of entries in cell->vertex connectivity array */ } PieceInfo; #if defined(PETSC_USE_REAL_SINGLE) || defined(PETSC_USE_REAL___FP16) /* output in float if single or half precision in memory */ static const char precision[] = "Float32"; typedef float PetscVTUReal; #define MPIU_VTUREAL MPI_FLOAT #elif defined(PETSC_USE_REAL_DOUBLE) || defined(PETSC_USE_REAL___FLOAT128) /* output in double if double or quad precision in memory */ static const char precision[] = "Float64"; typedef double PetscVTUReal; #define MPIU_VTUREAL MPI_DOUBLE #else static const char precision[] = "UnknownPrecision"; typedef PetscReal PetscVTUReal; #define MPIU_VTUREAL MPIU_REAL #endif static PetscErrorCode TransferWrite(MPI_Comm comm, PetscViewer viewer,FILE *fp,PetscMPIInt srank,PetscMPIInt root,const void *send,void *recv,PetscMPIInt count,MPI_Datatype mpidatatype,PetscMPIInt tag) { PetscMPIInt rank; PetscFunctionBegin; CHKERRMPI(MPI_Comm_rank(comm,&rank)); if (rank == srank && rank != root) { CHKERRMPI(MPI_Send((void*)send,count,mpidatatype,root,tag,comm)); } else if (rank == root) { const void *buffer; if (root == srank) { /* self */ buffer = send; } else { MPI_Status status; PetscMPIInt nrecv; CHKERRMPI(MPI_Recv(recv,count,mpidatatype,srank,tag,comm,&status)); CHKERRMPI(MPI_Get_count(&status,mpidatatype,&nrecv)); PetscCheckFalse(count != nrecv,PETSC_COMM_SELF,PETSC_ERR_PLIB,"Array size mismatch"); buffer = recv; } CHKERRQ(PetscViewerVTKFWrite(viewer,fp,buffer,count,mpidatatype)); } PetscFunctionReturn(0); } static PetscErrorCode DMPlexGetVTKConnectivity(DM dm, PetscBool localized, PieceInfo *piece,PetscVTKInt **oconn,PetscVTKInt **ooffsets,PetscVTKType **otypes) { PetscSection coordSection; PetscVTKInt *conn,*offsets; PetscVTKType *types; PetscInt dim,vStart,vEnd,cStart,cEnd,pStart,pEnd,cellHeight,numLabelCells,hasLabel,c,v,countcell,countconn; PetscFunctionBegin; CHKERRQ(PetscMalloc3(piece->nconn,&conn,piece->ncells,&offsets,piece->ncells,&types)); CHKERRQ(DMGetCoordinateSection(dm, &coordSection)); CHKERRQ(DMGetDimension(dm,&dim)); CHKERRQ(DMPlexGetChart(dm,&pStart,&pEnd)); CHKERRQ(DMPlexGetVTKCellHeight(dm, &cellHeight)); CHKERRQ(DMPlexGetHeightStratum(dm, cellHeight, &cStart, &cEnd)); CHKERRQ(DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd)); CHKERRQ(DMGetStratumSize(dm, "vtk", 1, &numLabelCells)); hasLabel = numLabelCells > 0 ? PETSC_TRUE : PETSC_FALSE; countcell = 0; countconn = 0; for (c = cStart; c < cEnd; ++c) { PetscInt nverts,dof = 0,celltype,startoffset,nC=0; if (hasLabel) { PetscInt value; CHKERRQ(DMGetLabelValue(dm, "vtk", c, &value)); if (value != 1) continue; } startoffset = countconn; if (localized) { CHKERRQ(PetscSectionGetDof(coordSection, c, &dof)); } if (!dof) { PetscInt *closure = NULL; PetscInt closureSize; CHKERRQ(DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure)); for (v = 0; v < closureSize*2; v += 2) { if ((closure[v] >= vStart) && (closure[v] < vEnd)) { if (!localized) conn[countconn++] = closure[v] - vStart; else conn[countconn++] = startoffset + nC; ++nC; } } CHKERRQ(DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure)); } else { for (nC = 0; nC < dof/dim; nC++) conn[countconn++] = startoffset + nC; } { PetscInt n = PetscMin(nC, 8), s = countconn - nC, i, cone[8]; for (i = 0; i < n; ++i) cone[i] = conn[s+i]; CHKERRQ(DMPlexReorderCell(dm, c, cone)); for (i = 0; i < n; ++i) conn[s+i] = (int)cone[i]; } offsets[countcell] = countconn; nverts = countconn - startoffset; CHKERRQ(DMPlexVTKGetCellType_Internal(dm,dim,nverts,&celltype)); types[countcell] = celltype; countcell++; } PetscCheckFalse(countcell != piece->ncells,PETSC_COMM_SELF,PETSC_ERR_PLIB,"Inconsistent cell count"); PetscCheckFalse(countconn != piece->nconn,PETSC_COMM_SELF,PETSC_ERR_PLIB,"Inconsistent connectivity count"); *oconn = conn; *ooffsets = offsets; *otypes = types; PetscFunctionReturn(0); } /* Write all fields that have been provided to the viewer Multi-block XML format with binary appended data. */ PetscErrorCode DMPlexVTKWriteAll_VTU(DM dm,PetscViewer viewer) { MPI_Comm comm; PetscSection coordSection; PetscViewer_VTK *vtk = (PetscViewer_VTK*)viewer->data; PetscViewerVTKObjectLink link; FILE *fp; PetscMPIInt rank,size,tag; PetscInt dimEmbed,cellHeight,cStart,cEnd,vStart,vEnd,numLabelCells,hasLabel,c,v,r,i; PetscBool localized; PieceInfo piece,*gpiece = NULL; void *buffer = NULL; const char *byte_order = PetscBinaryBigEndian() ? "BigEndian" : "LittleEndian"; PetscInt loops_per_scalar; PetscFunctionBegin; CHKERRQ(PetscObjectGetComm((PetscObject)dm,&comm)); #if defined(PETSC_USE_COMPLEX) loops_per_scalar = 2; #else loops_per_scalar = 1; #endif CHKERRMPI(MPI_Comm_size(comm,&size)); CHKERRMPI(MPI_Comm_rank(comm,&rank)); CHKERRQ(PetscCommGetNewTag(comm,&tag)); CHKERRQ(PetscFOpen(comm,vtk->filename,"wb",&fp)); CHKERRQ(PetscFPrintf(comm,fp,"\n")); CHKERRQ(PetscFPrintf(comm,fp,"\n", byte_order)); CHKERRQ(PetscFPrintf(comm,fp," \n")); CHKERRQ(DMGetCoordinateDim(dm, &dimEmbed)); CHKERRQ(DMPlexGetVTKCellHeight(dm, &cellHeight)); CHKERRQ(DMPlexGetHeightStratum(dm, cellHeight, &cStart, &cEnd)); CHKERRQ(DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd)); CHKERRQ(DMGetStratumSize(dm, "vtk", 1, &numLabelCells)); CHKERRQ(DMGetCoordinatesLocalized(dm, &localized)); CHKERRQ(DMGetCoordinateSection(dm, &coordSection)); hasLabel = numLabelCells > 0 ? PETSC_TRUE : PETSC_FALSE; piece.nvertices = 0; piece.ncells = 0; piece.nconn = 0; if (!localized) piece.nvertices = vEnd - vStart; for (c = cStart; c < cEnd; ++c) { PetscInt dof = 0; if (hasLabel) { PetscInt value; CHKERRQ(DMGetLabelValue(dm, "vtk", c, &value)); if (value != 1) continue; } if (localized) { CHKERRQ(PetscSectionGetDof(coordSection, c, &dof)); } if (!dof) { PetscInt *closure = NULL; PetscInt closureSize; CHKERRQ(DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure)); for (v = 0; v < closureSize*2; v += 2) { if ((closure[v] >= vStart) && (closure[v] < vEnd)) { piece.nconn++; if (localized) piece.nvertices++; } } CHKERRQ(DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure)); } else { piece.nvertices += dof/dimEmbed; piece.nconn += dof/dimEmbed; } piece.ncells++; } if (rank == 0) CHKERRQ(PetscMalloc1(size,&gpiece)); CHKERRMPI(MPI_Gather((PetscInt*)&piece,sizeof(piece)/sizeof(PetscInt),MPIU_INT,(PetscInt*)gpiece,sizeof(piece)/sizeof(PetscInt),MPIU_INT,0,comm)); /* * Write file header */ if (rank == 0) { PetscInt boffset = 0; for (r=0; r\n",gpiece[r].nvertices,gpiece[r].ncells)); /* Coordinate positions */ CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n")); CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n",precision,boffset)); boffset += gpiece[r].nvertices*3*sizeof(PetscVTUReal) + sizeof(int); CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n")); /* Cell connectivity */ CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n")); CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n",boffset)); boffset += gpiece[r].nconn*sizeof(PetscInt) + sizeof(int); CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n",boffset)); boffset += gpiece[r].ncells*sizeof(PetscInt) + sizeof(int); CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n",boffset)); boffset += gpiece[r].ncells*sizeof(unsigned char) + sizeof(int); CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n")); /* * Cell Data headers */ CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n")); CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n",boffset)); boffset += gpiece[r].ncells*sizeof(int) + sizeof(int); /* all the vectors */ for (link=vtk->link; link; link=link->next) { Vec X = (Vec)link->vec; DM dmX = NULL; PetscInt bs = 1,nfields,field; const char *vecname = ""; PetscSection section; if ((link->ft != PETSC_VTK_CELL_FIELD) && (link->ft != PETSC_VTK_CELL_VECTOR_FIELD)) continue; if (((PetscObject)X)->name || link != vtk->link) { /* If the object is already named, use it. If it is past the first link, name it to disambiguate. */ CHKERRQ(PetscObjectGetName((PetscObject)X,&vecname)); } CHKERRQ(VecGetDM(X, &dmX)); if (!dmX) dmX = dm; CHKERRQ(PetscObjectQuery(link->vec, "section", (PetscObject*) §ion)); if (!section) CHKERRQ(DMGetLocalSection(dmX, §ion)); if (cEnd > cStart) CHKERRQ(PetscSectionGetDof(section,cStart,&bs)); CHKERRQ(PetscSectionGetNumFields(section,&nfields)); field = 0; if (link->field >= 0) { field = link->field; nfields = field + 1; } for (i=0; field<(nfields?nfields:1); field++) { PetscInt fbs,j; PetscFV fv = NULL; PetscObject f; PetscClassId fClass; const char *fieldname = NULL; char buf[256]; PetscBool vector; if (nfields) { /* We have user-defined fields/components */ CHKERRQ(PetscSectionGetFieldDof(section,cStart,field,&fbs)); CHKERRQ(PetscSectionGetFieldName(section,field,&fieldname)); } else fbs = bs; /* Say we have one field with 'bs' components */ CHKERRQ(DMGetField(dmX,field,NULL,&f)); CHKERRQ(PetscObjectGetClassId(f,&fClass)); if (fClass == PETSCFV_CLASSID) { fv = (PetscFV) f; } if (nfields && !fieldname) { CHKERRQ(PetscSNPrintf(buf,sizeof(buf),"CellField%D",field)); fieldname = buf; } vector = PETSC_FALSE; if (link->ft == PETSC_VTK_CELL_VECTOR_FIELD) { vector = PETSC_TRUE; PetscCheckFalse(fbs > 3,PetscObjectComm((PetscObject)viewer),PETSC_ERR_ARG_SIZ,"Cell vector fields can have at most 3 components, %D given", fbs); for (j = 0; j < fbs; j++) { const char *compName = NULL; if (fv) { CHKERRQ(PetscFVGetComponentName(fv,j,&compName)); if (compName) break; } } if (j < fbs) vector = PETSC_FALSE; } if (vector) { #if defined(PETSC_USE_COMPLEX) CHKERRQ(PetscFPrintf(comm,fp," \n",precision,vecname,fieldname,boffset)); boffset += gpiece[r].ncells*3*sizeof(PetscVTUReal) + sizeof(int); CHKERRQ(PetscFPrintf(comm,fp," \n",precision,vecname,fieldname,boffset)); boffset += gpiece[r].ncells*3*sizeof(PetscVTUReal) + sizeof(int); #else CHKERRQ(PetscFPrintf(comm,fp," \n",precision,vecname,fieldname,boffset)); boffset += gpiece[r].ncells*3*sizeof(PetscVTUReal) + sizeof(int); #endif i+=fbs; } else { for (j=0; j 1) { CHKERRQ(PetscSNPrintf(finalname,255,"%s%s.%D",vecname,fieldname,j)); } else { CHKERRQ(PetscSNPrintf(finalname,255,"%s%s",vecname,fieldname)); } #if defined(PETSC_USE_COMPLEX) CHKERRQ(PetscFPrintf(comm,fp," \n",precision,finalname,boffset)); boffset += gpiece[r].ncells*sizeof(PetscVTUReal) + sizeof(int); CHKERRQ(PetscFPrintf(comm,fp," \n",precision,finalname,boffset)); boffset += gpiece[r].ncells*sizeof(PetscVTUReal) + sizeof(int); #else CHKERRQ(PetscFPrintf(comm,fp," \n",precision,finalname,boffset)); boffset += gpiece[r].ncells*sizeof(PetscVTUReal) + sizeof(int); #endif i++; } } } //PetscCheckFalse(i != bs,comm,PETSC_ERR_PLIB,"Total number of field components %D != block size %D",i,bs); } CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n")); /* * Point Data headers */ CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n")); for (link=vtk->link; link; link=link->next) { Vec X = (Vec)link->vec; DM dmX; PetscInt bs = 1,nfields,field; const char *vecname = ""; PetscSection section; if ((link->ft != PETSC_VTK_POINT_FIELD) && (link->ft != PETSC_VTK_POINT_VECTOR_FIELD)) continue; if (((PetscObject)X)->name || link != vtk->link) { /* If the object is already named, use it. If it is past the first link, name it to disambiguate. */ CHKERRQ(PetscObjectGetName((PetscObject)X,&vecname)); } CHKERRQ(VecGetDM(X, &dmX)); if (!dmX) dmX = dm; CHKERRQ(PetscObjectQuery(link->vec, "section", (PetscObject*) §ion)); if (!section) CHKERRQ(DMGetLocalSection(dmX, §ion)); if (vEnd > vStart) CHKERRQ(PetscSectionGetDof(section,vStart,&bs)); CHKERRQ(PetscSectionGetNumFields(section,&nfields)); field = 0; if (link->field >= 0) { field = link->field; nfields = field + 1; } for (i=0; field<(nfields?nfields:1); field++) { PetscInt fbs,j; const char *fieldname = NULL; char buf[256]; if (nfields) { /* We have user-defined fields/components */ CHKERRQ(PetscSectionGetFieldDof(section,vStart,field,&fbs)); CHKERRQ(PetscSectionGetFieldName(section,field,&fieldname)); } else fbs = bs; /* Say we have one field with 'bs' components */ if (nfields && !fieldname) { CHKERRQ(PetscSNPrintf(buf,sizeof(buf),"PointField%D",field)); fieldname = buf; } if (link->ft == PETSC_VTK_POINT_VECTOR_FIELD) { PetscCheckFalse(fbs > 3,PetscObjectComm((PetscObject)viewer),PETSC_ERR_ARG_SIZ,"Point vector fields can have at most 3 components, %D given", fbs); #if defined(PETSC_USE_COMPLEX) CHKERRQ(PetscFPrintf(comm,fp," \n",precision,vecname,fieldname,boffset)); boffset += gpiece[r].nvertices*3*sizeof(PetscVTUReal) + sizeof(int); CHKERRQ(PetscFPrintf(comm,fp," \n",precision,vecname,fieldname,boffset)); boffset += gpiece[r].nvertices*3*sizeof(PetscVTUReal) + sizeof(int); #else CHKERRQ(PetscFPrintf(comm,fp," \n",precision,vecname,fieldname,boffset)); boffset += gpiece[r].nvertices*3*sizeof(PetscVTUReal) + sizeof(int); #endif } else { for (j=0; j\n",precision,finalname,boffset)); boffset += gpiece[r].nvertices*sizeof(PetscVTUReal) + sizeof(int); CHKERRQ(PetscFPrintf(comm,fp," \n",precision,finalname,boffset)); boffset += gpiece[r].nvertices*sizeof(PetscVTUReal) + sizeof(int); #else CHKERRQ(PetscFPrintf(comm,fp," \n",precision,finalname,boffset)); boffset += gpiece[r].nvertices*sizeof(PetscVTUReal) + sizeof(int); #endif } } } } CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n")); CHKERRQ(PetscFPrintf(PETSC_COMM_SELF,fp," \n")); } } CHKERRQ(PetscFPrintf(comm,fp," \n")); CHKERRQ(PetscFPrintf(comm,fp," \n")); CHKERRQ(PetscFPrintf(comm,fp,"_")); if (rank == 0) { PetscInt maxsize = 0; for (r=0; r= vStart) && (closure[v] < vEnd)) { CHKERRQ(PetscSectionGetOffset(coordSection, closure[v], &off)); if (dimEmbed != 3) { y[cnt*3+0] = (PetscVTUReal) PetscRealPart(x[off+0]); y[cnt*3+1] = (PetscVTUReal) ((dimEmbed > 1) ? PetscRealPart(x[off+1]) : 0.0); y[cnt*3+2] = (PetscVTUReal) 0.0; } else { y[cnt*3+0] = (PetscVTUReal) PetscRealPart(x[off+0]); y[cnt*3+1] = (PetscVTUReal) PetscRealPart(x[off+1]); y[cnt*3+2] = (PetscVTUReal) PetscRealPart(x[off+2]); } cnt++; } } CHKERRQ(DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure)); } else { CHKERRQ(PetscSectionGetOffset(coordSection, c, &off)); if (dimEmbed != 3) { for (i=0; i 1) ? PetscRealPart(x[off + i*dimEmbed + 1]) : 0.0); y[cnt*3+2] = (PetscVTUReal) 0.0; cnt++; } } else { for (i=0; i 1) ? PetscRealPart(x[i*dimEmbed+1]) : 0.); y[i*3+2] = (PetscVTUReal) ((dimEmbed > 2) ? PetscRealPart(x[i*dimEmbed+2]) : 0.); } } } nsend = piece.nvertices*3; CHKERRQ(TransferWrite(comm,viewer,fp,r,0,copy ? (const void *) y : (const void *) x,buffer,nsend,MPIU_VTUREAL,tag)); CHKERRQ(PetscFree(y)); CHKERRQ(VecRestoreArrayRead(coords,&x)); } { /* Connectivity, offsets, types */ PetscVTKInt *connectivity = NULL, *offsets = NULL; PetscVTKType *types = NULL; CHKERRQ(DMPlexGetVTKConnectivity(dm,localized,&piece,&connectivity,&offsets,&types)); CHKERRQ(TransferWrite(comm,viewer,fp,r,0,connectivity,buffer,piece.nconn,MPI_INT,tag)); CHKERRQ(TransferWrite(comm,viewer,fp,r,0,offsets,buffer,piece.ncells,MPI_INT,tag)); CHKERRQ(TransferWrite(comm,viewer,fp,r,0,types,buffer,piece.ncells,MPI_CHAR,tag)); CHKERRQ(PetscFree3(connectivity,offsets,types)); } { /* Owners (cell data) */ PetscVTKInt *owners; CHKERRQ(PetscMalloc1(piece.ncells,&owners)); for (i=0; ilink; link; link=link->next) { Vec X = (Vec)link->vec; DM dmX; const PetscScalar *x; PetscVTUReal *y; PetscInt bs = 1, nfields, field; PetscSection section = NULL; if ((link->ft != PETSC_VTK_CELL_FIELD) && (link->ft != PETSC_VTK_CELL_VECTOR_FIELD)) continue; CHKERRQ(VecGetDM(X, &dmX)); if (!dmX) dmX = dm; CHKERRQ(PetscObjectQuery(link->vec, "section", (PetscObject*) §ion)); if (!section) CHKERRQ(DMGetLocalSection(dmX, §ion)); if (cEnd > cStart) CHKERRQ(PetscSectionGetDof(section,cStart,&bs)); CHKERRQ(PetscSectionGetNumFields(section,&nfields)); field = 0; if (link->field >= 0) { field = link->field; nfields = field + 1; } CHKERRQ(VecGetArrayRead(X,&x)); CHKERRQ(PetscMalloc1(piece.ncells*3,&y)); for (i=0; field<(nfields?nfields:1); field++) { PetscInt fbs,j; PetscFV fv = NULL; PetscObject f; PetscClassId fClass; PetscBool vector; if (nfields && cEnd > cStart) { /* We have user-defined fields/components */ CHKERRQ(PetscSectionGetFieldDof(section,cStart,field,&fbs)); } else fbs = bs; /* Say we have one field with 'bs' components */ CHKERRQ(DMGetField(dmX,field,NULL,&f)); CHKERRQ(PetscObjectGetClassId(f,&fClass)); if (fClass == PETSCFV_CLASSID) { fv = (PetscFV) f; } vector = PETSC_FALSE; if (link->ft == PETSC_VTK_CELL_VECTOR_FIELD) { vector = PETSC_TRUE; for (j = 0; j < fbs; j++) { const char *compName = NULL; if (fv) { CHKERRQ(PetscFVGetComponentName(fv,j,&compName)); if (compName) break; } } if (j < fbs) vector = PETSC_FALSE; } if (vector) { PetscInt cnt, l; for (l = 0; l < loops_per_scalar; l++) { for (c=cStart,cnt=0; clink; link; link=link->next) { Vec X = (Vec)link->vec; DM dmX; const PetscScalar *x; PetscVTUReal *y; PetscInt bs = 1, nfields, field; PetscSection section = NULL; if ((link->ft != PETSC_VTK_POINT_FIELD) && (link->ft != PETSC_VTK_POINT_VECTOR_FIELD)) continue; CHKERRQ(VecGetDM(X, &dmX)); if (!dmX) dmX = dm; CHKERRQ(PetscObjectQuery(link->vec, "section", (PetscObject*) §ion)); if (!section) CHKERRQ(DMGetLocalSection(dmX, §ion)); if (vEnd > vStart) CHKERRQ(PetscSectionGetDof(section,vStart,&bs)); CHKERRQ(PetscSectionGetNumFields(section,&nfields)); field = 0; if (link->field >= 0) { field = link->field; nfields = field + 1; } CHKERRQ(VecGetArrayRead(X,&x)); CHKERRQ(PetscMalloc1(piece.nvertices*3,&y)); for (i=0; field<(nfields?nfields:1); field++) { PetscInt fbs,j; if (nfields && vEnd > vStart) { /* We have user-defined fields/components */ CHKERRQ(PetscSectionGetFieldDof(section,vStart,field,&fbs)); } else fbs = bs; /* Say we have one field with 'bs' components */ if (link->ft == PETSC_VTK_POINT_VECTOR_FIELD) { PetscInt cnt, l; for (l = 0; l < loops_per_scalar; l++) { if (!localized) { for (v=vStart,cnt=0; v= vStart) && (closure[v] < vEnd)) { PetscInt voff; const PetscScalar *xpoint; if (nfields) { CHKERRQ(PetscSectionGetFieldOffset(section,closure[v],field,&voff)); } else { CHKERRQ(PetscSectionGetOffset(section,closure[v],&voff)); } xpoint = &x[voff]; for (j = 0; j < fbs; j++) { y[cnt + off++] = (PetscVTUReal) (l ? PetscImaginaryPart(xpoint[j]) : PetscRealPart(xpoint[j])); } for (; j < 3; j++) y[cnt + off++] = 0.; } } cnt += off; CHKERRQ(DMPlexRestoreTransitiveClosure(dmX, c, PETSC_TRUE, &closureSize, &closure)); } } PetscCheckFalse(cnt != piece.nvertices*3,PETSC_COMM_SELF,PETSC_ERR_PLIB,"Count does not match"); CHKERRQ(TransferWrite(comm,viewer,fp,r,0,y,buffer,piece.nvertices*3,MPIU_VTUREAL,tag)); } } else { for (i=0; i= vStart) && (closure[v] < vEnd)) { PetscInt voff; const PetscScalar *xpoint; if (nfields) { CHKERRQ(PetscSectionGetFieldOffset(section,closure[v],field,&voff)); } else { CHKERRQ(PetscSectionGetOffset(section,closure[v],&voff)); } xpoint = &x[voff]; y[cnt + off++] = (l ? PetscImaginaryPart(xpoint[i]) : PetscRealPart(xpoint[i])); } } cnt += off; CHKERRQ(DMPlexRestoreTransitiveClosure(dmX, c, PETSC_TRUE, &closureSize, &closure)); } } PetscCheckFalse(cnt != piece.nvertices,PETSC_COMM_SELF,PETSC_ERR_PLIB,"Count does not match"); CHKERRQ(TransferWrite(comm,viewer,fp,r,0,y,buffer,piece.nvertices,MPIU_VTUREAL,tag)); } } } } CHKERRQ(PetscFree(y)); CHKERRQ(VecRestoreArrayRead(X,&x)); } } else if (rank == 0) { PetscInt l; CHKERRQ(TransferWrite(comm,viewer,fp,r,0,NULL,buffer,gpiece[r].nvertices*3,MPIU_VTUREAL,tag)); /* positions */ CHKERRQ(TransferWrite(comm,viewer,fp,r,0,NULL,buffer,gpiece[r].nconn,MPI_INT,tag)); /* connectivity */ CHKERRQ(TransferWrite(comm,viewer,fp,r,0,NULL,buffer,gpiece[r].ncells,MPI_INT,tag)); /* offsets */ CHKERRQ(TransferWrite(comm,viewer,fp,r,0,NULL,buffer,gpiece[r].ncells,MPI_CHAR,tag)); /* types */ CHKERRQ(TransferWrite(comm,viewer,fp,r,0,NULL,buffer,gpiece[r].ncells,MPI_INT,tag)); /* owner rank (cells) */ /* all cell data */ for (link=vtk->link; link; link=link->next) { Vec X = (Vec)link->vec; PetscInt bs = 1, nfields, field; DM dmX; PetscSection section = NULL; if ((link->ft != PETSC_VTK_CELL_FIELD) && (link->ft != PETSC_VTK_CELL_VECTOR_FIELD)) continue; CHKERRQ(VecGetDM(X, &dmX)); if (!dmX) dmX = dm; CHKERRQ(PetscObjectQuery(link->vec, "section", (PetscObject*) §ion)); if (!section) CHKERRQ(DMGetLocalSection(dmX, §ion)); if (cEnd > cStart) CHKERRQ(PetscSectionGetDof(section,cStart,&bs)); CHKERRQ(PetscSectionGetNumFields(section,&nfields)); field = 0; if (link->field >= 0) { field = link->field; nfields = field + 1; } for (i=0; field<(nfields?nfields:1); field++) { PetscInt fbs,j; PetscFV fv = NULL; PetscObject f; PetscClassId fClass; PetscBool vector; if (nfields && cEnd > cStart) { /* We have user-defined fields/components */ CHKERRQ(PetscSectionGetFieldDof(section,cStart,field,&fbs)); } else fbs = bs; /* Say we have one field with 'bs' components */ CHKERRQ(DMGetField(dmX,field,NULL,&f)); CHKERRQ(PetscObjectGetClassId(f,&fClass)); if (fClass == PETSCFV_CLASSID) { fv = (PetscFV) f; } vector = PETSC_FALSE; if (link->ft == PETSC_VTK_CELL_VECTOR_FIELD) { vector = PETSC_TRUE; for (j = 0; j < fbs; j++) { const char *compName = NULL; if (fv) { CHKERRQ(PetscFVGetComponentName(fv,j,&compName)); if (compName) break; } } if (j < fbs) vector = PETSC_FALSE; } if (vector) { for (l = 0; l < loops_per_scalar; l++) { CHKERRQ(TransferWrite(comm,viewer,fp,r,0,NULL,buffer,gpiece[r].ncells*3,MPIU_VTUREAL,tag)); } } else { for (i=0; ilink; link; link=link->next) { Vec X = (Vec)link->vec; DM dmX; PetscInt bs = 1, nfields, field; PetscSection section = NULL; if ((link->ft != PETSC_VTK_POINT_FIELD) && (link->ft != PETSC_VTK_POINT_VECTOR_FIELD)) continue; CHKERRQ(VecGetDM(X, &dmX)); if (!dmX) dmX = dm; CHKERRQ(PetscObjectQuery(link->vec, "section", (PetscObject*) §ion)); if (!section) CHKERRQ(DMGetLocalSection(dmX, §ion)); if (vEnd > vStart) CHKERRQ(PetscSectionGetDof(section,vStart,&bs)); CHKERRQ(PetscSectionGetNumFields(section,&nfields)); field = 0; if (link->field >= 0) { field = link->field; nfields = field + 1; } for (i=0; field<(nfields?nfields:1); field++) { PetscInt fbs; if (nfields && vEnd > vStart) { /* We have user-defined fields/components */ CHKERRQ(PetscSectionGetFieldDof(section,vStart,field,&fbs)); } else fbs = bs; /* Say we have one field with 'bs' components */ if (link->ft == PETSC_VTK_POINT_VECTOR_FIELD) { for (l = 0; l < loops_per_scalar; l++) { CHKERRQ(TransferWrite(comm,viewer,fp,r,0,NULL,buffer,gpiece[r].nvertices*3,MPIU_VTUREAL,tag)); } } else { for (i=0; i\n")); CHKERRQ(PetscFPrintf(comm,fp,"\n")); CHKERRQ(PetscFClose(comm,fp)); PetscFunctionReturn(0); }