1b45d2f2cSJed Brown #include <petsc-private/dmimpl.h> /*I "petscdm.h" I*/ 20c312b8eSJed Brown #include <petscsf.h> 32764a2aaSMatthew G. Knepley #include <petscds.h> 447c6ae99SBarry Smith 5732e2eb9SMatthew G Knepley PetscClassId DM_CLASSID; 6f089877aSRichard Tran Mills PetscLogEvent DM_Convert, DM_GlobalToLocal, DM_LocalToGlobal, DM_LocalToLocal; 767a56275SMatthew G Knepley 8bff4a2f0SMatthew G. Knepley const char *const DMBoundaryTypes[] = {"NONE","GHOSTED","MIRROR","PERIODIC","TWIST","DM_BOUNDARY_",0}; 9bff4a2f0SMatthew G. Knepley 1047c6ae99SBarry Smith #undef __FUNCT__ 11a4121054SBarry Smith #define __FUNCT__ "DMCreate" 12a4121054SBarry Smith /*@ 13de043629SMatthew G Knepley DMCreate - Creates an empty DM object. The type can then be set with DMSetType(). 14a4121054SBarry Smith 15a4121054SBarry Smith If you never call DMSetType() it will generate an 16a4121054SBarry Smith error when you try to use the vector. 17a4121054SBarry Smith 18a4121054SBarry Smith Collective on MPI_Comm 19a4121054SBarry Smith 20a4121054SBarry Smith Input Parameter: 21a4121054SBarry Smith . comm - The communicator for the DM object 22a4121054SBarry Smith 23a4121054SBarry Smith Output Parameter: 24a4121054SBarry Smith . dm - The DM object 25a4121054SBarry Smith 26a4121054SBarry Smith Level: beginner 27a4121054SBarry Smith 28a4121054SBarry Smith .seealso: DMSetType(), DMDA, DMSLICED, DMCOMPOSITE 29a4121054SBarry Smith @*/ 307087cfbeSBarry Smith PetscErrorCode DMCreate(MPI_Comm comm,DM *dm) 31a4121054SBarry Smith { 32a4121054SBarry Smith DM v; 33a4121054SBarry Smith PetscErrorCode ierr; 34a4121054SBarry Smith 35a4121054SBarry Smith PetscFunctionBegin; 361411c6eeSJed Brown PetscValidPointer(dm,2); 370298fd71SBarry Smith *dm = NULL; 388b984314SMatthew G. Knepley ierr = PetscSysInitializePackage();CHKERRQ(ierr); 39607a6623SBarry Smith ierr = VecInitializePackage();CHKERRQ(ierr); 40607a6623SBarry Smith ierr = MatInitializePackage();CHKERRQ(ierr); 41607a6623SBarry Smith ierr = DMInitializePackage();CHKERRQ(ierr); 42a4121054SBarry Smith 4367c2884eSBarry Smith ierr = PetscHeaderCreate(v, _p_DM, struct _DMOps, DM_CLASSID, "DM", "Distribution Manager", "DM", comm, DMDestroy, DMView);CHKERRQ(ierr); 44a4121054SBarry Smith ierr = PetscMemzero(v->ops, sizeof(struct _DMOps));CHKERRQ(ierr); 451411c6eeSJed Brown 46e7c4fc90SDmitry Karpeev 470298fd71SBarry Smith v->ltogmap = NULL; 481411c6eeSJed Brown v->bs = 1; 49171400e9SBarry Smith v->coloringtype = IS_COLORING_GLOBAL; 5088ed4aceSMatthew G Knepley ierr = PetscSFCreate(comm, &v->sf);CHKERRQ(ierr); 5188ed4aceSMatthew G Knepley ierr = PetscSFCreate(comm, &v->defaultSF);CHKERRQ(ierr); 520298fd71SBarry Smith v->defaultSection = NULL; 530298fd71SBarry Smith v->defaultGlobalSection = NULL; 54c6b900c6SMatthew G. Knepley v->L = NULL; 55c6b900c6SMatthew G. Knepley v->maxCell = NULL; 56435a35e8SMatthew G Knepley { 57435a35e8SMatthew G Knepley PetscInt i; 58435a35e8SMatthew G Knepley for (i = 0; i < 10; ++i) { 590298fd71SBarry Smith v->nullspaceConstructors[i] = NULL; 60435a35e8SMatthew G Knepley } 61435a35e8SMatthew G Knepley } 622764a2aaSMatthew G. Knepley ierr = PetscDSCreate(comm, &v->prob);CHKERRQ(ierr); 6314f150ffSMatthew G. Knepley v->dmBC = NULL; 64f4d763aaSMatthew G. Knepley v->outputSequenceNum = -1; 65cdb7a50dSMatthew G. Knepley v->outputSequenceVal = 0.0; 66c0dedaeaSBarry Smith ierr = DMSetVecType(v,VECSTANDARD);CHKERRQ(ierr); 67b412c318SBarry Smith ierr = DMSetMatType(v,MATAIJ);CHKERRQ(ierr); 681411c6eeSJed Brown *dm = v; 69a4121054SBarry Smith PetscFunctionReturn(0); 70a4121054SBarry Smith } 71a4121054SBarry Smith 72a4121054SBarry Smith #undef __FUNCT__ 7338221697SMatthew G. Knepley #define __FUNCT__ "DMClone" 7438221697SMatthew G. Knepley /*@ 7538221697SMatthew G. Knepley DMClone - Creates a DM object with the same topology as the original. 7638221697SMatthew G. Knepley 7738221697SMatthew G. Knepley Collective on MPI_Comm 7838221697SMatthew G. Knepley 7938221697SMatthew G. Knepley Input Parameter: 8038221697SMatthew G. Knepley . dm - The original DM object 8138221697SMatthew G. Knepley 8238221697SMatthew G. Knepley Output Parameter: 8338221697SMatthew G. Knepley . newdm - The new DM object 8438221697SMatthew G. Knepley 8538221697SMatthew G. Knepley Level: beginner 8638221697SMatthew G. Knepley 8738221697SMatthew G. Knepley .keywords: DM, topology, create 8838221697SMatthew G. Knepley @*/ 8938221697SMatthew G. Knepley PetscErrorCode DMClone(DM dm, DM *newdm) 9038221697SMatthew G. Knepley { 9138221697SMatthew G. Knepley PetscSF sf; 9238221697SMatthew G. Knepley Vec coords; 9338221697SMatthew G. Knepley void *ctx; 9438221697SMatthew G. Knepley PetscErrorCode ierr; 9538221697SMatthew G. Knepley 9638221697SMatthew G. Knepley PetscFunctionBegin; 9738221697SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 9838221697SMatthew G. Knepley PetscValidPointer(newdm,2); 9938221697SMatthew G. Knepley ierr = DMCreate(PetscObjectComm((PetscObject)dm), newdm);CHKERRQ(ierr); 10038221697SMatthew G. Knepley if (dm->ops->clone) { 10138221697SMatthew G. Knepley ierr = (*dm->ops->clone)(dm, newdm);CHKERRQ(ierr); 10238221697SMatthew G. Knepley } 103cd27c7c9SMatthew G. Knepley (*newdm)->setupcalled = PETSC_TRUE; 10438221697SMatthew G. Knepley ierr = DMGetPointSF(dm, &sf);CHKERRQ(ierr); 10538221697SMatthew G. Knepley ierr = DMSetPointSF(*newdm, sf);CHKERRQ(ierr); 10638221697SMatthew G. Knepley ierr = DMGetApplicationContext(dm, &ctx);CHKERRQ(ierr); 10738221697SMatthew G. Knepley ierr = DMSetApplicationContext(*newdm, ctx);CHKERRQ(ierr); 10838221697SMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coords);CHKERRQ(ierr); 10938221697SMatthew G. Knepley if (coords) { 11038221697SMatthew G. Knepley ierr = DMSetCoordinatesLocal(*newdm, coords);CHKERRQ(ierr); 11138221697SMatthew G. Knepley } else { 11238221697SMatthew G. Knepley ierr = DMGetCoordinates(dm, &coords);CHKERRQ(ierr); 11338221697SMatthew G. Knepley if (coords) {ierr = DMSetCoordinates(*newdm, coords);CHKERRQ(ierr);} 11438221697SMatthew G. Knepley } 115c6b900c6SMatthew G. Knepley if (dm->maxCell) { 116c6b900c6SMatthew G. Knepley const PetscReal *maxCell, *L; 117c6b900c6SMatthew G. Knepley ierr = DMGetPeriodicity(dm, &maxCell, &L);CHKERRQ(ierr); 118c6b900c6SMatthew G. Knepley ierr = DMSetPeriodicity(*newdm, maxCell, L);CHKERRQ(ierr); 119c6b900c6SMatthew G. Knepley } 12038221697SMatthew G. Knepley PetscFunctionReturn(0); 12138221697SMatthew G. Knepley } 12238221697SMatthew G. Knepley 12338221697SMatthew G. Knepley #undef __FUNCT__ 1249a42bb27SBarry Smith #define __FUNCT__ "DMSetVecType" 1259a42bb27SBarry Smith /*@C 126564755cdSBarry Smith DMSetVecType - Sets the type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() 1279a42bb27SBarry Smith 128aa219208SBarry Smith Logically Collective on DMDA 1299a42bb27SBarry Smith 1309a42bb27SBarry Smith Input Parameter: 1319a42bb27SBarry Smith + da - initial distributed array 1328154be41SBarry Smith . ctype - the vector type, currently either VECSTANDARD or VECCUSP 1339a42bb27SBarry Smith 1349a42bb27SBarry Smith Options Database: 135dd85299cSBarry Smith . -dm_vec_type ctype 1369a42bb27SBarry Smith 1379a42bb27SBarry Smith Level: intermediate 1389a42bb27SBarry Smith 139c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMDestroy(), DMDA, DMDAInterpolationType, VecType, DMGetVecType() 1409a42bb27SBarry Smith @*/ 14119fd82e9SBarry Smith PetscErrorCode DMSetVecType(DM da,VecType ctype) 1429a42bb27SBarry Smith { 1439a42bb27SBarry Smith PetscErrorCode ierr; 1449a42bb27SBarry Smith 1459a42bb27SBarry Smith PetscFunctionBegin; 1469a42bb27SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 1479a42bb27SBarry Smith ierr = PetscFree(da->vectype);CHKERRQ(ierr); 14819fd82e9SBarry Smith ierr = PetscStrallocpy(ctype,(char**)&da->vectype);CHKERRQ(ierr); 1499a42bb27SBarry Smith PetscFunctionReturn(0); 1509a42bb27SBarry Smith } 1519a42bb27SBarry Smith 1529a42bb27SBarry Smith #undef __FUNCT__ 153c0dedaeaSBarry Smith #define __FUNCT__ "DMGetVecType" 154c0dedaeaSBarry Smith /*@C 155c0dedaeaSBarry Smith DMGetVecType - Gets the type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() 156c0dedaeaSBarry Smith 157c0dedaeaSBarry Smith Logically Collective on DMDA 158c0dedaeaSBarry Smith 159c0dedaeaSBarry Smith Input Parameter: 160c0dedaeaSBarry Smith . da - initial distributed array 161c0dedaeaSBarry Smith 162c0dedaeaSBarry Smith Output Parameter: 163c0dedaeaSBarry Smith . ctype - the vector type 164c0dedaeaSBarry Smith 165c0dedaeaSBarry Smith Level: intermediate 166c0dedaeaSBarry Smith 167c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMDestroy(), DMDA, DMDAInterpolationType, VecType 168c0dedaeaSBarry Smith @*/ 169c0dedaeaSBarry Smith PetscErrorCode DMGetVecType(DM da,VecType *ctype) 170c0dedaeaSBarry Smith { 171c0dedaeaSBarry Smith PetscFunctionBegin; 172c0dedaeaSBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 173c0dedaeaSBarry Smith *ctype = da->vectype; 174c0dedaeaSBarry Smith PetscFunctionReturn(0); 175c0dedaeaSBarry Smith } 176c0dedaeaSBarry Smith 177c0dedaeaSBarry Smith #undef __FUNCT__ 1785f1ad066SMatthew G Knepley #define __FUNCT__ "VecGetDM" 1795f1ad066SMatthew G Knepley /*@ 18034f98d34SBarry Smith VecGetDM - Gets the DM defining the data layout of the vector 1815f1ad066SMatthew G Knepley 1825f1ad066SMatthew G Knepley Not collective 1835f1ad066SMatthew G Knepley 1845f1ad066SMatthew G Knepley Input Parameter: 1855f1ad066SMatthew G Knepley . v - The Vec 1865f1ad066SMatthew G Knepley 1875f1ad066SMatthew G Knepley Output Parameter: 1885f1ad066SMatthew G Knepley . dm - The DM 1895f1ad066SMatthew G Knepley 1905f1ad066SMatthew G Knepley Level: intermediate 1915f1ad066SMatthew G Knepley 1925f1ad066SMatthew G Knepley .seealso: VecSetDM(), DMGetLocalVector(), DMGetGlobalVector(), DMSetVecType() 1935f1ad066SMatthew G Knepley @*/ 1945f1ad066SMatthew G Knepley PetscErrorCode VecGetDM(Vec v, DM *dm) 1955f1ad066SMatthew G Knepley { 1965f1ad066SMatthew G Knepley PetscErrorCode ierr; 1975f1ad066SMatthew G Knepley 1985f1ad066SMatthew G Knepley PetscFunctionBegin; 1995f1ad066SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,1); 2005f1ad066SMatthew G Knepley PetscValidPointer(dm,2); 2015f1ad066SMatthew G Knepley ierr = PetscObjectQuery((PetscObject) v, "__PETSc_dm", (PetscObject*) dm);CHKERRQ(ierr); 2025f1ad066SMatthew G Knepley PetscFunctionReturn(0); 2035f1ad066SMatthew G Knepley } 2045f1ad066SMatthew G Knepley 2055f1ad066SMatthew G Knepley #undef __FUNCT__ 2065f1ad066SMatthew G Knepley #define __FUNCT__ "VecSetDM" 2075f1ad066SMatthew G Knepley /*@ 2085f1ad066SMatthew G Knepley VecSetDM - Sets the DM defining the data layout of the vector 2095f1ad066SMatthew G Knepley 2105f1ad066SMatthew G Knepley Not collective 2115f1ad066SMatthew G Knepley 2125f1ad066SMatthew G Knepley Input Parameters: 2135f1ad066SMatthew G Knepley + v - The Vec 2145f1ad066SMatthew G Knepley - dm - The DM 2155f1ad066SMatthew G Knepley 2165f1ad066SMatthew G Knepley Level: intermediate 2175f1ad066SMatthew G Knepley 2185f1ad066SMatthew G Knepley .seealso: VecGetDM(), DMGetLocalVector(), DMGetGlobalVector(), DMSetVecType() 2195f1ad066SMatthew G Knepley @*/ 2205f1ad066SMatthew G Knepley PetscErrorCode VecSetDM(Vec v, DM dm) 2215f1ad066SMatthew G Knepley { 2225f1ad066SMatthew G Knepley PetscErrorCode ierr; 2235f1ad066SMatthew G Knepley 2245f1ad066SMatthew G Knepley PetscFunctionBegin; 2255f1ad066SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,1); 226d7f50e27SLisandro Dalcin if (dm) PetscValidHeaderSpecific(dm,DM_CLASSID,2); 2275f1ad066SMatthew G Knepley ierr = PetscObjectCompose((PetscObject) v, "__PETSc_dm", (PetscObject) dm);CHKERRQ(ierr); 2285f1ad066SMatthew G Knepley PetscFunctionReturn(0); 2295f1ad066SMatthew G Knepley } 2305f1ad066SMatthew G Knepley 2315f1ad066SMatthew G Knepley #undef __FUNCT__ 232521d9a4cSLisandro Dalcin #define __FUNCT__ "DMSetMatType" 233521d9a4cSLisandro Dalcin /*@C 234521d9a4cSLisandro Dalcin DMSetMatType - Sets the type of matrix created with DMCreateMatrix() 235521d9a4cSLisandro Dalcin 236521d9a4cSLisandro Dalcin Logically Collective on DM 237521d9a4cSLisandro Dalcin 238521d9a4cSLisandro Dalcin Input Parameter: 239521d9a4cSLisandro Dalcin + dm - the DM context 240521d9a4cSLisandro Dalcin . ctype - the matrix type 241521d9a4cSLisandro Dalcin 242521d9a4cSLisandro Dalcin Options Database: 243521d9a4cSLisandro Dalcin . -dm_mat_type ctype 244521d9a4cSLisandro Dalcin 245521d9a4cSLisandro Dalcin Level: intermediate 246521d9a4cSLisandro Dalcin 247c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateMatrix(), DMSetMatrixPreallocateOnly(), MatType, DMGetMatType() 248521d9a4cSLisandro Dalcin @*/ 24919fd82e9SBarry Smith PetscErrorCode DMSetMatType(DM dm,MatType ctype) 250521d9a4cSLisandro Dalcin { 251521d9a4cSLisandro Dalcin PetscErrorCode ierr; 25288f0584fSBarry Smith 253521d9a4cSLisandro Dalcin PetscFunctionBegin; 254521d9a4cSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 255521d9a4cSLisandro Dalcin ierr = PetscFree(dm->mattype);CHKERRQ(ierr); 25619fd82e9SBarry Smith ierr = PetscStrallocpy(ctype,(char**)&dm->mattype);CHKERRQ(ierr); 257521d9a4cSLisandro Dalcin PetscFunctionReturn(0); 258521d9a4cSLisandro Dalcin } 259521d9a4cSLisandro Dalcin 260521d9a4cSLisandro Dalcin #undef __FUNCT__ 261c0dedaeaSBarry Smith #define __FUNCT__ "DMGetMatType" 262c0dedaeaSBarry Smith /*@C 263c0dedaeaSBarry Smith DMGetMatType - Gets the type of matrix created with DMCreateMatrix() 264c0dedaeaSBarry Smith 265c0dedaeaSBarry Smith Logically Collective on DM 266c0dedaeaSBarry Smith 267c0dedaeaSBarry Smith Input Parameter: 268c0dedaeaSBarry Smith . dm - the DM context 269c0dedaeaSBarry Smith 270c0dedaeaSBarry Smith Output Parameter: 271c0dedaeaSBarry Smith . ctype - the matrix type 272c0dedaeaSBarry Smith 273c0dedaeaSBarry Smith Options Database: 274c0dedaeaSBarry Smith . -dm_mat_type ctype 275c0dedaeaSBarry Smith 276c0dedaeaSBarry Smith Level: intermediate 277c0dedaeaSBarry Smith 278c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateMatrix(), DMSetMatrixPreallocateOnly(), MatType, DMSetMatType() 279c0dedaeaSBarry Smith @*/ 280c0dedaeaSBarry Smith PetscErrorCode DMGetMatType(DM dm,MatType *ctype) 281c0dedaeaSBarry Smith { 282c0dedaeaSBarry Smith PetscFunctionBegin; 283c0dedaeaSBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 284c0dedaeaSBarry Smith *ctype = dm->mattype; 285c0dedaeaSBarry Smith PetscFunctionReturn(0); 286c0dedaeaSBarry Smith } 287c0dedaeaSBarry Smith 288c0dedaeaSBarry Smith #undef __FUNCT__ 289c688c046SMatthew G Knepley #define __FUNCT__ "MatGetDM" 290c688c046SMatthew G Knepley /*@ 29134f98d34SBarry Smith MatGetDM - Gets the DM defining the data layout of the matrix 292c688c046SMatthew G Knepley 293c688c046SMatthew G Knepley Not collective 294c688c046SMatthew G Knepley 295c688c046SMatthew G Knepley Input Parameter: 296c688c046SMatthew G Knepley . A - The Mat 297c688c046SMatthew G Knepley 298c688c046SMatthew G Knepley Output Parameter: 299c688c046SMatthew G Knepley . dm - The DM 300c688c046SMatthew G Knepley 301c688c046SMatthew G Knepley Level: intermediate 302c688c046SMatthew G Knepley 303c688c046SMatthew G Knepley .seealso: MatSetDM(), DMCreateMatrix(), DMSetMatType() 304c688c046SMatthew G Knepley @*/ 305c688c046SMatthew G Knepley PetscErrorCode MatGetDM(Mat A, DM *dm) 306c688c046SMatthew G Knepley { 307c688c046SMatthew G Knepley PetscErrorCode ierr; 308c688c046SMatthew G Knepley 309c688c046SMatthew G Knepley PetscFunctionBegin; 310c688c046SMatthew G Knepley PetscValidHeaderSpecific(A,MAT_CLASSID,1); 311c688c046SMatthew G Knepley PetscValidPointer(dm,2); 312c688c046SMatthew G Knepley ierr = PetscObjectQuery((PetscObject) A, "__PETSc_dm", (PetscObject*) dm);CHKERRQ(ierr); 313c688c046SMatthew G Knepley PetscFunctionReturn(0); 314c688c046SMatthew G Knepley } 315c688c046SMatthew G Knepley 316c688c046SMatthew G Knepley #undef __FUNCT__ 317c688c046SMatthew G Knepley #define __FUNCT__ "MatSetDM" 318c688c046SMatthew G Knepley /*@ 319c688c046SMatthew G Knepley MatSetDM - Sets the DM defining the data layout of the matrix 320c688c046SMatthew G Knepley 321c688c046SMatthew G Knepley Not collective 322c688c046SMatthew G Knepley 323c688c046SMatthew G Knepley Input Parameters: 324c688c046SMatthew G Knepley + A - The Mat 325c688c046SMatthew G Knepley - dm - The DM 326c688c046SMatthew G Knepley 327c688c046SMatthew G Knepley Level: intermediate 328c688c046SMatthew G Knepley 329c688c046SMatthew G Knepley .seealso: MatGetDM(), DMCreateMatrix(), DMSetMatType() 330c688c046SMatthew G Knepley @*/ 331c688c046SMatthew G Knepley PetscErrorCode MatSetDM(Mat A, DM dm) 332c688c046SMatthew G Knepley { 333c688c046SMatthew G Knepley PetscErrorCode ierr; 334c688c046SMatthew G Knepley 335c688c046SMatthew G Knepley PetscFunctionBegin; 336c688c046SMatthew G Knepley PetscValidHeaderSpecific(A,MAT_CLASSID,1); 3378865f1eaSKarl Rupp if (dm) PetscValidHeaderSpecific(dm,DM_CLASSID,2); 338c688c046SMatthew G Knepley ierr = PetscObjectCompose((PetscObject) A, "__PETSc_dm", (PetscObject) dm);CHKERRQ(ierr); 339c688c046SMatthew G Knepley PetscFunctionReturn(0); 340c688c046SMatthew G Knepley } 341c688c046SMatthew G Knepley 342c688c046SMatthew G Knepley #undef __FUNCT__ 3439a42bb27SBarry Smith #define __FUNCT__ "DMSetOptionsPrefix" 3449a42bb27SBarry Smith /*@C 3459a42bb27SBarry Smith DMSetOptionsPrefix - Sets the prefix used for searching for all 346aa219208SBarry Smith DMDA options in the database. 3479a42bb27SBarry Smith 348aa219208SBarry Smith Logically Collective on DMDA 3499a42bb27SBarry Smith 3509a42bb27SBarry Smith Input Parameter: 351aa219208SBarry Smith + da - the DMDA context 3529a42bb27SBarry Smith - prefix - the prefix to prepend to all option names 3539a42bb27SBarry Smith 3549a42bb27SBarry Smith Notes: 3559a42bb27SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 3569a42bb27SBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 3579a42bb27SBarry Smith 3589a42bb27SBarry Smith Level: advanced 3599a42bb27SBarry Smith 360aa219208SBarry Smith .keywords: DMDA, set, options, prefix, database 3619a42bb27SBarry Smith 3629a42bb27SBarry Smith .seealso: DMSetFromOptions() 3639a42bb27SBarry Smith @*/ 3647087cfbeSBarry Smith PetscErrorCode DMSetOptionsPrefix(DM dm,const char prefix[]) 3659a42bb27SBarry Smith { 3669a42bb27SBarry Smith PetscErrorCode ierr; 3679a42bb27SBarry Smith 3689a42bb27SBarry Smith PetscFunctionBegin; 3699a42bb27SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3709a42bb27SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)dm,prefix);CHKERRQ(ierr); 3719a42bb27SBarry Smith PetscFunctionReturn(0); 3729a42bb27SBarry Smith } 3739a42bb27SBarry Smith 3749a42bb27SBarry Smith #undef __FUNCT__ 37547c6ae99SBarry Smith #define __FUNCT__ "DMDestroy" 37647c6ae99SBarry Smith /*@ 377aa219208SBarry Smith DMDestroy - Destroys a vector packer or DMDA. 37847c6ae99SBarry Smith 37947c6ae99SBarry Smith Collective on DM 38047c6ae99SBarry Smith 38147c6ae99SBarry Smith Input Parameter: 38247c6ae99SBarry Smith . dm - the DM object to destroy 38347c6ae99SBarry Smith 38447c6ae99SBarry Smith Level: developer 38547c6ae99SBarry Smith 386e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 38747c6ae99SBarry Smith 38847c6ae99SBarry Smith @*/ 389fcfd50ebSBarry Smith PetscErrorCode DMDestroy(DM *dm) 39047c6ae99SBarry Smith { 391*c83e3748SMatthew G. Knepley PetscInt i, cnt = 0; 392dfe15315SJed Brown DMNamedVecLink nlink,nnext; 39347c6ae99SBarry Smith PetscErrorCode ierr; 39447c6ae99SBarry Smith 39547c6ae99SBarry Smith PetscFunctionBegin; 3966bf464f9SBarry Smith if (!*dm) PetscFunctionReturn(0); 3976bf464f9SBarry Smith PetscValidHeaderSpecific((*dm),DM_CLASSID,1); 39887e657c6SBarry Smith 39987e657c6SBarry Smith /* count all the circular references of DM and its contained Vecs */ 400732e2eb9SMatthew G Knepley for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 4018865f1eaSKarl Rupp if ((*dm)->localin[i]) cnt++; 4028865f1eaSKarl Rupp if ((*dm)->globalin[i]) cnt++; 403732e2eb9SMatthew G Knepley } 404dfe15315SJed Brown for (nlink=(*dm)->namedglobal; nlink; nlink=nlink->next) cnt++; 4052348bcf4SPeter Brune for (nlink=(*dm)->namedlocal; nlink; nlink=nlink->next) cnt++; 4062348bcf4SPeter Brune if ((*dm)->x) { 4072348bcf4SPeter Brune DM obj; 4082348bcf4SPeter Brune ierr = VecGetDM((*dm)->x, &obj);CHKERRQ(ierr); 4092348bcf4SPeter Brune if (obj == *dm) cnt++; 4102348bcf4SPeter Brune } 411732e2eb9SMatthew G Knepley 4126bf464f9SBarry Smith if (--((PetscObject)(*dm))->refct - cnt > 0) {*dm = 0; PetscFunctionReturn(0);} 413732e2eb9SMatthew G Knepley /* 414732e2eb9SMatthew G Knepley Need this test because the dm references the vectors that 415732e2eb9SMatthew G Knepley reference the dm, so destroying the dm calls destroy on the 416732e2eb9SMatthew G Knepley vectors that cause another destroy on the dm 417732e2eb9SMatthew G Knepley */ 4186bf464f9SBarry Smith if (((PetscObject)(*dm))->refct < 0) PetscFunctionReturn(0); 4196bf464f9SBarry Smith ((PetscObject) (*dm))->refct = 0; 420732e2eb9SMatthew G Knepley for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 4216bf464f9SBarry Smith if ((*dm)->localout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a local vector obtained with DMGetLocalVector()"); 4226bf464f9SBarry Smith ierr = VecDestroy(&(*dm)->localin[i]);CHKERRQ(ierr); 423732e2eb9SMatthew G Knepley } 424f490541aSPeter Brune nnext=(*dm)->namedglobal; 4250298fd71SBarry Smith (*dm)->namedglobal = NULL; 426f490541aSPeter Brune for (nlink=nnext; nlink; nlink=nnext) { /* Destroy the named vectors */ 4272348bcf4SPeter Brune nnext = nlink->next; 4282348bcf4SPeter 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); 4292348bcf4SPeter Brune ierr = PetscFree(nlink->name);CHKERRQ(ierr); 4302348bcf4SPeter Brune ierr = VecDestroy(&nlink->X);CHKERRQ(ierr); 4312348bcf4SPeter Brune ierr = PetscFree(nlink);CHKERRQ(ierr); 4322348bcf4SPeter Brune } 433f490541aSPeter Brune nnext=(*dm)->namedlocal; 4340298fd71SBarry Smith (*dm)->namedlocal = NULL; 435f490541aSPeter Brune for (nlink=nnext; nlink; nlink=nnext) { /* Destroy the named local vectors */ 436f490541aSPeter Brune nnext = nlink->next; 437f490541aSPeter 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); 438f490541aSPeter Brune ierr = PetscFree(nlink->name);CHKERRQ(ierr); 439f490541aSPeter Brune ierr = VecDestroy(&nlink->X);CHKERRQ(ierr); 440f490541aSPeter Brune ierr = PetscFree(nlink);CHKERRQ(ierr); 441f490541aSPeter Brune } 4422348bcf4SPeter Brune 443b17ce1afSJed Brown /* Destroy the list of hooks */ 444c833c3b5SJed Brown { 445c833c3b5SJed Brown DMCoarsenHookLink link,next; 446b17ce1afSJed Brown for (link=(*dm)->coarsenhook; link; link=next) { 447b17ce1afSJed Brown next = link->next; 448b17ce1afSJed Brown ierr = PetscFree(link);CHKERRQ(ierr); 449b17ce1afSJed Brown } 4500298fd71SBarry Smith (*dm)->coarsenhook = NULL; 451c833c3b5SJed Brown } 452c833c3b5SJed Brown { 453c833c3b5SJed Brown DMRefineHookLink link,next; 454c833c3b5SJed Brown for (link=(*dm)->refinehook; link; link=next) { 455c833c3b5SJed Brown next = link->next; 456c833c3b5SJed Brown ierr = PetscFree(link);CHKERRQ(ierr); 457c833c3b5SJed Brown } 4580298fd71SBarry Smith (*dm)->refinehook = NULL; 459c833c3b5SJed Brown } 460be081cd6SPeter Brune { 461be081cd6SPeter Brune DMSubDomainHookLink link,next; 462be081cd6SPeter Brune for (link=(*dm)->subdomainhook; link; link=next) { 463be081cd6SPeter Brune next = link->next; 464be081cd6SPeter Brune ierr = PetscFree(link);CHKERRQ(ierr); 465be081cd6SPeter Brune } 4660298fd71SBarry Smith (*dm)->subdomainhook = NULL; 467be081cd6SPeter Brune } 468baf369e7SPeter Brune { 469baf369e7SPeter Brune DMGlobalToLocalHookLink link,next; 470baf369e7SPeter Brune for (link=(*dm)->gtolhook; link; link=next) { 471baf369e7SPeter Brune next = link->next; 472baf369e7SPeter Brune ierr = PetscFree(link);CHKERRQ(ierr); 473baf369e7SPeter Brune } 4740298fd71SBarry Smith (*dm)->gtolhook = NULL; 475baf369e7SPeter Brune } 476aa1993deSMatthew G Knepley /* Destroy the work arrays */ 477aa1993deSMatthew G Knepley { 478aa1993deSMatthew G Knepley DMWorkLink link,next; 479aa1993deSMatthew G Knepley if ((*dm)->workout) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Work array still checked out"); 480aa1993deSMatthew G Knepley for (link=(*dm)->workin; link; link=next) { 481aa1993deSMatthew G Knepley next = link->next; 482aa1993deSMatthew G Knepley ierr = PetscFree(link->mem);CHKERRQ(ierr); 483aa1993deSMatthew G Knepley ierr = PetscFree(link);CHKERRQ(ierr); 484aa1993deSMatthew G Knepley } 4850298fd71SBarry Smith (*dm)->workin = NULL; 486aa1993deSMatthew G Knepley } 487b17ce1afSJed Brown 48852536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmksp);CHKERRQ(ierr); 48952536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmsnes);CHKERRQ(ierr); 49052536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmts);CHKERRQ(ierr); 49152536dc3SBarry Smith 4921a266240SBarry Smith if ((*dm)->ctx && (*dm)->ctxdestroy) { 4931a266240SBarry Smith ierr = (*(*dm)->ctxdestroy)(&(*dm)->ctx);CHKERRQ(ierr); 4941a266240SBarry Smith } 49587e657c6SBarry Smith ierr = VecDestroy(&(*dm)->x);CHKERRQ(ierr); 49671cd77b2SBarry Smith ierr = MatFDColoringDestroy(&(*dm)->fd);CHKERRQ(ierr); 4974dcab191SBarry Smith ierr = DMClearGlobalVectors(*dm);CHKERRQ(ierr); 4986bf464f9SBarry Smith ierr = ISLocalToGlobalMappingDestroy(&(*dm)->ltogmap);CHKERRQ(ierr); 4996bf464f9SBarry Smith ierr = PetscFree((*dm)->vectype);CHKERRQ(ierr); 500073dac72SJed Brown ierr = PetscFree((*dm)->mattype);CHKERRQ(ierr); 50188ed4aceSMatthew G Knepley 50288ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&(*dm)->defaultSection);CHKERRQ(ierr); 50388ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&(*dm)->defaultGlobalSection);CHKERRQ(ierr); 5048b1ab98fSJed Brown ierr = PetscLayoutDestroy(&(*dm)->map);CHKERRQ(ierr); 50588ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&(*dm)->sf);CHKERRQ(ierr); 50688ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&(*dm)->defaultSF);CHKERRQ(ierr); 507af122d2aSMatthew G Knepley 5086636e97aSMatthew G Knepley ierr = DMDestroy(&(*dm)->coordinateDM);CHKERRQ(ierr); 5096636e97aSMatthew G Knepley ierr = VecDestroy(&(*dm)->coordinates);CHKERRQ(ierr); 5106636e97aSMatthew G Knepley ierr = VecDestroy(&(*dm)->coordinatesLocal);CHKERRQ(ierr); 511c6b900c6SMatthew G. Knepley ierr = PetscFree((*dm)->maxCell);CHKERRQ(ierr); 512c6b900c6SMatthew G. Knepley ierr = PetscFree((*dm)->L);CHKERRQ(ierr); 5136636e97aSMatthew G Knepley 5142764a2aaSMatthew G. Knepley ierr = PetscDSDestroy(&(*dm)->prob);CHKERRQ(ierr); 51514f150ffSMatthew G. Knepley ierr = DMDestroy(&(*dm)->dmBC);CHKERRQ(ierr); 516e04113cfSBarry Smith /* if memory was published with SAWs then destroy it */ 517e04113cfSBarry Smith ierr = PetscObjectSAWsViewOff((PetscObject)*dm);CHKERRQ(ierr); 518732e2eb9SMatthew G Knepley 5196bf464f9SBarry Smith ierr = (*(*dm)->ops->destroy)(*dm);CHKERRQ(ierr); 520435a35e8SMatthew G Knepley /* We do not destroy (*dm)->data here so that we can reference count backend objects */ 521732e2eb9SMatthew G Knepley ierr = PetscHeaderDestroy(dm);CHKERRQ(ierr); 52247c6ae99SBarry Smith PetscFunctionReturn(0); 52347c6ae99SBarry Smith } 52447c6ae99SBarry Smith 52547c6ae99SBarry Smith #undef __FUNCT__ 526d7bf68aeSBarry Smith #define __FUNCT__ "DMSetUp" 527d7bf68aeSBarry Smith /*@ 528d7bf68aeSBarry Smith DMSetUp - sets up the data structures inside a DM object 529d7bf68aeSBarry Smith 530d7bf68aeSBarry Smith Collective on DM 531d7bf68aeSBarry Smith 532d7bf68aeSBarry Smith Input Parameter: 533d7bf68aeSBarry Smith . dm - the DM object to setup 534d7bf68aeSBarry Smith 535d7bf68aeSBarry Smith Level: developer 536d7bf68aeSBarry Smith 537e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 538d7bf68aeSBarry Smith 539d7bf68aeSBarry Smith @*/ 5407087cfbeSBarry Smith PetscErrorCode DMSetUp(DM dm) 541d7bf68aeSBarry Smith { 542d7bf68aeSBarry Smith PetscErrorCode ierr; 543d7bf68aeSBarry Smith 544d7bf68aeSBarry Smith PetscFunctionBegin; 545171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5468387afaaSJed Brown if (dm->setupcalled) PetscFunctionReturn(0); 547d7bf68aeSBarry Smith if (dm->ops->setup) { 548d7bf68aeSBarry Smith ierr = (*dm->ops->setup)(dm);CHKERRQ(ierr); 549d7bf68aeSBarry Smith } 5508387afaaSJed Brown dm->setupcalled = PETSC_TRUE; 551d7bf68aeSBarry Smith PetscFunctionReturn(0); 552d7bf68aeSBarry Smith } 553d7bf68aeSBarry Smith 554d7bf68aeSBarry Smith #undef __FUNCT__ 555d7bf68aeSBarry Smith #define __FUNCT__ "DMSetFromOptions" 556d7bf68aeSBarry Smith /*@ 557d7bf68aeSBarry Smith DMSetFromOptions - sets parameters in a DM from the options database 558d7bf68aeSBarry Smith 559d7bf68aeSBarry Smith Collective on DM 560d7bf68aeSBarry Smith 561d7bf68aeSBarry Smith Input Parameter: 562d7bf68aeSBarry Smith . dm - the DM object to set options for 563d7bf68aeSBarry Smith 564732e2eb9SMatthew G Knepley Options Database: 565dd85299cSBarry Smith + -dm_preallocate_only: Only preallocate the matrix for DMCreateMatrix(), but do not fill it with zeros 566dd85299cSBarry Smith . -dm_vec_type <type> type of vector to create inside DM 567171400e9SBarry Smith . -dm_mat_type <type> type of matrix to create inside DM 568171400e9SBarry Smith - -dm_coloring_type <global or ghosted> 569732e2eb9SMatthew G Knepley 570d7bf68aeSBarry Smith Level: developer 571d7bf68aeSBarry Smith 572e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 573d7bf68aeSBarry Smith 574d7bf68aeSBarry Smith @*/ 5757087cfbeSBarry Smith PetscErrorCode DMSetFromOptions(DM dm) 576d7bf68aeSBarry Smith { 5777781c08eSBarry Smith char typeName[256]; 578ca266f36SBarry Smith PetscBool flg; 579d7bf68aeSBarry Smith PetscErrorCode ierr; 580d7bf68aeSBarry Smith 581d7bf68aeSBarry Smith PetscFunctionBegin; 582171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5833194b578SJed Brown ierr = PetscObjectOptionsBegin((PetscObject)dm);CHKERRQ(ierr); 5840298fd71SBarry 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); 585a264d7a6SBarry Smith ierr = PetscOptionsFList("-dm_vec_type","Vector type used for created vectors","DMSetVecType",VecList,dm->vectype,typeName,256,&flg);CHKERRQ(ierr); 586f9ba7244SBarry Smith if (flg) { 587f9ba7244SBarry Smith ierr = DMSetVecType(dm,typeName);CHKERRQ(ierr); 588f9ba7244SBarry Smith } 589a264d7a6SBarry 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); 590073dac72SJed Brown if (flg) { 591521d9a4cSLisandro Dalcin ierr = DMSetMatType(dm,typeName);CHKERRQ(ierr); 592073dac72SJed Brown } 5930298fd71SBarry Smith ierr = PetscOptionsEnum("-dm_is_coloring_type","Global or local coloring of Jacobian","ISColoringType",ISColoringTypes,(PetscEnum)dm->coloringtype,(PetscEnum*)&dm->coloringtype,NULL);CHKERRQ(ierr); 594f9ba7244SBarry Smith if (dm->ops->setfromoptions) { 595f9ba7244SBarry Smith ierr = (*dm->ops->setfromoptions)(dm);CHKERRQ(ierr); 596f9ba7244SBarry Smith } 597f9ba7244SBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 598f9ba7244SBarry Smith ierr = PetscObjectProcessOptionsHandlers((PetscObject) dm);CHKERRQ(ierr); 59982fcb398SMatthew G Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 600d7bf68aeSBarry Smith PetscFunctionReturn(0); 601d7bf68aeSBarry Smith } 602d7bf68aeSBarry Smith 603d7bf68aeSBarry Smith #undef __FUNCT__ 60447c6ae99SBarry Smith #define __FUNCT__ "DMView" 605fc9bc008SSatish Balay /*@C 606aa219208SBarry Smith DMView - Views a vector packer or DMDA. 60747c6ae99SBarry Smith 60847c6ae99SBarry Smith Collective on DM 60947c6ae99SBarry Smith 61047c6ae99SBarry Smith Input Parameter: 61147c6ae99SBarry Smith + dm - the DM object to view 61247c6ae99SBarry Smith - v - the viewer 61347c6ae99SBarry Smith 61447c6ae99SBarry Smith Level: developer 61547c6ae99SBarry Smith 616e727c939SJed Brown .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 61747c6ae99SBarry Smith 61847c6ae99SBarry Smith @*/ 6197087cfbeSBarry Smith PetscErrorCode DMView(DM dm,PetscViewer v) 62047c6ae99SBarry Smith { 62147c6ae99SBarry Smith PetscErrorCode ierr; 62232c0f0efSBarry Smith PetscBool isbinary; 62347c6ae99SBarry Smith 62447c6ae99SBarry Smith PetscFunctionBegin; 625171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6263014e516SBarry Smith if (!v) { 627ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)dm),&v);CHKERRQ(ierr); 6283014e516SBarry Smith } 62998c3331eSBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)dm,v);CHKERRQ(ierr); 63032c0f0efSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); 63132c0f0efSBarry Smith if (isbinary) { 63255849f57SBarry Smith PetscInt classid = DM_FILE_CLASSID; 63332c0f0efSBarry Smith char type[256]; 63432c0f0efSBarry Smith 63532c0f0efSBarry Smith ierr = PetscViewerBinaryWrite(v,&classid,1,PETSC_INT,PETSC_FALSE);CHKERRQ(ierr); 63632c0f0efSBarry Smith ierr = PetscStrncpy(type,((PetscObject)dm)->type_name,256);CHKERRQ(ierr); 63732c0f0efSBarry Smith ierr = PetscViewerBinaryWrite(v,type,256,PETSC_CHAR,PETSC_FALSE);CHKERRQ(ierr); 63832c0f0efSBarry Smith } 6390c010503SBarry Smith if (dm->ops->view) { 6400c010503SBarry Smith ierr = (*dm->ops->view)(dm,v);CHKERRQ(ierr); 64147c6ae99SBarry Smith } 64247c6ae99SBarry Smith PetscFunctionReturn(0); 64347c6ae99SBarry Smith } 64447c6ae99SBarry Smith 64547c6ae99SBarry Smith #undef __FUNCT__ 64647c6ae99SBarry Smith #define __FUNCT__ "DMCreateGlobalVector" 64747c6ae99SBarry Smith /*@ 648aa219208SBarry Smith DMCreateGlobalVector - Creates a global vector from a DMDA or DMComposite object 64947c6ae99SBarry Smith 65047c6ae99SBarry Smith Collective on DM 65147c6ae99SBarry Smith 65247c6ae99SBarry Smith Input Parameter: 65347c6ae99SBarry Smith . dm - the DM object 65447c6ae99SBarry Smith 65547c6ae99SBarry Smith Output Parameter: 65647c6ae99SBarry Smith . vec - the global vector 65747c6ae99SBarry Smith 658073dac72SJed Brown Level: beginner 65947c6ae99SBarry Smith 660e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 66147c6ae99SBarry Smith 66247c6ae99SBarry Smith @*/ 6637087cfbeSBarry Smith PetscErrorCode DMCreateGlobalVector(DM dm,Vec *vec) 66447c6ae99SBarry Smith { 66547c6ae99SBarry Smith PetscErrorCode ierr; 66647c6ae99SBarry Smith 66747c6ae99SBarry Smith PetscFunctionBegin; 668171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 66947c6ae99SBarry Smith ierr = (*dm->ops->createglobalvector)(dm,vec);CHKERRQ(ierr); 67047c6ae99SBarry Smith PetscFunctionReturn(0); 67147c6ae99SBarry Smith } 67247c6ae99SBarry Smith 67347c6ae99SBarry Smith #undef __FUNCT__ 67447c6ae99SBarry Smith #define __FUNCT__ "DMCreateLocalVector" 67547c6ae99SBarry Smith /*@ 676aa219208SBarry Smith DMCreateLocalVector - Creates a local vector from a DMDA or DMComposite object 67747c6ae99SBarry Smith 67847c6ae99SBarry Smith Not Collective 67947c6ae99SBarry Smith 68047c6ae99SBarry Smith Input Parameter: 68147c6ae99SBarry Smith . dm - the DM object 68247c6ae99SBarry Smith 68347c6ae99SBarry Smith Output Parameter: 68447c6ae99SBarry Smith . vec - the local vector 68547c6ae99SBarry Smith 686073dac72SJed Brown Level: beginner 68747c6ae99SBarry Smith 688e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 68947c6ae99SBarry Smith 69047c6ae99SBarry Smith @*/ 6917087cfbeSBarry Smith PetscErrorCode DMCreateLocalVector(DM dm,Vec *vec) 69247c6ae99SBarry Smith { 69347c6ae99SBarry Smith PetscErrorCode ierr; 69447c6ae99SBarry Smith 69547c6ae99SBarry Smith PetscFunctionBegin; 696171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 69747c6ae99SBarry Smith ierr = (*dm->ops->createlocalvector)(dm,vec);CHKERRQ(ierr); 69847c6ae99SBarry Smith PetscFunctionReturn(0); 69947c6ae99SBarry Smith } 70047c6ae99SBarry Smith 70147c6ae99SBarry Smith #undef __FUNCT__ 7021411c6eeSJed Brown #define __FUNCT__ "DMGetLocalToGlobalMapping" 7031411c6eeSJed Brown /*@ 7041411c6eeSJed Brown DMGetLocalToGlobalMapping - Accesses the local-to-global mapping in a DM. 7051411c6eeSJed Brown 7061411c6eeSJed Brown Collective on DM 7071411c6eeSJed Brown 7081411c6eeSJed Brown Input Parameter: 7091411c6eeSJed Brown . dm - the DM that provides the mapping 7101411c6eeSJed Brown 7111411c6eeSJed Brown Output Parameter: 7121411c6eeSJed Brown . ltog - the mapping 7131411c6eeSJed Brown 7141411c6eeSJed Brown Level: intermediate 7151411c6eeSJed Brown 7161411c6eeSJed Brown Notes: 7171411c6eeSJed Brown This mapping can then be used by VecSetLocalToGlobalMapping() or 7181411c6eeSJed Brown MatSetLocalToGlobalMapping(). 7191411c6eeSJed Brown 720fc31e74dSBarry Smith .seealso: DMCreateLocalVector() 7211411c6eeSJed Brown @*/ 7227087cfbeSBarry Smith PetscErrorCode DMGetLocalToGlobalMapping(DM dm,ISLocalToGlobalMapping *ltog) 7231411c6eeSJed Brown { 7241411c6eeSJed Brown PetscErrorCode ierr; 7251411c6eeSJed Brown 7261411c6eeSJed Brown PetscFunctionBegin; 7271411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7281411c6eeSJed Brown PetscValidPointer(ltog,2); 7291411c6eeSJed Brown if (!dm->ltogmap) { 73037d0c07bSMatthew G Knepley PetscSection section, sectionGlobal; 73137d0c07bSMatthew G Knepley 73237d0c07bSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 73337d0c07bSMatthew G Knepley if (section) { 73437d0c07bSMatthew G Knepley PetscInt *ltog; 73537d0c07bSMatthew G Knepley PetscInt pStart, pEnd, size, p, l; 73637d0c07bSMatthew G Knepley 73737d0c07bSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 73837d0c07bSMatthew G Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 73937d0c07bSMatthew G Knepley ierr = PetscSectionGetStorageSize(section, &size);CHKERRQ(ierr); 740785e854fSJed Brown ierr = PetscMalloc1(size, <og);CHKERRQ(ierr); /* We want the local+overlap size */ 74137d0c07bSMatthew G Knepley for (p = pStart, l = 0; p < pEnd; ++p) { 74237d0c07bSMatthew G Knepley PetscInt dof, off, c; 74337d0c07bSMatthew G Knepley 74437d0c07bSMatthew G Knepley /* Should probably use constrained dofs */ 74537d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(section, p, &dof);CHKERRQ(ierr); 74637d0c07bSMatthew G Knepley ierr = PetscSectionGetOffset(sectionGlobal, p, &off);CHKERRQ(ierr); 74737d0c07bSMatthew G Knepley for (c = 0; c < dof; ++c, ++l) { 74837d0c07bSMatthew G Knepley ltog[l] = off+c; 74937d0c07bSMatthew G Knepley } 75037d0c07bSMatthew G Knepley } 751f0413b6fSBarry Smith ierr = ISLocalToGlobalMappingCreate(PETSC_COMM_SELF, 1,size, ltog, PETSC_OWN_POINTER, &dm->ltogmap);CHKERRQ(ierr); 7523bb1ff40SBarry Smith ierr = PetscLogObjectParent((PetscObject)dm, (PetscObject)dm->ltogmap);CHKERRQ(ierr); 75337d0c07bSMatthew G Knepley } else { 754184d77edSJed Brown if (!dm->ops->getlocaltoglobalmapping) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM can not create LocalToGlobalMapping"); 755184d77edSJed Brown ierr = (*dm->ops->getlocaltoglobalmapping)(dm);CHKERRQ(ierr); 7561411c6eeSJed Brown } 75737d0c07bSMatthew G Knepley } 7581411c6eeSJed Brown *ltog = dm->ltogmap; 7591411c6eeSJed Brown PetscFunctionReturn(0); 7601411c6eeSJed Brown } 7611411c6eeSJed Brown 7621411c6eeSJed Brown #undef __FUNCT__ 7631411c6eeSJed Brown #define __FUNCT__ "DMGetBlockSize" 7641411c6eeSJed Brown /*@ 7651411c6eeSJed Brown DMGetBlockSize - Gets the inherent block size associated with a DM 7661411c6eeSJed Brown 7671411c6eeSJed Brown Not Collective 7681411c6eeSJed Brown 7691411c6eeSJed Brown Input Parameter: 7701411c6eeSJed Brown . dm - the DM with block structure 7711411c6eeSJed Brown 7721411c6eeSJed Brown Output Parameter: 7731411c6eeSJed Brown . bs - the block size, 1 implies no exploitable block structure 7741411c6eeSJed Brown 7751411c6eeSJed Brown Level: intermediate 7761411c6eeSJed Brown 777fc31e74dSBarry Smith .seealso: ISCreateBlock(), VecSetBlockSize(), MatSetBlockSize(), DMGetLocalToGlobalMapping() 7781411c6eeSJed Brown @*/ 7797087cfbeSBarry Smith PetscErrorCode DMGetBlockSize(DM dm,PetscInt *bs) 7801411c6eeSJed Brown { 7811411c6eeSJed Brown PetscFunctionBegin; 7821411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7831411c6eeSJed Brown PetscValidPointer(bs,2); 7841411c6eeSJed 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"); 7851411c6eeSJed Brown *bs = dm->bs; 7861411c6eeSJed Brown PetscFunctionReturn(0); 7871411c6eeSJed Brown } 7881411c6eeSJed Brown 7891411c6eeSJed Brown #undef __FUNCT__ 790e727c939SJed Brown #define __FUNCT__ "DMCreateInterpolation" 79147c6ae99SBarry Smith /*@ 792e727c939SJed Brown DMCreateInterpolation - Gets interpolation matrix between two DMDA or DMComposite objects 79347c6ae99SBarry Smith 79447c6ae99SBarry Smith Collective on DM 79547c6ae99SBarry Smith 79647c6ae99SBarry Smith Input Parameter: 79747c6ae99SBarry Smith + dm1 - the DM object 79847c6ae99SBarry Smith - dm2 - the second, finer DM object 79947c6ae99SBarry Smith 80047c6ae99SBarry Smith Output Parameter: 80147c6ae99SBarry Smith + mat - the interpolation 80247c6ae99SBarry Smith - vec - the scaling (optional) 80347c6ae99SBarry Smith 80447c6ae99SBarry Smith Level: developer 80547c6ae99SBarry Smith 80685afcc9aSBarry 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 80785afcc9aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the interpolation. 808d52bd9f3SBarry Smith 8091f588964SMatthew G Knepley For DMDA objects you can use this interpolation (more precisely the interpolation from the DMGetCoordinateDM()) to interpolate the mesh coordinate vectors 810d52bd9f3SBarry Smith EXCEPT in the periodic case where it does not make sense since the coordinate vectors are not periodic. 81185afcc9aSBarry Smith 81285afcc9aSBarry Smith 813e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMRefine(), DMCoarsen() 81447c6ae99SBarry Smith 81547c6ae99SBarry Smith @*/ 816e727c939SJed Brown PetscErrorCode DMCreateInterpolation(DM dm1,DM dm2,Mat *mat,Vec *vec) 81747c6ae99SBarry Smith { 81847c6ae99SBarry Smith PetscErrorCode ierr; 81947c6ae99SBarry Smith 82047c6ae99SBarry Smith PetscFunctionBegin; 821171400e9SBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 822171400e9SBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 82325296bd5SBarry Smith ierr = (*dm1->ops->createinterpolation)(dm1,dm2,mat,vec);CHKERRQ(ierr); 82447c6ae99SBarry Smith PetscFunctionReturn(0); 82547c6ae99SBarry Smith } 82647c6ae99SBarry Smith 82747c6ae99SBarry Smith #undef __FUNCT__ 828e727c939SJed Brown #define __FUNCT__ "DMCreateInjection" 82947c6ae99SBarry Smith /*@ 830e727c939SJed Brown DMCreateInjection - Gets injection matrix between two DMDA or DMComposite objects 83147c6ae99SBarry Smith 83247c6ae99SBarry Smith Collective on DM 83347c6ae99SBarry Smith 83447c6ae99SBarry Smith Input Parameter: 83547c6ae99SBarry Smith + dm1 - the DM object 83647c6ae99SBarry Smith - dm2 - the second, finer DM object 83747c6ae99SBarry Smith 83847c6ae99SBarry Smith Output Parameter: 83947c6ae99SBarry Smith . ctx - the injection 84047c6ae99SBarry Smith 84147c6ae99SBarry Smith Level: developer 84247c6ae99SBarry Smith 84385afcc9aSBarry 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 84485afcc9aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the injection. 84585afcc9aSBarry Smith 846e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMCreateInterpolation() 84747c6ae99SBarry Smith 84847c6ae99SBarry Smith @*/ 849e727c939SJed Brown PetscErrorCode DMCreateInjection(DM dm1,DM dm2,VecScatter *ctx) 85047c6ae99SBarry Smith { 85147c6ae99SBarry Smith PetscErrorCode ierr; 85247c6ae99SBarry Smith 85347c6ae99SBarry Smith PetscFunctionBegin; 854171400e9SBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 855171400e9SBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 85647c6ae99SBarry Smith ierr = (*dm1->ops->getinjection)(dm1,dm2,ctx);CHKERRQ(ierr); 85747c6ae99SBarry Smith PetscFunctionReturn(0); 85847c6ae99SBarry Smith } 85947c6ae99SBarry Smith 86047c6ae99SBarry Smith #undef __FUNCT__ 861e727c939SJed Brown #define __FUNCT__ "DMCreateColoring" 862b412c318SBarry Smith /*@ 863b412c318SBarry Smith DMCreateColoring - Gets coloring for a DM 86447c6ae99SBarry Smith 86547c6ae99SBarry Smith Collective on DM 86647c6ae99SBarry Smith 86747c6ae99SBarry Smith Input Parameter: 86847c6ae99SBarry Smith + dm - the DM object 869b412c318SBarry Smith - ctype - IS_COLORING_GHOSTED or IS_COLORING_GLOBAL 87047c6ae99SBarry Smith 87147c6ae99SBarry Smith Output Parameter: 87247c6ae99SBarry Smith . coloring - the coloring 87347c6ae99SBarry Smith 87447c6ae99SBarry Smith Level: developer 87547c6ae99SBarry Smith 876b412c318SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateMatrix(), DMSetMatType() 87747c6ae99SBarry Smith 878aab9d709SJed Brown @*/ 879b412c318SBarry Smith PetscErrorCode DMCreateColoring(DM dm,ISColoringType ctype,ISColoring *coloring) 88047c6ae99SBarry Smith { 88147c6ae99SBarry Smith PetscErrorCode ierr; 88247c6ae99SBarry Smith 88347c6ae99SBarry Smith PetscFunctionBegin; 884171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 885ce94432eSBarry Smith if (!dm->ops->getcoloring) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No coloring for this type of DM yet"); 886b412c318SBarry Smith ierr = (*dm->ops->getcoloring)(dm,ctype,coloring);CHKERRQ(ierr); 88747c6ae99SBarry Smith PetscFunctionReturn(0); 88847c6ae99SBarry Smith } 88947c6ae99SBarry Smith 89047c6ae99SBarry Smith #undef __FUNCT__ 891950540a4SJed Brown #define __FUNCT__ "DMCreateMatrix" 892b412c318SBarry Smith /*@ 893950540a4SJed Brown DMCreateMatrix - Gets empty Jacobian for a DMDA or DMComposite 89447c6ae99SBarry Smith 89547c6ae99SBarry Smith Collective on DM 89647c6ae99SBarry Smith 89747c6ae99SBarry Smith Input Parameter: 898b412c318SBarry Smith . dm - the DM object 89947c6ae99SBarry Smith 90047c6ae99SBarry Smith Output Parameter: 90147c6ae99SBarry Smith . mat - the empty Jacobian 90247c6ae99SBarry Smith 903073dac72SJed Brown Level: beginner 90447c6ae99SBarry Smith 90594013140SBarry Smith Notes: This properly preallocates the number of nonzeros in the sparse matrix so you 90694013140SBarry Smith do not need to do it yourself. 90794013140SBarry Smith 90894013140SBarry Smith By default it also sets the nonzero structure and puts in the zero entries. To prevent setting 909aa219208SBarry Smith the nonzero pattern call DMDASetMatPreallocateOnly() 91094013140SBarry Smith 91194013140SBarry 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 91294013140SBarry Smith internally by PETSc. 91394013140SBarry Smith 91494013140SBarry Smith For structured grid problems, in general it is easiest to use MatSetValuesStencil() or MatSetValuesLocal() to put values into the matrix because MatSetValues() requires 915aa219208SBarry Smith the indices for the global numbering for DMDAs which is complicated. 91694013140SBarry Smith 917b412c318SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMSetMatType() 91847c6ae99SBarry Smith 919aab9d709SJed Brown @*/ 920b412c318SBarry Smith PetscErrorCode DMCreateMatrix(DM dm,Mat *mat) 92147c6ae99SBarry Smith { 92247c6ae99SBarry Smith PetscErrorCode ierr; 92347c6ae99SBarry Smith 92447c6ae99SBarry Smith PetscFunctionBegin; 925171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 926607a6623SBarry Smith ierr = MatInitializePackage();CHKERRQ(ierr); 927c7b7c8a4SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 928c7b7c8a4SJed Brown PetscValidPointer(mat,3); 929b412c318SBarry Smith ierr = (*dm->ops->creatematrix)(dm,mat);CHKERRQ(ierr); 93047c6ae99SBarry Smith PetscFunctionReturn(0); 93147c6ae99SBarry Smith } 93247c6ae99SBarry Smith 93347c6ae99SBarry Smith #undef __FUNCT__ 934732e2eb9SMatthew G Knepley #define __FUNCT__ "DMSetMatrixPreallocateOnly" 935732e2eb9SMatthew G Knepley /*@ 936950540a4SJed Brown DMSetMatrixPreallocateOnly - When DMCreateMatrix() is called the matrix will be properly 937732e2eb9SMatthew G Knepley preallocated but the nonzero structure and zero values will not be set. 938732e2eb9SMatthew G Knepley 939732e2eb9SMatthew G Knepley Logically Collective on DMDA 940732e2eb9SMatthew G Knepley 941732e2eb9SMatthew G Knepley Input Parameter: 942732e2eb9SMatthew G Knepley + dm - the DM 943732e2eb9SMatthew G Knepley - only - PETSC_TRUE if only want preallocation 944732e2eb9SMatthew G Knepley 945732e2eb9SMatthew G Knepley Level: developer 946950540a4SJed Brown .seealso DMCreateMatrix() 947732e2eb9SMatthew G Knepley @*/ 948732e2eb9SMatthew G Knepley PetscErrorCode DMSetMatrixPreallocateOnly(DM dm, PetscBool only) 949732e2eb9SMatthew G Knepley { 950732e2eb9SMatthew G Knepley PetscFunctionBegin; 951732e2eb9SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 952732e2eb9SMatthew G Knepley dm->prealloc_only = only; 953732e2eb9SMatthew G Knepley PetscFunctionReturn(0); 954732e2eb9SMatthew G Knepley } 955732e2eb9SMatthew G Knepley 956732e2eb9SMatthew G Knepley #undef __FUNCT__ 957a89ea682SMatthew G Knepley #define __FUNCT__ "DMGetWorkArray" 958a89ea682SMatthew G Knepley /*@C 959aa1993deSMatthew G Knepley DMGetWorkArray - Gets a work array guaranteed to be at least the input size, restore with DMRestoreWorkArray() 960a89ea682SMatthew G Knepley 961a89ea682SMatthew G Knepley Not Collective 962a89ea682SMatthew G Knepley 963a89ea682SMatthew G Knepley Input Parameters: 964a89ea682SMatthew G Knepley + dm - the DM object 965aa1993deSMatthew G Knepley . count - The minium size 966aa1993deSMatthew G Knepley - dtype - data type (PETSC_REAL, PETSC_SCALAR, PETSC_INT) 967a89ea682SMatthew G Knepley 968a89ea682SMatthew G Knepley Output Parameter: 969a89ea682SMatthew G Knepley . array - the work array 970a89ea682SMatthew G Knepley 971a89ea682SMatthew G Knepley Level: developer 972a89ea682SMatthew G Knepley 973a89ea682SMatthew G Knepley .seealso DMDestroy(), DMCreate() 974a89ea682SMatthew G Knepley @*/ 975aa1993deSMatthew G Knepley PetscErrorCode DMGetWorkArray(DM dm,PetscInt count,PetscDataType dtype,void *mem) 976a89ea682SMatthew G Knepley { 977a89ea682SMatthew G Knepley PetscErrorCode ierr; 978aa1993deSMatthew G Knepley DMWorkLink link; 979aa1993deSMatthew G Knepley size_t size; 980a89ea682SMatthew G Knepley 981a89ea682SMatthew G Knepley PetscFunctionBegin; 982a89ea682SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 983aa1993deSMatthew G Knepley PetscValidPointer(mem,4); 984aa1993deSMatthew G Knepley if (dm->workin) { 985aa1993deSMatthew G Knepley link = dm->workin; 986aa1993deSMatthew G Knepley dm->workin = dm->workin->next; 987aa1993deSMatthew G Knepley } else { 988b00a9115SJed Brown ierr = PetscNewLog(dm,&link);CHKERRQ(ierr); 989a89ea682SMatthew G Knepley } 990aa1993deSMatthew G Knepley ierr = PetscDataTypeGetSize(dtype,&size);CHKERRQ(ierr); 991aa1993deSMatthew G Knepley if (size*count > link->bytes) { 992aa1993deSMatthew G Knepley ierr = PetscFree(link->mem);CHKERRQ(ierr); 993aa1993deSMatthew G Knepley ierr = PetscMalloc(size*count,&link->mem);CHKERRQ(ierr); 994aa1993deSMatthew G Knepley link->bytes = size*count; 995aa1993deSMatthew G Knepley } 996aa1993deSMatthew G Knepley link->next = dm->workout; 997aa1993deSMatthew G Knepley dm->workout = link; 998aa1993deSMatthew G Knepley *(void**)mem = link->mem; 999a89ea682SMatthew G Knepley PetscFunctionReturn(0); 1000a89ea682SMatthew G Knepley } 1001a89ea682SMatthew G Knepley 1002aa1993deSMatthew G Knepley #undef __FUNCT__ 1003aa1993deSMatthew G Knepley #define __FUNCT__ "DMRestoreWorkArray" 1004aa1993deSMatthew G Knepley /*@C 1005aa1993deSMatthew G Knepley DMRestoreWorkArray - Restores a work array guaranteed to be at least the input size, restore with DMRestoreWorkArray() 1006aa1993deSMatthew G Knepley 1007aa1993deSMatthew G Knepley Not Collective 1008aa1993deSMatthew G Knepley 1009aa1993deSMatthew G Knepley Input Parameters: 1010aa1993deSMatthew G Knepley + dm - the DM object 1011aa1993deSMatthew G Knepley . count - The minium size 1012aa1993deSMatthew G Knepley - dtype - data type (PETSC_REAL, PETSC_SCALAR, PETSC_INT) 1013aa1993deSMatthew G Knepley 1014aa1993deSMatthew G Knepley Output Parameter: 1015aa1993deSMatthew G Knepley . array - the work array 1016aa1993deSMatthew G Knepley 1017aa1993deSMatthew G Knepley Level: developer 1018aa1993deSMatthew G Knepley 1019aa1993deSMatthew G Knepley .seealso DMDestroy(), DMCreate() 1020aa1993deSMatthew G Knepley @*/ 1021aa1993deSMatthew G Knepley PetscErrorCode DMRestoreWorkArray(DM dm,PetscInt count,PetscDataType dtype,void *mem) 1022aa1993deSMatthew G Knepley { 1023aa1993deSMatthew G Knepley DMWorkLink *p,link; 1024aa1993deSMatthew G Knepley 1025aa1993deSMatthew G Knepley PetscFunctionBegin; 1026aa1993deSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1027aa1993deSMatthew G Knepley PetscValidPointer(mem,4); 1028aa1993deSMatthew G Knepley for (p=&dm->workout; (link=*p); p=&link->next) { 1029aa1993deSMatthew G Knepley if (link->mem == *(void**)mem) { 1030aa1993deSMatthew G Knepley *p = link->next; 1031aa1993deSMatthew G Knepley link->next = dm->workin; 1032aa1993deSMatthew G Knepley dm->workin = link; 10330298fd71SBarry Smith *(void**)mem = NULL; 1034aa1993deSMatthew G Knepley PetscFunctionReturn(0); 1035aa1993deSMatthew G Knepley } 1036aa1993deSMatthew G Knepley } 1037aa1993deSMatthew G Knepley SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Array was not checked out"); 1038aa1993deSMatthew G Knepley PetscFunctionReturn(0); 1039aa1993deSMatthew G Knepley } 1040e7c4fc90SDmitry Karpeev 1041e7c4fc90SDmitry Karpeev #undef __FUNCT__ 1042435a35e8SMatthew G Knepley #define __FUNCT__ "DMSetNullSpaceConstructor" 1043435a35e8SMatthew G Knepley PetscErrorCode DMSetNullSpaceConstructor(DM dm, PetscInt field, PetscErrorCode (*nullsp)(DM dm, PetscInt field, MatNullSpace *nullSpace)) 1044435a35e8SMatthew G Knepley { 1045435a35e8SMatthew G Knepley PetscFunctionBegin; 1046435a35e8SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 104782f516ccSBarry Smith if (field >= 10) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cannot handle %d >= 10 fields", field); 1048435a35e8SMatthew G Knepley dm->nullspaceConstructors[field] = nullsp; 1049435a35e8SMatthew G Knepley PetscFunctionReturn(0); 1050435a35e8SMatthew G Knepley } 1051435a35e8SMatthew G Knepley 1052435a35e8SMatthew G Knepley #undef __FUNCT__ 10534d343eeaSMatthew G Knepley #define __FUNCT__ "DMCreateFieldIS" 10544f3b5142SJed Brown /*@C 10554d343eeaSMatthew G Knepley DMCreateFieldIS - Creates a set of IS objects with the global indices of dofs for each field 10564d343eeaSMatthew G Knepley 10574d343eeaSMatthew G Knepley Not collective 10584d343eeaSMatthew G Knepley 10594d343eeaSMatthew G Knepley Input Parameter: 10604d343eeaSMatthew G Knepley . dm - the DM object 10614d343eeaSMatthew G Knepley 10624d343eeaSMatthew G Knepley Output Parameters: 10630298fd71SBarry Smith + numFields - The number of fields (or NULL if not requested) 10640298fd71SBarry Smith . fieldNames - The name for each field (or NULL if not requested) 10650298fd71SBarry Smith - fields - The global indices for each field (or NULL if not requested) 10664d343eeaSMatthew G Knepley 10674d343eeaSMatthew G Knepley Level: intermediate 10684d343eeaSMatthew G Knepley 106921c9b008SJed Brown Notes: 107021c9b008SJed Brown The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 107121c9b008SJed Brown PetscFree(), every entry of fields should be destroyed with ISDestroy(), and both arrays should be freed with 107221c9b008SJed Brown PetscFree(). 107321c9b008SJed Brown 10744d343eeaSMatthew G Knepley .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 10754d343eeaSMatthew G Knepley @*/ 107637d0c07bSMatthew G Knepley PetscErrorCode DMCreateFieldIS(DM dm, PetscInt *numFields, char ***fieldNames, IS **fields) 10774d343eeaSMatthew G Knepley { 107837d0c07bSMatthew G Knepley PetscSection section, sectionGlobal; 10794d343eeaSMatthew G Knepley PetscErrorCode ierr; 10804d343eeaSMatthew G Knepley 10814d343eeaSMatthew G Knepley PetscFunctionBegin; 10824d343eeaSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 108369ca1f37SDmitry Karpeev if (numFields) { 108469ca1f37SDmitry Karpeev PetscValidPointer(numFields,2); 108569ca1f37SDmitry Karpeev *numFields = 0; 108669ca1f37SDmitry Karpeev } 108737d0c07bSMatthew G Knepley if (fieldNames) { 108837d0c07bSMatthew G Knepley PetscValidPointer(fieldNames,3); 10890298fd71SBarry Smith *fieldNames = NULL; 109069ca1f37SDmitry Karpeev } 109169ca1f37SDmitry Karpeev if (fields) { 109269ca1f37SDmitry Karpeev PetscValidPointer(fields,4); 10930298fd71SBarry Smith *fields = NULL; 109469ca1f37SDmitry Karpeev } 109537d0c07bSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 109637d0c07bSMatthew G Knepley if (section) { 109737d0c07bSMatthew G Knepley PetscInt *fieldSizes, **fieldIndices; 109837d0c07bSMatthew G Knepley PetscInt nF, f, pStart, pEnd, p; 109937d0c07bSMatthew G Knepley 110037d0c07bSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 110137d0c07bSMatthew G Knepley ierr = PetscSectionGetNumFields(section, &nF);CHKERRQ(ierr); 1102dcca6d9dSJed Brown ierr = PetscMalloc2(nF,&fieldSizes,nF,&fieldIndices);CHKERRQ(ierr); 110337d0c07bSMatthew G Knepley ierr = PetscSectionGetChart(sectionGlobal, &pStart, &pEnd);CHKERRQ(ierr); 110437d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 110537d0c07bSMatthew G Knepley fieldSizes[f] = 0; 110637d0c07bSMatthew G Knepley } 110737d0c07bSMatthew G Knepley for (p = pStart; p < pEnd; ++p) { 110837d0c07bSMatthew G Knepley PetscInt gdof; 110937d0c07bSMatthew G Knepley 111037d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 111137d0c07bSMatthew G Knepley if (gdof > 0) { 111237d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 111337d0c07bSMatthew G Knepley PetscInt fdof, fcdof; 111437d0c07bSMatthew G Knepley 111537d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldDof(section, p, f, &fdof);CHKERRQ(ierr); 111637d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 111737d0c07bSMatthew G Knepley fieldSizes[f] += fdof-fcdof; 111837d0c07bSMatthew G Knepley } 111937d0c07bSMatthew G Knepley } 112037d0c07bSMatthew G Knepley } 112137d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 1122785e854fSJed Brown ierr = PetscMalloc1(fieldSizes[f], &fieldIndices[f]);CHKERRQ(ierr); 112337d0c07bSMatthew G Knepley fieldSizes[f] = 0; 112437d0c07bSMatthew G Knepley } 112537d0c07bSMatthew G Knepley for (p = pStart; p < pEnd; ++p) { 112637d0c07bSMatthew G Knepley PetscInt gdof, goff; 112737d0c07bSMatthew G Knepley 112837d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 112937d0c07bSMatthew G Knepley if (gdof > 0) { 113037d0c07bSMatthew G Knepley ierr = PetscSectionGetOffset(sectionGlobal, p, &goff);CHKERRQ(ierr); 113137d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 113237d0c07bSMatthew G Knepley PetscInt fdof, fcdof, fc; 113337d0c07bSMatthew G Knepley 113437d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldDof(section, p, f, &fdof);CHKERRQ(ierr); 113537d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 113637d0c07bSMatthew G Knepley for (fc = 0; fc < fdof-fcdof; ++fc, ++fieldSizes[f]) { 113737d0c07bSMatthew G Knepley fieldIndices[f][fieldSizes[f]] = goff++; 113837d0c07bSMatthew G Knepley } 113937d0c07bSMatthew G Knepley } 114037d0c07bSMatthew G Knepley } 114137d0c07bSMatthew G Knepley } 11428865f1eaSKarl Rupp if (numFields) *numFields = nF; 114337d0c07bSMatthew G Knepley if (fieldNames) { 1144785e854fSJed Brown ierr = PetscMalloc1(nF, fieldNames);CHKERRQ(ierr); 114537d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 114637d0c07bSMatthew G Knepley const char *fieldName; 114737d0c07bSMatthew G Knepley 114837d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldName(section, f, &fieldName);CHKERRQ(ierr); 114937d0c07bSMatthew G Knepley ierr = PetscStrallocpy(fieldName, (char**) &(*fieldNames)[f]);CHKERRQ(ierr); 115037d0c07bSMatthew G Knepley } 115137d0c07bSMatthew G Knepley } 115237d0c07bSMatthew G Knepley if (fields) { 1153785e854fSJed Brown ierr = PetscMalloc1(nF, fields);CHKERRQ(ierr); 115437d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 115582f516ccSBarry Smith ierr = ISCreateGeneral(PetscObjectComm((PetscObject)dm), fieldSizes[f], fieldIndices[f], PETSC_OWN_POINTER, &(*fields)[f]);CHKERRQ(ierr); 115637d0c07bSMatthew G Knepley } 115737d0c07bSMatthew G Knepley } 115837d0c07bSMatthew G Knepley ierr = PetscFree2(fieldSizes,fieldIndices);CHKERRQ(ierr); 11598865f1eaSKarl Rupp } else if (dm->ops->createfieldis) { 11608865f1eaSKarl Rupp ierr = (*dm->ops->createfieldis)(dm, numFields, fieldNames, fields);CHKERRQ(ierr); 116169ca1f37SDmitry Karpeev } 11624d343eeaSMatthew G Knepley PetscFunctionReturn(0); 11634d343eeaSMatthew G Knepley } 11644d343eeaSMatthew G Knepley 116516621825SDmitry Karpeev 116616621825SDmitry Karpeev #undef __FUNCT__ 116716621825SDmitry Karpeev #define __FUNCT__ "DMCreateFieldDecomposition" 116816621825SDmitry Karpeev /*@C 116916621825SDmitry Karpeev DMCreateFieldDecomposition - Returns a list of IS objects defining a decomposition of a problem into subproblems 117016621825SDmitry Karpeev corresponding to different fields: each IS contains the global indices of the dofs of the 117116621825SDmitry Karpeev corresponding field. The optional list of DMs define the DM for each subproblem. 1172e7c4fc90SDmitry Karpeev Generalizes DMCreateFieldIS(). 1173e7c4fc90SDmitry Karpeev 1174e7c4fc90SDmitry Karpeev Not collective 1175e7c4fc90SDmitry Karpeev 1176e7c4fc90SDmitry Karpeev Input Parameter: 1177e7c4fc90SDmitry Karpeev . dm - the DM object 1178e7c4fc90SDmitry Karpeev 1179e7c4fc90SDmitry Karpeev Output Parameters: 11800298fd71SBarry Smith + len - The number of subproblems in the field decomposition (or NULL if not requested) 11810298fd71SBarry Smith . namelist - The name for each field (or NULL if not requested) 11820298fd71SBarry Smith . islist - The global indices for each field (or NULL if not requested) 11830298fd71SBarry Smith - dmlist - The DMs for each field subproblem (or NULL, if not requested; if NULL is returned, no DMs are defined) 1184e7c4fc90SDmitry Karpeev 1185e7c4fc90SDmitry Karpeev Level: intermediate 1186e7c4fc90SDmitry Karpeev 1187e7c4fc90SDmitry Karpeev Notes: 1188e7c4fc90SDmitry Karpeev The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 1189e7c4fc90SDmitry Karpeev PetscFree(), every entry of is should be destroyed with ISDestroy(), every entry of dm should be destroyed with DMDestroy(), 1190e7c4fc90SDmitry Karpeev and all of the arrays should be freed with PetscFree(). 1191e7c4fc90SDmitry Karpeev 1192e7c4fc90SDmitry Karpeev .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1193e7c4fc90SDmitry Karpeev @*/ 119416621825SDmitry Karpeev PetscErrorCode DMCreateFieldDecomposition(DM dm, PetscInt *len, char ***namelist, IS **islist, DM **dmlist) 1195e7c4fc90SDmitry Karpeev { 1196e7c4fc90SDmitry Karpeev PetscErrorCode ierr; 1197e7c4fc90SDmitry Karpeev 1198e7c4fc90SDmitry Karpeev PetscFunctionBegin; 1199e7c4fc90SDmitry Karpeev PetscValidHeaderSpecific(dm,DM_CLASSID,1); 12008865f1eaSKarl Rupp if (len) { 12018865f1eaSKarl Rupp PetscValidPointer(len,2); 12028865f1eaSKarl Rupp *len = 0; 12038865f1eaSKarl Rupp } 12048865f1eaSKarl Rupp if (namelist) { 12058865f1eaSKarl Rupp PetscValidPointer(namelist,3); 12068865f1eaSKarl Rupp *namelist = 0; 12078865f1eaSKarl Rupp } 12088865f1eaSKarl Rupp if (islist) { 12098865f1eaSKarl Rupp PetscValidPointer(islist,4); 12108865f1eaSKarl Rupp *islist = 0; 12118865f1eaSKarl Rupp } 12128865f1eaSKarl Rupp if (dmlist) { 12138865f1eaSKarl Rupp PetscValidPointer(dmlist,5); 12148865f1eaSKarl Rupp *dmlist = 0; 12158865f1eaSKarl Rupp } 1216f3f0edfdSDmitry Karpeev /* 1217f3f0edfdSDmitry Karpeev Is it a good idea to apply the following check across all impls? 1218f3f0edfdSDmitry Karpeev Perhaps some impls can have a well-defined decomposition before DMSetUp? 1219f3f0edfdSDmitry Karpeev This, however, follows the general principle that accessors are not well-behaved until the object is set up. 1220f3f0edfdSDmitry Karpeev */ 1221ce94432eSBarry Smith if (!dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE, "Decomposition defined only after DMSetUp"); 122216621825SDmitry Karpeev if (!dm->ops->createfielddecomposition) { 1223435a35e8SMatthew G Knepley PetscSection section; 1224435a35e8SMatthew G Knepley PetscInt numFields, f; 1225435a35e8SMatthew G Knepley 1226435a35e8SMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 1227435a35e8SMatthew G Knepley if (section) {ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr);} 1228435a35e8SMatthew G Knepley if (section && numFields && dm->ops->createsubdm) { 1229435a35e8SMatthew G Knepley *len = numFields; 123003dc3394SMatthew G. Knepley if (namelist) {ierr = PetscMalloc1(numFields,namelist);CHKERRQ(ierr);} 123103dc3394SMatthew G. Knepley if (islist) {ierr = PetscMalloc1(numFields,islist);CHKERRQ(ierr);} 123203dc3394SMatthew G. Knepley if (dmlist) {ierr = PetscMalloc1(numFields,dmlist);CHKERRQ(ierr);} 1233435a35e8SMatthew G Knepley for (f = 0; f < numFields; ++f) { 1234435a35e8SMatthew G Knepley const char *fieldName; 1235435a35e8SMatthew G Knepley 123603dc3394SMatthew G. Knepley ierr = DMCreateSubDM(dm, 1, &f, islist ? &(*islist)[f] : NULL, dmlist ? &(*dmlist)[f] : NULL);CHKERRQ(ierr); 123703dc3394SMatthew G. Knepley if (namelist) { 1238435a35e8SMatthew G Knepley ierr = PetscSectionGetFieldName(section, f, &fieldName);CHKERRQ(ierr); 1239435a35e8SMatthew G Knepley ierr = PetscStrallocpy(fieldName, (char**) &(*namelist)[f]);CHKERRQ(ierr); 1240435a35e8SMatthew G Knepley } 124103dc3394SMatthew G. Knepley } 1242435a35e8SMatthew G Knepley } else { 124369ca1f37SDmitry Karpeev ierr = DMCreateFieldIS(dm, len, namelist, islist);CHKERRQ(ierr); 1244e7c4fc90SDmitry Karpeev /* By default there are no DMs associated with subproblems. */ 12450298fd71SBarry Smith if (dmlist) *dmlist = NULL; 1246e7c4fc90SDmitry Karpeev } 12478865f1eaSKarl Rupp } else { 124816621825SDmitry Karpeev ierr = (*dm->ops->createfielddecomposition)(dm,len,namelist,islist,dmlist);CHKERRQ(ierr); 124916621825SDmitry Karpeev } 125016621825SDmitry Karpeev PetscFunctionReturn(0); 125116621825SDmitry Karpeev } 125216621825SDmitry Karpeev 125316621825SDmitry Karpeev #undef __FUNCT__ 1254435a35e8SMatthew G Knepley #define __FUNCT__ "DMCreateSubDM" 1255435a35e8SMatthew G Knepley /*@C 1256435a35e8SMatthew G Knepley DMCreateSubDM - Returns an IS and DM encapsulating a subproblem defined by the fields passed in. 1257435a35e8SMatthew G Knepley The fields are defined by DMCreateFieldIS(). 1258435a35e8SMatthew G Knepley 1259435a35e8SMatthew G Knepley Not collective 1260435a35e8SMatthew G Knepley 1261435a35e8SMatthew G Knepley Input Parameters: 1262435a35e8SMatthew G Knepley + dm - the DM object 1263435a35e8SMatthew G Knepley . numFields - number of fields in this subproblem 12640298fd71SBarry Smith - len - The number of subproblems in the decomposition (or NULL if not requested) 1265435a35e8SMatthew G Knepley 1266435a35e8SMatthew G Knepley Output Parameters: 1267435a35e8SMatthew G Knepley . is - The global indices for the subproblem 1268435a35e8SMatthew G Knepley - dm - The DM for the subproblem 1269435a35e8SMatthew G Knepley 1270435a35e8SMatthew G Knepley Level: intermediate 1271435a35e8SMatthew G Knepley 1272435a35e8SMatthew G Knepley .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1273435a35e8SMatthew G Knepley @*/ 1274435a35e8SMatthew G Knepley PetscErrorCode DMCreateSubDM(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) 1275435a35e8SMatthew G Knepley { 1276435a35e8SMatthew G Knepley PetscErrorCode ierr; 1277435a35e8SMatthew G Knepley 1278435a35e8SMatthew G Knepley PetscFunctionBegin; 1279435a35e8SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1280435a35e8SMatthew G Knepley PetscValidPointer(fields,3); 12818865f1eaSKarl Rupp if (is) PetscValidPointer(is,4); 12828865f1eaSKarl Rupp if (subdm) PetscValidPointer(subdm,5); 1283435a35e8SMatthew G Knepley if (dm->ops->createsubdm) { 1284435a35e8SMatthew G Knepley ierr = (*dm->ops->createsubdm)(dm, numFields, fields, is, subdm);CHKERRQ(ierr); 128582f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "This type has no DMCreateSubDM implementation defined"); 1286435a35e8SMatthew G Knepley PetscFunctionReturn(0); 1287435a35e8SMatthew G Knepley } 1288435a35e8SMatthew G Knepley 128916621825SDmitry Karpeev 129016621825SDmitry Karpeev #undef __FUNCT__ 129116621825SDmitry Karpeev #define __FUNCT__ "DMCreateDomainDecomposition" 129216621825SDmitry Karpeev /*@C 12938d4ac253SDmitry Karpeev DMCreateDomainDecomposition - Returns lists of IS objects defining a decomposition of a problem into subproblems 12948d4ac253SDmitry Karpeev corresponding to restrictions to pairs nested subdomains: each IS contains the global 12958d4ac253SDmitry Karpeev indices of the dofs of the corresponding subdomains. The inner subdomains conceptually 12968d4ac253SDmitry Karpeev define a nonoverlapping covering, while outer subdomains can overlap. 12978d4ac253SDmitry Karpeev The optional list of DMs define the DM for each subproblem. 129816621825SDmitry Karpeev 129916621825SDmitry Karpeev Not collective 130016621825SDmitry Karpeev 130116621825SDmitry Karpeev Input Parameter: 130216621825SDmitry Karpeev . dm - the DM object 130316621825SDmitry Karpeev 130416621825SDmitry Karpeev Output Parameters: 13050298fd71SBarry Smith + len - The number of subproblems in the domain decomposition (or NULL if not requested) 13060298fd71SBarry Smith . namelist - The name for each subdomain (or NULL if not requested) 13070298fd71SBarry Smith . innerislist - The global indices for each inner subdomain (or NULL, if not requested) 13080298fd71SBarry Smith . outerislist - The global indices for each outer subdomain (or NULL, if not requested) 13090298fd71SBarry Smith - dmlist - The DMs for each subdomain subproblem (or NULL, if not requested; if NULL is returned, no DMs are defined) 131016621825SDmitry Karpeev 131116621825SDmitry Karpeev Level: intermediate 131216621825SDmitry Karpeev 131316621825SDmitry Karpeev Notes: 131416621825SDmitry Karpeev The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 131516621825SDmitry Karpeev PetscFree(), every entry of is should be destroyed with ISDestroy(), every entry of dm should be destroyed with DMDestroy(), 131616621825SDmitry Karpeev and all of the arrays should be freed with PetscFree(). 131716621825SDmitry Karpeev 13188d4ac253SDmitry Karpeev .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateDomainDecompositionDM(), DMCreateFieldDecomposition() 131916621825SDmitry Karpeev @*/ 13208d4ac253SDmitry Karpeev PetscErrorCode DMCreateDomainDecomposition(DM dm, PetscInt *len, char ***namelist, IS **innerislist, IS **outerislist, DM **dmlist) 132116621825SDmitry Karpeev { 132216621825SDmitry Karpeev PetscErrorCode ierr; 1323be081cd6SPeter Brune DMSubDomainHookLink link; 1324be081cd6SPeter Brune PetscInt i,l; 132516621825SDmitry Karpeev 132616621825SDmitry Karpeev PetscFunctionBegin; 132716621825SDmitry Karpeev PetscValidHeaderSpecific(dm,DM_CLASSID,1); 132814a18fd3SPeter Brune if (len) {PetscValidPointer(len,2); *len = 0;} 13290298fd71SBarry Smith if (namelist) {PetscValidPointer(namelist,3); *namelist = NULL;} 13300298fd71SBarry Smith if (innerislist) {PetscValidPointer(innerislist,4); *innerislist = NULL;} 13310298fd71SBarry Smith if (outerislist) {PetscValidPointer(outerislist,5); *outerislist = NULL;} 13320298fd71SBarry Smith if (dmlist) {PetscValidPointer(dmlist,6); *dmlist = NULL;} 1333f3f0edfdSDmitry Karpeev /* 1334f3f0edfdSDmitry Karpeev Is it a good idea to apply the following check across all impls? 1335f3f0edfdSDmitry Karpeev Perhaps some impls can have a well-defined decomposition before DMSetUp? 1336f3f0edfdSDmitry Karpeev This, however, follows the general principle that accessors are not well-behaved until the object is set up. 1337f3f0edfdSDmitry Karpeev */ 1338ce94432eSBarry Smith if (!dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE, "Decomposition defined only after DMSetUp"); 133916621825SDmitry Karpeev if (dm->ops->createdomaindecomposition) { 1340be081cd6SPeter Brune ierr = (*dm->ops->createdomaindecomposition)(dm,&l,namelist,innerislist,outerislist,dmlist);CHKERRQ(ierr); 134114a18fd3SPeter Brune /* copy subdomain hooks and context over to the subdomain DMs */ 134214a18fd3SPeter Brune if (dmlist) { 1343be081cd6SPeter Brune for (i = 0; i < l; i++) { 1344be081cd6SPeter Brune for (link=dm->subdomainhook; link; link=link->next) { 1345be081cd6SPeter Brune if (link->ddhook) {ierr = (*link->ddhook)(dm,(*dmlist)[i],link->ctx);CHKERRQ(ierr);} 1346be081cd6SPeter Brune } 1347d425c654SPeter Brune (*dmlist)[i]->ctx = dm->ctx; 1348e7c4fc90SDmitry Karpeev } 134914a18fd3SPeter Brune } 135014a18fd3SPeter Brune if (len) *len = l; 135114a18fd3SPeter Brune } 1352e30e807fSPeter Brune PetscFunctionReturn(0); 1353e30e807fSPeter Brune } 1354e30e807fSPeter Brune 1355e30e807fSPeter Brune 1356e30e807fSPeter Brune #undef __FUNCT__ 1357e30e807fSPeter Brune #define __FUNCT__ "DMCreateDomainDecompositionScatters" 1358e30e807fSPeter Brune /*@C 1359e30e807fSPeter Brune DMCreateDomainDecompositionScatters - Returns scatters to the subdomain vectors from the global vector 1360e30e807fSPeter Brune 1361e30e807fSPeter Brune Not collective 1362e30e807fSPeter Brune 1363e30e807fSPeter Brune Input Parameters: 1364e30e807fSPeter Brune + dm - the DM object 1365e30e807fSPeter Brune . n - the number of subdomain scatters 1366e30e807fSPeter Brune - subdms - the local subdomains 1367e30e807fSPeter Brune 1368e30e807fSPeter Brune Output Parameters: 1369e30e807fSPeter Brune + n - the number of scatters returned 1370e30e807fSPeter Brune . iscat - scatter from global vector to nonoverlapping global vector entries on subdomain 1371e30e807fSPeter Brune . oscat - scatter from global vector to overlapping global vector entries on subdomain 1372e30e807fSPeter Brune - gscat - scatter from global vector to local vector on subdomain (fills in ghosts) 1373e30e807fSPeter Brune 1374e30e807fSPeter Brune Notes: This is an alternative to the iis and ois arguments in DMCreateDomainDecomposition that allow for the solution 1375e30e807fSPeter Brune of general nonlinear problems with overlapping subdomain methods. While merely having index sets that enable subsets 1376e30e807fSPeter Brune of the residual equations to be created is fine for linear problems, nonlinear problems require local assembly of 1377e30e807fSPeter Brune solution and residual data. 1378e30e807fSPeter Brune 1379e30e807fSPeter Brune Level: developer 1380e30e807fSPeter Brune 1381e30e807fSPeter Brune .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1382e30e807fSPeter Brune @*/ 1383e30e807fSPeter Brune PetscErrorCode DMCreateDomainDecompositionScatters(DM dm,PetscInt n,DM *subdms,VecScatter **iscat,VecScatter **oscat,VecScatter **gscat) 1384e30e807fSPeter Brune { 1385e30e807fSPeter Brune PetscErrorCode ierr; 1386e30e807fSPeter Brune 1387e30e807fSPeter Brune PetscFunctionBegin; 1388e30e807fSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1389e30e807fSPeter Brune PetscValidPointer(subdms,3); 1390e30e807fSPeter Brune if (dm->ops->createddscatters) { 1391e30e807fSPeter Brune ierr = (*dm->ops->createddscatters)(dm,n,subdms,iscat,oscat,gscat);CHKERRQ(ierr); 139282f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "This type has no DMCreateDomainDecompositionLocalScatter implementation defined"); 1393e7c4fc90SDmitry Karpeev PetscFunctionReturn(0); 1394e7c4fc90SDmitry Karpeev } 1395e7c4fc90SDmitry Karpeev 1396731c8d9eSDmitry Karpeev #undef __FUNCT__ 139747c6ae99SBarry Smith #define __FUNCT__ "DMRefine" 139847c6ae99SBarry Smith /*@ 139947c6ae99SBarry Smith DMRefine - Refines a DM object 140047c6ae99SBarry Smith 140147c6ae99SBarry Smith Collective on DM 140247c6ae99SBarry Smith 140347c6ae99SBarry Smith Input Parameter: 140447c6ae99SBarry Smith + dm - the DM object 140591d95f02SJed Brown - comm - the communicator to contain the new DM object (or MPI_COMM_NULL) 140647c6ae99SBarry Smith 140747c6ae99SBarry Smith Output Parameter: 14080298fd71SBarry Smith . dmf - the refined DM, or NULL 1409ae0a1c52SMatthew G Knepley 14100298fd71SBarry Smith Note: If no refinement was done, the return value is NULL 141147c6ae99SBarry Smith 141247c6ae99SBarry Smith Level: developer 141347c6ae99SBarry Smith 1414e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 141547c6ae99SBarry Smith @*/ 14167087cfbeSBarry Smith PetscErrorCode DMRefine(DM dm,MPI_Comm comm,DM *dmf) 141747c6ae99SBarry Smith { 141847c6ae99SBarry Smith PetscErrorCode ierr; 1419c833c3b5SJed Brown DMRefineHookLink link; 142047c6ae99SBarry Smith 142147c6ae99SBarry Smith PetscFunctionBegin; 1422732e2eb9SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 142347c6ae99SBarry Smith ierr = (*dm->ops->refine)(dm,comm,dmf);CHKERRQ(ierr); 14244057135bSMatthew G Knepley if (*dmf) { 142543842a1eSJed Brown (*dmf)->ops->creatematrix = dm->ops->creatematrix; 14268865f1eaSKarl Rupp 14278cd211a4SJed Brown ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)*dmf);CHKERRQ(ierr); 14288865f1eaSKarl Rupp 1429644e2e5bSBarry Smith (*dmf)->ctx = dm->ctx; 14300598a293SJed Brown (*dmf)->leveldown = dm->leveldown; 1431656b349aSBarry Smith (*dmf)->levelup = dm->levelup + 1; 14328865f1eaSKarl Rupp 1433e4b4b23bSJed Brown ierr = DMSetMatType(*dmf,dm->mattype);CHKERRQ(ierr); 1434c833c3b5SJed Brown for (link=dm->refinehook; link; link=link->next) { 14358865f1eaSKarl Rupp if (link->refinehook) { 14368865f1eaSKarl Rupp ierr = (*link->refinehook)(dm,*dmf,link->ctx);CHKERRQ(ierr); 14378865f1eaSKarl Rupp } 1438c833c3b5SJed Brown } 1439c833c3b5SJed Brown } 1440c833c3b5SJed Brown PetscFunctionReturn(0); 1441c833c3b5SJed Brown } 1442c833c3b5SJed Brown 1443c833c3b5SJed Brown #undef __FUNCT__ 1444c833c3b5SJed Brown #define __FUNCT__ "DMRefineHookAdd" 1445bb9467b5SJed Brown /*@C 1446c833c3b5SJed Brown DMRefineHookAdd - adds a callback to be run when interpolating a nonlinear problem to a finer grid 1447c833c3b5SJed Brown 1448c833c3b5SJed Brown Logically Collective 1449c833c3b5SJed Brown 1450c833c3b5SJed Brown Input Arguments: 1451c833c3b5SJed Brown + coarse - nonlinear solver context on which to run a hook when restricting to a coarser level 1452c833c3b5SJed Brown . refinehook - function to run when setting up a coarser level 1453c833c3b5SJed Brown . interphook - function to run to update data on finer levels (once per SNESSolve()) 14540298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1455c833c3b5SJed Brown 1456c833c3b5SJed Brown Calling sequence of refinehook: 1457c833c3b5SJed Brown $ refinehook(DM coarse,DM fine,void *ctx); 1458c833c3b5SJed Brown 1459c833c3b5SJed Brown + coarse - coarse level DM 1460c833c3b5SJed Brown . fine - fine level DM to interpolate problem to 1461c833c3b5SJed Brown - ctx - optional user-defined function context 1462c833c3b5SJed Brown 1463c833c3b5SJed Brown Calling sequence for interphook: 1464c833c3b5SJed Brown $ interphook(DM coarse,Mat interp,DM fine,void *ctx) 1465c833c3b5SJed Brown 1466c833c3b5SJed Brown + coarse - coarse level DM 1467c833c3b5SJed Brown . interp - matrix interpolating a coarse-level solution to the finer grid 1468c833c3b5SJed Brown . fine - fine level DM to update 1469c833c3b5SJed Brown - ctx - optional user-defined function context 1470c833c3b5SJed Brown 1471c833c3b5SJed Brown Level: advanced 1472c833c3b5SJed Brown 1473c833c3b5SJed Brown Notes: 1474c833c3b5SJed Brown This function is only needed if auxiliary data needs to be passed to fine grids while grid sequencing 1475c833c3b5SJed Brown 1476c833c3b5SJed Brown If this function is called multiple times, the hooks will be run in the order they are added. 1477c833c3b5SJed Brown 1478bb9467b5SJed Brown This function is currently not available from Fortran. 1479bb9467b5SJed Brown 1480c833c3b5SJed Brown .seealso: DMCoarsenHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1481c833c3b5SJed Brown @*/ 1482c833c3b5SJed Brown PetscErrorCode DMRefineHookAdd(DM coarse,PetscErrorCode (*refinehook)(DM,DM,void*),PetscErrorCode (*interphook)(DM,Mat,DM,void*),void *ctx) 1483c833c3b5SJed Brown { 1484c833c3b5SJed Brown PetscErrorCode ierr; 1485c833c3b5SJed Brown DMRefineHookLink link,*p; 1486c833c3b5SJed Brown 1487c833c3b5SJed Brown PetscFunctionBegin; 1488c833c3b5SJed Brown PetscValidHeaderSpecific(coarse,DM_CLASSID,1); 1489c833c3b5SJed Brown for (p=&coarse->refinehook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1490c833c3b5SJed Brown ierr = PetscMalloc(sizeof(struct _DMRefineHookLink),&link);CHKERRQ(ierr); 1491c833c3b5SJed Brown link->refinehook = refinehook; 1492c833c3b5SJed Brown link->interphook = interphook; 1493c833c3b5SJed Brown link->ctx = ctx; 14940298fd71SBarry Smith link->next = NULL; 1495c833c3b5SJed Brown *p = link; 1496c833c3b5SJed Brown PetscFunctionReturn(0); 1497c833c3b5SJed Brown } 1498c833c3b5SJed Brown 1499c833c3b5SJed Brown #undef __FUNCT__ 1500c833c3b5SJed Brown #define __FUNCT__ "DMInterpolate" 1501c833c3b5SJed Brown /*@ 1502c833c3b5SJed Brown DMInterpolate - interpolates user-defined problem data to a finer DM by running hooks registered by DMRefineHookAdd() 1503c833c3b5SJed Brown 1504c833c3b5SJed Brown Collective if any hooks are 1505c833c3b5SJed Brown 1506c833c3b5SJed Brown Input Arguments: 1507c833c3b5SJed Brown + coarse - coarser DM to use as a base 1508c833c3b5SJed Brown . restrct - interpolation matrix, apply using MatInterpolate() 1509c833c3b5SJed Brown - fine - finer DM to update 1510c833c3b5SJed Brown 1511c833c3b5SJed Brown Level: developer 1512c833c3b5SJed Brown 1513c833c3b5SJed Brown .seealso: DMRefineHookAdd(), MatInterpolate() 1514c833c3b5SJed Brown @*/ 1515c833c3b5SJed Brown PetscErrorCode DMInterpolate(DM coarse,Mat interp,DM fine) 1516c833c3b5SJed Brown { 1517c833c3b5SJed Brown PetscErrorCode ierr; 1518c833c3b5SJed Brown DMRefineHookLink link; 1519c833c3b5SJed Brown 1520c833c3b5SJed Brown PetscFunctionBegin; 1521c833c3b5SJed Brown for (link=fine->refinehook; link; link=link->next) { 15228865f1eaSKarl Rupp if (link->interphook) { 15238865f1eaSKarl Rupp ierr = (*link->interphook)(coarse,interp,fine,link->ctx);CHKERRQ(ierr); 15248865f1eaSKarl Rupp } 15254057135bSMatthew G Knepley } 152647c6ae99SBarry Smith PetscFunctionReturn(0); 152747c6ae99SBarry Smith } 152847c6ae99SBarry Smith 152947c6ae99SBarry Smith #undef __FUNCT__ 1530eb3f98d2SBarry Smith #define __FUNCT__ "DMGetRefineLevel" 1531eb3f98d2SBarry Smith /*@ 1532eb3f98d2SBarry Smith DMGetRefineLevel - Get's the number of refinements that have generated this DM. 1533eb3f98d2SBarry Smith 1534eb3f98d2SBarry Smith Not Collective 1535eb3f98d2SBarry Smith 1536eb3f98d2SBarry Smith Input Parameter: 1537eb3f98d2SBarry Smith . dm - the DM object 1538eb3f98d2SBarry Smith 1539eb3f98d2SBarry Smith Output Parameter: 1540eb3f98d2SBarry Smith . level - number of refinements 1541eb3f98d2SBarry Smith 1542eb3f98d2SBarry Smith Level: developer 1543eb3f98d2SBarry Smith 15446a7d9d85SPeter Brune .seealso DMCoarsen(), DMGetCoarsenLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 1545eb3f98d2SBarry Smith 1546eb3f98d2SBarry Smith @*/ 1547eb3f98d2SBarry Smith PetscErrorCode DMGetRefineLevel(DM dm,PetscInt *level) 1548eb3f98d2SBarry Smith { 1549eb3f98d2SBarry Smith PetscFunctionBegin; 1550eb3f98d2SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1551eb3f98d2SBarry Smith *level = dm->levelup; 1552eb3f98d2SBarry Smith PetscFunctionReturn(0); 1553eb3f98d2SBarry Smith } 1554eb3f98d2SBarry Smith 1555eb3f98d2SBarry Smith #undef __FUNCT__ 1556baf369e7SPeter Brune #define __FUNCT__ "DMGlobalToLocalHookAdd" 1557bb9467b5SJed Brown /*@C 1558baf369e7SPeter Brune DMGlobalToLocalHookAdd - adds a callback to be run when global to local is called 1559baf369e7SPeter Brune 1560baf369e7SPeter Brune Logically Collective 1561baf369e7SPeter Brune 1562baf369e7SPeter Brune Input Arguments: 1563baf369e7SPeter Brune + dm - the DM 1564baf369e7SPeter Brune . beginhook - function to run at the beginning of DMGlobalToLocalBegin() 1565baf369e7SPeter Brune . endhook - function to run after DMGlobalToLocalEnd() has completed 15660298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1567baf369e7SPeter Brune 1568baf369e7SPeter Brune Calling sequence for beginhook: 1569baf369e7SPeter Brune $ beginhook(DM fine,VecScatter out,VecScatter in,DM coarse,void *ctx) 1570baf369e7SPeter Brune 1571baf369e7SPeter Brune + dm - global DM 1572baf369e7SPeter Brune . g - global vector 1573baf369e7SPeter Brune . mode - mode 1574baf369e7SPeter Brune . l - local vector 1575baf369e7SPeter Brune - ctx - optional user-defined function context 1576baf369e7SPeter Brune 1577baf369e7SPeter Brune 1578baf369e7SPeter Brune Calling sequence for endhook: 1579ec4806b8SPeter Brune $ endhook(DM fine,VecScatter out,VecScatter in,DM coarse,void *ctx) 1580baf369e7SPeter Brune 1581baf369e7SPeter Brune + global - global DM 1582baf369e7SPeter Brune - ctx - optional user-defined function context 1583baf369e7SPeter Brune 1584baf369e7SPeter Brune Level: advanced 1585baf369e7SPeter Brune 1586baf369e7SPeter Brune .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1587baf369e7SPeter Brune @*/ 1588baf369e7SPeter Brune PetscErrorCode DMGlobalToLocalHookAdd(DM dm,PetscErrorCode (*beginhook)(DM,Vec,InsertMode,Vec,void*),PetscErrorCode (*endhook)(DM,Vec,InsertMode,Vec,void*),void *ctx) 1589baf369e7SPeter Brune { 1590baf369e7SPeter Brune PetscErrorCode ierr; 1591baf369e7SPeter Brune DMGlobalToLocalHookLink link,*p; 1592baf369e7SPeter Brune 1593baf369e7SPeter Brune PetscFunctionBegin; 1594baf369e7SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1595baf369e7SPeter Brune for (p=&dm->gtolhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1596baf369e7SPeter Brune ierr = PetscMalloc(sizeof(struct _DMGlobalToLocalHookLink),&link);CHKERRQ(ierr); 1597baf369e7SPeter Brune link->beginhook = beginhook; 1598baf369e7SPeter Brune link->endhook = endhook; 1599baf369e7SPeter Brune link->ctx = ctx; 16000298fd71SBarry Smith link->next = NULL; 1601baf369e7SPeter Brune *p = link; 1602baf369e7SPeter Brune PetscFunctionReturn(0); 1603baf369e7SPeter Brune } 1604baf369e7SPeter Brune 1605baf369e7SPeter Brune #undef __FUNCT__ 160647c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalBegin" 160747c6ae99SBarry Smith /*@ 160847c6ae99SBarry Smith DMGlobalToLocalBegin - Begins updating local vectors from global vector 160947c6ae99SBarry Smith 161047c6ae99SBarry Smith Neighbor-wise Collective on DM 161147c6ae99SBarry Smith 161247c6ae99SBarry Smith Input Parameters: 161347c6ae99SBarry Smith + dm - the DM object 161447c6ae99SBarry Smith . g - the global vector 161547c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 161647c6ae99SBarry Smith - l - the local vector 161747c6ae99SBarry Smith 161847c6ae99SBarry Smith 161947c6ae99SBarry Smith Level: beginner 162047c6ae99SBarry Smith 1621e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 162247c6ae99SBarry Smith 162347c6ae99SBarry Smith @*/ 16247087cfbeSBarry Smith PetscErrorCode DMGlobalToLocalBegin(DM dm,Vec g,InsertMode mode,Vec l) 162547c6ae99SBarry Smith { 16267128ae9fSMatthew G Knepley PetscSF sf; 162747c6ae99SBarry Smith PetscErrorCode ierr; 1628baf369e7SPeter Brune DMGlobalToLocalHookLink link; 162947c6ae99SBarry Smith 163047c6ae99SBarry Smith PetscFunctionBegin; 1631171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1632baf369e7SPeter Brune for (link=dm->gtolhook; link; link=link->next) { 16338865f1eaSKarl Rupp if (link->beginhook) { 16348865f1eaSKarl Rupp ierr = (*link->beginhook)(dm,g,mode,l,link->ctx);CHKERRQ(ierr); 16358865f1eaSKarl Rupp } 1636baf369e7SPeter Brune } 16377128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 16387128ae9fSMatthew G Knepley if (sf) { 16397128ae9fSMatthew G Knepley PetscScalar *lArray, *gArray; 16407128ae9fSMatthew G Knepley 164182f516ccSBarry Smith if (mode == ADD_VALUES) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 16427128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 16437128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 16447128ae9fSMatthew G Knepley ierr = PetscSFBcastBegin(sf, MPIU_SCALAR, gArray, lArray);CHKERRQ(ierr); 16457128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 16467128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 16477128ae9fSMatthew G Knepley } else { 1648843c4018SMatthew G Knepley ierr = (*dm->ops->globaltolocalbegin)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 16497128ae9fSMatthew G Knepley } 165047c6ae99SBarry Smith PetscFunctionReturn(0); 165147c6ae99SBarry Smith } 165247c6ae99SBarry Smith 165347c6ae99SBarry Smith #undef __FUNCT__ 165447c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalEnd" 165547c6ae99SBarry Smith /*@ 165647c6ae99SBarry Smith DMGlobalToLocalEnd - Ends updating local vectors from global vector 165747c6ae99SBarry Smith 165847c6ae99SBarry Smith Neighbor-wise Collective on DM 165947c6ae99SBarry Smith 166047c6ae99SBarry Smith Input Parameters: 166147c6ae99SBarry Smith + dm - the DM object 166247c6ae99SBarry Smith . g - the global vector 166347c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 166447c6ae99SBarry Smith - l - the local vector 166547c6ae99SBarry Smith 166647c6ae99SBarry Smith 166747c6ae99SBarry Smith Level: beginner 166847c6ae99SBarry Smith 1669e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 167047c6ae99SBarry Smith 167147c6ae99SBarry Smith @*/ 16727087cfbeSBarry Smith PetscErrorCode DMGlobalToLocalEnd(DM dm,Vec g,InsertMode mode,Vec l) 167347c6ae99SBarry Smith { 16747128ae9fSMatthew G Knepley PetscSF sf; 167547c6ae99SBarry Smith PetscErrorCode ierr; 167661a3c1faSSatish Balay PetscScalar *lArray, *gArray; 1677baf369e7SPeter Brune DMGlobalToLocalHookLink link; 167847c6ae99SBarry Smith 167947c6ae99SBarry Smith PetscFunctionBegin; 1680171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 16817128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 16827128ae9fSMatthew G Knepley if (sf) { 168382f516ccSBarry Smith if (mode == ADD_VALUES) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 16847128ae9fSMatthew G Knepley 16857128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 16867128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 16877128ae9fSMatthew G Knepley ierr = PetscSFBcastEnd(sf, MPIU_SCALAR, gArray, lArray);CHKERRQ(ierr); 16887128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 16897128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 16907128ae9fSMatthew G Knepley } else { 1691843c4018SMatthew G Knepley ierr = (*dm->ops->globaltolocalend)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 16927128ae9fSMatthew G Knepley } 1693baf369e7SPeter Brune for (link=dm->gtolhook; link; link=link->next) { 1694baf369e7SPeter Brune if (link->endhook) {ierr = (*link->endhook)(dm,g,mode,l,link->ctx);CHKERRQ(ierr);} 1695baf369e7SPeter Brune } 169647c6ae99SBarry Smith PetscFunctionReturn(0); 169747c6ae99SBarry Smith } 169847c6ae99SBarry Smith 169947c6ae99SBarry Smith #undef __FUNCT__ 17009a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalBegin" 170147c6ae99SBarry Smith /*@ 17029a42bb27SBarry Smith DMLocalToGlobalBegin - updates global vectors from local vectors 17039a42bb27SBarry Smith 17049a42bb27SBarry Smith Neighbor-wise Collective on DM 17059a42bb27SBarry Smith 17069a42bb27SBarry Smith Input Parameters: 17079a42bb27SBarry Smith + dm - the DM object 1708f6813fd5SJed Brown . l - the local vector 17099a42bb27SBarry 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 17109a42bb27SBarry Smith base point. 1711f6813fd5SJed Brown - - the global vector 17129a42bb27SBarry Smith 17139a42bb27SBarry Smith Notes: In the ADD_VALUES case you normally would zero the receiving vector before beginning this operation. If you would like to simply add the non-ghosted values in the local 17149a42bb27SBarry Smith array into the global array you need to either (1) zero the ghosted locations and use ADD_VALUES or (2) use INSERT_VALUES into a work global array and then add the work 17159a42bb27SBarry Smith global array to the final global array with VecAXPY(). 17169a42bb27SBarry Smith 17179a42bb27SBarry Smith Level: beginner 17189a42bb27SBarry Smith 1719e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalBegin() 17209a42bb27SBarry Smith 17219a42bb27SBarry Smith @*/ 17227087cfbeSBarry Smith PetscErrorCode DMLocalToGlobalBegin(DM dm,Vec l,InsertMode mode,Vec g) 17239a42bb27SBarry Smith { 17247128ae9fSMatthew G Knepley PetscSF sf; 17259a42bb27SBarry Smith PetscErrorCode ierr; 17269a42bb27SBarry Smith 17279a42bb27SBarry Smith PetscFunctionBegin; 1728171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 17297128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 17307128ae9fSMatthew G Knepley if (sf) { 17317128ae9fSMatthew G Knepley MPI_Op op; 17327128ae9fSMatthew G Knepley PetscScalar *lArray, *gArray; 17337128ae9fSMatthew G Knepley 17347128ae9fSMatthew G Knepley switch (mode) { 17357128ae9fSMatthew G Knepley case INSERT_VALUES: 17367128ae9fSMatthew G Knepley case INSERT_ALL_VALUES: 17378bfbc91cSJed Brown op = MPIU_REPLACE; break; 17387128ae9fSMatthew G Knepley case ADD_VALUES: 17397128ae9fSMatthew G Knepley case ADD_ALL_VALUES: 17407128ae9fSMatthew G Knepley op = MPI_SUM; break; 17417128ae9fSMatthew G Knepley default: 174282f516ccSBarry Smith SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 17437128ae9fSMatthew G Knepley } 17447128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 17457128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 17467128ae9fSMatthew G Knepley ierr = PetscSFReduceBegin(sf, MPIU_SCALAR, lArray, gArray, op);CHKERRQ(ierr); 17477128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 17487128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 17497128ae9fSMatthew G Knepley } else { 1750843c4018SMatthew G Knepley ierr = (*dm->ops->localtoglobalbegin)(dm,l,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),g);CHKERRQ(ierr); 17517128ae9fSMatthew G Knepley } 17529a42bb27SBarry Smith PetscFunctionReturn(0); 17539a42bb27SBarry Smith } 17549a42bb27SBarry Smith 17559a42bb27SBarry Smith #undef __FUNCT__ 17569a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalEnd" 17579a42bb27SBarry Smith /*@ 17589a42bb27SBarry Smith DMLocalToGlobalEnd - updates global vectors from local vectors 175947c6ae99SBarry Smith 176047c6ae99SBarry Smith Neighbor-wise Collective on DM 176147c6ae99SBarry Smith 176247c6ae99SBarry Smith Input Parameters: 176347c6ae99SBarry Smith + dm - the DM object 1764f6813fd5SJed Brown . l - the local vector 176547c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 1766f6813fd5SJed Brown - g - the global vector 176747c6ae99SBarry Smith 176847c6ae99SBarry Smith 176947c6ae99SBarry Smith Level: beginner 177047c6ae99SBarry Smith 1771e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalEnd() 177247c6ae99SBarry Smith 177347c6ae99SBarry Smith @*/ 17747087cfbeSBarry Smith PetscErrorCode DMLocalToGlobalEnd(DM dm,Vec l,InsertMode mode,Vec g) 177547c6ae99SBarry Smith { 17767128ae9fSMatthew G Knepley PetscSF sf; 177747c6ae99SBarry Smith PetscErrorCode ierr; 177847c6ae99SBarry Smith 177947c6ae99SBarry Smith PetscFunctionBegin; 1780171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 17817128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 17827128ae9fSMatthew G Knepley if (sf) { 17837128ae9fSMatthew G Knepley MPI_Op op; 17847128ae9fSMatthew G Knepley PetscScalar *lArray, *gArray; 17857128ae9fSMatthew G Knepley 17867128ae9fSMatthew G Knepley switch (mode) { 17877128ae9fSMatthew G Knepley case INSERT_VALUES: 17887128ae9fSMatthew G Knepley case INSERT_ALL_VALUES: 17898bfbc91cSJed Brown op = MPIU_REPLACE; break; 17907128ae9fSMatthew G Knepley case ADD_VALUES: 17917128ae9fSMatthew G Knepley case ADD_ALL_VALUES: 17927128ae9fSMatthew G Knepley op = MPI_SUM; break; 17937128ae9fSMatthew G Knepley default: 179482f516ccSBarry Smith SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 17957128ae9fSMatthew G Knepley } 17967128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 17977128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 17987128ae9fSMatthew G Knepley ierr = PetscSFReduceEnd(sf, MPIU_SCALAR, lArray, gArray, op);CHKERRQ(ierr); 17997128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 18007128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 18017128ae9fSMatthew G Knepley } else { 1802843c4018SMatthew G Knepley ierr = (*dm->ops->localtoglobalend)(dm,l,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),g);CHKERRQ(ierr); 18037128ae9fSMatthew G Knepley } 180447c6ae99SBarry Smith PetscFunctionReturn(0); 180547c6ae99SBarry Smith } 180647c6ae99SBarry Smith 180747c6ae99SBarry Smith #undef __FUNCT__ 1808f089877aSRichard Tran Mills #define __FUNCT__ "DMLocalToLocalBegin" 1809f089877aSRichard Tran Mills /*@ 1810bc0a1609SRichard Tran Mills DMLocalToLocalBegin - Maps from a local vector (including ghost points 1811bc0a1609SRichard Tran Mills that contain irrelevant values) to another local vector where the ghost 1812d78e899eSRichard Tran Mills points in the second are set correctly. Must be followed by DMLocalToLocalEnd(). 1813f089877aSRichard Tran Mills 1814bc0a1609SRichard Tran Mills Neighbor-wise Collective on DM and Vec 1815f089877aSRichard Tran Mills 1816f089877aSRichard Tran Mills Input Parameters: 1817f089877aSRichard Tran Mills + dm - the DM object 1818bc0a1609SRichard Tran Mills . g - the original local vector 1819bc0a1609SRichard Tran Mills - mode - one of INSERT_VALUES or ADD_VALUES 1820f089877aSRichard Tran Mills 1821bc0a1609SRichard Tran Mills Output Parameter: 1822bc0a1609SRichard Tran Mills . l - the local vector with correct ghost values 1823f089877aSRichard Tran Mills 1824f089877aSRichard Tran Mills Level: intermediate 1825f089877aSRichard Tran Mills 1826bc0a1609SRichard Tran Mills Notes: 1827bc0a1609SRichard Tran Mills The local vectors used here need not be the same as those 1828bc0a1609SRichard Tran Mills obtained from DMCreateLocalVector(), BUT they 1829bc0a1609SRichard Tran Mills must have the same parallel data layout; they could, for example, be 1830bc0a1609SRichard Tran Mills obtained with VecDuplicate() from the DM originating vectors. 1831bc0a1609SRichard Tran Mills 1832bc0a1609SRichard Tran Mills .keywords: DM, local-to-local, begin 1833bc0a1609SRichard Tran Mills .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateLocalVector(), DMCreateGlobalVector(), DMCreateInterpolation(), DMLocalToLocalEnd(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 1834f089877aSRichard Tran Mills 1835f089877aSRichard Tran Mills @*/ 1836f089877aSRichard Tran Mills PetscErrorCode DMLocalToLocalBegin(DM dm,Vec g,InsertMode mode,Vec l) 1837f089877aSRichard Tran Mills { 1838f089877aSRichard Tran Mills PetscErrorCode ierr; 1839f089877aSRichard Tran Mills 1840f089877aSRichard Tran Mills PetscFunctionBegin; 1841f089877aSRichard Tran Mills PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1842f089877aSRichard Tran Mills ierr = (*dm->ops->localtolocalbegin)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 1843f089877aSRichard Tran Mills PetscFunctionReturn(0); 1844f089877aSRichard Tran Mills } 1845f089877aSRichard Tran Mills 1846f089877aSRichard Tran Mills #undef __FUNCT__ 1847f089877aSRichard Tran Mills #define __FUNCT__ "DMLocalToLocalEnd" 1848f089877aSRichard Tran Mills /*@ 1849bc0a1609SRichard Tran Mills DMLocalToLocalEnd - Maps from a local vector (including ghost points 1850bc0a1609SRichard Tran Mills that contain irrelevant values) to another local vector where the ghost 1851d78e899eSRichard Tran Mills points in the second are set correctly. Must be preceded by DMLocalToLocalBegin(). 1852f089877aSRichard Tran Mills 1853bc0a1609SRichard Tran Mills Neighbor-wise Collective on DM and Vec 1854f089877aSRichard Tran Mills 1855f089877aSRichard Tran Mills Input Parameters: 1856bc0a1609SRichard Tran Mills + da - the DM object 1857bc0a1609SRichard Tran Mills . g - the original local vector 1858bc0a1609SRichard Tran Mills - mode - one of INSERT_VALUES or ADD_VALUES 1859f089877aSRichard Tran Mills 1860bc0a1609SRichard Tran Mills Output Parameter: 1861bc0a1609SRichard Tran Mills . l - the local vector with correct ghost values 1862f089877aSRichard Tran Mills 1863f089877aSRichard Tran Mills Level: intermediate 1864f089877aSRichard Tran Mills 1865bc0a1609SRichard Tran Mills Notes: 1866bc0a1609SRichard Tran Mills The local vectors used here need not be the same as those 1867bc0a1609SRichard Tran Mills obtained from DMCreateLocalVector(), BUT they 1868bc0a1609SRichard Tran Mills must have the same parallel data layout; they could, for example, be 1869bc0a1609SRichard Tran Mills obtained with VecDuplicate() from the DM originating vectors. 1870bc0a1609SRichard Tran Mills 1871bc0a1609SRichard Tran Mills .keywords: DM, local-to-local, end 1872bc0a1609SRichard Tran Mills .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateLocalVector(), DMCreateGlobalVector(), DMCreateInterpolation(), DMLocalToLocalBegin(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 1873f089877aSRichard Tran Mills 1874f089877aSRichard Tran Mills @*/ 1875f089877aSRichard Tran Mills PetscErrorCode DMLocalToLocalEnd(DM dm,Vec g,InsertMode mode,Vec l) 1876f089877aSRichard Tran Mills { 1877f089877aSRichard Tran Mills PetscErrorCode ierr; 1878f089877aSRichard Tran Mills 1879f089877aSRichard Tran Mills PetscFunctionBegin; 1880f089877aSRichard Tran Mills PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1881f089877aSRichard Tran Mills ierr = (*dm->ops->localtolocalend)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 1882f089877aSRichard Tran Mills PetscFunctionReturn(0); 1883f089877aSRichard Tran Mills } 1884f089877aSRichard Tran Mills 1885f089877aSRichard Tran Mills 1886f089877aSRichard Tran Mills #undef __FUNCT__ 188747c6ae99SBarry Smith #define __FUNCT__ "DMCoarsen" 188847c6ae99SBarry Smith /*@ 188947c6ae99SBarry Smith DMCoarsen - Coarsens a DM object 189047c6ae99SBarry Smith 189147c6ae99SBarry Smith Collective on DM 189247c6ae99SBarry Smith 189347c6ae99SBarry Smith Input Parameter: 189447c6ae99SBarry Smith + dm - the DM object 189591d95f02SJed Brown - comm - the communicator to contain the new DM object (or MPI_COMM_NULL) 189647c6ae99SBarry Smith 189747c6ae99SBarry Smith Output Parameter: 189847c6ae99SBarry Smith . dmc - the coarsened DM 189947c6ae99SBarry Smith 190047c6ae99SBarry Smith Level: developer 190147c6ae99SBarry Smith 1902e727c939SJed Brown .seealso DMRefine(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 190347c6ae99SBarry Smith 190447c6ae99SBarry Smith @*/ 19057087cfbeSBarry Smith PetscErrorCode DMCoarsen(DM dm, MPI_Comm comm, DM *dmc) 190647c6ae99SBarry Smith { 190747c6ae99SBarry Smith PetscErrorCode ierr; 1908b17ce1afSJed Brown DMCoarsenHookLink link; 190947c6ae99SBarry Smith 191047c6ae99SBarry Smith PetscFunctionBegin; 1911171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 191247c6ae99SBarry Smith ierr = (*dm->ops->coarsen)(dm, comm, dmc);CHKERRQ(ierr); 191343842a1eSJed Brown (*dmc)->ops->creatematrix = dm->ops->creatematrix; 19148cd211a4SJed Brown ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)*dmc);CHKERRQ(ierr); 1915644e2e5bSBarry Smith (*dmc)->ctx = dm->ctx; 19160598a293SJed Brown (*dmc)->levelup = dm->levelup; 1917656b349aSBarry Smith (*dmc)->leveldown = dm->leveldown + 1; 1918e4b4b23bSJed Brown ierr = DMSetMatType(*dmc,dm->mattype);CHKERRQ(ierr); 1919b17ce1afSJed Brown for (link=dm->coarsenhook; link; link=link->next) { 1920b17ce1afSJed Brown if (link->coarsenhook) {ierr = (*link->coarsenhook)(dm,*dmc,link->ctx);CHKERRQ(ierr);} 1921b17ce1afSJed Brown } 1922b17ce1afSJed Brown PetscFunctionReturn(0); 1923b17ce1afSJed Brown } 1924b17ce1afSJed Brown 1925b17ce1afSJed Brown #undef __FUNCT__ 1926b17ce1afSJed Brown #define __FUNCT__ "DMCoarsenHookAdd" 1927bb9467b5SJed Brown /*@C 1928b17ce1afSJed Brown DMCoarsenHookAdd - adds a callback to be run when restricting a nonlinear problem to the coarse grid 1929b17ce1afSJed Brown 1930b17ce1afSJed Brown Logically Collective 1931b17ce1afSJed Brown 1932b17ce1afSJed Brown Input Arguments: 1933b17ce1afSJed Brown + fine - nonlinear solver context on which to run a hook when restricting to a coarser level 1934b17ce1afSJed Brown . coarsenhook - function to run when setting up a coarser level 1935b17ce1afSJed Brown . restricthook - function to run to update data on coarser levels (once per SNESSolve()) 19360298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1937b17ce1afSJed Brown 1938b17ce1afSJed Brown Calling sequence of coarsenhook: 1939b17ce1afSJed Brown $ coarsenhook(DM fine,DM coarse,void *ctx); 1940b17ce1afSJed Brown 1941b17ce1afSJed Brown + fine - fine level DM 1942b17ce1afSJed Brown . coarse - coarse level DM to restrict problem to 1943b17ce1afSJed Brown - ctx - optional user-defined function context 1944b17ce1afSJed Brown 1945b17ce1afSJed Brown Calling sequence for restricthook: 1946c833c3b5SJed Brown $ restricthook(DM fine,Mat mrestrict,Vec rscale,Mat inject,DM coarse,void *ctx) 1947b17ce1afSJed Brown 1948b17ce1afSJed Brown + fine - fine level DM 1949b17ce1afSJed Brown . mrestrict - matrix restricting a fine-level solution to the coarse grid 1950c833c3b5SJed Brown . rscale - scaling vector for restriction 1951c833c3b5SJed Brown . inject - matrix restricting by injection 1952b17ce1afSJed Brown . coarse - coarse level DM to update 1953b17ce1afSJed Brown - ctx - optional user-defined function context 1954b17ce1afSJed Brown 1955b17ce1afSJed Brown Level: advanced 1956b17ce1afSJed Brown 1957b17ce1afSJed Brown Notes: 1958b17ce1afSJed Brown This function is only needed if auxiliary data needs to be set up on coarse grids. 1959b17ce1afSJed Brown 1960b17ce1afSJed Brown If this function is called multiple times, the hooks will be run in the order they are added. 1961b17ce1afSJed Brown 1962b17ce1afSJed Brown In order to compose with nonlinear preconditioning without duplicating storage, the hook should be implemented to 1963b17ce1afSJed Brown extract the finest level information from its context (instead of from the SNES). 1964b17ce1afSJed Brown 1965bb9467b5SJed Brown This function is currently not available from Fortran. 1966bb9467b5SJed Brown 1967c833c3b5SJed Brown .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1968b17ce1afSJed Brown @*/ 1969b17ce1afSJed Brown PetscErrorCode DMCoarsenHookAdd(DM fine,PetscErrorCode (*coarsenhook)(DM,DM,void*),PetscErrorCode (*restricthook)(DM,Mat,Vec,Mat,DM,void*),void *ctx) 1970b17ce1afSJed Brown { 1971b17ce1afSJed Brown PetscErrorCode ierr; 1972b17ce1afSJed Brown DMCoarsenHookLink link,*p; 1973b17ce1afSJed Brown 1974b17ce1afSJed Brown PetscFunctionBegin; 1975b17ce1afSJed Brown PetscValidHeaderSpecific(fine,DM_CLASSID,1); 19766bfea28cSJed Brown for (p=&fine->coarsenhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1977b17ce1afSJed Brown ierr = PetscMalloc(sizeof(struct _DMCoarsenHookLink),&link);CHKERRQ(ierr); 1978b17ce1afSJed Brown link->coarsenhook = coarsenhook; 1979b17ce1afSJed Brown link->restricthook = restricthook; 1980b17ce1afSJed Brown link->ctx = ctx; 19810298fd71SBarry Smith link->next = NULL; 1982b17ce1afSJed Brown *p = link; 1983b17ce1afSJed Brown PetscFunctionReturn(0); 1984b17ce1afSJed Brown } 1985b17ce1afSJed Brown 1986b17ce1afSJed Brown #undef __FUNCT__ 1987b17ce1afSJed Brown #define __FUNCT__ "DMRestrict" 1988b17ce1afSJed Brown /*@ 1989b17ce1afSJed Brown DMRestrict - restricts user-defined problem data to a coarser DM by running hooks registered by DMCoarsenHookAdd() 1990b17ce1afSJed Brown 1991b17ce1afSJed Brown Collective if any hooks are 1992b17ce1afSJed Brown 1993b17ce1afSJed Brown Input Arguments: 1994b17ce1afSJed Brown + fine - finer DM to use as a base 1995b17ce1afSJed Brown . restrct - restriction matrix, apply using MatRestrict() 1996b17ce1afSJed Brown . inject - injection matrix, also use MatRestrict() 1997b17ce1afSJed Brown - coarse - coarer DM to update 1998b17ce1afSJed Brown 1999b17ce1afSJed Brown Level: developer 2000b17ce1afSJed Brown 2001b17ce1afSJed Brown .seealso: DMCoarsenHookAdd(), MatRestrict() 2002b17ce1afSJed Brown @*/ 2003b17ce1afSJed Brown PetscErrorCode DMRestrict(DM fine,Mat restrct,Vec rscale,Mat inject,DM coarse) 2004b17ce1afSJed Brown { 2005b17ce1afSJed Brown PetscErrorCode ierr; 2006b17ce1afSJed Brown DMCoarsenHookLink link; 2007b17ce1afSJed Brown 2008b17ce1afSJed Brown PetscFunctionBegin; 2009b17ce1afSJed Brown for (link=fine->coarsenhook; link; link=link->next) { 20108865f1eaSKarl Rupp if (link->restricthook) { 20118865f1eaSKarl Rupp ierr = (*link->restricthook)(fine,restrct,rscale,inject,coarse,link->ctx);CHKERRQ(ierr); 20128865f1eaSKarl Rupp } 2013b17ce1afSJed Brown } 201447c6ae99SBarry Smith PetscFunctionReturn(0); 201547c6ae99SBarry Smith } 201647c6ae99SBarry Smith 201747c6ae99SBarry Smith #undef __FUNCT__ 2018be081cd6SPeter Brune #define __FUNCT__ "DMSubDomainHookAdd" 2019bb9467b5SJed Brown /*@C 2020be081cd6SPeter Brune DMSubDomainHookAdd - adds a callback to be run when restricting a problem to the coarse grid 20215dbd56e3SPeter Brune 20225dbd56e3SPeter Brune Logically Collective 20235dbd56e3SPeter Brune 20245dbd56e3SPeter Brune Input Arguments: 20255dbd56e3SPeter Brune + global - global DM 2026ec4806b8SPeter Brune . ddhook - function to run to pass data to the decomposition DM upon its creation 20275dbd56e3SPeter Brune . restricthook - function to run to update data on block solve (at the beginning of the block solve) 20280298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 20295dbd56e3SPeter Brune 2030ec4806b8SPeter Brune 2031ec4806b8SPeter Brune Calling sequence for ddhook: 2032ec4806b8SPeter Brune $ ddhook(DM global,DM block,void *ctx) 2033ec4806b8SPeter Brune 2034ec4806b8SPeter Brune + global - global DM 2035ec4806b8SPeter Brune . block - block DM 2036ec4806b8SPeter Brune - ctx - optional user-defined function context 2037ec4806b8SPeter Brune 20385dbd56e3SPeter Brune Calling sequence for restricthook: 2039ec4806b8SPeter Brune $ restricthook(DM global,VecScatter out,VecScatter in,DM block,void *ctx) 20405dbd56e3SPeter Brune 20415dbd56e3SPeter Brune + global - global DM 20425dbd56e3SPeter Brune . out - scatter to the outer (with ghost and overlap points) block vector 20435dbd56e3SPeter Brune . in - scatter to block vector values only owned locally 2044ec4806b8SPeter Brune . block - block DM 20455dbd56e3SPeter Brune - ctx - optional user-defined function context 20465dbd56e3SPeter Brune 20475dbd56e3SPeter Brune Level: advanced 20485dbd56e3SPeter Brune 20495dbd56e3SPeter Brune Notes: 2050ec4806b8SPeter Brune This function is only needed if auxiliary data needs to be set up on subdomain DMs. 20515dbd56e3SPeter Brune 20525dbd56e3SPeter Brune If this function is called multiple times, the hooks will be run in the order they are added. 20535dbd56e3SPeter Brune 20545dbd56e3SPeter Brune In order to compose with nonlinear preconditioning without duplicating storage, the hook should be implemented to 2055ec4806b8SPeter Brune extract the global information from its context (instead of from the SNES). 20565dbd56e3SPeter Brune 2057bb9467b5SJed Brown This function is currently not available from Fortran. 2058bb9467b5SJed Brown 20595dbd56e3SPeter Brune .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 20605dbd56e3SPeter Brune @*/ 2061be081cd6SPeter Brune PetscErrorCode DMSubDomainHookAdd(DM global,PetscErrorCode (*ddhook)(DM,DM,void*),PetscErrorCode (*restricthook)(DM,VecScatter,VecScatter,DM,void*),void *ctx) 20625dbd56e3SPeter Brune { 20635dbd56e3SPeter Brune PetscErrorCode ierr; 2064be081cd6SPeter Brune DMSubDomainHookLink link,*p; 20655dbd56e3SPeter Brune 20665dbd56e3SPeter Brune PetscFunctionBegin; 20675dbd56e3SPeter Brune PetscValidHeaderSpecific(global,DM_CLASSID,1); 2068be081cd6SPeter Brune for (p=&global->subdomainhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 2069be081cd6SPeter Brune ierr = PetscMalloc(sizeof(struct _DMSubDomainHookLink),&link);CHKERRQ(ierr); 20705dbd56e3SPeter Brune link->restricthook = restricthook; 2071be081cd6SPeter Brune link->ddhook = ddhook; 20725dbd56e3SPeter Brune link->ctx = ctx; 20730298fd71SBarry Smith link->next = NULL; 20745dbd56e3SPeter Brune *p = link; 20755dbd56e3SPeter Brune PetscFunctionReturn(0); 20765dbd56e3SPeter Brune } 20775dbd56e3SPeter Brune 20785dbd56e3SPeter Brune #undef __FUNCT__ 2079be081cd6SPeter Brune #define __FUNCT__ "DMSubDomainRestrict" 20805dbd56e3SPeter Brune /*@ 2081be081cd6SPeter Brune DMSubDomainRestrict - restricts user-defined problem data to a block DM by running hooks registered by DMSubDomainHookAdd() 20825dbd56e3SPeter Brune 20835dbd56e3SPeter Brune Collective if any hooks are 20845dbd56e3SPeter Brune 20855dbd56e3SPeter Brune Input Arguments: 20865dbd56e3SPeter Brune + fine - finer DM to use as a base 2087be081cd6SPeter Brune . oscatter - scatter from domain global vector filling subdomain global vector with overlap 2088be081cd6SPeter Brune . gscatter - scatter from domain global vector filling subdomain local vector with ghosts 20895dbd56e3SPeter Brune - coarse - coarer DM to update 20905dbd56e3SPeter Brune 20915dbd56e3SPeter Brune Level: developer 20925dbd56e3SPeter Brune 20935dbd56e3SPeter Brune .seealso: DMCoarsenHookAdd(), MatRestrict() 20945dbd56e3SPeter Brune @*/ 2095be081cd6SPeter Brune PetscErrorCode DMSubDomainRestrict(DM global,VecScatter oscatter,VecScatter gscatter,DM subdm) 20965dbd56e3SPeter Brune { 20975dbd56e3SPeter Brune PetscErrorCode ierr; 2098be081cd6SPeter Brune DMSubDomainHookLink link; 20995dbd56e3SPeter Brune 21005dbd56e3SPeter Brune PetscFunctionBegin; 2101be081cd6SPeter Brune for (link=global->subdomainhook; link; link=link->next) { 21028865f1eaSKarl Rupp if (link->restricthook) { 21038865f1eaSKarl Rupp ierr = (*link->restricthook)(global,oscatter,gscatter,subdm,link->ctx);CHKERRQ(ierr); 21048865f1eaSKarl Rupp } 21055dbd56e3SPeter Brune } 21065dbd56e3SPeter Brune PetscFunctionReturn(0); 21075dbd56e3SPeter Brune } 21085dbd56e3SPeter Brune 21095dbd56e3SPeter Brune #undef __FUNCT__ 21105fe1f584SPeter Brune #define __FUNCT__ "DMGetCoarsenLevel" 21115fe1f584SPeter Brune /*@ 21126a7d9d85SPeter Brune DMGetCoarsenLevel - Get's the number of coarsenings that have generated this DM. 21135fe1f584SPeter Brune 21145fe1f584SPeter Brune Not Collective 21155fe1f584SPeter Brune 21165fe1f584SPeter Brune Input Parameter: 21175fe1f584SPeter Brune . dm - the DM object 21185fe1f584SPeter Brune 21195fe1f584SPeter Brune Output Parameter: 21206a7d9d85SPeter Brune . level - number of coarsenings 21215fe1f584SPeter Brune 21225fe1f584SPeter Brune Level: developer 21235fe1f584SPeter Brune 21246a7d9d85SPeter Brune .seealso DMCoarsen(), DMGetRefineLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 21255fe1f584SPeter Brune 21265fe1f584SPeter Brune @*/ 21275fe1f584SPeter Brune PetscErrorCode DMGetCoarsenLevel(DM dm,PetscInt *level) 21285fe1f584SPeter Brune { 21295fe1f584SPeter Brune PetscFunctionBegin; 21305fe1f584SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 21315fe1f584SPeter Brune *level = dm->leveldown; 21325fe1f584SPeter Brune PetscFunctionReturn(0); 21335fe1f584SPeter Brune } 21345fe1f584SPeter Brune 21355fe1f584SPeter Brune 21365fe1f584SPeter Brune 21375fe1f584SPeter Brune #undef __FUNCT__ 213847c6ae99SBarry Smith #define __FUNCT__ "DMRefineHierarchy" 213947c6ae99SBarry Smith /*@C 214047c6ae99SBarry Smith DMRefineHierarchy - Refines a DM object, all levels at once 214147c6ae99SBarry Smith 214247c6ae99SBarry Smith Collective on DM 214347c6ae99SBarry Smith 214447c6ae99SBarry Smith Input Parameter: 214547c6ae99SBarry Smith + dm - the DM object 214647c6ae99SBarry Smith - nlevels - the number of levels of refinement 214747c6ae99SBarry Smith 214847c6ae99SBarry Smith Output Parameter: 214947c6ae99SBarry Smith . dmf - the refined DM hierarchy 215047c6ae99SBarry Smith 215147c6ae99SBarry Smith Level: developer 215247c6ae99SBarry Smith 2153e727c939SJed Brown .seealso DMCoarsenHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 215447c6ae99SBarry Smith 215547c6ae99SBarry Smith @*/ 21567087cfbeSBarry Smith PetscErrorCode DMRefineHierarchy(DM dm,PetscInt nlevels,DM dmf[]) 215747c6ae99SBarry Smith { 215847c6ae99SBarry Smith PetscErrorCode ierr; 215947c6ae99SBarry Smith 216047c6ae99SBarry Smith PetscFunctionBegin; 2161171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2162ce94432eSBarry Smith if (nlevels < 0) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 216347c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 216447c6ae99SBarry Smith if (dm->ops->refinehierarchy) { 216547c6ae99SBarry Smith ierr = (*dm->ops->refinehierarchy)(dm,nlevels,dmf);CHKERRQ(ierr); 216647c6ae99SBarry Smith } else if (dm->ops->refine) { 216747c6ae99SBarry Smith PetscInt i; 216847c6ae99SBarry Smith 2169ce94432eSBarry Smith ierr = DMRefine(dm,PetscObjectComm((PetscObject)dm),&dmf[0]);CHKERRQ(ierr); 217047c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 2171ce94432eSBarry Smith ierr = DMRefine(dmf[i-1],PetscObjectComm((PetscObject)dm),&dmf[i]);CHKERRQ(ierr); 217247c6ae99SBarry Smith } 2173ce94432eSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No RefineHierarchy for this DM yet"); 217447c6ae99SBarry Smith PetscFunctionReturn(0); 217547c6ae99SBarry Smith } 217647c6ae99SBarry Smith 217747c6ae99SBarry Smith #undef __FUNCT__ 217847c6ae99SBarry Smith #define __FUNCT__ "DMCoarsenHierarchy" 217947c6ae99SBarry Smith /*@C 218047c6ae99SBarry Smith DMCoarsenHierarchy - Coarsens a DM object, all levels at once 218147c6ae99SBarry Smith 218247c6ae99SBarry Smith Collective on DM 218347c6ae99SBarry Smith 218447c6ae99SBarry Smith Input Parameter: 218547c6ae99SBarry Smith + dm - the DM object 218647c6ae99SBarry Smith - nlevels - the number of levels of coarsening 218747c6ae99SBarry Smith 218847c6ae99SBarry Smith Output Parameter: 218947c6ae99SBarry Smith . dmc - the coarsened DM hierarchy 219047c6ae99SBarry Smith 219147c6ae99SBarry Smith Level: developer 219247c6ae99SBarry Smith 2193e727c939SJed Brown .seealso DMRefineHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 219447c6ae99SBarry Smith 219547c6ae99SBarry Smith @*/ 21967087cfbeSBarry Smith PetscErrorCode DMCoarsenHierarchy(DM dm, PetscInt nlevels, DM dmc[]) 219747c6ae99SBarry Smith { 219847c6ae99SBarry Smith PetscErrorCode ierr; 219947c6ae99SBarry Smith 220047c6ae99SBarry Smith PetscFunctionBegin; 2201171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2202ce94432eSBarry Smith if (nlevels < 0) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 220347c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 220447c6ae99SBarry Smith PetscValidPointer(dmc,3); 220547c6ae99SBarry Smith if (dm->ops->coarsenhierarchy) { 220647c6ae99SBarry Smith ierr = (*dm->ops->coarsenhierarchy)(dm, nlevels, dmc);CHKERRQ(ierr); 220747c6ae99SBarry Smith } else if (dm->ops->coarsen) { 220847c6ae99SBarry Smith PetscInt i; 220947c6ae99SBarry Smith 2210ce94432eSBarry Smith ierr = DMCoarsen(dm,PetscObjectComm((PetscObject)dm),&dmc[0]);CHKERRQ(ierr); 221147c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 2212ce94432eSBarry Smith ierr = DMCoarsen(dmc[i-1],PetscObjectComm((PetscObject)dm),&dmc[i]);CHKERRQ(ierr); 221347c6ae99SBarry Smith } 2214ce94432eSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No CoarsenHierarchy for this DM yet"); 221547c6ae99SBarry Smith PetscFunctionReturn(0); 221647c6ae99SBarry Smith } 221747c6ae99SBarry Smith 221847c6ae99SBarry Smith #undef __FUNCT__ 2219e727c939SJed Brown #define __FUNCT__ "DMCreateAggregates" 222047c6ae99SBarry Smith /*@ 2221e727c939SJed Brown DMCreateAggregates - Gets the aggregates that map between 222247c6ae99SBarry Smith grids associated with two DMs. 222347c6ae99SBarry Smith 222447c6ae99SBarry Smith Collective on DM 222547c6ae99SBarry Smith 222647c6ae99SBarry Smith Input Parameters: 222747c6ae99SBarry Smith + dmc - the coarse grid DM 222847c6ae99SBarry Smith - dmf - the fine grid DM 222947c6ae99SBarry Smith 223047c6ae99SBarry Smith Output Parameters: 223147c6ae99SBarry Smith . rest - the restriction matrix (transpose of the projection matrix) 223247c6ae99SBarry Smith 223347c6ae99SBarry Smith Level: intermediate 223447c6ae99SBarry Smith 223547c6ae99SBarry Smith .keywords: interpolation, restriction, multigrid 223647c6ae99SBarry Smith 2237e727c939SJed Brown .seealso: DMRefine(), DMCreateInjection(), DMCreateInterpolation() 223847c6ae99SBarry Smith @*/ 2239e727c939SJed Brown PetscErrorCode DMCreateAggregates(DM dmc, DM dmf, Mat *rest) 224047c6ae99SBarry Smith { 224147c6ae99SBarry Smith PetscErrorCode ierr; 224247c6ae99SBarry Smith 224347c6ae99SBarry Smith PetscFunctionBegin; 2244171400e9SBarry Smith PetscValidHeaderSpecific(dmc,DM_CLASSID,1); 2245171400e9SBarry Smith PetscValidHeaderSpecific(dmf,DM_CLASSID,2); 224647c6ae99SBarry Smith ierr = (*dmc->ops->getaggregates)(dmc, dmf, rest);CHKERRQ(ierr); 224747c6ae99SBarry Smith PetscFunctionReturn(0); 224847c6ae99SBarry Smith } 224947c6ae99SBarry Smith 225047c6ae99SBarry Smith #undef __FUNCT__ 22511a266240SBarry Smith #define __FUNCT__ "DMSetApplicationContextDestroy" 22521a266240SBarry Smith /*@C 22531a266240SBarry Smith DMSetApplicationContextDestroy - Sets a user function that will be called to destroy the application context when the DM is destroyed 22541a266240SBarry Smith 22551a266240SBarry Smith Not Collective 22561a266240SBarry Smith 22571a266240SBarry Smith Input Parameters: 22581a266240SBarry Smith + dm - the DM object 22591a266240SBarry Smith - destroy - the destroy function 22601a266240SBarry Smith 22611a266240SBarry Smith Level: intermediate 22621a266240SBarry Smith 2263e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 22641a266240SBarry Smith 2265f07f9ceaSJed Brown @*/ 22661a266240SBarry Smith PetscErrorCode DMSetApplicationContextDestroy(DM dm,PetscErrorCode (*destroy)(void**)) 22671a266240SBarry Smith { 22681a266240SBarry Smith PetscFunctionBegin; 2269171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 22701a266240SBarry Smith dm->ctxdestroy = destroy; 22711a266240SBarry Smith PetscFunctionReturn(0); 22721a266240SBarry Smith } 22731a266240SBarry Smith 22741a266240SBarry Smith #undef __FUNCT__ 22751b2093e4SBarry Smith #define __FUNCT__ "DMSetApplicationContext" 2276b07ff414SBarry Smith /*@ 22771b2093e4SBarry Smith DMSetApplicationContext - Set a user context into a DM object 227847c6ae99SBarry Smith 227947c6ae99SBarry Smith Not Collective 228047c6ae99SBarry Smith 228147c6ae99SBarry Smith Input Parameters: 228247c6ae99SBarry Smith + dm - the DM object 228347c6ae99SBarry Smith - ctx - the user context 228447c6ae99SBarry Smith 228547c6ae99SBarry Smith Level: intermediate 228647c6ae99SBarry Smith 2287e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 228847c6ae99SBarry Smith 228947c6ae99SBarry Smith @*/ 22901b2093e4SBarry Smith PetscErrorCode DMSetApplicationContext(DM dm,void *ctx) 229147c6ae99SBarry Smith { 229247c6ae99SBarry Smith PetscFunctionBegin; 2293171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 229447c6ae99SBarry Smith dm->ctx = ctx; 229547c6ae99SBarry Smith PetscFunctionReturn(0); 229647c6ae99SBarry Smith } 229747c6ae99SBarry Smith 229847c6ae99SBarry Smith #undef __FUNCT__ 22991b2093e4SBarry Smith #define __FUNCT__ "DMGetApplicationContext" 230047c6ae99SBarry Smith /*@ 23011b2093e4SBarry Smith DMGetApplicationContext - Gets a user context from a DM object 230247c6ae99SBarry Smith 230347c6ae99SBarry Smith Not Collective 230447c6ae99SBarry Smith 230547c6ae99SBarry Smith Input Parameter: 230647c6ae99SBarry Smith . dm - the DM object 230747c6ae99SBarry Smith 230847c6ae99SBarry Smith Output Parameter: 230947c6ae99SBarry Smith . ctx - the user context 231047c6ae99SBarry Smith 231147c6ae99SBarry Smith Level: intermediate 231247c6ae99SBarry Smith 2313e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 231447c6ae99SBarry Smith 231547c6ae99SBarry Smith @*/ 23161b2093e4SBarry Smith PetscErrorCode DMGetApplicationContext(DM dm,void *ctx) 231747c6ae99SBarry Smith { 231847c6ae99SBarry Smith PetscFunctionBegin; 2319171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 23201b2093e4SBarry Smith *(void**)ctx = dm->ctx; 232147c6ae99SBarry Smith PetscFunctionReturn(0); 232247c6ae99SBarry Smith } 232347c6ae99SBarry Smith 232447c6ae99SBarry Smith #undef __FUNCT__ 232508da532bSDmitry Karpeev #define __FUNCT__ "DMSetVariableBounds" 232608da532bSDmitry Karpeev /*@C 232708da532bSDmitry Karpeev DMSetVariableBounds - sets a function to compute the the lower and upper bound vectors for SNESVI. 232808da532bSDmitry Karpeev 232908da532bSDmitry Karpeev Logically Collective on DM 233008da532bSDmitry Karpeev 233108da532bSDmitry Karpeev Input Parameter: 233208da532bSDmitry Karpeev + dm - the DM object 23330298fd71SBarry Smith - f - the function that computes variable bounds used by SNESVI (use NULL to cancel a previous function that was set) 233408da532bSDmitry Karpeev 233508da532bSDmitry Karpeev Level: intermediate 233608da532bSDmitry Karpeev 2337835c3ec7SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), 233808da532bSDmitry Karpeev DMSetJacobian() 233908da532bSDmitry Karpeev 234008da532bSDmitry Karpeev @*/ 234108da532bSDmitry Karpeev PetscErrorCode DMSetVariableBounds(DM dm,PetscErrorCode (*f)(DM,Vec,Vec)) 234208da532bSDmitry Karpeev { 234308da532bSDmitry Karpeev PetscFunctionBegin; 234408da532bSDmitry Karpeev dm->ops->computevariablebounds = f; 234508da532bSDmitry Karpeev PetscFunctionReturn(0); 234608da532bSDmitry Karpeev } 234708da532bSDmitry Karpeev 234808da532bSDmitry Karpeev #undef __FUNCT__ 234908da532bSDmitry Karpeev #define __FUNCT__ "DMHasVariableBounds" 235008da532bSDmitry Karpeev /*@ 235108da532bSDmitry Karpeev DMHasVariableBounds - does the DM object have a variable bounds function? 235208da532bSDmitry Karpeev 235308da532bSDmitry Karpeev Not Collective 235408da532bSDmitry Karpeev 235508da532bSDmitry Karpeev Input Parameter: 235608da532bSDmitry Karpeev . dm - the DM object to destroy 235708da532bSDmitry Karpeev 235808da532bSDmitry Karpeev Output Parameter: 235908da532bSDmitry Karpeev . flg - PETSC_TRUE if the variable bounds function exists 236008da532bSDmitry Karpeev 236108da532bSDmitry Karpeev Level: developer 236208da532bSDmitry Karpeev 236374e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 236408da532bSDmitry Karpeev 236508da532bSDmitry Karpeev @*/ 236608da532bSDmitry Karpeev PetscErrorCode DMHasVariableBounds(DM dm,PetscBool *flg) 236708da532bSDmitry Karpeev { 236808da532bSDmitry Karpeev PetscFunctionBegin; 236908da532bSDmitry Karpeev *flg = (dm->ops->computevariablebounds) ? PETSC_TRUE : PETSC_FALSE; 237008da532bSDmitry Karpeev PetscFunctionReturn(0); 237108da532bSDmitry Karpeev } 237208da532bSDmitry Karpeev 237308da532bSDmitry Karpeev #undef __FUNCT__ 237408da532bSDmitry Karpeev #define __FUNCT__ "DMComputeVariableBounds" 237508da532bSDmitry Karpeev /*@C 237608da532bSDmitry Karpeev DMComputeVariableBounds - compute variable bounds used by SNESVI. 237708da532bSDmitry Karpeev 237808da532bSDmitry Karpeev Logically Collective on DM 237908da532bSDmitry Karpeev 238008da532bSDmitry Karpeev Input Parameters: 238108da532bSDmitry Karpeev + dm - the DM object to destroy 238208da532bSDmitry Karpeev - x - current solution at which the bounds are computed 238308da532bSDmitry Karpeev 238408da532bSDmitry Karpeev Output parameters: 238508da532bSDmitry Karpeev + xl - lower bound 238608da532bSDmitry Karpeev - xu - upper bound 238708da532bSDmitry Karpeev 238808da532bSDmitry Karpeev Level: intermediate 238908da532bSDmitry Karpeev 239074e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 239108da532bSDmitry Karpeev 239208da532bSDmitry Karpeev @*/ 239308da532bSDmitry Karpeev PetscErrorCode DMComputeVariableBounds(DM dm, Vec xl, Vec xu) 239408da532bSDmitry Karpeev { 239508da532bSDmitry Karpeev PetscErrorCode ierr; 23965fd66863SKarl Rupp 239708da532bSDmitry Karpeev PetscFunctionBegin; 239808da532bSDmitry Karpeev PetscValidHeaderSpecific(xl,VEC_CLASSID,2); 239908da532bSDmitry Karpeev PetscValidHeaderSpecific(xu,VEC_CLASSID,2); 240008da532bSDmitry Karpeev if (dm->ops->computevariablebounds) { 240108da532bSDmitry Karpeev ierr = (*dm->ops->computevariablebounds)(dm, xl,xu);CHKERRQ(ierr); 24028865f1eaSKarl Rupp } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "This DM is incapable of computing variable bounds."); 240308da532bSDmitry Karpeev PetscFunctionReturn(0); 240408da532bSDmitry Karpeev } 240508da532bSDmitry Karpeev 240608da532bSDmitry Karpeev #undef __FUNCT__ 2407b0ae01b7SPeter Brune #define __FUNCT__ "DMHasColoring" 2408b0ae01b7SPeter Brune /*@ 2409b0ae01b7SPeter Brune DMHasColoring - does the DM object have a method of providing a coloring? 2410b0ae01b7SPeter Brune 2411b0ae01b7SPeter Brune Not Collective 2412b0ae01b7SPeter Brune 2413b0ae01b7SPeter Brune Input Parameter: 2414b0ae01b7SPeter Brune . dm - the DM object 2415b0ae01b7SPeter Brune 2416b0ae01b7SPeter Brune Output Parameter: 2417b0ae01b7SPeter Brune . flg - PETSC_TRUE if the DM has facilities for DMCreateColoring(). 2418b0ae01b7SPeter Brune 2419b0ae01b7SPeter Brune Level: developer 2420b0ae01b7SPeter Brune 2421b0ae01b7SPeter Brune .seealso DMHasFunction(), DMCreateColoring() 2422b0ae01b7SPeter Brune 2423b0ae01b7SPeter Brune @*/ 2424b0ae01b7SPeter Brune PetscErrorCode DMHasColoring(DM dm,PetscBool *flg) 2425b0ae01b7SPeter Brune { 2426b0ae01b7SPeter Brune PetscFunctionBegin; 2427b0ae01b7SPeter Brune *flg = (dm->ops->getcoloring) ? PETSC_TRUE : PETSC_FALSE; 2428b0ae01b7SPeter Brune PetscFunctionReturn(0); 2429b0ae01b7SPeter Brune } 2430b0ae01b7SPeter Brune 2431b0ae01b7SPeter Brune #undef __FUNCT__ 243208da532bSDmitry Karpeev #define __FUNCT__ "DMSetVec" 2433748fac09SDmitry Karpeev /*@C 243408da532bSDmitry Karpeev DMSetVec - set the vector at which to compute residual, Jacobian and VI bounds, if the problem is nonlinear. 243508da532bSDmitry Karpeev 243608da532bSDmitry Karpeev Collective on DM 243708da532bSDmitry Karpeev 243808da532bSDmitry Karpeev Input Parameter: 243908da532bSDmitry Karpeev + dm - the DM object 24400298fd71SBarry Smith - x - location to compute residual and Jacobian, if NULL is passed to those routines; will be NULL for linear problems. 244108da532bSDmitry Karpeev 244208da532bSDmitry Karpeev Level: developer 244308da532bSDmitry Karpeev 244474e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 244508da532bSDmitry Karpeev 244608da532bSDmitry Karpeev @*/ 244708da532bSDmitry Karpeev PetscErrorCode DMSetVec(DM dm,Vec x) 244808da532bSDmitry Karpeev { 244908da532bSDmitry Karpeev PetscErrorCode ierr; 24505fd66863SKarl Rupp 245108da532bSDmitry Karpeev PetscFunctionBegin; 245208da532bSDmitry Karpeev if (x) { 245308da532bSDmitry Karpeev if (!dm->x) { 245408da532bSDmitry Karpeev ierr = DMCreateGlobalVector(dm,&dm->x);CHKERRQ(ierr); 245508da532bSDmitry Karpeev } 245608da532bSDmitry Karpeev ierr = VecCopy(x,dm->x);CHKERRQ(ierr); 24578865f1eaSKarl Rupp } else if (dm->x) { 245808da532bSDmitry Karpeev ierr = VecDestroy(&dm->x);CHKERRQ(ierr); 245908da532bSDmitry Karpeev } 246008da532bSDmitry Karpeev PetscFunctionReturn(0); 246108da532bSDmitry Karpeev } 246208da532bSDmitry Karpeev 24630298fd71SBarry Smith PetscFunctionList DMList = NULL; 2464264ace61SBarry Smith PetscBool DMRegisterAllCalled = PETSC_FALSE; 2465264ace61SBarry Smith 2466264ace61SBarry Smith #undef __FUNCT__ 2467264ace61SBarry Smith #define __FUNCT__ "DMSetType" 2468264ace61SBarry Smith /*@C 2469264ace61SBarry Smith DMSetType - Builds a DM, for a particular DM implementation. 2470264ace61SBarry Smith 2471264ace61SBarry Smith Collective on DM 2472264ace61SBarry Smith 2473264ace61SBarry Smith Input Parameters: 2474264ace61SBarry Smith + dm - The DM object 2475264ace61SBarry Smith - method - The name of the DM type 2476264ace61SBarry Smith 2477264ace61SBarry Smith Options Database Key: 2478264ace61SBarry Smith . -dm_type <type> - Sets the DM type; use -help for a list of available types 2479264ace61SBarry Smith 2480264ace61SBarry Smith Notes: 2481e1589f56SBarry Smith See "petsc/include/petscdm.h" for available DM types (for instance, DM1D, DM2D, or DM3D). 2482264ace61SBarry Smith 2483264ace61SBarry Smith Level: intermediate 2484264ace61SBarry Smith 2485264ace61SBarry Smith .keywords: DM, set, type 2486264ace61SBarry Smith .seealso: DMGetType(), DMCreate() 2487264ace61SBarry Smith @*/ 248819fd82e9SBarry Smith PetscErrorCode DMSetType(DM dm, DMType method) 2489264ace61SBarry Smith { 2490264ace61SBarry Smith PetscErrorCode (*r)(DM); 2491264ace61SBarry Smith PetscBool match; 2492264ace61SBarry Smith PetscErrorCode ierr; 2493264ace61SBarry Smith 2494264ace61SBarry Smith PetscFunctionBegin; 2495264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 2496251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject) dm, method, &match);CHKERRQ(ierr); 2497264ace61SBarry Smith if (match) PetscFunctionReturn(0); 2498264ace61SBarry Smith 2499607a6623SBarry Smith if (!DMRegisterAllCalled) {ierr = DMRegisterAll();CHKERRQ(ierr);} 25001c9cd337SJed Brown ierr = PetscFunctionListFind(DMList,method,&r);CHKERRQ(ierr); 2501ce94432eSBarry Smith if (!r) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown DM type: %s", method); 2502264ace61SBarry Smith 2503264ace61SBarry Smith if (dm->ops->destroy) { 2504264ace61SBarry Smith ierr = (*dm->ops->destroy)(dm);CHKERRQ(ierr); 25050298fd71SBarry Smith dm->ops->destroy = NULL; 2506264ace61SBarry Smith } 2507264ace61SBarry Smith ierr = (*r)(dm);CHKERRQ(ierr); 2508264ace61SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)dm,method);CHKERRQ(ierr); 2509264ace61SBarry Smith PetscFunctionReturn(0); 2510264ace61SBarry Smith } 2511264ace61SBarry Smith 2512264ace61SBarry Smith #undef __FUNCT__ 2513264ace61SBarry Smith #define __FUNCT__ "DMGetType" 2514264ace61SBarry Smith /*@C 2515264ace61SBarry Smith DMGetType - Gets the DM type name (as a string) from the DM. 2516264ace61SBarry Smith 2517264ace61SBarry Smith Not Collective 2518264ace61SBarry Smith 2519264ace61SBarry Smith Input Parameter: 2520264ace61SBarry Smith . dm - The DM 2521264ace61SBarry Smith 2522264ace61SBarry Smith Output Parameter: 2523264ace61SBarry Smith . type - The DM type name 2524264ace61SBarry Smith 2525264ace61SBarry Smith Level: intermediate 2526264ace61SBarry Smith 2527264ace61SBarry Smith .keywords: DM, get, type, name 2528264ace61SBarry Smith .seealso: DMSetType(), DMCreate() 2529264ace61SBarry Smith @*/ 253019fd82e9SBarry Smith PetscErrorCode DMGetType(DM dm, DMType *type) 2531264ace61SBarry Smith { 2532264ace61SBarry Smith PetscErrorCode ierr; 2533264ace61SBarry Smith 2534264ace61SBarry Smith PetscFunctionBegin; 2535264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 2536264ace61SBarry Smith PetscValidCharPointer(type,2); 2537264ace61SBarry Smith if (!DMRegisterAllCalled) { 2538607a6623SBarry Smith ierr = DMRegisterAll();CHKERRQ(ierr); 2539264ace61SBarry Smith } 2540264ace61SBarry Smith *type = ((PetscObject)dm)->type_name; 2541264ace61SBarry Smith PetscFunctionReturn(0); 2542264ace61SBarry Smith } 2543264ace61SBarry Smith 254467a56275SMatthew G Knepley #undef __FUNCT__ 254567a56275SMatthew G Knepley #define __FUNCT__ "DMConvert" 254667a56275SMatthew G Knepley /*@C 254767a56275SMatthew G Knepley DMConvert - Converts a DM to another DM, either of the same or different type. 254867a56275SMatthew G Knepley 254967a56275SMatthew G Knepley Collective on DM 255067a56275SMatthew G Knepley 255167a56275SMatthew G Knepley Input Parameters: 255267a56275SMatthew G Knepley + dm - the DM 255367a56275SMatthew G Knepley - newtype - new DM type (use "same" for the same type) 255467a56275SMatthew G Knepley 255567a56275SMatthew G Knepley Output Parameter: 255667a56275SMatthew G Knepley . M - pointer to new DM 255767a56275SMatthew G Knepley 255867a56275SMatthew G Knepley Notes: 255967a56275SMatthew G Knepley Cannot be used to convert a sequential DM to parallel or parallel to sequential, 256067a56275SMatthew G Knepley the MPI communicator of the generated DM is always the same as the communicator 256167a56275SMatthew G Knepley of the input DM. 256267a56275SMatthew G Knepley 256367a56275SMatthew G Knepley Level: intermediate 256467a56275SMatthew G Knepley 256567a56275SMatthew G Knepley .seealso: DMCreate() 256667a56275SMatthew G Knepley @*/ 256719fd82e9SBarry Smith PetscErrorCode DMConvert(DM dm, DMType newtype, DM *M) 256867a56275SMatthew G Knepley { 256967a56275SMatthew G Knepley DM B; 257067a56275SMatthew G Knepley char convname[256]; 257167a56275SMatthew G Knepley PetscBool sametype, issame; 257267a56275SMatthew G Knepley PetscErrorCode ierr; 257367a56275SMatthew G Knepley 257467a56275SMatthew G Knepley PetscFunctionBegin; 257567a56275SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 257667a56275SMatthew G Knepley PetscValidType(dm,1); 257767a56275SMatthew G Knepley PetscValidPointer(M,3); 2578251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject) dm, newtype, &sametype);CHKERRQ(ierr); 257967a56275SMatthew G Knepley ierr = PetscStrcmp(newtype, "same", &issame);CHKERRQ(ierr); 258067a56275SMatthew G Knepley { 25810298fd71SBarry Smith PetscErrorCode (*conv)(DM, DMType, DM*) = NULL; 258267a56275SMatthew G Knepley 258367a56275SMatthew G Knepley /* 258467a56275SMatthew G Knepley Order of precedence: 258567a56275SMatthew G Knepley 1) See if a specialized converter is known to the current DM. 258667a56275SMatthew G Knepley 2) See if a specialized converter is known to the desired DM class. 258767a56275SMatthew G Knepley 3) See if a good general converter is registered for the desired class 258867a56275SMatthew G Knepley 4) See if a good general converter is known for the current matrix. 258967a56275SMatthew G Knepley 5) Use a really basic converter. 259067a56275SMatthew G Knepley */ 259167a56275SMatthew G Knepley 259267a56275SMatthew G Knepley /* 1) See if a specialized converter is known to the current DM and the desired class */ 259367a56275SMatthew G Knepley ierr = PetscStrcpy(convname,"DMConvert_");CHKERRQ(ierr); 259467a56275SMatthew G Knepley ierr = PetscStrcat(convname,((PetscObject) dm)->type_name);CHKERRQ(ierr); 259567a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_");CHKERRQ(ierr); 259667a56275SMatthew G Knepley ierr = PetscStrcat(convname,newtype);CHKERRQ(ierr); 259767a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_C");CHKERRQ(ierr); 25980005d66cSJed Brown ierr = PetscObjectQueryFunction((PetscObject)dm,convname,&conv);CHKERRQ(ierr); 259967a56275SMatthew G Knepley if (conv) goto foundconv; 260067a56275SMatthew G Knepley 260167a56275SMatthew G Knepley /* 2) See if a specialized converter is known to the desired DM class. */ 260282f516ccSBarry Smith ierr = DMCreate(PetscObjectComm((PetscObject)dm), &B);CHKERRQ(ierr); 260367a56275SMatthew G Knepley ierr = DMSetType(B, newtype);CHKERRQ(ierr); 260467a56275SMatthew G Knepley ierr = PetscStrcpy(convname,"DMConvert_");CHKERRQ(ierr); 260567a56275SMatthew G Knepley ierr = PetscStrcat(convname,((PetscObject) dm)->type_name);CHKERRQ(ierr); 260667a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_");CHKERRQ(ierr); 260767a56275SMatthew G Knepley ierr = PetscStrcat(convname,newtype);CHKERRQ(ierr); 260867a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_C");CHKERRQ(ierr); 26090005d66cSJed Brown ierr = PetscObjectQueryFunction((PetscObject)B,convname,&conv);CHKERRQ(ierr); 261067a56275SMatthew G Knepley if (conv) { 2611fcfd50ebSBarry Smith ierr = DMDestroy(&B);CHKERRQ(ierr); 261267a56275SMatthew G Knepley goto foundconv; 261367a56275SMatthew G Knepley } 261467a56275SMatthew G Knepley 261567a56275SMatthew G Knepley #if 0 261667a56275SMatthew G Knepley /* 3) See if a good general converter is registered for the desired class */ 261767a56275SMatthew G Knepley conv = B->ops->convertfrom; 2618fcfd50ebSBarry Smith ierr = DMDestroy(&B);CHKERRQ(ierr); 261967a56275SMatthew G Knepley if (conv) goto foundconv; 262067a56275SMatthew G Knepley 262167a56275SMatthew G Knepley /* 4) See if a good general converter is known for the current matrix */ 262267a56275SMatthew G Knepley if (dm->ops->convert) { 262367a56275SMatthew G Knepley conv = dm->ops->convert; 262467a56275SMatthew G Knepley } 262567a56275SMatthew G Knepley if (conv) goto foundconv; 262667a56275SMatthew G Knepley #endif 262767a56275SMatthew G Knepley 262867a56275SMatthew G Knepley /* 5) Use a really basic converter. */ 262982f516ccSBarry Smith SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "No conversion possible between DM types %s and %s", ((PetscObject) dm)->type_name, newtype); 263067a56275SMatthew G Knepley 263167a56275SMatthew G Knepley foundconv: 263267a56275SMatthew G Knepley ierr = PetscLogEventBegin(DM_Convert,dm,0,0,0);CHKERRQ(ierr); 263367a56275SMatthew G Knepley ierr = (*conv)(dm,newtype,M);CHKERRQ(ierr); 263467a56275SMatthew G Knepley ierr = PetscLogEventEnd(DM_Convert,dm,0,0,0);CHKERRQ(ierr); 263567a56275SMatthew G Knepley } 263667a56275SMatthew G Knepley ierr = PetscObjectStateIncrease((PetscObject) *M);CHKERRQ(ierr); 263767a56275SMatthew G Knepley PetscFunctionReturn(0); 263867a56275SMatthew G Knepley } 2639264ace61SBarry Smith 2640264ace61SBarry Smith /*--------------------------------------------------------------------------------------------------------------------*/ 2641264ace61SBarry Smith 2642264ace61SBarry Smith #undef __FUNCT__ 2643264ace61SBarry Smith #define __FUNCT__ "DMRegister" 2644264ace61SBarry Smith /*@C 26451c84c290SBarry Smith DMRegister - Adds a new DM component implementation 26461c84c290SBarry Smith 26471c84c290SBarry Smith Not Collective 26481c84c290SBarry Smith 26491c84c290SBarry Smith Input Parameters: 26501c84c290SBarry Smith + name - The name of a new user-defined creation routine 26511c84c290SBarry Smith - create_func - The creation routine itself 26521c84c290SBarry Smith 26531c84c290SBarry Smith Notes: 26541c84c290SBarry Smith DMRegister() may be called multiple times to add several user-defined DMs 26551c84c290SBarry Smith 26561c84c290SBarry Smith 26571c84c290SBarry Smith Sample usage: 26581c84c290SBarry Smith .vb 2659bdf89e91SBarry Smith DMRegister("my_da", MyDMCreate); 26601c84c290SBarry Smith .ve 26611c84c290SBarry Smith 26621c84c290SBarry Smith Then, your DM type can be chosen with the procedural interface via 26631c84c290SBarry Smith .vb 26641c84c290SBarry Smith DMCreate(MPI_Comm, DM *); 26651c84c290SBarry Smith DMSetType(DM,"my_da"); 26661c84c290SBarry Smith .ve 26671c84c290SBarry Smith or at runtime via the option 26681c84c290SBarry Smith .vb 26691c84c290SBarry Smith -da_type my_da 26701c84c290SBarry Smith .ve 2671264ace61SBarry Smith 2672264ace61SBarry Smith Level: advanced 26731c84c290SBarry Smith 26741c84c290SBarry Smith .keywords: DM, register 2675bdf89e91SBarry Smith .seealso: DMRegisterAll(), DMRegisterDestroy() 26761c84c290SBarry Smith 2677264ace61SBarry Smith @*/ 2678bdf89e91SBarry Smith PetscErrorCode DMRegister(const char sname[],PetscErrorCode (*function)(DM)) 2679264ace61SBarry Smith { 2680264ace61SBarry Smith PetscErrorCode ierr; 2681264ace61SBarry Smith 2682264ace61SBarry Smith PetscFunctionBegin; 2683a240a19fSJed Brown ierr = PetscFunctionListAdd(&DMList,sname,function);CHKERRQ(ierr); 2684264ace61SBarry Smith PetscFunctionReturn(0); 2685264ace61SBarry Smith } 2686264ace61SBarry Smith 2687b859378eSBarry Smith #undef __FUNCT__ 2688b859378eSBarry Smith #define __FUNCT__ "DMLoad" 2689b859378eSBarry Smith /*@C 269055849f57SBarry Smith DMLoad - Loads a DM that has been stored in binary with DMView(). 2691b859378eSBarry Smith 2692b859378eSBarry Smith Collective on PetscViewer 2693b859378eSBarry Smith 2694b859378eSBarry Smith Input Parameters: 2695b859378eSBarry Smith + newdm - the newly loaded DM, this needs to have been created with DMCreate() or 2696b859378eSBarry Smith some related function before a call to DMLoad(). 2697b859378eSBarry Smith - viewer - binary file viewer, obtained from PetscViewerBinaryOpen() or 2698b859378eSBarry Smith HDF5 file viewer, obtained from PetscViewerHDF5Open() 2699b859378eSBarry Smith 2700b859378eSBarry Smith Level: intermediate 2701b859378eSBarry Smith 2702b859378eSBarry Smith Notes: 270355849f57SBarry Smith The type is determined by the data in the file, any type set into the DM before this call is ignored. 2704b859378eSBarry Smith 2705b859378eSBarry Smith Notes for advanced users: 2706b859378eSBarry Smith Most users should not need to know the details of the binary storage 2707b859378eSBarry Smith format, since DMLoad() and DMView() completely hide these details. 2708b859378eSBarry Smith But for anyone who's interested, the standard binary matrix storage 2709b859378eSBarry Smith format is 2710b859378eSBarry Smith .vb 2711b859378eSBarry Smith has not yet been determined 2712b859378eSBarry Smith .ve 2713b859378eSBarry Smith 2714b859378eSBarry Smith .seealso: PetscViewerBinaryOpen(), DMView(), MatLoad(), VecLoad() 2715b859378eSBarry Smith @*/ 2716b859378eSBarry Smith PetscErrorCode DMLoad(DM newdm, PetscViewer viewer) 2717b859378eSBarry Smith { 27189331c7a4SMatthew G. Knepley PetscBool isbinary, ishdf5; 2719b859378eSBarry Smith PetscErrorCode ierr; 2720b859378eSBarry Smith 2721b859378eSBarry Smith PetscFunctionBegin; 2722b859378eSBarry Smith PetscValidHeaderSpecific(newdm,DM_CLASSID,1); 2723b859378eSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 272432c0f0efSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); 27259331c7a4SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERHDF5,&ishdf5);CHKERRQ(ierr); 27269331c7a4SMatthew G. Knepley if (isbinary) { 27279331c7a4SMatthew G. Knepley PetscInt classid; 27289331c7a4SMatthew G. Knepley char type[256]; 2729b859378eSBarry Smith 273032c0f0efSBarry Smith ierr = PetscViewerBinaryRead(viewer,&classid,1,PETSC_INT);CHKERRQ(ierr); 27319200755eSBarry Smith if (classid != DM_FILE_CLASSID) SETERRQ1(PetscObjectComm((PetscObject)newdm),PETSC_ERR_ARG_WRONG,"Not DM next in file, classid found %d",(int)classid); 273232c0f0efSBarry Smith ierr = PetscViewerBinaryRead(viewer,type,256,PETSC_CHAR);CHKERRQ(ierr); 273332c0f0efSBarry Smith ierr = DMSetType(newdm, type);CHKERRQ(ierr); 27349331c7a4SMatthew G. Knepley if (newdm->ops->load) {ierr = (*newdm->ops->load)(newdm,viewer);CHKERRQ(ierr);} 27359331c7a4SMatthew G. Knepley } else if (ishdf5) { 27369331c7a4SMatthew G. Knepley if (newdm->ops->load) {ierr = (*newdm->ops->load)(newdm,viewer);CHKERRQ(ierr);} 27379331c7a4SMatthew G. Knepley } else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Invalid viewer; open viewer with PetscViewerBinaryOpen() or PetscViewerHDF5Open()"); 2738b859378eSBarry Smith PetscFunctionReturn(0); 2739b859378eSBarry Smith } 2740b859378eSBarry Smith 27417da65231SMatthew G Knepley /******************************** FEM Support **********************************/ 27427da65231SMatthew G Knepley 27437da65231SMatthew G Knepley #undef __FUNCT__ 27447da65231SMatthew G Knepley #define __FUNCT__ "DMPrintCellVector" 2745a6dfd86eSKarl Rupp PetscErrorCode DMPrintCellVector(PetscInt c, const char name[], PetscInt len, const PetscScalar x[]) 2746a6dfd86eSKarl Rupp { 27471d47ebbbSSatish Balay PetscInt f; 27481b30c384SMatthew G Knepley PetscErrorCode ierr; 27491b30c384SMatthew G Knepley 27507da65231SMatthew G Knepley PetscFunctionBegin; 275174778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, "Cell %D Element %s\n", c, name);CHKERRQ(ierr); 27521d47ebbbSSatish Balay for (f = 0; f < len; ++f) { 275357622a8eSBarry Smith ierr = PetscPrintf(PETSC_COMM_SELF, " | %g |\n", (double)PetscRealPart(x[f]));CHKERRQ(ierr); 27547da65231SMatthew G Knepley } 27557da65231SMatthew G Knepley PetscFunctionReturn(0); 27567da65231SMatthew G Knepley } 27577da65231SMatthew G Knepley 27587da65231SMatthew G Knepley #undef __FUNCT__ 27597da65231SMatthew G Knepley #define __FUNCT__ "DMPrintCellMatrix" 2760a6dfd86eSKarl Rupp PetscErrorCode DMPrintCellMatrix(PetscInt c, const char name[], PetscInt rows, PetscInt cols, const PetscScalar A[]) 2761a6dfd86eSKarl Rupp { 27621b30c384SMatthew G Knepley PetscInt f, g; 27637da65231SMatthew G Knepley PetscErrorCode ierr; 27647da65231SMatthew G Knepley 27657da65231SMatthew G Knepley PetscFunctionBegin; 276674778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, "Cell %D Element %s\n", c, name);CHKERRQ(ierr); 27671d47ebbbSSatish Balay for (f = 0; f < rows; ++f) { 276874778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " |");CHKERRQ(ierr); 27691d47ebbbSSatish Balay for (g = 0; g < cols; ++g) { 2770e3556bceSMatthew G. Knepley ierr = PetscPrintf(PETSC_COMM_SELF, " % 9.5g", PetscRealPart(A[f*cols+g]));CHKERRQ(ierr); 27717da65231SMatthew G Knepley } 277274778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " |\n");CHKERRQ(ierr); 27737da65231SMatthew G Knepley } 27747da65231SMatthew G Knepley PetscFunctionReturn(0); 27757da65231SMatthew G Knepley } 2776e7c4fc90SDmitry Karpeev 2777970e74d5SMatthew G Knepley #undef __FUNCT__ 2778e759306cSMatthew G. Knepley #define __FUNCT__ "DMPrintLocalVec" 27796113b454SMatthew G. Knepley PetscErrorCode DMPrintLocalVec(DM dm, const char name[], PetscReal tol, Vec X) 2780e759306cSMatthew G. Knepley { 2781e759306cSMatthew G. Knepley PetscMPIInt rank, numProcs; 2782e759306cSMatthew G. Knepley PetscInt p; 2783e759306cSMatthew G. Knepley PetscErrorCode ierr; 2784e759306cSMatthew G. Knepley 2785e759306cSMatthew G. Knepley PetscFunctionBegin; 2786e759306cSMatthew G. Knepley ierr = MPI_Comm_rank(PetscObjectComm((PetscObject) dm), &rank);CHKERRQ(ierr); 2787e759306cSMatthew G. Knepley ierr = MPI_Comm_size(PetscObjectComm((PetscObject) dm), &numProcs);CHKERRQ(ierr); 2788e759306cSMatthew G. Knepley ierr = PetscPrintf(PetscObjectComm((PetscObject) dm), "%s:\n", name);CHKERRQ(ierr); 2789e759306cSMatthew G. Knepley for (p = 0; p < numProcs; ++p) { 2790e759306cSMatthew G. Knepley if (p == rank) { 2791e759306cSMatthew G. Knepley Vec x; 2792e759306cSMatthew G. Knepley 2793e759306cSMatthew G. Knepley ierr = VecDuplicate(X, &x);CHKERRQ(ierr); 2794e759306cSMatthew G. Knepley ierr = VecCopy(X, x);CHKERRQ(ierr); 27956113b454SMatthew G. Knepley ierr = VecChop(x, tol);CHKERRQ(ierr); 2796e759306cSMatthew G. Knepley ierr = VecView(x, PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); 2797e759306cSMatthew G. Knepley ierr = VecDestroy(&x);CHKERRQ(ierr); 2798e759306cSMatthew G. Knepley ierr = PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); 2799e759306cSMatthew G. Knepley } 2800e759306cSMatthew G. Knepley ierr = PetscBarrier((PetscObject) dm);CHKERRQ(ierr); 2801e759306cSMatthew G. Knepley } 2802e759306cSMatthew G. Knepley PetscFunctionReturn(0); 2803e759306cSMatthew G. Knepley } 2804e759306cSMatthew G. Knepley 2805e759306cSMatthew G. Knepley #undef __FUNCT__ 280688ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultSection" 280788ed4aceSMatthew G Knepley /*@ 280888ed4aceSMatthew G Knepley DMGetDefaultSection - Get the PetscSection encoding the local data layout for the DM. 280988ed4aceSMatthew G Knepley 281088ed4aceSMatthew G Knepley Input Parameter: 281188ed4aceSMatthew G Knepley . dm - The DM 281288ed4aceSMatthew G Knepley 281388ed4aceSMatthew G Knepley Output Parameter: 281488ed4aceSMatthew G Knepley . section - The PetscSection 281588ed4aceSMatthew G Knepley 281688ed4aceSMatthew G Knepley Level: intermediate 281788ed4aceSMatthew G Knepley 281888ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSection. 281988ed4aceSMatthew G Knepley 282088ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultGlobalSection() 282188ed4aceSMatthew G Knepley @*/ 28220adebc6cSBarry Smith PetscErrorCode DMGetDefaultSection(DM dm, PetscSection *section) 28230adebc6cSBarry Smith { 2824fd59a867SMatthew G. Knepley PetscErrorCode ierr; 2825fd59a867SMatthew G. Knepley 282688ed4aceSMatthew G Knepley PetscFunctionBegin; 282788ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 282888ed4aceSMatthew G Knepley PetscValidPointer(section, 2); 2829fd59a867SMatthew G. Knepley if (!dm->defaultSection && dm->ops->createdefaultsection) {ierr = (*dm->ops->createdefaultsection)(dm);CHKERRQ(ierr);} 283088ed4aceSMatthew G Knepley *section = dm->defaultSection; 283188ed4aceSMatthew G Knepley PetscFunctionReturn(0); 283288ed4aceSMatthew G Knepley } 283388ed4aceSMatthew G Knepley 283488ed4aceSMatthew G Knepley #undef __FUNCT__ 283588ed4aceSMatthew G Knepley #define __FUNCT__ "DMSetDefaultSection" 283688ed4aceSMatthew G Knepley /*@ 283788ed4aceSMatthew G Knepley DMSetDefaultSection - Set the PetscSection encoding the local data layout for the DM. 283888ed4aceSMatthew G Knepley 283988ed4aceSMatthew G Knepley Input Parameters: 284088ed4aceSMatthew G Knepley + dm - The DM 284188ed4aceSMatthew G Knepley - section - The PetscSection 284288ed4aceSMatthew G Knepley 284388ed4aceSMatthew G Knepley Level: intermediate 284488ed4aceSMatthew G Knepley 284588ed4aceSMatthew G Knepley Note: Any existing Section will be destroyed 284688ed4aceSMatthew G Knepley 284788ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultGlobalSection() 284888ed4aceSMatthew G Knepley @*/ 28490adebc6cSBarry Smith PetscErrorCode DMSetDefaultSection(DM dm, PetscSection section) 28500adebc6cSBarry Smith { 2851af122d2aSMatthew G Knepley PetscInt numFields; 2852af122d2aSMatthew G Knepley PetscInt f; 285388ed4aceSMatthew G Knepley PetscErrorCode ierr; 285488ed4aceSMatthew G Knepley 285588ed4aceSMatthew G Knepley PetscFunctionBegin; 285688ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 28571d799100SJed Brown PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 28581d799100SJed Brown ierr = PetscObjectReference((PetscObject)section);CHKERRQ(ierr); 285988ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&dm->defaultSection);CHKERRQ(ierr); 286088ed4aceSMatthew G Knepley dm->defaultSection = section; 2861af122d2aSMatthew G Knepley ierr = PetscSectionGetNumFields(dm->defaultSection, &numFields);CHKERRQ(ierr); 2862af122d2aSMatthew G Knepley if (numFields) { 2863af122d2aSMatthew G Knepley ierr = DMSetNumFields(dm, numFields);CHKERRQ(ierr); 2864af122d2aSMatthew G Knepley for (f = 0; f < numFields; ++f) { 28650f21e855SMatthew G. Knepley PetscObject disc; 2866af122d2aSMatthew G Knepley const char *name; 2867af122d2aSMatthew G Knepley 2868af122d2aSMatthew G Knepley ierr = PetscSectionGetFieldName(dm->defaultSection, f, &name);CHKERRQ(ierr); 28690f21e855SMatthew G. Knepley ierr = DMGetField(dm, f, &disc);CHKERRQ(ierr); 28700f21e855SMatthew G. Knepley ierr = PetscObjectSetName(disc, name);CHKERRQ(ierr); 2871af122d2aSMatthew G Knepley } 2872af122d2aSMatthew G Knepley } 28731d799100SJed Brown /* The global section will be rebuilt in the next call to DMGetDefaultGlobalSection(). */ 28741d799100SJed Brown ierr = PetscSectionDestroy(&dm->defaultGlobalSection);CHKERRQ(ierr); 287588ed4aceSMatthew G Knepley PetscFunctionReturn(0); 287688ed4aceSMatthew G Knepley } 287788ed4aceSMatthew G Knepley 287888ed4aceSMatthew G Knepley #undef __FUNCT__ 287988ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultGlobalSection" 288088ed4aceSMatthew G Knepley /*@ 288188ed4aceSMatthew G Knepley DMGetDefaultGlobalSection - Get the PetscSection encoding the global data layout for the DM. 288288ed4aceSMatthew G Knepley 28838b1ab98fSJed Brown Collective on DM 28848b1ab98fSJed Brown 288588ed4aceSMatthew G Knepley Input Parameter: 288688ed4aceSMatthew G Knepley . dm - The DM 288788ed4aceSMatthew G Knepley 288888ed4aceSMatthew G Knepley Output Parameter: 288988ed4aceSMatthew G Knepley . section - The PetscSection 289088ed4aceSMatthew G Knepley 289188ed4aceSMatthew G Knepley Level: intermediate 289288ed4aceSMatthew G Knepley 289388ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSection. 289488ed4aceSMatthew G Knepley 289588ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultSection() 289688ed4aceSMatthew G Knepley @*/ 28970adebc6cSBarry Smith PetscErrorCode DMGetDefaultGlobalSection(DM dm, PetscSection *section) 28980adebc6cSBarry Smith { 289988ed4aceSMatthew G Knepley PetscErrorCode ierr; 290088ed4aceSMatthew G Knepley 290188ed4aceSMatthew G Knepley PetscFunctionBegin; 290288ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 290388ed4aceSMatthew G Knepley PetscValidPointer(section, 2); 290488ed4aceSMatthew G Knepley if (!dm->defaultGlobalSection) { 2905fd59a867SMatthew G. Knepley PetscSection s; 2906fd59a867SMatthew G. Knepley 2907fd59a867SMatthew G. Knepley ierr = DMGetDefaultSection(dm, &s);CHKERRQ(ierr); 2908fd59a867SMatthew 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"); 2909fd59a867SMatthew 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"); 2910fd59a867SMatthew G. Knepley ierr = PetscSectionCreateGlobalSection(s, dm->sf, PETSC_FALSE, &dm->defaultGlobalSection);CHKERRQ(ierr); 2911cf06b437SMatthew G. Knepley ierr = PetscLayoutDestroy(&dm->map);CHKERRQ(ierr); 2912ce94432eSBarry Smith ierr = PetscSectionGetValueLayout(PetscObjectComm((PetscObject)dm), dm->defaultGlobalSection, &dm->map);CHKERRQ(ierr); 291388ed4aceSMatthew G Knepley } 291488ed4aceSMatthew G Knepley *section = dm->defaultGlobalSection; 291588ed4aceSMatthew G Knepley PetscFunctionReturn(0); 291688ed4aceSMatthew G Knepley } 291788ed4aceSMatthew G Knepley 291888ed4aceSMatthew G Knepley #undef __FUNCT__ 2919b21d0597SMatthew G Knepley #define __FUNCT__ "DMSetDefaultGlobalSection" 2920b21d0597SMatthew G Knepley /*@ 2921b21d0597SMatthew G Knepley DMSetDefaultGlobalSection - Set the PetscSection encoding the global data layout for the DM. 2922b21d0597SMatthew G Knepley 2923b21d0597SMatthew G Knepley Input Parameters: 2924b21d0597SMatthew G Knepley + dm - The DM 29255080bbdbSMatthew G Knepley - section - The PetscSection, or NULL 2926b21d0597SMatthew G Knepley 2927b21d0597SMatthew G Knepley Level: intermediate 2928b21d0597SMatthew G Knepley 2929b21d0597SMatthew G Knepley Note: Any existing Section will be destroyed 2930b21d0597SMatthew G Knepley 2931b21d0597SMatthew G Knepley .seealso: DMGetDefaultGlobalSection(), DMSetDefaultSection() 2932b21d0597SMatthew G Knepley @*/ 29330adebc6cSBarry Smith PetscErrorCode DMSetDefaultGlobalSection(DM dm, PetscSection section) 29340adebc6cSBarry Smith { 2935b21d0597SMatthew G Knepley PetscErrorCode ierr; 2936b21d0597SMatthew G Knepley 2937b21d0597SMatthew G Knepley PetscFunctionBegin; 2938b21d0597SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 29395080bbdbSMatthew G Knepley if (section) PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 29401d799100SJed Brown ierr = PetscObjectReference((PetscObject)section);CHKERRQ(ierr); 2941b21d0597SMatthew G Knepley ierr = PetscSectionDestroy(&dm->defaultGlobalSection);CHKERRQ(ierr); 2942b21d0597SMatthew G Knepley dm->defaultGlobalSection = section; 2943b21d0597SMatthew G Knepley PetscFunctionReturn(0); 2944b21d0597SMatthew G Knepley } 2945b21d0597SMatthew G Knepley 2946b21d0597SMatthew G Knepley #undef __FUNCT__ 294788ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultSF" 294888ed4aceSMatthew G Knepley /*@ 294988ed4aceSMatthew G Knepley DMGetDefaultSF - Get the PetscSF encoding the parallel dof overlap for the DM. If it has not been set, 295088ed4aceSMatthew G Knepley it is created from the default PetscSection layouts in the DM. 295188ed4aceSMatthew G Knepley 295288ed4aceSMatthew G Knepley Input Parameter: 295388ed4aceSMatthew G Knepley . dm - The DM 295488ed4aceSMatthew G Knepley 295588ed4aceSMatthew G Knepley Output Parameter: 295688ed4aceSMatthew G Knepley . sf - The PetscSF 295788ed4aceSMatthew G Knepley 295888ed4aceSMatthew G Knepley Level: intermediate 295988ed4aceSMatthew G Knepley 296088ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSF. 296188ed4aceSMatthew G Knepley 296288ed4aceSMatthew G Knepley .seealso: DMSetDefaultSF(), DMCreateDefaultSF() 296388ed4aceSMatthew G Knepley @*/ 29640adebc6cSBarry Smith PetscErrorCode DMGetDefaultSF(DM dm, PetscSF *sf) 29650adebc6cSBarry Smith { 296688ed4aceSMatthew G Knepley PetscInt nroots; 296788ed4aceSMatthew G Knepley PetscErrorCode ierr; 296888ed4aceSMatthew G Knepley 296988ed4aceSMatthew G Knepley PetscFunctionBegin; 297088ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 297188ed4aceSMatthew G Knepley PetscValidPointer(sf, 2); 29720298fd71SBarry Smith ierr = PetscSFGetGraph(dm->defaultSF, &nroots, NULL, NULL, NULL);CHKERRQ(ierr); 297388ed4aceSMatthew G Knepley if (nroots < 0) { 297488ed4aceSMatthew G Knepley PetscSection section, gSection; 297588ed4aceSMatthew G Knepley 297688ed4aceSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 297731ea6d37SMatthew G Knepley if (section) { 297888ed4aceSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, &gSection);CHKERRQ(ierr); 297988ed4aceSMatthew G Knepley ierr = DMCreateDefaultSF(dm, section, gSection);CHKERRQ(ierr); 298031ea6d37SMatthew G Knepley } else { 29810298fd71SBarry Smith *sf = NULL; 298231ea6d37SMatthew G Knepley PetscFunctionReturn(0); 298331ea6d37SMatthew G Knepley } 298488ed4aceSMatthew G Knepley } 298588ed4aceSMatthew G Knepley *sf = dm->defaultSF; 298688ed4aceSMatthew G Knepley PetscFunctionReturn(0); 298788ed4aceSMatthew G Knepley } 298888ed4aceSMatthew G Knepley 298988ed4aceSMatthew G Knepley #undef __FUNCT__ 299088ed4aceSMatthew G Knepley #define __FUNCT__ "DMSetDefaultSF" 299188ed4aceSMatthew G Knepley /*@ 299288ed4aceSMatthew G Knepley DMSetDefaultSF - Set the PetscSF encoding the parallel dof overlap for the DM 299388ed4aceSMatthew G Knepley 299488ed4aceSMatthew G Knepley Input Parameters: 299588ed4aceSMatthew G Knepley + dm - The DM 299688ed4aceSMatthew G Knepley - sf - The PetscSF 299788ed4aceSMatthew G Knepley 299888ed4aceSMatthew G Knepley Level: intermediate 299988ed4aceSMatthew G Knepley 300088ed4aceSMatthew G Knepley Note: Any previous SF is destroyed 300188ed4aceSMatthew G Knepley 300288ed4aceSMatthew G Knepley .seealso: DMGetDefaultSF(), DMCreateDefaultSF() 300388ed4aceSMatthew G Knepley @*/ 30040adebc6cSBarry Smith PetscErrorCode DMSetDefaultSF(DM dm, PetscSF sf) 30050adebc6cSBarry Smith { 300688ed4aceSMatthew G Knepley PetscErrorCode ierr; 300788ed4aceSMatthew G Knepley 300888ed4aceSMatthew G Knepley PetscFunctionBegin; 300988ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 301088ed4aceSMatthew G Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 301188ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&dm->defaultSF);CHKERRQ(ierr); 301288ed4aceSMatthew G Knepley dm->defaultSF = sf; 301388ed4aceSMatthew G Knepley PetscFunctionReturn(0); 301488ed4aceSMatthew G Knepley } 301588ed4aceSMatthew G Knepley 301688ed4aceSMatthew G Knepley #undef __FUNCT__ 301788ed4aceSMatthew G Knepley #define __FUNCT__ "DMCreateDefaultSF" 301888ed4aceSMatthew G Knepley /*@C 301988ed4aceSMatthew G Knepley DMCreateDefaultSF - Create the PetscSF encoding the parallel dof overlap for the DM based upon the PetscSections 302088ed4aceSMatthew G Knepley describing the data layout. 302188ed4aceSMatthew G Knepley 302288ed4aceSMatthew G Knepley Input Parameters: 302388ed4aceSMatthew G Knepley + dm - The DM 302488ed4aceSMatthew G Knepley . localSection - PetscSection describing the local data layout 302588ed4aceSMatthew G Knepley - globalSection - PetscSection describing the global data layout 302688ed4aceSMatthew G Knepley 302788ed4aceSMatthew G Knepley Level: intermediate 302888ed4aceSMatthew G Knepley 302988ed4aceSMatthew G Knepley .seealso: DMGetDefaultSF(), DMSetDefaultSF() 303088ed4aceSMatthew G Knepley @*/ 303188ed4aceSMatthew G Knepley PetscErrorCode DMCreateDefaultSF(DM dm, PetscSection localSection, PetscSection globalSection) 303288ed4aceSMatthew G Knepley { 303382f516ccSBarry Smith MPI_Comm comm; 303488ed4aceSMatthew G Knepley PetscLayout layout; 303588ed4aceSMatthew G Knepley const PetscInt *ranges; 303688ed4aceSMatthew G Knepley PetscInt *local; 303788ed4aceSMatthew G Knepley PetscSFNode *remote; 3038ecd73843SMatthew G. Knepley PetscInt pStart, pEnd, p, nroots, nleaves = 0, l; 303988ed4aceSMatthew G Knepley PetscMPIInt size, rank; 304088ed4aceSMatthew G Knepley PetscErrorCode ierr; 304188ed4aceSMatthew G Knepley 304288ed4aceSMatthew G Knepley PetscFunctionBegin; 304382f516ccSBarry Smith ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 304488ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 304588ed4aceSMatthew G Knepley ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); 304688ed4aceSMatthew G Knepley ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); 304788ed4aceSMatthew G Knepley ierr = PetscSectionGetChart(globalSection, &pStart, &pEnd);CHKERRQ(ierr); 304888ed4aceSMatthew G Knepley ierr = PetscSectionGetConstrainedStorageSize(globalSection, &nroots);CHKERRQ(ierr); 304988ed4aceSMatthew G Knepley ierr = PetscLayoutCreate(comm, &layout);CHKERRQ(ierr); 305088ed4aceSMatthew G Knepley ierr = PetscLayoutSetBlockSize(layout, 1);CHKERRQ(ierr); 305188ed4aceSMatthew G Knepley ierr = PetscLayoutSetLocalSize(layout, nroots);CHKERRQ(ierr); 305288ed4aceSMatthew G Knepley ierr = PetscLayoutSetUp(layout);CHKERRQ(ierr); 305388ed4aceSMatthew G Knepley ierr = PetscLayoutGetRanges(layout, &ranges);CHKERRQ(ierr); 3054ecd73843SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 30556636e97aSMatthew G Knepley PetscInt gdof, gcdof; 305688ed4aceSMatthew G Knepley 30576636e97aSMatthew G Knepley ierr = PetscSectionGetDof(globalSection, p, &gdof);CHKERRQ(ierr); 30586636e97aSMatthew G Knepley ierr = PetscSectionGetConstraintDof(globalSection, p, &gcdof);CHKERRQ(ierr); 3059235fbf56SMatthew 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)); 30606636e97aSMatthew G Knepley nleaves += gdof < 0 ? -(gdof+1)-gcdof : gdof-gcdof; 306188ed4aceSMatthew G Knepley } 3062785e854fSJed Brown ierr = PetscMalloc1(nleaves, &local);CHKERRQ(ierr); 3063785e854fSJed Brown ierr = PetscMalloc1(nleaves, &remote);CHKERRQ(ierr); 306488ed4aceSMatthew G Knepley for (p = pStart, l = 0; p < pEnd; ++p) { 30651f588964SMatthew G Knepley const PetscInt *cind; 30666636e97aSMatthew G Knepley PetscInt dof, cdof, off, gdof, gcdof, goff, gsize, d, c; 306788ed4aceSMatthew G Knepley 306888ed4aceSMatthew G Knepley ierr = PetscSectionGetDof(localSection, p, &dof);CHKERRQ(ierr); 306988ed4aceSMatthew G Knepley ierr = PetscSectionGetOffset(localSection, p, &off);CHKERRQ(ierr); 307088ed4aceSMatthew G Knepley ierr = PetscSectionGetConstraintDof(localSection, p, &cdof);CHKERRQ(ierr); 307188ed4aceSMatthew G Knepley ierr = PetscSectionGetConstraintIndices(localSection, p, &cind);CHKERRQ(ierr); 307288ed4aceSMatthew G Knepley ierr = PetscSectionGetDof(globalSection, p, &gdof);CHKERRQ(ierr); 30736636e97aSMatthew G Knepley ierr = PetscSectionGetConstraintDof(globalSection, p, &gcdof);CHKERRQ(ierr); 307488ed4aceSMatthew G Knepley ierr = PetscSectionGetOffset(globalSection, p, &goff);CHKERRQ(ierr); 30756636e97aSMatthew G Knepley if (!gdof) continue; /* Censored point */ 30766636e97aSMatthew G Knepley gsize = gdof < 0 ? -(gdof+1)-gcdof : gdof-gcdof; 30776636e97aSMatthew G Knepley if (gsize != dof-cdof) { 3078057b4bcdSMatthew 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); 30796636e97aSMatthew G Knepley cdof = 0; /* Ignore constraints */ 30806636e97aSMatthew G Knepley } 308188ed4aceSMatthew G Knepley for (d = 0, c = 0; d < dof; ++d) { 308288ed4aceSMatthew G Knepley if ((c < cdof) && (cind[c] == d)) {++c; continue;} 308388ed4aceSMatthew G Knepley local[l+d-c] = off+d; 308488ed4aceSMatthew G Knepley } 308588ed4aceSMatthew G Knepley if (gdof < 0) { 30866636e97aSMatthew G Knepley for (d = 0; d < gsize; ++d, ++l) { 308788ed4aceSMatthew G Knepley PetscInt offset = -(goff+1) + d, r; 308888ed4aceSMatthew G Knepley 308905376888SMatthew G. Knepley ierr = PetscFindInt(offset,size+1,ranges,&r);CHKERRQ(ierr); 309031d3f06eSJed Brown if (r < 0) r = -(r+2); 309105376888SMatthew 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); 309288ed4aceSMatthew G Knepley remote[l].rank = r; 309388ed4aceSMatthew G Knepley remote[l].index = offset - ranges[r]; 309488ed4aceSMatthew G Knepley } 309588ed4aceSMatthew G Knepley } else { 30966636e97aSMatthew G Knepley for (d = 0; d < gsize; ++d, ++l) { 309788ed4aceSMatthew G Knepley remote[l].rank = rank; 309888ed4aceSMatthew G Knepley remote[l].index = goff+d - ranges[rank]; 309988ed4aceSMatthew G Knepley } 310088ed4aceSMatthew G Knepley } 310188ed4aceSMatthew G Knepley } 31026636e97aSMatthew G Knepley if (l != nleaves) SETERRQ2(comm, PETSC_ERR_PLIB, "Iteration error, l %d != nleaves %d", l, nleaves); 310388ed4aceSMatthew G Knepley ierr = PetscLayoutDestroy(&layout);CHKERRQ(ierr); 310488ed4aceSMatthew G Knepley ierr = PetscSFSetGraph(dm->defaultSF, nroots, nleaves, local, PETSC_OWN_POINTER, remote, PETSC_OWN_POINTER);CHKERRQ(ierr); 310588ed4aceSMatthew G Knepley PetscFunctionReturn(0); 310688ed4aceSMatthew G Knepley } 3107af122d2aSMatthew G Knepley 3108af122d2aSMatthew G Knepley #undef __FUNCT__ 3109b21d0597SMatthew G Knepley #define __FUNCT__ "DMGetPointSF" 3110b21d0597SMatthew G Knepley /*@ 3111b21d0597SMatthew G Knepley DMGetPointSF - Get the PetscSF encoding the parallel section point overlap for the DM. 3112b21d0597SMatthew G Knepley 3113b21d0597SMatthew G Knepley Input Parameter: 3114b21d0597SMatthew G Knepley . dm - The DM 3115b21d0597SMatthew G Knepley 3116b21d0597SMatthew G Knepley Output Parameter: 3117b21d0597SMatthew G Knepley . sf - The PetscSF 3118b21d0597SMatthew G Knepley 3119b21d0597SMatthew G Knepley Level: intermediate 3120b21d0597SMatthew G Knepley 3121b21d0597SMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSF. 3122b21d0597SMatthew G Knepley 3123057b4bcdSMatthew G Knepley .seealso: DMSetPointSF(), DMGetDefaultSF(), DMSetDefaultSF(), DMCreateDefaultSF() 3124b21d0597SMatthew G Knepley @*/ 31250adebc6cSBarry Smith PetscErrorCode DMGetPointSF(DM dm, PetscSF *sf) 31260adebc6cSBarry Smith { 3127b21d0597SMatthew G Knepley PetscFunctionBegin; 3128b21d0597SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3129b21d0597SMatthew G Knepley PetscValidPointer(sf, 2); 3130b21d0597SMatthew G Knepley *sf = dm->sf; 3131b21d0597SMatthew G Knepley PetscFunctionReturn(0); 3132b21d0597SMatthew G Knepley } 3133b21d0597SMatthew G Knepley 3134b21d0597SMatthew G Knepley #undef __FUNCT__ 3135057b4bcdSMatthew G Knepley #define __FUNCT__ "DMSetPointSF" 3136057b4bcdSMatthew G Knepley /*@ 3137057b4bcdSMatthew G Knepley DMSetPointSF - Set the PetscSF encoding the parallel section point overlap for the DM. 3138057b4bcdSMatthew G Knepley 3139057b4bcdSMatthew G Knepley Input Parameters: 3140057b4bcdSMatthew G Knepley + dm - The DM 3141057b4bcdSMatthew G Knepley - sf - The PetscSF 3142057b4bcdSMatthew G Knepley 3143057b4bcdSMatthew G Knepley Level: intermediate 3144057b4bcdSMatthew G Knepley 3145057b4bcdSMatthew G Knepley .seealso: DMGetPointSF(), DMGetDefaultSF(), DMSetDefaultSF(), DMCreateDefaultSF() 3146057b4bcdSMatthew G Knepley @*/ 31470adebc6cSBarry Smith PetscErrorCode DMSetPointSF(DM dm, PetscSF sf) 31480adebc6cSBarry Smith { 3149057b4bcdSMatthew G Knepley PetscErrorCode ierr; 3150057b4bcdSMatthew G Knepley 3151057b4bcdSMatthew G Knepley PetscFunctionBegin; 3152057b4bcdSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3153057b4bcdSMatthew G Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 1); 3154057b4bcdSMatthew G Knepley ierr = PetscSFDestroy(&dm->sf);CHKERRQ(ierr); 3155057b4bcdSMatthew G Knepley ierr = PetscObjectReference((PetscObject) sf);CHKERRQ(ierr); 3156057b4bcdSMatthew G Knepley dm->sf = sf; 3157057b4bcdSMatthew G Knepley PetscFunctionReturn(0); 3158057b4bcdSMatthew G Knepley } 3159057b4bcdSMatthew G Knepley 3160057b4bcdSMatthew G Knepley #undef __FUNCT__ 31612764a2aaSMatthew G. Knepley #define __FUNCT__ "DMGetDS" 31622764a2aaSMatthew G. Knepley /*@ 31632764a2aaSMatthew G. Knepley DMGetDS - Get the PetscDS 31642764a2aaSMatthew G. Knepley 31652764a2aaSMatthew G. Knepley Input Parameter: 31662764a2aaSMatthew G. Knepley . dm - The DM 31672764a2aaSMatthew G. Knepley 31682764a2aaSMatthew G. Knepley Output Parameter: 31692764a2aaSMatthew G. Knepley . prob - The PetscDS 31702764a2aaSMatthew G. Knepley 31712764a2aaSMatthew G. Knepley Level: developer 31722764a2aaSMatthew G. Knepley 31732764a2aaSMatthew G. Knepley .seealso: DMSetDS() 31742764a2aaSMatthew G. Knepley @*/ 31752764a2aaSMatthew G. Knepley PetscErrorCode DMGetDS(DM dm, PetscDS *prob) 3176af122d2aSMatthew G Knepley { 3177af122d2aSMatthew G Knepley PetscFunctionBegin; 3178af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 31790f21e855SMatthew G. Knepley PetscValidPointer(prob, 2); 31800f21e855SMatthew G. Knepley *prob = dm->prob; 31810f21e855SMatthew G. Knepley PetscFunctionReturn(0); 31820f21e855SMatthew G. Knepley } 31830f21e855SMatthew G. Knepley 31840f21e855SMatthew G. Knepley #undef __FUNCT__ 31852764a2aaSMatthew G. Knepley #define __FUNCT__ "DMSetDS" 31862764a2aaSMatthew G. Knepley /*@ 31872764a2aaSMatthew G. Knepley DMSetDS - Set the PetscDS 31882764a2aaSMatthew G. Knepley 31892764a2aaSMatthew G. Knepley Input Parameters: 31902764a2aaSMatthew G. Knepley + dm - The DM 31912764a2aaSMatthew G. Knepley - prob - The PetscDS 31922764a2aaSMatthew G. Knepley 31932764a2aaSMatthew G. Knepley Level: developer 31942764a2aaSMatthew G. Knepley 31952764a2aaSMatthew G. Knepley .seealso: DMGetDS() 31962764a2aaSMatthew G. Knepley @*/ 31972764a2aaSMatthew G. Knepley PetscErrorCode DMSetDS(DM dm, PetscDS prob) 31980f21e855SMatthew G. Knepley { 31990f21e855SMatthew G. Knepley PetscErrorCode ierr; 32000f21e855SMatthew G. Knepley 32010f21e855SMatthew G. Knepley PetscFunctionBegin; 32020f21e855SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 32032764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 2); 32042764a2aaSMatthew G. Knepley ierr = PetscDSDestroy(&dm->prob);CHKERRQ(ierr); 32050f21e855SMatthew G. Knepley dm->prob = prob; 32060f21e855SMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm->prob);CHKERRQ(ierr); 32070f21e855SMatthew G. Knepley PetscFunctionReturn(0); 32080f21e855SMatthew G. Knepley } 32090f21e855SMatthew G. Knepley 32100f21e855SMatthew G. Knepley #undef __FUNCT__ 32110f21e855SMatthew G. Knepley #define __FUNCT__ "DMGetNumFields" 32120f21e855SMatthew G. Knepley PetscErrorCode DMGetNumFields(DM dm, PetscInt *numFields) 32130f21e855SMatthew G. Knepley { 32140f21e855SMatthew G. Knepley PetscErrorCode ierr; 32150f21e855SMatthew G. Knepley 32160f21e855SMatthew G. Knepley PetscFunctionBegin; 32170f21e855SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 32182764a2aaSMatthew G. Knepley ierr = PetscDSGetNumFields(dm->prob, numFields);CHKERRQ(ierr); 3219af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3220af122d2aSMatthew G Knepley } 3221af122d2aSMatthew G Knepley 3222af122d2aSMatthew G Knepley #undef __FUNCT__ 3223af122d2aSMatthew G Knepley #define __FUNCT__ "DMSetNumFields" 3224af122d2aSMatthew G Knepley PetscErrorCode DMSetNumFields(DM dm, PetscInt numFields) 3225af122d2aSMatthew G Knepley { 32260f21e855SMatthew G. Knepley PetscInt Nf, f; 3227af122d2aSMatthew G Knepley PetscErrorCode ierr; 3228af122d2aSMatthew G Knepley 3229af122d2aSMatthew G Knepley PetscFunctionBegin; 3230af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 32312764a2aaSMatthew G. Knepley ierr = PetscDSGetNumFields(dm->prob, &Nf);CHKERRQ(ierr); 32320f21e855SMatthew G. Knepley for (f = Nf; f < numFields; ++f) { 32330f21e855SMatthew G. Knepley PetscContainer obj; 32340f21e855SMatthew G. Knepley 32350f21e855SMatthew G. Knepley ierr = PetscContainerCreate(PetscObjectComm((PetscObject) dm), &obj);CHKERRQ(ierr); 32362764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(dm->prob, f, (PetscObject) obj);CHKERRQ(ierr); 32370f21e855SMatthew G. Knepley ierr = PetscContainerDestroy(&obj);CHKERRQ(ierr); 3238af122d2aSMatthew G Knepley } 3239af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3240af122d2aSMatthew G Knepley } 3241af122d2aSMatthew G Knepley 3242af122d2aSMatthew G Knepley #undef __FUNCT__ 3243af122d2aSMatthew G Knepley #define __FUNCT__ "DMGetField" 3244c1929be8SMatthew G. Knepley /*@ 3245c1929be8SMatthew G. Knepley DMGetField - Return the discretization object for a given DM field 3246c1929be8SMatthew G. Knepley 3247c1929be8SMatthew G. Knepley Not collective 3248c1929be8SMatthew G. Knepley 3249c1929be8SMatthew G. Knepley Input Parameters: 3250c1929be8SMatthew G. Knepley + dm - The DM 3251c1929be8SMatthew G. Knepley - f - The field number 3252c1929be8SMatthew G. Knepley 3253c1929be8SMatthew G. Knepley Output Parameter: 3254c1929be8SMatthew G. Knepley . field - The discretization object 3255c1929be8SMatthew G. Knepley 3256c1929be8SMatthew G. Knepley Level: developer 3257c1929be8SMatthew G. Knepley 3258c1929be8SMatthew G. Knepley .seealso: DMSetField() 3259c1929be8SMatthew G. Knepley @*/ 3260af122d2aSMatthew G Knepley PetscErrorCode DMGetField(DM dm, PetscInt f, PetscObject *field) 3261af122d2aSMatthew G Knepley { 32620f21e855SMatthew G. Knepley PetscErrorCode ierr; 32630f21e855SMatthew G. Knepley 3264af122d2aSMatthew G Knepley PetscFunctionBegin; 3265af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 32662764a2aaSMatthew G. Knepley ierr = PetscDSGetDiscretization(dm->prob, f, field);CHKERRQ(ierr); 3267decb47aaSMatthew G. Knepley PetscFunctionReturn(0); 3268decb47aaSMatthew G. Knepley } 3269decb47aaSMatthew G. Knepley 3270decb47aaSMatthew G. Knepley #undef __FUNCT__ 3271decb47aaSMatthew G. Knepley #define __FUNCT__ "DMSetField" 3272c1929be8SMatthew G. Knepley /*@ 3273c1929be8SMatthew G. Knepley DMSetField - Set the discretization object for a given DM field 3274c1929be8SMatthew G. Knepley 3275c1929be8SMatthew G. Knepley Logically collective on DM 3276c1929be8SMatthew G. Knepley 3277c1929be8SMatthew G. Knepley Input Parameters: 3278c1929be8SMatthew G. Knepley + dm - The DM 3279c1929be8SMatthew G. Knepley . f - The field number 3280c1929be8SMatthew G. Knepley - field - The discretization object 3281c1929be8SMatthew G. Knepley 3282c1929be8SMatthew G. Knepley Level: developer 3283c1929be8SMatthew G. Knepley 3284c1929be8SMatthew G. Knepley .seealso: DMGetField() 3285c1929be8SMatthew G. Knepley @*/ 3286decb47aaSMatthew G. Knepley PetscErrorCode DMSetField(DM dm, PetscInt f, PetscObject field) 3287decb47aaSMatthew G. Knepley { 3288decb47aaSMatthew G. Knepley PetscErrorCode ierr; 3289decb47aaSMatthew G. Knepley 3290decb47aaSMatthew G. Knepley PetscFunctionBegin; 3291decb47aaSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 32922764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(dm->prob, f, field);CHKERRQ(ierr); 3293af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3294af122d2aSMatthew G Knepley } 32956636e97aSMatthew G Knepley 32966636e97aSMatthew G Knepley #undef __FUNCT__ 3297b64e0483SPeter Brune #define __FUNCT__ "DMRestrictHook_Coordinates" 3298b64e0483SPeter Brune PetscErrorCode DMRestrictHook_Coordinates(DM dm,DM dmc,void *ctx) 3299b64e0483SPeter Brune { 3300b64e0483SPeter Brune DM dm_coord,dmc_coord; 3301b64e0483SPeter Brune PetscErrorCode ierr; 3302b64e0483SPeter Brune Vec coords,ccoords; 3303b64e0483SPeter Brune VecScatter scat; 3304b64e0483SPeter Brune PetscFunctionBegin; 3305b64e0483SPeter Brune ierr = DMGetCoordinateDM(dm,&dm_coord);CHKERRQ(ierr); 3306b64e0483SPeter Brune ierr = DMGetCoordinateDM(dmc,&dmc_coord);CHKERRQ(ierr); 3307b64e0483SPeter Brune ierr = DMGetCoordinates(dm,&coords);CHKERRQ(ierr); 3308b64e0483SPeter Brune ierr = DMGetCoordinates(dmc,&ccoords);CHKERRQ(ierr); 3309b64e0483SPeter Brune if (coords && !ccoords) { 3310b64e0483SPeter Brune ierr = DMCreateGlobalVector(dmc_coord,&ccoords);CHKERRQ(ierr); 3311b64e0483SPeter Brune ierr = DMCreateInjection(dmc_coord,dm_coord,&scat);CHKERRQ(ierr); 3312b64e0483SPeter Brune ierr = VecScatterBegin(scat,coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 3313b64e0483SPeter Brune ierr = VecScatterEnd(scat,coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 3314b64e0483SPeter Brune ierr = DMSetCoordinates(dmc,ccoords);CHKERRQ(ierr); 3315b64e0483SPeter Brune ierr = VecScatterDestroy(&scat);CHKERRQ(ierr); 3316b64e0483SPeter Brune ierr = VecDestroy(&ccoords);CHKERRQ(ierr); 3317b64e0483SPeter Brune } 3318b64e0483SPeter Brune PetscFunctionReturn(0); 3319b64e0483SPeter Brune } 3320b64e0483SPeter Brune 3321b64e0483SPeter Brune #undef __FUNCT__ 332203dadc2fSPeter Brune #define __FUNCT__ "DMSubDomainHook_Coordinates" 332303dadc2fSPeter Brune static PetscErrorCode DMSubDomainHook_Coordinates(DM dm,DM subdm,void *ctx) 332403dadc2fSPeter Brune { 332503dadc2fSPeter Brune DM dm_coord,subdm_coord; 332603dadc2fSPeter Brune PetscErrorCode ierr; 332703dadc2fSPeter Brune Vec coords,ccoords,clcoords; 332803dadc2fSPeter Brune VecScatter *scat_i,*scat_g; 332903dadc2fSPeter Brune PetscFunctionBegin; 333003dadc2fSPeter Brune ierr = DMGetCoordinateDM(dm,&dm_coord);CHKERRQ(ierr); 333103dadc2fSPeter Brune ierr = DMGetCoordinateDM(subdm,&subdm_coord);CHKERRQ(ierr); 333203dadc2fSPeter Brune ierr = DMGetCoordinates(dm,&coords);CHKERRQ(ierr); 333303dadc2fSPeter Brune ierr = DMGetCoordinates(subdm,&ccoords);CHKERRQ(ierr); 333403dadc2fSPeter Brune if (coords && !ccoords) { 333503dadc2fSPeter Brune ierr = DMCreateGlobalVector(subdm_coord,&ccoords);CHKERRQ(ierr); 333603dadc2fSPeter Brune ierr = DMCreateLocalVector(subdm_coord,&clcoords);CHKERRQ(ierr); 333703dadc2fSPeter Brune ierr = DMCreateDomainDecompositionScatters(dm_coord,1,&subdm_coord,NULL,&scat_i,&scat_g);CHKERRQ(ierr); 333803dadc2fSPeter Brune ierr = VecScatterBegin(scat_i[0],coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 333903dadc2fSPeter Brune ierr = VecScatterBegin(scat_g[0],coords,clcoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 334003dadc2fSPeter Brune ierr = VecScatterEnd(scat_i[0],coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 334103dadc2fSPeter Brune ierr = VecScatterEnd(scat_g[0],coords,clcoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 334203dadc2fSPeter Brune ierr = DMSetCoordinates(subdm,ccoords);CHKERRQ(ierr); 334303dadc2fSPeter Brune ierr = DMSetCoordinatesLocal(subdm,clcoords);CHKERRQ(ierr); 334403dadc2fSPeter Brune ierr = VecScatterDestroy(&scat_i[0]);CHKERRQ(ierr); 334503dadc2fSPeter Brune ierr = VecScatterDestroy(&scat_g[0]);CHKERRQ(ierr); 334603dadc2fSPeter Brune ierr = VecDestroy(&ccoords);CHKERRQ(ierr); 334703dadc2fSPeter Brune ierr = VecDestroy(&clcoords);CHKERRQ(ierr); 334803dadc2fSPeter Brune ierr = PetscFree(scat_i);CHKERRQ(ierr); 334903dadc2fSPeter Brune ierr = PetscFree(scat_g);CHKERRQ(ierr); 335003dadc2fSPeter Brune } 335103dadc2fSPeter Brune PetscFunctionReturn(0); 335203dadc2fSPeter Brune } 335303dadc2fSPeter Brune 335403dadc2fSPeter Brune #undef __FUNCT__ 33556636e97aSMatthew G Knepley #define __FUNCT__ "DMSetCoordinates" 33566636e97aSMatthew G Knepley /*@ 33576636e97aSMatthew G Knepley DMSetCoordinates - Sets into the DM a global vector that holds the coordinates 33586636e97aSMatthew G Knepley 33596636e97aSMatthew G Knepley Collective on DM 33606636e97aSMatthew G Knepley 33616636e97aSMatthew G Knepley Input Parameters: 33626636e97aSMatthew G Knepley + dm - the DM 33636636e97aSMatthew G Knepley - c - coordinate vector 33646636e97aSMatthew G Knepley 33656636e97aSMatthew G Knepley Note: 33666636e97aSMatthew G Knepley The coordinates do include those for ghost points, which are in the local vector 33676636e97aSMatthew G Knepley 33686636e97aSMatthew G Knepley Level: intermediate 33696636e97aSMatthew G Knepley 33706636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 33716636e97aSMatthew G Knepley .seealso: DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLoca(), DMGetCoordinateDM() 33726636e97aSMatthew G Knepley @*/ 33736636e97aSMatthew G Knepley PetscErrorCode DMSetCoordinates(DM dm, Vec c) 33746636e97aSMatthew G Knepley { 33756636e97aSMatthew G Knepley PetscErrorCode ierr; 33766636e97aSMatthew G Knepley 33776636e97aSMatthew G Knepley PetscFunctionBegin; 33786636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 33796636e97aSMatthew G Knepley PetscValidHeaderSpecific(c,VEC_CLASSID,2); 33806636e97aSMatthew G Knepley ierr = PetscObjectReference((PetscObject) c);CHKERRQ(ierr); 33816636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinates);CHKERRQ(ierr); 33826636e97aSMatthew G Knepley dm->coordinates = c; 33836636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinatesLocal);CHKERRQ(ierr); 3384b64e0483SPeter Brune ierr = DMCoarsenHookAdd(dm,DMRestrictHook_Coordinates,NULL,NULL);CHKERRQ(ierr); 338503dadc2fSPeter Brune ierr = DMSubDomainHookAdd(dm,DMSubDomainHook_Coordinates,NULL,NULL);CHKERRQ(ierr); 33866636e97aSMatthew G Knepley PetscFunctionReturn(0); 33876636e97aSMatthew G Knepley } 33886636e97aSMatthew G Knepley 33896636e97aSMatthew G Knepley #undef __FUNCT__ 33906636e97aSMatthew G Knepley #define __FUNCT__ "DMSetCoordinatesLocal" 33916636e97aSMatthew G Knepley /*@ 33926636e97aSMatthew G Knepley DMSetCoordinatesLocal - Sets into the DM a local vector that holds the coordinates 33936636e97aSMatthew G Knepley 33946636e97aSMatthew G Knepley Collective on DM 33956636e97aSMatthew G Knepley 33966636e97aSMatthew G Knepley Input Parameters: 33976636e97aSMatthew G Knepley + dm - the DM 33986636e97aSMatthew G Knepley - c - coordinate vector 33996636e97aSMatthew G Knepley 34006636e97aSMatthew G Knepley Note: 34016636e97aSMatthew G Knepley The coordinates of ghost points can be set using DMSetCoordinates() 34026636e97aSMatthew G Knepley followed by DMGetCoordinatesLocal(). This is intended to enable the 34036636e97aSMatthew G Knepley setting of ghost coordinates outside of the domain. 34046636e97aSMatthew G Knepley 34056636e97aSMatthew G Knepley Level: intermediate 34066636e97aSMatthew G Knepley 34076636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 34086636e97aSMatthew G Knepley .seealso: DMGetCoordinatesLocal(), DMSetCoordinates(), DMGetCoordinates(), DMGetCoordinateDM() 34096636e97aSMatthew G Knepley @*/ 34106636e97aSMatthew G Knepley PetscErrorCode DMSetCoordinatesLocal(DM dm, Vec c) 34116636e97aSMatthew G Knepley { 34126636e97aSMatthew G Knepley PetscErrorCode ierr; 34136636e97aSMatthew G Knepley 34146636e97aSMatthew G Knepley PetscFunctionBegin; 34156636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 34166636e97aSMatthew G Knepley PetscValidHeaderSpecific(c,VEC_CLASSID,2); 34176636e97aSMatthew G Knepley ierr = PetscObjectReference((PetscObject) c);CHKERRQ(ierr); 34186636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinatesLocal);CHKERRQ(ierr); 34198865f1eaSKarl Rupp 34206636e97aSMatthew G Knepley dm->coordinatesLocal = c; 34218865f1eaSKarl Rupp 34226636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinates);CHKERRQ(ierr); 34236636e97aSMatthew G Knepley PetscFunctionReturn(0); 34246636e97aSMatthew G Knepley } 34256636e97aSMatthew G Knepley 34266636e97aSMatthew G Knepley #undef __FUNCT__ 34276636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinates" 34286636e97aSMatthew G Knepley /*@ 34296636e97aSMatthew G Knepley DMGetCoordinates - Gets a global vector with the coordinates associated with the DM. 34306636e97aSMatthew G Knepley 34316636e97aSMatthew G Knepley Not Collective 34326636e97aSMatthew G Knepley 34336636e97aSMatthew G Knepley Input Parameter: 34346636e97aSMatthew G Knepley . dm - the DM 34356636e97aSMatthew G Knepley 34366636e97aSMatthew G Knepley Output Parameter: 34376636e97aSMatthew G Knepley . c - global coordinate vector 34386636e97aSMatthew G Knepley 34396636e97aSMatthew G Knepley Note: 34406636e97aSMatthew G Knepley This is a borrowed reference, so the user should NOT destroy this vector 34416636e97aSMatthew G Knepley 34426636e97aSMatthew G Knepley Each process has only the local coordinates (does NOT have the ghost coordinates). 34436636e97aSMatthew G Knepley 34446636e97aSMatthew G Knepley For DMDA, in two and three dimensions coordinates are interlaced (x_0,y_0,x_1,y_1,...) 34456636e97aSMatthew G Knepley and (x_0,y_0,z_0,x_1,y_1,z_1...) 34466636e97aSMatthew G Knepley 34476636e97aSMatthew G Knepley Level: intermediate 34486636e97aSMatthew G Knepley 34496636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 34506636e97aSMatthew G Knepley .seealso: DMSetCoordinates(), DMGetCoordinatesLocal(), DMGetCoordinateDM() 34516636e97aSMatthew G Knepley @*/ 34526636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinates(DM dm, Vec *c) 34536636e97aSMatthew G Knepley { 34546636e97aSMatthew G Knepley PetscErrorCode ierr; 34556636e97aSMatthew G Knepley 34566636e97aSMatthew G Knepley PetscFunctionBegin; 34576636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 34586636e97aSMatthew G Knepley PetscValidPointer(c,2); 34591f588964SMatthew G Knepley if (!dm->coordinates && dm->coordinatesLocal) { 34600298fd71SBarry Smith DM cdm = NULL; 34616636e97aSMatthew G Knepley 34626636e97aSMatthew G Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 34636636e97aSMatthew G Knepley ierr = DMCreateGlobalVector(cdm, &dm->coordinates);CHKERRQ(ierr); 34646636e97aSMatthew G Knepley ierr = PetscObjectSetName((PetscObject) dm->coordinates, "coordinates");CHKERRQ(ierr); 34656636e97aSMatthew G Knepley ierr = DMLocalToGlobalBegin(cdm, dm->coordinatesLocal, INSERT_VALUES, dm->coordinates);CHKERRQ(ierr); 34666636e97aSMatthew G Knepley ierr = DMLocalToGlobalEnd(cdm, dm->coordinatesLocal, INSERT_VALUES, dm->coordinates);CHKERRQ(ierr); 34676636e97aSMatthew G Knepley } 34686636e97aSMatthew G Knepley *c = dm->coordinates; 34696636e97aSMatthew G Knepley PetscFunctionReturn(0); 34706636e97aSMatthew G Knepley } 34716636e97aSMatthew G Knepley 34726636e97aSMatthew G Knepley #undef __FUNCT__ 34736636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinatesLocal" 34746636e97aSMatthew G Knepley /*@ 34756636e97aSMatthew G Knepley DMGetCoordinatesLocal - Gets a local vector with the coordinates associated with the DM. 34766636e97aSMatthew G Knepley 34776636e97aSMatthew G Knepley Collective on DM 34786636e97aSMatthew G Knepley 34796636e97aSMatthew G Knepley Input Parameter: 34806636e97aSMatthew G Knepley . dm - the DM 34816636e97aSMatthew G Knepley 34826636e97aSMatthew G Knepley Output Parameter: 34836636e97aSMatthew G Knepley . c - coordinate vector 34846636e97aSMatthew G Knepley 34856636e97aSMatthew G Knepley Note: 34866636e97aSMatthew G Knepley This is a borrowed reference, so the user should NOT destroy this vector 34876636e97aSMatthew G Knepley 34886636e97aSMatthew G Knepley Each process has the local and ghost coordinates 34896636e97aSMatthew G Knepley 34906636e97aSMatthew G Knepley For DMDA, in two and three dimensions coordinates are interlaced (x_0,y_0,x_1,y_1,...) 34916636e97aSMatthew G Knepley and (x_0,y_0,z_0,x_1,y_1,z_1...) 34926636e97aSMatthew G Knepley 34936636e97aSMatthew G Knepley Level: intermediate 34946636e97aSMatthew G Knepley 34956636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 34966636e97aSMatthew G Knepley .seealso: DMSetCoordinatesLocal(), DMGetCoordinates(), DMSetCoordinates(), DMGetCoordinateDM() 34976636e97aSMatthew G Knepley @*/ 34986636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinatesLocal(DM dm, Vec *c) 34996636e97aSMatthew G Knepley { 35006636e97aSMatthew G Knepley PetscErrorCode ierr; 35016636e97aSMatthew G Knepley 35026636e97aSMatthew G Knepley PetscFunctionBegin; 35036636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 35046636e97aSMatthew G Knepley PetscValidPointer(c,2); 35051f588964SMatthew G Knepley if (!dm->coordinatesLocal && dm->coordinates) { 35060298fd71SBarry Smith DM cdm = NULL; 35076636e97aSMatthew G Knepley 35086636e97aSMatthew G Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 35096636e97aSMatthew G Knepley ierr = DMCreateLocalVector(cdm, &dm->coordinatesLocal);CHKERRQ(ierr); 35106636e97aSMatthew G Knepley ierr = PetscObjectSetName((PetscObject) dm->coordinatesLocal, "coordinates");CHKERRQ(ierr); 35116636e97aSMatthew G Knepley ierr = DMGlobalToLocalBegin(cdm, dm->coordinates, INSERT_VALUES, dm->coordinatesLocal);CHKERRQ(ierr); 35126636e97aSMatthew G Knepley ierr = DMGlobalToLocalEnd(cdm, dm->coordinates, INSERT_VALUES, dm->coordinatesLocal);CHKERRQ(ierr); 35136636e97aSMatthew G Knepley } 35146636e97aSMatthew G Knepley *c = dm->coordinatesLocal; 35156636e97aSMatthew G Knepley PetscFunctionReturn(0); 35166636e97aSMatthew G Knepley } 35176636e97aSMatthew G Knepley 35186636e97aSMatthew G Knepley #undef __FUNCT__ 35196636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinateDM" 35206636e97aSMatthew G Knepley /*@ 35211cfe2091SMatthew G. Knepley DMGetCoordinateDM - Gets the DM that prescribes coordinate layout and scatters between global and local coordinates 35226636e97aSMatthew G Knepley 35236636e97aSMatthew G Knepley Collective on DM 35246636e97aSMatthew G Knepley 35256636e97aSMatthew G Knepley Input Parameter: 35266636e97aSMatthew G Knepley . dm - the DM 35276636e97aSMatthew G Knepley 35286636e97aSMatthew G Knepley Output Parameter: 35296636e97aSMatthew G Knepley . cdm - coordinate DM 35306636e97aSMatthew G Knepley 35316636e97aSMatthew G Knepley Level: intermediate 35326636e97aSMatthew G Knepley 35336636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 35341cfe2091SMatthew G. Knepley .seealso: DMSetCoordinateDM(), DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 35356636e97aSMatthew G Knepley @*/ 35366636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinateDM(DM dm, DM *cdm) 35376636e97aSMatthew G Knepley { 35386636e97aSMatthew G Knepley PetscErrorCode ierr; 35396636e97aSMatthew G Knepley 35406636e97aSMatthew G Knepley PetscFunctionBegin; 35416636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 35426636e97aSMatthew G Knepley PetscValidPointer(cdm,2); 35436636e97aSMatthew G Knepley if (!dm->coordinateDM) { 354482f516ccSBarry Smith if (!dm->ops->createcoordinatedm) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Unable to create coordinates for this DM"); 35456636e97aSMatthew G Knepley ierr = (*dm->ops->createcoordinatedm)(dm, &dm->coordinateDM);CHKERRQ(ierr); 35466636e97aSMatthew G Knepley } 35476636e97aSMatthew G Knepley *cdm = dm->coordinateDM; 35486636e97aSMatthew G Knepley PetscFunctionReturn(0); 35496636e97aSMatthew G Knepley } 3550e87bb0d3SMatthew G Knepley 3551e87bb0d3SMatthew G Knepley #undef __FUNCT__ 35521cfe2091SMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateDM" 35531cfe2091SMatthew G. Knepley /*@ 35541cfe2091SMatthew G. Knepley DMSetCoordinateDM - Sets the DM that prescribes coordinate layout and scatters between global and local coordinates 35551cfe2091SMatthew G. Knepley 35561cfe2091SMatthew G. Knepley Logically Collective on DM 35571cfe2091SMatthew G. Knepley 35581cfe2091SMatthew G. Knepley Input Parameters: 35591cfe2091SMatthew G. Knepley + dm - the DM 35601cfe2091SMatthew G. Knepley - cdm - coordinate DM 35611cfe2091SMatthew G. Knepley 35621cfe2091SMatthew G. Knepley Level: intermediate 35631cfe2091SMatthew G. Knepley 35641cfe2091SMatthew G. Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 35651cfe2091SMatthew G. Knepley .seealso: DMGetCoordinateDM(), DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 35661cfe2091SMatthew G. Knepley @*/ 35671cfe2091SMatthew G. Knepley PetscErrorCode DMSetCoordinateDM(DM dm, DM cdm) 35681cfe2091SMatthew G. Knepley { 35691cfe2091SMatthew G. Knepley PetscErrorCode ierr; 35701cfe2091SMatthew G. Knepley 35711cfe2091SMatthew G. Knepley PetscFunctionBegin; 35721cfe2091SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 35731cfe2091SMatthew G. Knepley PetscValidHeaderSpecific(cdm,DM_CLASSID,2); 35741cfe2091SMatthew G. Knepley ierr = DMDestroy(&dm->coordinateDM);CHKERRQ(ierr); 35751cfe2091SMatthew G. Knepley dm->coordinateDM = cdm; 35761cfe2091SMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm->coordinateDM);CHKERRQ(ierr); 35771cfe2091SMatthew G. Knepley PetscFunctionReturn(0); 35781cfe2091SMatthew G. Knepley } 35791cfe2091SMatthew G. Knepley 35801cfe2091SMatthew G. Knepley #undef __FUNCT__ 3581e8abe2deSMatthew G. Knepley #define __FUNCT__ "DMGetCoordinateSection" 3582e8abe2deSMatthew G. Knepley /*@ 3583e8abe2deSMatthew G. Knepley DMGetCoordinateSection - Retrieve the layout of coordinate values over the mesh. 3584e8abe2deSMatthew G. Knepley 3585e8abe2deSMatthew G. Knepley Not Collective 3586e8abe2deSMatthew G. Knepley 3587e8abe2deSMatthew G. Knepley Input Parameter: 3588e8abe2deSMatthew G. Knepley . dm - The DM object 3589e8abe2deSMatthew G. Knepley 3590e8abe2deSMatthew G. Knepley Output Parameter: 3591e8abe2deSMatthew G. Knepley . section - The PetscSection object 3592e8abe2deSMatthew G. Knepley 3593e8abe2deSMatthew G. Knepley Level: intermediate 3594e8abe2deSMatthew G. Knepley 3595e8abe2deSMatthew G. Knepley .keywords: mesh, coordinates 3596e8abe2deSMatthew G. Knepley .seealso: DMGetCoordinateDM(), DMGetDefaultSection(), DMSetDefaultSection() 3597e8abe2deSMatthew G. Knepley @*/ 3598e8abe2deSMatthew G. Knepley PetscErrorCode DMGetCoordinateSection(DM dm, PetscSection *section) 3599e8abe2deSMatthew G. Knepley { 3600e8abe2deSMatthew G. Knepley DM cdm; 3601e8abe2deSMatthew G. Knepley PetscErrorCode ierr; 3602e8abe2deSMatthew G. Knepley 3603e8abe2deSMatthew G. Knepley PetscFunctionBegin; 3604e8abe2deSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3605e8abe2deSMatthew G. Knepley PetscValidPointer(section, 2); 3606e8abe2deSMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 3607e8abe2deSMatthew G. Knepley ierr = DMGetDefaultSection(cdm, section);CHKERRQ(ierr); 3608e8abe2deSMatthew G. Knepley PetscFunctionReturn(0); 3609e8abe2deSMatthew G. Knepley } 3610e8abe2deSMatthew G. Knepley 3611e8abe2deSMatthew G. Knepley #undef __FUNCT__ 3612e8abe2deSMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateSection" 3613e8abe2deSMatthew G. Knepley /*@ 3614e8abe2deSMatthew G. Knepley DMSetCoordinateSection - Set the layout of coordinate values over the mesh. 3615e8abe2deSMatthew G. Knepley 3616e8abe2deSMatthew G. Knepley Not Collective 3617e8abe2deSMatthew G. Knepley 3618e8abe2deSMatthew G. Knepley Input Parameters: 3619e8abe2deSMatthew G. Knepley + dm - The DM object 3620e8abe2deSMatthew G. Knepley - section - The PetscSection object 3621e8abe2deSMatthew G. Knepley 3622e8abe2deSMatthew G. Knepley Level: intermediate 3623e8abe2deSMatthew G. Knepley 3624e8abe2deSMatthew G. Knepley .keywords: mesh, coordinates 3625e8abe2deSMatthew G. Knepley .seealso: DMGetCoordinateSection(), DMGetDefaultSection(), DMSetDefaultSection() 3626e8abe2deSMatthew G. Knepley @*/ 3627e8abe2deSMatthew G. Knepley PetscErrorCode DMSetCoordinateSection(DM dm, PetscSection section) 3628e8abe2deSMatthew G. Knepley { 3629e8abe2deSMatthew G. Knepley DM cdm; 3630e8abe2deSMatthew G. Knepley PetscErrorCode ierr; 3631e8abe2deSMatthew G. Knepley 3632e8abe2deSMatthew G. Knepley PetscFunctionBegin; 3633e8abe2deSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3634e8abe2deSMatthew G. Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 3635e8abe2deSMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 3636e8abe2deSMatthew G. Knepley ierr = DMSetDefaultSection(cdm, section);CHKERRQ(ierr); 3637e8abe2deSMatthew G. Knepley PetscFunctionReturn(0); 3638e8abe2deSMatthew G. Knepley } 3639e8abe2deSMatthew G. Knepley 3640e8abe2deSMatthew G. Knepley #undef __FUNCT__ 3641c6b900c6SMatthew G. Knepley #define __FUNCT__ "DMGetPeriodicity" 3642c6b900c6SMatthew G. Knepley PetscErrorCode DMGetPeriodicity(DM dm, const PetscReal **maxCell, const PetscReal **L) 3643c6b900c6SMatthew G. Knepley { 3644c6b900c6SMatthew G. Knepley PetscFunctionBegin; 3645c6b900c6SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3646c6b900c6SMatthew G. Knepley if (L) *L = dm->L; 3647c6b900c6SMatthew G. Knepley if (maxCell) *maxCell = dm->maxCell; 3648c6b900c6SMatthew G. Knepley PetscFunctionReturn(0); 3649c6b900c6SMatthew G. Knepley } 3650c6b900c6SMatthew G. Knepley 3651c6b900c6SMatthew G. Knepley #undef __FUNCT__ 3652c6b900c6SMatthew G. Knepley #define __FUNCT__ "DMSetPeriodicity" 3653c6b900c6SMatthew G. Knepley PetscErrorCode DMSetPeriodicity(DM dm, const PetscReal maxCell[], const PetscReal L[]) 3654c6b900c6SMatthew G. Knepley { 3655c6b900c6SMatthew G. Knepley Vec coordinates; 3656c6b900c6SMatthew G. Knepley PetscInt dim, d; 3657c6b900c6SMatthew G. Knepley PetscErrorCode ierr; 3658c6b900c6SMatthew G. Knepley 3659c6b900c6SMatthew G. Knepley PetscFunctionBegin; 3660c6b900c6SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3661c6b900c6SMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); 3662c6b900c6SMatthew G. Knepley ierr = VecGetBlockSize(coordinates, &dim);CHKERRQ(ierr); 3663c6b900c6SMatthew G. Knepley ierr = PetscMalloc1(dim,&dm->L);CHKERRQ(ierr); 3664c6b900c6SMatthew G. Knepley ierr = PetscMalloc1(dim,&dm->maxCell);CHKERRQ(ierr); 3665c6b900c6SMatthew G. Knepley for (d = 0; d < dim; ++d) {dm->L[d] = L[d]; dm->maxCell[d] = maxCell[d];} 3666c6b900c6SMatthew G. Knepley PetscFunctionReturn(0); 3667c6b900c6SMatthew G. Knepley } 3668c6b900c6SMatthew G. Knepley 3669c6b900c6SMatthew G. Knepley #undef __FUNCT__ 3670e87bb0d3SMatthew G Knepley #define __FUNCT__ "DMLocatePoints" 3671e87bb0d3SMatthew G Knepley /*@ 3672e87bb0d3SMatthew G Knepley DMLocatePoints - Locate the points in v in the mesh and return an IS of the containing cells 3673e87bb0d3SMatthew G Knepley 3674e87bb0d3SMatthew G Knepley Not collective 3675e87bb0d3SMatthew G Knepley 3676e87bb0d3SMatthew G Knepley Input Parameters: 3677e87bb0d3SMatthew G Knepley + dm - The DM 3678e87bb0d3SMatthew G Knepley - v - The Vec of points 3679e87bb0d3SMatthew G Knepley 368061e3bb9bSMatthew G Knepley Output Parameter: 3681e87bb0d3SMatthew G Knepley . cells - The local cell numbers for cells which contain the points 3682e87bb0d3SMatthew G Knepley 3683e87bb0d3SMatthew G Knepley Level: developer 368461e3bb9bSMatthew G Knepley 368561e3bb9bSMatthew G Knepley .keywords: point location, mesh 368661e3bb9bSMatthew G Knepley .seealso: DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 368761e3bb9bSMatthew G Knepley @*/ 3688e87bb0d3SMatthew G Knepley PetscErrorCode DMLocatePoints(DM dm, Vec v, IS *cells) 3689e87bb0d3SMatthew G Knepley { 3690735aa83eSMatthew G Knepley PetscErrorCode ierr; 3691735aa83eSMatthew G Knepley 3692e87bb0d3SMatthew G Knepley PetscFunctionBegin; 3693e87bb0d3SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3694e87bb0d3SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,2); 3695e87bb0d3SMatthew G Knepley PetscValidPointer(cells,3); 3696735aa83eSMatthew G Knepley if (dm->ops->locatepoints) { 3697735aa83eSMatthew G Knepley ierr = (*dm->ops->locatepoints)(dm,v,cells);CHKERRQ(ierr); 369882f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Point location not available for this DM"); 3699e87bb0d3SMatthew G Knepley PetscFunctionReturn(0); 3700e87bb0d3SMatthew G Knepley } 370114f150ffSMatthew G. Knepley 370214f150ffSMatthew G. Knepley #undef __FUNCT__ 370314f150ffSMatthew G. Knepley #define __FUNCT__ "DMGetOutputDM" 3704f4d763aaSMatthew G. Knepley /*@ 3705f4d763aaSMatthew G. Knepley DMGetOutputDM - Retrieve the DM associated with the layout for output 3706f4d763aaSMatthew G. Knepley 3707f4d763aaSMatthew G. Knepley Input Parameter: 3708f4d763aaSMatthew G. Knepley . dm - The original DM 3709f4d763aaSMatthew G. Knepley 3710f4d763aaSMatthew G. Knepley Output Parameter: 3711f4d763aaSMatthew G. Knepley . odm - The DM which provides the layout for output 3712f4d763aaSMatthew G. Knepley 3713f4d763aaSMatthew G. Knepley Level: intermediate 3714f4d763aaSMatthew G. Knepley 3715f4d763aaSMatthew G. Knepley .seealso: VecView(), DMGetDefaultGlobalSection() 3716f4d763aaSMatthew G. Knepley @*/ 371714f150ffSMatthew G. Knepley PetscErrorCode DMGetOutputDM(DM dm, DM *odm) 371814f150ffSMatthew G. Knepley { 3719c26acbdeSMatthew G. Knepley PetscSection section; 3720c26acbdeSMatthew G. Knepley PetscBool hasConstraints; 372114f150ffSMatthew G. Knepley PetscErrorCode ierr; 372214f150ffSMatthew G. Knepley 372314f150ffSMatthew G. Knepley PetscFunctionBegin; 372414f150ffSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 372514f150ffSMatthew G. Knepley PetscValidPointer(odm,2); 3726c26acbdeSMatthew G. Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 3727c26acbdeSMatthew G. Knepley ierr = PetscSectionHasConstraints(section, &hasConstraints);CHKERRQ(ierr); 3728c26acbdeSMatthew G. Knepley if (!hasConstraints) { 3729c26acbdeSMatthew G. Knepley *odm = dm; 3730c26acbdeSMatthew G. Knepley PetscFunctionReturn(0); 3731c26acbdeSMatthew G. Knepley } 373214f150ffSMatthew G. Knepley if (!dm->dmBC) { 3733c26acbdeSMatthew G. Knepley PetscSection newSection, gsection; 373414f150ffSMatthew G. Knepley PetscSF sf; 373514f150ffSMatthew G. Knepley 373614f150ffSMatthew G. Knepley ierr = DMClone(dm, &dm->dmBC);CHKERRQ(ierr); 373714f150ffSMatthew G. Knepley ierr = PetscSectionClone(section, &newSection);CHKERRQ(ierr); 373814f150ffSMatthew G. Knepley ierr = DMSetDefaultSection(dm->dmBC, newSection);CHKERRQ(ierr); 373914f150ffSMatthew G. Knepley ierr = PetscSectionDestroy(&newSection);CHKERRQ(ierr); 374014f150ffSMatthew G. Knepley ierr = DMGetPointSF(dm->dmBC, &sf);CHKERRQ(ierr); 374114f150ffSMatthew G. Knepley ierr = PetscSectionCreateGlobalSection(section, sf, PETSC_TRUE, &gsection);CHKERRQ(ierr); 374214f150ffSMatthew G. Knepley ierr = DMSetDefaultGlobalSection(dm->dmBC, gsection);CHKERRQ(ierr); 374314f150ffSMatthew G. Knepley ierr = PetscSectionDestroy(&gsection);CHKERRQ(ierr); 374414f150ffSMatthew G. Knepley } 374514f150ffSMatthew G. Knepley *odm = dm->dmBC; 374614f150ffSMatthew G. Knepley PetscFunctionReturn(0); 374714f150ffSMatthew G. Knepley } 3748f4d763aaSMatthew G. Knepley 3749f4d763aaSMatthew G. Knepley #undef __FUNCT__ 3750f4d763aaSMatthew G. Knepley #define __FUNCT__ "DMGetOutputSequenceNumber" 3751f4d763aaSMatthew G. Knepley /*@ 3752cdb7a50dSMatthew G. Knepley DMGetOutputSequenceNumber - Retrieve the sequence number/value for output 3753f4d763aaSMatthew G. Knepley 3754f4d763aaSMatthew G. Knepley Input Parameter: 3755f4d763aaSMatthew G. Knepley . dm - The original DM 3756f4d763aaSMatthew G. Knepley 3757cdb7a50dSMatthew G. Knepley Output Parameters: 3758cdb7a50dSMatthew G. Knepley + num - The output sequence number 3759cdb7a50dSMatthew G. Knepley - val - The output sequence value 3760f4d763aaSMatthew G. Knepley 3761f4d763aaSMatthew G. Knepley Level: intermediate 3762f4d763aaSMatthew G. Knepley 3763f4d763aaSMatthew G. Knepley Note: This is intended for output that should appear in sequence, for instance 3764f4d763aaSMatthew G. Knepley a set of timesteps in an HDF5 file, or a set of realizations of a stochastic system. 3765f4d763aaSMatthew G. Knepley 3766f4d763aaSMatthew G. Knepley .seealso: VecView() 3767f4d763aaSMatthew G. Knepley @*/ 3768cdb7a50dSMatthew G. Knepley PetscErrorCode DMGetOutputSequenceNumber(DM dm, PetscInt *num, PetscReal *val) 3769f4d763aaSMatthew G. Knepley { 3770f4d763aaSMatthew G. Knepley PetscFunctionBegin; 3771f4d763aaSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3772cdb7a50dSMatthew G. Knepley if (num) {PetscValidPointer(num,2); *num = dm->outputSequenceNum;} 3773cdb7a50dSMatthew G. Knepley if (val) {PetscValidPointer(val,3);*val = dm->outputSequenceVal;} 3774f4d763aaSMatthew G. Knepley PetscFunctionReturn(0); 3775f4d763aaSMatthew G. Knepley } 3776f4d763aaSMatthew G. Knepley 3777f4d763aaSMatthew G. Knepley #undef __FUNCT__ 3778f4d763aaSMatthew G. Knepley #define __FUNCT__ "DMSetOutputSequenceNumber" 3779f4d763aaSMatthew G. Knepley /*@ 3780cdb7a50dSMatthew G. Knepley DMSetOutputSequenceNumber - Set the sequence number/value for output 3781f4d763aaSMatthew G. Knepley 3782f4d763aaSMatthew G. Knepley Input Parameters: 3783f4d763aaSMatthew G. Knepley + dm - The original DM 3784cdb7a50dSMatthew G. Knepley . num - The output sequence number 3785cdb7a50dSMatthew G. Knepley - val - The output sequence value 3786f4d763aaSMatthew G. Knepley 3787f4d763aaSMatthew G. Knepley Level: intermediate 3788f4d763aaSMatthew G. Knepley 3789f4d763aaSMatthew G. Knepley Note: This is intended for output that should appear in sequence, for instance 3790f4d763aaSMatthew G. Knepley a set of timesteps in an HDF5 file, or a set of realizations of a stochastic system. 3791f4d763aaSMatthew G. Knepley 3792f4d763aaSMatthew G. Knepley .seealso: VecView() 3793f4d763aaSMatthew G. Knepley @*/ 3794cdb7a50dSMatthew G. Knepley PetscErrorCode DMSetOutputSequenceNumber(DM dm, PetscInt num, PetscReal val) 3795f4d763aaSMatthew G. Knepley { 3796f4d763aaSMatthew G. Knepley PetscFunctionBegin; 3797f4d763aaSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3798f4d763aaSMatthew G. Knepley dm->outputSequenceNum = num; 3799cdb7a50dSMatthew G. Knepley dm->outputSequenceVal = val; 3800cdb7a50dSMatthew G. Knepley PetscFunctionReturn(0); 3801cdb7a50dSMatthew G. Knepley } 3802cdb7a50dSMatthew G. Knepley 3803cdb7a50dSMatthew G. Knepley #undef __FUNCT__ 3804cdb7a50dSMatthew G. Knepley #define __FUNCT__ "DMOutputSequenceLoad" 3805cdb7a50dSMatthew G. Knepley /*@C 3806cdb7a50dSMatthew G. Knepley DMOutputSequenceLoad - Retrieve the sequence value from a Viewer 3807cdb7a50dSMatthew G. Knepley 3808cdb7a50dSMatthew G. Knepley Input Parameters: 3809cdb7a50dSMatthew G. Knepley + dm - The original DM 3810cdb7a50dSMatthew G. Knepley . name - The sequence name 3811cdb7a50dSMatthew G. Knepley - num - The output sequence number 3812cdb7a50dSMatthew G. Knepley 3813cdb7a50dSMatthew G. Knepley Output Parameter: 3814cdb7a50dSMatthew G. Knepley . val - The output sequence value 3815cdb7a50dSMatthew G. Knepley 3816cdb7a50dSMatthew G. Knepley Level: intermediate 3817cdb7a50dSMatthew G. Knepley 3818cdb7a50dSMatthew G. Knepley Note: This is intended for output that should appear in sequence, for instance 3819cdb7a50dSMatthew G. Knepley a set of timesteps in an HDF5 file, or a set of realizations of a stochastic system. 3820cdb7a50dSMatthew G. Knepley 3821cdb7a50dSMatthew G. Knepley .seealso: DMGetOutputSequenceNumber(), DMSetOutputSequenceNumber(), VecView() 3822cdb7a50dSMatthew G. Knepley @*/ 3823cdb7a50dSMatthew G. Knepley PetscErrorCode DMOutputSequenceLoad(DM dm, PetscViewer viewer, const char *name, PetscInt num, PetscReal *val) 3824cdb7a50dSMatthew G. Knepley { 3825cdb7a50dSMatthew G. Knepley PetscBool ishdf5; 3826cdb7a50dSMatthew G. Knepley PetscErrorCode ierr; 3827cdb7a50dSMatthew G. Knepley 3828cdb7a50dSMatthew G. Knepley PetscFunctionBegin; 3829cdb7a50dSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3830cdb7a50dSMatthew G. Knepley PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 3831cdb7a50dSMatthew G. Knepley PetscValidPointer(val,4); 3832cdb7a50dSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 3833cdb7a50dSMatthew G. Knepley if (ishdf5) { 3834cdb7a50dSMatthew G. Knepley #if defined(PETSC_HAVE_HDF5) 3835cdb7a50dSMatthew G. Knepley PetscScalar value; 3836cdb7a50dSMatthew G. Knepley 3837cdb7a50dSMatthew G. Knepley ierr = DMSequenceLoad_HDF5(dm, name, num, &value, viewer);CHKERRQ(ierr); 38384aeb217fSMatthew G. Knepley *val = PetscRealPart(value); 3839cdb7a50dSMatthew G. Knepley #endif 3840cdb7a50dSMatthew G. Knepley } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Invalid viewer; open viewer with PetscViewerHDF5Open()"); 3841f4d763aaSMatthew G. Knepley PetscFunctionReturn(0); 3842f4d763aaSMatthew G. Knepley } 3843