1af0996ceSBarry Smith #include <petsc/private/dmimpl.h> /*I "petscdm.h" I*/ 22764a2aaSMatthew G. Knepley #include <petscds.h> 311689aebSJed Brown 411689aebSJed Brown PetscErrorCode DMCreateGlobalVector_Section_Private(DM dm,Vec *vec) 511689aebSJed Brown { 611689aebSJed Brown PetscSection gSection; 7cc30b04dSMatthew G Knepley PetscInt localSize, bs, blockSize = -1, pStart, pEnd, p; 8fad22124SMatthew G Knepley PetscErrorCode ierr; 95d1c0279SHong Zhang PetscInt in[2],out[2]; 1011689aebSJed Brown 1111689aebSJed Brown PetscFunctionBegin; 12e87a4003SBarry Smith ierr = DMGetGlobalSection(dm, &gSection);CHKERRQ(ierr); 13fad22124SMatthew G Knepley ierr = PetscSectionGetChart(gSection, &pStart, &pEnd);CHKERRQ(ierr); 1411689aebSJed Brown for (p = pStart; p < pEnd; ++p) { 1511689aebSJed Brown PetscInt dof, cdof; 1611689aebSJed Brown 17fad22124SMatthew G Knepley ierr = PetscSectionGetDof(gSection, p, &dof);CHKERRQ(ierr); 18fad22124SMatthew G Knepley ierr = PetscSectionGetConstraintDof(gSection, p, &cdof);CHKERRQ(ierr); 190680ce0aSHong Zhang 200680ce0aSHong Zhang if (dof > 0) { 210680ce0aSHong Zhang if (blockSize < 0 && dof-cdof > 0) { 220680ce0aSHong Zhang /* set blockSize */ 230680ce0aSHong Zhang blockSize = dof-cdof; 240680ce0aSHong Zhang } else if (dof-cdof != blockSize) { 250680ce0aSHong Zhang /* non-identical blockSize, set it as 1 */ 2611689aebSJed Brown blockSize = 1; 2711689aebSJed Brown break; 2811689aebSJed Brown } 2911689aebSJed Brown } 300680ce0aSHong Zhang } 315d1c0279SHong Zhang 322c8be454SMatthew G. Knepley in[0] = blockSize < 0 ? PETSC_MIN_INT : -blockSize; 335d1c0279SHong Zhang in[1] = blockSize; 34bdfec8b8SHong Zhang ierr = MPIU_Allreduce(in,out,2,MPIU_INT,MPI_MAX,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 355d1c0279SHong Zhang /* -out[0] = min(blockSize), out[1] = max(blockSize) */ 365d1c0279SHong Zhang if (-out[0] == out[1]) { 375d1c0279SHong Zhang bs = out[1]; 385d1c0279SHong Zhang } else bs = 1; 395d1c0279SHong Zhang 405d1c0279SHong Zhang if (bs < 0) { /* Everyone was empty */ 415d1c0279SHong Zhang blockSize = 1; 425d1c0279SHong Zhang bs = 1; 435d1c0279SHong Zhang } 445d1c0279SHong Zhang 45fad22124SMatthew G Knepley ierr = PetscSectionGetConstrainedStorageSize(gSection, &localSize);CHKERRQ(ierr); 4682f516ccSBarry Smith if (localSize%blockSize) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Mismatch between blocksize %d and local storage size %d", blockSize, localSize); 4782f516ccSBarry Smith ierr = VecCreate(PetscObjectComm((PetscObject)dm), vec);CHKERRQ(ierr); 4811689aebSJed Brown ierr = VecSetSizes(*vec, localSize, PETSC_DETERMINE);CHKERRQ(ierr); 49cc30b04dSMatthew G Knepley ierr = VecSetBlockSize(*vec, bs);CHKERRQ(ierr); 50c0dedaeaSBarry Smith ierr = VecSetType(*vec,dm->vectype);CHKERRQ(ierr); 5111689aebSJed Brown ierr = VecSetDM(*vec, dm);CHKERRQ(ierr); 5211689aebSJed Brown /* ierr = VecSetLocalToGlobalMapping(*vec, dm->ltogmap);CHKERRQ(ierr); */ 5311689aebSJed Brown PetscFunctionReturn(0); 5411689aebSJed Brown } 5511689aebSJed Brown 5611689aebSJed Brown PetscErrorCode DMCreateLocalVector_Section_Private(DM dm,Vec *vec) 5711689aebSJed Brown { 58fad22124SMatthew G Knepley PetscSection section; 5911689aebSJed Brown PetscInt localSize, blockSize = -1, pStart, pEnd, p; 60fad22124SMatthew G Knepley PetscErrorCode ierr; 6111689aebSJed Brown 6211689aebSJed Brown PetscFunctionBegin; 63e87a4003SBarry Smith ierr = DMGetSection(dm, §ion);CHKERRQ(ierr); 64fad22124SMatthew G Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 6511689aebSJed Brown for (p = pStart; p < pEnd; ++p) { 6611689aebSJed Brown PetscInt dof; 6711689aebSJed Brown 68fad22124SMatthew G Knepley ierr = PetscSectionGetDof(section, p, &dof);CHKERRQ(ierr); 6911689aebSJed Brown if ((blockSize < 0) && (dof > 0)) blockSize = dof; 7011689aebSJed Brown if ((dof > 0) && (dof != blockSize)) { 7111689aebSJed Brown blockSize = 1; 7211689aebSJed Brown break; 7311689aebSJed Brown } 7411689aebSJed Brown } 75fad22124SMatthew G Knepley ierr = PetscSectionGetStorageSize(section, &localSize);CHKERRQ(ierr); 7611689aebSJed Brown ierr = VecCreate(PETSC_COMM_SELF, vec);CHKERRQ(ierr); 7711689aebSJed Brown ierr = VecSetSizes(*vec, localSize, localSize);CHKERRQ(ierr); 7811689aebSJed Brown ierr = VecSetBlockSize(*vec, blockSize);CHKERRQ(ierr); 79c0dedaeaSBarry Smith ierr = VecSetType(*vec,dm->vectype);CHKERRQ(ierr); 8011689aebSJed Brown ierr = VecSetDM(*vec, dm);CHKERRQ(ierr); 8111689aebSJed Brown PetscFunctionReturn(0); 8211689aebSJed Brown } 834d9407bcSMatthew G. Knepley 84*792b654fSMatthew G. Knepley /*@C 85*792b654fSMatthew G. Knepley DMCreateSectionSubDM - Returns an IS and subDM+subSection encapsulating a subproblem defined by the fields in a PetscSection in the DM. 86*792b654fSMatthew G. Knepley 87*792b654fSMatthew G. Knepley Not collective 88*792b654fSMatthew G. Knepley 89*792b654fSMatthew G. Knepley Input Parameters: 90*792b654fSMatthew G. Knepley + dm - The DM object 91*792b654fSMatthew G. Knepley . numFields - The number of fields in this subproblem 92*792b654fSMatthew G. Knepley - fields - The field numbers of the selected fields 93*792b654fSMatthew G. Knepley 94*792b654fSMatthew G. Knepley Output Parameters: 95*792b654fSMatthew G. Knepley + is - The global indices for the subproblem 96*792b654fSMatthew G. Knepley - subdm - The DM for the subproblem, which must already have be cloned from dm 97*792b654fSMatthew G. Knepley 98*792b654fSMatthew G. Knepley Note: This handles all information in the DM class and the PetscSection. This is used as the basis for creating subDMs in specialized classes, 99*792b654fSMatthew G. Knepley such as Plex and Forest. 100*792b654fSMatthew G. Knepley 101*792b654fSMatthew G. Knepley Level: intermediate 102*792b654fSMatthew G. Knepley 103*792b654fSMatthew G. Knepley .seealso DMCreateSubDM(), DMGetSection(), DMPlexSetMigrationSF(), DMView() 104*792b654fSMatthew G. Knepley @*/ 105*792b654fSMatthew G. Knepley PetscErrorCode DMCreateSectionSubDM(DM dm, PetscInt numFields, const PetscInt fields[], IS *is, DM *subdm) 1064d9407bcSMatthew G. Knepley { 1074d9407bcSMatthew G. Knepley PetscSection section, sectionGlobal; 1084d9407bcSMatthew G. Knepley PetscInt *subIndices; 109696188eaSMatthew G. Knepley PetscInt subSize = 0, subOff = 0, Nf, f, pStart, pEnd, p; 1104d9407bcSMatthew G. Knepley PetscErrorCode ierr; 1114d9407bcSMatthew G. Knepley 1124d9407bcSMatthew G. Knepley PetscFunctionBegin; 1134d9407bcSMatthew G. Knepley if (!numFields) PetscFunctionReturn(0); 114e87a4003SBarry Smith ierr = DMGetSection(dm, §ion);CHKERRQ(ierr); 115e87a4003SBarry Smith ierr = DMGetGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 1164d9407bcSMatthew G. Knepley if (!section) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Must set default section for DM before splitting fields"); 1174d9407bcSMatthew G. Knepley if (!sectionGlobal) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Must set default global section for DM before splitting fields"); 118696188eaSMatthew G. Knepley ierr = PetscSectionGetNumFields(section, &Nf);CHKERRQ(ierr); 119696188eaSMatthew G. Knepley if (numFields > Nf) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Number of requested fields %d greater than number of DM fields %d", numFields, Nf); 1204d9407bcSMatthew G. Knepley if (is) { 1213a544194SStefano Zampini PetscInt bs, bsLocal[2], bsMinMax[2]; 1223a544194SStefano Zampini 1233a544194SStefano Zampini for (f = 0, bs = 0; f < numFields; ++f) { 1243a544194SStefano Zampini PetscInt Nc; 1253a544194SStefano Zampini 1263a544194SStefano Zampini ierr = PetscSectionGetFieldComponents(section, fields[f], &Nc);CHKERRQ(ierr); 1273a544194SStefano Zampini bs += Nc; 1283a544194SStefano Zampini } 1294d9407bcSMatthew G. Knepley ierr = PetscSectionGetChart(sectionGlobal, &pStart, &pEnd);CHKERRQ(ierr); 1304d9407bcSMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 131b9eca265Ssarens PetscInt gdof, pSubSize = 0; 1324d9407bcSMatthew G. Knepley 1334d9407bcSMatthew G. Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 1344d9407bcSMatthew G. Knepley if (gdof > 0) { 1354d9407bcSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 1364d9407bcSMatthew G. Knepley PetscInt fdof, fcdof; 1374d9407bcSMatthew G. Knepley 1384d9407bcSMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, p, fields[f], &fdof);CHKERRQ(ierr); 1394d9407bcSMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, fields[f], &fcdof);CHKERRQ(ierr); 140b9eca265Ssarens pSubSize += fdof-fcdof; 141b9eca265Ssarens } 142b9eca265Ssarens subSize += pSubSize; 1433a544194SStefano Zampini if (pSubSize && bs != pSubSize) { 144b9eca265Ssarens /* Layout does not admit a pointwise block size */ 145b9eca265Ssarens bs = 1; 1464d9407bcSMatthew G. Knepley } 1474d9407bcSMatthew G. Knepley } 1484d9407bcSMatthew G. Knepley } 149b9eca265Ssarens /* Must have same blocksize on all procs (some might have no points) */ 1500be3e97aSMatthew G. Knepley bsLocal[0] = bs < 0 ? PETSC_MAX_INT : bs; bsLocal[1] = bs; 1510be3e97aSMatthew G. Knepley ierr = PetscGlobalMinMaxInt(PetscObjectComm((PetscObject) dm), bsLocal, bsMinMax);CHKERRQ(ierr); 1520be3e97aSMatthew G. Knepley if (bsMinMax[0] != bsMinMax[1]) {bs = 1;} 1530be3e97aSMatthew G. Knepley else {bs = bsMinMax[0];} 154785e854fSJed Brown ierr = PetscMalloc1(subSize, &subIndices);CHKERRQ(ierr); 1554d9407bcSMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 1564d9407bcSMatthew G. Knepley PetscInt gdof, goff; 1574d9407bcSMatthew G. Knepley 1584d9407bcSMatthew G. Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 1594d9407bcSMatthew G. Knepley if (gdof > 0) { 1604d9407bcSMatthew G. Knepley ierr = PetscSectionGetOffset(sectionGlobal, p, &goff);CHKERRQ(ierr); 1614d9407bcSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 1624d9407bcSMatthew G. Knepley PetscInt fdof, fcdof, fc, f2, poff = 0; 1634d9407bcSMatthew G. Knepley 1644d9407bcSMatthew G. Knepley /* Can get rid of this loop by storing field information in the global section */ 1654d9407bcSMatthew G. Knepley for (f2 = 0; f2 < fields[f]; ++f2) { 1664d9407bcSMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, p, f2, &fdof);CHKERRQ(ierr); 1674d9407bcSMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f2, &fcdof);CHKERRQ(ierr); 1684d9407bcSMatthew G. Knepley poff += fdof-fcdof; 1694d9407bcSMatthew G. Knepley } 1704d9407bcSMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, p, fields[f], &fdof);CHKERRQ(ierr); 1714d9407bcSMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, fields[f], &fcdof);CHKERRQ(ierr); 1724d9407bcSMatthew G. Knepley for (fc = 0; fc < fdof-fcdof; ++fc, ++subOff) { 1734d9407bcSMatthew G. Knepley subIndices[subOff] = goff+poff+fc; 1744d9407bcSMatthew G. Knepley } 1754d9407bcSMatthew G. Knepley } 1764d9407bcSMatthew G. Knepley } 1774d9407bcSMatthew G. Knepley } 1784d9407bcSMatthew G. Knepley ierr = ISCreateGeneral(PetscObjectComm((PetscObject)dm), subSize, subIndices, PETSC_OWN_POINTER, is);CHKERRQ(ierr); 179627349f5SMatthew G. Knepley if (bs > 1) { 180627349f5SMatthew G. Knepley /* We need to check that the block size does not come from non-contiguous fields */ 181627349f5SMatthew G. Knepley PetscInt i, j, set = 1; 182627349f5SMatthew G. Knepley for (i = 0; i < subSize; i += bs) { 183627349f5SMatthew G. Knepley for (j = 0; j < bs; ++j) { 184627349f5SMatthew G. Knepley if (subIndices[i+j] != subIndices[i]+j) {set = 0; break;} 185627349f5SMatthew G. Knepley } 186627349f5SMatthew G. Knepley } 187627349f5SMatthew G. Knepley if (set) {ierr = ISSetBlockSize(*is, bs);CHKERRQ(ierr);} 188627349f5SMatthew G. Knepley } 1894d9407bcSMatthew G. Knepley } 1904d9407bcSMatthew G. Knepley if (subdm) { 1914d9407bcSMatthew G. Knepley PetscSection subsection; 1924d9407bcSMatthew G. Knepley PetscBool haveNull = PETSC_FALSE; 1934d9407bcSMatthew G. Knepley PetscInt f, nf = 0; 1944d9407bcSMatthew G. Knepley 1954d9407bcSMatthew G. Knepley ierr = PetscSectionCreateSubsection(section, numFields, fields, &subsection);CHKERRQ(ierr); 196e87a4003SBarry Smith ierr = DMSetSection(*subdm, subsection);CHKERRQ(ierr); 1974d9407bcSMatthew G. Knepley ierr = PetscSectionDestroy(&subsection);CHKERRQ(ierr); 1984d9407bcSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 1994d9407bcSMatthew G. Knepley (*subdm)->nullspaceConstructors[f] = dm->nullspaceConstructors[fields[f]]; 2004d9407bcSMatthew G. Knepley if ((*subdm)->nullspaceConstructors[f]) { 2014d9407bcSMatthew G. Knepley haveNull = PETSC_TRUE; 2024d9407bcSMatthew G. Knepley nf = f; 2034d9407bcSMatthew G. Knepley } 2044d9407bcSMatthew G. Knepley } 205f646a522SMatthew G. Knepley if (haveNull && is) { 2064d9407bcSMatthew G. Knepley MatNullSpace nullSpace; 2074d9407bcSMatthew G. Knepley 2084d9407bcSMatthew G. Knepley ierr = (*(*subdm)->nullspaceConstructors[nf])(*subdm, nf, &nullSpace);CHKERRQ(ierr); 2094d9407bcSMatthew G. Knepley ierr = PetscObjectCompose((PetscObject) *is, "nullspace", (PetscObject) nullSpace);CHKERRQ(ierr); 2104d9407bcSMatthew G. Knepley ierr = MatNullSpaceDestroy(&nullSpace);CHKERRQ(ierr); 2114d9407bcSMatthew G. Knepley } 212e5e52638SMatthew G. Knepley if (dm->probs) { 2134d9407bcSMatthew G. Knepley ierr = DMSetNumFields(*subdm, numFields);CHKERRQ(ierr); 2144d9407bcSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 2150f21e855SMatthew G. Knepley PetscObject disc; 2160f21e855SMatthew G. Knepley 21744a7f3ddSMatthew G. Knepley ierr = DMGetField(dm, fields[f], NULL, &disc);CHKERRQ(ierr); 21844a7f3ddSMatthew G. Knepley ierr = DMSetField(*subdm, f, NULL, disc);CHKERRQ(ierr); 2194d9407bcSMatthew G. Knepley } 220e5e52638SMatthew G. Knepley ierr = DMCreateDS(*subdm);CHKERRQ(ierr); 221f646a522SMatthew G. Knepley if (numFields == 1 && is) { 2220f21e855SMatthew G. Knepley PetscObject disc, space, pmat; 2234d9407bcSMatthew G. Knepley 22444a7f3ddSMatthew G. Knepley ierr = DMGetField(*subdm, 0, NULL, &disc);CHKERRQ(ierr); 2250f21e855SMatthew G. Knepley ierr = PetscObjectQuery(disc, "nullspace", &space);CHKERRQ(ierr); 2260f21e855SMatthew G. Knepley if (space) {ierr = PetscObjectCompose((PetscObject) *is, "nullspace", space);CHKERRQ(ierr);} 2270f21e855SMatthew G. Knepley ierr = PetscObjectQuery(disc, "nearnullspace", &space);CHKERRQ(ierr); 2280f21e855SMatthew G. Knepley if (space) {ierr = PetscObjectCompose((PetscObject) *is, "nearnullspace", space);CHKERRQ(ierr);} 2290f21e855SMatthew G. Knepley ierr = PetscObjectQuery(disc, "pmat", &pmat);CHKERRQ(ierr); 2300f21e855SMatthew G. Knepley if (pmat) {ierr = PetscObjectCompose((PetscObject) *is, "pmat", pmat);CHKERRQ(ierr);} 2314d9407bcSMatthew G. Knepley } 232e5e52638SMatthew G. Knepley ierr = PetscDSCopyConstants(dm->probs[0].ds, (*subdm)->probs[0].ds);CHKERRQ(ierr); 233e5e52638SMatthew G. Knepley ierr = PetscDSCopyBoundary(dm->probs[0].ds, (*subdm)->probs[0].ds);CHKERRQ(ierr); 234e5e52638SMatthew G. Knepley ierr = PetscDSSelectEquations(dm->probs[0].ds, numFields, fields, (*subdm)->probs[0].ds);CHKERRQ(ierr); 235d5af271aSMatthew G. Knepley } 236d5af271aSMatthew G. Knepley if (dm->coarseMesh) { 237d5af271aSMatthew G. Knepley ierr = DMCreateSubDM(dm->coarseMesh, numFields, fields, NULL, &(*subdm)->coarseMesh);CHKERRQ(ierr); 2384d9407bcSMatthew G. Knepley } 2394d9407bcSMatthew G. Knepley } 2404d9407bcSMatthew G. Knepley PetscFunctionReturn(0); 2414d9407bcSMatthew G. Knepley } 2422adcc780SMatthew G. Knepley 243*792b654fSMatthew G. Knepley /*@C 244*792b654fSMatthew G. Knepley DMCreateSectionSuperDM - Returns an arrays of ISes and DM+Section encapsulating a superproblem defined by the DM+Sections passed in. 245*792b654fSMatthew G. Knepley 246*792b654fSMatthew G. Knepley Not collective 247*792b654fSMatthew G. Knepley 248*792b654fSMatthew G. Knepley Input Parameter: 249*792b654fSMatthew G. Knepley + dms - The DM objects 250*792b654fSMatthew G. Knepley - len - The number of DMs 251*792b654fSMatthew G. Knepley 252*792b654fSMatthew G. Knepley Output Parameters: 253*792b654fSMatthew G. Knepley + is - The global indices for the subproblem, or NULL 254*792b654fSMatthew G. Knepley - superdm - The DM for the superproblem, which must already have be cloned 255*792b654fSMatthew G. Knepley 256*792b654fSMatthew G. Knepley Note: This handles all information in the DM class and the PetscSection. This is used as the basis for creating subDMs in specialized classes, 257*792b654fSMatthew G. Knepley such as Plex and Forest. 258*792b654fSMatthew G. Knepley 259*792b654fSMatthew G. Knepley Level: intermediate 260*792b654fSMatthew G. Knepley 261*792b654fSMatthew G. Knepley .seealso DMCreateSuperDM(), DMGetSection(), DMPlexSetMigrationSF(), DMView() 262*792b654fSMatthew G. Knepley @*/ 263*792b654fSMatthew G. Knepley PetscErrorCode DMCreateSectionSuperDM(DM dms[], PetscInt len, IS **is, DM *superdm) 2642adcc780SMatthew G. Knepley { 2659796d432SMatthew G. Knepley MPI_Comm comm; 2669796d432SMatthew G. Knepley PetscSection supersection, *sections, *sectionGlobals; 2679796d432SMatthew G. Knepley PetscInt *Nfs, Nf = 0, f, supf, nullf = -1, i; 2689796d432SMatthew G. Knepley PetscBool haveNull = PETSC_FALSE; 2692adcc780SMatthew G. Knepley PetscErrorCode ierr; 2702adcc780SMatthew G. Knepley 2712adcc780SMatthew G. Knepley PetscFunctionBegin; 2729796d432SMatthew G. Knepley ierr = PetscObjectGetComm((PetscObject)dms[0], &comm);CHKERRQ(ierr); 2739796d432SMatthew G. Knepley /* Pull out local and global sections */ 2742adcc780SMatthew G. Knepley ierr = PetscMalloc3(len, &Nfs, len, §ions, len, §ionGlobals);CHKERRQ(ierr); 2752adcc780SMatthew G. Knepley for (i = 0 ; i < len; ++i) { 276e87a4003SBarry Smith ierr = DMGetSection(dms[i], §ions[i]);CHKERRQ(ierr); 277e87a4003SBarry Smith ierr = DMGetGlobalSection(dms[i], §ionGlobals[i]);CHKERRQ(ierr); 2789796d432SMatthew G. Knepley if (!sections[i]) SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Must set default section for DM before splitting fields"); 2799796d432SMatthew G. Knepley if (!sectionGlobals[i]) SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Must set default global section for DM before splitting fields"); 2802adcc780SMatthew G. Knepley ierr = PetscSectionGetNumFields(sections[i], &Nfs[i]);CHKERRQ(ierr); 2812adcc780SMatthew G. Knepley Nf += Nfs[i]; 2822adcc780SMatthew G. Knepley } 2839796d432SMatthew G. Knepley /* Create the supersection */ 2849796d432SMatthew G. Knepley ierr = PetscSectionCreateSupersection(sections, len, &supersection);CHKERRQ(ierr); 2853b16a644SMatthew G. Knepley ierr = DMSetSection(*superdm, supersection);CHKERRQ(ierr); 2869796d432SMatthew G. Knepley /* Create ISes */ 2872adcc780SMatthew G. Knepley if (is) { 2889796d432SMatthew G. Knepley PetscSection supersectionGlobal; 2899796d432SMatthew G. Knepley PetscInt bs = -1, startf = 0; 2902adcc780SMatthew G. Knepley 2912adcc780SMatthew G. Knepley ierr = PetscMalloc1(len, is);CHKERRQ(ierr); 2929796d432SMatthew G. Knepley ierr = DMGetDefaultGlobalSection(*superdm, &supersectionGlobal);CHKERRQ(ierr); 2939796d432SMatthew G. Knepley for (i = 0 ; i < len; startf += Nfs[i], ++i) { 2949796d432SMatthew G. Knepley PetscInt *subIndices; 295ec4c761aSMatthew G. Knepley PetscInt subSize, subOff, pStart, pEnd, p, start, end, dummy; 2962adcc780SMatthew G. Knepley 2972adcc780SMatthew G. Knepley ierr = PetscSectionGetChart(sectionGlobals[i], &pStart, &pEnd);CHKERRQ(ierr); 2982adcc780SMatthew G. Knepley ierr = PetscSectionGetConstrainedStorageSize(sectionGlobals[i], &subSize);CHKERRQ(ierr); 2992adcc780SMatthew G. Knepley ierr = PetscMalloc1(subSize, &subIndices);CHKERRQ(ierr); 3009796d432SMatthew G. Knepley for (p = pStart, subOff = 0; p < pEnd; ++p) { 3019796d432SMatthew G. Knepley PetscInt gdof, gcdof, gtdof, d; 3022adcc780SMatthew G. Knepley 3032adcc780SMatthew G. Knepley ierr = PetscSectionGetDof(sectionGlobals[i], p, &gdof);CHKERRQ(ierr); 3042adcc780SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(sections[i], p, &gcdof);CHKERRQ(ierr); 3052adcc780SMatthew G. Knepley gtdof = gdof - gcdof; 3062adcc780SMatthew G. Knepley if (gdof > 0 && gtdof) { 3072adcc780SMatthew G. Knepley if (bs < 0) {bs = gtdof;} 3082adcc780SMatthew G. Knepley else if (bs != gtdof) {bs = 1;} 309ec4c761aSMatthew G. Knepley ierr = DMGetGlobalFieldOffset_Private(*superdm, p, startf, &start, &dummy);CHKERRQ(ierr); 310ec4c761aSMatthew G. Knepley ierr = DMGetGlobalFieldOffset_Private(*superdm, p, startf+Nfs[i]-1, &dummy, &end);CHKERRQ(ierr); 3119796d432SMatthew G. Knepley if (end-start != gtdof) SETERRQ4(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Invalid number of global dofs %D != %D for dm %D on point %D", end-start, gtdof, i, p); 3129796d432SMatthew G. Knepley for (d = start; d < end; ++d, ++subOff) subIndices[subOff] = d; 3132adcc780SMatthew G. Knepley } 3142adcc780SMatthew G. Knepley } 3159796d432SMatthew G. Knepley ierr = ISCreateGeneral(comm, subSize, subIndices, PETSC_OWN_POINTER, &(*is)[i]);CHKERRQ(ierr); 3162adcc780SMatthew G. Knepley /* Must have same blocksize on all procs (some might have no points) */ 3179796d432SMatthew G. Knepley { 3189796d432SMatthew G. Knepley PetscInt bs = -1, bsLocal[2], bsMinMax[2]; 3199796d432SMatthew G. Knepley 3202adcc780SMatthew G. Knepley bsLocal[0] = bs < 0 ? PETSC_MAX_INT : bs; bsLocal[1] = bs; 3219796d432SMatthew G. Knepley ierr = PetscGlobalMinMaxInt(comm, bsLocal, bsMinMax);CHKERRQ(ierr); 3222adcc780SMatthew G. Knepley if (bsMinMax[0] != bsMinMax[1]) {bs = 1;} 3232adcc780SMatthew G. Knepley else {bs = bsMinMax[0];} 3242adcc780SMatthew G. Knepley ierr = ISSetBlockSize((*is)[i], bs);CHKERRQ(ierr); 3252adcc780SMatthew G. Knepley } 3262adcc780SMatthew G. Knepley } 3272adcc780SMatthew G. Knepley } 3289796d432SMatthew G. Knepley /* Preserve discretizations */ 329e5e52638SMatthew G. Knepley if (len && dms[0]->probs) { 3302adcc780SMatthew G. Knepley ierr = DMSetNumFields(*superdm, Nf);CHKERRQ(ierr); 3319796d432SMatthew G. Knepley for (i = 0, supf = 0; i < len; ++i) { 3329796d432SMatthew G. Knepley for (f = 0; f < Nfs[i]; ++f, ++supf) { 3332adcc780SMatthew G. Knepley PetscObject disc; 3342adcc780SMatthew G. Knepley 33544a7f3ddSMatthew G. Knepley ierr = DMGetField(dms[i], f, NULL, &disc);CHKERRQ(ierr); 33644a7f3ddSMatthew G. Knepley ierr = DMSetField(*superdm, supf, NULL, disc);CHKERRQ(ierr); 3372adcc780SMatthew G. Knepley } 3382adcc780SMatthew G. Knepley } 339e5e52638SMatthew G. Knepley ierr = DMCreateDS(*superdm);CHKERRQ(ierr); 3402adcc780SMatthew G. Knepley } 3419796d432SMatthew G. Knepley /* Preserve nullspaces */ 3429796d432SMatthew G. Knepley for (i = 0, supf = 0; i < len; ++i) { 3439796d432SMatthew G. Knepley for (f = 0; f < Nfs[i]; ++f, ++supf) { 3449796d432SMatthew G. Knepley (*superdm)->nullspaceConstructors[supf] = dms[i]->nullspaceConstructors[f]; 3459796d432SMatthew G. Knepley if ((*superdm)->nullspaceConstructors[supf]) { 3469796d432SMatthew G. Knepley haveNull = PETSC_TRUE; 3479796d432SMatthew G. Knepley nullf = supf; 3482adcc780SMatthew G. Knepley } 3499796d432SMatthew G. Knepley } 3509796d432SMatthew G. Knepley } 3519796d432SMatthew G. Knepley /* Attach nullspace to IS */ 3529796d432SMatthew G. Knepley if (haveNull && is) { 3539796d432SMatthew G. Knepley MatNullSpace nullSpace; 3549796d432SMatthew G. Knepley 3559796d432SMatthew G. Knepley ierr = (*(*superdm)->nullspaceConstructors[nullf])(*superdm, nullf, &nullSpace);CHKERRQ(ierr); 3569796d432SMatthew G. Knepley ierr = PetscObjectCompose((PetscObject) (*is)[nullf], "nullspace", (PetscObject) nullSpace);CHKERRQ(ierr); 3579796d432SMatthew G. Knepley ierr = MatNullSpaceDestroy(&nullSpace);CHKERRQ(ierr); 3589796d432SMatthew G. Knepley } 3599796d432SMatthew G. Knepley ierr = PetscSectionDestroy(&supersection);CHKERRQ(ierr); 36095b1d6b7SMatthew G. Knepley ierr = PetscFree3(Nfs, sections, sectionGlobals);CHKERRQ(ierr); 3612adcc780SMatthew G. Knepley PetscFunctionReturn(0); 3622adcc780SMatthew G. Knepley } 363