1 static char help[] = "Test FEM layout with DM and ExodusII storage\n\n"; 2 3 /* 4 In order to see the vectors which are being tested, use 5 6 -ua_vec_view -s_vec_view 7 */ 8 9 #include <petsc.h> 10 #include <exodusII.h> 11 12 #include <petsc/private/dmpleximpl.h> 13 14 int main(int argc, char **argv) { 15 DM dm, dmU, dmA, dmS, dmUA, dmUA2, *dmList; 16 Vec X, U, A, S, UA, UA2; 17 IS isU, isA, isS, isUA; 18 PetscSection section; 19 const PetscInt fieldU = 0; 20 const PetscInt fieldA = 2; 21 const PetscInt fieldS = 1; 22 const PetscInt fieldUA[2] = {0, 2}; 23 char ifilename[PETSC_MAX_PATH_LEN], ofilename[PETSC_MAX_PATH_LEN]; 24 int exoid = -1; 25 IS csIS; 26 const PetscInt *csID; 27 PetscInt *pStartDepth, *pEndDepth; 28 PetscInt order = 1; 29 PetscInt sdim, d, pStart, pEnd, p, numCS, set; 30 PetscMPIInt rank, size; 31 PetscViewer viewer; 32 PetscErrorCode ierr; 33 34 PetscCall(PetscInitialize(&argc, &argv,NULL, help)); 35 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank)); 36 PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size)); 37 ierr = PetscOptionsBegin(PETSC_COMM_WORLD, NULL, "FEM Layout Options", "ex26");PetscCall(ierr); 38 PetscCall(PetscOptionsString("-i", "Filename to read", "ex26", ifilename, ifilename, sizeof(ifilename), NULL)); 39 PetscCall(PetscOptionsString("-o", "Filename to write", "ex26", ofilename, ofilename, sizeof(ofilename), NULL)); 40 PetscCall(PetscOptionsBoundedInt("-order", "FEM polynomial order", "ex26", order, &order, NULL,1)); 41 ierr = PetscOptionsEnd();PetscCall(ierr); 42 PetscCheck(!(order > 2) && !(order < 1),PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Unsupported polynomial order %D not in [1, 2]", order); 43 44 /* Read the mesh from a file in any supported format */ 45 PetscCall(DMPlexCreateFromFile(PETSC_COMM_WORLD, ifilename, NULL, PETSC_TRUE, &dm)); 46 PetscCall(DMPlexDistributeSetDefault(dm, PETSC_FALSE)); 47 PetscCall(DMSetFromOptions(dm)); 48 PetscCall(DMViewFromOptions(dm, NULL, "-dm_view")); 49 PetscCall(DMGetDimension(dm, &sdim)); 50 51 /* Create the exodus result file */ 52 { 53 PetscInt numstep = 3, step; 54 char *nodalVarName[4]; 55 char *zonalVarName[6]; 56 int *truthtable; 57 PetscInt numNodalVar, numZonalVar, i; 58 59 /* enable exodus debugging information */ 60 ex_opts(EX_VERBOSE|EX_DEBUG); 61 /* Create the exodus file */ 62 PetscCall(PetscViewerExodusIIOpen(PETSC_COMM_WORLD,ofilename,FILE_MODE_WRITE,&viewer)); 63 /* The long way would be */ 64 /* 65 PetscCall(PetscViewerCreate(PETSC_COMM_WORLD,&viewer)); 66 PetscCall(PetscViewerSetType(viewer,PETSCVIEWEREXODUSII)); 67 PetscCall(PetscViewerFileSetMode(viewer,FILE_MODE_APPEND)); 68 PetscCall(PetscViewerFileSetName(viewer,ofilename)); 69 */ 70 /* set the mesh order */ 71 PetscCall(PetscViewerExodusIISetOrder(viewer,order)); 72 PetscCall(PetscViewerView(viewer,PETSC_VIEWER_STDOUT_WORLD)); 73 /* 74 Notice how the exodus file is actually NOT open at this point (exoid is -1) 75 Since we are overwritting the file (mode is FILE_MODE_WRITE), we are going to have to 76 write the geometry (the DM), which can only be done on a brand new file. 77 */ 78 79 /* Save the geometry to the file, erasing all previous content */ 80 PetscCall(DMView(dm,viewer)); 81 PetscCall(PetscViewerView(viewer,PETSC_VIEWER_STDOUT_WORLD)); 82 /* 83 Note how the exodus file is now open 84 */ 85 86 /* "Format" the exodus result file, i.e. allocate space for nodal and zonal variables */ 87 switch (sdim) { 88 case 2: 89 numNodalVar = 3; 90 nodalVarName[0] = (char *) "U_x"; 91 nodalVarName[1] = (char *) "U_y"; 92 nodalVarName[2] = (char *) "Alpha"; 93 numZonalVar = 3; 94 zonalVarName[0] = (char *) "Sigma_11"; 95 zonalVarName[1] = (char *) "Sigma_22"; 96 zonalVarName[2] = (char *) "Sigma_12"; 97 break; 98 case 3: 99 numNodalVar = 4; 100 nodalVarName[0] = (char *) "U_x"; 101 nodalVarName[1] = (char *) "U_y"; 102 nodalVarName[2] = (char *) "U_z"; 103 nodalVarName[3] = (char *) "Alpha"; 104 numZonalVar = 6; 105 zonalVarName[0] = (char *) "Sigma_11"; 106 zonalVarName[1] = (char *) "Sigma_22"; 107 zonalVarName[2] = (char *) "Sigma_33"; 108 zonalVarName[3] = (char *) "Sigma_23"; 109 zonalVarName[4] = (char *) "Sigma_13"; 110 zonalVarName[5] = (char *) "Sigma_12"; 111 break; 112 default: SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "No layout for dimension %D", sdim); 113 } 114 PetscCall(PetscViewerExodusIIGetId(viewer,&exoid)); 115 PetscStackCallStandard(ex_put_variable_param,exoid, EX_ELEM_BLOCK, numZonalVar); 116 PetscStackCallStandard(ex_put_variable_names,exoid, EX_ELEM_BLOCK, numZonalVar, zonalVarName); 117 PetscStackCallStandard(ex_put_variable_param,exoid, EX_NODAL, numNodalVar); 118 PetscStackCallStandard(ex_put_variable_names,exoid, EX_NODAL, numNodalVar, nodalVarName); 119 numCS = ex_inquire_int(exoid, EX_INQ_ELEM_BLK); 120 121 /* 122 An exodusII truth table specifies which fields are saved at which time step 123 It speeds up I/O but reserving space for fieldsin the file ahead of time. 124 */ 125 PetscCall(PetscMalloc1(numZonalVar * numCS, &truthtable)); 126 for (i = 0; i < numZonalVar * numCS; ++i) truthtable[i] = 1; 127 PetscStackCallStandard(ex_put_truth_table,exoid, EX_ELEM_BLOCK, numCS, numZonalVar, truthtable); 128 PetscCall(PetscFree(truthtable)); 129 130 /* Writing time step information in the file. Note that this is currently broken in the exodus library for netcdf4 (HDF5-based) files */ 131 for (step = 0; step < numstep; ++step) { 132 PetscReal time = step; 133 PetscStackCallStandard(ex_put_time,exoid, step+1, &time); 134 } 135 } 136 137 /* Create the main section containing all fields */ 138 PetscCall(PetscSectionCreate(PetscObjectComm((PetscObject) dm), §ion)); 139 PetscCall(PetscSectionSetNumFields(section, 3)); 140 PetscCall(PetscSectionSetFieldName(section, fieldU, "U")); 141 PetscCall(PetscSectionSetFieldName(section, fieldA, "Alpha")); 142 PetscCall(PetscSectionSetFieldName(section, fieldS, "Sigma")); 143 PetscCall(DMPlexGetChart(dm, &pStart, &pEnd)); 144 PetscCall(PetscSectionSetChart(section, pStart, pEnd)); 145 PetscCall(PetscMalloc2(sdim+1, &pStartDepth, sdim+1, &pEndDepth)); 146 for (d = 0; d <= sdim; ++d) PetscCall(DMPlexGetDepthStratum(dm, d, &pStartDepth[d], &pEndDepth[d])); 147 /* Vector field U, Scalar field Alpha, Tensor field Sigma */ 148 PetscCall(PetscSectionSetFieldComponents(section, fieldU, sdim)); 149 PetscCall(PetscSectionSetFieldComponents(section, fieldA, 1)); 150 PetscCall(PetscSectionSetFieldComponents(section, fieldS, sdim*(sdim+1)/2)); 151 152 /* Going through cell sets then cells, and setting up storage for the sections */ 153 PetscCall(DMGetLabelSize(dm, "Cell Sets", &numCS)); 154 PetscCall(DMGetLabelIdIS(dm, "Cell Sets", &csIS)); 155 if (csIS) PetscCall(ISGetIndices(csIS, &csID)); 156 for (set = 0; set < numCS; set++) { 157 IS cellIS; 158 const PetscInt *cellID; 159 PetscInt numCells, cell, closureSize, *closureA = NULL; 160 161 PetscCall(DMGetStratumSize(dm, "Cell Sets", csID[set], &numCells)); 162 PetscCall(DMGetStratumIS(dm, "Cell Sets", csID[set], &cellIS)); 163 if (numCells > 0) { 164 /* dof layout ordered by increasing height in the DAG: cell, face, edge, vertex */ 165 PetscInt dofUP1Tri[] = {2, 0, 0}; 166 PetscInt dofAP1Tri[] = {1, 0, 0}; 167 PetscInt dofUP2Tri[] = {2, 2, 0}; 168 PetscInt dofAP2Tri[] = {1, 1, 0}; 169 PetscInt dofUP1Quad[] = {2, 0, 0}; 170 PetscInt dofAP1Quad[] = {1, 0, 0}; 171 PetscInt dofUP2Quad[] = {2, 2, 2}; 172 PetscInt dofAP2Quad[] = {1, 1, 1}; 173 PetscInt dofS2D[] = {0, 0, 3}; 174 PetscInt dofUP1Tet[] = {3, 0, 0, 0}; 175 PetscInt dofAP1Tet[] = {1, 0, 0, 0}; 176 PetscInt dofUP2Tet[] = {3, 3, 0, 0}; 177 PetscInt dofAP2Tet[] = {1, 1, 0, 0}; 178 PetscInt dofUP1Hex[] = {3, 0, 0, 0}; 179 PetscInt dofAP1Hex[] = {1, 0, 0, 0}; 180 PetscInt dofUP2Hex[] = {3, 3, 3, 3}; 181 PetscInt dofAP2Hex[] = {1, 1, 1, 1}; 182 PetscInt dofS3D[] = {0, 0, 0, 6}; 183 PetscInt *dofU, *dofA, *dofS; 184 185 switch (sdim) { 186 case 2: dofS = dofS2D;break; 187 case 3: dofS = dofS3D;break; 188 default: SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "No layout for dimension %D", sdim); 189 } 190 191 /* Identify cell type based on closure size only. This works for Tri/Tet/Quad/Hex meshes 192 It will not be enough to identify more exotic elements like pyramid or prisms... */ 193 PetscCall(ISGetIndices(cellIS, &cellID)); 194 PetscCall(DMPlexGetTransitiveClosure(dm, cellID[0], PETSC_TRUE, &closureSize, &closureA)); 195 switch (closureSize) { 196 case 7: /* Tri */ 197 if (order == 1) { 198 dofU = dofUP1Tri; 199 dofA = dofAP1Tri; 200 } else { 201 dofU = dofUP2Tri; 202 dofA = dofAP2Tri; 203 } 204 break; 205 case 9: /* Quad */ 206 if (order == 1) { 207 dofU = dofUP1Quad; 208 dofA = dofAP1Quad; 209 } else { 210 dofU = dofUP2Quad; 211 dofA = dofAP2Quad; 212 } 213 break; 214 case 15: /* Tet */ 215 if (order == 1) { 216 dofU = dofUP1Tet; 217 dofA = dofAP1Tet; 218 } else { 219 dofU = dofUP2Tet; 220 dofA = dofAP2Tet; 221 } 222 break; 223 case 27: /* Hex */ 224 if (order == 1) { 225 dofU = dofUP1Hex; 226 dofA = dofAP1Hex; 227 } else { 228 dofU = dofUP2Hex; 229 dofA = dofAP2Hex; 230 } 231 break; 232 default: SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP, "Unknown element with closure size %D", closureSize); 233 } 234 PetscCall(DMPlexRestoreTransitiveClosure(dm, cellID[0], PETSC_TRUE, &closureSize, &closureA)); 235 236 for (cell = 0; cell < numCells; cell++) { 237 PetscInt *closure = NULL; 238 239 PetscCall(DMPlexGetTransitiveClosure(dm, cellID[cell], PETSC_TRUE, &closureSize, &closure)); 240 for (p = 0; p < closureSize; ++p) { 241 /* Find depth of p */ 242 for (d = 0; d <= sdim; ++d) { 243 if ((closure[2*p] >= pStartDepth[d]) && (closure[2*p] < pEndDepth[d])) { 244 PetscCall(PetscSectionSetDof(section, closure[2*p], dofU[d]+dofA[d]+dofS[d])); 245 PetscCall(PetscSectionSetFieldDof(section, closure[2*p], fieldU, dofU[d])); 246 PetscCall(PetscSectionSetFieldDof(section, closure[2*p], fieldA, dofA[d])); 247 PetscCall(PetscSectionSetFieldDof(section, closure[2*p], fieldS, dofS[d])); 248 } 249 } 250 } 251 PetscCall(DMPlexRestoreTransitiveClosure(dm, cellID[cell], PETSC_TRUE, &closureSize, &closure)); 252 } 253 PetscCall(ISRestoreIndices(cellIS, &cellID)); 254 PetscCall(ISDestroy(&cellIS)); 255 } 256 } 257 if (csIS) PetscCall(ISRestoreIndices(csIS, &csID)); 258 PetscCall(ISDestroy(&csIS)); 259 PetscCall(PetscSectionSetUp(section)); 260 PetscCall(DMSetLocalSection(dm, section)); 261 PetscCall(PetscObjectViewFromOptions((PetscObject) section, NULL, "-dm_section_view")); 262 PetscCall(PetscSectionDestroy(§ion)); 263 264 { 265 DM pdm; 266 PetscSF migrationSF; 267 PetscInt ovlp = 0; 268 PetscPartitioner part; 269 270 PetscCall(DMSetUseNatural(dm,PETSC_TRUE)); 271 PetscCall(DMPlexGetPartitioner(dm,&part)); 272 PetscCall(PetscPartitionerSetFromOptions(part)); 273 PetscCall(DMPlexDistribute(dm,ovlp,&migrationSF,&pdm)); 274 if (pdm) { 275 PetscCall(DMPlexSetMigrationSF(pdm,migrationSF)); 276 PetscCall(PetscSFDestroy(&migrationSF)); 277 PetscCall(DMDestroy(&dm)); 278 dm = pdm; 279 PetscCall(DMViewFromOptions(dm,NULL,"-dm_view")); 280 } 281 } 282 283 /* Get DM and IS for each field of dm */ 284 PetscCall(DMCreateSubDM(dm, 1, &fieldU, &isU, &dmU)); 285 PetscCall(DMCreateSubDM(dm, 1, &fieldA, &isA, &dmA)); 286 PetscCall(DMCreateSubDM(dm, 1, &fieldS, &isS, &dmS)); 287 PetscCall(DMCreateSubDM(dm, 2, fieldUA, &isUA, &dmUA)); 288 289 PetscCall(PetscMalloc1(2,&dmList)); 290 dmList[0] = dmU; 291 dmList[1] = dmA; 292 /* We temporarily disable dmU->useNatural to test that we can reconstruct the 293 NaturaltoGlobal SF from any of the dm in dms 294 */ 295 dmU->useNatural = PETSC_FALSE; 296 PetscCall(DMCreateSuperDM(dmList,2,NULL,&dmUA2)); 297 dmU->useNatural = PETSC_TRUE; 298 PetscCall(PetscFree(dmList)); 299 300 PetscCall(DMGetGlobalVector(dm, &X)); 301 PetscCall(DMGetGlobalVector(dmU, &U)); 302 PetscCall(DMGetGlobalVector(dmA, &A)); 303 PetscCall(DMGetGlobalVector(dmS, &S)); 304 PetscCall(DMGetGlobalVector(dmUA, &UA)); 305 PetscCall(DMGetGlobalVector(dmUA2, &UA2)); 306 307 PetscCall(PetscObjectSetName((PetscObject) U, "U")); 308 PetscCall(PetscObjectSetName((PetscObject) A, "Alpha")); 309 PetscCall(PetscObjectSetName((PetscObject) S, "Sigma")); 310 PetscCall(PetscObjectSetName((PetscObject) UA, "UAlpha")); 311 PetscCall(PetscObjectSetName((PetscObject) UA2, "UAlpha2")); 312 PetscCall(VecSet(X, -111.)); 313 314 /* Setting u to [x,y,z] and alpha to x^2+y^2+z^2 by writing in UAlpha then restricting to U and Alpha */ 315 { 316 PetscSection sectionUA; 317 Vec UALoc; 318 PetscSection coordSection; 319 Vec coord; 320 PetscScalar *cval, *xyz; 321 PetscInt clSize, i, j; 322 323 PetscCall(DMGetLocalSection(dmUA, §ionUA)); 324 PetscCall(DMGetLocalVector(dmUA, &UALoc)); 325 PetscCall(VecGetArray(UALoc, &cval)); 326 PetscCall(DMGetCoordinateSection(dmUA, &coordSection)); 327 PetscCall(DMGetCoordinatesLocal(dmUA, &coord)); 328 PetscCall(DMPlexGetChart(dmUA, &pStart, &pEnd)); 329 330 for (p = pStart; p < pEnd; ++p) { 331 PetscInt dofUA, offUA; 332 333 PetscCall(PetscSectionGetDof(sectionUA, p, &dofUA)); 334 if (dofUA > 0) { 335 xyz=NULL; 336 PetscCall(PetscSectionGetOffset(sectionUA, p, &offUA)); 337 PetscCall(DMPlexVecGetClosure(dmUA, coordSection, coord, p, &clSize, &xyz)); 338 cval[offUA+sdim] = 0.; 339 for (i = 0; i < sdim; ++i) { 340 cval[offUA+i] = 0; 341 for (j = 0; j < clSize/sdim; ++j) { 342 cval[offUA+i] += xyz[j*sdim+i]; 343 } 344 cval[offUA+i] = cval[offUA+i] * sdim / clSize; 345 cval[offUA+sdim] += PetscSqr(cval[offUA+i]); 346 } 347 PetscCall(DMPlexVecRestoreClosure(dmUA, coordSection, coord, p, &clSize, &xyz)); 348 } 349 } 350 PetscCall(VecRestoreArray(UALoc, &cval)); 351 PetscCall(DMLocalToGlobalBegin(dmUA, UALoc, INSERT_VALUES, UA)); 352 PetscCall(DMLocalToGlobalEnd(dmUA, UALoc, INSERT_VALUES, UA)); 353 PetscCall(DMRestoreLocalVector(dmUA, &UALoc)); 354 355 /* Update X */ 356 PetscCall(VecISCopy(X, isUA, SCATTER_FORWARD, UA)); 357 PetscCall(VecViewFromOptions(UA, NULL, "-ua_vec_view")); 358 359 /* Restrict to U and Alpha */ 360 PetscCall(VecISCopy(X, isU, SCATTER_REVERSE, U)); 361 PetscCall(VecISCopy(X, isA, SCATTER_REVERSE, A)); 362 363 /* restrict to UA2 */ 364 PetscCall(VecISCopy(X, isUA, SCATTER_REVERSE, UA2)); 365 PetscCall(VecViewFromOptions(UA2, NULL, "-ua2_vec_view")); 366 } 367 368 { 369 Vec tmpVec; 370 PetscSection coordSection; 371 Vec coord; 372 PetscReal norm; 373 PetscReal time = 1.234; 374 375 /* Writing nodal variables to ExodusII file */ 376 PetscCall(DMSetOutputSequenceNumber(dmU,0,time)); 377 PetscCall(DMSetOutputSequenceNumber(dmA,0,time)); 378 379 PetscCall(VecView(U, viewer)); 380 PetscCall(VecView(A, viewer)); 381 382 /* Saving U and Alpha in one shot. 383 For this, we need to cheat and change the Vec's name 384 Note that in the end we write variables one component at a time, 385 so that there is no real values in doing this 386 */ 387 388 PetscCall(DMSetOutputSequenceNumber(dmUA,1,time)); 389 PetscCall(DMGetGlobalVector(dmUA, &tmpVec)); 390 PetscCall(VecCopy(UA, tmpVec)); 391 PetscCall(PetscObjectSetName((PetscObject) tmpVec, "U")); 392 PetscCall(VecView(tmpVec, viewer)); 393 /* Reading nodal variables in Exodus file */ 394 PetscCall(VecSet(tmpVec, -1000.0)); 395 PetscCall(VecLoad(tmpVec, viewer)); 396 PetscCall(VecAXPY(UA, -1.0, tmpVec)); 397 PetscCall(VecNorm(UA, NORM_INFINITY, &norm)); 398 PetscCheck(norm <= PETSC_SQRT_MACHINE_EPSILON,PetscObjectComm((PetscObject) dm), PETSC_ERR_PLIB, "UAlpha ||Vin - Vout|| = %g", (double) norm); 399 PetscCall(DMRestoreGlobalVector(dmUA, &tmpVec)); 400 401 /* same thing with the UA2 Vec obtained from the superDM */ 402 PetscCall(DMGetGlobalVector(dmUA2, &tmpVec)); 403 PetscCall(VecCopy(UA2, tmpVec)); 404 PetscCall(PetscObjectSetName((PetscObject) tmpVec, "U")); 405 PetscCall(DMSetOutputSequenceNumber(dmUA2,2,time)); 406 PetscCall(VecView(tmpVec, viewer)); 407 /* Reading nodal variables in Exodus file */ 408 PetscCall(VecSet(tmpVec, -1000.0)); 409 PetscCall(VecLoad(tmpVec,viewer)); 410 PetscCall(VecAXPY(UA2, -1.0, tmpVec)); 411 PetscCall(VecNorm(UA2, NORM_INFINITY, &norm)); 412 PetscCheck(norm <= PETSC_SQRT_MACHINE_EPSILON,PetscObjectComm((PetscObject) dm), PETSC_ERR_PLIB, "UAlpha2 ||Vin - Vout|| = %g", (double) norm); 413 PetscCall(DMRestoreGlobalVector(dmUA2, &tmpVec)); 414 415 /* Building and saving Sigma 416 We set sigma_0 = rank (to see partitioning) 417 sigma_1 = cell set ID 418 sigma_2 = x_coordinate of the cell center of mass 419 */ 420 PetscCall(DMGetCoordinateSection(dmS, &coordSection)); 421 PetscCall(DMGetCoordinatesLocal(dmS, &coord)); 422 PetscCall(DMGetLabelIdIS(dmS, "Cell Sets", &csIS)); 423 PetscCall(DMGetLabelSize(dmS, "Cell Sets", &numCS)); 424 PetscCall(ISGetIndices(csIS, &csID)); 425 for (set = 0; set < numCS; ++set) { 426 /* We know that all cells in a cell set have the same type, so we can dimension cval and xyz once for each cell set */ 427 IS cellIS; 428 const PetscInt *cellID; 429 PetscInt numCells, cell; 430 PetscScalar *cval = NULL, *xyz = NULL; 431 PetscInt clSize, cdimCoord, c; 432 433 PetscCall(DMGetStratumIS(dmS, "Cell Sets", csID[set], &cellIS)); 434 PetscCall(ISGetIndices(cellIS, &cellID)); 435 PetscCall(ISGetSize(cellIS, &numCells)); 436 for (cell = 0; cell < numCells; cell++) { 437 PetscCall(DMPlexVecGetClosure(dmS, NULL, S, cellID[cell], &clSize, &cval)); 438 PetscCall(DMPlexVecGetClosure(dmS, coordSection, coord, cellID[cell], &cdimCoord, &xyz)); 439 cval[0] = rank; 440 cval[1] = csID[set]; 441 cval[2] = 0.; 442 for (c = 0; c < cdimCoord/sdim; c++) cval[2] += xyz[c*sdim]; 443 cval[2] = cval[2] * sdim / cdimCoord; 444 PetscCall(DMPlexVecSetClosure(dmS, NULL, S, cellID[cell], cval, INSERT_ALL_VALUES)); 445 } 446 PetscCall(DMPlexVecRestoreClosure(dmS, NULL, S, cellID[0], &clSize, &cval)); 447 PetscCall(DMPlexVecRestoreClosure(dmS, coordSection, coord, cellID[0], NULL, &xyz)); 448 PetscCall(ISRestoreIndices(cellIS, &cellID)); 449 PetscCall(ISDestroy(&cellIS)); 450 } 451 PetscCall(ISRestoreIndices(csIS, &csID)); 452 PetscCall(ISDestroy(&csIS)); 453 PetscCall(VecViewFromOptions(S, NULL, "-s_vec_view")); 454 455 /* Writing zonal variables in Exodus file */ 456 PetscCall(DMSetOutputSequenceNumber(dmS,0,time)); 457 PetscCall(VecView(S,viewer)); 458 459 /* Reading zonal variables in Exodus file */ 460 PetscCall(DMGetGlobalVector(dmS, &tmpVec)); 461 PetscCall(VecSet(tmpVec, -1000.0)); 462 PetscCall(PetscObjectSetName((PetscObject) tmpVec, "Sigma")); 463 PetscCall(VecLoad(tmpVec,viewer)); 464 PetscCall(VecAXPY(S, -1.0, tmpVec)); 465 PetscCall(VecNorm(S, NORM_INFINITY, &norm)); 466 PetscCheck(norm <= PETSC_SQRT_MACHINE_EPSILON,PetscObjectComm((PetscObject) dm), PETSC_ERR_PLIB, "Sigma ||Vin - Vout|| = %g", (double) norm); 467 PetscCall(DMRestoreGlobalVector(dmS, &tmpVec)); 468 } 469 PetscCall(PetscViewerDestroy(&viewer)); 470 471 PetscCall(DMRestoreGlobalVector(dmUA2, &UA2)); 472 PetscCall(DMRestoreGlobalVector(dmUA, &UA)); 473 PetscCall(DMRestoreGlobalVector(dmS, &S)); 474 PetscCall(DMRestoreGlobalVector(dmA, &A)); 475 PetscCall(DMRestoreGlobalVector(dmU, &U)); 476 PetscCall(DMRestoreGlobalVector(dm, &X)); 477 PetscCall(DMDestroy(&dmU)); PetscCall(ISDestroy(&isU)); 478 PetscCall(DMDestroy(&dmA)); PetscCall(ISDestroy(&isA)); 479 PetscCall(DMDestroy(&dmS)); PetscCall(ISDestroy(&isS)); 480 PetscCall(DMDestroy(&dmUA));PetscCall(ISDestroy(&isUA)); 481 PetscCall(DMDestroy(&dmUA2)); 482 PetscCall(DMDestroy(&dm)); 483 PetscCall(PetscFree2(pStartDepth, pEndDepth)); 484 PetscCall(PetscFinalize()); 485 return 0; 486 } 487 488 /*TEST 489 490 build: 491 requires: exodusii pnetcdf !complex 492 # 2D seq 493 test: 494 suffix: 0 495 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareT-large.exo -o FourSquareT-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 1 496 #TODO: bug in call to NetCDF failed to complete invalid type definition in file id 65536 NetCDF: One or more variable sizes violate format constraints 497 test: 498 suffix: 1 499 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareQ-large.exo -o FourSquareQ-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 1 500 test: 501 suffix: 2 502 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareH-large.exo -o FourSquareH-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 1 503 #TODO: bug in call to NetCDF failed to complete invalid type definition in file id 65536 NetCDF: One or more variable sizes violate format constraints 504 test: 505 suffix: 3 506 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareT-large.exo -o FourSquareT-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 2 507 test: 508 suffix: 4 509 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareQ-large.exo -o FourSquareQ-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 2 510 test: 511 suffix: 5 512 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareH-large.exo -o FourSquareH-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 2 513 514 # 2D par 515 test: 516 suffix: 6 517 nsize: 2 518 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareT-large.exo -o FourSquareT-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 1 519 #TODO: bug in call to NetCDF failed to complete invalid type definition in file id 65536 NetCDF: One or more variable sizes violate format constraints 520 test: 521 suffix: 7 522 nsize: 2 523 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareQ-large.exo -o FourSquareQ-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 1 524 test: 525 suffix: 8 526 nsize: 2 527 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareH-large.exo -o FourSquareH-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 1 528 #TODO: bug in call to NetCDF failed to complete invalid type definition in file id 65536 NetCDF: invalid dimension ID or name 529 test: 530 suffix: 9 531 nsize: 2 532 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareT-large.exo -o FourSquareT-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 2 533 test: 534 suffix: 10 535 nsize: 2 536 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareQ-large.exo -o FourSquareQ-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 2 537 test: 538 # Something is now broken with parallel read/write for wahtever shape H is 539 TODO: broken 540 suffix: 11 541 nsize: 2 542 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourSquareH-large.exo -o FourSquareH-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 2 543 544 #3d seq 545 test: 546 suffix: 12 547 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourBrickHex-large.exo -o FourBrickHex-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 1 548 test: 549 suffix: 13 550 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourBrickTet-large.exo -o FourBrickTet-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 1 551 #TODO: bug in call to NetCDF failed to complete invalid type definition in file id 65536 NetCDF: One or more variable sizes violate format constraints 552 test: 553 suffix: 14 554 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourBrickHex-large.exo -o FourBrickHex-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 2 555 test: 556 suffix: 15 557 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourBrickTet-large.exo -o FourBrickTet-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 2 558 #TODO: bug in call to NetCDF failed to complete invalid type definition in file id 65536 NetCDF: One or more variable sizes violate format constraints 559 #3d par 560 test: 561 suffix: 16 562 nsize: 2 563 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourBrickHex-large.exo -o FourBrickHex-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 1 564 test: 565 suffix: 17 566 nsize: 2 567 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourBrickTet-large.exo -o FourBrickTet-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 1 568 #TODO: bug in call to NetCDF failed to complete invalid type definition in file id 65536 NetCDF: One or more variable sizes violate format constraints 569 test: 570 suffix: 18 571 nsize: 2 572 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourBrickHex-large.exo -o FourBrickHex-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 2 573 test: 574 suffix: 19 575 nsize: 2 576 args: -i ${wPETSC_DIR}/share/petsc/datafiles/meshes/FourBrickTet-large.exo -o FourBrickTet-large_out.exo -dm_view -dm_section_view -petscpartitioner_type simple -order 2 577 #TODO: bug in call to NetCDF failed to complete invalid type definition in file id 65536 NetCDF: One or more variable sizes violate format constraints 578 579 TEST*/ 580