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; 1211689aebSJed Brown ierr = DMGetDefaultGlobalSection(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; 63fad22124SMatthew G Knepley ierr = DMGetDefaultSection(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 844d9407bcSMatthew G. Knepley /* This assumes that the DM has been cloned prior to the call */ 854d9407bcSMatthew G. Knepley PetscErrorCode DMCreateSubDM_Section_Private(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) 864d9407bcSMatthew G. Knepley { 874d9407bcSMatthew G. Knepley PetscSection section, sectionGlobal; 884d9407bcSMatthew G. Knepley PetscInt *subIndices; 894d9407bcSMatthew G. Knepley PetscInt subSize = 0, subOff = 0, nF, f, pStart, pEnd, p; 904d9407bcSMatthew G. Knepley PetscErrorCode ierr; 914d9407bcSMatthew G. Knepley 924d9407bcSMatthew G. Knepley PetscFunctionBegin; 934d9407bcSMatthew G. Knepley if (!numFields) PetscFunctionReturn(0); 944d9407bcSMatthew G. Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 954d9407bcSMatthew G. Knepley ierr = DMGetDefaultGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 964d9407bcSMatthew G. Knepley if (!section) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Must set default section for DM before splitting fields"); 974d9407bcSMatthew G. Knepley if (!sectionGlobal) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Must set default global section for DM before splitting fields"); 984d9407bcSMatthew G. Knepley ierr = PetscSectionGetNumFields(section, &nF);CHKERRQ(ierr); 994d9407bcSMatthew 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); 1004d9407bcSMatthew G. Knepley if (is) { 101b9eca265Ssarens PetscInt bs = -1, bsLocal, bsMax, bsMin; 1024d9407bcSMatthew G. Knepley ierr = PetscSectionGetChart(sectionGlobal, &pStart, &pEnd);CHKERRQ(ierr); 1034d9407bcSMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 104b9eca265Ssarens PetscInt gdof, pSubSize = 0; 1054d9407bcSMatthew G. Knepley 1064d9407bcSMatthew G. Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 1074d9407bcSMatthew G. Knepley if (gdof > 0) { 1084d9407bcSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 1094d9407bcSMatthew G. Knepley PetscInt fdof, fcdof; 1104d9407bcSMatthew G. Knepley 1114d9407bcSMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, p, fields[f], &fdof);CHKERRQ(ierr); 1124d9407bcSMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, fields[f], &fcdof);CHKERRQ(ierr); 113b9eca265Ssarens pSubSize += fdof-fcdof; 114b9eca265Ssarens } 115b9eca265Ssarens subSize += pSubSize; 116b9eca265Ssarens if (pSubSize) { 117b9eca265Ssarens if (bs < 0) { 118b9eca265Ssarens bs = pSubSize; 119b9eca265Ssarens } else if (bs != pSubSize) { 120b9eca265Ssarens /* Layout does not admit a pointwise block size */ 121b9eca265Ssarens bs = 1; 1224d9407bcSMatthew G. Knepley } 1234d9407bcSMatthew G. Knepley } 1244d9407bcSMatthew G. Knepley } 125b9eca265Ssarens } 126b9eca265Ssarens /* Must have same blocksize on all procs (some might have no points) */ 127b9eca265Ssarens bsLocal = bs; 128b9eca265Ssarens ierr = MPIU_Allreduce(&bsLocal, &bsMax, 1, MPIU_INT, MPI_MAX, PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 129b9eca265Ssarens bsLocal = bs < 0 ? bsMax : bs; 130b9eca265Ssarens ierr = MPIU_Allreduce(&bsLocal, &bsMin, 1, MPIU_INT, MPI_MIN, PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 131b9eca265Ssarens if (bsMin != bsMax) { 132b9eca265Ssarens bs = 1; 133b9eca265Ssarens } else { 134b9eca265Ssarens bs = bsMax; 135b9eca265Ssarens } 136785e854fSJed Brown ierr = PetscMalloc1(subSize, &subIndices);CHKERRQ(ierr); 1374d9407bcSMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 1384d9407bcSMatthew G. Knepley PetscInt gdof, goff; 1394d9407bcSMatthew G. Knepley 1404d9407bcSMatthew G. Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 1414d9407bcSMatthew G. Knepley if (gdof > 0) { 1424d9407bcSMatthew G. Knepley ierr = PetscSectionGetOffset(sectionGlobal, p, &goff);CHKERRQ(ierr); 1434d9407bcSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 1444d9407bcSMatthew G. Knepley PetscInt fdof, fcdof, fc, f2, poff = 0; 1454d9407bcSMatthew G. Knepley 1464d9407bcSMatthew G. Knepley /* Can get rid of this loop by storing field information in the global section */ 1474d9407bcSMatthew G. Knepley for (f2 = 0; f2 < fields[f]; ++f2) { 1484d9407bcSMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, p, f2, &fdof);CHKERRQ(ierr); 1494d9407bcSMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f2, &fcdof);CHKERRQ(ierr); 1504d9407bcSMatthew G. Knepley poff += fdof-fcdof; 1514d9407bcSMatthew G. Knepley } 1524d9407bcSMatthew G. Knepley ierr = PetscSectionGetFieldDof(section, p, fields[f], &fdof);CHKERRQ(ierr); 1534d9407bcSMatthew G. Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, fields[f], &fcdof);CHKERRQ(ierr); 1544d9407bcSMatthew G. Knepley for (fc = 0; fc < fdof-fcdof; ++fc, ++subOff) { 1554d9407bcSMatthew G. Knepley subIndices[subOff] = goff+poff+fc; 1564d9407bcSMatthew G. Knepley } 1574d9407bcSMatthew G. Knepley } 1584d9407bcSMatthew G. Knepley } 1594d9407bcSMatthew G. Knepley } 1604d9407bcSMatthew G. Knepley ierr = ISCreateGeneral(PetscObjectComm((PetscObject)dm), subSize, subIndices, PETSC_OWN_POINTER, is);CHKERRQ(ierr); 161b9eca265Ssarens ierr = ISSetBlockSize(*is, bs);CHKERRQ(ierr); 1624d9407bcSMatthew G. Knepley } 1634d9407bcSMatthew G. Knepley if (subdm) { 1644d9407bcSMatthew G. Knepley PetscSection subsection; 1654d9407bcSMatthew G. Knepley PetscBool haveNull = PETSC_FALSE; 1664d9407bcSMatthew G. Knepley PetscInt f, nf = 0; 1674d9407bcSMatthew G. Knepley 1684d9407bcSMatthew G. Knepley ierr = PetscSectionCreateSubsection(section, numFields, fields, &subsection);CHKERRQ(ierr); 1694d9407bcSMatthew G. Knepley ierr = DMSetDefaultSection(*subdm, subsection);CHKERRQ(ierr); 1704d9407bcSMatthew G. Knepley ierr = PetscSectionDestroy(&subsection);CHKERRQ(ierr); 1714d9407bcSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 1724d9407bcSMatthew G. Knepley (*subdm)->nullspaceConstructors[f] = dm->nullspaceConstructors[fields[f]]; 1734d9407bcSMatthew G. Knepley if ((*subdm)->nullspaceConstructors[f]) { 1744d9407bcSMatthew G. Knepley haveNull = PETSC_TRUE; 1754d9407bcSMatthew G. Knepley nf = f; 1764d9407bcSMatthew G. Knepley } 1774d9407bcSMatthew G. Knepley } 178f646a522SMatthew G. Knepley if (haveNull && is) { 1794d9407bcSMatthew G. Knepley MatNullSpace nullSpace; 1804d9407bcSMatthew G. Knepley 1814d9407bcSMatthew G. Knepley ierr = (*(*subdm)->nullspaceConstructors[nf])(*subdm, nf, &nullSpace);CHKERRQ(ierr); 1824d9407bcSMatthew G. Knepley ierr = PetscObjectCompose((PetscObject) *is, "nullspace", (PetscObject) nullSpace);CHKERRQ(ierr); 1834d9407bcSMatthew G. Knepley ierr = MatNullSpaceDestroy(&nullSpace);CHKERRQ(ierr); 1844d9407bcSMatthew G. Knepley } 1850f21e855SMatthew G. Knepley if (dm->prob) { 1860f21e855SMatthew G. Knepley PetscInt Nf; 1870f21e855SMatthew G. Knepley 1882764a2aaSMatthew G. Knepley ierr = PetscDSGetNumFields(dm->prob, &Nf);CHKERRQ(ierr); 1890f21e855SMatthew G. Knepley if (nF != Nf) SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "The number of DM fields %d does not match the number of Section fields %d", Nf, nF); 1904d9407bcSMatthew G. Knepley ierr = DMSetNumFields(*subdm, numFields);CHKERRQ(ierr); 1914d9407bcSMatthew G. Knepley for (f = 0; f < numFields; ++f) { 1920f21e855SMatthew G. Knepley PetscObject disc; 1930f21e855SMatthew G. Knepley 1940f21e855SMatthew G. Knepley ierr = DMGetField(dm, fields[f], &disc);CHKERRQ(ierr); 1950f21e855SMatthew G. Knepley ierr = DMSetField(*subdm, f, disc);CHKERRQ(ierr); 1964d9407bcSMatthew G. Knepley } 197f646a522SMatthew G. Knepley if (numFields == 1 && is) { 1980f21e855SMatthew G. Knepley PetscObject disc, space, pmat; 1994d9407bcSMatthew G. Knepley 2000f21e855SMatthew G. Knepley ierr = DMGetField(*subdm, 0, &disc);CHKERRQ(ierr); 2010f21e855SMatthew G. Knepley ierr = PetscObjectQuery(disc, "nullspace", &space);CHKERRQ(ierr); 2020f21e855SMatthew G. Knepley if (space) {ierr = PetscObjectCompose((PetscObject) *is, "nullspace", space);CHKERRQ(ierr);} 2030f21e855SMatthew G. Knepley ierr = PetscObjectQuery(disc, "nearnullspace", &space);CHKERRQ(ierr); 2040f21e855SMatthew G. Knepley if (space) {ierr = PetscObjectCompose((PetscObject) *is, "nearnullspace", space);CHKERRQ(ierr);} 2050f21e855SMatthew G. Knepley ierr = PetscObjectQuery(disc, "pmat", &pmat);CHKERRQ(ierr); 2060f21e855SMatthew G. Knepley if (pmat) {ierr = PetscObjectCompose((PetscObject) *is, "pmat", pmat);CHKERRQ(ierr);} 2074d9407bcSMatthew G. Knepley } 2084d9407bcSMatthew G. Knepley } 2094d9407bcSMatthew G. Knepley } 2108333ec13SMatthew G. Knepley #if 0 2118333ec13SMatthew G. Knepley /* We need a way to filter the original SF for given fields: 2128333ec13SMatthew G. Knepley - Keeping the original section around it too much I think 2138333ec13SMatthew G. Knepley - We could keep the distributed section, and subset it 2148333ec13SMatthew G. Knepley */ 2158333ec13SMatthew G. Knepley if (dm->sfNatural) { 2168333ec13SMatthew G. Knepley PetscSF sfNatural; 2178333ec13SMatthew G. Knepley 2188333ec13SMatthew G. Knepley ierr = PetscSectionCreateSubsection(dm->originalSection, numFields, fields, &(*subdm)->originalSection);CHKERRQ(ierr); 2198333ec13SMatthew G. Knepley ierr = DMPlexCreateGlobalToNaturalPetscSF(*subdm, &sfNatural);CHKERRQ(ierr); 2208333ec13SMatthew G. Knepley ierr = DMPlexSetGlobalToNaturalPetscSF(*subdm, sfNatural);CHKERRQ(ierr); 2218333ec13SMatthew G. Knepley } 2228333ec13SMatthew G. Knepley #endif 2234d9407bcSMatthew G. Knepley PetscFunctionReturn(0); 2244d9407bcSMatthew G. Knepley } 225*2adcc780SMatthew G. Knepley 226*2adcc780SMatthew G. Knepley /* This assumes that the DM has been cloned prior to the call */ 227*2adcc780SMatthew G. Knepley PetscErrorCode DMCreateSuperDM_Section_Private(DM dms[], PetscInt len, IS **is, DM *superdm) 228*2adcc780SMatthew G. Knepley { 229*2adcc780SMatthew G. Knepley PetscSection *sections, *sectionGlobals; 230*2adcc780SMatthew G. Knepley PetscInt *Nfs, Nf = 0, *subIndices, i; 231*2adcc780SMatthew G. Knepley PetscErrorCode ierr; 232*2adcc780SMatthew G. Knepley 233*2adcc780SMatthew G. Knepley PetscFunctionBegin; 234*2adcc780SMatthew G. Knepley ierr = PetscMalloc3(len, &Nfs, len, §ions, len, §ionGlobals);CHKERRQ(ierr); 235*2adcc780SMatthew G. Knepley for (i = 0 ; i < len; ++i) { 236*2adcc780SMatthew G. Knepley ierr = DMGetDefaultSection(dms[i], §ions[i]);CHKERRQ(ierr); 237*2adcc780SMatthew G. Knepley ierr = DMGetDefaultGlobalSection(dms[i], §ionGlobals[i]);CHKERRQ(ierr); 238*2adcc780SMatthew G. Knepley if (!sections[i]) SETERRQ(PetscObjectComm((PetscObject)dms[0]), PETSC_ERR_ARG_WRONG, "Must set default section for DM before splitting fields"); 239*2adcc780SMatthew G. Knepley if (!sectionGlobals[i]) SETERRQ(PetscObjectComm((PetscObject)dms[0]), PETSC_ERR_ARG_WRONG, "Must set default global section for DM before splitting fields"); 240*2adcc780SMatthew G. Knepley ierr = PetscSectionGetNumFields(sections[i], &Nfs[i]);CHKERRQ(ierr); 241*2adcc780SMatthew G. Knepley Nf += Nfs[i]; 242*2adcc780SMatthew G. Knepley ierr = PetscSectionView(sectionGlobals[i], PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); 243*2adcc780SMatthew G. Knepley } 244*2adcc780SMatthew G. Knepley if (is) { 245*2adcc780SMatthew G. Knepley PetscInt *offs, *globalOffs, iOff = 0; 246*2adcc780SMatthew G. Knepley 247*2adcc780SMatthew G. Knepley ierr = PetscMalloc1(len, is);CHKERRQ(ierr); 248*2adcc780SMatthew G. Knepley ierr = PetscCalloc2(len+1, &offs, len+1, &globalOffs);CHKERRQ(ierr); 249*2adcc780SMatthew G. Knepley for (i = 0 ; i < len; ++i) { 250*2adcc780SMatthew G. Knepley ierr = PetscSectionGetConstrainedStorageSize(sectionGlobals[i], &offs[i]);CHKERRQ(ierr); 251*2adcc780SMatthew G. Knepley offs[len] += offs[i]; 252*2adcc780SMatthew G. Knepley } 253*2adcc780SMatthew G. Knepley ierr = MPI_Scan(offs, globalOffs, len+1, MPIU_INT, MPI_SUM, PetscObjectComm((PetscObject) dms[0]));CHKERRQ(ierr); 254*2adcc780SMatthew G. Knepley for (i = 0 ; i <= len; ++i) globalOffs[i] -= offs[i]; 255*2adcc780SMatthew G. Knepley for (i = 0 ; i < len; ++i, iOff += offs[i-1]) { 256*2adcc780SMatthew G. Knepley PetscInt bs = -1, bsLocal[2], bsMinMax[2]; 257*2adcc780SMatthew G. Knepley PetscInt subSize = 0, subOff = 0, gtoff = globalOffs[len] - globalOffs[i], pStart, pEnd, p; 258*2adcc780SMatthew G. Knepley 259*2adcc780SMatthew G. Knepley ierr = PetscSectionGetChart(sectionGlobals[i], &pStart, &pEnd);CHKERRQ(ierr); 260*2adcc780SMatthew G. Knepley ierr = PetscSectionGetConstrainedStorageSize(sectionGlobals[i], &subSize);CHKERRQ(ierr); 261*2adcc780SMatthew G. Knepley ierr = PetscMalloc1(subSize, &subIndices);CHKERRQ(ierr); 262*2adcc780SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 263*2adcc780SMatthew G. Knepley PetscInt gdof, gcdof, gtdof, goff, d; 264*2adcc780SMatthew G. Knepley 265*2adcc780SMatthew G. Knepley ierr = PetscSectionGetDof(sectionGlobals[i], p, &gdof);CHKERRQ(ierr); 266*2adcc780SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(sections[i], p, &gcdof);CHKERRQ(ierr); 267*2adcc780SMatthew G. Knepley gtdof = gdof-gcdof; 268*2adcc780SMatthew G. Knepley if (gdof > 0 && gtdof) { 269*2adcc780SMatthew G. Knepley if (bs < 0) {bs = gtdof;} 270*2adcc780SMatthew G. Knepley else if (bs != gtdof) {bs = 1;} 271*2adcc780SMatthew G. Knepley ierr = PetscSectionGetOffset(sectionGlobals[i], p, &goff);CHKERRQ(ierr); 272*2adcc780SMatthew G. Knepley for (d = 0; d < gtdof; ++d, ++subOff) { 273*2adcc780SMatthew G. Knepley subIndices[subOff] = goff+gtoff+d+iOff; 274*2adcc780SMatthew G. Knepley } 275*2adcc780SMatthew G. Knepley } 276*2adcc780SMatthew G. Knepley } 277*2adcc780SMatthew G. Knepley ierr = ISCreateGeneral(PetscObjectComm((PetscObject) dms[0]), subSize, subIndices, PETSC_OWN_POINTER, &(*is)[i]);CHKERRQ(ierr); 278*2adcc780SMatthew G. Knepley /* Must have same blocksize on all procs (some might have no points) */ 279*2adcc780SMatthew G. Knepley bsLocal[0] = bs < 0 ? PETSC_MAX_INT : bs; bsLocal[1] = bs; 280*2adcc780SMatthew G. Knepley ierr = PetscGlobalMinMaxInt(PetscObjectComm((PetscObject) dms[0]), bsLocal, bsMinMax);CHKERRQ(ierr); 281*2adcc780SMatthew G. Knepley if (bsMinMax[0] != bsMinMax[1]) {bs = 1;} 282*2adcc780SMatthew G. Knepley else {bs = bsMinMax[0];} 283*2adcc780SMatthew G. Knepley ierr = ISSetBlockSize((*is)[i], bs);CHKERRQ(ierr); 284*2adcc780SMatthew G. Knepley } 285*2adcc780SMatthew G. Knepley } 286*2adcc780SMatthew G. Knepley if (superdm) { 287*2adcc780SMatthew G. Knepley PetscSection supersection; 288*2adcc780SMatthew G. Knepley PetscBool haveNull = PETSC_FALSE; 289*2adcc780SMatthew G. Knepley PetscInt field, f, nf = 0; 290*2adcc780SMatthew G. Knepley 291*2adcc780SMatthew G. Knepley ierr = PetscSectionCreateSupersection(sections, len, &supersection);CHKERRQ(ierr); 292*2adcc780SMatthew G. Knepley ierr = DMSetDefaultSection(*superdm, supersection);CHKERRQ(ierr); 293*2adcc780SMatthew G. Knepley ierr = PetscSectionDestroy(&supersection);CHKERRQ(ierr); 294*2adcc780SMatthew G. Knepley for (i = 0, field = 0; i < len; ++i) { 295*2adcc780SMatthew G. Knepley for (f = 0; f < Nfs[i]; ++f, ++field) { 296*2adcc780SMatthew G. Knepley (*superdm)->nullspaceConstructors[field] = dms[i]->nullspaceConstructors[f]; 297*2adcc780SMatthew G. Knepley if ((*superdm)->nullspaceConstructors[field]) { 298*2adcc780SMatthew G. Knepley haveNull = PETSC_TRUE; 299*2adcc780SMatthew G. Knepley nf = field; 300*2adcc780SMatthew G. Knepley } 301*2adcc780SMatthew G. Knepley } 302*2adcc780SMatthew G. Knepley } 303*2adcc780SMatthew G. Knepley if (haveNull && is) { 304*2adcc780SMatthew G. Knepley MatNullSpace nullSpace; 305*2adcc780SMatthew G. Knepley 306*2adcc780SMatthew G. Knepley ierr = (*(*superdm)->nullspaceConstructors[nf])(*superdm, nf, &nullSpace);CHKERRQ(ierr); 307*2adcc780SMatthew G. Knepley ierr = PetscObjectCompose((PetscObject) (*is)[nf], "nullspace", (PetscObject) nullSpace);CHKERRQ(ierr); 308*2adcc780SMatthew G. Knepley ierr = MatNullSpaceDestroy(&nullSpace);CHKERRQ(ierr); 309*2adcc780SMatthew G. Knepley } 310*2adcc780SMatthew G. Knepley if (len && dms[0]->prob) { 311*2adcc780SMatthew G. Knepley ierr = DMSetNumFields(*superdm, Nf);CHKERRQ(ierr); 312*2adcc780SMatthew G. Knepley for (i = 0, field = 0; i < len; ++i) { 313*2adcc780SMatthew G. Knepley for (f = 0; f < Nfs[i]; ++f, ++field) { 314*2adcc780SMatthew G. Knepley PetscObject disc; 315*2adcc780SMatthew G. Knepley 316*2adcc780SMatthew G. Knepley ierr = DMGetField(dms[i], f, &disc);CHKERRQ(ierr); 317*2adcc780SMatthew G. Knepley ierr = DMSetField(*superdm, field, disc);CHKERRQ(ierr); 318*2adcc780SMatthew G. Knepley } 319*2adcc780SMatthew G. Knepley } 320*2adcc780SMatthew G. Knepley } 321*2adcc780SMatthew G. Knepley } 322*2adcc780SMatthew G. Knepley #if 0 323*2adcc780SMatthew G. Knepley /* We need a way to filter the original SF for given fields: 324*2adcc780SMatthew G. Knepley - Keeping the original section around is too much I think 325*2adcc780SMatthew G. Knepley - We could keep the distributed section, and subset it 326*2adcc780SMatthew G. Knepley */ 327*2adcc780SMatthew G. Knepley if (len && dms[0]->sfNatural) { 328*2adcc780SMatthew G. Knepley PetscSF sfNatural; 329*2adcc780SMatthew G. Knepley 330*2adcc780SMatthew G. Knepley ierr = PetscSectionCreateSupersection(originalSections, len, &(*superdm)->originalSection);CHKERRQ(ierr); 331*2adcc780SMatthew G. Knepley ierr = DMPlexCreateGlobalToNaturalPetscSF(*superdm, &sfNatural);CHKERRQ(ierr); 332*2adcc780SMatthew G. Knepley ierr = DMPlexSetGlobalToNaturalPetscSF(*superdm, sfNatural);CHKERRQ(ierr); 333*2adcc780SMatthew G. Knepley } 334*2adcc780SMatthew G. Knepley #endif 335*2adcc780SMatthew G. Knepley PetscFunctionReturn(0); 336*2adcc780SMatthew G. Knepley } 337