1af0996ceSBarry Smith #include <petsc/private/dmimpl.h> /*I "petscdm.h" I*/ 2c58f1c22SToby Isaac #include <petsc/private/dmlabelimpl.h> /*I "petscdmlabel.h" I*/ 33e922f36SToby Isaac #include <petscdmplex.h> 40c312b8eSJed Brown #include <petscsf.h> 52764a2aaSMatthew G. Knepley #include <petscds.h> 647c6ae99SBarry Smith 7732e2eb9SMatthew G Knepley PetscClassId DM_CLASSID; 83ad4599aSBarry Smith PetscLogEvent DM_Convert, DM_GlobalToLocal, DM_LocalToGlobal, DM_LocalToLocal, DM_LocatePoints, DM_Coarsen, DM_CreateInterpolation, DM_CreateRestriction; 967a56275SMatthew G Knepley 10bff4a2f0SMatthew G. Knepley const char *const DMBoundaryTypes[] = {"NONE","GHOSTED","MIRROR","PERIODIC","TWIST","DM_BOUNDARY_",0}; 11bff4a2f0SMatthew G. Knepley 1247c6ae99SBarry Smith #undef __FUNCT__ 13a4121054SBarry Smith #define __FUNCT__ "DMCreate" 14a4121054SBarry Smith /*@ 15de043629SMatthew G Knepley DMCreate - Creates an empty DM object. The type can then be set with DMSetType(). 16a4121054SBarry Smith 17a4121054SBarry Smith If you never call DMSetType() it will generate an 18a4121054SBarry Smith error when you try to use the vector. 19a4121054SBarry Smith 20a4121054SBarry Smith Collective on MPI_Comm 21a4121054SBarry Smith 22a4121054SBarry Smith Input Parameter: 23a4121054SBarry Smith . comm - The communicator for the DM object 24a4121054SBarry Smith 25a4121054SBarry Smith Output Parameter: 26a4121054SBarry Smith . dm - The DM object 27a4121054SBarry Smith 28a4121054SBarry Smith Level: beginner 29a4121054SBarry Smith 308472ad0fSDave May .seealso: DMSetType(), DMDA, DMSLICED, DMCOMPOSITE, DMPLEX, DMMOAB, DMNETWORK 31a4121054SBarry Smith @*/ 327087cfbeSBarry Smith PetscErrorCode DMCreate(MPI_Comm comm,DM *dm) 33a4121054SBarry Smith { 34a4121054SBarry Smith DM v; 35a4121054SBarry Smith PetscErrorCode ierr; 36a4121054SBarry Smith 37a4121054SBarry Smith PetscFunctionBegin; 381411c6eeSJed Brown PetscValidPointer(dm,2); 390298fd71SBarry Smith *dm = NULL; 408b984314SMatthew G. Knepley ierr = PetscSysInitializePackage();CHKERRQ(ierr); 41607a6623SBarry Smith ierr = VecInitializePackage();CHKERRQ(ierr); 42607a6623SBarry Smith ierr = MatInitializePackage();CHKERRQ(ierr); 43607a6623SBarry Smith ierr = DMInitializePackage();CHKERRQ(ierr); 44a4121054SBarry Smith 4573107ff1SLisandro Dalcin ierr = PetscHeaderCreate(v, DM_CLASSID, "DM", "Distribution Manager", "DM", comm, DMDestroy, DMView);CHKERRQ(ierr); 46e7c4fc90SDmitry Karpeev 470298fd71SBarry Smith v->ltogmap = NULL; 481411c6eeSJed Brown v->bs = 1; 49171400e9SBarry Smith v->coloringtype = IS_COLORING_GLOBAL; 5088ed4aceSMatthew G Knepley ierr = PetscSFCreate(comm, &v->sf);CHKERRQ(ierr); 5188ed4aceSMatthew G Knepley ierr = PetscSFCreate(comm, &v->defaultSF);CHKERRQ(ierr); 52c58f1c22SToby Isaac v->labels = NULL; 53c58f1c22SToby Isaac v->depthLabel = NULL; 540298fd71SBarry Smith v->defaultSection = NULL; 550298fd71SBarry Smith v->defaultGlobalSection = NULL; 56fba222abSToby Isaac v->defaultConstraintSection = NULL; 57fba222abSToby Isaac v->defaultConstraintMat = NULL; 58c6b900c6SMatthew G. Knepley v->L = NULL; 59c6b900c6SMatthew G. Knepley v->maxCell = NULL; 605dc8c3f7SMatthew G. Knepley v->bdtype = NULL; 619a9a41abSToby Isaac v->dimEmbed = PETSC_DEFAULT; 62435a35e8SMatthew G Knepley { 63435a35e8SMatthew G Knepley PetscInt i; 64435a35e8SMatthew G Knepley for (i = 0; i < 10; ++i) { 650298fd71SBarry Smith v->nullspaceConstructors[i] = NULL; 66435a35e8SMatthew G Knepley } 67435a35e8SMatthew G Knepley } 682764a2aaSMatthew G. Knepley ierr = PetscDSCreate(comm, &v->prob);CHKERRQ(ierr); 6914f150ffSMatthew G. Knepley v->dmBC = NULL; 70a8fb8f29SToby Isaac v->coarseMesh = NULL; 71f4d763aaSMatthew G. Knepley v->outputSequenceNum = -1; 72cdb7a50dSMatthew G. Knepley v->outputSequenceVal = 0.0; 73c0dedaeaSBarry Smith ierr = DMSetVecType(v,VECSTANDARD);CHKERRQ(ierr); 74b412c318SBarry Smith ierr = DMSetMatType(v,MATAIJ);CHKERRQ(ierr); 75bcc5ffd9SToby Isaac ierr = PetscNew(&(v->labels));CHKERRQ(ierr); 76c58f1c22SToby Isaac v->labels->refct = 1; 77bcc5ffd9SToby Isaac ierr = PetscNew(&(v->boundary));CHKERRQ(ierr); 78bcc5ffd9SToby Isaac v->boundary->refct = 1; 791411c6eeSJed Brown *dm = v; 80a4121054SBarry Smith PetscFunctionReturn(0); 81a4121054SBarry Smith } 82a4121054SBarry Smith 83a4121054SBarry Smith #undef __FUNCT__ 8438221697SMatthew G. Knepley #define __FUNCT__ "DMClone" 8538221697SMatthew G. Knepley /*@ 8638221697SMatthew G. Knepley DMClone - Creates a DM object with the same topology as the original. 8738221697SMatthew G. Knepley 8838221697SMatthew G. Knepley Collective on MPI_Comm 8938221697SMatthew G. Knepley 9038221697SMatthew G. Knepley Input Parameter: 9138221697SMatthew G. Knepley . dm - The original DM object 9238221697SMatthew G. Knepley 9338221697SMatthew G. Knepley Output Parameter: 9438221697SMatthew G. Knepley . newdm - The new DM object 9538221697SMatthew G. Knepley 9638221697SMatthew G. Knepley Level: beginner 9738221697SMatthew G. Knepley 9838221697SMatthew G. Knepley .keywords: DM, topology, create 9938221697SMatthew G. Knepley @*/ 10038221697SMatthew G. Knepley PetscErrorCode DMClone(DM dm, DM *newdm) 10138221697SMatthew G. Knepley { 10238221697SMatthew G. Knepley PetscSF sf; 10338221697SMatthew G. Knepley Vec coords; 10438221697SMatthew G. Knepley void *ctx; 1051de53e9aSMatthew G. Knepley PetscInt dim; 10638221697SMatthew G. Knepley PetscErrorCode ierr; 10738221697SMatthew G. Knepley 10838221697SMatthew G. Knepley PetscFunctionBegin; 10938221697SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 11038221697SMatthew G. Knepley PetscValidPointer(newdm,2); 11138221697SMatthew G. Knepley ierr = DMCreate(PetscObjectComm((PetscObject) dm), newdm);CHKERRQ(ierr); 112c58f1c22SToby Isaac ierr = PetscFree((*newdm)->labels);CHKERRQ(ierr); 113c58f1c22SToby Isaac dm->labels->refct++; 114c58f1c22SToby Isaac (*newdm)->labels = dm->labels; 115c58f1c22SToby Isaac (*newdm)->depthLabel = dm->depthLabel; 1161de53e9aSMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 1171de53e9aSMatthew G. Knepley ierr = DMSetDimension(*newdm, dim);CHKERRQ(ierr); 11838221697SMatthew G. Knepley if (dm->ops->clone) { 11938221697SMatthew G. Knepley ierr = (*dm->ops->clone)(dm, newdm);CHKERRQ(ierr); 12038221697SMatthew G. Knepley } 1213f22bcbcSToby Isaac (*newdm)->setupcalled = dm->setupcalled; 12238221697SMatthew G. Knepley ierr = DMGetPointSF(dm, &sf);CHKERRQ(ierr); 12338221697SMatthew G. Knepley ierr = DMSetPointSF(*newdm, sf);CHKERRQ(ierr); 12438221697SMatthew G. Knepley ierr = DMGetApplicationContext(dm, &ctx);CHKERRQ(ierr); 12538221697SMatthew G. Knepley ierr = DMSetApplicationContext(*newdm, ctx);CHKERRQ(ierr); 126be4c1c3eSMatthew G. Knepley if (dm->coordinateDM) { 127be4c1c3eSMatthew G. Knepley DM ncdm; 128be4c1c3eSMatthew G. Knepley PetscSection cs; 1295a0206caSToby Isaac PetscInt pEnd = -1, pEndMax = -1; 130be4c1c3eSMatthew G. Knepley 131be4c1c3eSMatthew G. Knepley ierr = DMGetDefaultSection(dm->coordinateDM, &cs);CHKERRQ(ierr); 132be4c1c3eSMatthew G. Knepley if (cs) {ierr = PetscSectionGetChart(cs, NULL, &pEnd);CHKERRQ(ierr);} 1335a0206caSToby Isaac ierr = MPI_Allreduce(&pEnd,&pEndMax,1,MPIU_INT,MPI_MAX,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 1345a0206caSToby Isaac if (pEndMax >= 0) { 135be4c1c3eSMatthew G. Knepley ierr = DMClone(dm->coordinateDM, &ncdm);CHKERRQ(ierr); 13613bffc4cSMatthew G. Knepley ierr = DMSetDefaultSection(ncdm, cs);CHKERRQ(ierr); 137a61e840bSMatthew G. Knepley ierr = DMSetCoordinateDM(*newdm, ncdm);CHKERRQ(ierr); 138be4c1c3eSMatthew G. Knepley ierr = DMDestroy(&ncdm);CHKERRQ(ierr); 139be4c1c3eSMatthew G. Knepley } 140be4c1c3eSMatthew G. Knepley } 14138221697SMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coords);CHKERRQ(ierr); 14238221697SMatthew G. Knepley if (coords) { 14338221697SMatthew G. Knepley ierr = DMSetCoordinatesLocal(*newdm, coords);CHKERRQ(ierr); 14438221697SMatthew G. Knepley } else { 14538221697SMatthew G. Knepley ierr = DMGetCoordinates(dm, &coords);CHKERRQ(ierr); 14638221697SMatthew G. Knepley if (coords) {ierr = DMSetCoordinates(*newdm, coords);CHKERRQ(ierr);} 14738221697SMatthew G. Knepley } 148c6b900c6SMatthew G. Knepley if (dm->maxCell) { 149c6b900c6SMatthew G. Knepley const PetscReal *maxCell, *L; 1505dc8c3f7SMatthew G. Knepley const DMBoundaryType *bd; 1515dc8c3f7SMatthew G. Knepley ierr = DMGetPeriodicity(dm, &maxCell, &L, &bd);CHKERRQ(ierr); 1525dc8c3f7SMatthew G. Knepley ierr = DMSetPeriodicity(*newdm, maxCell, L, bd);CHKERRQ(ierr); 153c6b900c6SMatthew G. Knepley } 15438221697SMatthew G. Knepley PetscFunctionReturn(0); 15538221697SMatthew G. Knepley } 15638221697SMatthew G. Knepley 15738221697SMatthew G. Knepley #undef __FUNCT__ 1589a42bb27SBarry Smith #define __FUNCT__ "DMSetVecType" 1599a42bb27SBarry Smith /*@C 160564755cdSBarry Smith DMSetVecType - Sets the type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() 1619a42bb27SBarry Smith 1628472ad0fSDave May Logically Collective on DM 1639a42bb27SBarry Smith 1649a42bb27SBarry Smith Input Parameter: 1659a42bb27SBarry Smith + da - initial distributed array 1668154be41SBarry Smith . ctype - the vector type, currently either VECSTANDARD or VECCUSP 1679a42bb27SBarry Smith 1689a42bb27SBarry Smith Options Database: 169dd85299cSBarry Smith . -dm_vec_type ctype 1709a42bb27SBarry Smith 1719a42bb27SBarry Smith Level: intermediate 1729a42bb27SBarry Smith 1738472ad0fSDave May .seealso: DMCreate(), DMDestroy(), DM, DMDAInterpolationType, VecType, DMGetVecType() 1749a42bb27SBarry Smith @*/ 17519fd82e9SBarry Smith PetscErrorCode DMSetVecType(DM da,VecType ctype) 1769a42bb27SBarry Smith { 1779a42bb27SBarry Smith PetscErrorCode ierr; 1789a42bb27SBarry Smith 1799a42bb27SBarry Smith PetscFunctionBegin; 1809a42bb27SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 1819a42bb27SBarry Smith ierr = PetscFree(da->vectype);CHKERRQ(ierr); 18219fd82e9SBarry Smith ierr = PetscStrallocpy(ctype,(char**)&da->vectype);CHKERRQ(ierr); 1839a42bb27SBarry Smith PetscFunctionReturn(0); 1849a42bb27SBarry Smith } 1859a42bb27SBarry Smith 1869a42bb27SBarry Smith #undef __FUNCT__ 187c0dedaeaSBarry Smith #define __FUNCT__ "DMGetVecType" 188c0dedaeaSBarry Smith /*@C 189c0dedaeaSBarry Smith DMGetVecType - Gets the type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() 190c0dedaeaSBarry Smith 1918472ad0fSDave May Logically Collective on DM 192c0dedaeaSBarry Smith 193c0dedaeaSBarry Smith Input Parameter: 194c0dedaeaSBarry Smith . da - initial distributed array 195c0dedaeaSBarry Smith 196c0dedaeaSBarry Smith Output Parameter: 197c0dedaeaSBarry Smith . ctype - the vector type 198c0dedaeaSBarry Smith 199c0dedaeaSBarry Smith Level: intermediate 200c0dedaeaSBarry Smith 2018472ad0fSDave May .seealso: DMCreate(), DMDestroy(), DM, DMDAInterpolationType, VecType 202c0dedaeaSBarry Smith @*/ 203c0dedaeaSBarry Smith PetscErrorCode DMGetVecType(DM da,VecType *ctype) 204c0dedaeaSBarry Smith { 205c0dedaeaSBarry Smith PetscFunctionBegin; 206c0dedaeaSBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 207c0dedaeaSBarry Smith *ctype = da->vectype; 208c0dedaeaSBarry Smith PetscFunctionReturn(0); 209c0dedaeaSBarry Smith } 210c0dedaeaSBarry Smith 211c0dedaeaSBarry Smith #undef __FUNCT__ 2125f1ad066SMatthew G Knepley #define __FUNCT__ "VecGetDM" 2135f1ad066SMatthew G Knepley /*@ 21434f98d34SBarry Smith VecGetDM - Gets the DM defining the data layout of the vector 2155f1ad066SMatthew G Knepley 2165f1ad066SMatthew G Knepley Not collective 2175f1ad066SMatthew G Knepley 2185f1ad066SMatthew G Knepley Input Parameter: 2195f1ad066SMatthew G Knepley . v - The Vec 2205f1ad066SMatthew G Knepley 2215f1ad066SMatthew G Knepley Output Parameter: 2225f1ad066SMatthew G Knepley . dm - The DM 2235f1ad066SMatthew G Knepley 2245f1ad066SMatthew G Knepley Level: intermediate 2255f1ad066SMatthew G Knepley 2265f1ad066SMatthew G Knepley .seealso: VecSetDM(), DMGetLocalVector(), DMGetGlobalVector(), DMSetVecType() 2275f1ad066SMatthew G Knepley @*/ 2285f1ad066SMatthew G Knepley PetscErrorCode VecGetDM(Vec v, DM *dm) 2295f1ad066SMatthew G Knepley { 2305f1ad066SMatthew G Knepley PetscErrorCode ierr; 2315f1ad066SMatthew G Knepley 2325f1ad066SMatthew G Knepley PetscFunctionBegin; 2335f1ad066SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,1); 2345f1ad066SMatthew G Knepley PetscValidPointer(dm,2); 2355f1ad066SMatthew G Knepley ierr = PetscObjectQuery((PetscObject) v, "__PETSc_dm", (PetscObject*) dm);CHKERRQ(ierr); 2365f1ad066SMatthew G Knepley PetscFunctionReturn(0); 2375f1ad066SMatthew G Knepley } 2385f1ad066SMatthew G Knepley 2395f1ad066SMatthew G Knepley #undef __FUNCT__ 2405f1ad066SMatthew G Knepley #define __FUNCT__ "VecSetDM" 2415f1ad066SMatthew G Knepley /*@ 242d9805387SMatthew G. Knepley VecSetDM - Sets the DM defining the data layout of the vector. 2435f1ad066SMatthew G Knepley 2445f1ad066SMatthew G Knepley Not collective 2455f1ad066SMatthew G Knepley 2465f1ad066SMatthew G Knepley Input Parameters: 2475f1ad066SMatthew G Knepley + v - The Vec 2485f1ad066SMatthew G Knepley - dm - The DM 2495f1ad066SMatthew G Knepley 250d9805387SMatthew G. Knepley Note: This is NOT the same as DMCreateGlobalVector() since it does not change the view methods or perform other customization, but merely sets the DM member. 251d9805387SMatthew G. Knepley 2525f1ad066SMatthew G Knepley Level: intermediate 2535f1ad066SMatthew G Knepley 2545f1ad066SMatthew G Knepley .seealso: VecGetDM(), DMGetLocalVector(), DMGetGlobalVector(), DMSetVecType() 2555f1ad066SMatthew G Knepley @*/ 2565f1ad066SMatthew G Knepley PetscErrorCode VecSetDM(Vec v, DM dm) 2575f1ad066SMatthew G Knepley { 2585f1ad066SMatthew G Knepley PetscErrorCode ierr; 2595f1ad066SMatthew G Knepley 2605f1ad066SMatthew G Knepley PetscFunctionBegin; 2615f1ad066SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,1); 262d7f50e27SLisandro Dalcin if (dm) PetscValidHeaderSpecific(dm,DM_CLASSID,2); 2635f1ad066SMatthew G Knepley ierr = PetscObjectCompose((PetscObject) v, "__PETSc_dm", (PetscObject) dm);CHKERRQ(ierr); 2645f1ad066SMatthew G Knepley PetscFunctionReturn(0); 2655f1ad066SMatthew G Knepley } 2665f1ad066SMatthew G Knepley 2675f1ad066SMatthew G Knepley #undef __FUNCT__ 268521d9a4cSLisandro Dalcin #define __FUNCT__ "DMSetMatType" 269521d9a4cSLisandro Dalcin /*@C 270521d9a4cSLisandro Dalcin DMSetMatType - Sets the type of matrix created with DMCreateMatrix() 271521d9a4cSLisandro Dalcin 272521d9a4cSLisandro Dalcin Logically Collective on DM 273521d9a4cSLisandro Dalcin 274521d9a4cSLisandro Dalcin Input Parameter: 275521d9a4cSLisandro Dalcin + dm - the DM context 276521d9a4cSLisandro Dalcin . ctype - the matrix type 277521d9a4cSLisandro Dalcin 278521d9a4cSLisandro Dalcin Options Database: 279521d9a4cSLisandro Dalcin . -dm_mat_type ctype 280521d9a4cSLisandro Dalcin 281521d9a4cSLisandro Dalcin Level: intermediate 282521d9a4cSLisandro Dalcin 283c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateMatrix(), DMSetMatrixPreallocateOnly(), MatType, DMGetMatType() 284521d9a4cSLisandro Dalcin @*/ 28519fd82e9SBarry Smith PetscErrorCode DMSetMatType(DM dm,MatType ctype) 286521d9a4cSLisandro Dalcin { 287521d9a4cSLisandro Dalcin PetscErrorCode ierr; 28888f0584fSBarry Smith 289521d9a4cSLisandro Dalcin PetscFunctionBegin; 290521d9a4cSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 291521d9a4cSLisandro Dalcin ierr = PetscFree(dm->mattype);CHKERRQ(ierr); 29219fd82e9SBarry Smith ierr = PetscStrallocpy(ctype,(char**)&dm->mattype);CHKERRQ(ierr); 293521d9a4cSLisandro Dalcin PetscFunctionReturn(0); 294521d9a4cSLisandro Dalcin } 295521d9a4cSLisandro Dalcin 296521d9a4cSLisandro Dalcin #undef __FUNCT__ 297c0dedaeaSBarry Smith #define __FUNCT__ "DMGetMatType" 298c0dedaeaSBarry Smith /*@C 299c0dedaeaSBarry Smith DMGetMatType - Gets the type of matrix created with DMCreateMatrix() 300c0dedaeaSBarry Smith 301c0dedaeaSBarry Smith Logically Collective on DM 302c0dedaeaSBarry Smith 303c0dedaeaSBarry Smith Input Parameter: 304c0dedaeaSBarry Smith . dm - the DM context 305c0dedaeaSBarry Smith 306c0dedaeaSBarry Smith Output Parameter: 307c0dedaeaSBarry Smith . ctype - the matrix type 308c0dedaeaSBarry Smith 309c0dedaeaSBarry Smith Options Database: 310c0dedaeaSBarry Smith . -dm_mat_type ctype 311c0dedaeaSBarry Smith 312c0dedaeaSBarry Smith Level: intermediate 313c0dedaeaSBarry Smith 314c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateMatrix(), DMSetMatrixPreallocateOnly(), MatType, DMSetMatType() 315c0dedaeaSBarry Smith @*/ 316c0dedaeaSBarry Smith PetscErrorCode DMGetMatType(DM dm,MatType *ctype) 317c0dedaeaSBarry Smith { 318c0dedaeaSBarry Smith PetscFunctionBegin; 319c0dedaeaSBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 320c0dedaeaSBarry Smith *ctype = dm->mattype; 321c0dedaeaSBarry Smith PetscFunctionReturn(0); 322c0dedaeaSBarry Smith } 323c0dedaeaSBarry Smith 324c0dedaeaSBarry Smith #undef __FUNCT__ 325c688c046SMatthew G Knepley #define __FUNCT__ "MatGetDM" 326c688c046SMatthew G Knepley /*@ 32734f98d34SBarry Smith MatGetDM - Gets the DM defining the data layout of the matrix 328c688c046SMatthew G Knepley 329c688c046SMatthew G Knepley Not collective 330c688c046SMatthew G Knepley 331c688c046SMatthew G Knepley Input Parameter: 332c688c046SMatthew G Knepley . A - The Mat 333c688c046SMatthew G Knepley 334c688c046SMatthew G Knepley Output Parameter: 335c688c046SMatthew G Knepley . dm - The DM 336c688c046SMatthew G Knepley 337c688c046SMatthew G Knepley Level: intermediate 338c688c046SMatthew G Knepley 339c688c046SMatthew G Knepley .seealso: MatSetDM(), DMCreateMatrix(), DMSetMatType() 340c688c046SMatthew G Knepley @*/ 341c688c046SMatthew G Knepley PetscErrorCode MatGetDM(Mat A, DM *dm) 342c688c046SMatthew G Knepley { 343c688c046SMatthew G Knepley PetscErrorCode ierr; 344c688c046SMatthew G Knepley 345c688c046SMatthew G Knepley PetscFunctionBegin; 346c688c046SMatthew G Knepley PetscValidHeaderSpecific(A,MAT_CLASSID,1); 347c688c046SMatthew G Knepley PetscValidPointer(dm,2); 348c688c046SMatthew G Knepley ierr = PetscObjectQuery((PetscObject) A, "__PETSc_dm", (PetscObject*) dm);CHKERRQ(ierr); 349c688c046SMatthew G Knepley PetscFunctionReturn(0); 350c688c046SMatthew G Knepley } 351c688c046SMatthew G Knepley 352c688c046SMatthew G Knepley #undef __FUNCT__ 353c688c046SMatthew G Knepley #define __FUNCT__ "MatSetDM" 354c688c046SMatthew G Knepley /*@ 355c688c046SMatthew G Knepley MatSetDM - Sets the DM defining the data layout of the matrix 356c688c046SMatthew G Knepley 357c688c046SMatthew G Knepley Not collective 358c688c046SMatthew G Knepley 359c688c046SMatthew G Knepley Input Parameters: 360c688c046SMatthew G Knepley + A - The Mat 361c688c046SMatthew G Knepley - dm - The DM 362c688c046SMatthew G Knepley 363c688c046SMatthew G Knepley Level: intermediate 364c688c046SMatthew G Knepley 365c688c046SMatthew G Knepley .seealso: MatGetDM(), DMCreateMatrix(), DMSetMatType() 366c688c046SMatthew G Knepley @*/ 367c688c046SMatthew G Knepley PetscErrorCode MatSetDM(Mat A, DM dm) 368c688c046SMatthew G Knepley { 369c688c046SMatthew G Knepley PetscErrorCode ierr; 370c688c046SMatthew G Knepley 371c688c046SMatthew G Knepley PetscFunctionBegin; 372c688c046SMatthew G Knepley PetscValidHeaderSpecific(A,MAT_CLASSID,1); 3738865f1eaSKarl Rupp if (dm) PetscValidHeaderSpecific(dm,DM_CLASSID,2); 374c688c046SMatthew G Knepley ierr = PetscObjectCompose((PetscObject) A, "__PETSc_dm", (PetscObject) dm);CHKERRQ(ierr); 375c688c046SMatthew G Knepley PetscFunctionReturn(0); 376c688c046SMatthew G Knepley } 377c688c046SMatthew G Knepley 378c688c046SMatthew G Knepley #undef __FUNCT__ 3799a42bb27SBarry Smith #define __FUNCT__ "DMSetOptionsPrefix" 3809a42bb27SBarry Smith /*@C 3819a42bb27SBarry Smith DMSetOptionsPrefix - Sets the prefix used for searching for all 3826757b960SDave May DM options in the database. 3839a42bb27SBarry Smith 3848353ddbbSDave May Logically Collective on DM 3859a42bb27SBarry Smith 3869a42bb27SBarry Smith Input Parameter: 3878353ddbbSDave May + da - the DM context 3889a42bb27SBarry Smith - prefix - the prefix to prepend to all option names 3899a42bb27SBarry Smith 3909a42bb27SBarry Smith Notes: 3919a42bb27SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 3929a42bb27SBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 3939a42bb27SBarry Smith 3949a42bb27SBarry Smith Level: advanced 3959a42bb27SBarry Smith 3968353ddbbSDave May .keywords: DM, set, options, prefix, database 3979a42bb27SBarry Smith 3989a42bb27SBarry Smith .seealso: DMSetFromOptions() 3999a42bb27SBarry Smith @*/ 4007087cfbeSBarry Smith PetscErrorCode DMSetOptionsPrefix(DM dm,const char prefix[]) 4019a42bb27SBarry Smith { 4029a42bb27SBarry Smith PetscErrorCode ierr; 4039a42bb27SBarry Smith 4049a42bb27SBarry Smith PetscFunctionBegin; 4059a42bb27SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4069a42bb27SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)dm,prefix);CHKERRQ(ierr); 407691be533SLawrence Mitchell if (dm->sf) { 408691be533SLawrence Mitchell ierr = PetscObjectSetOptionsPrefix((PetscObject)dm->sf,prefix);CHKERRQ(ierr); 409691be533SLawrence Mitchell } 410691be533SLawrence Mitchell if (dm->defaultSF) { 411691be533SLawrence Mitchell ierr = PetscObjectSetOptionsPrefix((PetscObject)dm->defaultSF,prefix);CHKERRQ(ierr); 412691be533SLawrence Mitchell } 4139a42bb27SBarry Smith PetscFunctionReturn(0); 4149a42bb27SBarry Smith } 4159a42bb27SBarry Smith 4169a42bb27SBarry Smith #undef __FUNCT__ 41731697293SDave May #define __FUNCT__ "DMAppendOptionsPrefix" 41831697293SDave May /*@C 41931697293SDave May DMAppendOptionsPrefix - Appends to the prefix used for searching for all 42031697293SDave May DM options in the database. 42131697293SDave May 42231697293SDave May Logically Collective on DM 42331697293SDave May 42431697293SDave May Input Parameters: 42531697293SDave May + dm - the DM context 42631697293SDave May - prefix - the prefix string to prepend to all DM option requests 42731697293SDave May 42831697293SDave May Notes: 42931697293SDave May A hyphen (-) must NOT be given at the beginning of the prefix name. 43031697293SDave May The first character of all runtime options is AUTOMATICALLY the hyphen. 43131697293SDave May 43231697293SDave May Level: advanced 43331697293SDave May 43431697293SDave May .keywords: DM, append, options, prefix, database 43531697293SDave May 43631697293SDave May .seealso: DMSetOptionsPrefix(), DMGetOptionsPrefix() 43731697293SDave May @*/ 43831697293SDave May PetscErrorCode DMAppendOptionsPrefix(DM dm,const char prefix[]) 43931697293SDave May { 44031697293SDave May PetscErrorCode ierr; 44131697293SDave May 44231697293SDave May PetscFunctionBegin; 44331697293SDave May PetscValidHeaderSpecific(dm,DM_CLASSID,1); 44431697293SDave May ierr = PetscObjectAppendOptionsPrefix((PetscObject)dm,prefix);CHKERRQ(ierr); 44531697293SDave May PetscFunctionReturn(0); 44631697293SDave May } 44731697293SDave May 44831697293SDave May #undef __FUNCT__ 44931697293SDave May #define __FUNCT__ "DMGetOptionsPrefix" 45031697293SDave May /*@C 45131697293SDave May DMGetOptionsPrefix - Gets the prefix used for searching for all 45231697293SDave May DM options in the database. 45331697293SDave May 45431697293SDave May Not Collective 45531697293SDave May 45631697293SDave May Input Parameters: 45731697293SDave May . dm - the DM context 45831697293SDave May 45931697293SDave May Output Parameters: 46031697293SDave May . prefix - pointer to the prefix string used is returned 46131697293SDave May 46231697293SDave May Notes: On the fortran side, the user should pass in a string 'prefix' of 46331697293SDave May sufficient length to hold the prefix. 46431697293SDave May 46531697293SDave May Level: advanced 46631697293SDave May 46731697293SDave May .keywords: DM, set, options, prefix, database 46831697293SDave May 46931697293SDave May .seealso: DMSetOptionsPrefix(), DMAppendOptionsPrefix() 47031697293SDave May @*/ 47131697293SDave May PetscErrorCode DMGetOptionsPrefix(DM dm,const char *prefix[]) 47231697293SDave May { 47331697293SDave May PetscErrorCode ierr; 47431697293SDave May 47531697293SDave May PetscFunctionBegin; 47631697293SDave May PetscValidHeaderSpecific(dm,DM_CLASSID,1); 47731697293SDave May ierr = PetscObjectGetOptionsPrefix((PetscObject)dm,prefix);CHKERRQ(ierr); 47831697293SDave May PetscFunctionReturn(0); 47931697293SDave May } 48031697293SDave May 48131697293SDave May #undef __FUNCT__ 48288bdff64SToby Isaac #define __FUNCT__ "DMCountNonCyclicReferences" 48388bdff64SToby Isaac static PetscErrorCode DMCountNonCyclicReferences(DM dm, PetscBool recurseCoarse, PetscBool recurseFine, PetscInt *ncrefct) 48488bdff64SToby Isaac { 48588bdff64SToby Isaac PetscInt i, refct = ((PetscObject) dm)->refct; 48688bdff64SToby Isaac DMNamedVecLink nlink; 48788bdff64SToby Isaac PetscErrorCode ierr; 48888bdff64SToby Isaac 48988bdff64SToby Isaac PetscFunctionBegin; 49088bdff64SToby Isaac /* count all the circular references of DM and its contained Vecs */ 49188bdff64SToby Isaac for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 49288bdff64SToby Isaac if (dm->localin[i]) refct--; 49388bdff64SToby Isaac if (dm->globalin[i]) refct--; 49488bdff64SToby Isaac } 49588bdff64SToby Isaac for (nlink=dm->namedglobal; nlink; nlink=nlink->next) refct--; 49688bdff64SToby Isaac for (nlink=dm->namedlocal; nlink; nlink=nlink->next) refct--; 49788bdff64SToby Isaac if (dm->x) { 49888bdff64SToby Isaac DM obj; 49988bdff64SToby Isaac ierr = VecGetDM(dm->x, &obj);CHKERRQ(ierr); 50088bdff64SToby Isaac if (obj == dm) refct--; 50188bdff64SToby Isaac } 50288bdff64SToby Isaac if (dm->coarseMesh && dm->coarseMesh->fineMesh == dm) { 50388bdff64SToby Isaac refct--; 50488bdff64SToby Isaac if (recurseCoarse) { 50588bdff64SToby Isaac PetscInt coarseCount; 50688bdff64SToby Isaac 50788bdff64SToby Isaac ierr = DMCountNonCyclicReferences(dm->coarseMesh, PETSC_TRUE, PETSC_FALSE,&coarseCount);CHKERRQ(ierr); 50888bdff64SToby Isaac refct += coarseCount; 50988bdff64SToby Isaac } 51088bdff64SToby Isaac } 51188bdff64SToby Isaac if (dm->fineMesh && dm->fineMesh->coarseMesh == dm) { 51288bdff64SToby Isaac refct--; 51388bdff64SToby Isaac if (recurseFine) { 51488bdff64SToby Isaac PetscInt fineCount; 51588bdff64SToby Isaac 51688bdff64SToby Isaac ierr = DMCountNonCyclicReferences(dm->fineMesh, PETSC_FALSE, PETSC_TRUE,&fineCount);CHKERRQ(ierr); 51788bdff64SToby Isaac refct += fineCount; 51888bdff64SToby Isaac } 51988bdff64SToby Isaac } 52088bdff64SToby Isaac *ncrefct = refct; 52188bdff64SToby Isaac PetscFunctionReturn(0); 52288bdff64SToby Isaac } 52388bdff64SToby Isaac 524bcc5ffd9SToby Isaac PetscErrorCode DMBoundaryDestroy(DMBoundaryLinkList *boundary); 525a6ba4734SToby Isaac 52688bdff64SToby Isaac #undef __FUNCT__ 527354557abSToby Isaac #define __FUNCT__ "DMDestroyLabelLinkList" 528354557abSToby Isaac PetscErrorCode DMDestroyLabelLinkList(DM dm) 529354557abSToby Isaac { 530354557abSToby Isaac PetscErrorCode ierr; 531354557abSToby Isaac 532354557abSToby Isaac PetscFunctionBegin; 533354557abSToby Isaac if (!--(dm->labels->refct)) { 534354557abSToby Isaac DMLabelLink next = dm->labels->next; 535354557abSToby Isaac 536354557abSToby Isaac /* destroy the labels */ 537354557abSToby Isaac while (next) { 538354557abSToby Isaac DMLabelLink tmp = next->next; 539354557abSToby Isaac 540354557abSToby Isaac ierr = DMLabelDestroy(&next->label);CHKERRQ(ierr); 541354557abSToby Isaac ierr = PetscFree(next);CHKERRQ(ierr); 542354557abSToby Isaac next = tmp; 543354557abSToby Isaac } 544354557abSToby Isaac ierr = PetscFree(dm->labels);CHKERRQ(ierr); 545354557abSToby Isaac } 546354557abSToby Isaac PetscFunctionReturn(0); 547354557abSToby Isaac } 548354557abSToby Isaac 549354557abSToby Isaac #undef __FUNCT__ 55047c6ae99SBarry Smith #define __FUNCT__ "DMDestroy" 55147c6ae99SBarry Smith /*@ 5528472ad0fSDave May DMDestroy - Destroys a vector packer or DM. 55347c6ae99SBarry Smith 55447c6ae99SBarry Smith Collective on DM 55547c6ae99SBarry Smith 55647c6ae99SBarry Smith Input Parameter: 55747c6ae99SBarry Smith . dm - the DM object to destroy 55847c6ae99SBarry Smith 55947c6ae99SBarry Smith Level: developer 56047c6ae99SBarry Smith 561e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 56247c6ae99SBarry Smith 56347c6ae99SBarry Smith @*/ 564fcfd50ebSBarry Smith PetscErrorCode DMDestroy(DM *dm) 56547c6ae99SBarry Smith { 56688bdff64SToby Isaac PetscInt i, cnt; 567dfe15315SJed Brown DMNamedVecLink nlink,nnext; 56847c6ae99SBarry Smith PetscErrorCode ierr; 56947c6ae99SBarry Smith 57047c6ae99SBarry Smith PetscFunctionBegin; 5716bf464f9SBarry Smith if (!*dm) PetscFunctionReturn(0); 5726bf464f9SBarry Smith PetscValidHeaderSpecific((*dm),DM_CLASSID,1); 57387e657c6SBarry Smith 57488bdff64SToby Isaac /* count all non-cyclic references in the doubly-linked list of coarse<->fine meshes */ 57588bdff64SToby Isaac ierr = DMCountNonCyclicReferences(*dm,PETSC_TRUE,PETSC_TRUE,&cnt);CHKERRQ(ierr); 57688bdff64SToby Isaac --((PetscObject)(*dm))->refct; 57788bdff64SToby Isaac if (--cnt > 0) {*dm = 0; PetscFunctionReturn(0);} 578732e2eb9SMatthew G Knepley /* 579732e2eb9SMatthew G Knepley Need this test because the dm references the vectors that 580732e2eb9SMatthew G Knepley reference the dm, so destroying the dm calls destroy on the 581732e2eb9SMatthew G Knepley vectors that cause another destroy on the dm 582732e2eb9SMatthew G Knepley */ 5836bf464f9SBarry Smith if (((PetscObject)(*dm))->refct < 0) PetscFunctionReturn(0); 5846bf464f9SBarry Smith ((PetscObject) (*dm))->refct = 0; 585732e2eb9SMatthew G Knepley for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 5866bf464f9SBarry Smith if ((*dm)->localout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a local vector obtained with DMGetLocalVector()"); 5876bf464f9SBarry Smith ierr = VecDestroy(&(*dm)->localin[i]);CHKERRQ(ierr); 588732e2eb9SMatthew G Knepley } 589f490541aSPeter Brune nnext=(*dm)->namedglobal; 5900298fd71SBarry Smith (*dm)->namedglobal = NULL; 591f490541aSPeter Brune for (nlink=nnext; nlink; nlink=nnext) { /* Destroy the named vectors */ 5922348bcf4SPeter Brune nnext = nlink->next; 5932348bcf4SPeter Brune if (nlink->status != DMVEC_STATUS_IN) SETERRQ1(((PetscObject)*dm)->comm,PETSC_ERR_ARG_WRONGSTATE,"DM still has Vec named '%s' checked out",nlink->name); 5942348bcf4SPeter Brune ierr = PetscFree(nlink->name);CHKERRQ(ierr); 5952348bcf4SPeter Brune ierr = VecDestroy(&nlink->X);CHKERRQ(ierr); 5962348bcf4SPeter Brune ierr = PetscFree(nlink);CHKERRQ(ierr); 5972348bcf4SPeter Brune } 598f490541aSPeter Brune nnext=(*dm)->namedlocal; 5990298fd71SBarry Smith (*dm)->namedlocal = NULL; 600f490541aSPeter Brune for (nlink=nnext; nlink; nlink=nnext) { /* Destroy the named local vectors */ 601f490541aSPeter Brune nnext = nlink->next; 602f490541aSPeter Brune if (nlink->status != DMVEC_STATUS_IN) SETERRQ1(((PetscObject)*dm)->comm,PETSC_ERR_ARG_WRONGSTATE,"DM still has Vec named '%s' checked out",nlink->name); 603f490541aSPeter Brune ierr = PetscFree(nlink->name);CHKERRQ(ierr); 604f490541aSPeter Brune ierr = VecDestroy(&nlink->X);CHKERRQ(ierr); 605f490541aSPeter Brune ierr = PetscFree(nlink);CHKERRQ(ierr); 606f490541aSPeter Brune } 6072348bcf4SPeter Brune 608b17ce1afSJed Brown /* Destroy the list of hooks */ 609c833c3b5SJed Brown { 610c833c3b5SJed Brown DMCoarsenHookLink link,next; 611b17ce1afSJed Brown for (link=(*dm)->coarsenhook; link; link=next) { 612b17ce1afSJed Brown next = link->next; 613b17ce1afSJed Brown ierr = PetscFree(link);CHKERRQ(ierr); 614b17ce1afSJed Brown } 6150298fd71SBarry Smith (*dm)->coarsenhook = NULL; 616c833c3b5SJed Brown } 617c833c3b5SJed Brown { 618c833c3b5SJed Brown DMRefineHookLink link,next; 619c833c3b5SJed Brown for (link=(*dm)->refinehook; link; link=next) { 620c833c3b5SJed Brown next = link->next; 621c833c3b5SJed Brown ierr = PetscFree(link);CHKERRQ(ierr); 622c833c3b5SJed Brown } 6230298fd71SBarry Smith (*dm)->refinehook = NULL; 624c833c3b5SJed Brown } 625be081cd6SPeter Brune { 626be081cd6SPeter Brune DMSubDomainHookLink link,next; 627be081cd6SPeter Brune for (link=(*dm)->subdomainhook; link; link=next) { 628be081cd6SPeter Brune next = link->next; 629be081cd6SPeter Brune ierr = PetscFree(link);CHKERRQ(ierr); 630be081cd6SPeter Brune } 6310298fd71SBarry Smith (*dm)->subdomainhook = NULL; 632be081cd6SPeter Brune } 633baf369e7SPeter Brune { 634baf369e7SPeter Brune DMGlobalToLocalHookLink link,next; 635baf369e7SPeter Brune for (link=(*dm)->gtolhook; link; link=next) { 636baf369e7SPeter Brune next = link->next; 637baf369e7SPeter Brune ierr = PetscFree(link);CHKERRQ(ierr); 638baf369e7SPeter Brune } 6390298fd71SBarry Smith (*dm)->gtolhook = NULL; 640baf369e7SPeter Brune } 641d4d07f1eSToby Isaac { 642d4d07f1eSToby Isaac DMLocalToGlobalHookLink link,next; 643d4d07f1eSToby Isaac for (link=(*dm)->ltoghook; link; link=next) { 644d4d07f1eSToby Isaac next = link->next; 645d4d07f1eSToby Isaac ierr = PetscFree(link);CHKERRQ(ierr); 646d4d07f1eSToby Isaac } 647d4d07f1eSToby Isaac (*dm)->ltoghook = NULL; 648d4d07f1eSToby Isaac } 649aa1993deSMatthew G Knepley /* Destroy the work arrays */ 650aa1993deSMatthew G Knepley { 651aa1993deSMatthew G Knepley DMWorkLink link,next; 652aa1993deSMatthew G Knepley if ((*dm)->workout) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Work array still checked out"); 653aa1993deSMatthew G Knepley for (link=(*dm)->workin; link; link=next) { 654aa1993deSMatthew G Knepley next = link->next; 655aa1993deSMatthew G Knepley ierr = PetscFree(link->mem);CHKERRQ(ierr); 656aa1993deSMatthew G Knepley ierr = PetscFree(link);CHKERRQ(ierr); 657aa1993deSMatthew G Knepley } 6580298fd71SBarry Smith (*dm)->workin = NULL; 659aa1993deSMatthew G Knepley } 660c58f1c22SToby Isaac if (!--((*dm)->labels->refct)) { 661c58f1c22SToby Isaac DMLabelLink next = (*dm)->labels->next; 662c58f1c22SToby Isaac 663c58f1c22SToby Isaac /* destroy the labels */ 664c58f1c22SToby Isaac while (next) { 665c58f1c22SToby Isaac DMLabelLink tmp = next->next; 666c58f1c22SToby Isaac 667c58f1c22SToby Isaac ierr = DMLabelDestroy(&next->label);CHKERRQ(ierr); 668c58f1c22SToby Isaac ierr = PetscFree(next);CHKERRQ(ierr); 669c58f1c22SToby Isaac next = tmp; 670c58f1c22SToby Isaac } 671c58f1c22SToby Isaac ierr = PetscFree((*dm)->labels);CHKERRQ(ierr); 672c58f1c22SToby Isaac } 673bcc5ffd9SToby Isaac ierr = DMBoundaryDestroy(&(*dm)->boundary);CHKERRQ(ierr); 674b17ce1afSJed Brown 67552536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmksp);CHKERRQ(ierr); 67652536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmsnes);CHKERRQ(ierr); 67752536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmts);CHKERRQ(ierr); 67852536dc3SBarry Smith 6791a266240SBarry Smith if ((*dm)->ctx && (*dm)->ctxdestroy) { 6801a266240SBarry Smith ierr = (*(*dm)->ctxdestroy)(&(*dm)->ctx);CHKERRQ(ierr); 6811a266240SBarry Smith } 68287e657c6SBarry Smith ierr = VecDestroy(&(*dm)->x);CHKERRQ(ierr); 68371cd77b2SBarry Smith ierr = MatFDColoringDestroy(&(*dm)->fd);CHKERRQ(ierr); 6844dcab191SBarry Smith ierr = DMClearGlobalVectors(*dm);CHKERRQ(ierr); 6856bf464f9SBarry Smith ierr = ISLocalToGlobalMappingDestroy(&(*dm)->ltogmap);CHKERRQ(ierr); 6866bf464f9SBarry Smith ierr = PetscFree((*dm)->vectype);CHKERRQ(ierr); 687073dac72SJed Brown ierr = PetscFree((*dm)->mattype);CHKERRQ(ierr); 68888ed4aceSMatthew G Knepley 68988ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&(*dm)->defaultSection);CHKERRQ(ierr); 69088ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&(*dm)->defaultGlobalSection);CHKERRQ(ierr); 6918b1ab98fSJed Brown ierr = PetscLayoutDestroy(&(*dm)->map);CHKERRQ(ierr); 692fba222abSToby Isaac ierr = PetscSectionDestroy(&(*dm)->defaultConstraintSection);CHKERRQ(ierr); 693fba222abSToby Isaac ierr = MatDestroy(&(*dm)->defaultConstraintMat);CHKERRQ(ierr); 69488ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&(*dm)->sf);CHKERRQ(ierr); 69588ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&(*dm)->defaultSF);CHKERRQ(ierr); 6968e4ac7eaSMatthew G. Knepley ierr = PetscSFDestroy(&(*dm)->sfNatural);CHKERRQ(ierr); 697af122d2aSMatthew G Knepley 69888bdff64SToby Isaac if ((*dm)->coarseMesh && (*dm)->coarseMesh->fineMesh == *dm) { 69988bdff64SToby Isaac ierr = DMSetFineDM((*dm)->coarseMesh,NULL);CHKERRQ(ierr); 70088bdff64SToby Isaac } 701a8fb8f29SToby Isaac ierr = DMDestroy(&(*dm)->coarseMesh);CHKERRQ(ierr); 70288bdff64SToby Isaac if ((*dm)->fineMesh && (*dm)->fineMesh->coarseMesh == *dm) { 70388bdff64SToby Isaac ierr = DMSetCoarseDM((*dm)->fineMesh,NULL);CHKERRQ(ierr); 70488bdff64SToby Isaac } 70588bdff64SToby Isaac ierr = DMDestroy(&(*dm)->fineMesh);CHKERRQ(ierr); 7066636e97aSMatthew G Knepley ierr = DMDestroy(&(*dm)->coordinateDM);CHKERRQ(ierr); 7076636e97aSMatthew G Knepley ierr = VecDestroy(&(*dm)->coordinates);CHKERRQ(ierr); 7086636e97aSMatthew G Knepley ierr = VecDestroy(&(*dm)->coordinatesLocal);CHKERRQ(ierr); 7095dc8c3f7SMatthew G. Knepley ierr = PetscFree3((*dm)->L,(*dm)->maxCell,(*dm)->bdtype);CHKERRQ(ierr); 7106636e97aSMatthew G Knepley 7112764a2aaSMatthew G. Knepley ierr = PetscDSDestroy(&(*dm)->prob);CHKERRQ(ierr); 71214f150ffSMatthew G. Knepley ierr = DMDestroy(&(*dm)->dmBC);CHKERRQ(ierr); 713e04113cfSBarry Smith /* if memory was published with SAWs then destroy it */ 714e04113cfSBarry Smith ierr = PetscObjectSAWsViewOff((PetscObject)*dm);CHKERRQ(ierr); 715732e2eb9SMatthew G Knepley 7166bf464f9SBarry Smith ierr = (*(*dm)->ops->destroy)(*dm);CHKERRQ(ierr); 717435a35e8SMatthew G Knepley /* We do not destroy (*dm)->data here so that we can reference count backend objects */ 718732e2eb9SMatthew G Knepley ierr = PetscHeaderDestroy(dm);CHKERRQ(ierr); 71947c6ae99SBarry Smith PetscFunctionReturn(0); 72047c6ae99SBarry Smith } 72147c6ae99SBarry Smith 72247c6ae99SBarry Smith #undef __FUNCT__ 723d7bf68aeSBarry Smith #define __FUNCT__ "DMSetUp" 724d7bf68aeSBarry Smith /*@ 725d7bf68aeSBarry Smith DMSetUp - sets up the data structures inside a DM object 726d7bf68aeSBarry Smith 727d7bf68aeSBarry Smith Collective on DM 728d7bf68aeSBarry Smith 729d7bf68aeSBarry Smith Input Parameter: 730d7bf68aeSBarry Smith . dm - the DM object to setup 731d7bf68aeSBarry Smith 732d7bf68aeSBarry Smith Level: developer 733d7bf68aeSBarry Smith 734e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 735d7bf68aeSBarry Smith 736d7bf68aeSBarry Smith @*/ 7377087cfbeSBarry Smith PetscErrorCode DMSetUp(DM dm) 738d7bf68aeSBarry Smith { 739d7bf68aeSBarry Smith PetscErrorCode ierr; 740d7bf68aeSBarry Smith 741d7bf68aeSBarry Smith PetscFunctionBegin; 742171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7438387afaaSJed Brown if (dm->setupcalled) PetscFunctionReturn(0); 744d7bf68aeSBarry Smith if (dm->ops->setup) { 745d7bf68aeSBarry Smith ierr = (*dm->ops->setup)(dm);CHKERRQ(ierr); 746d7bf68aeSBarry Smith } 7478387afaaSJed Brown dm->setupcalled = PETSC_TRUE; 748d7bf68aeSBarry Smith PetscFunctionReturn(0); 749d7bf68aeSBarry Smith } 750d7bf68aeSBarry Smith 751d7bf68aeSBarry Smith #undef __FUNCT__ 752d7bf68aeSBarry Smith #define __FUNCT__ "DMSetFromOptions" 753d7bf68aeSBarry Smith /*@ 754d7bf68aeSBarry Smith DMSetFromOptions - sets parameters in a DM from the options database 755d7bf68aeSBarry Smith 756d7bf68aeSBarry Smith Collective on DM 757d7bf68aeSBarry Smith 758d7bf68aeSBarry Smith Input Parameter: 759d7bf68aeSBarry Smith . dm - the DM object to set options for 760d7bf68aeSBarry Smith 761732e2eb9SMatthew G Knepley Options Database: 7624164ae61SDominic Meiser + -dm_preallocate_only - Only preallocate the matrix for DMCreateMatrix(), but do not fill it with zeros 7634164ae61SDominic Meiser . -dm_vec_type <type> - type of vector to create inside DM 7644164ae61SDominic Meiser . -dm_mat_type <type> - type of matrix to create inside DM 7654164ae61SDominic Meiser - -dm_coloring_type - <global or ghosted> 766732e2eb9SMatthew G Knepley 767d7bf68aeSBarry Smith Level: developer 768d7bf68aeSBarry Smith 769e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 770d7bf68aeSBarry Smith 771d7bf68aeSBarry Smith @*/ 7727087cfbeSBarry Smith PetscErrorCode DMSetFromOptions(DM dm) 773d7bf68aeSBarry Smith { 7747781c08eSBarry Smith char typeName[256]; 775ca266f36SBarry Smith PetscBool flg; 776d7bf68aeSBarry Smith PetscErrorCode ierr; 777d7bf68aeSBarry Smith 778d7bf68aeSBarry Smith PetscFunctionBegin; 779171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 780691be533SLawrence Mitchell if (dm->sf) { 781691be533SLawrence Mitchell ierr = PetscSFSetFromOptions(dm->sf);CHKERRQ(ierr); 782691be533SLawrence Mitchell } 783691be533SLawrence Mitchell if (dm->defaultSF) { 784691be533SLawrence Mitchell ierr = PetscSFSetFromOptions(dm->defaultSF);CHKERRQ(ierr); 785691be533SLawrence Mitchell } 7863194b578SJed Brown ierr = PetscObjectOptionsBegin((PetscObject)dm);CHKERRQ(ierr); 7870298fd71SBarry Smith ierr = PetscOptionsBool("-dm_preallocate_only","only preallocate matrix, but do not set column indices","DMSetMatrixPreallocateOnly",dm->prealloc_only,&dm->prealloc_only,NULL);CHKERRQ(ierr); 788a264d7a6SBarry Smith ierr = PetscOptionsFList("-dm_vec_type","Vector type used for created vectors","DMSetVecType",VecList,dm->vectype,typeName,256,&flg);CHKERRQ(ierr); 789f9ba7244SBarry Smith if (flg) { 790f9ba7244SBarry Smith ierr = DMSetVecType(dm,typeName);CHKERRQ(ierr); 791f9ba7244SBarry Smith } 792a264d7a6SBarry Smith ierr = PetscOptionsFList("-dm_mat_type","Matrix type used for created matrices","DMSetMatType",MatList,dm->mattype ? dm->mattype : typeName,typeName,sizeof(typeName),&flg);CHKERRQ(ierr); 793073dac72SJed Brown if (flg) { 794521d9a4cSLisandro Dalcin ierr = DMSetMatType(dm,typeName);CHKERRQ(ierr); 795073dac72SJed Brown } 7960298fd71SBarry Smith ierr = PetscOptionsEnum("-dm_is_coloring_type","Global or local coloring of Jacobian","ISColoringType",ISColoringTypes,(PetscEnum)dm->coloringtype,(PetscEnum*)&dm->coloringtype,NULL);CHKERRQ(ierr); 797f9ba7244SBarry Smith if (dm->ops->setfromoptions) { 798e55864a3SBarry Smith ierr = (*dm->ops->setfromoptions)(PetscOptionsObject,dm);CHKERRQ(ierr); 799f9ba7244SBarry Smith } 800f9ba7244SBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 8010633abcbSJed Brown ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) dm);CHKERRQ(ierr); 80282fcb398SMatthew G Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 803d7bf68aeSBarry Smith PetscFunctionReturn(0); 804d7bf68aeSBarry Smith } 805d7bf68aeSBarry Smith 806d7bf68aeSBarry Smith #undef __FUNCT__ 80747c6ae99SBarry Smith #define __FUNCT__ "DMView" 808fc9bc008SSatish Balay /*@C 809224748a4SBarry Smith DMView - Views a DM 81047c6ae99SBarry Smith 81147c6ae99SBarry Smith Collective on DM 81247c6ae99SBarry Smith 81347c6ae99SBarry Smith Input Parameter: 81447c6ae99SBarry Smith + dm - the DM object to view 81547c6ae99SBarry Smith - v - the viewer 81647c6ae99SBarry Smith 817224748a4SBarry Smith Level: beginner 81847c6ae99SBarry Smith 819e727c939SJed Brown .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 82047c6ae99SBarry Smith 82147c6ae99SBarry Smith @*/ 8227087cfbeSBarry Smith PetscErrorCode DMView(DM dm,PetscViewer v) 82347c6ae99SBarry Smith { 82447c6ae99SBarry Smith PetscErrorCode ierr; 82532c0f0efSBarry Smith PetscBool isbinary; 82647c6ae99SBarry Smith 82747c6ae99SBarry Smith PetscFunctionBegin; 828171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8293014e516SBarry Smith if (!v) { 830ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)dm),&v);CHKERRQ(ierr); 8313014e516SBarry Smith } 83298c3331eSBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)dm,v);CHKERRQ(ierr); 83332c0f0efSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); 83432c0f0efSBarry Smith if (isbinary) { 83555849f57SBarry Smith PetscInt classid = DM_FILE_CLASSID; 83632c0f0efSBarry Smith char type[256]; 83732c0f0efSBarry Smith 83832c0f0efSBarry Smith ierr = PetscViewerBinaryWrite(v,&classid,1,PETSC_INT,PETSC_FALSE);CHKERRQ(ierr); 83932c0f0efSBarry Smith ierr = PetscStrncpy(type,((PetscObject)dm)->type_name,256);CHKERRQ(ierr); 84032c0f0efSBarry Smith ierr = PetscViewerBinaryWrite(v,type,256,PETSC_CHAR,PETSC_FALSE);CHKERRQ(ierr); 84132c0f0efSBarry Smith } 8420c010503SBarry Smith if (dm->ops->view) { 8430c010503SBarry Smith ierr = (*dm->ops->view)(dm,v);CHKERRQ(ierr); 84447c6ae99SBarry Smith } 84547c6ae99SBarry Smith PetscFunctionReturn(0); 84647c6ae99SBarry Smith } 84747c6ae99SBarry Smith 84847c6ae99SBarry Smith #undef __FUNCT__ 84947c6ae99SBarry Smith #define __FUNCT__ "DMCreateGlobalVector" 85047c6ae99SBarry Smith /*@ 8518472ad0fSDave May DMCreateGlobalVector - Creates a global vector from a DM object 85247c6ae99SBarry Smith 85347c6ae99SBarry Smith Collective on DM 85447c6ae99SBarry Smith 85547c6ae99SBarry Smith Input Parameter: 85647c6ae99SBarry Smith . dm - the DM object 85747c6ae99SBarry Smith 85847c6ae99SBarry Smith Output Parameter: 85947c6ae99SBarry Smith . vec - the global vector 86047c6ae99SBarry Smith 861073dac72SJed Brown Level: beginner 86247c6ae99SBarry Smith 863e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 86447c6ae99SBarry Smith 86547c6ae99SBarry Smith @*/ 8667087cfbeSBarry Smith PetscErrorCode DMCreateGlobalVector(DM dm,Vec *vec) 86747c6ae99SBarry Smith { 86847c6ae99SBarry Smith PetscErrorCode ierr; 86947c6ae99SBarry Smith 87047c6ae99SBarry Smith PetscFunctionBegin; 871171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 87247c6ae99SBarry Smith ierr = (*dm->ops->createglobalvector)(dm,vec);CHKERRQ(ierr); 87347c6ae99SBarry Smith PetscFunctionReturn(0); 87447c6ae99SBarry Smith } 87547c6ae99SBarry Smith 87647c6ae99SBarry Smith #undef __FUNCT__ 87747c6ae99SBarry Smith #define __FUNCT__ "DMCreateLocalVector" 87847c6ae99SBarry Smith /*@ 8798472ad0fSDave May DMCreateLocalVector - Creates a local vector from a DM object 88047c6ae99SBarry Smith 88147c6ae99SBarry Smith Not Collective 88247c6ae99SBarry Smith 88347c6ae99SBarry Smith Input Parameter: 88447c6ae99SBarry Smith . dm - the DM object 88547c6ae99SBarry Smith 88647c6ae99SBarry Smith Output Parameter: 88747c6ae99SBarry Smith . vec - the local vector 88847c6ae99SBarry Smith 889073dac72SJed Brown Level: beginner 89047c6ae99SBarry Smith 891e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 89247c6ae99SBarry Smith 89347c6ae99SBarry Smith @*/ 8947087cfbeSBarry Smith PetscErrorCode DMCreateLocalVector(DM dm,Vec *vec) 89547c6ae99SBarry Smith { 89647c6ae99SBarry Smith PetscErrorCode ierr; 89747c6ae99SBarry Smith 89847c6ae99SBarry Smith PetscFunctionBegin; 899171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 90047c6ae99SBarry Smith ierr = (*dm->ops->createlocalvector)(dm,vec);CHKERRQ(ierr); 90147c6ae99SBarry Smith PetscFunctionReturn(0); 90247c6ae99SBarry Smith } 90347c6ae99SBarry Smith 90447c6ae99SBarry Smith #undef __FUNCT__ 9051411c6eeSJed Brown #define __FUNCT__ "DMGetLocalToGlobalMapping" 9061411c6eeSJed Brown /*@ 9071411c6eeSJed Brown DMGetLocalToGlobalMapping - Accesses the local-to-global mapping in a DM. 9081411c6eeSJed Brown 9091411c6eeSJed Brown Collective on DM 9101411c6eeSJed Brown 9111411c6eeSJed Brown Input Parameter: 9121411c6eeSJed Brown . dm - the DM that provides the mapping 9131411c6eeSJed Brown 9141411c6eeSJed Brown Output Parameter: 9151411c6eeSJed Brown . ltog - the mapping 9161411c6eeSJed Brown 9171411c6eeSJed Brown Level: intermediate 9181411c6eeSJed Brown 9191411c6eeSJed Brown Notes: 9201411c6eeSJed Brown This mapping can then be used by VecSetLocalToGlobalMapping() or 9211411c6eeSJed Brown MatSetLocalToGlobalMapping(). 9221411c6eeSJed Brown 923fc31e74dSBarry Smith .seealso: DMCreateLocalVector() 9241411c6eeSJed Brown @*/ 9257087cfbeSBarry Smith PetscErrorCode DMGetLocalToGlobalMapping(DM dm,ISLocalToGlobalMapping *ltog) 9261411c6eeSJed Brown { 927bff27382SMatthew G. Knepley PetscInt bs = -1, bsLocal, bsMin, bsMax; 9281411c6eeSJed Brown PetscErrorCode ierr; 9291411c6eeSJed Brown 9301411c6eeSJed Brown PetscFunctionBegin; 9311411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 9321411c6eeSJed Brown PetscValidPointer(ltog,2); 9331411c6eeSJed Brown if (!dm->ltogmap) { 93437d0c07bSMatthew G Knepley PetscSection section, sectionGlobal; 93537d0c07bSMatthew G Knepley 93637d0c07bSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 93737d0c07bSMatthew G Knepley if (section) { 93837d0c07bSMatthew G Knepley PetscInt *ltog; 93937d0c07bSMatthew G Knepley PetscInt pStart, pEnd, size, p, l; 94037d0c07bSMatthew G Knepley 94137d0c07bSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 94237d0c07bSMatthew G Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 94337d0c07bSMatthew G Knepley ierr = PetscSectionGetStorageSize(section, &size);CHKERRQ(ierr); 944785e854fSJed Brown ierr = PetscMalloc1(size, <og);CHKERRQ(ierr); /* We want the local+overlap size */ 94537d0c07bSMatthew G Knepley for (p = pStart, l = 0; p < pEnd; ++p) { 946b190aa46SMatthew G. Knepley PetscInt bdof, cdof, dof, off, c; 94737d0c07bSMatthew G Knepley 94837d0c07bSMatthew G Knepley /* Should probably use constrained dofs */ 94937d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(section, p, &dof);CHKERRQ(ierr); 95037d0c07bSMatthew G Knepley ierr = PetscSectionGetOffset(sectionGlobal, p, &off);CHKERRQ(ierr); 951b190aa46SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(sectionGlobal, p, &cdof);CHKERRQ(ierr); 9521a7dc684SMatthew G. Knepley /* If you have dofs, and constraints, and they are unequal, we set the blocksize to 1 */ 9531a7dc684SMatthew G. Knepley bdof = cdof && (dof-cdof) ? 1 : dof; 9541a7dc684SMatthew G. Knepley if (dof) { 955b190aa46SMatthew G. Knepley if (bs < 0) {bs = bdof;} 956b190aa46SMatthew G. Knepley else if (bs != bdof) {bs = 1;} 9571a7dc684SMatthew G. Knepley } 95837d0c07bSMatthew G Knepley for (c = 0; c < dof; ++c, ++l) { 95937d0c07bSMatthew G Knepley ltog[l] = off+c; 96037d0c07bSMatthew G Knepley } 96137d0c07bSMatthew G Knepley } 962bff27382SMatthew G. Knepley /* Must have same blocksize on all procs (some might have no points) */ 963bff27382SMatthew G. Knepley bsLocal = bs; 964bff27382SMatthew G. Knepley ierr = MPIU_Allreduce(&bsLocal, &bsMax, 1, MPIU_INT, MPI_MAX, PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 965bff27382SMatthew G. Knepley bsLocal = bs < 0 ? bsMax : bs; 966bff27382SMatthew G. Knepley ierr = MPIU_Allreduce(&bsLocal, &bsMin, 1, MPIU_INT, MPI_MIN, PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 967bff27382SMatthew G. Knepley if (bsMin != bsMax) {bs = 1;} 968bff27382SMatthew G. Knepley else {bs = bsMax;} 969b190aa46SMatthew G. Knepley ierr = ISLocalToGlobalMappingCreate(PETSC_COMM_SELF, bs < 0 ? 1 : bs, size, ltog, PETSC_OWN_POINTER, &dm->ltogmap);CHKERRQ(ierr); 9703bb1ff40SBarry Smith ierr = PetscLogObjectParent((PetscObject)dm, (PetscObject)dm->ltogmap);CHKERRQ(ierr); 97137d0c07bSMatthew G Knepley } else { 972184d77edSJed Brown if (!dm->ops->getlocaltoglobalmapping) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM can not create LocalToGlobalMapping"); 973184d77edSJed Brown ierr = (*dm->ops->getlocaltoglobalmapping)(dm);CHKERRQ(ierr); 9741411c6eeSJed Brown } 97537d0c07bSMatthew G Knepley } 9761411c6eeSJed Brown *ltog = dm->ltogmap; 9771411c6eeSJed Brown PetscFunctionReturn(0); 9781411c6eeSJed Brown } 9791411c6eeSJed Brown 9801411c6eeSJed Brown #undef __FUNCT__ 9811411c6eeSJed Brown #define __FUNCT__ "DMGetBlockSize" 9821411c6eeSJed Brown /*@ 9831411c6eeSJed Brown DMGetBlockSize - Gets the inherent block size associated with a DM 9841411c6eeSJed Brown 9851411c6eeSJed Brown Not Collective 9861411c6eeSJed Brown 9871411c6eeSJed Brown Input Parameter: 9881411c6eeSJed Brown . dm - the DM with block structure 9891411c6eeSJed Brown 9901411c6eeSJed Brown Output Parameter: 9911411c6eeSJed Brown . bs - the block size, 1 implies no exploitable block structure 9921411c6eeSJed Brown 9931411c6eeSJed Brown Level: intermediate 9941411c6eeSJed Brown 995fc31e74dSBarry Smith .seealso: ISCreateBlock(), VecSetBlockSize(), MatSetBlockSize(), DMGetLocalToGlobalMapping() 9961411c6eeSJed Brown @*/ 9977087cfbeSBarry Smith PetscErrorCode DMGetBlockSize(DM dm,PetscInt *bs) 9981411c6eeSJed Brown { 9991411c6eeSJed Brown PetscFunctionBegin; 10001411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 10011411c6eeSJed Brown PetscValidPointer(bs,2); 10021411c6eeSJed Brown if (dm->bs < 1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"DM does not have enough information to provide a block size yet"); 10031411c6eeSJed Brown *bs = dm->bs; 10041411c6eeSJed Brown PetscFunctionReturn(0); 10051411c6eeSJed Brown } 10061411c6eeSJed Brown 10071411c6eeSJed Brown #undef __FUNCT__ 1008e727c939SJed Brown #define __FUNCT__ "DMCreateInterpolation" 100947c6ae99SBarry Smith /*@ 10108472ad0fSDave May DMCreateInterpolation - Gets interpolation matrix between two DM objects 101147c6ae99SBarry Smith 101247c6ae99SBarry Smith Collective on DM 101347c6ae99SBarry Smith 101447c6ae99SBarry Smith Input Parameter: 101547c6ae99SBarry Smith + dm1 - the DM object 101647c6ae99SBarry Smith - dm2 - the second, finer DM object 101747c6ae99SBarry Smith 101847c6ae99SBarry Smith Output Parameter: 101947c6ae99SBarry Smith + mat - the interpolation 102047c6ae99SBarry Smith - vec - the scaling (optional) 102147c6ae99SBarry Smith 102247c6ae99SBarry Smith Level: developer 102347c6ae99SBarry Smith 102485afcc9aSBarry Smith Notes: For DMDA objects this only works for "uniform refinement", that is the refined mesh was obtained DMRefine() or the coarse mesh was obtained by 102585afcc9aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the interpolation. 1026d52bd9f3SBarry Smith 10271f588964SMatthew G Knepley For DMDA objects you can use this interpolation (more precisely the interpolation from the DMGetCoordinateDM()) to interpolate the mesh coordinate vectors 1028d52bd9f3SBarry Smith EXCEPT in the periodic case where it does not make sense since the coordinate vectors are not periodic. 102985afcc9aSBarry Smith 103085afcc9aSBarry Smith 10313ad4599aSBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMRefine(), DMCoarsen(), DMCreateRestriction() 103247c6ae99SBarry Smith 103347c6ae99SBarry Smith @*/ 1034e727c939SJed Brown PetscErrorCode DMCreateInterpolation(DM dm1,DM dm2,Mat *mat,Vec *vec) 103547c6ae99SBarry Smith { 103647c6ae99SBarry Smith PetscErrorCode ierr; 103747c6ae99SBarry Smith 103847c6ae99SBarry Smith PetscFunctionBegin; 1039171400e9SBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 1040171400e9SBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 1041cea54e9dSPatrick Farrell ierr = PetscLogEventBegin(DM_CreateInterpolation,dm1,dm2,0,0);CHKERRQ(ierr); 104225296bd5SBarry Smith ierr = (*dm1->ops->createinterpolation)(dm1,dm2,mat,vec);CHKERRQ(ierr); 1043cea54e9dSPatrick Farrell ierr = PetscLogEventEnd(DM_CreateInterpolation,dm1,dm2,0,0);CHKERRQ(ierr); 104447c6ae99SBarry Smith PetscFunctionReturn(0); 104547c6ae99SBarry Smith } 104647c6ae99SBarry Smith 104747c6ae99SBarry Smith #undef __FUNCT__ 10483ad4599aSBarry Smith #define __FUNCT__ "DMCreateRestriction" 10493ad4599aSBarry Smith /*@ 10503ad4599aSBarry Smith DMCreateRestriction - Gets restriction matrix between two DM objects 10513ad4599aSBarry Smith 10523ad4599aSBarry Smith Collective on DM 10533ad4599aSBarry Smith 10543ad4599aSBarry Smith Input Parameter: 10553ad4599aSBarry Smith + dm1 - the DM object 10563ad4599aSBarry Smith - dm2 - the second, finer DM object 10573ad4599aSBarry Smith 10583ad4599aSBarry Smith Output Parameter: 10593ad4599aSBarry Smith . mat - the restriction 10603ad4599aSBarry Smith 10613ad4599aSBarry Smith 10623ad4599aSBarry Smith Level: developer 10633ad4599aSBarry Smith 10643ad4599aSBarry Smith Notes: For DMDA objects this only works for "uniform refinement", that is the refined mesh was obtained DMRefine() or the coarse mesh was obtained by 10653ad4599aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the interpolation. 10663ad4599aSBarry Smith 10673ad4599aSBarry Smith 10683ad4599aSBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMRefine(), DMCoarsen(), DMCreateInterpolation() 10693ad4599aSBarry Smith 10703ad4599aSBarry Smith @*/ 10713ad4599aSBarry Smith PetscErrorCode DMCreateRestriction(DM dm1,DM dm2,Mat *mat) 10723ad4599aSBarry Smith { 10733ad4599aSBarry Smith PetscErrorCode ierr; 10743ad4599aSBarry Smith 10753ad4599aSBarry Smith PetscFunctionBegin; 10763ad4599aSBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 10773ad4599aSBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 10783ad4599aSBarry Smith ierr = PetscLogEventBegin(DM_CreateRestriction,dm1,dm2,0,0);CHKERRQ(ierr); 10793ad4599aSBarry Smith ierr = (*dm1->ops->createrestriction)(dm1,dm2,mat);CHKERRQ(ierr); 10803ad4599aSBarry Smith ierr = PetscLogEventEnd(DM_CreateRestriction,dm1,dm2,0,0);CHKERRQ(ierr); 10813ad4599aSBarry Smith PetscFunctionReturn(0); 10823ad4599aSBarry Smith } 10833ad4599aSBarry Smith 10843ad4599aSBarry Smith #undef __FUNCT__ 1085e727c939SJed Brown #define __FUNCT__ "DMCreateInjection" 108647c6ae99SBarry Smith /*@ 10878472ad0fSDave May DMCreateInjection - Gets injection matrix between two DM objects 108847c6ae99SBarry Smith 108947c6ae99SBarry Smith Collective on DM 109047c6ae99SBarry Smith 109147c6ae99SBarry Smith Input Parameter: 109247c6ae99SBarry Smith + dm1 - the DM object 109347c6ae99SBarry Smith - dm2 - the second, finer DM object 109447c6ae99SBarry Smith 109547c6ae99SBarry Smith Output Parameter: 10966dbf9973SLawrence Mitchell . mat - the injection 109747c6ae99SBarry Smith 109847c6ae99SBarry Smith Level: developer 109947c6ae99SBarry Smith 110085afcc9aSBarry Smith Notes: For DMDA objects this only works for "uniform refinement", that is the refined mesh was obtained DMRefine() or the coarse mesh was obtained by 110185afcc9aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the injection. 110285afcc9aSBarry Smith 1103e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMCreateInterpolation() 110447c6ae99SBarry Smith 110547c6ae99SBarry Smith @*/ 11066dbf9973SLawrence Mitchell PetscErrorCode DMCreateInjection(DM dm1,DM dm2,Mat *mat) 110747c6ae99SBarry Smith { 110847c6ae99SBarry Smith PetscErrorCode ierr; 110947c6ae99SBarry Smith 111047c6ae99SBarry Smith PetscFunctionBegin; 1111171400e9SBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 1112171400e9SBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 111323384938SToby Isaac if (!*dm1->ops->getinjection) SETERRQ(PetscObjectComm((PetscObject)dm1),PETSC_ERR_SUP,"DMCreateInjection not implemented for this type"); 11146dbf9973SLawrence Mitchell ierr = (*dm1->ops->getinjection)(dm1,dm2,mat);CHKERRQ(ierr); 111547c6ae99SBarry Smith PetscFunctionReturn(0); 111647c6ae99SBarry Smith } 111747c6ae99SBarry Smith 111847c6ae99SBarry Smith #undef __FUNCT__ 1119e727c939SJed Brown #define __FUNCT__ "DMCreateColoring" 1120b412c318SBarry Smith /*@ 1121b412c318SBarry Smith DMCreateColoring - Gets coloring for a DM 112247c6ae99SBarry Smith 112347c6ae99SBarry Smith Collective on DM 112447c6ae99SBarry Smith 112547c6ae99SBarry Smith Input Parameter: 112647c6ae99SBarry Smith + dm - the DM object 1127b412c318SBarry Smith - ctype - IS_COLORING_GHOSTED or IS_COLORING_GLOBAL 112847c6ae99SBarry Smith 112947c6ae99SBarry Smith Output Parameter: 113047c6ae99SBarry Smith . coloring - the coloring 113147c6ae99SBarry Smith 113247c6ae99SBarry Smith Level: developer 113347c6ae99SBarry Smith 1134b412c318SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateMatrix(), DMSetMatType() 113547c6ae99SBarry Smith 1136aab9d709SJed Brown @*/ 1137b412c318SBarry Smith PetscErrorCode DMCreateColoring(DM dm,ISColoringType ctype,ISColoring *coloring) 113847c6ae99SBarry Smith { 113947c6ae99SBarry Smith PetscErrorCode ierr; 114047c6ae99SBarry Smith 114147c6ae99SBarry Smith PetscFunctionBegin; 1142171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1143ce94432eSBarry Smith if (!dm->ops->getcoloring) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No coloring for this type of DM yet"); 1144b412c318SBarry Smith ierr = (*dm->ops->getcoloring)(dm,ctype,coloring);CHKERRQ(ierr); 114547c6ae99SBarry Smith PetscFunctionReturn(0); 114647c6ae99SBarry Smith } 114747c6ae99SBarry Smith 114847c6ae99SBarry Smith #undef __FUNCT__ 1149950540a4SJed Brown #define __FUNCT__ "DMCreateMatrix" 1150b412c318SBarry Smith /*@ 11518472ad0fSDave May DMCreateMatrix - Gets empty Jacobian for a DM 115247c6ae99SBarry Smith 115347c6ae99SBarry Smith Collective on DM 115447c6ae99SBarry Smith 115547c6ae99SBarry Smith Input Parameter: 1156b412c318SBarry Smith . dm - the DM object 115747c6ae99SBarry Smith 115847c6ae99SBarry Smith Output Parameter: 115947c6ae99SBarry Smith . mat - the empty Jacobian 116047c6ae99SBarry Smith 1161073dac72SJed Brown Level: beginner 116247c6ae99SBarry Smith 116394013140SBarry Smith Notes: This properly preallocates the number of nonzeros in the sparse matrix so you 116494013140SBarry Smith do not need to do it yourself. 116594013140SBarry Smith 116694013140SBarry Smith By default it also sets the nonzero structure and puts in the zero entries. To prevent setting 1167aa219208SBarry Smith the nonzero pattern call DMDASetMatPreallocateOnly() 116894013140SBarry Smith 116994013140SBarry Smith For structured grid problems, when you call MatView() on this matrix it is displayed using the global natural ordering, NOT in the ordering used 117094013140SBarry Smith internally by PETSc. 117194013140SBarry Smith 117294013140SBarry Smith For structured grid problems, in general it is easiest to use MatSetValuesStencil() or MatSetValuesLocal() to put values into the matrix because MatSetValues() requires 1173aa219208SBarry Smith the indices for the global numbering for DMDAs which is complicated. 117494013140SBarry Smith 1175b412c318SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMSetMatType() 117647c6ae99SBarry Smith 1177aab9d709SJed Brown @*/ 1178b412c318SBarry Smith PetscErrorCode DMCreateMatrix(DM dm,Mat *mat) 117947c6ae99SBarry Smith { 118047c6ae99SBarry Smith PetscErrorCode ierr; 118147c6ae99SBarry Smith 118247c6ae99SBarry Smith PetscFunctionBegin; 1183171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1184607a6623SBarry Smith ierr = MatInitializePackage();CHKERRQ(ierr); 1185c7b7c8a4SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1186c7b7c8a4SJed Brown PetscValidPointer(mat,3); 1187b412c318SBarry Smith ierr = (*dm->ops->creatematrix)(dm,mat);CHKERRQ(ierr); 118847c6ae99SBarry Smith PetscFunctionReturn(0); 118947c6ae99SBarry Smith } 119047c6ae99SBarry Smith 119147c6ae99SBarry Smith #undef __FUNCT__ 1192732e2eb9SMatthew G Knepley #define __FUNCT__ "DMSetMatrixPreallocateOnly" 1193732e2eb9SMatthew G Knepley /*@ 1194950540a4SJed Brown DMSetMatrixPreallocateOnly - When DMCreateMatrix() is called the matrix will be properly 1195732e2eb9SMatthew G Knepley preallocated but the nonzero structure and zero values will not be set. 1196732e2eb9SMatthew G Knepley 11978472ad0fSDave May Logically Collective on DM 1198732e2eb9SMatthew G Knepley 1199732e2eb9SMatthew G Knepley Input Parameter: 1200732e2eb9SMatthew G Knepley + dm - the DM 1201732e2eb9SMatthew G Knepley - only - PETSC_TRUE if only want preallocation 1202732e2eb9SMatthew G Knepley 1203732e2eb9SMatthew G Knepley Level: developer 1204950540a4SJed Brown .seealso DMCreateMatrix() 1205732e2eb9SMatthew G Knepley @*/ 1206732e2eb9SMatthew G Knepley PetscErrorCode DMSetMatrixPreallocateOnly(DM dm, PetscBool only) 1207732e2eb9SMatthew G Knepley { 1208732e2eb9SMatthew G Knepley PetscFunctionBegin; 1209732e2eb9SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1210732e2eb9SMatthew G Knepley dm->prealloc_only = only; 1211732e2eb9SMatthew G Knepley PetscFunctionReturn(0); 1212732e2eb9SMatthew G Knepley } 1213732e2eb9SMatthew G Knepley 1214732e2eb9SMatthew G Knepley #undef __FUNCT__ 1215a89ea682SMatthew G Knepley #define __FUNCT__ "DMGetWorkArray" 1216a89ea682SMatthew G Knepley /*@C 1217aa1993deSMatthew G Knepley DMGetWorkArray - Gets a work array guaranteed to be at least the input size, restore with DMRestoreWorkArray() 1218a89ea682SMatthew G Knepley 1219a89ea682SMatthew G Knepley Not Collective 1220a89ea682SMatthew G Knepley 1221a89ea682SMatthew G Knepley Input Parameters: 1222a89ea682SMatthew G Knepley + dm - the DM object 1223aa1993deSMatthew G Knepley . count - The minium size 1224aa1993deSMatthew G Knepley - dtype - data type (PETSC_REAL, PETSC_SCALAR, PETSC_INT) 1225a89ea682SMatthew G Knepley 1226a89ea682SMatthew G Knepley Output Parameter: 1227a89ea682SMatthew G Knepley . array - the work array 1228a89ea682SMatthew G Knepley 1229a89ea682SMatthew G Knepley Level: developer 1230a89ea682SMatthew G Knepley 1231a89ea682SMatthew G Knepley .seealso DMDestroy(), DMCreate() 1232a89ea682SMatthew G Knepley @*/ 1233aa1993deSMatthew G Knepley PetscErrorCode DMGetWorkArray(DM dm,PetscInt count,PetscDataType dtype,void *mem) 1234a89ea682SMatthew G Knepley { 1235a89ea682SMatthew G Knepley PetscErrorCode ierr; 1236aa1993deSMatthew G Knepley DMWorkLink link; 1237854ce69bSBarry Smith size_t dsize; 1238a89ea682SMatthew G Knepley 1239a89ea682SMatthew G Knepley PetscFunctionBegin; 1240a89ea682SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1241aa1993deSMatthew G Knepley PetscValidPointer(mem,4); 1242aa1993deSMatthew G Knepley if (dm->workin) { 1243aa1993deSMatthew G Knepley link = dm->workin; 1244aa1993deSMatthew G Knepley dm->workin = dm->workin->next; 1245aa1993deSMatthew G Knepley } else { 1246b00a9115SJed Brown ierr = PetscNewLog(dm,&link);CHKERRQ(ierr); 1247a89ea682SMatthew G Knepley } 1248854ce69bSBarry Smith ierr = PetscDataTypeGetSize(dtype,&dsize);CHKERRQ(ierr); 1249854ce69bSBarry Smith if (dsize*count > link->bytes) { 1250aa1993deSMatthew G Knepley ierr = PetscFree(link->mem);CHKERRQ(ierr); 1251854ce69bSBarry Smith ierr = PetscMalloc(dsize*count,&link->mem);CHKERRQ(ierr); 1252854ce69bSBarry Smith link->bytes = dsize*count; 1253aa1993deSMatthew G Knepley } 1254aa1993deSMatthew G Knepley link->next = dm->workout; 1255aa1993deSMatthew G Knepley dm->workout = link; 1256aa1993deSMatthew G Knepley *(void**)mem = link->mem; 1257a89ea682SMatthew G Knepley PetscFunctionReturn(0); 1258a89ea682SMatthew G Knepley } 1259a89ea682SMatthew G Knepley 1260aa1993deSMatthew G Knepley #undef __FUNCT__ 1261aa1993deSMatthew G Knepley #define __FUNCT__ "DMRestoreWorkArray" 1262aa1993deSMatthew G Knepley /*@C 1263aa1993deSMatthew G Knepley DMRestoreWorkArray - Restores a work array guaranteed to be at least the input size, restore with DMRestoreWorkArray() 1264aa1993deSMatthew G Knepley 1265aa1993deSMatthew G Knepley Not Collective 1266aa1993deSMatthew G Knepley 1267aa1993deSMatthew G Knepley Input Parameters: 1268aa1993deSMatthew G Knepley + dm - the DM object 1269aa1993deSMatthew G Knepley . count - The minium size 1270aa1993deSMatthew G Knepley - dtype - data type (PETSC_REAL, PETSC_SCALAR, PETSC_INT) 1271aa1993deSMatthew G Knepley 1272aa1993deSMatthew G Knepley Output Parameter: 1273aa1993deSMatthew G Knepley . array - the work array 1274aa1993deSMatthew G Knepley 1275aa1993deSMatthew G Knepley Level: developer 1276aa1993deSMatthew G Knepley 1277aa1993deSMatthew G Knepley .seealso DMDestroy(), DMCreate() 1278aa1993deSMatthew G Knepley @*/ 1279aa1993deSMatthew G Knepley PetscErrorCode DMRestoreWorkArray(DM dm,PetscInt count,PetscDataType dtype,void *mem) 1280aa1993deSMatthew G Knepley { 1281aa1993deSMatthew G Knepley DMWorkLink *p,link; 1282aa1993deSMatthew G Knepley 1283aa1993deSMatthew G Knepley PetscFunctionBegin; 1284aa1993deSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1285aa1993deSMatthew G Knepley PetscValidPointer(mem,4); 1286aa1993deSMatthew G Knepley for (p=&dm->workout; (link=*p); p=&link->next) { 1287aa1993deSMatthew G Knepley if (link->mem == *(void**)mem) { 1288aa1993deSMatthew G Knepley *p = link->next; 1289aa1993deSMatthew G Knepley link->next = dm->workin; 1290aa1993deSMatthew G Knepley dm->workin = link; 12910298fd71SBarry Smith *(void**)mem = NULL; 1292aa1993deSMatthew G Knepley PetscFunctionReturn(0); 1293aa1993deSMatthew G Knepley } 1294aa1993deSMatthew G Knepley } 1295aa1993deSMatthew G Knepley SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Array was not checked out"); 1296aa1993deSMatthew G Knepley } 1297e7c4fc90SDmitry Karpeev 1298e7c4fc90SDmitry Karpeev #undef __FUNCT__ 1299435a35e8SMatthew G Knepley #define __FUNCT__ "DMSetNullSpaceConstructor" 1300435a35e8SMatthew G Knepley PetscErrorCode DMSetNullSpaceConstructor(DM dm, PetscInt field, PetscErrorCode (*nullsp)(DM dm, PetscInt field, MatNullSpace *nullSpace)) 1301435a35e8SMatthew G Knepley { 1302435a35e8SMatthew G Knepley PetscFunctionBegin; 1303435a35e8SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 130482f516ccSBarry Smith if (field >= 10) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cannot handle %d >= 10 fields", field); 1305435a35e8SMatthew G Knepley dm->nullspaceConstructors[field] = nullsp; 1306435a35e8SMatthew G Knepley PetscFunctionReturn(0); 1307435a35e8SMatthew G Knepley } 1308435a35e8SMatthew G Knepley 1309435a35e8SMatthew G Knepley #undef __FUNCT__ 13104d343eeaSMatthew G Knepley #define __FUNCT__ "DMCreateFieldIS" 13114f3b5142SJed Brown /*@C 13124d343eeaSMatthew G Knepley DMCreateFieldIS - Creates a set of IS objects with the global indices of dofs for each field 13134d343eeaSMatthew G Knepley 13144d343eeaSMatthew G Knepley Not collective 13154d343eeaSMatthew G Knepley 13164d343eeaSMatthew G Knepley Input Parameter: 13174d343eeaSMatthew G Knepley . dm - the DM object 13184d343eeaSMatthew G Knepley 13194d343eeaSMatthew G Knepley Output Parameters: 13200298fd71SBarry Smith + numFields - The number of fields (or NULL if not requested) 13210298fd71SBarry Smith . fieldNames - The name for each field (or NULL if not requested) 13220298fd71SBarry Smith - fields - The global indices for each field (or NULL if not requested) 13234d343eeaSMatthew G Knepley 13244d343eeaSMatthew G Knepley Level: intermediate 13254d343eeaSMatthew G Knepley 132621c9b008SJed Brown Notes: 132721c9b008SJed Brown The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 132821c9b008SJed Brown PetscFree(), every entry of fields should be destroyed with ISDestroy(), and both arrays should be freed with 132921c9b008SJed Brown PetscFree(). 133021c9b008SJed Brown 13314d343eeaSMatthew G Knepley .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 13324d343eeaSMatthew G Knepley @*/ 133337d0c07bSMatthew G Knepley PetscErrorCode DMCreateFieldIS(DM dm, PetscInt *numFields, char ***fieldNames, IS **fields) 13344d343eeaSMatthew G Knepley { 133537d0c07bSMatthew G Knepley PetscSection section, sectionGlobal; 13364d343eeaSMatthew G Knepley PetscErrorCode ierr; 13374d343eeaSMatthew G Knepley 13384d343eeaSMatthew G Knepley PetscFunctionBegin; 13394d343eeaSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 134069ca1f37SDmitry Karpeev if (numFields) { 134169ca1f37SDmitry Karpeev PetscValidPointer(numFields,2); 134269ca1f37SDmitry Karpeev *numFields = 0; 134369ca1f37SDmitry Karpeev } 134437d0c07bSMatthew G Knepley if (fieldNames) { 134537d0c07bSMatthew G Knepley PetscValidPointer(fieldNames,3); 13460298fd71SBarry Smith *fieldNames = NULL; 134769ca1f37SDmitry Karpeev } 134869ca1f37SDmitry Karpeev if (fields) { 134969ca1f37SDmitry Karpeev PetscValidPointer(fields,4); 13500298fd71SBarry Smith *fields = NULL; 135169ca1f37SDmitry Karpeev } 135237d0c07bSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 135337d0c07bSMatthew G Knepley if (section) { 135437d0c07bSMatthew G Knepley PetscInt *fieldSizes, **fieldIndices; 135537d0c07bSMatthew G Knepley PetscInt nF, f, pStart, pEnd, p; 135637d0c07bSMatthew G Knepley 135737d0c07bSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 135837d0c07bSMatthew G Knepley ierr = PetscSectionGetNumFields(section, &nF);CHKERRQ(ierr); 1359dcca6d9dSJed Brown ierr = PetscMalloc2(nF,&fieldSizes,nF,&fieldIndices);CHKERRQ(ierr); 136037d0c07bSMatthew G Knepley ierr = PetscSectionGetChart(sectionGlobal, &pStart, &pEnd);CHKERRQ(ierr); 136137d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 136237d0c07bSMatthew G Knepley fieldSizes[f] = 0; 136337d0c07bSMatthew G Knepley } 136437d0c07bSMatthew G Knepley for (p = pStart; p < pEnd; ++p) { 136537d0c07bSMatthew G Knepley PetscInt gdof; 136637d0c07bSMatthew G Knepley 136737d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 136837d0c07bSMatthew G Knepley if (gdof > 0) { 136937d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 137037d0c07bSMatthew G Knepley PetscInt fdof, fcdof; 137137d0c07bSMatthew G Knepley 137237d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldDof(section, p, f, &fdof);CHKERRQ(ierr); 137337d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 137437d0c07bSMatthew G Knepley fieldSizes[f] += fdof-fcdof; 137537d0c07bSMatthew G Knepley } 137637d0c07bSMatthew G Knepley } 137737d0c07bSMatthew G Knepley } 137837d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 1379785e854fSJed Brown ierr = PetscMalloc1(fieldSizes[f], &fieldIndices[f]);CHKERRQ(ierr); 138037d0c07bSMatthew G Knepley fieldSizes[f] = 0; 138137d0c07bSMatthew G Knepley } 138237d0c07bSMatthew G Knepley for (p = pStart; p < pEnd; ++p) { 138337d0c07bSMatthew G Knepley PetscInt gdof, goff; 138437d0c07bSMatthew G Knepley 138537d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 138637d0c07bSMatthew G Knepley if (gdof > 0) { 138737d0c07bSMatthew G Knepley ierr = PetscSectionGetOffset(sectionGlobal, p, &goff);CHKERRQ(ierr); 138837d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 138937d0c07bSMatthew G Knepley PetscInt fdof, fcdof, fc; 139037d0c07bSMatthew G Knepley 139137d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldDof(section, p, f, &fdof);CHKERRQ(ierr); 139237d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 139337d0c07bSMatthew G Knepley for (fc = 0; fc < fdof-fcdof; ++fc, ++fieldSizes[f]) { 139437d0c07bSMatthew G Knepley fieldIndices[f][fieldSizes[f]] = goff++; 139537d0c07bSMatthew G Knepley } 139637d0c07bSMatthew G Knepley } 139737d0c07bSMatthew G Knepley } 139837d0c07bSMatthew G Knepley } 13998865f1eaSKarl Rupp if (numFields) *numFields = nF; 140037d0c07bSMatthew G Knepley if (fieldNames) { 1401785e854fSJed Brown ierr = PetscMalloc1(nF, fieldNames);CHKERRQ(ierr); 140237d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 140337d0c07bSMatthew G Knepley const char *fieldName; 140437d0c07bSMatthew G Knepley 140537d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldName(section, f, &fieldName);CHKERRQ(ierr); 140637d0c07bSMatthew G Knepley ierr = PetscStrallocpy(fieldName, (char**) &(*fieldNames)[f]);CHKERRQ(ierr); 140737d0c07bSMatthew G Knepley } 140837d0c07bSMatthew G Knepley } 140937d0c07bSMatthew G Knepley if (fields) { 1410785e854fSJed Brown ierr = PetscMalloc1(nF, fields);CHKERRQ(ierr); 141137d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 141282f516ccSBarry Smith ierr = ISCreateGeneral(PetscObjectComm((PetscObject)dm), fieldSizes[f], fieldIndices[f], PETSC_OWN_POINTER, &(*fields)[f]);CHKERRQ(ierr); 141337d0c07bSMatthew G Knepley } 141437d0c07bSMatthew G Knepley } 141537d0c07bSMatthew G Knepley ierr = PetscFree2(fieldSizes,fieldIndices);CHKERRQ(ierr); 14168865f1eaSKarl Rupp } else if (dm->ops->createfieldis) { 14178865f1eaSKarl Rupp ierr = (*dm->ops->createfieldis)(dm, numFields, fieldNames, fields);CHKERRQ(ierr); 141869ca1f37SDmitry Karpeev } 14194d343eeaSMatthew G Knepley PetscFunctionReturn(0); 14204d343eeaSMatthew G Knepley } 14214d343eeaSMatthew G Knepley 142216621825SDmitry Karpeev 142316621825SDmitry Karpeev #undef __FUNCT__ 142416621825SDmitry Karpeev #define __FUNCT__ "DMCreateFieldDecomposition" 142516621825SDmitry Karpeev /*@C 142616621825SDmitry Karpeev DMCreateFieldDecomposition - Returns a list of IS objects defining a decomposition of a problem into subproblems 142716621825SDmitry Karpeev corresponding to different fields: each IS contains the global indices of the dofs of the 142816621825SDmitry Karpeev corresponding field. The optional list of DMs define the DM for each subproblem. 1429e7c4fc90SDmitry Karpeev Generalizes DMCreateFieldIS(). 1430e7c4fc90SDmitry Karpeev 1431e7c4fc90SDmitry Karpeev Not collective 1432e7c4fc90SDmitry Karpeev 1433e7c4fc90SDmitry Karpeev Input Parameter: 1434e7c4fc90SDmitry Karpeev . dm - the DM object 1435e7c4fc90SDmitry Karpeev 1436e7c4fc90SDmitry Karpeev Output Parameters: 14370298fd71SBarry Smith + len - The number of subproblems in the field decomposition (or NULL if not requested) 14380298fd71SBarry Smith . namelist - The name for each field (or NULL if not requested) 14390298fd71SBarry Smith . islist - The global indices for each field (or NULL if not requested) 14400298fd71SBarry Smith - dmlist - The DMs for each field subproblem (or NULL, if not requested; if NULL is returned, no DMs are defined) 1441e7c4fc90SDmitry Karpeev 1442e7c4fc90SDmitry Karpeev Level: intermediate 1443e7c4fc90SDmitry Karpeev 1444e7c4fc90SDmitry Karpeev Notes: 1445e7c4fc90SDmitry Karpeev The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 1446e7c4fc90SDmitry Karpeev PetscFree(), every entry of is should be destroyed with ISDestroy(), every entry of dm should be destroyed with DMDestroy(), 1447e7c4fc90SDmitry Karpeev and all of the arrays should be freed with PetscFree(). 1448e7c4fc90SDmitry Karpeev 1449e7c4fc90SDmitry Karpeev .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1450e7c4fc90SDmitry Karpeev @*/ 145116621825SDmitry Karpeev PetscErrorCode DMCreateFieldDecomposition(DM dm, PetscInt *len, char ***namelist, IS **islist, DM **dmlist) 1452e7c4fc90SDmitry Karpeev { 1453e7c4fc90SDmitry Karpeev PetscErrorCode ierr; 1454e7c4fc90SDmitry Karpeev 1455e7c4fc90SDmitry Karpeev PetscFunctionBegin; 1456e7c4fc90SDmitry Karpeev PetscValidHeaderSpecific(dm,DM_CLASSID,1); 14578865f1eaSKarl Rupp if (len) { 14588865f1eaSKarl Rupp PetscValidPointer(len,2); 14598865f1eaSKarl Rupp *len = 0; 14608865f1eaSKarl Rupp } 14618865f1eaSKarl Rupp if (namelist) { 14628865f1eaSKarl Rupp PetscValidPointer(namelist,3); 14638865f1eaSKarl Rupp *namelist = 0; 14648865f1eaSKarl Rupp } 14658865f1eaSKarl Rupp if (islist) { 14668865f1eaSKarl Rupp PetscValidPointer(islist,4); 14678865f1eaSKarl Rupp *islist = 0; 14688865f1eaSKarl Rupp } 14698865f1eaSKarl Rupp if (dmlist) { 14708865f1eaSKarl Rupp PetscValidPointer(dmlist,5); 14718865f1eaSKarl Rupp *dmlist = 0; 14728865f1eaSKarl Rupp } 1473f3f0edfdSDmitry Karpeev /* 1474f3f0edfdSDmitry Karpeev Is it a good idea to apply the following check across all impls? 1475f3f0edfdSDmitry Karpeev Perhaps some impls can have a well-defined decomposition before DMSetUp? 1476f3f0edfdSDmitry Karpeev This, however, follows the general principle that accessors are not well-behaved until the object is set up. 1477f3f0edfdSDmitry Karpeev */ 1478ce94432eSBarry Smith if (!dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE, "Decomposition defined only after DMSetUp"); 147916621825SDmitry Karpeev if (!dm->ops->createfielddecomposition) { 1480435a35e8SMatthew G Knepley PetscSection section; 1481435a35e8SMatthew G Knepley PetscInt numFields, f; 1482435a35e8SMatthew G Knepley 1483435a35e8SMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 1484435a35e8SMatthew G Knepley if (section) {ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr);} 1485435a35e8SMatthew G Knepley if (section && numFields && dm->ops->createsubdm) { 1486f25d98f1SMatthew G. Knepley if (len) *len = numFields; 148703dc3394SMatthew G. Knepley if (namelist) {ierr = PetscMalloc1(numFields,namelist);CHKERRQ(ierr);} 148803dc3394SMatthew G. Knepley if (islist) {ierr = PetscMalloc1(numFields,islist);CHKERRQ(ierr);} 148903dc3394SMatthew G. Knepley if (dmlist) {ierr = PetscMalloc1(numFields,dmlist);CHKERRQ(ierr);} 1490435a35e8SMatthew G Knepley for (f = 0; f < numFields; ++f) { 1491435a35e8SMatthew G Knepley const char *fieldName; 1492435a35e8SMatthew G Knepley 149303dc3394SMatthew G. Knepley ierr = DMCreateSubDM(dm, 1, &f, islist ? &(*islist)[f] : NULL, dmlist ? &(*dmlist)[f] : NULL);CHKERRQ(ierr); 149403dc3394SMatthew G. Knepley if (namelist) { 1495435a35e8SMatthew G Knepley ierr = PetscSectionGetFieldName(section, f, &fieldName);CHKERRQ(ierr); 1496435a35e8SMatthew G Knepley ierr = PetscStrallocpy(fieldName, (char**) &(*namelist)[f]);CHKERRQ(ierr); 1497435a35e8SMatthew G Knepley } 149803dc3394SMatthew G. Knepley } 1499435a35e8SMatthew G Knepley } else { 150069ca1f37SDmitry Karpeev ierr = DMCreateFieldIS(dm, len, namelist, islist);CHKERRQ(ierr); 1501e7c4fc90SDmitry Karpeev /* By default there are no DMs associated with subproblems. */ 15020298fd71SBarry Smith if (dmlist) *dmlist = NULL; 1503e7c4fc90SDmitry Karpeev } 15048865f1eaSKarl Rupp } else { 150516621825SDmitry Karpeev ierr = (*dm->ops->createfielddecomposition)(dm,len,namelist,islist,dmlist);CHKERRQ(ierr); 150616621825SDmitry Karpeev } 150716621825SDmitry Karpeev PetscFunctionReturn(0); 150816621825SDmitry Karpeev } 150916621825SDmitry Karpeev 151016621825SDmitry Karpeev #undef __FUNCT__ 1511435a35e8SMatthew G Knepley #define __FUNCT__ "DMCreateSubDM" 1512564cec59SMatthew G. Knepley /*@ 1513435a35e8SMatthew G Knepley DMCreateSubDM - Returns an IS and DM encapsulating a subproblem defined by the fields passed in. 1514435a35e8SMatthew G Knepley The fields are defined by DMCreateFieldIS(). 1515435a35e8SMatthew G Knepley 1516435a35e8SMatthew G Knepley Not collective 1517435a35e8SMatthew G Knepley 1518435a35e8SMatthew G Knepley Input Parameters: 1519435a35e8SMatthew G Knepley + dm - the DM object 1520435a35e8SMatthew G Knepley . numFields - number of fields in this subproblem 15210298fd71SBarry Smith - len - The number of subproblems in the decomposition (or NULL if not requested) 1522435a35e8SMatthew G Knepley 1523435a35e8SMatthew G Knepley Output Parameters: 1524435a35e8SMatthew G Knepley . is - The global indices for the subproblem 1525435a35e8SMatthew G Knepley - dm - The DM for the subproblem 1526435a35e8SMatthew G Knepley 1527435a35e8SMatthew G Knepley Level: intermediate 1528435a35e8SMatthew G Knepley 1529435a35e8SMatthew G Knepley .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1530435a35e8SMatthew G Knepley @*/ 1531435a35e8SMatthew G Knepley PetscErrorCode DMCreateSubDM(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) 1532435a35e8SMatthew G Knepley { 1533435a35e8SMatthew G Knepley PetscErrorCode ierr; 1534435a35e8SMatthew G Knepley 1535435a35e8SMatthew G Knepley PetscFunctionBegin; 1536435a35e8SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1537435a35e8SMatthew G Knepley PetscValidPointer(fields,3); 15388865f1eaSKarl Rupp if (is) PetscValidPointer(is,4); 15398865f1eaSKarl Rupp if (subdm) PetscValidPointer(subdm,5); 1540435a35e8SMatthew G Knepley if (dm->ops->createsubdm) { 1541435a35e8SMatthew G Knepley ierr = (*dm->ops->createsubdm)(dm, numFields, fields, is, subdm);CHKERRQ(ierr); 154282f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "This type has no DMCreateSubDM implementation defined"); 1543435a35e8SMatthew G Knepley PetscFunctionReturn(0); 1544435a35e8SMatthew G Knepley } 1545435a35e8SMatthew G Knepley 154616621825SDmitry Karpeev 154716621825SDmitry Karpeev #undef __FUNCT__ 154816621825SDmitry Karpeev #define __FUNCT__ "DMCreateDomainDecomposition" 154916621825SDmitry Karpeev /*@C 15508d4ac253SDmitry Karpeev DMCreateDomainDecomposition - Returns lists of IS objects defining a decomposition of a problem into subproblems 15518d4ac253SDmitry Karpeev corresponding to restrictions to pairs nested subdomains: each IS contains the global 15528d4ac253SDmitry Karpeev indices of the dofs of the corresponding subdomains. The inner subdomains conceptually 15538d4ac253SDmitry Karpeev define a nonoverlapping covering, while outer subdomains can overlap. 15548d4ac253SDmitry Karpeev The optional list of DMs define the DM for each subproblem. 155516621825SDmitry Karpeev 155616621825SDmitry Karpeev Not collective 155716621825SDmitry Karpeev 155816621825SDmitry Karpeev Input Parameter: 155916621825SDmitry Karpeev . dm - the DM object 156016621825SDmitry Karpeev 156116621825SDmitry Karpeev Output Parameters: 15620298fd71SBarry Smith + len - The number of subproblems in the domain decomposition (or NULL if not requested) 15630298fd71SBarry Smith . namelist - The name for each subdomain (or NULL if not requested) 15640298fd71SBarry Smith . innerislist - The global indices for each inner subdomain (or NULL, if not requested) 15650298fd71SBarry Smith . outerislist - The global indices for each outer subdomain (or NULL, if not requested) 15660298fd71SBarry Smith - dmlist - The DMs for each subdomain subproblem (or NULL, if not requested; if NULL is returned, no DMs are defined) 156716621825SDmitry Karpeev 156816621825SDmitry Karpeev Level: intermediate 156916621825SDmitry Karpeev 157016621825SDmitry Karpeev Notes: 157116621825SDmitry Karpeev The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 157216621825SDmitry Karpeev PetscFree(), every entry of is should be destroyed with ISDestroy(), every entry of dm should be destroyed with DMDestroy(), 157316621825SDmitry Karpeev and all of the arrays should be freed with PetscFree(). 157416621825SDmitry Karpeev 15758d4ac253SDmitry Karpeev .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateDomainDecompositionDM(), DMCreateFieldDecomposition() 157616621825SDmitry Karpeev @*/ 15778d4ac253SDmitry Karpeev PetscErrorCode DMCreateDomainDecomposition(DM dm, PetscInt *len, char ***namelist, IS **innerislist, IS **outerislist, DM **dmlist) 157816621825SDmitry Karpeev { 157916621825SDmitry Karpeev PetscErrorCode ierr; 1580be081cd6SPeter Brune DMSubDomainHookLink link; 1581be081cd6SPeter Brune PetscInt i,l; 158216621825SDmitry Karpeev 158316621825SDmitry Karpeev PetscFunctionBegin; 158416621825SDmitry Karpeev PetscValidHeaderSpecific(dm,DM_CLASSID,1); 158514a18fd3SPeter Brune if (len) {PetscValidPointer(len,2); *len = 0;} 15860298fd71SBarry Smith if (namelist) {PetscValidPointer(namelist,3); *namelist = NULL;} 15870298fd71SBarry Smith if (innerislist) {PetscValidPointer(innerislist,4); *innerislist = NULL;} 15880298fd71SBarry Smith if (outerislist) {PetscValidPointer(outerislist,5); *outerislist = NULL;} 15890298fd71SBarry Smith if (dmlist) {PetscValidPointer(dmlist,6); *dmlist = NULL;} 1590f3f0edfdSDmitry Karpeev /* 1591f3f0edfdSDmitry Karpeev Is it a good idea to apply the following check across all impls? 1592f3f0edfdSDmitry Karpeev Perhaps some impls can have a well-defined decomposition before DMSetUp? 1593f3f0edfdSDmitry Karpeev This, however, follows the general principle that accessors are not well-behaved until the object is set up. 1594f3f0edfdSDmitry Karpeev */ 1595ce94432eSBarry Smith if (!dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE, "Decomposition defined only after DMSetUp"); 159616621825SDmitry Karpeev if (dm->ops->createdomaindecomposition) { 1597be081cd6SPeter Brune ierr = (*dm->ops->createdomaindecomposition)(dm,&l,namelist,innerislist,outerislist,dmlist);CHKERRQ(ierr); 159814a18fd3SPeter Brune /* copy subdomain hooks and context over to the subdomain DMs */ 159914a18fd3SPeter Brune if (dmlist) { 16002ca110d9SMatthew G. Knepley if (!*dmlist) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_POINTER,"Method mapped to dm->ops->createdomaindecomposition must allocate at least one DM"); 1601be081cd6SPeter Brune for (i = 0; i < l; i++) { 1602be081cd6SPeter Brune for (link=dm->subdomainhook; link; link=link->next) { 1603be081cd6SPeter Brune if (link->ddhook) {ierr = (*link->ddhook)(dm,(*dmlist)[i],link->ctx);CHKERRQ(ierr);} 1604be081cd6SPeter Brune } 1605d425c654SPeter Brune (*dmlist)[i]->ctx = dm->ctx; 1606e7c4fc90SDmitry Karpeev } 160714a18fd3SPeter Brune } 160814a18fd3SPeter Brune if (len) *len = l; 160914a18fd3SPeter Brune } 1610e30e807fSPeter Brune PetscFunctionReturn(0); 1611e30e807fSPeter Brune } 1612e30e807fSPeter Brune 1613e30e807fSPeter Brune 1614e30e807fSPeter Brune #undef __FUNCT__ 1615e30e807fSPeter Brune #define __FUNCT__ "DMCreateDomainDecompositionScatters" 1616e30e807fSPeter Brune /*@C 1617e30e807fSPeter Brune DMCreateDomainDecompositionScatters - Returns scatters to the subdomain vectors from the global vector 1618e30e807fSPeter Brune 1619e30e807fSPeter Brune Not collective 1620e30e807fSPeter Brune 1621e30e807fSPeter Brune Input Parameters: 1622e30e807fSPeter Brune + dm - the DM object 1623e30e807fSPeter Brune . n - the number of subdomain scatters 1624e30e807fSPeter Brune - subdms - the local subdomains 1625e30e807fSPeter Brune 1626e30e807fSPeter Brune Output Parameters: 1627e30e807fSPeter Brune + n - the number of scatters returned 1628e30e807fSPeter Brune . iscat - scatter from global vector to nonoverlapping global vector entries on subdomain 1629e30e807fSPeter Brune . oscat - scatter from global vector to overlapping global vector entries on subdomain 1630e30e807fSPeter Brune - gscat - scatter from global vector to local vector on subdomain (fills in ghosts) 1631e30e807fSPeter Brune 1632e30e807fSPeter Brune Notes: This is an alternative to the iis and ois arguments in DMCreateDomainDecomposition that allow for the solution 1633e30e807fSPeter Brune of general nonlinear problems with overlapping subdomain methods. While merely having index sets that enable subsets 1634e30e807fSPeter Brune of the residual equations to be created is fine for linear problems, nonlinear problems require local assembly of 1635e30e807fSPeter Brune solution and residual data. 1636e30e807fSPeter Brune 1637e30e807fSPeter Brune Level: developer 1638e30e807fSPeter Brune 1639e30e807fSPeter Brune .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1640e30e807fSPeter Brune @*/ 1641e30e807fSPeter Brune PetscErrorCode DMCreateDomainDecompositionScatters(DM dm,PetscInt n,DM *subdms,VecScatter **iscat,VecScatter **oscat,VecScatter **gscat) 1642e30e807fSPeter Brune { 1643e30e807fSPeter Brune PetscErrorCode ierr; 1644e30e807fSPeter Brune 1645e30e807fSPeter Brune PetscFunctionBegin; 1646e30e807fSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1647e30e807fSPeter Brune PetscValidPointer(subdms,3); 1648e30e807fSPeter Brune if (dm->ops->createddscatters) { 1649e30e807fSPeter Brune ierr = (*dm->ops->createddscatters)(dm,n,subdms,iscat,oscat,gscat);CHKERRQ(ierr); 165082f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "This type has no DMCreateDomainDecompositionLocalScatter implementation defined"); 1651e7c4fc90SDmitry Karpeev PetscFunctionReturn(0); 1652e7c4fc90SDmitry Karpeev } 1653e7c4fc90SDmitry Karpeev 1654731c8d9eSDmitry Karpeev #undef __FUNCT__ 165547c6ae99SBarry Smith #define __FUNCT__ "DMRefine" 165647c6ae99SBarry Smith /*@ 165747c6ae99SBarry Smith DMRefine - Refines a DM object 165847c6ae99SBarry Smith 165947c6ae99SBarry Smith Collective on DM 166047c6ae99SBarry Smith 166147c6ae99SBarry Smith Input Parameter: 166247c6ae99SBarry Smith + dm - the DM object 166391d95f02SJed Brown - comm - the communicator to contain the new DM object (or MPI_COMM_NULL) 166447c6ae99SBarry Smith 166547c6ae99SBarry Smith Output Parameter: 16660298fd71SBarry Smith . dmf - the refined DM, or NULL 1667ae0a1c52SMatthew G Knepley 16680298fd71SBarry Smith Note: If no refinement was done, the return value is NULL 166947c6ae99SBarry Smith 167047c6ae99SBarry Smith Level: developer 167147c6ae99SBarry Smith 1672e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 167347c6ae99SBarry Smith @*/ 16747087cfbeSBarry Smith PetscErrorCode DMRefine(DM dm,MPI_Comm comm,DM *dmf) 167547c6ae99SBarry Smith { 167647c6ae99SBarry Smith PetscErrorCode ierr; 1677c833c3b5SJed Brown DMRefineHookLink link; 167847c6ae99SBarry Smith 167947c6ae99SBarry Smith PetscFunctionBegin; 1680732e2eb9SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1681fef3a512SBarry Smith if (!dm->ops->refine) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"This DM cannot refine"); 168247c6ae99SBarry Smith ierr = (*dm->ops->refine)(dm,comm,dmf);CHKERRQ(ierr); 16834057135bSMatthew G Knepley if (*dmf) { 168443842a1eSJed Brown (*dmf)->ops->creatematrix = dm->ops->creatematrix; 16858865f1eaSKarl Rupp 16868cd211a4SJed Brown ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)*dmf);CHKERRQ(ierr); 16878865f1eaSKarl Rupp 1688644e2e5bSBarry Smith (*dmf)->ctx = dm->ctx; 16890598a293SJed Brown (*dmf)->leveldown = dm->leveldown; 1690656b349aSBarry Smith (*dmf)->levelup = dm->levelup + 1; 16918865f1eaSKarl Rupp 1692e4b4b23bSJed Brown ierr = DMSetMatType(*dmf,dm->mattype);CHKERRQ(ierr); 1693c833c3b5SJed Brown for (link=dm->refinehook; link; link=link->next) { 16948865f1eaSKarl Rupp if (link->refinehook) { 16958865f1eaSKarl Rupp ierr = (*link->refinehook)(dm,*dmf,link->ctx);CHKERRQ(ierr); 16968865f1eaSKarl Rupp } 1697c833c3b5SJed Brown } 1698c833c3b5SJed Brown } 1699c833c3b5SJed Brown PetscFunctionReturn(0); 1700c833c3b5SJed Brown } 1701c833c3b5SJed Brown 1702c833c3b5SJed Brown #undef __FUNCT__ 1703c833c3b5SJed Brown #define __FUNCT__ "DMRefineHookAdd" 1704bb9467b5SJed Brown /*@C 1705c833c3b5SJed Brown DMRefineHookAdd - adds a callback to be run when interpolating a nonlinear problem to a finer grid 1706c833c3b5SJed Brown 1707c833c3b5SJed Brown Logically Collective 1708c833c3b5SJed Brown 1709c833c3b5SJed Brown Input Arguments: 1710c833c3b5SJed Brown + coarse - nonlinear solver context on which to run a hook when restricting to a coarser level 1711c833c3b5SJed Brown . refinehook - function to run when setting up a coarser level 1712c833c3b5SJed Brown . interphook - function to run to update data on finer levels (once per SNESSolve()) 17130298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1714c833c3b5SJed Brown 1715c833c3b5SJed Brown Calling sequence of refinehook: 1716c833c3b5SJed Brown $ refinehook(DM coarse,DM fine,void *ctx); 1717c833c3b5SJed Brown 1718c833c3b5SJed Brown + coarse - coarse level DM 1719c833c3b5SJed Brown . fine - fine level DM to interpolate problem to 1720c833c3b5SJed Brown - ctx - optional user-defined function context 1721c833c3b5SJed Brown 1722c833c3b5SJed Brown Calling sequence for interphook: 1723c833c3b5SJed Brown $ interphook(DM coarse,Mat interp,DM fine,void *ctx) 1724c833c3b5SJed Brown 1725c833c3b5SJed Brown + coarse - coarse level DM 1726c833c3b5SJed Brown . interp - matrix interpolating a coarse-level solution to the finer grid 1727c833c3b5SJed Brown . fine - fine level DM to update 1728c833c3b5SJed Brown - ctx - optional user-defined function context 1729c833c3b5SJed Brown 1730c833c3b5SJed Brown Level: advanced 1731c833c3b5SJed Brown 1732c833c3b5SJed Brown Notes: 1733c833c3b5SJed Brown This function is only needed if auxiliary data needs to be passed to fine grids while grid sequencing 1734c833c3b5SJed Brown 1735c833c3b5SJed Brown If this function is called multiple times, the hooks will be run in the order they are added. 1736c833c3b5SJed Brown 1737bb9467b5SJed Brown This function is currently not available from Fortran. 1738bb9467b5SJed Brown 1739c833c3b5SJed Brown .seealso: DMCoarsenHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1740c833c3b5SJed Brown @*/ 1741c833c3b5SJed Brown PetscErrorCode DMRefineHookAdd(DM coarse,PetscErrorCode (*refinehook)(DM,DM,void*),PetscErrorCode (*interphook)(DM,Mat,DM,void*),void *ctx) 1742c833c3b5SJed Brown { 1743c833c3b5SJed Brown PetscErrorCode ierr; 1744c833c3b5SJed Brown DMRefineHookLink link,*p; 1745c833c3b5SJed Brown 1746c833c3b5SJed Brown PetscFunctionBegin; 1747c833c3b5SJed Brown PetscValidHeaderSpecific(coarse,DM_CLASSID,1); 1748c833c3b5SJed Brown for (p=&coarse->refinehook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1749*95dccacaSBarry Smith ierr = PetscNew(&link);CHKERRQ(ierr); 1750c833c3b5SJed Brown link->refinehook = refinehook; 1751c833c3b5SJed Brown link->interphook = interphook; 1752c833c3b5SJed Brown link->ctx = ctx; 17530298fd71SBarry Smith link->next = NULL; 1754c833c3b5SJed Brown *p = link; 1755c833c3b5SJed Brown PetscFunctionReturn(0); 1756c833c3b5SJed Brown } 1757c833c3b5SJed Brown 1758c833c3b5SJed Brown #undef __FUNCT__ 1759c833c3b5SJed Brown #define __FUNCT__ "DMInterpolate" 1760c833c3b5SJed Brown /*@ 1761c833c3b5SJed Brown DMInterpolate - interpolates user-defined problem data to a finer DM by running hooks registered by DMRefineHookAdd() 1762c833c3b5SJed Brown 1763c833c3b5SJed Brown Collective if any hooks are 1764c833c3b5SJed Brown 1765c833c3b5SJed Brown Input Arguments: 1766c833c3b5SJed Brown + coarse - coarser DM to use as a base 1767c833c3b5SJed Brown . restrct - interpolation matrix, apply using MatInterpolate() 1768c833c3b5SJed Brown - fine - finer DM to update 1769c833c3b5SJed Brown 1770c833c3b5SJed Brown Level: developer 1771c833c3b5SJed Brown 1772c833c3b5SJed Brown .seealso: DMRefineHookAdd(), MatInterpolate() 1773c833c3b5SJed Brown @*/ 1774c833c3b5SJed Brown PetscErrorCode DMInterpolate(DM coarse,Mat interp,DM fine) 1775c833c3b5SJed Brown { 1776c833c3b5SJed Brown PetscErrorCode ierr; 1777c833c3b5SJed Brown DMRefineHookLink link; 1778c833c3b5SJed Brown 1779c833c3b5SJed Brown PetscFunctionBegin; 1780c833c3b5SJed Brown for (link=fine->refinehook; link; link=link->next) { 17818865f1eaSKarl Rupp if (link->interphook) { 17828865f1eaSKarl Rupp ierr = (*link->interphook)(coarse,interp,fine,link->ctx);CHKERRQ(ierr); 17838865f1eaSKarl Rupp } 17844057135bSMatthew G Knepley } 178547c6ae99SBarry Smith PetscFunctionReturn(0); 178647c6ae99SBarry Smith } 178747c6ae99SBarry Smith 178847c6ae99SBarry Smith #undef __FUNCT__ 1789eb3f98d2SBarry Smith #define __FUNCT__ "DMGetRefineLevel" 1790eb3f98d2SBarry Smith /*@ 1791eb3f98d2SBarry Smith DMGetRefineLevel - Get's the number of refinements that have generated this DM. 1792eb3f98d2SBarry Smith 1793eb3f98d2SBarry Smith Not Collective 1794eb3f98d2SBarry Smith 1795eb3f98d2SBarry Smith Input Parameter: 1796eb3f98d2SBarry Smith . dm - the DM object 1797eb3f98d2SBarry Smith 1798eb3f98d2SBarry Smith Output Parameter: 1799eb3f98d2SBarry Smith . level - number of refinements 1800eb3f98d2SBarry Smith 1801eb3f98d2SBarry Smith Level: developer 1802eb3f98d2SBarry Smith 18036a7d9d85SPeter Brune .seealso DMCoarsen(), DMGetCoarsenLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 1804eb3f98d2SBarry Smith 1805eb3f98d2SBarry Smith @*/ 1806eb3f98d2SBarry Smith PetscErrorCode DMGetRefineLevel(DM dm,PetscInt *level) 1807eb3f98d2SBarry Smith { 1808eb3f98d2SBarry Smith PetscFunctionBegin; 1809eb3f98d2SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1810eb3f98d2SBarry Smith *level = dm->levelup; 1811eb3f98d2SBarry Smith PetscFunctionReturn(0); 1812eb3f98d2SBarry Smith } 1813eb3f98d2SBarry Smith 1814eb3f98d2SBarry Smith #undef __FUNCT__ 1815fef3a512SBarry Smith #define __FUNCT__ "DMSetRefineLevel" 1816fef3a512SBarry Smith /*@ 1817fef3a512SBarry Smith DMSetRefineLevel - Set's the number of refinements that have generated this DM. 1818fef3a512SBarry Smith 1819fef3a512SBarry Smith Not Collective 1820fef3a512SBarry Smith 1821fef3a512SBarry Smith Input Parameter: 1822fef3a512SBarry Smith + dm - the DM object 1823fef3a512SBarry Smith - level - number of refinements 1824fef3a512SBarry Smith 1825fef3a512SBarry Smith Level: advanced 1826fef3a512SBarry Smith 1827fef3a512SBarry Smith Notes: This value is used by PCMG to determine how many multigrid levels to use 1828fef3a512SBarry Smith 1829fef3a512SBarry Smith .seealso DMCoarsen(), DMGetCoarsenLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 1830fef3a512SBarry Smith 1831fef3a512SBarry Smith @*/ 1832fef3a512SBarry Smith PetscErrorCode DMSetRefineLevel(DM dm,PetscInt level) 1833fef3a512SBarry Smith { 1834fef3a512SBarry Smith PetscFunctionBegin; 1835fef3a512SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1836fef3a512SBarry Smith dm->levelup = level; 1837fef3a512SBarry Smith PetscFunctionReturn(0); 1838fef3a512SBarry Smith } 1839fef3a512SBarry Smith 1840fef3a512SBarry Smith #undef __FUNCT__ 1841baf369e7SPeter Brune #define __FUNCT__ "DMGlobalToLocalHookAdd" 1842bb9467b5SJed Brown /*@C 1843baf369e7SPeter Brune DMGlobalToLocalHookAdd - adds a callback to be run when global to local is called 1844baf369e7SPeter Brune 1845baf369e7SPeter Brune Logically Collective 1846baf369e7SPeter Brune 1847baf369e7SPeter Brune Input Arguments: 1848baf369e7SPeter Brune + dm - the DM 1849baf369e7SPeter Brune . beginhook - function to run at the beginning of DMGlobalToLocalBegin() 1850baf369e7SPeter Brune . endhook - function to run after DMGlobalToLocalEnd() has completed 18510298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1852baf369e7SPeter Brune 1853baf369e7SPeter Brune Calling sequence for beginhook: 1854baf369e7SPeter Brune $ beginhook(DM fine,VecScatter out,VecScatter in,DM coarse,void *ctx) 1855baf369e7SPeter Brune 1856baf369e7SPeter Brune + dm - global DM 1857baf369e7SPeter Brune . g - global vector 1858baf369e7SPeter Brune . mode - mode 1859baf369e7SPeter Brune . l - local vector 1860baf369e7SPeter Brune - ctx - optional user-defined function context 1861baf369e7SPeter Brune 1862baf369e7SPeter Brune 1863baf369e7SPeter Brune Calling sequence for endhook: 1864ec4806b8SPeter Brune $ endhook(DM fine,VecScatter out,VecScatter in,DM coarse,void *ctx) 1865baf369e7SPeter Brune 1866baf369e7SPeter Brune + global - global DM 1867baf369e7SPeter Brune - ctx - optional user-defined function context 1868baf369e7SPeter Brune 1869baf369e7SPeter Brune Level: advanced 1870baf369e7SPeter Brune 1871baf369e7SPeter Brune .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1872baf369e7SPeter Brune @*/ 1873baf369e7SPeter Brune PetscErrorCode DMGlobalToLocalHookAdd(DM dm,PetscErrorCode (*beginhook)(DM,Vec,InsertMode,Vec,void*),PetscErrorCode (*endhook)(DM,Vec,InsertMode,Vec,void*),void *ctx) 1874baf369e7SPeter Brune { 1875baf369e7SPeter Brune PetscErrorCode ierr; 1876baf369e7SPeter Brune DMGlobalToLocalHookLink link,*p; 1877baf369e7SPeter Brune 1878baf369e7SPeter Brune PetscFunctionBegin; 1879baf369e7SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1880baf369e7SPeter Brune for (p=&dm->gtolhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1881*95dccacaSBarry Smith ierr = PetscNew(&link);CHKERRQ(ierr); 1882baf369e7SPeter Brune link->beginhook = beginhook; 1883baf369e7SPeter Brune link->endhook = endhook; 1884baf369e7SPeter Brune link->ctx = ctx; 18850298fd71SBarry Smith link->next = NULL; 1886baf369e7SPeter Brune *p = link; 1887baf369e7SPeter Brune PetscFunctionReturn(0); 1888baf369e7SPeter Brune } 1889baf369e7SPeter Brune 1890baf369e7SPeter Brune #undef __FUNCT__ 18914c274da1SToby Isaac #define __FUNCT__ "DMGlobalToLocalHook_Constraints" 18924c274da1SToby Isaac static PetscErrorCode DMGlobalToLocalHook_Constraints(DM dm, Vec g, InsertMode mode, Vec l, void *ctx) 18934c274da1SToby Isaac { 18944c274da1SToby Isaac Mat cMat; 18954c274da1SToby Isaac Vec cVec; 18964c274da1SToby Isaac PetscSection section, cSec; 18974c274da1SToby Isaac PetscInt pStart, pEnd, p, dof; 18984c274da1SToby Isaac PetscErrorCode ierr; 18994c274da1SToby Isaac 19004c274da1SToby Isaac PetscFunctionBegin; 19014c274da1SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 19024c274da1SToby Isaac ierr = DMGetDefaultConstraints(dm,&cSec,&cMat);CHKERRQ(ierr); 19034c274da1SToby Isaac if (cMat && (mode == INSERT_VALUES || mode == INSERT_ALL_VALUES || mode == INSERT_BC_VALUES)) { 19045db9a05bSToby Isaac PetscInt nRows; 19055db9a05bSToby Isaac 19065db9a05bSToby Isaac ierr = MatGetSize(cMat,&nRows,NULL);CHKERRQ(ierr); 19075db9a05bSToby Isaac if (nRows <= 0) PetscFunctionReturn(0); 19084c274da1SToby Isaac ierr = DMGetDefaultSection(dm,§ion);CHKERRQ(ierr); 19097711e48fSToby Isaac ierr = MatCreateVecs(cMat,NULL,&cVec);CHKERRQ(ierr); 19104c274da1SToby Isaac ierr = MatMult(cMat,l,cVec);CHKERRQ(ierr); 19114c274da1SToby Isaac ierr = PetscSectionGetChart(cSec,&pStart,&pEnd);CHKERRQ(ierr); 19124c274da1SToby Isaac for (p = pStart; p < pEnd; p++) { 19134c274da1SToby Isaac ierr = PetscSectionGetDof(cSec,p,&dof);CHKERRQ(ierr); 19144c274da1SToby Isaac if (dof) { 19154c274da1SToby Isaac PetscScalar *vals; 19164c274da1SToby Isaac ierr = VecGetValuesSection(cVec,cSec,p,&vals);CHKERRQ(ierr); 19174c274da1SToby Isaac ierr = VecSetValuesSection(l,section,p,vals,INSERT_ALL_VALUES);CHKERRQ(ierr); 19184c274da1SToby Isaac } 19194c274da1SToby Isaac } 19204c274da1SToby Isaac ierr = VecDestroy(&cVec);CHKERRQ(ierr); 19214c274da1SToby Isaac } 19224c274da1SToby Isaac PetscFunctionReturn(0); 19234c274da1SToby Isaac } 19244c274da1SToby Isaac 19254c274da1SToby Isaac #undef __FUNCT__ 192647c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalBegin" 192747c6ae99SBarry Smith /*@ 192847c6ae99SBarry Smith DMGlobalToLocalBegin - Begins updating local vectors from global vector 192947c6ae99SBarry Smith 193047c6ae99SBarry Smith Neighbor-wise Collective on DM 193147c6ae99SBarry Smith 193247c6ae99SBarry Smith Input Parameters: 193347c6ae99SBarry Smith + dm - the DM object 193447c6ae99SBarry Smith . g - the global vector 193547c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 193647c6ae99SBarry Smith - l - the local vector 193747c6ae99SBarry Smith 193847c6ae99SBarry Smith 193947c6ae99SBarry Smith Level: beginner 194047c6ae99SBarry Smith 1941e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 194247c6ae99SBarry Smith 194347c6ae99SBarry Smith @*/ 19447087cfbeSBarry Smith PetscErrorCode DMGlobalToLocalBegin(DM dm,Vec g,InsertMode mode,Vec l) 194547c6ae99SBarry Smith { 19467128ae9fSMatthew G Knepley PetscSF sf; 194747c6ae99SBarry Smith PetscErrorCode ierr; 1948baf369e7SPeter Brune DMGlobalToLocalHookLink link; 194947c6ae99SBarry Smith 195047c6ae99SBarry Smith PetscFunctionBegin; 1951171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1952baf369e7SPeter Brune for (link=dm->gtolhook; link; link=link->next) { 19538865f1eaSKarl Rupp if (link->beginhook) { 19548865f1eaSKarl Rupp ierr = (*link->beginhook)(dm,g,mode,l,link->ctx);CHKERRQ(ierr); 19558865f1eaSKarl Rupp } 1956baf369e7SPeter Brune } 19577128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 19587128ae9fSMatthew G Knepley if (sf) { 1959ae5cfb4aSMatthew G. Knepley const PetscScalar *gArray; 1960ae5cfb4aSMatthew G. Knepley PetscScalar *lArray; 19617128ae9fSMatthew G Knepley 196282f516ccSBarry Smith if (mode == ADD_VALUES) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 19637128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 1964ae5cfb4aSMatthew G. Knepley ierr = VecGetArrayRead(g, &gArray);CHKERRQ(ierr); 19657128ae9fSMatthew G Knepley ierr = PetscSFBcastBegin(sf, MPIU_SCALAR, gArray, lArray);CHKERRQ(ierr); 19667128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 1967ae5cfb4aSMatthew G. Knepley ierr = VecRestoreArrayRead(g, &gArray);CHKERRQ(ierr); 19687128ae9fSMatthew G Knepley } else { 1969843c4018SMatthew G Knepley ierr = (*dm->ops->globaltolocalbegin)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 19707128ae9fSMatthew G Knepley } 197147c6ae99SBarry Smith PetscFunctionReturn(0); 197247c6ae99SBarry Smith } 197347c6ae99SBarry Smith 197447c6ae99SBarry Smith #undef __FUNCT__ 197547c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalEnd" 197647c6ae99SBarry Smith /*@ 197747c6ae99SBarry Smith DMGlobalToLocalEnd - Ends updating local vectors from global vector 197847c6ae99SBarry Smith 197947c6ae99SBarry Smith Neighbor-wise Collective on DM 198047c6ae99SBarry Smith 198147c6ae99SBarry Smith Input Parameters: 198247c6ae99SBarry Smith + dm - the DM object 198347c6ae99SBarry Smith . g - the global vector 198447c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 198547c6ae99SBarry Smith - l - the local vector 198647c6ae99SBarry Smith 198747c6ae99SBarry Smith 198847c6ae99SBarry Smith Level: beginner 198947c6ae99SBarry Smith 1990e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 199147c6ae99SBarry Smith 199247c6ae99SBarry Smith @*/ 19937087cfbeSBarry Smith PetscErrorCode DMGlobalToLocalEnd(DM dm,Vec g,InsertMode mode,Vec l) 199447c6ae99SBarry Smith { 19957128ae9fSMatthew G Knepley PetscSF sf; 199647c6ae99SBarry Smith PetscErrorCode ierr; 1997ae5cfb4aSMatthew G. Knepley const PetscScalar *gArray; 1998ae5cfb4aSMatthew G. Knepley PetscScalar *lArray; 1999baf369e7SPeter Brune DMGlobalToLocalHookLink link; 200047c6ae99SBarry Smith 200147c6ae99SBarry Smith PetscFunctionBegin; 2002171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 20037128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 20047128ae9fSMatthew G Knepley if (sf) { 200582f516ccSBarry Smith if (mode == ADD_VALUES) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 20067128ae9fSMatthew G Knepley 20077128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 2008ae5cfb4aSMatthew G. Knepley ierr = VecGetArrayRead(g, &gArray);CHKERRQ(ierr); 20097128ae9fSMatthew G Knepley ierr = PetscSFBcastEnd(sf, MPIU_SCALAR, gArray, lArray);CHKERRQ(ierr); 20107128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 2011ae5cfb4aSMatthew G. Knepley ierr = VecRestoreArrayRead(g, &gArray);CHKERRQ(ierr); 20127128ae9fSMatthew G Knepley } else { 2013843c4018SMatthew G Knepley ierr = (*dm->ops->globaltolocalend)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 20147128ae9fSMatthew G Knepley } 20154c274da1SToby Isaac ierr = DMGlobalToLocalHook_Constraints(dm,g,mode,l,NULL);CHKERRQ(ierr); 2016baf369e7SPeter Brune for (link=dm->gtolhook; link; link=link->next) { 2017baf369e7SPeter Brune if (link->endhook) {ierr = (*link->endhook)(dm,g,mode,l,link->ctx);CHKERRQ(ierr);} 2018baf369e7SPeter Brune } 201947c6ae99SBarry Smith PetscFunctionReturn(0); 202047c6ae99SBarry Smith } 202147c6ae99SBarry Smith 202247c6ae99SBarry Smith #undef __FUNCT__ 2023d4d07f1eSToby Isaac #define __FUNCT__ "DMLocalToGlobalHookAdd" 2024d4d07f1eSToby Isaac /*@C 2025d4d07f1eSToby Isaac DMLocalToGlobalHookAdd - adds a callback to be run when a local to global is called 2026d4d07f1eSToby Isaac 2027d4d07f1eSToby Isaac Logically Collective 2028d4d07f1eSToby Isaac 2029d4d07f1eSToby Isaac Input Arguments: 2030d4d07f1eSToby Isaac + dm - the DM 2031d4d07f1eSToby Isaac . beginhook - function to run at the beginning of DMLocalToGlobalBegin() 2032d4d07f1eSToby Isaac . endhook - function to run after DMLocalToGlobalEnd() has completed 2033d4d07f1eSToby Isaac - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 2034d4d07f1eSToby Isaac 2035d4d07f1eSToby Isaac Calling sequence for beginhook: 2036d4d07f1eSToby Isaac $ beginhook(DM fine,Vec l,InsertMode mode,Vec g,void *ctx) 2037d4d07f1eSToby Isaac 2038d4d07f1eSToby Isaac + dm - global DM 2039d4d07f1eSToby Isaac . l - local vector 2040d4d07f1eSToby Isaac . mode - mode 2041d4d07f1eSToby Isaac . g - global vector 2042d4d07f1eSToby Isaac - ctx - optional user-defined function context 2043d4d07f1eSToby Isaac 2044d4d07f1eSToby Isaac 2045d4d07f1eSToby Isaac Calling sequence for endhook: 2046d4d07f1eSToby Isaac $ endhook(DM fine,Vec l,InsertMode mode,Vec g,void *ctx) 2047d4d07f1eSToby Isaac 2048d4d07f1eSToby Isaac + global - global DM 2049d4d07f1eSToby Isaac . l - local vector 2050d4d07f1eSToby Isaac . mode - mode 2051d4d07f1eSToby Isaac . g - global vector 2052d4d07f1eSToby Isaac - ctx - optional user-defined function context 2053d4d07f1eSToby Isaac 2054d4d07f1eSToby Isaac Level: advanced 2055d4d07f1eSToby Isaac 2056d4d07f1eSToby Isaac .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 2057d4d07f1eSToby Isaac @*/ 2058d4d07f1eSToby Isaac PetscErrorCode DMLocalToGlobalHookAdd(DM dm,PetscErrorCode (*beginhook)(DM,Vec,InsertMode,Vec,void*),PetscErrorCode (*endhook)(DM,Vec,InsertMode,Vec,void*),void *ctx) 2059d4d07f1eSToby Isaac { 2060d4d07f1eSToby Isaac PetscErrorCode ierr; 2061d4d07f1eSToby Isaac DMLocalToGlobalHookLink link,*p; 2062d4d07f1eSToby Isaac 2063d4d07f1eSToby Isaac PetscFunctionBegin; 2064d4d07f1eSToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2065d4d07f1eSToby Isaac for (p=&dm->ltoghook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 2066*95dccacaSBarry Smith ierr = PetscNew(&link);CHKERRQ(ierr); 2067d4d07f1eSToby Isaac link->beginhook = beginhook; 2068d4d07f1eSToby Isaac link->endhook = endhook; 2069d4d07f1eSToby Isaac link->ctx = ctx; 2070d4d07f1eSToby Isaac link->next = NULL; 2071d4d07f1eSToby Isaac *p = link; 2072d4d07f1eSToby Isaac PetscFunctionReturn(0); 2073d4d07f1eSToby Isaac } 2074d4d07f1eSToby Isaac 2075d4d07f1eSToby Isaac #undef __FUNCT__ 20764c274da1SToby Isaac #define __FUNCT__ "DMLocalToGlobalHook_Constraints" 20774c274da1SToby Isaac static PetscErrorCode DMLocalToGlobalHook_Constraints(DM dm, Vec l, InsertMode mode, Vec g, void *ctx) 20784c274da1SToby Isaac { 20794c274da1SToby Isaac Mat cMat; 20804c274da1SToby Isaac Vec cVec; 20814c274da1SToby Isaac PetscSection section, cSec; 20824c274da1SToby Isaac PetscInt pStart, pEnd, p, dof; 20834c274da1SToby Isaac PetscErrorCode ierr; 20844c274da1SToby Isaac 20854c274da1SToby Isaac PetscFunctionBegin; 20864c274da1SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 20874c274da1SToby Isaac ierr = DMGetDefaultConstraints(dm,&cSec,&cMat);CHKERRQ(ierr); 20884c274da1SToby Isaac if (cMat && (mode == ADD_VALUES || mode == ADD_ALL_VALUES || mode == ADD_BC_VALUES)) { 20895db9a05bSToby Isaac PetscInt nRows; 20905db9a05bSToby Isaac 20915db9a05bSToby Isaac ierr = MatGetSize(cMat,&nRows,NULL);CHKERRQ(ierr); 20925db9a05bSToby Isaac if (nRows <= 0) PetscFunctionReturn(0); 20934c274da1SToby Isaac ierr = DMGetDefaultSection(dm,§ion);CHKERRQ(ierr); 20947711e48fSToby Isaac ierr = MatCreateVecs(cMat,NULL,&cVec);CHKERRQ(ierr); 20954c274da1SToby Isaac ierr = PetscSectionGetChart(cSec,&pStart,&pEnd);CHKERRQ(ierr); 20964c274da1SToby Isaac for (p = pStart; p < pEnd; p++) { 20974c274da1SToby Isaac ierr = PetscSectionGetDof(cSec,p,&dof);CHKERRQ(ierr); 20984c274da1SToby Isaac if (dof) { 20994c274da1SToby Isaac PetscInt d; 21004c274da1SToby Isaac PetscScalar *vals; 21014c274da1SToby Isaac ierr = VecGetValuesSection(l,section,p,&vals);CHKERRQ(ierr); 21024c274da1SToby Isaac ierr = VecSetValuesSection(cVec,cSec,p,vals,mode);CHKERRQ(ierr); 21034c274da1SToby Isaac /* for this to be the true transpose, we have to zero the values that 21044c274da1SToby Isaac * we just extracted */ 21054c274da1SToby Isaac for (d = 0; d < dof; d++) { 21064c274da1SToby Isaac vals[d] = 0.; 21074c274da1SToby Isaac } 21084c274da1SToby Isaac } 21094c274da1SToby Isaac } 21104c274da1SToby Isaac ierr = MatMultTransposeAdd(cMat,cVec,l,l);CHKERRQ(ierr); 21114c274da1SToby Isaac ierr = VecDestroy(&cVec);CHKERRQ(ierr); 21124c274da1SToby Isaac } 21134c274da1SToby Isaac PetscFunctionReturn(0); 21144c274da1SToby Isaac } 21154c274da1SToby Isaac 21164c274da1SToby Isaac #undef __FUNCT__ 21179a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalBegin" 211847c6ae99SBarry Smith /*@ 21199a42bb27SBarry Smith DMLocalToGlobalBegin - updates global vectors from local vectors 21209a42bb27SBarry Smith 21219a42bb27SBarry Smith Neighbor-wise Collective on DM 21229a42bb27SBarry Smith 21239a42bb27SBarry Smith Input Parameters: 21249a42bb27SBarry Smith + dm - the DM object 2125f6813fd5SJed Brown . l - the local vector 21261eb28f2eSBarry Smith . mode - if INSERT_VALUES then no parallel communication is used, if ADD_VALUES then all ghost points from the same base point accumulate into that base point. 21271eb28f2eSBarry Smith - g - the global vector 21289a42bb27SBarry Smith 2129d96308ebSBarry Smith Notes: In the ADD_VALUES case you normally would zero the receiving vector before beginning this operation. 213084330215SMatthew G. Knepley INSERT_VALUES is not supported for DMDA, in that case simply compute the values directly into a global vector instead of a local one. 21319a42bb27SBarry Smith 21329a42bb27SBarry Smith Level: beginner 21339a42bb27SBarry Smith 2134e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalBegin() 21359a42bb27SBarry Smith 21369a42bb27SBarry Smith @*/ 21377087cfbeSBarry Smith PetscErrorCode DMLocalToGlobalBegin(DM dm,Vec l,InsertMode mode,Vec g) 21389a42bb27SBarry Smith { 21397128ae9fSMatthew G Knepley PetscSF sf; 214084330215SMatthew G. Knepley PetscSection s, gs; 2141d4d07f1eSToby Isaac DMLocalToGlobalHookLink link; 2142ae5cfb4aSMatthew G. Knepley const PetscScalar *lArray; 2143ae5cfb4aSMatthew G. Knepley PetscScalar *gArray; 214484330215SMatthew G. Knepley PetscBool isInsert; 214584330215SMatthew G. Knepley PetscErrorCode ierr; 21469a42bb27SBarry Smith 21479a42bb27SBarry Smith PetscFunctionBegin; 2148171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2149d4d07f1eSToby Isaac for (link=dm->ltoghook; link; link=link->next) { 2150d4d07f1eSToby Isaac if (link->beginhook) { 2151d4d07f1eSToby Isaac ierr = (*link->beginhook)(dm,l,mode,g,link->ctx);CHKERRQ(ierr); 2152d4d07f1eSToby Isaac } 2153d4d07f1eSToby Isaac } 21544c274da1SToby Isaac ierr = DMLocalToGlobalHook_Constraints(dm,l,mode,g,NULL);CHKERRQ(ierr); 21557128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 215684330215SMatthew G. Knepley ierr = DMGetDefaultSection(dm, &s);CHKERRQ(ierr); 21577128ae9fSMatthew G Knepley switch (mode) { 21587128ae9fSMatthew G Knepley case INSERT_VALUES: 21597128ae9fSMatthew G Knepley case INSERT_ALL_VALUES: 2160304ab55fSMatthew G. Knepley case INSERT_BC_VALUES: 216184330215SMatthew G. Knepley isInsert = PETSC_TRUE; break; 21627128ae9fSMatthew G Knepley case ADD_VALUES: 21637128ae9fSMatthew G Knepley case ADD_ALL_VALUES: 2164304ab55fSMatthew G. Knepley case ADD_BC_VALUES: 216584330215SMatthew G. Knepley isInsert = PETSC_FALSE; break; 21667128ae9fSMatthew G Knepley default: 216782f516ccSBarry Smith SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 21687128ae9fSMatthew G Knepley } 216984330215SMatthew G. Knepley if (sf && !isInsert) { 2170ae5cfb4aSMatthew G. Knepley ierr = VecGetArrayRead(l, &lArray);CHKERRQ(ierr); 21717128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 2172a9b180a6SBarry Smith ierr = PetscSFReduceBegin(sf, MPIU_SCALAR, lArray, gArray, MPIU_SUM);CHKERRQ(ierr); 2173ae5cfb4aSMatthew G. Knepley ierr = VecRestoreArrayRead(l, &lArray);CHKERRQ(ierr); 217484330215SMatthew G. Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 217584330215SMatthew G. Knepley } else if (s && isInsert) { 217684330215SMatthew G. Knepley PetscInt gStart, pStart, pEnd, p; 217784330215SMatthew G. Knepley 217884330215SMatthew G. Knepley ierr = DMGetDefaultGlobalSection(dm, &gs);CHKERRQ(ierr); 217984330215SMatthew G. Knepley ierr = PetscSectionGetChart(s, &pStart, &pEnd);CHKERRQ(ierr); 218084330215SMatthew G. Knepley ierr = VecGetOwnershipRange(g, &gStart, NULL);CHKERRQ(ierr); 2181ae5cfb4aSMatthew G. Knepley ierr = VecGetArrayRead(l, &lArray);CHKERRQ(ierr); 218284330215SMatthew G. Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 218384330215SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 2184b3b16f48SMatthew G. Knepley PetscInt dof, gdof, cdof, gcdof, off, goff, d, e; 218584330215SMatthew G. Knepley 218684330215SMatthew G. Knepley ierr = PetscSectionGetDof(s, p, &dof);CHKERRQ(ierr); 218703442857SMatthew G. Knepley ierr = PetscSectionGetDof(gs, p, &gdof);CHKERRQ(ierr); 218884330215SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(s, p, &cdof);CHKERRQ(ierr); 2189b3b16f48SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(gs, p, &gcdof);CHKERRQ(ierr); 219084330215SMatthew G. Knepley ierr = PetscSectionGetOffset(s, p, &off);CHKERRQ(ierr); 219184330215SMatthew G. Knepley ierr = PetscSectionGetOffset(gs, p, &goff);CHKERRQ(ierr); 2192b3b16f48SMatthew G. Knepley /* Ignore off-process data and points with no global data */ 219303442857SMatthew G. Knepley if (!gdof || goff < 0) continue; 2194b3b16f48SMatthew G. Knepley if (dof != gdof) SETERRQ5(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Inconsistent sizes, p: %d dof: %d gdof: %d cdof: %d gcdof: %d", p, dof, gdof, cdof, gcdof); 2195b3b16f48SMatthew G. Knepley /* If no constraints are enforced in the global vector */ 2196b3b16f48SMatthew G. Knepley if (!gcdof) { 219784330215SMatthew G. Knepley for (d = 0; d < dof; ++d) gArray[goff-gStart+d] = lArray[off+d]; 2198b3b16f48SMatthew G. Knepley /* If constraints are enforced in the global vector */ 2199b3b16f48SMatthew G. Knepley } else if (cdof == gcdof) { 220084330215SMatthew G. Knepley const PetscInt *cdofs; 220184330215SMatthew G. Knepley PetscInt cind = 0; 220284330215SMatthew G. Knepley 220384330215SMatthew G. Knepley ierr = PetscSectionGetConstraintIndices(s, p, &cdofs);CHKERRQ(ierr); 2204b3b16f48SMatthew G. Knepley for (d = 0, e = 0; d < dof; ++d) { 220584330215SMatthew G. Knepley if ((cind < cdof) && (d == cdofs[cind])) {++cind; continue;} 2206b3b16f48SMatthew G. Knepley gArray[goff-gStart+e++] = lArray[off+d]; 220784330215SMatthew G. Knepley } 2208b3b16f48SMatthew G. Knepley } else SETERRQ5(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, "Inconsistent sizes, p: %d dof: %d gdof: %d cdof: %d gcdof: %d", p, dof, gdof, cdof, gcdof); 220984330215SMatthew G. Knepley } 2210ae5cfb4aSMatthew G. Knepley ierr = VecRestoreArrayRead(l, &lArray);CHKERRQ(ierr); 22117128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 22127128ae9fSMatthew G Knepley } else { 2213843c4018SMatthew G Knepley ierr = (*dm->ops->localtoglobalbegin)(dm,l,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),g);CHKERRQ(ierr); 22147128ae9fSMatthew G Knepley } 22159a42bb27SBarry Smith PetscFunctionReturn(0); 22169a42bb27SBarry Smith } 22179a42bb27SBarry Smith 22189a42bb27SBarry Smith #undef __FUNCT__ 22199a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalEnd" 22209a42bb27SBarry Smith /*@ 22219a42bb27SBarry Smith DMLocalToGlobalEnd - updates global vectors from local vectors 222247c6ae99SBarry Smith 222347c6ae99SBarry Smith Neighbor-wise Collective on DM 222447c6ae99SBarry Smith 222547c6ae99SBarry Smith Input Parameters: 222647c6ae99SBarry Smith + dm - the DM object 2227f6813fd5SJed Brown . l - the local vector 222847c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 2229f6813fd5SJed Brown - g - the global vector 223047c6ae99SBarry Smith 223147c6ae99SBarry Smith 223247c6ae99SBarry Smith Level: beginner 223347c6ae99SBarry Smith 2234e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalEnd() 223547c6ae99SBarry Smith 223647c6ae99SBarry Smith @*/ 22377087cfbeSBarry Smith PetscErrorCode DMLocalToGlobalEnd(DM dm,Vec l,InsertMode mode,Vec g) 223847c6ae99SBarry Smith { 22397128ae9fSMatthew G Knepley PetscSF sf; 224084330215SMatthew G. Knepley PetscSection s; 2241d4d07f1eSToby Isaac DMLocalToGlobalHookLink link; 224284330215SMatthew G. Knepley PetscBool isInsert; 224384330215SMatthew G. Knepley PetscErrorCode ierr; 224447c6ae99SBarry Smith 224547c6ae99SBarry Smith PetscFunctionBegin; 2246171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 22477128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 224884330215SMatthew G. Knepley ierr = DMGetDefaultSection(dm, &s);CHKERRQ(ierr); 22497128ae9fSMatthew G Knepley switch (mode) { 22507128ae9fSMatthew G Knepley case INSERT_VALUES: 22517128ae9fSMatthew G Knepley case INSERT_ALL_VALUES: 225284330215SMatthew G. Knepley isInsert = PETSC_TRUE; break; 22537128ae9fSMatthew G Knepley case ADD_VALUES: 22547128ae9fSMatthew G Knepley case ADD_ALL_VALUES: 225584330215SMatthew G. Knepley isInsert = PETSC_FALSE; break; 22567128ae9fSMatthew G Knepley default: 225782f516ccSBarry Smith SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 22587128ae9fSMatthew G Knepley } 225984330215SMatthew G. Knepley if (sf && !isInsert) { 2260ae5cfb4aSMatthew G. Knepley const PetscScalar *lArray; 2261ae5cfb4aSMatthew G. Knepley PetscScalar *gArray; 226284330215SMatthew G. Knepley 2263ae5cfb4aSMatthew G. Knepley ierr = VecGetArrayRead(l, &lArray);CHKERRQ(ierr); 22647128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 2265a9b180a6SBarry Smith ierr = PetscSFReduceEnd(sf, MPIU_SCALAR, lArray, gArray, MPIU_SUM);CHKERRQ(ierr); 2266ae5cfb4aSMatthew G. Knepley ierr = VecRestoreArrayRead(l, &lArray);CHKERRQ(ierr); 22677128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 226884330215SMatthew G. Knepley } else if (s && isInsert) { 22697128ae9fSMatthew G Knepley } else { 2270843c4018SMatthew G Knepley ierr = (*dm->ops->localtoglobalend)(dm,l,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),g);CHKERRQ(ierr); 22717128ae9fSMatthew G Knepley } 2272d4d07f1eSToby Isaac for (link=dm->ltoghook; link; link=link->next) { 2273d4d07f1eSToby Isaac if (link->endhook) {ierr = (*link->endhook)(dm,g,mode,l,link->ctx);CHKERRQ(ierr);} 2274d4d07f1eSToby Isaac } 227547c6ae99SBarry Smith PetscFunctionReturn(0); 227647c6ae99SBarry Smith } 227747c6ae99SBarry Smith 227847c6ae99SBarry Smith #undef __FUNCT__ 2279f089877aSRichard Tran Mills #define __FUNCT__ "DMLocalToLocalBegin" 2280f089877aSRichard Tran Mills /*@ 2281bc0a1609SRichard Tran Mills DMLocalToLocalBegin - Maps from a local vector (including ghost points 2282bc0a1609SRichard Tran Mills that contain irrelevant values) to another local vector where the ghost 2283d78e899eSRichard Tran Mills points in the second are set correctly. Must be followed by DMLocalToLocalEnd(). 2284f089877aSRichard Tran Mills 2285bc0a1609SRichard Tran Mills Neighbor-wise Collective on DM and Vec 2286f089877aSRichard Tran Mills 2287f089877aSRichard Tran Mills Input Parameters: 2288f089877aSRichard Tran Mills + dm - the DM object 2289bc0a1609SRichard Tran Mills . g - the original local vector 2290bc0a1609SRichard Tran Mills - mode - one of INSERT_VALUES or ADD_VALUES 2291f089877aSRichard Tran Mills 2292bc0a1609SRichard Tran Mills Output Parameter: 2293bc0a1609SRichard Tran Mills . l - the local vector with correct ghost values 2294f089877aSRichard Tran Mills 2295f089877aSRichard Tran Mills Level: intermediate 2296f089877aSRichard Tran Mills 2297bc0a1609SRichard Tran Mills Notes: 2298bc0a1609SRichard Tran Mills The local vectors used here need not be the same as those 2299bc0a1609SRichard Tran Mills obtained from DMCreateLocalVector(), BUT they 2300bc0a1609SRichard Tran Mills must have the same parallel data layout; they could, for example, be 2301bc0a1609SRichard Tran Mills obtained with VecDuplicate() from the DM originating vectors. 2302bc0a1609SRichard Tran Mills 2303bc0a1609SRichard Tran Mills .keywords: DM, local-to-local, begin 2304bc0a1609SRichard Tran Mills .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateLocalVector(), DMCreateGlobalVector(), DMCreateInterpolation(), DMLocalToLocalEnd(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 2305f089877aSRichard Tran Mills 2306f089877aSRichard Tran Mills @*/ 2307f089877aSRichard Tran Mills PetscErrorCode DMLocalToLocalBegin(DM dm,Vec g,InsertMode mode,Vec l) 2308f089877aSRichard Tran Mills { 2309f089877aSRichard Tran Mills PetscErrorCode ierr; 2310f089877aSRichard Tran Mills 2311f089877aSRichard Tran Mills PetscFunctionBegin; 2312f089877aSRichard Tran Mills PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2313f089877aSRichard Tran Mills ierr = (*dm->ops->localtolocalbegin)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 2314f089877aSRichard Tran Mills PetscFunctionReturn(0); 2315f089877aSRichard Tran Mills } 2316f089877aSRichard Tran Mills 2317f089877aSRichard Tran Mills #undef __FUNCT__ 2318f089877aSRichard Tran Mills #define __FUNCT__ "DMLocalToLocalEnd" 2319f089877aSRichard Tran Mills /*@ 2320bc0a1609SRichard Tran Mills DMLocalToLocalEnd - Maps from a local vector (including ghost points 2321bc0a1609SRichard Tran Mills that contain irrelevant values) to another local vector where the ghost 2322d78e899eSRichard Tran Mills points in the second are set correctly. Must be preceded by DMLocalToLocalBegin(). 2323f089877aSRichard Tran Mills 2324bc0a1609SRichard Tran Mills Neighbor-wise Collective on DM and Vec 2325f089877aSRichard Tran Mills 2326f089877aSRichard Tran Mills Input Parameters: 2327bc0a1609SRichard Tran Mills + da - the DM object 2328bc0a1609SRichard Tran Mills . g - the original local vector 2329bc0a1609SRichard Tran Mills - mode - one of INSERT_VALUES or ADD_VALUES 2330f089877aSRichard Tran Mills 2331bc0a1609SRichard Tran Mills Output Parameter: 2332bc0a1609SRichard Tran Mills . l - the local vector with correct ghost values 2333f089877aSRichard Tran Mills 2334f089877aSRichard Tran Mills Level: intermediate 2335f089877aSRichard Tran Mills 2336bc0a1609SRichard Tran Mills Notes: 2337bc0a1609SRichard Tran Mills The local vectors used here need not be the same as those 2338bc0a1609SRichard Tran Mills obtained from DMCreateLocalVector(), BUT they 2339bc0a1609SRichard Tran Mills must have the same parallel data layout; they could, for example, be 2340bc0a1609SRichard Tran Mills obtained with VecDuplicate() from the DM originating vectors. 2341bc0a1609SRichard Tran Mills 2342bc0a1609SRichard Tran Mills .keywords: DM, local-to-local, end 2343bc0a1609SRichard Tran Mills .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateLocalVector(), DMCreateGlobalVector(), DMCreateInterpolation(), DMLocalToLocalBegin(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 2344f089877aSRichard Tran Mills 2345f089877aSRichard Tran Mills @*/ 2346f089877aSRichard Tran Mills PetscErrorCode DMLocalToLocalEnd(DM dm,Vec g,InsertMode mode,Vec l) 2347f089877aSRichard Tran Mills { 2348f089877aSRichard Tran Mills PetscErrorCode ierr; 2349f089877aSRichard Tran Mills 2350f089877aSRichard Tran Mills PetscFunctionBegin; 2351f089877aSRichard Tran Mills PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2352f089877aSRichard Tran Mills ierr = (*dm->ops->localtolocalend)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 2353f089877aSRichard Tran Mills PetscFunctionReturn(0); 2354f089877aSRichard Tran Mills } 2355f089877aSRichard Tran Mills 2356f089877aSRichard Tran Mills 2357f089877aSRichard Tran Mills #undef __FUNCT__ 235847c6ae99SBarry Smith #define __FUNCT__ "DMCoarsen" 235947c6ae99SBarry Smith /*@ 236047c6ae99SBarry Smith DMCoarsen - Coarsens a DM object 236147c6ae99SBarry Smith 236247c6ae99SBarry Smith Collective on DM 236347c6ae99SBarry Smith 236447c6ae99SBarry Smith Input Parameter: 236547c6ae99SBarry Smith + dm - the DM object 236691d95f02SJed Brown - comm - the communicator to contain the new DM object (or MPI_COMM_NULL) 236747c6ae99SBarry Smith 236847c6ae99SBarry Smith Output Parameter: 236947c6ae99SBarry Smith . dmc - the coarsened DM 237047c6ae99SBarry Smith 237147c6ae99SBarry Smith Level: developer 237247c6ae99SBarry Smith 2373e727c939SJed Brown .seealso DMRefine(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 237447c6ae99SBarry Smith 237547c6ae99SBarry Smith @*/ 23767087cfbeSBarry Smith PetscErrorCode DMCoarsen(DM dm, MPI_Comm comm, DM *dmc) 237747c6ae99SBarry Smith { 237847c6ae99SBarry Smith PetscErrorCode ierr; 2379b17ce1afSJed Brown DMCoarsenHookLink link; 238047c6ae99SBarry Smith 238147c6ae99SBarry Smith PetscFunctionBegin; 2382171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2383fef3a512SBarry Smith if (!dm->ops->coarsen) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"This DM cannot coarsen"); 238447a35634SPatrick Farrell ierr = PetscLogEventBegin(DM_Coarsen,dm,0,0,0);CHKERRQ(ierr); 238547c6ae99SBarry Smith ierr = (*dm->ops->coarsen)(dm, comm, dmc);CHKERRQ(ierr); 23868892b4c3SMatthew G. Knepley if (!(*dmc)) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "NULL coarse mesh produced"); 2387a8fb8f29SToby Isaac ierr = DMSetCoarseDM(dm,*dmc);CHKERRQ(ierr); 238843842a1eSJed Brown (*dmc)->ops->creatematrix = dm->ops->creatematrix; 23898cd211a4SJed Brown ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)*dmc);CHKERRQ(ierr); 2390644e2e5bSBarry Smith (*dmc)->ctx = dm->ctx; 23910598a293SJed Brown (*dmc)->levelup = dm->levelup; 2392656b349aSBarry Smith (*dmc)->leveldown = dm->leveldown + 1; 2393e4b4b23bSJed Brown ierr = DMSetMatType(*dmc,dm->mattype);CHKERRQ(ierr); 2394b17ce1afSJed Brown for (link=dm->coarsenhook; link; link=link->next) { 2395b17ce1afSJed Brown if (link->coarsenhook) {ierr = (*link->coarsenhook)(dm,*dmc,link->ctx);CHKERRQ(ierr);} 2396b17ce1afSJed Brown } 239747a35634SPatrick Farrell ierr = PetscLogEventEnd(DM_Coarsen,dm,0,0,0);CHKERRQ(ierr); 2398b17ce1afSJed Brown PetscFunctionReturn(0); 2399b17ce1afSJed Brown } 2400b17ce1afSJed Brown 2401b17ce1afSJed Brown #undef __FUNCT__ 2402b17ce1afSJed Brown #define __FUNCT__ "DMCoarsenHookAdd" 2403bb9467b5SJed Brown /*@C 2404b17ce1afSJed Brown DMCoarsenHookAdd - adds a callback to be run when restricting a nonlinear problem to the coarse grid 2405b17ce1afSJed Brown 2406b17ce1afSJed Brown Logically Collective 2407b17ce1afSJed Brown 2408b17ce1afSJed Brown Input Arguments: 2409b17ce1afSJed Brown + fine - nonlinear solver context on which to run a hook when restricting to a coarser level 2410b17ce1afSJed Brown . coarsenhook - function to run when setting up a coarser level 2411b17ce1afSJed Brown . restricthook - function to run to update data on coarser levels (once per SNESSolve()) 24120298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 2413b17ce1afSJed Brown 2414b17ce1afSJed Brown Calling sequence of coarsenhook: 2415b17ce1afSJed Brown $ coarsenhook(DM fine,DM coarse,void *ctx); 2416b17ce1afSJed Brown 2417b17ce1afSJed Brown + fine - fine level DM 2418b17ce1afSJed Brown . coarse - coarse level DM to restrict problem to 2419b17ce1afSJed Brown - ctx - optional user-defined function context 2420b17ce1afSJed Brown 2421b17ce1afSJed Brown Calling sequence for restricthook: 2422c833c3b5SJed Brown $ restricthook(DM fine,Mat mrestrict,Vec rscale,Mat inject,DM coarse,void *ctx) 2423b17ce1afSJed Brown 2424b17ce1afSJed Brown + fine - fine level DM 2425b17ce1afSJed Brown . mrestrict - matrix restricting a fine-level solution to the coarse grid 2426c833c3b5SJed Brown . rscale - scaling vector for restriction 2427c833c3b5SJed Brown . inject - matrix restricting by injection 2428b17ce1afSJed Brown . coarse - coarse level DM to update 2429b17ce1afSJed Brown - ctx - optional user-defined function context 2430b17ce1afSJed Brown 2431b17ce1afSJed Brown Level: advanced 2432b17ce1afSJed Brown 2433b17ce1afSJed Brown Notes: 2434b17ce1afSJed Brown This function is only needed if auxiliary data needs to be set up on coarse grids. 2435b17ce1afSJed Brown 2436b17ce1afSJed Brown If this function is called multiple times, the hooks will be run in the order they are added. 2437b17ce1afSJed Brown 2438b17ce1afSJed Brown In order to compose with nonlinear preconditioning without duplicating storage, the hook should be implemented to 2439b17ce1afSJed Brown extract the finest level information from its context (instead of from the SNES). 2440b17ce1afSJed Brown 2441bb9467b5SJed Brown This function is currently not available from Fortran. 2442bb9467b5SJed Brown 2443c833c3b5SJed Brown .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 2444b17ce1afSJed Brown @*/ 2445b17ce1afSJed Brown PetscErrorCode DMCoarsenHookAdd(DM fine,PetscErrorCode (*coarsenhook)(DM,DM,void*),PetscErrorCode (*restricthook)(DM,Mat,Vec,Mat,DM,void*),void *ctx) 2446b17ce1afSJed Brown { 2447b17ce1afSJed Brown PetscErrorCode ierr; 2448b17ce1afSJed Brown DMCoarsenHookLink link,*p; 2449b17ce1afSJed Brown 2450b17ce1afSJed Brown PetscFunctionBegin; 2451b17ce1afSJed Brown PetscValidHeaderSpecific(fine,DM_CLASSID,1); 24526bfea28cSJed Brown for (p=&fine->coarsenhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 2453*95dccacaSBarry Smith ierr = PetscNew(&link);CHKERRQ(ierr); 2454b17ce1afSJed Brown link->coarsenhook = coarsenhook; 2455b17ce1afSJed Brown link->restricthook = restricthook; 2456b17ce1afSJed Brown link->ctx = ctx; 24570298fd71SBarry Smith link->next = NULL; 2458b17ce1afSJed Brown *p = link; 2459b17ce1afSJed Brown PetscFunctionReturn(0); 2460b17ce1afSJed Brown } 2461b17ce1afSJed Brown 2462b17ce1afSJed Brown #undef __FUNCT__ 2463b17ce1afSJed Brown #define __FUNCT__ "DMRestrict" 2464b17ce1afSJed Brown /*@ 2465b17ce1afSJed Brown DMRestrict - restricts user-defined problem data to a coarser DM by running hooks registered by DMCoarsenHookAdd() 2466b17ce1afSJed Brown 2467b17ce1afSJed Brown Collective if any hooks are 2468b17ce1afSJed Brown 2469b17ce1afSJed Brown Input Arguments: 2470b17ce1afSJed Brown + fine - finer DM to use as a base 2471b17ce1afSJed Brown . restrct - restriction matrix, apply using MatRestrict() 2472b17ce1afSJed Brown . inject - injection matrix, also use MatRestrict() 2473b17ce1afSJed Brown - coarse - coarer DM to update 2474b17ce1afSJed Brown 2475b17ce1afSJed Brown Level: developer 2476b17ce1afSJed Brown 2477b17ce1afSJed Brown .seealso: DMCoarsenHookAdd(), MatRestrict() 2478b17ce1afSJed Brown @*/ 2479b17ce1afSJed Brown PetscErrorCode DMRestrict(DM fine,Mat restrct,Vec rscale,Mat inject,DM coarse) 2480b17ce1afSJed Brown { 2481b17ce1afSJed Brown PetscErrorCode ierr; 2482b17ce1afSJed Brown DMCoarsenHookLink link; 2483b17ce1afSJed Brown 2484b17ce1afSJed Brown PetscFunctionBegin; 2485b17ce1afSJed Brown for (link=fine->coarsenhook; link; link=link->next) { 24868865f1eaSKarl Rupp if (link->restricthook) { 24878865f1eaSKarl Rupp ierr = (*link->restricthook)(fine,restrct,rscale,inject,coarse,link->ctx);CHKERRQ(ierr); 24888865f1eaSKarl Rupp } 2489b17ce1afSJed Brown } 249047c6ae99SBarry Smith PetscFunctionReturn(0); 249147c6ae99SBarry Smith } 249247c6ae99SBarry Smith 249347c6ae99SBarry Smith #undef __FUNCT__ 2494be081cd6SPeter Brune #define __FUNCT__ "DMSubDomainHookAdd" 2495bb9467b5SJed Brown /*@C 2496be081cd6SPeter Brune DMSubDomainHookAdd - adds a callback to be run when restricting a problem to the coarse grid 24975dbd56e3SPeter Brune 24985dbd56e3SPeter Brune Logically Collective 24995dbd56e3SPeter Brune 25005dbd56e3SPeter Brune Input Arguments: 25015dbd56e3SPeter Brune + global - global DM 2502ec4806b8SPeter Brune . ddhook - function to run to pass data to the decomposition DM upon its creation 25035dbd56e3SPeter Brune . restricthook - function to run to update data on block solve (at the beginning of the block solve) 25040298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 25055dbd56e3SPeter Brune 2506ec4806b8SPeter Brune 2507ec4806b8SPeter Brune Calling sequence for ddhook: 2508ec4806b8SPeter Brune $ ddhook(DM global,DM block,void *ctx) 2509ec4806b8SPeter Brune 2510ec4806b8SPeter Brune + global - global DM 2511ec4806b8SPeter Brune . block - block DM 2512ec4806b8SPeter Brune - ctx - optional user-defined function context 2513ec4806b8SPeter Brune 25145dbd56e3SPeter Brune Calling sequence for restricthook: 2515ec4806b8SPeter Brune $ restricthook(DM global,VecScatter out,VecScatter in,DM block,void *ctx) 25165dbd56e3SPeter Brune 25175dbd56e3SPeter Brune + global - global DM 25185dbd56e3SPeter Brune . out - scatter to the outer (with ghost and overlap points) block vector 25195dbd56e3SPeter Brune . in - scatter to block vector values only owned locally 2520ec4806b8SPeter Brune . block - block DM 25215dbd56e3SPeter Brune - ctx - optional user-defined function context 25225dbd56e3SPeter Brune 25235dbd56e3SPeter Brune Level: advanced 25245dbd56e3SPeter Brune 25255dbd56e3SPeter Brune Notes: 2526ec4806b8SPeter Brune This function is only needed if auxiliary data needs to be set up on subdomain DMs. 25275dbd56e3SPeter Brune 25285dbd56e3SPeter Brune If this function is called multiple times, the hooks will be run in the order they are added. 25295dbd56e3SPeter Brune 25305dbd56e3SPeter Brune In order to compose with nonlinear preconditioning without duplicating storage, the hook should be implemented to 2531ec4806b8SPeter Brune extract the global information from its context (instead of from the SNES). 25325dbd56e3SPeter Brune 2533bb9467b5SJed Brown This function is currently not available from Fortran. 2534bb9467b5SJed Brown 25355dbd56e3SPeter Brune .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 25365dbd56e3SPeter Brune @*/ 2537be081cd6SPeter Brune PetscErrorCode DMSubDomainHookAdd(DM global,PetscErrorCode (*ddhook)(DM,DM,void*),PetscErrorCode (*restricthook)(DM,VecScatter,VecScatter,DM,void*),void *ctx) 25385dbd56e3SPeter Brune { 25395dbd56e3SPeter Brune PetscErrorCode ierr; 2540be081cd6SPeter Brune DMSubDomainHookLink link,*p; 25415dbd56e3SPeter Brune 25425dbd56e3SPeter Brune PetscFunctionBegin; 25435dbd56e3SPeter Brune PetscValidHeaderSpecific(global,DM_CLASSID,1); 2544be081cd6SPeter Brune for (p=&global->subdomainhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 2545*95dccacaSBarry Smith ierr = PetscNew(&link);CHKERRQ(ierr); 25465dbd56e3SPeter Brune link->restricthook = restricthook; 2547be081cd6SPeter Brune link->ddhook = ddhook; 25485dbd56e3SPeter Brune link->ctx = ctx; 25490298fd71SBarry Smith link->next = NULL; 25505dbd56e3SPeter Brune *p = link; 25515dbd56e3SPeter Brune PetscFunctionReturn(0); 25525dbd56e3SPeter Brune } 25535dbd56e3SPeter Brune 25545dbd56e3SPeter Brune #undef __FUNCT__ 2555be081cd6SPeter Brune #define __FUNCT__ "DMSubDomainRestrict" 25565dbd56e3SPeter Brune /*@ 2557be081cd6SPeter Brune DMSubDomainRestrict - restricts user-defined problem data to a block DM by running hooks registered by DMSubDomainHookAdd() 25585dbd56e3SPeter Brune 25595dbd56e3SPeter Brune Collective if any hooks are 25605dbd56e3SPeter Brune 25615dbd56e3SPeter Brune Input Arguments: 25625dbd56e3SPeter Brune + fine - finer DM to use as a base 2563be081cd6SPeter Brune . oscatter - scatter from domain global vector filling subdomain global vector with overlap 2564be081cd6SPeter Brune . gscatter - scatter from domain global vector filling subdomain local vector with ghosts 25655dbd56e3SPeter Brune - coarse - coarer DM to update 25665dbd56e3SPeter Brune 25675dbd56e3SPeter Brune Level: developer 25685dbd56e3SPeter Brune 25695dbd56e3SPeter Brune .seealso: DMCoarsenHookAdd(), MatRestrict() 25705dbd56e3SPeter Brune @*/ 2571be081cd6SPeter Brune PetscErrorCode DMSubDomainRestrict(DM global,VecScatter oscatter,VecScatter gscatter,DM subdm) 25725dbd56e3SPeter Brune { 25735dbd56e3SPeter Brune PetscErrorCode ierr; 2574be081cd6SPeter Brune DMSubDomainHookLink link; 25755dbd56e3SPeter Brune 25765dbd56e3SPeter Brune PetscFunctionBegin; 2577be081cd6SPeter Brune for (link=global->subdomainhook; link; link=link->next) { 25788865f1eaSKarl Rupp if (link->restricthook) { 25798865f1eaSKarl Rupp ierr = (*link->restricthook)(global,oscatter,gscatter,subdm,link->ctx);CHKERRQ(ierr); 25808865f1eaSKarl Rupp } 25815dbd56e3SPeter Brune } 25825dbd56e3SPeter Brune PetscFunctionReturn(0); 25835dbd56e3SPeter Brune } 25845dbd56e3SPeter Brune 25855dbd56e3SPeter Brune #undef __FUNCT__ 25865fe1f584SPeter Brune #define __FUNCT__ "DMGetCoarsenLevel" 25875fe1f584SPeter Brune /*@ 25886a7d9d85SPeter Brune DMGetCoarsenLevel - Get's the number of coarsenings that have generated this DM. 25895fe1f584SPeter Brune 25905fe1f584SPeter Brune Not Collective 25915fe1f584SPeter Brune 25925fe1f584SPeter Brune Input Parameter: 25935fe1f584SPeter Brune . dm - the DM object 25945fe1f584SPeter Brune 25955fe1f584SPeter Brune Output Parameter: 25966a7d9d85SPeter Brune . level - number of coarsenings 25975fe1f584SPeter Brune 25985fe1f584SPeter Brune Level: developer 25995fe1f584SPeter Brune 26006a7d9d85SPeter Brune .seealso DMCoarsen(), DMGetRefineLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 26015fe1f584SPeter Brune 26025fe1f584SPeter Brune @*/ 26035fe1f584SPeter Brune PetscErrorCode DMGetCoarsenLevel(DM dm,PetscInt *level) 26045fe1f584SPeter Brune { 26055fe1f584SPeter Brune PetscFunctionBegin; 26065fe1f584SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 26075fe1f584SPeter Brune *level = dm->leveldown; 26085fe1f584SPeter Brune PetscFunctionReturn(0); 26095fe1f584SPeter Brune } 26105fe1f584SPeter Brune 26115fe1f584SPeter Brune 26125fe1f584SPeter Brune 26135fe1f584SPeter Brune #undef __FUNCT__ 261447c6ae99SBarry Smith #define __FUNCT__ "DMRefineHierarchy" 261547c6ae99SBarry Smith /*@C 261647c6ae99SBarry Smith DMRefineHierarchy - Refines a DM object, all levels at once 261747c6ae99SBarry Smith 261847c6ae99SBarry Smith Collective on DM 261947c6ae99SBarry Smith 262047c6ae99SBarry Smith Input Parameter: 262147c6ae99SBarry Smith + dm - the DM object 262247c6ae99SBarry Smith - nlevels - the number of levels of refinement 262347c6ae99SBarry Smith 262447c6ae99SBarry Smith Output Parameter: 262547c6ae99SBarry Smith . dmf - the refined DM hierarchy 262647c6ae99SBarry Smith 262747c6ae99SBarry Smith Level: developer 262847c6ae99SBarry Smith 2629e727c939SJed Brown .seealso DMCoarsenHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 263047c6ae99SBarry Smith 263147c6ae99SBarry Smith @*/ 26327087cfbeSBarry Smith PetscErrorCode DMRefineHierarchy(DM dm,PetscInt nlevels,DM dmf[]) 263347c6ae99SBarry Smith { 263447c6ae99SBarry Smith PetscErrorCode ierr; 263547c6ae99SBarry Smith 263647c6ae99SBarry Smith PetscFunctionBegin; 2637171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2638ce94432eSBarry Smith if (nlevels < 0) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 263947c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 264047c6ae99SBarry Smith if (dm->ops->refinehierarchy) { 264147c6ae99SBarry Smith ierr = (*dm->ops->refinehierarchy)(dm,nlevels,dmf);CHKERRQ(ierr); 264247c6ae99SBarry Smith } else if (dm->ops->refine) { 264347c6ae99SBarry Smith PetscInt i; 264447c6ae99SBarry Smith 2645ce94432eSBarry Smith ierr = DMRefine(dm,PetscObjectComm((PetscObject)dm),&dmf[0]);CHKERRQ(ierr); 264647c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 2647ce94432eSBarry Smith ierr = DMRefine(dmf[i-1],PetscObjectComm((PetscObject)dm),&dmf[i]);CHKERRQ(ierr); 264847c6ae99SBarry Smith } 2649ce94432eSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No RefineHierarchy for this DM yet"); 265047c6ae99SBarry Smith PetscFunctionReturn(0); 265147c6ae99SBarry Smith } 265247c6ae99SBarry Smith 265347c6ae99SBarry Smith #undef __FUNCT__ 265447c6ae99SBarry Smith #define __FUNCT__ "DMCoarsenHierarchy" 265547c6ae99SBarry Smith /*@C 265647c6ae99SBarry Smith DMCoarsenHierarchy - Coarsens a DM object, all levels at once 265747c6ae99SBarry Smith 265847c6ae99SBarry Smith Collective on DM 265947c6ae99SBarry Smith 266047c6ae99SBarry Smith Input Parameter: 266147c6ae99SBarry Smith + dm - the DM object 266247c6ae99SBarry Smith - nlevels - the number of levels of coarsening 266347c6ae99SBarry Smith 266447c6ae99SBarry Smith Output Parameter: 266547c6ae99SBarry Smith . dmc - the coarsened DM hierarchy 266647c6ae99SBarry Smith 266747c6ae99SBarry Smith Level: developer 266847c6ae99SBarry Smith 2669e727c939SJed Brown .seealso DMRefineHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 267047c6ae99SBarry Smith 267147c6ae99SBarry Smith @*/ 26727087cfbeSBarry Smith PetscErrorCode DMCoarsenHierarchy(DM dm, PetscInt nlevels, DM dmc[]) 267347c6ae99SBarry Smith { 267447c6ae99SBarry Smith PetscErrorCode ierr; 267547c6ae99SBarry Smith 267647c6ae99SBarry Smith PetscFunctionBegin; 2677171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2678ce94432eSBarry Smith if (nlevels < 0) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 267947c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 268047c6ae99SBarry Smith PetscValidPointer(dmc,3); 268147c6ae99SBarry Smith if (dm->ops->coarsenhierarchy) { 268247c6ae99SBarry Smith ierr = (*dm->ops->coarsenhierarchy)(dm, nlevels, dmc);CHKERRQ(ierr); 268347c6ae99SBarry Smith } else if (dm->ops->coarsen) { 268447c6ae99SBarry Smith PetscInt i; 268547c6ae99SBarry Smith 2686ce94432eSBarry Smith ierr = DMCoarsen(dm,PetscObjectComm((PetscObject)dm),&dmc[0]);CHKERRQ(ierr); 268747c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 2688ce94432eSBarry Smith ierr = DMCoarsen(dmc[i-1],PetscObjectComm((PetscObject)dm),&dmc[i]);CHKERRQ(ierr); 268947c6ae99SBarry Smith } 2690ce94432eSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No CoarsenHierarchy for this DM yet"); 269147c6ae99SBarry Smith PetscFunctionReturn(0); 269247c6ae99SBarry Smith } 269347c6ae99SBarry Smith 269447c6ae99SBarry Smith #undef __FUNCT__ 2695e727c939SJed Brown #define __FUNCT__ "DMCreateAggregates" 269647c6ae99SBarry Smith /*@ 2697e727c939SJed Brown DMCreateAggregates - Gets the aggregates that map between 269847c6ae99SBarry Smith grids associated with two DMs. 269947c6ae99SBarry Smith 270047c6ae99SBarry Smith Collective on DM 270147c6ae99SBarry Smith 270247c6ae99SBarry Smith Input Parameters: 270347c6ae99SBarry Smith + dmc - the coarse grid DM 270447c6ae99SBarry Smith - dmf - the fine grid DM 270547c6ae99SBarry Smith 270647c6ae99SBarry Smith Output Parameters: 270747c6ae99SBarry Smith . rest - the restriction matrix (transpose of the projection matrix) 270847c6ae99SBarry Smith 270947c6ae99SBarry Smith Level: intermediate 271047c6ae99SBarry Smith 271147c6ae99SBarry Smith .keywords: interpolation, restriction, multigrid 271247c6ae99SBarry Smith 2713e727c939SJed Brown .seealso: DMRefine(), DMCreateInjection(), DMCreateInterpolation() 271447c6ae99SBarry Smith @*/ 2715e727c939SJed Brown PetscErrorCode DMCreateAggregates(DM dmc, DM dmf, Mat *rest) 271647c6ae99SBarry Smith { 271747c6ae99SBarry Smith PetscErrorCode ierr; 271847c6ae99SBarry Smith 271947c6ae99SBarry Smith PetscFunctionBegin; 2720171400e9SBarry Smith PetscValidHeaderSpecific(dmc,DM_CLASSID,1); 2721171400e9SBarry Smith PetscValidHeaderSpecific(dmf,DM_CLASSID,2); 272247c6ae99SBarry Smith ierr = (*dmc->ops->getaggregates)(dmc, dmf, rest);CHKERRQ(ierr); 272347c6ae99SBarry Smith PetscFunctionReturn(0); 272447c6ae99SBarry Smith } 272547c6ae99SBarry Smith 272647c6ae99SBarry Smith #undef __FUNCT__ 27271a266240SBarry Smith #define __FUNCT__ "DMSetApplicationContextDestroy" 27281a266240SBarry Smith /*@C 27291a266240SBarry Smith DMSetApplicationContextDestroy - Sets a user function that will be called to destroy the application context when the DM is destroyed 27301a266240SBarry Smith 27311a266240SBarry Smith Not Collective 27321a266240SBarry Smith 27331a266240SBarry Smith Input Parameters: 27341a266240SBarry Smith + dm - the DM object 27351a266240SBarry Smith - destroy - the destroy function 27361a266240SBarry Smith 27371a266240SBarry Smith Level: intermediate 27381a266240SBarry Smith 2739e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 27401a266240SBarry Smith 2741f07f9ceaSJed Brown @*/ 27421a266240SBarry Smith PetscErrorCode DMSetApplicationContextDestroy(DM dm,PetscErrorCode (*destroy)(void**)) 27431a266240SBarry Smith { 27441a266240SBarry Smith PetscFunctionBegin; 2745171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 27461a266240SBarry Smith dm->ctxdestroy = destroy; 27471a266240SBarry Smith PetscFunctionReturn(0); 27481a266240SBarry Smith } 27491a266240SBarry Smith 27501a266240SBarry Smith #undef __FUNCT__ 27511b2093e4SBarry Smith #define __FUNCT__ "DMSetApplicationContext" 2752b07ff414SBarry Smith /*@ 27531b2093e4SBarry Smith DMSetApplicationContext - Set a user context into a DM object 275447c6ae99SBarry Smith 275547c6ae99SBarry Smith Not Collective 275647c6ae99SBarry Smith 275747c6ae99SBarry Smith Input Parameters: 275847c6ae99SBarry Smith + dm - the DM object 275947c6ae99SBarry Smith - ctx - the user context 276047c6ae99SBarry Smith 276147c6ae99SBarry Smith Level: intermediate 276247c6ae99SBarry Smith 2763e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 276447c6ae99SBarry Smith 276547c6ae99SBarry Smith @*/ 27661b2093e4SBarry Smith PetscErrorCode DMSetApplicationContext(DM dm,void *ctx) 276747c6ae99SBarry Smith { 276847c6ae99SBarry Smith PetscFunctionBegin; 2769171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 277047c6ae99SBarry Smith dm->ctx = ctx; 277147c6ae99SBarry Smith PetscFunctionReturn(0); 277247c6ae99SBarry Smith } 277347c6ae99SBarry Smith 277447c6ae99SBarry Smith #undef __FUNCT__ 27751b2093e4SBarry Smith #define __FUNCT__ "DMGetApplicationContext" 277647c6ae99SBarry Smith /*@ 27771b2093e4SBarry Smith DMGetApplicationContext - Gets a user context from a DM object 277847c6ae99SBarry Smith 277947c6ae99SBarry Smith Not Collective 278047c6ae99SBarry Smith 278147c6ae99SBarry Smith Input Parameter: 278247c6ae99SBarry Smith . dm - the DM object 278347c6ae99SBarry Smith 278447c6ae99SBarry Smith Output Parameter: 278547c6ae99SBarry Smith . ctx - the user context 278647c6ae99SBarry Smith 278747c6ae99SBarry Smith Level: intermediate 278847c6ae99SBarry Smith 2789e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 279047c6ae99SBarry Smith 279147c6ae99SBarry Smith @*/ 27921b2093e4SBarry Smith PetscErrorCode DMGetApplicationContext(DM dm,void *ctx) 279347c6ae99SBarry Smith { 279447c6ae99SBarry Smith PetscFunctionBegin; 2795171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 27961b2093e4SBarry Smith *(void**)ctx = dm->ctx; 279747c6ae99SBarry Smith PetscFunctionReturn(0); 279847c6ae99SBarry Smith } 279947c6ae99SBarry Smith 280047c6ae99SBarry Smith #undef __FUNCT__ 280108da532bSDmitry Karpeev #define __FUNCT__ "DMSetVariableBounds" 280208da532bSDmitry Karpeev /*@C 2803df3898eeSBarry Smith DMSetVariableBounds - sets a function to compute the lower and upper bound vectors for SNESVI. 280408da532bSDmitry Karpeev 280508da532bSDmitry Karpeev Logically Collective on DM 280608da532bSDmitry Karpeev 280708da532bSDmitry Karpeev Input Parameter: 280808da532bSDmitry Karpeev + dm - the DM object 28090298fd71SBarry Smith - f - the function that computes variable bounds used by SNESVI (use NULL to cancel a previous function that was set) 281008da532bSDmitry Karpeev 281108da532bSDmitry Karpeev Level: intermediate 281208da532bSDmitry Karpeev 2813835c3ec7SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), 281408da532bSDmitry Karpeev DMSetJacobian() 281508da532bSDmitry Karpeev 281608da532bSDmitry Karpeev @*/ 281708da532bSDmitry Karpeev PetscErrorCode DMSetVariableBounds(DM dm,PetscErrorCode (*f)(DM,Vec,Vec)) 281808da532bSDmitry Karpeev { 281908da532bSDmitry Karpeev PetscFunctionBegin; 282008da532bSDmitry Karpeev dm->ops->computevariablebounds = f; 282108da532bSDmitry Karpeev PetscFunctionReturn(0); 282208da532bSDmitry Karpeev } 282308da532bSDmitry Karpeev 282408da532bSDmitry Karpeev #undef __FUNCT__ 282508da532bSDmitry Karpeev #define __FUNCT__ "DMHasVariableBounds" 282608da532bSDmitry Karpeev /*@ 282708da532bSDmitry Karpeev DMHasVariableBounds - does the DM object have a variable bounds function? 282808da532bSDmitry Karpeev 282908da532bSDmitry Karpeev Not Collective 283008da532bSDmitry Karpeev 283108da532bSDmitry Karpeev Input Parameter: 283208da532bSDmitry Karpeev . dm - the DM object to destroy 283308da532bSDmitry Karpeev 283408da532bSDmitry Karpeev Output Parameter: 283508da532bSDmitry Karpeev . flg - PETSC_TRUE if the variable bounds function exists 283608da532bSDmitry Karpeev 283708da532bSDmitry Karpeev Level: developer 283808da532bSDmitry Karpeev 283974e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 284008da532bSDmitry Karpeev 284108da532bSDmitry Karpeev @*/ 284208da532bSDmitry Karpeev PetscErrorCode DMHasVariableBounds(DM dm,PetscBool *flg) 284308da532bSDmitry Karpeev { 284408da532bSDmitry Karpeev PetscFunctionBegin; 284508da532bSDmitry Karpeev *flg = (dm->ops->computevariablebounds) ? PETSC_TRUE : PETSC_FALSE; 284608da532bSDmitry Karpeev PetscFunctionReturn(0); 284708da532bSDmitry Karpeev } 284808da532bSDmitry Karpeev 284908da532bSDmitry Karpeev #undef __FUNCT__ 285008da532bSDmitry Karpeev #define __FUNCT__ "DMComputeVariableBounds" 285108da532bSDmitry Karpeev /*@C 285208da532bSDmitry Karpeev DMComputeVariableBounds - compute variable bounds used by SNESVI. 285308da532bSDmitry Karpeev 285408da532bSDmitry Karpeev Logically Collective on DM 285508da532bSDmitry Karpeev 285608da532bSDmitry Karpeev Input Parameters: 2857907376e6SBarry Smith . dm - the DM object 285808da532bSDmitry Karpeev 285908da532bSDmitry Karpeev Output parameters: 286008da532bSDmitry Karpeev + xl - lower bound 286108da532bSDmitry Karpeev - xu - upper bound 286208da532bSDmitry Karpeev 2863907376e6SBarry Smith Level: advanced 2864907376e6SBarry Smith 2865907376e6SBarry Smith Notes: This is generally not called by users. It calls the function provided by the user with DMSetVariableBounds() 286608da532bSDmitry Karpeev 286774e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 286808da532bSDmitry Karpeev 286908da532bSDmitry Karpeev @*/ 287008da532bSDmitry Karpeev PetscErrorCode DMComputeVariableBounds(DM dm, Vec xl, Vec xu) 287108da532bSDmitry Karpeev { 287208da532bSDmitry Karpeev PetscErrorCode ierr; 28735fd66863SKarl Rupp 287408da532bSDmitry Karpeev PetscFunctionBegin; 287508da532bSDmitry Karpeev PetscValidHeaderSpecific(xl,VEC_CLASSID,2); 287608da532bSDmitry Karpeev PetscValidHeaderSpecific(xu,VEC_CLASSID,2); 287708da532bSDmitry Karpeev if (dm->ops->computevariablebounds) { 287808da532bSDmitry Karpeev ierr = (*dm->ops->computevariablebounds)(dm, xl,xu);CHKERRQ(ierr); 28798865f1eaSKarl Rupp } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "This DM is incapable of computing variable bounds."); 288008da532bSDmitry Karpeev PetscFunctionReturn(0); 288108da532bSDmitry Karpeev } 288208da532bSDmitry Karpeev 288308da532bSDmitry Karpeev #undef __FUNCT__ 2884b0ae01b7SPeter Brune #define __FUNCT__ "DMHasColoring" 2885b0ae01b7SPeter Brune /*@ 2886b0ae01b7SPeter Brune DMHasColoring - does the DM object have a method of providing a coloring? 2887b0ae01b7SPeter Brune 2888b0ae01b7SPeter Brune Not Collective 2889b0ae01b7SPeter Brune 2890b0ae01b7SPeter Brune Input Parameter: 2891b0ae01b7SPeter Brune . dm - the DM object 2892b0ae01b7SPeter Brune 2893b0ae01b7SPeter Brune Output Parameter: 2894b0ae01b7SPeter Brune . flg - PETSC_TRUE if the DM has facilities for DMCreateColoring(). 2895b0ae01b7SPeter Brune 2896b0ae01b7SPeter Brune Level: developer 2897b0ae01b7SPeter Brune 2898b0ae01b7SPeter Brune .seealso DMHasFunction(), DMCreateColoring() 2899b0ae01b7SPeter Brune 2900b0ae01b7SPeter Brune @*/ 2901b0ae01b7SPeter Brune PetscErrorCode DMHasColoring(DM dm,PetscBool *flg) 2902b0ae01b7SPeter Brune { 2903b0ae01b7SPeter Brune PetscFunctionBegin; 2904b0ae01b7SPeter Brune *flg = (dm->ops->getcoloring) ? PETSC_TRUE : PETSC_FALSE; 2905b0ae01b7SPeter Brune PetscFunctionReturn(0); 2906b0ae01b7SPeter Brune } 2907b0ae01b7SPeter Brune 2908b0ae01b7SPeter Brune #undef __FUNCT__ 29093ad4599aSBarry Smith #define __FUNCT__ "DMHasCreateRestriction" 29103ad4599aSBarry Smith /*@ 29113ad4599aSBarry Smith DMHasCreateRestriction - does the DM object have a method of providing a restriction? 29123ad4599aSBarry Smith 29133ad4599aSBarry Smith Not Collective 29143ad4599aSBarry Smith 29153ad4599aSBarry Smith Input Parameter: 29163ad4599aSBarry Smith . dm - the DM object 29173ad4599aSBarry Smith 29183ad4599aSBarry Smith Output Parameter: 29193ad4599aSBarry Smith . flg - PETSC_TRUE if the DM has facilities for DMCreateRestriction(). 29203ad4599aSBarry Smith 29213ad4599aSBarry Smith Level: developer 29223ad4599aSBarry Smith 29233ad4599aSBarry Smith .seealso DMHasFunction(), DMCreateRestriction() 29243ad4599aSBarry Smith 29253ad4599aSBarry Smith @*/ 29263ad4599aSBarry Smith PetscErrorCode DMHasCreateRestriction(DM dm,PetscBool *flg) 29273ad4599aSBarry Smith { 29283ad4599aSBarry Smith PetscFunctionBegin; 29293ad4599aSBarry Smith *flg = (dm->ops->createrestriction) ? PETSC_TRUE : PETSC_FALSE; 29303ad4599aSBarry Smith PetscFunctionReturn(0); 29313ad4599aSBarry Smith } 29323ad4599aSBarry Smith 29333ad4599aSBarry Smith #undef __FUNCT__ 293408da532bSDmitry Karpeev #define __FUNCT__ "DMSetVec" 2935748fac09SDmitry Karpeev /*@C 293608da532bSDmitry Karpeev DMSetVec - set the vector at which to compute residual, Jacobian and VI bounds, if the problem is nonlinear. 293708da532bSDmitry Karpeev 293808da532bSDmitry Karpeev Collective on DM 293908da532bSDmitry Karpeev 294008da532bSDmitry Karpeev Input Parameter: 294108da532bSDmitry Karpeev + dm - the DM object 29420298fd71SBarry Smith - x - location to compute residual and Jacobian, if NULL is passed to those routines; will be NULL for linear problems. 294308da532bSDmitry Karpeev 294408da532bSDmitry Karpeev Level: developer 294508da532bSDmitry Karpeev 294674e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 294708da532bSDmitry Karpeev 294808da532bSDmitry Karpeev @*/ 294908da532bSDmitry Karpeev PetscErrorCode DMSetVec(DM dm,Vec x) 295008da532bSDmitry Karpeev { 295108da532bSDmitry Karpeev PetscErrorCode ierr; 29525fd66863SKarl Rupp 295308da532bSDmitry Karpeev PetscFunctionBegin; 295408da532bSDmitry Karpeev if (x) { 295508da532bSDmitry Karpeev if (!dm->x) { 295608da532bSDmitry Karpeev ierr = DMCreateGlobalVector(dm,&dm->x);CHKERRQ(ierr); 295708da532bSDmitry Karpeev } 295808da532bSDmitry Karpeev ierr = VecCopy(x,dm->x);CHKERRQ(ierr); 29598865f1eaSKarl Rupp } else if (dm->x) { 296008da532bSDmitry Karpeev ierr = VecDestroy(&dm->x);CHKERRQ(ierr); 296108da532bSDmitry Karpeev } 296208da532bSDmitry Karpeev PetscFunctionReturn(0); 296308da532bSDmitry Karpeev } 296408da532bSDmitry Karpeev 29650298fd71SBarry Smith PetscFunctionList DMList = NULL; 2966264ace61SBarry Smith PetscBool DMRegisterAllCalled = PETSC_FALSE; 2967264ace61SBarry Smith 2968264ace61SBarry Smith #undef __FUNCT__ 2969264ace61SBarry Smith #define __FUNCT__ "DMSetType" 2970264ace61SBarry Smith /*@C 2971264ace61SBarry Smith DMSetType - Builds a DM, for a particular DM implementation. 2972264ace61SBarry Smith 2973264ace61SBarry Smith Collective on DM 2974264ace61SBarry Smith 2975264ace61SBarry Smith Input Parameters: 2976264ace61SBarry Smith + dm - The DM object 2977264ace61SBarry Smith - method - The name of the DM type 2978264ace61SBarry Smith 2979264ace61SBarry Smith Options Database Key: 2980264ace61SBarry Smith . -dm_type <type> - Sets the DM type; use -help for a list of available types 2981264ace61SBarry Smith 2982264ace61SBarry Smith Notes: 2983e1589f56SBarry Smith See "petsc/include/petscdm.h" for available DM types (for instance, DM1D, DM2D, or DM3D). 2984264ace61SBarry Smith 2985264ace61SBarry Smith Level: intermediate 2986264ace61SBarry Smith 2987264ace61SBarry Smith .keywords: DM, set, type 2988264ace61SBarry Smith .seealso: DMGetType(), DMCreate() 2989264ace61SBarry Smith @*/ 299019fd82e9SBarry Smith PetscErrorCode DMSetType(DM dm, DMType method) 2991264ace61SBarry Smith { 2992264ace61SBarry Smith PetscErrorCode (*r)(DM); 2993264ace61SBarry Smith PetscBool match; 2994264ace61SBarry Smith PetscErrorCode ierr; 2995264ace61SBarry Smith 2996264ace61SBarry Smith PetscFunctionBegin; 2997264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 2998251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject) dm, method, &match);CHKERRQ(ierr); 2999264ace61SBarry Smith if (match) PetscFunctionReturn(0); 3000264ace61SBarry Smith 30010f51fdf8SToby Isaac ierr = DMRegisterAll();CHKERRQ(ierr); 30021c9cd337SJed Brown ierr = PetscFunctionListFind(DMList,method,&r);CHKERRQ(ierr); 3003ce94432eSBarry Smith if (!r) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown DM type: %s", method); 3004264ace61SBarry Smith 3005264ace61SBarry Smith if (dm->ops->destroy) { 3006264ace61SBarry Smith ierr = (*dm->ops->destroy)(dm);CHKERRQ(ierr); 30070298fd71SBarry Smith dm->ops->destroy = NULL; 3008264ace61SBarry Smith } 3009264ace61SBarry Smith ierr = (*r)(dm);CHKERRQ(ierr); 3010264ace61SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)dm,method);CHKERRQ(ierr); 3011264ace61SBarry Smith PetscFunctionReturn(0); 3012264ace61SBarry Smith } 3013264ace61SBarry Smith 3014264ace61SBarry Smith #undef __FUNCT__ 3015264ace61SBarry Smith #define __FUNCT__ "DMGetType" 3016264ace61SBarry Smith /*@C 3017264ace61SBarry Smith DMGetType - Gets the DM type name (as a string) from the DM. 3018264ace61SBarry Smith 3019264ace61SBarry Smith Not Collective 3020264ace61SBarry Smith 3021264ace61SBarry Smith Input Parameter: 3022264ace61SBarry Smith . dm - The DM 3023264ace61SBarry Smith 3024264ace61SBarry Smith Output Parameter: 3025264ace61SBarry Smith . type - The DM type name 3026264ace61SBarry Smith 3027264ace61SBarry Smith Level: intermediate 3028264ace61SBarry Smith 3029264ace61SBarry Smith .keywords: DM, get, type, name 3030264ace61SBarry Smith .seealso: DMSetType(), DMCreate() 3031264ace61SBarry Smith @*/ 303219fd82e9SBarry Smith PetscErrorCode DMGetType(DM dm, DMType *type) 3033264ace61SBarry Smith { 3034264ace61SBarry Smith PetscErrorCode ierr; 3035264ace61SBarry Smith 3036264ace61SBarry Smith PetscFunctionBegin; 3037264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 3038c959eef4SJed Brown PetscValidPointer(type,2); 3039607a6623SBarry Smith ierr = DMRegisterAll();CHKERRQ(ierr); 3040264ace61SBarry Smith *type = ((PetscObject)dm)->type_name; 3041264ace61SBarry Smith PetscFunctionReturn(0); 3042264ace61SBarry Smith } 3043264ace61SBarry Smith 304467a56275SMatthew G Knepley #undef __FUNCT__ 304567a56275SMatthew G Knepley #define __FUNCT__ "DMConvert" 304667a56275SMatthew G Knepley /*@C 304767a56275SMatthew G Knepley DMConvert - Converts a DM to another DM, either of the same or different type. 304867a56275SMatthew G Knepley 304967a56275SMatthew G Knepley Collective on DM 305067a56275SMatthew G Knepley 305167a56275SMatthew G Knepley Input Parameters: 305267a56275SMatthew G Knepley + dm - the DM 305367a56275SMatthew G Knepley - newtype - new DM type (use "same" for the same type) 305467a56275SMatthew G Knepley 305567a56275SMatthew G Knepley Output Parameter: 305667a56275SMatthew G Knepley . M - pointer to new DM 305767a56275SMatthew G Knepley 305867a56275SMatthew G Knepley Notes: 305967a56275SMatthew G Knepley Cannot be used to convert a sequential DM to parallel or parallel to sequential, 306067a56275SMatthew G Knepley the MPI communicator of the generated DM is always the same as the communicator 306167a56275SMatthew G Knepley of the input DM. 306267a56275SMatthew G Knepley 306367a56275SMatthew G Knepley Level: intermediate 306467a56275SMatthew G Knepley 306567a56275SMatthew G Knepley .seealso: DMCreate() 306667a56275SMatthew G Knepley @*/ 306719fd82e9SBarry Smith PetscErrorCode DMConvert(DM dm, DMType newtype, DM *M) 306867a56275SMatthew G Knepley { 306967a56275SMatthew G Knepley DM B; 307067a56275SMatthew G Knepley char convname[256]; 3071c067b6caSMatthew G. Knepley PetscBool sametype/*, issame */; 307267a56275SMatthew G Knepley PetscErrorCode ierr; 307367a56275SMatthew G Knepley 307467a56275SMatthew G Knepley PetscFunctionBegin; 307567a56275SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 307667a56275SMatthew G Knepley PetscValidType(dm,1); 307767a56275SMatthew G Knepley PetscValidPointer(M,3); 3078251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject) dm, newtype, &sametype);CHKERRQ(ierr); 3079c067b6caSMatthew G. Knepley /* ierr = PetscStrcmp(newtype, "same", &issame);CHKERRQ(ierr); */ 3080c067b6caSMatthew G. Knepley if (sametype) { 3081c067b6caSMatthew G. Knepley *M = dm; 3082c067b6caSMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm);CHKERRQ(ierr); 3083c067b6caSMatthew G. Knepley PetscFunctionReturn(0); 3084c067b6caSMatthew G. Knepley } else { 30850298fd71SBarry Smith PetscErrorCode (*conv)(DM, DMType, DM*) = NULL; 308667a56275SMatthew G Knepley 308767a56275SMatthew G Knepley /* 308867a56275SMatthew G Knepley Order of precedence: 308967a56275SMatthew G Knepley 1) See if a specialized converter is known to the current DM. 309067a56275SMatthew G Knepley 2) See if a specialized converter is known to the desired DM class. 309167a56275SMatthew G Knepley 3) See if a good general converter is registered for the desired class 309267a56275SMatthew G Knepley 4) See if a good general converter is known for the current matrix. 309367a56275SMatthew G Knepley 5) Use a really basic converter. 309467a56275SMatthew G Knepley */ 309567a56275SMatthew G Knepley 309667a56275SMatthew G Knepley /* 1) See if a specialized converter is known to the current DM and the desired class */ 309767a56275SMatthew G Knepley ierr = PetscStrcpy(convname,"DMConvert_");CHKERRQ(ierr); 309867a56275SMatthew G Knepley ierr = PetscStrcat(convname,((PetscObject) dm)->type_name);CHKERRQ(ierr); 309967a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_");CHKERRQ(ierr); 310067a56275SMatthew G Knepley ierr = PetscStrcat(convname,newtype);CHKERRQ(ierr); 310167a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_C");CHKERRQ(ierr); 31020005d66cSJed Brown ierr = PetscObjectQueryFunction((PetscObject)dm,convname,&conv);CHKERRQ(ierr); 310367a56275SMatthew G Knepley if (conv) goto foundconv; 310467a56275SMatthew G Knepley 310567a56275SMatthew G Knepley /* 2) See if a specialized converter is known to the desired DM class. */ 310682f516ccSBarry Smith ierr = DMCreate(PetscObjectComm((PetscObject)dm), &B);CHKERRQ(ierr); 310767a56275SMatthew G Knepley ierr = DMSetType(B, newtype);CHKERRQ(ierr); 310867a56275SMatthew G Knepley ierr = PetscStrcpy(convname,"DMConvert_");CHKERRQ(ierr); 310967a56275SMatthew G Knepley ierr = PetscStrcat(convname,((PetscObject) dm)->type_name);CHKERRQ(ierr); 311067a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_");CHKERRQ(ierr); 311167a56275SMatthew G Knepley ierr = PetscStrcat(convname,newtype);CHKERRQ(ierr); 311267a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_C");CHKERRQ(ierr); 31130005d66cSJed Brown ierr = PetscObjectQueryFunction((PetscObject)B,convname,&conv);CHKERRQ(ierr); 311467a56275SMatthew G Knepley if (conv) { 3115fcfd50ebSBarry Smith ierr = DMDestroy(&B);CHKERRQ(ierr); 311667a56275SMatthew G Knepley goto foundconv; 311767a56275SMatthew G Knepley } 311867a56275SMatthew G Knepley 311967a56275SMatthew G Knepley #if 0 312067a56275SMatthew G Knepley /* 3) See if a good general converter is registered for the desired class */ 312167a56275SMatthew G Knepley conv = B->ops->convertfrom; 3122fcfd50ebSBarry Smith ierr = DMDestroy(&B);CHKERRQ(ierr); 312367a56275SMatthew G Knepley if (conv) goto foundconv; 312467a56275SMatthew G Knepley 312567a56275SMatthew G Knepley /* 4) See if a good general converter is known for the current matrix */ 312667a56275SMatthew G Knepley if (dm->ops->convert) { 312767a56275SMatthew G Knepley conv = dm->ops->convert; 312867a56275SMatthew G Knepley } 312967a56275SMatthew G Knepley if (conv) goto foundconv; 313067a56275SMatthew G Knepley #endif 313167a56275SMatthew G Knepley 313267a56275SMatthew G Knepley /* 5) Use a really basic converter. */ 313382f516ccSBarry Smith SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "No conversion possible between DM types %s and %s", ((PetscObject) dm)->type_name, newtype); 313467a56275SMatthew G Knepley 313567a56275SMatthew G Knepley foundconv: 313667a56275SMatthew G Knepley ierr = PetscLogEventBegin(DM_Convert,dm,0,0,0);CHKERRQ(ierr); 313767a56275SMatthew G Knepley ierr = (*conv)(dm,newtype,M);CHKERRQ(ierr); 313812fa691eSMatthew G. Knepley /* Things that are independent of DM type: We should consult DMClone() here */ 313912fa691eSMatthew G. Knepley if (dm->maxCell) { 314012fa691eSMatthew G. Knepley const PetscReal *maxCell, *L; 314112fa691eSMatthew G. Knepley const DMBoundaryType *bd; 314212fa691eSMatthew G. Knepley ierr = DMGetPeriodicity(dm, &maxCell, &L, &bd);CHKERRQ(ierr); 314312fa691eSMatthew G. Knepley ierr = DMSetPeriodicity(*M, maxCell, L, bd);CHKERRQ(ierr); 314412fa691eSMatthew G. Knepley } 314567a56275SMatthew G Knepley ierr = PetscLogEventEnd(DM_Convert,dm,0,0,0);CHKERRQ(ierr); 314667a56275SMatthew G Knepley } 314767a56275SMatthew G Knepley ierr = PetscObjectStateIncrease((PetscObject) *M);CHKERRQ(ierr); 314867a56275SMatthew G Knepley PetscFunctionReturn(0); 314967a56275SMatthew G Knepley } 3150264ace61SBarry Smith 3151264ace61SBarry Smith /*--------------------------------------------------------------------------------------------------------------------*/ 3152264ace61SBarry Smith 3153264ace61SBarry Smith #undef __FUNCT__ 3154264ace61SBarry Smith #define __FUNCT__ "DMRegister" 3155264ace61SBarry Smith /*@C 31561c84c290SBarry Smith DMRegister - Adds a new DM component implementation 31571c84c290SBarry Smith 31581c84c290SBarry Smith Not Collective 31591c84c290SBarry Smith 31601c84c290SBarry Smith Input Parameters: 31611c84c290SBarry Smith + name - The name of a new user-defined creation routine 31621c84c290SBarry Smith - create_func - The creation routine itself 31631c84c290SBarry Smith 31641c84c290SBarry Smith Notes: 31651c84c290SBarry Smith DMRegister() may be called multiple times to add several user-defined DMs 31661c84c290SBarry Smith 31671c84c290SBarry Smith 31681c84c290SBarry Smith Sample usage: 31691c84c290SBarry Smith .vb 3170bdf89e91SBarry Smith DMRegister("my_da", MyDMCreate); 31711c84c290SBarry Smith .ve 31721c84c290SBarry Smith 31731c84c290SBarry Smith Then, your DM type can be chosen with the procedural interface via 31741c84c290SBarry Smith .vb 31751c84c290SBarry Smith DMCreate(MPI_Comm, DM *); 31761c84c290SBarry Smith DMSetType(DM,"my_da"); 31771c84c290SBarry Smith .ve 31781c84c290SBarry Smith or at runtime via the option 31791c84c290SBarry Smith .vb 31801c84c290SBarry Smith -da_type my_da 31811c84c290SBarry Smith .ve 3182264ace61SBarry Smith 3183264ace61SBarry Smith Level: advanced 31841c84c290SBarry Smith 31851c84c290SBarry Smith .keywords: DM, register 3186bdf89e91SBarry Smith .seealso: DMRegisterAll(), DMRegisterDestroy() 31871c84c290SBarry Smith 3188264ace61SBarry Smith @*/ 3189bdf89e91SBarry Smith PetscErrorCode DMRegister(const char sname[],PetscErrorCode (*function)(DM)) 3190264ace61SBarry Smith { 3191264ace61SBarry Smith PetscErrorCode ierr; 3192264ace61SBarry Smith 3193264ace61SBarry Smith PetscFunctionBegin; 3194a240a19fSJed Brown ierr = PetscFunctionListAdd(&DMList,sname,function);CHKERRQ(ierr); 3195264ace61SBarry Smith PetscFunctionReturn(0); 3196264ace61SBarry Smith } 3197264ace61SBarry Smith 3198b859378eSBarry Smith #undef __FUNCT__ 3199b859378eSBarry Smith #define __FUNCT__ "DMLoad" 3200b859378eSBarry Smith /*@C 320155849f57SBarry Smith DMLoad - Loads a DM that has been stored in binary with DMView(). 3202b859378eSBarry Smith 3203b859378eSBarry Smith Collective on PetscViewer 3204b859378eSBarry Smith 3205b859378eSBarry Smith Input Parameters: 3206b859378eSBarry Smith + newdm - the newly loaded DM, this needs to have been created with DMCreate() or 3207b859378eSBarry Smith some related function before a call to DMLoad(). 3208b859378eSBarry Smith - viewer - binary file viewer, obtained from PetscViewerBinaryOpen() or 3209b859378eSBarry Smith HDF5 file viewer, obtained from PetscViewerHDF5Open() 3210b859378eSBarry Smith 3211b859378eSBarry Smith Level: intermediate 3212b859378eSBarry Smith 3213b859378eSBarry Smith Notes: 321455849f57SBarry Smith The type is determined by the data in the file, any type set into the DM before this call is ignored. 3215b859378eSBarry Smith 3216b859378eSBarry Smith Notes for advanced users: 3217b859378eSBarry Smith Most users should not need to know the details of the binary storage 3218b859378eSBarry Smith format, since DMLoad() and DMView() completely hide these details. 3219b859378eSBarry Smith But for anyone who's interested, the standard binary matrix storage 3220b859378eSBarry Smith format is 3221b859378eSBarry Smith .vb 3222b859378eSBarry Smith has not yet been determined 3223b859378eSBarry Smith .ve 3224b859378eSBarry Smith 3225b859378eSBarry Smith .seealso: PetscViewerBinaryOpen(), DMView(), MatLoad(), VecLoad() 3226b859378eSBarry Smith @*/ 3227b859378eSBarry Smith PetscErrorCode DMLoad(DM newdm, PetscViewer viewer) 3228b859378eSBarry Smith { 32299331c7a4SMatthew G. Knepley PetscBool isbinary, ishdf5; 3230b859378eSBarry Smith PetscErrorCode ierr; 3231b859378eSBarry Smith 3232b859378eSBarry Smith PetscFunctionBegin; 3233b859378eSBarry Smith PetscValidHeaderSpecific(newdm,DM_CLASSID,1); 3234b859378eSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 323532c0f0efSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); 32369331c7a4SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERHDF5,&ishdf5);CHKERRQ(ierr); 32379331c7a4SMatthew G. Knepley if (isbinary) { 32389331c7a4SMatthew G. Knepley PetscInt classid; 32399331c7a4SMatthew G. Knepley char type[256]; 3240b859378eSBarry Smith 3241060da220SMatthew G. Knepley ierr = PetscViewerBinaryRead(viewer,&classid,1,NULL,PETSC_INT);CHKERRQ(ierr); 32429200755eSBarry Smith if (classid != DM_FILE_CLASSID) SETERRQ1(PetscObjectComm((PetscObject)newdm),PETSC_ERR_ARG_WRONG,"Not DM next in file, classid found %d",(int)classid); 3243060da220SMatthew G. Knepley ierr = PetscViewerBinaryRead(viewer,type,256,NULL,PETSC_CHAR);CHKERRQ(ierr); 324432c0f0efSBarry Smith ierr = DMSetType(newdm, type);CHKERRQ(ierr); 32459331c7a4SMatthew G. Knepley if (newdm->ops->load) {ierr = (*newdm->ops->load)(newdm,viewer);CHKERRQ(ierr);} 32469331c7a4SMatthew G. Knepley } else if (ishdf5) { 32479331c7a4SMatthew G. Knepley if (newdm->ops->load) {ierr = (*newdm->ops->load)(newdm,viewer);CHKERRQ(ierr);} 32489331c7a4SMatthew G. Knepley } else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Invalid viewer; open viewer with PetscViewerBinaryOpen() or PetscViewerHDF5Open()"); 3249b859378eSBarry Smith PetscFunctionReturn(0); 3250b859378eSBarry Smith } 3251b859378eSBarry Smith 32527da65231SMatthew G Knepley /******************************** FEM Support **********************************/ 32537da65231SMatthew G Knepley 32547da65231SMatthew G Knepley #undef __FUNCT__ 32557da65231SMatthew G Knepley #define __FUNCT__ "DMPrintCellVector" 3256a6dfd86eSKarl Rupp PetscErrorCode DMPrintCellVector(PetscInt c, const char name[], PetscInt len, const PetscScalar x[]) 3257a6dfd86eSKarl Rupp { 32581d47ebbbSSatish Balay PetscInt f; 32591b30c384SMatthew G Knepley PetscErrorCode ierr; 32601b30c384SMatthew G Knepley 32617da65231SMatthew G Knepley PetscFunctionBegin; 326274778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, "Cell %D Element %s\n", c, name);CHKERRQ(ierr); 32631d47ebbbSSatish Balay for (f = 0; f < len; ++f) { 326457622a8eSBarry Smith ierr = PetscPrintf(PETSC_COMM_SELF, " | %g |\n", (double)PetscRealPart(x[f]));CHKERRQ(ierr); 32657da65231SMatthew G Knepley } 32667da65231SMatthew G Knepley PetscFunctionReturn(0); 32677da65231SMatthew G Knepley } 32687da65231SMatthew G Knepley 32697da65231SMatthew G Knepley #undef __FUNCT__ 32707da65231SMatthew G Knepley #define __FUNCT__ "DMPrintCellMatrix" 3271a6dfd86eSKarl Rupp PetscErrorCode DMPrintCellMatrix(PetscInt c, const char name[], PetscInt rows, PetscInt cols, const PetscScalar A[]) 3272a6dfd86eSKarl Rupp { 32731b30c384SMatthew G Knepley PetscInt f, g; 32747da65231SMatthew G Knepley PetscErrorCode ierr; 32757da65231SMatthew G Knepley 32767da65231SMatthew G Knepley PetscFunctionBegin; 327774778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, "Cell %D Element %s\n", c, name);CHKERRQ(ierr); 32781d47ebbbSSatish Balay for (f = 0; f < rows; ++f) { 327974778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " |");CHKERRQ(ierr); 32801d47ebbbSSatish Balay for (g = 0; g < cols; ++g) { 3281e3556bceSMatthew G. Knepley ierr = PetscPrintf(PETSC_COMM_SELF, " % 9.5g", PetscRealPart(A[f*cols+g]));CHKERRQ(ierr); 32827da65231SMatthew G Knepley } 328374778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " |\n");CHKERRQ(ierr); 32847da65231SMatthew G Knepley } 32857da65231SMatthew G Knepley PetscFunctionReturn(0); 32867da65231SMatthew G Knepley } 3287e7c4fc90SDmitry Karpeev 3288970e74d5SMatthew G Knepley #undef __FUNCT__ 3289e759306cSMatthew G. Knepley #define __FUNCT__ "DMPrintLocalVec" 32906113b454SMatthew G. Knepley PetscErrorCode DMPrintLocalVec(DM dm, const char name[], PetscReal tol, Vec X) 3291e759306cSMatthew G. Knepley { 3292e759306cSMatthew G. Knepley PetscMPIInt rank, numProcs; 3293e759306cSMatthew G. Knepley PetscInt p; 3294e759306cSMatthew G. Knepley PetscErrorCode ierr; 3295e759306cSMatthew G. Knepley 3296e759306cSMatthew G. Knepley PetscFunctionBegin; 3297e759306cSMatthew G. Knepley ierr = MPI_Comm_rank(PetscObjectComm((PetscObject) dm), &rank);CHKERRQ(ierr); 3298e759306cSMatthew G. Knepley ierr = MPI_Comm_size(PetscObjectComm((PetscObject) dm), &numProcs);CHKERRQ(ierr); 3299e759306cSMatthew G. Knepley ierr = PetscPrintf(PetscObjectComm((PetscObject) dm), "%s:\n", name);CHKERRQ(ierr); 3300e759306cSMatthew G. Knepley for (p = 0; p < numProcs; ++p) { 3301e759306cSMatthew G. Knepley if (p == rank) { 3302e759306cSMatthew G. Knepley Vec x; 3303e759306cSMatthew G. Knepley 3304e759306cSMatthew G. Knepley ierr = VecDuplicate(X, &x);CHKERRQ(ierr); 3305e759306cSMatthew G. Knepley ierr = VecCopy(X, x);CHKERRQ(ierr); 33066113b454SMatthew G. Knepley ierr = VecChop(x, tol);CHKERRQ(ierr); 3307e759306cSMatthew G. Knepley ierr = VecView(x, PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); 3308e759306cSMatthew G. Knepley ierr = VecDestroy(&x);CHKERRQ(ierr); 3309e759306cSMatthew G. Knepley ierr = PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); 3310e759306cSMatthew G. Knepley } 3311e759306cSMatthew G. Knepley ierr = PetscBarrier((PetscObject) dm);CHKERRQ(ierr); 3312e759306cSMatthew G. Knepley } 3313e759306cSMatthew G. Knepley PetscFunctionReturn(0); 3314e759306cSMatthew G. Knepley } 3315e759306cSMatthew G. Knepley 3316e759306cSMatthew G. Knepley #undef __FUNCT__ 331788ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultSection" 331888ed4aceSMatthew G Knepley /*@ 331988ed4aceSMatthew G Knepley DMGetDefaultSection - Get the PetscSection encoding the local data layout for the DM. 332088ed4aceSMatthew G Knepley 332188ed4aceSMatthew G Knepley Input Parameter: 332288ed4aceSMatthew G Knepley . dm - The DM 332388ed4aceSMatthew G Knepley 332488ed4aceSMatthew G Knepley Output Parameter: 332588ed4aceSMatthew G Knepley . section - The PetscSection 332688ed4aceSMatthew G Knepley 332788ed4aceSMatthew G Knepley Level: intermediate 332888ed4aceSMatthew G Knepley 332988ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSection. 333088ed4aceSMatthew G Knepley 333188ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultGlobalSection() 333288ed4aceSMatthew G Knepley @*/ 33330adebc6cSBarry Smith PetscErrorCode DMGetDefaultSection(DM dm, PetscSection *section) 33340adebc6cSBarry Smith { 3335fd59a867SMatthew G. Knepley PetscErrorCode ierr; 3336fd59a867SMatthew G. Knepley 333788ed4aceSMatthew G Knepley PetscFunctionBegin; 333888ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 333988ed4aceSMatthew G Knepley PetscValidPointer(section, 2); 33402f0f8703SMatthew G. Knepley if (!dm->defaultSection && dm->ops->createdefaultsection) { 33412f0f8703SMatthew G. Knepley ierr = (*dm->ops->createdefaultsection)(dm);CHKERRQ(ierr); 3342ae71db08SMatthew G. Knepley if (dm->defaultSection) {ierr = PetscObjectViewFromOptions((PetscObject) dm->defaultSection, NULL, "-dm_petscsection_view");CHKERRQ(ierr);} 33432f0f8703SMatthew G. Knepley } 334488ed4aceSMatthew G Knepley *section = dm->defaultSection; 334588ed4aceSMatthew G Knepley PetscFunctionReturn(0); 334688ed4aceSMatthew G Knepley } 334788ed4aceSMatthew G Knepley 334888ed4aceSMatthew G Knepley #undef __FUNCT__ 334988ed4aceSMatthew G Knepley #define __FUNCT__ "DMSetDefaultSection" 335088ed4aceSMatthew G Knepley /*@ 335188ed4aceSMatthew G Knepley DMSetDefaultSection - Set the PetscSection encoding the local data layout for the DM. 335288ed4aceSMatthew G Knepley 335388ed4aceSMatthew G Knepley Input Parameters: 335488ed4aceSMatthew G Knepley + dm - The DM 335588ed4aceSMatthew G Knepley - section - The PetscSection 335688ed4aceSMatthew G Knepley 335788ed4aceSMatthew G Knepley Level: intermediate 335888ed4aceSMatthew G Knepley 335988ed4aceSMatthew G Knepley Note: Any existing Section will be destroyed 336088ed4aceSMatthew G Knepley 336188ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultGlobalSection() 336288ed4aceSMatthew G Knepley @*/ 33630adebc6cSBarry Smith PetscErrorCode DMSetDefaultSection(DM dm, PetscSection section) 33640adebc6cSBarry Smith { 3365c473ab19SMatthew G. Knepley PetscInt numFields = 0; 3366af122d2aSMatthew G Knepley PetscInt f; 336788ed4aceSMatthew G Knepley PetscErrorCode ierr; 336888ed4aceSMatthew G Knepley 336988ed4aceSMatthew G Knepley PetscFunctionBegin; 337088ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3371c473ab19SMatthew G. Knepley if (section) { 33721d799100SJed Brown PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 33731d799100SJed Brown ierr = PetscObjectReference((PetscObject)section);CHKERRQ(ierr); 3374c473ab19SMatthew G. Knepley } 337588ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&dm->defaultSection);CHKERRQ(ierr); 337688ed4aceSMatthew G Knepley dm->defaultSection = section; 3377c473ab19SMatthew G. Knepley if (section) {ierr = PetscSectionGetNumFields(dm->defaultSection, &numFields);CHKERRQ(ierr);} 3378af122d2aSMatthew G Knepley if (numFields) { 3379af122d2aSMatthew G Knepley ierr = DMSetNumFields(dm, numFields);CHKERRQ(ierr); 3380af122d2aSMatthew G Knepley for (f = 0; f < numFields; ++f) { 33810f21e855SMatthew G. Knepley PetscObject disc; 3382af122d2aSMatthew G Knepley const char *name; 3383af122d2aSMatthew G Knepley 3384af122d2aSMatthew G Knepley ierr = PetscSectionGetFieldName(dm->defaultSection, f, &name);CHKERRQ(ierr); 33850f21e855SMatthew G. Knepley ierr = DMGetField(dm, f, &disc);CHKERRQ(ierr); 33860f21e855SMatthew G. Knepley ierr = PetscObjectSetName(disc, name);CHKERRQ(ierr); 3387af122d2aSMatthew G Knepley } 3388af122d2aSMatthew G Knepley } 33891d799100SJed Brown /* The global section will be rebuilt in the next call to DMGetDefaultGlobalSection(). */ 33901d799100SJed Brown ierr = PetscSectionDestroy(&dm->defaultGlobalSection);CHKERRQ(ierr); 339188ed4aceSMatthew G Knepley PetscFunctionReturn(0); 339288ed4aceSMatthew G Knepley } 339388ed4aceSMatthew G Knepley 339488ed4aceSMatthew G Knepley #undef __FUNCT__ 33959435951eSToby Isaac #define __FUNCT__ "DMGetDefaultConstraints" 33969435951eSToby Isaac /*@ 33979435951eSToby Isaac DMGetDefaultConstraints - Get the PetscSection and Mat the specify the local constraint interpolation. See DMSetDefaultConstraints() for a description of the purpose of constraint interpolation. 33989435951eSToby Isaac 3399e228b242SToby Isaac not collective 3400e228b242SToby Isaac 34019435951eSToby Isaac Input Parameter: 34029435951eSToby Isaac . dm - The DM 34039435951eSToby Isaac 34049435951eSToby Isaac Output Parameter: 34059435951eSToby Isaac + section - The PetscSection describing the range of the constraint matrix: relates rows of the constraint matrix to dofs of the default section. Returns NULL if there are no local constraints. 34069435951eSToby Isaac - mat - The Mat that interpolates local constraints: its width should be the layout size of the default section. Returns NULL if there are no local constraints. 34079435951eSToby Isaac 34089435951eSToby Isaac Level: advanced 34099435951eSToby Isaac 34109435951eSToby Isaac Note: This gets borrowed references, so the user should not destroy the PetscSection or the Mat. 34119435951eSToby Isaac 34129435951eSToby Isaac .seealso: DMSetDefaultConstraints() 34139435951eSToby Isaac @*/ 34149435951eSToby Isaac PetscErrorCode DMGetDefaultConstraints(DM dm, PetscSection *section, Mat *mat) 34159435951eSToby Isaac { 34169435951eSToby Isaac PetscErrorCode ierr; 34179435951eSToby Isaac 34189435951eSToby Isaac PetscFunctionBegin; 34199435951eSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 34209435951eSToby Isaac if (!dm->defaultConstraintSection && !dm->defaultConstraintMat && dm->ops->createdefaultconstraints) {ierr = (*dm->ops->createdefaultconstraints)(dm);CHKERRQ(ierr);} 342145a75d81SToby Isaac if (section) {*section = dm->defaultConstraintSection;} 342245a75d81SToby Isaac if (mat) {*mat = dm->defaultConstraintMat;} 34239435951eSToby Isaac PetscFunctionReturn(0); 34249435951eSToby Isaac } 34259435951eSToby Isaac 34269435951eSToby Isaac #undef __FUNCT__ 34279435951eSToby Isaac #define __FUNCT__ "DMSetDefaultConstraints" 34289435951eSToby Isaac /*@ 34299435951eSToby Isaac DMSetDefaultConstraints - Set the PetscSection and Mat the specify the local constraint interpolation. 34309435951eSToby Isaac 34319435951eSToby Isaac If a constraint matrix is specified, then it is applied during DMGlobalToLocalEnd() when mode is INSERT_VALUES, INSERT_BC_VALUES, or INSERT_ALL_VALUES. Without a constraint matrix, the local vector l returned by DMGlobalToLocalEnd() contains values that have been scattered from a global vector without modification; with a constraint matrix A, l is modified by computing c = A * l, l[s[i]] = c[i], where the scatter s is defined by the PetscSection returned by DMGetDefaultConstraintMatrix(). 34329435951eSToby Isaac 34339435951eSToby Isaac If a constraint matrix is specified, then its adjoint is applied during DMLocalToGlobalBegin() when mode is ADD_VALUES, ADD_BC_VALUES, or ADD_ALL_VALUES. Without a constraint matrix, the local vector l is accumulated into a global vector without modification; with a constraint matrix A, l is first modified by computing c[i] = l[s[i]], l[s[i]] = 0, l = l + A'*c, which is the adjoint of the operation described above. 34349435951eSToby Isaac 3435e228b242SToby Isaac collective on dm 3436e228b242SToby Isaac 34379435951eSToby Isaac Input Parameters: 34389435951eSToby Isaac + dm - The DM 3439e228b242SToby Isaac + section - The PetscSection describing the range of the constraint matrix: relates rows of the constraint matrix to dofs of the default section. Must have a local communicator (PETSC_COMM_SELF or derivative). 3440e228b242SToby Isaac - mat - The Mat that interpolates local constraints: its width should be the layout size of the default section: NULL indicates no constraints. Must have a local communicator (PETSC_COMM_SELF or derivative). 34419435951eSToby Isaac 34429435951eSToby Isaac Level: advanced 34439435951eSToby Isaac 34449435951eSToby Isaac Note: This increments the references of the PetscSection and the Mat, so they user can destroy them 34459435951eSToby Isaac 34469435951eSToby Isaac .seealso: DMGetDefaultConstraints() 34479435951eSToby Isaac @*/ 34489435951eSToby Isaac PetscErrorCode DMSetDefaultConstraints(DM dm, PetscSection section, Mat mat) 34499435951eSToby Isaac { 3450e228b242SToby Isaac PetscMPIInt result; 34519435951eSToby Isaac PetscErrorCode ierr; 34529435951eSToby Isaac 34539435951eSToby Isaac PetscFunctionBegin; 34549435951eSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3455e228b242SToby Isaac if (section) { 3456e228b242SToby Isaac PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 3457e228b242SToby Isaac ierr = MPI_Comm_compare(PETSC_COMM_SELF,PetscObjectComm((PetscObject)section),&result);CHKERRQ(ierr); 3458f60917d2SBarry Smith if (result != MPI_CONGRUENT && result != MPI_IDENT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NOTSAMECOMM,"constraint section must have local communicator"); 3459e228b242SToby Isaac } 3460e228b242SToby Isaac if (mat) { 3461e228b242SToby Isaac PetscValidHeaderSpecific(mat,MAT_CLASSID,3); 3462e228b242SToby Isaac ierr = MPI_Comm_compare(PETSC_COMM_SELF,PetscObjectComm((PetscObject)mat),&result);CHKERRQ(ierr); 3463f60917d2SBarry Smith if (result != MPI_CONGRUENT && result != MPI_IDENT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NOTSAMECOMM,"constraint matrix must have local communicator"); 3464e228b242SToby Isaac } 34659435951eSToby Isaac ierr = PetscObjectReference((PetscObject)section);CHKERRQ(ierr); 34669435951eSToby Isaac ierr = PetscSectionDestroy(&dm->defaultConstraintSection);CHKERRQ(ierr); 34679435951eSToby Isaac dm->defaultConstraintSection = section; 34689435951eSToby Isaac ierr = PetscObjectReference((PetscObject)mat);CHKERRQ(ierr); 34699435951eSToby Isaac ierr = MatDestroy(&dm->defaultConstraintMat);CHKERRQ(ierr); 34709435951eSToby Isaac dm->defaultConstraintMat = mat; 34719435951eSToby Isaac PetscFunctionReturn(0); 34729435951eSToby Isaac } 34739435951eSToby Isaac 3474f741bcd2SMatthew G. Knepley #ifdef PETSC_USE_DEBUG 34759435951eSToby Isaac #undef __FUNCT__ 3476284f5c8fSMatthew G. Knepley #define __FUNCT__ "DMDefaultSectionCheckConsistency_Internal" 3477507e4973SMatthew G. Knepley /* 3478507e4973SMatthew G. Knepley DMDefaultSectionCheckConsistency - Check the consistentcy of the global and local sections. 3479507e4973SMatthew G. Knepley 3480507e4973SMatthew G. Knepley Input Parameters: 3481507e4973SMatthew G. Knepley + dm - The DM 3482507e4973SMatthew G. Knepley . localSection - PetscSection describing the local data layout 3483507e4973SMatthew G. Knepley - globalSection - PetscSection describing the global data layout 3484507e4973SMatthew G. Knepley 3485507e4973SMatthew G. Knepley Level: intermediate 3486507e4973SMatthew G. Knepley 3487507e4973SMatthew G. Knepley .seealso: DMGetDefaultSF(), DMSetDefaultSF() 3488507e4973SMatthew G. Knepley */ 3489f741bcd2SMatthew G. Knepley static PetscErrorCode DMDefaultSectionCheckConsistency_Internal(DM dm, PetscSection localSection, PetscSection globalSection) 3490507e4973SMatthew G. Knepley { 3491507e4973SMatthew G. Knepley MPI_Comm comm; 3492507e4973SMatthew G. Knepley PetscLayout layout; 3493507e4973SMatthew G. Knepley const PetscInt *ranges; 3494507e4973SMatthew G. Knepley PetscInt pStart, pEnd, p, nroots; 3495507e4973SMatthew G. Knepley PetscMPIInt size, rank; 3496507e4973SMatthew G. Knepley PetscBool valid = PETSC_TRUE, gvalid; 3497507e4973SMatthew G. Knepley PetscErrorCode ierr; 3498507e4973SMatthew G. Knepley 3499507e4973SMatthew G. Knepley PetscFunctionBegin; 3500507e4973SMatthew G. Knepley ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 3501507e4973SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3502507e4973SMatthew G. Knepley ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); 3503507e4973SMatthew G. Knepley ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); 3504507e4973SMatthew G. Knepley ierr = PetscSectionGetChart(globalSection, &pStart, &pEnd);CHKERRQ(ierr); 3505507e4973SMatthew G. Knepley ierr = PetscSectionGetConstrainedStorageSize(globalSection, &nroots);CHKERRQ(ierr); 3506507e4973SMatthew G. Knepley ierr = PetscLayoutCreate(comm, &layout);CHKERRQ(ierr); 3507507e4973SMatthew G. Knepley ierr = PetscLayoutSetBlockSize(layout, 1);CHKERRQ(ierr); 3508507e4973SMatthew G. Knepley ierr = PetscLayoutSetLocalSize(layout, nroots);CHKERRQ(ierr); 3509507e4973SMatthew G. Knepley ierr = PetscLayoutSetUp(layout);CHKERRQ(ierr); 3510507e4973SMatthew G. Knepley ierr = PetscLayoutGetRanges(layout, &ranges);CHKERRQ(ierr); 3511507e4973SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 3512f741bcd2SMatthew G. Knepley PetscInt dof, cdof, off, gdof, gcdof, goff, gsize, d; 3513507e4973SMatthew G. Knepley 3514507e4973SMatthew G. Knepley ierr = PetscSectionGetDof(localSection, p, &dof);CHKERRQ(ierr); 3515507e4973SMatthew G. Knepley ierr = PetscSectionGetOffset(localSection, p, &off);CHKERRQ(ierr); 3516507e4973SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(localSection, p, &cdof);CHKERRQ(ierr); 3517507e4973SMatthew G. Knepley ierr = PetscSectionGetDof(globalSection, p, &gdof);CHKERRQ(ierr); 3518507e4973SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(globalSection, p, &gcdof);CHKERRQ(ierr); 3519507e4973SMatthew G. Knepley ierr = PetscSectionGetOffset(globalSection, p, &goff);CHKERRQ(ierr); 3520507e4973SMatthew G. Knepley if (!gdof) continue; /* Censored point */ 3521507e4973SMatthew G. Knepley if ((gdof < 0 ? -(gdof+1) : gdof) != dof) {ierr = PetscSynchronizedPrintf(comm, "[%d]Global dof %d for point %d not equal to local dof %d\n", rank, gdof, p, dof);CHKERRQ(ierr); valid = PETSC_FALSE;} 3522507e4973SMatthew G. Knepley if (gcdof && (gcdof != cdof)) {ierr = PetscSynchronizedPrintf(comm, "[%d]Global constraints %d for point %d not equal to local constraints %d\n", rank, gcdof, p, cdof);CHKERRQ(ierr); valid = PETSC_FALSE;} 3523507e4973SMatthew G. Knepley if (gdof < 0) { 3524507e4973SMatthew G. Knepley gsize = gdof < 0 ? -(gdof+1)-gcdof : gdof-gcdof; 3525507e4973SMatthew G. Knepley for (d = 0; d < gsize; ++d) { 3526507e4973SMatthew G. Knepley PetscInt offset = -(goff+1) + d, r; 3527507e4973SMatthew G. Knepley 3528507e4973SMatthew G. Knepley ierr = PetscFindInt(offset,size+1,ranges,&r);CHKERRQ(ierr); 3529507e4973SMatthew G. Knepley if (r < 0) r = -(r+2); 3530507e4973SMatthew G. Knepley if ((r < 0) || (r >= size)) {ierr = PetscSynchronizedPrintf(comm, "[%d]Point %d mapped to invalid process %d (%d, %d)\n", rank, p, r, gdof, goff);CHKERRQ(ierr); valid = PETSC_FALSE;break;} 3531507e4973SMatthew G. Knepley } 3532507e4973SMatthew G. Knepley } 3533507e4973SMatthew G. Knepley } 3534507e4973SMatthew G. Knepley ierr = PetscLayoutDestroy(&layout);CHKERRQ(ierr); 3535507e4973SMatthew G. Knepley ierr = PetscSynchronizedFlush(comm, NULL);CHKERRQ(ierr); 3536b2566f29SBarry Smith ierr = MPIU_Allreduce(&valid, &gvalid, 1, MPIU_BOOL, MPI_LAND, comm);CHKERRQ(ierr); 3537507e4973SMatthew G. Knepley if (!gvalid) { 3538507e4973SMatthew G. Knepley ierr = DMView(dm, NULL);CHKERRQ(ierr); 3539507e4973SMatthew G. Knepley SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Inconsistent local and global sections"); 3540507e4973SMatthew G. Knepley } 3541507e4973SMatthew G. Knepley PetscFunctionReturn(0); 3542507e4973SMatthew G. Knepley } 3543f741bcd2SMatthew G. Knepley #endif 3544507e4973SMatthew G. Knepley 3545507e4973SMatthew G. Knepley #undef __FUNCT__ 354688ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultGlobalSection" 354788ed4aceSMatthew G Knepley /*@ 354888ed4aceSMatthew G Knepley DMGetDefaultGlobalSection - Get the PetscSection encoding the global data layout for the DM. 354988ed4aceSMatthew G Knepley 35508b1ab98fSJed Brown Collective on DM 35518b1ab98fSJed Brown 355288ed4aceSMatthew G Knepley Input Parameter: 355388ed4aceSMatthew G Knepley . dm - The DM 355488ed4aceSMatthew G Knepley 355588ed4aceSMatthew G Knepley Output Parameter: 355688ed4aceSMatthew G Knepley . section - The PetscSection 355788ed4aceSMatthew G Knepley 355888ed4aceSMatthew G Knepley Level: intermediate 355988ed4aceSMatthew G Knepley 356088ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSection. 356188ed4aceSMatthew G Knepley 356288ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultSection() 356388ed4aceSMatthew G Knepley @*/ 35640adebc6cSBarry Smith PetscErrorCode DMGetDefaultGlobalSection(DM dm, PetscSection *section) 35650adebc6cSBarry Smith { 356688ed4aceSMatthew G Knepley PetscErrorCode ierr; 356788ed4aceSMatthew G Knepley 356888ed4aceSMatthew G Knepley PetscFunctionBegin; 356988ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 357088ed4aceSMatthew G Knepley PetscValidPointer(section, 2); 357188ed4aceSMatthew G Knepley if (!dm->defaultGlobalSection) { 3572fd59a867SMatthew G. Knepley PetscSection s; 3573fd59a867SMatthew G. Knepley 3574fd59a867SMatthew G. Knepley ierr = DMGetDefaultSection(dm, &s);CHKERRQ(ierr); 3575fd59a867SMatthew G. Knepley if (!s) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONGSTATE, "DM must have a default PetscSection in order to create a global PetscSection"); 3576fd59a867SMatthew G. Knepley if (!dm->sf) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONGSTATE, "DM must have a default PetscSF in order to create a global PetscSection"); 357715b58121SMatthew G. Knepley ierr = PetscSectionCreateGlobalSection(s, dm->sf, PETSC_FALSE, PETSC_FALSE, &dm->defaultGlobalSection);CHKERRQ(ierr); 3578cf06b437SMatthew G. Knepley ierr = PetscLayoutDestroy(&dm->map);CHKERRQ(ierr); 3579ce94432eSBarry Smith ierr = PetscSectionGetValueLayout(PetscObjectComm((PetscObject)dm), dm->defaultGlobalSection, &dm->map);CHKERRQ(ierr); 3580685405a1SBarry Smith ierr = PetscSectionViewFromOptions(dm->defaultGlobalSection, NULL, "-global_section_view");CHKERRQ(ierr); 358188ed4aceSMatthew G Knepley } 358288ed4aceSMatthew G Knepley *section = dm->defaultGlobalSection; 358388ed4aceSMatthew G Knepley PetscFunctionReturn(0); 358488ed4aceSMatthew G Knepley } 358588ed4aceSMatthew G Knepley 358688ed4aceSMatthew G Knepley #undef __FUNCT__ 3587b21d0597SMatthew G Knepley #define __FUNCT__ "DMSetDefaultGlobalSection" 3588b21d0597SMatthew G Knepley /*@ 3589b21d0597SMatthew G Knepley DMSetDefaultGlobalSection - Set the PetscSection encoding the global data layout for the DM. 3590b21d0597SMatthew G Knepley 3591b21d0597SMatthew G Knepley Input Parameters: 3592b21d0597SMatthew G Knepley + dm - The DM 35935080bbdbSMatthew G Knepley - section - The PetscSection, or NULL 3594b21d0597SMatthew G Knepley 3595b21d0597SMatthew G Knepley Level: intermediate 3596b21d0597SMatthew G Knepley 3597b21d0597SMatthew G Knepley Note: Any existing Section will be destroyed 3598b21d0597SMatthew G Knepley 3599b21d0597SMatthew G Knepley .seealso: DMGetDefaultGlobalSection(), DMSetDefaultSection() 3600b21d0597SMatthew G Knepley @*/ 36010adebc6cSBarry Smith PetscErrorCode DMSetDefaultGlobalSection(DM dm, PetscSection section) 36020adebc6cSBarry Smith { 3603b21d0597SMatthew G Knepley PetscErrorCode ierr; 3604b21d0597SMatthew G Knepley 3605b21d0597SMatthew G Knepley PetscFunctionBegin; 3606b21d0597SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 36075080bbdbSMatthew G Knepley if (section) PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 36081d799100SJed Brown ierr = PetscObjectReference((PetscObject)section);CHKERRQ(ierr); 3609b21d0597SMatthew G Knepley ierr = PetscSectionDestroy(&dm->defaultGlobalSection);CHKERRQ(ierr); 3610b21d0597SMatthew G Knepley dm->defaultGlobalSection = section; 3611507e4973SMatthew G. Knepley #ifdef PETSC_USE_DEBUG 3612f741bcd2SMatthew G. Knepley if (section) {ierr = DMDefaultSectionCheckConsistency_Internal(dm, dm->defaultSection, section);CHKERRQ(ierr);} 3613507e4973SMatthew G. Knepley #endif 3614b21d0597SMatthew G Knepley PetscFunctionReturn(0); 3615b21d0597SMatthew G Knepley } 3616b21d0597SMatthew G Knepley 3617b21d0597SMatthew G Knepley #undef __FUNCT__ 361888ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultSF" 361988ed4aceSMatthew G Knepley /*@ 362088ed4aceSMatthew G Knepley DMGetDefaultSF - Get the PetscSF encoding the parallel dof overlap for the DM. If it has not been set, 362188ed4aceSMatthew G Knepley it is created from the default PetscSection layouts in the DM. 362288ed4aceSMatthew G Knepley 362388ed4aceSMatthew G Knepley Input Parameter: 362488ed4aceSMatthew G Knepley . dm - The DM 362588ed4aceSMatthew G Knepley 362688ed4aceSMatthew G Knepley Output Parameter: 362788ed4aceSMatthew G Knepley . sf - The PetscSF 362888ed4aceSMatthew G Knepley 362988ed4aceSMatthew G Knepley Level: intermediate 363088ed4aceSMatthew G Knepley 363188ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSF. 363288ed4aceSMatthew G Knepley 363388ed4aceSMatthew G Knepley .seealso: DMSetDefaultSF(), DMCreateDefaultSF() 363488ed4aceSMatthew G Knepley @*/ 36350adebc6cSBarry Smith PetscErrorCode DMGetDefaultSF(DM dm, PetscSF *sf) 36360adebc6cSBarry Smith { 363788ed4aceSMatthew G Knepley PetscInt nroots; 363888ed4aceSMatthew G Knepley PetscErrorCode ierr; 363988ed4aceSMatthew G Knepley 364088ed4aceSMatthew G Knepley PetscFunctionBegin; 364188ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 364288ed4aceSMatthew G Knepley PetscValidPointer(sf, 2); 36430298fd71SBarry Smith ierr = PetscSFGetGraph(dm->defaultSF, &nroots, NULL, NULL, NULL);CHKERRQ(ierr); 364488ed4aceSMatthew G Knepley if (nroots < 0) { 364588ed4aceSMatthew G Knepley PetscSection section, gSection; 364688ed4aceSMatthew G Knepley 364788ed4aceSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 364831ea6d37SMatthew G Knepley if (section) { 364988ed4aceSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, &gSection);CHKERRQ(ierr); 365088ed4aceSMatthew G Knepley ierr = DMCreateDefaultSF(dm, section, gSection);CHKERRQ(ierr); 365131ea6d37SMatthew G Knepley } else { 36520298fd71SBarry Smith *sf = NULL; 365331ea6d37SMatthew G Knepley PetscFunctionReturn(0); 365431ea6d37SMatthew G Knepley } 365588ed4aceSMatthew G Knepley } 365688ed4aceSMatthew G Knepley *sf = dm->defaultSF; 365788ed4aceSMatthew G Knepley PetscFunctionReturn(0); 365888ed4aceSMatthew G Knepley } 365988ed4aceSMatthew G Knepley 366088ed4aceSMatthew G Knepley #undef __FUNCT__ 366188ed4aceSMatthew G Knepley #define __FUNCT__ "DMSetDefaultSF" 366288ed4aceSMatthew G Knepley /*@ 366388ed4aceSMatthew G Knepley DMSetDefaultSF - Set the PetscSF encoding the parallel dof overlap for the DM 366488ed4aceSMatthew G Knepley 366588ed4aceSMatthew G Knepley Input Parameters: 366688ed4aceSMatthew G Knepley + dm - The DM 366788ed4aceSMatthew G Knepley - sf - The PetscSF 366888ed4aceSMatthew G Knepley 366988ed4aceSMatthew G Knepley Level: intermediate 367088ed4aceSMatthew G Knepley 367188ed4aceSMatthew G Knepley Note: Any previous SF is destroyed 367288ed4aceSMatthew G Knepley 367388ed4aceSMatthew G Knepley .seealso: DMGetDefaultSF(), DMCreateDefaultSF() 367488ed4aceSMatthew G Knepley @*/ 36750adebc6cSBarry Smith PetscErrorCode DMSetDefaultSF(DM dm, PetscSF sf) 36760adebc6cSBarry Smith { 367788ed4aceSMatthew G Knepley PetscErrorCode ierr; 367888ed4aceSMatthew G Knepley 367988ed4aceSMatthew G Knepley PetscFunctionBegin; 368088ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 368188ed4aceSMatthew G Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 368288ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&dm->defaultSF);CHKERRQ(ierr); 368388ed4aceSMatthew G Knepley dm->defaultSF = sf; 368488ed4aceSMatthew G Knepley PetscFunctionReturn(0); 368588ed4aceSMatthew G Knepley } 368688ed4aceSMatthew G Knepley 368788ed4aceSMatthew G Knepley #undef __FUNCT__ 368888ed4aceSMatthew G Knepley #define __FUNCT__ "DMCreateDefaultSF" 368988ed4aceSMatthew G Knepley /*@C 369088ed4aceSMatthew G Knepley DMCreateDefaultSF - Create the PetscSF encoding the parallel dof overlap for the DM based upon the PetscSections 369188ed4aceSMatthew G Knepley describing the data layout. 369288ed4aceSMatthew G Knepley 369388ed4aceSMatthew G Knepley Input Parameters: 369488ed4aceSMatthew G Knepley + dm - The DM 369588ed4aceSMatthew G Knepley . localSection - PetscSection describing the local data layout 369688ed4aceSMatthew G Knepley - globalSection - PetscSection describing the global data layout 369788ed4aceSMatthew G Knepley 369888ed4aceSMatthew G Knepley Level: intermediate 369988ed4aceSMatthew G Knepley 370088ed4aceSMatthew G Knepley .seealso: DMGetDefaultSF(), DMSetDefaultSF() 370188ed4aceSMatthew G Knepley @*/ 370288ed4aceSMatthew G Knepley PetscErrorCode DMCreateDefaultSF(DM dm, PetscSection localSection, PetscSection globalSection) 370388ed4aceSMatthew G Knepley { 370482f516ccSBarry Smith MPI_Comm comm; 370588ed4aceSMatthew G Knepley PetscLayout layout; 370688ed4aceSMatthew G Knepley const PetscInt *ranges; 370788ed4aceSMatthew G Knepley PetscInt *local; 370888ed4aceSMatthew G Knepley PetscSFNode *remote; 3709ecd73843SMatthew G. Knepley PetscInt pStart, pEnd, p, nroots, nleaves = 0, l; 371088ed4aceSMatthew G Knepley PetscMPIInt size, rank; 371188ed4aceSMatthew G Knepley PetscErrorCode ierr; 371288ed4aceSMatthew G Knepley 371388ed4aceSMatthew G Knepley PetscFunctionBegin; 371482f516ccSBarry Smith ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 371588ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 371688ed4aceSMatthew G Knepley ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); 371788ed4aceSMatthew G Knepley ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); 371888ed4aceSMatthew G Knepley ierr = PetscSectionGetChart(globalSection, &pStart, &pEnd);CHKERRQ(ierr); 371988ed4aceSMatthew G Knepley ierr = PetscSectionGetConstrainedStorageSize(globalSection, &nroots);CHKERRQ(ierr); 372088ed4aceSMatthew G Knepley ierr = PetscLayoutCreate(comm, &layout);CHKERRQ(ierr); 372188ed4aceSMatthew G Knepley ierr = PetscLayoutSetBlockSize(layout, 1);CHKERRQ(ierr); 372288ed4aceSMatthew G Knepley ierr = PetscLayoutSetLocalSize(layout, nroots);CHKERRQ(ierr); 372388ed4aceSMatthew G Knepley ierr = PetscLayoutSetUp(layout);CHKERRQ(ierr); 372488ed4aceSMatthew G Knepley ierr = PetscLayoutGetRanges(layout, &ranges);CHKERRQ(ierr); 3725ecd73843SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 37266636e97aSMatthew G Knepley PetscInt gdof, gcdof; 372788ed4aceSMatthew G Knepley 37286636e97aSMatthew G Knepley ierr = PetscSectionGetDof(globalSection, p, &gdof);CHKERRQ(ierr); 37296636e97aSMatthew G Knepley ierr = PetscSectionGetConstraintDof(globalSection, p, &gcdof);CHKERRQ(ierr); 3730235fbf56SMatthew G. Knepley if (gcdof > (gdof < 0 ? -(gdof+1) : gdof)) SETERRQ3(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Point %d has %d constraints > %d dof", p, gcdof, (gdof < 0 ? -(gdof+1) : gdof)); 37316636e97aSMatthew G Knepley nleaves += gdof < 0 ? -(gdof+1)-gcdof : gdof-gcdof; 373288ed4aceSMatthew G Knepley } 3733785e854fSJed Brown ierr = PetscMalloc1(nleaves, &local);CHKERRQ(ierr); 3734785e854fSJed Brown ierr = PetscMalloc1(nleaves, &remote);CHKERRQ(ierr); 373588ed4aceSMatthew G Knepley for (p = pStart, l = 0; p < pEnd; ++p) { 37361f588964SMatthew G Knepley const PetscInt *cind; 37376636e97aSMatthew G Knepley PetscInt dof, cdof, off, gdof, gcdof, goff, gsize, d, c; 373888ed4aceSMatthew G Knepley 373988ed4aceSMatthew G Knepley ierr = PetscSectionGetDof(localSection, p, &dof);CHKERRQ(ierr); 374088ed4aceSMatthew G Knepley ierr = PetscSectionGetOffset(localSection, p, &off);CHKERRQ(ierr); 374188ed4aceSMatthew G Knepley ierr = PetscSectionGetConstraintDof(localSection, p, &cdof);CHKERRQ(ierr); 374288ed4aceSMatthew G Knepley ierr = PetscSectionGetConstraintIndices(localSection, p, &cind);CHKERRQ(ierr); 374388ed4aceSMatthew G Knepley ierr = PetscSectionGetDof(globalSection, p, &gdof);CHKERRQ(ierr); 37446636e97aSMatthew G Knepley ierr = PetscSectionGetConstraintDof(globalSection, p, &gcdof);CHKERRQ(ierr); 374588ed4aceSMatthew G Knepley ierr = PetscSectionGetOffset(globalSection, p, &goff);CHKERRQ(ierr); 37466636e97aSMatthew G Knepley if (!gdof) continue; /* Censored point */ 37476636e97aSMatthew G Knepley gsize = gdof < 0 ? -(gdof+1)-gcdof : gdof-gcdof; 37486636e97aSMatthew G Knepley if (gsize != dof-cdof) { 3749057b4bcdSMatthew G Knepley if (gsize != dof) SETERRQ4(comm, PETSC_ERR_ARG_WRONG, "Global dof %d for point %d is neither the constrained size %d, nor the unconstrained %d", gsize, p, dof-cdof, dof); 37506636e97aSMatthew G Knepley cdof = 0; /* Ignore constraints */ 37516636e97aSMatthew G Knepley } 375288ed4aceSMatthew G Knepley for (d = 0, c = 0; d < dof; ++d) { 375388ed4aceSMatthew G Knepley if ((c < cdof) && (cind[c] == d)) {++c; continue;} 375488ed4aceSMatthew G Knepley local[l+d-c] = off+d; 375588ed4aceSMatthew G Knepley } 375688ed4aceSMatthew G Knepley if (gdof < 0) { 37576636e97aSMatthew G Knepley for (d = 0; d < gsize; ++d, ++l) { 375888ed4aceSMatthew G Knepley PetscInt offset = -(goff+1) + d, r; 375988ed4aceSMatthew G Knepley 376005376888SMatthew G. Knepley ierr = PetscFindInt(offset,size+1,ranges,&r);CHKERRQ(ierr); 376131d3f06eSJed Brown if (r < 0) r = -(r+2); 376205376888SMatthew G. Knepley if ((r < 0) || (r >= size)) SETERRQ4(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Point %d mapped to invalid process %d (%d, %d)", p, r, gdof, goff); 376388ed4aceSMatthew G Knepley remote[l].rank = r; 376488ed4aceSMatthew G Knepley remote[l].index = offset - ranges[r]; 376588ed4aceSMatthew G Knepley } 376688ed4aceSMatthew G Knepley } else { 37676636e97aSMatthew G Knepley for (d = 0; d < gsize; ++d, ++l) { 376888ed4aceSMatthew G Knepley remote[l].rank = rank; 376988ed4aceSMatthew G Knepley remote[l].index = goff+d - ranges[rank]; 377088ed4aceSMatthew G Knepley } 377188ed4aceSMatthew G Knepley } 377288ed4aceSMatthew G Knepley } 37736636e97aSMatthew G Knepley if (l != nleaves) SETERRQ2(comm, PETSC_ERR_PLIB, "Iteration error, l %d != nleaves %d", l, nleaves); 377488ed4aceSMatthew G Knepley ierr = PetscLayoutDestroy(&layout);CHKERRQ(ierr); 377588ed4aceSMatthew G Knepley ierr = PetscSFSetGraph(dm->defaultSF, nroots, nleaves, local, PETSC_OWN_POINTER, remote, PETSC_OWN_POINTER);CHKERRQ(ierr); 377688ed4aceSMatthew G Knepley PetscFunctionReturn(0); 377788ed4aceSMatthew G Knepley } 3778af122d2aSMatthew G Knepley 3779af122d2aSMatthew G Knepley #undef __FUNCT__ 3780b21d0597SMatthew G Knepley #define __FUNCT__ "DMGetPointSF" 3781b21d0597SMatthew G Knepley /*@ 3782b21d0597SMatthew G Knepley DMGetPointSF - Get the PetscSF encoding the parallel section point overlap for the DM. 3783b21d0597SMatthew G Knepley 3784b21d0597SMatthew G Knepley Input Parameter: 3785b21d0597SMatthew G Knepley . dm - The DM 3786b21d0597SMatthew G Knepley 3787b21d0597SMatthew G Knepley Output Parameter: 3788b21d0597SMatthew G Knepley . sf - The PetscSF 3789b21d0597SMatthew G Knepley 3790b21d0597SMatthew G Knepley Level: intermediate 3791b21d0597SMatthew G Knepley 3792b21d0597SMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSF. 3793b21d0597SMatthew G Knepley 3794057b4bcdSMatthew G Knepley .seealso: DMSetPointSF(), DMGetDefaultSF(), DMSetDefaultSF(), DMCreateDefaultSF() 3795b21d0597SMatthew G Knepley @*/ 37960adebc6cSBarry Smith PetscErrorCode DMGetPointSF(DM dm, PetscSF *sf) 37970adebc6cSBarry Smith { 3798b21d0597SMatthew G Knepley PetscFunctionBegin; 3799b21d0597SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3800b21d0597SMatthew G Knepley PetscValidPointer(sf, 2); 3801b21d0597SMatthew G Knepley *sf = dm->sf; 3802b21d0597SMatthew G Knepley PetscFunctionReturn(0); 3803b21d0597SMatthew G Knepley } 3804b21d0597SMatthew G Knepley 3805b21d0597SMatthew G Knepley #undef __FUNCT__ 3806057b4bcdSMatthew G Knepley #define __FUNCT__ "DMSetPointSF" 3807057b4bcdSMatthew G Knepley /*@ 3808057b4bcdSMatthew G Knepley DMSetPointSF - Set the PetscSF encoding the parallel section point overlap for the DM. 3809057b4bcdSMatthew G Knepley 3810057b4bcdSMatthew G Knepley Input Parameters: 3811057b4bcdSMatthew G Knepley + dm - The DM 3812057b4bcdSMatthew G Knepley - sf - The PetscSF 3813057b4bcdSMatthew G Knepley 3814057b4bcdSMatthew G Knepley Level: intermediate 3815057b4bcdSMatthew G Knepley 3816057b4bcdSMatthew G Knepley .seealso: DMGetPointSF(), DMGetDefaultSF(), DMSetDefaultSF(), DMCreateDefaultSF() 3817057b4bcdSMatthew G Knepley @*/ 38180adebc6cSBarry Smith PetscErrorCode DMSetPointSF(DM dm, PetscSF sf) 38190adebc6cSBarry Smith { 3820057b4bcdSMatthew G Knepley PetscErrorCode ierr; 3821057b4bcdSMatthew G Knepley 3822057b4bcdSMatthew G Knepley PetscFunctionBegin; 3823057b4bcdSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3824057b4bcdSMatthew G Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 1); 3825057b4bcdSMatthew G Knepley ierr = PetscSFDestroy(&dm->sf);CHKERRQ(ierr); 3826057b4bcdSMatthew G Knepley ierr = PetscObjectReference((PetscObject) sf);CHKERRQ(ierr); 3827057b4bcdSMatthew G Knepley dm->sf = sf; 3828057b4bcdSMatthew G Knepley PetscFunctionReturn(0); 3829057b4bcdSMatthew G Knepley } 3830057b4bcdSMatthew G Knepley 3831057b4bcdSMatthew G Knepley #undef __FUNCT__ 38322764a2aaSMatthew G. Knepley #define __FUNCT__ "DMGetDS" 38332764a2aaSMatthew G. Knepley /*@ 38342764a2aaSMatthew G. Knepley DMGetDS - Get the PetscDS 38352764a2aaSMatthew G. Knepley 38362764a2aaSMatthew G. Knepley Input Parameter: 38372764a2aaSMatthew G. Knepley . dm - The DM 38382764a2aaSMatthew G. Knepley 38392764a2aaSMatthew G. Knepley Output Parameter: 38402764a2aaSMatthew G. Knepley . prob - The PetscDS 38412764a2aaSMatthew G. Knepley 38422764a2aaSMatthew G. Knepley Level: developer 38432764a2aaSMatthew G. Knepley 38442764a2aaSMatthew G. Knepley .seealso: DMSetDS() 38452764a2aaSMatthew G. Knepley @*/ 38462764a2aaSMatthew G. Knepley PetscErrorCode DMGetDS(DM dm, PetscDS *prob) 3847af122d2aSMatthew G Knepley { 3848af122d2aSMatthew G Knepley PetscFunctionBegin; 3849af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 38500f21e855SMatthew G. Knepley PetscValidPointer(prob, 2); 38510f21e855SMatthew G. Knepley *prob = dm->prob; 38520f21e855SMatthew G. Knepley PetscFunctionReturn(0); 38530f21e855SMatthew G. Knepley } 38540f21e855SMatthew G. Knepley 38550f21e855SMatthew G. Knepley #undef __FUNCT__ 38562764a2aaSMatthew G. Knepley #define __FUNCT__ "DMSetDS" 38572764a2aaSMatthew G. Knepley /*@ 38582764a2aaSMatthew G. Knepley DMSetDS - Set the PetscDS 38592764a2aaSMatthew G. Knepley 38602764a2aaSMatthew G. Knepley Input Parameters: 38612764a2aaSMatthew G. Knepley + dm - The DM 38622764a2aaSMatthew G. Knepley - prob - The PetscDS 38632764a2aaSMatthew G. Knepley 38642764a2aaSMatthew G. Knepley Level: developer 38652764a2aaSMatthew G. Knepley 38662764a2aaSMatthew G. Knepley .seealso: DMGetDS() 38672764a2aaSMatthew G. Knepley @*/ 38682764a2aaSMatthew G. Knepley PetscErrorCode DMSetDS(DM dm, PetscDS prob) 38690f21e855SMatthew G. Knepley { 38700f21e855SMatthew G. Knepley PetscErrorCode ierr; 38710f21e855SMatthew G. Knepley 38720f21e855SMatthew G. Knepley PetscFunctionBegin; 38730f21e855SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 38742764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 2); 38752764a2aaSMatthew G. Knepley ierr = PetscDSDestroy(&dm->prob);CHKERRQ(ierr); 38760f21e855SMatthew G. Knepley dm->prob = prob; 38770f21e855SMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm->prob);CHKERRQ(ierr); 38780f21e855SMatthew G. Knepley PetscFunctionReturn(0); 38790f21e855SMatthew G. Knepley } 38800f21e855SMatthew G. Knepley 38810f21e855SMatthew G. Knepley #undef __FUNCT__ 38820f21e855SMatthew G. Knepley #define __FUNCT__ "DMGetNumFields" 38830f21e855SMatthew G. Knepley PetscErrorCode DMGetNumFields(DM dm, PetscInt *numFields) 38840f21e855SMatthew G. Knepley { 38850f21e855SMatthew G. Knepley PetscErrorCode ierr; 38860f21e855SMatthew G. Knepley 38870f21e855SMatthew G. Knepley PetscFunctionBegin; 38880f21e855SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 38892764a2aaSMatthew G. Knepley ierr = PetscDSGetNumFields(dm->prob, numFields);CHKERRQ(ierr); 3890af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3891af122d2aSMatthew G Knepley } 3892af122d2aSMatthew G Knepley 3893af122d2aSMatthew G Knepley #undef __FUNCT__ 3894af122d2aSMatthew G Knepley #define __FUNCT__ "DMSetNumFields" 3895af122d2aSMatthew G Knepley PetscErrorCode DMSetNumFields(DM dm, PetscInt numFields) 3896af122d2aSMatthew G Knepley { 38970f21e855SMatthew G. Knepley PetscInt Nf, f; 3898af122d2aSMatthew G Knepley PetscErrorCode ierr; 3899af122d2aSMatthew G Knepley 3900af122d2aSMatthew G Knepley PetscFunctionBegin; 3901af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 39022764a2aaSMatthew G. Knepley ierr = PetscDSGetNumFields(dm->prob, &Nf);CHKERRQ(ierr); 39030f21e855SMatthew G. Knepley for (f = Nf; f < numFields; ++f) { 39040f21e855SMatthew G. Knepley PetscContainer obj; 39050f21e855SMatthew G. Knepley 39060f21e855SMatthew G. Knepley ierr = PetscContainerCreate(PetscObjectComm((PetscObject) dm), &obj);CHKERRQ(ierr); 39072764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(dm->prob, f, (PetscObject) obj);CHKERRQ(ierr); 39080f21e855SMatthew G. Knepley ierr = PetscContainerDestroy(&obj);CHKERRQ(ierr); 3909af122d2aSMatthew G Knepley } 3910af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3911af122d2aSMatthew G Knepley } 3912af122d2aSMatthew G Knepley 3913af122d2aSMatthew G Knepley #undef __FUNCT__ 3914af122d2aSMatthew G Knepley #define __FUNCT__ "DMGetField" 3915c1929be8SMatthew G. Knepley /*@ 3916c1929be8SMatthew G. Knepley DMGetField - Return the discretization object for a given DM field 3917c1929be8SMatthew G. Knepley 3918c1929be8SMatthew G. Knepley Not collective 3919c1929be8SMatthew G. Knepley 3920c1929be8SMatthew G. Knepley Input Parameters: 3921c1929be8SMatthew G. Knepley + dm - The DM 3922c1929be8SMatthew G. Knepley - f - The field number 3923c1929be8SMatthew G. Knepley 3924c1929be8SMatthew G. Knepley Output Parameter: 3925c1929be8SMatthew G. Knepley . field - The discretization object 3926c1929be8SMatthew G. Knepley 3927c1929be8SMatthew G. Knepley Level: developer 3928c1929be8SMatthew G. Knepley 3929c1929be8SMatthew G. Knepley .seealso: DMSetField() 3930c1929be8SMatthew G. Knepley @*/ 3931af122d2aSMatthew G Knepley PetscErrorCode DMGetField(DM dm, PetscInt f, PetscObject *field) 3932af122d2aSMatthew G Knepley { 39330f21e855SMatthew G. Knepley PetscErrorCode ierr; 39340f21e855SMatthew G. Knepley 3935af122d2aSMatthew G Knepley PetscFunctionBegin; 3936af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 39372764a2aaSMatthew G. Knepley ierr = PetscDSGetDiscretization(dm->prob, f, field);CHKERRQ(ierr); 3938decb47aaSMatthew G. Knepley PetscFunctionReturn(0); 3939decb47aaSMatthew G. Knepley } 3940decb47aaSMatthew G. Knepley 3941decb47aaSMatthew G. Knepley #undef __FUNCT__ 3942decb47aaSMatthew G. Knepley #define __FUNCT__ "DMSetField" 3943c1929be8SMatthew G. Knepley /*@ 3944c1929be8SMatthew G. Knepley DMSetField - Set the discretization object for a given DM field 3945c1929be8SMatthew G. Knepley 3946c1929be8SMatthew G. Knepley Logically collective on DM 3947c1929be8SMatthew G. Knepley 3948c1929be8SMatthew G. Knepley Input Parameters: 3949c1929be8SMatthew G. Knepley + dm - The DM 3950c1929be8SMatthew G. Knepley . f - The field number 3951c1929be8SMatthew G. Knepley - field - The discretization object 3952c1929be8SMatthew G. Knepley 3953c1929be8SMatthew G. Knepley Level: developer 3954c1929be8SMatthew G. Knepley 3955c1929be8SMatthew G. Knepley .seealso: DMGetField() 3956c1929be8SMatthew G. Knepley @*/ 3957decb47aaSMatthew G. Knepley PetscErrorCode DMSetField(DM dm, PetscInt f, PetscObject field) 3958decb47aaSMatthew G. Knepley { 3959decb47aaSMatthew G. Knepley PetscErrorCode ierr; 3960decb47aaSMatthew G. Knepley 3961decb47aaSMatthew G. Knepley PetscFunctionBegin; 3962decb47aaSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 39632764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(dm->prob, f, field);CHKERRQ(ierr); 3964af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3965af122d2aSMatthew G Knepley } 39666636e97aSMatthew G Knepley 39676636e97aSMatthew G Knepley #undef __FUNCT__ 3968b64e0483SPeter Brune #define __FUNCT__ "DMRestrictHook_Coordinates" 3969b64e0483SPeter Brune PetscErrorCode DMRestrictHook_Coordinates(DM dm,DM dmc,void *ctx) 3970b64e0483SPeter Brune { 3971b64e0483SPeter Brune DM dm_coord,dmc_coord; 3972b64e0483SPeter Brune PetscErrorCode ierr; 3973b64e0483SPeter Brune Vec coords,ccoords; 39746dbf9973SLawrence Mitchell Mat inject; 3975b64e0483SPeter Brune PetscFunctionBegin; 3976b64e0483SPeter Brune ierr = DMGetCoordinateDM(dm,&dm_coord);CHKERRQ(ierr); 3977b64e0483SPeter Brune ierr = DMGetCoordinateDM(dmc,&dmc_coord);CHKERRQ(ierr); 3978b64e0483SPeter Brune ierr = DMGetCoordinates(dm,&coords);CHKERRQ(ierr); 3979b64e0483SPeter Brune ierr = DMGetCoordinates(dmc,&ccoords);CHKERRQ(ierr); 3980b64e0483SPeter Brune if (coords && !ccoords) { 3981b64e0483SPeter Brune ierr = DMCreateGlobalVector(dmc_coord,&ccoords);CHKERRQ(ierr); 39826dbf9973SLawrence Mitchell ierr = DMCreateInjection(dmc_coord,dm_coord,&inject);CHKERRQ(ierr); 39832adcf181SLawrence Mitchell ierr = MatRestrict(inject,coords,ccoords);CHKERRQ(ierr); 39846dbf9973SLawrence Mitchell ierr = MatDestroy(&inject);CHKERRQ(ierr); 3985b64e0483SPeter Brune ierr = DMSetCoordinates(dmc,ccoords);CHKERRQ(ierr); 3986b64e0483SPeter Brune ierr = VecDestroy(&ccoords);CHKERRQ(ierr); 3987b64e0483SPeter Brune } 3988b64e0483SPeter Brune PetscFunctionReturn(0); 3989b64e0483SPeter Brune } 3990b64e0483SPeter Brune 3991b64e0483SPeter Brune #undef __FUNCT__ 399203dadc2fSPeter Brune #define __FUNCT__ "DMSubDomainHook_Coordinates" 399303dadc2fSPeter Brune static PetscErrorCode DMSubDomainHook_Coordinates(DM dm,DM subdm,void *ctx) 399403dadc2fSPeter Brune { 399503dadc2fSPeter Brune DM dm_coord,subdm_coord; 399603dadc2fSPeter Brune PetscErrorCode ierr; 399703dadc2fSPeter Brune Vec coords,ccoords,clcoords; 399803dadc2fSPeter Brune VecScatter *scat_i,*scat_g; 399903dadc2fSPeter Brune PetscFunctionBegin; 400003dadc2fSPeter Brune ierr = DMGetCoordinateDM(dm,&dm_coord);CHKERRQ(ierr); 400103dadc2fSPeter Brune ierr = DMGetCoordinateDM(subdm,&subdm_coord);CHKERRQ(ierr); 400203dadc2fSPeter Brune ierr = DMGetCoordinates(dm,&coords);CHKERRQ(ierr); 400303dadc2fSPeter Brune ierr = DMGetCoordinates(subdm,&ccoords);CHKERRQ(ierr); 400403dadc2fSPeter Brune if (coords && !ccoords) { 400503dadc2fSPeter Brune ierr = DMCreateGlobalVector(subdm_coord,&ccoords);CHKERRQ(ierr); 400603dadc2fSPeter Brune ierr = DMCreateLocalVector(subdm_coord,&clcoords);CHKERRQ(ierr); 400724640c55SToby Isaac ierr = PetscObjectSetName((PetscObject)clcoords,"coordinates");CHKERRQ(ierr); 400803dadc2fSPeter Brune ierr = DMCreateDomainDecompositionScatters(dm_coord,1,&subdm_coord,NULL,&scat_i,&scat_g);CHKERRQ(ierr); 400903dadc2fSPeter Brune ierr = VecScatterBegin(scat_i[0],coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 401003dadc2fSPeter Brune ierr = VecScatterBegin(scat_g[0],coords,clcoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 401103dadc2fSPeter Brune ierr = VecScatterEnd(scat_i[0],coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 401203dadc2fSPeter Brune ierr = VecScatterEnd(scat_g[0],coords,clcoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 401303dadc2fSPeter Brune ierr = DMSetCoordinates(subdm,ccoords);CHKERRQ(ierr); 401403dadc2fSPeter Brune ierr = DMSetCoordinatesLocal(subdm,clcoords);CHKERRQ(ierr); 401503dadc2fSPeter Brune ierr = VecScatterDestroy(&scat_i[0]);CHKERRQ(ierr); 401603dadc2fSPeter Brune ierr = VecScatterDestroy(&scat_g[0]);CHKERRQ(ierr); 401703dadc2fSPeter Brune ierr = VecDestroy(&ccoords);CHKERRQ(ierr); 401803dadc2fSPeter Brune ierr = VecDestroy(&clcoords);CHKERRQ(ierr); 401903dadc2fSPeter Brune ierr = PetscFree(scat_i);CHKERRQ(ierr); 402003dadc2fSPeter Brune ierr = PetscFree(scat_g);CHKERRQ(ierr); 402103dadc2fSPeter Brune } 402203dadc2fSPeter Brune PetscFunctionReturn(0); 402303dadc2fSPeter Brune } 402403dadc2fSPeter Brune 402503dadc2fSPeter Brune #undef __FUNCT__ 4026c73cfb54SMatthew G. Knepley #define __FUNCT__ "DMGetDimension" 4027c73cfb54SMatthew G. Knepley /*@ 4028c73cfb54SMatthew G. Knepley DMGetDimension - Return the topological dimension of the DM 4029c73cfb54SMatthew G. Knepley 4030c73cfb54SMatthew G. Knepley Not collective 4031c73cfb54SMatthew G. Knepley 4032c73cfb54SMatthew G. Knepley Input Parameter: 4033c73cfb54SMatthew G. Knepley . dm - The DM 4034c73cfb54SMatthew G. Knepley 4035c73cfb54SMatthew G. Knepley Output Parameter: 4036c73cfb54SMatthew G. Knepley . dim - The topological dimension 4037c73cfb54SMatthew G. Knepley 4038c73cfb54SMatthew G. Knepley Level: beginner 4039c73cfb54SMatthew G. Knepley 4040c73cfb54SMatthew G. Knepley .seealso: DMSetDimension(), DMCreate() 4041c73cfb54SMatthew G. Knepley @*/ 4042c73cfb54SMatthew G. Knepley PetscErrorCode DMGetDimension(DM dm, PetscInt *dim) 4043c73cfb54SMatthew G. Knepley { 4044c73cfb54SMatthew G. Knepley PetscFunctionBegin; 4045c73cfb54SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 4046c73cfb54SMatthew G. Knepley PetscValidPointer(dim, 2); 4047c73cfb54SMatthew G. Knepley *dim = dm->dim; 4048c73cfb54SMatthew G. Knepley PetscFunctionReturn(0); 4049c73cfb54SMatthew G. Knepley } 4050c73cfb54SMatthew G. Knepley 4051c73cfb54SMatthew G. Knepley #undef __FUNCT__ 4052c73cfb54SMatthew G. Knepley #define __FUNCT__ "DMSetDimension" 4053c73cfb54SMatthew G. Knepley /*@ 4054c73cfb54SMatthew G. Knepley DMSetDimension - Set the topological dimension of the DM 4055c73cfb54SMatthew G. Knepley 4056c73cfb54SMatthew G. Knepley Collective on dm 4057c73cfb54SMatthew G. Knepley 4058c73cfb54SMatthew G. Knepley Input Parameters: 4059c73cfb54SMatthew G. Knepley + dm - The DM 4060c73cfb54SMatthew G. Knepley - dim - The topological dimension 4061c73cfb54SMatthew G. Knepley 4062c73cfb54SMatthew G. Knepley Level: beginner 4063c73cfb54SMatthew G. Knepley 4064c73cfb54SMatthew G. Knepley .seealso: DMGetDimension(), DMCreate() 4065c73cfb54SMatthew G. Knepley @*/ 4066c73cfb54SMatthew G. Knepley PetscErrorCode DMSetDimension(DM dm, PetscInt dim) 4067c73cfb54SMatthew G. Knepley { 4068c73cfb54SMatthew G. Knepley PetscFunctionBegin; 4069c73cfb54SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 4070c73cfb54SMatthew G. Knepley PetscValidLogicalCollectiveInt(dm, dim, 2); 4071c73cfb54SMatthew G. Knepley dm->dim = dim; 4072c73cfb54SMatthew G. Knepley PetscFunctionReturn(0); 4073c73cfb54SMatthew G. Knepley } 4074c73cfb54SMatthew G. Knepley 4075793f3fe5SMatthew G. Knepley #undef __FUNCT__ 4076793f3fe5SMatthew G. Knepley #define __FUNCT__ "DMGetDimPoints" 4077793f3fe5SMatthew G. Knepley /*@ 4078793f3fe5SMatthew G. Knepley DMGetDimPoints - Get the half-open interval for all points of a given dimension 4079793f3fe5SMatthew G. Knepley 4080793f3fe5SMatthew G. Knepley Collective on DM 4081793f3fe5SMatthew G. Knepley 4082793f3fe5SMatthew G. Knepley Input Parameters: 4083793f3fe5SMatthew G. Knepley + dm - the DM 4084793f3fe5SMatthew G. Knepley - dim - the dimension 4085793f3fe5SMatthew G. Knepley 4086793f3fe5SMatthew G. Knepley Output Parameters: 4087793f3fe5SMatthew G. Knepley + pStart - The first point of the given dimension 4088793f3fe5SMatthew G. Knepley . pEnd - The first point following points of the given dimension 4089793f3fe5SMatthew G. Knepley 4090793f3fe5SMatthew G. Knepley Note: 4091793f3fe5SMatthew G. Knepley The points are vertices in the Hasse diagram encoding the topology. This is explained in 4092793f3fe5SMatthew G. Knepley http://arxiv.org/abs/0908.4427. If not points exist of this dimension in the storage scheme, 4093793f3fe5SMatthew G. Knepley then the interval is empty. 4094793f3fe5SMatthew G. Knepley 4095793f3fe5SMatthew G. Knepley Level: intermediate 4096793f3fe5SMatthew G. Knepley 4097793f3fe5SMatthew G. Knepley .keywords: point, Hasse Diagram, dimension 4098793f3fe5SMatthew G. Knepley .seealso: DMPLEX, DMPlexGetDepthStratum(), DMPlexGetHeightStratum() 4099793f3fe5SMatthew G. Knepley @*/ 4100793f3fe5SMatthew G. Knepley PetscErrorCode DMGetDimPoints(DM dm, PetscInt dim, PetscInt *pStart, PetscInt *pEnd) 4101793f3fe5SMatthew G. Knepley { 4102793f3fe5SMatthew G. Knepley PetscInt d; 4103793f3fe5SMatthew G. Knepley PetscErrorCode ierr; 4104793f3fe5SMatthew G. Knepley 4105793f3fe5SMatthew G. Knepley PetscFunctionBegin; 4106793f3fe5SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4107793f3fe5SMatthew G. Knepley ierr = DMGetDimension(dm, &d);CHKERRQ(ierr); 4108793f3fe5SMatthew G. Knepley if ((dim < 0) || (dim > d)) SETERRQ2(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid dimension %d 1", dim, d); 4109793f3fe5SMatthew G. Knepley ierr = (*dm->ops->getdimpoints)(dm, dim, pStart, pEnd);CHKERRQ(ierr); 4110793f3fe5SMatthew G. Knepley PetscFunctionReturn(0); 4111793f3fe5SMatthew G. Knepley } 4112793f3fe5SMatthew G. Knepley 4113793f3fe5SMatthew G. Knepley #undef __FUNCT__ 41146636e97aSMatthew G Knepley #define __FUNCT__ "DMSetCoordinates" 41156636e97aSMatthew G Knepley /*@ 41166636e97aSMatthew G Knepley DMSetCoordinates - Sets into the DM a global vector that holds the coordinates 41176636e97aSMatthew G Knepley 41186636e97aSMatthew G Knepley Collective on DM 41196636e97aSMatthew G Knepley 41206636e97aSMatthew G Knepley Input Parameters: 41216636e97aSMatthew G Knepley + dm - the DM 41226636e97aSMatthew G Knepley - c - coordinate vector 41236636e97aSMatthew G Knepley 41246636e97aSMatthew G Knepley Note: 41256636e97aSMatthew G Knepley The coordinates do include those for ghost points, which are in the local vector 41266636e97aSMatthew G Knepley 41276636e97aSMatthew G Knepley Level: intermediate 41286636e97aSMatthew G Knepley 41296636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 41306636e97aSMatthew G Knepley .seealso: DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLoca(), DMGetCoordinateDM() 41316636e97aSMatthew G Knepley @*/ 41326636e97aSMatthew G Knepley PetscErrorCode DMSetCoordinates(DM dm, Vec c) 41336636e97aSMatthew G Knepley { 41346636e97aSMatthew G Knepley PetscErrorCode ierr; 41356636e97aSMatthew G Knepley 41366636e97aSMatthew G Knepley PetscFunctionBegin; 41376636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 41386636e97aSMatthew G Knepley PetscValidHeaderSpecific(c,VEC_CLASSID,2); 41396636e97aSMatthew G Knepley ierr = PetscObjectReference((PetscObject) c);CHKERRQ(ierr); 41406636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinates);CHKERRQ(ierr); 41416636e97aSMatthew G Knepley dm->coordinates = c; 41426636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinatesLocal);CHKERRQ(ierr); 4143b64e0483SPeter Brune ierr = DMCoarsenHookAdd(dm,DMRestrictHook_Coordinates,NULL,NULL);CHKERRQ(ierr); 414403dadc2fSPeter Brune ierr = DMSubDomainHookAdd(dm,DMSubDomainHook_Coordinates,NULL,NULL);CHKERRQ(ierr); 41456636e97aSMatthew G Knepley PetscFunctionReturn(0); 41466636e97aSMatthew G Knepley } 41476636e97aSMatthew G Knepley 41486636e97aSMatthew G Knepley #undef __FUNCT__ 41496636e97aSMatthew G Knepley #define __FUNCT__ "DMSetCoordinatesLocal" 41506636e97aSMatthew G Knepley /*@ 41516636e97aSMatthew G Knepley DMSetCoordinatesLocal - Sets into the DM a local vector that holds the coordinates 41526636e97aSMatthew G Knepley 41536636e97aSMatthew G Knepley Collective on DM 41546636e97aSMatthew G Knepley 41556636e97aSMatthew G Knepley Input Parameters: 41566636e97aSMatthew G Knepley + dm - the DM 41576636e97aSMatthew G Knepley - c - coordinate vector 41586636e97aSMatthew G Knepley 41596636e97aSMatthew G Knepley Note: 41606636e97aSMatthew G Knepley The coordinates of ghost points can be set using DMSetCoordinates() 41616636e97aSMatthew G Knepley followed by DMGetCoordinatesLocal(). This is intended to enable the 41626636e97aSMatthew G Knepley setting of ghost coordinates outside of the domain. 41636636e97aSMatthew G Knepley 41646636e97aSMatthew G Knepley Level: intermediate 41656636e97aSMatthew G Knepley 41666636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 41676636e97aSMatthew G Knepley .seealso: DMGetCoordinatesLocal(), DMSetCoordinates(), DMGetCoordinates(), DMGetCoordinateDM() 41686636e97aSMatthew G Knepley @*/ 41696636e97aSMatthew G Knepley PetscErrorCode DMSetCoordinatesLocal(DM dm, Vec c) 41706636e97aSMatthew G Knepley { 41716636e97aSMatthew G Knepley PetscErrorCode ierr; 41726636e97aSMatthew G Knepley 41736636e97aSMatthew G Knepley PetscFunctionBegin; 41746636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 41756636e97aSMatthew G Knepley PetscValidHeaderSpecific(c,VEC_CLASSID,2); 41766636e97aSMatthew G Knepley ierr = PetscObjectReference((PetscObject) c);CHKERRQ(ierr); 41776636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinatesLocal);CHKERRQ(ierr); 41788865f1eaSKarl Rupp 41796636e97aSMatthew G Knepley dm->coordinatesLocal = c; 41808865f1eaSKarl Rupp 41816636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinates);CHKERRQ(ierr); 41826636e97aSMatthew G Knepley PetscFunctionReturn(0); 41836636e97aSMatthew G Knepley } 41846636e97aSMatthew G Knepley 41856636e97aSMatthew G Knepley #undef __FUNCT__ 41866636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinates" 41876636e97aSMatthew G Knepley /*@ 41886636e97aSMatthew G Knepley DMGetCoordinates - Gets a global vector with the coordinates associated with the DM. 41896636e97aSMatthew G Knepley 41906636e97aSMatthew G Knepley Not Collective 41916636e97aSMatthew G Knepley 41926636e97aSMatthew G Knepley Input Parameter: 41936636e97aSMatthew G Knepley . dm - the DM 41946636e97aSMatthew G Knepley 41956636e97aSMatthew G Knepley Output Parameter: 41966636e97aSMatthew G Knepley . c - global coordinate vector 41976636e97aSMatthew G Knepley 41986636e97aSMatthew G Knepley Note: 41996636e97aSMatthew G Knepley This is a borrowed reference, so the user should NOT destroy this vector 42006636e97aSMatthew G Knepley 42016636e97aSMatthew G Knepley Each process has only the local coordinates (does NOT have the ghost coordinates). 42026636e97aSMatthew G Knepley 42036636e97aSMatthew G Knepley For DMDA, in two and three dimensions coordinates are interlaced (x_0,y_0,x_1,y_1,...) 42046636e97aSMatthew G Knepley and (x_0,y_0,z_0,x_1,y_1,z_1...) 42056636e97aSMatthew G Knepley 42066636e97aSMatthew G Knepley Level: intermediate 42076636e97aSMatthew G Knepley 42086636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 42096636e97aSMatthew G Knepley .seealso: DMSetCoordinates(), DMGetCoordinatesLocal(), DMGetCoordinateDM() 42106636e97aSMatthew G Knepley @*/ 42116636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinates(DM dm, Vec *c) 42126636e97aSMatthew G Knepley { 42136636e97aSMatthew G Knepley PetscErrorCode ierr; 42146636e97aSMatthew G Knepley 42156636e97aSMatthew G Knepley PetscFunctionBegin; 42166636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 42176636e97aSMatthew G Knepley PetscValidPointer(c,2); 42181f588964SMatthew G Knepley if (!dm->coordinates && dm->coordinatesLocal) { 42190298fd71SBarry Smith DM cdm = NULL; 42206636e97aSMatthew G Knepley 42216636e97aSMatthew G Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 42226636e97aSMatthew G Knepley ierr = DMCreateGlobalVector(cdm, &dm->coordinates);CHKERRQ(ierr); 42236636e97aSMatthew G Knepley ierr = PetscObjectSetName((PetscObject) dm->coordinates, "coordinates");CHKERRQ(ierr); 42246636e97aSMatthew G Knepley ierr = DMLocalToGlobalBegin(cdm, dm->coordinatesLocal, INSERT_VALUES, dm->coordinates);CHKERRQ(ierr); 42256636e97aSMatthew G Knepley ierr = DMLocalToGlobalEnd(cdm, dm->coordinatesLocal, INSERT_VALUES, dm->coordinates);CHKERRQ(ierr); 42266636e97aSMatthew G Knepley } 42276636e97aSMatthew G Knepley *c = dm->coordinates; 42286636e97aSMatthew G Knepley PetscFunctionReturn(0); 42296636e97aSMatthew G Knepley } 42306636e97aSMatthew G Knepley 42316636e97aSMatthew G Knepley #undef __FUNCT__ 42326636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinatesLocal" 42336636e97aSMatthew G Knepley /*@ 42346636e97aSMatthew G Knepley DMGetCoordinatesLocal - Gets a local vector with the coordinates associated with the DM. 42356636e97aSMatthew G Knepley 42366636e97aSMatthew G Knepley Collective on DM 42376636e97aSMatthew G Knepley 42386636e97aSMatthew G Knepley Input Parameter: 42396636e97aSMatthew G Knepley . dm - the DM 42406636e97aSMatthew G Knepley 42416636e97aSMatthew G Knepley Output Parameter: 42426636e97aSMatthew G Knepley . c - coordinate vector 42436636e97aSMatthew G Knepley 42446636e97aSMatthew G Knepley Note: 42456636e97aSMatthew G Knepley This is a borrowed reference, so the user should NOT destroy this vector 42466636e97aSMatthew G Knepley 42476636e97aSMatthew G Knepley Each process has the local and ghost coordinates 42486636e97aSMatthew G Knepley 42496636e97aSMatthew G Knepley For DMDA, in two and three dimensions coordinates are interlaced (x_0,y_0,x_1,y_1,...) 42506636e97aSMatthew G Knepley and (x_0,y_0,z_0,x_1,y_1,z_1...) 42516636e97aSMatthew G Knepley 42526636e97aSMatthew G Knepley Level: intermediate 42536636e97aSMatthew G Knepley 42546636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 42556636e97aSMatthew G Knepley .seealso: DMSetCoordinatesLocal(), DMGetCoordinates(), DMSetCoordinates(), DMGetCoordinateDM() 42566636e97aSMatthew G Knepley @*/ 42576636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinatesLocal(DM dm, Vec *c) 42586636e97aSMatthew G Knepley { 42596636e97aSMatthew G Knepley PetscErrorCode ierr; 42606636e97aSMatthew G Knepley 42616636e97aSMatthew G Knepley PetscFunctionBegin; 42626636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 42636636e97aSMatthew G Knepley PetscValidPointer(c,2); 42641f588964SMatthew G Knepley if (!dm->coordinatesLocal && dm->coordinates) { 42650298fd71SBarry Smith DM cdm = NULL; 42666636e97aSMatthew G Knepley 42676636e97aSMatthew G Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 42686636e97aSMatthew G Knepley ierr = DMCreateLocalVector(cdm, &dm->coordinatesLocal);CHKERRQ(ierr); 42696636e97aSMatthew G Knepley ierr = PetscObjectSetName((PetscObject) dm->coordinatesLocal, "coordinates");CHKERRQ(ierr); 42706636e97aSMatthew G Knepley ierr = DMGlobalToLocalBegin(cdm, dm->coordinates, INSERT_VALUES, dm->coordinatesLocal);CHKERRQ(ierr); 42716636e97aSMatthew G Knepley ierr = DMGlobalToLocalEnd(cdm, dm->coordinates, INSERT_VALUES, dm->coordinatesLocal);CHKERRQ(ierr); 42726636e97aSMatthew G Knepley } 42736636e97aSMatthew G Knepley *c = dm->coordinatesLocal; 42746636e97aSMatthew G Knepley PetscFunctionReturn(0); 42756636e97aSMatthew G Knepley } 42766636e97aSMatthew G Knepley 42776636e97aSMatthew G Knepley #undef __FUNCT__ 42786636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinateDM" 42796636e97aSMatthew G Knepley /*@ 42801cfe2091SMatthew G. Knepley DMGetCoordinateDM - Gets the DM that prescribes coordinate layout and scatters between global and local coordinates 42816636e97aSMatthew G Knepley 42826636e97aSMatthew G Knepley Collective on DM 42836636e97aSMatthew G Knepley 42846636e97aSMatthew G Knepley Input Parameter: 42856636e97aSMatthew G Knepley . dm - the DM 42866636e97aSMatthew G Knepley 42876636e97aSMatthew G Knepley Output Parameter: 42886636e97aSMatthew G Knepley . cdm - coordinate DM 42896636e97aSMatthew G Knepley 42906636e97aSMatthew G Knepley Level: intermediate 42916636e97aSMatthew G Knepley 42926636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 42931cfe2091SMatthew G. Knepley .seealso: DMSetCoordinateDM(), DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 42946636e97aSMatthew G Knepley @*/ 42956636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinateDM(DM dm, DM *cdm) 42966636e97aSMatthew G Knepley { 42976636e97aSMatthew G Knepley PetscErrorCode ierr; 42986636e97aSMatthew G Knepley 42996636e97aSMatthew G Knepley PetscFunctionBegin; 43006636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 43016636e97aSMatthew G Knepley PetscValidPointer(cdm,2); 43026636e97aSMatthew G Knepley if (!dm->coordinateDM) { 430382f516ccSBarry Smith if (!dm->ops->createcoordinatedm) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Unable to create coordinates for this DM"); 43046636e97aSMatthew G Knepley ierr = (*dm->ops->createcoordinatedm)(dm, &dm->coordinateDM);CHKERRQ(ierr); 43056636e97aSMatthew G Knepley } 43066636e97aSMatthew G Knepley *cdm = dm->coordinateDM; 43076636e97aSMatthew G Knepley PetscFunctionReturn(0); 43086636e97aSMatthew G Knepley } 4309e87bb0d3SMatthew G Knepley 4310e87bb0d3SMatthew G Knepley #undef __FUNCT__ 43111cfe2091SMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateDM" 43121cfe2091SMatthew G. Knepley /*@ 43131cfe2091SMatthew G. Knepley DMSetCoordinateDM - Sets the DM that prescribes coordinate layout and scatters between global and local coordinates 43141cfe2091SMatthew G. Knepley 43151cfe2091SMatthew G. Knepley Logically Collective on DM 43161cfe2091SMatthew G. Knepley 43171cfe2091SMatthew G. Knepley Input Parameters: 43181cfe2091SMatthew G. Knepley + dm - the DM 43191cfe2091SMatthew G. Knepley - cdm - coordinate DM 43201cfe2091SMatthew G. Knepley 43211cfe2091SMatthew G. Knepley Level: intermediate 43221cfe2091SMatthew G. Knepley 43231cfe2091SMatthew G. Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 43241cfe2091SMatthew G. Knepley .seealso: DMGetCoordinateDM(), DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 43251cfe2091SMatthew G. Knepley @*/ 43261cfe2091SMatthew G. Knepley PetscErrorCode DMSetCoordinateDM(DM dm, DM cdm) 43271cfe2091SMatthew G. Knepley { 43281cfe2091SMatthew G. Knepley PetscErrorCode ierr; 43291cfe2091SMatthew G. Knepley 43301cfe2091SMatthew G. Knepley PetscFunctionBegin; 43311cfe2091SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 43321cfe2091SMatthew G. Knepley PetscValidHeaderSpecific(cdm,DM_CLASSID,2); 43331cfe2091SMatthew G. Knepley ierr = DMDestroy(&dm->coordinateDM);CHKERRQ(ierr); 43341cfe2091SMatthew G. Knepley dm->coordinateDM = cdm; 43351cfe2091SMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm->coordinateDM);CHKERRQ(ierr); 43361cfe2091SMatthew G. Knepley PetscFunctionReturn(0); 43371cfe2091SMatthew G. Knepley } 43381cfe2091SMatthew G. Knepley 43391cfe2091SMatthew G. Knepley #undef __FUNCT__ 434046e270d4SMatthew G. Knepley #define __FUNCT__ "DMGetCoordinateDim" 434146e270d4SMatthew G. Knepley /*@ 434246e270d4SMatthew G. Knepley DMGetCoordinateDim - Retrieve the dimension of embedding space for coordinate values. 434346e270d4SMatthew G. Knepley 434446e270d4SMatthew G. Knepley Not Collective 434546e270d4SMatthew G. Knepley 434646e270d4SMatthew G. Knepley Input Parameter: 434746e270d4SMatthew G. Knepley . dm - The DM object 434846e270d4SMatthew G. Knepley 434946e270d4SMatthew G. Knepley Output Parameter: 435046e270d4SMatthew G. Knepley . dim - The embedding dimension 435146e270d4SMatthew G. Knepley 435246e270d4SMatthew G. Knepley Level: intermediate 435346e270d4SMatthew G. Knepley 435446e270d4SMatthew G. Knepley .keywords: mesh, coordinates 435546e270d4SMatthew G. Knepley .seealso: DMSetCoordinateDim(), DMGetCoordinateSection(), DMGetCoordinateDM(), DMGetDefaultSection(), DMSetDefaultSection() 435646e270d4SMatthew G. Knepley @*/ 435746e270d4SMatthew G. Knepley PetscErrorCode DMGetCoordinateDim(DM dm, PetscInt *dim) 435846e270d4SMatthew G. Knepley { 435946e270d4SMatthew G. Knepley PetscFunctionBegin; 436046e270d4SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 436146e270d4SMatthew G. Knepley PetscValidPointer(dim, 2); 43629a9a41abSToby Isaac if (dm->dimEmbed == PETSC_DEFAULT) { 43639a9a41abSToby Isaac dm->dimEmbed = dm->dim; 43649a9a41abSToby Isaac } 436546e270d4SMatthew G. Knepley *dim = dm->dimEmbed; 436646e270d4SMatthew G. Knepley PetscFunctionReturn(0); 436746e270d4SMatthew G. Knepley } 436846e270d4SMatthew G. Knepley 436946e270d4SMatthew G. Knepley #undef __FUNCT__ 437046e270d4SMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateDim" 437146e270d4SMatthew G. Knepley /*@ 437246e270d4SMatthew G. Knepley DMSetCoordinateDim - Set the dimension of the embedding space for coordinate values. 437346e270d4SMatthew G. Knepley 437446e270d4SMatthew G. Knepley Not Collective 437546e270d4SMatthew G. Knepley 437646e270d4SMatthew G. Knepley Input Parameters: 437746e270d4SMatthew G. Knepley + dm - The DM object 437846e270d4SMatthew G. Knepley - dim - The embedding dimension 437946e270d4SMatthew G. Knepley 438046e270d4SMatthew G. Knepley Level: intermediate 438146e270d4SMatthew G. Knepley 438246e270d4SMatthew G. Knepley .keywords: mesh, coordinates 438346e270d4SMatthew G. Knepley .seealso: DMGetCoordinateDim(), DMSetCoordinateSection(), DMGetCoordinateSection(), DMGetDefaultSection(), DMSetDefaultSection() 438446e270d4SMatthew G. Knepley @*/ 438546e270d4SMatthew G. Knepley PetscErrorCode DMSetCoordinateDim(DM dm, PetscInt dim) 438646e270d4SMatthew G. Knepley { 438746e270d4SMatthew G. Knepley PetscFunctionBegin; 438846e270d4SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 438946e270d4SMatthew G. Knepley dm->dimEmbed = dim; 439046e270d4SMatthew G. Knepley PetscFunctionReturn(0); 439146e270d4SMatthew G. Knepley } 439246e270d4SMatthew G. Knepley 439346e270d4SMatthew G. Knepley #undef __FUNCT__ 4394e8abe2deSMatthew G. Knepley #define __FUNCT__ "DMGetCoordinateSection" 4395e8abe2deSMatthew G. Knepley /*@ 4396e8abe2deSMatthew G. Knepley DMGetCoordinateSection - Retrieve the layout of coordinate values over the mesh. 4397e8abe2deSMatthew G. Knepley 4398e8abe2deSMatthew G. Knepley Not Collective 4399e8abe2deSMatthew G. Knepley 4400e8abe2deSMatthew G. Knepley Input Parameter: 4401e8abe2deSMatthew G. Knepley . dm - The DM object 4402e8abe2deSMatthew G. Knepley 4403e8abe2deSMatthew G. Knepley Output Parameter: 4404e8abe2deSMatthew G. Knepley . section - The PetscSection object 4405e8abe2deSMatthew G. Knepley 4406e8abe2deSMatthew G. Knepley Level: intermediate 4407e8abe2deSMatthew G. Knepley 4408e8abe2deSMatthew G. Knepley .keywords: mesh, coordinates 4409e8abe2deSMatthew G. Knepley .seealso: DMGetCoordinateDM(), DMGetDefaultSection(), DMSetDefaultSection() 4410e8abe2deSMatthew G. Knepley @*/ 4411e8abe2deSMatthew G. Knepley PetscErrorCode DMGetCoordinateSection(DM dm, PetscSection *section) 4412e8abe2deSMatthew G. Knepley { 4413e8abe2deSMatthew G. Knepley DM cdm; 4414e8abe2deSMatthew G. Knepley PetscErrorCode ierr; 4415e8abe2deSMatthew G. Knepley 4416e8abe2deSMatthew G. Knepley PetscFunctionBegin; 4417e8abe2deSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 4418e8abe2deSMatthew G. Knepley PetscValidPointer(section, 2); 4419e8abe2deSMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 4420e8abe2deSMatthew G. Knepley ierr = DMGetDefaultSection(cdm, section);CHKERRQ(ierr); 4421e8abe2deSMatthew G. Knepley PetscFunctionReturn(0); 4422e8abe2deSMatthew G. Knepley } 4423e8abe2deSMatthew G. Knepley 4424e8abe2deSMatthew G. Knepley #undef __FUNCT__ 4425e8abe2deSMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateSection" 4426e8abe2deSMatthew G. Knepley /*@ 4427e8abe2deSMatthew G. Knepley DMSetCoordinateSection - Set the layout of coordinate values over the mesh. 4428e8abe2deSMatthew G. Knepley 4429e8abe2deSMatthew G. Knepley Not Collective 4430e8abe2deSMatthew G. Knepley 4431e8abe2deSMatthew G. Knepley Input Parameters: 4432e8abe2deSMatthew G. Knepley + dm - The DM object 443346e270d4SMatthew G. Knepley . dim - The embedding dimension, or PETSC_DETERMINE 4434e8abe2deSMatthew G. Knepley - section - The PetscSection object 4435e8abe2deSMatthew G. Knepley 4436e8abe2deSMatthew G. Knepley Level: intermediate 4437e8abe2deSMatthew G. Knepley 4438e8abe2deSMatthew G. Knepley .keywords: mesh, coordinates 4439e8abe2deSMatthew G. Knepley .seealso: DMGetCoordinateSection(), DMGetDefaultSection(), DMSetDefaultSection() 4440e8abe2deSMatthew G. Knepley @*/ 444146e270d4SMatthew G. Knepley PetscErrorCode DMSetCoordinateSection(DM dm, PetscInt dim, PetscSection section) 4442e8abe2deSMatthew G. Knepley { 4443e8abe2deSMatthew G. Knepley DM cdm; 4444e8abe2deSMatthew G. Knepley PetscErrorCode ierr; 4445e8abe2deSMatthew G. Knepley 4446e8abe2deSMatthew G. Knepley PetscFunctionBegin; 4447e8abe2deSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 444846e270d4SMatthew G. Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,3); 4449e8abe2deSMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 4450e8abe2deSMatthew G. Knepley ierr = DMSetDefaultSection(cdm, section);CHKERRQ(ierr); 445146e270d4SMatthew G. Knepley if (dim == PETSC_DETERMINE) { 445246e270d4SMatthew G. Knepley PetscInt d = dim; 445346e270d4SMatthew G. Knepley PetscInt pStart, pEnd, vStart, vEnd, v, dd; 445446e270d4SMatthew G. Knepley 445546e270d4SMatthew G. Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 445646e270d4SMatthew G. Knepley ierr = DMGetDimPoints(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 445746e270d4SMatthew G. Knepley pStart = PetscMax(vStart, pStart); 445846e270d4SMatthew G. Knepley pEnd = PetscMin(vEnd, pEnd); 445946e270d4SMatthew G. Knepley for (v = pStart; v < pEnd; ++v) { 446046e270d4SMatthew G. Knepley ierr = PetscSectionGetDof(section, v, &dd);CHKERRQ(ierr); 446146e270d4SMatthew G. Knepley if (dd) {d = dd; break;} 446246e270d4SMatthew G. Knepley } 446346e270d4SMatthew G. Knepley ierr = DMSetCoordinateDim(dm, d);CHKERRQ(ierr); 446446e270d4SMatthew G. Knepley } 4465e8abe2deSMatthew G. Knepley PetscFunctionReturn(0); 4466e8abe2deSMatthew G. Knepley } 4467e8abe2deSMatthew G. Knepley 4468e8abe2deSMatthew G. Knepley #undef __FUNCT__ 4469c6b900c6SMatthew G. Knepley #define __FUNCT__ "DMGetPeriodicity" 44705dc8c3f7SMatthew G. Knepley /*@C 44715dc8c3f7SMatthew G. Knepley DMSetPeriodicity - Set the description of mesh periodicity 44725dc8c3f7SMatthew G. Knepley 44735dc8c3f7SMatthew G. Knepley Input Parameters: 44745dc8c3f7SMatthew G. Knepley + dm - The DM object 44755dc8c3f7SMatthew G. Knepley . maxCell - Over distances greater than this, we can assume a point has crossed over to another sheet, when trying to localize cell coordinates 44765dc8c3f7SMatthew G. Knepley . L - If we assume the mesh is a torus, this is the length of each coordinate 44775dc8c3f7SMatthew G. Knepley - bd - This describes the type of periodicity in each topological dimension 44785dc8c3f7SMatthew G. Knepley 44795dc8c3f7SMatthew G. Knepley Level: developer 44805dc8c3f7SMatthew G. Knepley 44815dc8c3f7SMatthew G. Knepley .seealso: DMGetPeriodicity() 44825dc8c3f7SMatthew G. Knepley @*/ 44835dc8c3f7SMatthew G. Knepley PetscErrorCode DMGetPeriodicity(DM dm, const PetscReal **maxCell, const PetscReal **L, const DMBoundaryType **bd) 4484c6b900c6SMatthew G. Knepley { 4485c6b900c6SMatthew G. Knepley PetscFunctionBegin; 4486c6b900c6SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4487c6b900c6SMatthew G. Knepley if (L) *L = dm->L; 4488c6b900c6SMatthew G. Knepley if (maxCell) *maxCell = dm->maxCell; 44895dc8c3f7SMatthew G. Knepley if (bd) *bd = dm->bdtype; 4490c6b900c6SMatthew G. Knepley PetscFunctionReturn(0); 4491c6b900c6SMatthew G. Knepley } 4492c6b900c6SMatthew G. Knepley 4493c6b900c6SMatthew G. Knepley #undef __FUNCT__ 4494c6b900c6SMatthew G. Knepley #define __FUNCT__ "DMSetPeriodicity" 44955dc8c3f7SMatthew G. Knepley /*@C 44965dc8c3f7SMatthew G. Knepley DMSetPeriodicity - Set the description of mesh periodicity 44975dc8c3f7SMatthew G. Knepley 44985dc8c3f7SMatthew G. Knepley Input Parameters: 44995dc8c3f7SMatthew G. Knepley + dm - The DM object 45005dc8c3f7SMatthew G. Knepley . maxCell - Over distances greater than this, we can assume a point has crossed over to another sheet, when trying to localize cell coordinates 45015dc8c3f7SMatthew G. Knepley . L - If we assume the mesh is a torus, this is the length of each coordinate 45025dc8c3f7SMatthew G. Knepley - bd - This describes the type of periodicity in each topological dimension 45035dc8c3f7SMatthew G. Knepley 45045dc8c3f7SMatthew G. Knepley Level: developer 45055dc8c3f7SMatthew G. Knepley 45065dc8c3f7SMatthew G. Knepley .seealso: DMGetPeriodicity() 45075dc8c3f7SMatthew G. Knepley @*/ 45085dc8c3f7SMatthew G. Knepley PetscErrorCode DMSetPeriodicity(DM dm, const PetscReal maxCell[], const PetscReal L[], const DMBoundaryType bd[]) 4509c6b900c6SMatthew G. Knepley { 4510c6b900c6SMatthew G. Knepley PetscInt dim, d; 4511c6b900c6SMatthew G. Knepley PetscErrorCode ierr; 4512c6b900c6SMatthew G. Knepley 4513c6b900c6SMatthew G. Knepley PetscFunctionBegin; 4514c6b900c6SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 45155dc8c3f7SMatthew G. Knepley PetscValidPointer(L,3);PetscValidPointer(maxCell,2);PetscValidPointer(bd,4); 45165dc8c3f7SMatthew G. Knepley ierr = PetscFree3(dm->L,dm->maxCell,dm->bdtype);CHKERRQ(ierr); 45175dc8c3f7SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 45185dc8c3f7SMatthew G. Knepley ierr = PetscMalloc3(dim,&dm->L,dim,&dm->maxCell,dim,&dm->bdtype);CHKERRQ(ierr); 45195dc8c3f7SMatthew G. Knepley for (d = 0; d < dim; ++d) {dm->L[d] = L[d]; dm->maxCell[d] = maxCell[d]; dm->bdtype[d] = bd[d];} 4520c6b900c6SMatthew G. Knepley PetscFunctionReturn(0); 4521c6b900c6SMatthew G. Knepley } 4522c6b900c6SMatthew G. Knepley 4523c6b900c6SMatthew G. Knepley #undef __FUNCT__ 45242e17dfb7SMatthew G. Knepley #define __FUNCT__ "DMLocalizeCoordinate" 45252e17dfb7SMatthew G. Knepley /*@ 45262e17dfb7SMatthew G. Knepley DMLocalizeCoordinate - If a mesh is periodic (a torus with lengths L_i, some of which can be infinite), project the coordinate onto [0, L_i) in each dimension. 45272e17dfb7SMatthew G. Knepley 45282e17dfb7SMatthew G. Knepley Input Parameters: 45292e17dfb7SMatthew G. Knepley + dm - The DM 45302e17dfb7SMatthew G. Knepley - in - The input coordinate point (dim numbers) 45312e17dfb7SMatthew G. Knepley 45322e17dfb7SMatthew G. Knepley Output Parameter: 45332e17dfb7SMatthew G. Knepley . out - The localized coordinate point 45342e17dfb7SMatthew G. Knepley 45352e17dfb7SMatthew G. Knepley Level: developer 45362e17dfb7SMatthew G. Knepley 45372e17dfb7SMatthew G. Knepley .seealso: DMLocalizeCoordinates(), DMLocalizeAddCoordinate() 45382e17dfb7SMatthew G. Knepley @*/ 45392e17dfb7SMatthew G. Knepley PetscErrorCode DMLocalizeCoordinate(DM dm, const PetscScalar in[], PetscScalar out[]) 45402e17dfb7SMatthew G. Knepley { 45412e17dfb7SMatthew G. Knepley PetscInt dim, d; 45422e17dfb7SMatthew G. Knepley PetscErrorCode ierr; 45432e17dfb7SMatthew G. Knepley 45442e17dfb7SMatthew G. Knepley PetscFunctionBegin; 45452e17dfb7SMatthew G. Knepley ierr = DMGetCoordinateDim(dm, &dim);CHKERRQ(ierr); 45462e17dfb7SMatthew G. Knepley if (!dm->maxCell) { 45472e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) out[d] = in[d]; 45482e17dfb7SMatthew G. Knepley } else { 45492e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) { 45502e17dfb7SMatthew G. Knepley out[d] = in[d] - dm->L[d]*floor(PetscRealPart(in[d])/dm->L[d]); 45512e17dfb7SMatthew G. Knepley } 45522e17dfb7SMatthew G. Knepley } 45532e17dfb7SMatthew G. Knepley PetscFunctionReturn(0); 45542e17dfb7SMatthew G. Knepley } 45552e17dfb7SMatthew G. Knepley 45562e17dfb7SMatthew G. Knepley #undef __FUNCT__ 45572e17dfb7SMatthew G. Knepley #define __FUNCT__ "DMLocalizeCoordinate_Internal" 45582e17dfb7SMatthew G. Knepley /* 45592e17dfb7SMatthew G. Knepley DMLocalizeCoordinate_Internal - If a mesh is periodic, and the input point is far from the anchor, pick the coordinate sheet of the torus which moves it closer. 45602e17dfb7SMatthew G. Knepley 45612e17dfb7SMatthew G. Knepley Input Parameters: 45622e17dfb7SMatthew G. Knepley + dm - The DM 45632e17dfb7SMatthew G. Knepley . dim - The spatial dimension 45642e17dfb7SMatthew G. Knepley . anchor - The anchor point, the input point can be no more than maxCell away from it 45652e17dfb7SMatthew G. Knepley - in - The input coordinate point (dim numbers) 45662e17dfb7SMatthew G. Knepley 45672e17dfb7SMatthew G. Knepley Output Parameter: 45682e17dfb7SMatthew G. Knepley . out - The localized coordinate point 45692e17dfb7SMatthew G. Knepley 45702e17dfb7SMatthew G. Knepley Level: developer 45712e17dfb7SMatthew G. Knepley 45722e17dfb7SMatthew G. Knepley Note: This is meant to get a set of coordinates close to each other, as in a cell. The anchor is usually the one of the vertices on a containing cell 45732e17dfb7SMatthew G. Knepley 45742e17dfb7SMatthew G. Knepley .seealso: DMLocalizeCoordinates(), DMLocalizeAddCoordinate() 45752e17dfb7SMatthew G. Knepley */ 45762e17dfb7SMatthew G. Knepley PetscErrorCode DMLocalizeCoordinate_Internal(DM dm, PetscInt dim, const PetscScalar anchor[], const PetscScalar in[], PetscScalar out[]) 45772e17dfb7SMatthew G. Knepley { 45782e17dfb7SMatthew G. Knepley PetscInt d; 45792e17dfb7SMatthew G. Knepley 45802e17dfb7SMatthew G. Knepley PetscFunctionBegin; 45812e17dfb7SMatthew G. Knepley if (!dm->maxCell) { 45822e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) out[d] = in[d]; 45832e17dfb7SMatthew G. Knepley } else { 45842e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) { 45852e17dfb7SMatthew G. Knepley if (PetscAbsScalar(anchor[d] - in[d]) > dm->maxCell[d]) { 45862e17dfb7SMatthew G. Knepley out[d] = PetscRealPart(anchor[d]) > PetscRealPart(in[d]) ? dm->L[d] + in[d] : in[d] - dm->L[d]; 45872e17dfb7SMatthew G. Knepley } else { 45882e17dfb7SMatthew G. Knepley out[d] = in[d]; 45892e17dfb7SMatthew G. Knepley } 45902e17dfb7SMatthew G. Knepley } 45912e17dfb7SMatthew G. Knepley } 45922e17dfb7SMatthew G. Knepley PetscFunctionReturn(0); 45932e17dfb7SMatthew G. Knepley } 45942e17dfb7SMatthew G. Knepley #undef __FUNCT__ 45952e17dfb7SMatthew G. Knepley #define __FUNCT__ "DMLocalizeCoordinateReal_Internal" 45962e17dfb7SMatthew G. Knepley PetscErrorCode DMLocalizeCoordinateReal_Internal(DM dm, PetscInt dim, const PetscReal anchor[], const PetscReal in[], PetscReal out[]) 45972e17dfb7SMatthew G. Knepley { 45982e17dfb7SMatthew G. Knepley PetscInt d; 45992e17dfb7SMatthew G. Knepley 46002e17dfb7SMatthew G. Knepley PetscFunctionBegin; 46012e17dfb7SMatthew G. Knepley if (!dm->maxCell) { 46022e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) out[d] = in[d]; 46032e17dfb7SMatthew G. Knepley } else { 46042e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) { 46052e17dfb7SMatthew G. Knepley if (PetscAbsReal(anchor[d] - in[d]) > dm->maxCell[d]) { 46062e17dfb7SMatthew G. Knepley out[d] = anchor[d] > in[d] ? dm->L[d] + in[d] : in[d] - dm->L[d]; 46072e17dfb7SMatthew G. Knepley } else { 46082e17dfb7SMatthew G. Knepley out[d] = in[d]; 46092e17dfb7SMatthew G. Knepley } 46102e17dfb7SMatthew G. Knepley } 46112e17dfb7SMatthew G. Knepley } 46122e17dfb7SMatthew G. Knepley PetscFunctionReturn(0); 46132e17dfb7SMatthew G. Knepley } 46142e17dfb7SMatthew G. Knepley 46152e17dfb7SMatthew G. Knepley #undef __FUNCT__ 46162e17dfb7SMatthew G. Knepley #define __FUNCT__ "DMLocalizeAddCoordinate_Internal" 46172e17dfb7SMatthew G. Knepley /* 46182e17dfb7SMatthew G. Knepley DMLocalizeAddCoordinate_Internal - If a mesh is periodic, and the input point is far from the anchor, pick the coordinate sheet of the torus which moves it closer. 46192e17dfb7SMatthew G. Knepley 46202e17dfb7SMatthew G. Knepley Input Parameters: 46212e17dfb7SMatthew G. Knepley + dm - The DM 46222e17dfb7SMatthew G. Knepley . dim - The spatial dimension 46232e17dfb7SMatthew G. Knepley . anchor - The anchor point, the input point can be no more than maxCell away from it 46242e17dfb7SMatthew G. Knepley . in - The input coordinate delta (dim numbers) 46252e17dfb7SMatthew G. Knepley - out - The input coordinate point (dim numbers) 46262e17dfb7SMatthew G. Knepley 46272e17dfb7SMatthew G. Knepley Output Parameter: 46282e17dfb7SMatthew G. Knepley . out - The localized coordinate in + out 46292e17dfb7SMatthew G. Knepley 46302e17dfb7SMatthew G. Knepley Level: developer 46312e17dfb7SMatthew G. Knepley 46322e17dfb7SMatthew G. Knepley Note: This is meant to get a set of coordinates close to each other, as in a cell. The anchor is usually the one of the vertices on a containing cell 46332e17dfb7SMatthew G. Knepley 46342e17dfb7SMatthew G. Knepley .seealso: DMLocalizeCoordinates(), DMLocalizeCoordinate() 46352e17dfb7SMatthew G. Knepley */ 46362e17dfb7SMatthew G. Knepley PetscErrorCode DMLocalizeAddCoordinate_Internal(DM dm, PetscInt dim, const PetscScalar anchor[], const PetscScalar in[], PetscScalar out[]) 46372e17dfb7SMatthew G. Knepley { 46382e17dfb7SMatthew G. Knepley PetscInt d; 46392e17dfb7SMatthew G. Knepley 46402e17dfb7SMatthew G. Knepley PetscFunctionBegin; 46412e17dfb7SMatthew G. Knepley if (!dm->maxCell) { 46422e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) out[d] += in[d]; 46432e17dfb7SMatthew G. Knepley } else { 46442e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) { 46452e17dfb7SMatthew G. Knepley if (PetscAbsScalar(anchor[d] - in[d]) > dm->maxCell[d]) { 46462e17dfb7SMatthew G. Knepley out[d] += PetscRealPart(anchor[d]) > PetscRealPart(in[d]) ? dm->L[d] + in[d] : in[d] - dm->L[d]; 46472e17dfb7SMatthew G. Knepley } else { 46482e17dfb7SMatthew G. Knepley out[d] += in[d]; 46492e17dfb7SMatthew G. Knepley } 46502e17dfb7SMatthew G. Knepley } 46512e17dfb7SMatthew G. Knepley } 46522e17dfb7SMatthew G. Knepley PetscFunctionReturn(0); 46532e17dfb7SMatthew G. Knepley } 46542e17dfb7SMatthew G. Knepley 46552e17dfb7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMPlexGetDepthStratum(DM, PetscInt, PetscInt *, PetscInt *); 46562e17dfb7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMPlexGetHeightStratum(DM, PetscInt, PetscInt *, PetscInt *); 46572e17dfb7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMPlexVecGetClosure(DM, PetscSection, Vec, PetscInt, PetscInt *, PetscScalar *[]); 46582e17dfb7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMPlexVecRestoreClosure(DM, PetscSection, Vec, PetscInt, PetscInt *, PetscScalar *[]); 46592e17dfb7SMatthew G. Knepley 46602e17dfb7SMatthew G. Knepley #undef __FUNCT__ 466136447a5eSToby Isaac #define __FUNCT__ "DMGetCoordinatesLocalized" 466236447a5eSToby Isaac /*@ 466336447a5eSToby Isaac DMGetCoordinatesLocalized - Check if the DM coordinates have been localized for cells 466436447a5eSToby Isaac 466536447a5eSToby Isaac Input Parameter: 466636447a5eSToby Isaac . dm - The DM 466736447a5eSToby Isaac 466836447a5eSToby Isaac Output Parameter: 466936447a5eSToby Isaac areLocalized - True if localized 467036447a5eSToby Isaac 467136447a5eSToby Isaac Level: developer 467236447a5eSToby Isaac 467336447a5eSToby Isaac .seealso: DMLocalizeCoordinates() 467436447a5eSToby Isaac @*/ 467536447a5eSToby Isaac PetscErrorCode DMGetCoordinatesLocalized(DM dm,PetscBool *areLocalized) 467636447a5eSToby Isaac { 467736447a5eSToby Isaac DM cdm; 467836447a5eSToby Isaac PetscSection coordSection; 467936447a5eSToby Isaac PetscInt cStart, cEnd, c, sStart, sEnd, dof; 468036447a5eSToby Isaac PetscBool alreadyLocalized, alreadyLocalizedGlobal; 468136447a5eSToby Isaac PetscErrorCode ierr; 468236447a5eSToby Isaac 468336447a5eSToby Isaac PetscFunctionBegin; 468436447a5eSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 46858b09590cSToby Isaac if (!dm->maxCell) { 46868b09590cSToby Isaac *areLocalized = PETSC_FALSE; 46878b09590cSToby Isaac PetscFunctionReturn(0); 46888b09590cSToby Isaac } 468936447a5eSToby Isaac /* We need some generic way of refering to cells/vertices */ 469036447a5eSToby Isaac ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 469136447a5eSToby Isaac { 469236447a5eSToby Isaac PetscBool isplex; 469336447a5eSToby Isaac 469436447a5eSToby Isaac ierr = PetscObjectTypeCompare((PetscObject) cdm, DMPLEX, &isplex);CHKERRQ(ierr); 469536447a5eSToby Isaac if (isplex) { 469636447a5eSToby Isaac ierr = DMPlexGetHeightStratum(cdm, 0, &cStart, &cEnd);CHKERRQ(ierr); 469736447a5eSToby Isaac } else SETERRQ(PetscObjectComm((PetscObject) cdm), PETSC_ERR_ARG_WRONG, "Coordinate localization requires a DMPLEX coordinate DM"); 469836447a5eSToby Isaac } 469936447a5eSToby Isaac ierr = DMGetCoordinateSection(dm, &coordSection);CHKERRQ(ierr); 470036447a5eSToby Isaac ierr = PetscSectionGetChart(coordSection,&sStart,&sEnd);CHKERRQ(ierr); 470136447a5eSToby Isaac alreadyLocalized = alreadyLocalizedGlobal = PETSC_TRUE; 470236447a5eSToby Isaac for (c = cStart; c < cEnd; ++c) { 470336447a5eSToby Isaac if (c < sStart || c >= sEnd) { 470436447a5eSToby Isaac alreadyLocalized = PETSC_FALSE; 470536447a5eSToby Isaac break; 470636447a5eSToby Isaac } 470736447a5eSToby Isaac ierr = PetscSectionGetDof(coordSection, c, &dof);CHKERRQ(ierr); 470836447a5eSToby Isaac if (!dof) { 470936447a5eSToby Isaac alreadyLocalized = PETSC_FALSE; 471036447a5eSToby Isaac break; 471136447a5eSToby Isaac } 471236447a5eSToby Isaac } 471336447a5eSToby Isaac ierr = MPI_Allreduce(&alreadyLocalized,&alreadyLocalizedGlobal,1,MPIU_BOOL,MPI_LAND,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 471436447a5eSToby Isaac *areLocalized = alreadyLocalizedGlobal; 471536447a5eSToby Isaac PetscFunctionReturn(0); 471636447a5eSToby Isaac } 471736447a5eSToby Isaac 471836447a5eSToby Isaac 471936447a5eSToby Isaac #undef __FUNCT__ 47202e17dfb7SMatthew G. Knepley #define __FUNCT__ "DMLocalizeCoordinates" 47212e17dfb7SMatthew G. Knepley /*@ 47222e17dfb7SMatthew G. Knepley DMLocalizeCoordinates - If a mesh is periodic, create local coordinates for each cell 47232e17dfb7SMatthew G. Knepley 47242e17dfb7SMatthew G. Knepley Input Parameter: 47252e17dfb7SMatthew G. Knepley . dm - The DM 47262e17dfb7SMatthew G. Knepley 47272e17dfb7SMatthew G. Knepley Level: developer 47282e17dfb7SMatthew G. Knepley 47292e17dfb7SMatthew G. Knepley .seealso: DMLocalizeCoordinate(), DMLocalizeAddCoordinate() 47302e17dfb7SMatthew G. Knepley @*/ 47312e17dfb7SMatthew G. Knepley PetscErrorCode DMLocalizeCoordinates(DM dm) 47322e17dfb7SMatthew G. Knepley { 47332e17dfb7SMatthew G. Knepley DM cdm; 47342e17dfb7SMatthew G. Knepley PetscSection coordSection, cSection; 47352e17dfb7SMatthew G. Knepley Vec coordinates, cVec; 47363e922f36SToby Isaac PetscScalar *coords, *coords2, *anchor, *localized; 47373e922f36SToby Isaac PetscInt Nc, vStart, vEnd, v, sStart, sEnd, newStart = PETSC_MAX_INT, newEnd = PETSC_MIN_INT, dof, d, off, off2, bs, coordSize; 4738e0ae35bbSToby Isaac PetscBool alreadyLocalized, alreadyLocalizedGlobal; 47393e922f36SToby Isaac PetscInt maxHeight = 0, h; 47403e922f36SToby Isaac PetscInt *pStart = NULL, *pEnd = NULL; 47412e17dfb7SMatthew G. Knepley PetscErrorCode ierr; 47422e17dfb7SMatthew G. Knepley 47432e17dfb7SMatthew G. Knepley PetscFunctionBegin; 47442e17dfb7SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 47452e17dfb7SMatthew G. Knepley if (!dm->maxCell) PetscFunctionReturn(0); 47462e17dfb7SMatthew G. Knepley /* We need some generic way of refering to cells/vertices */ 47472e17dfb7SMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 47482e17dfb7SMatthew G. Knepley { 47492e17dfb7SMatthew G. Knepley PetscBool isplex; 47502e17dfb7SMatthew G. Knepley 47512e17dfb7SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) cdm, DMPLEX, &isplex);CHKERRQ(ierr); 47522e17dfb7SMatthew G. Knepley if (isplex) { 47532e17dfb7SMatthew G. Knepley ierr = DMPlexGetDepthStratum(cdm, 0, &vStart, &vEnd);CHKERRQ(ierr); 47543e922f36SToby Isaac ierr = DMPlexGetMaxProjectionHeight(cdm,&maxHeight);CHKERRQ(ierr); 47553e922f36SToby Isaac ierr = DMGetWorkArray(dm,2*(maxHeight + 1),PETSC_INT,&pStart);CHKERRQ(ierr); 47563e922f36SToby Isaac pEnd = &pStart[maxHeight + 1]; 47573e922f36SToby Isaac newStart = vStart; 47583e922f36SToby Isaac newEnd = vEnd; 47593e922f36SToby Isaac for (h = 0; h <= maxHeight; h++) { 47603e922f36SToby Isaac ierr = DMPlexGetHeightStratum(cdm, h, &pStart[h], &pEnd[h]);CHKERRQ(ierr); 47613e922f36SToby Isaac newStart = PetscMin(newStart,pStart[h]); 47623e922f36SToby Isaac newEnd = PetscMax(newEnd,pEnd[h]); 47633e922f36SToby Isaac } 47642e17dfb7SMatthew G. Knepley } else SETERRQ(PetscObjectComm((PetscObject) cdm), PETSC_ERR_ARG_WRONG, "Coordinate localization requires a DMPLEX coordinate DM"); 47652e17dfb7SMatthew G. Knepley } 47662e17dfb7SMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); 47672e17dfb7SMatthew G. Knepley ierr = DMGetCoordinateSection(dm, &coordSection);CHKERRQ(ierr); 47683e922f36SToby Isaac ierr = VecGetBlockSize(coordinates, &bs);CHKERRQ(ierr); 4769e0ae35bbSToby Isaac ierr = PetscSectionGetChart(coordSection,&sStart,&sEnd);CHKERRQ(ierr); 47703e922f36SToby Isaac 47712e17dfb7SMatthew G. Knepley ierr = PetscSectionCreate(PetscObjectComm((PetscObject) dm), &cSection);CHKERRQ(ierr); 47722e17dfb7SMatthew G. Knepley ierr = PetscSectionSetNumFields(cSection, 1);CHKERRQ(ierr); 47732e17dfb7SMatthew G. Knepley ierr = PetscSectionGetFieldComponents(coordSection, 0, &Nc);CHKERRQ(ierr); 47742e17dfb7SMatthew G. Knepley ierr = PetscSectionSetFieldComponents(cSection, 0, Nc);CHKERRQ(ierr); 47753e922f36SToby Isaac ierr = PetscSectionSetChart(cSection, newStart, newEnd);CHKERRQ(ierr); 47763e922f36SToby Isaac 47773e922f36SToby Isaac ierr = DMGetWorkArray(dm, 2 * bs, PETSC_SCALAR, &anchor);CHKERRQ(ierr); 47783e922f36SToby Isaac localized = &anchor[bs]; 47793e922f36SToby Isaac alreadyLocalized = alreadyLocalizedGlobal = PETSC_TRUE; 47803e922f36SToby Isaac for (h = 0; h <= maxHeight; h++) { 47813e922f36SToby Isaac PetscInt cStart = pStart[h], cEnd = pEnd[h], c; 47823e922f36SToby Isaac 47833e922f36SToby Isaac for (c = cStart; c < cEnd; ++c) { 47843e922f36SToby Isaac PetscScalar *cellCoords = NULL; 47853e922f36SToby Isaac PetscInt b; 47863e922f36SToby Isaac 47873e922f36SToby Isaac if (c < sStart || c >= sEnd) alreadyLocalized = PETSC_FALSE; 47883e922f36SToby Isaac ierr = DMPlexVecGetClosure(cdm, coordSection, coordinates, c, &dof, &cellCoords);CHKERRQ(ierr); 47893e922f36SToby Isaac for (b = 0; b < bs; ++b) anchor[b] = cellCoords[b]; 47903e922f36SToby Isaac for (d = 0; d < dof/bs; ++d) { 47913e922f36SToby Isaac ierr = DMLocalizeCoordinate_Internal(dm, bs, anchor, &cellCoords[d*bs], localized);CHKERRQ(ierr); 47923e922f36SToby Isaac for (b = 0; b < bs; b++) { 47933e922f36SToby Isaac if (cellCoords[d*bs + b] != localized[b]) break; 47943e922f36SToby Isaac } 47953e922f36SToby Isaac if (b < bs) break; 47963e922f36SToby Isaac } 47973e922f36SToby Isaac if (d < dof/bs) { 47983e922f36SToby Isaac if (c >= sStart && c < sEnd) { 47993e922f36SToby Isaac PetscInt cdof; 48003e922f36SToby Isaac 48013e922f36SToby Isaac ierr = PetscSectionGetDof(coordSection, c, &cdof);CHKERRQ(ierr); 48023e922f36SToby Isaac if (cdof != dof) alreadyLocalized = PETSC_FALSE; 48033e922f36SToby Isaac } 48043e922f36SToby Isaac ierr = PetscSectionSetDof(cSection, c, dof);CHKERRQ(ierr); 48053e922f36SToby Isaac ierr = PetscSectionSetFieldDof(cSection, c, 0, dof);CHKERRQ(ierr); 48063e922f36SToby Isaac } 48073e922f36SToby Isaac ierr = DMPlexVecRestoreClosure(cdm, coordSection, coordinates, c, &dof, &cellCoords);CHKERRQ(ierr); 48083e922f36SToby Isaac } 48093e922f36SToby Isaac } 48103e922f36SToby Isaac ierr = MPI_Allreduce(&alreadyLocalized,&alreadyLocalizedGlobal,1,MPIU_BOOL,MPI_LAND,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 48113e922f36SToby Isaac if (alreadyLocalizedGlobal) { 48123e922f36SToby Isaac ierr = DMRestoreWorkArray(dm, 2 * bs, PETSC_SCALAR, &anchor);CHKERRQ(ierr); 48133e922f36SToby Isaac ierr = PetscSectionDestroy(&cSection);CHKERRQ(ierr); 48143e922f36SToby Isaac ierr = DMRestoreWorkArray(dm,2*(maxHeight + 1),PETSC_INT,&pStart);CHKERRQ(ierr); 48153e922f36SToby Isaac PetscFunctionReturn(0); 48163e922f36SToby Isaac } 48172e17dfb7SMatthew G. Knepley for (v = vStart; v < vEnd; ++v) { 48182e17dfb7SMatthew G. Knepley ierr = PetscSectionGetDof(coordSection, v, &dof);CHKERRQ(ierr); 48192e17dfb7SMatthew G. Knepley ierr = PetscSectionSetDof(cSection, v, dof);CHKERRQ(ierr); 48202e17dfb7SMatthew G. Knepley ierr = PetscSectionSetFieldDof(cSection, v, 0, dof);CHKERRQ(ierr); 48212e17dfb7SMatthew G. Knepley } 48222e17dfb7SMatthew G. Knepley ierr = PetscSectionSetUp(cSection);CHKERRQ(ierr); 48232e17dfb7SMatthew G. Knepley ierr = PetscSectionGetStorageSize(cSection, &coordSize);CHKERRQ(ierr); 48242e17dfb7SMatthew G. Knepley ierr = VecCreate(PetscObjectComm((PetscObject) dm), &cVec);CHKERRQ(ierr); 48252e17dfb7SMatthew G. Knepley ierr = PetscObjectSetName((PetscObject)cVec,"coordinates");CHKERRQ(ierr); 48262e17dfb7SMatthew G. Knepley ierr = VecSetBlockSize(cVec, bs);CHKERRQ(ierr); 48272e17dfb7SMatthew G. Knepley ierr = VecSetSizes(cVec, coordSize, PETSC_DETERMINE);CHKERRQ(ierr); 48282e17dfb7SMatthew G. Knepley ierr = VecSetType(cVec,VECSTANDARD);CHKERRQ(ierr); 48292e17dfb7SMatthew G. Knepley ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr); 48302e17dfb7SMatthew G. Knepley ierr = VecGetArray(cVec, &coords2);CHKERRQ(ierr); 48312e17dfb7SMatthew G. Knepley for (v = vStart; v < vEnd; ++v) { 48322e17dfb7SMatthew G. Knepley ierr = PetscSectionGetDof(coordSection, v, &dof);CHKERRQ(ierr); 48332e17dfb7SMatthew G. Knepley ierr = PetscSectionGetOffset(coordSection, v, &off);CHKERRQ(ierr); 48342e17dfb7SMatthew G. Knepley ierr = PetscSectionGetOffset(cSection, v, &off2);CHKERRQ(ierr); 48352e17dfb7SMatthew G. Knepley for (d = 0; d < dof; ++d) coords2[off2+d] = coords[off+d]; 48362e17dfb7SMatthew G. Knepley } 48373e922f36SToby Isaac for (h = 0; h <= maxHeight; h++) { 48383e922f36SToby Isaac PetscInt cStart = pStart[h], cEnd = pEnd[h], c; 48393e922f36SToby Isaac 48402e17dfb7SMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 48412e17dfb7SMatthew G. Knepley PetscScalar *cellCoords = NULL; 48423e922f36SToby Isaac PetscInt b, cdof; 48432e17dfb7SMatthew G. Knepley 48443e922f36SToby Isaac ierr = PetscSectionGetDof(cSection,c,&cdof);CHKERRQ(ierr); 48453e922f36SToby Isaac if (!cdof) continue; 48462e17dfb7SMatthew G. Knepley ierr = DMPlexVecGetClosure(cdm, coordSection, coordinates, c, &dof, &cellCoords);CHKERRQ(ierr); 48472e17dfb7SMatthew G. Knepley ierr = PetscSectionGetOffset(cSection, c, &off2);CHKERRQ(ierr); 48482e17dfb7SMatthew G. Knepley for (b = 0; b < bs; ++b) anchor[b] = cellCoords[b]; 48492e17dfb7SMatthew G. Knepley for (d = 0; d < dof/bs; ++d) {ierr = DMLocalizeCoordinate_Internal(dm, bs, anchor, &cellCoords[d*bs], &coords2[off2+d*bs]);CHKERRQ(ierr);} 48502e17dfb7SMatthew G. Knepley ierr = DMPlexVecRestoreClosure(cdm, coordSection, coordinates, c, &dof, &cellCoords);CHKERRQ(ierr); 48512e17dfb7SMatthew G. Knepley } 48523e922f36SToby Isaac } 48533e922f36SToby Isaac ierr = DMRestoreWorkArray(dm, 2 * bs, PETSC_SCALAR, &anchor);CHKERRQ(ierr); 48543e922f36SToby Isaac ierr = DMRestoreWorkArray(dm,2*(maxHeight + 1),PETSC_INT,&pStart);CHKERRQ(ierr); 48552e17dfb7SMatthew G. Knepley ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr); 48562e17dfb7SMatthew G. Knepley ierr = VecRestoreArray(cVec, &coords2);CHKERRQ(ierr); 48572e17dfb7SMatthew G. Knepley ierr = DMSetCoordinateSection(dm, PETSC_DETERMINE, cSection);CHKERRQ(ierr); 48582e17dfb7SMatthew G. Knepley ierr = DMSetCoordinatesLocal(dm, cVec);CHKERRQ(ierr); 48592e17dfb7SMatthew G. Knepley ierr = VecDestroy(&cVec);CHKERRQ(ierr); 48602e17dfb7SMatthew G. Knepley ierr = PetscSectionDestroy(&cSection);CHKERRQ(ierr); 48612e17dfb7SMatthew G. Knepley PetscFunctionReturn(0); 48622e17dfb7SMatthew G. Knepley } 48632e17dfb7SMatthew G. Knepley 48642e17dfb7SMatthew G. Knepley #undef __FUNCT__ 4865e87bb0d3SMatthew G Knepley #define __FUNCT__ "DMLocatePoints" 4866e87bb0d3SMatthew G Knepley /*@ 48673a93e3b7SToby Isaac DMLocatePoints - Locate the points in v in the mesh and return a PetscSF of the containing cells 4868e87bb0d3SMatthew G Knepley 48693a93e3b7SToby Isaac Collective on Vec v (see explanation below) 4870e87bb0d3SMatthew G Knepley 4871e87bb0d3SMatthew G Knepley Input Parameters: 4872e87bb0d3SMatthew G Knepley + dm - The DM 48733a93e3b7SToby Isaac . v - The Vec of points 487462a38674SMatthew G. Knepley . ltype - The type of point location, e.g. DM_POINTLOCATION_NONE or DM_POINTLOCATION_NEAREST 48753a93e3b7SToby Isaac - cells - Points to either NULL, or a PetscSF with guesses for which cells contain each point. 4876e87bb0d3SMatthew G Knepley 487761e3bb9bSMatthew G Knepley Output Parameter: 487862a38674SMatthew G. Knepley + v - The Vec of points, which now contains the nearest mesh points to the given points if DM_POINTLOCATION_NEAREST is used 487962a38674SMatthew G. Knepley - cells - The PetscSF containing the ranks and local indices of the containing points. 48803a93e3b7SToby Isaac 4881e87bb0d3SMatthew G Knepley 4882e87bb0d3SMatthew G Knepley Level: developer 488361e3bb9bSMatthew G Knepley 488462a38674SMatthew G. Knepley Notes: 48853a93e3b7SToby Isaac To do a search of the local cells of the mesh, v should have PETSC_COMM_SELF as its communicator. 488662a38674SMatthew G. Knepley To do a search of all the cells in the distributed mesh, v should have the same communicator as dm. 48873a93e3b7SToby Isaac 48883a93e3b7SToby Isaac If *cellSF is NULL on input, a PetscSF will be created. 488962a38674SMatthew G. Knepley If *cellSF is not NULL on input, it should point to an existing PetscSF, whose graph will be used as initial guesses. 48903a93e3b7SToby Isaac 48913a93e3b7SToby Isaac An array that maps each point to its containing cell can be obtained with 48923a93e3b7SToby Isaac 489362a38674SMatthew G. Knepley $ const PetscSFNode *cells; 489462a38674SMatthew G. Knepley $ PetscInt nFound; 489562a38674SMatthew G. Knepley $ const PetscSFNode *found; 489662a38674SMatthew G. Knepley $ 489762a38674SMatthew G. Knepley $ PetscSFGetGraph(cells,NULL,&nFound,&found,&cells); 48983a93e3b7SToby Isaac 48993a93e3b7SToby Isaac Where cells[i].rank is the rank of the cell containing point found[i] (or i if found == NULL), and cells[i].index is 49003a93e3b7SToby Isaac the index of the cell in its rank's local numbering. 49013a93e3b7SToby Isaac 490261e3bb9bSMatthew G Knepley .keywords: point location, mesh 490362a38674SMatthew G. Knepley .seealso: DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal(), DMPointLocationType 490461e3bb9bSMatthew G Knepley @*/ 490562a38674SMatthew G. Knepley PetscErrorCode DMLocatePoints(DM dm, Vec v, DMPointLocationType ltype, PetscSF *cellSF) 4906e87bb0d3SMatthew G Knepley { 4907735aa83eSMatthew G Knepley PetscErrorCode ierr; 4908735aa83eSMatthew G Knepley 4909e87bb0d3SMatthew G Knepley PetscFunctionBegin; 4910e87bb0d3SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4911e87bb0d3SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,2); 49123a93e3b7SToby Isaac PetscValidPointer(cellSF,3); 49133a93e3b7SToby Isaac if (*cellSF) { 49143a93e3b7SToby Isaac PetscMPIInt result; 49153a93e3b7SToby Isaac 49163a93e3b7SToby Isaac PetscValidHeaderSpecific(cellSF,PETSCSF_CLASSID,3); 49173a93e3b7SToby Isaac ierr = MPI_Comm_compare(PetscObjectComm((PetscObject)v),PetscObjectComm((PetscObject)cellSF),&result);CHKERRQ(ierr); 49183a93e3b7SToby Isaac if (result != MPI_IDENT && result != MPI_CONGRUENT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"cellSF must have a communicator congruent to v's"); 49193a93e3b7SToby Isaac } 49203a93e3b7SToby Isaac else { 49213a93e3b7SToby Isaac ierr = PetscSFCreate(PetscObjectComm((PetscObject)v),cellSF);CHKERRQ(ierr); 49223a93e3b7SToby Isaac } 492347a35634SPatrick Farrell ierr = PetscLogEventBegin(DM_LocatePoints,dm,0,0,0);CHKERRQ(ierr); 4924735aa83eSMatthew G Knepley if (dm->ops->locatepoints) { 492562a38674SMatthew G. Knepley ierr = (*dm->ops->locatepoints)(dm,v,ltype,*cellSF);CHKERRQ(ierr); 492682f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Point location not available for this DM"); 492747a35634SPatrick Farrell ierr = PetscLogEventEnd(DM_LocatePoints,dm,0,0,0);CHKERRQ(ierr); 4928e87bb0d3SMatthew G Knepley PetscFunctionReturn(0); 4929e87bb0d3SMatthew G Knepley } 493014f150ffSMatthew G. Knepley 493114f150ffSMatthew G. Knepley #undef __FUNCT__ 493214f150ffSMatthew G. Knepley #define __FUNCT__ "DMGetOutputDM" 4933f4d763aaSMatthew G. Knepley /*@ 4934f4d763aaSMatthew G. Knepley DMGetOutputDM - Retrieve the DM associated with the layout for output 4935f4d763aaSMatthew G. Knepley 4936f4d763aaSMatthew G. Knepley Input Parameter: 4937f4d763aaSMatthew G. Knepley . dm - The original DM 4938f4d763aaSMatthew G. Knepley 4939f4d763aaSMatthew G. Knepley Output Parameter: 4940f4d763aaSMatthew G. Knepley . odm - The DM which provides the layout for output 4941f4d763aaSMatthew G. Knepley 4942f4d763aaSMatthew G. Knepley Level: intermediate 4943f4d763aaSMatthew G. Knepley 4944f4d763aaSMatthew G. Knepley .seealso: VecView(), DMGetDefaultGlobalSection() 4945f4d763aaSMatthew G. Knepley @*/ 494614f150ffSMatthew G. Knepley PetscErrorCode DMGetOutputDM(DM dm, DM *odm) 494714f150ffSMatthew G. Knepley { 4948c26acbdeSMatthew G. Knepley PetscSection section; 4949c26acbdeSMatthew G. Knepley PetscBool hasConstraints; 495014f150ffSMatthew G. Knepley PetscErrorCode ierr; 495114f150ffSMatthew G. Knepley 495214f150ffSMatthew G. Knepley PetscFunctionBegin; 495314f150ffSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 495414f150ffSMatthew G. Knepley PetscValidPointer(odm,2); 4955c26acbdeSMatthew G. Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 4956c26acbdeSMatthew G. Knepley ierr = PetscSectionHasConstraints(section, &hasConstraints);CHKERRQ(ierr); 4957c26acbdeSMatthew G. Knepley if (!hasConstraints) { 4958c26acbdeSMatthew G. Knepley *odm = dm; 4959c26acbdeSMatthew G. Knepley PetscFunctionReturn(0); 4960c26acbdeSMatthew G. Knepley } 496114f150ffSMatthew G. Knepley if (!dm->dmBC) { 49620305aff6SMatthew G. Knepley PetscDS ds; 4963c26acbdeSMatthew G. Knepley PetscSection newSection, gsection; 496414f150ffSMatthew G. Knepley PetscSF sf; 496514f150ffSMatthew G. Knepley 496614f150ffSMatthew G. Knepley ierr = DMClone(dm, &dm->dmBC);CHKERRQ(ierr); 49670305aff6SMatthew G. Knepley ierr = DMGetDS(dm, &ds);CHKERRQ(ierr); 49680305aff6SMatthew G. Knepley ierr = DMSetDS(dm->dmBC, ds);CHKERRQ(ierr); 496914f150ffSMatthew G. Knepley ierr = PetscSectionClone(section, &newSection);CHKERRQ(ierr); 497014f150ffSMatthew G. Knepley ierr = DMSetDefaultSection(dm->dmBC, newSection);CHKERRQ(ierr); 497114f150ffSMatthew G. Knepley ierr = PetscSectionDestroy(&newSection);CHKERRQ(ierr); 497214f150ffSMatthew G. Knepley ierr = DMGetPointSF(dm->dmBC, &sf);CHKERRQ(ierr); 497315b58121SMatthew G. Knepley ierr = PetscSectionCreateGlobalSection(section, sf, PETSC_TRUE, PETSC_FALSE, &gsection);CHKERRQ(ierr); 497414f150ffSMatthew G. Knepley ierr = DMSetDefaultGlobalSection(dm->dmBC, gsection);CHKERRQ(ierr); 497514f150ffSMatthew G. Knepley ierr = PetscSectionDestroy(&gsection);CHKERRQ(ierr); 497614f150ffSMatthew G. Knepley } 497714f150ffSMatthew G. Knepley *odm = dm->dmBC; 497814f150ffSMatthew G. Knepley PetscFunctionReturn(0); 497914f150ffSMatthew G. Knepley } 4980f4d763aaSMatthew G. Knepley 4981f4d763aaSMatthew G. Knepley #undef __FUNCT__ 4982f4d763aaSMatthew G. Knepley #define __FUNCT__ "DMGetOutputSequenceNumber" 4983f4d763aaSMatthew G. Knepley /*@ 4984cdb7a50dSMatthew G. Knepley DMGetOutputSequenceNumber - Retrieve the sequence number/value for output 4985f4d763aaSMatthew G. Knepley 4986f4d763aaSMatthew G. Knepley Input Parameter: 4987f4d763aaSMatthew G. Knepley . dm - The original DM 4988f4d763aaSMatthew G. Knepley 4989cdb7a50dSMatthew G. Knepley Output Parameters: 4990cdb7a50dSMatthew G. Knepley + num - The output sequence number 4991cdb7a50dSMatthew G. Knepley - val - The output sequence value 4992f4d763aaSMatthew G. Knepley 4993f4d763aaSMatthew G. Knepley Level: intermediate 4994f4d763aaSMatthew G. Knepley 4995f4d763aaSMatthew G. Knepley Note: This is intended for output that should appear in sequence, for instance 4996f4d763aaSMatthew G. Knepley a set of timesteps in an HDF5 file, or a set of realizations of a stochastic system. 4997f4d763aaSMatthew G. Knepley 4998f4d763aaSMatthew G. Knepley .seealso: VecView() 4999f4d763aaSMatthew G. Knepley @*/ 5000cdb7a50dSMatthew G. Knepley PetscErrorCode DMGetOutputSequenceNumber(DM dm, PetscInt *num, PetscReal *val) 5001f4d763aaSMatthew G. Knepley { 5002f4d763aaSMatthew G. Knepley PetscFunctionBegin; 5003f4d763aaSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5004cdb7a50dSMatthew G. Knepley if (num) {PetscValidPointer(num,2); *num = dm->outputSequenceNum;} 5005cdb7a50dSMatthew G. Knepley if (val) {PetscValidPointer(val,3);*val = dm->outputSequenceVal;} 5006f4d763aaSMatthew G. Knepley PetscFunctionReturn(0); 5007f4d763aaSMatthew G. Knepley } 5008f4d763aaSMatthew G. Knepley 5009f4d763aaSMatthew G. Knepley #undef __FUNCT__ 5010f4d763aaSMatthew G. Knepley #define __FUNCT__ "DMSetOutputSequenceNumber" 5011f4d763aaSMatthew G. Knepley /*@ 5012cdb7a50dSMatthew G. Knepley DMSetOutputSequenceNumber - Set the sequence number/value for output 5013f4d763aaSMatthew G. Knepley 5014f4d763aaSMatthew G. Knepley Input Parameters: 5015f4d763aaSMatthew G. Knepley + dm - The original DM 5016cdb7a50dSMatthew G. Knepley . num - The output sequence number 5017cdb7a50dSMatthew G. Knepley - val - The output sequence value 5018f4d763aaSMatthew G. Knepley 5019f4d763aaSMatthew G. Knepley Level: intermediate 5020f4d763aaSMatthew G. Knepley 5021f4d763aaSMatthew G. Knepley Note: This is intended for output that should appear in sequence, for instance 5022f4d763aaSMatthew G. Knepley a set of timesteps in an HDF5 file, or a set of realizations of a stochastic system. 5023f4d763aaSMatthew G. Knepley 5024f4d763aaSMatthew G. Knepley .seealso: VecView() 5025f4d763aaSMatthew G. Knepley @*/ 5026cdb7a50dSMatthew G. Knepley PetscErrorCode DMSetOutputSequenceNumber(DM dm, PetscInt num, PetscReal val) 5027f4d763aaSMatthew G. Knepley { 5028f4d763aaSMatthew G. Knepley PetscFunctionBegin; 5029f4d763aaSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5030f4d763aaSMatthew G. Knepley dm->outputSequenceNum = num; 5031cdb7a50dSMatthew G. Knepley dm->outputSequenceVal = val; 5032cdb7a50dSMatthew G. Knepley PetscFunctionReturn(0); 5033cdb7a50dSMatthew G. Knepley } 5034cdb7a50dSMatthew G. Knepley 5035cdb7a50dSMatthew G. Knepley #undef __FUNCT__ 5036cdb7a50dSMatthew G. Knepley #define __FUNCT__ "DMOutputSequenceLoad" 5037cdb7a50dSMatthew G. Knepley /*@C 5038cdb7a50dSMatthew G. Knepley DMOutputSequenceLoad - Retrieve the sequence value from a Viewer 5039cdb7a50dSMatthew G. Knepley 5040cdb7a50dSMatthew G. Knepley Input Parameters: 5041cdb7a50dSMatthew G. Knepley + dm - The original DM 5042cdb7a50dSMatthew G. Knepley . name - The sequence name 5043cdb7a50dSMatthew G. Knepley - num - The output sequence number 5044cdb7a50dSMatthew G. Knepley 5045cdb7a50dSMatthew G. Knepley Output Parameter: 5046cdb7a50dSMatthew G. Knepley . val - The output sequence value 5047cdb7a50dSMatthew G. Knepley 5048cdb7a50dSMatthew G. Knepley Level: intermediate 5049cdb7a50dSMatthew G. Knepley 5050cdb7a50dSMatthew G. Knepley Note: This is intended for output that should appear in sequence, for instance 5051cdb7a50dSMatthew G. Knepley a set of timesteps in an HDF5 file, or a set of realizations of a stochastic system. 5052cdb7a50dSMatthew G. Knepley 5053cdb7a50dSMatthew G. Knepley .seealso: DMGetOutputSequenceNumber(), DMSetOutputSequenceNumber(), VecView() 5054cdb7a50dSMatthew G. Knepley @*/ 5055cdb7a50dSMatthew G. Knepley PetscErrorCode DMOutputSequenceLoad(DM dm, PetscViewer viewer, const char *name, PetscInt num, PetscReal *val) 5056cdb7a50dSMatthew G. Knepley { 5057cdb7a50dSMatthew G. Knepley PetscBool ishdf5; 5058cdb7a50dSMatthew G. Knepley PetscErrorCode ierr; 5059cdb7a50dSMatthew G. Knepley 5060cdb7a50dSMatthew G. Knepley PetscFunctionBegin; 5061cdb7a50dSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5062cdb7a50dSMatthew G. Knepley PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 5063cdb7a50dSMatthew G. Knepley PetscValidPointer(val,4); 5064cdb7a50dSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 5065cdb7a50dSMatthew G. Knepley if (ishdf5) { 5066cdb7a50dSMatthew G. Knepley #if defined(PETSC_HAVE_HDF5) 5067cdb7a50dSMatthew G. Knepley PetscScalar value; 5068cdb7a50dSMatthew G. Knepley 5069cdb7a50dSMatthew G. Knepley ierr = DMSequenceLoad_HDF5(dm, name, num, &value, viewer);CHKERRQ(ierr); 50704aeb217fSMatthew G. Knepley *val = PetscRealPart(value); 5071cdb7a50dSMatthew G. Knepley #endif 5072cdb7a50dSMatthew G. Knepley } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Invalid viewer; open viewer with PetscViewerHDF5Open()"); 5073f4d763aaSMatthew G. Knepley PetscFunctionReturn(0); 5074f4d763aaSMatthew G. Knepley } 50758e4ac7eaSMatthew G. Knepley 50768e4ac7eaSMatthew G. Knepley #undef __FUNCT__ 50778e4ac7eaSMatthew G. Knepley #define __FUNCT__ "DMGetUseNatural" 50788e4ac7eaSMatthew G. Knepley /*@ 50798e4ac7eaSMatthew G. Knepley DMGetUseNatural - Get the flag for creating a mapping to the natural order on distribution 50808e4ac7eaSMatthew G. Knepley 50818e4ac7eaSMatthew G. Knepley Not collective 50828e4ac7eaSMatthew G. Knepley 50838e4ac7eaSMatthew G. Knepley Input Parameter: 50848e4ac7eaSMatthew G. Knepley . dm - The DM 50858e4ac7eaSMatthew G. Knepley 50868e4ac7eaSMatthew G. Knepley Output Parameter: 50878e4ac7eaSMatthew G. Knepley . useNatural - The flag to build the mapping to a natural order during distribution 50888e4ac7eaSMatthew G. Knepley 50898e4ac7eaSMatthew G. Knepley Level: beginner 50908e4ac7eaSMatthew G. Knepley 50918e4ac7eaSMatthew G. Knepley .seealso: DMSetUseNatural(), DMCreate() 50928e4ac7eaSMatthew G. Knepley @*/ 50938e4ac7eaSMatthew G. Knepley PetscErrorCode DMGetUseNatural(DM dm, PetscBool *useNatural) 50948e4ac7eaSMatthew G. Knepley { 50958e4ac7eaSMatthew G. Knepley PetscFunctionBegin; 50968e4ac7eaSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 50978e4ac7eaSMatthew G. Knepley PetscValidPointer(useNatural, 2); 50988e4ac7eaSMatthew G. Knepley *useNatural = dm->useNatural; 50998e4ac7eaSMatthew G. Knepley PetscFunctionReturn(0); 51008e4ac7eaSMatthew G. Knepley } 51018e4ac7eaSMatthew G. Knepley 51028e4ac7eaSMatthew G. Knepley #undef __FUNCT__ 51038e4ac7eaSMatthew G. Knepley #define __FUNCT__ "DMSetUseNatural" 51048e4ac7eaSMatthew G. Knepley /*@ 51058e4ac7eaSMatthew G. Knepley DMSetUseNatural - Set the flag for creating a mapping to the natural order on distribution 51068e4ac7eaSMatthew G. Knepley 51078e4ac7eaSMatthew G. Knepley Collective on dm 51088e4ac7eaSMatthew G. Knepley 51098e4ac7eaSMatthew G. Knepley Input Parameters: 51108e4ac7eaSMatthew G. Knepley + dm - The DM 51118e4ac7eaSMatthew G. Knepley - useNatural - The flag to build the mapping to a natural order during distribution 51128e4ac7eaSMatthew G. Knepley 51138e4ac7eaSMatthew G. Knepley Level: beginner 51148e4ac7eaSMatthew G. Knepley 51158e4ac7eaSMatthew G. Knepley .seealso: DMGetUseNatural(), DMCreate() 51168e4ac7eaSMatthew G. Knepley @*/ 51178e4ac7eaSMatthew G. Knepley PetscErrorCode DMSetUseNatural(DM dm, PetscBool useNatural) 51188e4ac7eaSMatthew G. Knepley { 51198e4ac7eaSMatthew G. Knepley PetscFunctionBegin; 51208e4ac7eaSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 51218e4ac7eaSMatthew G. Knepley PetscValidLogicalCollectiveInt(dm, useNatural, 2); 51228e4ac7eaSMatthew G. Knepley dm->useNatural = useNatural; 51238e4ac7eaSMatthew G. Knepley PetscFunctionReturn(0); 51248e4ac7eaSMatthew G. Knepley } 5125c58f1c22SToby Isaac 5126c58f1c22SToby Isaac #undef __FUNCT__ 5127c58f1c22SToby Isaac #define __FUNCT__ 5128c58f1c22SToby Isaac 5129c58f1c22SToby Isaac #undef __FUNCT__ 5130c58f1c22SToby Isaac #define __FUNCT__ "DMCreateLabel" 5131c58f1c22SToby Isaac /*@C 5132c58f1c22SToby Isaac DMCreateLabel - Create a label of the given name if it does not already exist 5133c58f1c22SToby Isaac 5134c58f1c22SToby Isaac Not Collective 5135c58f1c22SToby Isaac 5136c58f1c22SToby Isaac Input Parameters: 5137c58f1c22SToby Isaac + dm - The DM object 5138c58f1c22SToby Isaac - name - The label name 5139c58f1c22SToby Isaac 5140c58f1c22SToby Isaac Level: intermediate 5141c58f1c22SToby Isaac 5142c58f1c22SToby Isaac .keywords: mesh 5143c58f1c22SToby Isaac .seealso: DMLabelCreate(), DMHasLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5144c58f1c22SToby Isaac @*/ 5145c58f1c22SToby Isaac PetscErrorCode DMCreateLabel(DM dm, const char name[]) 5146c58f1c22SToby Isaac { 5147c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5148c58f1c22SToby Isaac PetscBool flg = PETSC_FALSE; 5149c58f1c22SToby Isaac PetscErrorCode ierr; 5150c58f1c22SToby Isaac 5151c58f1c22SToby Isaac PetscFunctionBegin; 5152c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5153c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5154c58f1c22SToby Isaac while (next) { 5155c58f1c22SToby Isaac ierr = PetscStrcmp(name, next->label->name, &flg);CHKERRQ(ierr); 5156c58f1c22SToby Isaac if (flg) break; 5157c58f1c22SToby Isaac next = next->next; 5158c58f1c22SToby Isaac } 5159c58f1c22SToby Isaac if (!flg) { 5160c58f1c22SToby Isaac DMLabelLink tmpLabel; 5161c58f1c22SToby Isaac 5162c58f1c22SToby Isaac ierr = PetscCalloc1(1, &tmpLabel);CHKERRQ(ierr); 5163c58f1c22SToby Isaac ierr = DMLabelCreate(name, &tmpLabel->label);CHKERRQ(ierr); 5164c58f1c22SToby Isaac tmpLabel->output = PETSC_TRUE; 5165c58f1c22SToby Isaac tmpLabel->next = dm->labels->next; 5166c58f1c22SToby Isaac dm->labels->next = tmpLabel; 5167c58f1c22SToby Isaac } 5168c58f1c22SToby Isaac PetscFunctionReturn(0); 5169c58f1c22SToby Isaac } 5170c58f1c22SToby Isaac 5171c58f1c22SToby Isaac #undef __FUNCT__ 5172c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabelValue" 5173c58f1c22SToby Isaac /*@C 5174c58f1c22SToby Isaac DMGetLabelValue - Get the value in a Sieve Label for the given point, with 0 as the default 5175c58f1c22SToby Isaac 5176c58f1c22SToby Isaac Not Collective 5177c58f1c22SToby Isaac 5178c58f1c22SToby Isaac Input Parameters: 5179c58f1c22SToby Isaac + dm - The DM object 5180c58f1c22SToby Isaac . name - The label name 5181c58f1c22SToby Isaac - point - The mesh point 5182c58f1c22SToby Isaac 5183c58f1c22SToby Isaac Output Parameter: 5184c58f1c22SToby Isaac . value - The label value for this point, or -1 if the point is not in the label 5185c58f1c22SToby Isaac 5186c58f1c22SToby Isaac Level: beginner 5187c58f1c22SToby Isaac 5188c58f1c22SToby Isaac .keywords: mesh 5189c58f1c22SToby Isaac .seealso: DMLabelGetValue(), DMSetLabelValue(), DMGetStratumIS() 5190c58f1c22SToby Isaac @*/ 5191c58f1c22SToby Isaac PetscErrorCode DMGetLabelValue(DM dm, const char name[], PetscInt point, PetscInt *value) 5192c58f1c22SToby Isaac { 5193c58f1c22SToby Isaac DMLabel label; 5194c58f1c22SToby Isaac PetscErrorCode ierr; 5195c58f1c22SToby Isaac 5196c58f1c22SToby Isaac PetscFunctionBegin; 5197c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5198c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5199c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5200c58f1c22SToby Isaac if (!label) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No label named %s was found", name);CHKERRQ(ierr); 5201c58f1c22SToby Isaac ierr = DMLabelGetValue(label, point, value);CHKERRQ(ierr); 5202c58f1c22SToby Isaac PetscFunctionReturn(0); 5203c58f1c22SToby Isaac } 5204c58f1c22SToby Isaac 5205c58f1c22SToby Isaac #undef __FUNCT__ 5206c58f1c22SToby Isaac #define __FUNCT__ "DMSetLabelValue" 5207c58f1c22SToby Isaac /*@C 5208c58f1c22SToby Isaac DMSetLabelValue - Add a point to a Sieve Label with given value 5209c58f1c22SToby Isaac 5210c58f1c22SToby Isaac Not Collective 5211c58f1c22SToby Isaac 5212c58f1c22SToby Isaac Input Parameters: 5213c58f1c22SToby Isaac + dm - The DM object 5214c58f1c22SToby Isaac . name - The label name 5215c58f1c22SToby Isaac . point - The mesh point 5216c58f1c22SToby Isaac - value - The label value for this point 5217c58f1c22SToby Isaac 5218c58f1c22SToby Isaac Output Parameter: 5219c58f1c22SToby Isaac 5220c58f1c22SToby Isaac Level: beginner 5221c58f1c22SToby Isaac 5222c58f1c22SToby Isaac .keywords: mesh 5223c58f1c22SToby Isaac .seealso: DMLabelSetValue(), DMGetStratumIS(), DMClearLabelValue() 5224c58f1c22SToby Isaac @*/ 5225c58f1c22SToby Isaac PetscErrorCode DMSetLabelValue(DM dm, const char name[], PetscInt point, PetscInt value) 5226c58f1c22SToby Isaac { 5227c58f1c22SToby Isaac DMLabel label; 5228c58f1c22SToby Isaac PetscErrorCode ierr; 5229c58f1c22SToby Isaac 5230c58f1c22SToby Isaac PetscFunctionBegin; 5231c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5232c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5233c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5234c58f1c22SToby Isaac if (!label) { 5235c58f1c22SToby Isaac ierr = DMCreateLabel(dm, name);CHKERRQ(ierr); 5236c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5237c58f1c22SToby Isaac } 5238c58f1c22SToby Isaac ierr = DMLabelSetValue(label, point, value);CHKERRQ(ierr); 5239c58f1c22SToby Isaac PetscFunctionReturn(0); 5240c58f1c22SToby Isaac } 5241c58f1c22SToby Isaac 5242c58f1c22SToby Isaac #undef __FUNCT__ 5243c58f1c22SToby Isaac #define __FUNCT__ "DMClearLabelValue" 5244c58f1c22SToby Isaac /*@C 5245c58f1c22SToby Isaac DMClearLabelValue - Remove a point from a Sieve Label with given value 5246c58f1c22SToby Isaac 5247c58f1c22SToby Isaac Not Collective 5248c58f1c22SToby Isaac 5249c58f1c22SToby Isaac Input Parameters: 5250c58f1c22SToby Isaac + dm - The DM object 5251c58f1c22SToby Isaac . name - The label name 5252c58f1c22SToby Isaac . point - The mesh point 5253c58f1c22SToby Isaac - value - The label value for this point 5254c58f1c22SToby Isaac 5255c58f1c22SToby Isaac Output Parameter: 5256c58f1c22SToby Isaac 5257c58f1c22SToby Isaac Level: beginner 5258c58f1c22SToby Isaac 5259c58f1c22SToby Isaac .keywords: mesh 5260c58f1c22SToby Isaac .seealso: DMLabelClearValue(), DMSetLabelValue(), DMGetStratumIS() 5261c58f1c22SToby Isaac @*/ 5262c58f1c22SToby Isaac PetscErrorCode DMClearLabelValue(DM dm, const char name[], PetscInt point, PetscInt value) 5263c58f1c22SToby Isaac { 5264c58f1c22SToby Isaac DMLabel label; 5265c58f1c22SToby Isaac PetscErrorCode ierr; 5266c58f1c22SToby Isaac 5267c58f1c22SToby Isaac PetscFunctionBegin; 5268c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5269c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5270c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5271c58f1c22SToby Isaac if (!label) PetscFunctionReturn(0); 5272c58f1c22SToby Isaac ierr = DMLabelClearValue(label, point, value);CHKERRQ(ierr); 5273c58f1c22SToby Isaac PetscFunctionReturn(0); 5274c58f1c22SToby Isaac } 5275c58f1c22SToby Isaac 5276c58f1c22SToby Isaac #undef __FUNCT__ 5277c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabelSize" 5278c58f1c22SToby Isaac /*@C 5279c58f1c22SToby Isaac DMGetLabelSize - Get the number of different integer ids in a Label 5280c58f1c22SToby Isaac 5281c58f1c22SToby Isaac Not Collective 5282c58f1c22SToby Isaac 5283c58f1c22SToby Isaac Input Parameters: 5284c58f1c22SToby Isaac + dm - The DM object 5285c58f1c22SToby Isaac - name - The label name 5286c58f1c22SToby Isaac 5287c58f1c22SToby Isaac Output Parameter: 5288c58f1c22SToby Isaac . size - The number of different integer ids, or 0 if the label does not exist 5289c58f1c22SToby Isaac 5290c58f1c22SToby Isaac Level: beginner 5291c58f1c22SToby Isaac 5292c58f1c22SToby Isaac .keywords: mesh 5293c58f1c22SToby Isaac .seealso: DMLabeGetNumValues(), DMSetLabelValue() 5294c58f1c22SToby Isaac @*/ 5295c58f1c22SToby Isaac PetscErrorCode DMGetLabelSize(DM dm, const char name[], PetscInt *size) 5296c58f1c22SToby Isaac { 5297c58f1c22SToby Isaac DMLabel label; 5298c58f1c22SToby Isaac PetscErrorCode ierr; 5299c58f1c22SToby Isaac 5300c58f1c22SToby Isaac PetscFunctionBegin; 5301c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5302c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5303c58f1c22SToby Isaac PetscValidPointer(size, 3); 5304c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5305c58f1c22SToby Isaac *size = 0; 5306c58f1c22SToby Isaac if (!label) PetscFunctionReturn(0); 5307c58f1c22SToby Isaac ierr = DMLabelGetNumValues(label, size);CHKERRQ(ierr); 5308c58f1c22SToby Isaac PetscFunctionReturn(0); 5309c58f1c22SToby Isaac } 5310c58f1c22SToby Isaac 5311c58f1c22SToby Isaac #undef __FUNCT__ 5312c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabelIdIS" 5313c58f1c22SToby Isaac /*@C 5314c58f1c22SToby Isaac DMGetLabelIdIS - Get the integer ids in a label 5315c58f1c22SToby Isaac 5316c58f1c22SToby Isaac Not Collective 5317c58f1c22SToby Isaac 5318c58f1c22SToby Isaac Input Parameters: 5319c58f1c22SToby Isaac + mesh - The DM object 5320c58f1c22SToby Isaac - name - The label name 5321c58f1c22SToby Isaac 5322c58f1c22SToby Isaac Output Parameter: 5323c58f1c22SToby Isaac . ids - The integer ids, or NULL if the label does not exist 5324c58f1c22SToby Isaac 5325c58f1c22SToby Isaac Level: beginner 5326c58f1c22SToby Isaac 5327c58f1c22SToby Isaac .keywords: mesh 5328c58f1c22SToby Isaac .seealso: DMLabelGetValueIS(), DMGetLabelSize() 5329c58f1c22SToby Isaac @*/ 5330c58f1c22SToby Isaac PetscErrorCode DMGetLabelIdIS(DM dm, const char name[], IS *ids) 5331c58f1c22SToby Isaac { 5332c58f1c22SToby Isaac DMLabel label; 5333c58f1c22SToby Isaac PetscErrorCode ierr; 5334c58f1c22SToby Isaac 5335c58f1c22SToby Isaac PetscFunctionBegin; 5336c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5337c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5338c58f1c22SToby Isaac PetscValidPointer(ids, 3); 5339c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5340c58f1c22SToby Isaac *ids = NULL; 5341c58f1c22SToby Isaac if (!label) PetscFunctionReturn(0); 5342c58f1c22SToby Isaac ierr = DMLabelGetValueIS(label, ids);CHKERRQ(ierr); 5343c58f1c22SToby Isaac PetscFunctionReturn(0); 5344c58f1c22SToby Isaac } 5345c58f1c22SToby Isaac 5346c58f1c22SToby Isaac #undef __FUNCT__ 5347c58f1c22SToby Isaac #define __FUNCT__ "DMGetStratumSize" 5348c58f1c22SToby Isaac /*@C 5349c58f1c22SToby Isaac DMGetStratumSize - Get the number of points in a label stratum 5350c58f1c22SToby Isaac 5351c58f1c22SToby Isaac Not Collective 5352c58f1c22SToby Isaac 5353c58f1c22SToby Isaac Input Parameters: 5354c58f1c22SToby Isaac + dm - The DM object 5355c58f1c22SToby Isaac . name - The label name 5356c58f1c22SToby Isaac - value - The stratum value 5357c58f1c22SToby Isaac 5358c58f1c22SToby Isaac Output Parameter: 5359c58f1c22SToby Isaac . size - The stratum size 5360c58f1c22SToby Isaac 5361c58f1c22SToby Isaac Level: beginner 5362c58f1c22SToby Isaac 5363c58f1c22SToby Isaac .keywords: mesh 5364c58f1c22SToby Isaac .seealso: DMLabelGetStratumSize(), DMGetLabelSize(), DMGetLabelIds() 5365c58f1c22SToby Isaac @*/ 5366c58f1c22SToby Isaac PetscErrorCode DMGetStratumSize(DM dm, const char name[], PetscInt value, PetscInt *size) 5367c58f1c22SToby Isaac { 5368c58f1c22SToby Isaac DMLabel label; 5369c58f1c22SToby Isaac PetscErrorCode ierr; 5370c58f1c22SToby Isaac 5371c58f1c22SToby Isaac PetscFunctionBegin; 5372c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5373c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5374c58f1c22SToby Isaac PetscValidPointer(size, 4); 5375c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5376c58f1c22SToby Isaac *size = 0; 5377c58f1c22SToby Isaac if (!label) PetscFunctionReturn(0); 5378c58f1c22SToby Isaac ierr = DMLabelGetStratumSize(label, value, size);CHKERRQ(ierr); 5379c58f1c22SToby Isaac PetscFunctionReturn(0); 5380c58f1c22SToby Isaac } 5381c58f1c22SToby Isaac 5382c58f1c22SToby Isaac #undef __FUNCT__ 5383c58f1c22SToby Isaac #define __FUNCT__ "DMGetStratumIS" 5384c58f1c22SToby Isaac /*@C 5385c58f1c22SToby Isaac DMGetStratumIS - Get the points in a label stratum 5386c58f1c22SToby Isaac 5387c58f1c22SToby Isaac Not Collective 5388c58f1c22SToby Isaac 5389c58f1c22SToby Isaac Input Parameters: 5390c58f1c22SToby Isaac + dm - The DM object 5391c58f1c22SToby Isaac . name - The label name 5392c58f1c22SToby Isaac - value - The stratum value 5393c58f1c22SToby Isaac 5394c58f1c22SToby Isaac Output Parameter: 5395c58f1c22SToby Isaac . points - The stratum points, or NULL if the label does not exist or does not have that value 5396c58f1c22SToby Isaac 5397c58f1c22SToby Isaac Level: beginner 5398c58f1c22SToby Isaac 5399c58f1c22SToby Isaac .keywords: mesh 5400c58f1c22SToby Isaac .seealso: DMLabelGetStratumIS(), DMGetStratumSize() 5401c58f1c22SToby Isaac @*/ 5402c58f1c22SToby Isaac PetscErrorCode DMGetStratumIS(DM dm, const char name[], PetscInt value, IS *points) 5403c58f1c22SToby Isaac { 5404c58f1c22SToby Isaac DMLabel label; 5405c58f1c22SToby Isaac PetscErrorCode ierr; 5406c58f1c22SToby Isaac 5407c58f1c22SToby Isaac PetscFunctionBegin; 5408c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5409c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5410c58f1c22SToby Isaac PetscValidPointer(points, 4); 5411c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5412c58f1c22SToby Isaac *points = NULL; 5413c58f1c22SToby Isaac if (!label) PetscFunctionReturn(0); 5414c58f1c22SToby Isaac ierr = DMLabelGetStratumIS(label, value, points);CHKERRQ(ierr); 5415c58f1c22SToby Isaac PetscFunctionReturn(0); 5416c58f1c22SToby Isaac } 5417c58f1c22SToby Isaac 5418c58f1c22SToby Isaac #undef __FUNCT__ 5419c58f1c22SToby Isaac #define __FUNCT__ "DMClearLabelStratum" 5420c58f1c22SToby Isaac /*@C 5421c58f1c22SToby Isaac DMClearLabelStratum - Remove all points from a stratum from a Sieve Label 5422c58f1c22SToby Isaac 5423c58f1c22SToby Isaac Not Collective 5424c58f1c22SToby Isaac 5425c58f1c22SToby Isaac Input Parameters: 5426c58f1c22SToby Isaac + dm - The DM object 5427c58f1c22SToby Isaac . name - The label name 5428c58f1c22SToby Isaac - value - The label value for this point 5429c58f1c22SToby Isaac 5430c58f1c22SToby Isaac Output Parameter: 5431c58f1c22SToby Isaac 5432c58f1c22SToby Isaac Level: beginner 5433c58f1c22SToby Isaac 5434c58f1c22SToby Isaac .keywords: mesh 5435c58f1c22SToby Isaac .seealso: DMLabelClearStratum(), DMSetLabelValue(), DMGetStratumIS(), DMClearLabelValue() 5436c58f1c22SToby Isaac @*/ 5437c58f1c22SToby Isaac PetscErrorCode DMClearLabelStratum(DM dm, const char name[], PetscInt value) 5438c58f1c22SToby Isaac { 5439c58f1c22SToby Isaac DMLabel label; 5440c58f1c22SToby Isaac PetscErrorCode ierr; 5441c58f1c22SToby Isaac 5442c58f1c22SToby Isaac PetscFunctionBegin; 5443c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5444c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5445c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5446c58f1c22SToby Isaac if (!label) PetscFunctionReturn(0); 5447c58f1c22SToby Isaac ierr = DMLabelClearStratum(label, value);CHKERRQ(ierr); 5448c58f1c22SToby Isaac PetscFunctionReturn(0); 5449c58f1c22SToby Isaac } 5450c58f1c22SToby Isaac 5451c58f1c22SToby Isaac #undef __FUNCT__ 5452c58f1c22SToby Isaac #define __FUNCT__ "DMGetNumLabels" 5453c58f1c22SToby Isaac /*@ 5454c58f1c22SToby Isaac DMGetNumLabels - Return the number of labels defined by the mesh 5455c58f1c22SToby Isaac 5456c58f1c22SToby Isaac Not Collective 5457c58f1c22SToby Isaac 5458c58f1c22SToby Isaac Input Parameter: 5459c58f1c22SToby Isaac . dm - The DM object 5460c58f1c22SToby Isaac 5461c58f1c22SToby Isaac Output Parameter: 5462c58f1c22SToby Isaac . numLabels - the number of Labels 5463c58f1c22SToby Isaac 5464c58f1c22SToby Isaac Level: intermediate 5465c58f1c22SToby Isaac 5466c58f1c22SToby Isaac .keywords: mesh 5467c58f1c22SToby Isaac .seealso: DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5468c58f1c22SToby Isaac @*/ 5469c58f1c22SToby Isaac PetscErrorCode DMGetNumLabels(DM dm, PetscInt *numLabels) 5470c58f1c22SToby Isaac { 5471c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5472c58f1c22SToby Isaac PetscInt n = 0; 5473c58f1c22SToby Isaac 5474c58f1c22SToby Isaac PetscFunctionBegin; 5475c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5476c58f1c22SToby Isaac PetscValidPointer(numLabels, 2); 5477c58f1c22SToby Isaac while (next) {++n; next = next->next;} 5478c58f1c22SToby Isaac *numLabels = n; 5479c58f1c22SToby Isaac PetscFunctionReturn(0); 5480c58f1c22SToby Isaac } 5481c58f1c22SToby Isaac 5482c58f1c22SToby Isaac #undef __FUNCT__ 5483c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabelName" 5484c58f1c22SToby Isaac /*@C 5485c58f1c22SToby Isaac DMGetLabelName - Return the name of nth label 5486c58f1c22SToby Isaac 5487c58f1c22SToby Isaac Not Collective 5488c58f1c22SToby Isaac 5489c58f1c22SToby Isaac Input Parameters: 5490c58f1c22SToby Isaac + dm - The DM object 5491c58f1c22SToby Isaac - n - the label number 5492c58f1c22SToby Isaac 5493c58f1c22SToby Isaac Output Parameter: 5494c58f1c22SToby Isaac . name - the label name 5495c58f1c22SToby Isaac 5496c58f1c22SToby Isaac Level: intermediate 5497c58f1c22SToby Isaac 5498c58f1c22SToby Isaac .keywords: mesh 5499c58f1c22SToby Isaac .seealso: DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5500c58f1c22SToby Isaac @*/ 5501c58f1c22SToby Isaac PetscErrorCode DMGetLabelName(DM dm, PetscInt n, const char **name) 5502c58f1c22SToby Isaac { 5503c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5504c58f1c22SToby Isaac PetscInt l = 0; 5505c58f1c22SToby Isaac 5506c58f1c22SToby Isaac PetscFunctionBegin; 5507c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5508c58f1c22SToby Isaac PetscValidPointer(name, 3); 5509c58f1c22SToby Isaac while (next) { 5510c58f1c22SToby Isaac if (l == n) { 5511c58f1c22SToby Isaac *name = next->label->name; 5512c58f1c22SToby Isaac PetscFunctionReturn(0); 5513c58f1c22SToby Isaac } 5514c58f1c22SToby Isaac ++l; 5515c58f1c22SToby Isaac next = next->next; 5516c58f1c22SToby Isaac } 5517c58f1c22SToby Isaac SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Label %D does not exist in this DM", n); 5518c58f1c22SToby Isaac } 5519c58f1c22SToby Isaac 5520c58f1c22SToby Isaac #undef __FUNCT__ 5521c58f1c22SToby Isaac #define __FUNCT__ "DMHasLabel" 5522c58f1c22SToby Isaac /*@C 5523c58f1c22SToby Isaac DMHasLabel - Determine whether the mesh has a label of a given name 5524c58f1c22SToby Isaac 5525c58f1c22SToby Isaac Not Collective 5526c58f1c22SToby Isaac 5527c58f1c22SToby Isaac Input Parameters: 5528c58f1c22SToby Isaac + dm - The DM object 5529c58f1c22SToby Isaac - name - The label name 5530c58f1c22SToby Isaac 5531c58f1c22SToby Isaac Output Parameter: 5532c58f1c22SToby Isaac . hasLabel - PETSC_TRUE if the label is present 5533c58f1c22SToby Isaac 5534c58f1c22SToby Isaac Level: intermediate 5535c58f1c22SToby Isaac 5536c58f1c22SToby Isaac .keywords: mesh 5537c58f1c22SToby Isaac .seealso: DMCreateLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5538c58f1c22SToby Isaac @*/ 5539c58f1c22SToby Isaac PetscErrorCode DMHasLabel(DM dm, const char name[], PetscBool *hasLabel) 5540c58f1c22SToby Isaac { 5541c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5542c58f1c22SToby Isaac PetscErrorCode ierr; 5543c58f1c22SToby Isaac 5544c58f1c22SToby Isaac PetscFunctionBegin; 5545c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5546c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5547c58f1c22SToby Isaac PetscValidPointer(hasLabel, 3); 5548c58f1c22SToby Isaac *hasLabel = PETSC_FALSE; 5549c58f1c22SToby Isaac while (next) { 5550c58f1c22SToby Isaac ierr = PetscStrcmp(name, next->label->name, hasLabel);CHKERRQ(ierr); 5551c58f1c22SToby Isaac if (*hasLabel) break; 5552c58f1c22SToby Isaac next = next->next; 5553c58f1c22SToby Isaac } 5554c58f1c22SToby Isaac PetscFunctionReturn(0); 5555c58f1c22SToby Isaac } 5556c58f1c22SToby Isaac 5557c58f1c22SToby Isaac #undef __FUNCT__ 5558c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabel" 5559c58f1c22SToby Isaac /*@C 5560c58f1c22SToby Isaac DMGetLabel - Return the label of a given name, or NULL 5561c58f1c22SToby Isaac 5562c58f1c22SToby Isaac Not Collective 5563c58f1c22SToby Isaac 5564c58f1c22SToby Isaac Input Parameters: 5565c58f1c22SToby Isaac + dm - The DM object 5566c58f1c22SToby Isaac - name - The label name 5567c58f1c22SToby Isaac 5568c58f1c22SToby Isaac Output Parameter: 5569c58f1c22SToby Isaac . label - The DMLabel, or NULL if the label is absent 5570c58f1c22SToby Isaac 5571c58f1c22SToby Isaac Level: intermediate 5572c58f1c22SToby Isaac 5573c58f1c22SToby Isaac .keywords: mesh 5574c58f1c22SToby Isaac .seealso: DMCreateLabel(), DMHasLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5575c58f1c22SToby Isaac @*/ 5576c58f1c22SToby Isaac PetscErrorCode DMGetLabel(DM dm, const char name[], DMLabel *label) 5577c58f1c22SToby Isaac { 5578c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5579c58f1c22SToby Isaac PetscBool hasLabel; 5580c58f1c22SToby Isaac PetscErrorCode ierr; 5581c58f1c22SToby Isaac 5582c58f1c22SToby Isaac PetscFunctionBegin; 5583c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5584c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5585c58f1c22SToby Isaac PetscValidPointer(label, 3); 5586c58f1c22SToby Isaac *label = NULL; 5587c58f1c22SToby Isaac while (next) { 5588c58f1c22SToby Isaac ierr = PetscStrcmp(name, next->label->name, &hasLabel);CHKERRQ(ierr); 5589c58f1c22SToby Isaac if (hasLabel) { 5590c58f1c22SToby Isaac *label = next->label; 5591c58f1c22SToby Isaac break; 5592c58f1c22SToby Isaac } 5593c58f1c22SToby Isaac next = next->next; 5594c58f1c22SToby Isaac } 5595c58f1c22SToby Isaac PetscFunctionReturn(0); 5596c58f1c22SToby Isaac } 5597c58f1c22SToby Isaac 5598c58f1c22SToby Isaac #undef __FUNCT__ 5599c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabelByNum" 5600c58f1c22SToby Isaac /*@C 5601c58f1c22SToby Isaac DMGetLabelByNum - Return the nth label 5602c58f1c22SToby Isaac 5603c58f1c22SToby Isaac Not Collective 5604c58f1c22SToby Isaac 5605c58f1c22SToby Isaac Input Parameters: 5606c58f1c22SToby Isaac + dm - The DM object 5607c58f1c22SToby Isaac - n - the label number 5608c58f1c22SToby Isaac 5609c58f1c22SToby Isaac Output Parameter: 5610c58f1c22SToby Isaac . label - the label 5611c58f1c22SToby Isaac 5612c58f1c22SToby Isaac Level: intermediate 5613c58f1c22SToby Isaac 5614c58f1c22SToby Isaac .keywords: mesh 5615c58f1c22SToby Isaac .seealso: DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5616c58f1c22SToby Isaac @*/ 5617c58f1c22SToby Isaac PetscErrorCode DMGetLabelByNum(DM dm, PetscInt n, DMLabel *label) 5618c58f1c22SToby Isaac { 5619c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5620c58f1c22SToby Isaac PetscInt l = 0; 5621c58f1c22SToby Isaac 5622c58f1c22SToby Isaac PetscFunctionBegin; 5623c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5624c58f1c22SToby Isaac PetscValidPointer(label, 3); 5625c58f1c22SToby Isaac while (next) { 5626c58f1c22SToby Isaac if (l == n) { 5627c58f1c22SToby Isaac *label = next->label; 5628c58f1c22SToby Isaac PetscFunctionReturn(0); 5629c58f1c22SToby Isaac } 5630c58f1c22SToby Isaac ++l; 5631c58f1c22SToby Isaac next = next->next; 5632c58f1c22SToby Isaac } 5633c58f1c22SToby Isaac SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Label %D does not exist in this DM", n); 5634c58f1c22SToby Isaac } 5635c58f1c22SToby Isaac 5636c58f1c22SToby Isaac #undef __FUNCT__ 5637c58f1c22SToby Isaac #define __FUNCT__ "DMAddLabel" 5638c58f1c22SToby Isaac /*@C 5639c58f1c22SToby Isaac DMAddLabel - Add the label to this mesh 5640c58f1c22SToby Isaac 5641c58f1c22SToby Isaac Not Collective 5642c58f1c22SToby Isaac 5643c58f1c22SToby Isaac Input Parameters: 5644c58f1c22SToby Isaac + dm - The DM object 5645c58f1c22SToby Isaac - label - The DMLabel 5646c58f1c22SToby Isaac 5647c58f1c22SToby Isaac Level: developer 5648c58f1c22SToby Isaac 5649c58f1c22SToby Isaac .keywords: mesh 5650c58f1c22SToby Isaac .seealso: DMCreateLabel(), DMHasLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5651c58f1c22SToby Isaac @*/ 5652c58f1c22SToby Isaac PetscErrorCode DMAddLabel(DM dm, DMLabel label) 5653c58f1c22SToby Isaac { 5654c58f1c22SToby Isaac DMLabelLink tmpLabel; 5655c58f1c22SToby Isaac PetscBool hasLabel; 5656c58f1c22SToby Isaac PetscErrorCode ierr; 5657c58f1c22SToby Isaac 5658c58f1c22SToby Isaac PetscFunctionBegin; 5659c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5660c58f1c22SToby Isaac ierr = DMHasLabel(dm, label->name, &hasLabel);CHKERRQ(ierr); 5661c58f1c22SToby Isaac if (hasLabel) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Label %s already exists in this DM", label->name); 5662c58f1c22SToby Isaac ierr = PetscCalloc1(1, &tmpLabel);CHKERRQ(ierr); 5663c58f1c22SToby Isaac tmpLabel->label = label; 5664c58f1c22SToby Isaac tmpLabel->output = PETSC_TRUE; 5665c58f1c22SToby Isaac tmpLabel->next = dm->labels->next; 5666c58f1c22SToby Isaac dm->labels->next = tmpLabel; 5667c58f1c22SToby Isaac PetscFunctionReturn(0); 5668c58f1c22SToby Isaac } 5669c58f1c22SToby Isaac 5670c58f1c22SToby Isaac #undef __FUNCT__ 5671c58f1c22SToby Isaac #define __FUNCT__ "DMRemoveLabel" 5672c58f1c22SToby Isaac /*@C 5673c58f1c22SToby Isaac DMRemoveLabel - Remove the label from this mesh 5674c58f1c22SToby Isaac 5675c58f1c22SToby Isaac Not Collective 5676c58f1c22SToby Isaac 5677c58f1c22SToby Isaac Input Parameters: 5678c58f1c22SToby Isaac + dm - The DM object 5679c58f1c22SToby Isaac - name - The label name 5680c58f1c22SToby Isaac 5681c58f1c22SToby Isaac Output Parameter: 5682c58f1c22SToby Isaac . label - The DMLabel, or NULL if the label is absent 5683c58f1c22SToby Isaac 5684c58f1c22SToby Isaac Level: developer 5685c58f1c22SToby Isaac 5686c58f1c22SToby Isaac .keywords: mesh 5687c58f1c22SToby Isaac .seealso: DMCreateLabel(), DMHasLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5688c58f1c22SToby Isaac @*/ 5689c58f1c22SToby Isaac PetscErrorCode DMRemoveLabel(DM dm, const char name[], DMLabel *label) 5690c58f1c22SToby Isaac { 5691c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5692c58f1c22SToby Isaac DMLabelLink last = NULL; 5693c58f1c22SToby Isaac PetscBool hasLabel; 5694c58f1c22SToby Isaac PetscErrorCode ierr; 5695c58f1c22SToby Isaac 5696c58f1c22SToby Isaac PetscFunctionBegin; 5697c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5698c58f1c22SToby Isaac ierr = DMHasLabel(dm, name, &hasLabel);CHKERRQ(ierr); 5699c58f1c22SToby Isaac *label = NULL; 5700c58f1c22SToby Isaac if (!hasLabel) PetscFunctionReturn(0); 5701c58f1c22SToby Isaac while (next) { 5702c58f1c22SToby Isaac ierr = PetscStrcmp(name, next->label->name, &hasLabel);CHKERRQ(ierr); 5703c58f1c22SToby Isaac if (hasLabel) { 5704c58f1c22SToby Isaac if (last) last->next = next->next; 5705c58f1c22SToby Isaac else dm->labels->next = next->next; 5706c58f1c22SToby Isaac next->next = NULL; 5707c58f1c22SToby Isaac *label = next->label; 5708c58f1c22SToby Isaac ierr = PetscStrcmp(name, "depth", &hasLabel);CHKERRQ(ierr); 5709c58f1c22SToby Isaac if (hasLabel) { 5710c58f1c22SToby Isaac dm->depthLabel = NULL; 5711c58f1c22SToby Isaac } 5712c58f1c22SToby Isaac ierr = PetscFree(next);CHKERRQ(ierr); 5713c58f1c22SToby Isaac break; 5714c58f1c22SToby Isaac } 5715c58f1c22SToby Isaac last = next; 5716c58f1c22SToby Isaac next = next->next; 5717c58f1c22SToby Isaac } 5718c58f1c22SToby Isaac PetscFunctionReturn(0); 5719c58f1c22SToby Isaac } 5720c58f1c22SToby Isaac 5721c58f1c22SToby Isaac #undef __FUNCT__ 5722c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabelOutput" 5723c58f1c22SToby Isaac /*@C 5724c58f1c22SToby Isaac DMGetLabelOutput - Get the output flag for a given label 5725c58f1c22SToby Isaac 5726c58f1c22SToby Isaac Not Collective 5727c58f1c22SToby Isaac 5728c58f1c22SToby Isaac Input Parameters: 5729c58f1c22SToby Isaac + dm - The DM object 5730c58f1c22SToby Isaac - name - The label name 5731c58f1c22SToby Isaac 5732c58f1c22SToby Isaac Output Parameter: 5733c58f1c22SToby Isaac . output - The flag for output 5734c58f1c22SToby Isaac 5735c58f1c22SToby Isaac Level: developer 5736c58f1c22SToby Isaac 5737c58f1c22SToby Isaac .keywords: mesh 5738c58f1c22SToby Isaac .seealso: DMSetLabelOutput(), DMCreateLabel(), DMHasLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5739c58f1c22SToby Isaac @*/ 5740c58f1c22SToby Isaac PetscErrorCode DMGetLabelOutput(DM dm, const char name[], PetscBool *output) 5741c58f1c22SToby Isaac { 5742c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5743c58f1c22SToby Isaac PetscErrorCode ierr; 5744c58f1c22SToby Isaac 5745c58f1c22SToby Isaac PetscFunctionBegin; 5746c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5747c58f1c22SToby Isaac PetscValidPointer(name, 2); 5748c58f1c22SToby Isaac PetscValidPointer(output, 3); 5749c58f1c22SToby Isaac while (next) { 5750c58f1c22SToby Isaac PetscBool flg; 5751c58f1c22SToby Isaac 5752c58f1c22SToby Isaac ierr = PetscStrcmp(name, next->label->name, &flg);CHKERRQ(ierr); 5753c58f1c22SToby Isaac if (flg) {*output = next->output; PetscFunctionReturn(0);} 5754c58f1c22SToby Isaac next = next->next; 5755c58f1c22SToby Isaac } 5756c58f1c22SToby Isaac SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "No label named %s was present in this dm", name); 5757c58f1c22SToby Isaac } 5758c58f1c22SToby Isaac 5759c58f1c22SToby Isaac #undef __FUNCT__ 5760c58f1c22SToby Isaac #define __FUNCT__ "DMSetLabelOutput" 5761c58f1c22SToby Isaac /*@C 5762c58f1c22SToby Isaac DMSetLabelOutput - Set the output flag for a given label 5763c58f1c22SToby Isaac 5764c58f1c22SToby Isaac Not Collective 5765c58f1c22SToby Isaac 5766c58f1c22SToby Isaac Input Parameters: 5767c58f1c22SToby Isaac + dm - The DM object 5768c58f1c22SToby Isaac . name - The label name 5769c58f1c22SToby Isaac - output - The flag for output 5770c58f1c22SToby Isaac 5771c58f1c22SToby Isaac Level: developer 5772c58f1c22SToby Isaac 5773c58f1c22SToby Isaac .keywords: mesh 5774c58f1c22SToby Isaac .seealso: DMGetLabelOutput(), DMCreateLabel(), DMHasLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5775c58f1c22SToby Isaac @*/ 5776c58f1c22SToby Isaac PetscErrorCode DMSetLabelOutput(DM dm, const char name[], PetscBool output) 5777c58f1c22SToby Isaac { 5778c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5779c58f1c22SToby Isaac PetscErrorCode ierr; 5780c58f1c22SToby Isaac 5781c58f1c22SToby Isaac PetscFunctionBegin; 5782c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5783c58f1c22SToby Isaac PetscValidPointer(name, 2); 5784c58f1c22SToby Isaac while (next) { 5785c58f1c22SToby Isaac PetscBool flg; 5786c58f1c22SToby Isaac 5787c58f1c22SToby Isaac ierr = PetscStrcmp(name, next->label->name, &flg);CHKERRQ(ierr); 5788c58f1c22SToby Isaac if (flg) {next->output = output; PetscFunctionReturn(0);} 5789c58f1c22SToby Isaac next = next->next; 5790c58f1c22SToby Isaac } 5791c58f1c22SToby Isaac SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "No label named %s was present in this dm", name); 5792c58f1c22SToby Isaac } 5793c58f1c22SToby Isaac 5794c58f1c22SToby Isaac 5795c58f1c22SToby Isaac #undef __FUNCT__ 5796c58f1c22SToby Isaac #define __FUNCT__ "DMCopyLabels" 5797c58f1c22SToby Isaac /*@ 5798c58f1c22SToby Isaac DMCopyLabels - Copy labels from one mesh to another with a superset of the points 5799c58f1c22SToby Isaac 5800c58f1c22SToby Isaac Collective on DM 5801c58f1c22SToby Isaac 5802c58f1c22SToby Isaac Input Parameter: 58032e17dfb7SMatthew G. Knepley . dmA - The DM object with initial labels 5804c58f1c22SToby Isaac 5805c58f1c22SToby Isaac Output Parameter: 58062e17dfb7SMatthew G. Knepley . dmB - The DM object with copied labels 5807c58f1c22SToby Isaac 5808c58f1c22SToby Isaac Level: intermediate 5809c58f1c22SToby Isaac 5810c58f1c22SToby Isaac Note: This is typically used when interpolating or otherwise adding to a mesh 5811c58f1c22SToby Isaac 5812c58f1c22SToby Isaac .keywords: mesh 5813c58f1c22SToby Isaac .seealso: DMCopyCoordinates(), DMGetCoordinates(), DMGetCoordinatesLocal(), DMGetCoordinateDM(), DMGetCoordinateSection() 5814c58f1c22SToby Isaac @*/ 5815c58f1c22SToby Isaac PetscErrorCode DMCopyLabels(DM dmA, DM dmB) 5816c58f1c22SToby Isaac { 5817c58f1c22SToby Isaac PetscInt numLabels, l; 5818c58f1c22SToby Isaac PetscErrorCode ierr; 5819c58f1c22SToby Isaac 5820c58f1c22SToby Isaac PetscFunctionBegin; 5821c58f1c22SToby Isaac if (dmA == dmB) PetscFunctionReturn(0); 5822c58f1c22SToby Isaac ierr = DMGetNumLabels(dmA, &numLabels);CHKERRQ(ierr); 5823c58f1c22SToby Isaac for (l = 0; l < numLabels; ++l) { 5824c58f1c22SToby Isaac DMLabel label, labelNew; 5825c58f1c22SToby Isaac const char *name; 5826c58f1c22SToby Isaac PetscBool flg; 5827c58f1c22SToby Isaac 5828c58f1c22SToby Isaac ierr = DMGetLabelName(dmA, l, &name);CHKERRQ(ierr); 5829c58f1c22SToby Isaac ierr = PetscStrcmp(name, "depth", &flg);CHKERRQ(ierr); 5830c58f1c22SToby Isaac if (flg) continue; 5831c58f1c22SToby Isaac ierr = DMGetLabel(dmA, name, &label);CHKERRQ(ierr); 5832c58f1c22SToby Isaac ierr = DMLabelDuplicate(label, &labelNew);CHKERRQ(ierr); 5833c58f1c22SToby Isaac ierr = DMAddLabel(dmB, labelNew);CHKERRQ(ierr); 5834c58f1c22SToby Isaac } 5835c58f1c22SToby Isaac PetscFunctionReturn(0); 5836c58f1c22SToby Isaac } 5837a8fb8f29SToby Isaac 5838a8fb8f29SToby Isaac #undef __FUNCT__ 5839a8fb8f29SToby Isaac #define __FUNCT__ "DMGetCoarseDM" 5840a8fb8f29SToby Isaac /*@ 5841a8fb8f29SToby Isaac DMGetCoarseDM - Get the coarse mesh from which this was obtained by refinement 5842a8fb8f29SToby Isaac 5843a8fb8f29SToby Isaac Input Parameter: 5844a8fb8f29SToby Isaac . dm - The DM object 5845a8fb8f29SToby Isaac 5846a8fb8f29SToby Isaac Output Parameter: 5847a8fb8f29SToby Isaac . cdm - The coarse DM 5848a8fb8f29SToby Isaac 5849a8fb8f29SToby Isaac Level: intermediate 5850a8fb8f29SToby Isaac 5851a8fb8f29SToby Isaac .seealso: DMSetCoarseDM() 5852a8fb8f29SToby Isaac @*/ 5853a8fb8f29SToby Isaac PetscErrorCode DMGetCoarseDM(DM dm, DM *cdm) 5854a8fb8f29SToby Isaac { 5855a8fb8f29SToby Isaac PetscFunctionBegin; 5856a8fb8f29SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5857a8fb8f29SToby Isaac PetscValidPointer(cdm, 2); 5858a8fb8f29SToby Isaac *cdm = dm->coarseMesh; 5859a8fb8f29SToby Isaac PetscFunctionReturn(0); 5860a8fb8f29SToby Isaac } 5861a8fb8f29SToby Isaac 5862a8fb8f29SToby Isaac #undef __FUNCT__ 5863a8fb8f29SToby Isaac #define __FUNCT__ "DMSetCoarseDM" 5864a8fb8f29SToby Isaac /*@ 5865a8fb8f29SToby Isaac DMSetCoarseDM - Set the coarse mesh from which this was obtained by refinement 5866a8fb8f29SToby Isaac 5867a8fb8f29SToby Isaac Input Parameters: 5868a8fb8f29SToby Isaac + dm - The DM object 5869a8fb8f29SToby Isaac - cdm - The coarse DM 5870a8fb8f29SToby Isaac 5871a8fb8f29SToby Isaac Level: intermediate 5872a8fb8f29SToby Isaac 5873a8fb8f29SToby Isaac .seealso: DMGetCoarseDM() 5874a8fb8f29SToby Isaac @*/ 5875a8fb8f29SToby Isaac PetscErrorCode DMSetCoarseDM(DM dm, DM cdm) 5876a8fb8f29SToby Isaac { 5877a8fb8f29SToby Isaac PetscErrorCode ierr; 5878a8fb8f29SToby Isaac 5879a8fb8f29SToby Isaac PetscFunctionBegin; 5880a8fb8f29SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5881a8fb8f29SToby Isaac if (cdm) PetscValidHeaderSpecific(cdm, DM_CLASSID, 2); 5882a8fb8f29SToby Isaac ierr = PetscObjectReference((PetscObject)cdm);CHKERRQ(ierr); 5883a8fb8f29SToby Isaac ierr = DMDestroy(&dm->coarseMesh);CHKERRQ(ierr); 5884a8fb8f29SToby Isaac dm->coarseMesh = cdm; 5885a8fb8f29SToby Isaac PetscFunctionReturn(0); 5886a8fb8f29SToby Isaac } 5887a8fb8f29SToby Isaac 588888bdff64SToby Isaac #undef __FUNCT__ 588988bdff64SToby Isaac #define __FUNCT__ "DMGetFineDM" 589088bdff64SToby Isaac /*@ 589188bdff64SToby Isaac DMGetFineDM - Get the fine mesh from which this was obtained by refinement 589288bdff64SToby Isaac 589388bdff64SToby Isaac Input Parameter: 589488bdff64SToby Isaac . dm - The DM object 589588bdff64SToby Isaac 589688bdff64SToby Isaac Output Parameter: 589788bdff64SToby Isaac . fdm - The fine DM 589888bdff64SToby Isaac 589988bdff64SToby Isaac Level: intermediate 590088bdff64SToby Isaac 590188bdff64SToby Isaac .seealso: DMSetFineDM() 590288bdff64SToby Isaac @*/ 590388bdff64SToby Isaac PetscErrorCode DMGetFineDM(DM dm, DM *fdm) 590488bdff64SToby Isaac { 590588bdff64SToby Isaac PetscFunctionBegin; 590688bdff64SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 590788bdff64SToby Isaac PetscValidPointer(fdm, 2); 590888bdff64SToby Isaac *fdm = dm->fineMesh; 590988bdff64SToby Isaac PetscFunctionReturn(0); 591088bdff64SToby Isaac } 591188bdff64SToby Isaac 591288bdff64SToby Isaac #undef __FUNCT__ 591388bdff64SToby Isaac #define __FUNCT__ "DMSetFineDM" 591488bdff64SToby Isaac /*@ 591588bdff64SToby Isaac DMSetFineDM - Set the fine mesh from which this was obtained by refinement 591688bdff64SToby Isaac 591788bdff64SToby Isaac Input Parameters: 591888bdff64SToby Isaac + dm - The DM object 591988bdff64SToby Isaac - fdm - The fine DM 592088bdff64SToby Isaac 592188bdff64SToby Isaac Level: intermediate 592288bdff64SToby Isaac 592388bdff64SToby Isaac .seealso: DMGetFineDM() 592488bdff64SToby Isaac @*/ 592588bdff64SToby Isaac PetscErrorCode DMSetFineDM(DM dm, DM fdm) 592688bdff64SToby Isaac { 592788bdff64SToby Isaac PetscErrorCode ierr; 592888bdff64SToby Isaac 592988bdff64SToby Isaac PetscFunctionBegin; 593088bdff64SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 593188bdff64SToby Isaac if (fdm) PetscValidHeaderSpecific(fdm, DM_CLASSID, 2); 593288bdff64SToby Isaac ierr = PetscObjectReference((PetscObject)fdm);CHKERRQ(ierr); 593388bdff64SToby Isaac ierr = DMDestroy(&dm->fineMesh);CHKERRQ(ierr); 593488bdff64SToby Isaac dm->fineMesh = fdm; 593588bdff64SToby Isaac PetscFunctionReturn(0); 593688bdff64SToby Isaac } 593788bdff64SToby Isaac 5938a6ba4734SToby Isaac /*=== DMBoundary code ===*/ 5939a6ba4734SToby Isaac 5940a6ba4734SToby Isaac #undef __FUNCT__ 5941bcc5ffd9SToby Isaac #define __FUNCT__ "DMBoundaryDuplicate" 5942354557abSToby Isaac PetscErrorCode DMBoundaryDuplicate(DMBoundaryLinkList bd, DMBoundaryLinkList *boundary) 5943a6ba4734SToby Isaac { 5944bcc5ffd9SToby Isaac DMBoundary b = bd->next, b2, bold = NULL; 5945a6ba4734SToby Isaac PetscErrorCode ierr; 5946a6ba4734SToby Isaac 5947a6ba4734SToby Isaac PetscFunctionBegin; 5948bcc5ffd9SToby Isaac ierr = PetscNew(boundary);CHKERRQ(ierr); 5949bcc5ffd9SToby Isaac (*boundary)->refct = 1; 5950bcc5ffd9SToby Isaac (*boundary)->next = NULL; 5951a6ba4734SToby Isaac for (; b; b = b->next, bold = b2) { 5952a6ba4734SToby Isaac ierr = PetscNew(&b2);CHKERRQ(ierr); 5953a6ba4734SToby Isaac ierr = PetscStrallocpy(b->name, (char **) &b2->name);CHKERRQ(ierr); 5954a6ba4734SToby Isaac ierr = PetscStrallocpy(b->labelname, (char **) &b2->labelname);CHKERRQ(ierr); 5955a6ba4734SToby Isaac ierr = PetscMalloc1(b->numids, &b2->ids);CHKERRQ(ierr); 5956a6ba4734SToby Isaac ierr = PetscMemcpy(b2->ids, b->ids, b->numids*sizeof(PetscInt));CHKERRQ(ierr); 5957a6ba4734SToby Isaac ierr = PetscMalloc1(b->numcomps, &b2->comps);CHKERRQ(ierr); 5958a6ba4734SToby Isaac ierr = PetscMemcpy(b2->comps, b->comps, b->numcomps*sizeof(PetscInt));CHKERRQ(ierr); 5959a6ba4734SToby Isaac b2->label = NULL; 5960a6ba4734SToby Isaac b2->essential = b->essential; 5961a6ba4734SToby Isaac b2->field = b->field; 5962a6ba4734SToby Isaac b2->numcomps = b->numcomps; 5963a6ba4734SToby Isaac b2->func = b->func; 5964a6ba4734SToby Isaac b2->numids = b->numids; 5965a6ba4734SToby Isaac b2->ctx = b->ctx; 5966a6ba4734SToby Isaac b2->next = NULL; 5967bcc5ffd9SToby Isaac if (!(*boundary)->next) (*boundary)->next = b2; 5968a6ba4734SToby Isaac if (bold) bold->next = b2; 5969a6ba4734SToby Isaac } 5970a6ba4734SToby Isaac PetscFunctionReturn(0); 5971a6ba4734SToby Isaac } 5972a6ba4734SToby Isaac 5973a6ba4734SToby Isaac #undef __FUNCT__ 5974bcc5ffd9SToby Isaac #define __FUNCT__ "DMBoundaryDestroy" 5975bcc5ffd9SToby Isaac PetscErrorCode DMBoundaryDestroy(DMBoundaryLinkList *boundary) 5976a6ba4734SToby Isaac { 5977a6ba4734SToby Isaac DMBoundary b, next; 5978a6ba4734SToby Isaac PetscErrorCode ierr; 5979a6ba4734SToby Isaac 5980a6ba4734SToby Isaac PetscFunctionBegin; 5981a6ba4734SToby Isaac if (!boundary) PetscFunctionReturn(0); 5982bcc5ffd9SToby Isaac if (--((*boundary)->refct)) { 5983a6ba4734SToby Isaac *boundary = NULL; 5984bcc5ffd9SToby Isaac PetscFunctionReturn(0); 5985bcc5ffd9SToby Isaac } 5986bcc5ffd9SToby Isaac b = (*boundary)->next; 5987a6ba4734SToby Isaac for (; b; b = next) { 5988a6ba4734SToby Isaac next = b->next; 5989a6ba4734SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 5990a6ba4734SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 5991a6ba4734SToby Isaac ierr = PetscFree(b->name);CHKERRQ(ierr); 5992a6ba4734SToby Isaac ierr = PetscFree(b->labelname);CHKERRQ(ierr); 5993a6ba4734SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 5994a6ba4734SToby Isaac } 5995bcc5ffd9SToby Isaac ierr = PetscFree(*boundary);CHKERRQ(ierr); 5996a6ba4734SToby Isaac PetscFunctionReturn(0); 5997a6ba4734SToby Isaac } 5998a6ba4734SToby Isaac 5999a6ba4734SToby Isaac #undef __FUNCT__ 6000a6ba4734SToby Isaac #define __FUNCT__ "DMCopyBoundary" 6001a6ba4734SToby Isaac PetscErrorCode DMCopyBoundary(DM dm, DM dmNew) 6002a6ba4734SToby Isaac { 6003a6ba4734SToby Isaac PetscErrorCode ierr; 6004a6ba4734SToby Isaac 6005a6ba4734SToby Isaac PetscFunctionBegin; 6006bcc5ffd9SToby Isaac ierr = DMBoundaryDestroy(&dmNew->boundary);CHKERRQ(ierr); 6007bcc5ffd9SToby Isaac ierr = DMBoundaryDuplicate(dm->boundary, &dmNew->boundary);CHKERRQ(ierr); 6008a6ba4734SToby Isaac PetscFunctionReturn(0); 6009a6ba4734SToby Isaac } 6010a6ba4734SToby Isaac 6011a6ba4734SToby Isaac #undef __FUNCT__ 6012a6ba4734SToby Isaac #define __FUNCT__ "DMAddBoundary" 6013a6ba4734SToby Isaac /*@C 6014a6ba4734SToby Isaac DMAddBoundary - Add a boundary condition to the model 6015a6ba4734SToby Isaac 6016a6ba4734SToby Isaac Input Parameters: 6017a6ba4734SToby Isaac + dm - The mesh object 6018a6ba4734SToby Isaac . isEssential - Flag for an essential (Dirichlet) condition, as opposed to a natural (Neumann) condition 6019a6ba4734SToby Isaac . name - The BC name 6020a6ba4734SToby Isaac . labelname - The label defining constrained points 6021a6ba4734SToby Isaac . field - The field to constrain 6022a6ba4734SToby Isaac . numcomps - The number of constrained field components 6023a6ba4734SToby Isaac . comps - An array of constrained component numbers 6024a6ba4734SToby Isaac . bcFunc - A pointwise function giving boundary values 6025a6ba4734SToby Isaac . numids - The number of DMLabel ids for constrained points 6026a6ba4734SToby Isaac . ids - An array of ids for constrained points 6027a6ba4734SToby Isaac - ctx - An optional user context for bcFunc 6028a6ba4734SToby Isaac 6029a6ba4734SToby Isaac Options Database Keys: 6030a6ba4734SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 6031a6ba4734SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 6032a6ba4734SToby Isaac 6033a6ba4734SToby Isaac Level: developer 6034a6ba4734SToby Isaac 6035a6ba4734SToby Isaac .seealso: DMGetBoundary() 6036a6ba4734SToby Isaac @*/ 6037a6ba4734SToby Isaac PetscErrorCode DMAddBoundary(DM dm, PetscBool isEssential, const char name[], const char labelname[], PetscInt field, PetscInt numcomps, const PetscInt *comps, void (*bcFunc)(), PetscInt numids, const PetscInt *ids, void *ctx) 6038a6ba4734SToby Isaac { 6039a6ba4734SToby Isaac DMBoundary b; 6040a6ba4734SToby Isaac PetscErrorCode ierr; 6041a6ba4734SToby Isaac 6042a6ba4734SToby Isaac PetscFunctionBegin; 6043a6ba4734SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6044a6ba4734SToby Isaac ierr = PetscNew(&b);CHKERRQ(ierr); 6045a6ba4734SToby Isaac ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 6046a6ba4734SToby Isaac ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr); 6047a6ba4734SToby Isaac ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr); 6048a6ba4734SToby Isaac if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);} 6049a6ba4734SToby Isaac ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr); 6050a6ba4734SToby Isaac if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);} 6051a6ba4734SToby Isaac if (b->labelname) { 6052a6ba4734SToby Isaac } 6053a6ba4734SToby Isaac b->essential = isEssential; 6054a6ba4734SToby Isaac b->field = field; 6055a6ba4734SToby Isaac b->numcomps = numcomps; 6056a6ba4734SToby Isaac b->func = bcFunc; 6057a6ba4734SToby Isaac b->numids = numids; 6058a6ba4734SToby Isaac b->ctx = ctx; 6059bcc5ffd9SToby Isaac b->next = dm->boundary->next; 6060bcc5ffd9SToby Isaac dm->boundary->next = b; 6061a6ba4734SToby Isaac PetscFunctionReturn(0); 6062a6ba4734SToby Isaac } 6063a6ba4734SToby Isaac 6064a6ba4734SToby Isaac #undef __FUNCT__ 6065a6ba4734SToby Isaac #define __FUNCT__ "DMGetNumBoundary" 6066a6ba4734SToby Isaac /*@ 6067a6ba4734SToby Isaac DMGetNumBoundary - Get the number of registered BC 6068a6ba4734SToby Isaac 6069a6ba4734SToby Isaac Input Parameters: 6070a6ba4734SToby Isaac . dm - The mesh object 6071a6ba4734SToby Isaac 6072a6ba4734SToby Isaac Output Parameters: 6073a6ba4734SToby Isaac . numBd - The number of BC 6074a6ba4734SToby Isaac 6075a6ba4734SToby Isaac Level: intermediate 6076a6ba4734SToby Isaac 6077a6ba4734SToby Isaac .seealso: DMAddBoundary(), DMGetBoundary() 6078a6ba4734SToby Isaac @*/ 6079a6ba4734SToby Isaac PetscErrorCode DMGetNumBoundary(DM dm, PetscInt *numBd) 6080a6ba4734SToby Isaac { 6081bcc5ffd9SToby Isaac DMBoundary b = dm->boundary->next; 6082a6ba4734SToby Isaac 6083a6ba4734SToby Isaac PetscFunctionBegin; 6084a6ba4734SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6085a6ba4734SToby Isaac PetscValidPointer(numBd, 2); 6086a6ba4734SToby Isaac *numBd = 0; 6087a6ba4734SToby Isaac while (b) {++(*numBd); b = b->next;} 6088a6ba4734SToby Isaac PetscFunctionReturn(0); 6089a6ba4734SToby Isaac } 6090a6ba4734SToby Isaac 6091a6ba4734SToby Isaac #undef __FUNCT__ 6092a6ba4734SToby Isaac #define __FUNCT__ "DMGetBoundary" 6093a6ba4734SToby Isaac /*@C 6094a6ba4734SToby Isaac DMGetBoundary - Add a boundary condition to the model 6095a6ba4734SToby Isaac 6096a6ba4734SToby Isaac Input Parameters: 6097a6ba4734SToby Isaac + dm - The mesh object 6098a6ba4734SToby Isaac - bd - The BC number 6099a6ba4734SToby Isaac 6100a6ba4734SToby Isaac Output Parameters: 6101a6ba4734SToby Isaac + isEssential - Flag for an essential (Dirichlet) condition, as opposed to a natural (Neumann) condition 6102a6ba4734SToby Isaac . name - The BC name 6103a6ba4734SToby Isaac . labelname - The label defining constrained points 6104a6ba4734SToby Isaac . field - The field to constrain 6105a6ba4734SToby Isaac . numcomps - The number of constrained field components 6106a6ba4734SToby Isaac . comps - An array of constrained component numbers 6107a6ba4734SToby Isaac . bcFunc - A pointwise function giving boundary values 6108a6ba4734SToby Isaac . numids - The number of DMLabel ids for constrained points 6109a6ba4734SToby Isaac . ids - An array of ids for constrained points 6110a6ba4734SToby Isaac - ctx - An optional user context for bcFunc 6111a6ba4734SToby Isaac 6112a6ba4734SToby Isaac Options Database Keys: 6113a6ba4734SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 6114a6ba4734SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 6115a6ba4734SToby Isaac 6116a6ba4734SToby Isaac Level: developer 6117a6ba4734SToby Isaac 6118a6ba4734SToby Isaac .seealso: DMAddBoundary() 6119a6ba4734SToby Isaac @*/ 6120a6ba4734SToby Isaac PetscErrorCode DMGetBoundary(DM dm, PetscInt bd, PetscBool *isEssential, const char **name, const char **labelname, PetscInt *field, PetscInt *numcomps, const PetscInt **comps, void (**func)(), PetscInt *numids, const PetscInt **ids, void **ctx) 6121a6ba4734SToby Isaac { 6122bcc5ffd9SToby Isaac DMBoundary b = dm->boundary->next; 6123a6ba4734SToby Isaac PetscInt n = 0; 6124a6ba4734SToby Isaac 6125a6ba4734SToby Isaac PetscFunctionBegin; 6126a6ba4734SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6127a6ba4734SToby Isaac while (b) { 6128a6ba4734SToby Isaac if (n == bd) break; 6129a6ba4734SToby Isaac b = b->next; 6130a6ba4734SToby Isaac ++n; 6131a6ba4734SToby Isaac } 61329fc93327SToby Isaac if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 6133a6ba4734SToby Isaac if (isEssential) { 6134a6ba4734SToby Isaac PetscValidPointer(isEssential, 3); 6135a6ba4734SToby Isaac *isEssential = b->essential; 6136a6ba4734SToby Isaac } 6137a6ba4734SToby Isaac if (name) { 6138a6ba4734SToby Isaac PetscValidPointer(name, 4); 6139a6ba4734SToby Isaac *name = b->name; 6140a6ba4734SToby Isaac } 6141a6ba4734SToby Isaac if (labelname) { 6142a6ba4734SToby Isaac PetscValidPointer(labelname, 5); 6143a6ba4734SToby Isaac *labelname = b->labelname; 6144a6ba4734SToby Isaac } 6145a6ba4734SToby Isaac if (field) { 6146a6ba4734SToby Isaac PetscValidPointer(field, 6); 6147a6ba4734SToby Isaac *field = b->field; 6148a6ba4734SToby Isaac } 6149a6ba4734SToby Isaac if (numcomps) { 6150a6ba4734SToby Isaac PetscValidPointer(numcomps, 7); 6151a6ba4734SToby Isaac *numcomps = b->numcomps; 6152a6ba4734SToby Isaac } 6153a6ba4734SToby Isaac if (comps) { 6154a6ba4734SToby Isaac PetscValidPointer(comps, 8); 6155a6ba4734SToby Isaac *comps = b->comps; 6156a6ba4734SToby Isaac } 6157a6ba4734SToby Isaac if (func) { 6158a6ba4734SToby Isaac PetscValidPointer(func, 9); 6159a6ba4734SToby Isaac *func = b->func; 6160a6ba4734SToby Isaac } 6161a6ba4734SToby Isaac if (numids) { 6162a6ba4734SToby Isaac PetscValidPointer(numids, 10); 6163a6ba4734SToby Isaac *numids = b->numids; 6164a6ba4734SToby Isaac } 6165a6ba4734SToby Isaac if (ids) { 6166a6ba4734SToby Isaac PetscValidPointer(ids, 11); 6167a6ba4734SToby Isaac *ids = b->ids; 6168a6ba4734SToby Isaac } 6169a6ba4734SToby Isaac if (ctx) { 6170a6ba4734SToby Isaac PetscValidPointer(ctx, 12); 6171a6ba4734SToby Isaac *ctx = b->ctx; 6172a6ba4734SToby Isaac } 6173a6ba4734SToby Isaac PetscFunctionReturn(0); 6174a6ba4734SToby Isaac } 6175a6ba4734SToby Isaac 6176a6ba4734SToby Isaac #undef __FUNCT__ 6177a6ba4734SToby Isaac #define __FUNCT__ "DMIsBoundaryPoint" 6178a6ba4734SToby Isaac PetscErrorCode DMIsBoundaryPoint(DM dm, PetscInt point, PetscBool *isBd) 6179a6ba4734SToby Isaac { 6180bcc5ffd9SToby Isaac DMBoundary b = dm->boundary->next; 6181a6ba4734SToby Isaac PetscErrorCode ierr; 6182a6ba4734SToby Isaac 6183a6ba4734SToby Isaac PetscFunctionBegin; 6184a6ba4734SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6185a6ba4734SToby Isaac PetscValidPointer(isBd, 3); 6186a6ba4734SToby Isaac *isBd = PETSC_FALSE; 6187a6ba4734SToby Isaac while (b && !(*isBd)) { 6188bff67a9bSToby Isaac if (!b->label) {ierr = DMGetLabel(dm, b->labelname, &b->label);CHKERRQ(ierr);} 6189a6ba4734SToby Isaac if (b->label) { 6190a6ba4734SToby Isaac PetscInt i; 6191a6ba4734SToby Isaac 6192a6ba4734SToby Isaac for (i = 0; i < b->numids && !(*isBd); ++i) { 6193a6ba4734SToby Isaac ierr = DMLabelStratumHasPoint(b->label, b->ids[i], point, isBd);CHKERRQ(ierr); 6194a6ba4734SToby Isaac } 6195a6ba4734SToby Isaac } 6196a6ba4734SToby Isaac b = b->next; 6197a6ba4734SToby Isaac } 6198a6ba4734SToby Isaac PetscFunctionReturn(0); 6199a6ba4734SToby Isaac } 62004d6f44ffSToby Isaac 62014d6f44ffSToby Isaac #undef __FUNCT__ 62024d6f44ffSToby Isaac #define __FUNCT__ "DMProjectFunction" 62034d6f44ffSToby Isaac /*@C 62044d6f44ffSToby Isaac DMProjectFunction - This projects the given function into the function space provided. 62054d6f44ffSToby Isaac 62064d6f44ffSToby Isaac Input Parameters: 62074d6f44ffSToby Isaac + dm - The DM 62080709b2feSToby Isaac . time - The time 62094d6f44ffSToby Isaac . funcs - The coordinate functions to evaluate, one per field 62104d6f44ffSToby Isaac . ctxs - Optional array of contexts to pass to each coordinate function. ctxs itself may be null. 62114d6f44ffSToby Isaac - mode - The insertion mode for values 62124d6f44ffSToby Isaac 62134d6f44ffSToby Isaac Output Parameter: 62144d6f44ffSToby Isaac . X - vector 62154d6f44ffSToby Isaac 62164d6f44ffSToby Isaac Calling sequence of func: 62170709b2feSToby Isaac $ func(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nf, PetscScalar u[], void *ctx); 62184d6f44ffSToby Isaac 62194d6f44ffSToby Isaac + dim - The spatial dimension 62204d6f44ffSToby Isaac . x - The coordinates 62214d6f44ffSToby Isaac . Nf - The number of fields 62224d6f44ffSToby Isaac . u - The output field values 62234d6f44ffSToby Isaac - ctx - optional user-defined function context 62244d6f44ffSToby Isaac 62254d6f44ffSToby Isaac Level: developer 62264d6f44ffSToby Isaac 62272716604bSToby Isaac .seealso: DMComputeL2Diff() 62284d6f44ffSToby Isaac @*/ 62290709b2feSToby Isaac PetscErrorCode DMProjectFunction(DM dm, PetscReal time, PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void **ctxs, InsertMode mode, Vec X) 62304d6f44ffSToby Isaac { 62314d6f44ffSToby Isaac Vec localX; 62324d6f44ffSToby Isaac PetscErrorCode ierr; 62334d6f44ffSToby Isaac 62344d6f44ffSToby Isaac PetscFunctionBegin; 62354d6f44ffSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 62364d6f44ffSToby Isaac ierr = DMGetLocalVector(dm, &localX);CHKERRQ(ierr); 62370709b2feSToby Isaac ierr = DMProjectFunctionLocal(dm, time, funcs, ctxs, mode, localX);CHKERRQ(ierr); 62384d6f44ffSToby Isaac ierr = DMLocalToGlobalBegin(dm, localX, mode, X);CHKERRQ(ierr); 62394d6f44ffSToby Isaac ierr = DMLocalToGlobalEnd(dm, localX, mode, X);CHKERRQ(ierr); 62404d6f44ffSToby Isaac ierr = DMRestoreLocalVector(dm, &localX);CHKERRQ(ierr); 62414d6f44ffSToby Isaac PetscFunctionReturn(0); 62424d6f44ffSToby Isaac } 62434d6f44ffSToby Isaac 62444d6f44ffSToby Isaac #undef __FUNCT__ 62454d6f44ffSToby Isaac #define __FUNCT__ "DMProjectFunctionLocal" 62460709b2feSToby Isaac PetscErrorCode DMProjectFunctionLocal(DM dm, PetscReal time, PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void **ctxs, InsertMode mode, Vec localX) 62474d6f44ffSToby Isaac { 62484d6f44ffSToby Isaac PetscErrorCode ierr; 62494d6f44ffSToby Isaac 62504d6f44ffSToby Isaac PetscFunctionBegin; 62514d6f44ffSToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 62524d6f44ffSToby Isaac PetscValidHeaderSpecific(localX,VEC_CLASSID,5); 62534d6f44ffSToby Isaac if (!dm->ops->projectfunctionlocal) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM type %s does not implemnt DMProjectFunctionLocal",((PetscObject)dm)->type_name); 62540709b2feSToby Isaac ierr = (dm->ops->projectfunctionlocal) (dm, time, funcs, ctxs, mode, localX);CHKERRQ(ierr); 62554d6f44ffSToby Isaac PetscFunctionReturn(0); 62564d6f44ffSToby Isaac } 62574d6f44ffSToby Isaac 62584d6f44ffSToby Isaac #undef __FUNCT__ 6259bfc4295aSToby Isaac #define __FUNCT__ "DMProjectFieldLocal" 6260bfc4295aSToby Isaac PetscErrorCode DMProjectFieldLocal(DM dm, Vec localU, 6261bfc4295aSToby Isaac void (**funcs)(PetscInt, PetscInt, PetscInt, 6262bfc4295aSToby Isaac const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], 6263bfc4295aSToby Isaac const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], 6264bfc4295aSToby Isaac PetscReal, const PetscReal[], PetscScalar[]), 6265bfc4295aSToby Isaac InsertMode mode, Vec localX) 6266bfc4295aSToby Isaac { 6267bfc4295aSToby Isaac PetscErrorCode ierr; 6268bfc4295aSToby Isaac 6269bfc4295aSToby Isaac PetscFunctionBegin; 6270bfc4295aSToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6271bfc4295aSToby Isaac PetscValidHeaderSpecific(localU,VEC_CLASSID,2); 6272bfc4295aSToby Isaac PetscValidHeaderSpecific(localX,VEC_CLASSID,5); 6273bfc4295aSToby Isaac if (!dm->ops->projectfieldlocal) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM type %s does not implemnt DMProjectFieldLocal",((PetscObject)dm)->type_name); 6274bfc4295aSToby Isaac ierr = (dm->ops->projectfieldlocal) (dm, localU, funcs, mode, localX);CHKERRQ(ierr); 6275bfc4295aSToby Isaac PetscFunctionReturn(0); 6276bfc4295aSToby Isaac } 6277bfc4295aSToby Isaac 6278bfc4295aSToby Isaac #undef __FUNCT__ 62794d6f44ffSToby Isaac #define __FUNCT__ "DMProjectFunctionLabelLocal" 62800709b2feSToby Isaac PetscErrorCode DMProjectFunctionLabelLocal(DM dm, PetscReal time, DMLabel label, PetscInt numIds, const PetscInt ids[], PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void **ctxs, InsertMode mode, Vec localX) 62814d6f44ffSToby Isaac { 62824d6f44ffSToby Isaac PetscErrorCode ierr; 62834d6f44ffSToby Isaac 62844d6f44ffSToby Isaac PetscFunctionBegin; 62854d6f44ffSToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 62864d6f44ffSToby Isaac PetscValidHeaderSpecific(localX,VEC_CLASSID,5); 62874d6f44ffSToby Isaac if (!dm->ops->projectfunctionlabellocal) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM type %s does not implemnt DMProjectFunctionLabelLocal",((PetscObject)dm)->type_name); 62880709b2feSToby Isaac ierr = (dm->ops->projectfunctionlabellocal) (dm, time, label, numIds, ids, funcs, ctxs, mode, localX);CHKERRQ(ierr); 62894d6f44ffSToby Isaac PetscFunctionReturn(0); 62904d6f44ffSToby Isaac } 62912716604bSToby Isaac 62922716604bSToby Isaac #undef __FUNCT__ 62932716604bSToby Isaac #define __FUNCT__ "DMComputeL2Diff" 62942716604bSToby Isaac /*@C 62952716604bSToby Isaac DMComputeL2Diff - This function computes the L_2 difference between a function u and an FEM interpolant solution u_h. 62962716604bSToby Isaac 62972716604bSToby Isaac Input Parameters: 62982716604bSToby Isaac + dm - The DM 62990709b2feSToby Isaac . time - The time 63002716604bSToby Isaac . funcs - The functions to evaluate for each field component 63012716604bSToby Isaac . ctxs - Optional array of contexts to pass to each function, or NULL. 63022716604bSToby Isaac - X - The coefficient vector u_h 63032716604bSToby Isaac 63042716604bSToby Isaac Output Parameter: 63052716604bSToby Isaac . diff - The diff ||u - u_h||_2 63062716604bSToby Isaac 63072716604bSToby Isaac Level: developer 63082716604bSToby Isaac 63091189c1efSToby Isaac .seealso: DMProjectFunction(), DMComputeL2FieldDiff(), DMComputeL2GradientDiff() 63102716604bSToby Isaac @*/ 63110709b2feSToby Isaac PetscErrorCode DMComputeL2Diff(DM dm, PetscReal time, PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void **ctxs, Vec X, PetscReal *diff) 63122716604bSToby Isaac { 63132716604bSToby Isaac PetscErrorCode ierr; 63142716604bSToby Isaac 63152716604bSToby Isaac PetscFunctionBegin; 63162716604bSToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6317b698f381SToby Isaac PetscValidHeaderSpecific(X,VEC_CLASSID,5); 63182716604bSToby Isaac if (!dm->ops->computel2diff) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM type %s does not implemnt DMComputeL2Diff",((PetscObject)dm)->type_name); 63190709b2feSToby Isaac ierr = (dm->ops->computel2diff)(dm,time,funcs,ctxs,X,diff);CHKERRQ(ierr); 63202716604bSToby Isaac PetscFunctionReturn(0); 63212716604bSToby Isaac } 6322b698f381SToby Isaac 6323b698f381SToby Isaac #undef __FUNCT__ 6324b698f381SToby Isaac #define __FUNCT__ "DMComputeL2GradientDiff" 6325b698f381SToby Isaac /*@C 6326b698f381SToby Isaac DMComputeL2GradientDiff - This function computes the L_2 difference between the gradient of a function u and an FEM interpolant solution grad u_h. 6327b698f381SToby Isaac 6328b698f381SToby Isaac Input Parameters: 6329b698f381SToby Isaac + dm - The DM 6330b698f381SToby Isaac , time - The time 6331b698f381SToby Isaac . funcs - The gradient functions to evaluate for each field component 6332b698f381SToby Isaac . ctxs - Optional array of contexts to pass to each function, or NULL. 6333b698f381SToby Isaac . X - The coefficient vector u_h 6334b698f381SToby Isaac - n - The vector to project along 6335b698f381SToby Isaac 6336b698f381SToby Isaac Output Parameter: 6337b698f381SToby Isaac . diff - The diff ||(grad u - grad u_h) . n||_2 6338b698f381SToby Isaac 6339b698f381SToby Isaac Level: developer 6340b698f381SToby Isaac 6341b698f381SToby Isaac .seealso: DMProjectFunction(), DMComputeL2Diff() 6342b698f381SToby Isaac @*/ 6343b698f381SToby Isaac PetscErrorCode DMComputeL2GradientDiff(DM dm, PetscReal time, PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], const PetscReal[], PetscInt, PetscScalar *, void *), void **ctxs, Vec X, const PetscReal n[], PetscReal *diff) 6344b698f381SToby Isaac { 6345b698f381SToby Isaac PetscErrorCode ierr; 6346b698f381SToby Isaac 6347b698f381SToby Isaac PetscFunctionBegin; 6348b698f381SToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6349b698f381SToby Isaac PetscValidHeaderSpecific(X,VEC_CLASSID,5); 6350b698f381SToby Isaac if (!dm->ops->computel2gradientdiff) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM type %s does not implement DMComputeL2GradientDiff",((PetscObject)dm)->type_name); 6351b698f381SToby Isaac ierr = (dm->ops->computel2gradientdiff)(dm,time,funcs,ctxs,X,n,diff);CHKERRQ(ierr); 6352b698f381SToby Isaac PetscFunctionReturn(0); 6353b698f381SToby Isaac } 6354b698f381SToby Isaac 63552a16baeaSToby Isaac #undef __FUNCT__ 63562a16baeaSToby Isaac #define __FUNCT__ "DMComputeL2FieldDiff" 63572a16baeaSToby Isaac /*@C 63582a16baeaSToby Isaac DMComputeL2FieldDiff - This function computes the L_2 difference between a function u and an FEM interpolant solution u_h, separated into field components. 63592a16baeaSToby Isaac 63602a16baeaSToby Isaac Input Parameters: 63612a16baeaSToby Isaac + dm - The DM 63622a16baeaSToby Isaac . time - The time 63632a16baeaSToby Isaac . funcs - The functions to evaluate for each field component 63642a16baeaSToby Isaac . ctxs - Optional array of contexts to pass to each function, or NULL. 63652a16baeaSToby Isaac - X - The coefficient vector u_h 63662a16baeaSToby Isaac 63672a16baeaSToby Isaac Output Parameter: 63682a16baeaSToby Isaac . diff - The array of differences, ||u^f - u^f_h||_2 63692a16baeaSToby Isaac 63702a16baeaSToby Isaac Level: developer 63712a16baeaSToby Isaac 63721189c1efSToby Isaac .seealso: DMProjectFunction(), DMComputeL2FieldDiff(), DMComputeL2GradientDiff() 63732a16baeaSToby Isaac @*/ 63741189c1efSToby Isaac PetscErrorCode DMComputeL2FieldDiff(DM dm, PetscReal time, PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void **ctxs, Vec X, PetscReal diff[]) 63752a16baeaSToby Isaac { 63762a16baeaSToby Isaac PetscErrorCode ierr; 63772a16baeaSToby Isaac 63782a16baeaSToby Isaac PetscFunctionBegin; 63792a16baeaSToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 63802a16baeaSToby Isaac PetscValidHeaderSpecific(X,VEC_CLASSID,5); 63812a16baeaSToby Isaac if (!dm->ops->computel2fielddiff) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM type %s does not implemnt DMComputeL2FieldDiff",((PetscObject)dm)->type_name); 63822a16baeaSToby Isaac ierr = (dm->ops->computel2fielddiff)(dm,time,funcs,ctxs,X,diff);CHKERRQ(ierr); 63832a16baeaSToby Isaac PetscFunctionReturn(0); 63842a16baeaSToby Isaac } 63852a16baeaSToby Isaac 6386