static PetscErrorCode CreateHex_3D(MPI_Comm comm, DM *newdm) { DM dm; PetscInt numPoints[2] = {12, 2}; PetscInt coneSize[14] = {8, 8, 0,0,0,0,0,0,0,0,0,0,0,0}; PetscInt cones[16] = {2,5,4,3,6,7,8,9, 3,4,11,10,7,12,13,8}; PetscInt coneOrientations[16] = {0,0,0,0,0,0,0,0, 0,0, 0, 0,0, 0, 0,0}; PetscScalar vertexCoords[36] = {-0.5,0.0,0.0, 0.0,0.0,0.0, 0.0,1.0,0.0, -0.5,1.0,0.0, -0.5,0.0,1.0, 0.0,0.0,1.0, 0.0,1.0,1.0, -0.5,1.0,1.0, 0.5,0.0,0.0, 0.5,1.0,0.0, 0.5,0.0,1.0, 0.5,1.0,1.0}; PetscInt markerPoints[24] = {2,1,3,1,4,1,5,1,6,1,7,1,8,1,9,1,10,1,11,1,12,1,13,1}; PetscInt dim = 3, depth = 1, p; PetscErrorCode ierr; PetscFunctionBegin; ierr = DMCreate(comm, &dm);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) dm, "hexahedral");CHKERRQ(ierr); ierr = DMSetType(dm, DMPLEX);CHKERRQ(ierr); ierr = DMSetDimension(dm, dim);CHKERRQ(ierr); ierr = DMPlexCreateFromDAG(dm, depth, numPoints, coneSize, cones, coneOrientations, vertexCoords);CHKERRQ(ierr); for(p = 0; p < 12; ++p) { ierr = DMSetLabelValue(dm, "marker", markerPoints[p*2], markerPoints[p*2+1]);CHKERRQ(ierr); } *newdm = dm; PetscFunctionReturn(0); }
int main(int argc, char **argv) { DM dm; char typeString[256] = {'\0'}; PetscViewer viewer = NULL; PetscBool flg; PetscErrorCode ierr; ierr = PetscInitialize(&argc, &argv, NULL,help);if (ierr) return ierr; ierr = DMCreate(PETSC_COMM_WORLD, &dm);CHKERRQ(ierr); ierr = PetscStrncpy(typeString,DMFOREST,256);CHKERRQ(ierr); ierr = PetscOptionsBegin(PETSC_COMM_WORLD,NULL,"DM Forest example options",NULL);CHKERRQ(ierr); ierr = PetscOptionsString("-dm_type","The type of the dm",NULL,DMFOREST,typeString,sizeof(typeString),NULL);CHKERRQ(ierr); ierr = PetscOptionsEnd();CHKERRQ(ierr); ierr = DMSetType(dm,(DMType) typeString);CHKERRQ(ierr); ierr = DMSetFromOptions(dm);CHKERRQ(ierr); ierr = DMSetUp(dm);CHKERRQ(ierr); ierr = PetscOptionsGetViewer(PETSC_COMM_WORLD,NULL,"-dm_view",&viewer,NULL,&flg);CHKERRQ(ierr); if (flg) { ierr = DMView(dm,viewer);CHKERRQ(ierr); } ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); ierr = DMDestroy(&dm);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; }
EXTERN_C_END #undef __FUNCT__ #define __FUNCT__ "DMMeshCreate" /*@ DMMeshCreate - Creates a DMMesh object. Collective on MPI_Comm Input Parameter: . comm - The communicator for the DMMesh object Output Parameter: . mesh - The DMMesh object Level: beginner .keywords: DMMesh, create @*/ PetscErrorCode DMMeshCreate(MPI_Comm comm, DM *mesh) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(mesh,2); ierr = DMCreate(comm, mesh);CHKERRQ(ierr); ierr = DMSetType(*mesh, DMMESH);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode DMPatchCreateGrid(MPI_Comm comm, PetscInt dim, MatStencil patchSize, MatStencil commSize, MatStencil gridSize, DM *dm) { DM_Patch *mesh; DM da; PetscInt dof = 1, width = 1; PetscErrorCode ierr; PetscFunctionBegin; ierr = DMPatchCreate(comm, dm);CHKERRQ(ierr); mesh = (DM_Patch*) (*dm)->data; if (dim < 2) { gridSize.j = 1; patchSize.j = 1; } if (dim < 3) { gridSize.k = 1; patchSize.k = 1; } ierr = DMCreate(comm, &da);CHKERRQ(ierr); ierr = DMSetType(da, DMDA);CHKERRQ(ierr); ierr = DMSetDimension(da, dim);CHKERRQ(ierr); ierr = DMDASetSizes(da, gridSize.i, gridSize.j, gridSize.k);CHKERRQ(ierr); ierr = DMDASetBoundaryType(da, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE);CHKERRQ(ierr); ierr = DMDASetDof(da, dof);CHKERRQ(ierr); ierr = DMDASetStencilType(da, DMDA_STENCIL_BOX);CHKERRQ(ierr); ierr = DMDASetStencilWidth(da, width);CHKERRQ(ierr); mesh->dmCoarse = da; ierr = DMPatchSetPatchSize(*dm, patchSize);CHKERRQ(ierr); ierr = DMPatchSetCommSize(*dm, commSize);CHKERRQ(ierr); PetscFunctionReturn(0); }
int main(int argc,char **argv) { PetscErrorCode ierr; PetscInt M = PETSC_DECIDE,N = PETSC_DECIDE; DM da; Vec global; PetscViewer bviewer; ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr; ierr = PetscOptionsGetInt(NULL,NULL,"-M",&M,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,NULL,"-N",&N,NULL);CHKERRQ(ierr); ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"daoutput",FILE_MODE_READ,&bviewer);CHKERRQ(ierr); ierr = DMCreate(PETSC_COMM_WORLD,&da);CHKERRQ(ierr); ierr = DMLoad(da,bviewer);CHKERRQ(ierr); ierr = DMCreateGlobalVector(da,&global);CHKERRQ(ierr); ierr = VecLoad(global,bviewer);CHKERRQ(ierr); ierr = PetscViewerDestroy(&bviewer);CHKERRQ(ierr); ierr = VecView(global,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr); /* Free memory */ ierr = VecDestroy(&global);CHKERRQ(ierr); ierr = DMDestroy(&da);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; }
EXTERN_C_END #undef __FUNCT__ #define __FUNCT__ "DMComplexCreate" /*@ DMComplexCreate - Creates a DMComplex object, which encapsulates an unstructured mesh, or CW complex, which can be expressed using a Hasse Diagram. Collective on MPI_Comm Input Parameter: . comm - The communicator for the DMComplex object Output Parameter: . mesh - The DMComplex object Level: beginner .keywords: DMComplex, create @*/ PetscErrorCode DMComplexCreate(MPI_Comm comm, DM *mesh) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(mesh,2); ierr = DMCreate(comm, mesh);CHKERRQ(ierr); ierr = DMSetType(*mesh, DMCOMPLEX);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode DMPlexCreateHexBoxMesh(MPI_Comm comm, PetscInt dim, const PetscInt cells[], DM *dm) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(dm, 4); ierr = DMCreate(comm, dm);CHKERRQ(ierr); PetscValidLogicalCollectiveInt(*dm,dim,2); ierr = DMSetType(*dm, DMPLEX);CHKERRQ(ierr); ierr = DMPlexSetDimension(*dm, dim);CHKERRQ(ierr); switch (dim) { case 2: { PetscReal lower[2] = {0.0, 0.0}; PetscReal upper[2] = {1.0, 1.0}; ierr = DMPlexCreateSquareMesh(*dm, lower, upper, cells);CHKERRQ(ierr); break; } #if 0 case 3: { PetscReal lower[3] = {0.0, 0.0, 0.0}; PetscReal upper[3] = {1.0, 1.0, 1.0}; ierr = DMPlexCreateCubeMesh(boundary, lower, upper, cells);CHKERRQ(ierr); break; } #endif default: SETERRQ1(comm, PETSC_ERR_SUP, "Dimension not supported: %d", dim); } PetscFunctionReturn(0); }
/*@ DMPlexClone - Creates a DMPlex object with the same mesh as the original. Collective on MPI_Comm Input Parameter: . dm - The original DMPlex object Output Parameter: . newdm - The new DMPlex object Level: beginner .keywords: DMPlex, create @*/ PetscErrorCode DMPlexClone(DM dm, DM *newdm) { DM_Plex *mesh; Vec coords; void *ctx; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(dm, DM_CLASSID, 1); PetscValidPointer(newdm,2); ierr = DMCreate(PetscObjectComm((PetscObject)dm), newdm);CHKERRQ(ierr); ierr = PetscSFDestroy(&(*newdm)->sf);CHKERRQ(ierr); ierr = PetscObjectReference((PetscObject) dm->sf);CHKERRQ(ierr); (*newdm)->sf = dm->sf; mesh = (DM_Plex*) dm->data; mesh->refct++; (*newdm)->data = mesh; ierr = PetscObjectChangeTypeName((PetscObject) *newdm, DMPLEX);CHKERRQ(ierr); ierr = DMInitialize_Plex(*newdm);CHKERRQ(ierr); ierr = DMGetApplicationContext(dm, &ctx);CHKERRQ(ierr); ierr = DMSetApplicationContext(*newdm, ctx);CHKERRQ(ierr); ierr = DMGetCoordinatesLocal(dm, &coords);CHKERRQ(ierr); if (coords) { ierr = DMSetCoordinatesLocal(*newdm, coords);CHKERRQ(ierr); } else { ierr = DMGetCoordinates(dm, &coords);CHKERRQ(ierr); if (coords) {ierr = DMSetCoordinates(*newdm, coords);CHKERRQ(ierr);} } PetscFunctionReturn(0); }
/*@ DMPlexInterpolate - Take in a cell-vertex mesh and return one with all intermediate faces, edges, etc. Collective on DM Input Parameter: . dm - The DMPlex object with only cells and vertices Output Parameter: . dmInt - The complete DMPlex object Level: intermediate .keywords: mesh .seealso: DMPlexUninterpolate(), DMPlexCreateFromCellList() @*/ PetscErrorCode DMPlexInterpolate(DM dm, DM *dmInt) { DM idm, odm = dm; PetscInt depth, dim, d; PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscLogEventBegin(DMPLEX_Interpolate,dm,0,0,0);CHKERRQ(ierr); ierr = DMPlexGetDepth(dm, &depth);CHKERRQ(ierr); ierr = DMPlexGetDimension(dm, &dim);CHKERRQ(ierr); if (dim <= 1) { ierr = PetscObjectReference((PetscObject) dm);CHKERRQ(ierr); idm = dm; } for (d = 1; d < dim; ++d) { /* Create interpolated mesh */ ierr = DMCreate(PetscObjectComm((PetscObject)dm), &idm);CHKERRQ(ierr); ierr = DMSetType(idm, DMPLEX);CHKERRQ(ierr); ierr = DMPlexSetDimension(idm, dim);CHKERRQ(ierr); if (depth > 0) {ierr = DMPlexInterpolateFaces_Internal(odm, 1, idm);CHKERRQ(ierr);} if (odm != dm) {ierr = DMDestroy(&odm);CHKERRQ(ierr);} odm = idm; } *dmInt = idm; ierr = PetscLogEventEnd(DMPLEX_Interpolate,dm,0,0,0);CHKERRQ(ierr); PetscFunctionReturn(0); }
int main(int argc, char **argv) { PetscErrorCode ierr; DM dm, rdm; PetscViewer vwr; PetscBool flg; char datafile[PETSC_MAX_PATH_LEN]; MPI_Comm comm; ierr = PetscInitialize(&argc, &argv, NULL, help); if (ierr) return ierr; comm = PETSC_COMM_WORLD; ierr = PetscViewerCreate(comm, &vwr);CHKERRQ(ierr); ierr = PetscViewerSetType(vwr, PETSCVIEWERHDF5);CHKERRQ(ierr); ierr = PetscViewerFileSetMode(vwr, FILE_MODE_READ);CHKERRQ(ierr); ierr = PetscOptionsGetString(NULL, NULL, "-f", datafile, PETSC_MAX_PATH_LEN, &flg);CHKERRQ(ierr); if (!flg) SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Must provide meshfile"); ierr = PetscViewerFileSetName(vwr, datafile);CHKERRQ(ierr); ierr = DMCreate(comm, &dm);CHKERRQ(ierr); ierr = DMSetType(dm, DMPLEX);CHKERRQ(ierr); ierr = DMLoad(dm, vwr);CHKERRQ(ierr); ierr = PetscViewerDestroy(&vwr);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject)dm, "BaryDM");CHKERRQ(ierr); ierr = DMViewFromOptions(dm, NULL, "-dm_view");CHKERRQ(ierr); ierr = DMPlexSetRefinementUniform(dm, PETSC_TRUE);CHKERRQ(ierr); ierr = DMRefine(dm, comm, &rdm);CHKERRQ(ierr); ierr = DMDestroy(&dm);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject)rdm, "RefinedDM");CHKERRQ(ierr); ierr = DMViewFromOptions(rdm, NULL, "-refined_dm_view");CHKERRQ(ierr); ierr = DMDestroy(&rdm);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; }
EXTERN_C_END #undef __FUNCT__ #define __FUNCT__ "DMCompositeCreate" /*@C DMCompositeCreate - Creates a vector packer, used to generate "composite" vectors made up of several subvectors. Collective on MPI_Comm Input Parameter: . comm - the processors that will share the global vector Output Parameters: . packer - the packer object Level: advanced .seealso DMDestroy(), DMCompositeAddDM(), DMCompositeScatter(), DMCompositeGather(), DMCreateGlobalVector(), DMCompositeGetISLocalToGlobalMappings(), DMCompositeGetAccess() DMCompositeGetLocalVectors(), DMCompositeRestoreLocalVectors(), DMCompositeGetEntries() @*/ PetscErrorCode DMCompositeCreate(MPI_Comm comm,DM *packer) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(packer,2); ierr = DMCreate(comm,packer);CHKERRQ(ierr); ierr = DMSetType(*packer,DMCOMPOSITE);CHKERRQ(ierr); PetscFunctionReturn(0); }
EXTERN_C_END #undef __FUNCT__ #define __FUNCT__ "DMDACreate" /*@ DMDACreate - Creates a DMDA object. Collective on MPI_Comm Input Parameter: . comm - The communicator for the DMDA object Output Parameter: . da - The DMDA object Level: advanced Developers Note: Since there exists DMDACreate1/2/3d() should this routine even exist? .keywords: DMDA, create .seealso: DMDASetSizes(), DMDADuplicate(), DMDACreate1d(), DMDACreate2d(), DMDACreate3d() @*/ PetscErrorCode DMDACreate(MPI_Comm comm, DM *da) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(da,2); ierr = DMCreate(comm,da);CHKERRQ(ierr); ierr = DMSetType(*da,DMDA);CHKERRQ(ierr); PetscFunctionReturn(0); }
int main(int argc, char **argv) { PetscErrorCode ierr; Vec U,cv,eta; DM da,da2; PetscViewer viewer,view_vtk_cv,view_vtk_eta; char filename[PETSC_MAX_PATH_LEN],cv_filename[PETSC_MAX_PATH_LEN],eta_filename[PETSC_MAX_PATH_LEN]; PetscBool flg,sflg = PETSC_FALSE; PetscInt i,n=10000; PetscInt seed; PetscInitialize(&argc,&argv, (char*)0, help); ierr = PetscOptionsSetValue("-viewer_binary_skip_info","true");CHKERRQ(ierr); ierr = PetscOptionsGetString(PETSC_NULL,"-f",filename,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr); if (!flg) { ierr = PetscOptionsGetInt(PETSC_NULL,"-random_seed",&seed,&sflg);CHKERRQ(ierr); if (!sflg) { ierr = PetscStrcpy(filename,"ex61.data");CHKERRQ(ierr); } else { sprintf(filename,"ex61.data.%d",seed); } } ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,filename,FILE_MODE_READ,&viewer);CHKERRQ(ierr); /* Get physics and time parameters */ ierr = DMCreate(PETSC_COMM_WORLD,&da);CHKERRQ(ierr); ierr = DMLoad(da,viewer);CHKERRQ(ierr); ierr = DMCreateGlobalVector(da,&U);CHKERRQ(ierr); ierr = DMDAGetReducedDA(da,1,&da2);CHKERRQ(ierr); ierr = DMCreateGlobalVector(da2,&cv);CHKERRQ(ierr); ierr = DMCreateGlobalVector(da2,&eta);CHKERRQ(ierr); for (i=0; i<n; i++) { /* when this fails it simply means the file is finished */ ierr = VecLoad(U,viewer);CHKERRQ(ierr); ierr = VecStrideGather(U,1,cv,INSERT_VALUES);CHKERRQ(ierr); ierr = VecStrideGather(U,4,eta,INSERT_VALUES);CHKERRQ(ierr); sprintf(cv_filename,"%s_cv_%d.vtk",filename,i); sprintf(eta_filename,"%s_eta_%d.vtk",filename,i); ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD,cv_filename,&view_vtk_cv);CHKERRQ(ierr); ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD,eta_filename,&view_vtk_eta);CHKERRQ(ierr); ierr = PetscViewerSetFormat(view_vtk_cv, PETSC_VIEWER_ASCII_VTK);CHKERRQ(ierr); ierr = PetscViewerSetFormat(view_vtk_eta, PETSC_VIEWER_ASCII_VTK);CHKERRQ(ierr); ierr = DMView(da2,view_vtk_cv);CHKERRQ(ierr); ierr = DMView(da2,view_vtk_eta);CHKERRQ(ierr); ierr = VecView(cv,view_vtk_cv);CHKERRQ(ierr); ierr = VecView(eta,view_vtk_eta);CHKERRQ(ierr); ierr = PetscViewerDestroy(&view_vtk_cv);CHKERRQ(ierr); ierr = PetscViewerDestroy(&view_vtk_eta);CHKERRQ(ierr); } ierr = VecDestroy(&U);CHKERRQ(ierr); ierr = VecDestroy(&cv);CHKERRQ(ierr); ierr = VecDestroy(&eta);CHKERRQ(ierr); ierr = DMDestroy(&da);CHKERRQ(ierr); ierr = DMDestroy(&da2);CHKERRQ(ierr); PetscFinalize(); return 0; }
PetscErrorCode CreateMesh(MPI_Comm comm, AppCtx *user, DM *dm) { PetscInt dim = user->dim; PetscBool refinementUniform = user->refinementUniform; PetscBool cellSimplex = user->cellSimplex; const char *partitioner = "chaco"; PetscMPIInt rank; PetscErrorCode ierr; PetscFunctionBegin; ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); ierr = DMCreate(comm, dm);CHKERRQ(ierr); ierr = DMSetType(*dm, DMPLEX);CHKERRQ(ierr); ierr = DMPlexSetDimension(*dm, dim);CHKERRQ(ierr); switch(dim) { case 2: if (cellSimplex) { ierr = CreateSimplexHybrid_2D(comm, *dm);CHKERRQ(ierr); } else { SETERRQ(comm, PETSC_ERR_ARG_OUTOFRANGE, "Cannot make hybrid meshes for quadrilaterals"); } break; default: SETERRQ1(comm, PETSC_ERR_ARG_OUTOFRANGE, "Cannot make hybrid meshes for dimension %d", dim); } { DM refinedMesh = PETSC_NULL; DM distributedMesh = PETSC_NULL; /* Distribute mesh over processes */ ierr = DMPlexDistribute(*dm, partitioner, 0, &distributedMesh);CHKERRQ(ierr); if (distributedMesh) { PetscInt cMax = PETSC_DETERMINE, fMax = PETSC_DETERMINE; /* Do not know how to preserve this after distribution */ if (rank) { cMax = 1; fMax = 11; } ierr = DMPlexSetHybridBounds(distributedMesh, cMax, PETSC_DETERMINE, fMax, PETSC_DETERMINE);CHKERRQ(ierr); ierr = DMDestroy(dm);CHKERRQ(ierr); *dm = distributedMesh; } if (refinementUniform) { ierr = DMPlexSetRefinementUniform(*dm, refinementUniform);CHKERRQ(ierr); ierr = DMRefine(*dm, comm, &refinedMesh);CHKERRQ(ierr); if (refinedMesh) { ierr = DMDestroy(dm);CHKERRQ(ierr); *dm = refinedMesh; } } } ierr = PetscObjectSetName((PetscObject) *dm, "Hybrid Mesh");CHKERRQ(ierr); ierr = DMSetFromOptions(*dm);CHKERRQ(ierr); user->dm = *dm; PetscFunctionReturn(0); }
/*@ DMDACreate - Creates a DMDA object. Collective on MPI_Comm Input Parameter: . comm - The communicator for the DMDA object Output Parameter: . da - The DMDA object Level: advanced Developers Note: Since there exists DMDACreate1/2/3d() should this routine even exist? .keywords: DMDA, create .seealso: DMDASetSizes(), DMDADuplicate(), DMDACreate1d(), DMDACreate2d(), DMDACreate3d() @*/ PetscErrorCode DMDACreate(MPI_Comm comm, DM *da) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(da,2); ierr = DMCreate(comm,da);CHKERRQ(ierr); ierr = DMSetType(*da,DMDA);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@ DMPatchCreate - Creates a DMPatch object, which is a collections of DMs called patches. Collective on MPI_Comm Input Parameter: . comm - The communicator for the DMPatch object Output Parameter: . mesh - The DMPatch object Level: beginner .keywords: DMPatch, create @*/ PetscErrorCode DMPatchCreate(MPI_Comm comm, DM *mesh) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(mesh,2); ierr = DMCreate(comm, mesh);CHKERRQ(ierr); ierr = DMSetType(*mesh, DMPATCH);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@ DMShellCreate - Creates a shell DM object, used to manage user-defined problem data Collective on MPI_Comm Input Parameter: . comm - the processors that will share the global vector Output Parameters: . shell - the shell DM Level: advanced .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateLocalVector() @*/ PetscErrorCode DMShellCreate(MPI_Comm comm,DM *dm) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(dm,2); ierr = DMCreate(comm,dm);CHKERRQ(ierr); ierr = DMSetType(*dm,DMSHELL);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode DMCreateSubDM_DA(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) { DM_DA *da = (DM_DA*) dm->data; PetscSection section; PetscErrorCode ierr; PetscFunctionBegin; if (subdm) { PetscSF sf; Vec coords; void *ctx; /* Cannot use DMClone since the dof stuff is mixed in. Ugh ierr = DMClone(dm, subdm);CHKERRQ(ierr); */ ierr = DMCreate(PetscObjectComm((PetscObject)dm), subdm);CHKERRQ(ierr); ierr = DMGetPointSF(dm, &sf);CHKERRQ(ierr); ierr = DMSetPointSF(*subdm, sf);CHKERRQ(ierr); ierr = DMGetApplicationContext(dm, &ctx);CHKERRQ(ierr); ierr = DMSetApplicationContext(*subdm, ctx);CHKERRQ(ierr); ierr = DMGetCoordinatesLocal(dm, &coords);CHKERRQ(ierr); if (coords) { ierr = DMSetCoordinatesLocal(*subdm, coords);CHKERRQ(ierr); } else { ierr = DMGetCoordinates(dm, &coords);CHKERRQ(ierr); if (coords) {ierr = DMSetCoordinates(*subdm, coords);CHKERRQ(ierr);} } ierr = DMSetType(*subdm, DMDA);CHKERRQ(ierr); ierr = DMSetDimension(*subdm, dm->dim);CHKERRQ(ierr); ierr = DMDASetSizes(*subdm, da->M, da->N, da->P);CHKERRQ(ierr); ierr = DMDASetNumProcs(*subdm, da->m, da->n, da->p);CHKERRQ(ierr); ierr = DMDASetBoundaryType(*subdm, da->bx, da->by, da->bz);CHKERRQ(ierr); ierr = DMDASetDof(*subdm, numFields);CHKERRQ(ierr); ierr = DMDASetStencilType(*subdm, da->stencil_type);CHKERRQ(ierr); ierr = DMDASetStencilWidth(*subdm, da->s);CHKERRQ(ierr); ierr = DMDASetOwnershipRanges(*subdm, da->lx, da->ly, da->lz);CHKERRQ(ierr); } ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); if (section) { ierr = DMCreateSubDM_Section_Private(dm, numFields, fields, is, subdm);CHKERRQ(ierr); } else { if (is) { PetscInt *indices, cnt = 0, dof = da->w, i, j; ierr = PetscMalloc1(da->Nlocal*numFields/dof, &indices);CHKERRQ(ierr); for (i = da->base/dof; i < (da->base+da->Nlocal)/dof; ++i) { for (j = 0; j < numFields; ++j) { indices[cnt++] = dof*i + fields[j]; } } if (cnt != da->Nlocal*numFields/dof) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Count %d does not equal expected value %d", cnt, da->Nlocal*numFields/dof); ierr = ISCreateGeneral(PetscObjectComm((PetscObject) dm), cnt, indices, PETSC_OWN_POINTER, is);CHKERRQ(ierr); } } PetscFunctionReturn(0); }
/*@C DMADDACreate - Creates and ADDA object that translate between coordinates in a geometric grid of arbitrary dimension and data in a PETSc vector distributed on several processors. Collective on MPI_Comm Input Parameters: + comm - MPI communicator . dim - the dimension of the grid . nodes - array with d entries that give the number of nodes in each dimension . procs - array with d entries that give the number of processors in each dimension (or NULL if to be determined automatically) . dof - number of degrees of freedom per node - periodic - array with d entries that, i-th entry is set to true iff dimension i is periodic Output Parameters: . adda - pointer to ADDA data structure that is created Level: intermediate @*/ PetscErrorCode DMADDACreate(MPI_Comm comm, PetscInt dim, PetscInt *nodes,PetscInt *procs,PetscInt dof, PetscBool *periodic,DM *dm_p) { PetscErrorCode ierr; PetscFunctionBegin; ierr = DMCreate(comm,dm_p);CHKERRQ(ierr); ierr = DMSetType(*dm_p,DMADDA);CHKERRQ(ierr); ierr = DMADDASetParameters(*dm_p,dim,nodes,procs,dof,periodic);CHKERRQ(ierr); ierr = DMSetUp(*dm_p);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C DMRedundantCreate - Creates a DM object, used to manage data for dense globally coupled variables Collective on MPI_Comm Input Parameter: + comm - the processors that will share the global vector . rank - rank to own the redundant values - N - total number of degrees of freedom Output Parameters: . red - the redundant DM Level: advanced .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateMatrix(), DMCompositeAddDM(), DMREDUNDANT, DMSetType(), DMRedundantSetSize(), DMRedundantGetSize() @*/ PetscErrorCode DMRedundantCreate(MPI_Comm comm,PetscInt rank,PetscInt N,DM *dm) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(dm,2); ierr = DMCreate(comm,dm);CHKERRQ(ierr); ierr = DMSetType(*dm,DMREDUNDANT);CHKERRQ(ierr); ierr = DMRedundantSetSize(*dm,rank,N);CHKERRQ(ierr); ierr = DMSetUp(*dm);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@ DMPlexUninterpolate - Take in a mesh with all intermediate faces, edges, etc. and return a cell-vertex mesh Collective on DM Input Parameter: . dm - The complete DMPlex object Output Parameter: . dmUnint - The DMPlex object with only cells and vertices Level: intermediate .keywords: mesh .seealso: DMPlexInterpolate(), DMPlexCreateFromCellList() @*/ PetscErrorCode DMPlexUninterpolate(DM dm, DM *dmUnint) { DM udm; PetscInt dim, vStart, vEnd, cStart, cEnd, c, maxConeSize = 0, *cone; PetscErrorCode ierr; PetscFunctionBegin; ierr = DMPlexGetDimension(dm, &dim);CHKERRQ(ierr); if (dim <= 1) { ierr = PetscObjectReference((PetscObject) dm);CHKERRQ(ierr); *dmUnint = dm; PetscFunctionReturn(0); } ierr = DMPlexGetDepthStratum(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); ierr = DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd);CHKERRQ(ierr); ierr = DMCreate(PetscObjectComm((PetscObject) dm), &udm);CHKERRQ(ierr); ierr = DMSetType(udm, DMPLEX);CHKERRQ(ierr); ierr = DMPlexSetDimension(udm, dim);CHKERRQ(ierr); ierr = DMPlexSetChart(udm, cStart, vEnd);CHKERRQ(ierr); for (c = cStart; c < cEnd; ++c) { PetscInt *closure = NULL, closureSize, cl, coneSize = 0; ierr = DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); for (cl = 0; cl < closureSize*2; cl += 2) { const PetscInt p = closure[cl]; if ((p >= vStart) && (p < vEnd)) ++coneSize; } ierr = DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); ierr = DMPlexSetConeSize(udm, c, coneSize);CHKERRQ(ierr); maxConeSize = PetscMax(maxConeSize, coneSize); } ierr = DMSetUp(udm);CHKERRQ(ierr); ierr = PetscMalloc1(maxConeSize, &cone);CHKERRQ(ierr); for (c = cStart; c < cEnd; ++c) { PetscInt *closure = NULL, closureSize, cl, coneSize = 0; ierr = DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); for (cl = 0; cl < closureSize*2; cl += 2) { const PetscInt p = closure[cl]; if ((p >= vStart) && (p < vEnd)) cone[coneSize++] = p; } ierr = DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure);CHKERRQ(ierr); ierr = DMPlexSetCone(udm, c, cone);CHKERRQ(ierr); } ierr = PetscFree(cone);CHKERRQ(ierr); ierr = DMPlexSymmetrize(udm);CHKERRQ(ierr); ierr = DMPlexStratify(udm);CHKERRQ(ierr); *dmUnint = udm; PetscFunctionReturn(0); }
PetscErrorCode DMLibMeshCreateDomainDecompositionDM(DM dm, PetscInt dnumber, PetscInt* dsizes, char*** dblocklists, DM* ddm) { PetscErrorCode ierr; PetscBool islibmesh; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); ierr = PetscObjectTypeCompare((PetscObject)dm, DMLIBMESH,&islibmesh); if(!islibmesh) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Got DM oftype %s, not of type %s", ((PetscObject)dm)->type_name, DMLIBMESH); if(dnumber < 0) SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Negative number %D of decomposition parts", dnumber); PetscValidPointer(ddm,5); DM_libMesh *dlm = (DM_libMesh *)(dm->data); ierr = DMCreate(((PetscObject)dm)->comm, ddm); CHKERRQ(ierr); ierr = DMSetType(*ddm, DMLIBMESH); CHKERRQ(ierr); DM_libMesh *ddlm = (DM_libMesh *)((*ddm)->data); ddlm->sys = dlm->sys; ddlm->varids = dlm->varids; ddlm->varnames = dlm->varnames; ddlm->blockids = dlm->blockids; ddlm->blocknames = dlm->blocknames; ddlm->decomposition = new(std::vector<std::set<unsigned int> >); ddlm->decomposition_type = DMLIBMESH_DOMAIN_DECOMPOSITION; if(dnumber) { for(PetscInt d = 0; d < dnumber; ++d) { if(dsizes[d] < 0) SETERRQ2(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Negative size %D of decomposition part %D", dsizes[d],d); ddlm->decomposition->push_back(std::set<unsigned int>()); for(PetscInt b = 0; b < dsizes[d]; ++b) { std::string bname(dblocklists[d][b]); std::map<std::string, unsigned int>::const_iterator bit = dlm->blockids->find(bname); if(bit == dlm->blockids->end()) SETERRQ3(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Block %D on the %D-th list with name %s is not owned by this DM", b, d, dblocklists[d][b]); unsigned int bid = bit->second; (*ddlm->decomposition)[d].insert(bid); } } } else { /* Empty splits indicate default: split all blocks with one per split. */ PetscInt d = 0; for(std::map<std::string, unsigned int>::const_iterator bit = ddlm->blockids->begin(); bit != ddlm->blockids->end(); ++bit) { ddlm->decomposition->push_back(std::set<unsigned int>()); unsigned int bid = bit->second; std::string bname = bit->first; (*ddlm->decomposition)[d].insert(bid); ++d; } } ierr = DMLibMeshSetUpName_Private(*ddm); CHKERRQ(ierr); ierr = DMSetFromOptions(*ddm); CHKERRQ(ierr); ierr = DMSetUp(*ddm); CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode DMMeshCreateBoxMesh(MPI_Comm comm, PetscInt dim, PetscBool interpolate, DM *dm) { PetscBool flg; PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(dm, 4); ierr = PetscOptionsBool("-dm_mesh_new_impl", "Use the new C unstructured mesh implementation", "DMView", PETSC_FALSE, &flg, PETSC_NULL);CHKERRQ(ierr); if (flg) { DM boundary; if (interpolate) {SETERRQ(comm, PETSC_ERR_SUP, "Interpolation (creation of faces and edges) is not yet supported.");} ierr = DMCreate(comm, &boundary);CHKERRQ(ierr); PetscValidLogicalCollectiveInt(boundary,dim,2); ierr = DMSetType(boundary, DMMESH);CHKERRQ(ierr); ierr = DMMeshSetDimension(boundary, dim-1);CHKERRQ(ierr); switch(dim) { case 2: { PetscReal lower[2] = {0.0, 0.0}; PetscReal upper[2] = {1.0, 1.0}; PetscInt edges[2] = {2, 2}; ierr = DMMeshCreateSquareBoundary(boundary, lower, upper, edges);CHKERRQ(ierr); break; } case 3: { PetscReal lower[3] = {0.0, 0.0, 0.0}; PetscReal upper[3] = {1.0, 1.0, 1.0}; PetscInt faces[3] = {1, 1, 1}; ierr = DMMeshCreateCubeBoundary(boundary, lower, upper, faces);CHKERRQ(ierr); break; } default: SETERRQ1(comm, PETSC_ERR_SUP, "Dimension not supported: %d", dim); } ierr = DMMeshGenerate(boundary, interpolate, dm);CHKERRQ(ierr); ierr = DMDestroy(&boundary);CHKERRQ(ierr); } else { PetscInt debug = 0; try { ierr = ALE::DMBuilder::createBoxMesh(comm, dim, false, interpolate, debug, dm);CHKERRQ(ierr); } catch(ALE::Exception e) { SETERRQ1(comm, PETSC_ERR_PLIB, "Unable to create mesh: %s", e.message()); } } PetscFunctionReturn(0); }
EXTERN_C_END #undef __FUNCT__ #define __FUNCT__ "DMSlicedCreate" /*@C DMSlicedCreate - Creates a DM object, used to manage data for a unstructured problem Collective on MPI_Comm Input Parameter: + comm - the processors that will share the global vector . bs - the block size . nlocal - number of vector entries on this process . Nghosts - number of ghost points needed on this process . ghosts - global indices of all ghost points for this process . d_nnz - matrix preallocation information representing coupling within this process - o_nnz - matrix preallocation information representing coupling between this process and other processes Output Parameters: . slice - the slice object Notes: This DM does not support DMCreateLocalVector(), DMGlobalToLocalBegin(), and DMGlobalToLocalEnd() instead one directly uses VecGhostGetLocalForm() and VecGhostRestoreLocalForm() to access the local representation and VecGhostUpdateBegin() and VecGhostUpdateEnd() to update the ghost points. One can use DMGlobalToLocalBegin(), and DMGlobalToLocalEnd() instead of VecGhostUpdateBegin() and VecGhostUpdateEnd(). Level: advanced .seealso DMDestroy(), DMCreateGlobalVector(), DMSetType(), DMSLICED, DMSlicedSetGhosts(), DMSlicedSetPreallocation(), VecGhostUpdateBegin(), VecGhostUpdateEnd(), VecGhostGetLocalForm(), VecGhostRestoreLocalForm() @*/ PetscErrorCode DMSlicedCreate(MPI_Comm comm,PetscInt bs,PetscInt nlocal,PetscInt Nghosts,const PetscInt ghosts[], const PetscInt d_nnz[],const PetscInt o_nnz[],DM *dm) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(dm,2); ierr = DMCreate(comm,dm);CHKERRQ(ierr); ierr = DMSetType(*dm,DMSLICED);CHKERRQ(ierr); ierr = DMSlicedSetGhosts(*dm,bs,nlocal,Nghosts,ghosts);CHKERRQ(ierr); if (d_nnz) { ierr = DMSlicedSetPreallocation(*dm,0, d_nnz,0,o_nnz);CHKERRQ(ierr); } PetscFunctionReturn(0); }
/*@C DMPlexCreateFromCellList - This takes as input common mesh generator output, a list of the vertices for each cell, and produces a DM Input Parameters: + comm - The communicator . dim - The topological dimension of the mesh . numCells - The number of cells . numVertices - The number of vertices . numCorners - The number of vertices for each cell . interpolate - Flag indicating that intermediate mesh entities (faces, edges) should be created automatically . cells - An array of numCells*numCorners numbers, the vertices for each cell . spaceDim - The spatial dimension used for coordinates - vertexCoords - An array of numVertices*spaceDim numbers, the coordinates of each vertex Output Parameter: . dm - The DM Note: Two triangles sharing a face $ $ 2 $ / | \ $ / | \ $ / | \ $ 0 0 | 1 3 $ \ | / $ \ | / $ \ | / $ 1 would have input $ numCells = 2, numVertices = 4 $ cells = [0 1 2 1 3 2] $ which would result in the DMPlex $ $ 4 $ / | \ $ / | \ $ / | \ $ 2 0 | 1 5 $ \ | / $ \ | / $ \ | / $ 3 Level: beginner .seealso: DMPlexCreate() @*/ PetscErrorCode DMPlexCreateFromCellList(MPI_Comm comm, PetscInt dim, PetscInt numCells, PetscInt numVertices, PetscInt numCorners, PetscBool interpolate, const int cells[], PetscInt spaceDim, const double vertexCoords[], DM *dm) { PetscErrorCode ierr; PetscFunctionBegin; ierr = DMCreate(comm, dm);CHKERRQ(ierr); ierr = DMSetType(*dm, DMPLEX);CHKERRQ(ierr); ierr = DMPlexSetDimension(*dm, dim);CHKERRQ(ierr); ierr = DMPlexBuildFromCellList_Private(*dm, numCells, numVertices, numCorners, cells);CHKERRQ(ierr); if (interpolate) { DM idm; ierr = DMPlexInterpolate(*dm, &idm);CHKERRQ(ierr); ierr = DMDestroy(dm);CHKERRQ(ierr); *dm = idm; } ierr = DMPlexBuildCoordinates_Private(*dm, spaceDim, numCells, numVertices, vertexCoords);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode DMPlexInterpolate(DM dm, DM *dmInt) { DM idm, odm = dm; PetscInt dim, d; PetscErrorCode ierr; PetscFunctionBegin; ierr = DMPlexGetDimension(dm, &dim);CHKERRQ(ierr); for (d = 1; d < dim; ++d) { /* Create interpolated mesh */ ierr = DMCreate(PetscObjectComm((PetscObject)dm), &idm);CHKERRQ(ierr); ierr = DMSetType(idm, DMPLEX);CHKERRQ(ierr); ierr = DMPlexSetDimension(idm, dim);CHKERRQ(ierr); ierr = DMPlexInterpolateFaces_Internal(odm, 1, idm);CHKERRQ(ierr); if (odm != dm) {ierr = DMDestroy(&odm);CHKERRQ(ierr);} odm = idm; } *dmInt = idm; PetscFunctionReturn(0); }
/*@ DMMeshCreateMeshFromAdjacency - Create an unstrctured mesh from a list of the vertices for each cell, and the coordinates for each vertex. Collective on comm Input Parameters: + comm - An MPI communicator . dim - The dimension of the cells, e.g. triangles have dimension 2 . numCells - The number of cells in the mesh . numCorners - The number of vertices in each cell . cellVertices - An array of the vertices for each cell, numbered 0 to numVertices-1 . spatialDim - The dimension for coordinates, e.g. for a triangle in 3D this would be 3 . numVertices - The number of mesh vertices . coordinates - An array of the coordinates for each vertex - interpolate - Flag to create faces and edges Output Parameter: . dm - The DMMesh object Level: beginner .seealso DMMESH, DMMeshCreateMeshFromAdjacencyHybrid(), DMMeshCreateBoxMesh() @*/ PetscErrorCode DMMeshCreateMeshFromAdjacency(MPI_Comm comm, PetscInt dim, PetscInt numCells, PetscInt numCorners, PetscInt cellVertices[], PetscInt spatialDim, PetscInt numVertices, const PetscReal coordinates[], PetscBool interpolate, DM *dm) { PetscInt *cone; PetscInt *coneO; PetscInt debug = 0; PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(cellVertices, 5); /* PetscValidLogicalCollectiveBool(comm,interpolate,6); */ PetscValidPointer(dm, 7); if (interpolate) {SETERRQ(comm, PETSC_ERR_SUP, "Interpolation (creation of faces and edges) is not yet supported.");} ierr = PetscOptionsGetInt(PETSC_NULL, "-dm_mesh_debug", &debug, PETSC_NULL);CHKERRQ(ierr); Obj<PETSC_MESH_TYPE> mesh = new PETSC_MESH_TYPE(comm, dim, debug); Obj<PETSC_MESH_TYPE::sieve_type> sieve = new PETSC_MESH_TYPE::sieve_type(comm, 0, numCells+numVertices, debug); mesh->setSieve(sieve); for(PetscInt c = 0; c < numCells; ++c) { sieve->setConeSize(c, numCorners); } sieve->symmetrizeSizes(numCells, numCorners, cellVertices, numCells); sieve->allocate(); ierr = PetscMalloc2(numCorners,PetscInt,&cone,numCorners,PetscInt,&coneO);CHKERRQ(ierr); for(PetscInt v = 0; v < numCorners; ++v) { coneO[v] = 1; } for(PetscInt c = 0; c < numCells; ++c) { for(PetscInt v = 0; v < numCorners; ++v) { cone[v] = cellVertices[c*numCorners+v]+numCells; } sieve->setCone(cone, c); sieve->setConeOrientation(coneO, c); } ierr = PetscFree2(cone,coneO);CHKERRQ(ierr); sieve->symmetrize(); mesh->stratify(); ALE::SieveBuilder<PETSC_MESH_TYPE>::buildCoordinates(mesh, spatialDim, coordinates, numCells); ierr = DMCreate(comm, dm);CHKERRQ(ierr); ierr = DMSetType(*dm, DMMESH);CHKERRQ(ierr); ierr = DMMeshSetMesh(*dm, mesh);CHKERRQ(ierr); PetscFunctionReturn(0); }
EXTERN_C_END #undef __FUNCT__ #define __FUNCT__ "DMADDACreate" /*@C DMADDACreate - Creates and ADDA object that translate between coordinates in a geometric grid of arbitrary dimension and data in a PETSc vector distributed on several processors. Collective on MPI_Comm Input Parameters: + comm - MPI communicator . dim - the dimension of the grid . nodes - array with d entries that give the number of nodes in each dimension . procs - array with d entries that give the number of processors in each dimension (or PETSC_NULL if to be determined automatically) . dof - number of degrees of freedom per node - periodic - array with d entries that, i-th entry is set to true iff dimension i is periodic Output Parameters: . adda - pointer to ADDA data structure that is created Level: intermediate @*/ PetscErrorCode DMADDACreate(MPI_Comm comm, PetscInt dim, PetscInt *nodes,PetscInt *procs,PetscInt dof, PetscBool *periodic,DM *dm_p) { PetscErrorCode ierr; PetscFunctionBegin; ierr = DMCreate(comm,dm_p);CHKERRQ(ierr); ierr = DMSetType(*dm_p,DMADDA);CHKERRQ(ierr); ierr = DMADDASetParameters(*dm_p,dim,nodes,procs,dof,periodic);CHKERRQ(ierr); ierr = DMSetUp(*dm_p);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@ DMPlexCreateBoxMesh - Creates a mesh on the tensor product of unit intervals (box). Collective on MPI_Comm Input Parameters: + comm - The communicator for the DM object . dim - The spatial dimension - interpolate - Flag to create intermediate mesh pieces (edges, faces) Output Parameter: . dm - The DM object Level: beginner .keywords: DM, create .seealso: DMSetType(), DMCreate() @*/ PetscErrorCode DMPlexCreateBoxMesh(MPI_Comm comm, PetscInt dim, PetscBool interpolate, DM *dm) { DM boundary; PetscErrorCode ierr; PetscFunctionBegin; PetscValidPointer(dm, 4); ierr = DMCreate(comm, &boundary);CHKERRQ(ierr); PetscValidLogicalCollectiveInt(boundary,dim,2); ierr = DMSetType(boundary, DMPLEX);CHKERRQ(ierr); ierr = DMPlexSetDimension(boundary, dim-1);CHKERRQ(ierr); switch (dim) { case 2: { PetscReal lower[2] = {0.0, 0.0}; PetscReal upper[2] = {1.0, 1.0}; PetscInt edges[2] = {2, 2}; ierr = DMPlexCreateSquareBoundary(boundary, lower, upper, edges);CHKERRQ(ierr); break; } case 3: { PetscReal lower[3] = {0.0, 0.0, 0.0}; PetscReal upper[3] = {1.0, 1.0, 1.0}; PetscInt faces[3] = {1, 1, 1}; ierr = DMPlexCreateCubeBoundary(boundary, lower, upper, faces);CHKERRQ(ierr); break; } default: SETERRQ1(comm, PETSC_ERR_SUP, "Dimension not supported: %d", dim); } ierr = DMPlexGenerate(boundary, NULL, interpolate, dm);CHKERRQ(ierr); ierr = DMDestroy(&boundary);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C DMStagCreate1d - Create an object to manage data living on the faces, edges, and vertices of a parallelized regular 1D grid. Collective Input Parameters: + comm - MPI communicator . bndx - boundary type: DM_BOUNDARY_NONE, DM_BOUNDARY_PERIODIC, or DM_BOUNDARY_GHOSTED . M - global number of grid points . dof0 - number of degrees of freedom per vertex/point/node/0-cell . dof1 - number of degrees of freedom per element/edge/1-cell . stencilType - ghost/halo region type: DMSTAG_STENCIL_BOX or DMSTAG_STENCIL_NONE . stencilWidth - width, in elements, of halo/ghost region - lx - array of local sizes, of length equal to the comm size, summing to M Output Parameter: . dm - the new DMStag object Options Database Keys: + -dm_view - calls DMViewFromOptions() a the conclusion of DMSetUp() . -stag_grid_x <nx> - number of elements in the x direction . -stag_ghost_stencil_width - width of ghost region, in elements - -stag_boundary_type_x <none,ghosted,periodic> - DMBoundaryType value Notes: You must call DMSetUp() after this call before using the DM. If you wish to use the options database (see the keys above) to change values in the DMStag, you must call DMSetFromOptions() after this function but before DMSetUp(). Level: beginner .seealso: DMSTAG, DMStagCreate2d(), DMStagCreate3d(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateLocalVector(), DMLocalToGlobalBegin() @*/ PETSC_EXTERN PetscErrorCode DMStagCreate1d(MPI_Comm comm,DMBoundaryType bndx,PetscInt M,PetscInt dof0,PetscInt dof1,DMStagStencilType stencilType,PetscInt stencilWidth,const PetscInt lx[],DM* dm) { PetscErrorCode ierr; DM_Stag *stag; PetscMPIInt size; PetscFunctionBegin; ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); ierr = DMCreate(comm,dm);CHKERRQ(ierr); ierr = DMSetDimension(*dm,1);CHKERRQ(ierr); /* Must precede DMSetType */ ierr = DMSetType(*dm,DMSTAG);CHKERRQ(ierr); stag = (DM_Stag*)(*dm)->data; /* Global sizes and flags (derived quantities set in DMSetUp_Stag) */ stag->boundaryType[0] = bndx; stag->N[0] = M; stag->nRanks[0] = size; stag->stencilType = stencilType; stag->stencilWidth = stencilWidth; ierr = DMStagSetDOF(*dm,dof0,dof1,0,0);CHKERRQ(ierr); ierr = DMStagSetOwnershipRanges(*dm,lx,NULL,NULL);CHKERRQ(ierr); PetscFunctionReturn(0); }