19f074e33SMatthew G Knepley #include <petsc-private/dmpleximpl.h> /*I "petscdmplex.h" I*/ 29f074e33SMatthew G Knepley #include <../src/sys/utils/hash.h> 39f074e33SMatthew G Knepley 49f074e33SMatthew G Knepley #undef __FUNCT__ 59a5b13a2SMatthew G Knepley #define __FUNCT__ "DMPlexGetFaces_Internal" 69f074e33SMatthew G Knepley /* 79a5b13a2SMatthew G Knepley DMPlexGetFaces_Internal - Gets groups of vertices that correspond to faces for the given cell 89f074e33SMatthew G Knepley */ 99a5b13a2SMatthew G Knepley static PetscErrorCode DMPlexGetFaces_Internal(DM dm, PetscInt dim, PetscInt p, PetscInt *numFaces, PetscInt *faceSize, const PetscInt *faces[]) 109f074e33SMatthew G Knepley { 119f074e33SMatthew G Knepley const PetscInt *cone = NULL; 129a5b13a2SMatthew G Knepley PetscInt *facesTmp; 139a5b13a2SMatthew G Knepley PetscInt maxConeSize, maxSupportSize, coneSize; 149f074e33SMatthew G Knepley PetscErrorCode ierr; 159f074e33SMatthew G Knepley 169f074e33SMatthew G Knepley PetscFunctionBegin; 179f074e33SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 189a5b13a2SMatthew G Knepley ierr = DMPlexGetMaxSizes(dm, &maxConeSize, &maxSupportSize);CHKERRQ(ierr); 199a5b13a2SMatthew G Knepley ierr = DMGetWorkArray(dm, PetscSqr(PetscMax(maxConeSize, maxSupportSize)), PETSC_INT, &facesTmp);CHKERRQ(ierr); 209f074e33SMatthew G Knepley ierr = DMPlexGetConeSize(dm, p, &coneSize);CHKERRQ(ierr); 219f074e33SMatthew G Knepley ierr = DMPlexGetCone(dm, p, &cone);CHKERRQ(ierr); 229f074e33SMatthew G Knepley switch (dim) { 239f074e33SMatthew G Knepley case 2: 249f074e33SMatthew G Knepley switch (coneSize) { 259f074e33SMatthew G Knepley case 3: 269a5b13a2SMatthew G Knepley if (faces) { 279a5b13a2SMatthew G Knepley facesTmp[0] = cone[0]; facesTmp[1] = cone[1]; 289a5b13a2SMatthew G Knepley facesTmp[2] = cone[1]; facesTmp[3] = cone[2]; 299a5b13a2SMatthew G Knepley facesTmp[4] = cone[2]; facesTmp[5] = cone[0]; 309a5b13a2SMatthew G Knepley *faces = facesTmp; 319a5b13a2SMatthew G Knepley } 329a5b13a2SMatthew G Knepley if (numFaces) *numFaces = 3; 339a5b13a2SMatthew G Knepley if (faceSize) *faceSize = 2; 349f074e33SMatthew G Knepley break; 359f074e33SMatthew G Knepley case 4: 369a5b13a2SMatthew G Knepley /* Vertices follow right hand rule */ 379a5b13a2SMatthew G Knepley if (faces) { 389a5b13a2SMatthew G Knepley facesTmp[0] = cone[0]; facesTmp[1] = cone[1]; 399a5b13a2SMatthew G Knepley facesTmp[2] = cone[1]; facesTmp[3] = cone[2]; 409a5b13a2SMatthew G Knepley facesTmp[4] = cone[2]; facesTmp[5] = cone[3]; 419a5b13a2SMatthew G Knepley facesTmp[6] = cone[3]; facesTmp[7] = cone[0]; 429a5b13a2SMatthew G Knepley *faces = facesTmp; 439a5b13a2SMatthew G Knepley } 449a5b13a2SMatthew G Knepley if (numFaces) *numFaces = 4; 459a5b13a2SMatthew G Knepley if (faceSize) *faceSize = 2; 469a5b13a2SMatthew G Knepley if (faces) *faces = facesTmp; 479f074e33SMatthew G Knepley break; 489f074e33SMatthew G Knepley default: 499f074e33SMatthew G Knepley SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cone size %D not supported for dimension %D", coneSize, dim); 509f074e33SMatthew G Knepley } 519f074e33SMatthew G Knepley break; 529f074e33SMatthew G Knepley case 3: 539f074e33SMatthew G Knepley switch (coneSize) { 549f074e33SMatthew G Knepley case 3: 559a5b13a2SMatthew G Knepley if (faces) { 569a5b13a2SMatthew G Knepley facesTmp[0] = cone[0]; facesTmp[1] = cone[1]; 579a5b13a2SMatthew G Knepley facesTmp[2] = cone[1]; facesTmp[3] = cone[2]; 589a5b13a2SMatthew G Knepley facesTmp[4] = cone[2]; facesTmp[5] = cone[0]; 599a5b13a2SMatthew G Knepley *faces = facesTmp; 609a5b13a2SMatthew G Knepley } 619a5b13a2SMatthew G Knepley if (numFaces) *numFaces = 3; 629a5b13a2SMatthew G Knepley if (faceSize) *faceSize = 2; 639a5b13a2SMatthew G Knepley if (faces) *faces = facesTmp; 649f074e33SMatthew G Knepley break; 659f074e33SMatthew G Knepley case 4: 669a5b13a2SMatthew G Knepley /* Vertices of first face follow right hand rule and normal points towards last vertex */ 679a5b13a2SMatthew G Knepley if (faces) { 689a5b13a2SMatthew G Knepley facesTmp[0] = cone[0]; facesTmp[1] = cone[2]; facesTmp[2] = cone[1]; 699a5b13a2SMatthew G Knepley facesTmp[3] = cone[0]; facesTmp[4] = cone[1]; facesTmp[5] = cone[3]; 709a5b13a2SMatthew G Knepley facesTmp[6] = cone[0]; facesTmp[7] = cone[3]; facesTmp[8] = cone[2]; 719a5b13a2SMatthew G Knepley facesTmp[9] = cone[1]; facesTmp[10] = cone[2]; facesTmp[11] = cone[3]; 729a5b13a2SMatthew G Knepley *faces = facesTmp; 739a5b13a2SMatthew G Knepley } 749a5b13a2SMatthew G Knepley if (numFaces) *numFaces = 4; 759a5b13a2SMatthew G Knepley if (faceSize) *faceSize = 3; 769a5b13a2SMatthew G Knepley if (faces) *faces = facesTmp; 779a5b13a2SMatthew G Knepley break; 789a5b13a2SMatthew G Knepley case 8: 799a5b13a2SMatthew G Knepley if (faces) { 809a5b13a2SMatthew G Knepley facesTmp[0] = cone[0]; facesTmp[1] = cone[3]; facesTmp[2] = cone[2]; facesTmp[3] = cone[1]; 81a014044eSMatthew G Knepley facesTmp[4] = cone[4]; facesTmp[5] = cone[5]; facesTmp[6] = cone[6]; facesTmp[7] = cone[7]; 829a5b13a2SMatthew G Knepley facesTmp[8] = cone[0]; facesTmp[9] = cone[1]; facesTmp[10] = cone[5]; facesTmp[11] = cone[4]; 839a5b13a2SMatthew G Knepley facesTmp[12] = cone[2]; facesTmp[13] = cone[3]; facesTmp[14] = cone[7]; facesTmp[15] = cone[6]; 849a5b13a2SMatthew G Knepley facesTmp[16] = cone[1]; facesTmp[17] = cone[2]; facesTmp[18] = cone[6]; facesTmp[19] = cone[5]; 859a5b13a2SMatthew G Knepley facesTmp[20] = cone[0]; facesTmp[21] = cone[4]; facesTmp[22] = cone[7]; facesTmp[23] = cone[3]; 869a5b13a2SMatthew G Knepley *faces = facesTmp; 879a5b13a2SMatthew G Knepley } 889a5b13a2SMatthew G Knepley if (numFaces) *numFaces = 6; 899a5b13a2SMatthew G Knepley if (faceSize) *faceSize = 4; 909f074e33SMatthew G Knepley break; 919f074e33SMatthew G Knepley default: 929f074e33SMatthew G Knepley SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cone size %D not supported for dimension %D", coneSize, dim); 939f074e33SMatthew G Knepley } 949f074e33SMatthew G Knepley break; 959f074e33SMatthew G Knepley default: 969f074e33SMatthew G Knepley SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Dimension %D not supported", dim); 979f074e33SMatthew G Knepley } 989a5b13a2SMatthew G Knepley ierr = DMRestoreWorkArray(dm, 0, PETSC_INT, &facesTmp);CHKERRQ(ierr); 999f074e33SMatthew G Knepley PetscFunctionReturn(0); 1009f074e33SMatthew G Knepley } 1019f074e33SMatthew G Knepley 1029f074e33SMatthew G Knepley #undef __FUNCT__ 1039a5b13a2SMatthew G Knepley #define __FUNCT__ "DMPlexInterpolateFaces_Internal" 1049a5b13a2SMatthew G Knepley /* This interpolates faces for cells at some stratum */ 1059a5b13a2SMatthew G Knepley static PetscErrorCode DMPlexInterpolateFaces_Internal(DM dm, PetscInt cellDepth, DM idm) 1069f074e33SMatthew G Knepley { 107d4efc6f1SMatthew G. Knepley DMLabel subpointMap; 1089a5b13a2SMatthew G Knepley PetscHashIJKL faceTable; 1099a5b13a2SMatthew G Knepley PetscInt *pStart, *pEnd; 1109a5b13a2SMatthew G Knepley PetscInt cellDim, depth, faceDepth = cellDepth, numPoints = 0, faceSizeAll = 0, face, c, d; 1119f074e33SMatthew G Knepley PetscErrorCode ierr; 1129f074e33SMatthew G Knepley 1139f074e33SMatthew G Knepley PetscFunctionBegin; 1149a5b13a2SMatthew G Knepley ierr = DMPlexGetDimension(dm, &cellDim);CHKERRQ(ierr); 115d4efc6f1SMatthew G. Knepley /* HACK: I need a better way to determine face dimension, or an alternative to GetFaces() */ 116d4efc6f1SMatthew G. Knepley ierr = DMPlexGetSubpointMap(dm, &subpointMap);CHKERRQ(ierr); 117d4efc6f1SMatthew G. Knepley if (subpointMap) ++cellDim; 1189a5b13a2SMatthew G Knepley ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); 1199a5b13a2SMatthew G Knepley ++depth; 1209a5b13a2SMatthew G Knepley ++cellDepth; 1219a5b13a2SMatthew G Knepley cellDim -= depth - cellDepth; 1229a5b13a2SMatthew G Knepley ierr = PetscMalloc2(depth+1,PetscInt,&pStart,depth+1,PetscInt,&pEnd);CHKERRQ(ierr); 1239a5b13a2SMatthew G Knepley for (d = depth-1; d >= faceDepth; --d) { 1249a5b13a2SMatthew G Knepley ierr = DMPlexGetDepthStratum(dm, d, &pStart[d+1], &pEnd[d+1]);CHKERRQ(ierr); 1259f074e33SMatthew G Knepley } 1269a5b13a2SMatthew G Knepley ierr = DMPlexGetDepthStratum(dm, -1, NULL, &pStart[faceDepth]);CHKERRQ(ierr); 1279a5b13a2SMatthew G Knepley pEnd[faceDepth] = pStart[faceDepth]; 1289a5b13a2SMatthew G Knepley for (d = faceDepth-1; d >= 0; --d) { 1299a5b13a2SMatthew G Knepley ierr = DMPlexGetDepthStratum(dm, d, &pStart[d], &pEnd[d]);CHKERRQ(ierr); 1309f074e33SMatthew G Knepley } 1319a5b13a2SMatthew G Knepley if (pEnd[cellDepth] > pStart[cellDepth]) {ierr = DMPlexGetFaces_Internal(dm, cellDim, pStart[cellDepth], NULL, &faceSizeAll, NULL);CHKERRQ(ierr);} 1329a5b13a2SMatthew G Knepley if (faceSizeAll > 4) SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "Do not support interpolation of meshes with faces of %D vertices", faceSizeAll); 1339a5b13a2SMatthew G Knepley ierr = PetscHashIJKLCreate(&faceTable);CHKERRQ(ierr); 1349a5b13a2SMatthew G Knepley ierr = PetscHashIJKLSetMultivalued(faceTable, PETSC_FALSE);CHKERRQ(ierr); 1359a5b13a2SMatthew G Knepley for (c = pStart[cellDepth], face = pStart[faceDepth]; c < pEnd[cellDepth]; ++c) { 1369f074e33SMatthew G Knepley const PetscInt *cellFaces; 1379a5b13a2SMatthew G Knepley PetscInt numCellFaces, faceSize, cf, f; 1389f074e33SMatthew G Knepley 1399a5b13a2SMatthew G Knepley ierr = DMPlexGetFaces_Internal(dm, cellDim, c, &numCellFaces, &faceSize, &cellFaces);CHKERRQ(ierr); 1409a5b13a2SMatthew G Knepley if (faceSize != faceSizeAll) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Inconsistent face for cell %D of size %D != %D", c, faceSize, faceSizeAll); 1419f074e33SMatthew G Knepley for (cf = 0; cf < numCellFaces; ++cf) { 1429a5b13a2SMatthew G Knepley const PetscInt *cellFace = &cellFaces[cf*faceSize]; 1439a5b13a2SMatthew G Knepley PetscHashIJKLKey key; 1449f074e33SMatthew G Knepley 1459a5b13a2SMatthew G Knepley if (faceSize == 2) { 1469a5b13a2SMatthew G Knepley key.i = PetscMin(cellFace[0], cellFace[1]); 1479a5b13a2SMatthew G Knepley key.j = PetscMax(cellFace[0], cellFace[1]); 1489a5b13a2SMatthew G Knepley } else { 1499a5b13a2SMatthew G Knepley key.i = cellFace[0]; key.j = cellFace[1]; key.k = cellFace[2]; key.l = faceSize > 3 ? cellFace[3] : 0; 1509a5b13a2SMatthew G Knepley ierr = PetscSortInt(faceSize, (PetscInt *) &key); 1519f074e33SMatthew G Knepley } 1529a5b13a2SMatthew G Knepley ierr = PetscHashIJKLGet(faceTable, key, &f);CHKERRQ(ierr); 1539a5b13a2SMatthew G Knepley if (f < 0) { 1549a5b13a2SMatthew G Knepley ierr = PetscHashIJKLAdd(faceTable, key, face);CHKERRQ(ierr); 1559a5b13a2SMatthew G Knepley f = face++; 1569a5b13a2SMatthew G Knepley } 1579a5b13a2SMatthew G Knepley } 1589a5b13a2SMatthew G Knepley } 1599a5b13a2SMatthew G Knepley pEnd[faceDepth] = face; 1609a5b13a2SMatthew G Knepley ierr = PetscHashIJKLDestroy(&faceTable);CHKERRQ(ierr); 1619a5b13a2SMatthew G Knepley /* Count new points */ 1629a5b13a2SMatthew G Knepley for (d = 0; d <= depth; ++d) { 1639a5b13a2SMatthew G Knepley numPoints += pEnd[d]-pStart[d]; 1649a5b13a2SMatthew G Knepley } 1659a5b13a2SMatthew G Knepley ierr = DMPlexSetChart(idm, 0, numPoints);CHKERRQ(ierr); 1669a5b13a2SMatthew G Knepley /* Set cone sizes */ 1679a5b13a2SMatthew G Knepley for (d = 0; d <= depth; ++d) { 1689a5b13a2SMatthew G Knepley PetscInt coneSize, p; 1699f074e33SMatthew G Knepley 1709a5b13a2SMatthew G Knepley if (d == faceDepth) { 1719a5b13a2SMatthew G Knepley for (p = pStart[d]; p < pEnd[d]; ++p) { 1729a5b13a2SMatthew G Knepley /* I see no way to do this if we admit faces of different shapes */ 1739a5b13a2SMatthew G Knepley ierr = DMPlexSetConeSize(idm, p, faceSizeAll);CHKERRQ(ierr); 1749a5b13a2SMatthew G Knepley } 175a014044eSMatthew G Knepley } else if (d == cellDepth) { 176a014044eSMatthew G Knepley for (p = pStart[d]; p < pEnd[d]; ++p) { 177a014044eSMatthew G Knepley /* Number of cell faces may be different from number of cell vertices*/ 178a014044eSMatthew G Knepley ierr = DMPlexGetFaces_Internal(dm, cellDim, p, &coneSize, NULL, NULL);CHKERRQ(ierr); 179a014044eSMatthew G Knepley ierr = DMPlexSetConeSize(idm, p, coneSize);CHKERRQ(ierr); 180a014044eSMatthew G Knepley } 1819a5b13a2SMatthew G Knepley } else { 1829a5b13a2SMatthew G Knepley for (p = pStart[d]; p < pEnd[d]; ++p) { 1839a5b13a2SMatthew G Knepley ierr = DMPlexGetConeSize(dm, p, &coneSize);CHKERRQ(ierr); 1849a5b13a2SMatthew G Knepley ierr = DMPlexSetConeSize(idm, p, coneSize);CHKERRQ(ierr); 1859f074e33SMatthew G Knepley } 1869f074e33SMatthew G Knepley } 1879f074e33SMatthew G Knepley } 1889f074e33SMatthew G Knepley ierr = DMSetUp(idm);CHKERRQ(ierr); 1899f074e33SMatthew G Knepley /* Get face cones from subsets of cell vertices */ 1909a5b13a2SMatthew G Knepley if (faceSizeAll > 4) SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "Do not support interpolation of meshes with faces of %D vertices", faceSizeAll); 1919a5b13a2SMatthew G Knepley ierr = PetscHashIJKLCreate(&faceTable);CHKERRQ(ierr); 1929a5b13a2SMatthew G Knepley ierr = PetscHashIJKLSetMultivalued(faceTable, PETSC_FALSE);CHKERRQ(ierr); 1939a5b13a2SMatthew G Knepley for (d = depth; d > cellDepth; --d) { 1949a5b13a2SMatthew G Knepley const PetscInt *cone; 1959a5b13a2SMatthew G Knepley PetscInt p; 1969a5b13a2SMatthew G Knepley 1979a5b13a2SMatthew G Knepley for (p = pStart[d]; p < pEnd[d]; ++p) { 1989a5b13a2SMatthew G Knepley ierr = DMPlexGetCone(dm, p, &cone);CHKERRQ(ierr); 1999a5b13a2SMatthew G Knepley ierr = DMPlexSetCone(idm, p, cone);CHKERRQ(ierr); 2009a5b13a2SMatthew G Knepley ierr = DMPlexGetConeOrientation(dm, p, &cone);CHKERRQ(ierr); 2019a5b13a2SMatthew G Knepley ierr = DMPlexSetConeOrientation(idm, p, cone);CHKERRQ(ierr); 2029f074e33SMatthew G Knepley } 2039a5b13a2SMatthew G Knepley } 2049a5b13a2SMatthew G Knepley for (c = pStart[cellDepth], face = pStart[faceDepth]; c < pEnd[cellDepth]; ++c) { 2059f074e33SMatthew G Knepley const PetscInt *cellFaces; 2069a5b13a2SMatthew G Knepley PetscInt numCellFaces, faceSize, cf, f; 2079f074e33SMatthew G Knepley 2089a5b13a2SMatthew G Knepley ierr = DMPlexGetFaces_Internal(dm, cellDim, c, &numCellFaces, &faceSize, &cellFaces);CHKERRQ(ierr); 2099a5b13a2SMatthew G Knepley if (faceSize != faceSizeAll) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Inconsistent face for cell %D of size %D != %D", c, faceSize, faceSizeAll); 2109f074e33SMatthew G Knepley for (cf = 0; cf < numCellFaces; ++cf) { 2119a5b13a2SMatthew G Knepley const PetscInt *cellFace = &cellFaces[cf*faceSize]; 2129a5b13a2SMatthew G Knepley PetscHashIJKLKey key; 2139f074e33SMatthew G Knepley 2149a5b13a2SMatthew G Knepley if (faceSize == 2) { 2159a5b13a2SMatthew G Knepley key.i = PetscMin(cellFace[0], cellFace[1]); 2169a5b13a2SMatthew G Knepley key.j = PetscMax(cellFace[0], cellFace[1]); 2179a5b13a2SMatthew G Knepley } else { 2189a5b13a2SMatthew G Knepley key.i = cellFace[0]; key.j = cellFace[1]; key.k = cellFace[2]; key.l = faceSize > 3 ? cellFace[3] : 0; 2199a5b13a2SMatthew G Knepley ierr = PetscSortInt(faceSize, (PetscInt *) &key); 2209f074e33SMatthew G Knepley } 2219a5b13a2SMatthew G Knepley ierr = PetscHashIJKLGet(faceTable, key, &f);CHKERRQ(ierr); 2229a5b13a2SMatthew G Knepley if (f < 0) { 2239a5b13a2SMatthew G Knepley ierr = DMPlexSetCone(idm, face, cellFace);CHKERRQ(ierr); 2249a5b13a2SMatthew G Knepley ierr = PetscHashIJKLAdd(faceTable, key, face);CHKERRQ(ierr); 2259a5b13a2SMatthew G Knepley f = face++; 2269f074e33SMatthew G Knepley ierr = DMPlexInsertCone(idm, c, cf, f);CHKERRQ(ierr); 2279a5b13a2SMatthew G Knepley } else { 2289a5b13a2SMatthew G Knepley const PetscInt *cone; 2299a5b13a2SMatthew G Knepley PetscInt coneSize, ornt, i, j; 2309f074e33SMatthew G Knepley 2319a5b13a2SMatthew G Knepley ierr = DMPlexInsertCone(idm, c, cf, f);CHKERRQ(ierr); 2329a5b13a2SMatthew G Knepley /* Orient face */ 2339f074e33SMatthew G Knepley ierr = DMPlexGetConeSize(idm, f, &coneSize);CHKERRQ(ierr); 2349f074e33SMatthew G Knepley ierr = DMPlexGetCone(idm, f, &cone);CHKERRQ(ierr); 2359a5b13a2SMatthew G Knepley if (coneSize != faceSize) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid number of face vertices %D for face %D should be %D", coneSize, f, faceSize); 2369a5b13a2SMatthew G Knepley /* - First find the initial vertex */ 2379a5b13a2SMatthew G Knepley for (i = 0; i < faceSize; ++i) if (cellFace[0] == cone[i]) break; 2389a5b13a2SMatthew G Knepley /* - Try forward comparison */ 2399a5b13a2SMatthew G Knepley for (j = 0; j < faceSize; ++j) if (cellFace[j] != cone[(i+j)%faceSize]) break; 2409a5b13a2SMatthew G Knepley if (j == faceSize) { 2419a5b13a2SMatthew G Knepley if ((faceSize == 2) && (i == 1)) ornt = -2; 2429a5b13a2SMatthew G Knepley else ornt = i; 2439a5b13a2SMatthew G Knepley } else { 2449a5b13a2SMatthew G Knepley /* - Try backward comparison */ 2459a5b13a2SMatthew G Knepley for (j = 0; j < faceSize; ++j) if (cellFace[j] != cone[(i+faceSize-j)%faceSize]) break; 2469a5b13a2SMatthew G Knepley if (j == faceSize) ornt = -(i+1); 2479a5b13a2SMatthew G Knepley else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Could not determine face orientation"); 2489a5b13a2SMatthew G Knepley } 2499a5b13a2SMatthew G Knepley ierr = DMPlexInsertConeOrientation(idm, c, cf, ornt);CHKERRQ(ierr); 2509f074e33SMatthew G Knepley } 2519f074e33SMatthew G Knepley } 2529f074e33SMatthew G Knepley } 2539a5b13a2SMatthew G Knepley if (face != pEnd[faceDepth]) SETERRQ2(PetscObjectComm((PetscObject) dm), PETSC_ERR_PLIB, "Invalid number of faces %D should be %D", face-pStart[faceDepth], pEnd[faceDepth]-pStart[faceDepth]); 2549a5b13a2SMatthew G Knepley ierr = PetscHashIJKLDestroy(&faceTable);CHKERRQ(ierr); 2559a5b13a2SMatthew G Knepley ierr = DMPlexSymmetrize(idm);CHKERRQ(ierr); 2569a5b13a2SMatthew G Knepley ierr = DMPlexStratify(idm);CHKERRQ(ierr); 2579f074e33SMatthew G Knepley PetscFunctionReturn(0); 2589f074e33SMatthew G Knepley } 2599f074e33SMatthew G Knepley 2609f074e33SMatthew G Knepley #undef __FUNCT__ 2619f074e33SMatthew G Knepley #define __FUNCT__ "DMPlexInterpolate" 2629f074e33SMatthew G Knepley PetscErrorCode DMPlexInterpolate(DM dm, DM *dmInt) 2639f074e33SMatthew G Knepley { 2649a5b13a2SMatthew G Knepley DM idm, odm = dm; 2659a5b13a2SMatthew G Knepley PetscInt dim, d; 2669f074e33SMatthew G Knepley PetscErrorCode ierr; 2679f074e33SMatthew G Knepley 2689f074e33SMatthew G Knepley PetscFunctionBegin; 2699f074e33SMatthew G Knepley ierr = DMPlexGetDimension(dm, &dim);CHKERRQ(ierr); 270*76b791aaSMatthew G. Knepley if (dim <= 1) { 271*76b791aaSMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm);CHKERRQ(ierr); 272*76b791aaSMatthew G. Knepley idm = dm; 273*76b791aaSMatthew G. Knepley } 2749a5b13a2SMatthew G Knepley for (d = 1; d < dim; ++d) { 2759a5b13a2SMatthew G Knepley /* Create interpolated mesh */ 2769a5b13a2SMatthew G Knepley ierr = DMCreate(PetscObjectComm((PetscObject)dm), &idm);CHKERRQ(ierr); 2779a5b13a2SMatthew G Knepley ierr = DMSetType(idm, DMPLEX);CHKERRQ(ierr); 2789a5b13a2SMatthew G Knepley ierr = DMPlexSetDimension(idm, dim);CHKERRQ(ierr); 2799a5b13a2SMatthew G Knepley ierr = DMPlexInterpolateFaces_Internal(odm, 1, idm);CHKERRQ(ierr); 2809a5b13a2SMatthew G Knepley if (odm != dm) {ierr = DMDestroy(&odm);CHKERRQ(ierr);} 2819a5b13a2SMatthew G Knepley odm = idm; 2829f074e33SMatthew G Knepley } 2839a5b13a2SMatthew G Knepley *dmInt = idm; 2849f074e33SMatthew G Knepley PetscFunctionReturn(0); 2859f074e33SMatthew G Knepley } 28607b0a1fcSMatthew G Knepley 28707b0a1fcSMatthew G Knepley #undef __FUNCT__ 28807b0a1fcSMatthew G Knepley #define __FUNCT__ "DMPlexCopyCoordinates" 28907b0a1fcSMatthew G Knepley PetscErrorCode DMPlexCopyCoordinates(DM dmA, DM dmB) 29007b0a1fcSMatthew G Knepley { 29107b0a1fcSMatthew G Knepley Vec coordinatesA, coordinatesB; 29207b0a1fcSMatthew G Knepley PetscSection coordSectionA, coordSectionB; 29307b0a1fcSMatthew G Knepley PetscScalar *coordsA, *coordsB; 29407b0a1fcSMatthew G Knepley PetscInt spaceDim, vStartA, vStartB, vEndA, vEndB, coordSizeB, v, d; 29507b0a1fcSMatthew G Knepley PetscErrorCode ierr; 29607b0a1fcSMatthew G Knepley 29707b0a1fcSMatthew G Knepley PetscFunctionBegin; 298*76b791aaSMatthew G. Knepley if (dmA == dmB) PetscFunctionReturn(0); 29907b0a1fcSMatthew G Knepley ierr = DMPlexGetDepthStratum(dmA, 0, &vStartA, &vEndA);CHKERRQ(ierr); 30007b0a1fcSMatthew G Knepley ierr = DMPlexGetDepthStratum(dmB, 0, &vStartB, &vEndB);CHKERRQ(ierr); 30107b0a1fcSMatthew G Knepley if ((vEndA-vStartA) != (vEndB-vStartB)) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "The number of vertices in first DM %d != %d in the second DM", vEndA-vStartA, vEndB-vStartB); 30207b0a1fcSMatthew G Knepley ierr = DMPlexGetCoordinateSection(dmA, &coordSectionA);CHKERRQ(ierr); 30307b0a1fcSMatthew G Knepley ierr = DMPlexGetCoordinateSection(dmB, &coordSectionB);CHKERRQ(ierr); 30407b0a1fcSMatthew G Knepley ierr = PetscSectionSetNumFields(coordSectionB, 1);CHKERRQ(ierr); 30507b0a1fcSMatthew G Knepley ierr = PetscSectionGetFieldComponents(coordSectionA, 0, &spaceDim);CHKERRQ(ierr); 30607b0a1fcSMatthew G Knepley ierr = PetscSectionSetFieldComponents(coordSectionB, 0, spaceDim);CHKERRQ(ierr); 30707b0a1fcSMatthew G Knepley ierr = PetscSectionSetChart(coordSectionB, vStartB, vEndB);CHKERRQ(ierr); 30807b0a1fcSMatthew G Knepley for (v = vStartB; v < vEndB; ++v) { 30907b0a1fcSMatthew G Knepley ierr = PetscSectionSetDof(coordSectionB, v, spaceDim);CHKERRQ(ierr); 31007b0a1fcSMatthew G Knepley ierr = PetscSectionSetFieldDof(coordSectionB, v, 0, spaceDim);CHKERRQ(ierr); 31107b0a1fcSMatthew G Knepley } 31207b0a1fcSMatthew G Knepley ierr = PetscSectionSetUp(coordSectionB);CHKERRQ(ierr); 31307b0a1fcSMatthew G Knepley ierr = PetscSectionGetStorageSize(coordSectionB, &coordSizeB);CHKERRQ(ierr); 31407b0a1fcSMatthew G Knepley ierr = DMGetCoordinatesLocal(dmA, &coordinatesA);CHKERRQ(ierr); 31507b0a1fcSMatthew G Knepley ierr = VecCreate(PetscObjectComm((PetscObject) dmB), &coordinatesB);CHKERRQ(ierr); 31607b0a1fcSMatthew G Knepley ierr = PetscObjectSetName((PetscObject) coordinatesB, "coordinates");CHKERRQ(ierr); 31707b0a1fcSMatthew G Knepley ierr = VecSetSizes(coordinatesB, coordSizeB, PETSC_DETERMINE);CHKERRQ(ierr); 31807b0a1fcSMatthew G Knepley ierr = VecSetFromOptions(coordinatesB);CHKERRQ(ierr); 31907b0a1fcSMatthew G Knepley ierr = VecGetArray(coordinatesA, &coordsA);CHKERRQ(ierr); 32007b0a1fcSMatthew G Knepley ierr = VecGetArray(coordinatesB, &coordsB);CHKERRQ(ierr); 32107b0a1fcSMatthew G Knepley for (v = 0; v < vEndB-vStartB; ++v) { 32207b0a1fcSMatthew G Knepley for (d = 0; d < spaceDim; ++d) { 32307b0a1fcSMatthew G Knepley coordsB[v*spaceDim+d] = coordsA[v*spaceDim+d]; 32407b0a1fcSMatthew G Knepley } 32507b0a1fcSMatthew G Knepley } 32607b0a1fcSMatthew G Knepley ierr = VecRestoreArray(coordinatesA, &coordsA);CHKERRQ(ierr); 32707b0a1fcSMatthew G Knepley ierr = VecRestoreArray(coordinatesB, &coordsB);CHKERRQ(ierr); 32807b0a1fcSMatthew G Knepley ierr = DMSetCoordinatesLocal(dmB, coordinatesB);CHKERRQ(ierr); 32907b0a1fcSMatthew G Knepley ierr = VecDestroy(&coordinatesB);CHKERRQ(ierr); 33007b0a1fcSMatthew G Knepley PetscFunctionReturn(0); 33107b0a1fcSMatthew G Knepley } 332