1af0996ceSBarry Smith #include <petsc/private/dmimpl.h> /*I "petscdm.h" I*/ 2c58f1c22SToby Isaac #include <petsc/private/dmlabelimpl.h> /*I "petscdmlabel.h" I*/ 30c312b8eSJed Brown #include <petscsf.h> 42764a2aaSMatthew G. Knepley #include <petscds.h> 547c6ae99SBarry Smith 6732e2eb9SMatthew G Knepley PetscClassId DM_CLASSID; 73ad4599aSBarry Smith PetscLogEvent DM_Convert, DM_GlobalToLocal, DM_LocalToGlobal, DM_LocalToLocal, DM_LocatePoints, DM_Coarsen, DM_CreateInterpolation, DM_CreateRestriction; 867a56275SMatthew G Knepley 9bff4a2f0SMatthew G. Knepley const char *const DMBoundaryTypes[] = {"NONE","GHOSTED","MIRROR","PERIODIC","TWIST","DM_BOUNDARY_",0}; 10bff4a2f0SMatthew G. Knepley 1147c6ae99SBarry Smith #undef __FUNCT__ 12a4121054SBarry Smith #define __FUNCT__ "DMCreate" 13a4121054SBarry Smith /*@ 14de043629SMatthew G Knepley DMCreate - Creates an empty DM object. The type can then be set with DMSetType(). 15a4121054SBarry Smith 16a4121054SBarry Smith If you never call DMSetType() it will generate an 17a4121054SBarry Smith error when you try to use the vector. 18a4121054SBarry Smith 19a4121054SBarry Smith Collective on MPI_Comm 20a4121054SBarry Smith 21a4121054SBarry Smith Input Parameter: 22a4121054SBarry Smith . comm - The communicator for the DM object 23a4121054SBarry Smith 24a4121054SBarry Smith Output Parameter: 25a4121054SBarry Smith . dm - The DM object 26a4121054SBarry Smith 27a4121054SBarry Smith Level: beginner 28a4121054SBarry Smith 298472ad0fSDave May .seealso: DMSetType(), DMDA, DMSLICED, DMCOMPOSITE, DMPLEX, DMMOAB, DMNETWORK 30a4121054SBarry Smith @*/ 317087cfbeSBarry Smith PetscErrorCode DMCreate(MPI_Comm comm,DM *dm) 32a4121054SBarry Smith { 33a4121054SBarry Smith DM v; 34a4121054SBarry Smith PetscErrorCode ierr; 35a4121054SBarry Smith 36a4121054SBarry Smith PetscFunctionBegin; 371411c6eeSJed Brown PetscValidPointer(dm,2); 380298fd71SBarry Smith *dm = NULL; 398b984314SMatthew G. Knepley ierr = PetscSysInitializePackage();CHKERRQ(ierr); 40607a6623SBarry Smith ierr = VecInitializePackage();CHKERRQ(ierr); 41607a6623SBarry Smith ierr = MatInitializePackage();CHKERRQ(ierr); 42607a6623SBarry Smith ierr = DMInitializePackage();CHKERRQ(ierr); 43a4121054SBarry Smith 4473107ff1SLisandro Dalcin ierr = PetscHeaderCreate(v, DM_CLASSID, "DM", "Distribution Manager", "DM", comm, DMDestroy, DMView);CHKERRQ(ierr); 45e7c4fc90SDmitry Karpeev 460298fd71SBarry Smith v->ltogmap = NULL; 471411c6eeSJed Brown v->bs = 1; 48171400e9SBarry Smith v->coloringtype = IS_COLORING_GLOBAL; 4988ed4aceSMatthew G Knepley ierr = PetscSFCreate(comm, &v->sf);CHKERRQ(ierr); 5088ed4aceSMatthew G Knepley ierr = PetscSFCreate(comm, &v->defaultSF);CHKERRQ(ierr); 51c58f1c22SToby Isaac v->labels = NULL; 52c58f1c22SToby Isaac v->depthLabel = NULL; 530298fd71SBarry Smith v->defaultSection = NULL; 540298fd71SBarry Smith v->defaultGlobalSection = NULL; 55fba222abSToby Isaac v->defaultConstraintSection = NULL; 56fba222abSToby Isaac v->defaultConstraintMat = NULL; 57c6b900c6SMatthew G. Knepley v->L = NULL; 58c6b900c6SMatthew G. Knepley v->maxCell = NULL; 595dc8c3f7SMatthew G. Knepley v->bdtype = NULL; 609a9a41abSToby Isaac v->dimEmbed = PETSC_DEFAULT; 61435a35e8SMatthew G Knepley { 62435a35e8SMatthew G Knepley PetscInt i; 63435a35e8SMatthew G Knepley for (i = 0; i < 10; ++i) { 640298fd71SBarry Smith v->nullspaceConstructors[i] = NULL; 65435a35e8SMatthew G Knepley } 66435a35e8SMatthew G Knepley } 672764a2aaSMatthew G. Knepley ierr = PetscDSCreate(comm, &v->prob);CHKERRQ(ierr); 6814f150ffSMatthew G. Knepley v->dmBC = NULL; 69a8fb8f29SToby Isaac v->coarseMesh = NULL; 70f4d763aaSMatthew G. Knepley v->outputSequenceNum = -1; 71cdb7a50dSMatthew G. Knepley v->outputSequenceVal = 0.0; 72c0dedaeaSBarry Smith ierr = DMSetVecType(v,VECSTANDARD);CHKERRQ(ierr); 73b412c318SBarry Smith ierr = DMSetMatType(v,MATAIJ);CHKERRQ(ierr); 74bcc5ffd9SToby Isaac ierr = PetscNew(&(v->labels));CHKERRQ(ierr); 75c58f1c22SToby Isaac v->labels->refct = 1; 76bcc5ffd9SToby Isaac ierr = PetscNew(&(v->boundary));CHKERRQ(ierr); 77bcc5ffd9SToby Isaac v->boundary->refct = 1; 781411c6eeSJed Brown *dm = v; 79a4121054SBarry Smith PetscFunctionReturn(0); 80a4121054SBarry Smith } 81a4121054SBarry Smith 82a4121054SBarry Smith #undef __FUNCT__ 8338221697SMatthew G. Knepley #define __FUNCT__ "DMClone" 8438221697SMatthew G. Knepley /*@ 8538221697SMatthew G. Knepley DMClone - Creates a DM object with the same topology as the original. 8638221697SMatthew G. Knepley 8738221697SMatthew G. Knepley Collective on MPI_Comm 8838221697SMatthew G. Knepley 8938221697SMatthew G. Knepley Input Parameter: 9038221697SMatthew G. Knepley . dm - The original DM object 9138221697SMatthew G. Knepley 9238221697SMatthew G. Knepley Output Parameter: 9338221697SMatthew G. Knepley . newdm - The new DM object 9438221697SMatthew G. Knepley 9538221697SMatthew G. Knepley Level: beginner 9638221697SMatthew G. Knepley 9738221697SMatthew G. Knepley .keywords: DM, topology, create 9838221697SMatthew G. Knepley @*/ 9938221697SMatthew G. Knepley PetscErrorCode DMClone(DM dm, DM *newdm) 10038221697SMatthew G. Knepley { 10138221697SMatthew G. Knepley PetscSF sf; 10238221697SMatthew G. Knepley Vec coords; 10338221697SMatthew G. Knepley void *ctx; 1041de53e9aSMatthew G. Knepley PetscInt dim; 10538221697SMatthew G. Knepley PetscErrorCode ierr; 10638221697SMatthew G. Knepley 10738221697SMatthew G. Knepley PetscFunctionBegin; 10838221697SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 10938221697SMatthew G. Knepley PetscValidPointer(newdm,2); 11038221697SMatthew G. Knepley ierr = DMCreate(PetscObjectComm((PetscObject) dm), newdm);CHKERRQ(ierr); 111c58f1c22SToby Isaac ierr = PetscFree((*newdm)->labels);CHKERRQ(ierr); 112c58f1c22SToby Isaac dm->labels->refct++; 113c58f1c22SToby Isaac (*newdm)->labels = dm->labels; 114c58f1c22SToby Isaac (*newdm)->depthLabel = dm->depthLabel; 1151de53e9aSMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 1161de53e9aSMatthew G. Knepley ierr = DMSetDimension(*newdm, dim);CHKERRQ(ierr); 11738221697SMatthew G. Knepley if (dm->ops->clone) { 11838221697SMatthew G. Knepley ierr = (*dm->ops->clone)(dm, newdm);CHKERRQ(ierr); 11938221697SMatthew G. Knepley } 1203f22bcbcSToby Isaac (*newdm)->setupcalled = dm->setupcalled; 12138221697SMatthew G. Knepley ierr = DMGetPointSF(dm, &sf);CHKERRQ(ierr); 12238221697SMatthew G. Knepley ierr = DMSetPointSF(*newdm, sf);CHKERRQ(ierr); 12338221697SMatthew G. Knepley ierr = DMGetApplicationContext(dm, &ctx);CHKERRQ(ierr); 12438221697SMatthew G. Knepley ierr = DMSetApplicationContext(*newdm, ctx);CHKERRQ(ierr); 125be4c1c3eSMatthew G. Knepley if (dm->coordinateDM) { 126be4c1c3eSMatthew G. Knepley DM ncdm; 127be4c1c3eSMatthew G. Knepley PetscSection cs; 1285a0206caSToby Isaac PetscInt pEnd = -1, pEndMax = -1; 129be4c1c3eSMatthew G. Knepley 130be4c1c3eSMatthew G. Knepley ierr = DMGetDefaultSection(dm->coordinateDM, &cs);CHKERRQ(ierr); 131be4c1c3eSMatthew G. Knepley if (cs) {ierr = PetscSectionGetChart(cs, NULL, &pEnd);CHKERRQ(ierr);} 1325a0206caSToby Isaac ierr = MPI_Allreduce(&pEnd,&pEndMax,1,MPIU_INT,MPI_MAX,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 1335a0206caSToby Isaac if (pEndMax >= 0) { 134be4c1c3eSMatthew G. Knepley ierr = DMClone(dm->coordinateDM, &ncdm);CHKERRQ(ierr); 13513bffc4cSMatthew G. Knepley ierr = DMSetDefaultSection(ncdm, cs);CHKERRQ(ierr); 136a61e840bSMatthew G. Knepley ierr = DMSetCoordinateDM(*newdm, ncdm);CHKERRQ(ierr); 137be4c1c3eSMatthew G. Knepley ierr = DMDestroy(&ncdm);CHKERRQ(ierr); 138be4c1c3eSMatthew G. Knepley } 139be4c1c3eSMatthew G. Knepley } 14038221697SMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coords);CHKERRQ(ierr); 14138221697SMatthew G. Knepley if (coords) { 14238221697SMatthew G. Knepley ierr = DMSetCoordinatesLocal(*newdm, coords);CHKERRQ(ierr); 14338221697SMatthew G. Knepley } else { 14438221697SMatthew G. Knepley ierr = DMGetCoordinates(dm, &coords);CHKERRQ(ierr); 14538221697SMatthew G. Knepley if (coords) {ierr = DMSetCoordinates(*newdm, coords);CHKERRQ(ierr);} 14638221697SMatthew G. Knepley } 147c6b900c6SMatthew G. Knepley if (dm->maxCell) { 148c6b900c6SMatthew G. Knepley const PetscReal *maxCell, *L; 1495dc8c3f7SMatthew G. Knepley const DMBoundaryType *bd; 1505dc8c3f7SMatthew G. Knepley ierr = DMGetPeriodicity(dm, &maxCell, &L, &bd);CHKERRQ(ierr); 1515dc8c3f7SMatthew G. Knepley ierr = DMSetPeriodicity(*newdm, maxCell, L, bd);CHKERRQ(ierr); 152c6b900c6SMatthew G. Knepley } 15338221697SMatthew G. Knepley PetscFunctionReturn(0); 15438221697SMatthew G. Knepley } 15538221697SMatthew G. Knepley 15638221697SMatthew G. Knepley #undef __FUNCT__ 1579a42bb27SBarry Smith #define __FUNCT__ "DMSetVecType" 1589a42bb27SBarry Smith /*@C 159564755cdSBarry Smith DMSetVecType - Sets the type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() 1609a42bb27SBarry Smith 1618472ad0fSDave May Logically Collective on DM 1629a42bb27SBarry Smith 1639a42bb27SBarry Smith Input Parameter: 1649a42bb27SBarry Smith + da - initial distributed array 1658154be41SBarry Smith . ctype - the vector type, currently either VECSTANDARD or VECCUSP 1669a42bb27SBarry Smith 1679a42bb27SBarry Smith Options Database: 168dd85299cSBarry Smith . -dm_vec_type ctype 1699a42bb27SBarry Smith 1709a42bb27SBarry Smith Level: intermediate 1719a42bb27SBarry Smith 1728472ad0fSDave May .seealso: DMCreate(), DMDestroy(), DM, DMDAInterpolationType, VecType, DMGetVecType() 1739a42bb27SBarry Smith @*/ 17419fd82e9SBarry Smith PetscErrorCode DMSetVecType(DM da,VecType ctype) 1759a42bb27SBarry Smith { 1769a42bb27SBarry Smith PetscErrorCode ierr; 1779a42bb27SBarry Smith 1789a42bb27SBarry Smith PetscFunctionBegin; 1799a42bb27SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 1809a42bb27SBarry Smith ierr = PetscFree(da->vectype);CHKERRQ(ierr); 18119fd82e9SBarry Smith ierr = PetscStrallocpy(ctype,(char**)&da->vectype);CHKERRQ(ierr); 1829a42bb27SBarry Smith PetscFunctionReturn(0); 1839a42bb27SBarry Smith } 1849a42bb27SBarry Smith 1859a42bb27SBarry Smith #undef __FUNCT__ 186c0dedaeaSBarry Smith #define __FUNCT__ "DMGetVecType" 187c0dedaeaSBarry Smith /*@C 188c0dedaeaSBarry Smith DMGetVecType - Gets the type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() 189c0dedaeaSBarry Smith 1908472ad0fSDave May Logically Collective on DM 191c0dedaeaSBarry Smith 192c0dedaeaSBarry Smith Input Parameter: 193c0dedaeaSBarry Smith . da - initial distributed array 194c0dedaeaSBarry Smith 195c0dedaeaSBarry Smith Output Parameter: 196c0dedaeaSBarry Smith . ctype - the vector type 197c0dedaeaSBarry Smith 198c0dedaeaSBarry Smith Level: intermediate 199c0dedaeaSBarry Smith 2008472ad0fSDave May .seealso: DMCreate(), DMDestroy(), DM, DMDAInterpolationType, VecType 201c0dedaeaSBarry Smith @*/ 202c0dedaeaSBarry Smith PetscErrorCode DMGetVecType(DM da,VecType *ctype) 203c0dedaeaSBarry Smith { 204c0dedaeaSBarry Smith PetscFunctionBegin; 205c0dedaeaSBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 206c0dedaeaSBarry Smith *ctype = da->vectype; 207c0dedaeaSBarry Smith PetscFunctionReturn(0); 208c0dedaeaSBarry Smith } 209c0dedaeaSBarry Smith 210c0dedaeaSBarry Smith #undef __FUNCT__ 2115f1ad066SMatthew G Knepley #define __FUNCT__ "VecGetDM" 2125f1ad066SMatthew G Knepley /*@ 21334f98d34SBarry Smith VecGetDM - Gets the DM defining the data layout of the vector 2145f1ad066SMatthew G Knepley 2155f1ad066SMatthew G Knepley Not collective 2165f1ad066SMatthew G Knepley 2175f1ad066SMatthew G Knepley Input Parameter: 2185f1ad066SMatthew G Knepley . v - The Vec 2195f1ad066SMatthew G Knepley 2205f1ad066SMatthew G Knepley Output Parameter: 2215f1ad066SMatthew G Knepley . dm - The DM 2225f1ad066SMatthew G Knepley 2235f1ad066SMatthew G Knepley Level: intermediate 2245f1ad066SMatthew G Knepley 2255f1ad066SMatthew G Knepley .seealso: VecSetDM(), DMGetLocalVector(), DMGetGlobalVector(), DMSetVecType() 2265f1ad066SMatthew G Knepley @*/ 2275f1ad066SMatthew G Knepley PetscErrorCode VecGetDM(Vec v, DM *dm) 2285f1ad066SMatthew G Knepley { 2295f1ad066SMatthew G Knepley PetscErrorCode ierr; 2305f1ad066SMatthew G Knepley 2315f1ad066SMatthew G Knepley PetscFunctionBegin; 2325f1ad066SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,1); 2335f1ad066SMatthew G Knepley PetscValidPointer(dm,2); 2345f1ad066SMatthew G Knepley ierr = PetscObjectQuery((PetscObject) v, "__PETSc_dm", (PetscObject*) dm);CHKERRQ(ierr); 2355f1ad066SMatthew G Knepley PetscFunctionReturn(0); 2365f1ad066SMatthew G Knepley } 2375f1ad066SMatthew G Knepley 2385f1ad066SMatthew G Knepley #undef __FUNCT__ 2395f1ad066SMatthew G Knepley #define __FUNCT__ "VecSetDM" 2405f1ad066SMatthew G Knepley /*@ 241d9805387SMatthew G. Knepley VecSetDM - Sets the DM defining the data layout of the vector. 2425f1ad066SMatthew G Knepley 2435f1ad066SMatthew G Knepley Not collective 2445f1ad066SMatthew G Knepley 2455f1ad066SMatthew G Knepley Input Parameters: 2465f1ad066SMatthew G Knepley + v - The Vec 2475f1ad066SMatthew G Knepley - dm - The DM 2485f1ad066SMatthew G Knepley 249d9805387SMatthew 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. 250d9805387SMatthew G. Knepley 2515f1ad066SMatthew G Knepley Level: intermediate 2525f1ad066SMatthew G Knepley 2535f1ad066SMatthew G Knepley .seealso: VecGetDM(), DMGetLocalVector(), DMGetGlobalVector(), DMSetVecType() 2545f1ad066SMatthew G Knepley @*/ 2555f1ad066SMatthew G Knepley PetscErrorCode VecSetDM(Vec v, DM dm) 2565f1ad066SMatthew G Knepley { 2575f1ad066SMatthew G Knepley PetscErrorCode ierr; 2585f1ad066SMatthew G Knepley 2595f1ad066SMatthew G Knepley PetscFunctionBegin; 2605f1ad066SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,1); 261d7f50e27SLisandro Dalcin if (dm) PetscValidHeaderSpecific(dm,DM_CLASSID,2); 2625f1ad066SMatthew G Knepley ierr = PetscObjectCompose((PetscObject) v, "__PETSc_dm", (PetscObject) dm);CHKERRQ(ierr); 2635f1ad066SMatthew G Knepley PetscFunctionReturn(0); 2645f1ad066SMatthew G Knepley } 2655f1ad066SMatthew G Knepley 2665f1ad066SMatthew G Knepley #undef __FUNCT__ 267521d9a4cSLisandro Dalcin #define __FUNCT__ "DMSetMatType" 268521d9a4cSLisandro Dalcin /*@C 269521d9a4cSLisandro Dalcin DMSetMatType - Sets the type of matrix created with DMCreateMatrix() 270521d9a4cSLisandro Dalcin 271521d9a4cSLisandro Dalcin Logically Collective on DM 272521d9a4cSLisandro Dalcin 273521d9a4cSLisandro Dalcin Input Parameter: 274521d9a4cSLisandro Dalcin + dm - the DM context 275521d9a4cSLisandro Dalcin . ctype - the matrix type 276521d9a4cSLisandro Dalcin 277521d9a4cSLisandro Dalcin Options Database: 278521d9a4cSLisandro Dalcin . -dm_mat_type ctype 279521d9a4cSLisandro Dalcin 280521d9a4cSLisandro Dalcin Level: intermediate 281521d9a4cSLisandro Dalcin 282c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateMatrix(), DMSetMatrixPreallocateOnly(), MatType, DMGetMatType() 283521d9a4cSLisandro Dalcin @*/ 28419fd82e9SBarry Smith PetscErrorCode DMSetMatType(DM dm,MatType ctype) 285521d9a4cSLisandro Dalcin { 286521d9a4cSLisandro Dalcin PetscErrorCode ierr; 28788f0584fSBarry Smith 288521d9a4cSLisandro Dalcin PetscFunctionBegin; 289521d9a4cSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 290521d9a4cSLisandro Dalcin ierr = PetscFree(dm->mattype);CHKERRQ(ierr); 29119fd82e9SBarry Smith ierr = PetscStrallocpy(ctype,(char**)&dm->mattype);CHKERRQ(ierr); 292521d9a4cSLisandro Dalcin PetscFunctionReturn(0); 293521d9a4cSLisandro Dalcin } 294521d9a4cSLisandro Dalcin 295521d9a4cSLisandro Dalcin #undef __FUNCT__ 296c0dedaeaSBarry Smith #define __FUNCT__ "DMGetMatType" 297c0dedaeaSBarry Smith /*@C 298c0dedaeaSBarry Smith DMGetMatType - Gets the type of matrix created with DMCreateMatrix() 299c0dedaeaSBarry Smith 300c0dedaeaSBarry Smith Logically Collective on DM 301c0dedaeaSBarry Smith 302c0dedaeaSBarry Smith Input Parameter: 303c0dedaeaSBarry Smith . dm - the DM context 304c0dedaeaSBarry Smith 305c0dedaeaSBarry Smith Output Parameter: 306c0dedaeaSBarry Smith . ctype - the matrix type 307c0dedaeaSBarry Smith 308c0dedaeaSBarry Smith Options Database: 309c0dedaeaSBarry Smith . -dm_mat_type ctype 310c0dedaeaSBarry Smith 311c0dedaeaSBarry Smith Level: intermediate 312c0dedaeaSBarry Smith 313c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateMatrix(), DMSetMatrixPreallocateOnly(), MatType, DMSetMatType() 314c0dedaeaSBarry Smith @*/ 315c0dedaeaSBarry Smith PetscErrorCode DMGetMatType(DM dm,MatType *ctype) 316c0dedaeaSBarry Smith { 317c0dedaeaSBarry Smith PetscFunctionBegin; 318c0dedaeaSBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 319c0dedaeaSBarry Smith *ctype = dm->mattype; 320c0dedaeaSBarry Smith PetscFunctionReturn(0); 321c0dedaeaSBarry Smith } 322c0dedaeaSBarry Smith 323c0dedaeaSBarry Smith #undef __FUNCT__ 324c688c046SMatthew G Knepley #define __FUNCT__ "MatGetDM" 325c688c046SMatthew G Knepley /*@ 32634f98d34SBarry Smith MatGetDM - Gets the DM defining the data layout of the matrix 327c688c046SMatthew G Knepley 328c688c046SMatthew G Knepley Not collective 329c688c046SMatthew G Knepley 330c688c046SMatthew G Knepley Input Parameter: 331c688c046SMatthew G Knepley . A - The Mat 332c688c046SMatthew G Knepley 333c688c046SMatthew G Knepley Output Parameter: 334c688c046SMatthew G Knepley . dm - The DM 335c688c046SMatthew G Knepley 336c688c046SMatthew G Knepley Level: intermediate 337c688c046SMatthew G Knepley 338c688c046SMatthew G Knepley .seealso: MatSetDM(), DMCreateMatrix(), DMSetMatType() 339c688c046SMatthew G Knepley @*/ 340c688c046SMatthew G Knepley PetscErrorCode MatGetDM(Mat A, DM *dm) 341c688c046SMatthew G Knepley { 342c688c046SMatthew G Knepley PetscErrorCode ierr; 343c688c046SMatthew G Knepley 344c688c046SMatthew G Knepley PetscFunctionBegin; 345c688c046SMatthew G Knepley PetscValidHeaderSpecific(A,MAT_CLASSID,1); 346c688c046SMatthew G Knepley PetscValidPointer(dm,2); 347c688c046SMatthew G Knepley ierr = PetscObjectQuery((PetscObject) A, "__PETSc_dm", (PetscObject*) dm);CHKERRQ(ierr); 348c688c046SMatthew G Knepley PetscFunctionReturn(0); 349c688c046SMatthew G Knepley } 350c688c046SMatthew G Knepley 351c688c046SMatthew G Knepley #undef __FUNCT__ 352c688c046SMatthew G Knepley #define __FUNCT__ "MatSetDM" 353c688c046SMatthew G Knepley /*@ 354c688c046SMatthew G Knepley MatSetDM - Sets the DM defining the data layout of the matrix 355c688c046SMatthew G Knepley 356c688c046SMatthew G Knepley Not collective 357c688c046SMatthew G Knepley 358c688c046SMatthew G Knepley Input Parameters: 359c688c046SMatthew G Knepley + A - The Mat 360c688c046SMatthew G Knepley - dm - The DM 361c688c046SMatthew G Knepley 362c688c046SMatthew G Knepley Level: intermediate 363c688c046SMatthew G Knepley 364c688c046SMatthew G Knepley .seealso: MatGetDM(), DMCreateMatrix(), DMSetMatType() 365c688c046SMatthew G Knepley @*/ 366c688c046SMatthew G Knepley PetscErrorCode MatSetDM(Mat A, DM dm) 367c688c046SMatthew G Knepley { 368c688c046SMatthew G Knepley PetscErrorCode ierr; 369c688c046SMatthew G Knepley 370c688c046SMatthew G Knepley PetscFunctionBegin; 371c688c046SMatthew G Knepley PetscValidHeaderSpecific(A,MAT_CLASSID,1); 3728865f1eaSKarl Rupp if (dm) PetscValidHeaderSpecific(dm,DM_CLASSID,2); 373c688c046SMatthew G Knepley ierr = PetscObjectCompose((PetscObject) A, "__PETSc_dm", (PetscObject) dm);CHKERRQ(ierr); 374c688c046SMatthew G Knepley PetscFunctionReturn(0); 375c688c046SMatthew G Knepley } 376c688c046SMatthew G Knepley 377c688c046SMatthew G Knepley #undef __FUNCT__ 3789a42bb27SBarry Smith #define __FUNCT__ "DMSetOptionsPrefix" 3799a42bb27SBarry Smith /*@C 3809a42bb27SBarry Smith DMSetOptionsPrefix - Sets the prefix used for searching for all 3816757b960SDave May DM options in the database. 3829a42bb27SBarry Smith 3838353ddbbSDave May Logically Collective on DM 3849a42bb27SBarry Smith 3859a42bb27SBarry Smith Input Parameter: 3868353ddbbSDave May + da - the DM context 3879a42bb27SBarry Smith - prefix - the prefix to prepend to all option names 3889a42bb27SBarry Smith 3899a42bb27SBarry Smith Notes: 3909a42bb27SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 3919a42bb27SBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 3929a42bb27SBarry Smith 3939a42bb27SBarry Smith Level: advanced 3949a42bb27SBarry Smith 3958353ddbbSDave May .keywords: DM, set, options, prefix, database 3969a42bb27SBarry Smith 3979a42bb27SBarry Smith .seealso: DMSetFromOptions() 3989a42bb27SBarry Smith @*/ 3997087cfbeSBarry Smith PetscErrorCode DMSetOptionsPrefix(DM dm,const char prefix[]) 4009a42bb27SBarry Smith { 4019a42bb27SBarry Smith PetscErrorCode ierr; 4029a42bb27SBarry Smith 4039a42bb27SBarry Smith PetscFunctionBegin; 4049a42bb27SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4059a42bb27SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)dm,prefix);CHKERRQ(ierr); 406691be533SLawrence Mitchell if (dm->sf) { 407691be533SLawrence Mitchell ierr = PetscObjectSetOptionsPrefix((PetscObject)dm->sf,prefix);CHKERRQ(ierr); 408691be533SLawrence Mitchell } 409691be533SLawrence Mitchell if (dm->defaultSF) { 410691be533SLawrence Mitchell ierr = PetscObjectSetOptionsPrefix((PetscObject)dm->defaultSF,prefix);CHKERRQ(ierr); 411691be533SLawrence Mitchell } 4129a42bb27SBarry Smith PetscFunctionReturn(0); 4139a42bb27SBarry Smith } 4149a42bb27SBarry Smith 4159a42bb27SBarry Smith #undef __FUNCT__ 41631697293SDave May #define __FUNCT__ "DMAppendOptionsPrefix" 41731697293SDave May /*@C 41831697293SDave May DMAppendOptionsPrefix - Appends to the prefix used for searching for all 41931697293SDave May DM options in the database. 42031697293SDave May 42131697293SDave May Logically Collective on DM 42231697293SDave May 42331697293SDave May Input Parameters: 42431697293SDave May + dm - the DM context 42531697293SDave May - prefix - the prefix string to prepend to all DM option requests 42631697293SDave May 42731697293SDave May Notes: 42831697293SDave May A hyphen (-) must NOT be given at the beginning of the prefix name. 42931697293SDave May The first character of all runtime options is AUTOMATICALLY the hyphen. 43031697293SDave May 43131697293SDave May Level: advanced 43231697293SDave May 43331697293SDave May .keywords: DM, append, options, prefix, database 43431697293SDave May 43531697293SDave May .seealso: DMSetOptionsPrefix(), DMGetOptionsPrefix() 43631697293SDave May @*/ 43731697293SDave May PetscErrorCode DMAppendOptionsPrefix(DM dm,const char prefix[]) 43831697293SDave May { 43931697293SDave May PetscErrorCode ierr; 44031697293SDave May 44131697293SDave May PetscFunctionBegin; 44231697293SDave May PetscValidHeaderSpecific(dm,DM_CLASSID,1); 44331697293SDave May ierr = PetscObjectAppendOptionsPrefix((PetscObject)dm,prefix);CHKERRQ(ierr); 44431697293SDave May PetscFunctionReturn(0); 44531697293SDave May } 44631697293SDave May 44731697293SDave May #undef __FUNCT__ 44831697293SDave May #define __FUNCT__ "DMGetOptionsPrefix" 44931697293SDave May /*@C 45031697293SDave May DMGetOptionsPrefix - Gets the prefix used for searching for all 45131697293SDave May DM options in the database. 45231697293SDave May 45331697293SDave May Not Collective 45431697293SDave May 45531697293SDave May Input Parameters: 45631697293SDave May . dm - the DM context 45731697293SDave May 45831697293SDave May Output Parameters: 45931697293SDave May . prefix - pointer to the prefix string used is returned 46031697293SDave May 46131697293SDave May Notes: On the fortran side, the user should pass in a string 'prefix' of 46231697293SDave May sufficient length to hold the prefix. 46331697293SDave May 46431697293SDave May Level: advanced 46531697293SDave May 46631697293SDave May .keywords: DM, set, options, prefix, database 46731697293SDave May 46831697293SDave May .seealso: DMSetOptionsPrefix(), DMAppendOptionsPrefix() 46931697293SDave May @*/ 47031697293SDave May PetscErrorCode DMGetOptionsPrefix(DM dm,const char *prefix[]) 47131697293SDave May { 47231697293SDave May PetscErrorCode ierr; 47331697293SDave May 47431697293SDave May PetscFunctionBegin; 47531697293SDave May PetscValidHeaderSpecific(dm,DM_CLASSID,1); 47631697293SDave May ierr = PetscObjectGetOptionsPrefix((PetscObject)dm,prefix);CHKERRQ(ierr); 47731697293SDave May PetscFunctionReturn(0); 47831697293SDave May } 47931697293SDave May 48031697293SDave May #undef __FUNCT__ 48188bdff64SToby Isaac #define __FUNCT__ "DMCountNonCyclicReferences" 48288bdff64SToby Isaac static PetscErrorCode DMCountNonCyclicReferences(DM dm, PetscBool recurseCoarse, PetscBool recurseFine, PetscInt *ncrefct) 48388bdff64SToby Isaac { 48488bdff64SToby Isaac PetscInt i, refct = ((PetscObject) dm)->refct; 48588bdff64SToby Isaac DMNamedVecLink nlink; 48688bdff64SToby Isaac PetscErrorCode ierr; 48788bdff64SToby Isaac 48888bdff64SToby Isaac PetscFunctionBegin; 48988bdff64SToby Isaac /* count all the circular references of DM and its contained Vecs */ 49088bdff64SToby Isaac for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 49188bdff64SToby Isaac if (dm->localin[i]) refct--; 49288bdff64SToby Isaac if (dm->globalin[i]) refct--; 49388bdff64SToby Isaac } 49488bdff64SToby Isaac for (nlink=dm->namedglobal; nlink; nlink=nlink->next) refct--; 49588bdff64SToby Isaac for (nlink=dm->namedlocal; nlink; nlink=nlink->next) refct--; 49688bdff64SToby Isaac if (dm->x) { 49788bdff64SToby Isaac DM obj; 49888bdff64SToby Isaac ierr = VecGetDM(dm->x, &obj);CHKERRQ(ierr); 49988bdff64SToby Isaac if (obj == dm) refct--; 50088bdff64SToby Isaac } 50188bdff64SToby Isaac if (dm->coarseMesh && dm->coarseMesh->fineMesh == dm) { 50288bdff64SToby Isaac refct--; 50388bdff64SToby Isaac if (recurseCoarse) { 50488bdff64SToby Isaac PetscInt coarseCount; 50588bdff64SToby Isaac 50688bdff64SToby Isaac ierr = DMCountNonCyclicReferences(dm->coarseMesh, PETSC_TRUE, PETSC_FALSE,&coarseCount);CHKERRQ(ierr); 50788bdff64SToby Isaac refct += coarseCount; 50888bdff64SToby Isaac } 50988bdff64SToby Isaac } 51088bdff64SToby Isaac if (dm->fineMesh && dm->fineMesh->coarseMesh == dm) { 51188bdff64SToby Isaac refct--; 51288bdff64SToby Isaac if (recurseFine) { 51388bdff64SToby Isaac PetscInt fineCount; 51488bdff64SToby Isaac 51588bdff64SToby Isaac ierr = DMCountNonCyclicReferences(dm->fineMesh, PETSC_FALSE, PETSC_TRUE,&fineCount);CHKERRQ(ierr); 51688bdff64SToby Isaac refct += fineCount; 51788bdff64SToby Isaac } 51888bdff64SToby Isaac } 51988bdff64SToby Isaac *ncrefct = refct; 52088bdff64SToby Isaac PetscFunctionReturn(0); 52188bdff64SToby Isaac } 52288bdff64SToby Isaac 523bcc5ffd9SToby Isaac PetscErrorCode DMBoundaryDestroy(DMBoundaryLinkList *boundary); 524a6ba4734SToby Isaac 52588bdff64SToby Isaac #undef __FUNCT__ 526354557abSToby Isaac #define __FUNCT__ "DMDestroyLabelLinkList" 527354557abSToby Isaac PetscErrorCode DMDestroyLabelLinkList(DM dm) 528354557abSToby Isaac { 529354557abSToby Isaac PetscErrorCode ierr; 530354557abSToby Isaac 531354557abSToby Isaac PetscFunctionBegin; 532354557abSToby Isaac if (!--(dm->labels->refct)) { 533354557abSToby Isaac DMLabelLink next = dm->labels->next; 534354557abSToby Isaac 535354557abSToby Isaac /* destroy the labels */ 536354557abSToby Isaac while (next) { 537354557abSToby Isaac DMLabelLink tmp = next->next; 538354557abSToby Isaac 539354557abSToby Isaac ierr = DMLabelDestroy(&next->label);CHKERRQ(ierr); 540354557abSToby Isaac ierr = PetscFree(next);CHKERRQ(ierr); 541354557abSToby Isaac next = tmp; 542354557abSToby Isaac } 543354557abSToby Isaac ierr = PetscFree(dm->labels);CHKERRQ(ierr); 544354557abSToby Isaac } 545354557abSToby Isaac PetscFunctionReturn(0); 546354557abSToby Isaac } 547354557abSToby Isaac 548354557abSToby Isaac #undef __FUNCT__ 54947c6ae99SBarry Smith #define __FUNCT__ "DMDestroy" 55047c6ae99SBarry Smith /*@ 5518472ad0fSDave May DMDestroy - Destroys a vector packer or DM. 55247c6ae99SBarry Smith 55347c6ae99SBarry Smith Collective on DM 55447c6ae99SBarry Smith 55547c6ae99SBarry Smith Input Parameter: 55647c6ae99SBarry Smith . dm - the DM object to destroy 55747c6ae99SBarry Smith 55847c6ae99SBarry Smith Level: developer 55947c6ae99SBarry Smith 560e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 56147c6ae99SBarry Smith 56247c6ae99SBarry Smith @*/ 563fcfd50ebSBarry Smith PetscErrorCode DMDestroy(DM *dm) 56447c6ae99SBarry Smith { 56588bdff64SToby Isaac PetscInt i, cnt; 566dfe15315SJed Brown DMNamedVecLink nlink,nnext; 56747c6ae99SBarry Smith PetscErrorCode ierr; 56847c6ae99SBarry Smith 56947c6ae99SBarry Smith PetscFunctionBegin; 5706bf464f9SBarry Smith if (!*dm) PetscFunctionReturn(0); 5716bf464f9SBarry Smith PetscValidHeaderSpecific((*dm),DM_CLASSID,1); 57287e657c6SBarry Smith 57388bdff64SToby Isaac /* count all non-cyclic references in the doubly-linked list of coarse<->fine meshes */ 57488bdff64SToby Isaac ierr = DMCountNonCyclicReferences(*dm,PETSC_TRUE,PETSC_TRUE,&cnt);CHKERRQ(ierr); 57588bdff64SToby Isaac --((PetscObject)(*dm))->refct; 57688bdff64SToby Isaac if (--cnt > 0) {*dm = 0; PetscFunctionReturn(0);} 577732e2eb9SMatthew G Knepley /* 578732e2eb9SMatthew G Knepley Need this test because the dm references the vectors that 579732e2eb9SMatthew G Knepley reference the dm, so destroying the dm calls destroy on the 580732e2eb9SMatthew G Knepley vectors that cause another destroy on the dm 581732e2eb9SMatthew G Knepley */ 5826bf464f9SBarry Smith if (((PetscObject)(*dm))->refct < 0) PetscFunctionReturn(0); 5836bf464f9SBarry Smith ((PetscObject) (*dm))->refct = 0; 584732e2eb9SMatthew G Knepley for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 5856bf464f9SBarry Smith if ((*dm)->localout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a local vector obtained with DMGetLocalVector()"); 5866bf464f9SBarry Smith ierr = VecDestroy(&(*dm)->localin[i]);CHKERRQ(ierr); 587732e2eb9SMatthew G Knepley } 588f490541aSPeter Brune nnext=(*dm)->namedglobal; 5890298fd71SBarry Smith (*dm)->namedglobal = NULL; 590f490541aSPeter Brune for (nlink=nnext; nlink; nlink=nnext) { /* Destroy the named vectors */ 5912348bcf4SPeter Brune nnext = nlink->next; 5922348bcf4SPeter 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); 5932348bcf4SPeter Brune ierr = PetscFree(nlink->name);CHKERRQ(ierr); 5942348bcf4SPeter Brune ierr = VecDestroy(&nlink->X);CHKERRQ(ierr); 5952348bcf4SPeter Brune ierr = PetscFree(nlink);CHKERRQ(ierr); 5962348bcf4SPeter Brune } 597f490541aSPeter Brune nnext=(*dm)->namedlocal; 5980298fd71SBarry Smith (*dm)->namedlocal = NULL; 599f490541aSPeter Brune for (nlink=nnext; nlink; nlink=nnext) { /* Destroy the named local vectors */ 600f490541aSPeter Brune nnext = nlink->next; 601f490541aSPeter 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); 602f490541aSPeter Brune ierr = PetscFree(nlink->name);CHKERRQ(ierr); 603f490541aSPeter Brune ierr = VecDestroy(&nlink->X);CHKERRQ(ierr); 604f490541aSPeter Brune ierr = PetscFree(nlink);CHKERRQ(ierr); 605f490541aSPeter Brune } 6062348bcf4SPeter Brune 607b17ce1afSJed Brown /* Destroy the list of hooks */ 608c833c3b5SJed Brown { 609c833c3b5SJed Brown DMCoarsenHookLink link,next; 610b17ce1afSJed Brown for (link=(*dm)->coarsenhook; link; link=next) { 611b17ce1afSJed Brown next = link->next; 612b17ce1afSJed Brown ierr = PetscFree(link);CHKERRQ(ierr); 613b17ce1afSJed Brown } 6140298fd71SBarry Smith (*dm)->coarsenhook = NULL; 615c833c3b5SJed Brown } 616c833c3b5SJed Brown { 617c833c3b5SJed Brown DMRefineHookLink link,next; 618c833c3b5SJed Brown for (link=(*dm)->refinehook; link; link=next) { 619c833c3b5SJed Brown next = link->next; 620c833c3b5SJed Brown ierr = PetscFree(link);CHKERRQ(ierr); 621c833c3b5SJed Brown } 6220298fd71SBarry Smith (*dm)->refinehook = NULL; 623c833c3b5SJed Brown } 624be081cd6SPeter Brune { 625be081cd6SPeter Brune DMSubDomainHookLink link,next; 626be081cd6SPeter Brune for (link=(*dm)->subdomainhook; link; link=next) { 627be081cd6SPeter Brune next = link->next; 628be081cd6SPeter Brune ierr = PetscFree(link);CHKERRQ(ierr); 629be081cd6SPeter Brune } 6300298fd71SBarry Smith (*dm)->subdomainhook = NULL; 631be081cd6SPeter Brune } 632baf369e7SPeter Brune { 633baf369e7SPeter Brune DMGlobalToLocalHookLink link,next; 634baf369e7SPeter Brune for (link=(*dm)->gtolhook; link; link=next) { 635baf369e7SPeter Brune next = link->next; 636baf369e7SPeter Brune ierr = PetscFree(link);CHKERRQ(ierr); 637baf369e7SPeter Brune } 6380298fd71SBarry Smith (*dm)->gtolhook = NULL; 639baf369e7SPeter Brune } 640d4d07f1eSToby Isaac { 641d4d07f1eSToby Isaac DMLocalToGlobalHookLink link,next; 642d4d07f1eSToby Isaac for (link=(*dm)->ltoghook; link; link=next) { 643d4d07f1eSToby Isaac next = link->next; 644d4d07f1eSToby Isaac ierr = PetscFree(link);CHKERRQ(ierr); 645d4d07f1eSToby Isaac } 646d4d07f1eSToby Isaac (*dm)->ltoghook = NULL; 647d4d07f1eSToby Isaac } 648aa1993deSMatthew G Knepley /* Destroy the work arrays */ 649aa1993deSMatthew G Knepley { 650aa1993deSMatthew G Knepley DMWorkLink link,next; 651aa1993deSMatthew G Knepley if ((*dm)->workout) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Work array still checked out"); 652aa1993deSMatthew G Knepley for (link=(*dm)->workin; link; link=next) { 653aa1993deSMatthew G Knepley next = link->next; 654aa1993deSMatthew G Knepley ierr = PetscFree(link->mem);CHKERRQ(ierr); 655aa1993deSMatthew G Knepley ierr = PetscFree(link);CHKERRQ(ierr); 656aa1993deSMatthew G Knepley } 6570298fd71SBarry Smith (*dm)->workin = NULL; 658aa1993deSMatthew G Knepley } 659c58f1c22SToby Isaac if (!--((*dm)->labels->refct)) { 660c58f1c22SToby Isaac DMLabelLink next = (*dm)->labels->next; 661c58f1c22SToby Isaac 662c58f1c22SToby Isaac /* destroy the labels */ 663c58f1c22SToby Isaac while (next) { 664c58f1c22SToby Isaac DMLabelLink tmp = next->next; 665c58f1c22SToby Isaac 666c58f1c22SToby Isaac ierr = DMLabelDestroy(&next->label);CHKERRQ(ierr); 667c58f1c22SToby Isaac ierr = PetscFree(next);CHKERRQ(ierr); 668c58f1c22SToby Isaac next = tmp; 669c58f1c22SToby Isaac } 670c58f1c22SToby Isaac ierr = PetscFree((*dm)->labels);CHKERRQ(ierr); 671c58f1c22SToby Isaac } 672bcc5ffd9SToby Isaac ierr = DMBoundaryDestroy(&(*dm)->boundary);CHKERRQ(ierr); 673b17ce1afSJed Brown 67452536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmksp);CHKERRQ(ierr); 67552536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmsnes);CHKERRQ(ierr); 67652536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmts);CHKERRQ(ierr); 67752536dc3SBarry Smith 6781a266240SBarry Smith if ((*dm)->ctx && (*dm)->ctxdestroy) { 6791a266240SBarry Smith ierr = (*(*dm)->ctxdestroy)(&(*dm)->ctx);CHKERRQ(ierr); 6801a266240SBarry Smith } 68187e657c6SBarry Smith ierr = VecDestroy(&(*dm)->x);CHKERRQ(ierr); 68271cd77b2SBarry Smith ierr = MatFDColoringDestroy(&(*dm)->fd);CHKERRQ(ierr); 6834dcab191SBarry Smith ierr = DMClearGlobalVectors(*dm);CHKERRQ(ierr); 6846bf464f9SBarry Smith ierr = ISLocalToGlobalMappingDestroy(&(*dm)->ltogmap);CHKERRQ(ierr); 6856bf464f9SBarry Smith ierr = PetscFree((*dm)->vectype);CHKERRQ(ierr); 686073dac72SJed Brown ierr = PetscFree((*dm)->mattype);CHKERRQ(ierr); 68788ed4aceSMatthew G Knepley 68888ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&(*dm)->defaultSection);CHKERRQ(ierr); 68988ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&(*dm)->defaultGlobalSection);CHKERRQ(ierr); 6908b1ab98fSJed Brown ierr = PetscLayoutDestroy(&(*dm)->map);CHKERRQ(ierr); 691fba222abSToby Isaac ierr = PetscSectionDestroy(&(*dm)->defaultConstraintSection);CHKERRQ(ierr); 692fba222abSToby Isaac ierr = MatDestroy(&(*dm)->defaultConstraintMat);CHKERRQ(ierr); 69388ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&(*dm)->sf);CHKERRQ(ierr); 69488ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&(*dm)->defaultSF);CHKERRQ(ierr); 6958e4ac7eaSMatthew G. Knepley ierr = PetscSFDestroy(&(*dm)->sfNatural);CHKERRQ(ierr); 696af122d2aSMatthew G Knepley 69788bdff64SToby Isaac if ((*dm)->coarseMesh && (*dm)->coarseMesh->fineMesh == *dm) { 69888bdff64SToby Isaac ierr = DMSetFineDM((*dm)->coarseMesh,NULL);CHKERRQ(ierr); 69988bdff64SToby Isaac } 700a8fb8f29SToby Isaac ierr = DMDestroy(&(*dm)->coarseMesh);CHKERRQ(ierr); 70188bdff64SToby Isaac if ((*dm)->fineMesh && (*dm)->fineMesh->coarseMesh == *dm) { 70288bdff64SToby Isaac ierr = DMSetCoarseDM((*dm)->fineMesh,NULL);CHKERRQ(ierr); 70388bdff64SToby Isaac } 70488bdff64SToby Isaac ierr = DMDestroy(&(*dm)->fineMesh);CHKERRQ(ierr); 7056636e97aSMatthew G Knepley ierr = DMDestroy(&(*dm)->coordinateDM);CHKERRQ(ierr); 7066636e97aSMatthew G Knepley ierr = VecDestroy(&(*dm)->coordinates);CHKERRQ(ierr); 7076636e97aSMatthew G Knepley ierr = VecDestroy(&(*dm)->coordinatesLocal);CHKERRQ(ierr); 7085dc8c3f7SMatthew G. Knepley ierr = PetscFree3((*dm)->L,(*dm)->maxCell,(*dm)->bdtype);CHKERRQ(ierr); 7096636e97aSMatthew G Knepley 7102764a2aaSMatthew G. Knepley ierr = PetscDSDestroy(&(*dm)->prob);CHKERRQ(ierr); 71114f150ffSMatthew G. Knepley ierr = DMDestroy(&(*dm)->dmBC);CHKERRQ(ierr); 712e04113cfSBarry Smith /* if memory was published with SAWs then destroy it */ 713e04113cfSBarry Smith ierr = PetscObjectSAWsViewOff((PetscObject)*dm);CHKERRQ(ierr); 714732e2eb9SMatthew G Knepley 7156bf464f9SBarry Smith ierr = (*(*dm)->ops->destroy)(*dm);CHKERRQ(ierr); 716435a35e8SMatthew G Knepley /* We do not destroy (*dm)->data here so that we can reference count backend objects */ 717732e2eb9SMatthew G Knepley ierr = PetscHeaderDestroy(dm);CHKERRQ(ierr); 71847c6ae99SBarry Smith PetscFunctionReturn(0); 71947c6ae99SBarry Smith } 72047c6ae99SBarry Smith 72147c6ae99SBarry Smith #undef __FUNCT__ 722d7bf68aeSBarry Smith #define __FUNCT__ "DMSetUp" 723d7bf68aeSBarry Smith /*@ 724d7bf68aeSBarry Smith DMSetUp - sets up the data structures inside a DM object 725d7bf68aeSBarry Smith 726d7bf68aeSBarry Smith Collective on DM 727d7bf68aeSBarry Smith 728d7bf68aeSBarry Smith Input Parameter: 729d7bf68aeSBarry Smith . dm - the DM object to setup 730d7bf68aeSBarry Smith 731d7bf68aeSBarry Smith Level: developer 732d7bf68aeSBarry Smith 733e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 734d7bf68aeSBarry Smith 735d7bf68aeSBarry Smith @*/ 7367087cfbeSBarry Smith PetscErrorCode DMSetUp(DM dm) 737d7bf68aeSBarry Smith { 738d7bf68aeSBarry Smith PetscErrorCode ierr; 739d7bf68aeSBarry Smith 740d7bf68aeSBarry Smith PetscFunctionBegin; 741171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7428387afaaSJed Brown if (dm->setupcalled) PetscFunctionReturn(0); 743d7bf68aeSBarry Smith if (dm->ops->setup) { 744d7bf68aeSBarry Smith ierr = (*dm->ops->setup)(dm);CHKERRQ(ierr); 745d7bf68aeSBarry Smith } 7468387afaaSJed Brown dm->setupcalled = PETSC_TRUE; 747d7bf68aeSBarry Smith PetscFunctionReturn(0); 748d7bf68aeSBarry Smith } 749d7bf68aeSBarry Smith 750d7bf68aeSBarry Smith #undef __FUNCT__ 751d7bf68aeSBarry Smith #define __FUNCT__ "DMSetFromOptions" 752d7bf68aeSBarry Smith /*@ 753d7bf68aeSBarry Smith DMSetFromOptions - sets parameters in a DM from the options database 754d7bf68aeSBarry Smith 755d7bf68aeSBarry Smith Collective on DM 756d7bf68aeSBarry Smith 757d7bf68aeSBarry Smith Input Parameter: 758d7bf68aeSBarry Smith . dm - the DM object to set options for 759d7bf68aeSBarry Smith 760732e2eb9SMatthew G Knepley Options Database: 7614164ae61SDominic Meiser + -dm_preallocate_only - Only preallocate the matrix for DMCreateMatrix(), but do not fill it with zeros 7624164ae61SDominic Meiser . -dm_vec_type <type> - type of vector to create inside DM 7634164ae61SDominic Meiser . -dm_mat_type <type> - type of matrix to create inside DM 7644164ae61SDominic Meiser - -dm_coloring_type - <global or ghosted> 765732e2eb9SMatthew G Knepley 766d7bf68aeSBarry Smith Level: developer 767d7bf68aeSBarry Smith 768e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 769d7bf68aeSBarry Smith 770d7bf68aeSBarry Smith @*/ 7717087cfbeSBarry Smith PetscErrorCode DMSetFromOptions(DM dm) 772d7bf68aeSBarry Smith { 7737781c08eSBarry Smith char typeName[256]; 774ca266f36SBarry Smith PetscBool flg; 775d7bf68aeSBarry Smith PetscErrorCode ierr; 776d7bf68aeSBarry Smith 777d7bf68aeSBarry Smith PetscFunctionBegin; 778171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 779691be533SLawrence Mitchell if (dm->sf) { 780691be533SLawrence Mitchell ierr = PetscSFSetFromOptions(dm->sf);CHKERRQ(ierr); 781691be533SLawrence Mitchell } 782691be533SLawrence Mitchell if (dm->defaultSF) { 783691be533SLawrence Mitchell ierr = PetscSFSetFromOptions(dm->defaultSF);CHKERRQ(ierr); 784691be533SLawrence Mitchell } 7853194b578SJed Brown ierr = PetscObjectOptionsBegin((PetscObject)dm);CHKERRQ(ierr); 7860298fd71SBarry 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); 787a264d7a6SBarry Smith ierr = PetscOptionsFList("-dm_vec_type","Vector type used for created vectors","DMSetVecType",VecList,dm->vectype,typeName,256,&flg);CHKERRQ(ierr); 788f9ba7244SBarry Smith if (flg) { 789f9ba7244SBarry Smith ierr = DMSetVecType(dm,typeName);CHKERRQ(ierr); 790f9ba7244SBarry Smith } 791a264d7a6SBarry 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); 792073dac72SJed Brown if (flg) { 793521d9a4cSLisandro Dalcin ierr = DMSetMatType(dm,typeName);CHKERRQ(ierr); 794073dac72SJed Brown } 7950298fd71SBarry Smith ierr = PetscOptionsEnum("-dm_is_coloring_type","Global or local coloring of Jacobian","ISColoringType",ISColoringTypes,(PetscEnum)dm->coloringtype,(PetscEnum*)&dm->coloringtype,NULL);CHKERRQ(ierr); 796f9ba7244SBarry Smith if (dm->ops->setfromoptions) { 797e55864a3SBarry Smith ierr = (*dm->ops->setfromoptions)(PetscOptionsObject,dm);CHKERRQ(ierr); 798f9ba7244SBarry Smith } 799f9ba7244SBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 8000633abcbSJed Brown ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject) dm);CHKERRQ(ierr); 80182fcb398SMatthew G Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 802d7bf68aeSBarry Smith PetscFunctionReturn(0); 803d7bf68aeSBarry Smith } 804d7bf68aeSBarry Smith 805d7bf68aeSBarry Smith #undef __FUNCT__ 80647c6ae99SBarry Smith #define __FUNCT__ "DMView" 807fc9bc008SSatish Balay /*@C 808224748a4SBarry Smith DMView - Views a DM 80947c6ae99SBarry Smith 81047c6ae99SBarry Smith Collective on DM 81147c6ae99SBarry Smith 81247c6ae99SBarry Smith Input Parameter: 81347c6ae99SBarry Smith + dm - the DM object to view 81447c6ae99SBarry Smith - v - the viewer 81547c6ae99SBarry Smith 816224748a4SBarry Smith Level: beginner 81747c6ae99SBarry Smith 818e727c939SJed Brown .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 81947c6ae99SBarry Smith 82047c6ae99SBarry Smith @*/ 8217087cfbeSBarry Smith PetscErrorCode DMView(DM dm,PetscViewer v) 82247c6ae99SBarry Smith { 82347c6ae99SBarry Smith PetscErrorCode ierr; 82432c0f0efSBarry Smith PetscBool isbinary; 82547c6ae99SBarry Smith 82647c6ae99SBarry Smith PetscFunctionBegin; 827171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8283014e516SBarry Smith if (!v) { 829ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)dm),&v);CHKERRQ(ierr); 8303014e516SBarry Smith } 83198c3331eSBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)dm,v);CHKERRQ(ierr); 83232c0f0efSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); 83332c0f0efSBarry Smith if (isbinary) { 83455849f57SBarry Smith PetscInt classid = DM_FILE_CLASSID; 83532c0f0efSBarry Smith char type[256]; 83632c0f0efSBarry Smith 83732c0f0efSBarry Smith ierr = PetscViewerBinaryWrite(v,&classid,1,PETSC_INT,PETSC_FALSE);CHKERRQ(ierr); 83832c0f0efSBarry Smith ierr = PetscStrncpy(type,((PetscObject)dm)->type_name,256);CHKERRQ(ierr); 83932c0f0efSBarry Smith ierr = PetscViewerBinaryWrite(v,type,256,PETSC_CHAR,PETSC_FALSE);CHKERRQ(ierr); 84032c0f0efSBarry Smith } 8410c010503SBarry Smith if (dm->ops->view) { 8420c010503SBarry Smith ierr = (*dm->ops->view)(dm,v);CHKERRQ(ierr); 84347c6ae99SBarry Smith } 84447c6ae99SBarry Smith PetscFunctionReturn(0); 84547c6ae99SBarry Smith } 84647c6ae99SBarry Smith 84747c6ae99SBarry Smith #undef __FUNCT__ 84847c6ae99SBarry Smith #define __FUNCT__ "DMCreateGlobalVector" 84947c6ae99SBarry Smith /*@ 8508472ad0fSDave May DMCreateGlobalVector - Creates a global vector from a DM object 85147c6ae99SBarry Smith 85247c6ae99SBarry Smith Collective on DM 85347c6ae99SBarry Smith 85447c6ae99SBarry Smith Input Parameter: 85547c6ae99SBarry Smith . dm - the DM object 85647c6ae99SBarry Smith 85747c6ae99SBarry Smith Output Parameter: 85847c6ae99SBarry Smith . vec - the global vector 85947c6ae99SBarry Smith 860073dac72SJed Brown Level: beginner 86147c6ae99SBarry Smith 862e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 86347c6ae99SBarry Smith 86447c6ae99SBarry Smith @*/ 8657087cfbeSBarry Smith PetscErrorCode DMCreateGlobalVector(DM dm,Vec *vec) 86647c6ae99SBarry Smith { 86747c6ae99SBarry Smith PetscErrorCode ierr; 86847c6ae99SBarry Smith 86947c6ae99SBarry Smith PetscFunctionBegin; 870171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 87147c6ae99SBarry Smith ierr = (*dm->ops->createglobalvector)(dm,vec);CHKERRQ(ierr); 87247c6ae99SBarry Smith PetscFunctionReturn(0); 87347c6ae99SBarry Smith } 87447c6ae99SBarry Smith 87547c6ae99SBarry Smith #undef __FUNCT__ 87647c6ae99SBarry Smith #define __FUNCT__ "DMCreateLocalVector" 87747c6ae99SBarry Smith /*@ 8788472ad0fSDave May DMCreateLocalVector - Creates a local vector from a DM object 87947c6ae99SBarry Smith 88047c6ae99SBarry Smith Not Collective 88147c6ae99SBarry Smith 88247c6ae99SBarry Smith Input Parameter: 88347c6ae99SBarry Smith . dm - the DM object 88447c6ae99SBarry Smith 88547c6ae99SBarry Smith Output Parameter: 88647c6ae99SBarry Smith . vec - the local vector 88747c6ae99SBarry Smith 888073dac72SJed Brown Level: beginner 88947c6ae99SBarry Smith 890e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 89147c6ae99SBarry Smith 89247c6ae99SBarry Smith @*/ 8937087cfbeSBarry Smith PetscErrorCode DMCreateLocalVector(DM dm,Vec *vec) 89447c6ae99SBarry Smith { 89547c6ae99SBarry Smith PetscErrorCode ierr; 89647c6ae99SBarry Smith 89747c6ae99SBarry Smith PetscFunctionBegin; 898171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 89947c6ae99SBarry Smith ierr = (*dm->ops->createlocalvector)(dm,vec);CHKERRQ(ierr); 90047c6ae99SBarry Smith PetscFunctionReturn(0); 90147c6ae99SBarry Smith } 90247c6ae99SBarry Smith 90347c6ae99SBarry Smith #undef __FUNCT__ 9041411c6eeSJed Brown #define __FUNCT__ "DMGetLocalToGlobalMapping" 9051411c6eeSJed Brown /*@ 9061411c6eeSJed Brown DMGetLocalToGlobalMapping - Accesses the local-to-global mapping in a DM. 9071411c6eeSJed Brown 9081411c6eeSJed Brown Collective on DM 9091411c6eeSJed Brown 9101411c6eeSJed Brown Input Parameter: 9111411c6eeSJed Brown . dm - the DM that provides the mapping 9121411c6eeSJed Brown 9131411c6eeSJed Brown Output Parameter: 9141411c6eeSJed Brown . ltog - the mapping 9151411c6eeSJed Brown 9161411c6eeSJed Brown Level: intermediate 9171411c6eeSJed Brown 9181411c6eeSJed Brown Notes: 9191411c6eeSJed Brown This mapping can then be used by VecSetLocalToGlobalMapping() or 9201411c6eeSJed Brown MatSetLocalToGlobalMapping(). 9211411c6eeSJed Brown 922fc31e74dSBarry Smith .seealso: DMCreateLocalVector() 9231411c6eeSJed Brown @*/ 9247087cfbeSBarry Smith PetscErrorCode DMGetLocalToGlobalMapping(DM dm,ISLocalToGlobalMapping *ltog) 9251411c6eeSJed Brown { 926b190aa46SMatthew G. Knepley PetscInt bs = -1; 9271411c6eeSJed Brown PetscErrorCode ierr; 9281411c6eeSJed Brown 9291411c6eeSJed Brown PetscFunctionBegin; 9301411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 9311411c6eeSJed Brown PetscValidPointer(ltog,2); 9321411c6eeSJed Brown if (!dm->ltogmap) { 93337d0c07bSMatthew G Knepley PetscSection section, sectionGlobal; 93437d0c07bSMatthew G Knepley 93537d0c07bSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 93637d0c07bSMatthew G Knepley if (section) { 93737d0c07bSMatthew G Knepley PetscInt *ltog; 93837d0c07bSMatthew G Knepley PetscInt pStart, pEnd, size, p, l; 93937d0c07bSMatthew G Knepley 94037d0c07bSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 94137d0c07bSMatthew G Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 94237d0c07bSMatthew G Knepley ierr = PetscSectionGetStorageSize(section, &size);CHKERRQ(ierr); 943785e854fSJed Brown ierr = PetscMalloc1(size, <og);CHKERRQ(ierr); /* We want the local+overlap size */ 94437d0c07bSMatthew G Knepley for (p = pStart, l = 0; p < pEnd; ++p) { 945b190aa46SMatthew G. Knepley PetscInt bdof, cdof, dof, off, c; 94637d0c07bSMatthew G Knepley 94737d0c07bSMatthew G Knepley /* Should probably use constrained dofs */ 94837d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(section, p, &dof);CHKERRQ(ierr); 94937d0c07bSMatthew G Knepley ierr = PetscSectionGetOffset(sectionGlobal, p, &off);CHKERRQ(ierr); 950b190aa46SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(sectionGlobal, p, &cdof);CHKERRQ(ierr); 9511a7dc684SMatthew G. Knepley /* If you have dofs, and constraints, and they are unequal, we set the blocksize to 1 */ 9521a7dc684SMatthew G. Knepley bdof = cdof && (dof-cdof) ? 1 : dof; 9531a7dc684SMatthew G. Knepley if (dof) { 954b190aa46SMatthew G. Knepley if (bs < 0) {bs = bdof;} 955b190aa46SMatthew G. Knepley else if (bs != bdof) {bs = 1;} 9561a7dc684SMatthew G. Knepley } 95737d0c07bSMatthew G Knepley for (c = 0; c < dof; ++c, ++l) { 95837d0c07bSMatthew G Knepley ltog[l] = off+c; 95937d0c07bSMatthew G Knepley } 96037d0c07bSMatthew G Knepley } 961b190aa46SMatthew G. Knepley ierr = ISLocalToGlobalMappingCreate(PETSC_COMM_SELF, bs < 0 ? 1 : bs, size, ltog, PETSC_OWN_POINTER, &dm->ltogmap);CHKERRQ(ierr); 9623bb1ff40SBarry Smith ierr = PetscLogObjectParent((PetscObject)dm, (PetscObject)dm->ltogmap);CHKERRQ(ierr); 96337d0c07bSMatthew G Knepley } else { 964184d77edSJed Brown if (!dm->ops->getlocaltoglobalmapping) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM can not create LocalToGlobalMapping"); 965184d77edSJed Brown ierr = (*dm->ops->getlocaltoglobalmapping)(dm);CHKERRQ(ierr); 9661411c6eeSJed Brown } 96737d0c07bSMatthew G Knepley } 9681411c6eeSJed Brown *ltog = dm->ltogmap; 9691411c6eeSJed Brown PetscFunctionReturn(0); 9701411c6eeSJed Brown } 9711411c6eeSJed Brown 9721411c6eeSJed Brown #undef __FUNCT__ 9731411c6eeSJed Brown #define __FUNCT__ "DMGetBlockSize" 9741411c6eeSJed Brown /*@ 9751411c6eeSJed Brown DMGetBlockSize - Gets the inherent block size associated with a DM 9761411c6eeSJed Brown 9771411c6eeSJed Brown Not Collective 9781411c6eeSJed Brown 9791411c6eeSJed Brown Input Parameter: 9801411c6eeSJed Brown . dm - the DM with block structure 9811411c6eeSJed Brown 9821411c6eeSJed Brown Output Parameter: 9831411c6eeSJed Brown . bs - the block size, 1 implies no exploitable block structure 9841411c6eeSJed Brown 9851411c6eeSJed Brown Level: intermediate 9861411c6eeSJed Brown 987fc31e74dSBarry Smith .seealso: ISCreateBlock(), VecSetBlockSize(), MatSetBlockSize(), DMGetLocalToGlobalMapping() 9881411c6eeSJed Brown @*/ 9897087cfbeSBarry Smith PetscErrorCode DMGetBlockSize(DM dm,PetscInt *bs) 9901411c6eeSJed Brown { 9911411c6eeSJed Brown PetscFunctionBegin; 9921411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 9931411c6eeSJed Brown PetscValidPointer(bs,2); 9941411c6eeSJed 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"); 9951411c6eeSJed Brown *bs = dm->bs; 9961411c6eeSJed Brown PetscFunctionReturn(0); 9971411c6eeSJed Brown } 9981411c6eeSJed Brown 9991411c6eeSJed Brown #undef __FUNCT__ 1000e727c939SJed Brown #define __FUNCT__ "DMCreateInterpolation" 100147c6ae99SBarry Smith /*@ 10028472ad0fSDave May DMCreateInterpolation - Gets interpolation matrix between two DM objects 100347c6ae99SBarry Smith 100447c6ae99SBarry Smith Collective on DM 100547c6ae99SBarry Smith 100647c6ae99SBarry Smith Input Parameter: 100747c6ae99SBarry Smith + dm1 - the DM object 100847c6ae99SBarry Smith - dm2 - the second, finer DM object 100947c6ae99SBarry Smith 101047c6ae99SBarry Smith Output Parameter: 101147c6ae99SBarry Smith + mat - the interpolation 101247c6ae99SBarry Smith - vec - the scaling (optional) 101347c6ae99SBarry Smith 101447c6ae99SBarry Smith Level: developer 101547c6ae99SBarry Smith 101685afcc9aSBarry 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 101785afcc9aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the interpolation. 1018d52bd9f3SBarry Smith 10191f588964SMatthew G Knepley For DMDA objects you can use this interpolation (more precisely the interpolation from the DMGetCoordinateDM()) to interpolate the mesh coordinate vectors 1020d52bd9f3SBarry Smith EXCEPT in the periodic case where it does not make sense since the coordinate vectors are not periodic. 102185afcc9aSBarry Smith 102285afcc9aSBarry Smith 10233ad4599aSBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMRefine(), DMCoarsen(), DMCreateRestriction() 102447c6ae99SBarry Smith 102547c6ae99SBarry Smith @*/ 1026e727c939SJed Brown PetscErrorCode DMCreateInterpolation(DM dm1,DM dm2,Mat *mat,Vec *vec) 102747c6ae99SBarry Smith { 102847c6ae99SBarry Smith PetscErrorCode ierr; 102947c6ae99SBarry Smith 103047c6ae99SBarry Smith PetscFunctionBegin; 1031171400e9SBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 1032171400e9SBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 1033cea54e9dSPatrick Farrell ierr = PetscLogEventBegin(DM_CreateInterpolation,dm1,dm2,0,0);CHKERRQ(ierr); 103425296bd5SBarry Smith ierr = (*dm1->ops->createinterpolation)(dm1,dm2,mat,vec);CHKERRQ(ierr); 1035cea54e9dSPatrick Farrell ierr = PetscLogEventEnd(DM_CreateInterpolation,dm1,dm2,0,0);CHKERRQ(ierr); 103647c6ae99SBarry Smith PetscFunctionReturn(0); 103747c6ae99SBarry Smith } 103847c6ae99SBarry Smith 103947c6ae99SBarry Smith #undef __FUNCT__ 10403ad4599aSBarry Smith #define __FUNCT__ "DMCreateRestriction" 10413ad4599aSBarry Smith /*@ 10423ad4599aSBarry Smith DMCreateRestriction - Gets restriction matrix between two DM objects 10433ad4599aSBarry Smith 10443ad4599aSBarry Smith Collective on DM 10453ad4599aSBarry Smith 10463ad4599aSBarry Smith Input Parameter: 10473ad4599aSBarry Smith + dm1 - the DM object 10483ad4599aSBarry Smith - dm2 - the second, finer DM object 10493ad4599aSBarry Smith 10503ad4599aSBarry Smith Output Parameter: 10513ad4599aSBarry Smith . mat - the restriction 10523ad4599aSBarry Smith 10533ad4599aSBarry Smith 10543ad4599aSBarry Smith Level: developer 10553ad4599aSBarry Smith 10563ad4599aSBarry 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 10573ad4599aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the interpolation. 10583ad4599aSBarry Smith 10593ad4599aSBarry Smith 10603ad4599aSBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMRefine(), DMCoarsen(), DMCreateInterpolation() 10613ad4599aSBarry Smith 10623ad4599aSBarry Smith @*/ 10633ad4599aSBarry Smith PetscErrorCode DMCreateRestriction(DM dm1,DM dm2,Mat *mat) 10643ad4599aSBarry Smith { 10653ad4599aSBarry Smith PetscErrorCode ierr; 10663ad4599aSBarry Smith 10673ad4599aSBarry Smith PetscFunctionBegin; 10683ad4599aSBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 10693ad4599aSBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 10703ad4599aSBarry Smith ierr = PetscLogEventBegin(DM_CreateRestriction,dm1,dm2,0,0);CHKERRQ(ierr); 10713ad4599aSBarry Smith ierr = (*dm1->ops->createrestriction)(dm1,dm2,mat);CHKERRQ(ierr); 10723ad4599aSBarry Smith ierr = PetscLogEventEnd(DM_CreateRestriction,dm1,dm2,0,0);CHKERRQ(ierr); 10733ad4599aSBarry Smith PetscFunctionReturn(0); 10743ad4599aSBarry Smith } 10753ad4599aSBarry Smith 10763ad4599aSBarry Smith #undef __FUNCT__ 1077e727c939SJed Brown #define __FUNCT__ "DMCreateInjection" 107847c6ae99SBarry Smith /*@ 10798472ad0fSDave May DMCreateInjection - Gets injection matrix between two DM objects 108047c6ae99SBarry Smith 108147c6ae99SBarry Smith Collective on DM 108247c6ae99SBarry Smith 108347c6ae99SBarry Smith Input Parameter: 108447c6ae99SBarry Smith + dm1 - the DM object 108547c6ae99SBarry Smith - dm2 - the second, finer DM object 108647c6ae99SBarry Smith 108747c6ae99SBarry Smith Output Parameter: 10886dbf9973SLawrence Mitchell . mat - the injection 108947c6ae99SBarry Smith 109047c6ae99SBarry Smith Level: developer 109147c6ae99SBarry Smith 109285afcc9aSBarry 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 109385afcc9aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the injection. 109485afcc9aSBarry Smith 1095e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMCreateInterpolation() 109647c6ae99SBarry Smith 109747c6ae99SBarry Smith @*/ 10986dbf9973SLawrence Mitchell PetscErrorCode DMCreateInjection(DM dm1,DM dm2,Mat *mat) 109947c6ae99SBarry Smith { 110047c6ae99SBarry Smith PetscErrorCode ierr; 110147c6ae99SBarry Smith 110247c6ae99SBarry Smith PetscFunctionBegin; 1103171400e9SBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 1104171400e9SBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 110523384938SToby Isaac if (!*dm1->ops->getinjection) SETERRQ(PetscObjectComm((PetscObject)dm1),PETSC_ERR_SUP,"DMCreateInjection not implemented for this type"); 11066dbf9973SLawrence Mitchell ierr = (*dm1->ops->getinjection)(dm1,dm2,mat);CHKERRQ(ierr); 110747c6ae99SBarry Smith PetscFunctionReturn(0); 110847c6ae99SBarry Smith } 110947c6ae99SBarry Smith 111047c6ae99SBarry Smith #undef __FUNCT__ 1111e727c939SJed Brown #define __FUNCT__ "DMCreateColoring" 1112b412c318SBarry Smith /*@ 1113b412c318SBarry Smith DMCreateColoring - Gets coloring for a DM 111447c6ae99SBarry Smith 111547c6ae99SBarry Smith Collective on DM 111647c6ae99SBarry Smith 111747c6ae99SBarry Smith Input Parameter: 111847c6ae99SBarry Smith + dm - the DM object 1119b412c318SBarry Smith - ctype - IS_COLORING_GHOSTED or IS_COLORING_GLOBAL 112047c6ae99SBarry Smith 112147c6ae99SBarry Smith Output Parameter: 112247c6ae99SBarry Smith . coloring - the coloring 112347c6ae99SBarry Smith 112447c6ae99SBarry Smith Level: developer 112547c6ae99SBarry Smith 1126b412c318SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateMatrix(), DMSetMatType() 112747c6ae99SBarry Smith 1128aab9d709SJed Brown @*/ 1129b412c318SBarry Smith PetscErrorCode DMCreateColoring(DM dm,ISColoringType ctype,ISColoring *coloring) 113047c6ae99SBarry Smith { 113147c6ae99SBarry Smith PetscErrorCode ierr; 113247c6ae99SBarry Smith 113347c6ae99SBarry Smith PetscFunctionBegin; 1134171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1135ce94432eSBarry Smith if (!dm->ops->getcoloring) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No coloring for this type of DM yet"); 1136b412c318SBarry Smith ierr = (*dm->ops->getcoloring)(dm,ctype,coloring);CHKERRQ(ierr); 113747c6ae99SBarry Smith PetscFunctionReturn(0); 113847c6ae99SBarry Smith } 113947c6ae99SBarry Smith 114047c6ae99SBarry Smith #undef __FUNCT__ 1141950540a4SJed Brown #define __FUNCT__ "DMCreateMatrix" 1142b412c318SBarry Smith /*@ 11438472ad0fSDave May DMCreateMatrix - Gets empty Jacobian for a DM 114447c6ae99SBarry Smith 114547c6ae99SBarry Smith Collective on DM 114647c6ae99SBarry Smith 114747c6ae99SBarry Smith Input Parameter: 1148b412c318SBarry Smith . dm - the DM object 114947c6ae99SBarry Smith 115047c6ae99SBarry Smith Output Parameter: 115147c6ae99SBarry Smith . mat - the empty Jacobian 115247c6ae99SBarry Smith 1153073dac72SJed Brown Level: beginner 115447c6ae99SBarry Smith 115594013140SBarry Smith Notes: This properly preallocates the number of nonzeros in the sparse matrix so you 115694013140SBarry Smith do not need to do it yourself. 115794013140SBarry Smith 115894013140SBarry Smith By default it also sets the nonzero structure and puts in the zero entries. To prevent setting 1159aa219208SBarry Smith the nonzero pattern call DMDASetMatPreallocateOnly() 116094013140SBarry Smith 116194013140SBarry 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 116294013140SBarry Smith internally by PETSc. 116394013140SBarry Smith 116494013140SBarry Smith For structured grid problems, in general it is easiest to use MatSetValuesStencil() or MatSetValuesLocal() to put values into the matrix because MatSetValues() requires 1165aa219208SBarry Smith the indices for the global numbering for DMDAs which is complicated. 116694013140SBarry Smith 1167b412c318SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMSetMatType() 116847c6ae99SBarry Smith 1169aab9d709SJed Brown @*/ 1170b412c318SBarry Smith PetscErrorCode DMCreateMatrix(DM dm,Mat *mat) 117147c6ae99SBarry Smith { 117247c6ae99SBarry Smith PetscErrorCode ierr; 117347c6ae99SBarry Smith 117447c6ae99SBarry Smith PetscFunctionBegin; 1175171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1176607a6623SBarry Smith ierr = MatInitializePackage();CHKERRQ(ierr); 1177c7b7c8a4SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1178c7b7c8a4SJed Brown PetscValidPointer(mat,3); 1179b412c318SBarry Smith ierr = (*dm->ops->creatematrix)(dm,mat);CHKERRQ(ierr); 118047c6ae99SBarry Smith PetscFunctionReturn(0); 118147c6ae99SBarry Smith } 118247c6ae99SBarry Smith 118347c6ae99SBarry Smith #undef __FUNCT__ 1184732e2eb9SMatthew G Knepley #define __FUNCT__ "DMSetMatrixPreallocateOnly" 1185732e2eb9SMatthew G Knepley /*@ 1186950540a4SJed Brown DMSetMatrixPreallocateOnly - When DMCreateMatrix() is called the matrix will be properly 1187732e2eb9SMatthew G Knepley preallocated but the nonzero structure and zero values will not be set. 1188732e2eb9SMatthew G Knepley 11898472ad0fSDave May Logically Collective on DM 1190732e2eb9SMatthew G Knepley 1191732e2eb9SMatthew G Knepley Input Parameter: 1192732e2eb9SMatthew G Knepley + dm - the DM 1193732e2eb9SMatthew G Knepley - only - PETSC_TRUE if only want preallocation 1194732e2eb9SMatthew G Knepley 1195732e2eb9SMatthew G Knepley Level: developer 1196950540a4SJed Brown .seealso DMCreateMatrix() 1197732e2eb9SMatthew G Knepley @*/ 1198732e2eb9SMatthew G Knepley PetscErrorCode DMSetMatrixPreallocateOnly(DM dm, PetscBool only) 1199732e2eb9SMatthew G Knepley { 1200732e2eb9SMatthew G Knepley PetscFunctionBegin; 1201732e2eb9SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1202732e2eb9SMatthew G Knepley dm->prealloc_only = only; 1203732e2eb9SMatthew G Knepley PetscFunctionReturn(0); 1204732e2eb9SMatthew G Knepley } 1205732e2eb9SMatthew G Knepley 1206732e2eb9SMatthew G Knepley #undef __FUNCT__ 1207a89ea682SMatthew G Knepley #define __FUNCT__ "DMGetWorkArray" 1208a89ea682SMatthew G Knepley /*@C 1209aa1993deSMatthew G Knepley DMGetWorkArray - Gets a work array guaranteed to be at least the input size, restore with DMRestoreWorkArray() 1210a89ea682SMatthew G Knepley 1211a89ea682SMatthew G Knepley Not Collective 1212a89ea682SMatthew G Knepley 1213a89ea682SMatthew G Knepley Input Parameters: 1214a89ea682SMatthew G Knepley + dm - the DM object 1215aa1993deSMatthew G Knepley . count - The minium size 1216aa1993deSMatthew G Knepley - dtype - data type (PETSC_REAL, PETSC_SCALAR, PETSC_INT) 1217a89ea682SMatthew G Knepley 1218a89ea682SMatthew G Knepley Output Parameter: 1219a89ea682SMatthew G Knepley . array - the work array 1220a89ea682SMatthew G Knepley 1221a89ea682SMatthew G Knepley Level: developer 1222a89ea682SMatthew G Knepley 1223a89ea682SMatthew G Knepley .seealso DMDestroy(), DMCreate() 1224a89ea682SMatthew G Knepley @*/ 1225aa1993deSMatthew G Knepley PetscErrorCode DMGetWorkArray(DM dm,PetscInt count,PetscDataType dtype,void *mem) 1226a89ea682SMatthew G Knepley { 1227a89ea682SMatthew G Knepley PetscErrorCode ierr; 1228aa1993deSMatthew G Knepley DMWorkLink link; 1229854ce69bSBarry Smith size_t dsize; 1230a89ea682SMatthew G Knepley 1231a89ea682SMatthew G Knepley PetscFunctionBegin; 1232a89ea682SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1233aa1993deSMatthew G Knepley PetscValidPointer(mem,4); 1234aa1993deSMatthew G Knepley if (dm->workin) { 1235aa1993deSMatthew G Knepley link = dm->workin; 1236aa1993deSMatthew G Knepley dm->workin = dm->workin->next; 1237aa1993deSMatthew G Knepley } else { 1238b00a9115SJed Brown ierr = PetscNewLog(dm,&link);CHKERRQ(ierr); 1239a89ea682SMatthew G Knepley } 1240854ce69bSBarry Smith ierr = PetscDataTypeGetSize(dtype,&dsize);CHKERRQ(ierr); 1241854ce69bSBarry Smith if (dsize*count > link->bytes) { 1242aa1993deSMatthew G Knepley ierr = PetscFree(link->mem);CHKERRQ(ierr); 1243854ce69bSBarry Smith ierr = PetscMalloc(dsize*count,&link->mem);CHKERRQ(ierr); 1244854ce69bSBarry Smith link->bytes = dsize*count; 1245aa1993deSMatthew G Knepley } 1246aa1993deSMatthew G Knepley link->next = dm->workout; 1247aa1993deSMatthew G Knepley dm->workout = link; 1248aa1993deSMatthew G Knepley *(void**)mem = link->mem; 1249a89ea682SMatthew G Knepley PetscFunctionReturn(0); 1250a89ea682SMatthew G Knepley } 1251a89ea682SMatthew G Knepley 1252aa1993deSMatthew G Knepley #undef __FUNCT__ 1253aa1993deSMatthew G Knepley #define __FUNCT__ "DMRestoreWorkArray" 1254aa1993deSMatthew G Knepley /*@C 1255aa1993deSMatthew G Knepley DMRestoreWorkArray - Restores a work array guaranteed to be at least the input size, restore with DMRestoreWorkArray() 1256aa1993deSMatthew G Knepley 1257aa1993deSMatthew G Knepley Not Collective 1258aa1993deSMatthew G Knepley 1259aa1993deSMatthew G Knepley Input Parameters: 1260aa1993deSMatthew G Knepley + dm - the DM object 1261aa1993deSMatthew G Knepley . count - The minium size 1262aa1993deSMatthew G Knepley - dtype - data type (PETSC_REAL, PETSC_SCALAR, PETSC_INT) 1263aa1993deSMatthew G Knepley 1264aa1993deSMatthew G Knepley Output Parameter: 1265aa1993deSMatthew G Knepley . array - the work array 1266aa1993deSMatthew G Knepley 1267aa1993deSMatthew G Knepley Level: developer 1268aa1993deSMatthew G Knepley 1269aa1993deSMatthew G Knepley .seealso DMDestroy(), DMCreate() 1270aa1993deSMatthew G Knepley @*/ 1271aa1993deSMatthew G Knepley PetscErrorCode DMRestoreWorkArray(DM dm,PetscInt count,PetscDataType dtype,void *mem) 1272aa1993deSMatthew G Knepley { 1273aa1993deSMatthew G Knepley DMWorkLink *p,link; 1274aa1993deSMatthew G Knepley 1275aa1993deSMatthew G Knepley PetscFunctionBegin; 1276aa1993deSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1277aa1993deSMatthew G Knepley PetscValidPointer(mem,4); 1278aa1993deSMatthew G Knepley for (p=&dm->workout; (link=*p); p=&link->next) { 1279aa1993deSMatthew G Knepley if (link->mem == *(void**)mem) { 1280aa1993deSMatthew G Knepley *p = link->next; 1281aa1993deSMatthew G Knepley link->next = dm->workin; 1282aa1993deSMatthew G Knepley dm->workin = link; 12830298fd71SBarry Smith *(void**)mem = NULL; 1284aa1993deSMatthew G Knepley PetscFunctionReturn(0); 1285aa1993deSMatthew G Knepley } 1286aa1993deSMatthew G Knepley } 1287aa1993deSMatthew G Knepley SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Array was not checked out"); 1288aa1993deSMatthew G Knepley } 1289e7c4fc90SDmitry Karpeev 1290e7c4fc90SDmitry Karpeev #undef __FUNCT__ 1291435a35e8SMatthew G Knepley #define __FUNCT__ "DMSetNullSpaceConstructor" 1292435a35e8SMatthew G Knepley PetscErrorCode DMSetNullSpaceConstructor(DM dm, PetscInt field, PetscErrorCode (*nullsp)(DM dm, PetscInt field, MatNullSpace *nullSpace)) 1293435a35e8SMatthew G Knepley { 1294435a35e8SMatthew G Knepley PetscFunctionBegin; 1295435a35e8SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 129682f516ccSBarry Smith if (field >= 10) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cannot handle %d >= 10 fields", field); 1297435a35e8SMatthew G Knepley dm->nullspaceConstructors[field] = nullsp; 1298435a35e8SMatthew G Knepley PetscFunctionReturn(0); 1299435a35e8SMatthew G Knepley } 1300435a35e8SMatthew G Knepley 1301435a35e8SMatthew G Knepley #undef __FUNCT__ 13024d343eeaSMatthew G Knepley #define __FUNCT__ "DMCreateFieldIS" 13034f3b5142SJed Brown /*@C 13044d343eeaSMatthew G Knepley DMCreateFieldIS - Creates a set of IS objects with the global indices of dofs for each field 13054d343eeaSMatthew G Knepley 13064d343eeaSMatthew G Knepley Not collective 13074d343eeaSMatthew G Knepley 13084d343eeaSMatthew G Knepley Input Parameter: 13094d343eeaSMatthew G Knepley . dm - the DM object 13104d343eeaSMatthew G Knepley 13114d343eeaSMatthew G Knepley Output Parameters: 13120298fd71SBarry Smith + numFields - The number of fields (or NULL if not requested) 13130298fd71SBarry Smith . fieldNames - The name for each field (or NULL if not requested) 13140298fd71SBarry Smith - fields - The global indices for each field (or NULL if not requested) 13154d343eeaSMatthew G Knepley 13164d343eeaSMatthew G Knepley Level: intermediate 13174d343eeaSMatthew G Knepley 131821c9b008SJed Brown Notes: 131921c9b008SJed Brown The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 132021c9b008SJed Brown PetscFree(), every entry of fields should be destroyed with ISDestroy(), and both arrays should be freed with 132121c9b008SJed Brown PetscFree(). 132221c9b008SJed Brown 13234d343eeaSMatthew G Knepley .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 13244d343eeaSMatthew G Knepley @*/ 132537d0c07bSMatthew G Knepley PetscErrorCode DMCreateFieldIS(DM dm, PetscInt *numFields, char ***fieldNames, IS **fields) 13264d343eeaSMatthew G Knepley { 132737d0c07bSMatthew G Knepley PetscSection section, sectionGlobal; 13284d343eeaSMatthew G Knepley PetscErrorCode ierr; 13294d343eeaSMatthew G Knepley 13304d343eeaSMatthew G Knepley PetscFunctionBegin; 13314d343eeaSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 133269ca1f37SDmitry Karpeev if (numFields) { 133369ca1f37SDmitry Karpeev PetscValidPointer(numFields,2); 133469ca1f37SDmitry Karpeev *numFields = 0; 133569ca1f37SDmitry Karpeev } 133637d0c07bSMatthew G Knepley if (fieldNames) { 133737d0c07bSMatthew G Knepley PetscValidPointer(fieldNames,3); 13380298fd71SBarry Smith *fieldNames = NULL; 133969ca1f37SDmitry Karpeev } 134069ca1f37SDmitry Karpeev if (fields) { 134169ca1f37SDmitry Karpeev PetscValidPointer(fields,4); 13420298fd71SBarry Smith *fields = NULL; 134369ca1f37SDmitry Karpeev } 134437d0c07bSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 134537d0c07bSMatthew G Knepley if (section) { 134637d0c07bSMatthew G Knepley PetscInt *fieldSizes, **fieldIndices; 134737d0c07bSMatthew G Knepley PetscInt nF, f, pStart, pEnd, p; 134837d0c07bSMatthew G Knepley 134937d0c07bSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 135037d0c07bSMatthew G Knepley ierr = PetscSectionGetNumFields(section, &nF);CHKERRQ(ierr); 1351dcca6d9dSJed Brown ierr = PetscMalloc2(nF,&fieldSizes,nF,&fieldIndices);CHKERRQ(ierr); 135237d0c07bSMatthew G Knepley ierr = PetscSectionGetChart(sectionGlobal, &pStart, &pEnd);CHKERRQ(ierr); 135337d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 135437d0c07bSMatthew G Knepley fieldSizes[f] = 0; 135537d0c07bSMatthew G Knepley } 135637d0c07bSMatthew G Knepley for (p = pStart; p < pEnd; ++p) { 135737d0c07bSMatthew G Knepley PetscInt gdof; 135837d0c07bSMatthew G Knepley 135937d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 136037d0c07bSMatthew G Knepley if (gdof > 0) { 136137d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 136237d0c07bSMatthew G Knepley PetscInt fdof, fcdof; 136337d0c07bSMatthew G Knepley 136437d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldDof(section, p, f, &fdof);CHKERRQ(ierr); 136537d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 136637d0c07bSMatthew G Knepley fieldSizes[f] += fdof-fcdof; 136737d0c07bSMatthew G Knepley } 136837d0c07bSMatthew G Knepley } 136937d0c07bSMatthew G Knepley } 137037d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 1371785e854fSJed Brown ierr = PetscMalloc1(fieldSizes[f], &fieldIndices[f]);CHKERRQ(ierr); 137237d0c07bSMatthew G Knepley fieldSizes[f] = 0; 137337d0c07bSMatthew G Knepley } 137437d0c07bSMatthew G Knepley for (p = pStart; p < pEnd; ++p) { 137537d0c07bSMatthew G Knepley PetscInt gdof, goff; 137637d0c07bSMatthew G Knepley 137737d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 137837d0c07bSMatthew G Knepley if (gdof > 0) { 137937d0c07bSMatthew G Knepley ierr = PetscSectionGetOffset(sectionGlobal, p, &goff);CHKERRQ(ierr); 138037d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 138137d0c07bSMatthew G Knepley PetscInt fdof, fcdof, fc; 138237d0c07bSMatthew G Knepley 138337d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldDof(section, p, f, &fdof);CHKERRQ(ierr); 138437d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 138537d0c07bSMatthew G Knepley for (fc = 0; fc < fdof-fcdof; ++fc, ++fieldSizes[f]) { 138637d0c07bSMatthew G Knepley fieldIndices[f][fieldSizes[f]] = goff++; 138737d0c07bSMatthew G Knepley } 138837d0c07bSMatthew G Knepley } 138937d0c07bSMatthew G Knepley } 139037d0c07bSMatthew G Knepley } 13918865f1eaSKarl Rupp if (numFields) *numFields = nF; 139237d0c07bSMatthew G Knepley if (fieldNames) { 1393785e854fSJed Brown ierr = PetscMalloc1(nF, fieldNames);CHKERRQ(ierr); 139437d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 139537d0c07bSMatthew G Knepley const char *fieldName; 139637d0c07bSMatthew G Knepley 139737d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldName(section, f, &fieldName);CHKERRQ(ierr); 139837d0c07bSMatthew G Knepley ierr = PetscStrallocpy(fieldName, (char**) &(*fieldNames)[f]);CHKERRQ(ierr); 139937d0c07bSMatthew G Knepley } 140037d0c07bSMatthew G Knepley } 140137d0c07bSMatthew G Knepley if (fields) { 1402785e854fSJed Brown ierr = PetscMalloc1(nF, fields);CHKERRQ(ierr); 140337d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 140482f516ccSBarry Smith ierr = ISCreateGeneral(PetscObjectComm((PetscObject)dm), fieldSizes[f], fieldIndices[f], PETSC_OWN_POINTER, &(*fields)[f]);CHKERRQ(ierr); 140537d0c07bSMatthew G Knepley } 140637d0c07bSMatthew G Knepley } 140737d0c07bSMatthew G Knepley ierr = PetscFree2(fieldSizes,fieldIndices);CHKERRQ(ierr); 14088865f1eaSKarl Rupp } else if (dm->ops->createfieldis) { 14098865f1eaSKarl Rupp ierr = (*dm->ops->createfieldis)(dm, numFields, fieldNames, fields);CHKERRQ(ierr); 141069ca1f37SDmitry Karpeev } 14114d343eeaSMatthew G Knepley PetscFunctionReturn(0); 14124d343eeaSMatthew G Knepley } 14134d343eeaSMatthew G Knepley 141416621825SDmitry Karpeev 141516621825SDmitry Karpeev #undef __FUNCT__ 141616621825SDmitry Karpeev #define __FUNCT__ "DMCreateFieldDecomposition" 141716621825SDmitry Karpeev /*@C 141816621825SDmitry Karpeev DMCreateFieldDecomposition - Returns a list of IS objects defining a decomposition of a problem into subproblems 141916621825SDmitry Karpeev corresponding to different fields: each IS contains the global indices of the dofs of the 142016621825SDmitry Karpeev corresponding field. The optional list of DMs define the DM for each subproblem. 1421e7c4fc90SDmitry Karpeev Generalizes DMCreateFieldIS(). 1422e7c4fc90SDmitry Karpeev 1423e7c4fc90SDmitry Karpeev Not collective 1424e7c4fc90SDmitry Karpeev 1425e7c4fc90SDmitry Karpeev Input Parameter: 1426e7c4fc90SDmitry Karpeev . dm - the DM object 1427e7c4fc90SDmitry Karpeev 1428e7c4fc90SDmitry Karpeev Output Parameters: 14290298fd71SBarry Smith + len - The number of subproblems in the field decomposition (or NULL if not requested) 14300298fd71SBarry Smith . namelist - The name for each field (or NULL if not requested) 14310298fd71SBarry Smith . islist - The global indices for each field (or NULL if not requested) 14320298fd71SBarry Smith - dmlist - The DMs for each field subproblem (or NULL, if not requested; if NULL is returned, no DMs are defined) 1433e7c4fc90SDmitry Karpeev 1434e7c4fc90SDmitry Karpeev Level: intermediate 1435e7c4fc90SDmitry Karpeev 1436e7c4fc90SDmitry Karpeev Notes: 1437e7c4fc90SDmitry Karpeev The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 1438e7c4fc90SDmitry Karpeev PetscFree(), every entry of is should be destroyed with ISDestroy(), every entry of dm should be destroyed with DMDestroy(), 1439e7c4fc90SDmitry Karpeev and all of the arrays should be freed with PetscFree(). 1440e7c4fc90SDmitry Karpeev 1441e7c4fc90SDmitry Karpeev .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1442e7c4fc90SDmitry Karpeev @*/ 144316621825SDmitry Karpeev PetscErrorCode DMCreateFieldDecomposition(DM dm, PetscInt *len, char ***namelist, IS **islist, DM **dmlist) 1444e7c4fc90SDmitry Karpeev { 1445e7c4fc90SDmitry Karpeev PetscErrorCode ierr; 1446e7c4fc90SDmitry Karpeev 1447e7c4fc90SDmitry Karpeev PetscFunctionBegin; 1448e7c4fc90SDmitry Karpeev PetscValidHeaderSpecific(dm,DM_CLASSID,1); 14498865f1eaSKarl Rupp if (len) { 14508865f1eaSKarl Rupp PetscValidPointer(len,2); 14518865f1eaSKarl Rupp *len = 0; 14528865f1eaSKarl Rupp } 14538865f1eaSKarl Rupp if (namelist) { 14548865f1eaSKarl Rupp PetscValidPointer(namelist,3); 14558865f1eaSKarl Rupp *namelist = 0; 14568865f1eaSKarl Rupp } 14578865f1eaSKarl Rupp if (islist) { 14588865f1eaSKarl Rupp PetscValidPointer(islist,4); 14598865f1eaSKarl Rupp *islist = 0; 14608865f1eaSKarl Rupp } 14618865f1eaSKarl Rupp if (dmlist) { 14628865f1eaSKarl Rupp PetscValidPointer(dmlist,5); 14638865f1eaSKarl Rupp *dmlist = 0; 14648865f1eaSKarl Rupp } 1465f3f0edfdSDmitry Karpeev /* 1466f3f0edfdSDmitry Karpeev Is it a good idea to apply the following check across all impls? 1467f3f0edfdSDmitry Karpeev Perhaps some impls can have a well-defined decomposition before DMSetUp? 1468f3f0edfdSDmitry Karpeev This, however, follows the general principle that accessors are not well-behaved until the object is set up. 1469f3f0edfdSDmitry Karpeev */ 1470ce94432eSBarry Smith if (!dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE, "Decomposition defined only after DMSetUp"); 147116621825SDmitry Karpeev if (!dm->ops->createfielddecomposition) { 1472435a35e8SMatthew G Knepley PetscSection section; 1473435a35e8SMatthew G Knepley PetscInt numFields, f; 1474435a35e8SMatthew G Knepley 1475435a35e8SMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 1476435a35e8SMatthew G Knepley if (section) {ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr);} 1477435a35e8SMatthew G Knepley if (section && numFields && dm->ops->createsubdm) { 1478f25d98f1SMatthew G. Knepley if (len) *len = numFields; 147903dc3394SMatthew G. Knepley if (namelist) {ierr = PetscMalloc1(numFields,namelist);CHKERRQ(ierr);} 148003dc3394SMatthew G. Knepley if (islist) {ierr = PetscMalloc1(numFields,islist);CHKERRQ(ierr);} 148103dc3394SMatthew G. Knepley if (dmlist) {ierr = PetscMalloc1(numFields,dmlist);CHKERRQ(ierr);} 1482435a35e8SMatthew G Knepley for (f = 0; f < numFields; ++f) { 1483435a35e8SMatthew G Knepley const char *fieldName; 1484435a35e8SMatthew G Knepley 148503dc3394SMatthew G. Knepley ierr = DMCreateSubDM(dm, 1, &f, islist ? &(*islist)[f] : NULL, dmlist ? &(*dmlist)[f] : NULL);CHKERRQ(ierr); 148603dc3394SMatthew G. Knepley if (namelist) { 1487435a35e8SMatthew G Knepley ierr = PetscSectionGetFieldName(section, f, &fieldName);CHKERRQ(ierr); 1488435a35e8SMatthew G Knepley ierr = PetscStrallocpy(fieldName, (char**) &(*namelist)[f]);CHKERRQ(ierr); 1489435a35e8SMatthew G Knepley } 149003dc3394SMatthew G. Knepley } 1491435a35e8SMatthew G Knepley } else { 149269ca1f37SDmitry Karpeev ierr = DMCreateFieldIS(dm, len, namelist, islist);CHKERRQ(ierr); 1493e7c4fc90SDmitry Karpeev /* By default there are no DMs associated with subproblems. */ 14940298fd71SBarry Smith if (dmlist) *dmlist = NULL; 1495e7c4fc90SDmitry Karpeev } 14968865f1eaSKarl Rupp } else { 149716621825SDmitry Karpeev ierr = (*dm->ops->createfielddecomposition)(dm,len,namelist,islist,dmlist);CHKERRQ(ierr); 149816621825SDmitry Karpeev } 149916621825SDmitry Karpeev PetscFunctionReturn(0); 150016621825SDmitry Karpeev } 150116621825SDmitry Karpeev 150216621825SDmitry Karpeev #undef __FUNCT__ 1503435a35e8SMatthew G Knepley #define __FUNCT__ "DMCreateSubDM" 1504564cec59SMatthew G. Knepley /*@ 1505435a35e8SMatthew G Knepley DMCreateSubDM - Returns an IS and DM encapsulating a subproblem defined by the fields passed in. 1506435a35e8SMatthew G Knepley The fields are defined by DMCreateFieldIS(). 1507435a35e8SMatthew G Knepley 1508435a35e8SMatthew G Knepley Not collective 1509435a35e8SMatthew G Knepley 1510435a35e8SMatthew G Knepley Input Parameters: 1511435a35e8SMatthew G Knepley + dm - the DM object 1512435a35e8SMatthew G Knepley . numFields - number of fields in this subproblem 15130298fd71SBarry Smith - len - The number of subproblems in the decomposition (or NULL if not requested) 1514435a35e8SMatthew G Knepley 1515435a35e8SMatthew G Knepley Output Parameters: 1516435a35e8SMatthew G Knepley . is - The global indices for the subproblem 1517435a35e8SMatthew G Knepley - dm - The DM for the subproblem 1518435a35e8SMatthew G Knepley 1519435a35e8SMatthew G Knepley Level: intermediate 1520435a35e8SMatthew G Knepley 1521435a35e8SMatthew G Knepley .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1522435a35e8SMatthew G Knepley @*/ 1523435a35e8SMatthew G Knepley PetscErrorCode DMCreateSubDM(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) 1524435a35e8SMatthew G Knepley { 1525435a35e8SMatthew G Knepley PetscErrorCode ierr; 1526435a35e8SMatthew G Knepley 1527435a35e8SMatthew G Knepley PetscFunctionBegin; 1528435a35e8SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1529435a35e8SMatthew G Knepley PetscValidPointer(fields,3); 15308865f1eaSKarl Rupp if (is) PetscValidPointer(is,4); 15318865f1eaSKarl Rupp if (subdm) PetscValidPointer(subdm,5); 1532435a35e8SMatthew G Knepley if (dm->ops->createsubdm) { 1533435a35e8SMatthew G Knepley ierr = (*dm->ops->createsubdm)(dm, numFields, fields, is, subdm);CHKERRQ(ierr); 153482f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "This type has no DMCreateSubDM implementation defined"); 1535435a35e8SMatthew G Knepley PetscFunctionReturn(0); 1536435a35e8SMatthew G Knepley } 1537435a35e8SMatthew G Knepley 153816621825SDmitry Karpeev 153916621825SDmitry Karpeev #undef __FUNCT__ 154016621825SDmitry Karpeev #define __FUNCT__ "DMCreateDomainDecomposition" 154116621825SDmitry Karpeev /*@C 15428d4ac253SDmitry Karpeev DMCreateDomainDecomposition - Returns lists of IS objects defining a decomposition of a problem into subproblems 15438d4ac253SDmitry Karpeev corresponding to restrictions to pairs nested subdomains: each IS contains the global 15448d4ac253SDmitry Karpeev indices of the dofs of the corresponding subdomains. The inner subdomains conceptually 15458d4ac253SDmitry Karpeev define a nonoverlapping covering, while outer subdomains can overlap. 15468d4ac253SDmitry Karpeev The optional list of DMs define the DM for each subproblem. 154716621825SDmitry Karpeev 154816621825SDmitry Karpeev Not collective 154916621825SDmitry Karpeev 155016621825SDmitry Karpeev Input Parameter: 155116621825SDmitry Karpeev . dm - the DM object 155216621825SDmitry Karpeev 155316621825SDmitry Karpeev Output Parameters: 15540298fd71SBarry Smith + len - The number of subproblems in the domain decomposition (or NULL if not requested) 15550298fd71SBarry Smith . namelist - The name for each subdomain (or NULL if not requested) 15560298fd71SBarry Smith . innerislist - The global indices for each inner subdomain (or NULL, if not requested) 15570298fd71SBarry Smith . outerislist - The global indices for each outer subdomain (or NULL, if not requested) 15580298fd71SBarry Smith - dmlist - The DMs for each subdomain subproblem (or NULL, if not requested; if NULL is returned, no DMs are defined) 155916621825SDmitry Karpeev 156016621825SDmitry Karpeev Level: intermediate 156116621825SDmitry Karpeev 156216621825SDmitry Karpeev Notes: 156316621825SDmitry Karpeev The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 156416621825SDmitry Karpeev PetscFree(), every entry of is should be destroyed with ISDestroy(), every entry of dm should be destroyed with DMDestroy(), 156516621825SDmitry Karpeev and all of the arrays should be freed with PetscFree(). 156616621825SDmitry Karpeev 15678d4ac253SDmitry Karpeev .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateDomainDecompositionDM(), DMCreateFieldDecomposition() 156816621825SDmitry Karpeev @*/ 15698d4ac253SDmitry Karpeev PetscErrorCode DMCreateDomainDecomposition(DM dm, PetscInt *len, char ***namelist, IS **innerislist, IS **outerislist, DM **dmlist) 157016621825SDmitry Karpeev { 157116621825SDmitry Karpeev PetscErrorCode ierr; 1572be081cd6SPeter Brune DMSubDomainHookLink link; 1573be081cd6SPeter Brune PetscInt i,l; 157416621825SDmitry Karpeev 157516621825SDmitry Karpeev PetscFunctionBegin; 157616621825SDmitry Karpeev PetscValidHeaderSpecific(dm,DM_CLASSID,1); 157714a18fd3SPeter Brune if (len) {PetscValidPointer(len,2); *len = 0;} 15780298fd71SBarry Smith if (namelist) {PetscValidPointer(namelist,3); *namelist = NULL;} 15790298fd71SBarry Smith if (innerislist) {PetscValidPointer(innerislist,4); *innerislist = NULL;} 15800298fd71SBarry Smith if (outerislist) {PetscValidPointer(outerislist,5); *outerislist = NULL;} 15810298fd71SBarry Smith if (dmlist) {PetscValidPointer(dmlist,6); *dmlist = NULL;} 1582f3f0edfdSDmitry Karpeev /* 1583f3f0edfdSDmitry Karpeev Is it a good idea to apply the following check across all impls? 1584f3f0edfdSDmitry Karpeev Perhaps some impls can have a well-defined decomposition before DMSetUp? 1585f3f0edfdSDmitry Karpeev This, however, follows the general principle that accessors are not well-behaved until the object is set up. 1586f3f0edfdSDmitry Karpeev */ 1587ce94432eSBarry Smith if (!dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE, "Decomposition defined only after DMSetUp"); 158816621825SDmitry Karpeev if (dm->ops->createdomaindecomposition) { 1589be081cd6SPeter Brune ierr = (*dm->ops->createdomaindecomposition)(dm,&l,namelist,innerislist,outerislist,dmlist);CHKERRQ(ierr); 159014a18fd3SPeter Brune /* copy subdomain hooks and context over to the subdomain DMs */ 159114a18fd3SPeter Brune if (dmlist) { 15922ca110d9SMatthew G. Knepley if (!*dmlist) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_POINTER,"Method mapped to dm->ops->createdomaindecomposition must allocate at least one DM"); 1593be081cd6SPeter Brune for (i = 0; i < l; i++) { 1594be081cd6SPeter Brune for (link=dm->subdomainhook; link; link=link->next) { 1595be081cd6SPeter Brune if (link->ddhook) {ierr = (*link->ddhook)(dm,(*dmlist)[i],link->ctx);CHKERRQ(ierr);} 1596be081cd6SPeter Brune } 1597d425c654SPeter Brune (*dmlist)[i]->ctx = dm->ctx; 1598e7c4fc90SDmitry Karpeev } 159914a18fd3SPeter Brune } 160014a18fd3SPeter Brune if (len) *len = l; 160114a18fd3SPeter Brune } 1602e30e807fSPeter Brune PetscFunctionReturn(0); 1603e30e807fSPeter Brune } 1604e30e807fSPeter Brune 1605e30e807fSPeter Brune 1606e30e807fSPeter Brune #undef __FUNCT__ 1607e30e807fSPeter Brune #define __FUNCT__ "DMCreateDomainDecompositionScatters" 1608e30e807fSPeter Brune /*@C 1609e30e807fSPeter Brune DMCreateDomainDecompositionScatters - Returns scatters to the subdomain vectors from the global vector 1610e30e807fSPeter Brune 1611e30e807fSPeter Brune Not collective 1612e30e807fSPeter Brune 1613e30e807fSPeter Brune Input Parameters: 1614e30e807fSPeter Brune + dm - the DM object 1615e30e807fSPeter Brune . n - the number of subdomain scatters 1616e30e807fSPeter Brune - subdms - the local subdomains 1617e30e807fSPeter Brune 1618e30e807fSPeter Brune Output Parameters: 1619e30e807fSPeter Brune + n - the number of scatters returned 1620e30e807fSPeter Brune . iscat - scatter from global vector to nonoverlapping global vector entries on subdomain 1621e30e807fSPeter Brune . oscat - scatter from global vector to overlapping global vector entries on subdomain 1622e30e807fSPeter Brune - gscat - scatter from global vector to local vector on subdomain (fills in ghosts) 1623e30e807fSPeter Brune 1624e30e807fSPeter Brune Notes: This is an alternative to the iis and ois arguments in DMCreateDomainDecomposition that allow for the solution 1625e30e807fSPeter Brune of general nonlinear problems with overlapping subdomain methods. While merely having index sets that enable subsets 1626e30e807fSPeter Brune of the residual equations to be created is fine for linear problems, nonlinear problems require local assembly of 1627e30e807fSPeter Brune solution and residual data. 1628e30e807fSPeter Brune 1629e30e807fSPeter Brune Level: developer 1630e30e807fSPeter Brune 1631e30e807fSPeter Brune .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1632e30e807fSPeter Brune @*/ 1633e30e807fSPeter Brune PetscErrorCode DMCreateDomainDecompositionScatters(DM dm,PetscInt n,DM *subdms,VecScatter **iscat,VecScatter **oscat,VecScatter **gscat) 1634e30e807fSPeter Brune { 1635e30e807fSPeter Brune PetscErrorCode ierr; 1636e30e807fSPeter Brune 1637e30e807fSPeter Brune PetscFunctionBegin; 1638e30e807fSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1639e30e807fSPeter Brune PetscValidPointer(subdms,3); 1640e30e807fSPeter Brune if (dm->ops->createddscatters) { 1641e30e807fSPeter Brune ierr = (*dm->ops->createddscatters)(dm,n,subdms,iscat,oscat,gscat);CHKERRQ(ierr); 164282f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "This type has no DMCreateDomainDecompositionLocalScatter implementation defined"); 1643e7c4fc90SDmitry Karpeev PetscFunctionReturn(0); 1644e7c4fc90SDmitry Karpeev } 1645e7c4fc90SDmitry Karpeev 1646731c8d9eSDmitry Karpeev #undef __FUNCT__ 164747c6ae99SBarry Smith #define __FUNCT__ "DMRefine" 164847c6ae99SBarry Smith /*@ 164947c6ae99SBarry Smith DMRefine - Refines a DM object 165047c6ae99SBarry Smith 165147c6ae99SBarry Smith Collective on DM 165247c6ae99SBarry Smith 165347c6ae99SBarry Smith Input Parameter: 165447c6ae99SBarry Smith + dm - the DM object 165591d95f02SJed Brown - comm - the communicator to contain the new DM object (or MPI_COMM_NULL) 165647c6ae99SBarry Smith 165747c6ae99SBarry Smith Output Parameter: 16580298fd71SBarry Smith . dmf - the refined DM, or NULL 1659ae0a1c52SMatthew G Knepley 16600298fd71SBarry Smith Note: If no refinement was done, the return value is NULL 166147c6ae99SBarry Smith 166247c6ae99SBarry Smith Level: developer 166347c6ae99SBarry Smith 1664e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 166547c6ae99SBarry Smith @*/ 16667087cfbeSBarry Smith PetscErrorCode DMRefine(DM dm,MPI_Comm comm,DM *dmf) 166747c6ae99SBarry Smith { 166847c6ae99SBarry Smith PetscErrorCode ierr; 1669c833c3b5SJed Brown DMRefineHookLink link; 167047c6ae99SBarry Smith 167147c6ae99SBarry Smith PetscFunctionBegin; 1672732e2eb9SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1673fef3a512SBarry Smith if (!dm->ops->refine) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"This DM cannot refine"); 167447c6ae99SBarry Smith ierr = (*dm->ops->refine)(dm,comm,dmf);CHKERRQ(ierr); 16754057135bSMatthew G Knepley if (*dmf) { 167643842a1eSJed Brown (*dmf)->ops->creatematrix = dm->ops->creatematrix; 16778865f1eaSKarl Rupp 16788cd211a4SJed Brown ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)*dmf);CHKERRQ(ierr); 16798865f1eaSKarl Rupp 1680644e2e5bSBarry Smith (*dmf)->ctx = dm->ctx; 16810598a293SJed Brown (*dmf)->leveldown = dm->leveldown; 1682656b349aSBarry Smith (*dmf)->levelup = dm->levelup + 1; 16838865f1eaSKarl Rupp 1684e4b4b23bSJed Brown ierr = DMSetMatType(*dmf,dm->mattype);CHKERRQ(ierr); 1685c833c3b5SJed Brown for (link=dm->refinehook; link; link=link->next) { 16868865f1eaSKarl Rupp if (link->refinehook) { 16878865f1eaSKarl Rupp ierr = (*link->refinehook)(dm,*dmf,link->ctx);CHKERRQ(ierr); 16888865f1eaSKarl Rupp } 1689c833c3b5SJed Brown } 1690c833c3b5SJed Brown } 1691c833c3b5SJed Brown PetscFunctionReturn(0); 1692c833c3b5SJed Brown } 1693c833c3b5SJed Brown 1694c833c3b5SJed Brown #undef __FUNCT__ 1695c833c3b5SJed Brown #define __FUNCT__ "DMRefineHookAdd" 1696bb9467b5SJed Brown /*@C 1697c833c3b5SJed Brown DMRefineHookAdd - adds a callback to be run when interpolating a nonlinear problem to a finer grid 1698c833c3b5SJed Brown 1699c833c3b5SJed Brown Logically Collective 1700c833c3b5SJed Brown 1701c833c3b5SJed Brown Input Arguments: 1702c833c3b5SJed Brown + coarse - nonlinear solver context on which to run a hook when restricting to a coarser level 1703c833c3b5SJed Brown . refinehook - function to run when setting up a coarser level 1704c833c3b5SJed Brown . interphook - function to run to update data on finer levels (once per SNESSolve()) 17050298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1706c833c3b5SJed Brown 1707c833c3b5SJed Brown Calling sequence of refinehook: 1708c833c3b5SJed Brown $ refinehook(DM coarse,DM fine,void *ctx); 1709c833c3b5SJed Brown 1710c833c3b5SJed Brown + coarse - coarse level DM 1711c833c3b5SJed Brown . fine - fine level DM to interpolate problem to 1712c833c3b5SJed Brown - ctx - optional user-defined function context 1713c833c3b5SJed Brown 1714c833c3b5SJed Brown Calling sequence for interphook: 1715c833c3b5SJed Brown $ interphook(DM coarse,Mat interp,DM fine,void *ctx) 1716c833c3b5SJed Brown 1717c833c3b5SJed Brown + coarse - coarse level DM 1718c833c3b5SJed Brown . interp - matrix interpolating a coarse-level solution to the finer grid 1719c833c3b5SJed Brown . fine - fine level DM to update 1720c833c3b5SJed Brown - ctx - optional user-defined function context 1721c833c3b5SJed Brown 1722c833c3b5SJed Brown Level: advanced 1723c833c3b5SJed Brown 1724c833c3b5SJed Brown Notes: 1725c833c3b5SJed Brown This function is only needed if auxiliary data needs to be passed to fine grids while grid sequencing 1726c833c3b5SJed Brown 1727c833c3b5SJed Brown If this function is called multiple times, the hooks will be run in the order they are added. 1728c833c3b5SJed Brown 1729bb9467b5SJed Brown This function is currently not available from Fortran. 1730bb9467b5SJed Brown 1731c833c3b5SJed Brown .seealso: DMCoarsenHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1732c833c3b5SJed Brown @*/ 1733c833c3b5SJed Brown PetscErrorCode DMRefineHookAdd(DM coarse,PetscErrorCode (*refinehook)(DM,DM,void*),PetscErrorCode (*interphook)(DM,Mat,DM,void*),void *ctx) 1734c833c3b5SJed Brown { 1735c833c3b5SJed Brown PetscErrorCode ierr; 1736c833c3b5SJed Brown DMRefineHookLink link,*p; 1737c833c3b5SJed Brown 1738c833c3b5SJed Brown PetscFunctionBegin; 1739c833c3b5SJed Brown PetscValidHeaderSpecific(coarse,DM_CLASSID,1); 1740c833c3b5SJed Brown for (p=&coarse->refinehook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1741c833c3b5SJed Brown ierr = PetscMalloc(sizeof(struct _DMRefineHookLink),&link);CHKERRQ(ierr); 1742c833c3b5SJed Brown link->refinehook = refinehook; 1743c833c3b5SJed Brown link->interphook = interphook; 1744c833c3b5SJed Brown link->ctx = ctx; 17450298fd71SBarry Smith link->next = NULL; 1746c833c3b5SJed Brown *p = link; 1747c833c3b5SJed Brown PetscFunctionReturn(0); 1748c833c3b5SJed Brown } 1749c833c3b5SJed Brown 1750c833c3b5SJed Brown #undef __FUNCT__ 1751c833c3b5SJed Brown #define __FUNCT__ "DMInterpolate" 1752c833c3b5SJed Brown /*@ 1753c833c3b5SJed Brown DMInterpolate - interpolates user-defined problem data to a finer DM by running hooks registered by DMRefineHookAdd() 1754c833c3b5SJed Brown 1755c833c3b5SJed Brown Collective if any hooks are 1756c833c3b5SJed Brown 1757c833c3b5SJed Brown Input Arguments: 1758c833c3b5SJed Brown + coarse - coarser DM to use as a base 1759c833c3b5SJed Brown . restrct - interpolation matrix, apply using MatInterpolate() 1760c833c3b5SJed Brown - fine - finer DM to update 1761c833c3b5SJed Brown 1762c833c3b5SJed Brown Level: developer 1763c833c3b5SJed Brown 1764c833c3b5SJed Brown .seealso: DMRefineHookAdd(), MatInterpolate() 1765c833c3b5SJed Brown @*/ 1766c833c3b5SJed Brown PetscErrorCode DMInterpolate(DM coarse,Mat interp,DM fine) 1767c833c3b5SJed Brown { 1768c833c3b5SJed Brown PetscErrorCode ierr; 1769c833c3b5SJed Brown DMRefineHookLink link; 1770c833c3b5SJed Brown 1771c833c3b5SJed Brown PetscFunctionBegin; 1772c833c3b5SJed Brown for (link=fine->refinehook; link; link=link->next) { 17738865f1eaSKarl Rupp if (link->interphook) { 17748865f1eaSKarl Rupp ierr = (*link->interphook)(coarse,interp,fine,link->ctx);CHKERRQ(ierr); 17758865f1eaSKarl Rupp } 17764057135bSMatthew G Knepley } 177747c6ae99SBarry Smith PetscFunctionReturn(0); 177847c6ae99SBarry Smith } 177947c6ae99SBarry Smith 178047c6ae99SBarry Smith #undef __FUNCT__ 1781eb3f98d2SBarry Smith #define __FUNCT__ "DMGetRefineLevel" 1782eb3f98d2SBarry Smith /*@ 1783eb3f98d2SBarry Smith DMGetRefineLevel - Get's the number of refinements that have generated this DM. 1784eb3f98d2SBarry Smith 1785eb3f98d2SBarry Smith Not Collective 1786eb3f98d2SBarry Smith 1787eb3f98d2SBarry Smith Input Parameter: 1788eb3f98d2SBarry Smith . dm - the DM object 1789eb3f98d2SBarry Smith 1790eb3f98d2SBarry Smith Output Parameter: 1791eb3f98d2SBarry Smith . level - number of refinements 1792eb3f98d2SBarry Smith 1793eb3f98d2SBarry Smith Level: developer 1794eb3f98d2SBarry Smith 17956a7d9d85SPeter Brune .seealso DMCoarsen(), DMGetCoarsenLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 1796eb3f98d2SBarry Smith 1797eb3f98d2SBarry Smith @*/ 1798eb3f98d2SBarry Smith PetscErrorCode DMGetRefineLevel(DM dm,PetscInt *level) 1799eb3f98d2SBarry Smith { 1800eb3f98d2SBarry Smith PetscFunctionBegin; 1801eb3f98d2SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1802eb3f98d2SBarry Smith *level = dm->levelup; 1803eb3f98d2SBarry Smith PetscFunctionReturn(0); 1804eb3f98d2SBarry Smith } 1805eb3f98d2SBarry Smith 1806eb3f98d2SBarry Smith #undef __FUNCT__ 1807fef3a512SBarry Smith #define __FUNCT__ "DMSetRefineLevel" 1808fef3a512SBarry Smith /*@ 1809fef3a512SBarry Smith DMSetRefineLevel - Set's the number of refinements that have generated this DM. 1810fef3a512SBarry Smith 1811fef3a512SBarry Smith Not Collective 1812fef3a512SBarry Smith 1813fef3a512SBarry Smith Input Parameter: 1814fef3a512SBarry Smith + dm - the DM object 1815fef3a512SBarry Smith - level - number of refinements 1816fef3a512SBarry Smith 1817fef3a512SBarry Smith Level: advanced 1818fef3a512SBarry Smith 1819fef3a512SBarry Smith Notes: This value is used by PCMG to determine how many multigrid levels to use 1820fef3a512SBarry Smith 1821fef3a512SBarry Smith .seealso DMCoarsen(), DMGetCoarsenLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 1822fef3a512SBarry Smith 1823fef3a512SBarry Smith @*/ 1824fef3a512SBarry Smith PetscErrorCode DMSetRefineLevel(DM dm,PetscInt level) 1825fef3a512SBarry Smith { 1826fef3a512SBarry Smith PetscFunctionBegin; 1827fef3a512SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1828fef3a512SBarry Smith dm->levelup = level; 1829fef3a512SBarry Smith PetscFunctionReturn(0); 1830fef3a512SBarry Smith } 1831fef3a512SBarry Smith 1832fef3a512SBarry Smith #undef __FUNCT__ 1833baf369e7SPeter Brune #define __FUNCT__ "DMGlobalToLocalHookAdd" 1834bb9467b5SJed Brown /*@C 1835baf369e7SPeter Brune DMGlobalToLocalHookAdd - adds a callback to be run when global to local is called 1836baf369e7SPeter Brune 1837baf369e7SPeter Brune Logically Collective 1838baf369e7SPeter Brune 1839baf369e7SPeter Brune Input Arguments: 1840baf369e7SPeter Brune + dm - the DM 1841baf369e7SPeter Brune . beginhook - function to run at the beginning of DMGlobalToLocalBegin() 1842baf369e7SPeter Brune . endhook - function to run after DMGlobalToLocalEnd() has completed 18430298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1844baf369e7SPeter Brune 1845baf369e7SPeter Brune Calling sequence for beginhook: 1846baf369e7SPeter Brune $ beginhook(DM fine,VecScatter out,VecScatter in,DM coarse,void *ctx) 1847baf369e7SPeter Brune 1848baf369e7SPeter Brune + dm - global DM 1849baf369e7SPeter Brune . g - global vector 1850baf369e7SPeter Brune . mode - mode 1851baf369e7SPeter Brune . l - local vector 1852baf369e7SPeter Brune - ctx - optional user-defined function context 1853baf369e7SPeter Brune 1854baf369e7SPeter Brune 1855baf369e7SPeter Brune Calling sequence for endhook: 1856ec4806b8SPeter Brune $ endhook(DM fine,VecScatter out,VecScatter in,DM coarse,void *ctx) 1857baf369e7SPeter Brune 1858baf369e7SPeter Brune + global - global DM 1859baf369e7SPeter Brune - ctx - optional user-defined function context 1860baf369e7SPeter Brune 1861baf369e7SPeter Brune Level: advanced 1862baf369e7SPeter Brune 1863baf369e7SPeter Brune .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1864baf369e7SPeter Brune @*/ 1865baf369e7SPeter Brune PetscErrorCode DMGlobalToLocalHookAdd(DM dm,PetscErrorCode (*beginhook)(DM,Vec,InsertMode,Vec,void*),PetscErrorCode (*endhook)(DM,Vec,InsertMode,Vec,void*),void *ctx) 1866baf369e7SPeter Brune { 1867baf369e7SPeter Brune PetscErrorCode ierr; 1868baf369e7SPeter Brune DMGlobalToLocalHookLink link,*p; 1869baf369e7SPeter Brune 1870baf369e7SPeter Brune PetscFunctionBegin; 1871baf369e7SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1872baf369e7SPeter Brune for (p=&dm->gtolhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1873baf369e7SPeter Brune ierr = PetscMalloc(sizeof(struct _DMGlobalToLocalHookLink),&link);CHKERRQ(ierr); 1874baf369e7SPeter Brune link->beginhook = beginhook; 1875baf369e7SPeter Brune link->endhook = endhook; 1876baf369e7SPeter Brune link->ctx = ctx; 18770298fd71SBarry Smith link->next = NULL; 1878baf369e7SPeter Brune *p = link; 1879baf369e7SPeter Brune PetscFunctionReturn(0); 1880baf369e7SPeter Brune } 1881baf369e7SPeter Brune 1882baf369e7SPeter Brune #undef __FUNCT__ 18834c274da1SToby Isaac #define __FUNCT__ "DMGlobalToLocalHook_Constraints" 18844c274da1SToby Isaac static PetscErrorCode DMGlobalToLocalHook_Constraints(DM dm, Vec g, InsertMode mode, Vec l, void *ctx) 18854c274da1SToby Isaac { 18864c274da1SToby Isaac Mat cMat; 18874c274da1SToby Isaac Vec cVec; 18884c274da1SToby Isaac PetscSection section, cSec; 18894c274da1SToby Isaac PetscInt pStart, pEnd, p, dof; 18904c274da1SToby Isaac PetscErrorCode ierr; 18914c274da1SToby Isaac 18924c274da1SToby Isaac PetscFunctionBegin; 18934c274da1SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 18944c274da1SToby Isaac ierr = DMGetDefaultConstraints(dm,&cSec,&cMat);CHKERRQ(ierr); 18954c274da1SToby Isaac if (cMat && (mode == INSERT_VALUES || mode == INSERT_ALL_VALUES || mode == INSERT_BC_VALUES)) { 18965db9a05bSToby Isaac PetscInt nRows; 18975db9a05bSToby Isaac 18985db9a05bSToby Isaac ierr = MatGetSize(cMat,&nRows,NULL);CHKERRQ(ierr); 18995db9a05bSToby Isaac if (nRows <= 0) PetscFunctionReturn(0); 19004c274da1SToby Isaac ierr = DMGetDefaultSection(dm,§ion);CHKERRQ(ierr); 19017711e48fSToby Isaac ierr = MatCreateVecs(cMat,NULL,&cVec);CHKERRQ(ierr); 19024c274da1SToby Isaac ierr = MatMult(cMat,l,cVec);CHKERRQ(ierr); 19034c274da1SToby Isaac ierr = PetscSectionGetChart(cSec,&pStart,&pEnd);CHKERRQ(ierr); 19044c274da1SToby Isaac for (p = pStart; p < pEnd; p++) { 19054c274da1SToby Isaac ierr = PetscSectionGetDof(cSec,p,&dof);CHKERRQ(ierr); 19064c274da1SToby Isaac if (dof) { 19074c274da1SToby Isaac PetscScalar *vals; 19084c274da1SToby Isaac ierr = VecGetValuesSection(cVec,cSec,p,&vals);CHKERRQ(ierr); 19094c274da1SToby Isaac ierr = VecSetValuesSection(l,section,p,vals,INSERT_ALL_VALUES);CHKERRQ(ierr); 19104c274da1SToby Isaac } 19114c274da1SToby Isaac } 19124c274da1SToby Isaac ierr = VecDestroy(&cVec);CHKERRQ(ierr); 19134c274da1SToby Isaac } 19144c274da1SToby Isaac PetscFunctionReturn(0); 19154c274da1SToby Isaac } 19164c274da1SToby Isaac 19174c274da1SToby Isaac #undef __FUNCT__ 191847c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalBegin" 191947c6ae99SBarry Smith /*@ 192047c6ae99SBarry Smith DMGlobalToLocalBegin - Begins updating local vectors from global vector 192147c6ae99SBarry Smith 192247c6ae99SBarry Smith Neighbor-wise Collective on DM 192347c6ae99SBarry Smith 192447c6ae99SBarry Smith Input Parameters: 192547c6ae99SBarry Smith + dm - the DM object 192647c6ae99SBarry Smith . g - the global vector 192747c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 192847c6ae99SBarry Smith - l - the local vector 192947c6ae99SBarry Smith 193047c6ae99SBarry Smith 193147c6ae99SBarry Smith Level: beginner 193247c6ae99SBarry Smith 1933e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 193447c6ae99SBarry Smith 193547c6ae99SBarry Smith @*/ 19367087cfbeSBarry Smith PetscErrorCode DMGlobalToLocalBegin(DM dm,Vec g,InsertMode mode,Vec l) 193747c6ae99SBarry Smith { 19387128ae9fSMatthew G Knepley PetscSF sf; 193947c6ae99SBarry Smith PetscErrorCode ierr; 1940baf369e7SPeter Brune DMGlobalToLocalHookLink link; 194147c6ae99SBarry Smith 194247c6ae99SBarry Smith PetscFunctionBegin; 1943171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1944baf369e7SPeter Brune for (link=dm->gtolhook; link; link=link->next) { 19458865f1eaSKarl Rupp if (link->beginhook) { 19468865f1eaSKarl Rupp ierr = (*link->beginhook)(dm,g,mode,l,link->ctx);CHKERRQ(ierr); 19478865f1eaSKarl Rupp } 1948baf369e7SPeter Brune } 19497128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 19507128ae9fSMatthew G Knepley if (sf) { 1951ae5cfb4aSMatthew G. Knepley const PetscScalar *gArray; 1952ae5cfb4aSMatthew G. Knepley PetscScalar *lArray; 19537128ae9fSMatthew G Knepley 195482f516ccSBarry Smith if (mode == ADD_VALUES) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 19557128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 1956ae5cfb4aSMatthew G. Knepley ierr = VecGetArrayRead(g, &gArray);CHKERRQ(ierr); 19577128ae9fSMatthew G Knepley ierr = PetscSFBcastBegin(sf, MPIU_SCALAR, gArray, lArray);CHKERRQ(ierr); 19587128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 1959ae5cfb4aSMatthew G. Knepley ierr = VecRestoreArrayRead(g, &gArray);CHKERRQ(ierr); 19607128ae9fSMatthew G Knepley } else { 1961843c4018SMatthew G Knepley ierr = (*dm->ops->globaltolocalbegin)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 19627128ae9fSMatthew G Knepley } 196347c6ae99SBarry Smith PetscFunctionReturn(0); 196447c6ae99SBarry Smith } 196547c6ae99SBarry Smith 196647c6ae99SBarry Smith #undef __FUNCT__ 196747c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalEnd" 196847c6ae99SBarry Smith /*@ 196947c6ae99SBarry Smith DMGlobalToLocalEnd - Ends updating local vectors from global vector 197047c6ae99SBarry Smith 197147c6ae99SBarry Smith Neighbor-wise Collective on DM 197247c6ae99SBarry Smith 197347c6ae99SBarry Smith Input Parameters: 197447c6ae99SBarry Smith + dm - the DM object 197547c6ae99SBarry Smith . g - the global vector 197647c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 197747c6ae99SBarry Smith - l - the local vector 197847c6ae99SBarry Smith 197947c6ae99SBarry Smith 198047c6ae99SBarry Smith Level: beginner 198147c6ae99SBarry Smith 1982e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 198347c6ae99SBarry Smith 198447c6ae99SBarry Smith @*/ 19857087cfbeSBarry Smith PetscErrorCode DMGlobalToLocalEnd(DM dm,Vec g,InsertMode mode,Vec l) 198647c6ae99SBarry Smith { 19877128ae9fSMatthew G Knepley PetscSF sf; 198847c6ae99SBarry Smith PetscErrorCode ierr; 1989ae5cfb4aSMatthew G. Knepley const PetscScalar *gArray; 1990ae5cfb4aSMatthew G. Knepley PetscScalar *lArray; 1991baf369e7SPeter Brune DMGlobalToLocalHookLink link; 199247c6ae99SBarry Smith 199347c6ae99SBarry Smith PetscFunctionBegin; 1994171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 19957128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 19967128ae9fSMatthew G Knepley if (sf) { 199782f516ccSBarry Smith if (mode == ADD_VALUES) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 19987128ae9fSMatthew G Knepley 19997128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 2000ae5cfb4aSMatthew G. Knepley ierr = VecGetArrayRead(g, &gArray);CHKERRQ(ierr); 20017128ae9fSMatthew G Knepley ierr = PetscSFBcastEnd(sf, MPIU_SCALAR, gArray, lArray);CHKERRQ(ierr); 20027128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 2003ae5cfb4aSMatthew G. Knepley ierr = VecRestoreArrayRead(g, &gArray);CHKERRQ(ierr); 20047128ae9fSMatthew G Knepley } else { 2005843c4018SMatthew G Knepley ierr = (*dm->ops->globaltolocalend)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 20067128ae9fSMatthew G Knepley } 20074c274da1SToby Isaac ierr = DMGlobalToLocalHook_Constraints(dm,g,mode,l,NULL);CHKERRQ(ierr); 2008baf369e7SPeter Brune for (link=dm->gtolhook; link; link=link->next) { 2009baf369e7SPeter Brune if (link->endhook) {ierr = (*link->endhook)(dm,g,mode,l,link->ctx);CHKERRQ(ierr);} 2010baf369e7SPeter Brune } 201147c6ae99SBarry Smith PetscFunctionReturn(0); 201247c6ae99SBarry Smith } 201347c6ae99SBarry Smith 201447c6ae99SBarry Smith #undef __FUNCT__ 2015d4d07f1eSToby Isaac #define __FUNCT__ "DMLocalToGlobalHookAdd" 2016d4d07f1eSToby Isaac /*@C 2017d4d07f1eSToby Isaac DMLocalToGlobalHookAdd - adds a callback to be run when a local to global is called 2018d4d07f1eSToby Isaac 2019d4d07f1eSToby Isaac Logically Collective 2020d4d07f1eSToby Isaac 2021d4d07f1eSToby Isaac Input Arguments: 2022d4d07f1eSToby Isaac + dm - the DM 2023d4d07f1eSToby Isaac . beginhook - function to run at the beginning of DMLocalToGlobalBegin() 2024d4d07f1eSToby Isaac . endhook - function to run after DMLocalToGlobalEnd() has completed 2025d4d07f1eSToby Isaac - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 2026d4d07f1eSToby Isaac 2027d4d07f1eSToby Isaac Calling sequence for beginhook: 2028d4d07f1eSToby Isaac $ beginhook(DM fine,Vec l,InsertMode mode,Vec g,void *ctx) 2029d4d07f1eSToby Isaac 2030d4d07f1eSToby Isaac + dm - global DM 2031d4d07f1eSToby Isaac . l - local vector 2032d4d07f1eSToby Isaac . mode - mode 2033d4d07f1eSToby Isaac . g - global vector 2034d4d07f1eSToby Isaac - ctx - optional user-defined function context 2035d4d07f1eSToby Isaac 2036d4d07f1eSToby Isaac 2037d4d07f1eSToby Isaac Calling sequence for endhook: 2038d4d07f1eSToby Isaac $ endhook(DM fine,Vec l,InsertMode mode,Vec g,void *ctx) 2039d4d07f1eSToby Isaac 2040d4d07f1eSToby Isaac + global - global DM 2041d4d07f1eSToby Isaac . l - local vector 2042d4d07f1eSToby Isaac . mode - mode 2043d4d07f1eSToby Isaac . g - global vector 2044d4d07f1eSToby Isaac - ctx - optional user-defined function context 2045d4d07f1eSToby Isaac 2046d4d07f1eSToby Isaac Level: advanced 2047d4d07f1eSToby Isaac 2048d4d07f1eSToby Isaac .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 2049d4d07f1eSToby Isaac @*/ 2050d4d07f1eSToby Isaac PetscErrorCode DMLocalToGlobalHookAdd(DM dm,PetscErrorCode (*beginhook)(DM,Vec,InsertMode,Vec,void*),PetscErrorCode (*endhook)(DM,Vec,InsertMode,Vec,void*),void *ctx) 2051d4d07f1eSToby Isaac { 2052d4d07f1eSToby Isaac PetscErrorCode ierr; 2053d4d07f1eSToby Isaac DMLocalToGlobalHookLink link,*p; 2054d4d07f1eSToby Isaac 2055d4d07f1eSToby Isaac PetscFunctionBegin; 2056d4d07f1eSToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2057d4d07f1eSToby Isaac for (p=&dm->ltoghook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 2058d4d07f1eSToby Isaac ierr = PetscMalloc(sizeof(struct _DMLocalToGlobalHookLink),&link);CHKERRQ(ierr); 2059d4d07f1eSToby Isaac link->beginhook = beginhook; 2060d4d07f1eSToby Isaac link->endhook = endhook; 2061d4d07f1eSToby Isaac link->ctx = ctx; 2062d4d07f1eSToby Isaac link->next = NULL; 2063d4d07f1eSToby Isaac *p = link; 2064d4d07f1eSToby Isaac PetscFunctionReturn(0); 2065d4d07f1eSToby Isaac } 2066d4d07f1eSToby Isaac 2067d4d07f1eSToby Isaac #undef __FUNCT__ 20684c274da1SToby Isaac #define __FUNCT__ "DMLocalToGlobalHook_Constraints" 20694c274da1SToby Isaac static PetscErrorCode DMLocalToGlobalHook_Constraints(DM dm, Vec l, InsertMode mode, Vec g, void *ctx) 20704c274da1SToby Isaac { 20714c274da1SToby Isaac Mat cMat; 20724c274da1SToby Isaac Vec cVec; 20734c274da1SToby Isaac PetscSection section, cSec; 20744c274da1SToby Isaac PetscInt pStart, pEnd, p, dof; 20754c274da1SToby Isaac PetscErrorCode ierr; 20764c274da1SToby Isaac 20774c274da1SToby Isaac PetscFunctionBegin; 20784c274da1SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 20794c274da1SToby Isaac ierr = DMGetDefaultConstraints(dm,&cSec,&cMat);CHKERRQ(ierr); 20804c274da1SToby Isaac if (cMat && (mode == ADD_VALUES || mode == ADD_ALL_VALUES || mode == ADD_BC_VALUES)) { 20815db9a05bSToby Isaac PetscInt nRows; 20825db9a05bSToby Isaac 20835db9a05bSToby Isaac ierr = MatGetSize(cMat,&nRows,NULL);CHKERRQ(ierr); 20845db9a05bSToby Isaac if (nRows <= 0) PetscFunctionReturn(0); 20854c274da1SToby Isaac ierr = DMGetDefaultSection(dm,§ion);CHKERRQ(ierr); 20867711e48fSToby Isaac ierr = MatCreateVecs(cMat,NULL,&cVec);CHKERRQ(ierr); 20874c274da1SToby Isaac ierr = PetscSectionGetChart(cSec,&pStart,&pEnd);CHKERRQ(ierr); 20884c274da1SToby Isaac for (p = pStart; p < pEnd; p++) { 20894c274da1SToby Isaac ierr = PetscSectionGetDof(cSec,p,&dof);CHKERRQ(ierr); 20904c274da1SToby Isaac if (dof) { 20914c274da1SToby Isaac PetscInt d; 20924c274da1SToby Isaac PetscScalar *vals; 20934c274da1SToby Isaac ierr = VecGetValuesSection(l,section,p,&vals);CHKERRQ(ierr); 20944c274da1SToby Isaac ierr = VecSetValuesSection(cVec,cSec,p,vals,mode);CHKERRQ(ierr); 20954c274da1SToby Isaac /* for this to be the true transpose, we have to zero the values that 20964c274da1SToby Isaac * we just extracted */ 20974c274da1SToby Isaac for (d = 0; d < dof; d++) { 20984c274da1SToby Isaac vals[d] = 0.; 20994c274da1SToby Isaac } 21004c274da1SToby Isaac } 21014c274da1SToby Isaac } 21024c274da1SToby Isaac ierr = MatMultTransposeAdd(cMat,cVec,l,l);CHKERRQ(ierr); 21034c274da1SToby Isaac ierr = VecDestroy(&cVec);CHKERRQ(ierr); 21044c274da1SToby Isaac } 21054c274da1SToby Isaac PetscFunctionReturn(0); 21064c274da1SToby Isaac } 21074c274da1SToby Isaac 21084c274da1SToby Isaac #undef __FUNCT__ 21099a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalBegin" 211047c6ae99SBarry Smith /*@ 21119a42bb27SBarry Smith DMLocalToGlobalBegin - updates global vectors from local vectors 21129a42bb27SBarry Smith 21139a42bb27SBarry Smith Neighbor-wise Collective on DM 21149a42bb27SBarry Smith 21159a42bb27SBarry Smith Input Parameters: 21169a42bb27SBarry Smith + dm - the DM object 2117f6813fd5SJed Brown . l - the local vector 21181eb28f2eSBarry 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. 21191eb28f2eSBarry Smith - g - the global vector 21209a42bb27SBarry Smith 2121d96308ebSBarry Smith Notes: In the ADD_VALUES case you normally would zero the receiving vector before beginning this operation. 212284330215SMatthew 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. 21239a42bb27SBarry Smith 21249a42bb27SBarry Smith Level: beginner 21259a42bb27SBarry Smith 2126e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalBegin() 21279a42bb27SBarry Smith 21289a42bb27SBarry Smith @*/ 21297087cfbeSBarry Smith PetscErrorCode DMLocalToGlobalBegin(DM dm,Vec l,InsertMode mode,Vec g) 21309a42bb27SBarry Smith { 21317128ae9fSMatthew G Knepley PetscSF sf; 213284330215SMatthew G. Knepley PetscSection s, gs; 2133d4d07f1eSToby Isaac DMLocalToGlobalHookLink link; 2134ae5cfb4aSMatthew G. Knepley const PetscScalar *lArray; 2135ae5cfb4aSMatthew G. Knepley PetscScalar *gArray; 213684330215SMatthew G. Knepley PetscBool isInsert; 213784330215SMatthew G. Knepley PetscErrorCode ierr; 21389a42bb27SBarry Smith 21399a42bb27SBarry Smith PetscFunctionBegin; 2140171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2141d4d07f1eSToby Isaac for (link=dm->ltoghook; link; link=link->next) { 2142d4d07f1eSToby Isaac if (link->beginhook) { 2143d4d07f1eSToby Isaac ierr = (*link->beginhook)(dm,l,mode,g,link->ctx);CHKERRQ(ierr); 2144d4d07f1eSToby Isaac } 2145d4d07f1eSToby Isaac } 21464c274da1SToby Isaac ierr = DMLocalToGlobalHook_Constraints(dm,l,mode,g,NULL);CHKERRQ(ierr); 21477128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 214884330215SMatthew G. Knepley ierr = DMGetDefaultSection(dm, &s);CHKERRQ(ierr); 21497128ae9fSMatthew G Knepley switch (mode) { 21507128ae9fSMatthew G Knepley case INSERT_VALUES: 21517128ae9fSMatthew G Knepley case INSERT_ALL_VALUES: 2152*304ab55fSMatthew G. Knepley case INSERT_BC_VALUES: 215384330215SMatthew G. Knepley isInsert = PETSC_TRUE; break; 21547128ae9fSMatthew G Knepley case ADD_VALUES: 21557128ae9fSMatthew G Knepley case ADD_ALL_VALUES: 2156*304ab55fSMatthew G. Knepley case ADD_BC_VALUES: 215784330215SMatthew G. Knepley isInsert = PETSC_FALSE; break; 21587128ae9fSMatthew G Knepley default: 215982f516ccSBarry Smith SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 21607128ae9fSMatthew G Knepley } 216184330215SMatthew G. Knepley if (sf && !isInsert) { 2162ae5cfb4aSMatthew G. Knepley ierr = VecGetArrayRead(l, &lArray);CHKERRQ(ierr); 21637128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 2164a9b180a6SBarry Smith ierr = PetscSFReduceBegin(sf, MPIU_SCALAR, lArray, gArray, MPIU_SUM);CHKERRQ(ierr); 2165ae5cfb4aSMatthew G. Knepley ierr = VecRestoreArrayRead(l, &lArray);CHKERRQ(ierr); 216684330215SMatthew G. Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 216784330215SMatthew G. Knepley } else if (s && isInsert) { 216884330215SMatthew G. Knepley PetscInt gStart, pStart, pEnd, p; 216984330215SMatthew G. Knepley 217084330215SMatthew G. Knepley ierr = DMGetDefaultGlobalSection(dm, &gs);CHKERRQ(ierr); 217184330215SMatthew G. Knepley ierr = PetscSectionGetChart(s, &pStart, &pEnd);CHKERRQ(ierr); 217284330215SMatthew G. Knepley ierr = VecGetOwnershipRange(g, &gStart, NULL);CHKERRQ(ierr); 2173ae5cfb4aSMatthew G. Knepley ierr = VecGetArrayRead(l, &lArray);CHKERRQ(ierr); 217484330215SMatthew G. Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 217584330215SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 2176b3b16f48SMatthew G. Knepley PetscInt dof, gdof, cdof, gcdof, off, goff, d, e; 217784330215SMatthew G. Knepley 217884330215SMatthew G. Knepley ierr = PetscSectionGetDof(s, p, &dof);CHKERRQ(ierr); 217903442857SMatthew G. Knepley ierr = PetscSectionGetDof(gs, p, &gdof);CHKERRQ(ierr); 218084330215SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(s, p, &cdof);CHKERRQ(ierr); 2181b3b16f48SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(gs, p, &gcdof);CHKERRQ(ierr); 218284330215SMatthew G. Knepley ierr = PetscSectionGetOffset(s, p, &off);CHKERRQ(ierr); 218384330215SMatthew G. Knepley ierr = PetscSectionGetOffset(gs, p, &goff);CHKERRQ(ierr); 2184b3b16f48SMatthew G. Knepley /* Ignore off-process data and points with no global data */ 218503442857SMatthew G. Knepley if (!gdof || goff < 0) continue; 2186b3b16f48SMatthew 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); 2187b3b16f48SMatthew G. Knepley /* If no constraints are enforced in the global vector */ 2188b3b16f48SMatthew G. Knepley if (!gcdof) { 218984330215SMatthew G. Knepley for (d = 0; d < dof; ++d) gArray[goff-gStart+d] = lArray[off+d]; 2190b3b16f48SMatthew G. Knepley /* If constraints are enforced in the global vector */ 2191b3b16f48SMatthew G. Knepley } else if (cdof == gcdof) { 219284330215SMatthew G. Knepley const PetscInt *cdofs; 219384330215SMatthew G. Knepley PetscInt cind = 0; 219484330215SMatthew G. Knepley 219584330215SMatthew G. Knepley ierr = PetscSectionGetConstraintIndices(s, p, &cdofs);CHKERRQ(ierr); 2196b3b16f48SMatthew G. Knepley for (d = 0, e = 0; d < dof; ++d) { 219784330215SMatthew G. Knepley if ((cind < cdof) && (d == cdofs[cind])) {++cind; continue;} 2198b3b16f48SMatthew G. Knepley gArray[goff-gStart+e++] = lArray[off+d]; 219984330215SMatthew G. Knepley } 2200b3b16f48SMatthew 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); 220184330215SMatthew G. Knepley } 2202ae5cfb4aSMatthew G. Knepley ierr = VecRestoreArrayRead(l, &lArray);CHKERRQ(ierr); 22037128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 22047128ae9fSMatthew G Knepley } else { 2205843c4018SMatthew G Knepley ierr = (*dm->ops->localtoglobalbegin)(dm,l,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),g);CHKERRQ(ierr); 22067128ae9fSMatthew G Knepley } 22079a42bb27SBarry Smith PetscFunctionReturn(0); 22089a42bb27SBarry Smith } 22099a42bb27SBarry Smith 22109a42bb27SBarry Smith #undef __FUNCT__ 22119a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalEnd" 22129a42bb27SBarry Smith /*@ 22139a42bb27SBarry Smith DMLocalToGlobalEnd - updates global vectors from local vectors 221447c6ae99SBarry Smith 221547c6ae99SBarry Smith Neighbor-wise Collective on DM 221647c6ae99SBarry Smith 221747c6ae99SBarry Smith Input Parameters: 221847c6ae99SBarry Smith + dm - the DM object 2219f6813fd5SJed Brown . l - the local vector 222047c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 2221f6813fd5SJed Brown - g - the global vector 222247c6ae99SBarry Smith 222347c6ae99SBarry Smith 222447c6ae99SBarry Smith Level: beginner 222547c6ae99SBarry Smith 2226e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalEnd() 222747c6ae99SBarry Smith 222847c6ae99SBarry Smith @*/ 22297087cfbeSBarry Smith PetscErrorCode DMLocalToGlobalEnd(DM dm,Vec l,InsertMode mode,Vec g) 223047c6ae99SBarry Smith { 22317128ae9fSMatthew G Knepley PetscSF sf; 223284330215SMatthew G. Knepley PetscSection s; 2233d4d07f1eSToby Isaac DMLocalToGlobalHookLink link; 223484330215SMatthew G. Knepley PetscBool isInsert; 223584330215SMatthew G. Knepley PetscErrorCode ierr; 223647c6ae99SBarry Smith 223747c6ae99SBarry Smith PetscFunctionBegin; 2238171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 22397128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 224084330215SMatthew G. Knepley ierr = DMGetDefaultSection(dm, &s);CHKERRQ(ierr); 22417128ae9fSMatthew G Knepley switch (mode) { 22427128ae9fSMatthew G Knepley case INSERT_VALUES: 22437128ae9fSMatthew G Knepley case INSERT_ALL_VALUES: 224484330215SMatthew G. Knepley isInsert = PETSC_TRUE; break; 22457128ae9fSMatthew G Knepley case ADD_VALUES: 22467128ae9fSMatthew G Knepley case ADD_ALL_VALUES: 224784330215SMatthew G. Knepley isInsert = PETSC_FALSE; break; 22487128ae9fSMatthew G Knepley default: 224982f516ccSBarry Smith SETERRQ1(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 22507128ae9fSMatthew G Knepley } 225184330215SMatthew G. Knepley if (sf && !isInsert) { 2252ae5cfb4aSMatthew G. Knepley const PetscScalar *lArray; 2253ae5cfb4aSMatthew G. Knepley PetscScalar *gArray; 225484330215SMatthew G. Knepley 2255ae5cfb4aSMatthew G. Knepley ierr = VecGetArrayRead(l, &lArray);CHKERRQ(ierr); 22567128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 2257a9b180a6SBarry Smith ierr = PetscSFReduceEnd(sf, MPIU_SCALAR, lArray, gArray, MPIU_SUM);CHKERRQ(ierr); 2258ae5cfb4aSMatthew G. Knepley ierr = VecRestoreArrayRead(l, &lArray);CHKERRQ(ierr); 22597128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 226084330215SMatthew G. Knepley } else if (s && isInsert) { 22617128ae9fSMatthew G Knepley } else { 2262843c4018SMatthew G Knepley ierr = (*dm->ops->localtoglobalend)(dm,l,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),g);CHKERRQ(ierr); 22637128ae9fSMatthew G Knepley } 2264d4d07f1eSToby Isaac for (link=dm->ltoghook; link; link=link->next) { 2265d4d07f1eSToby Isaac if (link->endhook) {ierr = (*link->endhook)(dm,g,mode,l,link->ctx);CHKERRQ(ierr);} 2266d4d07f1eSToby Isaac } 226747c6ae99SBarry Smith PetscFunctionReturn(0); 226847c6ae99SBarry Smith } 226947c6ae99SBarry Smith 227047c6ae99SBarry Smith #undef __FUNCT__ 2271f089877aSRichard Tran Mills #define __FUNCT__ "DMLocalToLocalBegin" 2272f089877aSRichard Tran Mills /*@ 2273bc0a1609SRichard Tran Mills DMLocalToLocalBegin - Maps from a local vector (including ghost points 2274bc0a1609SRichard Tran Mills that contain irrelevant values) to another local vector where the ghost 2275d78e899eSRichard Tran Mills points in the second are set correctly. Must be followed by DMLocalToLocalEnd(). 2276f089877aSRichard Tran Mills 2277bc0a1609SRichard Tran Mills Neighbor-wise Collective on DM and Vec 2278f089877aSRichard Tran Mills 2279f089877aSRichard Tran Mills Input Parameters: 2280f089877aSRichard Tran Mills + dm - the DM object 2281bc0a1609SRichard Tran Mills . g - the original local vector 2282bc0a1609SRichard Tran Mills - mode - one of INSERT_VALUES or ADD_VALUES 2283f089877aSRichard Tran Mills 2284bc0a1609SRichard Tran Mills Output Parameter: 2285bc0a1609SRichard Tran Mills . l - the local vector with correct ghost values 2286f089877aSRichard Tran Mills 2287f089877aSRichard Tran Mills Level: intermediate 2288f089877aSRichard Tran Mills 2289bc0a1609SRichard Tran Mills Notes: 2290bc0a1609SRichard Tran Mills The local vectors used here need not be the same as those 2291bc0a1609SRichard Tran Mills obtained from DMCreateLocalVector(), BUT they 2292bc0a1609SRichard Tran Mills must have the same parallel data layout; they could, for example, be 2293bc0a1609SRichard Tran Mills obtained with VecDuplicate() from the DM originating vectors. 2294bc0a1609SRichard Tran Mills 2295bc0a1609SRichard Tran Mills .keywords: DM, local-to-local, begin 2296bc0a1609SRichard Tran Mills .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateLocalVector(), DMCreateGlobalVector(), DMCreateInterpolation(), DMLocalToLocalEnd(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 2297f089877aSRichard Tran Mills 2298f089877aSRichard Tran Mills @*/ 2299f089877aSRichard Tran Mills PetscErrorCode DMLocalToLocalBegin(DM dm,Vec g,InsertMode mode,Vec l) 2300f089877aSRichard Tran Mills { 2301f089877aSRichard Tran Mills PetscErrorCode ierr; 2302f089877aSRichard Tran Mills 2303f089877aSRichard Tran Mills PetscFunctionBegin; 2304f089877aSRichard Tran Mills PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2305f089877aSRichard Tran Mills ierr = (*dm->ops->localtolocalbegin)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 2306f089877aSRichard Tran Mills PetscFunctionReturn(0); 2307f089877aSRichard Tran Mills } 2308f089877aSRichard Tran Mills 2309f089877aSRichard Tran Mills #undef __FUNCT__ 2310f089877aSRichard Tran Mills #define __FUNCT__ "DMLocalToLocalEnd" 2311f089877aSRichard Tran Mills /*@ 2312bc0a1609SRichard Tran Mills DMLocalToLocalEnd - Maps from a local vector (including ghost points 2313bc0a1609SRichard Tran Mills that contain irrelevant values) to another local vector where the ghost 2314d78e899eSRichard Tran Mills points in the second are set correctly. Must be preceded by DMLocalToLocalBegin(). 2315f089877aSRichard Tran Mills 2316bc0a1609SRichard Tran Mills Neighbor-wise Collective on DM and Vec 2317f089877aSRichard Tran Mills 2318f089877aSRichard Tran Mills Input Parameters: 2319bc0a1609SRichard Tran Mills + da - the DM object 2320bc0a1609SRichard Tran Mills . g - the original local vector 2321bc0a1609SRichard Tran Mills - mode - one of INSERT_VALUES or ADD_VALUES 2322f089877aSRichard Tran Mills 2323bc0a1609SRichard Tran Mills Output Parameter: 2324bc0a1609SRichard Tran Mills . l - the local vector with correct ghost values 2325f089877aSRichard Tran Mills 2326f089877aSRichard Tran Mills Level: intermediate 2327f089877aSRichard Tran Mills 2328bc0a1609SRichard Tran Mills Notes: 2329bc0a1609SRichard Tran Mills The local vectors used here need not be the same as those 2330bc0a1609SRichard Tran Mills obtained from DMCreateLocalVector(), BUT they 2331bc0a1609SRichard Tran Mills must have the same parallel data layout; they could, for example, be 2332bc0a1609SRichard Tran Mills obtained with VecDuplicate() from the DM originating vectors. 2333bc0a1609SRichard Tran Mills 2334bc0a1609SRichard Tran Mills .keywords: DM, local-to-local, end 2335bc0a1609SRichard Tran Mills .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateLocalVector(), DMCreateGlobalVector(), DMCreateInterpolation(), DMLocalToLocalBegin(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 2336f089877aSRichard Tran Mills 2337f089877aSRichard Tran Mills @*/ 2338f089877aSRichard Tran Mills PetscErrorCode DMLocalToLocalEnd(DM dm,Vec g,InsertMode mode,Vec l) 2339f089877aSRichard Tran Mills { 2340f089877aSRichard Tran Mills PetscErrorCode ierr; 2341f089877aSRichard Tran Mills 2342f089877aSRichard Tran Mills PetscFunctionBegin; 2343f089877aSRichard Tran Mills PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2344f089877aSRichard Tran Mills ierr = (*dm->ops->localtolocalend)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 2345f089877aSRichard Tran Mills PetscFunctionReturn(0); 2346f089877aSRichard Tran Mills } 2347f089877aSRichard Tran Mills 2348f089877aSRichard Tran Mills 2349f089877aSRichard Tran Mills #undef __FUNCT__ 235047c6ae99SBarry Smith #define __FUNCT__ "DMCoarsen" 235147c6ae99SBarry Smith /*@ 235247c6ae99SBarry Smith DMCoarsen - Coarsens a DM object 235347c6ae99SBarry Smith 235447c6ae99SBarry Smith Collective on DM 235547c6ae99SBarry Smith 235647c6ae99SBarry Smith Input Parameter: 235747c6ae99SBarry Smith + dm - the DM object 235891d95f02SJed Brown - comm - the communicator to contain the new DM object (or MPI_COMM_NULL) 235947c6ae99SBarry Smith 236047c6ae99SBarry Smith Output Parameter: 236147c6ae99SBarry Smith . dmc - the coarsened DM 236247c6ae99SBarry Smith 236347c6ae99SBarry Smith Level: developer 236447c6ae99SBarry Smith 2365e727c939SJed Brown .seealso DMRefine(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 236647c6ae99SBarry Smith 236747c6ae99SBarry Smith @*/ 23687087cfbeSBarry Smith PetscErrorCode DMCoarsen(DM dm, MPI_Comm comm, DM *dmc) 236947c6ae99SBarry Smith { 237047c6ae99SBarry Smith PetscErrorCode ierr; 2371b17ce1afSJed Brown DMCoarsenHookLink link; 237247c6ae99SBarry Smith 237347c6ae99SBarry Smith PetscFunctionBegin; 2374171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2375fef3a512SBarry Smith if (!dm->ops->coarsen) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"This DM cannot coarsen"); 237647a35634SPatrick Farrell ierr = PetscLogEventBegin(DM_Coarsen,dm,0,0,0);CHKERRQ(ierr); 237747c6ae99SBarry Smith ierr = (*dm->ops->coarsen)(dm, comm, dmc);CHKERRQ(ierr); 23788892b4c3SMatthew G. Knepley if (!(*dmc)) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "NULL coarse mesh produced"); 2379a8fb8f29SToby Isaac ierr = DMSetCoarseDM(dm,*dmc);CHKERRQ(ierr); 238043842a1eSJed Brown (*dmc)->ops->creatematrix = dm->ops->creatematrix; 23818cd211a4SJed Brown ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)*dmc);CHKERRQ(ierr); 2382644e2e5bSBarry Smith (*dmc)->ctx = dm->ctx; 23830598a293SJed Brown (*dmc)->levelup = dm->levelup; 2384656b349aSBarry Smith (*dmc)->leveldown = dm->leveldown + 1; 2385e4b4b23bSJed Brown ierr = DMSetMatType(*dmc,dm->mattype);CHKERRQ(ierr); 2386b17ce1afSJed Brown for (link=dm->coarsenhook; link; link=link->next) { 2387b17ce1afSJed Brown if (link->coarsenhook) {ierr = (*link->coarsenhook)(dm,*dmc,link->ctx);CHKERRQ(ierr);} 2388b17ce1afSJed Brown } 238947a35634SPatrick Farrell ierr = PetscLogEventEnd(DM_Coarsen,dm,0,0,0);CHKERRQ(ierr); 2390b17ce1afSJed Brown PetscFunctionReturn(0); 2391b17ce1afSJed Brown } 2392b17ce1afSJed Brown 2393b17ce1afSJed Brown #undef __FUNCT__ 2394b17ce1afSJed Brown #define __FUNCT__ "DMCoarsenHookAdd" 2395bb9467b5SJed Brown /*@C 2396b17ce1afSJed Brown DMCoarsenHookAdd - adds a callback to be run when restricting a nonlinear problem to the coarse grid 2397b17ce1afSJed Brown 2398b17ce1afSJed Brown Logically Collective 2399b17ce1afSJed Brown 2400b17ce1afSJed Brown Input Arguments: 2401b17ce1afSJed Brown + fine - nonlinear solver context on which to run a hook when restricting to a coarser level 2402b17ce1afSJed Brown . coarsenhook - function to run when setting up a coarser level 2403b17ce1afSJed Brown . restricthook - function to run to update data on coarser levels (once per SNESSolve()) 24040298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 2405b17ce1afSJed Brown 2406b17ce1afSJed Brown Calling sequence of coarsenhook: 2407b17ce1afSJed Brown $ coarsenhook(DM fine,DM coarse,void *ctx); 2408b17ce1afSJed Brown 2409b17ce1afSJed Brown + fine - fine level DM 2410b17ce1afSJed Brown . coarse - coarse level DM to restrict problem to 2411b17ce1afSJed Brown - ctx - optional user-defined function context 2412b17ce1afSJed Brown 2413b17ce1afSJed Brown Calling sequence for restricthook: 2414c833c3b5SJed Brown $ restricthook(DM fine,Mat mrestrict,Vec rscale,Mat inject,DM coarse,void *ctx) 2415b17ce1afSJed Brown 2416b17ce1afSJed Brown + fine - fine level DM 2417b17ce1afSJed Brown . mrestrict - matrix restricting a fine-level solution to the coarse grid 2418c833c3b5SJed Brown . rscale - scaling vector for restriction 2419c833c3b5SJed Brown . inject - matrix restricting by injection 2420b17ce1afSJed Brown . coarse - coarse level DM to update 2421b17ce1afSJed Brown - ctx - optional user-defined function context 2422b17ce1afSJed Brown 2423b17ce1afSJed Brown Level: advanced 2424b17ce1afSJed Brown 2425b17ce1afSJed Brown Notes: 2426b17ce1afSJed Brown This function is only needed if auxiliary data needs to be set up on coarse grids. 2427b17ce1afSJed Brown 2428b17ce1afSJed Brown If this function is called multiple times, the hooks will be run in the order they are added. 2429b17ce1afSJed Brown 2430b17ce1afSJed Brown In order to compose with nonlinear preconditioning without duplicating storage, the hook should be implemented to 2431b17ce1afSJed Brown extract the finest level information from its context (instead of from the SNES). 2432b17ce1afSJed Brown 2433bb9467b5SJed Brown This function is currently not available from Fortran. 2434bb9467b5SJed Brown 2435c833c3b5SJed Brown .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 2436b17ce1afSJed Brown @*/ 2437b17ce1afSJed Brown PetscErrorCode DMCoarsenHookAdd(DM fine,PetscErrorCode (*coarsenhook)(DM,DM,void*),PetscErrorCode (*restricthook)(DM,Mat,Vec,Mat,DM,void*),void *ctx) 2438b17ce1afSJed Brown { 2439b17ce1afSJed Brown PetscErrorCode ierr; 2440b17ce1afSJed Brown DMCoarsenHookLink link,*p; 2441b17ce1afSJed Brown 2442b17ce1afSJed Brown PetscFunctionBegin; 2443b17ce1afSJed Brown PetscValidHeaderSpecific(fine,DM_CLASSID,1); 24446bfea28cSJed Brown for (p=&fine->coarsenhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 2445b17ce1afSJed Brown ierr = PetscMalloc(sizeof(struct _DMCoarsenHookLink),&link);CHKERRQ(ierr); 2446b17ce1afSJed Brown link->coarsenhook = coarsenhook; 2447b17ce1afSJed Brown link->restricthook = restricthook; 2448b17ce1afSJed Brown link->ctx = ctx; 24490298fd71SBarry Smith link->next = NULL; 2450b17ce1afSJed Brown *p = link; 2451b17ce1afSJed Brown PetscFunctionReturn(0); 2452b17ce1afSJed Brown } 2453b17ce1afSJed Brown 2454b17ce1afSJed Brown #undef __FUNCT__ 2455b17ce1afSJed Brown #define __FUNCT__ "DMRestrict" 2456b17ce1afSJed Brown /*@ 2457b17ce1afSJed Brown DMRestrict - restricts user-defined problem data to a coarser DM by running hooks registered by DMCoarsenHookAdd() 2458b17ce1afSJed Brown 2459b17ce1afSJed Brown Collective if any hooks are 2460b17ce1afSJed Brown 2461b17ce1afSJed Brown Input Arguments: 2462b17ce1afSJed Brown + fine - finer DM to use as a base 2463b17ce1afSJed Brown . restrct - restriction matrix, apply using MatRestrict() 2464b17ce1afSJed Brown . inject - injection matrix, also use MatRestrict() 2465b17ce1afSJed Brown - coarse - coarer DM to update 2466b17ce1afSJed Brown 2467b17ce1afSJed Brown Level: developer 2468b17ce1afSJed Brown 2469b17ce1afSJed Brown .seealso: DMCoarsenHookAdd(), MatRestrict() 2470b17ce1afSJed Brown @*/ 2471b17ce1afSJed Brown PetscErrorCode DMRestrict(DM fine,Mat restrct,Vec rscale,Mat inject,DM coarse) 2472b17ce1afSJed Brown { 2473b17ce1afSJed Brown PetscErrorCode ierr; 2474b17ce1afSJed Brown DMCoarsenHookLink link; 2475b17ce1afSJed Brown 2476b17ce1afSJed Brown PetscFunctionBegin; 2477b17ce1afSJed Brown for (link=fine->coarsenhook; link; link=link->next) { 24788865f1eaSKarl Rupp if (link->restricthook) { 24798865f1eaSKarl Rupp ierr = (*link->restricthook)(fine,restrct,rscale,inject,coarse,link->ctx);CHKERRQ(ierr); 24808865f1eaSKarl Rupp } 2481b17ce1afSJed Brown } 248247c6ae99SBarry Smith PetscFunctionReturn(0); 248347c6ae99SBarry Smith } 248447c6ae99SBarry Smith 248547c6ae99SBarry Smith #undef __FUNCT__ 2486be081cd6SPeter Brune #define __FUNCT__ "DMSubDomainHookAdd" 2487bb9467b5SJed Brown /*@C 2488be081cd6SPeter Brune DMSubDomainHookAdd - adds a callback to be run when restricting a problem to the coarse grid 24895dbd56e3SPeter Brune 24905dbd56e3SPeter Brune Logically Collective 24915dbd56e3SPeter Brune 24925dbd56e3SPeter Brune Input Arguments: 24935dbd56e3SPeter Brune + global - global DM 2494ec4806b8SPeter Brune . ddhook - function to run to pass data to the decomposition DM upon its creation 24955dbd56e3SPeter Brune . restricthook - function to run to update data on block solve (at the beginning of the block solve) 24960298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 24975dbd56e3SPeter Brune 2498ec4806b8SPeter Brune 2499ec4806b8SPeter Brune Calling sequence for ddhook: 2500ec4806b8SPeter Brune $ ddhook(DM global,DM block,void *ctx) 2501ec4806b8SPeter Brune 2502ec4806b8SPeter Brune + global - global DM 2503ec4806b8SPeter Brune . block - block DM 2504ec4806b8SPeter Brune - ctx - optional user-defined function context 2505ec4806b8SPeter Brune 25065dbd56e3SPeter Brune Calling sequence for restricthook: 2507ec4806b8SPeter Brune $ restricthook(DM global,VecScatter out,VecScatter in,DM block,void *ctx) 25085dbd56e3SPeter Brune 25095dbd56e3SPeter Brune + global - global DM 25105dbd56e3SPeter Brune . out - scatter to the outer (with ghost and overlap points) block vector 25115dbd56e3SPeter Brune . in - scatter to block vector values only owned locally 2512ec4806b8SPeter Brune . block - block DM 25135dbd56e3SPeter Brune - ctx - optional user-defined function context 25145dbd56e3SPeter Brune 25155dbd56e3SPeter Brune Level: advanced 25165dbd56e3SPeter Brune 25175dbd56e3SPeter Brune Notes: 2518ec4806b8SPeter Brune This function is only needed if auxiliary data needs to be set up on subdomain DMs. 25195dbd56e3SPeter Brune 25205dbd56e3SPeter Brune If this function is called multiple times, the hooks will be run in the order they are added. 25215dbd56e3SPeter Brune 25225dbd56e3SPeter Brune In order to compose with nonlinear preconditioning without duplicating storage, the hook should be implemented to 2523ec4806b8SPeter Brune extract the global information from its context (instead of from the SNES). 25245dbd56e3SPeter Brune 2525bb9467b5SJed Brown This function is currently not available from Fortran. 2526bb9467b5SJed Brown 25275dbd56e3SPeter Brune .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 25285dbd56e3SPeter Brune @*/ 2529be081cd6SPeter Brune PetscErrorCode DMSubDomainHookAdd(DM global,PetscErrorCode (*ddhook)(DM,DM,void*),PetscErrorCode (*restricthook)(DM,VecScatter,VecScatter,DM,void*),void *ctx) 25305dbd56e3SPeter Brune { 25315dbd56e3SPeter Brune PetscErrorCode ierr; 2532be081cd6SPeter Brune DMSubDomainHookLink link,*p; 25335dbd56e3SPeter Brune 25345dbd56e3SPeter Brune PetscFunctionBegin; 25355dbd56e3SPeter Brune PetscValidHeaderSpecific(global,DM_CLASSID,1); 2536be081cd6SPeter Brune for (p=&global->subdomainhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 2537be081cd6SPeter Brune ierr = PetscMalloc(sizeof(struct _DMSubDomainHookLink),&link);CHKERRQ(ierr); 25385dbd56e3SPeter Brune link->restricthook = restricthook; 2539be081cd6SPeter Brune link->ddhook = ddhook; 25405dbd56e3SPeter Brune link->ctx = ctx; 25410298fd71SBarry Smith link->next = NULL; 25425dbd56e3SPeter Brune *p = link; 25435dbd56e3SPeter Brune PetscFunctionReturn(0); 25445dbd56e3SPeter Brune } 25455dbd56e3SPeter Brune 25465dbd56e3SPeter Brune #undef __FUNCT__ 2547be081cd6SPeter Brune #define __FUNCT__ "DMSubDomainRestrict" 25485dbd56e3SPeter Brune /*@ 2549be081cd6SPeter Brune DMSubDomainRestrict - restricts user-defined problem data to a block DM by running hooks registered by DMSubDomainHookAdd() 25505dbd56e3SPeter Brune 25515dbd56e3SPeter Brune Collective if any hooks are 25525dbd56e3SPeter Brune 25535dbd56e3SPeter Brune Input Arguments: 25545dbd56e3SPeter Brune + fine - finer DM to use as a base 2555be081cd6SPeter Brune . oscatter - scatter from domain global vector filling subdomain global vector with overlap 2556be081cd6SPeter Brune . gscatter - scatter from domain global vector filling subdomain local vector with ghosts 25575dbd56e3SPeter Brune - coarse - coarer DM to update 25585dbd56e3SPeter Brune 25595dbd56e3SPeter Brune Level: developer 25605dbd56e3SPeter Brune 25615dbd56e3SPeter Brune .seealso: DMCoarsenHookAdd(), MatRestrict() 25625dbd56e3SPeter Brune @*/ 2563be081cd6SPeter Brune PetscErrorCode DMSubDomainRestrict(DM global,VecScatter oscatter,VecScatter gscatter,DM subdm) 25645dbd56e3SPeter Brune { 25655dbd56e3SPeter Brune PetscErrorCode ierr; 2566be081cd6SPeter Brune DMSubDomainHookLink link; 25675dbd56e3SPeter Brune 25685dbd56e3SPeter Brune PetscFunctionBegin; 2569be081cd6SPeter Brune for (link=global->subdomainhook; link; link=link->next) { 25708865f1eaSKarl Rupp if (link->restricthook) { 25718865f1eaSKarl Rupp ierr = (*link->restricthook)(global,oscatter,gscatter,subdm,link->ctx);CHKERRQ(ierr); 25728865f1eaSKarl Rupp } 25735dbd56e3SPeter Brune } 25745dbd56e3SPeter Brune PetscFunctionReturn(0); 25755dbd56e3SPeter Brune } 25765dbd56e3SPeter Brune 25775dbd56e3SPeter Brune #undef __FUNCT__ 25785fe1f584SPeter Brune #define __FUNCT__ "DMGetCoarsenLevel" 25795fe1f584SPeter Brune /*@ 25806a7d9d85SPeter Brune DMGetCoarsenLevel - Get's the number of coarsenings that have generated this DM. 25815fe1f584SPeter Brune 25825fe1f584SPeter Brune Not Collective 25835fe1f584SPeter Brune 25845fe1f584SPeter Brune Input Parameter: 25855fe1f584SPeter Brune . dm - the DM object 25865fe1f584SPeter Brune 25875fe1f584SPeter Brune Output Parameter: 25886a7d9d85SPeter Brune . level - number of coarsenings 25895fe1f584SPeter Brune 25905fe1f584SPeter Brune Level: developer 25915fe1f584SPeter Brune 25926a7d9d85SPeter Brune .seealso DMCoarsen(), DMGetRefineLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 25935fe1f584SPeter Brune 25945fe1f584SPeter Brune @*/ 25955fe1f584SPeter Brune PetscErrorCode DMGetCoarsenLevel(DM dm,PetscInt *level) 25965fe1f584SPeter Brune { 25975fe1f584SPeter Brune PetscFunctionBegin; 25985fe1f584SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 25995fe1f584SPeter Brune *level = dm->leveldown; 26005fe1f584SPeter Brune PetscFunctionReturn(0); 26015fe1f584SPeter Brune } 26025fe1f584SPeter Brune 26035fe1f584SPeter Brune 26045fe1f584SPeter Brune 26055fe1f584SPeter Brune #undef __FUNCT__ 260647c6ae99SBarry Smith #define __FUNCT__ "DMRefineHierarchy" 260747c6ae99SBarry Smith /*@C 260847c6ae99SBarry Smith DMRefineHierarchy - Refines a DM object, all levels at once 260947c6ae99SBarry Smith 261047c6ae99SBarry Smith Collective on DM 261147c6ae99SBarry Smith 261247c6ae99SBarry Smith Input Parameter: 261347c6ae99SBarry Smith + dm - the DM object 261447c6ae99SBarry Smith - nlevels - the number of levels of refinement 261547c6ae99SBarry Smith 261647c6ae99SBarry Smith Output Parameter: 261747c6ae99SBarry Smith . dmf - the refined DM hierarchy 261847c6ae99SBarry Smith 261947c6ae99SBarry Smith Level: developer 262047c6ae99SBarry Smith 2621e727c939SJed Brown .seealso DMCoarsenHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 262247c6ae99SBarry Smith 262347c6ae99SBarry Smith @*/ 26247087cfbeSBarry Smith PetscErrorCode DMRefineHierarchy(DM dm,PetscInt nlevels,DM dmf[]) 262547c6ae99SBarry Smith { 262647c6ae99SBarry Smith PetscErrorCode ierr; 262747c6ae99SBarry Smith 262847c6ae99SBarry Smith PetscFunctionBegin; 2629171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2630ce94432eSBarry Smith if (nlevels < 0) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 263147c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 263247c6ae99SBarry Smith if (dm->ops->refinehierarchy) { 263347c6ae99SBarry Smith ierr = (*dm->ops->refinehierarchy)(dm,nlevels,dmf);CHKERRQ(ierr); 263447c6ae99SBarry Smith } else if (dm->ops->refine) { 263547c6ae99SBarry Smith PetscInt i; 263647c6ae99SBarry Smith 2637ce94432eSBarry Smith ierr = DMRefine(dm,PetscObjectComm((PetscObject)dm),&dmf[0]);CHKERRQ(ierr); 263847c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 2639ce94432eSBarry Smith ierr = DMRefine(dmf[i-1],PetscObjectComm((PetscObject)dm),&dmf[i]);CHKERRQ(ierr); 264047c6ae99SBarry Smith } 2641ce94432eSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No RefineHierarchy for this DM yet"); 264247c6ae99SBarry Smith PetscFunctionReturn(0); 264347c6ae99SBarry Smith } 264447c6ae99SBarry Smith 264547c6ae99SBarry Smith #undef __FUNCT__ 264647c6ae99SBarry Smith #define __FUNCT__ "DMCoarsenHierarchy" 264747c6ae99SBarry Smith /*@C 264847c6ae99SBarry Smith DMCoarsenHierarchy - Coarsens a DM object, all levels at once 264947c6ae99SBarry Smith 265047c6ae99SBarry Smith Collective on DM 265147c6ae99SBarry Smith 265247c6ae99SBarry Smith Input Parameter: 265347c6ae99SBarry Smith + dm - the DM object 265447c6ae99SBarry Smith - nlevels - the number of levels of coarsening 265547c6ae99SBarry Smith 265647c6ae99SBarry Smith Output Parameter: 265747c6ae99SBarry Smith . dmc - the coarsened DM hierarchy 265847c6ae99SBarry Smith 265947c6ae99SBarry Smith Level: developer 266047c6ae99SBarry Smith 2661e727c939SJed Brown .seealso DMRefineHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 266247c6ae99SBarry Smith 266347c6ae99SBarry Smith @*/ 26647087cfbeSBarry Smith PetscErrorCode DMCoarsenHierarchy(DM dm, PetscInt nlevels, DM dmc[]) 266547c6ae99SBarry Smith { 266647c6ae99SBarry Smith PetscErrorCode ierr; 266747c6ae99SBarry Smith 266847c6ae99SBarry Smith PetscFunctionBegin; 2669171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2670ce94432eSBarry Smith if (nlevels < 0) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 267147c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 267247c6ae99SBarry Smith PetscValidPointer(dmc,3); 267347c6ae99SBarry Smith if (dm->ops->coarsenhierarchy) { 267447c6ae99SBarry Smith ierr = (*dm->ops->coarsenhierarchy)(dm, nlevels, dmc);CHKERRQ(ierr); 267547c6ae99SBarry Smith } else if (dm->ops->coarsen) { 267647c6ae99SBarry Smith PetscInt i; 267747c6ae99SBarry Smith 2678ce94432eSBarry Smith ierr = DMCoarsen(dm,PetscObjectComm((PetscObject)dm),&dmc[0]);CHKERRQ(ierr); 267947c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 2680ce94432eSBarry Smith ierr = DMCoarsen(dmc[i-1],PetscObjectComm((PetscObject)dm),&dmc[i]);CHKERRQ(ierr); 268147c6ae99SBarry Smith } 2682ce94432eSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No CoarsenHierarchy for this DM yet"); 268347c6ae99SBarry Smith PetscFunctionReturn(0); 268447c6ae99SBarry Smith } 268547c6ae99SBarry Smith 268647c6ae99SBarry Smith #undef __FUNCT__ 2687e727c939SJed Brown #define __FUNCT__ "DMCreateAggregates" 268847c6ae99SBarry Smith /*@ 2689e727c939SJed Brown DMCreateAggregates - Gets the aggregates that map between 269047c6ae99SBarry Smith grids associated with two DMs. 269147c6ae99SBarry Smith 269247c6ae99SBarry Smith Collective on DM 269347c6ae99SBarry Smith 269447c6ae99SBarry Smith Input Parameters: 269547c6ae99SBarry Smith + dmc - the coarse grid DM 269647c6ae99SBarry Smith - dmf - the fine grid DM 269747c6ae99SBarry Smith 269847c6ae99SBarry Smith Output Parameters: 269947c6ae99SBarry Smith . rest - the restriction matrix (transpose of the projection matrix) 270047c6ae99SBarry Smith 270147c6ae99SBarry Smith Level: intermediate 270247c6ae99SBarry Smith 270347c6ae99SBarry Smith .keywords: interpolation, restriction, multigrid 270447c6ae99SBarry Smith 2705e727c939SJed Brown .seealso: DMRefine(), DMCreateInjection(), DMCreateInterpolation() 270647c6ae99SBarry Smith @*/ 2707e727c939SJed Brown PetscErrorCode DMCreateAggregates(DM dmc, DM dmf, Mat *rest) 270847c6ae99SBarry Smith { 270947c6ae99SBarry Smith PetscErrorCode ierr; 271047c6ae99SBarry Smith 271147c6ae99SBarry Smith PetscFunctionBegin; 2712171400e9SBarry Smith PetscValidHeaderSpecific(dmc,DM_CLASSID,1); 2713171400e9SBarry Smith PetscValidHeaderSpecific(dmf,DM_CLASSID,2); 271447c6ae99SBarry Smith ierr = (*dmc->ops->getaggregates)(dmc, dmf, rest);CHKERRQ(ierr); 271547c6ae99SBarry Smith PetscFunctionReturn(0); 271647c6ae99SBarry Smith } 271747c6ae99SBarry Smith 271847c6ae99SBarry Smith #undef __FUNCT__ 27191a266240SBarry Smith #define __FUNCT__ "DMSetApplicationContextDestroy" 27201a266240SBarry Smith /*@C 27211a266240SBarry Smith DMSetApplicationContextDestroy - Sets a user function that will be called to destroy the application context when the DM is destroyed 27221a266240SBarry Smith 27231a266240SBarry Smith Not Collective 27241a266240SBarry Smith 27251a266240SBarry Smith Input Parameters: 27261a266240SBarry Smith + dm - the DM object 27271a266240SBarry Smith - destroy - the destroy function 27281a266240SBarry Smith 27291a266240SBarry Smith Level: intermediate 27301a266240SBarry Smith 2731e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 27321a266240SBarry Smith 2733f07f9ceaSJed Brown @*/ 27341a266240SBarry Smith PetscErrorCode DMSetApplicationContextDestroy(DM dm,PetscErrorCode (*destroy)(void**)) 27351a266240SBarry Smith { 27361a266240SBarry Smith PetscFunctionBegin; 2737171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 27381a266240SBarry Smith dm->ctxdestroy = destroy; 27391a266240SBarry Smith PetscFunctionReturn(0); 27401a266240SBarry Smith } 27411a266240SBarry Smith 27421a266240SBarry Smith #undef __FUNCT__ 27431b2093e4SBarry Smith #define __FUNCT__ "DMSetApplicationContext" 2744b07ff414SBarry Smith /*@ 27451b2093e4SBarry Smith DMSetApplicationContext - Set a user context into a DM object 274647c6ae99SBarry Smith 274747c6ae99SBarry Smith Not Collective 274847c6ae99SBarry Smith 274947c6ae99SBarry Smith Input Parameters: 275047c6ae99SBarry Smith + dm - the DM object 275147c6ae99SBarry Smith - ctx - the user context 275247c6ae99SBarry Smith 275347c6ae99SBarry Smith Level: intermediate 275447c6ae99SBarry Smith 2755e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 275647c6ae99SBarry Smith 275747c6ae99SBarry Smith @*/ 27581b2093e4SBarry Smith PetscErrorCode DMSetApplicationContext(DM dm,void *ctx) 275947c6ae99SBarry Smith { 276047c6ae99SBarry Smith PetscFunctionBegin; 2761171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 276247c6ae99SBarry Smith dm->ctx = ctx; 276347c6ae99SBarry Smith PetscFunctionReturn(0); 276447c6ae99SBarry Smith } 276547c6ae99SBarry Smith 276647c6ae99SBarry Smith #undef __FUNCT__ 27671b2093e4SBarry Smith #define __FUNCT__ "DMGetApplicationContext" 276847c6ae99SBarry Smith /*@ 27691b2093e4SBarry Smith DMGetApplicationContext - Gets a user context from a DM object 277047c6ae99SBarry Smith 277147c6ae99SBarry Smith Not Collective 277247c6ae99SBarry Smith 277347c6ae99SBarry Smith Input Parameter: 277447c6ae99SBarry Smith . dm - the DM object 277547c6ae99SBarry Smith 277647c6ae99SBarry Smith Output Parameter: 277747c6ae99SBarry Smith . ctx - the user context 277847c6ae99SBarry Smith 277947c6ae99SBarry Smith Level: intermediate 278047c6ae99SBarry Smith 2781e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 278247c6ae99SBarry Smith 278347c6ae99SBarry Smith @*/ 27841b2093e4SBarry Smith PetscErrorCode DMGetApplicationContext(DM dm,void *ctx) 278547c6ae99SBarry Smith { 278647c6ae99SBarry Smith PetscFunctionBegin; 2787171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 27881b2093e4SBarry Smith *(void**)ctx = dm->ctx; 278947c6ae99SBarry Smith PetscFunctionReturn(0); 279047c6ae99SBarry Smith } 279147c6ae99SBarry Smith 279247c6ae99SBarry Smith #undef __FUNCT__ 279308da532bSDmitry Karpeev #define __FUNCT__ "DMSetVariableBounds" 279408da532bSDmitry Karpeev /*@C 2795df3898eeSBarry Smith DMSetVariableBounds - sets a function to compute the lower and upper bound vectors for SNESVI. 279608da532bSDmitry Karpeev 279708da532bSDmitry Karpeev Logically Collective on DM 279808da532bSDmitry Karpeev 279908da532bSDmitry Karpeev Input Parameter: 280008da532bSDmitry Karpeev + dm - the DM object 28010298fd71SBarry Smith - f - the function that computes variable bounds used by SNESVI (use NULL to cancel a previous function that was set) 280208da532bSDmitry Karpeev 280308da532bSDmitry Karpeev Level: intermediate 280408da532bSDmitry Karpeev 2805835c3ec7SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), 280608da532bSDmitry Karpeev DMSetJacobian() 280708da532bSDmitry Karpeev 280808da532bSDmitry Karpeev @*/ 280908da532bSDmitry Karpeev PetscErrorCode DMSetVariableBounds(DM dm,PetscErrorCode (*f)(DM,Vec,Vec)) 281008da532bSDmitry Karpeev { 281108da532bSDmitry Karpeev PetscFunctionBegin; 281208da532bSDmitry Karpeev dm->ops->computevariablebounds = f; 281308da532bSDmitry Karpeev PetscFunctionReturn(0); 281408da532bSDmitry Karpeev } 281508da532bSDmitry Karpeev 281608da532bSDmitry Karpeev #undef __FUNCT__ 281708da532bSDmitry Karpeev #define __FUNCT__ "DMHasVariableBounds" 281808da532bSDmitry Karpeev /*@ 281908da532bSDmitry Karpeev DMHasVariableBounds - does the DM object have a variable bounds function? 282008da532bSDmitry Karpeev 282108da532bSDmitry Karpeev Not Collective 282208da532bSDmitry Karpeev 282308da532bSDmitry Karpeev Input Parameter: 282408da532bSDmitry Karpeev . dm - the DM object to destroy 282508da532bSDmitry Karpeev 282608da532bSDmitry Karpeev Output Parameter: 282708da532bSDmitry Karpeev . flg - PETSC_TRUE if the variable bounds function exists 282808da532bSDmitry Karpeev 282908da532bSDmitry Karpeev Level: developer 283008da532bSDmitry Karpeev 283174e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 283208da532bSDmitry Karpeev 283308da532bSDmitry Karpeev @*/ 283408da532bSDmitry Karpeev PetscErrorCode DMHasVariableBounds(DM dm,PetscBool *flg) 283508da532bSDmitry Karpeev { 283608da532bSDmitry Karpeev PetscFunctionBegin; 283708da532bSDmitry Karpeev *flg = (dm->ops->computevariablebounds) ? PETSC_TRUE : PETSC_FALSE; 283808da532bSDmitry Karpeev PetscFunctionReturn(0); 283908da532bSDmitry Karpeev } 284008da532bSDmitry Karpeev 284108da532bSDmitry Karpeev #undef __FUNCT__ 284208da532bSDmitry Karpeev #define __FUNCT__ "DMComputeVariableBounds" 284308da532bSDmitry Karpeev /*@C 284408da532bSDmitry Karpeev DMComputeVariableBounds - compute variable bounds used by SNESVI. 284508da532bSDmitry Karpeev 284608da532bSDmitry Karpeev Logically Collective on DM 284708da532bSDmitry Karpeev 284808da532bSDmitry Karpeev Input Parameters: 2849907376e6SBarry Smith . dm - the DM object 285008da532bSDmitry Karpeev 285108da532bSDmitry Karpeev Output parameters: 285208da532bSDmitry Karpeev + xl - lower bound 285308da532bSDmitry Karpeev - xu - upper bound 285408da532bSDmitry Karpeev 2855907376e6SBarry Smith Level: advanced 2856907376e6SBarry Smith 2857907376e6SBarry Smith Notes: This is generally not called by users. It calls the function provided by the user with DMSetVariableBounds() 285808da532bSDmitry Karpeev 285974e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 286008da532bSDmitry Karpeev 286108da532bSDmitry Karpeev @*/ 286208da532bSDmitry Karpeev PetscErrorCode DMComputeVariableBounds(DM dm, Vec xl, Vec xu) 286308da532bSDmitry Karpeev { 286408da532bSDmitry Karpeev PetscErrorCode ierr; 28655fd66863SKarl Rupp 286608da532bSDmitry Karpeev PetscFunctionBegin; 286708da532bSDmitry Karpeev PetscValidHeaderSpecific(xl,VEC_CLASSID,2); 286808da532bSDmitry Karpeev PetscValidHeaderSpecific(xu,VEC_CLASSID,2); 286908da532bSDmitry Karpeev if (dm->ops->computevariablebounds) { 287008da532bSDmitry Karpeev ierr = (*dm->ops->computevariablebounds)(dm, xl,xu);CHKERRQ(ierr); 28718865f1eaSKarl Rupp } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "This DM is incapable of computing variable bounds."); 287208da532bSDmitry Karpeev PetscFunctionReturn(0); 287308da532bSDmitry Karpeev } 287408da532bSDmitry Karpeev 287508da532bSDmitry Karpeev #undef __FUNCT__ 2876b0ae01b7SPeter Brune #define __FUNCT__ "DMHasColoring" 2877b0ae01b7SPeter Brune /*@ 2878b0ae01b7SPeter Brune DMHasColoring - does the DM object have a method of providing a coloring? 2879b0ae01b7SPeter Brune 2880b0ae01b7SPeter Brune Not Collective 2881b0ae01b7SPeter Brune 2882b0ae01b7SPeter Brune Input Parameter: 2883b0ae01b7SPeter Brune . dm - the DM object 2884b0ae01b7SPeter Brune 2885b0ae01b7SPeter Brune Output Parameter: 2886b0ae01b7SPeter Brune . flg - PETSC_TRUE if the DM has facilities for DMCreateColoring(). 2887b0ae01b7SPeter Brune 2888b0ae01b7SPeter Brune Level: developer 2889b0ae01b7SPeter Brune 2890b0ae01b7SPeter Brune .seealso DMHasFunction(), DMCreateColoring() 2891b0ae01b7SPeter Brune 2892b0ae01b7SPeter Brune @*/ 2893b0ae01b7SPeter Brune PetscErrorCode DMHasColoring(DM dm,PetscBool *flg) 2894b0ae01b7SPeter Brune { 2895b0ae01b7SPeter Brune PetscFunctionBegin; 2896b0ae01b7SPeter Brune *flg = (dm->ops->getcoloring) ? PETSC_TRUE : PETSC_FALSE; 2897b0ae01b7SPeter Brune PetscFunctionReturn(0); 2898b0ae01b7SPeter Brune } 2899b0ae01b7SPeter Brune 2900b0ae01b7SPeter Brune #undef __FUNCT__ 29013ad4599aSBarry Smith #define __FUNCT__ "DMHasCreateRestriction" 29023ad4599aSBarry Smith /*@ 29033ad4599aSBarry Smith DMHasCreateRestriction - does the DM object have a method of providing a restriction? 29043ad4599aSBarry Smith 29053ad4599aSBarry Smith Not Collective 29063ad4599aSBarry Smith 29073ad4599aSBarry Smith Input Parameter: 29083ad4599aSBarry Smith . dm - the DM object 29093ad4599aSBarry Smith 29103ad4599aSBarry Smith Output Parameter: 29113ad4599aSBarry Smith . flg - PETSC_TRUE if the DM has facilities for DMCreateRestriction(). 29123ad4599aSBarry Smith 29133ad4599aSBarry Smith Level: developer 29143ad4599aSBarry Smith 29153ad4599aSBarry Smith .seealso DMHasFunction(), DMCreateRestriction() 29163ad4599aSBarry Smith 29173ad4599aSBarry Smith @*/ 29183ad4599aSBarry Smith PetscErrorCode DMHasCreateRestriction(DM dm,PetscBool *flg) 29193ad4599aSBarry Smith { 29203ad4599aSBarry Smith PetscFunctionBegin; 29213ad4599aSBarry Smith *flg = (dm->ops->createrestriction) ? PETSC_TRUE : PETSC_FALSE; 29223ad4599aSBarry Smith PetscFunctionReturn(0); 29233ad4599aSBarry Smith } 29243ad4599aSBarry Smith 29253ad4599aSBarry Smith #undef __FUNCT__ 292608da532bSDmitry Karpeev #define __FUNCT__ "DMSetVec" 2927748fac09SDmitry Karpeev /*@C 292808da532bSDmitry Karpeev DMSetVec - set the vector at which to compute residual, Jacobian and VI bounds, if the problem is nonlinear. 292908da532bSDmitry Karpeev 293008da532bSDmitry Karpeev Collective on DM 293108da532bSDmitry Karpeev 293208da532bSDmitry Karpeev Input Parameter: 293308da532bSDmitry Karpeev + dm - the DM object 29340298fd71SBarry Smith - x - location to compute residual and Jacobian, if NULL is passed to those routines; will be NULL for linear problems. 293508da532bSDmitry Karpeev 293608da532bSDmitry Karpeev Level: developer 293708da532bSDmitry Karpeev 293874e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 293908da532bSDmitry Karpeev 294008da532bSDmitry Karpeev @*/ 294108da532bSDmitry Karpeev PetscErrorCode DMSetVec(DM dm,Vec x) 294208da532bSDmitry Karpeev { 294308da532bSDmitry Karpeev PetscErrorCode ierr; 29445fd66863SKarl Rupp 294508da532bSDmitry Karpeev PetscFunctionBegin; 294608da532bSDmitry Karpeev if (x) { 294708da532bSDmitry Karpeev if (!dm->x) { 294808da532bSDmitry Karpeev ierr = DMCreateGlobalVector(dm,&dm->x);CHKERRQ(ierr); 294908da532bSDmitry Karpeev } 295008da532bSDmitry Karpeev ierr = VecCopy(x,dm->x);CHKERRQ(ierr); 29518865f1eaSKarl Rupp } else if (dm->x) { 295208da532bSDmitry Karpeev ierr = VecDestroy(&dm->x);CHKERRQ(ierr); 295308da532bSDmitry Karpeev } 295408da532bSDmitry Karpeev PetscFunctionReturn(0); 295508da532bSDmitry Karpeev } 295608da532bSDmitry Karpeev 29570298fd71SBarry Smith PetscFunctionList DMList = NULL; 2958264ace61SBarry Smith PetscBool DMRegisterAllCalled = PETSC_FALSE; 2959264ace61SBarry Smith 2960264ace61SBarry Smith #undef __FUNCT__ 2961264ace61SBarry Smith #define __FUNCT__ "DMSetType" 2962264ace61SBarry Smith /*@C 2963264ace61SBarry Smith DMSetType - Builds a DM, for a particular DM implementation. 2964264ace61SBarry Smith 2965264ace61SBarry Smith Collective on DM 2966264ace61SBarry Smith 2967264ace61SBarry Smith Input Parameters: 2968264ace61SBarry Smith + dm - The DM object 2969264ace61SBarry Smith - method - The name of the DM type 2970264ace61SBarry Smith 2971264ace61SBarry Smith Options Database Key: 2972264ace61SBarry Smith . -dm_type <type> - Sets the DM type; use -help for a list of available types 2973264ace61SBarry Smith 2974264ace61SBarry Smith Notes: 2975e1589f56SBarry Smith See "petsc/include/petscdm.h" for available DM types (for instance, DM1D, DM2D, or DM3D). 2976264ace61SBarry Smith 2977264ace61SBarry Smith Level: intermediate 2978264ace61SBarry Smith 2979264ace61SBarry Smith .keywords: DM, set, type 2980264ace61SBarry Smith .seealso: DMGetType(), DMCreate() 2981264ace61SBarry Smith @*/ 298219fd82e9SBarry Smith PetscErrorCode DMSetType(DM dm, DMType method) 2983264ace61SBarry Smith { 2984264ace61SBarry Smith PetscErrorCode (*r)(DM); 2985264ace61SBarry Smith PetscBool match; 2986264ace61SBarry Smith PetscErrorCode ierr; 2987264ace61SBarry Smith 2988264ace61SBarry Smith PetscFunctionBegin; 2989264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 2990251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject) dm, method, &match);CHKERRQ(ierr); 2991264ace61SBarry Smith if (match) PetscFunctionReturn(0); 2992264ace61SBarry Smith 29930f51fdf8SToby Isaac ierr = DMRegisterAll();CHKERRQ(ierr); 29941c9cd337SJed Brown ierr = PetscFunctionListFind(DMList,method,&r);CHKERRQ(ierr); 2995ce94432eSBarry Smith if (!r) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown DM type: %s", method); 2996264ace61SBarry Smith 2997264ace61SBarry Smith if (dm->ops->destroy) { 2998264ace61SBarry Smith ierr = (*dm->ops->destroy)(dm);CHKERRQ(ierr); 29990298fd71SBarry Smith dm->ops->destroy = NULL; 3000264ace61SBarry Smith } 3001264ace61SBarry Smith ierr = (*r)(dm);CHKERRQ(ierr); 3002264ace61SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)dm,method);CHKERRQ(ierr); 3003264ace61SBarry Smith PetscFunctionReturn(0); 3004264ace61SBarry Smith } 3005264ace61SBarry Smith 3006264ace61SBarry Smith #undef __FUNCT__ 3007264ace61SBarry Smith #define __FUNCT__ "DMGetType" 3008264ace61SBarry Smith /*@C 3009264ace61SBarry Smith DMGetType - Gets the DM type name (as a string) from the DM. 3010264ace61SBarry Smith 3011264ace61SBarry Smith Not Collective 3012264ace61SBarry Smith 3013264ace61SBarry Smith Input Parameter: 3014264ace61SBarry Smith . dm - The DM 3015264ace61SBarry Smith 3016264ace61SBarry Smith Output Parameter: 3017264ace61SBarry Smith . type - The DM type name 3018264ace61SBarry Smith 3019264ace61SBarry Smith Level: intermediate 3020264ace61SBarry Smith 3021264ace61SBarry Smith .keywords: DM, get, type, name 3022264ace61SBarry Smith .seealso: DMSetType(), DMCreate() 3023264ace61SBarry Smith @*/ 302419fd82e9SBarry Smith PetscErrorCode DMGetType(DM dm, DMType *type) 3025264ace61SBarry Smith { 3026264ace61SBarry Smith PetscErrorCode ierr; 3027264ace61SBarry Smith 3028264ace61SBarry Smith PetscFunctionBegin; 3029264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 3030c959eef4SJed Brown PetscValidPointer(type,2); 3031607a6623SBarry Smith ierr = DMRegisterAll();CHKERRQ(ierr); 3032264ace61SBarry Smith *type = ((PetscObject)dm)->type_name; 3033264ace61SBarry Smith PetscFunctionReturn(0); 3034264ace61SBarry Smith } 3035264ace61SBarry Smith 303667a56275SMatthew G Knepley #undef __FUNCT__ 303767a56275SMatthew G Knepley #define __FUNCT__ "DMConvert" 303867a56275SMatthew G Knepley /*@C 303967a56275SMatthew G Knepley DMConvert - Converts a DM to another DM, either of the same or different type. 304067a56275SMatthew G Knepley 304167a56275SMatthew G Knepley Collective on DM 304267a56275SMatthew G Knepley 304367a56275SMatthew G Knepley Input Parameters: 304467a56275SMatthew G Knepley + dm - the DM 304567a56275SMatthew G Knepley - newtype - new DM type (use "same" for the same type) 304667a56275SMatthew G Knepley 304767a56275SMatthew G Knepley Output Parameter: 304867a56275SMatthew G Knepley . M - pointer to new DM 304967a56275SMatthew G Knepley 305067a56275SMatthew G Knepley Notes: 305167a56275SMatthew G Knepley Cannot be used to convert a sequential DM to parallel or parallel to sequential, 305267a56275SMatthew G Knepley the MPI communicator of the generated DM is always the same as the communicator 305367a56275SMatthew G Knepley of the input DM. 305467a56275SMatthew G Knepley 305567a56275SMatthew G Knepley Level: intermediate 305667a56275SMatthew G Knepley 305767a56275SMatthew G Knepley .seealso: DMCreate() 305867a56275SMatthew G Knepley @*/ 305919fd82e9SBarry Smith PetscErrorCode DMConvert(DM dm, DMType newtype, DM *M) 306067a56275SMatthew G Knepley { 306167a56275SMatthew G Knepley DM B; 306267a56275SMatthew G Knepley char convname[256]; 3063c067b6caSMatthew G. Knepley PetscBool sametype/*, issame */; 306467a56275SMatthew G Knepley PetscErrorCode ierr; 306567a56275SMatthew G Knepley 306667a56275SMatthew G Knepley PetscFunctionBegin; 306767a56275SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 306867a56275SMatthew G Knepley PetscValidType(dm,1); 306967a56275SMatthew G Knepley PetscValidPointer(M,3); 3070251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject) dm, newtype, &sametype);CHKERRQ(ierr); 3071c067b6caSMatthew G. Knepley /* ierr = PetscStrcmp(newtype, "same", &issame);CHKERRQ(ierr); */ 3072c067b6caSMatthew G. Knepley if (sametype) { 3073c067b6caSMatthew G. Knepley *M = dm; 3074c067b6caSMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm);CHKERRQ(ierr); 3075c067b6caSMatthew G. Knepley PetscFunctionReturn(0); 3076c067b6caSMatthew G. Knepley } else { 30770298fd71SBarry Smith PetscErrorCode (*conv)(DM, DMType, DM*) = NULL; 307867a56275SMatthew G Knepley 307967a56275SMatthew G Knepley /* 308067a56275SMatthew G Knepley Order of precedence: 308167a56275SMatthew G Knepley 1) See if a specialized converter is known to the current DM. 308267a56275SMatthew G Knepley 2) See if a specialized converter is known to the desired DM class. 308367a56275SMatthew G Knepley 3) See if a good general converter is registered for the desired class 308467a56275SMatthew G Knepley 4) See if a good general converter is known for the current matrix. 308567a56275SMatthew G Knepley 5) Use a really basic converter. 308667a56275SMatthew G Knepley */ 308767a56275SMatthew G Knepley 308867a56275SMatthew G Knepley /* 1) See if a specialized converter is known to the current DM and the desired class */ 308967a56275SMatthew G Knepley ierr = PetscStrcpy(convname,"DMConvert_");CHKERRQ(ierr); 309067a56275SMatthew G Knepley ierr = PetscStrcat(convname,((PetscObject) dm)->type_name);CHKERRQ(ierr); 309167a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_");CHKERRQ(ierr); 309267a56275SMatthew G Knepley ierr = PetscStrcat(convname,newtype);CHKERRQ(ierr); 309367a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_C");CHKERRQ(ierr); 30940005d66cSJed Brown ierr = PetscObjectQueryFunction((PetscObject)dm,convname,&conv);CHKERRQ(ierr); 309567a56275SMatthew G Knepley if (conv) goto foundconv; 309667a56275SMatthew G Knepley 309767a56275SMatthew G Knepley /* 2) See if a specialized converter is known to the desired DM class. */ 309882f516ccSBarry Smith ierr = DMCreate(PetscObjectComm((PetscObject)dm), &B);CHKERRQ(ierr); 309967a56275SMatthew G Knepley ierr = DMSetType(B, newtype);CHKERRQ(ierr); 310067a56275SMatthew G Knepley ierr = PetscStrcpy(convname,"DMConvert_");CHKERRQ(ierr); 310167a56275SMatthew G Knepley ierr = PetscStrcat(convname,((PetscObject) dm)->type_name);CHKERRQ(ierr); 310267a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_");CHKERRQ(ierr); 310367a56275SMatthew G Knepley ierr = PetscStrcat(convname,newtype);CHKERRQ(ierr); 310467a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_C");CHKERRQ(ierr); 31050005d66cSJed Brown ierr = PetscObjectQueryFunction((PetscObject)B,convname,&conv);CHKERRQ(ierr); 310667a56275SMatthew G Knepley if (conv) { 3107fcfd50ebSBarry Smith ierr = DMDestroy(&B);CHKERRQ(ierr); 310867a56275SMatthew G Knepley goto foundconv; 310967a56275SMatthew G Knepley } 311067a56275SMatthew G Knepley 311167a56275SMatthew G Knepley #if 0 311267a56275SMatthew G Knepley /* 3) See if a good general converter is registered for the desired class */ 311367a56275SMatthew G Knepley conv = B->ops->convertfrom; 3114fcfd50ebSBarry Smith ierr = DMDestroy(&B);CHKERRQ(ierr); 311567a56275SMatthew G Knepley if (conv) goto foundconv; 311667a56275SMatthew G Knepley 311767a56275SMatthew G Knepley /* 4) See if a good general converter is known for the current matrix */ 311867a56275SMatthew G Knepley if (dm->ops->convert) { 311967a56275SMatthew G Knepley conv = dm->ops->convert; 312067a56275SMatthew G Knepley } 312167a56275SMatthew G Knepley if (conv) goto foundconv; 312267a56275SMatthew G Knepley #endif 312367a56275SMatthew G Knepley 312467a56275SMatthew G Knepley /* 5) Use a really basic converter. */ 312582f516ccSBarry Smith SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "No conversion possible between DM types %s and %s", ((PetscObject) dm)->type_name, newtype); 312667a56275SMatthew G Knepley 312767a56275SMatthew G Knepley foundconv: 312867a56275SMatthew G Knepley ierr = PetscLogEventBegin(DM_Convert,dm,0,0,0);CHKERRQ(ierr); 312967a56275SMatthew G Knepley ierr = (*conv)(dm,newtype,M);CHKERRQ(ierr); 313012fa691eSMatthew G. Knepley /* Things that are independent of DM type: We should consult DMClone() here */ 313112fa691eSMatthew G. Knepley if (dm->maxCell) { 313212fa691eSMatthew G. Knepley const PetscReal *maxCell, *L; 313312fa691eSMatthew G. Knepley const DMBoundaryType *bd; 313412fa691eSMatthew G. Knepley ierr = DMGetPeriodicity(dm, &maxCell, &L, &bd);CHKERRQ(ierr); 313512fa691eSMatthew G. Knepley ierr = DMSetPeriodicity(*M, maxCell, L, bd);CHKERRQ(ierr); 313612fa691eSMatthew G. Knepley } 313767a56275SMatthew G Knepley ierr = PetscLogEventEnd(DM_Convert,dm,0,0,0);CHKERRQ(ierr); 313867a56275SMatthew G Knepley } 313967a56275SMatthew G Knepley ierr = PetscObjectStateIncrease((PetscObject) *M);CHKERRQ(ierr); 314067a56275SMatthew G Knepley PetscFunctionReturn(0); 314167a56275SMatthew G Knepley } 3142264ace61SBarry Smith 3143264ace61SBarry Smith /*--------------------------------------------------------------------------------------------------------------------*/ 3144264ace61SBarry Smith 3145264ace61SBarry Smith #undef __FUNCT__ 3146264ace61SBarry Smith #define __FUNCT__ "DMRegister" 3147264ace61SBarry Smith /*@C 31481c84c290SBarry Smith DMRegister - Adds a new DM component implementation 31491c84c290SBarry Smith 31501c84c290SBarry Smith Not Collective 31511c84c290SBarry Smith 31521c84c290SBarry Smith Input Parameters: 31531c84c290SBarry Smith + name - The name of a new user-defined creation routine 31541c84c290SBarry Smith - create_func - The creation routine itself 31551c84c290SBarry Smith 31561c84c290SBarry Smith Notes: 31571c84c290SBarry Smith DMRegister() may be called multiple times to add several user-defined DMs 31581c84c290SBarry Smith 31591c84c290SBarry Smith 31601c84c290SBarry Smith Sample usage: 31611c84c290SBarry Smith .vb 3162bdf89e91SBarry Smith DMRegister("my_da", MyDMCreate); 31631c84c290SBarry Smith .ve 31641c84c290SBarry Smith 31651c84c290SBarry Smith Then, your DM type can be chosen with the procedural interface via 31661c84c290SBarry Smith .vb 31671c84c290SBarry Smith DMCreate(MPI_Comm, DM *); 31681c84c290SBarry Smith DMSetType(DM,"my_da"); 31691c84c290SBarry Smith .ve 31701c84c290SBarry Smith or at runtime via the option 31711c84c290SBarry Smith .vb 31721c84c290SBarry Smith -da_type my_da 31731c84c290SBarry Smith .ve 3174264ace61SBarry Smith 3175264ace61SBarry Smith Level: advanced 31761c84c290SBarry Smith 31771c84c290SBarry Smith .keywords: DM, register 3178bdf89e91SBarry Smith .seealso: DMRegisterAll(), DMRegisterDestroy() 31791c84c290SBarry Smith 3180264ace61SBarry Smith @*/ 3181bdf89e91SBarry Smith PetscErrorCode DMRegister(const char sname[],PetscErrorCode (*function)(DM)) 3182264ace61SBarry Smith { 3183264ace61SBarry Smith PetscErrorCode ierr; 3184264ace61SBarry Smith 3185264ace61SBarry Smith PetscFunctionBegin; 3186a240a19fSJed Brown ierr = PetscFunctionListAdd(&DMList,sname,function);CHKERRQ(ierr); 3187264ace61SBarry Smith PetscFunctionReturn(0); 3188264ace61SBarry Smith } 3189264ace61SBarry Smith 3190b859378eSBarry Smith #undef __FUNCT__ 3191b859378eSBarry Smith #define __FUNCT__ "DMLoad" 3192b859378eSBarry Smith /*@C 319355849f57SBarry Smith DMLoad - Loads a DM that has been stored in binary with DMView(). 3194b859378eSBarry Smith 3195b859378eSBarry Smith Collective on PetscViewer 3196b859378eSBarry Smith 3197b859378eSBarry Smith Input Parameters: 3198b859378eSBarry Smith + newdm - the newly loaded DM, this needs to have been created with DMCreate() or 3199b859378eSBarry Smith some related function before a call to DMLoad(). 3200b859378eSBarry Smith - viewer - binary file viewer, obtained from PetscViewerBinaryOpen() or 3201b859378eSBarry Smith HDF5 file viewer, obtained from PetscViewerHDF5Open() 3202b859378eSBarry Smith 3203b859378eSBarry Smith Level: intermediate 3204b859378eSBarry Smith 3205b859378eSBarry Smith Notes: 320655849f57SBarry Smith The type is determined by the data in the file, any type set into the DM before this call is ignored. 3207b859378eSBarry Smith 3208b859378eSBarry Smith Notes for advanced users: 3209b859378eSBarry Smith Most users should not need to know the details of the binary storage 3210b859378eSBarry Smith format, since DMLoad() and DMView() completely hide these details. 3211b859378eSBarry Smith But for anyone who's interested, the standard binary matrix storage 3212b859378eSBarry Smith format is 3213b859378eSBarry Smith .vb 3214b859378eSBarry Smith has not yet been determined 3215b859378eSBarry Smith .ve 3216b859378eSBarry Smith 3217b859378eSBarry Smith .seealso: PetscViewerBinaryOpen(), DMView(), MatLoad(), VecLoad() 3218b859378eSBarry Smith @*/ 3219b859378eSBarry Smith PetscErrorCode DMLoad(DM newdm, PetscViewer viewer) 3220b859378eSBarry Smith { 32219331c7a4SMatthew G. Knepley PetscBool isbinary, ishdf5; 3222b859378eSBarry Smith PetscErrorCode ierr; 3223b859378eSBarry Smith 3224b859378eSBarry Smith PetscFunctionBegin; 3225b859378eSBarry Smith PetscValidHeaderSpecific(newdm,DM_CLASSID,1); 3226b859378eSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 322732c0f0efSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); 32289331c7a4SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERHDF5,&ishdf5);CHKERRQ(ierr); 32299331c7a4SMatthew G. Knepley if (isbinary) { 32309331c7a4SMatthew G. Knepley PetscInt classid; 32319331c7a4SMatthew G. Knepley char type[256]; 3232b859378eSBarry Smith 3233060da220SMatthew G. Knepley ierr = PetscViewerBinaryRead(viewer,&classid,1,NULL,PETSC_INT);CHKERRQ(ierr); 32349200755eSBarry Smith if (classid != DM_FILE_CLASSID) SETERRQ1(PetscObjectComm((PetscObject)newdm),PETSC_ERR_ARG_WRONG,"Not DM next in file, classid found %d",(int)classid); 3235060da220SMatthew G. Knepley ierr = PetscViewerBinaryRead(viewer,type,256,NULL,PETSC_CHAR);CHKERRQ(ierr); 323632c0f0efSBarry Smith ierr = DMSetType(newdm, type);CHKERRQ(ierr); 32379331c7a4SMatthew G. Knepley if (newdm->ops->load) {ierr = (*newdm->ops->load)(newdm,viewer);CHKERRQ(ierr);} 32389331c7a4SMatthew G. Knepley } else if (ishdf5) { 32399331c7a4SMatthew G. Knepley if (newdm->ops->load) {ierr = (*newdm->ops->load)(newdm,viewer);CHKERRQ(ierr);} 32409331c7a4SMatthew G. Knepley } else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Invalid viewer; open viewer with PetscViewerBinaryOpen() or PetscViewerHDF5Open()"); 3241b859378eSBarry Smith PetscFunctionReturn(0); 3242b859378eSBarry Smith } 3243b859378eSBarry Smith 32447da65231SMatthew G Knepley /******************************** FEM Support **********************************/ 32457da65231SMatthew G Knepley 32467da65231SMatthew G Knepley #undef __FUNCT__ 32477da65231SMatthew G Knepley #define __FUNCT__ "DMPrintCellVector" 3248a6dfd86eSKarl Rupp PetscErrorCode DMPrintCellVector(PetscInt c, const char name[], PetscInt len, const PetscScalar x[]) 3249a6dfd86eSKarl Rupp { 32501d47ebbbSSatish Balay PetscInt f; 32511b30c384SMatthew G Knepley PetscErrorCode ierr; 32521b30c384SMatthew G Knepley 32537da65231SMatthew G Knepley PetscFunctionBegin; 325474778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, "Cell %D Element %s\n", c, name);CHKERRQ(ierr); 32551d47ebbbSSatish Balay for (f = 0; f < len; ++f) { 325657622a8eSBarry Smith ierr = PetscPrintf(PETSC_COMM_SELF, " | %g |\n", (double)PetscRealPart(x[f]));CHKERRQ(ierr); 32577da65231SMatthew G Knepley } 32587da65231SMatthew G Knepley PetscFunctionReturn(0); 32597da65231SMatthew G Knepley } 32607da65231SMatthew G Knepley 32617da65231SMatthew G Knepley #undef __FUNCT__ 32627da65231SMatthew G Knepley #define __FUNCT__ "DMPrintCellMatrix" 3263a6dfd86eSKarl Rupp PetscErrorCode DMPrintCellMatrix(PetscInt c, const char name[], PetscInt rows, PetscInt cols, const PetscScalar A[]) 3264a6dfd86eSKarl Rupp { 32651b30c384SMatthew G Knepley PetscInt f, g; 32667da65231SMatthew G Knepley PetscErrorCode ierr; 32677da65231SMatthew G Knepley 32687da65231SMatthew G Knepley PetscFunctionBegin; 326974778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, "Cell %D Element %s\n", c, name);CHKERRQ(ierr); 32701d47ebbbSSatish Balay for (f = 0; f < rows; ++f) { 327174778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " |");CHKERRQ(ierr); 32721d47ebbbSSatish Balay for (g = 0; g < cols; ++g) { 3273e3556bceSMatthew G. Knepley ierr = PetscPrintf(PETSC_COMM_SELF, " % 9.5g", PetscRealPart(A[f*cols+g]));CHKERRQ(ierr); 32747da65231SMatthew G Knepley } 327574778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " |\n");CHKERRQ(ierr); 32767da65231SMatthew G Knepley } 32777da65231SMatthew G Knepley PetscFunctionReturn(0); 32787da65231SMatthew G Knepley } 3279e7c4fc90SDmitry Karpeev 3280970e74d5SMatthew G Knepley #undef __FUNCT__ 3281e759306cSMatthew G. Knepley #define __FUNCT__ "DMPrintLocalVec" 32826113b454SMatthew G. Knepley PetscErrorCode DMPrintLocalVec(DM dm, const char name[], PetscReal tol, Vec X) 3283e759306cSMatthew G. Knepley { 3284e759306cSMatthew G. Knepley PetscMPIInt rank, numProcs; 3285e759306cSMatthew G. Knepley PetscInt p; 3286e759306cSMatthew G. Knepley PetscErrorCode ierr; 3287e759306cSMatthew G. Knepley 3288e759306cSMatthew G. Knepley PetscFunctionBegin; 3289e759306cSMatthew G. Knepley ierr = MPI_Comm_rank(PetscObjectComm((PetscObject) dm), &rank);CHKERRQ(ierr); 3290e759306cSMatthew G. Knepley ierr = MPI_Comm_size(PetscObjectComm((PetscObject) dm), &numProcs);CHKERRQ(ierr); 3291e759306cSMatthew G. Knepley ierr = PetscPrintf(PetscObjectComm((PetscObject) dm), "%s:\n", name);CHKERRQ(ierr); 3292e759306cSMatthew G. Knepley for (p = 0; p < numProcs; ++p) { 3293e759306cSMatthew G. Knepley if (p == rank) { 3294e759306cSMatthew G. Knepley Vec x; 3295e759306cSMatthew G. Knepley 3296e759306cSMatthew G. Knepley ierr = VecDuplicate(X, &x);CHKERRQ(ierr); 3297e759306cSMatthew G. Knepley ierr = VecCopy(X, x);CHKERRQ(ierr); 32986113b454SMatthew G. Knepley ierr = VecChop(x, tol);CHKERRQ(ierr); 3299e759306cSMatthew G. Knepley ierr = VecView(x, PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); 3300e759306cSMatthew G. Knepley ierr = VecDestroy(&x);CHKERRQ(ierr); 3301e759306cSMatthew G. Knepley ierr = PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); 3302e759306cSMatthew G. Knepley } 3303e759306cSMatthew G. Knepley ierr = PetscBarrier((PetscObject) dm);CHKERRQ(ierr); 3304e759306cSMatthew G. Knepley } 3305e759306cSMatthew G. Knepley PetscFunctionReturn(0); 3306e759306cSMatthew G. Knepley } 3307e759306cSMatthew G. Knepley 3308e759306cSMatthew G. Knepley #undef __FUNCT__ 330988ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultSection" 331088ed4aceSMatthew G Knepley /*@ 331188ed4aceSMatthew G Knepley DMGetDefaultSection - Get the PetscSection encoding the local data layout for the DM. 331288ed4aceSMatthew G Knepley 331388ed4aceSMatthew G Knepley Input Parameter: 331488ed4aceSMatthew G Knepley . dm - The DM 331588ed4aceSMatthew G Knepley 331688ed4aceSMatthew G Knepley Output Parameter: 331788ed4aceSMatthew G Knepley . section - The PetscSection 331888ed4aceSMatthew G Knepley 331988ed4aceSMatthew G Knepley Level: intermediate 332088ed4aceSMatthew G Knepley 332188ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSection. 332288ed4aceSMatthew G Knepley 332388ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultGlobalSection() 332488ed4aceSMatthew G Knepley @*/ 33250adebc6cSBarry Smith PetscErrorCode DMGetDefaultSection(DM dm, PetscSection *section) 33260adebc6cSBarry Smith { 3327fd59a867SMatthew G. Knepley PetscErrorCode ierr; 3328fd59a867SMatthew G. Knepley 332988ed4aceSMatthew G Knepley PetscFunctionBegin; 333088ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 333188ed4aceSMatthew G Knepley PetscValidPointer(section, 2); 33322f0f8703SMatthew G. Knepley if (!dm->defaultSection && dm->ops->createdefaultsection) { 33332f0f8703SMatthew G. Knepley ierr = (*dm->ops->createdefaultsection)(dm);CHKERRQ(ierr); 3334ae71db08SMatthew G. Knepley if (dm->defaultSection) {ierr = PetscObjectViewFromOptions((PetscObject) dm->defaultSection, NULL, "-dm_petscsection_view");CHKERRQ(ierr);} 33352f0f8703SMatthew G. Knepley } 333688ed4aceSMatthew G Knepley *section = dm->defaultSection; 333788ed4aceSMatthew G Knepley PetscFunctionReturn(0); 333888ed4aceSMatthew G Knepley } 333988ed4aceSMatthew G Knepley 334088ed4aceSMatthew G Knepley #undef __FUNCT__ 334188ed4aceSMatthew G Knepley #define __FUNCT__ "DMSetDefaultSection" 334288ed4aceSMatthew G Knepley /*@ 334388ed4aceSMatthew G Knepley DMSetDefaultSection - Set the PetscSection encoding the local data layout for the DM. 334488ed4aceSMatthew G Knepley 334588ed4aceSMatthew G Knepley Input Parameters: 334688ed4aceSMatthew G Knepley + dm - The DM 334788ed4aceSMatthew G Knepley - section - The PetscSection 334888ed4aceSMatthew G Knepley 334988ed4aceSMatthew G Knepley Level: intermediate 335088ed4aceSMatthew G Knepley 335188ed4aceSMatthew G Knepley Note: Any existing Section will be destroyed 335288ed4aceSMatthew G Knepley 335388ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultGlobalSection() 335488ed4aceSMatthew G Knepley @*/ 33550adebc6cSBarry Smith PetscErrorCode DMSetDefaultSection(DM dm, PetscSection section) 33560adebc6cSBarry Smith { 3357c473ab19SMatthew G. Knepley PetscInt numFields = 0; 3358af122d2aSMatthew G Knepley PetscInt f; 335988ed4aceSMatthew G Knepley PetscErrorCode ierr; 336088ed4aceSMatthew G Knepley 336188ed4aceSMatthew G Knepley PetscFunctionBegin; 336288ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3363c473ab19SMatthew G. Knepley if (section) { 33641d799100SJed Brown PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 33651d799100SJed Brown ierr = PetscObjectReference((PetscObject)section);CHKERRQ(ierr); 3366c473ab19SMatthew G. Knepley } 336788ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&dm->defaultSection);CHKERRQ(ierr); 336888ed4aceSMatthew G Knepley dm->defaultSection = section; 3369c473ab19SMatthew G. Knepley if (section) {ierr = PetscSectionGetNumFields(dm->defaultSection, &numFields);CHKERRQ(ierr);} 3370af122d2aSMatthew G Knepley if (numFields) { 3371af122d2aSMatthew G Knepley ierr = DMSetNumFields(dm, numFields);CHKERRQ(ierr); 3372af122d2aSMatthew G Knepley for (f = 0; f < numFields; ++f) { 33730f21e855SMatthew G. Knepley PetscObject disc; 3374af122d2aSMatthew G Knepley const char *name; 3375af122d2aSMatthew G Knepley 3376af122d2aSMatthew G Knepley ierr = PetscSectionGetFieldName(dm->defaultSection, f, &name);CHKERRQ(ierr); 33770f21e855SMatthew G. Knepley ierr = DMGetField(dm, f, &disc);CHKERRQ(ierr); 33780f21e855SMatthew G. Knepley ierr = PetscObjectSetName(disc, name);CHKERRQ(ierr); 3379af122d2aSMatthew G Knepley } 3380af122d2aSMatthew G Knepley } 33811d799100SJed Brown /* The global section will be rebuilt in the next call to DMGetDefaultGlobalSection(). */ 33821d799100SJed Brown ierr = PetscSectionDestroy(&dm->defaultGlobalSection);CHKERRQ(ierr); 338388ed4aceSMatthew G Knepley PetscFunctionReturn(0); 338488ed4aceSMatthew G Knepley } 338588ed4aceSMatthew G Knepley 338688ed4aceSMatthew G Knepley #undef __FUNCT__ 33879435951eSToby Isaac #define __FUNCT__ "DMGetDefaultConstraints" 33889435951eSToby Isaac /*@ 33899435951eSToby Isaac DMGetDefaultConstraints - Get the PetscSection and Mat the specify the local constraint interpolation. See DMSetDefaultConstraints() for a description of the purpose of constraint interpolation. 33909435951eSToby Isaac 3391e228b242SToby Isaac not collective 3392e228b242SToby Isaac 33939435951eSToby Isaac Input Parameter: 33949435951eSToby Isaac . dm - The DM 33959435951eSToby Isaac 33969435951eSToby Isaac Output Parameter: 33979435951eSToby 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. 33989435951eSToby 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. 33999435951eSToby Isaac 34009435951eSToby Isaac Level: advanced 34019435951eSToby Isaac 34029435951eSToby Isaac Note: This gets borrowed references, so the user should not destroy the PetscSection or the Mat. 34039435951eSToby Isaac 34049435951eSToby Isaac .seealso: DMSetDefaultConstraints() 34059435951eSToby Isaac @*/ 34069435951eSToby Isaac PetscErrorCode DMGetDefaultConstraints(DM dm, PetscSection *section, Mat *mat) 34079435951eSToby Isaac { 34089435951eSToby Isaac PetscErrorCode ierr; 34099435951eSToby Isaac 34109435951eSToby Isaac PetscFunctionBegin; 34119435951eSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 34129435951eSToby Isaac if (!dm->defaultConstraintSection && !dm->defaultConstraintMat && dm->ops->createdefaultconstraints) {ierr = (*dm->ops->createdefaultconstraints)(dm);CHKERRQ(ierr);} 341345a75d81SToby Isaac if (section) {*section = dm->defaultConstraintSection;} 341445a75d81SToby Isaac if (mat) {*mat = dm->defaultConstraintMat;} 34159435951eSToby Isaac PetscFunctionReturn(0); 34169435951eSToby Isaac } 34179435951eSToby Isaac 34189435951eSToby Isaac #undef __FUNCT__ 34199435951eSToby Isaac #define __FUNCT__ "DMSetDefaultConstraints" 34209435951eSToby Isaac /*@ 34219435951eSToby Isaac DMSetDefaultConstraints - Set the PetscSection and Mat the specify the local constraint interpolation. 34229435951eSToby Isaac 34239435951eSToby 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(). 34249435951eSToby Isaac 34259435951eSToby 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. 34269435951eSToby Isaac 3427e228b242SToby Isaac collective on dm 3428e228b242SToby Isaac 34299435951eSToby Isaac Input Parameters: 34309435951eSToby Isaac + dm - The DM 3431e228b242SToby 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). 3432e228b242SToby 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). 34339435951eSToby Isaac 34349435951eSToby Isaac Level: advanced 34359435951eSToby Isaac 34369435951eSToby Isaac Note: This increments the references of the PetscSection and the Mat, so they user can destroy them 34379435951eSToby Isaac 34389435951eSToby Isaac .seealso: DMGetDefaultConstraints() 34399435951eSToby Isaac @*/ 34409435951eSToby Isaac PetscErrorCode DMSetDefaultConstraints(DM dm, PetscSection section, Mat mat) 34419435951eSToby Isaac { 3442e228b242SToby Isaac PetscMPIInt result; 34439435951eSToby Isaac PetscErrorCode ierr; 34449435951eSToby Isaac 34459435951eSToby Isaac PetscFunctionBegin; 34469435951eSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3447e228b242SToby Isaac if (section) { 3448e228b242SToby Isaac PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 3449e228b242SToby Isaac ierr = MPI_Comm_compare(PETSC_COMM_SELF,PetscObjectComm((PetscObject)section),&result);CHKERRQ(ierr); 3450f60917d2SBarry Smith if (result != MPI_CONGRUENT && result != MPI_IDENT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NOTSAMECOMM,"constraint section must have local communicator"); 3451e228b242SToby Isaac } 3452e228b242SToby Isaac if (mat) { 3453e228b242SToby Isaac PetscValidHeaderSpecific(mat,MAT_CLASSID,3); 3454e228b242SToby Isaac ierr = MPI_Comm_compare(PETSC_COMM_SELF,PetscObjectComm((PetscObject)mat),&result);CHKERRQ(ierr); 3455f60917d2SBarry Smith if (result != MPI_CONGRUENT && result != MPI_IDENT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NOTSAMECOMM,"constraint matrix must have local communicator"); 3456e228b242SToby Isaac } 34579435951eSToby Isaac ierr = PetscObjectReference((PetscObject)section);CHKERRQ(ierr); 34589435951eSToby Isaac ierr = PetscSectionDestroy(&dm->defaultConstraintSection);CHKERRQ(ierr); 34599435951eSToby Isaac dm->defaultConstraintSection = section; 34609435951eSToby Isaac ierr = PetscObjectReference((PetscObject)mat);CHKERRQ(ierr); 34619435951eSToby Isaac ierr = MatDestroy(&dm->defaultConstraintMat);CHKERRQ(ierr); 34629435951eSToby Isaac dm->defaultConstraintMat = mat; 34639435951eSToby Isaac PetscFunctionReturn(0); 34649435951eSToby Isaac } 34659435951eSToby Isaac 3466f741bcd2SMatthew G. Knepley #ifdef PETSC_USE_DEBUG 34679435951eSToby Isaac #undef __FUNCT__ 3468284f5c8fSMatthew G. Knepley #define __FUNCT__ "DMDefaultSectionCheckConsistency_Internal" 3469507e4973SMatthew G. Knepley /* 3470507e4973SMatthew G. Knepley DMDefaultSectionCheckConsistency - Check the consistentcy of the global and local sections. 3471507e4973SMatthew G. Knepley 3472507e4973SMatthew G. Knepley Input Parameters: 3473507e4973SMatthew G. Knepley + dm - The DM 3474507e4973SMatthew G. Knepley . localSection - PetscSection describing the local data layout 3475507e4973SMatthew G. Knepley - globalSection - PetscSection describing the global data layout 3476507e4973SMatthew G. Knepley 3477507e4973SMatthew G. Knepley Level: intermediate 3478507e4973SMatthew G. Knepley 3479507e4973SMatthew G. Knepley .seealso: DMGetDefaultSF(), DMSetDefaultSF() 3480507e4973SMatthew G. Knepley */ 3481f741bcd2SMatthew G. Knepley static PetscErrorCode DMDefaultSectionCheckConsistency_Internal(DM dm, PetscSection localSection, PetscSection globalSection) 3482507e4973SMatthew G. Knepley { 3483507e4973SMatthew G. Knepley MPI_Comm comm; 3484507e4973SMatthew G. Knepley PetscLayout layout; 3485507e4973SMatthew G. Knepley const PetscInt *ranges; 3486507e4973SMatthew G. Knepley PetscInt pStart, pEnd, p, nroots; 3487507e4973SMatthew G. Knepley PetscMPIInt size, rank; 3488507e4973SMatthew G. Knepley PetscBool valid = PETSC_TRUE, gvalid; 3489507e4973SMatthew G. Knepley PetscErrorCode ierr; 3490507e4973SMatthew G. Knepley 3491507e4973SMatthew G. Knepley PetscFunctionBegin; 3492507e4973SMatthew G. Knepley ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 3493507e4973SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3494507e4973SMatthew G. Knepley ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); 3495507e4973SMatthew G. Knepley ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); 3496507e4973SMatthew G. Knepley ierr = PetscSectionGetChart(globalSection, &pStart, &pEnd);CHKERRQ(ierr); 3497507e4973SMatthew G. Knepley ierr = PetscSectionGetConstrainedStorageSize(globalSection, &nroots);CHKERRQ(ierr); 3498507e4973SMatthew G. Knepley ierr = PetscLayoutCreate(comm, &layout);CHKERRQ(ierr); 3499507e4973SMatthew G. Knepley ierr = PetscLayoutSetBlockSize(layout, 1);CHKERRQ(ierr); 3500507e4973SMatthew G. Knepley ierr = PetscLayoutSetLocalSize(layout, nroots);CHKERRQ(ierr); 3501507e4973SMatthew G. Knepley ierr = PetscLayoutSetUp(layout);CHKERRQ(ierr); 3502507e4973SMatthew G. Knepley ierr = PetscLayoutGetRanges(layout, &ranges);CHKERRQ(ierr); 3503507e4973SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 3504f741bcd2SMatthew G. Knepley PetscInt dof, cdof, off, gdof, gcdof, goff, gsize, d; 3505507e4973SMatthew G. Knepley 3506507e4973SMatthew G. Knepley ierr = PetscSectionGetDof(localSection, p, &dof);CHKERRQ(ierr); 3507507e4973SMatthew G. Knepley ierr = PetscSectionGetOffset(localSection, p, &off);CHKERRQ(ierr); 3508507e4973SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(localSection, p, &cdof);CHKERRQ(ierr); 3509507e4973SMatthew G. Knepley ierr = PetscSectionGetDof(globalSection, p, &gdof);CHKERRQ(ierr); 3510507e4973SMatthew G. Knepley ierr = PetscSectionGetConstraintDof(globalSection, p, &gcdof);CHKERRQ(ierr); 3511507e4973SMatthew G. Knepley ierr = PetscSectionGetOffset(globalSection, p, &goff);CHKERRQ(ierr); 3512507e4973SMatthew G. Knepley if (!gdof) continue; /* Censored point */ 3513507e4973SMatthew 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;} 3514507e4973SMatthew 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;} 3515507e4973SMatthew G. Knepley if (gdof < 0) { 3516507e4973SMatthew G. Knepley gsize = gdof < 0 ? -(gdof+1)-gcdof : gdof-gcdof; 3517507e4973SMatthew G. Knepley for (d = 0; d < gsize; ++d) { 3518507e4973SMatthew G. Knepley PetscInt offset = -(goff+1) + d, r; 3519507e4973SMatthew G. Knepley 3520507e4973SMatthew G. Knepley ierr = PetscFindInt(offset,size+1,ranges,&r);CHKERRQ(ierr); 3521507e4973SMatthew G. Knepley if (r < 0) r = -(r+2); 3522507e4973SMatthew 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;} 3523507e4973SMatthew G. Knepley } 3524507e4973SMatthew G. Knepley } 3525507e4973SMatthew G. Knepley } 3526507e4973SMatthew G. Knepley ierr = PetscLayoutDestroy(&layout);CHKERRQ(ierr); 3527507e4973SMatthew G. Knepley ierr = PetscSynchronizedFlush(comm, NULL);CHKERRQ(ierr); 3528b2566f29SBarry Smith ierr = MPIU_Allreduce(&valid, &gvalid, 1, MPIU_BOOL, MPI_LAND, comm);CHKERRQ(ierr); 3529507e4973SMatthew G. Knepley if (!gvalid) { 3530507e4973SMatthew G. Knepley ierr = DMView(dm, NULL);CHKERRQ(ierr); 3531507e4973SMatthew G. Knepley SETERRQ(comm, PETSC_ERR_ARG_WRONG, "Inconsistent local and global sections"); 3532507e4973SMatthew G. Knepley } 3533507e4973SMatthew G. Knepley PetscFunctionReturn(0); 3534507e4973SMatthew G. Knepley } 3535f741bcd2SMatthew G. Knepley #endif 3536507e4973SMatthew G. Knepley 3537507e4973SMatthew G. Knepley #undef __FUNCT__ 353888ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultGlobalSection" 353988ed4aceSMatthew G Knepley /*@ 354088ed4aceSMatthew G Knepley DMGetDefaultGlobalSection - Get the PetscSection encoding the global data layout for the DM. 354188ed4aceSMatthew G Knepley 35428b1ab98fSJed Brown Collective on DM 35438b1ab98fSJed Brown 354488ed4aceSMatthew G Knepley Input Parameter: 354588ed4aceSMatthew G Knepley . dm - The DM 354688ed4aceSMatthew G Knepley 354788ed4aceSMatthew G Knepley Output Parameter: 354888ed4aceSMatthew G Knepley . section - The PetscSection 354988ed4aceSMatthew G Knepley 355088ed4aceSMatthew G Knepley Level: intermediate 355188ed4aceSMatthew G Knepley 355288ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSection. 355388ed4aceSMatthew G Knepley 355488ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultSection() 355588ed4aceSMatthew G Knepley @*/ 35560adebc6cSBarry Smith PetscErrorCode DMGetDefaultGlobalSection(DM dm, PetscSection *section) 35570adebc6cSBarry Smith { 355888ed4aceSMatthew G Knepley PetscErrorCode ierr; 355988ed4aceSMatthew G Knepley 356088ed4aceSMatthew G Knepley PetscFunctionBegin; 356188ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 356288ed4aceSMatthew G Knepley PetscValidPointer(section, 2); 356388ed4aceSMatthew G Knepley if (!dm->defaultGlobalSection) { 3564fd59a867SMatthew G. Knepley PetscSection s; 3565fd59a867SMatthew G. Knepley 3566fd59a867SMatthew G. Knepley ierr = DMGetDefaultSection(dm, &s);CHKERRQ(ierr); 3567fd59a867SMatthew 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"); 3568fd59a867SMatthew 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"); 356915b58121SMatthew G. Knepley ierr = PetscSectionCreateGlobalSection(s, dm->sf, PETSC_FALSE, PETSC_FALSE, &dm->defaultGlobalSection);CHKERRQ(ierr); 3570cf06b437SMatthew G. Knepley ierr = PetscLayoutDestroy(&dm->map);CHKERRQ(ierr); 3571ce94432eSBarry Smith ierr = PetscSectionGetValueLayout(PetscObjectComm((PetscObject)dm), dm->defaultGlobalSection, &dm->map);CHKERRQ(ierr); 3572685405a1SBarry Smith ierr = PetscSectionViewFromOptions(dm->defaultGlobalSection, NULL, "-global_section_view");CHKERRQ(ierr); 357388ed4aceSMatthew G Knepley } 357488ed4aceSMatthew G Knepley *section = dm->defaultGlobalSection; 357588ed4aceSMatthew G Knepley PetscFunctionReturn(0); 357688ed4aceSMatthew G Knepley } 357788ed4aceSMatthew G Knepley 357888ed4aceSMatthew G Knepley #undef __FUNCT__ 3579b21d0597SMatthew G Knepley #define __FUNCT__ "DMSetDefaultGlobalSection" 3580b21d0597SMatthew G Knepley /*@ 3581b21d0597SMatthew G Knepley DMSetDefaultGlobalSection - Set the PetscSection encoding the global data layout for the DM. 3582b21d0597SMatthew G Knepley 3583b21d0597SMatthew G Knepley Input Parameters: 3584b21d0597SMatthew G Knepley + dm - The DM 35855080bbdbSMatthew G Knepley - section - The PetscSection, or NULL 3586b21d0597SMatthew G Knepley 3587b21d0597SMatthew G Knepley Level: intermediate 3588b21d0597SMatthew G Knepley 3589b21d0597SMatthew G Knepley Note: Any existing Section will be destroyed 3590b21d0597SMatthew G Knepley 3591b21d0597SMatthew G Knepley .seealso: DMGetDefaultGlobalSection(), DMSetDefaultSection() 3592b21d0597SMatthew G Knepley @*/ 35930adebc6cSBarry Smith PetscErrorCode DMSetDefaultGlobalSection(DM dm, PetscSection section) 35940adebc6cSBarry Smith { 3595b21d0597SMatthew G Knepley PetscErrorCode ierr; 3596b21d0597SMatthew G Knepley 3597b21d0597SMatthew G Knepley PetscFunctionBegin; 3598b21d0597SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 35995080bbdbSMatthew G Knepley if (section) PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 36001d799100SJed Brown ierr = PetscObjectReference((PetscObject)section);CHKERRQ(ierr); 3601b21d0597SMatthew G Knepley ierr = PetscSectionDestroy(&dm->defaultGlobalSection);CHKERRQ(ierr); 3602b21d0597SMatthew G Knepley dm->defaultGlobalSection = section; 3603507e4973SMatthew G. Knepley #ifdef PETSC_USE_DEBUG 3604f741bcd2SMatthew G. Knepley if (section) {ierr = DMDefaultSectionCheckConsistency_Internal(dm, dm->defaultSection, section);CHKERRQ(ierr);} 3605507e4973SMatthew G. Knepley #endif 3606b21d0597SMatthew G Knepley PetscFunctionReturn(0); 3607b21d0597SMatthew G Knepley } 3608b21d0597SMatthew G Knepley 3609b21d0597SMatthew G Knepley #undef __FUNCT__ 361088ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultSF" 361188ed4aceSMatthew G Knepley /*@ 361288ed4aceSMatthew G Knepley DMGetDefaultSF - Get the PetscSF encoding the parallel dof overlap for the DM. If it has not been set, 361388ed4aceSMatthew G Knepley it is created from the default PetscSection layouts in the DM. 361488ed4aceSMatthew G Knepley 361588ed4aceSMatthew G Knepley Input Parameter: 361688ed4aceSMatthew G Knepley . dm - The DM 361788ed4aceSMatthew G Knepley 361888ed4aceSMatthew G Knepley Output Parameter: 361988ed4aceSMatthew G Knepley . sf - The PetscSF 362088ed4aceSMatthew G Knepley 362188ed4aceSMatthew G Knepley Level: intermediate 362288ed4aceSMatthew G Knepley 362388ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSF. 362488ed4aceSMatthew G Knepley 362588ed4aceSMatthew G Knepley .seealso: DMSetDefaultSF(), DMCreateDefaultSF() 362688ed4aceSMatthew G Knepley @*/ 36270adebc6cSBarry Smith PetscErrorCode DMGetDefaultSF(DM dm, PetscSF *sf) 36280adebc6cSBarry Smith { 362988ed4aceSMatthew G Knepley PetscInt nroots; 363088ed4aceSMatthew G Knepley PetscErrorCode ierr; 363188ed4aceSMatthew G Knepley 363288ed4aceSMatthew G Knepley PetscFunctionBegin; 363388ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 363488ed4aceSMatthew G Knepley PetscValidPointer(sf, 2); 36350298fd71SBarry Smith ierr = PetscSFGetGraph(dm->defaultSF, &nroots, NULL, NULL, NULL);CHKERRQ(ierr); 363688ed4aceSMatthew G Knepley if (nroots < 0) { 363788ed4aceSMatthew G Knepley PetscSection section, gSection; 363888ed4aceSMatthew G Knepley 363988ed4aceSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 364031ea6d37SMatthew G Knepley if (section) { 364188ed4aceSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, &gSection);CHKERRQ(ierr); 364288ed4aceSMatthew G Knepley ierr = DMCreateDefaultSF(dm, section, gSection);CHKERRQ(ierr); 364331ea6d37SMatthew G Knepley } else { 36440298fd71SBarry Smith *sf = NULL; 364531ea6d37SMatthew G Knepley PetscFunctionReturn(0); 364631ea6d37SMatthew G Knepley } 364788ed4aceSMatthew G Knepley } 364888ed4aceSMatthew G Knepley *sf = dm->defaultSF; 364988ed4aceSMatthew G Knepley PetscFunctionReturn(0); 365088ed4aceSMatthew G Knepley } 365188ed4aceSMatthew G Knepley 365288ed4aceSMatthew G Knepley #undef __FUNCT__ 365388ed4aceSMatthew G Knepley #define __FUNCT__ "DMSetDefaultSF" 365488ed4aceSMatthew G Knepley /*@ 365588ed4aceSMatthew G Knepley DMSetDefaultSF - Set the PetscSF encoding the parallel dof overlap for the DM 365688ed4aceSMatthew G Knepley 365788ed4aceSMatthew G Knepley Input Parameters: 365888ed4aceSMatthew G Knepley + dm - The DM 365988ed4aceSMatthew G Knepley - sf - The PetscSF 366088ed4aceSMatthew G Knepley 366188ed4aceSMatthew G Knepley Level: intermediate 366288ed4aceSMatthew G Knepley 366388ed4aceSMatthew G Knepley Note: Any previous SF is destroyed 366488ed4aceSMatthew G Knepley 366588ed4aceSMatthew G Knepley .seealso: DMGetDefaultSF(), DMCreateDefaultSF() 366688ed4aceSMatthew G Knepley @*/ 36670adebc6cSBarry Smith PetscErrorCode DMSetDefaultSF(DM dm, PetscSF sf) 36680adebc6cSBarry Smith { 366988ed4aceSMatthew G Knepley PetscErrorCode ierr; 367088ed4aceSMatthew G Knepley 367188ed4aceSMatthew G Knepley PetscFunctionBegin; 367288ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 367388ed4aceSMatthew G Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 367488ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&dm->defaultSF);CHKERRQ(ierr); 367588ed4aceSMatthew G Knepley dm->defaultSF = sf; 367688ed4aceSMatthew G Knepley PetscFunctionReturn(0); 367788ed4aceSMatthew G Knepley } 367888ed4aceSMatthew G Knepley 367988ed4aceSMatthew G Knepley #undef __FUNCT__ 368088ed4aceSMatthew G Knepley #define __FUNCT__ "DMCreateDefaultSF" 368188ed4aceSMatthew G Knepley /*@C 368288ed4aceSMatthew G Knepley DMCreateDefaultSF - Create the PetscSF encoding the parallel dof overlap for the DM based upon the PetscSections 368388ed4aceSMatthew G Knepley describing the data layout. 368488ed4aceSMatthew G Knepley 368588ed4aceSMatthew G Knepley Input Parameters: 368688ed4aceSMatthew G Knepley + dm - The DM 368788ed4aceSMatthew G Knepley . localSection - PetscSection describing the local data layout 368888ed4aceSMatthew G Knepley - globalSection - PetscSection describing the global data layout 368988ed4aceSMatthew G Knepley 369088ed4aceSMatthew G Knepley Level: intermediate 369188ed4aceSMatthew G Knepley 369288ed4aceSMatthew G Knepley .seealso: DMGetDefaultSF(), DMSetDefaultSF() 369388ed4aceSMatthew G Knepley @*/ 369488ed4aceSMatthew G Knepley PetscErrorCode DMCreateDefaultSF(DM dm, PetscSection localSection, PetscSection globalSection) 369588ed4aceSMatthew G Knepley { 369682f516ccSBarry Smith MPI_Comm comm; 369788ed4aceSMatthew G Knepley PetscLayout layout; 369888ed4aceSMatthew G Knepley const PetscInt *ranges; 369988ed4aceSMatthew G Knepley PetscInt *local; 370088ed4aceSMatthew G Knepley PetscSFNode *remote; 3701ecd73843SMatthew G. Knepley PetscInt pStart, pEnd, p, nroots, nleaves = 0, l; 370288ed4aceSMatthew G Knepley PetscMPIInt size, rank; 370388ed4aceSMatthew G Knepley PetscErrorCode ierr; 370488ed4aceSMatthew G Knepley 370588ed4aceSMatthew G Knepley PetscFunctionBegin; 370682f516ccSBarry Smith ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 370788ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 370888ed4aceSMatthew G Knepley ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); 370988ed4aceSMatthew G Knepley ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); 371088ed4aceSMatthew G Knepley ierr = PetscSectionGetChart(globalSection, &pStart, &pEnd);CHKERRQ(ierr); 371188ed4aceSMatthew G Knepley ierr = PetscSectionGetConstrainedStorageSize(globalSection, &nroots);CHKERRQ(ierr); 371288ed4aceSMatthew G Knepley ierr = PetscLayoutCreate(comm, &layout);CHKERRQ(ierr); 371388ed4aceSMatthew G Knepley ierr = PetscLayoutSetBlockSize(layout, 1);CHKERRQ(ierr); 371488ed4aceSMatthew G Knepley ierr = PetscLayoutSetLocalSize(layout, nroots);CHKERRQ(ierr); 371588ed4aceSMatthew G Knepley ierr = PetscLayoutSetUp(layout);CHKERRQ(ierr); 371688ed4aceSMatthew G Knepley ierr = PetscLayoutGetRanges(layout, &ranges);CHKERRQ(ierr); 3717ecd73843SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 37186636e97aSMatthew G Knepley PetscInt gdof, gcdof; 371988ed4aceSMatthew G Knepley 37206636e97aSMatthew G Knepley ierr = PetscSectionGetDof(globalSection, p, &gdof);CHKERRQ(ierr); 37216636e97aSMatthew G Knepley ierr = PetscSectionGetConstraintDof(globalSection, p, &gcdof);CHKERRQ(ierr); 3722235fbf56SMatthew 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)); 37236636e97aSMatthew G Knepley nleaves += gdof < 0 ? -(gdof+1)-gcdof : gdof-gcdof; 372488ed4aceSMatthew G Knepley } 3725785e854fSJed Brown ierr = PetscMalloc1(nleaves, &local);CHKERRQ(ierr); 3726785e854fSJed Brown ierr = PetscMalloc1(nleaves, &remote);CHKERRQ(ierr); 372788ed4aceSMatthew G Knepley for (p = pStart, l = 0; p < pEnd; ++p) { 37281f588964SMatthew G Knepley const PetscInt *cind; 37296636e97aSMatthew G Knepley PetscInt dof, cdof, off, gdof, gcdof, goff, gsize, d, c; 373088ed4aceSMatthew G Knepley 373188ed4aceSMatthew G Knepley ierr = PetscSectionGetDof(localSection, p, &dof);CHKERRQ(ierr); 373288ed4aceSMatthew G Knepley ierr = PetscSectionGetOffset(localSection, p, &off);CHKERRQ(ierr); 373388ed4aceSMatthew G Knepley ierr = PetscSectionGetConstraintDof(localSection, p, &cdof);CHKERRQ(ierr); 373488ed4aceSMatthew G Knepley ierr = PetscSectionGetConstraintIndices(localSection, p, &cind);CHKERRQ(ierr); 373588ed4aceSMatthew G Knepley ierr = PetscSectionGetDof(globalSection, p, &gdof);CHKERRQ(ierr); 37366636e97aSMatthew G Knepley ierr = PetscSectionGetConstraintDof(globalSection, p, &gcdof);CHKERRQ(ierr); 373788ed4aceSMatthew G Knepley ierr = PetscSectionGetOffset(globalSection, p, &goff);CHKERRQ(ierr); 37386636e97aSMatthew G Knepley if (!gdof) continue; /* Censored point */ 37396636e97aSMatthew G Knepley gsize = gdof < 0 ? -(gdof+1)-gcdof : gdof-gcdof; 37406636e97aSMatthew G Knepley if (gsize != dof-cdof) { 3741057b4bcdSMatthew 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); 37426636e97aSMatthew G Knepley cdof = 0; /* Ignore constraints */ 37436636e97aSMatthew G Knepley } 374488ed4aceSMatthew G Knepley for (d = 0, c = 0; d < dof; ++d) { 374588ed4aceSMatthew G Knepley if ((c < cdof) && (cind[c] == d)) {++c; continue;} 374688ed4aceSMatthew G Knepley local[l+d-c] = off+d; 374788ed4aceSMatthew G Knepley } 374888ed4aceSMatthew G Knepley if (gdof < 0) { 37496636e97aSMatthew G Knepley for (d = 0; d < gsize; ++d, ++l) { 375088ed4aceSMatthew G Knepley PetscInt offset = -(goff+1) + d, r; 375188ed4aceSMatthew G Knepley 375205376888SMatthew G. Knepley ierr = PetscFindInt(offset,size+1,ranges,&r);CHKERRQ(ierr); 375331d3f06eSJed Brown if (r < 0) r = -(r+2); 375405376888SMatthew 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); 375588ed4aceSMatthew G Knepley remote[l].rank = r; 375688ed4aceSMatthew G Knepley remote[l].index = offset - ranges[r]; 375788ed4aceSMatthew G Knepley } 375888ed4aceSMatthew G Knepley } else { 37596636e97aSMatthew G Knepley for (d = 0; d < gsize; ++d, ++l) { 376088ed4aceSMatthew G Knepley remote[l].rank = rank; 376188ed4aceSMatthew G Knepley remote[l].index = goff+d - ranges[rank]; 376288ed4aceSMatthew G Knepley } 376388ed4aceSMatthew G Knepley } 376488ed4aceSMatthew G Knepley } 37656636e97aSMatthew G Knepley if (l != nleaves) SETERRQ2(comm, PETSC_ERR_PLIB, "Iteration error, l %d != nleaves %d", l, nleaves); 376688ed4aceSMatthew G Knepley ierr = PetscLayoutDestroy(&layout);CHKERRQ(ierr); 376788ed4aceSMatthew G Knepley ierr = PetscSFSetGraph(dm->defaultSF, nroots, nleaves, local, PETSC_OWN_POINTER, remote, PETSC_OWN_POINTER);CHKERRQ(ierr); 376888ed4aceSMatthew G Knepley PetscFunctionReturn(0); 376988ed4aceSMatthew G Knepley } 3770af122d2aSMatthew G Knepley 3771af122d2aSMatthew G Knepley #undef __FUNCT__ 3772b21d0597SMatthew G Knepley #define __FUNCT__ "DMGetPointSF" 3773b21d0597SMatthew G Knepley /*@ 3774b21d0597SMatthew G Knepley DMGetPointSF - Get the PetscSF encoding the parallel section point overlap for the DM. 3775b21d0597SMatthew G Knepley 3776b21d0597SMatthew G Knepley Input Parameter: 3777b21d0597SMatthew G Knepley . dm - The DM 3778b21d0597SMatthew G Knepley 3779b21d0597SMatthew G Knepley Output Parameter: 3780b21d0597SMatthew G Knepley . sf - The PetscSF 3781b21d0597SMatthew G Knepley 3782b21d0597SMatthew G Knepley Level: intermediate 3783b21d0597SMatthew G Knepley 3784b21d0597SMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSF. 3785b21d0597SMatthew G Knepley 3786057b4bcdSMatthew G Knepley .seealso: DMSetPointSF(), DMGetDefaultSF(), DMSetDefaultSF(), DMCreateDefaultSF() 3787b21d0597SMatthew G Knepley @*/ 37880adebc6cSBarry Smith PetscErrorCode DMGetPointSF(DM dm, PetscSF *sf) 37890adebc6cSBarry Smith { 3790b21d0597SMatthew G Knepley PetscFunctionBegin; 3791b21d0597SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3792b21d0597SMatthew G Knepley PetscValidPointer(sf, 2); 3793b21d0597SMatthew G Knepley *sf = dm->sf; 3794b21d0597SMatthew G Knepley PetscFunctionReturn(0); 3795b21d0597SMatthew G Knepley } 3796b21d0597SMatthew G Knepley 3797b21d0597SMatthew G Knepley #undef __FUNCT__ 3798057b4bcdSMatthew G Knepley #define __FUNCT__ "DMSetPointSF" 3799057b4bcdSMatthew G Knepley /*@ 3800057b4bcdSMatthew G Knepley DMSetPointSF - Set the PetscSF encoding the parallel section point overlap for the DM. 3801057b4bcdSMatthew G Knepley 3802057b4bcdSMatthew G Knepley Input Parameters: 3803057b4bcdSMatthew G Knepley + dm - The DM 3804057b4bcdSMatthew G Knepley - sf - The PetscSF 3805057b4bcdSMatthew G Knepley 3806057b4bcdSMatthew G Knepley Level: intermediate 3807057b4bcdSMatthew G Knepley 3808057b4bcdSMatthew G Knepley .seealso: DMGetPointSF(), DMGetDefaultSF(), DMSetDefaultSF(), DMCreateDefaultSF() 3809057b4bcdSMatthew G Knepley @*/ 38100adebc6cSBarry Smith PetscErrorCode DMSetPointSF(DM dm, PetscSF sf) 38110adebc6cSBarry Smith { 3812057b4bcdSMatthew G Knepley PetscErrorCode ierr; 3813057b4bcdSMatthew G Knepley 3814057b4bcdSMatthew G Knepley PetscFunctionBegin; 3815057b4bcdSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3816057b4bcdSMatthew G Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 1); 3817057b4bcdSMatthew G Knepley ierr = PetscSFDestroy(&dm->sf);CHKERRQ(ierr); 3818057b4bcdSMatthew G Knepley ierr = PetscObjectReference((PetscObject) sf);CHKERRQ(ierr); 3819057b4bcdSMatthew G Knepley dm->sf = sf; 3820057b4bcdSMatthew G Knepley PetscFunctionReturn(0); 3821057b4bcdSMatthew G Knepley } 3822057b4bcdSMatthew G Knepley 3823057b4bcdSMatthew G Knepley #undef __FUNCT__ 38242764a2aaSMatthew G. Knepley #define __FUNCT__ "DMGetDS" 38252764a2aaSMatthew G. Knepley /*@ 38262764a2aaSMatthew G. Knepley DMGetDS - Get the PetscDS 38272764a2aaSMatthew G. Knepley 38282764a2aaSMatthew G. Knepley Input Parameter: 38292764a2aaSMatthew G. Knepley . dm - The DM 38302764a2aaSMatthew G. Knepley 38312764a2aaSMatthew G. Knepley Output Parameter: 38322764a2aaSMatthew G. Knepley . prob - The PetscDS 38332764a2aaSMatthew G. Knepley 38342764a2aaSMatthew G. Knepley Level: developer 38352764a2aaSMatthew G. Knepley 38362764a2aaSMatthew G. Knepley .seealso: DMSetDS() 38372764a2aaSMatthew G. Knepley @*/ 38382764a2aaSMatthew G. Knepley PetscErrorCode DMGetDS(DM dm, PetscDS *prob) 3839af122d2aSMatthew G Knepley { 3840af122d2aSMatthew G Knepley PetscFunctionBegin; 3841af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 38420f21e855SMatthew G. Knepley PetscValidPointer(prob, 2); 38430f21e855SMatthew G. Knepley *prob = dm->prob; 38440f21e855SMatthew G. Knepley PetscFunctionReturn(0); 38450f21e855SMatthew G. Knepley } 38460f21e855SMatthew G. Knepley 38470f21e855SMatthew G. Knepley #undef __FUNCT__ 38482764a2aaSMatthew G. Knepley #define __FUNCT__ "DMSetDS" 38492764a2aaSMatthew G. Knepley /*@ 38502764a2aaSMatthew G. Knepley DMSetDS - Set the PetscDS 38512764a2aaSMatthew G. Knepley 38522764a2aaSMatthew G. Knepley Input Parameters: 38532764a2aaSMatthew G. Knepley + dm - The DM 38542764a2aaSMatthew G. Knepley - prob - The PetscDS 38552764a2aaSMatthew G. Knepley 38562764a2aaSMatthew G. Knepley Level: developer 38572764a2aaSMatthew G. Knepley 38582764a2aaSMatthew G. Knepley .seealso: DMGetDS() 38592764a2aaSMatthew G. Knepley @*/ 38602764a2aaSMatthew G. Knepley PetscErrorCode DMSetDS(DM dm, PetscDS prob) 38610f21e855SMatthew G. Knepley { 38620f21e855SMatthew G. Knepley PetscErrorCode ierr; 38630f21e855SMatthew G. Knepley 38640f21e855SMatthew G. Knepley PetscFunctionBegin; 38650f21e855SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 38662764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 2); 38672764a2aaSMatthew G. Knepley ierr = PetscDSDestroy(&dm->prob);CHKERRQ(ierr); 38680f21e855SMatthew G. Knepley dm->prob = prob; 38690f21e855SMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm->prob);CHKERRQ(ierr); 38700f21e855SMatthew G. Knepley PetscFunctionReturn(0); 38710f21e855SMatthew G. Knepley } 38720f21e855SMatthew G. Knepley 38730f21e855SMatthew G. Knepley #undef __FUNCT__ 38740f21e855SMatthew G. Knepley #define __FUNCT__ "DMGetNumFields" 38750f21e855SMatthew G. Knepley PetscErrorCode DMGetNumFields(DM dm, PetscInt *numFields) 38760f21e855SMatthew G. Knepley { 38770f21e855SMatthew G. Knepley PetscErrorCode ierr; 38780f21e855SMatthew G. Knepley 38790f21e855SMatthew G. Knepley PetscFunctionBegin; 38800f21e855SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 38812764a2aaSMatthew G. Knepley ierr = PetscDSGetNumFields(dm->prob, numFields);CHKERRQ(ierr); 3882af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3883af122d2aSMatthew G Knepley } 3884af122d2aSMatthew G Knepley 3885af122d2aSMatthew G Knepley #undef __FUNCT__ 3886af122d2aSMatthew G Knepley #define __FUNCT__ "DMSetNumFields" 3887af122d2aSMatthew G Knepley PetscErrorCode DMSetNumFields(DM dm, PetscInt numFields) 3888af122d2aSMatthew G Knepley { 38890f21e855SMatthew G. Knepley PetscInt Nf, f; 3890af122d2aSMatthew G Knepley PetscErrorCode ierr; 3891af122d2aSMatthew G Knepley 3892af122d2aSMatthew G Knepley PetscFunctionBegin; 3893af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 38942764a2aaSMatthew G. Knepley ierr = PetscDSGetNumFields(dm->prob, &Nf);CHKERRQ(ierr); 38950f21e855SMatthew G. Knepley for (f = Nf; f < numFields; ++f) { 38960f21e855SMatthew G. Knepley PetscContainer obj; 38970f21e855SMatthew G. Knepley 38980f21e855SMatthew G. Knepley ierr = PetscContainerCreate(PetscObjectComm((PetscObject) dm), &obj);CHKERRQ(ierr); 38992764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(dm->prob, f, (PetscObject) obj);CHKERRQ(ierr); 39000f21e855SMatthew G. Knepley ierr = PetscContainerDestroy(&obj);CHKERRQ(ierr); 3901af122d2aSMatthew G Knepley } 3902af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3903af122d2aSMatthew G Knepley } 3904af122d2aSMatthew G Knepley 3905af122d2aSMatthew G Knepley #undef __FUNCT__ 3906af122d2aSMatthew G Knepley #define __FUNCT__ "DMGetField" 3907c1929be8SMatthew G. Knepley /*@ 3908c1929be8SMatthew G. Knepley DMGetField - Return the discretization object for a given DM field 3909c1929be8SMatthew G. Knepley 3910c1929be8SMatthew G. Knepley Not collective 3911c1929be8SMatthew G. Knepley 3912c1929be8SMatthew G. Knepley Input Parameters: 3913c1929be8SMatthew G. Knepley + dm - The DM 3914c1929be8SMatthew G. Knepley - f - The field number 3915c1929be8SMatthew G. Knepley 3916c1929be8SMatthew G. Knepley Output Parameter: 3917c1929be8SMatthew G. Knepley . field - The discretization object 3918c1929be8SMatthew G. Knepley 3919c1929be8SMatthew G. Knepley Level: developer 3920c1929be8SMatthew G. Knepley 3921c1929be8SMatthew G. Knepley .seealso: DMSetField() 3922c1929be8SMatthew G. Knepley @*/ 3923af122d2aSMatthew G Knepley PetscErrorCode DMGetField(DM dm, PetscInt f, PetscObject *field) 3924af122d2aSMatthew G Knepley { 39250f21e855SMatthew G. Knepley PetscErrorCode ierr; 39260f21e855SMatthew G. Knepley 3927af122d2aSMatthew G Knepley PetscFunctionBegin; 3928af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 39292764a2aaSMatthew G. Knepley ierr = PetscDSGetDiscretization(dm->prob, f, field);CHKERRQ(ierr); 3930decb47aaSMatthew G. Knepley PetscFunctionReturn(0); 3931decb47aaSMatthew G. Knepley } 3932decb47aaSMatthew G. Knepley 3933decb47aaSMatthew G. Knepley #undef __FUNCT__ 3934decb47aaSMatthew G. Knepley #define __FUNCT__ "DMSetField" 3935c1929be8SMatthew G. Knepley /*@ 3936c1929be8SMatthew G. Knepley DMSetField - Set the discretization object for a given DM field 3937c1929be8SMatthew G. Knepley 3938c1929be8SMatthew G. Knepley Logically collective on DM 3939c1929be8SMatthew G. Knepley 3940c1929be8SMatthew G. Knepley Input Parameters: 3941c1929be8SMatthew G. Knepley + dm - The DM 3942c1929be8SMatthew G. Knepley . f - The field number 3943c1929be8SMatthew G. Knepley - field - The discretization object 3944c1929be8SMatthew G. Knepley 3945c1929be8SMatthew G. Knepley Level: developer 3946c1929be8SMatthew G. Knepley 3947c1929be8SMatthew G. Knepley .seealso: DMGetField() 3948c1929be8SMatthew G. Knepley @*/ 3949decb47aaSMatthew G. Knepley PetscErrorCode DMSetField(DM dm, PetscInt f, PetscObject field) 3950decb47aaSMatthew G. Knepley { 3951decb47aaSMatthew G. Knepley PetscErrorCode ierr; 3952decb47aaSMatthew G. Knepley 3953decb47aaSMatthew G. Knepley PetscFunctionBegin; 3954decb47aaSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 39552764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(dm->prob, f, field);CHKERRQ(ierr); 3956af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3957af122d2aSMatthew G Knepley } 39586636e97aSMatthew G Knepley 39596636e97aSMatthew G Knepley #undef __FUNCT__ 3960b64e0483SPeter Brune #define __FUNCT__ "DMRestrictHook_Coordinates" 3961b64e0483SPeter Brune PetscErrorCode DMRestrictHook_Coordinates(DM dm,DM dmc,void *ctx) 3962b64e0483SPeter Brune { 3963b64e0483SPeter Brune DM dm_coord,dmc_coord; 3964b64e0483SPeter Brune PetscErrorCode ierr; 3965b64e0483SPeter Brune Vec coords,ccoords; 39666dbf9973SLawrence Mitchell Mat inject; 3967b64e0483SPeter Brune PetscFunctionBegin; 3968b64e0483SPeter Brune ierr = DMGetCoordinateDM(dm,&dm_coord);CHKERRQ(ierr); 3969b64e0483SPeter Brune ierr = DMGetCoordinateDM(dmc,&dmc_coord);CHKERRQ(ierr); 3970b64e0483SPeter Brune ierr = DMGetCoordinates(dm,&coords);CHKERRQ(ierr); 3971b64e0483SPeter Brune ierr = DMGetCoordinates(dmc,&ccoords);CHKERRQ(ierr); 3972b64e0483SPeter Brune if (coords && !ccoords) { 3973b64e0483SPeter Brune ierr = DMCreateGlobalVector(dmc_coord,&ccoords);CHKERRQ(ierr); 39746dbf9973SLawrence Mitchell ierr = DMCreateInjection(dmc_coord,dm_coord,&inject);CHKERRQ(ierr); 39752adcf181SLawrence Mitchell ierr = MatRestrict(inject,coords,ccoords);CHKERRQ(ierr); 39766dbf9973SLawrence Mitchell ierr = MatDestroy(&inject);CHKERRQ(ierr); 3977b64e0483SPeter Brune ierr = DMSetCoordinates(dmc,ccoords);CHKERRQ(ierr); 3978b64e0483SPeter Brune ierr = VecDestroy(&ccoords);CHKERRQ(ierr); 3979b64e0483SPeter Brune } 3980b64e0483SPeter Brune PetscFunctionReturn(0); 3981b64e0483SPeter Brune } 3982b64e0483SPeter Brune 3983b64e0483SPeter Brune #undef __FUNCT__ 398403dadc2fSPeter Brune #define __FUNCT__ "DMSubDomainHook_Coordinates" 398503dadc2fSPeter Brune static PetscErrorCode DMSubDomainHook_Coordinates(DM dm,DM subdm,void *ctx) 398603dadc2fSPeter Brune { 398703dadc2fSPeter Brune DM dm_coord,subdm_coord; 398803dadc2fSPeter Brune PetscErrorCode ierr; 398903dadc2fSPeter Brune Vec coords,ccoords,clcoords; 399003dadc2fSPeter Brune VecScatter *scat_i,*scat_g; 399103dadc2fSPeter Brune PetscFunctionBegin; 399203dadc2fSPeter Brune ierr = DMGetCoordinateDM(dm,&dm_coord);CHKERRQ(ierr); 399303dadc2fSPeter Brune ierr = DMGetCoordinateDM(subdm,&subdm_coord);CHKERRQ(ierr); 399403dadc2fSPeter Brune ierr = DMGetCoordinates(dm,&coords);CHKERRQ(ierr); 399503dadc2fSPeter Brune ierr = DMGetCoordinates(subdm,&ccoords);CHKERRQ(ierr); 399603dadc2fSPeter Brune if (coords && !ccoords) { 399703dadc2fSPeter Brune ierr = DMCreateGlobalVector(subdm_coord,&ccoords);CHKERRQ(ierr); 399803dadc2fSPeter Brune ierr = DMCreateLocalVector(subdm_coord,&clcoords);CHKERRQ(ierr); 399924640c55SToby Isaac ierr = PetscObjectSetName((PetscObject)clcoords,"coordinates");CHKERRQ(ierr); 400003dadc2fSPeter Brune ierr = DMCreateDomainDecompositionScatters(dm_coord,1,&subdm_coord,NULL,&scat_i,&scat_g);CHKERRQ(ierr); 400103dadc2fSPeter Brune ierr = VecScatterBegin(scat_i[0],coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 400203dadc2fSPeter Brune ierr = VecScatterBegin(scat_g[0],coords,clcoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 400303dadc2fSPeter Brune ierr = VecScatterEnd(scat_i[0],coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 400403dadc2fSPeter Brune ierr = VecScatterEnd(scat_g[0],coords,clcoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 400503dadc2fSPeter Brune ierr = DMSetCoordinates(subdm,ccoords);CHKERRQ(ierr); 400603dadc2fSPeter Brune ierr = DMSetCoordinatesLocal(subdm,clcoords);CHKERRQ(ierr); 400703dadc2fSPeter Brune ierr = VecScatterDestroy(&scat_i[0]);CHKERRQ(ierr); 400803dadc2fSPeter Brune ierr = VecScatterDestroy(&scat_g[0]);CHKERRQ(ierr); 400903dadc2fSPeter Brune ierr = VecDestroy(&ccoords);CHKERRQ(ierr); 401003dadc2fSPeter Brune ierr = VecDestroy(&clcoords);CHKERRQ(ierr); 401103dadc2fSPeter Brune ierr = PetscFree(scat_i);CHKERRQ(ierr); 401203dadc2fSPeter Brune ierr = PetscFree(scat_g);CHKERRQ(ierr); 401303dadc2fSPeter Brune } 401403dadc2fSPeter Brune PetscFunctionReturn(0); 401503dadc2fSPeter Brune } 401603dadc2fSPeter Brune 401703dadc2fSPeter Brune #undef __FUNCT__ 4018c73cfb54SMatthew G. Knepley #define __FUNCT__ "DMGetDimension" 4019c73cfb54SMatthew G. Knepley /*@ 4020c73cfb54SMatthew G. Knepley DMGetDimension - Return the topological dimension of the DM 4021c73cfb54SMatthew G. Knepley 4022c73cfb54SMatthew G. Knepley Not collective 4023c73cfb54SMatthew G. Knepley 4024c73cfb54SMatthew G. Knepley Input Parameter: 4025c73cfb54SMatthew G. Knepley . dm - The DM 4026c73cfb54SMatthew G. Knepley 4027c73cfb54SMatthew G. Knepley Output Parameter: 4028c73cfb54SMatthew G. Knepley . dim - The topological dimension 4029c73cfb54SMatthew G. Knepley 4030c73cfb54SMatthew G. Knepley Level: beginner 4031c73cfb54SMatthew G. Knepley 4032c73cfb54SMatthew G. Knepley .seealso: DMSetDimension(), DMCreate() 4033c73cfb54SMatthew G. Knepley @*/ 4034c73cfb54SMatthew G. Knepley PetscErrorCode DMGetDimension(DM dm, PetscInt *dim) 4035c73cfb54SMatthew G. Knepley { 4036c73cfb54SMatthew G. Knepley PetscFunctionBegin; 4037c73cfb54SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 4038c73cfb54SMatthew G. Knepley PetscValidPointer(dim, 2); 4039c73cfb54SMatthew G. Knepley *dim = dm->dim; 4040c73cfb54SMatthew G. Knepley PetscFunctionReturn(0); 4041c73cfb54SMatthew G. Knepley } 4042c73cfb54SMatthew G. Knepley 4043c73cfb54SMatthew G. Knepley #undef __FUNCT__ 4044c73cfb54SMatthew G. Knepley #define __FUNCT__ "DMSetDimension" 4045c73cfb54SMatthew G. Knepley /*@ 4046c73cfb54SMatthew G. Knepley DMSetDimension - Set the topological dimension of the DM 4047c73cfb54SMatthew G. Knepley 4048c73cfb54SMatthew G. Knepley Collective on dm 4049c73cfb54SMatthew G. Knepley 4050c73cfb54SMatthew G. Knepley Input Parameters: 4051c73cfb54SMatthew G. Knepley + dm - The DM 4052c73cfb54SMatthew G. Knepley - dim - The topological dimension 4053c73cfb54SMatthew G. Knepley 4054c73cfb54SMatthew G. Knepley Level: beginner 4055c73cfb54SMatthew G. Knepley 4056c73cfb54SMatthew G. Knepley .seealso: DMGetDimension(), DMCreate() 4057c73cfb54SMatthew G. Knepley @*/ 4058c73cfb54SMatthew G. Knepley PetscErrorCode DMSetDimension(DM dm, PetscInt dim) 4059c73cfb54SMatthew G. Knepley { 4060c73cfb54SMatthew G. Knepley PetscFunctionBegin; 4061c73cfb54SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 4062c73cfb54SMatthew G. Knepley PetscValidLogicalCollectiveInt(dm, dim, 2); 4063c73cfb54SMatthew G. Knepley dm->dim = dim; 4064c73cfb54SMatthew G. Knepley PetscFunctionReturn(0); 4065c73cfb54SMatthew G. Knepley } 4066c73cfb54SMatthew G. Knepley 4067793f3fe5SMatthew G. Knepley #undef __FUNCT__ 4068793f3fe5SMatthew G. Knepley #define __FUNCT__ "DMGetDimPoints" 4069793f3fe5SMatthew G. Knepley /*@ 4070793f3fe5SMatthew G. Knepley DMGetDimPoints - Get the half-open interval for all points of a given dimension 4071793f3fe5SMatthew G. Knepley 4072793f3fe5SMatthew G. Knepley Collective on DM 4073793f3fe5SMatthew G. Knepley 4074793f3fe5SMatthew G. Knepley Input Parameters: 4075793f3fe5SMatthew G. Knepley + dm - the DM 4076793f3fe5SMatthew G. Knepley - dim - the dimension 4077793f3fe5SMatthew G. Knepley 4078793f3fe5SMatthew G. Knepley Output Parameters: 4079793f3fe5SMatthew G. Knepley + pStart - The first point of the given dimension 4080793f3fe5SMatthew G. Knepley . pEnd - The first point following points of the given dimension 4081793f3fe5SMatthew G. Knepley 4082793f3fe5SMatthew G. Knepley Note: 4083793f3fe5SMatthew G. Knepley The points are vertices in the Hasse diagram encoding the topology. This is explained in 4084793f3fe5SMatthew G. Knepley http://arxiv.org/abs/0908.4427. If not points exist of this dimension in the storage scheme, 4085793f3fe5SMatthew G. Knepley then the interval is empty. 4086793f3fe5SMatthew G. Knepley 4087793f3fe5SMatthew G. Knepley Level: intermediate 4088793f3fe5SMatthew G. Knepley 4089793f3fe5SMatthew G. Knepley .keywords: point, Hasse Diagram, dimension 4090793f3fe5SMatthew G. Knepley .seealso: DMPLEX, DMPlexGetDepthStratum(), DMPlexGetHeightStratum() 4091793f3fe5SMatthew G. Knepley @*/ 4092793f3fe5SMatthew G. Knepley PetscErrorCode DMGetDimPoints(DM dm, PetscInt dim, PetscInt *pStart, PetscInt *pEnd) 4093793f3fe5SMatthew G. Knepley { 4094793f3fe5SMatthew G. Knepley PetscInt d; 4095793f3fe5SMatthew G. Knepley PetscErrorCode ierr; 4096793f3fe5SMatthew G. Knepley 4097793f3fe5SMatthew G. Knepley PetscFunctionBegin; 4098793f3fe5SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4099793f3fe5SMatthew G. Knepley ierr = DMGetDimension(dm, &d);CHKERRQ(ierr); 4100793f3fe5SMatthew G. Knepley if ((dim < 0) || (dim > d)) SETERRQ2(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid dimension %d 1", dim, d); 4101793f3fe5SMatthew G. Knepley ierr = (*dm->ops->getdimpoints)(dm, dim, pStart, pEnd);CHKERRQ(ierr); 4102793f3fe5SMatthew G. Knepley PetscFunctionReturn(0); 4103793f3fe5SMatthew G. Knepley } 4104793f3fe5SMatthew G. Knepley 4105793f3fe5SMatthew G. Knepley #undef __FUNCT__ 41066636e97aSMatthew G Knepley #define __FUNCT__ "DMSetCoordinates" 41076636e97aSMatthew G Knepley /*@ 41086636e97aSMatthew G Knepley DMSetCoordinates - Sets into the DM a global vector that holds the coordinates 41096636e97aSMatthew G Knepley 41106636e97aSMatthew G Knepley Collective on DM 41116636e97aSMatthew G Knepley 41126636e97aSMatthew G Knepley Input Parameters: 41136636e97aSMatthew G Knepley + dm - the DM 41146636e97aSMatthew G Knepley - c - coordinate vector 41156636e97aSMatthew G Knepley 41166636e97aSMatthew G Knepley Note: 41176636e97aSMatthew G Knepley The coordinates do include those for ghost points, which are in the local vector 41186636e97aSMatthew G Knepley 41196636e97aSMatthew G Knepley Level: intermediate 41206636e97aSMatthew G Knepley 41216636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 41226636e97aSMatthew G Knepley .seealso: DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLoca(), DMGetCoordinateDM() 41236636e97aSMatthew G Knepley @*/ 41246636e97aSMatthew G Knepley PetscErrorCode DMSetCoordinates(DM dm, Vec c) 41256636e97aSMatthew G Knepley { 41266636e97aSMatthew G Knepley PetscErrorCode ierr; 41276636e97aSMatthew G Knepley 41286636e97aSMatthew G Knepley PetscFunctionBegin; 41296636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 41306636e97aSMatthew G Knepley PetscValidHeaderSpecific(c,VEC_CLASSID,2); 41316636e97aSMatthew G Knepley ierr = PetscObjectReference((PetscObject) c);CHKERRQ(ierr); 41326636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinates);CHKERRQ(ierr); 41336636e97aSMatthew G Knepley dm->coordinates = c; 41346636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinatesLocal);CHKERRQ(ierr); 4135b64e0483SPeter Brune ierr = DMCoarsenHookAdd(dm,DMRestrictHook_Coordinates,NULL,NULL);CHKERRQ(ierr); 413603dadc2fSPeter Brune ierr = DMSubDomainHookAdd(dm,DMSubDomainHook_Coordinates,NULL,NULL);CHKERRQ(ierr); 41376636e97aSMatthew G Knepley PetscFunctionReturn(0); 41386636e97aSMatthew G Knepley } 41396636e97aSMatthew G Knepley 41406636e97aSMatthew G Knepley #undef __FUNCT__ 41416636e97aSMatthew G Knepley #define __FUNCT__ "DMSetCoordinatesLocal" 41426636e97aSMatthew G Knepley /*@ 41436636e97aSMatthew G Knepley DMSetCoordinatesLocal - Sets into the DM a local vector that holds the coordinates 41446636e97aSMatthew G Knepley 41456636e97aSMatthew G Knepley Collective on DM 41466636e97aSMatthew G Knepley 41476636e97aSMatthew G Knepley Input Parameters: 41486636e97aSMatthew G Knepley + dm - the DM 41496636e97aSMatthew G Knepley - c - coordinate vector 41506636e97aSMatthew G Knepley 41516636e97aSMatthew G Knepley Note: 41526636e97aSMatthew G Knepley The coordinates of ghost points can be set using DMSetCoordinates() 41536636e97aSMatthew G Knepley followed by DMGetCoordinatesLocal(). This is intended to enable the 41546636e97aSMatthew G Knepley setting of ghost coordinates outside of the domain. 41556636e97aSMatthew G Knepley 41566636e97aSMatthew G Knepley Level: intermediate 41576636e97aSMatthew G Knepley 41586636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 41596636e97aSMatthew G Knepley .seealso: DMGetCoordinatesLocal(), DMSetCoordinates(), DMGetCoordinates(), DMGetCoordinateDM() 41606636e97aSMatthew G Knepley @*/ 41616636e97aSMatthew G Knepley PetscErrorCode DMSetCoordinatesLocal(DM dm, Vec c) 41626636e97aSMatthew G Knepley { 41636636e97aSMatthew G Knepley PetscErrorCode ierr; 41646636e97aSMatthew G Knepley 41656636e97aSMatthew G Knepley PetscFunctionBegin; 41666636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 41676636e97aSMatthew G Knepley PetscValidHeaderSpecific(c,VEC_CLASSID,2); 41686636e97aSMatthew G Knepley ierr = PetscObjectReference((PetscObject) c);CHKERRQ(ierr); 41696636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinatesLocal);CHKERRQ(ierr); 41708865f1eaSKarl Rupp 41716636e97aSMatthew G Knepley dm->coordinatesLocal = c; 41728865f1eaSKarl Rupp 41736636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinates);CHKERRQ(ierr); 41746636e97aSMatthew G Knepley PetscFunctionReturn(0); 41756636e97aSMatthew G Knepley } 41766636e97aSMatthew G Knepley 41776636e97aSMatthew G Knepley #undef __FUNCT__ 41786636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinates" 41796636e97aSMatthew G Knepley /*@ 41806636e97aSMatthew G Knepley DMGetCoordinates - Gets a global vector with the coordinates associated with the DM. 41816636e97aSMatthew G Knepley 41826636e97aSMatthew G Knepley Not Collective 41836636e97aSMatthew G Knepley 41846636e97aSMatthew G Knepley Input Parameter: 41856636e97aSMatthew G Knepley . dm - the DM 41866636e97aSMatthew G Knepley 41876636e97aSMatthew G Knepley Output Parameter: 41886636e97aSMatthew G Knepley . c - global coordinate vector 41896636e97aSMatthew G Knepley 41906636e97aSMatthew G Knepley Note: 41916636e97aSMatthew G Knepley This is a borrowed reference, so the user should NOT destroy this vector 41926636e97aSMatthew G Knepley 41936636e97aSMatthew G Knepley Each process has only the local coordinates (does NOT have the ghost coordinates). 41946636e97aSMatthew G Knepley 41956636e97aSMatthew G Knepley For DMDA, in two and three dimensions coordinates are interlaced (x_0,y_0,x_1,y_1,...) 41966636e97aSMatthew G Knepley and (x_0,y_0,z_0,x_1,y_1,z_1...) 41976636e97aSMatthew G Knepley 41986636e97aSMatthew G Knepley Level: intermediate 41996636e97aSMatthew G Knepley 42006636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 42016636e97aSMatthew G Knepley .seealso: DMSetCoordinates(), DMGetCoordinatesLocal(), DMGetCoordinateDM() 42026636e97aSMatthew G Knepley @*/ 42036636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinates(DM dm, Vec *c) 42046636e97aSMatthew G Knepley { 42056636e97aSMatthew G Knepley PetscErrorCode ierr; 42066636e97aSMatthew G Knepley 42076636e97aSMatthew G Knepley PetscFunctionBegin; 42086636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 42096636e97aSMatthew G Knepley PetscValidPointer(c,2); 42101f588964SMatthew G Knepley if (!dm->coordinates && dm->coordinatesLocal) { 42110298fd71SBarry Smith DM cdm = NULL; 42126636e97aSMatthew G Knepley 42136636e97aSMatthew G Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 42146636e97aSMatthew G Knepley ierr = DMCreateGlobalVector(cdm, &dm->coordinates);CHKERRQ(ierr); 42156636e97aSMatthew G Knepley ierr = PetscObjectSetName((PetscObject) dm->coordinates, "coordinates");CHKERRQ(ierr); 42166636e97aSMatthew G Knepley ierr = DMLocalToGlobalBegin(cdm, dm->coordinatesLocal, INSERT_VALUES, dm->coordinates);CHKERRQ(ierr); 42176636e97aSMatthew G Knepley ierr = DMLocalToGlobalEnd(cdm, dm->coordinatesLocal, INSERT_VALUES, dm->coordinates);CHKERRQ(ierr); 42186636e97aSMatthew G Knepley } 42196636e97aSMatthew G Knepley *c = dm->coordinates; 42206636e97aSMatthew G Knepley PetscFunctionReturn(0); 42216636e97aSMatthew G Knepley } 42226636e97aSMatthew G Knepley 42236636e97aSMatthew G Knepley #undef __FUNCT__ 42246636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinatesLocal" 42256636e97aSMatthew G Knepley /*@ 42266636e97aSMatthew G Knepley DMGetCoordinatesLocal - Gets a local vector with the coordinates associated with the DM. 42276636e97aSMatthew G Knepley 42286636e97aSMatthew G Knepley Collective on DM 42296636e97aSMatthew G Knepley 42306636e97aSMatthew G Knepley Input Parameter: 42316636e97aSMatthew G Knepley . dm - the DM 42326636e97aSMatthew G Knepley 42336636e97aSMatthew G Knepley Output Parameter: 42346636e97aSMatthew G Knepley . c - coordinate vector 42356636e97aSMatthew G Knepley 42366636e97aSMatthew G Knepley Note: 42376636e97aSMatthew G Knepley This is a borrowed reference, so the user should NOT destroy this vector 42386636e97aSMatthew G Knepley 42396636e97aSMatthew G Knepley Each process has the local and ghost coordinates 42406636e97aSMatthew G Knepley 42416636e97aSMatthew G Knepley For DMDA, in two and three dimensions coordinates are interlaced (x_0,y_0,x_1,y_1,...) 42426636e97aSMatthew G Knepley and (x_0,y_0,z_0,x_1,y_1,z_1...) 42436636e97aSMatthew G Knepley 42446636e97aSMatthew G Knepley Level: intermediate 42456636e97aSMatthew G Knepley 42466636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 42476636e97aSMatthew G Knepley .seealso: DMSetCoordinatesLocal(), DMGetCoordinates(), DMSetCoordinates(), DMGetCoordinateDM() 42486636e97aSMatthew G Knepley @*/ 42496636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinatesLocal(DM dm, Vec *c) 42506636e97aSMatthew G Knepley { 42516636e97aSMatthew G Knepley PetscErrorCode ierr; 42526636e97aSMatthew G Knepley 42536636e97aSMatthew G Knepley PetscFunctionBegin; 42546636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 42556636e97aSMatthew G Knepley PetscValidPointer(c,2); 42561f588964SMatthew G Knepley if (!dm->coordinatesLocal && dm->coordinates) { 42570298fd71SBarry Smith DM cdm = NULL; 42586636e97aSMatthew G Knepley 42596636e97aSMatthew G Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 42606636e97aSMatthew G Knepley ierr = DMCreateLocalVector(cdm, &dm->coordinatesLocal);CHKERRQ(ierr); 42616636e97aSMatthew G Knepley ierr = PetscObjectSetName((PetscObject) dm->coordinatesLocal, "coordinates");CHKERRQ(ierr); 42626636e97aSMatthew G Knepley ierr = DMGlobalToLocalBegin(cdm, dm->coordinates, INSERT_VALUES, dm->coordinatesLocal);CHKERRQ(ierr); 42636636e97aSMatthew G Knepley ierr = DMGlobalToLocalEnd(cdm, dm->coordinates, INSERT_VALUES, dm->coordinatesLocal);CHKERRQ(ierr); 42646636e97aSMatthew G Knepley } 42656636e97aSMatthew G Knepley *c = dm->coordinatesLocal; 42666636e97aSMatthew G Knepley PetscFunctionReturn(0); 42676636e97aSMatthew G Knepley } 42686636e97aSMatthew G Knepley 42696636e97aSMatthew G Knepley #undef __FUNCT__ 42706636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinateDM" 42716636e97aSMatthew G Knepley /*@ 42721cfe2091SMatthew G. Knepley DMGetCoordinateDM - Gets the DM that prescribes coordinate layout and scatters between global and local coordinates 42736636e97aSMatthew G Knepley 42746636e97aSMatthew G Knepley Collective on DM 42756636e97aSMatthew G Knepley 42766636e97aSMatthew G Knepley Input Parameter: 42776636e97aSMatthew G Knepley . dm - the DM 42786636e97aSMatthew G Knepley 42796636e97aSMatthew G Knepley Output Parameter: 42806636e97aSMatthew G Knepley . cdm - coordinate DM 42816636e97aSMatthew G Knepley 42826636e97aSMatthew G Knepley Level: intermediate 42836636e97aSMatthew G Knepley 42846636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 42851cfe2091SMatthew G. Knepley .seealso: DMSetCoordinateDM(), DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 42866636e97aSMatthew G Knepley @*/ 42876636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinateDM(DM dm, DM *cdm) 42886636e97aSMatthew G Knepley { 42896636e97aSMatthew G Knepley PetscErrorCode ierr; 42906636e97aSMatthew G Knepley 42916636e97aSMatthew G Knepley PetscFunctionBegin; 42926636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 42936636e97aSMatthew G Knepley PetscValidPointer(cdm,2); 42946636e97aSMatthew G Knepley if (!dm->coordinateDM) { 429582f516ccSBarry Smith if (!dm->ops->createcoordinatedm) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Unable to create coordinates for this DM"); 42966636e97aSMatthew G Knepley ierr = (*dm->ops->createcoordinatedm)(dm, &dm->coordinateDM);CHKERRQ(ierr); 42976636e97aSMatthew G Knepley } 42986636e97aSMatthew G Knepley *cdm = dm->coordinateDM; 42996636e97aSMatthew G Knepley PetscFunctionReturn(0); 43006636e97aSMatthew G Knepley } 4301e87bb0d3SMatthew G Knepley 4302e87bb0d3SMatthew G Knepley #undef __FUNCT__ 43031cfe2091SMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateDM" 43041cfe2091SMatthew G. Knepley /*@ 43051cfe2091SMatthew G. Knepley DMSetCoordinateDM - Sets the DM that prescribes coordinate layout and scatters between global and local coordinates 43061cfe2091SMatthew G. Knepley 43071cfe2091SMatthew G. Knepley Logically Collective on DM 43081cfe2091SMatthew G. Knepley 43091cfe2091SMatthew G. Knepley Input Parameters: 43101cfe2091SMatthew G. Knepley + dm - the DM 43111cfe2091SMatthew G. Knepley - cdm - coordinate DM 43121cfe2091SMatthew G. Knepley 43131cfe2091SMatthew G. Knepley Level: intermediate 43141cfe2091SMatthew G. Knepley 43151cfe2091SMatthew G. Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 43161cfe2091SMatthew G. Knepley .seealso: DMGetCoordinateDM(), DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 43171cfe2091SMatthew G. Knepley @*/ 43181cfe2091SMatthew G. Knepley PetscErrorCode DMSetCoordinateDM(DM dm, DM cdm) 43191cfe2091SMatthew G. Knepley { 43201cfe2091SMatthew G. Knepley PetscErrorCode ierr; 43211cfe2091SMatthew G. Knepley 43221cfe2091SMatthew G. Knepley PetscFunctionBegin; 43231cfe2091SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 43241cfe2091SMatthew G. Knepley PetscValidHeaderSpecific(cdm,DM_CLASSID,2); 43251cfe2091SMatthew G. Knepley ierr = DMDestroy(&dm->coordinateDM);CHKERRQ(ierr); 43261cfe2091SMatthew G. Knepley dm->coordinateDM = cdm; 43271cfe2091SMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm->coordinateDM);CHKERRQ(ierr); 43281cfe2091SMatthew G. Knepley PetscFunctionReturn(0); 43291cfe2091SMatthew G. Knepley } 43301cfe2091SMatthew G. Knepley 43311cfe2091SMatthew G. Knepley #undef __FUNCT__ 433246e270d4SMatthew G. Knepley #define __FUNCT__ "DMGetCoordinateDim" 433346e270d4SMatthew G. Knepley /*@ 433446e270d4SMatthew G. Knepley DMGetCoordinateDim - Retrieve the dimension of embedding space for coordinate values. 433546e270d4SMatthew G. Knepley 433646e270d4SMatthew G. Knepley Not Collective 433746e270d4SMatthew G. Knepley 433846e270d4SMatthew G. Knepley Input Parameter: 433946e270d4SMatthew G. Knepley . dm - The DM object 434046e270d4SMatthew G. Knepley 434146e270d4SMatthew G. Knepley Output Parameter: 434246e270d4SMatthew G. Knepley . dim - The embedding dimension 434346e270d4SMatthew G. Knepley 434446e270d4SMatthew G. Knepley Level: intermediate 434546e270d4SMatthew G. Knepley 434646e270d4SMatthew G. Knepley .keywords: mesh, coordinates 434746e270d4SMatthew G. Knepley .seealso: DMSetCoordinateDim(), DMGetCoordinateSection(), DMGetCoordinateDM(), DMGetDefaultSection(), DMSetDefaultSection() 434846e270d4SMatthew G. Knepley @*/ 434946e270d4SMatthew G. Knepley PetscErrorCode DMGetCoordinateDim(DM dm, PetscInt *dim) 435046e270d4SMatthew G. Knepley { 435146e270d4SMatthew G. Knepley PetscFunctionBegin; 435246e270d4SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 435346e270d4SMatthew G. Knepley PetscValidPointer(dim, 2); 43549a9a41abSToby Isaac if (dm->dimEmbed == PETSC_DEFAULT) { 43559a9a41abSToby Isaac dm->dimEmbed = dm->dim; 43569a9a41abSToby Isaac } 435746e270d4SMatthew G. Knepley *dim = dm->dimEmbed; 435846e270d4SMatthew G. Knepley PetscFunctionReturn(0); 435946e270d4SMatthew G. Knepley } 436046e270d4SMatthew G. Knepley 436146e270d4SMatthew G. Knepley #undef __FUNCT__ 436246e270d4SMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateDim" 436346e270d4SMatthew G. Knepley /*@ 436446e270d4SMatthew G. Knepley DMSetCoordinateDim - Set the dimension of the embedding space for coordinate values. 436546e270d4SMatthew G. Knepley 436646e270d4SMatthew G. Knepley Not Collective 436746e270d4SMatthew G. Knepley 436846e270d4SMatthew G. Knepley Input Parameters: 436946e270d4SMatthew G. Knepley + dm - The DM object 437046e270d4SMatthew G. Knepley - dim - The embedding dimension 437146e270d4SMatthew G. Knepley 437246e270d4SMatthew G. Knepley Level: intermediate 437346e270d4SMatthew G. Knepley 437446e270d4SMatthew G. Knepley .keywords: mesh, coordinates 437546e270d4SMatthew G. Knepley .seealso: DMGetCoordinateDim(), DMSetCoordinateSection(), DMGetCoordinateSection(), DMGetDefaultSection(), DMSetDefaultSection() 437646e270d4SMatthew G. Knepley @*/ 437746e270d4SMatthew G. Knepley PetscErrorCode DMSetCoordinateDim(DM dm, PetscInt dim) 437846e270d4SMatthew G. Knepley { 437946e270d4SMatthew G. Knepley PetscFunctionBegin; 438046e270d4SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 438146e270d4SMatthew G. Knepley dm->dimEmbed = dim; 438246e270d4SMatthew G. Knepley PetscFunctionReturn(0); 438346e270d4SMatthew G. Knepley } 438446e270d4SMatthew G. Knepley 438546e270d4SMatthew G. Knepley #undef __FUNCT__ 4386e8abe2deSMatthew G. Knepley #define __FUNCT__ "DMGetCoordinateSection" 4387e8abe2deSMatthew G. Knepley /*@ 4388e8abe2deSMatthew G. Knepley DMGetCoordinateSection - Retrieve the layout of coordinate values over the mesh. 4389e8abe2deSMatthew G. Knepley 4390e8abe2deSMatthew G. Knepley Not Collective 4391e8abe2deSMatthew G. Knepley 4392e8abe2deSMatthew G. Knepley Input Parameter: 4393e8abe2deSMatthew G. Knepley . dm - The DM object 4394e8abe2deSMatthew G. Knepley 4395e8abe2deSMatthew G. Knepley Output Parameter: 4396e8abe2deSMatthew G. Knepley . section - The PetscSection object 4397e8abe2deSMatthew G. Knepley 4398e8abe2deSMatthew G. Knepley Level: intermediate 4399e8abe2deSMatthew G. Knepley 4400e8abe2deSMatthew G. Knepley .keywords: mesh, coordinates 4401e8abe2deSMatthew G. Knepley .seealso: DMGetCoordinateDM(), DMGetDefaultSection(), DMSetDefaultSection() 4402e8abe2deSMatthew G. Knepley @*/ 4403e8abe2deSMatthew G. Knepley PetscErrorCode DMGetCoordinateSection(DM dm, PetscSection *section) 4404e8abe2deSMatthew G. Knepley { 4405e8abe2deSMatthew G. Knepley DM cdm; 4406e8abe2deSMatthew G. Knepley PetscErrorCode ierr; 4407e8abe2deSMatthew G. Knepley 4408e8abe2deSMatthew G. Knepley PetscFunctionBegin; 4409e8abe2deSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 4410e8abe2deSMatthew G. Knepley PetscValidPointer(section, 2); 4411e8abe2deSMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 4412e8abe2deSMatthew G. Knepley ierr = DMGetDefaultSection(cdm, section);CHKERRQ(ierr); 4413e8abe2deSMatthew G. Knepley PetscFunctionReturn(0); 4414e8abe2deSMatthew G. Knepley } 4415e8abe2deSMatthew G. Knepley 4416e8abe2deSMatthew G. Knepley #undef __FUNCT__ 4417e8abe2deSMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateSection" 4418e8abe2deSMatthew G. Knepley /*@ 4419e8abe2deSMatthew G. Knepley DMSetCoordinateSection - Set the layout of coordinate values over the mesh. 4420e8abe2deSMatthew G. Knepley 4421e8abe2deSMatthew G. Knepley Not Collective 4422e8abe2deSMatthew G. Knepley 4423e8abe2deSMatthew G. Knepley Input Parameters: 4424e8abe2deSMatthew G. Knepley + dm - The DM object 442546e270d4SMatthew G. Knepley . dim - The embedding dimension, or PETSC_DETERMINE 4426e8abe2deSMatthew G. Knepley - section - The PetscSection object 4427e8abe2deSMatthew G. Knepley 4428e8abe2deSMatthew G. Knepley Level: intermediate 4429e8abe2deSMatthew G. Knepley 4430e8abe2deSMatthew G. Knepley .keywords: mesh, coordinates 4431e8abe2deSMatthew G. Knepley .seealso: DMGetCoordinateSection(), DMGetDefaultSection(), DMSetDefaultSection() 4432e8abe2deSMatthew G. Knepley @*/ 443346e270d4SMatthew G. Knepley PetscErrorCode DMSetCoordinateSection(DM dm, PetscInt dim, PetscSection section) 4434e8abe2deSMatthew G. Knepley { 4435e8abe2deSMatthew G. Knepley DM cdm; 4436e8abe2deSMatthew G. Knepley PetscErrorCode ierr; 4437e8abe2deSMatthew G. Knepley 4438e8abe2deSMatthew G. Knepley PetscFunctionBegin; 4439e8abe2deSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 444046e270d4SMatthew G. Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,3); 4441e8abe2deSMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 4442e8abe2deSMatthew G. Knepley ierr = DMSetDefaultSection(cdm, section);CHKERRQ(ierr); 444346e270d4SMatthew G. Knepley if (dim == PETSC_DETERMINE) { 444446e270d4SMatthew G. Knepley PetscInt d = dim; 444546e270d4SMatthew G. Knepley PetscInt pStart, pEnd, vStart, vEnd, v, dd; 444646e270d4SMatthew G. Knepley 444746e270d4SMatthew G. Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 444846e270d4SMatthew G. Knepley ierr = DMGetDimPoints(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 444946e270d4SMatthew G. Knepley pStart = PetscMax(vStart, pStart); 445046e270d4SMatthew G. Knepley pEnd = PetscMin(vEnd, pEnd); 445146e270d4SMatthew G. Knepley for (v = pStart; v < pEnd; ++v) { 445246e270d4SMatthew G. Knepley ierr = PetscSectionGetDof(section, v, &dd);CHKERRQ(ierr); 445346e270d4SMatthew G. Knepley if (dd) {d = dd; break;} 445446e270d4SMatthew G. Knepley } 445546e270d4SMatthew G. Knepley ierr = DMSetCoordinateDim(dm, d);CHKERRQ(ierr); 445646e270d4SMatthew G. Knepley } 4457e8abe2deSMatthew G. Knepley PetscFunctionReturn(0); 4458e8abe2deSMatthew G. Knepley } 4459e8abe2deSMatthew G. Knepley 4460e8abe2deSMatthew G. Knepley #undef __FUNCT__ 4461c6b900c6SMatthew G. Knepley #define __FUNCT__ "DMGetPeriodicity" 44625dc8c3f7SMatthew G. Knepley /*@C 44635dc8c3f7SMatthew G. Knepley DMSetPeriodicity - Set the description of mesh periodicity 44645dc8c3f7SMatthew G. Knepley 44655dc8c3f7SMatthew G. Knepley Input Parameters: 44665dc8c3f7SMatthew G. Knepley + dm - The DM object 44675dc8c3f7SMatthew 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 44685dc8c3f7SMatthew G. Knepley . L - If we assume the mesh is a torus, this is the length of each coordinate 44695dc8c3f7SMatthew G. Knepley - bd - This describes the type of periodicity in each topological dimension 44705dc8c3f7SMatthew G. Knepley 44715dc8c3f7SMatthew G. Knepley Level: developer 44725dc8c3f7SMatthew G. Knepley 44735dc8c3f7SMatthew G. Knepley .seealso: DMGetPeriodicity() 44745dc8c3f7SMatthew G. Knepley @*/ 44755dc8c3f7SMatthew G. Knepley PetscErrorCode DMGetPeriodicity(DM dm, const PetscReal **maxCell, const PetscReal **L, const DMBoundaryType **bd) 4476c6b900c6SMatthew G. Knepley { 4477c6b900c6SMatthew G. Knepley PetscFunctionBegin; 4478c6b900c6SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4479c6b900c6SMatthew G. Knepley if (L) *L = dm->L; 4480c6b900c6SMatthew G. Knepley if (maxCell) *maxCell = dm->maxCell; 44815dc8c3f7SMatthew G. Knepley if (bd) *bd = dm->bdtype; 4482c6b900c6SMatthew G. Knepley PetscFunctionReturn(0); 4483c6b900c6SMatthew G. Knepley } 4484c6b900c6SMatthew G. Knepley 4485c6b900c6SMatthew G. Knepley #undef __FUNCT__ 4486c6b900c6SMatthew G. Knepley #define __FUNCT__ "DMSetPeriodicity" 44875dc8c3f7SMatthew G. Knepley /*@C 44885dc8c3f7SMatthew G. Knepley DMSetPeriodicity - Set the description of mesh periodicity 44895dc8c3f7SMatthew G. Knepley 44905dc8c3f7SMatthew G. Knepley Input Parameters: 44915dc8c3f7SMatthew G. Knepley + dm - The DM object 44925dc8c3f7SMatthew 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 44935dc8c3f7SMatthew G. Knepley . L - If we assume the mesh is a torus, this is the length of each coordinate 44945dc8c3f7SMatthew G. Knepley - bd - This describes the type of periodicity in each topological dimension 44955dc8c3f7SMatthew G. Knepley 44965dc8c3f7SMatthew G. Knepley Level: developer 44975dc8c3f7SMatthew G. Knepley 44985dc8c3f7SMatthew G. Knepley .seealso: DMGetPeriodicity() 44995dc8c3f7SMatthew G. Knepley @*/ 45005dc8c3f7SMatthew G. Knepley PetscErrorCode DMSetPeriodicity(DM dm, const PetscReal maxCell[], const PetscReal L[], const DMBoundaryType bd[]) 4501c6b900c6SMatthew G. Knepley { 4502c6b900c6SMatthew G. Knepley PetscInt dim, d; 4503c6b900c6SMatthew G. Knepley PetscErrorCode ierr; 4504c6b900c6SMatthew G. Knepley 4505c6b900c6SMatthew G. Knepley PetscFunctionBegin; 4506c6b900c6SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 45075dc8c3f7SMatthew G. Knepley PetscValidPointer(L,3);PetscValidPointer(maxCell,2);PetscValidPointer(bd,4); 45085dc8c3f7SMatthew G. Knepley ierr = PetscFree3(dm->L,dm->maxCell,dm->bdtype);CHKERRQ(ierr); 45095dc8c3f7SMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 45105dc8c3f7SMatthew G. Knepley ierr = PetscMalloc3(dim,&dm->L,dim,&dm->maxCell,dim,&dm->bdtype);CHKERRQ(ierr); 45115dc8c3f7SMatthew G. Knepley for (d = 0; d < dim; ++d) {dm->L[d] = L[d]; dm->maxCell[d] = maxCell[d]; dm->bdtype[d] = bd[d];} 4512c6b900c6SMatthew G. Knepley PetscFunctionReturn(0); 4513c6b900c6SMatthew G. Knepley } 4514c6b900c6SMatthew G. Knepley 4515c6b900c6SMatthew G. Knepley #undef __FUNCT__ 45162e17dfb7SMatthew G. Knepley #define __FUNCT__ "DMLocalizeCoordinate" 45172e17dfb7SMatthew G. Knepley /*@ 45182e17dfb7SMatthew 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. 45192e17dfb7SMatthew G. Knepley 45202e17dfb7SMatthew G. Knepley Input Parameters: 45212e17dfb7SMatthew G. Knepley + dm - The DM 45222e17dfb7SMatthew G. Knepley - in - The input coordinate point (dim numbers) 45232e17dfb7SMatthew G. Knepley 45242e17dfb7SMatthew G. Knepley Output Parameter: 45252e17dfb7SMatthew G. Knepley . out - The localized coordinate point 45262e17dfb7SMatthew G. Knepley 45272e17dfb7SMatthew G. Knepley Level: developer 45282e17dfb7SMatthew G. Knepley 45292e17dfb7SMatthew G. Knepley .seealso: DMLocalizeCoordinates(), DMLocalizeAddCoordinate() 45302e17dfb7SMatthew G. Knepley @*/ 45312e17dfb7SMatthew G. Knepley PetscErrorCode DMLocalizeCoordinate(DM dm, const PetscScalar in[], PetscScalar out[]) 45322e17dfb7SMatthew G. Knepley { 45332e17dfb7SMatthew G. Knepley PetscInt dim, d; 45342e17dfb7SMatthew G. Knepley PetscErrorCode ierr; 45352e17dfb7SMatthew G. Knepley 45362e17dfb7SMatthew G. Knepley PetscFunctionBegin; 45372e17dfb7SMatthew G. Knepley ierr = DMGetCoordinateDim(dm, &dim);CHKERRQ(ierr); 45382e17dfb7SMatthew G. Knepley if (!dm->maxCell) { 45392e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) out[d] = in[d]; 45402e17dfb7SMatthew G. Knepley } else { 45412e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) { 45422e17dfb7SMatthew G. Knepley out[d] = in[d] - dm->L[d]*floor(PetscRealPart(in[d])/dm->L[d]); 45432e17dfb7SMatthew G. Knepley } 45442e17dfb7SMatthew G. Knepley } 45452e17dfb7SMatthew G. Knepley PetscFunctionReturn(0); 45462e17dfb7SMatthew G. Knepley } 45472e17dfb7SMatthew G. Knepley 45482e17dfb7SMatthew G. Knepley #undef __FUNCT__ 45492e17dfb7SMatthew G. Knepley #define __FUNCT__ "DMLocalizeCoordinate_Internal" 45502e17dfb7SMatthew G. Knepley /* 45512e17dfb7SMatthew 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. 45522e17dfb7SMatthew G. Knepley 45532e17dfb7SMatthew G. Knepley Input Parameters: 45542e17dfb7SMatthew G. Knepley + dm - The DM 45552e17dfb7SMatthew G. Knepley . dim - The spatial dimension 45562e17dfb7SMatthew G. Knepley . anchor - The anchor point, the input point can be no more than maxCell away from it 45572e17dfb7SMatthew G. Knepley - in - The input coordinate point (dim numbers) 45582e17dfb7SMatthew G. Knepley 45592e17dfb7SMatthew G. Knepley Output Parameter: 45602e17dfb7SMatthew G. Knepley . out - The localized coordinate point 45612e17dfb7SMatthew G. Knepley 45622e17dfb7SMatthew G. Knepley Level: developer 45632e17dfb7SMatthew G. Knepley 45642e17dfb7SMatthew 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 45652e17dfb7SMatthew G. Knepley 45662e17dfb7SMatthew G. Knepley .seealso: DMLocalizeCoordinates(), DMLocalizeAddCoordinate() 45672e17dfb7SMatthew G. Knepley */ 45682e17dfb7SMatthew G. Knepley PetscErrorCode DMLocalizeCoordinate_Internal(DM dm, PetscInt dim, const PetscScalar anchor[], const PetscScalar in[], PetscScalar out[]) 45692e17dfb7SMatthew G. Knepley { 45702e17dfb7SMatthew G. Knepley PetscInt d; 45712e17dfb7SMatthew G. Knepley 45722e17dfb7SMatthew G. Knepley PetscFunctionBegin; 45732e17dfb7SMatthew G. Knepley if (!dm->maxCell) { 45742e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) out[d] = in[d]; 45752e17dfb7SMatthew G. Knepley } else { 45762e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) { 45772e17dfb7SMatthew G. Knepley if (PetscAbsScalar(anchor[d] - in[d]) > dm->maxCell[d]) { 45782e17dfb7SMatthew G. Knepley out[d] = PetscRealPart(anchor[d]) > PetscRealPart(in[d]) ? dm->L[d] + in[d] : in[d] - dm->L[d]; 45792e17dfb7SMatthew G. Knepley } else { 45802e17dfb7SMatthew G. Knepley out[d] = in[d]; 45812e17dfb7SMatthew G. Knepley } 45822e17dfb7SMatthew G. Knepley } 45832e17dfb7SMatthew G. Knepley } 45842e17dfb7SMatthew G. Knepley PetscFunctionReturn(0); 45852e17dfb7SMatthew G. Knepley } 45862e17dfb7SMatthew G. Knepley #undef __FUNCT__ 45872e17dfb7SMatthew G. Knepley #define __FUNCT__ "DMLocalizeCoordinateReal_Internal" 45882e17dfb7SMatthew G. Knepley PetscErrorCode DMLocalizeCoordinateReal_Internal(DM dm, PetscInt dim, const PetscReal anchor[], const PetscReal in[], PetscReal out[]) 45892e17dfb7SMatthew G. Knepley { 45902e17dfb7SMatthew G. Knepley PetscInt d; 45912e17dfb7SMatthew G. Knepley 45922e17dfb7SMatthew G. Knepley PetscFunctionBegin; 45932e17dfb7SMatthew G. Knepley if (!dm->maxCell) { 45942e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) out[d] = in[d]; 45952e17dfb7SMatthew G. Knepley } else { 45962e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) { 45972e17dfb7SMatthew G. Knepley if (PetscAbsReal(anchor[d] - in[d]) > dm->maxCell[d]) { 45982e17dfb7SMatthew G. Knepley out[d] = anchor[d] > in[d] ? dm->L[d] + in[d] : in[d] - dm->L[d]; 45992e17dfb7SMatthew G. Knepley } else { 46002e17dfb7SMatthew G. Knepley out[d] = in[d]; 46012e17dfb7SMatthew G. Knepley } 46022e17dfb7SMatthew G. Knepley } 46032e17dfb7SMatthew G. Knepley } 46042e17dfb7SMatthew G. Knepley PetscFunctionReturn(0); 46052e17dfb7SMatthew G. Knepley } 46062e17dfb7SMatthew G. Knepley 46072e17dfb7SMatthew G. Knepley #undef __FUNCT__ 46082e17dfb7SMatthew G. Knepley #define __FUNCT__ "DMLocalizeAddCoordinate_Internal" 46092e17dfb7SMatthew G. Knepley /* 46102e17dfb7SMatthew 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. 46112e17dfb7SMatthew G. Knepley 46122e17dfb7SMatthew G. Knepley Input Parameters: 46132e17dfb7SMatthew G. Knepley + dm - The DM 46142e17dfb7SMatthew G. Knepley . dim - The spatial dimension 46152e17dfb7SMatthew G. Knepley . anchor - The anchor point, the input point can be no more than maxCell away from it 46162e17dfb7SMatthew G. Knepley . in - The input coordinate delta (dim numbers) 46172e17dfb7SMatthew G. Knepley - out - The input coordinate point (dim numbers) 46182e17dfb7SMatthew G. Knepley 46192e17dfb7SMatthew G. Knepley Output Parameter: 46202e17dfb7SMatthew G. Knepley . out - The localized coordinate in + out 46212e17dfb7SMatthew G. Knepley 46222e17dfb7SMatthew G. Knepley Level: developer 46232e17dfb7SMatthew G. Knepley 46242e17dfb7SMatthew 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 46252e17dfb7SMatthew G. Knepley 46262e17dfb7SMatthew G. Knepley .seealso: DMLocalizeCoordinates(), DMLocalizeCoordinate() 46272e17dfb7SMatthew G. Knepley */ 46282e17dfb7SMatthew G. Knepley PetscErrorCode DMLocalizeAddCoordinate_Internal(DM dm, PetscInt dim, const PetscScalar anchor[], const PetscScalar in[], PetscScalar out[]) 46292e17dfb7SMatthew G. Knepley { 46302e17dfb7SMatthew G. Knepley PetscInt d; 46312e17dfb7SMatthew G. Knepley 46322e17dfb7SMatthew G. Knepley PetscFunctionBegin; 46332e17dfb7SMatthew G. Knepley if (!dm->maxCell) { 46342e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) out[d] += in[d]; 46352e17dfb7SMatthew G. Knepley } else { 46362e17dfb7SMatthew G. Knepley for (d = 0; d < dim; ++d) { 46372e17dfb7SMatthew G. Knepley if (PetscAbsScalar(anchor[d] - in[d]) > dm->maxCell[d]) { 46382e17dfb7SMatthew G. Knepley out[d] += PetscRealPart(anchor[d]) > PetscRealPart(in[d]) ? dm->L[d] + in[d] : in[d] - dm->L[d]; 46392e17dfb7SMatthew G. Knepley } else { 46402e17dfb7SMatthew G. Knepley out[d] += in[d]; 46412e17dfb7SMatthew G. Knepley } 46422e17dfb7SMatthew G. Knepley } 46432e17dfb7SMatthew G. Knepley } 46442e17dfb7SMatthew G. Knepley PetscFunctionReturn(0); 46452e17dfb7SMatthew G. Knepley } 46462e17dfb7SMatthew G. Knepley 46472e17dfb7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMPlexGetDepthStratum(DM, PetscInt, PetscInt *, PetscInt *); 46482e17dfb7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMPlexGetHeightStratum(DM, PetscInt, PetscInt *, PetscInt *); 46492e17dfb7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMPlexVecGetClosure(DM, PetscSection, Vec, PetscInt, PetscInt *, PetscScalar *[]); 46502e17dfb7SMatthew G. Knepley PETSC_EXTERN PetscErrorCode DMPlexVecRestoreClosure(DM, PetscSection, Vec, PetscInt, PetscInt *, PetscScalar *[]); 46512e17dfb7SMatthew G. Knepley 46522e17dfb7SMatthew G. Knepley #undef __FUNCT__ 465336447a5eSToby Isaac #define __FUNCT__ "DMGetCoordinatesLocalized" 465436447a5eSToby Isaac /*@ 465536447a5eSToby Isaac DMGetCoordinatesLocalized - Check if the DM coordinates have been localized for cells 465636447a5eSToby Isaac 465736447a5eSToby Isaac Input Parameter: 465836447a5eSToby Isaac . dm - The DM 465936447a5eSToby Isaac 466036447a5eSToby Isaac Output Parameter: 466136447a5eSToby Isaac areLocalized - True if localized 466236447a5eSToby Isaac 466336447a5eSToby Isaac Level: developer 466436447a5eSToby Isaac 466536447a5eSToby Isaac .seealso: DMLocalizeCoordinates() 466636447a5eSToby Isaac @*/ 466736447a5eSToby Isaac PetscErrorCode DMGetCoordinatesLocalized(DM dm,PetscBool *areLocalized) 466836447a5eSToby Isaac { 466936447a5eSToby Isaac DM cdm; 467036447a5eSToby Isaac PetscSection coordSection; 467136447a5eSToby Isaac PetscInt cStart, cEnd, c, sStart, sEnd, dof; 467236447a5eSToby Isaac PetscBool alreadyLocalized, alreadyLocalizedGlobal; 467336447a5eSToby Isaac PetscErrorCode ierr; 467436447a5eSToby Isaac 467536447a5eSToby Isaac PetscFunctionBegin; 467636447a5eSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 46778b09590cSToby Isaac if (!dm->maxCell) { 46788b09590cSToby Isaac *areLocalized = PETSC_FALSE; 46798b09590cSToby Isaac PetscFunctionReturn(0); 46808b09590cSToby Isaac } 468136447a5eSToby Isaac /* We need some generic way of refering to cells/vertices */ 468236447a5eSToby Isaac ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 468336447a5eSToby Isaac { 468436447a5eSToby Isaac PetscBool isplex; 468536447a5eSToby Isaac 468636447a5eSToby Isaac ierr = PetscObjectTypeCompare((PetscObject) cdm, DMPLEX, &isplex);CHKERRQ(ierr); 468736447a5eSToby Isaac if (isplex) { 468836447a5eSToby Isaac ierr = DMPlexGetHeightStratum(cdm, 0, &cStart, &cEnd);CHKERRQ(ierr); 468936447a5eSToby Isaac } else SETERRQ(PetscObjectComm((PetscObject) cdm), PETSC_ERR_ARG_WRONG, "Coordinate localization requires a DMPLEX coordinate DM"); 469036447a5eSToby Isaac } 469136447a5eSToby Isaac ierr = DMGetCoordinateSection(dm, &coordSection);CHKERRQ(ierr); 469236447a5eSToby Isaac ierr = PetscSectionGetChart(coordSection,&sStart,&sEnd);CHKERRQ(ierr); 469336447a5eSToby Isaac alreadyLocalized = alreadyLocalizedGlobal = PETSC_TRUE; 469436447a5eSToby Isaac for (c = cStart; c < cEnd; ++c) { 469536447a5eSToby Isaac if (c < sStart || c >= sEnd) { 469636447a5eSToby Isaac alreadyLocalized = PETSC_FALSE; 469736447a5eSToby Isaac break; 469836447a5eSToby Isaac } 469936447a5eSToby Isaac ierr = PetscSectionGetDof(coordSection, c, &dof);CHKERRQ(ierr); 470036447a5eSToby Isaac if (!dof) { 470136447a5eSToby Isaac alreadyLocalized = PETSC_FALSE; 470236447a5eSToby Isaac break; 470336447a5eSToby Isaac } 470436447a5eSToby Isaac } 470536447a5eSToby Isaac ierr = MPI_Allreduce(&alreadyLocalized,&alreadyLocalizedGlobal,1,MPIU_BOOL,MPI_LAND,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 470636447a5eSToby Isaac *areLocalized = alreadyLocalizedGlobal; 470736447a5eSToby Isaac PetscFunctionReturn(0); 470836447a5eSToby Isaac } 470936447a5eSToby Isaac 471036447a5eSToby Isaac 471136447a5eSToby Isaac #undef __FUNCT__ 47122e17dfb7SMatthew G. Knepley #define __FUNCT__ "DMLocalizeCoordinates" 47132e17dfb7SMatthew G. Knepley /*@ 47142e17dfb7SMatthew G. Knepley DMLocalizeCoordinates - If a mesh is periodic, create local coordinates for each cell 47152e17dfb7SMatthew G. Knepley 47162e17dfb7SMatthew G. Knepley Input Parameter: 47172e17dfb7SMatthew G. Knepley . dm - The DM 47182e17dfb7SMatthew G. Knepley 47192e17dfb7SMatthew G. Knepley Level: developer 47202e17dfb7SMatthew G. Knepley 47212e17dfb7SMatthew G. Knepley .seealso: DMLocalizeCoordinate(), DMLocalizeAddCoordinate() 47222e17dfb7SMatthew G. Knepley @*/ 47232e17dfb7SMatthew G. Knepley PetscErrorCode DMLocalizeCoordinates(DM dm) 47242e17dfb7SMatthew G. Knepley { 47252e17dfb7SMatthew G. Knepley DM cdm; 47262e17dfb7SMatthew G. Knepley PetscSection coordSection, cSection; 47272e17dfb7SMatthew G. Knepley Vec coordinates, cVec; 47282e17dfb7SMatthew G. Knepley PetscScalar *coords, *coords2, *anchor; 4729e0ae35bbSToby Isaac PetscInt Nc, cStart, cEnd, c, vStart, vEnd, v, sStart, sEnd, dof, d, off, off2, bs, coordSize; 4730e0ae35bbSToby Isaac PetscBool alreadyLocalized, alreadyLocalizedGlobal; 47312e17dfb7SMatthew G. Knepley PetscErrorCode ierr; 47322e17dfb7SMatthew G. Knepley 47332e17dfb7SMatthew G. Knepley PetscFunctionBegin; 47342e17dfb7SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 47352e17dfb7SMatthew G. Knepley if (!dm->maxCell) PetscFunctionReturn(0); 47362e17dfb7SMatthew G. Knepley /* We need some generic way of refering to cells/vertices */ 47372e17dfb7SMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 47382e17dfb7SMatthew G. Knepley { 47392e17dfb7SMatthew G. Knepley PetscBool isplex; 47402e17dfb7SMatthew G. Knepley 47412e17dfb7SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) cdm, DMPLEX, &isplex);CHKERRQ(ierr); 47422e17dfb7SMatthew G. Knepley if (isplex) { 47432e17dfb7SMatthew G. Knepley ierr = DMPlexGetHeightStratum(cdm, 0, &cStart, &cEnd);CHKERRQ(ierr); 47442e17dfb7SMatthew G. Knepley ierr = DMPlexGetDepthStratum(cdm, 0, &vStart, &vEnd);CHKERRQ(ierr); 47452e17dfb7SMatthew G. Knepley } else SETERRQ(PetscObjectComm((PetscObject) cdm), PETSC_ERR_ARG_WRONG, "Coordinate localization requires a DMPLEX coordinate DM"); 47462e17dfb7SMatthew G. Knepley } 47472e17dfb7SMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); 47482e17dfb7SMatthew G. Knepley ierr = DMGetCoordinateSection(dm, &coordSection);CHKERRQ(ierr); 4749e0ae35bbSToby Isaac ierr = PetscSectionGetChart(coordSection,&sStart,&sEnd);CHKERRQ(ierr); 4750e0ae35bbSToby Isaac alreadyLocalized = alreadyLocalizedGlobal = PETSC_TRUE; 4751e0ae35bbSToby Isaac for (c = cStart; c < cEnd; ++c) { 4752e0ae35bbSToby Isaac if (c < sStart || c >= sEnd) { 4753e0ae35bbSToby Isaac alreadyLocalized = PETSC_FALSE; 4754e0ae35bbSToby Isaac break; 4755e0ae35bbSToby Isaac } 4756e0ae35bbSToby Isaac ierr = PetscSectionGetDof(coordSection, c, &dof);CHKERRQ(ierr); 4757e0ae35bbSToby Isaac if (!dof) { 4758e0ae35bbSToby Isaac alreadyLocalized = PETSC_FALSE; 4759e0ae35bbSToby Isaac break; 4760e0ae35bbSToby Isaac } 4761e0ae35bbSToby Isaac } 4762e0ae35bbSToby Isaac ierr = MPI_Allreduce(&alreadyLocalized,&alreadyLocalizedGlobal,1,MPIU_BOOL,MPI_LAND,PetscObjectComm((PetscObject)dm));CHKERRQ(ierr); 4763e0ae35bbSToby Isaac if (alreadyLocalizedGlobal) PetscFunctionReturn(0); 47642e17dfb7SMatthew G. Knepley ierr = PetscSectionCreate(PetscObjectComm((PetscObject) dm), &cSection);CHKERRQ(ierr); 47652e17dfb7SMatthew G. Knepley ierr = PetscSectionSetNumFields(cSection, 1);CHKERRQ(ierr); 47662e17dfb7SMatthew G. Knepley ierr = PetscSectionGetFieldComponents(coordSection, 0, &Nc);CHKERRQ(ierr); 47672e17dfb7SMatthew G. Knepley ierr = PetscSectionSetFieldComponents(cSection, 0, Nc);CHKERRQ(ierr); 47682e17dfb7SMatthew G. Knepley ierr = PetscSectionSetChart(cSection, cStart, vEnd);CHKERRQ(ierr); 47692e17dfb7SMatthew G. Knepley for (v = vStart; v < vEnd; ++v) { 47702e17dfb7SMatthew G. Knepley ierr = PetscSectionGetDof(coordSection, v, &dof);CHKERRQ(ierr); 47712e17dfb7SMatthew G. Knepley ierr = PetscSectionSetDof(cSection, v, dof);CHKERRQ(ierr); 47722e17dfb7SMatthew G. Knepley ierr = PetscSectionSetFieldDof(cSection, v, 0, dof);CHKERRQ(ierr); 47732e17dfb7SMatthew G. Knepley } 47742e17dfb7SMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 47752e17dfb7SMatthew G. Knepley ierr = DMPlexVecGetClosure(cdm, coordSection, coordinates, c, &dof, NULL);CHKERRQ(ierr); 47762e17dfb7SMatthew G. Knepley ierr = PetscSectionSetDof(cSection, c, dof);CHKERRQ(ierr); 47772e17dfb7SMatthew G. Knepley ierr = PetscSectionSetFieldDof(cSection, c, 0, dof);CHKERRQ(ierr); 47782e17dfb7SMatthew G. Knepley } 47792e17dfb7SMatthew G. Knepley ierr = PetscSectionSetUp(cSection);CHKERRQ(ierr); 47802e17dfb7SMatthew G. Knepley ierr = PetscSectionGetStorageSize(cSection, &coordSize);CHKERRQ(ierr); 47812e17dfb7SMatthew G. Knepley ierr = VecCreate(PetscObjectComm((PetscObject) dm), &cVec);CHKERRQ(ierr); 47822e17dfb7SMatthew G. Knepley ierr = PetscObjectSetName((PetscObject)cVec,"coordinates");CHKERRQ(ierr); 47832e17dfb7SMatthew G. Knepley ierr = VecGetBlockSize(coordinates, &bs);CHKERRQ(ierr); 47842e17dfb7SMatthew G. Knepley ierr = VecSetBlockSize(cVec, bs);CHKERRQ(ierr); 47852e17dfb7SMatthew G. Knepley ierr = VecSetSizes(cVec, coordSize, PETSC_DETERMINE);CHKERRQ(ierr); 47862e17dfb7SMatthew G. Knepley ierr = VecSetType(cVec,VECSTANDARD);CHKERRQ(ierr); 47872e17dfb7SMatthew G. Knepley ierr = VecGetArray(coordinates, &coords);CHKERRQ(ierr); 47882e17dfb7SMatthew G. Knepley ierr = VecGetArray(cVec, &coords2);CHKERRQ(ierr); 47892e17dfb7SMatthew G. Knepley for (v = vStart; v < vEnd; ++v) { 47902e17dfb7SMatthew G. Knepley ierr = PetscSectionGetDof(coordSection, v, &dof);CHKERRQ(ierr); 47912e17dfb7SMatthew G. Knepley ierr = PetscSectionGetOffset(coordSection, v, &off);CHKERRQ(ierr); 47922e17dfb7SMatthew G. Knepley ierr = PetscSectionGetOffset(cSection, v, &off2);CHKERRQ(ierr); 47932e17dfb7SMatthew G. Knepley for (d = 0; d < dof; ++d) coords2[off2+d] = coords[off+d]; 47942e17dfb7SMatthew G. Knepley } 47952e17dfb7SMatthew G. Knepley ierr = DMGetWorkArray(dm, 3, PETSC_SCALAR, &anchor);CHKERRQ(ierr); 47962e17dfb7SMatthew G. Knepley for (c = cStart; c < cEnd; ++c) { 47972e17dfb7SMatthew G. Knepley PetscScalar *cellCoords = NULL; 47982e17dfb7SMatthew G. Knepley PetscInt b; 47992e17dfb7SMatthew G. Knepley 48002e17dfb7SMatthew G. Knepley ierr = DMPlexVecGetClosure(cdm, coordSection, coordinates, c, &dof, &cellCoords);CHKERRQ(ierr); 48012e17dfb7SMatthew G. Knepley ierr = PetscSectionGetOffset(cSection, c, &off2);CHKERRQ(ierr); 48022e17dfb7SMatthew G. Knepley for (b = 0; b < bs; ++b) anchor[b] = cellCoords[b]; 48032e17dfb7SMatthew G. Knepley for (d = 0; d < dof/bs; ++d) {ierr = DMLocalizeCoordinate_Internal(dm, bs, anchor, &cellCoords[d*bs], &coords2[off2+d*bs]);CHKERRQ(ierr);} 48042e17dfb7SMatthew G. Knepley ierr = DMPlexVecRestoreClosure(cdm, coordSection, coordinates, c, &dof, &cellCoords);CHKERRQ(ierr); 48052e17dfb7SMatthew G. Knepley } 48062e17dfb7SMatthew G. Knepley ierr = DMRestoreWorkArray(dm, 3, PETSC_SCALAR, &anchor);CHKERRQ(ierr); 48072e17dfb7SMatthew G. Knepley ierr = VecRestoreArray(coordinates, &coords);CHKERRQ(ierr); 48082e17dfb7SMatthew G. Knepley ierr = VecRestoreArray(cVec, &coords2);CHKERRQ(ierr); 48092e17dfb7SMatthew G. Knepley ierr = DMSetCoordinateSection(dm, PETSC_DETERMINE, cSection);CHKERRQ(ierr); 48102e17dfb7SMatthew G. Knepley ierr = DMSetCoordinatesLocal(dm, cVec);CHKERRQ(ierr); 48112e17dfb7SMatthew G. Knepley ierr = VecDestroy(&cVec);CHKERRQ(ierr); 48122e17dfb7SMatthew G. Knepley ierr = PetscSectionDestroy(&cSection);CHKERRQ(ierr); 48132e17dfb7SMatthew G. Knepley PetscFunctionReturn(0); 48142e17dfb7SMatthew G. Knepley } 48152e17dfb7SMatthew G. Knepley 48162e17dfb7SMatthew G. Knepley #undef __FUNCT__ 4817e87bb0d3SMatthew G Knepley #define __FUNCT__ "DMLocatePoints" 4818e87bb0d3SMatthew G Knepley /*@ 48193a93e3b7SToby Isaac DMLocatePoints - Locate the points in v in the mesh and return a PetscSF of the containing cells 4820e87bb0d3SMatthew G Knepley 48213a93e3b7SToby Isaac Collective on Vec v (see explanation below) 4822e87bb0d3SMatthew G Knepley 4823e87bb0d3SMatthew G Knepley Input Parameters: 4824e87bb0d3SMatthew G Knepley + dm - The DM 48253a93e3b7SToby Isaac . v - The Vec of points 48263a93e3b7SToby Isaac - cells - Points to either NULL, or a PetscSF with guesses for which cells contain each point. 4827e87bb0d3SMatthew G Knepley 482861e3bb9bSMatthew G Knepley Output Parameter: 48293a93e3b7SToby Isaac . cells - The PetscSF containing the ranks and local indices of the containing points. 48303a93e3b7SToby Isaac 4831e87bb0d3SMatthew G Knepley 4832e87bb0d3SMatthew G Knepley Level: developer 483361e3bb9bSMatthew G Knepley 48343a93e3b7SToby Isaac To do a search of the local cells of the mesh, v should have PETSC_COMM_SELF as its communicator. 48353a93e3b7SToby Isaac 48363a93e3b7SToby Isaac To do a search of all the cells in the distributed mesh, v should have the same communicator as 48373a93e3b7SToby Isaac dm. 48383a93e3b7SToby Isaac 48393a93e3b7SToby Isaac If *cellSF is NULL on input, a PetscSF will be created. 48403a93e3b7SToby Isaac 48413a93e3b7SToby Isaac If *cellSF is not NULL on input, it should point to an existing PetscSF, whose graph will be used as initial 48423a93e3b7SToby Isaac guesses. 48433a93e3b7SToby Isaac 48443a93e3b7SToby Isaac An array that maps each point to its containing cell can be obtained with 48453a93e3b7SToby Isaac 48463a93e3b7SToby Isaac const PetscSFNode *cells; 48473a93e3b7SToby Isaac PetscInt nFound; 48483a93e3b7SToby Isaac const PetscSFNode *found; 48493a93e3b7SToby Isaac 48503a93e3b7SToby Isaac PetscSFGetGraph(cells,NULL,&nFound,&found,&cells); 48513a93e3b7SToby Isaac 48523a93e3b7SToby 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 48533a93e3b7SToby Isaac the index of the cell in its rank's local numbering. 48543a93e3b7SToby Isaac 485561e3bb9bSMatthew G Knepley .keywords: point location, mesh 485661e3bb9bSMatthew G Knepley .seealso: DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 485761e3bb9bSMatthew G Knepley @*/ 48583a93e3b7SToby Isaac PetscErrorCode DMLocatePoints(DM dm, Vec v, PetscSF *cellSF) 4859e87bb0d3SMatthew G Knepley { 4860735aa83eSMatthew G Knepley PetscErrorCode ierr; 4861735aa83eSMatthew G Knepley 4862e87bb0d3SMatthew G Knepley PetscFunctionBegin; 4863e87bb0d3SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4864e87bb0d3SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,2); 48653a93e3b7SToby Isaac PetscValidPointer(cellSF,3); 48663a93e3b7SToby Isaac if (*cellSF) { 48673a93e3b7SToby Isaac PetscMPIInt result; 48683a93e3b7SToby Isaac 48693a93e3b7SToby Isaac PetscValidHeaderSpecific(cellSF,PETSCSF_CLASSID,3); 48703a93e3b7SToby Isaac ierr = MPI_Comm_compare(PetscObjectComm((PetscObject)v),PetscObjectComm((PetscObject)cellSF),&result);CHKERRQ(ierr); 48713a93e3b7SToby 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"); 48723a93e3b7SToby Isaac } 48733a93e3b7SToby Isaac else { 48743a93e3b7SToby Isaac ierr = PetscSFCreate(PetscObjectComm((PetscObject)v),cellSF);CHKERRQ(ierr); 48753a93e3b7SToby Isaac } 487647a35634SPatrick Farrell ierr = PetscLogEventBegin(DM_LocatePoints,dm,0,0,0);CHKERRQ(ierr); 4877735aa83eSMatthew G Knepley if (dm->ops->locatepoints) { 48783a93e3b7SToby Isaac ierr = (*dm->ops->locatepoints)(dm,v,*cellSF);CHKERRQ(ierr); 487982f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Point location not available for this DM"); 488047a35634SPatrick Farrell ierr = PetscLogEventEnd(DM_LocatePoints,dm,0,0,0);CHKERRQ(ierr); 4881e87bb0d3SMatthew G Knepley PetscFunctionReturn(0); 4882e87bb0d3SMatthew G Knepley } 488314f150ffSMatthew G. Knepley 488414f150ffSMatthew G. Knepley #undef __FUNCT__ 488514f150ffSMatthew G. Knepley #define __FUNCT__ "DMGetOutputDM" 4886f4d763aaSMatthew G. Knepley /*@ 4887f4d763aaSMatthew G. Knepley DMGetOutputDM - Retrieve the DM associated with the layout for output 4888f4d763aaSMatthew G. Knepley 4889f4d763aaSMatthew G. Knepley Input Parameter: 4890f4d763aaSMatthew G. Knepley . dm - The original DM 4891f4d763aaSMatthew G. Knepley 4892f4d763aaSMatthew G. Knepley Output Parameter: 4893f4d763aaSMatthew G. Knepley . odm - The DM which provides the layout for output 4894f4d763aaSMatthew G. Knepley 4895f4d763aaSMatthew G. Knepley Level: intermediate 4896f4d763aaSMatthew G. Knepley 4897f4d763aaSMatthew G. Knepley .seealso: VecView(), DMGetDefaultGlobalSection() 4898f4d763aaSMatthew G. Knepley @*/ 489914f150ffSMatthew G. Knepley PetscErrorCode DMGetOutputDM(DM dm, DM *odm) 490014f150ffSMatthew G. Knepley { 4901c26acbdeSMatthew G. Knepley PetscSection section; 4902c26acbdeSMatthew G. Knepley PetscBool hasConstraints; 490314f150ffSMatthew G. Knepley PetscErrorCode ierr; 490414f150ffSMatthew G. Knepley 490514f150ffSMatthew G. Knepley PetscFunctionBegin; 490614f150ffSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 490714f150ffSMatthew G. Knepley PetscValidPointer(odm,2); 4908c26acbdeSMatthew G. Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 4909c26acbdeSMatthew G. Knepley ierr = PetscSectionHasConstraints(section, &hasConstraints);CHKERRQ(ierr); 4910c26acbdeSMatthew G. Knepley if (!hasConstraints) { 4911c26acbdeSMatthew G. Knepley *odm = dm; 4912c26acbdeSMatthew G. Knepley PetscFunctionReturn(0); 4913c26acbdeSMatthew G. Knepley } 491414f150ffSMatthew G. Knepley if (!dm->dmBC) { 49150305aff6SMatthew G. Knepley PetscDS ds; 4916c26acbdeSMatthew G. Knepley PetscSection newSection, gsection; 491714f150ffSMatthew G. Knepley PetscSF sf; 491814f150ffSMatthew G. Knepley 491914f150ffSMatthew G. Knepley ierr = DMClone(dm, &dm->dmBC);CHKERRQ(ierr); 49200305aff6SMatthew G. Knepley ierr = DMGetDS(dm, &ds);CHKERRQ(ierr); 49210305aff6SMatthew G. Knepley ierr = DMSetDS(dm->dmBC, ds);CHKERRQ(ierr); 492214f150ffSMatthew G. Knepley ierr = PetscSectionClone(section, &newSection);CHKERRQ(ierr); 492314f150ffSMatthew G. Knepley ierr = DMSetDefaultSection(dm->dmBC, newSection);CHKERRQ(ierr); 492414f150ffSMatthew G. Knepley ierr = PetscSectionDestroy(&newSection);CHKERRQ(ierr); 492514f150ffSMatthew G. Knepley ierr = DMGetPointSF(dm->dmBC, &sf);CHKERRQ(ierr); 492615b58121SMatthew G. Knepley ierr = PetscSectionCreateGlobalSection(section, sf, PETSC_TRUE, PETSC_FALSE, &gsection);CHKERRQ(ierr); 492714f150ffSMatthew G. Knepley ierr = DMSetDefaultGlobalSection(dm->dmBC, gsection);CHKERRQ(ierr); 492814f150ffSMatthew G. Knepley ierr = PetscSectionDestroy(&gsection);CHKERRQ(ierr); 492914f150ffSMatthew G. Knepley } 493014f150ffSMatthew G. Knepley *odm = dm->dmBC; 493114f150ffSMatthew G. Knepley PetscFunctionReturn(0); 493214f150ffSMatthew G. Knepley } 4933f4d763aaSMatthew G. Knepley 4934f4d763aaSMatthew G. Knepley #undef __FUNCT__ 4935f4d763aaSMatthew G. Knepley #define __FUNCT__ "DMGetOutputSequenceNumber" 4936f4d763aaSMatthew G. Knepley /*@ 4937cdb7a50dSMatthew G. Knepley DMGetOutputSequenceNumber - Retrieve the sequence number/value for output 4938f4d763aaSMatthew G. Knepley 4939f4d763aaSMatthew G. Knepley Input Parameter: 4940f4d763aaSMatthew G. Knepley . dm - The original DM 4941f4d763aaSMatthew G. Knepley 4942cdb7a50dSMatthew G. Knepley Output Parameters: 4943cdb7a50dSMatthew G. Knepley + num - The output sequence number 4944cdb7a50dSMatthew G. Knepley - val - The output sequence value 4945f4d763aaSMatthew G. Knepley 4946f4d763aaSMatthew G. Knepley Level: intermediate 4947f4d763aaSMatthew G. Knepley 4948f4d763aaSMatthew G. Knepley Note: This is intended for output that should appear in sequence, for instance 4949f4d763aaSMatthew G. Knepley a set of timesteps in an HDF5 file, or a set of realizations of a stochastic system. 4950f4d763aaSMatthew G. Knepley 4951f4d763aaSMatthew G. Knepley .seealso: VecView() 4952f4d763aaSMatthew G. Knepley @*/ 4953cdb7a50dSMatthew G. Knepley PetscErrorCode DMGetOutputSequenceNumber(DM dm, PetscInt *num, PetscReal *val) 4954f4d763aaSMatthew G. Knepley { 4955f4d763aaSMatthew G. Knepley PetscFunctionBegin; 4956f4d763aaSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4957cdb7a50dSMatthew G. Knepley if (num) {PetscValidPointer(num,2); *num = dm->outputSequenceNum;} 4958cdb7a50dSMatthew G. Knepley if (val) {PetscValidPointer(val,3);*val = dm->outputSequenceVal;} 4959f4d763aaSMatthew G. Knepley PetscFunctionReturn(0); 4960f4d763aaSMatthew G. Knepley } 4961f4d763aaSMatthew G. Knepley 4962f4d763aaSMatthew G. Knepley #undef __FUNCT__ 4963f4d763aaSMatthew G. Knepley #define __FUNCT__ "DMSetOutputSequenceNumber" 4964f4d763aaSMatthew G. Knepley /*@ 4965cdb7a50dSMatthew G. Knepley DMSetOutputSequenceNumber - Set the sequence number/value for output 4966f4d763aaSMatthew G. Knepley 4967f4d763aaSMatthew G. Knepley Input Parameters: 4968f4d763aaSMatthew G. Knepley + dm - The original DM 4969cdb7a50dSMatthew G. Knepley . num - The output sequence number 4970cdb7a50dSMatthew G. Knepley - val - The output sequence value 4971f4d763aaSMatthew G. Knepley 4972f4d763aaSMatthew G. Knepley Level: intermediate 4973f4d763aaSMatthew G. Knepley 4974f4d763aaSMatthew G. Knepley Note: This is intended for output that should appear in sequence, for instance 4975f4d763aaSMatthew G. Knepley a set of timesteps in an HDF5 file, or a set of realizations of a stochastic system. 4976f4d763aaSMatthew G. Knepley 4977f4d763aaSMatthew G. Knepley .seealso: VecView() 4978f4d763aaSMatthew G. Knepley @*/ 4979cdb7a50dSMatthew G. Knepley PetscErrorCode DMSetOutputSequenceNumber(DM dm, PetscInt num, PetscReal val) 4980f4d763aaSMatthew G. Knepley { 4981f4d763aaSMatthew G. Knepley PetscFunctionBegin; 4982f4d763aaSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4983f4d763aaSMatthew G. Knepley dm->outputSequenceNum = num; 4984cdb7a50dSMatthew G. Knepley dm->outputSequenceVal = val; 4985cdb7a50dSMatthew G. Knepley PetscFunctionReturn(0); 4986cdb7a50dSMatthew G. Knepley } 4987cdb7a50dSMatthew G. Knepley 4988cdb7a50dSMatthew G. Knepley #undef __FUNCT__ 4989cdb7a50dSMatthew G. Knepley #define __FUNCT__ "DMOutputSequenceLoad" 4990cdb7a50dSMatthew G. Knepley /*@C 4991cdb7a50dSMatthew G. Knepley DMOutputSequenceLoad - Retrieve the sequence value from a Viewer 4992cdb7a50dSMatthew G. Knepley 4993cdb7a50dSMatthew G. Knepley Input Parameters: 4994cdb7a50dSMatthew G. Knepley + dm - The original DM 4995cdb7a50dSMatthew G. Knepley . name - The sequence name 4996cdb7a50dSMatthew G. Knepley - num - The output sequence number 4997cdb7a50dSMatthew G. Knepley 4998cdb7a50dSMatthew G. Knepley Output Parameter: 4999cdb7a50dSMatthew G. Knepley . val - The output sequence value 5000cdb7a50dSMatthew G. Knepley 5001cdb7a50dSMatthew G. Knepley Level: intermediate 5002cdb7a50dSMatthew G. Knepley 5003cdb7a50dSMatthew G. Knepley Note: This is intended for output that should appear in sequence, for instance 5004cdb7a50dSMatthew G. Knepley a set of timesteps in an HDF5 file, or a set of realizations of a stochastic system. 5005cdb7a50dSMatthew G. Knepley 5006cdb7a50dSMatthew G. Knepley .seealso: DMGetOutputSequenceNumber(), DMSetOutputSequenceNumber(), VecView() 5007cdb7a50dSMatthew G. Knepley @*/ 5008cdb7a50dSMatthew G. Knepley PetscErrorCode DMOutputSequenceLoad(DM dm, PetscViewer viewer, const char *name, PetscInt num, PetscReal *val) 5009cdb7a50dSMatthew G. Knepley { 5010cdb7a50dSMatthew G. Knepley PetscBool ishdf5; 5011cdb7a50dSMatthew G. Knepley PetscErrorCode ierr; 5012cdb7a50dSMatthew G. Knepley 5013cdb7a50dSMatthew G. Knepley PetscFunctionBegin; 5014cdb7a50dSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5015cdb7a50dSMatthew G. Knepley PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 5016cdb7a50dSMatthew G. Knepley PetscValidPointer(val,4); 5017cdb7a50dSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 5018cdb7a50dSMatthew G. Knepley if (ishdf5) { 5019cdb7a50dSMatthew G. Knepley #if defined(PETSC_HAVE_HDF5) 5020cdb7a50dSMatthew G. Knepley PetscScalar value; 5021cdb7a50dSMatthew G. Knepley 5022cdb7a50dSMatthew G. Knepley ierr = DMSequenceLoad_HDF5(dm, name, num, &value, viewer);CHKERRQ(ierr); 50234aeb217fSMatthew G. Knepley *val = PetscRealPart(value); 5024cdb7a50dSMatthew G. Knepley #endif 5025cdb7a50dSMatthew G. Knepley } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Invalid viewer; open viewer with PetscViewerHDF5Open()"); 5026f4d763aaSMatthew G. Knepley PetscFunctionReturn(0); 5027f4d763aaSMatthew G. Knepley } 50288e4ac7eaSMatthew G. Knepley 50298e4ac7eaSMatthew G. Knepley #undef __FUNCT__ 50308e4ac7eaSMatthew G. Knepley #define __FUNCT__ "DMGetUseNatural" 50318e4ac7eaSMatthew G. Knepley /*@ 50328e4ac7eaSMatthew G. Knepley DMGetUseNatural - Get the flag for creating a mapping to the natural order on distribution 50338e4ac7eaSMatthew G. Knepley 50348e4ac7eaSMatthew G. Knepley Not collective 50358e4ac7eaSMatthew G. Knepley 50368e4ac7eaSMatthew G. Knepley Input Parameter: 50378e4ac7eaSMatthew G. Knepley . dm - The DM 50388e4ac7eaSMatthew G. Knepley 50398e4ac7eaSMatthew G. Knepley Output Parameter: 50408e4ac7eaSMatthew G. Knepley . useNatural - The flag to build the mapping to a natural order during distribution 50418e4ac7eaSMatthew G. Knepley 50428e4ac7eaSMatthew G. Knepley Level: beginner 50438e4ac7eaSMatthew G. Knepley 50448e4ac7eaSMatthew G. Knepley .seealso: DMSetUseNatural(), DMCreate() 50458e4ac7eaSMatthew G. Knepley @*/ 50468e4ac7eaSMatthew G. Knepley PetscErrorCode DMGetUseNatural(DM dm, PetscBool *useNatural) 50478e4ac7eaSMatthew G. Knepley { 50488e4ac7eaSMatthew G. Knepley PetscFunctionBegin; 50498e4ac7eaSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 50508e4ac7eaSMatthew G. Knepley PetscValidPointer(useNatural, 2); 50518e4ac7eaSMatthew G. Knepley *useNatural = dm->useNatural; 50528e4ac7eaSMatthew G. Knepley PetscFunctionReturn(0); 50538e4ac7eaSMatthew G. Knepley } 50548e4ac7eaSMatthew G. Knepley 50558e4ac7eaSMatthew G. Knepley #undef __FUNCT__ 50568e4ac7eaSMatthew G. Knepley #define __FUNCT__ "DMSetUseNatural" 50578e4ac7eaSMatthew G. Knepley /*@ 50588e4ac7eaSMatthew G. Knepley DMSetUseNatural - Set the flag for creating a mapping to the natural order on distribution 50598e4ac7eaSMatthew G. Knepley 50608e4ac7eaSMatthew G. Knepley Collective on dm 50618e4ac7eaSMatthew G. Knepley 50628e4ac7eaSMatthew G. Knepley Input Parameters: 50638e4ac7eaSMatthew G. Knepley + dm - The DM 50648e4ac7eaSMatthew G. Knepley - useNatural - The flag to build the mapping to a natural order during distribution 50658e4ac7eaSMatthew G. Knepley 50668e4ac7eaSMatthew G. Knepley Level: beginner 50678e4ac7eaSMatthew G. Knepley 50688e4ac7eaSMatthew G. Knepley .seealso: DMGetUseNatural(), DMCreate() 50698e4ac7eaSMatthew G. Knepley @*/ 50708e4ac7eaSMatthew G. Knepley PetscErrorCode DMSetUseNatural(DM dm, PetscBool useNatural) 50718e4ac7eaSMatthew G. Knepley { 50728e4ac7eaSMatthew G. Knepley PetscFunctionBegin; 50738e4ac7eaSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 50748e4ac7eaSMatthew G. Knepley PetscValidLogicalCollectiveInt(dm, useNatural, 2); 50758e4ac7eaSMatthew G. Knepley dm->useNatural = useNatural; 50768e4ac7eaSMatthew G. Knepley PetscFunctionReturn(0); 50778e4ac7eaSMatthew G. Knepley } 5078c58f1c22SToby Isaac 5079c58f1c22SToby Isaac #undef __FUNCT__ 5080c58f1c22SToby Isaac #define __FUNCT__ 5081c58f1c22SToby Isaac 5082c58f1c22SToby Isaac #undef __FUNCT__ 5083c58f1c22SToby Isaac #define __FUNCT__ "DMCreateLabel" 5084c58f1c22SToby Isaac /*@C 5085c58f1c22SToby Isaac DMCreateLabel - Create a label of the given name if it does not already exist 5086c58f1c22SToby Isaac 5087c58f1c22SToby Isaac Not Collective 5088c58f1c22SToby Isaac 5089c58f1c22SToby Isaac Input Parameters: 5090c58f1c22SToby Isaac + dm - The DM object 5091c58f1c22SToby Isaac - name - The label name 5092c58f1c22SToby Isaac 5093c58f1c22SToby Isaac Level: intermediate 5094c58f1c22SToby Isaac 5095c58f1c22SToby Isaac .keywords: mesh 5096c58f1c22SToby Isaac .seealso: DMLabelCreate(), DMHasLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5097c58f1c22SToby Isaac @*/ 5098c58f1c22SToby Isaac PetscErrorCode DMCreateLabel(DM dm, const char name[]) 5099c58f1c22SToby Isaac { 5100c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5101c58f1c22SToby Isaac PetscBool flg = PETSC_FALSE; 5102c58f1c22SToby Isaac PetscErrorCode ierr; 5103c58f1c22SToby Isaac 5104c58f1c22SToby Isaac PetscFunctionBegin; 5105c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5106c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5107c58f1c22SToby Isaac while (next) { 5108c58f1c22SToby Isaac ierr = PetscStrcmp(name, next->label->name, &flg);CHKERRQ(ierr); 5109c58f1c22SToby Isaac if (flg) break; 5110c58f1c22SToby Isaac next = next->next; 5111c58f1c22SToby Isaac } 5112c58f1c22SToby Isaac if (!flg) { 5113c58f1c22SToby Isaac DMLabelLink tmpLabel; 5114c58f1c22SToby Isaac 5115c58f1c22SToby Isaac ierr = PetscCalloc1(1, &tmpLabel);CHKERRQ(ierr); 5116c58f1c22SToby Isaac ierr = DMLabelCreate(name, &tmpLabel->label);CHKERRQ(ierr); 5117c58f1c22SToby Isaac tmpLabel->output = PETSC_TRUE; 5118c58f1c22SToby Isaac tmpLabel->next = dm->labels->next; 5119c58f1c22SToby Isaac dm->labels->next = tmpLabel; 5120c58f1c22SToby Isaac } 5121c58f1c22SToby Isaac PetscFunctionReturn(0); 5122c58f1c22SToby Isaac } 5123c58f1c22SToby Isaac 5124c58f1c22SToby Isaac #undef __FUNCT__ 5125c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabelValue" 5126c58f1c22SToby Isaac /*@C 5127c58f1c22SToby Isaac DMGetLabelValue - Get the value in a Sieve Label for the given point, with 0 as the default 5128c58f1c22SToby Isaac 5129c58f1c22SToby Isaac Not Collective 5130c58f1c22SToby Isaac 5131c58f1c22SToby Isaac Input Parameters: 5132c58f1c22SToby Isaac + dm - The DM object 5133c58f1c22SToby Isaac . name - The label name 5134c58f1c22SToby Isaac - point - The mesh point 5135c58f1c22SToby Isaac 5136c58f1c22SToby Isaac Output Parameter: 5137c58f1c22SToby Isaac . value - The label value for this point, or -1 if the point is not in the label 5138c58f1c22SToby Isaac 5139c58f1c22SToby Isaac Level: beginner 5140c58f1c22SToby Isaac 5141c58f1c22SToby Isaac .keywords: mesh 5142c58f1c22SToby Isaac .seealso: DMLabelGetValue(), DMSetLabelValue(), DMGetStratumIS() 5143c58f1c22SToby Isaac @*/ 5144c58f1c22SToby Isaac PetscErrorCode DMGetLabelValue(DM dm, const char name[], PetscInt point, PetscInt *value) 5145c58f1c22SToby Isaac { 5146c58f1c22SToby Isaac DMLabel label; 5147c58f1c22SToby Isaac PetscErrorCode ierr; 5148c58f1c22SToby Isaac 5149c58f1c22SToby Isaac PetscFunctionBegin; 5150c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5151c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5152c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5153c58f1c22SToby Isaac if (!label) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "No label named %s was found", name);CHKERRQ(ierr); 5154c58f1c22SToby Isaac ierr = DMLabelGetValue(label, point, value);CHKERRQ(ierr); 5155c58f1c22SToby Isaac PetscFunctionReturn(0); 5156c58f1c22SToby Isaac } 5157c58f1c22SToby Isaac 5158c58f1c22SToby Isaac #undef __FUNCT__ 5159c58f1c22SToby Isaac #define __FUNCT__ "DMSetLabelValue" 5160c58f1c22SToby Isaac /*@C 5161c58f1c22SToby Isaac DMSetLabelValue - Add a point to a Sieve Label with given value 5162c58f1c22SToby Isaac 5163c58f1c22SToby Isaac Not Collective 5164c58f1c22SToby Isaac 5165c58f1c22SToby Isaac Input Parameters: 5166c58f1c22SToby Isaac + dm - The DM object 5167c58f1c22SToby Isaac . name - The label name 5168c58f1c22SToby Isaac . point - The mesh point 5169c58f1c22SToby Isaac - value - The label value for this point 5170c58f1c22SToby Isaac 5171c58f1c22SToby Isaac Output Parameter: 5172c58f1c22SToby Isaac 5173c58f1c22SToby Isaac Level: beginner 5174c58f1c22SToby Isaac 5175c58f1c22SToby Isaac .keywords: mesh 5176c58f1c22SToby Isaac .seealso: DMLabelSetValue(), DMGetStratumIS(), DMClearLabelValue() 5177c58f1c22SToby Isaac @*/ 5178c58f1c22SToby Isaac PetscErrorCode DMSetLabelValue(DM dm, const char name[], PetscInt point, PetscInt value) 5179c58f1c22SToby Isaac { 5180c58f1c22SToby Isaac DMLabel label; 5181c58f1c22SToby Isaac PetscErrorCode ierr; 5182c58f1c22SToby Isaac 5183c58f1c22SToby Isaac PetscFunctionBegin; 5184c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5185c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5186c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5187c58f1c22SToby Isaac if (!label) { 5188c58f1c22SToby Isaac ierr = DMCreateLabel(dm, name);CHKERRQ(ierr); 5189c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5190c58f1c22SToby Isaac } 5191c58f1c22SToby Isaac ierr = DMLabelSetValue(label, point, value);CHKERRQ(ierr); 5192c58f1c22SToby Isaac PetscFunctionReturn(0); 5193c58f1c22SToby Isaac } 5194c58f1c22SToby Isaac 5195c58f1c22SToby Isaac #undef __FUNCT__ 5196c58f1c22SToby Isaac #define __FUNCT__ "DMClearLabelValue" 5197c58f1c22SToby Isaac /*@C 5198c58f1c22SToby Isaac DMClearLabelValue - Remove a point from a Sieve Label with given value 5199c58f1c22SToby Isaac 5200c58f1c22SToby Isaac Not Collective 5201c58f1c22SToby Isaac 5202c58f1c22SToby Isaac Input Parameters: 5203c58f1c22SToby Isaac + dm - The DM object 5204c58f1c22SToby Isaac . name - The label name 5205c58f1c22SToby Isaac . point - The mesh point 5206c58f1c22SToby Isaac - value - The label value for this point 5207c58f1c22SToby Isaac 5208c58f1c22SToby Isaac Output Parameter: 5209c58f1c22SToby Isaac 5210c58f1c22SToby Isaac Level: beginner 5211c58f1c22SToby Isaac 5212c58f1c22SToby Isaac .keywords: mesh 5213c58f1c22SToby Isaac .seealso: DMLabelClearValue(), DMSetLabelValue(), DMGetStratumIS() 5214c58f1c22SToby Isaac @*/ 5215c58f1c22SToby Isaac PetscErrorCode DMClearLabelValue(DM dm, const char name[], PetscInt point, PetscInt value) 5216c58f1c22SToby Isaac { 5217c58f1c22SToby Isaac DMLabel label; 5218c58f1c22SToby Isaac PetscErrorCode ierr; 5219c58f1c22SToby Isaac 5220c58f1c22SToby Isaac PetscFunctionBegin; 5221c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5222c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5223c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5224c58f1c22SToby Isaac if (!label) PetscFunctionReturn(0); 5225c58f1c22SToby Isaac ierr = DMLabelClearValue(label, point, value);CHKERRQ(ierr); 5226c58f1c22SToby Isaac PetscFunctionReturn(0); 5227c58f1c22SToby Isaac } 5228c58f1c22SToby Isaac 5229c58f1c22SToby Isaac #undef __FUNCT__ 5230c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabelSize" 5231c58f1c22SToby Isaac /*@C 5232c58f1c22SToby Isaac DMGetLabelSize - Get the number of different integer ids in a Label 5233c58f1c22SToby Isaac 5234c58f1c22SToby Isaac Not Collective 5235c58f1c22SToby Isaac 5236c58f1c22SToby Isaac Input Parameters: 5237c58f1c22SToby Isaac + dm - The DM object 5238c58f1c22SToby Isaac - name - The label name 5239c58f1c22SToby Isaac 5240c58f1c22SToby Isaac Output Parameter: 5241c58f1c22SToby Isaac . size - The number of different integer ids, or 0 if the label does not exist 5242c58f1c22SToby Isaac 5243c58f1c22SToby Isaac Level: beginner 5244c58f1c22SToby Isaac 5245c58f1c22SToby Isaac .keywords: mesh 5246c58f1c22SToby Isaac .seealso: DMLabeGetNumValues(), DMSetLabelValue() 5247c58f1c22SToby Isaac @*/ 5248c58f1c22SToby Isaac PetscErrorCode DMGetLabelSize(DM dm, const char name[], PetscInt *size) 5249c58f1c22SToby Isaac { 5250c58f1c22SToby Isaac DMLabel label; 5251c58f1c22SToby Isaac PetscErrorCode ierr; 5252c58f1c22SToby Isaac 5253c58f1c22SToby Isaac PetscFunctionBegin; 5254c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5255c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5256c58f1c22SToby Isaac PetscValidPointer(size, 3); 5257c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5258c58f1c22SToby Isaac *size = 0; 5259c58f1c22SToby Isaac if (!label) PetscFunctionReturn(0); 5260c58f1c22SToby Isaac ierr = DMLabelGetNumValues(label, size);CHKERRQ(ierr); 5261c58f1c22SToby Isaac PetscFunctionReturn(0); 5262c58f1c22SToby Isaac } 5263c58f1c22SToby Isaac 5264c58f1c22SToby Isaac #undef __FUNCT__ 5265c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabelIdIS" 5266c58f1c22SToby Isaac /*@C 5267c58f1c22SToby Isaac DMGetLabelIdIS - Get the integer ids in a label 5268c58f1c22SToby Isaac 5269c58f1c22SToby Isaac Not Collective 5270c58f1c22SToby Isaac 5271c58f1c22SToby Isaac Input Parameters: 5272c58f1c22SToby Isaac + mesh - The DM object 5273c58f1c22SToby Isaac - name - The label name 5274c58f1c22SToby Isaac 5275c58f1c22SToby Isaac Output Parameter: 5276c58f1c22SToby Isaac . ids - The integer ids, or NULL if the label does not exist 5277c58f1c22SToby Isaac 5278c58f1c22SToby Isaac Level: beginner 5279c58f1c22SToby Isaac 5280c58f1c22SToby Isaac .keywords: mesh 5281c58f1c22SToby Isaac .seealso: DMLabelGetValueIS(), DMGetLabelSize() 5282c58f1c22SToby Isaac @*/ 5283c58f1c22SToby Isaac PetscErrorCode DMGetLabelIdIS(DM dm, const char name[], IS *ids) 5284c58f1c22SToby Isaac { 5285c58f1c22SToby Isaac DMLabel label; 5286c58f1c22SToby Isaac PetscErrorCode ierr; 5287c58f1c22SToby Isaac 5288c58f1c22SToby Isaac PetscFunctionBegin; 5289c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5290c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5291c58f1c22SToby Isaac PetscValidPointer(ids, 3); 5292c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5293c58f1c22SToby Isaac *ids = NULL; 5294c58f1c22SToby Isaac if (!label) PetscFunctionReturn(0); 5295c58f1c22SToby Isaac ierr = DMLabelGetValueIS(label, ids);CHKERRQ(ierr); 5296c58f1c22SToby Isaac PetscFunctionReturn(0); 5297c58f1c22SToby Isaac } 5298c58f1c22SToby Isaac 5299c58f1c22SToby Isaac #undef __FUNCT__ 5300c58f1c22SToby Isaac #define __FUNCT__ "DMGetStratumSize" 5301c58f1c22SToby Isaac /*@C 5302c58f1c22SToby Isaac DMGetStratumSize - Get the number of points in a label stratum 5303c58f1c22SToby Isaac 5304c58f1c22SToby Isaac Not Collective 5305c58f1c22SToby Isaac 5306c58f1c22SToby Isaac Input Parameters: 5307c58f1c22SToby Isaac + dm - The DM object 5308c58f1c22SToby Isaac . name - The label name 5309c58f1c22SToby Isaac - value - The stratum value 5310c58f1c22SToby Isaac 5311c58f1c22SToby Isaac Output Parameter: 5312c58f1c22SToby Isaac . size - The stratum size 5313c58f1c22SToby Isaac 5314c58f1c22SToby Isaac Level: beginner 5315c58f1c22SToby Isaac 5316c58f1c22SToby Isaac .keywords: mesh 5317c58f1c22SToby Isaac .seealso: DMLabelGetStratumSize(), DMGetLabelSize(), DMGetLabelIds() 5318c58f1c22SToby Isaac @*/ 5319c58f1c22SToby Isaac PetscErrorCode DMGetStratumSize(DM dm, const char name[], PetscInt value, PetscInt *size) 5320c58f1c22SToby Isaac { 5321c58f1c22SToby Isaac DMLabel label; 5322c58f1c22SToby Isaac PetscErrorCode ierr; 5323c58f1c22SToby Isaac 5324c58f1c22SToby Isaac PetscFunctionBegin; 5325c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5326c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5327c58f1c22SToby Isaac PetscValidPointer(size, 4); 5328c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5329c58f1c22SToby Isaac *size = 0; 5330c58f1c22SToby Isaac if (!label) PetscFunctionReturn(0); 5331c58f1c22SToby Isaac ierr = DMLabelGetStratumSize(label, value, size);CHKERRQ(ierr); 5332c58f1c22SToby Isaac PetscFunctionReturn(0); 5333c58f1c22SToby Isaac } 5334c58f1c22SToby Isaac 5335c58f1c22SToby Isaac #undef __FUNCT__ 5336c58f1c22SToby Isaac #define __FUNCT__ "DMGetStratumIS" 5337c58f1c22SToby Isaac /*@C 5338c58f1c22SToby Isaac DMGetStratumIS - Get the points in a label stratum 5339c58f1c22SToby Isaac 5340c58f1c22SToby Isaac Not Collective 5341c58f1c22SToby Isaac 5342c58f1c22SToby Isaac Input Parameters: 5343c58f1c22SToby Isaac + dm - The DM object 5344c58f1c22SToby Isaac . name - The label name 5345c58f1c22SToby Isaac - value - The stratum value 5346c58f1c22SToby Isaac 5347c58f1c22SToby Isaac Output Parameter: 5348c58f1c22SToby Isaac . points - The stratum points, or NULL if the label does not exist or does not have that value 5349c58f1c22SToby Isaac 5350c58f1c22SToby Isaac Level: beginner 5351c58f1c22SToby Isaac 5352c58f1c22SToby Isaac .keywords: mesh 5353c58f1c22SToby Isaac .seealso: DMLabelGetStratumIS(), DMGetStratumSize() 5354c58f1c22SToby Isaac @*/ 5355c58f1c22SToby Isaac PetscErrorCode DMGetStratumIS(DM dm, const char name[], PetscInt value, IS *points) 5356c58f1c22SToby Isaac { 5357c58f1c22SToby Isaac DMLabel label; 5358c58f1c22SToby Isaac PetscErrorCode ierr; 5359c58f1c22SToby Isaac 5360c58f1c22SToby Isaac PetscFunctionBegin; 5361c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5362c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5363c58f1c22SToby Isaac PetscValidPointer(points, 4); 5364c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5365c58f1c22SToby Isaac *points = NULL; 5366c58f1c22SToby Isaac if (!label) PetscFunctionReturn(0); 5367c58f1c22SToby Isaac ierr = DMLabelGetStratumIS(label, value, points);CHKERRQ(ierr); 5368c58f1c22SToby Isaac PetscFunctionReturn(0); 5369c58f1c22SToby Isaac } 5370c58f1c22SToby Isaac 5371c58f1c22SToby Isaac #undef __FUNCT__ 5372c58f1c22SToby Isaac #define __FUNCT__ "DMClearLabelStratum" 5373c58f1c22SToby Isaac /*@C 5374c58f1c22SToby Isaac DMClearLabelStratum - Remove all points from a stratum from a Sieve Label 5375c58f1c22SToby Isaac 5376c58f1c22SToby Isaac Not Collective 5377c58f1c22SToby Isaac 5378c58f1c22SToby Isaac Input Parameters: 5379c58f1c22SToby Isaac + dm - The DM object 5380c58f1c22SToby Isaac . name - The label name 5381c58f1c22SToby Isaac - value - The label value for this point 5382c58f1c22SToby Isaac 5383c58f1c22SToby Isaac Output Parameter: 5384c58f1c22SToby Isaac 5385c58f1c22SToby Isaac Level: beginner 5386c58f1c22SToby Isaac 5387c58f1c22SToby Isaac .keywords: mesh 5388c58f1c22SToby Isaac .seealso: DMLabelClearStratum(), DMSetLabelValue(), DMGetStratumIS(), DMClearLabelValue() 5389c58f1c22SToby Isaac @*/ 5390c58f1c22SToby Isaac PetscErrorCode DMClearLabelStratum(DM dm, const char name[], PetscInt value) 5391c58f1c22SToby Isaac { 5392c58f1c22SToby Isaac DMLabel label; 5393c58f1c22SToby Isaac PetscErrorCode ierr; 5394c58f1c22SToby Isaac 5395c58f1c22SToby Isaac PetscFunctionBegin; 5396c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5397c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5398c58f1c22SToby Isaac ierr = DMGetLabel(dm, name, &label);CHKERRQ(ierr); 5399c58f1c22SToby Isaac if (!label) PetscFunctionReturn(0); 5400c58f1c22SToby Isaac ierr = DMLabelClearStratum(label, value);CHKERRQ(ierr); 5401c58f1c22SToby Isaac PetscFunctionReturn(0); 5402c58f1c22SToby Isaac } 5403c58f1c22SToby Isaac 5404c58f1c22SToby Isaac #undef __FUNCT__ 5405c58f1c22SToby Isaac #define __FUNCT__ "DMGetNumLabels" 5406c58f1c22SToby Isaac /*@ 5407c58f1c22SToby Isaac DMGetNumLabels - Return the number of labels defined by the mesh 5408c58f1c22SToby Isaac 5409c58f1c22SToby Isaac Not Collective 5410c58f1c22SToby Isaac 5411c58f1c22SToby Isaac Input Parameter: 5412c58f1c22SToby Isaac . dm - The DM object 5413c58f1c22SToby Isaac 5414c58f1c22SToby Isaac Output Parameter: 5415c58f1c22SToby Isaac . numLabels - the number of Labels 5416c58f1c22SToby Isaac 5417c58f1c22SToby Isaac Level: intermediate 5418c58f1c22SToby Isaac 5419c58f1c22SToby Isaac .keywords: mesh 5420c58f1c22SToby Isaac .seealso: DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5421c58f1c22SToby Isaac @*/ 5422c58f1c22SToby Isaac PetscErrorCode DMGetNumLabels(DM dm, PetscInt *numLabels) 5423c58f1c22SToby Isaac { 5424c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5425c58f1c22SToby Isaac PetscInt n = 0; 5426c58f1c22SToby Isaac 5427c58f1c22SToby Isaac PetscFunctionBegin; 5428c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5429c58f1c22SToby Isaac PetscValidPointer(numLabels, 2); 5430c58f1c22SToby Isaac while (next) {++n; next = next->next;} 5431c58f1c22SToby Isaac *numLabels = n; 5432c58f1c22SToby Isaac PetscFunctionReturn(0); 5433c58f1c22SToby Isaac } 5434c58f1c22SToby Isaac 5435c58f1c22SToby Isaac #undef __FUNCT__ 5436c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabelName" 5437c58f1c22SToby Isaac /*@C 5438c58f1c22SToby Isaac DMGetLabelName - Return the name of nth label 5439c58f1c22SToby Isaac 5440c58f1c22SToby Isaac Not Collective 5441c58f1c22SToby Isaac 5442c58f1c22SToby Isaac Input Parameters: 5443c58f1c22SToby Isaac + dm - The DM object 5444c58f1c22SToby Isaac - n - the label number 5445c58f1c22SToby Isaac 5446c58f1c22SToby Isaac Output Parameter: 5447c58f1c22SToby Isaac . name - the label name 5448c58f1c22SToby Isaac 5449c58f1c22SToby Isaac Level: intermediate 5450c58f1c22SToby Isaac 5451c58f1c22SToby Isaac .keywords: mesh 5452c58f1c22SToby Isaac .seealso: DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5453c58f1c22SToby Isaac @*/ 5454c58f1c22SToby Isaac PetscErrorCode DMGetLabelName(DM dm, PetscInt n, const char **name) 5455c58f1c22SToby Isaac { 5456c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5457c58f1c22SToby Isaac PetscInt l = 0; 5458c58f1c22SToby Isaac 5459c58f1c22SToby Isaac PetscFunctionBegin; 5460c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5461c58f1c22SToby Isaac PetscValidPointer(name, 3); 5462c58f1c22SToby Isaac while (next) { 5463c58f1c22SToby Isaac if (l == n) { 5464c58f1c22SToby Isaac *name = next->label->name; 5465c58f1c22SToby Isaac PetscFunctionReturn(0); 5466c58f1c22SToby Isaac } 5467c58f1c22SToby Isaac ++l; 5468c58f1c22SToby Isaac next = next->next; 5469c58f1c22SToby Isaac } 5470c58f1c22SToby Isaac SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Label %D does not exist in this DM", n); 5471c58f1c22SToby Isaac } 5472c58f1c22SToby Isaac 5473c58f1c22SToby Isaac #undef __FUNCT__ 5474c58f1c22SToby Isaac #define __FUNCT__ "DMHasLabel" 5475c58f1c22SToby Isaac /*@C 5476c58f1c22SToby Isaac DMHasLabel - Determine whether the mesh has a label of a given name 5477c58f1c22SToby Isaac 5478c58f1c22SToby Isaac Not Collective 5479c58f1c22SToby Isaac 5480c58f1c22SToby Isaac Input Parameters: 5481c58f1c22SToby Isaac + dm - The DM object 5482c58f1c22SToby Isaac - name - The label name 5483c58f1c22SToby Isaac 5484c58f1c22SToby Isaac Output Parameter: 5485c58f1c22SToby Isaac . hasLabel - PETSC_TRUE if the label is present 5486c58f1c22SToby Isaac 5487c58f1c22SToby Isaac Level: intermediate 5488c58f1c22SToby Isaac 5489c58f1c22SToby Isaac .keywords: mesh 5490c58f1c22SToby Isaac .seealso: DMCreateLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5491c58f1c22SToby Isaac @*/ 5492c58f1c22SToby Isaac PetscErrorCode DMHasLabel(DM dm, const char name[], PetscBool *hasLabel) 5493c58f1c22SToby Isaac { 5494c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5495c58f1c22SToby Isaac PetscErrorCode ierr; 5496c58f1c22SToby Isaac 5497c58f1c22SToby Isaac PetscFunctionBegin; 5498c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5499c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5500c58f1c22SToby Isaac PetscValidPointer(hasLabel, 3); 5501c58f1c22SToby Isaac *hasLabel = PETSC_FALSE; 5502c58f1c22SToby Isaac while (next) { 5503c58f1c22SToby Isaac ierr = PetscStrcmp(name, next->label->name, hasLabel);CHKERRQ(ierr); 5504c58f1c22SToby Isaac if (*hasLabel) break; 5505c58f1c22SToby Isaac next = next->next; 5506c58f1c22SToby Isaac } 5507c58f1c22SToby Isaac PetscFunctionReturn(0); 5508c58f1c22SToby Isaac } 5509c58f1c22SToby Isaac 5510c58f1c22SToby Isaac #undef __FUNCT__ 5511c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabel" 5512c58f1c22SToby Isaac /*@C 5513c58f1c22SToby Isaac DMGetLabel - Return the label of a given name, or NULL 5514c58f1c22SToby Isaac 5515c58f1c22SToby Isaac Not Collective 5516c58f1c22SToby Isaac 5517c58f1c22SToby Isaac Input Parameters: 5518c58f1c22SToby Isaac + dm - The DM object 5519c58f1c22SToby Isaac - name - The label name 5520c58f1c22SToby Isaac 5521c58f1c22SToby Isaac Output Parameter: 5522c58f1c22SToby Isaac . label - The DMLabel, or NULL if the label is absent 5523c58f1c22SToby Isaac 5524c58f1c22SToby Isaac Level: intermediate 5525c58f1c22SToby Isaac 5526c58f1c22SToby Isaac .keywords: mesh 5527c58f1c22SToby Isaac .seealso: DMCreateLabel(), DMHasLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5528c58f1c22SToby Isaac @*/ 5529c58f1c22SToby Isaac PetscErrorCode DMGetLabel(DM dm, const char name[], DMLabel *label) 5530c58f1c22SToby Isaac { 5531c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5532c58f1c22SToby Isaac PetscBool hasLabel; 5533c58f1c22SToby Isaac PetscErrorCode ierr; 5534c58f1c22SToby Isaac 5535c58f1c22SToby Isaac PetscFunctionBegin; 5536c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5537c58f1c22SToby Isaac PetscValidCharPointer(name, 2); 5538c58f1c22SToby Isaac PetscValidPointer(label, 3); 5539c58f1c22SToby Isaac *label = NULL; 5540c58f1c22SToby Isaac while (next) { 5541c58f1c22SToby Isaac ierr = PetscStrcmp(name, next->label->name, &hasLabel);CHKERRQ(ierr); 5542c58f1c22SToby Isaac if (hasLabel) { 5543c58f1c22SToby Isaac *label = next->label; 5544c58f1c22SToby Isaac break; 5545c58f1c22SToby Isaac } 5546c58f1c22SToby Isaac next = next->next; 5547c58f1c22SToby Isaac } 5548c58f1c22SToby Isaac PetscFunctionReturn(0); 5549c58f1c22SToby Isaac } 5550c58f1c22SToby Isaac 5551c58f1c22SToby Isaac #undef __FUNCT__ 5552c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabelByNum" 5553c58f1c22SToby Isaac /*@C 5554c58f1c22SToby Isaac DMGetLabelByNum - Return the nth label 5555c58f1c22SToby Isaac 5556c58f1c22SToby Isaac Not Collective 5557c58f1c22SToby Isaac 5558c58f1c22SToby Isaac Input Parameters: 5559c58f1c22SToby Isaac + dm - The DM object 5560c58f1c22SToby Isaac - n - the label number 5561c58f1c22SToby Isaac 5562c58f1c22SToby Isaac Output Parameter: 5563c58f1c22SToby Isaac . label - the label 5564c58f1c22SToby Isaac 5565c58f1c22SToby Isaac Level: intermediate 5566c58f1c22SToby Isaac 5567c58f1c22SToby Isaac .keywords: mesh 5568c58f1c22SToby Isaac .seealso: DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5569c58f1c22SToby Isaac @*/ 5570c58f1c22SToby Isaac PetscErrorCode DMGetLabelByNum(DM dm, PetscInt n, DMLabel *label) 5571c58f1c22SToby Isaac { 5572c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5573c58f1c22SToby Isaac PetscInt l = 0; 5574c58f1c22SToby Isaac 5575c58f1c22SToby Isaac PetscFunctionBegin; 5576c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5577c58f1c22SToby Isaac PetscValidPointer(label, 3); 5578c58f1c22SToby Isaac while (next) { 5579c58f1c22SToby Isaac if (l == n) { 5580c58f1c22SToby Isaac *label = next->label; 5581c58f1c22SToby Isaac PetscFunctionReturn(0); 5582c58f1c22SToby Isaac } 5583c58f1c22SToby Isaac ++l; 5584c58f1c22SToby Isaac next = next->next; 5585c58f1c22SToby Isaac } 5586c58f1c22SToby Isaac SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Label %D does not exist in this DM", n); 5587c58f1c22SToby Isaac } 5588c58f1c22SToby Isaac 5589c58f1c22SToby Isaac #undef __FUNCT__ 5590c58f1c22SToby Isaac #define __FUNCT__ "DMAddLabel" 5591c58f1c22SToby Isaac /*@C 5592c58f1c22SToby Isaac DMAddLabel - Add the label to this mesh 5593c58f1c22SToby Isaac 5594c58f1c22SToby Isaac Not Collective 5595c58f1c22SToby Isaac 5596c58f1c22SToby Isaac Input Parameters: 5597c58f1c22SToby Isaac + dm - The DM object 5598c58f1c22SToby Isaac - label - The DMLabel 5599c58f1c22SToby Isaac 5600c58f1c22SToby Isaac Level: developer 5601c58f1c22SToby Isaac 5602c58f1c22SToby Isaac .keywords: mesh 5603c58f1c22SToby Isaac .seealso: DMCreateLabel(), DMHasLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5604c58f1c22SToby Isaac @*/ 5605c58f1c22SToby Isaac PetscErrorCode DMAddLabel(DM dm, DMLabel label) 5606c58f1c22SToby Isaac { 5607c58f1c22SToby Isaac DMLabelLink tmpLabel; 5608c58f1c22SToby Isaac PetscBool hasLabel; 5609c58f1c22SToby Isaac PetscErrorCode ierr; 5610c58f1c22SToby Isaac 5611c58f1c22SToby Isaac PetscFunctionBegin; 5612c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5613c58f1c22SToby Isaac ierr = DMHasLabel(dm, label->name, &hasLabel);CHKERRQ(ierr); 5614c58f1c22SToby Isaac if (hasLabel) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Label %s already exists in this DM", label->name); 5615c58f1c22SToby Isaac ierr = PetscCalloc1(1, &tmpLabel);CHKERRQ(ierr); 5616c58f1c22SToby Isaac tmpLabel->label = label; 5617c58f1c22SToby Isaac tmpLabel->output = PETSC_TRUE; 5618c58f1c22SToby Isaac tmpLabel->next = dm->labels->next; 5619c58f1c22SToby Isaac dm->labels->next = tmpLabel; 5620c58f1c22SToby Isaac PetscFunctionReturn(0); 5621c58f1c22SToby Isaac } 5622c58f1c22SToby Isaac 5623c58f1c22SToby Isaac #undef __FUNCT__ 5624c58f1c22SToby Isaac #define __FUNCT__ "DMRemoveLabel" 5625c58f1c22SToby Isaac /*@C 5626c58f1c22SToby Isaac DMRemoveLabel - Remove the label from this mesh 5627c58f1c22SToby Isaac 5628c58f1c22SToby Isaac Not Collective 5629c58f1c22SToby Isaac 5630c58f1c22SToby Isaac Input Parameters: 5631c58f1c22SToby Isaac + dm - The DM object 5632c58f1c22SToby Isaac - name - The label name 5633c58f1c22SToby Isaac 5634c58f1c22SToby Isaac Output Parameter: 5635c58f1c22SToby Isaac . label - The DMLabel, or NULL if the label is absent 5636c58f1c22SToby Isaac 5637c58f1c22SToby Isaac Level: developer 5638c58f1c22SToby Isaac 5639c58f1c22SToby Isaac .keywords: mesh 5640c58f1c22SToby Isaac .seealso: DMCreateLabel(), DMHasLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5641c58f1c22SToby Isaac @*/ 5642c58f1c22SToby Isaac PetscErrorCode DMRemoveLabel(DM dm, const char name[], DMLabel *label) 5643c58f1c22SToby Isaac { 5644c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5645c58f1c22SToby Isaac DMLabelLink last = NULL; 5646c58f1c22SToby Isaac PetscBool hasLabel; 5647c58f1c22SToby Isaac PetscErrorCode ierr; 5648c58f1c22SToby Isaac 5649c58f1c22SToby Isaac PetscFunctionBegin; 5650c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5651c58f1c22SToby Isaac ierr = DMHasLabel(dm, name, &hasLabel);CHKERRQ(ierr); 5652c58f1c22SToby Isaac *label = NULL; 5653c58f1c22SToby Isaac if (!hasLabel) PetscFunctionReturn(0); 5654c58f1c22SToby Isaac while (next) { 5655c58f1c22SToby Isaac ierr = PetscStrcmp(name, next->label->name, &hasLabel);CHKERRQ(ierr); 5656c58f1c22SToby Isaac if (hasLabel) { 5657c58f1c22SToby Isaac if (last) last->next = next->next; 5658c58f1c22SToby Isaac else dm->labels->next = next->next; 5659c58f1c22SToby Isaac next->next = NULL; 5660c58f1c22SToby Isaac *label = next->label; 5661c58f1c22SToby Isaac ierr = PetscStrcmp(name, "depth", &hasLabel);CHKERRQ(ierr); 5662c58f1c22SToby Isaac if (hasLabel) { 5663c58f1c22SToby Isaac dm->depthLabel = NULL; 5664c58f1c22SToby Isaac } 5665c58f1c22SToby Isaac ierr = PetscFree(next);CHKERRQ(ierr); 5666c58f1c22SToby Isaac break; 5667c58f1c22SToby Isaac } 5668c58f1c22SToby Isaac last = next; 5669c58f1c22SToby Isaac next = next->next; 5670c58f1c22SToby Isaac } 5671c58f1c22SToby Isaac PetscFunctionReturn(0); 5672c58f1c22SToby Isaac } 5673c58f1c22SToby Isaac 5674c58f1c22SToby Isaac #undef __FUNCT__ 5675c58f1c22SToby Isaac #define __FUNCT__ "DMGetLabelOutput" 5676c58f1c22SToby Isaac /*@C 5677c58f1c22SToby Isaac DMGetLabelOutput - Get the output flag for a given label 5678c58f1c22SToby Isaac 5679c58f1c22SToby Isaac Not Collective 5680c58f1c22SToby Isaac 5681c58f1c22SToby Isaac Input Parameters: 5682c58f1c22SToby Isaac + dm - The DM object 5683c58f1c22SToby Isaac - name - The label name 5684c58f1c22SToby Isaac 5685c58f1c22SToby Isaac Output Parameter: 5686c58f1c22SToby Isaac . output - The flag for output 5687c58f1c22SToby Isaac 5688c58f1c22SToby Isaac Level: developer 5689c58f1c22SToby Isaac 5690c58f1c22SToby Isaac .keywords: mesh 5691c58f1c22SToby Isaac .seealso: DMSetLabelOutput(), DMCreateLabel(), DMHasLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5692c58f1c22SToby Isaac @*/ 5693c58f1c22SToby Isaac PetscErrorCode DMGetLabelOutput(DM dm, const char name[], PetscBool *output) 5694c58f1c22SToby Isaac { 5695c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5696c58f1c22SToby Isaac PetscErrorCode ierr; 5697c58f1c22SToby Isaac 5698c58f1c22SToby Isaac PetscFunctionBegin; 5699c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5700c58f1c22SToby Isaac PetscValidPointer(name, 2); 5701c58f1c22SToby Isaac PetscValidPointer(output, 3); 5702c58f1c22SToby Isaac while (next) { 5703c58f1c22SToby Isaac PetscBool flg; 5704c58f1c22SToby Isaac 5705c58f1c22SToby Isaac ierr = PetscStrcmp(name, next->label->name, &flg);CHKERRQ(ierr); 5706c58f1c22SToby Isaac if (flg) {*output = next->output; PetscFunctionReturn(0);} 5707c58f1c22SToby Isaac next = next->next; 5708c58f1c22SToby Isaac } 5709c58f1c22SToby Isaac SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "No label named %s was present in this dm", name); 5710c58f1c22SToby Isaac } 5711c58f1c22SToby Isaac 5712c58f1c22SToby Isaac #undef __FUNCT__ 5713c58f1c22SToby Isaac #define __FUNCT__ "DMSetLabelOutput" 5714c58f1c22SToby Isaac /*@C 5715c58f1c22SToby Isaac DMSetLabelOutput - Set the output flag for a given label 5716c58f1c22SToby Isaac 5717c58f1c22SToby Isaac Not Collective 5718c58f1c22SToby Isaac 5719c58f1c22SToby Isaac Input Parameters: 5720c58f1c22SToby Isaac + dm - The DM object 5721c58f1c22SToby Isaac . name - The label name 5722c58f1c22SToby Isaac - output - The flag for output 5723c58f1c22SToby Isaac 5724c58f1c22SToby Isaac Level: developer 5725c58f1c22SToby Isaac 5726c58f1c22SToby Isaac .keywords: mesh 5727c58f1c22SToby Isaac .seealso: DMGetLabelOutput(), DMCreateLabel(), DMHasLabel(), DMGetLabelValue(), DMSetLabelValue(), DMGetStratumIS() 5728c58f1c22SToby Isaac @*/ 5729c58f1c22SToby Isaac PetscErrorCode DMSetLabelOutput(DM dm, const char name[], PetscBool output) 5730c58f1c22SToby Isaac { 5731c58f1c22SToby Isaac DMLabelLink next = dm->labels->next; 5732c58f1c22SToby Isaac PetscErrorCode ierr; 5733c58f1c22SToby Isaac 5734c58f1c22SToby Isaac PetscFunctionBegin; 5735c58f1c22SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5736c58f1c22SToby Isaac PetscValidPointer(name, 2); 5737c58f1c22SToby Isaac while (next) { 5738c58f1c22SToby Isaac PetscBool flg; 5739c58f1c22SToby Isaac 5740c58f1c22SToby Isaac ierr = PetscStrcmp(name, next->label->name, &flg);CHKERRQ(ierr); 5741c58f1c22SToby Isaac if (flg) {next->output = output; PetscFunctionReturn(0);} 5742c58f1c22SToby Isaac next = next->next; 5743c58f1c22SToby Isaac } 5744c58f1c22SToby Isaac SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "No label named %s was present in this dm", name); 5745c58f1c22SToby Isaac } 5746c58f1c22SToby Isaac 5747c58f1c22SToby Isaac 5748c58f1c22SToby Isaac #undef __FUNCT__ 5749c58f1c22SToby Isaac #define __FUNCT__ "DMCopyLabels" 5750c58f1c22SToby Isaac /*@ 5751c58f1c22SToby Isaac DMCopyLabels - Copy labels from one mesh to another with a superset of the points 5752c58f1c22SToby Isaac 5753c58f1c22SToby Isaac Collective on DM 5754c58f1c22SToby Isaac 5755c58f1c22SToby Isaac Input Parameter: 57562e17dfb7SMatthew G. Knepley . dmA - The DM object with initial labels 5757c58f1c22SToby Isaac 5758c58f1c22SToby Isaac Output Parameter: 57592e17dfb7SMatthew G. Knepley . dmB - The DM object with copied labels 5760c58f1c22SToby Isaac 5761c58f1c22SToby Isaac Level: intermediate 5762c58f1c22SToby Isaac 5763c58f1c22SToby Isaac Note: This is typically used when interpolating or otherwise adding to a mesh 5764c58f1c22SToby Isaac 5765c58f1c22SToby Isaac .keywords: mesh 5766c58f1c22SToby Isaac .seealso: DMCopyCoordinates(), DMGetCoordinates(), DMGetCoordinatesLocal(), DMGetCoordinateDM(), DMGetCoordinateSection() 5767c58f1c22SToby Isaac @*/ 5768c58f1c22SToby Isaac PetscErrorCode DMCopyLabels(DM dmA, DM dmB) 5769c58f1c22SToby Isaac { 5770c58f1c22SToby Isaac PetscInt numLabels, l; 5771c58f1c22SToby Isaac PetscErrorCode ierr; 5772c58f1c22SToby Isaac 5773c58f1c22SToby Isaac PetscFunctionBegin; 5774c58f1c22SToby Isaac if (dmA == dmB) PetscFunctionReturn(0); 5775c58f1c22SToby Isaac ierr = DMGetNumLabels(dmA, &numLabels);CHKERRQ(ierr); 5776c58f1c22SToby Isaac for (l = 0; l < numLabels; ++l) { 5777c58f1c22SToby Isaac DMLabel label, labelNew; 5778c58f1c22SToby Isaac const char *name; 5779c58f1c22SToby Isaac PetscBool flg; 5780c58f1c22SToby Isaac 5781c58f1c22SToby Isaac ierr = DMGetLabelName(dmA, l, &name);CHKERRQ(ierr); 5782c58f1c22SToby Isaac ierr = PetscStrcmp(name, "depth", &flg);CHKERRQ(ierr); 5783c58f1c22SToby Isaac if (flg) continue; 5784c58f1c22SToby Isaac ierr = DMGetLabel(dmA, name, &label);CHKERRQ(ierr); 5785c58f1c22SToby Isaac ierr = DMLabelDuplicate(label, &labelNew);CHKERRQ(ierr); 5786c58f1c22SToby Isaac ierr = DMAddLabel(dmB, labelNew);CHKERRQ(ierr); 5787c58f1c22SToby Isaac } 5788c58f1c22SToby Isaac PetscFunctionReturn(0); 5789c58f1c22SToby Isaac } 5790a8fb8f29SToby Isaac 5791a8fb8f29SToby Isaac #undef __FUNCT__ 5792a8fb8f29SToby Isaac #define __FUNCT__ "DMGetCoarseDM" 5793a8fb8f29SToby Isaac /*@ 5794a8fb8f29SToby Isaac DMGetCoarseDM - Get the coarse mesh from which this was obtained by refinement 5795a8fb8f29SToby Isaac 5796a8fb8f29SToby Isaac Input Parameter: 5797a8fb8f29SToby Isaac . dm - The DM object 5798a8fb8f29SToby Isaac 5799a8fb8f29SToby Isaac Output Parameter: 5800a8fb8f29SToby Isaac . cdm - The coarse DM 5801a8fb8f29SToby Isaac 5802a8fb8f29SToby Isaac Level: intermediate 5803a8fb8f29SToby Isaac 5804a8fb8f29SToby Isaac .seealso: DMSetCoarseDM() 5805a8fb8f29SToby Isaac @*/ 5806a8fb8f29SToby Isaac PetscErrorCode DMGetCoarseDM(DM dm, DM *cdm) 5807a8fb8f29SToby Isaac { 5808a8fb8f29SToby Isaac PetscFunctionBegin; 5809a8fb8f29SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5810a8fb8f29SToby Isaac PetscValidPointer(cdm, 2); 5811a8fb8f29SToby Isaac *cdm = dm->coarseMesh; 5812a8fb8f29SToby Isaac PetscFunctionReturn(0); 5813a8fb8f29SToby Isaac } 5814a8fb8f29SToby Isaac 5815a8fb8f29SToby Isaac #undef __FUNCT__ 5816a8fb8f29SToby Isaac #define __FUNCT__ "DMSetCoarseDM" 5817a8fb8f29SToby Isaac /*@ 5818a8fb8f29SToby Isaac DMSetCoarseDM - Set the coarse mesh from which this was obtained by refinement 5819a8fb8f29SToby Isaac 5820a8fb8f29SToby Isaac Input Parameters: 5821a8fb8f29SToby Isaac + dm - The DM object 5822a8fb8f29SToby Isaac - cdm - The coarse DM 5823a8fb8f29SToby Isaac 5824a8fb8f29SToby Isaac Level: intermediate 5825a8fb8f29SToby Isaac 5826a8fb8f29SToby Isaac .seealso: DMGetCoarseDM() 5827a8fb8f29SToby Isaac @*/ 5828a8fb8f29SToby Isaac PetscErrorCode DMSetCoarseDM(DM dm, DM cdm) 5829a8fb8f29SToby Isaac { 5830a8fb8f29SToby Isaac PetscErrorCode ierr; 5831a8fb8f29SToby Isaac 5832a8fb8f29SToby Isaac PetscFunctionBegin; 5833a8fb8f29SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 5834a8fb8f29SToby Isaac if (cdm) PetscValidHeaderSpecific(cdm, DM_CLASSID, 2); 5835a8fb8f29SToby Isaac ierr = PetscObjectReference((PetscObject)cdm);CHKERRQ(ierr); 5836a8fb8f29SToby Isaac ierr = DMDestroy(&dm->coarseMesh);CHKERRQ(ierr); 5837a8fb8f29SToby Isaac dm->coarseMesh = cdm; 5838a8fb8f29SToby Isaac PetscFunctionReturn(0); 5839a8fb8f29SToby Isaac } 5840a8fb8f29SToby Isaac 584188bdff64SToby Isaac #undef __FUNCT__ 584288bdff64SToby Isaac #define __FUNCT__ "DMGetFineDM" 584388bdff64SToby Isaac /*@ 584488bdff64SToby Isaac DMGetFineDM - Get the fine mesh from which this was obtained by refinement 584588bdff64SToby Isaac 584688bdff64SToby Isaac Input Parameter: 584788bdff64SToby Isaac . dm - The DM object 584888bdff64SToby Isaac 584988bdff64SToby Isaac Output Parameter: 585088bdff64SToby Isaac . fdm - The fine DM 585188bdff64SToby Isaac 585288bdff64SToby Isaac Level: intermediate 585388bdff64SToby Isaac 585488bdff64SToby Isaac .seealso: DMSetFineDM() 585588bdff64SToby Isaac @*/ 585688bdff64SToby Isaac PetscErrorCode DMGetFineDM(DM dm, DM *fdm) 585788bdff64SToby Isaac { 585888bdff64SToby Isaac PetscFunctionBegin; 585988bdff64SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 586088bdff64SToby Isaac PetscValidPointer(fdm, 2); 586188bdff64SToby Isaac *fdm = dm->fineMesh; 586288bdff64SToby Isaac PetscFunctionReturn(0); 586388bdff64SToby Isaac } 586488bdff64SToby Isaac 586588bdff64SToby Isaac #undef __FUNCT__ 586688bdff64SToby Isaac #define __FUNCT__ "DMSetFineDM" 586788bdff64SToby Isaac /*@ 586888bdff64SToby Isaac DMSetFineDM - Set the fine mesh from which this was obtained by refinement 586988bdff64SToby Isaac 587088bdff64SToby Isaac Input Parameters: 587188bdff64SToby Isaac + dm - The DM object 587288bdff64SToby Isaac - fdm - The fine DM 587388bdff64SToby Isaac 587488bdff64SToby Isaac Level: intermediate 587588bdff64SToby Isaac 587688bdff64SToby Isaac .seealso: DMGetFineDM() 587788bdff64SToby Isaac @*/ 587888bdff64SToby Isaac PetscErrorCode DMSetFineDM(DM dm, DM fdm) 587988bdff64SToby Isaac { 588088bdff64SToby Isaac PetscErrorCode ierr; 588188bdff64SToby Isaac 588288bdff64SToby Isaac PetscFunctionBegin; 588388bdff64SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 588488bdff64SToby Isaac if (fdm) PetscValidHeaderSpecific(fdm, DM_CLASSID, 2); 588588bdff64SToby Isaac ierr = PetscObjectReference((PetscObject)fdm);CHKERRQ(ierr); 588688bdff64SToby Isaac ierr = DMDestroy(&dm->fineMesh);CHKERRQ(ierr); 588788bdff64SToby Isaac dm->fineMesh = fdm; 588888bdff64SToby Isaac PetscFunctionReturn(0); 588988bdff64SToby Isaac } 589088bdff64SToby Isaac 5891a6ba4734SToby Isaac /*=== DMBoundary code ===*/ 5892a6ba4734SToby Isaac 5893a6ba4734SToby Isaac #undef __FUNCT__ 5894bcc5ffd9SToby Isaac #define __FUNCT__ "DMBoundaryDuplicate" 5895354557abSToby Isaac PetscErrorCode DMBoundaryDuplicate(DMBoundaryLinkList bd, DMBoundaryLinkList *boundary) 5896a6ba4734SToby Isaac { 5897bcc5ffd9SToby Isaac DMBoundary b = bd->next, b2, bold = NULL; 5898a6ba4734SToby Isaac PetscErrorCode ierr; 5899a6ba4734SToby Isaac 5900a6ba4734SToby Isaac PetscFunctionBegin; 5901bcc5ffd9SToby Isaac ierr = PetscNew(boundary);CHKERRQ(ierr); 5902bcc5ffd9SToby Isaac (*boundary)->refct = 1; 5903bcc5ffd9SToby Isaac (*boundary)->next = NULL; 5904a6ba4734SToby Isaac for (; b; b = b->next, bold = b2) { 5905a6ba4734SToby Isaac ierr = PetscNew(&b2);CHKERRQ(ierr); 5906a6ba4734SToby Isaac ierr = PetscStrallocpy(b->name, (char **) &b2->name);CHKERRQ(ierr); 5907a6ba4734SToby Isaac ierr = PetscStrallocpy(b->labelname, (char **) &b2->labelname);CHKERRQ(ierr); 5908a6ba4734SToby Isaac ierr = PetscMalloc1(b->numids, &b2->ids);CHKERRQ(ierr); 5909a6ba4734SToby Isaac ierr = PetscMemcpy(b2->ids, b->ids, b->numids*sizeof(PetscInt));CHKERRQ(ierr); 5910a6ba4734SToby Isaac ierr = PetscMalloc1(b->numcomps, &b2->comps);CHKERRQ(ierr); 5911a6ba4734SToby Isaac ierr = PetscMemcpy(b2->comps, b->comps, b->numcomps*sizeof(PetscInt));CHKERRQ(ierr); 5912a6ba4734SToby Isaac b2->label = NULL; 5913a6ba4734SToby Isaac b2->essential = b->essential; 5914a6ba4734SToby Isaac b2->field = b->field; 5915a6ba4734SToby Isaac b2->numcomps = b->numcomps; 5916a6ba4734SToby Isaac b2->func = b->func; 5917a6ba4734SToby Isaac b2->numids = b->numids; 5918a6ba4734SToby Isaac b2->ctx = b->ctx; 5919a6ba4734SToby Isaac b2->next = NULL; 5920bcc5ffd9SToby Isaac if (!(*boundary)->next) (*boundary)->next = b2; 5921a6ba4734SToby Isaac if (bold) bold->next = b2; 5922a6ba4734SToby Isaac } 5923a6ba4734SToby Isaac PetscFunctionReturn(0); 5924a6ba4734SToby Isaac } 5925a6ba4734SToby Isaac 5926a6ba4734SToby Isaac #undef __FUNCT__ 5927bcc5ffd9SToby Isaac #define __FUNCT__ "DMBoundaryDestroy" 5928bcc5ffd9SToby Isaac PetscErrorCode DMBoundaryDestroy(DMBoundaryLinkList *boundary) 5929a6ba4734SToby Isaac { 5930a6ba4734SToby Isaac DMBoundary b, next; 5931a6ba4734SToby Isaac PetscErrorCode ierr; 5932a6ba4734SToby Isaac 5933a6ba4734SToby Isaac PetscFunctionBegin; 5934a6ba4734SToby Isaac if (!boundary) PetscFunctionReturn(0); 5935bcc5ffd9SToby Isaac if (--((*boundary)->refct)) { 5936a6ba4734SToby Isaac *boundary = NULL; 5937bcc5ffd9SToby Isaac PetscFunctionReturn(0); 5938bcc5ffd9SToby Isaac } 5939bcc5ffd9SToby Isaac b = (*boundary)->next; 5940a6ba4734SToby Isaac for (; b; b = next) { 5941a6ba4734SToby Isaac next = b->next; 5942a6ba4734SToby Isaac ierr = PetscFree(b->comps);CHKERRQ(ierr); 5943a6ba4734SToby Isaac ierr = PetscFree(b->ids);CHKERRQ(ierr); 5944a6ba4734SToby Isaac ierr = PetscFree(b->name);CHKERRQ(ierr); 5945a6ba4734SToby Isaac ierr = PetscFree(b->labelname);CHKERRQ(ierr); 5946a6ba4734SToby Isaac ierr = PetscFree(b);CHKERRQ(ierr); 5947a6ba4734SToby Isaac } 5948bcc5ffd9SToby Isaac ierr = PetscFree(*boundary);CHKERRQ(ierr); 5949a6ba4734SToby Isaac PetscFunctionReturn(0); 5950a6ba4734SToby Isaac } 5951a6ba4734SToby Isaac 5952a6ba4734SToby Isaac #undef __FUNCT__ 5953a6ba4734SToby Isaac #define __FUNCT__ "DMCopyBoundary" 5954a6ba4734SToby Isaac PetscErrorCode DMCopyBoundary(DM dm, DM dmNew) 5955a6ba4734SToby Isaac { 5956a6ba4734SToby Isaac DMBoundary b; 5957a6ba4734SToby Isaac PetscErrorCode ierr; 5958a6ba4734SToby Isaac 5959a6ba4734SToby Isaac PetscFunctionBegin; 5960bcc5ffd9SToby Isaac ierr = DMBoundaryDestroy(&dmNew->boundary);CHKERRQ(ierr); 5961bcc5ffd9SToby Isaac ierr = DMBoundaryDuplicate(dm->boundary, &dmNew->boundary);CHKERRQ(ierr); 5962bcc5ffd9SToby Isaac for (b = dmNew->boundary->next; b; b = b->next) { 5963a6ba4734SToby Isaac if (b->labelname) { 5964a6ba4734SToby Isaac ierr = DMGetLabel(dmNew, b->labelname, &b->label);CHKERRQ(ierr); 5965a6ba4734SToby Isaac if (!b->label) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Label %s does not exist in this DM", b->labelname); 5966a6ba4734SToby Isaac } 5967a6ba4734SToby Isaac } 5968a6ba4734SToby Isaac PetscFunctionReturn(0); 5969a6ba4734SToby Isaac } 5970a6ba4734SToby Isaac 5971a6ba4734SToby Isaac #undef __FUNCT__ 5972a6ba4734SToby Isaac #define __FUNCT__ "DMAddBoundary" 5973a6ba4734SToby Isaac /*@C 5974a6ba4734SToby Isaac DMAddBoundary - Add a boundary condition to the model 5975a6ba4734SToby Isaac 5976a6ba4734SToby Isaac Input Parameters: 5977a6ba4734SToby Isaac + dm - The mesh object 5978a6ba4734SToby Isaac . isEssential - Flag for an essential (Dirichlet) condition, as opposed to a natural (Neumann) condition 5979a6ba4734SToby Isaac . name - The BC name 5980a6ba4734SToby Isaac . labelname - The label defining constrained points 5981a6ba4734SToby Isaac . field - The field to constrain 5982a6ba4734SToby Isaac . numcomps - The number of constrained field components 5983a6ba4734SToby Isaac . comps - An array of constrained component numbers 5984a6ba4734SToby Isaac . bcFunc - A pointwise function giving boundary values 5985a6ba4734SToby Isaac . numids - The number of DMLabel ids for constrained points 5986a6ba4734SToby Isaac . ids - An array of ids for constrained points 5987a6ba4734SToby Isaac - ctx - An optional user context for bcFunc 5988a6ba4734SToby Isaac 5989a6ba4734SToby Isaac Options Database Keys: 5990a6ba4734SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 5991a6ba4734SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 5992a6ba4734SToby Isaac 5993a6ba4734SToby Isaac Level: developer 5994a6ba4734SToby Isaac 5995a6ba4734SToby Isaac .seealso: DMGetBoundary() 5996a6ba4734SToby Isaac @*/ 5997a6ba4734SToby 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) 5998a6ba4734SToby Isaac { 5999a6ba4734SToby Isaac DMBoundary b; 6000a6ba4734SToby Isaac PetscErrorCode ierr; 6001a6ba4734SToby Isaac 6002a6ba4734SToby Isaac PetscFunctionBegin; 6003a6ba4734SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6004a6ba4734SToby Isaac ierr = PetscNew(&b);CHKERRQ(ierr); 6005a6ba4734SToby Isaac ierr = PetscStrallocpy(name, (char **) &b->name);CHKERRQ(ierr); 6006a6ba4734SToby Isaac ierr = PetscStrallocpy(labelname, (char **) &b->labelname);CHKERRQ(ierr); 6007a6ba4734SToby Isaac ierr = PetscMalloc1(numcomps, &b->comps);CHKERRQ(ierr); 6008a6ba4734SToby Isaac if (numcomps) {ierr = PetscMemcpy(b->comps, comps, numcomps*sizeof(PetscInt));CHKERRQ(ierr);} 6009a6ba4734SToby Isaac ierr = PetscMalloc1(numids, &b->ids);CHKERRQ(ierr); 6010a6ba4734SToby Isaac if (numids) {ierr = PetscMemcpy(b->ids, ids, numids*sizeof(PetscInt));CHKERRQ(ierr);} 6011a6ba4734SToby Isaac if (b->labelname) { 6012a6ba4734SToby Isaac ierr = DMGetLabel(dm, b->labelname, &b->label);CHKERRQ(ierr); 6013a6ba4734SToby Isaac if (!b->label) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Label %s does not exist in this DM", b->labelname); 6014a6ba4734SToby Isaac } 6015a6ba4734SToby Isaac b->essential = isEssential; 6016a6ba4734SToby Isaac b->field = field; 6017a6ba4734SToby Isaac b->numcomps = numcomps; 6018a6ba4734SToby Isaac b->func = bcFunc; 6019a6ba4734SToby Isaac b->numids = numids; 6020a6ba4734SToby Isaac b->ctx = ctx; 6021bcc5ffd9SToby Isaac b->next = dm->boundary->next; 6022bcc5ffd9SToby Isaac dm->boundary->next = b; 6023a6ba4734SToby Isaac PetscFunctionReturn(0); 6024a6ba4734SToby Isaac } 6025a6ba4734SToby Isaac 6026a6ba4734SToby Isaac #undef __FUNCT__ 6027a6ba4734SToby Isaac #define __FUNCT__ "DMGetNumBoundary" 6028a6ba4734SToby Isaac /*@ 6029a6ba4734SToby Isaac DMGetNumBoundary - Get the number of registered BC 6030a6ba4734SToby Isaac 6031a6ba4734SToby Isaac Input Parameters: 6032a6ba4734SToby Isaac . dm - The mesh object 6033a6ba4734SToby Isaac 6034a6ba4734SToby Isaac Output Parameters: 6035a6ba4734SToby Isaac . numBd - The number of BC 6036a6ba4734SToby Isaac 6037a6ba4734SToby Isaac Level: intermediate 6038a6ba4734SToby Isaac 6039a6ba4734SToby Isaac .seealso: DMAddBoundary(), DMGetBoundary() 6040a6ba4734SToby Isaac @*/ 6041a6ba4734SToby Isaac PetscErrorCode DMGetNumBoundary(DM dm, PetscInt *numBd) 6042a6ba4734SToby Isaac { 6043bcc5ffd9SToby Isaac DMBoundary b = dm->boundary->next; 6044a6ba4734SToby Isaac 6045a6ba4734SToby Isaac PetscFunctionBegin; 6046a6ba4734SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6047a6ba4734SToby Isaac PetscValidPointer(numBd, 2); 6048a6ba4734SToby Isaac *numBd = 0; 6049a6ba4734SToby Isaac while (b) {++(*numBd); b = b->next;} 6050a6ba4734SToby Isaac PetscFunctionReturn(0); 6051a6ba4734SToby Isaac } 6052a6ba4734SToby Isaac 6053a6ba4734SToby Isaac #undef __FUNCT__ 6054a6ba4734SToby Isaac #define __FUNCT__ "DMGetBoundary" 6055a6ba4734SToby Isaac /*@C 6056a6ba4734SToby Isaac DMGetBoundary - Add a boundary condition to the model 6057a6ba4734SToby Isaac 6058a6ba4734SToby Isaac Input Parameters: 6059a6ba4734SToby Isaac + dm - The mesh object 6060a6ba4734SToby Isaac - bd - The BC number 6061a6ba4734SToby Isaac 6062a6ba4734SToby Isaac Output Parameters: 6063a6ba4734SToby Isaac + isEssential - Flag for an essential (Dirichlet) condition, as opposed to a natural (Neumann) condition 6064a6ba4734SToby Isaac . name - The BC name 6065a6ba4734SToby Isaac . labelname - The label defining constrained points 6066a6ba4734SToby Isaac . field - The field to constrain 6067a6ba4734SToby Isaac . numcomps - The number of constrained field components 6068a6ba4734SToby Isaac . comps - An array of constrained component numbers 6069a6ba4734SToby Isaac . bcFunc - A pointwise function giving boundary values 6070a6ba4734SToby Isaac . numids - The number of DMLabel ids for constrained points 6071a6ba4734SToby Isaac . ids - An array of ids for constrained points 6072a6ba4734SToby Isaac - ctx - An optional user context for bcFunc 6073a6ba4734SToby Isaac 6074a6ba4734SToby Isaac Options Database Keys: 6075a6ba4734SToby Isaac + -bc_<boundary name> <num> - Overrides the boundary ids 6076a6ba4734SToby Isaac - -bc_<boundary name>_comp <num> - Overrides the boundary components 6077a6ba4734SToby Isaac 6078a6ba4734SToby Isaac Level: developer 6079a6ba4734SToby Isaac 6080a6ba4734SToby Isaac .seealso: DMAddBoundary() 6081a6ba4734SToby Isaac @*/ 6082a6ba4734SToby 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) 6083a6ba4734SToby Isaac { 6084bcc5ffd9SToby Isaac DMBoundary b = dm->boundary->next; 6085a6ba4734SToby Isaac PetscInt n = 0; 6086a6ba4734SToby Isaac 6087a6ba4734SToby Isaac PetscFunctionBegin; 6088a6ba4734SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6089a6ba4734SToby Isaac while (b) { 6090a6ba4734SToby Isaac if (n == bd) break; 6091a6ba4734SToby Isaac b = b->next; 6092a6ba4734SToby Isaac ++n; 6093a6ba4734SToby Isaac } 60949fc93327SToby Isaac if (!b) SETERRQ2(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Boundary %d is not in [0, %d)", bd, n); 6095a6ba4734SToby Isaac if (isEssential) { 6096a6ba4734SToby Isaac PetscValidPointer(isEssential, 3); 6097a6ba4734SToby Isaac *isEssential = b->essential; 6098a6ba4734SToby Isaac } 6099a6ba4734SToby Isaac if (name) { 6100a6ba4734SToby Isaac PetscValidPointer(name, 4); 6101a6ba4734SToby Isaac *name = b->name; 6102a6ba4734SToby Isaac } 6103a6ba4734SToby Isaac if (labelname) { 6104a6ba4734SToby Isaac PetscValidPointer(labelname, 5); 6105a6ba4734SToby Isaac *labelname = b->labelname; 6106a6ba4734SToby Isaac } 6107a6ba4734SToby Isaac if (field) { 6108a6ba4734SToby Isaac PetscValidPointer(field, 6); 6109a6ba4734SToby Isaac *field = b->field; 6110a6ba4734SToby Isaac } 6111a6ba4734SToby Isaac if (numcomps) { 6112a6ba4734SToby Isaac PetscValidPointer(numcomps, 7); 6113a6ba4734SToby Isaac *numcomps = b->numcomps; 6114a6ba4734SToby Isaac } 6115a6ba4734SToby Isaac if (comps) { 6116a6ba4734SToby Isaac PetscValidPointer(comps, 8); 6117a6ba4734SToby Isaac *comps = b->comps; 6118a6ba4734SToby Isaac } 6119a6ba4734SToby Isaac if (func) { 6120a6ba4734SToby Isaac PetscValidPointer(func, 9); 6121a6ba4734SToby Isaac *func = b->func; 6122a6ba4734SToby Isaac } 6123a6ba4734SToby Isaac if (numids) { 6124a6ba4734SToby Isaac PetscValidPointer(numids, 10); 6125a6ba4734SToby Isaac *numids = b->numids; 6126a6ba4734SToby Isaac } 6127a6ba4734SToby Isaac if (ids) { 6128a6ba4734SToby Isaac PetscValidPointer(ids, 11); 6129a6ba4734SToby Isaac *ids = b->ids; 6130a6ba4734SToby Isaac } 6131a6ba4734SToby Isaac if (ctx) { 6132a6ba4734SToby Isaac PetscValidPointer(ctx, 12); 6133a6ba4734SToby Isaac *ctx = b->ctx; 6134a6ba4734SToby Isaac } 6135a6ba4734SToby Isaac PetscFunctionReturn(0); 6136a6ba4734SToby Isaac } 6137a6ba4734SToby Isaac 6138a6ba4734SToby Isaac #undef __FUNCT__ 6139a6ba4734SToby Isaac #define __FUNCT__ "DMIsBoundaryPoint" 6140a6ba4734SToby Isaac PetscErrorCode DMIsBoundaryPoint(DM dm, PetscInt point, PetscBool *isBd) 6141a6ba4734SToby Isaac { 6142bcc5ffd9SToby Isaac DMBoundary b = dm->boundary->next; 6143a6ba4734SToby Isaac PetscErrorCode ierr; 6144a6ba4734SToby Isaac 6145a6ba4734SToby Isaac PetscFunctionBegin; 6146a6ba4734SToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 6147a6ba4734SToby Isaac PetscValidPointer(isBd, 3); 6148a6ba4734SToby Isaac *isBd = PETSC_FALSE; 6149a6ba4734SToby Isaac while (b && !(*isBd)) { 6150a6ba4734SToby Isaac if (b->label) { 6151a6ba4734SToby Isaac PetscInt i; 6152a6ba4734SToby Isaac 6153a6ba4734SToby Isaac for (i = 0; i < b->numids && !(*isBd); ++i) { 6154a6ba4734SToby Isaac ierr = DMLabelStratumHasPoint(b->label, b->ids[i], point, isBd);CHKERRQ(ierr); 6155a6ba4734SToby Isaac } 6156a6ba4734SToby Isaac } 6157a6ba4734SToby Isaac b = b->next; 6158a6ba4734SToby Isaac } 6159a6ba4734SToby Isaac PetscFunctionReturn(0); 6160a6ba4734SToby Isaac } 61614d6f44ffSToby Isaac 61624d6f44ffSToby Isaac #undef __FUNCT__ 61634d6f44ffSToby Isaac #define __FUNCT__ "DMProjectFunction" 61644d6f44ffSToby Isaac /*@C 61654d6f44ffSToby Isaac DMProjectFunction - This projects the given function into the function space provided. 61664d6f44ffSToby Isaac 61674d6f44ffSToby Isaac Input Parameters: 61684d6f44ffSToby Isaac + dm - The DM 61690709b2feSToby Isaac . time - The time 61704d6f44ffSToby Isaac . funcs - The coordinate functions to evaluate, one per field 61714d6f44ffSToby Isaac . ctxs - Optional array of contexts to pass to each coordinate function. ctxs itself may be null. 61724d6f44ffSToby Isaac - mode - The insertion mode for values 61734d6f44ffSToby Isaac 61744d6f44ffSToby Isaac Output Parameter: 61754d6f44ffSToby Isaac . X - vector 61764d6f44ffSToby Isaac 61774d6f44ffSToby Isaac Calling sequence of func: 61780709b2feSToby Isaac $ func(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nf, PetscScalar u[], void *ctx); 61794d6f44ffSToby Isaac 61804d6f44ffSToby Isaac + dim - The spatial dimension 61814d6f44ffSToby Isaac . x - The coordinates 61824d6f44ffSToby Isaac . Nf - The number of fields 61834d6f44ffSToby Isaac . u - The output field values 61844d6f44ffSToby Isaac - ctx - optional user-defined function context 61854d6f44ffSToby Isaac 61864d6f44ffSToby Isaac Level: developer 61874d6f44ffSToby Isaac 61882716604bSToby Isaac .seealso: DMComputeL2Diff() 61894d6f44ffSToby Isaac @*/ 61900709b2feSToby Isaac PetscErrorCode DMProjectFunction(DM dm, PetscReal time, PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void **ctxs, InsertMode mode, Vec X) 61914d6f44ffSToby Isaac { 61924d6f44ffSToby Isaac Vec localX; 61934d6f44ffSToby Isaac PetscErrorCode ierr; 61944d6f44ffSToby Isaac 61954d6f44ffSToby Isaac PetscFunctionBegin; 61964d6f44ffSToby Isaac PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 61974d6f44ffSToby Isaac ierr = DMGetLocalVector(dm, &localX);CHKERRQ(ierr); 61980709b2feSToby Isaac ierr = DMProjectFunctionLocal(dm, time, funcs, ctxs, mode, localX);CHKERRQ(ierr); 61994d6f44ffSToby Isaac ierr = DMLocalToGlobalBegin(dm, localX, mode, X);CHKERRQ(ierr); 62004d6f44ffSToby Isaac ierr = DMLocalToGlobalEnd(dm, localX, mode, X);CHKERRQ(ierr); 62014d6f44ffSToby Isaac ierr = DMRestoreLocalVector(dm, &localX);CHKERRQ(ierr); 62024d6f44ffSToby Isaac PetscFunctionReturn(0); 62034d6f44ffSToby Isaac } 62044d6f44ffSToby Isaac 62054d6f44ffSToby Isaac #undef __FUNCT__ 62064d6f44ffSToby Isaac #define __FUNCT__ "DMProjectFunctionLocal" 62070709b2feSToby Isaac PetscErrorCode DMProjectFunctionLocal(DM dm, PetscReal time, PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void **ctxs, InsertMode mode, Vec localX) 62084d6f44ffSToby Isaac { 62094d6f44ffSToby Isaac PetscErrorCode ierr; 62104d6f44ffSToby Isaac 62114d6f44ffSToby Isaac PetscFunctionBegin; 62124d6f44ffSToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 62134d6f44ffSToby Isaac PetscValidHeaderSpecific(localX,VEC_CLASSID,5); 62144d6f44ffSToby Isaac if (!dm->ops->projectfunctionlocal) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM type %s does not implemnt DMProjectFunctionLocal",((PetscObject)dm)->type_name); 62150709b2feSToby Isaac ierr = (dm->ops->projectfunctionlocal) (dm, time, funcs, ctxs, mode, localX);CHKERRQ(ierr); 62164d6f44ffSToby Isaac PetscFunctionReturn(0); 62174d6f44ffSToby Isaac } 62184d6f44ffSToby Isaac 62194d6f44ffSToby Isaac #undef __FUNCT__ 6220bfc4295aSToby Isaac #define __FUNCT__ "DMProjectFieldLocal" 6221bfc4295aSToby Isaac PetscErrorCode DMProjectFieldLocal(DM dm, Vec localU, 6222bfc4295aSToby Isaac void (**funcs)(PetscInt, PetscInt, PetscInt, 6223bfc4295aSToby Isaac const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], 6224bfc4295aSToby Isaac const PetscInt[], const PetscInt[], const PetscScalar[], const PetscScalar[], const PetscScalar[], 6225bfc4295aSToby Isaac PetscReal, const PetscReal[], PetscScalar[]), 6226bfc4295aSToby Isaac InsertMode mode, Vec localX) 6227bfc4295aSToby Isaac { 6228bfc4295aSToby Isaac PetscErrorCode ierr; 6229bfc4295aSToby Isaac 6230bfc4295aSToby Isaac PetscFunctionBegin; 6231bfc4295aSToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6232bfc4295aSToby Isaac PetscValidHeaderSpecific(localU,VEC_CLASSID,2); 6233bfc4295aSToby Isaac PetscValidHeaderSpecific(localX,VEC_CLASSID,5); 6234bfc4295aSToby Isaac if (!dm->ops->projectfieldlocal) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM type %s does not implemnt DMProjectFieldLocal",((PetscObject)dm)->type_name); 6235bfc4295aSToby Isaac ierr = (dm->ops->projectfieldlocal) (dm, localU, funcs, mode, localX);CHKERRQ(ierr); 6236bfc4295aSToby Isaac PetscFunctionReturn(0); 6237bfc4295aSToby Isaac } 6238bfc4295aSToby Isaac 6239bfc4295aSToby Isaac #undef __FUNCT__ 62404d6f44ffSToby Isaac #define __FUNCT__ "DMProjectFunctionLabelLocal" 62410709b2feSToby 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) 62424d6f44ffSToby Isaac { 62434d6f44ffSToby Isaac PetscErrorCode ierr; 62444d6f44ffSToby Isaac 62454d6f44ffSToby Isaac PetscFunctionBegin; 62464d6f44ffSToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 62474d6f44ffSToby Isaac PetscValidHeaderSpecific(localX,VEC_CLASSID,5); 62484d6f44ffSToby Isaac if (!dm->ops->projectfunctionlabellocal) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM type %s does not implemnt DMProjectFunctionLabelLocal",((PetscObject)dm)->type_name); 62490709b2feSToby Isaac ierr = (dm->ops->projectfunctionlabellocal) (dm, time, label, numIds, ids, funcs, ctxs, mode, localX);CHKERRQ(ierr); 62504d6f44ffSToby Isaac PetscFunctionReturn(0); 62514d6f44ffSToby Isaac } 62522716604bSToby Isaac 62532716604bSToby Isaac #undef __FUNCT__ 62542716604bSToby Isaac #define __FUNCT__ "DMComputeL2Diff" 62552716604bSToby Isaac /*@C 62562716604bSToby Isaac DMComputeL2Diff - This function computes the L_2 difference between a function u and an FEM interpolant solution u_h. 62572716604bSToby Isaac 62582716604bSToby Isaac Input Parameters: 62592716604bSToby Isaac + dm - The DM 62600709b2feSToby Isaac . time - The time 62612716604bSToby Isaac . funcs - The functions to evaluate for each field component 62622716604bSToby Isaac . ctxs - Optional array of contexts to pass to each function, or NULL. 62632716604bSToby Isaac - X - The coefficient vector u_h 62642716604bSToby Isaac 62652716604bSToby Isaac Output Parameter: 62662716604bSToby Isaac . diff - The diff ||u - u_h||_2 62672716604bSToby Isaac 62682716604bSToby Isaac Level: developer 62692716604bSToby Isaac 62701189c1efSToby Isaac .seealso: DMProjectFunction(), DMComputeL2FieldDiff(), DMComputeL2GradientDiff() 62712716604bSToby Isaac @*/ 62720709b2feSToby Isaac PetscErrorCode DMComputeL2Diff(DM dm, PetscReal time, PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void **ctxs, Vec X, PetscReal *diff) 62732716604bSToby Isaac { 62742716604bSToby Isaac PetscErrorCode ierr; 62752716604bSToby Isaac 62762716604bSToby Isaac PetscFunctionBegin; 62772716604bSToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6278b698f381SToby Isaac PetscValidHeaderSpecific(X,VEC_CLASSID,5); 62792716604bSToby Isaac if (!dm->ops->computel2diff) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM type %s does not implemnt DMComputeL2Diff",((PetscObject)dm)->type_name); 62800709b2feSToby Isaac ierr = (dm->ops->computel2diff)(dm,time,funcs,ctxs,X,diff);CHKERRQ(ierr); 62812716604bSToby Isaac PetscFunctionReturn(0); 62822716604bSToby Isaac } 6283b698f381SToby Isaac 6284b698f381SToby Isaac #undef __FUNCT__ 6285b698f381SToby Isaac #define __FUNCT__ "DMComputeL2GradientDiff" 6286b698f381SToby Isaac /*@C 6287b698f381SToby Isaac DMComputeL2GradientDiff - This function computes the L_2 difference between the gradient of a function u and an FEM interpolant solution grad u_h. 6288b698f381SToby Isaac 6289b698f381SToby Isaac Input Parameters: 6290b698f381SToby Isaac + dm - The DM 6291b698f381SToby Isaac , time - The time 6292b698f381SToby Isaac . funcs - The gradient functions to evaluate for each field component 6293b698f381SToby Isaac . ctxs - Optional array of contexts to pass to each function, or NULL. 6294b698f381SToby Isaac . X - The coefficient vector u_h 6295b698f381SToby Isaac - n - The vector to project along 6296b698f381SToby Isaac 6297b698f381SToby Isaac Output Parameter: 6298b698f381SToby Isaac . diff - The diff ||(grad u - grad u_h) . n||_2 6299b698f381SToby Isaac 6300b698f381SToby Isaac Level: developer 6301b698f381SToby Isaac 6302b698f381SToby Isaac .seealso: DMProjectFunction(), DMComputeL2Diff() 6303b698f381SToby Isaac @*/ 6304b698f381SToby 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) 6305b698f381SToby Isaac { 6306b698f381SToby Isaac PetscErrorCode ierr; 6307b698f381SToby Isaac 6308b698f381SToby Isaac PetscFunctionBegin; 6309b698f381SToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6310b698f381SToby Isaac PetscValidHeaderSpecific(X,VEC_CLASSID,5); 6311b698f381SToby Isaac if (!dm->ops->computel2gradientdiff) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM type %s does not implement DMComputeL2GradientDiff",((PetscObject)dm)->type_name); 6312b698f381SToby Isaac ierr = (dm->ops->computel2gradientdiff)(dm,time,funcs,ctxs,X,n,diff);CHKERRQ(ierr); 6313b698f381SToby Isaac PetscFunctionReturn(0); 6314b698f381SToby Isaac } 6315b698f381SToby Isaac 63162a16baeaSToby Isaac #undef __FUNCT__ 63172a16baeaSToby Isaac #define __FUNCT__ "DMComputeL2FieldDiff" 63182a16baeaSToby Isaac /*@C 63192a16baeaSToby Isaac DMComputeL2FieldDiff - This function computes the L_2 difference between a function u and an FEM interpolant solution u_h, separated into field components. 63202a16baeaSToby Isaac 63212a16baeaSToby Isaac Input Parameters: 63222a16baeaSToby Isaac + dm - The DM 63232a16baeaSToby Isaac . time - The time 63242a16baeaSToby Isaac . funcs - The functions to evaluate for each field component 63252a16baeaSToby Isaac . ctxs - Optional array of contexts to pass to each function, or NULL. 63262a16baeaSToby Isaac - X - The coefficient vector u_h 63272a16baeaSToby Isaac 63282a16baeaSToby Isaac Output Parameter: 63292a16baeaSToby Isaac . diff - The array of differences, ||u^f - u^f_h||_2 63302a16baeaSToby Isaac 63312a16baeaSToby Isaac Level: developer 63322a16baeaSToby Isaac 63331189c1efSToby Isaac .seealso: DMProjectFunction(), DMComputeL2FieldDiff(), DMComputeL2GradientDiff() 63342a16baeaSToby Isaac @*/ 63351189c1efSToby Isaac PetscErrorCode DMComputeL2FieldDiff(DM dm, PetscReal time, PetscErrorCode (**funcs)(PetscInt, PetscReal, const PetscReal [], PetscInt, PetscScalar *, void *), void **ctxs, Vec X, PetscReal diff[]) 63362a16baeaSToby Isaac { 63372a16baeaSToby Isaac PetscErrorCode ierr; 63382a16baeaSToby Isaac 63392a16baeaSToby Isaac PetscFunctionBegin; 63402a16baeaSToby Isaac PetscValidHeaderSpecific(dm,DM_CLASSID,1); 63412a16baeaSToby Isaac PetscValidHeaderSpecific(X,VEC_CLASSID,5); 63422a16baeaSToby Isaac if (!dm->ops->computel2fielddiff) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM type %s does not implemnt DMComputeL2FieldDiff",((PetscObject)dm)->type_name); 63432a16baeaSToby Isaac ierr = (dm->ops->computel2fielddiff)(dm,time,funcs,ctxs,X,diff);CHKERRQ(ierr); 63442a16baeaSToby Isaac PetscFunctionReturn(0); 63452a16baeaSToby Isaac } 63462a16baeaSToby Isaac 6347