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; 941de53e9aSMatthew G. Knepley PetscInt dim; 9538221697SMatthew G. Knepley PetscErrorCode ierr; 9638221697SMatthew G. Knepley 9738221697SMatthew G. Knepley PetscFunctionBegin; 9838221697SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 9938221697SMatthew G. Knepley PetscValidPointer(newdm,2); 10038221697SMatthew G. Knepley ierr = DMCreate(PetscObjectComm((PetscObject)dm), newdm);CHKERRQ(ierr); 1011de53e9aSMatthew G. Knepley ierr = DMGetDimension(dm, &dim);CHKERRQ(ierr); 1021de53e9aSMatthew G. Knepley ierr = DMSetDimension(*newdm, dim);CHKERRQ(ierr); 10338221697SMatthew G. Knepley if (dm->ops->clone) { 10438221697SMatthew G. Knepley ierr = (*dm->ops->clone)(dm, newdm);CHKERRQ(ierr); 10538221697SMatthew G. Knepley } 106cd27c7c9SMatthew G. Knepley (*newdm)->setupcalled = PETSC_TRUE; 10738221697SMatthew G. Knepley ierr = DMGetPointSF(dm, &sf);CHKERRQ(ierr); 10838221697SMatthew G. Knepley ierr = DMSetPointSF(*newdm, sf);CHKERRQ(ierr); 10938221697SMatthew G. Knepley ierr = DMGetApplicationContext(dm, &ctx);CHKERRQ(ierr); 11038221697SMatthew G. Knepley ierr = DMSetApplicationContext(*newdm, ctx);CHKERRQ(ierr); 11138221697SMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coords);CHKERRQ(ierr); 11238221697SMatthew G. Knepley if (coords) { 11338221697SMatthew G. Knepley ierr = DMSetCoordinatesLocal(*newdm, coords);CHKERRQ(ierr); 11438221697SMatthew G. Knepley } else { 11538221697SMatthew G. Knepley ierr = DMGetCoordinates(dm, &coords);CHKERRQ(ierr); 11638221697SMatthew G. Knepley if (coords) {ierr = DMSetCoordinates(*newdm, coords);CHKERRQ(ierr);} 11738221697SMatthew G. Knepley } 118c6b900c6SMatthew G. Knepley if (dm->maxCell) { 119c6b900c6SMatthew G. Knepley const PetscReal *maxCell, *L; 120c6b900c6SMatthew G. Knepley ierr = DMGetPeriodicity(dm, &maxCell, &L);CHKERRQ(ierr); 121c6b900c6SMatthew G. Knepley ierr = DMSetPeriodicity(*newdm, maxCell, L);CHKERRQ(ierr); 122c6b900c6SMatthew G. Knepley } 12338221697SMatthew G. Knepley PetscFunctionReturn(0); 12438221697SMatthew G. Knepley } 12538221697SMatthew G. Knepley 12638221697SMatthew G. Knepley #undef __FUNCT__ 1279a42bb27SBarry Smith #define __FUNCT__ "DMSetVecType" 1289a42bb27SBarry Smith /*@C 129564755cdSBarry Smith DMSetVecType - Sets the type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() 1309a42bb27SBarry Smith 131aa219208SBarry Smith Logically Collective on DMDA 1329a42bb27SBarry Smith 1339a42bb27SBarry Smith Input Parameter: 1349a42bb27SBarry Smith + da - initial distributed array 1358154be41SBarry Smith . ctype - the vector type, currently either VECSTANDARD or VECCUSP 1369a42bb27SBarry Smith 1379a42bb27SBarry Smith Options Database: 138dd85299cSBarry Smith . -dm_vec_type ctype 1399a42bb27SBarry Smith 1409a42bb27SBarry Smith Level: intermediate 1419a42bb27SBarry Smith 142c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMDestroy(), DMDA, DMDAInterpolationType, VecType, DMGetVecType() 1439a42bb27SBarry Smith @*/ 14419fd82e9SBarry Smith PetscErrorCode DMSetVecType(DM da,VecType ctype) 1459a42bb27SBarry Smith { 1469a42bb27SBarry Smith PetscErrorCode ierr; 1479a42bb27SBarry Smith 1489a42bb27SBarry Smith PetscFunctionBegin; 1499a42bb27SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 1509a42bb27SBarry Smith ierr = PetscFree(da->vectype);CHKERRQ(ierr); 15119fd82e9SBarry Smith ierr = PetscStrallocpy(ctype,(char**)&da->vectype);CHKERRQ(ierr); 1529a42bb27SBarry Smith PetscFunctionReturn(0); 1539a42bb27SBarry Smith } 1549a42bb27SBarry Smith 1559a42bb27SBarry Smith #undef __FUNCT__ 156c0dedaeaSBarry Smith #define __FUNCT__ "DMGetVecType" 157c0dedaeaSBarry Smith /*@C 158c0dedaeaSBarry Smith DMGetVecType - Gets the type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() 159c0dedaeaSBarry Smith 160c0dedaeaSBarry Smith Logically Collective on DMDA 161c0dedaeaSBarry Smith 162c0dedaeaSBarry Smith Input Parameter: 163c0dedaeaSBarry Smith . da - initial distributed array 164c0dedaeaSBarry Smith 165c0dedaeaSBarry Smith Output Parameter: 166c0dedaeaSBarry Smith . ctype - the vector type 167c0dedaeaSBarry Smith 168c0dedaeaSBarry Smith Level: intermediate 169c0dedaeaSBarry Smith 170c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMDestroy(), DMDA, DMDAInterpolationType, VecType 171c0dedaeaSBarry Smith @*/ 172c0dedaeaSBarry Smith PetscErrorCode DMGetVecType(DM da,VecType *ctype) 173c0dedaeaSBarry Smith { 174c0dedaeaSBarry Smith PetscFunctionBegin; 175c0dedaeaSBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 176c0dedaeaSBarry Smith *ctype = da->vectype; 177c0dedaeaSBarry Smith PetscFunctionReturn(0); 178c0dedaeaSBarry Smith } 179c0dedaeaSBarry Smith 180c0dedaeaSBarry Smith #undef __FUNCT__ 1815f1ad066SMatthew G Knepley #define __FUNCT__ "VecGetDM" 1825f1ad066SMatthew G Knepley /*@ 18334f98d34SBarry Smith VecGetDM - Gets the DM defining the data layout of the vector 1845f1ad066SMatthew G Knepley 1855f1ad066SMatthew G Knepley Not collective 1865f1ad066SMatthew G Knepley 1875f1ad066SMatthew G Knepley Input Parameter: 1885f1ad066SMatthew G Knepley . v - The Vec 1895f1ad066SMatthew G Knepley 1905f1ad066SMatthew G Knepley Output Parameter: 1915f1ad066SMatthew G Knepley . dm - The DM 1925f1ad066SMatthew G Knepley 1935f1ad066SMatthew G Knepley Level: intermediate 1945f1ad066SMatthew G Knepley 1955f1ad066SMatthew G Knepley .seealso: VecSetDM(), DMGetLocalVector(), DMGetGlobalVector(), DMSetVecType() 1965f1ad066SMatthew G Knepley @*/ 1975f1ad066SMatthew G Knepley PetscErrorCode VecGetDM(Vec v, DM *dm) 1985f1ad066SMatthew G Knepley { 1995f1ad066SMatthew G Knepley PetscErrorCode ierr; 2005f1ad066SMatthew G Knepley 2015f1ad066SMatthew G Knepley PetscFunctionBegin; 2025f1ad066SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,1); 2035f1ad066SMatthew G Knepley PetscValidPointer(dm,2); 2045f1ad066SMatthew G Knepley ierr = PetscObjectQuery((PetscObject) v, "__PETSc_dm", (PetscObject*) dm);CHKERRQ(ierr); 2055f1ad066SMatthew G Knepley PetscFunctionReturn(0); 2065f1ad066SMatthew G Knepley } 2075f1ad066SMatthew G Knepley 2085f1ad066SMatthew G Knepley #undef __FUNCT__ 2095f1ad066SMatthew G Knepley #define __FUNCT__ "VecSetDM" 2105f1ad066SMatthew G Knepley /*@ 2115f1ad066SMatthew G Knepley VecSetDM - Sets the DM defining the data layout of the vector 2125f1ad066SMatthew G Knepley 2135f1ad066SMatthew G Knepley Not collective 2145f1ad066SMatthew G Knepley 2155f1ad066SMatthew G Knepley Input Parameters: 2165f1ad066SMatthew G Knepley + v - The Vec 2175f1ad066SMatthew G Knepley - dm - The DM 2185f1ad066SMatthew G Knepley 2195f1ad066SMatthew G Knepley Level: intermediate 2205f1ad066SMatthew G Knepley 2215f1ad066SMatthew G Knepley .seealso: VecGetDM(), DMGetLocalVector(), DMGetGlobalVector(), DMSetVecType() 2225f1ad066SMatthew G Knepley @*/ 2235f1ad066SMatthew G Knepley PetscErrorCode VecSetDM(Vec v, DM dm) 2245f1ad066SMatthew G Knepley { 2255f1ad066SMatthew G Knepley PetscErrorCode ierr; 2265f1ad066SMatthew G Knepley 2275f1ad066SMatthew G Knepley PetscFunctionBegin; 2285f1ad066SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,1); 229d7f50e27SLisandro Dalcin if (dm) PetscValidHeaderSpecific(dm,DM_CLASSID,2); 2305f1ad066SMatthew G Knepley ierr = PetscObjectCompose((PetscObject) v, "__PETSc_dm", (PetscObject) dm);CHKERRQ(ierr); 2315f1ad066SMatthew G Knepley PetscFunctionReturn(0); 2325f1ad066SMatthew G Knepley } 2335f1ad066SMatthew G Knepley 2345f1ad066SMatthew G Knepley #undef __FUNCT__ 235521d9a4cSLisandro Dalcin #define __FUNCT__ "DMSetMatType" 236521d9a4cSLisandro Dalcin /*@C 237521d9a4cSLisandro Dalcin DMSetMatType - Sets the type of matrix created with DMCreateMatrix() 238521d9a4cSLisandro Dalcin 239521d9a4cSLisandro Dalcin Logically Collective on DM 240521d9a4cSLisandro Dalcin 241521d9a4cSLisandro Dalcin Input Parameter: 242521d9a4cSLisandro Dalcin + dm - the DM context 243521d9a4cSLisandro Dalcin . ctype - the matrix type 244521d9a4cSLisandro Dalcin 245521d9a4cSLisandro Dalcin Options Database: 246521d9a4cSLisandro Dalcin . -dm_mat_type ctype 247521d9a4cSLisandro Dalcin 248521d9a4cSLisandro Dalcin Level: intermediate 249521d9a4cSLisandro Dalcin 250c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateMatrix(), DMSetMatrixPreallocateOnly(), MatType, DMGetMatType() 251521d9a4cSLisandro Dalcin @*/ 25219fd82e9SBarry Smith PetscErrorCode DMSetMatType(DM dm,MatType ctype) 253521d9a4cSLisandro Dalcin { 254521d9a4cSLisandro Dalcin PetscErrorCode ierr; 25588f0584fSBarry Smith 256521d9a4cSLisandro Dalcin PetscFunctionBegin; 257521d9a4cSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 258521d9a4cSLisandro Dalcin ierr = PetscFree(dm->mattype);CHKERRQ(ierr); 25919fd82e9SBarry Smith ierr = PetscStrallocpy(ctype,(char**)&dm->mattype);CHKERRQ(ierr); 260521d9a4cSLisandro Dalcin PetscFunctionReturn(0); 261521d9a4cSLisandro Dalcin } 262521d9a4cSLisandro Dalcin 263521d9a4cSLisandro Dalcin #undef __FUNCT__ 264c0dedaeaSBarry Smith #define __FUNCT__ "DMGetMatType" 265c0dedaeaSBarry Smith /*@C 266c0dedaeaSBarry Smith DMGetMatType - Gets the type of matrix created with DMCreateMatrix() 267c0dedaeaSBarry Smith 268c0dedaeaSBarry Smith Logically Collective on DM 269c0dedaeaSBarry Smith 270c0dedaeaSBarry Smith Input Parameter: 271c0dedaeaSBarry Smith . dm - the DM context 272c0dedaeaSBarry Smith 273c0dedaeaSBarry Smith Output Parameter: 274c0dedaeaSBarry Smith . ctype - the matrix type 275c0dedaeaSBarry Smith 276c0dedaeaSBarry Smith Options Database: 277c0dedaeaSBarry Smith . -dm_mat_type ctype 278c0dedaeaSBarry Smith 279c0dedaeaSBarry Smith Level: intermediate 280c0dedaeaSBarry Smith 281c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateMatrix(), DMSetMatrixPreallocateOnly(), MatType, DMSetMatType() 282c0dedaeaSBarry Smith @*/ 283c0dedaeaSBarry Smith PetscErrorCode DMGetMatType(DM dm,MatType *ctype) 284c0dedaeaSBarry Smith { 285c0dedaeaSBarry Smith PetscFunctionBegin; 286c0dedaeaSBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 287c0dedaeaSBarry Smith *ctype = dm->mattype; 288c0dedaeaSBarry Smith PetscFunctionReturn(0); 289c0dedaeaSBarry Smith } 290c0dedaeaSBarry Smith 291c0dedaeaSBarry Smith #undef __FUNCT__ 292c688c046SMatthew G Knepley #define __FUNCT__ "MatGetDM" 293c688c046SMatthew G Knepley /*@ 29434f98d34SBarry Smith MatGetDM - Gets the DM defining the data layout of the matrix 295c688c046SMatthew G Knepley 296c688c046SMatthew G Knepley Not collective 297c688c046SMatthew G Knepley 298c688c046SMatthew G Knepley Input Parameter: 299c688c046SMatthew G Knepley . A - The Mat 300c688c046SMatthew G Knepley 301c688c046SMatthew G Knepley Output Parameter: 302c688c046SMatthew G Knepley . dm - The DM 303c688c046SMatthew G Knepley 304c688c046SMatthew G Knepley Level: intermediate 305c688c046SMatthew G Knepley 306c688c046SMatthew G Knepley .seealso: MatSetDM(), DMCreateMatrix(), DMSetMatType() 307c688c046SMatthew G Knepley @*/ 308c688c046SMatthew G Knepley PetscErrorCode MatGetDM(Mat A, DM *dm) 309c688c046SMatthew G Knepley { 310c688c046SMatthew G Knepley PetscErrorCode ierr; 311c688c046SMatthew G Knepley 312c688c046SMatthew G Knepley PetscFunctionBegin; 313c688c046SMatthew G Knepley PetscValidHeaderSpecific(A,MAT_CLASSID,1); 314c688c046SMatthew G Knepley PetscValidPointer(dm,2); 315c688c046SMatthew G Knepley ierr = PetscObjectQuery((PetscObject) A, "__PETSc_dm", (PetscObject*) dm);CHKERRQ(ierr); 316c688c046SMatthew G Knepley PetscFunctionReturn(0); 317c688c046SMatthew G Knepley } 318c688c046SMatthew G Knepley 319c688c046SMatthew G Knepley #undef __FUNCT__ 320c688c046SMatthew G Knepley #define __FUNCT__ "MatSetDM" 321c688c046SMatthew G Knepley /*@ 322c688c046SMatthew G Knepley MatSetDM - Sets the DM defining the data layout of the matrix 323c688c046SMatthew G Knepley 324c688c046SMatthew G Knepley Not collective 325c688c046SMatthew G Knepley 326c688c046SMatthew G Knepley Input Parameters: 327c688c046SMatthew G Knepley + A - The Mat 328c688c046SMatthew G Knepley - dm - The DM 329c688c046SMatthew G Knepley 330c688c046SMatthew G Knepley Level: intermediate 331c688c046SMatthew G Knepley 332c688c046SMatthew G Knepley .seealso: MatGetDM(), DMCreateMatrix(), DMSetMatType() 333c688c046SMatthew G Knepley @*/ 334c688c046SMatthew G Knepley PetscErrorCode MatSetDM(Mat A, DM dm) 335c688c046SMatthew G Knepley { 336c688c046SMatthew G Knepley PetscErrorCode ierr; 337c688c046SMatthew G Knepley 338c688c046SMatthew G Knepley PetscFunctionBegin; 339c688c046SMatthew G Knepley PetscValidHeaderSpecific(A,MAT_CLASSID,1); 3408865f1eaSKarl Rupp if (dm) PetscValidHeaderSpecific(dm,DM_CLASSID,2); 341c688c046SMatthew G Knepley ierr = PetscObjectCompose((PetscObject) A, "__PETSc_dm", (PetscObject) dm);CHKERRQ(ierr); 342c688c046SMatthew G Knepley PetscFunctionReturn(0); 343c688c046SMatthew G Knepley } 344c688c046SMatthew G Knepley 345c688c046SMatthew G Knepley #undef __FUNCT__ 3469a42bb27SBarry Smith #define __FUNCT__ "DMSetOptionsPrefix" 3479a42bb27SBarry Smith /*@C 3489a42bb27SBarry Smith DMSetOptionsPrefix - Sets the prefix used for searching for all 349aa219208SBarry Smith DMDA options in the database. 3509a42bb27SBarry Smith 351aa219208SBarry Smith Logically Collective on DMDA 3529a42bb27SBarry Smith 3539a42bb27SBarry Smith Input Parameter: 354aa219208SBarry Smith + da - the DMDA context 3559a42bb27SBarry Smith - prefix - the prefix to prepend to all option names 3569a42bb27SBarry Smith 3579a42bb27SBarry Smith Notes: 3589a42bb27SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 3599a42bb27SBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 3609a42bb27SBarry Smith 3619a42bb27SBarry Smith Level: advanced 3629a42bb27SBarry Smith 363aa219208SBarry Smith .keywords: DMDA, set, options, prefix, database 3649a42bb27SBarry Smith 3659a42bb27SBarry Smith .seealso: DMSetFromOptions() 3669a42bb27SBarry Smith @*/ 3677087cfbeSBarry Smith PetscErrorCode DMSetOptionsPrefix(DM dm,const char prefix[]) 3689a42bb27SBarry Smith { 3699a42bb27SBarry Smith PetscErrorCode ierr; 3709a42bb27SBarry Smith 3719a42bb27SBarry Smith PetscFunctionBegin; 3729a42bb27SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3739a42bb27SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)dm,prefix);CHKERRQ(ierr); 3749a42bb27SBarry Smith PetscFunctionReturn(0); 3759a42bb27SBarry Smith } 3769a42bb27SBarry Smith 3779a42bb27SBarry Smith #undef __FUNCT__ 37847c6ae99SBarry Smith #define __FUNCT__ "DMDestroy" 37947c6ae99SBarry Smith /*@ 380aa219208SBarry Smith DMDestroy - Destroys a vector packer or DMDA. 38147c6ae99SBarry Smith 38247c6ae99SBarry Smith Collective on DM 38347c6ae99SBarry Smith 38447c6ae99SBarry Smith Input Parameter: 38547c6ae99SBarry Smith . dm - the DM object to destroy 38647c6ae99SBarry Smith 38747c6ae99SBarry Smith Level: developer 38847c6ae99SBarry Smith 389e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 39047c6ae99SBarry Smith 39147c6ae99SBarry Smith @*/ 392fcfd50ebSBarry Smith PetscErrorCode DMDestroy(DM *dm) 39347c6ae99SBarry Smith { 394c83e3748SMatthew G. Knepley PetscInt i, cnt = 0; 395dfe15315SJed Brown DMNamedVecLink nlink,nnext; 39647c6ae99SBarry Smith PetscErrorCode ierr; 39747c6ae99SBarry Smith 39847c6ae99SBarry Smith PetscFunctionBegin; 3996bf464f9SBarry Smith if (!*dm) PetscFunctionReturn(0); 4006bf464f9SBarry Smith PetscValidHeaderSpecific((*dm),DM_CLASSID,1); 40187e657c6SBarry Smith 40287e657c6SBarry Smith /* count all the circular references of DM and its contained Vecs */ 403732e2eb9SMatthew G Knepley for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 4048865f1eaSKarl Rupp if ((*dm)->localin[i]) cnt++; 4058865f1eaSKarl Rupp if ((*dm)->globalin[i]) cnt++; 406732e2eb9SMatthew G Knepley } 407dfe15315SJed Brown for (nlink=(*dm)->namedglobal; nlink; nlink=nlink->next) cnt++; 4082348bcf4SPeter Brune for (nlink=(*dm)->namedlocal; nlink; nlink=nlink->next) cnt++; 4092348bcf4SPeter Brune if ((*dm)->x) { 4102348bcf4SPeter Brune DM obj; 4112348bcf4SPeter Brune ierr = VecGetDM((*dm)->x, &obj);CHKERRQ(ierr); 4122348bcf4SPeter Brune if (obj == *dm) cnt++; 4132348bcf4SPeter Brune } 414732e2eb9SMatthew G Knepley 4156bf464f9SBarry Smith if (--((PetscObject)(*dm))->refct - cnt > 0) {*dm = 0; PetscFunctionReturn(0);} 416732e2eb9SMatthew G Knepley /* 417732e2eb9SMatthew G Knepley Need this test because the dm references the vectors that 418732e2eb9SMatthew G Knepley reference the dm, so destroying the dm calls destroy on the 419732e2eb9SMatthew G Knepley vectors that cause another destroy on the dm 420732e2eb9SMatthew G Knepley */ 4216bf464f9SBarry Smith if (((PetscObject)(*dm))->refct < 0) PetscFunctionReturn(0); 4226bf464f9SBarry Smith ((PetscObject) (*dm))->refct = 0; 423732e2eb9SMatthew G Knepley for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 4246bf464f9SBarry Smith if ((*dm)->localout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a local vector obtained with DMGetLocalVector()"); 4256bf464f9SBarry Smith ierr = VecDestroy(&(*dm)->localin[i]);CHKERRQ(ierr); 426732e2eb9SMatthew G Knepley } 427f490541aSPeter Brune nnext=(*dm)->namedglobal; 4280298fd71SBarry Smith (*dm)->namedglobal = NULL; 429f490541aSPeter Brune for (nlink=nnext; nlink; nlink=nnext) { /* Destroy the named vectors */ 4302348bcf4SPeter Brune nnext = nlink->next; 4312348bcf4SPeter 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); 4322348bcf4SPeter Brune ierr = PetscFree(nlink->name);CHKERRQ(ierr); 4332348bcf4SPeter Brune ierr = VecDestroy(&nlink->X);CHKERRQ(ierr); 4342348bcf4SPeter Brune ierr = PetscFree(nlink);CHKERRQ(ierr); 4352348bcf4SPeter Brune } 436f490541aSPeter Brune nnext=(*dm)->namedlocal; 4370298fd71SBarry Smith (*dm)->namedlocal = NULL; 438f490541aSPeter Brune for (nlink=nnext; nlink; nlink=nnext) { /* Destroy the named local vectors */ 439f490541aSPeter Brune nnext = nlink->next; 440f490541aSPeter 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); 441f490541aSPeter Brune ierr = PetscFree(nlink->name);CHKERRQ(ierr); 442f490541aSPeter Brune ierr = VecDestroy(&nlink->X);CHKERRQ(ierr); 443f490541aSPeter Brune ierr = PetscFree(nlink);CHKERRQ(ierr); 444f490541aSPeter Brune } 4452348bcf4SPeter Brune 446b17ce1afSJed Brown /* Destroy the list of hooks */ 447c833c3b5SJed Brown { 448c833c3b5SJed Brown DMCoarsenHookLink link,next; 449b17ce1afSJed Brown for (link=(*dm)->coarsenhook; link; link=next) { 450b17ce1afSJed Brown next = link->next; 451b17ce1afSJed Brown ierr = PetscFree(link);CHKERRQ(ierr); 452b17ce1afSJed Brown } 4530298fd71SBarry Smith (*dm)->coarsenhook = NULL; 454c833c3b5SJed Brown } 455c833c3b5SJed Brown { 456c833c3b5SJed Brown DMRefineHookLink link,next; 457c833c3b5SJed Brown for (link=(*dm)->refinehook; link; link=next) { 458c833c3b5SJed Brown next = link->next; 459c833c3b5SJed Brown ierr = PetscFree(link);CHKERRQ(ierr); 460c833c3b5SJed Brown } 4610298fd71SBarry Smith (*dm)->refinehook = NULL; 462c833c3b5SJed Brown } 463be081cd6SPeter Brune { 464be081cd6SPeter Brune DMSubDomainHookLink link,next; 465be081cd6SPeter Brune for (link=(*dm)->subdomainhook; link; link=next) { 466be081cd6SPeter Brune next = link->next; 467be081cd6SPeter Brune ierr = PetscFree(link);CHKERRQ(ierr); 468be081cd6SPeter Brune } 4690298fd71SBarry Smith (*dm)->subdomainhook = NULL; 470be081cd6SPeter Brune } 471baf369e7SPeter Brune { 472baf369e7SPeter Brune DMGlobalToLocalHookLink link,next; 473baf369e7SPeter Brune for (link=(*dm)->gtolhook; link; link=next) { 474baf369e7SPeter Brune next = link->next; 475baf369e7SPeter Brune ierr = PetscFree(link);CHKERRQ(ierr); 476baf369e7SPeter Brune } 4770298fd71SBarry Smith (*dm)->gtolhook = NULL; 478baf369e7SPeter Brune } 479aa1993deSMatthew G Knepley /* Destroy the work arrays */ 480aa1993deSMatthew G Knepley { 481aa1993deSMatthew G Knepley DMWorkLink link,next; 482aa1993deSMatthew G Knepley if ((*dm)->workout) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Work array still checked out"); 483aa1993deSMatthew G Knepley for (link=(*dm)->workin; link; link=next) { 484aa1993deSMatthew G Knepley next = link->next; 485aa1993deSMatthew G Knepley ierr = PetscFree(link->mem);CHKERRQ(ierr); 486aa1993deSMatthew G Knepley ierr = PetscFree(link);CHKERRQ(ierr); 487aa1993deSMatthew G Knepley } 4880298fd71SBarry Smith (*dm)->workin = NULL; 489aa1993deSMatthew G Knepley } 490b17ce1afSJed Brown 49152536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmksp);CHKERRQ(ierr); 49252536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmsnes);CHKERRQ(ierr); 49352536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmts);CHKERRQ(ierr); 49452536dc3SBarry Smith 4951a266240SBarry Smith if ((*dm)->ctx && (*dm)->ctxdestroy) { 4961a266240SBarry Smith ierr = (*(*dm)->ctxdestroy)(&(*dm)->ctx);CHKERRQ(ierr); 4971a266240SBarry Smith } 49887e657c6SBarry Smith ierr = VecDestroy(&(*dm)->x);CHKERRQ(ierr); 49971cd77b2SBarry Smith ierr = MatFDColoringDestroy(&(*dm)->fd);CHKERRQ(ierr); 5004dcab191SBarry Smith ierr = DMClearGlobalVectors(*dm);CHKERRQ(ierr); 5016bf464f9SBarry Smith ierr = ISLocalToGlobalMappingDestroy(&(*dm)->ltogmap);CHKERRQ(ierr); 5026bf464f9SBarry Smith ierr = PetscFree((*dm)->vectype);CHKERRQ(ierr); 503073dac72SJed Brown ierr = PetscFree((*dm)->mattype);CHKERRQ(ierr); 50488ed4aceSMatthew G Knepley 50588ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&(*dm)->defaultSection);CHKERRQ(ierr); 50688ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&(*dm)->defaultGlobalSection);CHKERRQ(ierr); 5078b1ab98fSJed Brown ierr = PetscLayoutDestroy(&(*dm)->map);CHKERRQ(ierr); 50888ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&(*dm)->sf);CHKERRQ(ierr); 50988ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&(*dm)->defaultSF);CHKERRQ(ierr); 510af122d2aSMatthew G Knepley 5116636e97aSMatthew G Knepley ierr = DMDestroy(&(*dm)->coordinateDM);CHKERRQ(ierr); 5126636e97aSMatthew G Knepley ierr = VecDestroy(&(*dm)->coordinates);CHKERRQ(ierr); 5136636e97aSMatthew G Knepley ierr = VecDestroy(&(*dm)->coordinatesLocal);CHKERRQ(ierr); 514c6b900c6SMatthew G. Knepley ierr = PetscFree((*dm)->maxCell);CHKERRQ(ierr); 515c6b900c6SMatthew G. Knepley ierr = PetscFree((*dm)->L);CHKERRQ(ierr); 5166636e97aSMatthew G Knepley 5172764a2aaSMatthew G. Knepley ierr = PetscDSDestroy(&(*dm)->prob);CHKERRQ(ierr); 51814f150ffSMatthew G. Knepley ierr = DMDestroy(&(*dm)->dmBC);CHKERRQ(ierr); 519e04113cfSBarry Smith /* if memory was published with SAWs then destroy it */ 520e04113cfSBarry Smith ierr = PetscObjectSAWsViewOff((PetscObject)*dm);CHKERRQ(ierr); 521732e2eb9SMatthew G Knepley 5226bf464f9SBarry Smith ierr = (*(*dm)->ops->destroy)(*dm);CHKERRQ(ierr); 523435a35e8SMatthew G Knepley /* We do not destroy (*dm)->data here so that we can reference count backend objects */ 524732e2eb9SMatthew G Knepley ierr = PetscHeaderDestroy(dm);CHKERRQ(ierr); 52547c6ae99SBarry Smith PetscFunctionReturn(0); 52647c6ae99SBarry Smith } 52747c6ae99SBarry Smith 52847c6ae99SBarry Smith #undef __FUNCT__ 529d7bf68aeSBarry Smith #define __FUNCT__ "DMSetUp" 530d7bf68aeSBarry Smith /*@ 531d7bf68aeSBarry Smith DMSetUp - sets up the data structures inside a DM object 532d7bf68aeSBarry Smith 533d7bf68aeSBarry Smith Collective on DM 534d7bf68aeSBarry Smith 535d7bf68aeSBarry Smith Input Parameter: 536d7bf68aeSBarry Smith . dm - the DM object to setup 537d7bf68aeSBarry Smith 538d7bf68aeSBarry Smith Level: developer 539d7bf68aeSBarry Smith 540e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 541d7bf68aeSBarry Smith 542d7bf68aeSBarry Smith @*/ 5437087cfbeSBarry Smith PetscErrorCode DMSetUp(DM dm) 544d7bf68aeSBarry Smith { 545d7bf68aeSBarry Smith PetscErrorCode ierr; 546d7bf68aeSBarry Smith 547d7bf68aeSBarry Smith PetscFunctionBegin; 548171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5498387afaaSJed Brown if (dm->setupcalled) PetscFunctionReturn(0); 550d7bf68aeSBarry Smith if (dm->ops->setup) { 551d7bf68aeSBarry Smith ierr = (*dm->ops->setup)(dm);CHKERRQ(ierr); 552d7bf68aeSBarry Smith } 5538387afaaSJed Brown dm->setupcalled = PETSC_TRUE; 554d7bf68aeSBarry Smith PetscFunctionReturn(0); 555d7bf68aeSBarry Smith } 556d7bf68aeSBarry Smith 557d7bf68aeSBarry Smith #undef __FUNCT__ 558d7bf68aeSBarry Smith #define __FUNCT__ "DMSetFromOptions" 559d7bf68aeSBarry Smith /*@ 560d7bf68aeSBarry Smith DMSetFromOptions - sets parameters in a DM from the options database 561d7bf68aeSBarry Smith 562d7bf68aeSBarry Smith Collective on DM 563d7bf68aeSBarry Smith 564d7bf68aeSBarry Smith Input Parameter: 565d7bf68aeSBarry Smith . dm - the DM object to set options for 566d7bf68aeSBarry Smith 567732e2eb9SMatthew G Knepley Options Database: 568dd85299cSBarry Smith + -dm_preallocate_only: Only preallocate the matrix for DMCreateMatrix(), but do not fill it with zeros 569dd85299cSBarry Smith . -dm_vec_type <type> type of vector to create inside DM 570171400e9SBarry Smith . -dm_mat_type <type> type of matrix to create inside DM 571171400e9SBarry Smith - -dm_coloring_type <global or ghosted> 572732e2eb9SMatthew G Knepley 573d7bf68aeSBarry Smith Level: developer 574d7bf68aeSBarry Smith 575e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 576d7bf68aeSBarry Smith 577d7bf68aeSBarry Smith @*/ 5787087cfbeSBarry Smith PetscErrorCode DMSetFromOptions(DM dm) 579d7bf68aeSBarry Smith { 5807781c08eSBarry Smith char typeName[256]; 581ca266f36SBarry Smith PetscBool flg; 582d7bf68aeSBarry Smith PetscErrorCode ierr; 583d7bf68aeSBarry Smith 584d7bf68aeSBarry Smith PetscFunctionBegin; 585171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5863194b578SJed Brown ierr = PetscObjectOptionsBegin((PetscObject)dm);CHKERRQ(ierr); 5870298fd71SBarry 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); 588a264d7a6SBarry Smith ierr = PetscOptionsFList("-dm_vec_type","Vector type used for created vectors","DMSetVecType",VecList,dm->vectype,typeName,256,&flg);CHKERRQ(ierr); 589f9ba7244SBarry Smith if (flg) { 590f9ba7244SBarry Smith ierr = DMSetVecType(dm,typeName);CHKERRQ(ierr); 591f9ba7244SBarry Smith } 592a264d7a6SBarry 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); 593073dac72SJed Brown if (flg) { 594521d9a4cSLisandro Dalcin ierr = DMSetMatType(dm,typeName);CHKERRQ(ierr); 595073dac72SJed Brown } 5960298fd71SBarry Smith ierr = PetscOptionsEnum("-dm_is_coloring_type","Global or local coloring of Jacobian","ISColoringType",ISColoringTypes,(PetscEnum)dm->coloringtype,(PetscEnum*)&dm->coloringtype,NULL);CHKERRQ(ierr); 597f9ba7244SBarry Smith if (dm->ops->setfromoptions) { 598f9ba7244SBarry Smith ierr = (*dm->ops->setfromoptions)(dm);CHKERRQ(ierr); 599f9ba7244SBarry Smith } 600f9ba7244SBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 601f9ba7244SBarry Smith ierr = PetscObjectProcessOptionsHandlers((PetscObject) dm);CHKERRQ(ierr); 60282fcb398SMatthew G Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 603d7bf68aeSBarry Smith PetscFunctionReturn(0); 604d7bf68aeSBarry Smith } 605d7bf68aeSBarry Smith 606d7bf68aeSBarry Smith #undef __FUNCT__ 60747c6ae99SBarry Smith #define __FUNCT__ "DMView" 608fc9bc008SSatish Balay /*@C 609aa219208SBarry Smith DMView - Views a vector packer or DMDA. 61047c6ae99SBarry Smith 61147c6ae99SBarry Smith Collective on DM 61247c6ae99SBarry Smith 61347c6ae99SBarry Smith Input Parameter: 61447c6ae99SBarry Smith + dm - the DM object to view 61547c6ae99SBarry Smith - v - the viewer 61647c6ae99SBarry Smith 61747c6ae99SBarry Smith Level: developer 61847c6ae99SBarry Smith 619e727c939SJed Brown .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 62047c6ae99SBarry Smith 62147c6ae99SBarry Smith @*/ 6227087cfbeSBarry Smith PetscErrorCode DMView(DM dm,PetscViewer v) 62347c6ae99SBarry Smith { 62447c6ae99SBarry Smith PetscErrorCode ierr; 62532c0f0efSBarry Smith PetscBool isbinary; 62647c6ae99SBarry Smith 62747c6ae99SBarry Smith PetscFunctionBegin; 628171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6293014e516SBarry Smith if (!v) { 630ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)dm),&v);CHKERRQ(ierr); 6313014e516SBarry Smith } 63298c3331eSBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)dm,v);CHKERRQ(ierr); 63332c0f0efSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); 63432c0f0efSBarry Smith if (isbinary) { 63555849f57SBarry Smith PetscInt classid = DM_FILE_CLASSID; 63632c0f0efSBarry Smith char type[256]; 63732c0f0efSBarry Smith 63832c0f0efSBarry Smith ierr = PetscViewerBinaryWrite(v,&classid,1,PETSC_INT,PETSC_FALSE);CHKERRQ(ierr); 63932c0f0efSBarry Smith ierr = PetscStrncpy(type,((PetscObject)dm)->type_name,256);CHKERRQ(ierr); 64032c0f0efSBarry Smith ierr = PetscViewerBinaryWrite(v,type,256,PETSC_CHAR,PETSC_FALSE);CHKERRQ(ierr); 64132c0f0efSBarry Smith } 6420c010503SBarry Smith if (dm->ops->view) { 6430c010503SBarry Smith ierr = (*dm->ops->view)(dm,v);CHKERRQ(ierr); 64447c6ae99SBarry Smith } 64547c6ae99SBarry Smith PetscFunctionReturn(0); 64647c6ae99SBarry Smith } 64747c6ae99SBarry Smith 64847c6ae99SBarry Smith #undef __FUNCT__ 64947c6ae99SBarry Smith #define __FUNCT__ "DMCreateGlobalVector" 65047c6ae99SBarry Smith /*@ 651aa219208SBarry Smith DMCreateGlobalVector - Creates a global vector from a DMDA or DMComposite object 65247c6ae99SBarry Smith 65347c6ae99SBarry Smith Collective on DM 65447c6ae99SBarry Smith 65547c6ae99SBarry Smith Input Parameter: 65647c6ae99SBarry Smith . dm - the DM object 65747c6ae99SBarry Smith 65847c6ae99SBarry Smith Output Parameter: 65947c6ae99SBarry Smith . vec - the global vector 66047c6ae99SBarry Smith 661073dac72SJed Brown Level: beginner 66247c6ae99SBarry Smith 663e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 66447c6ae99SBarry Smith 66547c6ae99SBarry Smith @*/ 6667087cfbeSBarry Smith PetscErrorCode DMCreateGlobalVector(DM dm,Vec *vec) 66747c6ae99SBarry Smith { 66847c6ae99SBarry Smith PetscErrorCode ierr; 66947c6ae99SBarry Smith 67047c6ae99SBarry Smith PetscFunctionBegin; 671171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 67247c6ae99SBarry Smith ierr = (*dm->ops->createglobalvector)(dm,vec);CHKERRQ(ierr); 67347c6ae99SBarry Smith PetscFunctionReturn(0); 67447c6ae99SBarry Smith } 67547c6ae99SBarry Smith 67647c6ae99SBarry Smith #undef __FUNCT__ 67747c6ae99SBarry Smith #define __FUNCT__ "DMCreateLocalVector" 67847c6ae99SBarry Smith /*@ 679aa219208SBarry Smith DMCreateLocalVector - Creates a local vector from a DMDA or DMComposite object 68047c6ae99SBarry Smith 68147c6ae99SBarry Smith Not Collective 68247c6ae99SBarry Smith 68347c6ae99SBarry Smith Input Parameter: 68447c6ae99SBarry Smith . dm - the DM object 68547c6ae99SBarry Smith 68647c6ae99SBarry Smith Output Parameter: 68747c6ae99SBarry Smith . vec - the local vector 68847c6ae99SBarry Smith 689073dac72SJed Brown Level: beginner 69047c6ae99SBarry Smith 691e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 69247c6ae99SBarry Smith 69347c6ae99SBarry Smith @*/ 6947087cfbeSBarry Smith PetscErrorCode DMCreateLocalVector(DM dm,Vec *vec) 69547c6ae99SBarry Smith { 69647c6ae99SBarry Smith PetscErrorCode ierr; 69747c6ae99SBarry Smith 69847c6ae99SBarry Smith PetscFunctionBegin; 699171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 70047c6ae99SBarry Smith ierr = (*dm->ops->createlocalvector)(dm,vec);CHKERRQ(ierr); 70147c6ae99SBarry Smith PetscFunctionReturn(0); 70247c6ae99SBarry Smith } 70347c6ae99SBarry Smith 70447c6ae99SBarry Smith #undef __FUNCT__ 7051411c6eeSJed Brown #define __FUNCT__ "DMGetLocalToGlobalMapping" 7061411c6eeSJed Brown /*@ 7071411c6eeSJed Brown DMGetLocalToGlobalMapping - Accesses the local-to-global mapping in a DM. 7081411c6eeSJed Brown 7091411c6eeSJed Brown Collective on DM 7101411c6eeSJed Brown 7111411c6eeSJed Brown Input Parameter: 7121411c6eeSJed Brown . dm - the DM that provides the mapping 7131411c6eeSJed Brown 7141411c6eeSJed Brown Output Parameter: 7151411c6eeSJed Brown . ltog - the mapping 7161411c6eeSJed Brown 7171411c6eeSJed Brown Level: intermediate 7181411c6eeSJed Brown 7191411c6eeSJed Brown Notes: 7201411c6eeSJed Brown This mapping can then be used by VecSetLocalToGlobalMapping() or 7211411c6eeSJed Brown MatSetLocalToGlobalMapping(). 7221411c6eeSJed Brown 723fc31e74dSBarry Smith .seealso: DMCreateLocalVector() 7241411c6eeSJed Brown @*/ 7257087cfbeSBarry Smith PetscErrorCode DMGetLocalToGlobalMapping(DM dm,ISLocalToGlobalMapping *ltog) 7261411c6eeSJed Brown { 7271411c6eeSJed Brown PetscErrorCode ierr; 7281411c6eeSJed Brown 7291411c6eeSJed Brown PetscFunctionBegin; 7301411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7311411c6eeSJed Brown PetscValidPointer(ltog,2); 7321411c6eeSJed Brown if (!dm->ltogmap) { 73337d0c07bSMatthew G Knepley PetscSection section, sectionGlobal; 73437d0c07bSMatthew G Knepley 73537d0c07bSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 73637d0c07bSMatthew G Knepley if (section) { 73737d0c07bSMatthew G Knepley PetscInt *ltog; 73837d0c07bSMatthew G Knepley PetscInt pStart, pEnd, size, p, l; 73937d0c07bSMatthew G Knepley 74037d0c07bSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 74137d0c07bSMatthew G Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 74237d0c07bSMatthew G Knepley ierr = PetscSectionGetStorageSize(section, &size);CHKERRQ(ierr); 743785e854fSJed Brown ierr = PetscMalloc1(size, <og);CHKERRQ(ierr); /* We want the local+overlap size */ 74437d0c07bSMatthew G Knepley for (p = pStart, l = 0; p < pEnd; ++p) { 74537d0c07bSMatthew G Knepley PetscInt dof, off, c; 74637d0c07bSMatthew G Knepley 74737d0c07bSMatthew G Knepley /* Should probably use constrained dofs */ 74837d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(section, p, &dof);CHKERRQ(ierr); 74937d0c07bSMatthew G Knepley ierr = PetscSectionGetOffset(sectionGlobal, p, &off);CHKERRQ(ierr); 75037d0c07bSMatthew G Knepley for (c = 0; c < dof; ++c, ++l) { 75137d0c07bSMatthew G Knepley ltog[l] = off+c; 75237d0c07bSMatthew G Knepley } 75337d0c07bSMatthew G Knepley } 754f0413b6fSBarry Smith ierr = ISLocalToGlobalMappingCreate(PETSC_COMM_SELF, 1,size, ltog, PETSC_OWN_POINTER, &dm->ltogmap);CHKERRQ(ierr); 7553bb1ff40SBarry Smith ierr = PetscLogObjectParent((PetscObject)dm, (PetscObject)dm->ltogmap);CHKERRQ(ierr); 75637d0c07bSMatthew G Knepley } else { 757184d77edSJed Brown if (!dm->ops->getlocaltoglobalmapping) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM can not create LocalToGlobalMapping"); 758184d77edSJed Brown ierr = (*dm->ops->getlocaltoglobalmapping)(dm);CHKERRQ(ierr); 7591411c6eeSJed Brown } 76037d0c07bSMatthew G Knepley } 7611411c6eeSJed Brown *ltog = dm->ltogmap; 7621411c6eeSJed Brown PetscFunctionReturn(0); 7631411c6eeSJed Brown } 7641411c6eeSJed Brown 7651411c6eeSJed Brown #undef __FUNCT__ 7661411c6eeSJed Brown #define __FUNCT__ "DMGetBlockSize" 7671411c6eeSJed Brown /*@ 7681411c6eeSJed Brown DMGetBlockSize - Gets the inherent block size associated with a DM 7691411c6eeSJed Brown 7701411c6eeSJed Brown Not Collective 7711411c6eeSJed Brown 7721411c6eeSJed Brown Input Parameter: 7731411c6eeSJed Brown . dm - the DM with block structure 7741411c6eeSJed Brown 7751411c6eeSJed Brown Output Parameter: 7761411c6eeSJed Brown . bs - the block size, 1 implies no exploitable block structure 7771411c6eeSJed Brown 7781411c6eeSJed Brown Level: intermediate 7791411c6eeSJed Brown 780fc31e74dSBarry Smith .seealso: ISCreateBlock(), VecSetBlockSize(), MatSetBlockSize(), DMGetLocalToGlobalMapping() 7811411c6eeSJed Brown @*/ 7827087cfbeSBarry Smith PetscErrorCode DMGetBlockSize(DM dm,PetscInt *bs) 7831411c6eeSJed Brown { 7841411c6eeSJed Brown PetscFunctionBegin; 7851411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7861411c6eeSJed Brown PetscValidPointer(bs,2); 7871411c6eeSJed 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"); 7881411c6eeSJed Brown *bs = dm->bs; 7891411c6eeSJed Brown PetscFunctionReturn(0); 7901411c6eeSJed Brown } 7911411c6eeSJed Brown 7921411c6eeSJed Brown #undef __FUNCT__ 793e727c939SJed Brown #define __FUNCT__ "DMCreateInterpolation" 79447c6ae99SBarry Smith /*@ 795e727c939SJed Brown DMCreateInterpolation - Gets interpolation matrix between two DMDA or DMComposite objects 79647c6ae99SBarry Smith 79747c6ae99SBarry Smith Collective on DM 79847c6ae99SBarry Smith 79947c6ae99SBarry Smith Input Parameter: 80047c6ae99SBarry Smith + dm1 - the DM object 80147c6ae99SBarry Smith - dm2 - the second, finer DM object 80247c6ae99SBarry Smith 80347c6ae99SBarry Smith Output Parameter: 80447c6ae99SBarry Smith + mat - the interpolation 80547c6ae99SBarry Smith - vec - the scaling (optional) 80647c6ae99SBarry Smith 80747c6ae99SBarry Smith Level: developer 80847c6ae99SBarry Smith 80985afcc9aSBarry 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 81085afcc9aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the interpolation. 811d52bd9f3SBarry Smith 8121f588964SMatthew G Knepley For DMDA objects you can use this interpolation (more precisely the interpolation from the DMGetCoordinateDM()) to interpolate the mesh coordinate vectors 813d52bd9f3SBarry Smith EXCEPT in the periodic case where it does not make sense since the coordinate vectors are not periodic. 81485afcc9aSBarry Smith 81585afcc9aSBarry Smith 816e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMRefine(), DMCoarsen() 81747c6ae99SBarry Smith 81847c6ae99SBarry Smith @*/ 819e727c939SJed Brown PetscErrorCode DMCreateInterpolation(DM dm1,DM dm2,Mat *mat,Vec *vec) 82047c6ae99SBarry Smith { 82147c6ae99SBarry Smith PetscErrorCode ierr; 82247c6ae99SBarry Smith 82347c6ae99SBarry Smith PetscFunctionBegin; 824171400e9SBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 825171400e9SBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 82625296bd5SBarry Smith ierr = (*dm1->ops->createinterpolation)(dm1,dm2,mat,vec);CHKERRQ(ierr); 82747c6ae99SBarry Smith PetscFunctionReturn(0); 82847c6ae99SBarry Smith } 82947c6ae99SBarry Smith 83047c6ae99SBarry Smith #undef __FUNCT__ 831e727c939SJed Brown #define __FUNCT__ "DMCreateInjection" 83247c6ae99SBarry Smith /*@ 833e727c939SJed Brown DMCreateInjection - Gets injection matrix between two DMDA or DMComposite objects 83447c6ae99SBarry Smith 83547c6ae99SBarry Smith Collective on DM 83647c6ae99SBarry Smith 83747c6ae99SBarry Smith Input Parameter: 83847c6ae99SBarry Smith + dm1 - the DM object 83947c6ae99SBarry Smith - dm2 - the second, finer DM object 84047c6ae99SBarry Smith 84147c6ae99SBarry Smith Output Parameter: 84247c6ae99SBarry Smith . ctx - the injection 84347c6ae99SBarry Smith 84447c6ae99SBarry Smith Level: developer 84547c6ae99SBarry Smith 84685afcc9aSBarry 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 84785afcc9aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the injection. 84885afcc9aSBarry Smith 849e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMCreateInterpolation() 85047c6ae99SBarry Smith 85147c6ae99SBarry Smith @*/ 852e727c939SJed Brown PetscErrorCode DMCreateInjection(DM dm1,DM dm2,VecScatter *ctx) 85347c6ae99SBarry Smith { 85447c6ae99SBarry Smith PetscErrorCode ierr; 85547c6ae99SBarry Smith 85647c6ae99SBarry Smith PetscFunctionBegin; 857171400e9SBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 858171400e9SBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 85947c6ae99SBarry Smith ierr = (*dm1->ops->getinjection)(dm1,dm2,ctx);CHKERRQ(ierr); 86047c6ae99SBarry Smith PetscFunctionReturn(0); 86147c6ae99SBarry Smith } 86247c6ae99SBarry Smith 86347c6ae99SBarry Smith #undef __FUNCT__ 864e727c939SJed Brown #define __FUNCT__ "DMCreateColoring" 865b412c318SBarry Smith /*@ 866b412c318SBarry Smith DMCreateColoring - Gets coloring for a DM 86747c6ae99SBarry Smith 86847c6ae99SBarry Smith Collective on DM 86947c6ae99SBarry Smith 87047c6ae99SBarry Smith Input Parameter: 87147c6ae99SBarry Smith + dm - the DM object 872b412c318SBarry Smith - ctype - IS_COLORING_GHOSTED or IS_COLORING_GLOBAL 87347c6ae99SBarry Smith 87447c6ae99SBarry Smith Output Parameter: 87547c6ae99SBarry Smith . coloring - the coloring 87647c6ae99SBarry Smith 87747c6ae99SBarry Smith Level: developer 87847c6ae99SBarry Smith 879b412c318SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateMatrix(), DMSetMatType() 88047c6ae99SBarry Smith 881aab9d709SJed Brown @*/ 882b412c318SBarry Smith PetscErrorCode DMCreateColoring(DM dm,ISColoringType ctype,ISColoring *coloring) 88347c6ae99SBarry Smith { 88447c6ae99SBarry Smith PetscErrorCode ierr; 88547c6ae99SBarry Smith 88647c6ae99SBarry Smith PetscFunctionBegin; 887171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 888ce94432eSBarry Smith if (!dm->ops->getcoloring) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No coloring for this type of DM yet"); 889b412c318SBarry Smith ierr = (*dm->ops->getcoloring)(dm,ctype,coloring);CHKERRQ(ierr); 89047c6ae99SBarry Smith PetscFunctionReturn(0); 89147c6ae99SBarry Smith } 89247c6ae99SBarry Smith 89347c6ae99SBarry Smith #undef __FUNCT__ 894950540a4SJed Brown #define __FUNCT__ "DMCreateMatrix" 895b412c318SBarry Smith /*@ 896950540a4SJed Brown DMCreateMatrix - Gets empty Jacobian for a DMDA or DMComposite 89747c6ae99SBarry Smith 89847c6ae99SBarry Smith Collective on DM 89947c6ae99SBarry Smith 90047c6ae99SBarry Smith Input Parameter: 901b412c318SBarry Smith . dm - the DM object 90247c6ae99SBarry Smith 90347c6ae99SBarry Smith Output Parameter: 90447c6ae99SBarry Smith . mat - the empty Jacobian 90547c6ae99SBarry Smith 906073dac72SJed Brown Level: beginner 90747c6ae99SBarry Smith 90894013140SBarry Smith Notes: This properly preallocates the number of nonzeros in the sparse matrix so you 90994013140SBarry Smith do not need to do it yourself. 91094013140SBarry Smith 91194013140SBarry Smith By default it also sets the nonzero structure and puts in the zero entries. To prevent setting 912aa219208SBarry Smith the nonzero pattern call DMDASetMatPreallocateOnly() 91394013140SBarry Smith 91494013140SBarry 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 91594013140SBarry Smith internally by PETSc. 91694013140SBarry Smith 91794013140SBarry Smith For structured grid problems, in general it is easiest to use MatSetValuesStencil() or MatSetValuesLocal() to put values into the matrix because MatSetValues() requires 918aa219208SBarry Smith the indices for the global numbering for DMDAs which is complicated. 91994013140SBarry Smith 920b412c318SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMSetMatType() 92147c6ae99SBarry Smith 922aab9d709SJed Brown @*/ 923b412c318SBarry Smith PetscErrorCode DMCreateMatrix(DM dm,Mat *mat) 92447c6ae99SBarry Smith { 92547c6ae99SBarry Smith PetscErrorCode ierr; 92647c6ae99SBarry Smith 92747c6ae99SBarry Smith PetscFunctionBegin; 928171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 929607a6623SBarry Smith ierr = MatInitializePackage();CHKERRQ(ierr); 930c7b7c8a4SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 931c7b7c8a4SJed Brown PetscValidPointer(mat,3); 932b412c318SBarry Smith ierr = (*dm->ops->creatematrix)(dm,mat);CHKERRQ(ierr); 93347c6ae99SBarry Smith PetscFunctionReturn(0); 93447c6ae99SBarry Smith } 93547c6ae99SBarry Smith 93647c6ae99SBarry Smith #undef __FUNCT__ 937732e2eb9SMatthew G Knepley #define __FUNCT__ "DMSetMatrixPreallocateOnly" 938732e2eb9SMatthew G Knepley /*@ 939950540a4SJed Brown DMSetMatrixPreallocateOnly - When DMCreateMatrix() is called the matrix will be properly 940732e2eb9SMatthew G Knepley preallocated but the nonzero structure and zero values will not be set. 941732e2eb9SMatthew G Knepley 942732e2eb9SMatthew G Knepley Logically Collective on DMDA 943732e2eb9SMatthew G Knepley 944732e2eb9SMatthew G Knepley Input Parameter: 945732e2eb9SMatthew G Knepley + dm - the DM 946732e2eb9SMatthew G Knepley - only - PETSC_TRUE if only want preallocation 947732e2eb9SMatthew G Knepley 948732e2eb9SMatthew G Knepley Level: developer 949950540a4SJed Brown .seealso DMCreateMatrix() 950732e2eb9SMatthew G Knepley @*/ 951732e2eb9SMatthew G Knepley PetscErrorCode DMSetMatrixPreallocateOnly(DM dm, PetscBool only) 952732e2eb9SMatthew G Knepley { 953732e2eb9SMatthew G Knepley PetscFunctionBegin; 954732e2eb9SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 955732e2eb9SMatthew G Knepley dm->prealloc_only = only; 956732e2eb9SMatthew G Knepley PetscFunctionReturn(0); 957732e2eb9SMatthew G Knepley } 958732e2eb9SMatthew G Knepley 959732e2eb9SMatthew G Knepley #undef __FUNCT__ 960a89ea682SMatthew G Knepley #define __FUNCT__ "DMGetWorkArray" 961a89ea682SMatthew G Knepley /*@C 962aa1993deSMatthew G Knepley DMGetWorkArray - Gets a work array guaranteed to be at least the input size, restore with DMRestoreWorkArray() 963a89ea682SMatthew G Knepley 964a89ea682SMatthew G Knepley Not Collective 965a89ea682SMatthew G Knepley 966a89ea682SMatthew G Knepley Input Parameters: 967a89ea682SMatthew G Knepley + dm - the DM object 968aa1993deSMatthew G Knepley . count - The minium size 969aa1993deSMatthew G Knepley - dtype - data type (PETSC_REAL, PETSC_SCALAR, PETSC_INT) 970a89ea682SMatthew G Knepley 971a89ea682SMatthew G Knepley Output Parameter: 972a89ea682SMatthew G Knepley . array - the work array 973a89ea682SMatthew G Knepley 974a89ea682SMatthew G Knepley Level: developer 975a89ea682SMatthew G Knepley 976a89ea682SMatthew G Knepley .seealso DMDestroy(), DMCreate() 977a89ea682SMatthew G Knepley @*/ 978aa1993deSMatthew G Knepley PetscErrorCode DMGetWorkArray(DM dm,PetscInt count,PetscDataType dtype,void *mem) 979a89ea682SMatthew G Knepley { 980a89ea682SMatthew G Knepley PetscErrorCode ierr; 981aa1993deSMatthew G Knepley DMWorkLink link; 982aa1993deSMatthew G Knepley size_t size; 983a89ea682SMatthew G Knepley 984a89ea682SMatthew G Knepley PetscFunctionBegin; 985a89ea682SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 986aa1993deSMatthew G Knepley PetscValidPointer(mem,4); 987aa1993deSMatthew G Knepley if (dm->workin) { 988aa1993deSMatthew G Knepley link = dm->workin; 989aa1993deSMatthew G Knepley dm->workin = dm->workin->next; 990aa1993deSMatthew G Knepley } else { 991b00a9115SJed Brown ierr = PetscNewLog(dm,&link);CHKERRQ(ierr); 992a89ea682SMatthew G Knepley } 993aa1993deSMatthew G Knepley ierr = PetscDataTypeGetSize(dtype,&size);CHKERRQ(ierr); 994aa1993deSMatthew G Knepley if (size*count > link->bytes) { 995aa1993deSMatthew G Knepley ierr = PetscFree(link->mem);CHKERRQ(ierr); 996aa1993deSMatthew G Knepley ierr = PetscMalloc(size*count,&link->mem);CHKERRQ(ierr); 997aa1993deSMatthew G Knepley link->bytes = size*count; 998aa1993deSMatthew G Knepley } 999aa1993deSMatthew G Knepley link->next = dm->workout; 1000aa1993deSMatthew G Knepley dm->workout = link; 1001aa1993deSMatthew G Knepley *(void**)mem = link->mem; 1002a89ea682SMatthew G Knepley PetscFunctionReturn(0); 1003a89ea682SMatthew G Knepley } 1004a89ea682SMatthew G Knepley 1005aa1993deSMatthew G Knepley #undef __FUNCT__ 1006aa1993deSMatthew G Knepley #define __FUNCT__ "DMRestoreWorkArray" 1007aa1993deSMatthew G Knepley /*@C 1008aa1993deSMatthew G Knepley DMRestoreWorkArray - Restores a work array guaranteed to be at least the input size, restore with DMRestoreWorkArray() 1009aa1993deSMatthew G Knepley 1010aa1993deSMatthew G Knepley Not Collective 1011aa1993deSMatthew G Knepley 1012aa1993deSMatthew G Knepley Input Parameters: 1013aa1993deSMatthew G Knepley + dm - the DM object 1014aa1993deSMatthew G Knepley . count - The minium size 1015aa1993deSMatthew G Knepley - dtype - data type (PETSC_REAL, PETSC_SCALAR, PETSC_INT) 1016aa1993deSMatthew G Knepley 1017aa1993deSMatthew G Knepley Output Parameter: 1018aa1993deSMatthew G Knepley . array - the work array 1019aa1993deSMatthew G Knepley 1020aa1993deSMatthew G Knepley Level: developer 1021aa1993deSMatthew G Knepley 1022aa1993deSMatthew G Knepley .seealso DMDestroy(), DMCreate() 1023aa1993deSMatthew G Knepley @*/ 1024aa1993deSMatthew G Knepley PetscErrorCode DMRestoreWorkArray(DM dm,PetscInt count,PetscDataType dtype,void *mem) 1025aa1993deSMatthew G Knepley { 1026aa1993deSMatthew G Knepley DMWorkLink *p,link; 1027aa1993deSMatthew G Knepley 1028aa1993deSMatthew G Knepley PetscFunctionBegin; 1029aa1993deSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1030aa1993deSMatthew G Knepley PetscValidPointer(mem,4); 1031aa1993deSMatthew G Knepley for (p=&dm->workout; (link=*p); p=&link->next) { 1032aa1993deSMatthew G Knepley if (link->mem == *(void**)mem) { 1033aa1993deSMatthew G Knepley *p = link->next; 1034aa1993deSMatthew G Knepley link->next = dm->workin; 1035aa1993deSMatthew G Knepley dm->workin = link; 10360298fd71SBarry Smith *(void**)mem = NULL; 1037aa1993deSMatthew G Knepley PetscFunctionReturn(0); 1038aa1993deSMatthew G Knepley } 1039aa1993deSMatthew G Knepley } 1040aa1993deSMatthew G Knepley SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Array was not checked out"); 1041aa1993deSMatthew G Knepley PetscFunctionReturn(0); 1042aa1993deSMatthew G Knepley } 1043e7c4fc90SDmitry Karpeev 1044e7c4fc90SDmitry Karpeev #undef __FUNCT__ 1045435a35e8SMatthew G Knepley #define __FUNCT__ "DMSetNullSpaceConstructor" 1046435a35e8SMatthew G Knepley PetscErrorCode DMSetNullSpaceConstructor(DM dm, PetscInt field, PetscErrorCode (*nullsp)(DM dm, PetscInt field, MatNullSpace *nullSpace)) 1047435a35e8SMatthew G Knepley { 1048435a35e8SMatthew G Knepley PetscFunctionBegin; 1049435a35e8SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 105082f516ccSBarry Smith if (field >= 10) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cannot handle %d >= 10 fields", field); 1051435a35e8SMatthew G Knepley dm->nullspaceConstructors[field] = nullsp; 1052435a35e8SMatthew G Knepley PetscFunctionReturn(0); 1053435a35e8SMatthew G Knepley } 1054435a35e8SMatthew G Knepley 1055435a35e8SMatthew G Knepley #undef __FUNCT__ 10564d343eeaSMatthew G Knepley #define __FUNCT__ "DMCreateFieldIS" 10574f3b5142SJed Brown /*@C 10584d343eeaSMatthew G Knepley DMCreateFieldIS - Creates a set of IS objects with the global indices of dofs for each field 10594d343eeaSMatthew G Knepley 10604d343eeaSMatthew G Knepley Not collective 10614d343eeaSMatthew G Knepley 10624d343eeaSMatthew G Knepley Input Parameter: 10634d343eeaSMatthew G Knepley . dm - the DM object 10644d343eeaSMatthew G Knepley 10654d343eeaSMatthew G Knepley Output Parameters: 10660298fd71SBarry Smith + numFields - The number of fields (or NULL if not requested) 10670298fd71SBarry Smith . fieldNames - The name for each field (or NULL if not requested) 10680298fd71SBarry Smith - fields - The global indices for each field (or NULL if not requested) 10694d343eeaSMatthew G Knepley 10704d343eeaSMatthew G Knepley Level: intermediate 10714d343eeaSMatthew G Knepley 107221c9b008SJed Brown Notes: 107321c9b008SJed Brown The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 107421c9b008SJed Brown PetscFree(), every entry of fields should be destroyed with ISDestroy(), and both arrays should be freed with 107521c9b008SJed Brown PetscFree(). 107621c9b008SJed Brown 10774d343eeaSMatthew G Knepley .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 10784d343eeaSMatthew G Knepley @*/ 107937d0c07bSMatthew G Knepley PetscErrorCode DMCreateFieldIS(DM dm, PetscInt *numFields, char ***fieldNames, IS **fields) 10804d343eeaSMatthew G Knepley { 108137d0c07bSMatthew G Knepley PetscSection section, sectionGlobal; 10824d343eeaSMatthew G Knepley PetscErrorCode ierr; 10834d343eeaSMatthew G Knepley 10844d343eeaSMatthew G Knepley PetscFunctionBegin; 10854d343eeaSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 108669ca1f37SDmitry Karpeev if (numFields) { 108769ca1f37SDmitry Karpeev PetscValidPointer(numFields,2); 108869ca1f37SDmitry Karpeev *numFields = 0; 108969ca1f37SDmitry Karpeev } 109037d0c07bSMatthew G Knepley if (fieldNames) { 109137d0c07bSMatthew G Knepley PetscValidPointer(fieldNames,3); 10920298fd71SBarry Smith *fieldNames = NULL; 109369ca1f37SDmitry Karpeev } 109469ca1f37SDmitry Karpeev if (fields) { 109569ca1f37SDmitry Karpeev PetscValidPointer(fields,4); 10960298fd71SBarry Smith *fields = NULL; 109769ca1f37SDmitry Karpeev } 109837d0c07bSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 109937d0c07bSMatthew G Knepley if (section) { 110037d0c07bSMatthew G Knepley PetscInt *fieldSizes, **fieldIndices; 110137d0c07bSMatthew G Knepley PetscInt nF, f, pStart, pEnd, p; 110237d0c07bSMatthew G Knepley 110337d0c07bSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 110437d0c07bSMatthew G Knepley ierr = PetscSectionGetNumFields(section, &nF);CHKERRQ(ierr); 1105dcca6d9dSJed Brown ierr = PetscMalloc2(nF,&fieldSizes,nF,&fieldIndices);CHKERRQ(ierr); 110637d0c07bSMatthew G Knepley ierr = PetscSectionGetChart(sectionGlobal, &pStart, &pEnd);CHKERRQ(ierr); 110737d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 110837d0c07bSMatthew G Knepley fieldSizes[f] = 0; 110937d0c07bSMatthew G Knepley } 111037d0c07bSMatthew G Knepley for (p = pStart; p < pEnd; ++p) { 111137d0c07bSMatthew G Knepley PetscInt gdof; 111237d0c07bSMatthew G Knepley 111337d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 111437d0c07bSMatthew G Knepley if (gdof > 0) { 111537d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 111637d0c07bSMatthew G Knepley PetscInt fdof, fcdof; 111737d0c07bSMatthew G Knepley 111837d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldDof(section, p, f, &fdof);CHKERRQ(ierr); 111937d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 112037d0c07bSMatthew G Knepley fieldSizes[f] += fdof-fcdof; 112137d0c07bSMatthew G Knepley } 112237d0c07bSMatthew G Knepley } 112337d0c07bSMatthew G Knepley } 112437d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 1125785e854fSJed Brown ierr = PetscMalloc1(fieldSizes[f], &fieldIndices[f]);CHKERRQ(ierr); 112637d0c07bSMatthew G Knepley fieldSizes[f] = 0; 112737d0c07bSMatthew G Knepley } 112837d0c07bSMatthew G Knepley for (p = pStart; p < pEnd; ++p) { 112937d0c07bSMatthew G Knepley PetscInt gdof, goff; 113037d0c07bSMatthew G Knepley 113137d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 113237d0c07bSMatthew G Knepley if (gdof > 0) { 113337d0c07bSMatthew G Knepley ierr = PetscSectionGetOffset(sectionGlobal, p, &goff);CHKERRQ(ierr); 113437d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 113537d0c07bSMatthew G Knepley PetscInt fdof, fcdof, fc; 113637d0c07bSMatthew G Knepley 113737d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldDof(section, p, f, &fdof);CHKERRQ(ierr); 113837d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 113937d0c07bSMatthew G Knepley for (fc = 0; fc < fdof-fcdof; ++fc, ++fieldSizes[f]) { 114037d0c07bSMatthew G Knepley fieldIndices[f][fieldSizes[f]] = goff++; 114137d0c07bSMatthew G Knepley } 114237d0c07bSMatthew G Knepley } 114337d0c07bSMatthew G Knepley } 114437d0c07bSMatthew G Knepley } 11458865f1eaSKarl Rupp if (numFields) *numFields = nF; 114637d0c07bSMatthew G Knepley if (fieldNames) { 1147785e854fSJed Brown ierr = PetscMalloc1(nF, fieldNames);CHKERRQ(ierr); 114837d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 114937d0c07bSMatthew G Knepley const char *fieldName; 115037d0c07bSMatthew G Knepley 115137d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldName(section, f, &fieldName);CHKERRQ(ierr); 115237d0c07bSMatthew G Knepley ierr = PetscStrallocpy(fieldName, (char**) &(*fieldNames)[f]);CHKERRQ(ierr); 115337d0c07bSMatthew G Knepley } 115437d0c07bSMatthew G Knepley } 115537d0c07bSMatthew G Knepley if (fields) { 1156785e854fSJed Brown ierr = PetscMalloc1(nF, fields);CHKERRQ(ierr); 115737d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 115882f516ccSBarry Smith ierr = ISCreateGeneral(PetscObjectComm((PetscObject)dm), fieldSizes[f], fieldIndices[f], PETSC_OWN_POINTER, &(*fields)[f]);CHKERRQ(ierr); 115937d0c07bSMatthew G Knepley } 116037d0c07bSMatthew G Knepley } 116137d0c07bSMatthew G Knepley ierr = PetscFree2(fieldSizes,fieldIndices);CHKERRQ(ierr); 11628865f1eaSKarl Rupp } else if (dm->ops->createfieldis) { 11638865f1eaSKarl Rupp ierr = (*dm->ops->createfieldis)(dm, numFields, fieldNames, fields);CHKERRQ(ierr); 116469ca1f37SDmitry Karpeev } 11654d343eeaSMatthew G Knepley PetscFunctionReturn(0); 11664d343eeaSMatthew G Knepley } 11674d343eeaSMatthew G Knepley 116816621825SDmitry Karpeev 116916621825SDmitry Karpeev #undef __FUNCT__ 117016621825SDmitry Karpeev #define __FUNCT__ "DMCreateFieldDecomposition" 117116621825SDmitry Karpeev /*@C 117216621825SDmitry Karpeev DMCreateFieldDecomposition - Returns a list of IS objects defining a decomposition of a problem into subproblems 117316621825SDmitry Karpeev corresponding to different fields: each IS contains the global indices of the dofs of the 117416621825SDmitry Karpeev corresponding field. The optional list of DMs define the DM for each subproblem. 1175e7c4fc90SDmitry Karpeev Generalizes DMCreateFieldIS(). 1176e7c4fc90SDmitry Karpeev 1177e7c4fc90SDmitry Karpeev Not collective 1178e7c4fc90SDmitry Karpeev 1179e7c4fc90SDmitry Karpeev Input Parameter: 1180e7c4fc90SDmitry Karpeev . dm - the DM object 1181e7c4fc90SDmitry Karpeev 1182e7c4fc90SDmitry Karpeev Output Parameters: 11830298fd71SBarry Smith + len - The number of subproblems in the field decomposition (or NULL if not requested) 11840298fd71SBarry Smith . namelist - The name for each field (or NULL if not requested) 11850298fd71SBarry Smith . islist - The global indices for each field (or NULL if not requested) 11860298fd71SBarry Smith - dmlist - The DMs for each field subproblem (or NULL, if not requested; if NULL is returned, no DMs are defined) 1187e7c4fc90SDmitry Karpeev 1188e7c4fc90SDmitry Karpeev Level: intermediate 1189e7c4fc90SDmitry Karpeev 1190e7c4fc90SDmitry Karpeev Notes: 1191e7c4fc90SDmitry Karpeev The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 1192e7c4fc90SDmitry Karpeev PetscFree(), every entry of is should be destroyed with ISDestroy(), every entry of dm should be destroyed with DMDestroy(), 1193e7c4fc90SDmitry Karpeev and all of the arrays should be freed with PetscFree(). 1194e7c4fc90SDmitry Karpeev 1195e7c4fc90SDmitry Karpeev .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1196e7c4fc90SDmitry Karpeev @*/ 119716621825SDmitry Karpeev PetscErrorCode DMCreateFieldDecomposition(DM dm, PetscInt *len, char ***namelist, IS **islist, DM **dmlist) 1198e7c4fc90SDmitry Karpeev { 1199e7c4fc90SDmitry Karpeev PetscErrorCode ierr; 1200e7c4fc90SDmitry Karpeev 1201e7c4fc90SDmitry Karpeev PetscFunctionBegin; 1202e7c4fc90SDmitry Karpeev PetscValidHeaderSpecific(dm,DM_CLASSID,1); 12038865f1eaSKarl Rupp if (len) { 12048865f1eaSKarl Rupp PetscValidPointer(len,2); 12058865f1eaSKarl Rupp *len = 0; 12068865f1eaSKarl Rupp } 12078865f1eaSKarl Rupp if (namelist) { 12088865f1eaSKarl Rupp PetscValidPointer(namelist,3); 12098865f1eaSKarl Rupp *namelist = 0; 12108865f1eaSKarl Rupp } 12118865f1eaSKarl Rupp if (islist) { 12128865f1eaSKarl Rupp PetscValidPointer(islist,4); 12138865f1eaSKarl Rupp *islist = 0; 12148865f1eaSKarl Rupp } 12158865f1eaSKarl Rupp if (dmlist) { 12168865f1eaSKarl Rupp PetscValidPointer(dmlist,5); 12178865f1eaSKarl Rupp *dmlist = 0; 12188865f1eaSKarl Rupp } 1219f3f0edfdSDmitry Karpeev /* 1220f3f0edfdSDmitry Karpeev Is it a good idea to apply the following check across all impls? 1221f3f0edfdSDmitry Karpeev Perhaps some impls can have a well-defined decomposition before DMSetUp? 1222f3f0edfdSDmitry Karpeev This, however, follows the general principle that accessors are not well-behaved until the object is set up. 1223f3f0edfdSDmitry Karpeev */ 1224ce94432eSBarry Smith if (!dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE, "Decomposition defined only after DMSetUp"); 122516621825SDmitry Karpeev if (!dm->ops->createfielddecomposition) { 1226435a35e8SMatthew G Knepley PetscSection section; 1227435a35e8SMatthew G Knepley PetscInt numFields, f; 1228435a35e8SMatthew G Knepley 1229435a35e8SMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 1230435a35e8SMatthew G Knepley if (section) {ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr);} 1231435a35e8SMatthew G Knepley if (section && numFields && dm->ops->createsubdm) { 1232435a35e8SMatthew G Knepley *len = numFields; 123303dc3394SMatthew G. Knepley if (namelist) {ierr = PetscMalloc1(numFields,namelist);CHKERRQ(ierr);} 123403dc3394SMatthew G. Knepley if (islist) {ierr = PetscMalloc1(numFields,islist);CHKERRQ(ierr);} 123503dc3394SMatthew G. Knepley if (dmlist) {ierr = PetscMalloc1(numFields,dmlist);CHKERRQ(ierr);} 1236435a35e8SMatthew G Knepley for (f = 0; f < numFields; ++f) { 1237435a35e8SMatthew G Knepley const char *fieldName; 1238435a35e8SMatthew G Knepley 123903dc3394SMatthew G. Knepley ierr = DMCreateSubDM(dm, 1, &f, islist ? &(*islist)[f] : NULL, dmlist ? &(*dmlist)[f] : NULL);CHKERRQ(ierr); 124003dc3394SMatthew G. Knepley if (namelist) { 1241435a35e8SMatthew G Knepley ierr = PetscSectionGetFieldName(section, f, &fieldName);CHKERRQ(ierr); 1242435a35e8SMatthew G Knepley ierr = PetscStrallocpy(fieldName, (char**) &(*namelist)[f]);CHKERRQ(ierr); 1243435a35e8SMatthew G Knepley } 124403dc3394SMatthew G. Knepley } 1245435a35e8SMatthew G Knepley } else { 124669ca1f37SDmitry Karpeev ierr = DMCreateFieldIS(dm, len, namelist, islist);CHKERRQ(ierr); 1247e7c4fc90SDmitry Karpeev /* By default there are no DMs associated with subproblems. */ 12480298fd71SBarry Smith if (dmlist) *dmlist = NULL; 1249e7c4fc90SDmitry Karpeev } 12508865f1eaSKarl Rupp } else { 125116621825SDmitry Karpeev ierr = (*dm->ops->createfielddecomposition)(dm,len,namelist,islist,dmlist);CHKERRQ(ierr); 125216621825SDmitry Karpeev } 125316621825SDmitry Karpeev PetscFunctionReturn(0); 125416621825SDmitry Karpeev } 125516621825SDmitry Karpeev 125616621825SDmitry Karpeev #undef __FUNCT__ 1257435a35e8SMatthew G Knepley #define __FUNCT__ "DMCreateSubDM" 1258435a35e8SMatthew G Knepley /*@C 1259435a35e8SMatthew G Knepley DMCreateSubDM - Returns an IS and DM encapsulating a subproblem defined by the fields passed in. 1260435a35e8SMatthew G Knepley The fields are defined by DMCreateFieldIS(). 1261435a35e8SMatthew G Knepley 1262435a35e8SMatthew G Knepley Not collective 1263435a35e8SMatthew G Knepley 1264435a35e8SMatthew G Knepley Input Parameters: 1265435a35e8SMatthew G Knepley + dm - the DM object 1266435a35e8SMatthew G Knepley . numFields - number of fields in this subproblem 12670298fd71SBarry Smith - len - The number of subproblems in the decomposition (or NULL if not requested) 1268435a35e8SMatthew G Knepley 1269435a35e8SMatthew G Knepley Output Parameters: 1270435a35e8SMatthew G Knepley . is - The global indices for the subproblem 1271435a35e8SMatthew G Knepley - dm - The DM for the subproblem 1272435a35e8SMatthew G Knepley 1273435a35e8SMatthew G Knepley Level: intermediate 1274435a35e8SMatthew G Knepley 1275435a35e8SMatthew G Knepley .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1276435a35e8SMatthew G Knepley @*/ 1277435a35e8SMatthew G Knepley PetscErrorCode DMCreateSubDM(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) 1278435a35e8SMatthew G Knepley { 1279435a35e8SMatthew G Knepley PetscErrorCode ierr; 1280435a35e8SMatthew G Knepley 1281435a35e8SMatthew G Knepley PetscFunctionBegin; 1282435a35e8SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1283435a35e8SMatthew G Knepley PetscValidPointer(fields,3); 12848865f1eaSKarl Rupp if (is) PetscValidPointer(is,4); 12858865f1eaSKarl Rupp if (subdm) PetscValidPointer(subdm,5); 1286435a35e8SMatthew G Knepley if (dm->ops->createsubdm) { 1287435a35e8SMatthew G Knepley ierr = (*dm->ops->createsubdm)(dm, numFields, fields, is, subdm);CHKERRQ(ierr); 128882f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "This type has no DMCreateSubDM implementation defined"); 1289435a35e8SMatthew G Knepley PetscFunctionReturn(0); 1290435a35e8SMatthew G Knepley } 1291435a35e8SMatthew G Knepley 129216621825SDmitry Karpeev 129316621825SDmitry Karpeev #undef __FUNCT__ 129416621825SDmitry Karpeev #define __FUNCT__ "DMCreateDomainDecomposition" 129516621825SDmitry Karpeev /*@C 12968d4ac253SDmitry Karpeev DMCreateDomainDecomposition - Returns lists of IS objects defining a decomposition of a problem into subproblems 12978d4ac253SDmitry Karpeev corresponding to restrictions to pairs nested subdomains: each IS contains the global 12988d4ac253SDmitry Karpeev indices of the dofs of the corresponding subdomains. The inner subdomains conceptually 12998d4ac253SDmitry Karpeev define a nonoverlapping covering, while outer subdomains can overlap. 13008d4ac253SDmitry Karpeev The optional list of DMs define the DM for each subproblem. 130116621825SDmitry Karpeev 130216621825SDmitry Karpeev Not collective 130316621825SDmitry Karpeev 130416621825SDmitry Karpeev Input Parameter: 130516621825SDmitry Karpeev . dm - the DM object 130616621825SDmitry Karpeev 130716621825SDmitry Karpeev Output Parameters: 13080298fd71SBarry Smith + len - The number of subproblems in the domain decomposition (or NULL if not requested) 13090298fd71SBarry Smith . namelist - The name for each subdomain (or NULL if not requested) 13100298fd71SBarry Smith . innerislist - The global indices for each inner subdomain (or NULL, if not requested) 13110298fd71SBarry Smith . outerislist - The global indices for each outer subdomain (or NULL, if not requested) 13120298fd71SBarry Smith - dmlist - The DMs for each subdomain subproblem (or NULL, if not requested; if NULL is returned, no DMs are defined) 131316621825SDmitry Karpeev 131416621825SDmitry Karpeev Level: intermediate 131516621825SDmitry Karpeev 131616621825SDmitry Karpeev Notes: 131716621825SDmitry Karpeev The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 131816621825SDmitry Karpeev PetscFree(), every entry of is should be destroyed with ISDestroy(), every entry of dm should be destroyed with DMDestroy(), 131916621825SDmitry Karpeev and all of the arrays should be freed with PetscFree(). 132016621825SDmitry Karpeev 13218d4ac253SDmitry Karpeev .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateDomainDecompositionDM(), DMCreateFieldDecomposition() 132216621825SDmitry Karpeev @*/ 13238d4ac253SDmitry Karpeev PetscErrorCode DMCreateDomainDecomposition(DM dm, PetscInt *len, char ***namelist, IS **innerislist, IS **outerislist, DM **dmlist) 132416621825SDmitry Karpeev { 132516621825SDmitry Karpeev PetscErrorCode ierr; 1326be081cd6SPeter Brune DMSubDomainHookLink link; 1327be081cd6SPeter Brune PetscInt i,l; 132816621825SDmitry Karpeev 132916621825SDmitry Karpeev PetscFunctionBegin; 133016621825SDmitry Karpeev PetscValidHeaderSpecific(dm,DM_CLASSID,1); 133114a18fd3SPeter Brune if (len) {PetscValidPointer(len,2); *len = 0;} 13320298fd71SBarry Smith if (namelist) {PetscValidPointer(namelist,3); *namelist = NULL;} 13330298fd71SBarry Smith if (innerislist) {PetscValidPointer(innerislist,4); *innerislist = NULL;} 13340298fd71SBarry Smith if (outerislist) {PetscValidPointer(outerislist,5); *outerislist = NULL;} 13350298fd71SBarry Smith if (dmlist) {PetscValidPointer(dmlist,6); *dmlist = NULL;} 1336f3f0edfdSDmitry Karpeev /* 1337f3f0edfdSDmitry Karpeev Is it a good idea to apply the following check across all impls? 1338f3f0edfdSDmitry Karpeev Perhaps some impls can have a well-defined decomposition before DMSetUp? 1339f3f0edfdSDmitry Karpeev This, however, follows the general principle that accessors are not well-behaved until the object is set up. 1340f3f0edfdSDmitry Karpeev */ 1341ce94432eSBarry Smith if (!dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE, "Decomposition defined only after DMSetUp"); 134216621825SDmitry Karpeev if (dm->ops->createdomaindecomposition) { 1343be081cd6SPeter Brune ierr = (*dm->ops->createdomaindecomposition)(dm,&l,namelist,innerislist,outerislist,dmlist);CHKERRQ(ierr); 134414a18fd3SPeter Brune /* copy subdomain hooks and context over to the subdomain DMs */ 134514a18fd3SPeter Brune if (dmlist) { 1346be081cd6SPeter Brune for (i = 0; i < l; i++) { 1347be081cd6SPeter Brune for (link=dm->subdomainhook; link; link=link->next) { 1348be081cd6SPeter Brune if (link->ddhook) {ierr = (*link->ddhook)(dm,(*dmlist)[i],link->ctx);CHKERRQ(ierr);} 1349be081cd6SPeter Brune } 1350d425c654SPeter Brune (*dmlist)[i]->ctx = dm->ctx; 1351e7c4fc90SDmitry Karpeev } 135214a18fd3SPeter Brune } 135314a18fd3SPeter Brune if (len) *len = l; 135414a18fd3SPeter Brune } 1355e30e807fSPeter Brune PetscFunctionReturn(0); 1356e30e807fSPeter Brune } 1357e30e807fSPeter Brune 1358e30e807fSPeter Brune 1359e30e807fSPeter Brune #undef __FUNCT__ 1360e30e807fSPeter Brune #define __FUNCT__ "DMCreateDomainDecompositionScatters" 1361e30e807fSPeter Brune /*@C 1362e30e807fSPeter Brune DMCreateDomainDecompositionScatters - Returns scatters to the subdomain vectors from the global vector 1363e30e807fSPeter Brune 1364e30e807fSPeter Brune Not collective 1365e30e807fSPeter Brune 1366e30e807fSPeter Brune Input Parameters: 1367e30e807fSPeter Brune + dm - the DM object 1368e30e807fSPeter Brune . n - the number of subdomain scatters 1369e30e807fSPeter Brune - subdms - the local subdomains 1370e30e807fSPeter Brune 1371e30e807fSPeter Brune Output Parameters: 1372e30e807fSPeter Brune + n - the number of scatters returned 1373e30e807fSPeter Brune . iscat - scatter from global vector to nonoverlapping global vector entries on subdomain 1374e30e807fSPeter Brune . oscat - scatter from global vector to overlapping global vector entries on subdomain 1375e30e807fSPeter Brune - gscat - scatter from global vector to local vector on subdomain (fills in ghosts) 1376e30e807fSPeter Brune 1377e30e807fSPeter Brune Notes: This is an alternative to the iis and ois arguments in DMCreateDomainDecomposition that allow for the solution 1378e30e807fSPeter Brune of general nonlinear problems with overlapping subdomain methods. While merely having index sets that enable subsets 1379e30e807fSPeter Brune of the residual equations to be created is fine for linear problems, nonlinear problems require local assembly of 1380e30e807fSPeter Brune solution and residual data. 1381e30e807fSPeter Brune 1382e30e807fSPeter Brune Level: developer 1383e30e807fSPeter Brune 1384e30e807fSPeter Brune .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1385e30e807fSPeter Brune @*/ 1386e30e807fSPeter Brune PetscErrorCode DMCreateDomainDecompositionScatters(DM dm,PetscInt n,DM *subdms,VecScatter **iscat,VecScatter **oscat,VecScatter **gscat) 1387e30e807fSPeter Brune { 1388e30e807fSPeter Brune PetscErrorCode ierr; 1389e30e807fSPeter Brune 1390e30e807fSPeter Brune PetscFunctionBegin; 1391e30e807fSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1392e30e807fSPeter Brune PetscValidPointer(subdms,3); 1393e30e807fSPeter Brune if (dm->ops->createddscatters) { 1394e30e807fSPeter Brune ierr = (*dm->ops->createddscatters)(dm,n,subdms,iscat,oscat,gscat);CHKERRQ(ierr); 139582f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "This type has no DMCreateDomainDecompositionLocalScatter implementation defined"); 1396e7c4fc90SDmitry Karpeev PetscFunctionReturn(0); 1397e7c4fc90SDmitry Karpeev } 1398e7c4fc90SDmitry Karpeev 1399731c8d9eSDmitry Karpeev #undef __FUNCT__ 140047c6ae99SBarry Smith #define __FUNCT__ "DMRefine" 140147c6ae99SBarry Smith /*@ 140247c6ae99SBarry Smith DMRefine - Refines a DM object 140347c6ae99SBarry Smith 140447c6ae99SBarry Smith Collective on DM 140547c6ae99SBarry Smith 140647c6ae99SBarry Smith Input Parameter: 140747c6ae99SBarry Smith + dm - the DM object 140891d95f02SJed Brown - comm - the communicator to contain the new DM object (or MPI_COMM_NULL) 140947c6ae99SBarry Smith 141047c6ae99SBarry Smith Output Parameter: 14110298fd71SBarry Smith . dmf - the refined DM, or NULL 1412ae0a1c52SMatthew G Knepley 14130298fd71SBarry Smith Note: If no refinement was done, the return value is NULL 141447c6ae99SBarry Smith 141547c6ae99SBarry Smith Level: developer 141647c6ae99SBarry Smith 1417e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 141847c6ae99SBarry Smith @*/ 14197087cfbeSBarry Smith PetscErrorCode DMRefine(DM dm,MPI_Comm comm,DM *dmf) 142047c6ae99SBarry Smith { 142147c6ae99SBarry Smith PetscErrorCode ierr; 1422c833c3b5SJed Brown DMRefineHookLink link; 142347c6ae99SBarry Smith 142447c6ae99SBarry Smith PetscFunctionBegin; 1425732e2eb9SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 142647c6ae99SBarry Smith ierr = (*dm->ops->refine)(dm,comm,dmf);CHKERRQ(ierr); 14274057135bSMatthew G Knepley if (*dmf) { 142843842a1eSJed Brown (*dmf)->ops->creatematrix = dm->ops->creatematrix; 14298865f1eaSKarl Rupp 14308cd211a4SJed Brown ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)*dmf);CHKERRQ(ierr); 14318865f1eaSKarl Rupp 1432644e2e5bSBarry Smith (*dmf)->ctx = dm->ctx; 14330598a293SJed Brown (*dmf)->leveldown = dm->leveldown; 1434656b349aSBarry Smith (*dmf)->levelup = dm->levelup + 1; 14358865f1eaSKarl Rupp 1436e4b4b23bSJed Brown ierr = DMSetMatType(*dmf,dm->mattype);CHKERRQ(ierr); 1437c833c3b5SJed Brown for (link=dm->refinehook; link; link=link->next) { 14388865f1eaSKarl Rupp if (link->refinehook) { 14398865f1eaSKarl Rupp ierr = (*link->refinehook)(dm,*dmf,link->ctx);CHKERRQ(ierr); 14408865f1eaSKarl Rupp } 1441c833c3b5SJed Brown } 1442c833c3b5SJed Brown } 1443c833c3b5SJed Brown PetscFunctionReturn(0); 1444c833c3b5SJed Brown } 1445c833c3b5SJed Brown 1446c833c3b5SJed Brown #undef __FUNCT__ 1447c833c3b5SJed Brown #define __FUNCT__ "DMRefineHookAdd" 1448bb9467b5SJed Brown /*@C 1449c833c3b5SJed Brown DMRefineHookAdd - adds a callback to be run when interpolating a nonlinear problem to a finer grid 1450c833c3b5SJed Brown 1451c833c3b5SJed Brown Logically Collective 1452c833c3b5SJed Brown 1453c833c3b5SJed Brown Input Arguments: 1454c833c3b5SJed Brown + coarse - nonlinear solver context on which to run a hook when restricting to a coarser level 1455c833c3b5SJed Brown . refinehook - function to run when setting up a coarser level 1456c833c3b5SJed Brown . interphook - function to run to update data on finer levels (once per SNESSolve()) 14570298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1458c833c3b5SJed Brown 1459c833c3b5SJed Brown Calling sequence of refinehook: 1460c833c3b5SJed Brown $ refinehook(DM coarse,DM fine,void *ctx); 1461c833c3b5SJed Brown 1462c833c3b5SJed Brown + coarse - coarse level DM 1463c833c3b5SJed Brown . fine - fine level DM to interpolate problem to 1464c833c3b5SJed Brown - ctx - optional user-defined function context 1465c833c3b5SJed Brown 1466c833c3b5SJed Brown Calling sequence for interphook: 1467c833c3b5SJed Brown $ interphook(DM coarse,Mat interp,DM fine,void *ctx) 1468c833c3b5SJed Brown 1469c833c3b5SJed Brown + coarse - coarse level DM 1470c833c3b5SJed Brown . interp - matrix interpolating a coarse-level solution to the finer grid 1471c833c3b5SJed Brown . fine - fine level DM to update 1472c833c3b5SJed Brown - ctx - optional user-defined function context 1473c833c3b5SJed Brown 1474c833c3b5SJed Brown Level: advanced 1475c833c3b5SJed Brown 1476c833c3b5SJed Brown Notes: 1477c833c3b5SJed Brown This function is only needed if auxiliary data needs to be passed to fine grids while grid sequencing 1478c833c3b5SJed Brown 1479c833c3b5SJed Brown If this function is called multiple times, the hooks will be run in the order they are added. 1480c833c3b5SJed Brown 1481bb9467b5SJed Brown This function is currently not available from Fortran. 1482bb9467b5SJed Brown 1483c833c3b5SJed Brown .seealso: DMCoarsenHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1484c833c3b5SJed Brown @*/ 1485c833c3b5SJed Brown PetscErrorCode DMRefineHookAdd(DM coarse,PetscErrorCode (*refinehook)(DM,DM,void*),PetscErrorCode (*interphook)(DM,Mat,DM,void*),void *ctx) 1486c833c3b5SJed Brown { 1487c833c3b5SJed Brown PetscErrorCode ierr; 1488c833c3b5SJed Brown DMRefineHookLink link,*p; 1489c833c3b5SJed Brown 1490c833c3b5SJed Brown PetscFunctionBegin; 1491c833c3b5SJed Brown PetscValidHeaderSpecific(coarse,DM_CLASSID,1); 1492c833c3b5SJed Brown for (p=&coarse->refinehook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1493c833c3b5SJed Brown ierr = PetscMalloc(sizeof(struct _DMRefineHookLink),&link);CHKERRQ(ierr); 1494c833c3b5SJed Brown link->refinehook = refinehook; 1495c833c3b5SJed Brown link->interphook = interphook; 1496c833c3b5SJed Brown link->ctx = ctx; 14970298fd71SBarry Smith link->next = NULL; 1498c833c3b5SJed Brown *p = link; 1499c833c3b5SJed Brown PetscFunctionReturn(0); 1500c833c3b5SJed Brown } 1501c833c3b5SJed Brown 1502c833c3b5SJed Brown #undef __FUNCT__ 1503c833c3b5SJed Brown #define __FUNCT__ "DMInterpolate" 1504c833c3b5SJed Brown /*@ 1505c833c3b5SJed Brown DMInterpolate - interpolates user-defined problem data to a finer DM by running hooks registered by DMRefineHookAdd() 1506c833c3b5SJed Brown 1507c833c3b5SJed Brown Collective if any hooks are 1508c833c3b5SJed Brown 1509c833c3b5SJed Brown Input Arguments: 1510c833c3b5SJed Brown + coarse - coarser DM to use as a base 1511c833c3b5SJed Brown . restrct - interpolation matrix, apply using MatInterpolate() 1512c833c3b5SJed Brown - fine - finer DM to update 1513c833c3b5SJed Brown 1514c833c3b5SJed Brown Level: developer 1515c833c3b5SJed Brown 1516c833c3b5SJed Brown .seealso: DMRefineHookAdd(), MatInterpolate() 1517c833c3b5SJed Brown @*/ 1518c833c3b5SJed Brown PetscErrorCode DMInterpolate(DM coarse,Mat interp,DM fine) 1519c833c3b5SJed Brown { 1520c833c3b5SJed Brown PetscErrorCode ierr; 1521c833c3b5SJed Brown DMRefineHookLink link; 1522c833c3b5SJed Brown 1523c833c3b5SJed Brown PetscFunctionBegin; 1524c833c3b5SJed Brown for (link=fine->refinehook; link; link=link->next) { 15258865f1eaSKarl Rupp if (link->interphook) { 15268865f1eaSKarl Rupp ierr = (*link->interphook)(coarse,interp,fine,link->ctx);CHKERRQ(ierr); 15278865f1eaSKarl Rupp } 15284057135bSMatthew G Knepley } 152947c6ae99SBarry Smith PetscFunctionReturn(0); 153047c6ae99SBarry Smith } 153147c6ae99SBarry Smith 153247c6ae99SBarry Smith #undef __FUNCT__ 1533eb3f98d2SBarry Smith #define __FUNCT__ "DMGetRefineLevel" 1534eb3f98d2SBarry Smith /*@ 1535eb3f98d2SBarry Smith DMGetRefineLevel - Get's the number of refinements that have generated this DM. 1536eb3f98d2SBarry Smith 1537eb3f98d2SBarry Smith Not Collective 1538eb3f98d2SBarry Smith 1539eb3f98d2SBarry Smith Input Parameter: 1540eb3f98d2SBarry Smith . dm - the DM object 1541eb3f98d2SBarry Smith 1542eb3f98d2SBarry Smith Output Parameter: 1543eb3f98d2SBarry Smith . level - number of refinements 1544eb3f98d2SBarry Smith 1545eb3f98d2SBarry Smith Level: developer 1546eb3f98d2SBarry Smith 15476a7d9d85SPeter Brune .seealso DMCoarsen(), DMGetCoarsenLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 1548eb3f98d2SBarry Smith 1549eb3f98d2SBarry Smith @*/ 1550eb3f98d2SBarry Smith PetscErrorCode DMGetRefineLevel(DM dm,PetscInt *level) 1551eb3f98d2SBarry Smith { 1552eb3f98d2SBarry Smith PetscFunctionBegin; 1553eb3f98d2SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1554eb3f98d2SBarry Smith *level = dm->levelup; 1555eb3f98d2SBarry Smith PetscFunctionReturn(0); 1556eb3f98d2SBarry Smith } 1557eb3f98d2SBarry Smith 1558eb3f98d2SBarry Smith #undef __FUNCT__ 1559baf369e7SPeter Brune #define __FUNCT__ "DMGlobalToLocalHookAdd" 1560bb9467b5SJed Brown /*@C 1561baf369e7SPeter Brune DMGlobalToLocalHookAdd - adds a callback to be run when global to local is called 1562baf369e7SPeter Brune 1563baf369e7SPeter Brune Logically Collective 1564baf369e7SPeter Brune 1565baf369e7SPeter Brune Input Arguments: 1566baf369e7SPeter Brune + dm - the DM 1567baf369e7SPeter Brune . beginhook - function to run at the beginning of DMGlobalToLocalBegin() 1568baf369e7SPeter Brune . endhook - function to run after DMGlobalToLocalEnd() has completed 15690298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1570baf369e7SPeter Brune 1571baf369e7SPeter Brune Calling sequence for beginhook: 1572baf369e7SPeter Brune $ beginhook(DM fine,VecScatter out,VecScatter in,DM coarse,void *ctx) 1573baf369e7SPeter Brune 1574baf369e7SPeter Brune + dm - global DM 1575baf369e7SPeter Brune . g - global vector 1576baf369e7SPeter Brune . mode - mode 1577baf369e7SPeter Brune . l - local vector 1578baf369e7SPeter Brune - ctx - optional user-defined function context 1579baf369e7SPeter Brune 1580baf369e7SPeter Brune 1581baf369e7SPeter Brune Calling sequence for endhook: 1582ec4806b8SPeter Brune $ endhook(DM fine,VecScatter out,VecScatter in,DM coarse,void *ctx) 1583baf369e7SPeter Brune 1584baf369e7SPeter Brune + global - global DM 1585baf369e7SPeter Brune - ctx - optional user-defined function context 1586baf369e7SPeter Brune 1587baf369e7SPeter Brune Level: advanced 1588baf369e7SPeter Brune 1589baf369e7SPeter Brune .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1590baf369e7SPeter Brune @*/ 1591baf369e7SPeter Brune PetscErrorCode DMGlobalToLocalHookAdd(DM dm,PetscErrorCode (*beginhook)(DM,Vec,InsertMode,Vec,void*),PetscErrorCode (*endhook)(DM,Vec,InsertMode,Vec,void*),void *ctx) 1592baf369e7SPeter Brune { 1593baf369e7SPeter Brune PetscErrorCode ierr; 1594baf369e7SPeter Brune DMGlobalToLocalHookLink link,*p; 1595baf369e7SPeter Brune 1596baf369e7SPeter Brune PetscFunctionBegin; 1597baf369e7SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1598baf369e7SPeter Brune for (p=&dm->gtolhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1599baf369e7SPeter Brune ierr = PetscMalloc(sizeof(struct _DMGlobalToLocalHookLink),&link);CHKERRQ(ierr); 1600baf369e7SPeter Brune link->beginhook = beginhook; 1601baf369e7SPeter Brune link->endhook = endhook; 1602baf369e7SPeter Brune link->ctx = ctx; 16030298fd71SBarry Smith link->next = NULL; 1604baf369e7SPeter Brune *p = link; 1605baf369e7SPeter Brune PetscFunctionReturn(0); 1606baf369e7SPeter Brune } 1607baf369e7SPeter Brune 1608baf369e7SPeter Brune #undef __FUNCT__ 160947c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalBegin" 161047c6ae99SBarry Smith /*@ 161147c6ae99SBarry Smith DMGlobalToLocalBegin - Begins updating local vectors from global vector 161247c6ae99SBarry Smith 161347c6ae99SBarry Smith Neighbor-wise Collective on DM 161447c6ae99SBarry Smith 161547c6ae99SBarry Smith Input Parameters: 161647c6ae99SBarry Smith + dm - the DM object 161747c6ae99SBarry Smith . g - the global vector 161847c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 161947c6ae99SBarry Smith - l - the local vector 162047c6ae99SBarry Smith 162147c6ae99SBarry Smith 162247c6ae99SBarry Smith Level: beginner 162347c6ae99SBarry Smith 1624e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 162547c6ae99SBarry Smith 162647c6ae99SBarry Smith @*/ 16277087cfbeSBarry Smith PetscErrorCode DMGlobalToLocalBegin(DM dm,Vec g,InsertMode mode,Vec l) 162847c6ae99SBarry Smith { 16297128ae9fSMatthew G Knepley PetscSF sf; 163047c6ae99SBarry Smith PetscErrorCode ierr; 1631baf369e7SPeter Brune DMGlobalToLocalHookLink link; 163247c6ae99SBarry Smith 163347c6ae99SBarry Smith PetscFunctionBegin; 1634171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1635baf369e7SPeter Brune for (link=dm->gtolhook; link; link=link->next) { 16368865f1eaSKarl Rupp if (link->beginhook) { 16378865f1eaSKarl Rupp ierr = (*link->beginhook)(dm,g,mode,l,link->ctx);CHKERRQ(ierr); 16388865f1eaSKarl Rupp } 1639baf369e7SPeter Brune } 16407128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 16417128ae9fSMatthew G Knepley if (sf) { 16427128ae9fSMatthew G Knepley PetscScalar *lArray, *gArray; 16437128ae9fSMatthew G Knepley 164482f516ccSBarry Smith if (mode == ADD_VALUES) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 16457128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 16467128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 16477128ae9fSMatthew G Knepley ierr = PetscSFBcastBegin(sf, MPIU_SCALAR, gArray, lArray);CHKERRQ(ierr); 16487128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 16497128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 16507128ae9fSMatthew G Knepley } else { 1651843c4018SMatthew G Knepley ierr = (*dm->ops->globaltolocalbegin)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 16527128ae9fSMatthew G Knepley } 165347c6ae99SBarry Smith PetscFunctionReturn(0); 165447c6ae99SBarry Smith } 165547c6ae99SBarry Smith 165647c6ae99SBarry Smith #undef __FUNCT__ 165747c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalEnd" 165847c6ae99SBarry Smith /*@ 165947c6ae99SBarry Smith DMGlobalToLocalEnd - Ends updating local vectors from global vector 166047c6ae99SBarry Smith 166147c6ae99SBarry Smith Neighbor-wise Collective on DM 166247c6ae99SBarry Smith 166347c6ae99SBarry Smith Input Parameters: 166447c6ae99SBarry Smith + dm - the DM object 166547c6ae99SBarry Smith . g - the global vector 166647c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 166747c6ae99SBarry Smith - l - the local vector 166847c6ae99SBarry Smith 166947c6ae99SBarry Smith 167047c6ae99SBarry Smith Level: beginner 167147c6ae99SBarry Smith 1672e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 167347c6ae99SBarry Smith 167447c6ae99SBarry Smith @*/ 16757087cfbeSBarry Smith PetscErrorCode DMGlobalToLocalEnd(DM dm,Vec g,InsertMode mode,Vec l) 167647c6ae99SBarry Smith { 16777128ae9fSMatthew G Knepley PetscSF sf; 167847c6ae99SBarry Smith PetscErrorCode ierr; 167961a3c1faSSatish Balay PetscScalar *lArray, *gArray; 1680baf369e7SPeter Brune DMGlobalToLocalHookLink link; 168147c6ae99SBarry Smith 168247c6ae99SBarry Smith PetscFunctionBegin; 1683171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 16847128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 16857128ae9fSMatthew G Knepley if (sf) { 168682f516ccSBarry Smith if (mode == ADD_VALUES) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 16877128ae9fSMatthew G Knepley 16887128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 16897128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 16907128ae9fSMatthew G Knepley ierr = PetscSFBcastEnd(sf, MPIU_SCALAR, gArray, lArray);CHKERRQ(ierr); 16917128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 16927128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 16937128ae9fSMatthew G Knepley } else { 1694843c4018SMatthew G Knepley ierr = (*dm->ops->globaltolocalend)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 16957128ae9fSMatthew G Knepley } 1696baf369e7SPeter Brune for (link=dm->gtolhook; link; link=link->next) { 1697baf369e7SPeter Brune if (link->endhook) {ierr = (*link->endhook)(dm,g,mode,l,link->ctx);CHKERRQ(ierr);} 1698baf369e7SPeter Brune } 169947c6ae99SBarry Smith PetscFunctionReturn(0); 170047c6ae99SBarry Smith } 170147c6ae99SBarry Smith 170247c6ae99SBarry Smith #undef __FUNCT__ 17039a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalBegin" 170447c6ae99SBarry Smith /*@ 17059a42bb27SBarry Smith DMLocalToGlobalBegin - updates global vectors from local vectors 17069a42bb27SBarry Smith 17079a42bb27SBarry Smith Neighbor-wise Collective on DM 17089a42bb27SBarry Smith 17099a42bb27SBarry Smith Input Parameters: 17109a42bb27SBarry Smith + dm - the DM object 1711f6813fd5SJed Brown . l - the local vector 17129a42bb27SBarry 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 17139a42bb27SBarry Smith base point. 1714f6813fd5SJed Brown - - the global vector 17159a42bb27SBarry Smith 17169a42bb27SBarry 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 17179a42bb27SBarry 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 17189a42bb27SBarry Smith global array to the final global array with VecAXPY(). 17199a42bb27SBarry Smith 17209a42bb27SBarry Smith Level: beginner 17219a42bb27SBarry Smith 1722e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalBegin() 17239a42bb27SBarry Smith 17249a42bb27SBarry Smith @*/ 17257087cfbeSBarry Smith PetscErrorCode DMLocalToGlobalBegin(DM dm,Vec l,InsertMode mode,Vec g) 17269a42bb27SBarry Smith { 17277128ae9fSMatthew G Knepley PetscSF sf; 17289a42bb27SBarry Smith PetscErrorCode ierr; 17299a42bb27SBarry Smith 17309a42bb27SBarry Smith PetscFunctionBegin; 1731171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 17327128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 17337128ae9fSMatthew G Knepley if (sf) { 17347128ae9fSMatthew G Knepley MPI_Op op; 17357128ae9fSMatthew G Knepley PetscScalar *lArray, *gArray; 17367128ae9fSMatthew G Knepley 17377128ae9fSMatthew G Knepley switch (mode) { 17387128ae9fSMatthew G Knepley case INSERT_VALUES: 17397128ae9fSMatthew G Knepley case INSERT_ALL_VALUES: 17408bfbc91cSJed Brown op = MPIU_REPLACE; break; 17417128ae9fSMatthew G Knepley case ADD_VALUES: 17427128ae9fSMatthew G Knepley case ADD_ALL_VALUES: 17437128ae9fSMatthew G Knepley op = MPI_SUM; break; 17447128ae9fSMatthew G Knepley default: 174582f516ccSBarry Smith SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 17467128ae9fSMatthew G Knepley } 17477128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 17487128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 17497128ae9fSMatthew G Knepley ierr = PetscSFReduceBegin(sf, MPIU_SCALAR, lArray, gArray, op);CHKERRQ(ierr); 17507128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 17517128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 17527128ae9fSMatthew G Knepley } else { 1753843c4018SMatthew G Knepley ierr = (*dm->ops->localtoglobalbegin)(dm,l,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),g);CHKERRQ(ierr); 17547128ae9fSMatthew G Knepley } 17559a42bb27SBarry Smith PetscFunctionReturn(0); 17569a42bb27SBarry Smith } 17579a42bb27SBarry Smith 17589a42bb27SBarry Smith #undef __FUNCT__ 17599a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalEnd" 17609a42bb27SBarry Smith /*@ 17619a42bb27SBarry Smith DMLocalToGlobalEnd - updates global vectors from local vectors 176247c6ae99SBarry Smith 176347c6ae99SBarry Smith Neighbor-wise Collective on DM 176447c6ae99SBarry Smith 176547c6ae99SBarry Smith Input Parameters: 176647c6ae99SBarry Smith + dm - the DM object 1767f6813fd5SJed Brown . l - the local vector 176847c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 1769f6813fd5SJed Brown - g - the global vector 177047c6ae99SBarry Smith 177147c6ae99SBarry Smith 177247c6ae99SBarry Smith Level: beginner 177347c6ae99SBarry Smith 1774e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalEnd() 177547c6ae99SBarry Smith 177647c6ae99SBarry Smith @*/ 17777087cfbeSBarry Smith PetscErrorCode DMLocalToGlobalEnd(DM dm,Vec l,InsertMode mode,Vec g) 177847c6ae99SBarry Smith { 17797128ae9fSMatthew G Knepley PetscSF sf; 178047c6ae99SBarry Smith PetscErrorCode ierr; 178147c6ae99SBarry Smith 178247c6ae99SBarry Smith PetscFunctionBegin; 1783171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 17847128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 17857128ae9fSMatthew G Knepley if (sf) { 17867128ae9fSMatthew G Knepley MPI_Op op; 17877128ae9fSMatthew G Knepley PetscScalar *lArray, *gArray; 17887128ae9fSMatthew G Knepley 17897128ae9fSMatthew G Knepley switch (mode) { 17907128ae9fSMatthew G Knepley case INSERT_VALUES: 17917128ae9fSMatthew G Knepley case INSERT_ALL_VALUES: 17928bfbc91cSJed Brown op = MPIU_REPLACE; break; 17937128ae9fSMatthew G Knepley case ADD_VALUES: 17947128ae9fSMatthew G Knepley case ADD_ALL_VALUES: 17957128ae9fSMatthew G Knepley op = MPI_SUM; break; 17967128ae9fSMatthew G Knepley default: 179782f516ccSBarry Smith SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 17987128ae9fSMatthew G Knepley } 17997128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 18007128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 18017128ae9fSMatthew G Knepley ierr = PetscSFReduceEnd(sf, MPIU_SCALAR, lArray, gArray, op);CHKERRQ(ierr); 18027128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 18037128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 18047128ae9fSMatthew G Knepley } else { 1805843c4018SMatthew G Knepley ierr = (*dm->ops->localtoglobalend)(dm,l,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),g);CHKERRQ(ierr); 18067128ae9fSMatthew G Knepley } 180747c6ae99SBarry Smith PetscFunctionReturn(0); 180847c6ae99SBarry Smith } 180947c6ae99SBarry Smith 181047c6ae99SBarry Smith #undef __FUNCT__ 1811f089877aSRichard Tran Mills #define __FUNCT__ "DMLocalToLocalBegin" 1812f089877aSRichard Tran Mills /*@ 1813bc0a1609SRichard Tran Mills DMLocalToLocalBegin - Maps from a local vector (including ghost points 1814bc0a1609SRichard Tran Mills that contain irrelevant values) to another local vector where the ghost 1815d78e899eSRichard Tran Mills points in the second are set correctly. Must be followed by DMLocalToLocalEnd(). 1816f089877aSRichard Tran Mills 1817bc0a1609SRichard Tran Mills Neighbor-wise Collective on DM and Vec 1818f089877aSRichard Tran Mills 1819f089877aSRichard Tran Mills Input Parameters: 1820f089877aSRichard Tran Mills + dm - the DM object 1821bc0a1609SRichard Tran Mills . g - the original local vector 1822bc0a1609SRichard Tran Mills - mode - one of INSERT_VALUES or ADD_VALUES 1823f089877aSRichard Tran Mills 1824bc0a1609SRichard Tran Mills Output Parameter: 1825bc0a1609SRichard Tran Mills . l - the local vector with correct ghost values 1826f089877aSRichard Tran Mills 1827f089877aSRichard Tran Mills Level: intermediate 1828f089877aSRichard Tran Mills 1829bc0a1609SRichard Tran Mills Notes: 1830bc0a1609SRichard Tran Mills The local vectors used here need not be the same as those 1831bc0a1609SRichard Tran Mills obtained from DMCreateLocalVector(), BUT they 1832bc0a1609SRichard Tran Mills must have the same parallel data layout; they could, for example, be 1833bc0a1609SRichard Tran Mills obtained with VecDuplicate() from the DM originating vectors. 1834bc0a1609SRichard Tran Mills 1835bc0a1609SRichard Tran Mills .keywords: DM, local-to-local, begin 1836bc0a1609SRichard Tran Mills .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateLocalVector(), DMCreateGlobalVector(), DMCreateInterpolation(), DMLocalToLocalEnd(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 1837f089877aSRichard Tran Mills 1838f089877aSRichard Tran Mills @*/ 1839f089877aSRichard Tran Mills PetscErrorCode DMLocalToLocalBegin(DM dm,Vec g,InsertMode mode,Vec l) 1840f089877aSRichard Tran Mills { 1841f089877aSRichard Tran Mills PetscErrorCode ierr; 1842f089877aSRichard Tran Mills 1843f089877aSRichard Tran Mills PetscFunctionBegin; 1844f089877aSRichard Tran Mills PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1845f089877aSRichard Tran Mills ierr = (*dm->ops->localtolocalbegin)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 1846f089877aSRichard Tran Mills PetscFunctionReturn(0); 1847f089877aSRichard Tran Mills } 1848f089877aSRichard Tran Mills 1849f089877aSRichard Tran Mills #undef __FUNCT__ 1850f089877aSRichard Tran Mills #define __FUNCT__ "DMLocalToLocalEnd" 1851f089877aSRichard Tran Mills /*@ 1852bc0a1609SRichard Tran Mills DMLocalToLocalEnd - Maps from a local vector (including ghost points 1853bc0a1609SRichard Tran Mills that contain irrelevant values) to another local vector where the ghost 1854d78e899eSRichard Tran Mills points in the second are set correctly. Must be preceded by DMLocalToLocalBegin(). 1855f089877aSRichard Tran Mills 1856bc0a1609SRichard Tran Mills Neighbor-wise Collective on DM and Vec 1857f089877aSRichard Tran Mills 1858f089877aSRichard Tran Mills Input Parameters: 1859bc0a1609SRichard Tran Mills + da - the DM object 1860bc0a1609SRichard Tran Mills . g - the original local vector 1861bc0a1609SRichard Tran Mills - mode - one of INSERT_VALUES or ADD_VALUES 1862f089877aSRichard Tran Mills 1863bc0a1609SRichard Tran Mills Output Parameter: 1864bc0a1609SRichard Tran Mills . l - the local vector with correct ghost values 1865f089877aSRichard Tran Mills 1866f089877aSRichard Tran Mills Level: intermediate 1867f089877aSRichard Tran Mills 1868bc0a1609SRichard Tran Mills Notes: 1869bc0a1609SRichard Tran Mills The local vectors used here need not be the same as those 1870bc0a1609SRichard Tran Mills obtained from DMCreateLocalVector(), BUT they 1871bc0a1609SRichard Tran Mills must have the same parallel data layout; they could, for example, be 1872bc0a1609SRichard Tran Mills obtained with VecDuplicate() from the DM originating vectors. 1873bc0a1609SRichard Tran Mills 1874bc0a1609SRichard Tran Mills .keywords: DM, local-to-local, end 1875bc0a1609SRichard Tran Mills .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateLocalVector(), DMCreateGlobalVector(), DMCreateInterpolation(), DMLocalToLocalBegin(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 1876f089877aSRichard Tran Mills 1877f089877aSRichard Tran Mills @*/ 1878f089877aSRichard Tran Mills PetscErrorCode DMLocalToLocalEnd(DM dm,Vec g,InsertMode mode,Vec l) 1879f089877aSRichard Tran Mills { 1880f089877aSRichard Tran Mills PetscErrorCode ierr; 1881f089877aSRichard Tran Mills 1882f089877aSRichard Tran Mills PetscFunctionBegin; 1883f089877aSRichard Tran Mills PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1884f089877aSRichard Tran Mills ierr = (*dm->ops->localtolocalend)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 1885f089877aSRichard Tran Mills PetscFunctionReturn(0); 1886f089877aSRichard Tran Mills } 1887f089877aSRichard Tran Mills 1888f089877aSRichard Tran Mills 1889f089877aSRichard Tran Mills #undef __FUNCT__ 189047c6ae99SBarry Smith #define __FUNCT__ "DMCoarsen" 189147c6ae99SBarry Smith /*@ 189247c6ae99SBarry Smith DMCoarsen - Coarsens a DM object 189347c6ae99SBarry Smith 189447c6ae99SBarry Smith Collective on DM 189547c6ae99SBarry Smith 189647c6ae99SBarry Smith Input Parameter: 189747c6ae99SBarry Smith + dm - the DM object 189891d95f02SJed Brown - comm - the communicator to contain the new DM object (or MPI_COMM_NULL) 189947c6ae99SBarry Smith 190047c6ae99SBarry Smith Output Parameter: 190147c6ae99SBarry Smith . dmc - the coarsened DM 190247c6ae99SBarry Smith 190347c6ae99SBarry Smith Level: developer 190447c6ae99SBarry Smith 1905e727c939SJed Brown .seealso DMRefine(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 190647c6ae99SBarry Smith 190747c6ae99SBarry Smith @*/ 19087087cfbeSBarry Smith PetscErrorCode DMCoarsen(DM dm, MPI_Comm comm, DM *dmc) 190947c6ae99SBarry Smith { 191047c6ae99SBarry Smith PetscErrorCode ierr; 1911b17ce1afSJed Brown DMCoarsenHookLink link; 191247c6ae99SBarry Smith 191347c6ae99SBarry Smith PetscFunctionBegin; 1914171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 191547c6ae99SBarry Smith ierr = (*dm->ops->coarsen)(dm, comm, dmc);CHKERRQ(ierr); 191643842a1eSJed Brown (*dmc)->ops->creatematrix = dm->ops->creatematrix; 19178cd211a4SJed Brown ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)*dmc);CHKERRQ(ierr); 1918644e2e5bSBarry Smith (*dmc)->ctx = dm->ctx; 19190598a293SJed Brown (*dmc)->levelup = dm->levelup; 1920656b349aSBarry Smith (*dmc)->leveldown = dm->leveldown + 1; 1921e4b4b23bSJed Brown ierr = DMSetMatType(*dmc,dm->mattype);CHKERRQ(ierr); 1922b17ce1afSJed Brown for (link=dm->coarsenhook; link; link=link->next) { 1923b17ce1afSJed Brown if (link->coarsenhook) {ierr = (*link->coarsenhook)(dm,*dmc,link->ctx);CHKERRQ(ierr);} 1924b17ce1afSJed Brown } 1925b17ce1afSJed Brown PetscFunctionReturn(0); 1926b17ce1afSJed Brown } 1927b17ce1afSJed Brown 1928b17ce1afSJed Brown #undef __FUNCT__ 1929b17ce1afSJed Brown #define __FUNCT__ "DMCoarsenHookAdd" 1930bb9467b5SJed Brown /*@C 1931b17ce1afSJed Brown DMCoarsenHookAdd - adds a callback to be run when restricting a nonlinear problem to the coarse grid 1932b17ce1afSJed Brown 1933b17ce1afSJed Brown Logically Collective 1934b17ce1afSJed Brown 1935b17ce1afSJed Brown Input Arguments: 1936b17ce1afSJed Brown + fine - nonlinear solver context on which to run a hook when restricting to a coarser level 1937b17ce1afSJed Brown . coarsenhook - function to run when setting up a coarser level 1938b17ce1afSJed Brown . restricthook - function to run to update data on coarser levels (once per SNESSolve()) 19390298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1940b17ce1afSJed Brown 1941b17ce1afSJed Brown Calling sequence of coarsenhook: 1942b17ce1afSJed Brown $ coarsenhook(DM fine,DM coarse,void *ctx); 1943b17ce1afSJed Brown 1944b17ce1afSJed Brown + fine - fine level DM 1945b17ce1afSJed Brown . coarse - coarse level DM to restrict problem to 1946b17ce1afSJed Brown - ctx - optional user-defined function context 1947b17ce1afSJed Brown 1948b17ce1afSJed Brown Calling sequence for restricthook: 1949c833c3b5SJed Brown $ restricthook(DM fine,Mat mrestrict,Vec rscale,Mat inject,DM coarse,void *ctx) 1950b17ce1afSJed Brown 1951b17ce1afSJed Brown + fine - fine level DM 1952b17ce1afSJed Brown . mrestrict - matrix restricting a fine-level solution to the coarse grid 1953c833c3b5SJed Brown . rscale - scaling vector for restriction 1954c833c3b5SJed Brown . inject - matrix restricting by injection 1955b17ce1afSJed Brown . coarse - coarse level DM to update 1956b17ce1afSJed Brown - ctx - optional user-defined function context 1957b17ce1afSJed Brown 1958b17ce1afSJed Brown Level: advanced 1959b17ce1afSJed Brown 1960b17ce1afSJed Brown Notes: 1961b17ce1afSJed Brown This function is only needed if auxiliary data needs to be set up on coarse grids. 1962b17ce1afSJed Brown 1963b17ce1afSJed Brown If this function is called multiple times, the hooks will be run in the order they are added. 1964b17ce1afSJed Brown 1965b17ce1afSJed Brown In order to compose with nonlinear preconditioning without duplicating storage, the hook should be implemented to 1966b17ce1afSJed Brown extract the finest level information from its context (instead of from the SNES). 1967b17ce1afSJed Brown 1968bb9467b5SJed Brown This function is currently not available from Fortran. 1969bb9467b5SJed Brown 1970c833c3b5SJed Brown .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1971b17ce1afSJed Brown @*/ 1972b17ce1afSJed Brown PetscErrorCode DMCoarsenHookAdd(DM fine,PetscErrorCode (*coarsenhook)(DM,DM,void*),PetscErrorCode (*restricthook)(DM,Mat,Vec,Mat,DM,void*),void *ctx) 1973b17ce1afSJed Brown { 1974b17ce1afSJed Brown PetscErrorCode ierr; 1975b17ce1afSJed Brown DMCoarsenHookLink link,*p; 1976b17ce1afSJed Brown 1977b17ce1afSJed Brown PetscFunctionBegin; 1978b17ce1afSJed Brown PetscValidHeaderSpecific(fine,DM_CLASSID,1); 19796bfea28cSJed Brown for (p=&fine->coarsenhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1980b17ce1afSJed Brown ierr = PetscMalloc(sizeof(struct _DMCoarsenHookLink),&link);CHKERRQ(ierr); 1981b17ce1afSJed Brown link->coarsenhook = coarsenhook; 1982b17ce1afSJed Brown link->restricthook = restricthook; 1983b17ce1afSJed Brown link->ctx = ctx; 19840298fd71SBarry Smith link->next = NULL; 1985b17ce1afSJed Brown *p = link; 1986b17ce1afSJed Brown PetscFunctionReturn(0); 1987b17ce1afSJed Brown } 1988b17ce1afSJed Brown 1989b17ce1afSJed Brown #undef __FUNCT__ 1990b17ce1afSJed Brown #define __FUNCT__ "DMRestrict" 1991b17ce1afSJed Brown /*@ 1992b17ce1afSJed Brown DMRestrict - restricts user-defined problem data to a coarser DM by running hooks registered by DMCoarsenHookAdd() 1993b17ce1afSJed Brown 1994b17ce1afSJed Brown Collective if any hooks are 1995b17ce1afSJed Brown 1996b17ce1afSJed Brown Input Arguments: 1997b17ce1afSJed Brown + fine - finer DM to use as a base 1998b17ce1afSJed Brown . restrct - restriction matrix, apply using MatRestrict() 1999b17ce1afSJed Brown . inject - injection matrix, also use MatRestrict() 2000b17ce1afSJed Brown - coarse - coarer DM to update 2001b17ce1afSJed Brown 2002b17ce1afSJed Brown Level: developer 2003b17ce1afSJed Brown 2004b17ce1afSJed Brown .seealso: DMCoarsenHookAdd(), MatRestrict() 2005b17ce1afSJed Brown @*/ 2006b17ce1afSJed Brown PetscErrorCode DMRestrict(DM fine,Mat restrct,Vec rscale,Mat inject,DM coarse) 2007b17ce1afSJed Brown { 2008b17ce1afSJed Brown PetscErrorCode ierr; 2009b17ce1afSJed Brown DMCoarsenHookLink link; 2010b17ce1afSJed Brown 2011b17ce1afSJed Brown PetscFunctionBegin; 2012b17ce1afSJed Brown for (link=fine->coarsenhook; link; link=link->next) { 20138865f1eaSKarl Rupp if (link->restricthook) { 20148865f1eaSKarl Rupp ierr = (*link->restricthook)(fine,restrct,rscale,inject,coarse,link->ctx);CHKERRQ(ierr); 20158865f1eaSKarl Rupp } 2016b17ce1afSJed Brown } 201747c6ae99SBarry Smith PetscFunctionReturn(0); 201847c6ae99SBarry Smith } 201947c6ae99SBarry Smith 202047c6ae99SBarry Smith #undef __FUNCT__ 2021be081cd6SPeter Brune #define __FUNCT__ "DMSubDomainHookAdd" 2022bb9467b5SJed Brown /*@C 2023be081cd6SPeter Brune DMSubDomainHookAdd - adds a callback to be run when restricting a problem to the coarse grid 20245dbd56e3SPeter Brune 20255dbd56e3SPeter Brune Logically Collective 20265dbd56e3SPeter Brune 20275dbd56e3SPeter Brune Input Arguments: 20285dbd56e3SPeter Brune + global - global DM 2029ec4806b8SPeter Brune . ddhook - function to run to pass data to the decomposition DM upon its creation 20305dbd56e3SPeter Brune . restricthook - function to run to update data on block solve (at the beginning of the block solve) 20310298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 20325dbd56e3SPeter Brune 2033ec4806b8SPeter Brune 2034ec4806b8SPeter Brune Calling sequence for ddhook: 2035ec4806b8SPeter Brune $ ddhook(DM global,DM block,void *ctx) 2036ec4806b8SPeter Brune 2037ec4806b8SPeter Brune + global - global DM 2038ec4806b8SPeter Brune . block - block DM 2039ec4806b8SPeter Brune - ctx - optional user-defined function context 2040ec4806b8SPeter Brune 20415dbd56e3SPeter Brune Calling sequence for restricthook: 2042ec4806b8SPeter Brune $ restricthook(DM global,VecScatter out,VecScatter in,DM block,void *ctx) 20435dbd56e3SPeter Brune 20445dbd56e3SPeter Brune + global - global DM 20455dbd56e3SPeter Brune . out - scatter to the outer (with ghost and overlap points) block vector 20465dbd56e3SPeter Brune . in - scatter to block vector values only owned locally 2047ec4806b8SPeter Brune . block - block DM 20485dbd56e3SPeter Brune - ctx - optional user-defined function context 20495dbd56e3SPeter Brune 20505dbd56e3SPeter Brune Level: advanced 20515dbd56e3SPeter Brune 20525dbd56e3SPeter Brune Notes: 2053ec4806b8SPeter Brune This function is only needed if auxiliary data needs to be set up on subdomain DMs. 20545dbd56e3SPeter Brune 20555dbd56e3SPeter Brune If this function is called multiple times, the hooks will be run in the order they are added. 20565dbd56e3SPeter Brune 20575dbd56e3SPeter Brune In order to compose with nonlinear preconditioning without duplicating storage, the hook should be implemented to 2058ec4806b8SPeter Brune extract the global information from its context (instead of from the SNES). 20595dbd56e3SPeter Brune 2060bb9467b5SJed Brown This function is currently not available from Fortran. 2061bb9467b5SJed Brown 20625dbd56e3SPeter Brune .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 20635dbd56e3SPeter Brune @*/ 2064be081cd6SPeter Brune PetscErrorCode DMSubDomainHookAdd(DM global,PetscErrorCode (*ddhook)(DM,DM,void*),PetscErrorCode (*restricthook)(DM,VecScatter,VecScatter,DM,void*),void *ctx) 20655dbd56e3SPeter Brune { 20665dbd56e3SPeter Brune PetscErrorCode ierr; 2067be081cd6SPeter Brune DMSubDomainHookLink link,*p; 20685dbd56e3SPeter Brune 20695dbd56e3SPeter Brune PetscFunctionBegin; 20705dbd56e3SPeter Brune PetscValidHeaderSpecific(global,DM_CLASSID,1); 2071be081cd6SPeter Brune for (p=&global->subdomainhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 2072be081cd6SPeter Brune ierr = PetscMalloc(sizeof(struct _DMSubDomainHookLink),&link);CHKERRQ(ierr); 20735dbd56e3SPeter Brune link->restricthook = restricthook; 2074be081cd6SPeter Brune link->ddhook = ddhook; 20755dbd56e3SPeter Brune link->ctx = ctx; 20760298fd71SBarry Smith link->next = NULL; 20775dbd56e3SPeter Brune *p = link; 20785dbd56e3SPeter Brune PetscFunctionReturn(0); 20795dbd56e3SPeter Brune } 20805dbd56e3SPeter Brune 20815dbd56e3SPeter Brune #undef __FUNCT__ 2082be081cd6SPeter Brune #define __FUNCT__ "DMSubDomainRestrict" 20835dbd56e3SPeter Brune /*@ 2084be081cd6SPeter Brune DMSubDomainRestrict - restricts user-defined problem data to a block DM by running hooks registered by DMSubDomainHookAdd() 20855dbd56e3SPeter Brune 20865dbd56e3SPeter Brune Collective if any hooks are 20875dbd56e3SPeter Brune 20885dbd56e3SPeter Brune Input Arguments: 20895dbd56e3SPeter Brune + fine - finer DM to use as a base 2090be081cd6SPeter Brune . oscatter - scatter from domain global vector filling subdomain global vector with overlap 2091be081cd6SPeter Brune . gscatter - scatter from domain global vector filling subdomain local vector with ghosts 20925dbd56e3SPeter Brune - coarse - coarer DM to update 20935dbd56e3SPeter Brune 20945dbd56e3SPeter Brune Level: developer 20955dbd56e3SPeter Brune 20965dbd56e3SPeter Brune .seealso: DMCoarsenHookAdd(), MatRestrict() 20975dbd56e3SPeter Brune @*/ 2098be081cd6SPeter Brune PetscErrorCode DMSubDomainRestrict(DM global,VecScatter oscatter,VecScatter gscatter,DM subdm) 20995dbd56e3SPeter Brune { 21005dbd56e3SPeter Brune PetscErrorCode ierr; 2101be081cd6SPeter Brune DMSubDomainHookLink link; 21025dbd56e3SPeter Brune 21035dbd56e3SPeter Brune PetscFunctionBegin; 2104be081cd6SPeter Brune for (link=global->subdomainhook; link; link=link->next) { 21058865f1eaSKarl Rupp if (link->restricthook) { 21068865f1eaSKarl Rupp ierr = (*link->restricthook)(global,oscatter,gscatter,subdm,link->ctx);CHKERRQ(ierr); 21078865f1eaSKarl Rupp } 21085dbd56e3SPeter Brune } 21095dbd56e3SPeter Brune PetscFunctionReturn(0); 21105dbd56e3SPeter Brune } 21115dbd56e3SPeter Brune 21125dbd56e3SPeter Brune #undef __FUNCT__ 21135fe1f584SPeter Brune #define __FUNCT__ "DMGetCoarsenLevel" 21145fe1f584SPeter Brune /*@ 21156a7d9d85SPeter Brune DMGetCoarsenLevel - Get's the number of coarsenings that have generated this DM. 21165fe1f584SPeter Brune 21175fe1f584SPeter Brune Not Collective 21185fe1f584SPeter Brune 21195fe1f584SPeter Brune Input Parameter: 21205fe1f584SPeter Brune . dm - the DM object 21215fe1f584SPeter Brune 21225fe1f584SPeter Brune Output Parameter: 21236a7d9d85SPeter Brune . level - number of coarsenings 21245fe1f584SPeter Brune 21255fe1f584SPeter Brune Level: developer 21265fe1f584SPeter Brune 21276a7d9d85SPeter Brune .seealso DMCoarsen(), DMGetRefineLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 21285fe1f584SPeter Brune 21295fe1f584SPeter Brune @*/ 21305fe1f584SPeter Brune PetscErrorCode DMGetCoarsenLevel(DM dm,PetscInt *level) 21315fe1f584SPeter Brune { 21325fe1f584SPeter Brune PetscFunctionBegin; 21335fe1f584SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 21345fe1f584SPeter Brune *level = dm->leveldown; 21355fe1f584SPeter Brune PetscFunctionReturn(0); 21365fe1f584SPeter Brune } 21375fe1f584SPeter Brune 21385fe1f584SPeter Brune 21395fe1f584SPeter Brune 21405fe1f584SPeter Brune #undef __FUNCT__ 214147c6ae99SBarry Smith #define __FUNCT__ "DMRefineHierarchy" 214247c6ae99SBarry Smith /*@C 214347c6ae99SBarry Smith DMRefineHierarchy - Refines a DM object, all levels at once 214447c6ae99SBarry Smith 214547c6ae99SBarry Smith Collective on DM 214647c6ae99SBarry Smith 214747c6ae99SBarry Smith Input Parameter: 214847c6ae99SBarry Smith + dm - the DM object 214947c6ae99SBarry Smith - nlevels - the number of levels of refinement 215047c6ae99SBarry Smith 215147c6ae99SBarry Smith Output Parameter: 215247c6ae99SBarry Smith . dmf - the refined DM hierarchy 215347c6ae99SBarry Smith 215447c6ae99SBarry Smith Level: developer 215547c6ae99SBarry Smith 2156e727c939SJed Brown .seealso DMCoarsenHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 215747c6ae99SBarry Smith 215847c6ae99SBarry Smith @*/ 21597087cfbeSBarry Smith PetscErrorCode DMRefineHierarchy(DM dm,PetscInt nlevels,DM dmf[]) 216047c6ae99SBarry Smith { 216147c6ae99SBarry Smith PetscErrorCode ierr; 216247c6ae99SBarry Smith 216347c6ae99SBarry Smith PetscFunctionBegin; 2164171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2165ce94432eSBarry Smith if (nlevels < 0) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 216647c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 216747c6ae99SBarry Smith if (dm->ops->refinehierarchy) { 216847c6ae99SBarry Smith ierr = (*dm->ops->refinehierarchy)(dm,nlevels,dmf);CHKERRQ(ierr); 216947c6ae99SBarry Smith } else if (dm->ops->refine) { 217047c6ae99SBarry Smith PetscInt i; 217147c6ae99SBarry Smith 2172ce94432eSBarry Smith ierr = DMRefine(dm,PetscObjectComm((PetscObject)dm),&dmf[0]);CHKERRQ(ierr); 217347c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 2174ce94432eSBarry Smith ierr = DMRefine(dmf[i-1],PetscObjectComm((PetscObject)dm),&dmf[i]);CHKERRQ(ierr); 217547c6ae99SBarry Smith } 2176ce94432eSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No RefineHierarchy for this DM yet"); 217747c6ae99SBarry Smith PetscFunctionReturn(0); 217847c6ae99SBarry Smith } 217947c6ae99SBarry Smith 218047c6ae99SBarry Smith #undef __FUNCT__ 218147c6ae99SBarry Smith #define __FUNCT__ "DMCoarsenHierarchy" 218247c6ae99SBarry Smith /*@C 218347c6ae99SBarry Smith DMCoarsenHierarchy - Coarsens a DM object, all levels at once 218447c6ae99SBarry Smith 218547c6ae99SBarry Smith Collective on DM 218647c6ae99SBarry Smith 218747c6ae99SBarry Smith Input Parameter: 218847c6ae99SBarry Smith + dm - the DM object 218947c6ae99SBarry Smith - nlevels - the number of levels of coarsening 219047c6ae99SBarry Smith 219147c6ae99SBarry Smith Output Parameter: 219247c6ae99SBarry Smith . dmc - the coarsened DM hierarchy 219347c6ae99SBarry Smith 219447c6ae99SBarry Smith Level: developer 219547c6ae99SBarry Smith 2196e727c939SJed Brown .seealso DMRefineHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 219747c6ae99SBarry Smith 219847c6ae99SBarry Smith @*/ 21997087cfbeSBarry Smith PetscErrorCode DMCoarsenHierarchy(DM dm, PetscInt nlevels, DM dmc[]) 220047c6ae99SBarry Smith { 220147c6ae99SBarry Smith PetscErrorCode ierr; 220247c6ae99SBarry Smith 220347c6ae99SBarry Smith PetscFunctionBegin; 2204171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2205ce94432eSBarry Smith if (nlevels < 0) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 220647c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 220747c6ae99SBarry Smith PetscValidPointer(dmc,3); 220847c6ae99SBarry Smith if (dm->ops->coarsenhierarchy) { 220947c6ae99SBarry Smith ierr = (*dm->ops->coarsenhierarchy)(dm, nlevels, dmc);CHKERRQ(ierr); 221047c6ae99SBarry Smith } else if (dm->ops->coarsen) { 221147c6ae99SBarry Smith PetscInt i; 221247c6ae99SBarry Smith 2213ce94432eSBarry Smith ierr = DMCoarsen(dm,PetscObjectComm((PetscObject)dm),&dmc[0]);CHKERRQ(ierr); 221447c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 2215ce94432eSBarry Smith ierr = DMCoarsen(dmc[i-1],PetscObjectComm((PetscObject)dm),&dmc[i]);CHKERRQ(ierr); 221647c6ae99SBarry Smith } 2217ce94432eSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No CoarsenHierarchy for this DM yet"); 221847c6ae99SBarry Smith PetscFunctionReturn(0); 221947c6ae99SBarry Smith } 222047c6ae99SBarry Smith 222147c6ae99SBarry Smith #undef __FUNCT__ 2222e727c939SJed Brown #define __FUNCT__ "DMCreateAggregates" 222347c6ae99SBarry Smith /*@ 2224e727c939SJed Brown DMCreateAggregates - Gets the aggregates that map between 222547c6ae99SBarry Smith grids associated with two DMs. 222647c6ae99SBarry Smith 222747c6ae99SBarry Smith Collective on DM 222847c6ae99SBarry Smith 222947c6ae99SBarry Smith Input Parameters: 223047c6ae99SBarry Smith + dmc - the coarse grid DM 223147c6ae99SBarry Smith - dmf - the fine grid DM 223247c6ae99SBarry Smith 223347c6ae99SBarry Smith Output Parameters: 223447c6ae99SBarry Smith . rest - the restriction matrix (transpose of the projection matrix) 223547c6ae99SBarry Smith 223647c6ae99SBarry Smith Level: intermediate 223747c6ae99SBarry Smith 223847c6ae99SBarry Smith .keywords: interpolation, restriction, multigrid 223947c6ae99SBarry Smith 2240e727c939SJed Brown .seealso: DMRefine(), DMCreateInjection(), DMCreateInterpolation() 224147c6ae99SBarry Smith @*/ 2242e727c939SJed Brown PetscErrorCode DMCreateAggregates(DM dmc, DM dmf, Mat *rest) 224347c6ae99SBarry Smith { 224447c6ae99SBarry Smith PetscErrorCode ierr; 224547c6ae99SBarry Smith 224647c6ae99SBarry Smith PetscFunctionBegin; 2247171400e9SBarry Smith PetscValidHeaderSpecific(dmc,DM_CLASSID,1); 2248171400e9SBarry Smith PetscValidHeaderSpecific(dmf,DM_CLASSID,2); 224947c6ae99SBarry Smith ierr = (*dmc->ops->getaggregates)(dmc, dmf, rest);CHKERRQ(ierr); 225047c6ae99SBarry Smith PetscFunctionReturn(0); 225147c6ae99SBarry Smith } 225247c6ae99SBarry Smith 225347c6ae99SBarry Smith #undef __FUNCT__ 22541a266240SBarry Smith #define __FUNCT__ "DMSetApplicationContextDestroy" 22551a266240SBarry Smith /*@C 22561a266240SBarry Smith DMSetApplicationContextDestroy - Sets a user function that will be called to destroy the application context when the DM is destroyed 22571a266240SBarry Smith 22581a266240SBarry Smith Not Collective 22591a266240SBarry Smith 22601a266240SBarry Smith Input Parameters: 22611a266240SBarry Smith + dm - the DM object 22621a266240SBarry Smith - destroy - the destroy function 22631a266240SBarry Smith 22641a266240SBarry Smith Level: intermediate 22651a266240SBarry Smith 2266e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 22671a266240SBarry Smith 2268f07f9ceaSJed Brown @*/ 22691a266240SBarry Smith PetscErrorCode DMSetApplicationContextDestroy(DM dm,PetscErrorCode (*destroy)(void**)) 22701a266240SBarry Smith { 22711a266240SBarry Smith PetscFunctionBegin; 2272171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 22731a266240SBarry Smith dm->ctxdestroy = destroy; 22741a266240SBarry Smith PetscFunctionReturn(0); 22751a266240SBarry Smith } 22761a266240SBarry Smith 22771a266240SBarry Smith #undef __FUNCT__ 22781b2093e4SBarry Smith #define __FUNCT__ "DMSetApplicationContext" 2279b07ff414SBarry Smith /*@ 22801b2093e4SBarry Smith DMSetApplicationContext - Set a user context into a DM object 228147c6ae99SBarry Smith 228247c6ae99SBarry Smith Not Collective 228347c6ae99SBarry Smith 228447c6ae99SBarry Smith Input Parameters: 228547c6ae99SBarry Smith + dm - the DM object 228647c6ae99SBarry Smith - ctx - the user context 228747c6ae99SBarry Smith 228847c6ae99SBarry Smith Level: intermediate 228947c6ae99SBarry Smith 2290e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 229147c6ae99SBarry Smith 229247c6ae99SBarry Smith @*/ 22931b2093e4SBarry Smith PetscErrorCode DMSetApplicationContext(DM dm,void *ctx) 229447c6ae99SBarry Smith { 229547c6ae99SBarry Smith PetscFunctionBegin; 2296171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 229747c6ae99SBarry Smith dm->ctx = ctx; 229847c6ae99SBarry Smith PetscFunctionReturn(0); 229947c6ae99SBarry Smith } 230047c6ae99SBarry Smith 230147c6ae99SBarry Smith #undef __FUNCT__ 23021b2093e4SBarry Smith #define __FUNCT__ "DMGetApplicationContext" 230347c6ae99SBarry Smith /*@ 23041b2093e4SBarry Smith DMGetApplicationContext - Gets a user context from a DM object 230547c6ae99SBarry Smith 230647c6ae99SBarry Smith Not Collective 230747c6ae99SBarry Smith 230847c6ae99SBarry Smith Input Parameter: 230947c6ae99SBarry Smith . dm - the DM object 231047c6ae99SBarry Smith 231147c6ae99SBarry Smith Output Parameter: 231247c6ae99SBarry Smith . ctx - the user context 231347c6ae99SBarry Smith 231447c6ae99SBarry Smith Level: intermediate 231547c6ae99SBarry Smith 2316e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 231747c6ae99SBarry Smith 231847c6ae99SBarry Smith @*/ 23191b2093e4SBarry Smith PetscErrorCode DMGetApplicationContext(DM dm,void *ctx) 232047c6ae99SBarry Smith { 232147c6ae99SBarry Smith PetscFunctionBegin; 2322171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 23231b2093e4SBarry Smith *(void**)ctx = dm->ctx; 232447c6ae99SBarry Smith PetscFunctionReturn(0); 232547c6ae99SBarry Smith } 232647c6ae99SBarry Smith 232747c6ae99SBarry Smith #undef __FUNCT__ 232808da532bSDmitry Karpeev #define __FUNCT__ "DMSetVariableBounds" 232908da532bSDmitry Karpeev /*@C 2330df3898eeSBarry Smith DMSetVariableBounds - sets a function to compute the lower and upper bound vectors for SNESVI. 233108da532bSDmitry Karpeev 233208da532bSDmitry Karpeev Logically Collective on DM 233308da532bSDmitry Karpeev 233408da532bSDmitry Karpeev Input Parameter: 233508da532bSDmitry Karpeev + dm - the DM object 23360298fd71SBarry Smith - f - the function that computes variable bounds used by SNESVI (use NULL to cancel a previous function that was set) 233708da532bSDmitry Karpeev 233808da532bSDmitry Karpeev Level: intermediate 233908da532bSDmitry Karpeev 2340835c3ec7SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), 234108da532bSDmitry Karpeev DMSetJacobian() 234208da532bSDmitry Karpeev 234308da532bSDmitry Karpeev @*/ 234408da532bSDmitry Karpeev PetscErrorCode DMSetVariableBounds(DM dm,PetscErrorCode (*f)(DM,Vec,Vec)) 234508da532bSDmitry Karpeev { 234608da532bSDmitry Karpeev PetscFunctionBegin; 234708da532bSDmitry Karpeev dm->ops->computevariablebounds = f; 234808da532bSDmitry Karpeev PetscFunctionReturn(0); 234908da532bSDmitry Karpeev } 235008da532bSDmitry Karpeev 235108da532bSDmitry Karpeev #undef __FUNCT__ 235208da532bSDmitry Karpeev #define __FUNCT__ "DMHasVariableBounds" 235308da532bSDmitry Karpeev /*@ 235408da532bSDmitry Karpeev DMHasVariableBounds - does the DM object have a variable bounds function? 235508da532bSDmitry Karpeev 235608da532bSDmitry Karpeev Not Collective 235708da532bSDmitry Karpeev 235808da532bSDmitry Karpeev Input Parameter: 235908da532bSDmitry Karpeev . dm - the DM object to destroy 236008da532bSDmitry Karpeev 236108da532bSDmitry Karpeev Output Parameter: 236208da532bSDmitry Karpeev . flg - PETSC_TRUE if the variable bounds function exists 236308da532bSDmitry Karpeev 236408da532bSDmitry Karpeev Level: developer 236508da532bSDmitry Karpeev 236674e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 236708da532bSDmitry Karpeev 236808da532bSDmitry Karpeev @*/ 236908da532bSDmitry Karpeev PetscErrorCode DMHasVariableBounds(DM dm,PetscBool *flg) 237008da532bSDmitry Karpeev { 237108da532bSDmitry Karpeev PetscFunctionBegin; 237208da532bSDmitry Karpeev *flg = (dm->ops->computevariablebounds) ? PETSC_TRUE : PETSC_FALSE; 237308da532bSDmitry Karpeev PetscFunctionReturn(0); 237408da532bSDmitry Karpeev } 237508da532bSDmitry Karpeev 237608da532bSDmitry Karpeev #undef __FUNCT__ 237708da532bSDmitry Karpeev #define __FUNCT__ "DMComputeVariableBounds" 237808da532bSDmitry Karpeev /*@C 237908da532bSDmitry Karpeev DMComputeVariableBounds - compute variable bounds used by SNESVI. 238008da532bSDmitry Karpeev 238108da532bSDmitry Karpeev Logically Collective on DM 238208da532bSDmitry Karpeev 238308da532bSDmitry Karpeev Input Parameters: 238408da532bSDmitry Karpeev + dm - the DM object to destroy 238508da532bSDmitry Karpeev - x - current solution at which the bounds are computed 238608da532bSDmitry Karpeev 238708da532bSDmitry Karpeev Output parameters: 238808da532bSDmitry Karpeev + xl - lower bound 238908da532bSDmitry Karpeev - xu - upper bound 239008da532bSDmitry Karpeev 239108da532bSDmitry Karpeev Level: intermediate 239208da532bSDmitry Karpeev 239374e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 239408da532bSDmitry Karpeev 239508da532bSDmitry Karpeev @*/ 239608da532bSDmitry Karpeev PetscErrorCode DMComputeVariableBounds(DM dm, Vec xl, Vec xu) 239708da532bSDmitry Karpeev { 239808da532bSDmitry Karpeev PetscErrorCode ierr; 23995fd66863SKarl Rupp 240008da532bSDmitry Karpeev PetscFunctionBegin; 240108da532bSDmitry Karpeev PetscValidHeaderSpecific(xl,VEC_CLASSID,2); 240208da532bSDmitry Karpeev PetscValidHeaderSpecific(xu,VEC_CLASSID,2); 240308da532bSDmitry Karpeev if (dm->ops->computevariablebounds) { 240408da532bSDmitry Karpeev ierr = (*dm->ops->computevariablebounds)(dm, xl,xu);CHKERRQ(ierr); 24058865f1eaSKarl Rupp } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "This DM is incapable of computing variable bounds."); 240608da532bSDmitry Karpeev PetscFunctionReturn(0); 240708da532bSDmitry Karpeev } 240808da532bSDmitry Karpeev 240908da532bSDmitry Karpeev #undef __FUNCT__ 2410b0ae01b7SPeter Brune #define __FUNCT__ "DMHasColoring" 2411b0ae01b7SPeter Brune /*@ 2412b0ae01b7SPeter Brune DMHasColoring - does the DM object have a method of providing a coloring? 2413b0ae01b7SPeter Brune 2414b0ae01b7SPeter Brune Not Collective 2415b0ae01b7SPeter Brune 2416b0ae01b7SPeter Brune Input Parameter: 2417b0ae01b7SPeter Brune . dm - the DM object 2418b0ae01b7SPeter Brune 2419b0ae01b7SPeter Brune Output Parameter: 2420b0ae01b7SPeter Brune . flg - PETSC_TRUE if the DM has facilities for DMCreateColoring(). 2421b0ae01b7SPeter Brune 2422b0ae01b7SPeter Brune Level: developer 2423b0ae01b7SPeter Brune 2424b0ae01b7SPeter Brune .seealso DMHasFunction(), DMCreateColoring() 2425b0ae01b7SPeter Brune 2426b0ae01b7SPeter Brune @*/ 2427b0ae01b7SPeter Brune PetscErrorCode DMHasColoring(DM dm,PetscBool *flg) 2428b0ae01b7SPeter Brune { 2429b0ae01b7SPeter Brune PetscFunctionBegin; 2430b0ae01b7SPeter Brune *flg = (dm->ops->getcoloring) ? PETSC_TRUE : PETSC_FALSE; 2431b0ae01b7SPeter Brune PetscFunctionReturn(0); 2432b0ae01b7SPeter Brune } 2433b0ae01b7SPeter Brune 2434b0ae01b7SPeter Brune #undef __FUNCT__ 243508da532bSDmitry Karpeev #define __FUNCT__ "DMSetVec" 2436748fac09SDmitry Karpeev /*@C 243708da532bSDmitry Karpeev DMSetVec - set the vector at which to compute residual, Jacobian and VI bounds, if the problem is nonlinear. 243808da532bSDmitry Karpeev 243908da532bSDmitry Karpeev Collective on DM 244008da532bSDmitry Karpeev 244108da532bSDmitry Karpeev Input Parameter: 244208da532bSDmitry Karpeev + dm - the DM object 24430298fd71SBarry Smith - x - location to compute residual and Jacobian, if NULL is passed to those routines; will be NULL for linear problems. 244408da532bSDmitry Karpeev 244508da532bSDmitry Karpeev Level: developer 244608da532bSDmitry Karpeev 244774e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 244808da532bSDmitry Karpeev 244908da532bSDmitry Karpeev @*/ 245008da532bSDmitry Karpeev PetscErrorCode DMSetVec(DM dm,Vec x) 245108da532bSDmitry Karpeev { 245208da532bSDmitry Karpeev PetscErrorCode ierr; 24535fd66863SKarl Rupp 245408da532bSDmitry Karpeev PetscFunctionBegin; 245508da532bSDmitry Karpeev if (x) { 245608da532bSDmitry Karpeev if (!dm->x) { 245708da532bSDmitry Karpeev ierr = DMCreateGlobalVector(dm,&dm->x);CHKERRQ(ierr); 245808da532bSDmitry Karpeev } 245908da532bSDmitry Karpeev ierr = VecCopy(x,dm->x);CHKERRQ(ierr); 24608865f1eaSKarl Rupp } else if (dm->x) { 246108da532bSDmitry Karpeev ierr = VecDestroy(&dm->x);CHKERRQ(ierr); 246208da532bSDmitry Karpeev } 246308da532bSDmitry Karpeev PetscFunctionReturn(0); 246408da532bSDmitry Karpeev } 246508da532bSDmitry Karpeev 24660298fd71SBarry Smith PetscFunctionList DMList = NULL; 2467264ace61SBarry Smith PetscBool DMRegisterAllCalled = PETSC_FALSE; 2468264ace61SBarry Smith 2469264ace61SBarry Smith #undef __FUNCT__ 2470264ace61SBarry Smith #define __FUNCT__ "DMSetType" 2471264ace61SBarry Smith /*@C 2472264ace61SBarry Smith DMSetType - Builds a DM, for a particular DM implementation. 2473264ace61SBarry Smith 2474264ace61SBarry Smith Collective on DM 2475264ace61SBarry Smith 2476264ace61SBarry Smith Input Parameters: 2477264ace61SBarry Smith + dm - The DM object 2478264ace61SBarry Smith - method - The name of the DM type 2479264ace61SBarry Smith 2480264ace61SBarry Smith Options Database Key: 2481264ace61SBarry Smith . -dm_type <type> - Sets the DM type; use -help for a list of available types 2482264ace61SBarry Smith 2483264ace61SBarry Smith Notes: 2484e1589f56SBarry Smith See "petsc/include/petscdm.h" for available DM types (for instance, DM1D, DM2D, or DM3D). 2485264ace61SBarry Smith 2486264ace61SBarry Smith Level: intermediate 2487264ace61SBarry Smith 2488264ace61SBarry Smith .keywords: DM, set, type 2489264ace61SBarry Smith .seealso: DMGetType(), DMCreate() 2490264ace61SBarry Smith @*/ 249119fd82e9SBarry Smith PetscErrorCode DMSetType(DM dm, DMType method) 2492264ace61SBarry Smith { 2493264ace61SBarry Smith PetscErrorCode (*r)(DM); 2494264ace61SBarry Smith PetscBool match; 2495264ace61SBarry Smith PetscErrorCode ierr; 2496264ace61SBarry Smith 2497264ace61SBarry Smith PetscFunctionBegin; 2498264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 2499251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject) dm, method, &match);CHKERRQ(ierr); 2500264ace61SBarry Smith if (match) PetscFunctionReturn(0); 2501264ace61SBarry Smith 2502607a6623SBarry Smith if (!DMRegisterAllCalled) {ierr = DMRegisterAll();CHKERRQ(ierr);} 25031c9cd337SJed Brown ierr = PetscFunctionListFind(DMList,method,&r);CHKERRQ(ierr); 2504ce94432eSBarry Smith if (!r) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown DM type: %s", method); 2505264ace61SBarry Smith 2506264ace61SBarry Smith if (dm->ops->destroy) { 2507264ace61SBarry Smith ierr = (*dm->ops->destroy)(dm);CHKERRQ(ierr); 25080298fd71SBarry Smith dm->ops->destroy = NULL; 2509264ace61SBarry Smith } 2510264ace61SBarry Smith ierr = (*r)(dm);CHKERRQ(ierr); 2511264ace61SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)dm,method);CHKERRQ(ierr); 2512264ace61SBarry Smith PetscFunctionReturn(0); 2513264ace61SBarry Smith } 2514264ace61SBarry Smith 2515264ace61SBarry Smith #undef __FUNCT__ 2516264ace61SBarry Smith #define __FUNCT__ "DMGetType" 2517264ace61SBarry Smith /*@C 2518264ace61SBarry Smith DMGetType - Gets the DM type name (as a string) from the DM. 2519264ace61SBarry Smith 2520264ace61SBarry Smith Not Collective 2521264ace61SBarry Smith 2522264ace61SBarry Smith Input Parameter: 2523264ace61SBarry Smith . dm - The DM 2524264ace61SBarry Smith 2525264ace61SBarry Smith Output Parameter: 2526264ace61SBarry Smith . type - The DM type name 2527264ace61SBarry Smith 2528264ace61SBarry Smith Level: intermediate 2529264ace61SBarry Smith 2530264ace61SBarry Smith .keywords: DM, get, type, name 2531264ace61SBarry Smith .seealso: DMSetType(), DMCreate() 2532264ace61SBarry Smith @*/ 253319fd82e9SBarry Smith PetscErrorCode DMGetType(DM dm, DMType *type) 2534264ace61SBarry Smith { 2535264ace61SBarry Smith PetscErrorCode ierr; 2536264ace61SBarry Smith 2537264ace61SBarry Smith PetscFunctionBegin; 2538264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 2539c959eef4SJed Brown PetscValidPointer(type,2); 2540264ace61SBarry Smith if (!DMRegisterAllCalled) { 2541607a6623SBarry Smith ierr = DMRegisterAll();CHKERRQ(ierr); 2542264ace61SBarry Smith } 2543264ace61SBarry Smith *type = ((PetscObject)dm)->type_name; 2544264ace61SBarry Smith PetscFunctionReturn(0); 2545264ace61SBarry Smith } 2546264ace61SBarry Smith 254767a56275SMatthew G Knepley #undef __FUNCT__ 254867a56275SMatthew G Knepley #define __FUNCT__ "DMConvert" 254967a56275SMatthew G Knepley /*@C 255067a56275SMatthew G Knepley DMConvert - Converts a DM to another DM, either of the same or different type. 255167a56275SMatthew G Knepley 255267a56275SMatthew G Knepley Collective on DM 255367a56275SMatthew G Knepley 255467a56275SMatthew G Knepley Input Parameters: 255567a56275SMatthew G Knepley + dm - the DM 255667a56275SMatthew G Knepley - newtype - new DM type (use "same" for the same type) 255767a56275SMatthew G Knepley 255867a56275SMatthew G Knepley Output Parameter: 255967a56275SMatthew G Knepley . M - pointer to new DM 256067a56275SMatthew G Knepley 256167a56275SMatthew G Knepley Notes: 256267a56275SMatthew G Knepley Cannot be used to convert a sequential DM to parallel or parallel to sequential, 256367a56275SMatthew G Knepley the MPI communicator of the generated DM is always the same as the communicator 256467a56275SMatthew G Knepley of the input DM. 256567a56275SMatthew G Knepley 256667a56275SMatthew G Knepley Level: intermediate 256767a56275SMatthew G Knepley 256867a56275SMatthew G Knepley .seealso: DMCreate() 256967a56275SMatthew G Knepley @*/ 257019fd82e9SBarry Smith PetscErrorCode DMConvert(DM dm, DMType newtype, DM *M) 257167a56275SMatthew G Knepley { 257267a56275SMatthew G Knepley DM B; 257367a56275SMatthew G Knepley char convname[256]; 257467a56275SMatthew G Knepley PetscBool sametype, issame; 257567a56275SMatthew G Knepley PetscErrorCode ierr; 257667a56275SMatthew G Knepley 257767a56275SMatthew G Knepley PetscFunctionBegin; 257867a56275SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 257967a56275SMatthew G Knepley PetscValidType(dm,1); 258067a56275SMatthew G Knepley PetscValidPointer(M,3); 2581251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject) dm, newtype, &sametype);CHKERRQ(ierr); 258267a56275SMatthew G Knepley ierr = PetscStrcmp(newtype, "same", &issame);CHKERRQ(ierr); 258367a56275SMatthew G Knepley { 25840298fd71SBarry Smith PetscErrorCode (*conv)(DM, DMType, DM*) = NULL; 258567a56275SMatthew G Knepley 258667a56275SMatthew G Knepley /* 258767a56275SMatthew G Knepley Order of precedence: 258867a56275SMatthew G Knepley 1) See if a specialized converter is known to the current DM. 258967a56275SMatthew G Knepley 2) See if a specialized converter is known to the desired DM class. 259067a56275SMatthew G Knepley 3) See if a good general converter is registered for the desired class 259167a56275SMatthew G Knepley 4) See if a good general converter is known for the current matrix. 259267a56275SMatthew G Knepley 5) Use a really basic converter. 259367a56275SMatthew G Knepley */ 259467a56275SMatthew G Knepley 259567a56275SMatthew G Knepley /* 1) See if a specialized converter is known to the current DM and the desired class */ 259667a56275SMatthew G Knepley ierr = PetscStrcpy(convname,"DMConvert_");CHKERRQ(ierr); 259767a56275SMatthew G Knepley ierr = PetscStrcat(convname,((PetscObject) dm)->type_name);CHKERRQ(ierr); 259867a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_");CHKERRQ(ierr); 259967a56275SMatthew G Knepley ierr = PetscStrcat(convname,newtype);CHKERRQ(ierr); 260067a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_C");CHKERRQ(ierr); 26010005d66cSJed Brown ierr = PetscObjectQueryFunction((PetscObject)dm,convname,&conv);CHKERRQ(ierr); 260267a56275SMatthew G Knepley if (conv) goto foundconv; 260367a56275SMatthew G Knepley 260467a56275SMatthew G Knepley /* 2) See if a specialized converter is known to the desired DM class. */ 260582f516ccSBarry Smith ierr = DMCreate(PetscObjectComm((PetscObject)dm), &B);CHKERRQ(ierr); 260667a56275SMatthew G Knepley ierr = DMSetType(B, newtype);CHKERRQ(ierr); 260767a56275SMatthew G Knepley ierr = PetscStrcpy(convname,"DMConvert_");CHKERRQ(ierr); 260867a56275SMatthew G Knepley ierr = PetscStrcat(convname,((PetscObject) dm)->type_name);CHKERRQ(ierr); 260967a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_");CHKERRQ(ierr); 261067a56275SMatthew G Knepley ierr = PetscStrcat(convname,newtype);CHKERRQ(ierr); 261167a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_C");CHKERRQ(ierr); 26120005d66cSJed Brown ierr = PetscObjectQueryFunction((PetscObject)B,convname,&conv);CHKERRQ(ierr); 261367a56275SMatthew G Knepley if (conv) { 2614fcfd50ebSBarry Smith ierr = DMDestroy(&B);CHKERRQ(ierr); 261567a56275SMatthew G Knepley goto foundconv; 261667a56275SMatthew G Knepley } 261767a56275SMatthew G Knepley 261867a56275SMatthew G Knepley #if 0 261967a56275SMatthew G Knepley /* 3) See if a good general converter is registered for the desired class */ 262067a56275SMatthew G Knepley conv = B->ops->convertfrom; 2621fcfd50ebSBarry Smith ierr = DMDestroy(&B);CHKERRQ(ierr); 262267a56275SMatthew G Knepley if (conv) goto foundconv; 262367a56275SMatthew G Knepley 262467a56275SMatthew G Knepley /* 4) See if a good general converter is known for the current matrix */ 262567a56275SMatthew G Knepley if (dm->ops->convert) { 262667a56275SMatthew G Knepley conv = dm->ops->convert; 262767a56275SMatthew G Knepley } 262867a56275SMatthew G Knepley if (conv) goto foundconv; 262967a56275SMatthew G Knepley #endif 263067a56275SMatthew G Knepley 263167a56275SMatthew G Knepley /* 5) Use a really basic converter. */ 263282f516ccSBarry Smith SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "No conversion possible between DM types %s and %s", ((PetscObject) dm)->type_name, newtype); 263367a56275SMatthew G Knepley 263467a56275SMatthew G Knepley foundconv: 263567a56275SMatthew G Knepley ierr = PetscLogEventBegin(DM_Convert,dm,0,0,0);CHKERRQ(ierr); 263667a56275SMatthew G Knepley ierr = (*conv)(dm,newtype,M);CHKERRQ(ierr); 263767a56275SMatthew G Knepley ierr = PetscLogEventEnd(DM_Convert,dm,0,0,0);CHKERRQ(ierr); 263867a56275SMatthew G Knepley } 263967a56275SMatthew G Knepley ierr = PetscObjectStateIncrease((PetscObject) *M);CHKERRQ(ierr); 264067a56275SMatthew G Knepley PetscFunctionReturn(0); 264167a56275SMatthew G Knepley } 2642264ace61SBarry Smith 2643264ace61SBarry Smith /*--------------------------------------------------------------------------------------------------------------------*/ 2644264ace61SBarry Smith 2645264ace61SBarry Smith #undef __FUNCT__ 2646264ace61SBarry Smith #define __FUNCT__ "DMRegister" 2647264ace61SBarry Smith /*@C 26481c84c290SBarry Smith DMRegister - Adds a new DM component implementation 26491c84c290SBarry Smith 26501c84c290SBarry Smith Not Collective 26511c84c290SBarry Smith 26521c84c290SBarry Smith Input Parameters: 26531c84c290SBarry Smith + name - The name of a new user-defined creation routine 26541c84c290SBarry Smith - create_func - The creation routine itself 26551c84c290SBarry Smith 26561c84c290SBarry Smith Notes: 26571c84c290SBarry Smith DMRegister() may be called multiple times to add several user-defined DMs 26581c84c290SBarry Smith 26591c84c290SBarry Smith 26601c84c290SBarry Smith Sample usage: 26611c84c290SBarry Smith .vb 2662bdf89e91SBarry Smith DMRegister("my_da", MyDMCreate); 26631c84c290SBarry Smith .ve 26641c84c290SBarry Smith 26651c84c290SBarry Smith Then, your DM type can be chosen with the procedural interface via 26661c84c290SBarry Smith .vb 26671c84c290SBarry Smith DMCreate(MPI_Comm, DM *); 26681c84c290SBarry Smith DMSetType(DM,"my_da"); 26691c84c290SBarry Smith .ve 26701c84c290SBarry Smith or at runtime via the option 26711c84c290SBarry Smith .vb 26721c84c290SBarry Smith -da_type my_da 26731c84c290SBarry Smith .ve 2674264ace61SBarry Smith 2675264ace61SBarry Smith Level: advanced 26761c84c290SBarry Smith 26771c84c290SBarry Smith .keywords: DM, register 2678bdf89e91SBarry Smith .seealso: DMRegisterAll(), DMRegisterDestroy() 26791c84c290SBarry Smith 2680264ace61SBarry Smith @*/ 2681bdf89e91SBarry Smith PetscErrorCode DMRegister(const char sname[],PetscErrorCode (*function)(DM)) 2682264ace61SBarry Smith { 2683264ace61SBarry Smith PetscErrorCode ierr; 2684264ace61SBarry Smith 2685264ace61SBarry Smith PetscFunctionBegin; 2686a240a19fSJed Brown ierr = PetscFunctionListAdd(&DMList,sname,function);CHKERRQ(ierr); 2687264ace61SBarry Smith PetscFunctionReturn(0); 2688264ace61SBarry Smith } 2689264ace61SBarry Smith 2690b859378eSBarry Smith #undef __FUNCT__ 2691b859378eSBarry Smith #define __FUNCT__ "DMLoad" 2692b859378eSBarry Smith /*@C 269355849f57SBarry Smith DMLoad - Loads a DM that has been stored in binary with DMView(). 2694b859378eSBarry Smith 2695b859378eSBarry Smith Collective on PetscViewer 2696b859378eSBarry Smith 2697b859378eSBarry Smith Input Parameters: 2698b859378eSBarry Smith + newdm - the newly loaded DM, this needs to have been created with DMCreate() or 2699b859378eSBarry Smith some related function before a call to DMLoad(). 2700b859378eSBarry Smith - viewer - binary file viewer, obtained from PetscViewerBinaryOpen() or 2701b859378eSBarry Smith HDF5 file viewer, obtained from PetscViewerHDF5Open() 2702b859378eSBarry Smith 2703b859378eSBarry Smith Level: intermediate 2704b859378eSBarry Smith 2705b859378eSBarry Smith Notes: 270655849f57SBarry Smith The type is determined by the data in the file, any type set into the DM before this call is ignored. 2707b859378eSBarry Smith 2708b859378eSBarry Smith Notes for advanced users: 2709b859378eSBarry Smith Most users should not need to know the details of the binary storage 2710b859378eSBarry Smith format, since DMLoad() and DMView() completely hide these details. 2711b859378eSBarry Smith But for anyone who's interested, the standard binary matrix storage 2712b859378eSBarry Smith format is 2713b859378eSBarry Smith .vb 2714b859378eSBarry Smith has not yet been determined 2715b859378eSBarry Smith .ve 2716b859378eSBarry Smith 2717b859378eSBarry Smith .seealso: PetscViewerBinaryOpen(), DMView(), MatLoad(), VecLoad() 2718b859378eSBarry Smith @*/ 2719b859378eSBarry Smith PetscErrorCode DMLoad(DM newdm, PetscViewer viewer) 2720b859378eSBarry Smith { 27219331c7a4SMatthew G. Knepley PetscBool isbinary, ishdf5; 2722b859378eSBarry Smith PetscErrorCode ierr; 2723b859378eSBarry Smith 2724b859378eSBarry Smith PetscFunctionBegin; 2725b859378eSBarry Smith PetscValidHeaderSpecific(newdm,DM_CLASSID,1); 2726b859378eSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 272732c0f0efSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); 27289331c7a4SMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERHDF5,&ishdf5);CHKERRQ(ierr); 27299331c7a4SMatthew G. Knepley if (isbinary) { 27309331c7a4SMatthew G. Knepley PetscInt classid; 27319331c7a4SMatthew G. Knepley char type[256]; 2732b859378eSBarry Smith 273332c0f0efSBarry Smith ierr = PetscViewerBinaryRead(viewer,&classid,1,PETSC_INT);CHKERRQ(ierr); 27349200755eSBarry Smith if (classid != DM_FILE_CLASSID) SETERRQ1(PetscObjectComm((PetscObject)newdm),PETSC_ERR_ARG_WRONG,"Not DM next in file, classid found %d",(int)classid); 273532c0f0efSBarry Smith ierr = PetscViewerBinaryRead(viewer,type,256,PETSC_CHAR);CHKERRQ(ierr); 273632c0f0efSBarry Smith ierr = DMSetType(newdm, type);CHKERRQ(ierr); 27379331c7a4SMatthew G. Knepley if (newdm->ops->load) {ierr = (*newdm->ops->load)(newdm,viewer);CHKERRQ(ierr);} 27389331c7a4SMatthew G. Knepley } else if (ishdf5) { 27399331c7a4SMatthew G. Knepley if (newdm->ops->load) {ierr = (*newdm->ops->load)(newdm,viewer);CHKERRQ(ierr);} 27409331c7a4SMatthew G. Knepley } else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Invalid viewer; open viewer with PetscViewerBinaryOpen() or PetscViewerHDF5Open()"); 2741b859378eSBarry Smith PetscFunctionReturn(0); 2742b859378eSBarry Smith } 2743b859378eSBarry Smith 27447da65231SMatthew G Knepley /******************************** FEM Support **********************************/ 27457da65231SMatthew G Knepley 27467da65231SMatthew G Knepley #undef __FUNCT__ 27477da65231SMatthew G Knepley #define __FUNCT__ "DMPrintCellVector" 2748a6dfd86eSKarl Rupp PetscErrorCode DMPrintCellVector(PetscInt c, const char name[], PetscInt len, const PetscScalar x[]) 2749a6dfd86eSKarl Rupp { 27501d47ebbbSSatish Balay PetscInt f; 27511b30c384SMatthew G Knepley PetscErrorCode ierr; 27521b30c384SMatthew G Knepley 27537da65231SMatthew G Knepley PetscFunctionBegin; 275474778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, "Cell %D Element %s\n", c, name);CHKERRQ(ierr); 27551d47ebbbSSatish Balay for (f = 0; f < len; ++f) { 275657622a8eSBarry Smith ierr = PetscPrintf(PETSC_COMM_SELF, " | %g |\n", (double)PetscRealPart(x[f]));CHKERRQ(ierr); 27577da65231SMatthew G Knepley } 27587da65231SMatthew G Knepley PetscFunctionReturn(0); 27597da65231SMatthew G Knepley } 27607da65231SMatthew G Knepley 27617da65231SMatthew G Knepley #undef __FUNCT__ 27627da65231SMatthew G Knepley #define __FUNCT__ "DMPrintCellMatrix" 2763a6dfd86eSKarl Rupp PetscErrorCode DMPrintCellMatrix(PetscInt c, const char name[], PetscInt rows, PetscInt cols, const PetscScalar A[]) 2764a6dfd86eSKarl Rupp { 27651b30c384SMatthew G Knepley PetscInt f, g; 27667da65231SMatthew G Knepley PetscErrorCode ierr; 27677da65231SMatthew G Knepley 27687da65231SMatthew G Knepley PetscFunctionBegin; 276974778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, "Cell %D Element %s\n", c, name);CHKERRQ(ierr); 27701d47ebbbSSatish Balay for (f = 0; f < rows; ++f) { 277174778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " |");CHKERRQ(ierr); 27721d47ebbbSSatish Balay for (g = 0; g < cols; ++g) { 2773e3556bceSMatthew G. Knepley ierr = PetscPrintf(PETSC_COMM_SELF, " % 9.5g", PetscRealPart(A[f*cols+g]));CHKERRQ(ierr); 27747da65231SMatthew G Knepley } 277574778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " |\n");CHKERRQ(ierr); 27767da65231SMatthew G Knepley } 27777da65231SMatthew G Knepley PetscFunctionReturn(0); 27787da65231SMatthew G Knepley } 2779e7c4fc90SDmitry Karpeev 2780970e74d5SMatthew G Knepley #undef __FUNCT__ 2781e759306cSMatthew G. Knepley #define __FUNCT__ "DMPrintLocalVec" 27826113b454SMatthew G. Knepley PetscErrorCode DMPrintLocalVec(DM dm, const char name[], PetscReal tol, Vec X) 2783e759306cSMatthew G. Knepley { 2784e759306cSMatthew G. Knepley PetscMPIInt rank, numProcs; 2785e759306cSMatthew G. Knepley PetscInt p; 2786e759306cSMatthew G. Knepley PetscErrorCode ierr; 2787e759306cSMatthew G. Knepley 2788e759306cSMatthew G. Knepley PetscFunctionBegin; 2789e759306cSMatthew G. Knepley ierr = MPI_Comm_rank(PetscObjectComm((PetscObject) dm), &rank);CHKERRQ(ierr); 2790e759306cSMatthew G. Knepley ierr = MPI_Comm_size(PetscObjectComm((PetscObject) dm), &numProcs);CHKERRQ(ierr); 2791e759306cSMatthew G. Knepley ierr = PetscPrintf(PetscObjectComm((PetscObject) dm), "%s:\n", name);CHKERRQ(ierr); 2792e759306cSMatthew G. Knepley for (p = 0; p < numProcs; ++p) { 2793e759306cSMatthew G. Knepley if (p == rank) { 2794e759306cSMatthew G. Knepley Vec x; 2795e759306cSMatthew G. Knepley 2796e759306cSMatthew G. Knepley ierr = VecDuplicate(X, &x);CHKERRQ(ierr); 2797e759306cSMatthew G. Knepley ierr = VecCopy(X, x);CHKERRQ(ierr); 27986113b454SMatthew G. Knepley ierr = VecChop(x, tol);CHKERRQ(ierr); 2799e759306cSMatthew G. Knepley ierr = VecView(x, PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); 2800e759306cSMatthew G. Knepley ierr = VecDestroy(&x);CHKERRQ(ierr); 2801e759306cSMatthew G. Knepley ierr = PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); 2802e759306cSMatthew G. Knepley } 2803e759306cSMatthew G. Knepley ierr = PetscBarrier((PetscObject) dm);CHKERRQ(ierr); 2804e759306cSMatthew G. Knepley } 2805e759306cSMatthew G. Knepley PetscFunctionReturn(0); 2806e759306cSMatthew G. Knepley } 2807e759306cSMatthew G. Knepley 2808e759306cSMatthew G. Knepley #undef __FUNCT__ 280988ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultSection" 281088ed4aceSMatthew G Knepley /*@ 281188ed4aceSMatthew G Knepley DMGetDefaultSection - Get the PetscSection encoding the local data layout for the DM. 281288ed4aceSMatthew G Knepley 281388ed4aceSMatthew G Knepley Input Parameter: 281488ed4aceSMatthew G Knepley . dm - The DM 281588ed4aceSMatthew G Knepley 281688ed4aceSMatthew G Knepley Output Parameter: 281788ed4aceSMatthew G Knepley . section - The PetscSection 281888ed4aceSMatthew G Knepley 281988ed4aceSMatthew G Knepley Level: intermediate 282088ed4aceSMatthew G Knepley 282188ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSection. 282288ed4aceSMatthew G Knepley 282388ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultGlobalSection() 282488ed4aceSMatthew G Knepley @*/ 28250adebc6cSBarry Smith PetscErrorCode DMGetDefaultSection(DM dm, PetscSection *section) 28260adebc6cSBarry Smith { 2827fd59a867SMatthew G. Knepley PetscErrorCode ierr; 2828fd59a867SMatthew G. Knepley 282988ed4aceSMatthew G Knepley PetscFunctionBegin; 283088ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 283188ed4aceSMatthew G Knepley PetscValidPointer(section, 2); 2832fd59a867SMatthew G. Knepley if (!dm->defaultSection && dm->ops->createdefaultsection) {ierr = (*dm->ops->createdefaultsection)(dm);CHKERRQ(ierr);} 283388ed4aceSMatthew G Knepley *section = dm->defaultSection; 283488ed4aceSMatthew G Knepley PetscFunctionReturn(0); 283588ed4aceSMatthew G Knepley } 283688ed4aceSMatthew G Knepley 283788ed4aceSMatthew G Knepley #undef __FUNCT__ 283888ed4aceSMatthew G Knepley #define __FUNCT__ "DMSetDefaultSection" 283988ed4aceSMatthew G Knepley /*@ 284088ed4aceSMatthew G Knepley DMSetDefaultSection - Set the PetscSection encoding the local data layout for the DM. 284188ed4aceSMatthew G Knepley 284288ed4aceSMatthew G Knepley Input Parameters: 284388ed4aceSMatthew G Knepley + dm - The DM 284488ed4aceSMatthew G Knepley - section - The PetscSection 284588ed4aceSMatthew G Knepley 284688ed4aceSMatthew G Knepley Level: intermediate 284788ed4aceSMatthew G Knepley 284888ed4aceSMatthew G Knepley Note: Any existing Section will be destroyed 284988ed4aceSMatthew G Knepley 285088ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultGlobalSection() 285188ed4aceSMatthew G Knepley @*/ 28520adebc6cSBarry Smith PetscErrorCode DMSetDefaultSection(DM dm, PetscSection section) 28530adebc6cSBarry Smith { 2854af122d2aSMatthew G Knepley PetscInt numFields; 2855af122d2aSMatthew G Knepley PetscInt f; 285688ed4aceSMatthew G Knepley PetscErrorCode ierr; 285788ed4aceSMatthew G Knepley 285888ed4aceSMatthew G Knepley PetscFunctionBegin; 285988ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 28601d799100SJed Brown PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 28611d799100SJed Brown ierr = PetscObjectReference((PetscObject)section);CHKERRQ(ierr); 286288ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&dm->defaultSection);CHKERRQ(ierr); 286388ed4aceSMatthew G Knepley dm->defaultSection = section; 2864af122d2aSMatthew G Knepley ierr = PetscSectionGetNumFields(dm->defaultSection, &numFields);CHKERRQ(ierr); 2865af122d2aSMatthew G Knepley if (numFields) { 2866af122d2aSMatthew G Knepley ierr = DMSetNumFields(dm, numFields);CHKERRQ(ierr); 2867af122d2aSMatthew G Knepley for (f = 0; f < numFields; ++f) { 28680f21e855SMatthew G. Knepley PetscObject disc; 2869af122d2aSMatthew G Knepley const char *name; 2870af122d2aSMatthew G Knepley 2871af122d2aSMatthew G Knepley ierr = PetscSectionGetFieldName(dm->defaultSection, f, &name);CHKERRQ(ierr); 28720f21e855SMatthew G. Knepley ierr = DMGetField(dm, f, &disc);CHKERRQ(ierr); 28730f21e855SMatthew G. Knepley ierr = PetscObjectSetName(disc, name);CHKERRQ(ierr); 2874af122d2aSMatthew G Knepley } 2875af122d2aSMatthew G Knepley } 28761d799100SJed Brown /* The global section will be rebuilt in the next call to DMGetDefaultGlobalSection(). */ 28771d799100SJed Brown ierr = PetscSectionDestroy(&dm->defaultGlobalSection);CHKERRQ(ierr); 287888ed4aceSMatthew G Knepley PetscFunctionReturn(0); 287988ed4aceSMatthew G Knepley } 288088ed4aceSMatthew G Knepley 288188ed4aceSMatthew G Knepley #undef __FUNCT__ 288288ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultGlobalSection" 288388ed4aceSMatthew G Knepley /*@ 288488ed4aceSMatthew G Knepley DMGetDefaultGlobalSection - Get the PetscSection encoding the global data layout for the DM. 288588ed4aceSMatthew G Knepley 28868b1ab98fSJed Brown Collective on DM 28878b1ab98fSJed Brown 288888ed4aceSMatthew G Knepley Input Parameter: 288988ed4aceSMatthew G Knepley . dm - The DM 289088ed4aceSMatthew G Knepley 289188ed4aceSMatthew G Knepley Output Parameter: 289288ed4aceSMatthew G Knepley . section - The PetscSection 289388ed4aceSMatthew G Knepley 289488ed4aceSMatthew G Knepley Level: intermediate 289588ed4aceSMatthew G Knepley 289688ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSection. 289788ed4aceSMatthew G Knepley 289888ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultSection() 289988ed4aceSMatthew G Knepley @*/ 29000adebc6cSBarry Smith PetscErrorCode DMGetDefaultGlobalSection(DM dm, PetscSection *section) 29010adebc6cSBarry Smith { 290288ed4aceSMatthew G Knepley PetscErrorCode ierr; 290388ed4aceSMatthew G Knepley 290488ed4aceSMatthew G Knepley PetscFunctionBegin; 290588ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 290688ed4aceSMatthew G Knepley PetscValidPointer(section, 2); 290788ed4aceSMatthew G Knepley if (!dm->defaultGlobalSection) { 2908fd59a867SMatthew G. Knepley PetscSection s; 2909fd59a867SMatthew G. Knepley 2910fd59a867SMatthew G. Knepley ierr = DMGetDefaultSection(dm, &s);CHKERRQ(ierr); 2911fd59a867SMatthew 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"); 2912fd59a867SMatthew 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"); 2913fd59a867SMatthew G. Knepley ierr = PetscSectionCreateGlobalSection(s, dm->sf, PETSC_FALSE, &dm->defaultGlobalSection);CHKERRQ(ierr); 2914cf06b437SMatthew G. Knepley ierr = PetscLayoutDestroy(&dm->map);CHKERRQ(ierr); 2915ce94432eSBarry Smith ierr = PetscSectionGetValueLayout(PetscObjectComm((PetscObject)dm), dm->defaultGlobalSection, &dm->map);CHKERRQ(ierr); 291688ed4aceSMatthew G Knepley } 291788ed4aceSMatthew G Knepley *section = dm->defaultGlobalSection; 291888ed4aceSMatthew G Knepley PetscFunctionReturn(0); 291988ed4aceSMatthew G Knepley } 292088ed4aceSMatthew G Knepley 292188ed4aceSMatthew G Knepley #undef __FUNCT__ 2922b21d0597SMatthew G Knepley #define __FUNCT__ "DMSetDefaultGlobalSection" 2923b21d0597SMatthew G Knepley /*@ 2924b21d0597SMatthew G Knepley DMSetDefaultGlobalSection - Set the PetscSection encoding the global data layout for the DM. 2925b21d0597SMatthew G Knepley 2926b21d0597SMatthew G Knepley Input Parameters: 2927b21d0597SMatthew G Knepley + dm - The DM 29285080bbdbSMatthew G Knepley - section - The PetscSection, or NULL 2929b21d0597SMatthew G Knepley 2930b21d0597SMatthew G Knepley Level: intermediate 2931b21d0597SMatthew G Knepley 2932b21d0597SMatthew G Knepley Note: Any existing Section will be destroyed 2933b21d0597SMatthew G Knepley 2934b21d0597SMatthew G Knepley .seealso: DMGetDefaultGlobalSection(), DMSetDefaultSection() 2935b21d0597SMatthew G Knepley @*/ 29360adebc6cSBarry Smith PetscErrorCode DMSetDefaultGlobalSection(DM dm, PetscSection section) 29370adebc6cSBarry Smith { 2938b21d0597SMatthew G Knepley PetscErrorCode ierr; 2939b21d0597SMatthew G Knepley 2940b21d0597SMatthew G Knepley PetscFunctionBegin; 2941b21d0597SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 29425080bbdbSMatthew G Knepley if (section) PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 29431d799100SJed Brown ierr = PetscObjectReference((PetscObject)section);CHKERRQ(ierr); 2944b21d0597SMatthew G Knepley ierr = PetscSectionDestroy(&dm->defaultGlobalSection);CHKERRQ(ierr); 2945b21d0597SMatthew G Knepley dm->defaultGlobalSection = section; 2946b21d0597SMatthew G Knepley PetscFunctionReturn(0); 2947b21d0597SMatthew G Knepley } 2948b21d0597SMatthew G Knepley 2949b21d0597SMatthew G Knepley #undef __FUNCT__ 295088ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultSF" 295188ed4aceSMatthew G Knepley /*@ 295288ed4aceSMatthew G Knepley DMGetDefaultSF - Get the PetscSF encoding the parallel dof overlap for the DM. If it has not been set, 295388ed4aceSMatthew G Knepley it is created from the default PetscSection layouts in the DM. 295488ed4aceSMatthew G Knepley 295588ed4aceSMatthew G Knepley Input Parameter: 295688ed4aceSMatthew G Knepley . dm - The DM 295788ed4aceSMatthew G Knepley 295888ed4aceSMatthew G Knepley Output Parameter: 295988ed4aceSMatthew G Knepley . sf - The PetscSF 296088ed4aceSMatthew G Knepley 296188ed4aceSMatthew G Knepley Level: intermediate 296288ed4aceSMatthew G Knepley 296388ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSF. 296488ed4aceSMatthew G Knepley 296588ed4aceSMatthew G Knepley .seealso: DMSetDefaultSF(), DMCreateDefaultSF() 296688ed4aceSMatthew G Knepley @*/ 29670adebc6cSBarry Smith PetscErrorCode DMGetDefaultSF(DM dm, PetscSF *sf) 29680adebc6cSBarry Smith { 296988ed4aceSMatthew G Knepley PetscInt nroots; 297088ed4aceSMatthew G Knepley PetscErrorCode ierr; 297188ed4aceSMatthew G Knepley 297288ed4aceSMatthew G Knepley PetscFunctionBegin; 297388ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 297488ed4aceSMatthew G Knepley PetscValidPointer(sf, 2); 29750298fd71SBarry Smith ierr = PetscSFGetGraph(dm->defaultSF, &nroots, NULL, NULL, NULL);CHKERRQ(ierr); 297688ed4aceSMatthew G Knepley if (nroots < 0) { 297788ed4aceSMatthew G Knepley PetscSection section, gSection; 297888ed4aceSMatthew G Knepley 297988ed4aceSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 298031ea6d37SMatthew G Knepley if (section) { 298188ed4aceSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, &gSection);CHKERRQ(ierr); 298288ed4aceSMatthew G Knepley ierr = DMCreateDefaultSF(dm, section, gSection);CHKERRQ(ierr); 298331ea6d37SMatthew G Knepley } else { 29840298fd71SBarry Smith *sf = NULL; 298531ea6d37SMatthew G Knepley PetscFunctionReturn(0); 298631ea6d37SMatthew G Knepley } 298788ed4aceSMatthew G Knepley } 298888ed4aceSMatthew G Knepley *sf = dm->defaultSF; 298988ed4aceSMatthew G Knepley PetscFunctionReturn(0); 299088ed4aceSMatthew G Knepley } 299188ed4aceSMatthew G Knepley 299288ed4aceSMatthew G Knepley #undef __FUNCT__ 299388ed4aceSMatthew G Knepley #define __FUNCT__ "DMSetDefaultSF" 299488ed4aceSMatthew G Knepley /*@ 299588ed4aceSMatthew G Knepley DMSetDefaultSF - Set the PetscSF encoding the parallel dof overlap for the DM 299688ed4aceSMatthew G Knepley 299788ed4aceSMatthew G Knepley Input Parameters: 299888ed4aceSMatthew G Knepley + dm - The DM 299988ed4aceSMatthew G Knepley - sf - The PetscSF 300088ed4aceSMatthew G Knepley 300188ed4aceSMatthew G Knepley Level: intermediate 300288ed4aceSMatthew G Knepley 300388ed4aceSMatthew G Knepley Note: Any previous SF is destroyed 300488ed4aceSMatthew G Knepley 300588ed4aceSMatthew G Knepley .seealso: DMGetDefaultSF(), DMCreateDefaultSF() 300688ed4aceSMatthew G Knepley @*/ 30070adebc6cSBarry Smith PetscErrorCode DMSetDefaultSF(DM dm, PetscSF sf) 30080adebc6cSBarry Smith { 300988ed4aceSMatthew G Knepley PetscErrorCode ierr; 301088ed4aceSMatthew G Knepley 301188ed4aceSMatthew G Knepley PetscFunctionBegin; 301288ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 301388ed4aceSMatthew G Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 301488ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&dm->defaultSF);CHKERRQ(ierr); 301588ed4aceSMatthew G Knepley dm->defaultSF = sf; 301688ed4aceSMatthew G Knepley PetscFunctionReturn(0); 301788ed4aceSMatthew G Knepley } 301888ed4aceSMatthew G Knepley 301988ed4aceSMatthew G Knepley #undef __FUNCT__ 302088ed4aceSMatthew G Knepley #define __FUNCT__ "DMCreateDefaultSF" 302188ed4aceSMatthew G Knepley /*@C 302288ed4aceSMatthew G Knepley DMCreateDefaultSF - Create the PetscSF encoding the parallel dof overlap for the DM based upon the PetscSections 302388ed4aceSMatthew G Knepley describing the data layout. 302488ed4aceSMatthew G Knepley 302588ed4aceSMatthew G Knepley Input Parameters: 302688ed4aceSMatthew G Knepley + dm - The DM 302788ed4aceSMatthew G Knepley . localSection - PetscSection describing the local data layout 302888ed4aceSMatthew G Knepley - globalSection - PetscSection describing the global data layout 302988ed4aceSMatthew G Knepley 303088ed4aceSMatthew G Knepley Level: intermediate 303188ed4aceSMatthew G Knepley 303288ed4aceSMatthew G Knepley .seealso: DMGetDefaultSF(), DMSetDefaultSF() 303388ed4aceSMatthew G Knepley @*/ 303488ed4aceSMatthew G Knepley PetscErrorCode DMCreateDefaultSF(DM dm, PetscSection localSection, PetscSection globalSection) 303588ed4aceSMatthew G Knepley { 303682f516ccSBarry Smith MPI_Comm comm; 303788ed4aceSMatthew G Knepley PetscLayout layout; 303888ed4aceSMatthew G Knepley const PetscInt *ranges; 303988ed4aceSMatthew G Knepley PetscInt *local; 304088ed4aceSMatthew G Knepley PetscSFNode *remote; 3041ecd73843SMatthew G. Knepley PetscInt pStart, pEnd, p, nroots, nleaves = 0, l; 304288ed4aceSMatthew G Knepley PetscMPIInt size, rank; 304388ed4aceSMatthew G Knepley PetscErrorCode ierr; 304488ed4aceSMatthew G Knepley 304588ed4aceSMatthew G Knepley PetscFunctionBegin; 304682f516ccSBarry Smith ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 304788ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 304888ed4aceSMatthew G Knepley ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); 304988ed4aceSMatthew G Knepley ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); 305088ed4aceSMatthew G Knepley ierr = PetscSectionGetChart(globalSection, &pStart, &pEnd);CHKERRQ(ierr); 305188ed4aceSMatthew G Knepley ierr = PetscSectionGetConstrainedStorageSize(globalSection, &nroots);CHKERRQ(ierr); 305288ed4aceSMatthew G Knepley ierr = PetscLayoutCreate(comm, &layout);CHKERRQ(ierr); 305388ed4aceSMatthew G Knepley ierr = PetscLayoutSetBlockSize(layout, 1);CHKERRQ(ierr); 305488ed4aceSMatthew G Knepley ierr = PetscLayoutSetLocalSize(layout, nroots);CHKERRQ(ierr); 305588ed4aceSMatthew G Knepley ierr = PetscLayoutSetUp(layout);CHKERRQ(ierr); 305688ed4aceSMatthew G Knepley ierr = PetscLayoutGetRanges(layout, &ranges);CHKERRQ(ierr); 3057ecd73843SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 30586636e97aSMatthew G Knepley PetscInt gdof, gcdof; 305988ed4aceSMatthew G Knepley 30606636e97aSMatthew G Knepley ierr = PetscSectionGetDof(globalSection, p, &gdof);CHKERRQ(ierr); 30616636e97aSMatthew G Knepley ierr = PetscSectionGetConstraintDof(globalSection, p, &gcdof);CHKERRQ(ierr); 3062235fbf56SMatthew 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)); 30636636e97aSMatthew G Knepley nleaves += gdof < 0 ? -(gdof+1)-gcdof : gdof-gcdof; 306488ed4aceSMatthew G Knepley } 3065785e854fSJed Brown ierr = PetscMalloc1(nleaves, &local);CHKERRQ(ierr); 3066785e854fSJed Brown ierr = PetscMalloc1(nleaves, &remote);CHKERRQ(ierr); 306788ed4aceSMatthew G Knepley for (p = pStart, l = 0; p < pEnd; ++p) { 30681f588964SMatthew G Knepley const PetscInt *cind; 30696636e97aSMatthew G Knepley PetscInt dof, cdof, off, gdof, gcdof, goff, gsize, d, c; 307088ed4aceSMatthew G Knepley 307188ed4aceSMatthew G Knepley ierr = PetscSectionGetDof(localSection, p, &dof);CHKERRQ(ierr); 307288ed4aceSMatthew G Knepley ierr = PetscSectionGetOffset(localSection, p, &off);CHKERRQ(ierr); 307388ed4aceSMatthew G Knepley ierr = PetscSectionGetConstraintDof(localSection, p, &cdof);CHKERRQ(ierr); 307488ed4aceSMatthew G Knepley ierr = PetscSectionGetConstraintIndices(localSection, p, &cind);CHKERRQ(ierr); 307588ed4aceSMatthew G Knepley ierr = PetscSectionGetDof(globalSection, p, &gdof);CHKERRQ(ierr); 30766636e97aSMatthew G Knepley ierr = PetscSectionGetConstraintDof(globalSection, p, &gcdof);CHKERRQ(ierr); 307788ed4aceSMatthew G Knepley ierr = PetscSectionGetOffset(globalSection, p, &goff);CHKERRQ(ierr); 30786636e97aSMatthew G Knepley if (!gdof) continue; /* Censored point */ 30796636e97aSMatthew G Knepley gsize = gdof < 0 ? -(gdof+1)-gcdof : gdof-gcdof; 30806636e97aSMatthew G Knepley if (gsize != dof-cdof) { 3081057b4bcdSMatthew 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); 30826636e97aSMatthew G Knepley cdof = 0; /* Ignore constraints */ 30836636e97aSMatthew G Knepley } 308488ed4aceSMatthew G Knepley for (d = 0, c = 0; d < dof; ++d) { 308588ed4aceSMatthew G Knepley if ((c < cdof) && (cind[c] == d)) {++c; continue;} 308688ed4aceSMatthew G Knepley local[l+d-c] = off+d; 308788ed4aceSMatthew G Knepley } 308888ed4aceSMatthew G Knepley if (gdof < 0) { 30896636e97aSMatthew G Knepley for (d = 0; d < gsize; ++d, ++l) { 309088ed4aceSMatthew G Knepley PetscInt offset = -(goff+1) + d, r; 309188ed4aceSMatthew G Knepley 309205376888SMatthew G. Knepley ierr = PetscFindInt(offset,size+1,ranges,&r);CHKERRQ(ierr); 309331d3f06eSJed Brown if (r < 0) r = -(r+2); 309405376888SMatthew 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); 309588ed4aceSMatthew G Knepley remote[l].rank = r; 309688ed4aceSMatthew G Knepley remote[l].index = offset - ranges[r]; 309788ed4aceSMatthew G Knepley } 309888ed4aceSMatthew G Knepley } else { 30996636e97aSMatthew G Knepley for (d = 0; d < gsize; ++d, ++l) { 310088ed4aceSMatthew G Knepley remote[l].rank = rank; 310188ed4aceSMatthew G Knepley remote[l].index = goff+d - ranges[rank]; 310288ed4aceSMatthew G Knepley } 310388ed4aceSMatthew G Knepley } 310488ed4aceSMatthew G Knepley } 31056636e97aSMatthew G Knepley if (l != nleaves) SETERRQ2(comm, PETSC_ERR_PLIB, "Iteration error, l %d != nleaves %d", l, nleaves); 310688ed4aceSMatthew G Knepley ierr = PetscLayoutDestroy(&layout);CHKERRQ(ierr); 310788ed4aceSMatthew G Knepley ierr = PetscSFSetGraph(dm->defaultSF, nroots, nleaves, local, PETSC_OWN_POINTER, remote, PETSC_OWN_POINTER);CHKERRQ(ierr); 310888ed4aceSMatthew G Knepley PetscFunctionReturn(0); 310988ed4aceSMatthew G Knepley } 3110af122d2aSMatthew G Knepley 3111af122d2aSMatthew G Knepley #undef __FUNCT__ 3112b21d0597SMatthew G Knepley #define __FUNCT__ "DMGetPointSF" 3113b21d0597SMatthew G Knepley /*@ 3114b21d0597SMatthew G Knepley DMGetPointSF - Get the PetscSF encoding the parallel section point overlap for the DM. 3115b21d0597SMatthew G Knepley 3116b21d0597SMatthew G Knepley Input Parameter: 3117b21d0597SMatthew G Knepley . dm - The DM 3118b21d0597SMatthew G Knepley 3119b21d0597SMatthew G Knepley Output Parameter: 3120b21d0597SMatthew G Knepley . sf - The PetscSF 3121b21d0597SMatthew G Knepley 3122b21d0597SMatthew G Knepley Level: intermediate 3123b21d0597SMatthew G Knepley 3124b21d0597SMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSF. 3125b21d0597SMatthew G Knepley 3126057b4bcdSMatthew G Knepley .seealso: DMSetPointSF(), DMGetDefaultSF(), DMSetDefaultSF(), DMCreateDefaultSF() 3127b21d0597SMatthew G Knepley @*/ 31280adebc6cSBarry Smith PetscErrorCode DMGetPointSF(DM dm, PetscSF *sf) 31290adebc6cSBarry Smith { 3130b21d0597SMatthew G Knepley PetscFunctionBegin; 3131b21d0597SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3132b21d0597SMatthew G Knepley PetscValidPointer(sf, 2); 3133b21d0597SMatthew G Knepley *sf = dm->sf; 3134b21d0597SMatthew G Knepley PetscFunctionReturn(0); 3135b21d0597SMatthew G Knepley } 3136b21d0597SMatthew G Knepley 3137b21d0597SMatthew G Knepley #undef __FUNCT__ 3138057b4bcdSMatthew G Knepley #define __FUNCT__ "DMSetPointSF" 3139057b4bcdSMatthew G Knepley /*@ 3140057b4bcdSMatthew G Knepley DMSetPointSF - Set the PetscSF encoding the parallel section point overlap for the DM. 3141057b4bcdSMatthew G Knepley 3142057b4bcdSMatthew G Knepley Input Parameters: 3143057b4bcdSMatthew G Knepley + dm - The DM 3144057b4bcdSMatthew G Knepley - sf - The PetscSF 3145057b4bcdSMatthew G Knepley 3146057b4bcdSMatthew G Knepley Level: intermediate 3147057b4bcdSMatthew G Knepley 3148057b4bcdSMatthew G Knepley .seealso: DMGetPointSF(), DMGetDefaultSF(), DMSetDefaultSF(), DMCreateDefaultSF() 3149057b4bcdSMatthew G Knepley @*/ 31500adebc6cSBarry Smith PetscErrorCode DMSetPointSF(DM dm, PetscSF sf) 31510adebc6cSBarry Smith { 3152057b4bcdSMatthew G Knepley PetscErrorCode ierr; 3153057b4bcdSMatthew G Knepley 3154057b4bcdSMatthew G Knepley PetscFunctionBegin; 3155057b4bcdSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3156057b4bcdSMatthew G Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 1); 3157057b4bcdSMatthew G Knepley ierr = PetscSFDestroy(&dm->sf);CHKERRQ(ierr); 3158057b4bcdSMatthew G Knepley ierr = PetscObjectReference((PetscObject) sf);CHKERRQ(ierr); 3159057b4bcdSMatthew G Knepley dm->sf = sf; 3160057b4bcdSMatthew G Knepley PetscFunctionReturn(0); 3161057b4bcdSMatthew G Knepley } 3162057b4bcdSMatthew G Knepley 3163057b4bcdSMatthew G Knepley #undef __FUNCT__ 31642764a2aaSMatthew G. Knepley #define __FUNCT__ "DMGetDS" 31652764a2aaSMatthew G. Knepley /*@ 31662764a2aaSMatthew G. Knepley DMGetDS - Get the PetscDS 31672764a2aaSMatthew G. Knepley 31682764a2aaSMatthew G. Knepley Input Parameter: 31692764a2aaSMatthew G. Knepley . dm - The DM 31702764a2aaSMatthew G. Knepley 31712764a2aaSMatthew G. Knepley Output Parameter: 31722764a2aaSMatthew G. Knepley . prob - The PetscDS 31732764a2aaSMatthew G. Knepley 31742764a2aaSMatthew G. Knepley Level: developer 31752764a2aaSMatthew G. Knepley 31762764a2aaSMatthew G. Knepley .seealso: DMSetDS() 31772764a2aaSMatthew G. Knepley @*/ 31782764a2aaSMatthew G. Knepley PetscErrorCode DMGetDS(DM dm, PetscDS *prob) 3179af122d2aSMatthew G Knepley { 3180af122d2aSMatthew G Knepley PetscFunctionBegin; 3181af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 31820f21e855SMatthew G. Knepley PetscValidPointer(prob, 2); 31830f21e855SMatthew G. Knepley *prob = dm->prob; 31840f21e855SMatthew G. Knepley PetscFunctionReturn(0); 31850f21e855SMatthew G. Knepley } 31860f21e855SMatthew G. Knepley 31870f21e855SMatthew G. Knepley #undef __FUNCT__ 31882764a2aaSMatthew G. Knepley #define __FUNCT__ "DMSetDS" 31892764a2aaSMatthew G. Knepley /*@ 31902764a2aaSMatthew G. Knepley DMSetDS - Set the PetscDS 31912764a2aaSMatthew G. Knepley 31922764a2aaSMatthew G. Knepley Input Parameters: 31932764a2aaSMatthew G. Knepley + dm - The DM 31942764a2aaSMatthew G. Knepley - prob - The PetscDS 31952764a2aaSMatthew G. Knepley 31962764a2aaSMatthew G. Knepley Level: developer 31972764a2aaSMatthew G. Knepley 31982764a2aaSMatthew G. Knepley .seealso: DMGetDS() 31992764a2aaSMatthew G. Knepley @*/ 32002764a2aaSMatthew G. Knepley PetscErrorCode DMSetDS(DM dm, PetscDS prob) 32010f21e855SMatthew G. Knepley { 32020f21e855SMatthew G. Knepley PetscErrorCode ierr; 32030f21e855SMatthew G. Knepley 32040f21e855SMatthew G. Knepley PetscFunctionBegin; 32050f21e855SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 32062764a2aaSMatthew G. Knepley PetscValidHeaderSpecific(prob, PETSCDS_CLASSID, 2); 32072764a2aaSMatthew G. Knepley ierr = PetscDSDestroy(&dm->prob);CHKERRQ(ierr); 32080f21e855SMatthew G. Knepley dm->prob = prob; 32090f21e855SMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm->prob);CHKERRQ(ierr); 32100f21e855SMatthew G. Knepley PetscFunctionReturn(0); 32110f21e855SMatthew G. Knepley } 32120f21e855SMatthew G. Knepley 32130f21e855SMatthew G. Knepley #undef __FUNCT__ 32140f21e855SMatthew G. Knepley #define __FUNCT__ "DMGetNumFields" 32150f21e855SMatthew G. Knepley PetscErrorCode DMGetNumFields(DM dm, PetscInt *numFields) 32160f21e855SMatthew G. Knepley { 32170f21e855SMatthew G. Knepley PetscErrorCode ierr; 32180f21e855SMatthew G. Knepley 32190f21e855SMatthew G. Knepley PetscFunctionBegin; 32200f21e855SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 32212764a2aaSMatthew G. Knepley ierr = PetscDSGetNumFields(dm->prob, numFields);CHKERRQ(ierr); 3222af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3223af122d2aSMatthew G Knepley } 3224af122d2aSMatthew G Knepley 3225af122d2aSMatthew G Knepley #undef __FUNCT__ 3226af122d2aSMatthew G Knepley #define __FUNCT__ "DMSetNumFields" 3227af122d2aSMatthew G Knepley PetscErrorCode DMSetNumFields(DM dm, PetscInt numFields) 3228af122d2aSMatthew G Knepley { 32290f21e855SMatthew G. Knepley PetscInt Nf, f; 3230af122d2aSMatthew G Knepley PetscErrorCode ierr; 3231af122d2aSMatthew G Knepley 3232af122d2aSMatthew G Knepley PetscFunctionBegin; 3233af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 32342764a2aaSMatthew G. Knepley ierr = PetscDSGetNumFields(dm->prob, &Nf);CHKERRQ(ierr); 32350f21e855SMatthew G. Knepley for (f = Nf; f < numFields; ++f) { 32360f21e855SMatthew G. Knepley PetscContainer obj; 32370f21e855SMatthew G. Knepley 32380f21e855SMatthew G. Knepley ierr = PetscContainerCreate(PetscObjectComm((PetscObject) dm), &obj);CHKERRQ(ierr); 32392764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(dm->prob, f, (PetscObject) obj);CHKERRQ(ierr); 32400f21e855SMatthew G. Knepley ierr = PetscContainerDestroy(&obj);CHKERRQ(ierr); 3241af122d2aSMatthew G Knepley } 3242af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3243af122d2aSMatthew G Knepley } 3244af122d2aSMatthew G Knepley 3245af122d2aSMatthew G Knepley #undef __FUNCT__ 3246af122d2aSMatthew G Knepley #define __FUNCT__ "DMGetField" 3247c1929be8SMatthew G. Knepley /*@ 3248c1929be8SMatthew G. Knepley DMGetField - Return the discretization object for a given DM field 3249c1929be8SMatthew G. Knepley 3250c1929be8SMatthew G. Knepley Not collective 3251c1929be8SMatthew G. Knepley 3252c1929be8SMatthew G. Knepley Input Parameters: 3253c1929be8SMatthew G. Knepley + dm - The DM 3254c1929be8SMatthew G. Knepley - f - The field number 3255c1929be8SMatthew G. Knepley 3256c1929be8SMatthew G. Knepley Output Parameter: 3257c1929be8SMatthew G. Knepley . field - The discretization object 3258c1929be8SMatthew G. Knepley 3259c1929be8SMatthew G. Knepley Level: developer 3260c1929be8SMatthew G. Knepley 3261c1929be8SMatthew G. Knepley .seealso: DMSetField() 3262c1929be8SMatthew G. Knepley @*/ 3263af122d2aSMatthew G Knepley PetscErrorCode DMGetField(DM dm, PetscInt f, PetscObject *field) 3264af122d2aSMatthew G Knepley { 32650f21e855SMatthew G. Knepley PetscErrorCode ierr; 32660f21e855SMatthew G. Knepley 3267af122d2aSMatthew G Knepley PetscFunctionBegin; 3268af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 32692764a2aaSMatthew G. Knepley ierr = PetscDSGetDiscretization(dm->prob, f, field);CHKERRQ(ierr); 3270decb47aaSMatthew G. Knepley PetscFunctionReturn(0); 3271decb47aaSMatthew G. Knepley } 3272decb47aaSMatthew G. Knepley 3273decb47aaSMatthew G. Knepley #undef __FUNCT__ 3274decb47aaSMatthew G. Knepley #define __FUNCT__ "DMSetField" 3275c1929be8SMatthew G. Knepley /*@ 3276c1929be8SMatthew G. Knepley DMSetField - Set the discretization object for a given DM field 3277c1929be8SMatthew G. Knepley 3278c1929be8SMatthew G. Knepley Logically collective on DM 3279c1929be8SMatthew G. Knepley 3280c1929be8SMatthew G. Knepley Input Parameters: 3281c1929be8SMatthew G. Knepley + dm - The DM 3282c1929be8SMatthew G. Knepley . f - The field number 3283c1929be8SMatthew G. Knepley - field - The discretization object 3284c1929be8SMatthew G. Knepley 3285c1929be8SMatthew G. Knepley Level: developer 3286c1929be8SMatthew G. Knepley 3287c1929be8SMatthew G. Knepley .seealso: DMGetField() 3288c1929be8SMatthew G. Knepley @*/ 3289decb47aaSMatthew G. Knepley PetscErrorCode DMSetField(DM dm, PetscInt f, PetscObject field) 3290decb47aaSMatthew G. Knepley { 3291decb47aaSMatthew G. Knepley PetscErrorCode ierr; 3292decb47aaSMatthew G. Knepley 3293decb47aaSMatthew G. Knepley PetscFunctionBegin; 3294decb47aaSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 32952764a2aaSMatthew G. Knepley ierr = PetscDSSetDiscretization(dm->prob, f, field);CHKERRQ(ierr); 3296af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3297af122d2aSMatthew G Knepley } 32986636e97aSMatthew G Knepley 32996636e97aSMatthew G Knepley #undef __FUNCT__ 3300b64e0483SPeter Brune #define __FUNCT__ "DMRestrictHook_Coordinates" 3301b64e0483SPeter Brune PetscErrorCode DMRestrictHook_Coordinates(DM dm,DM dmc,void *ctx) 3302b64e0483SPeter Brune { 3303b64e0483SPeter Brune DM dm_coord,dmc_coord; 3304b64e0483SPeter Brune PetscErrorCode ierr; 3305b64e0483SPeter Brune Vec coords,ccoords; 3306b64e0483SPeter Brune VecScatter scat; 3307b64e0483SPeter Brune PetscFunctionBegin; 3308b64e0483SPeter Brune ierr = DMGetCoordinateDM(dm,&dm_coord);CHKERRQ(ierr); 3309b64e0483SPeter Brune ierr = DMGetCoordinateDM(dmc,&dmc_coord);CHKERRQ(ierr); 3310b64e0483SPeter Brune ierr = DMGetCoordinates(dm,&coords);CHKERRQ(ierr); 3311b64e0483SPeter Brune ierr = DMGetCoordinates(dmc,&ccoords);CHKERRQ(ierr); 3312b64e0483SPeter Brune if (coords && !ccoords) { 3313b64e0483SPeter Brune ierr = DMCreateGlobalVector(dmc_coord,&ccoords);CHKERRQ(ierr); 3314b64e0483SPeter Brune ierr = DMCreateInjection(dmc_coord,dm_coord,&scat);CHKERRQ(ierr); 3315b64e0483SPeter Brune ierr = VecScatterBegin(scat,coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 3316b64e0483SPeter Brune ierr = VecScatterEnd(scat,coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 3317b64e0483SPeter Brune ierr = DMSetCoordinates(dmc,ccoords);CHKERRQ(ierr); 3318b64e0483SPeter Brune ierr = VecScatterDestroy(&scat);CHKERRQ(ierr); 3319b64e0483SPeter Brune ierr = VecDestroy(&ccoords);CHKERRQ(ierr); 3320b64e0483SPeter Brune } 3321b64e0483SPeter Brune PetscFunctionReturn(0); 3322b64e0483SPeter Brune } 3323b64e0483SPeter Brune 3324b64e0483SPeter Brune #undef __FUNCT__ 332503dadc2fSPeter Brune #define __FUNCT__ "DMSubDomainHook_Coordinates" 332603dadc2fSPeter Brune static PetscErrorCode DMSubDomainHook_Coordinates(DM dm,DM subdm,void *ctx) 332703dadc2fSPeter Brune { 332803dadc2fSPeter Brune DM dm_coord,subdm_coord; 332903dadc2fSPeter Brune PetscErrorCode ierr; 333003dadc2fSPeter Brune Vec coords,ccoords,clcoords; 333103dadc2fSPeter Brune VecScatter *scat_i,*scat_g; 333203dadc2fSPeter Brune PetscFunctionBegin; 333303dadc2fSPeter Brune ierr = DMGetCoordinateDM(dm,&dm_coord);CHKERRQ(ierr); 333403dadc2fSPeter Brune ierr = DMGetCoordinateDM(subdm,&subdm_coord);CHKERRQ(ierr); 333503dadc2fSPeter Brune ierr = DMGetCoordinates(dm,&coords);CHKERRQ(ierr); 333603dadc2fSPeter Brune ierr = DMGetCoordinates(subdm,&ccoords);CHKERRQ(ierr); 333703dadc2fSPeter Brune if (coords && !ccoords) { 333803dadc2fSPeter Brune ierr = DMCreateGlobalVector(subdm_coord,&ccoords);CHKERRQ(ierr); 333903dadc2fSPeter Brune ierr = DMCreateLocalVector(subdm_coord,&clcoords);CHKERRQ(ierr); 334003dadc2fSPeter Brune ierr = DMCreateDomainDecompositionScatters(dm_coord,1,&subdm_coord,NULL,&scat_i,&scat_g);CHKERRQ(ierr); 334103dadc2fSPeter Brune ierr = VecScatterBegin(scat_i[0],coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 334203dadc2fSPeter Brune ierr = VecScatterBegin(scat_g[0],coords,clcoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 334303dadc2fSPeter Brune ierr = VecScatterEnd(scat_i[0],coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 334403dadc2fSPeter Brune ierr = VecScatterEnd(scat_g[0],coords,clcoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 334503dadc2fSPeter Brune ierr = DMSetCoordinates(subdm,ccoords);CHKERRQ(ierr); 334603dadc2fSPeter Brune ierr = DMSetCoordinatesLocal(subdm,clcoords);CHKERRQ(ierr); 334703dadc2fSPeter Brune ierr = VecScatterDestroy(&scat_i[0]);CHKERRQ(ierr); 334803dadc2fSPeter Brune ierr = VecScatterDestroy(&scat_g[0]);CHKERRQ(ierr); 334903dadc2fSPeter Brune ierr = VecDestroy(&ccoords);CHKERRQ(ierr); 335003dadc2fSPeter Brune ierr = VecDestroy(&clcoords);CHKERRQ(ierr); 335103dadc2fSPeter Brune ierr = PetscFree(scat_i);CHKERRQ(ierr); 335203dadc2fSPeter Brune ierr = PetscFree(scat_g);CHKERRQ(ierr); 335303dadc2fSPeter Brune } 335403dadc2fSPeter Brune PetscFunctionReturn(0); 335503dadc2fSPeter Brune } 335603dadc2fSPeter Brune 335703dadc2fSPeter Brune #undef __FUNCT__ 3358c73cfb54SMatthew G. Knepley #define __FUNCT__ "DMGetDimension" 3359c73cfb54SMatthew G. Knepley /*@ 3360c73cfb54SMatthew G. Knepley DMGetDimension - Return the topological dimension of the DM 3361c73cfb54SMatthew G. Knepley 3362c73cfb54SMatthew G. Knepley Not collective 3363c73cfb54SMatthew G. Knepley 3364c73cfb54SMatthew G. Knepley Input Parameter: 3365c73cfb54SMatthew G. Knepley . dm - The DM 3366c73cfb54SMatthew G. Knepley 3367c73cfb54SMatthew G. Knepley Output Parameter: 3368c73cfb54SMatthew G. Knepley . dim - The topological dimension 3369c73cfb54SMatthew G. Knepley 3370c73cfb54SMatthew G. Knepley Level: beginner 3371c73cfb54SMatthew G. Knepley 3372c73cfb54SMatthew G. Knepley .seealso: DMSetDimension(), DMCreate() 3373c73cfb54SMatthew G. Knepley @*/ 3374c73cfb54SMatthew G. Knepley PetscErrorCode DMGetDimension(DM dm, PetscInt *dim) 3375c73cfb54SMatthew G. Knepley { 3376c73cfb54SMatthew G. Knepley PetscFunctionBegin; 3377c73cfb54SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3378c73cfb54SMatthew G. Knepley PetscValidPointer(dim, 2); 3379c73cfb54SMatthew G. Knepley *dim = dm->dim; 3380c73cfb54SMatthew G. Knepley PetscFunctionReturn(0); 3381c73cfb54SMatthew G. Knepley } 3382c73cfb54SMatthew G. Knepley 3383c73cfb54SMatthew G. Knepley #undef __FUNCT__ 3384c73cfb54SMatthew G. Knepley #define __FUNCT__ "DMSetDimension" 3385c73cfb54SMatthew G. Knepley /*@ 3386c73cfb54SMatthew G. Knepley DMSetDimension - Set the topological dimension of the DM 3387c73cfb54SMatthew G. Knepley 3388c73cfb54SMatthew G. Knepley Collective on dm 3389c73cfb54SMatthew G. Knepley 3390c73cfb54SMatthew G. Knepley Input Parameters: 3391c73cfb54SMatthew G. Knepley + dm - The DM 3392c73cfb54SMatthew G. Knepley - dim - The topological dimension 3393c73cfb54SMatthew G. Knepley 3394c73cfb54SMatthew G. Knepley Level: beginner 3395c73cfb54SMatthew G. Knepley 3396c73cfb54SMatthew G. Knepley .seealso: DMGetDimension(), DMCreate() 3397c73cfb54SMatthew G. Knepley @*/ 3398c73cfb54SMatthew G. Knepley PetscErrorCode DMSetDimension(DM dm, PetscInt dim) 3399c73cfb54SMatthew G. Knepley { 3400c73cfb54SMatthew G. Knepley PetscFunctionBegin; 3401c73cfb54SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3402c73cfb54SMatthew G. Knepley PetscValidLogicalCollectiveInt(dm, dim, 2); 3403c73cfb54SMatthew G. Knepley dm->dim = dim; 3404c73cfb54SMatthew G. Knepley PetscFunctionReturn(0); 3405c73cfb54SMatthew G. Knepley } 3406c73cfb54SMatthew G. Knepley 3407793f3fe5SMatthew G. Knepley #undef __FUNCT__ 3408793f3fe5SMatthew G. Knepley #define __FUNCT__ "DMGetDimPoints" 3409793f3fe5SMatthew G. Knepley /*@ 3410793f3fe5SMatthew G. Knepley DMGetDimPoints - Get the half-open interval for all points of a given dimension 3411793f3fe5SMatthew G. Knepley 3412793f3fe5SMatthew G. Knepley Collective on DM 3413793f3fe5SMatthew G. Knepley 3414793f3fe5SMatthew G. Knepley Input Parameters: 3415793f3fe5SMatthew G. Knepley + dm - the DM 3416793f3fe5SMatthew G. Knepley - dim - the dimension 3417793f3fe5SMatthew G. Knepley 3418793f3fe5SMatthew G. Knepley Output Parameters: 3419793f3fe5SMatthew G. Knepley + pStart - The first point of the given dimension 3420793f3fe5SMatthew G. Knepley . pEnd - The first point following points of the given dimension 3421793f3fe5SMatthew G. Knepley 3422793f3fe5SMatthew G. Knepley Note: 3423793f3fe5SMatthew G. Knepley The points are vertices in the Hasse diagram encoding the topology. This is explained in 3424793f3fe5SMatthew G. Knepley http://arxiv.org/abs/0908.4427. If not points exist of this dimension in the storage scheme, 3425793f3fe5SMatthew G. Knepley then the interval is empty. 3426793f3fe5SMatthew G. Knepley 3427793f3fe5SMatthew G. Knepley Level: intermediate 3428793f3fe5SMatthew G. Knepley 3429793f3fe5SMatthew G. Knepley .keywords: point, Hasse Diagram, dimension 3430793f3fe5SMatthew G. Knepley .seealso: DMPLEX, DMPlexGetDepthStratum(), DMPlexGetHeightStratum() 3431793f3fe5SMatthew G. Knepley @*/ 3432793f3fe5SMatthew G. Knepley PetscErrorCode DMGetDimPoints(DM dm, PetscInt dim, PetscInt *pStart, PetscInt *pEnd) 3433793f3fe5SMatthew G. Knepley { 3434793f3fe5SMatthew G. Knepley PetscInt d; 3435793f3fe5SMatthew G. Knepley PetscErrorCode ierr; 3436793f3fe5SMatthew G. Knepley 3437793f3fe5SMatthew G. Knepley PetscFunctionBegin; 3438793f3fe5SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3439793f3fe5SMatthew G. Knepley ierr = DMGetDimension(dm, &d);CHKERRQ(ierr); 3440793f3fe5SMatthew G. Knepley if ((dim < 0) || (dim > d)) SETERRQ2(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid dimension %d 1", dim, d); 3441793f3fe5SMatthew G. Knepley ierr = (*dm->ops->getdimpoints)(dm, dim, pStart, pEnd);CHKERRQ(ierr); 3442793f3fe5SMatthew G. Knepley PetscFunctionReturn(0); 3443793f3fe5SMatthew G. Knepley } 3444793f3fe5SMatthew G. Knepley 3445793f3fe5SMatthew G. Knepley #undef __FUNCT__ 34466636e97aSMatthew G Knepley #define __FUNCT__ "DMSetCoordinates" 34476636e97aSMatthew G Knepley /*@ 34486636e97aSMatthew G Knepley DMSetCoordinates - Sets into the DM a global vector that holds the coordinates 34496636e97aSMatthew G Knepley 34506636e97aSMatthew G Knepley Collective on DM 34516636e97aSMatthew G Knepley 34526636e97aSMatthew G Knepley Input Parameters: 34536636e97aSMatthew G Knepley + dm - the DM 34546636e97aSMatthew G Knepley - c - coordinate vector 34556636e97aSMatthew G Knepley 34566636e97aSMatthew G Knepley Note: 34576636e97aSMatthew G Knepley The coordinates do include those for ghost points, which are in the local vector 34586636e97aSMatthew G Knepley 34596636e97aSMatthew G Knepley Level: intermediate 34606636e97aSMatthew G Knepley 34616636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 34626636e97aSMatthew G Knepley .seealso: DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLoca(), DMGetCoordinateDM() 34636636e97aSMatthew G Knepley @*/ 34646636e97aSMatthew G Knepley PetscErrorCode DMSetCoordinates(DM dm, Vec c) 34656636e97aSMatthew G Knepley { 34666636e97aSMatthew G Knepley PetscErrorCode ierr; 34676636e97aSMatthew G Knepley 34686636e97aSMatthew G Knepley PetscFunctionBegin; 34696636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 34706636e97aSMatthew G Knepley PetscValidHeaderSpecific(c,VEC_CLASSID,2); 34716636e97aSMatthew G Knepley ierr = PetscObjectReference((PetscObject) c);CHKERRQ(ierr); 34726636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinates);CHKERRQ(ierr); 34736636e97aSMatthew G Knepley dm->coordinates = c; 34746636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinatesLocal);CHKERRQ(ierr); 3475b64e0483SPeter Brune ierr = DMCoarsenHookAdd(dm,DMRestrictHook_Coordinates,NULL,NULL);CHKERRQ(ierr); 347603dadc2fSPeter Brune ierr = DMSubDomainHookAdd(dm,DMSubDomainHook_Coordinates,NULL,NULL);CHKERRQ(ierr); 34776636e97aSMatthew G Knepley PetscFunctionReturn(0); 34786636e97aSMatthew G Knepley } 34796636e97aSMatthew G Knepley 34806636e97aSMatthew G Knepley #undef __FUNCT__ 34816636e97aSMatthew G Knepley #define __FUNCT__ "DMSetCoordinatesLocal" 34826636e97aSMatthew G Knepley /*@ 34836636e97aSMatthew G Knepley DMSetCoordinatesLocal - Sets into the DM a local vector that holds the coordinates 34846636e97aSMatthew G Knepley 34856636e97aSMatthew G Knepley Collective on DM 34866636e97aSMatthew G Knepley 34876636e97aSMatthew G Knepley Input Parameters: 34886636e97aSMatthew G Knepley + dm - the DM 34896636e97aSMatthew G Knepley - c - coordinate vector 34906636e97aSMatthew G Knepley 34916636e97aSMatthew G Knepley Note: 34926636e97aSMatthew G Knepley The coordinates of ghost points can be set using DMSetCoordinates() 34936636e97aSMatthew G Knepley followed by DMGetCoordinatesLocal(). This is intended to enable the 34946636e97aSMatthew G Knepley setting of ghost coordinates outside of the domain. 34956636e97aSMatthew G Knepley 34966636e97aSMatthew G Knepley Level: intermediate 34976636e97aSMatthew G Knepley 34986636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 34996636e97aSMatthew G Knepley .seealso: DMGetCoordinatesLocal(), DMSetCoordinates(), DMGetCoordinates(), DMGetCoordinateDM() 35006636e97aSMatthew G Knepley @*/ 35016636e97aSMatthew G Knepley PetscErrorCode DMSetCoordinatesLocal(DM dm, Vec c) 35026636e97aSMatthew G Knepley { 35036636e97aSMatthew G Knepley PetscErrorCode ierr; 35046636e97aSMatthew G Knepley 35056636e97aSMatthew G Knepley PetscFunctionBegin; 35066636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 35076636e97aSMatthew G Knepley PetscValidHeaderSpecific(c,VEC_CLASSID,2); 35086636e97aSMatthew G Knepley ierr = PetscObjectReference((PetscObject) c);CHKERRQ(ierr); 35096636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinatesLocal);CHKERRQ(ierr); 35108865f1eaSKarl Rupp 35116636e97aSMatthew G Knepley dm->coordinatesLocal = c; 35128865f1eaSKarl Rupp 35136636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinates);CHKERRQ(ierr); 35146636e97aSMatthew G Knepley PetscFunctionReturn(0); 35156636e97aSMatthew G Knepley } 35166636e97aSMatthew G Knepley 35176636e97aSMatthew G Knepley #undef __FUNCT__ 35186636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinates" 35196636e97aSMatthew G Knepley /*@ 35206636e97aSMatthew G Knepley DMGetCoordinates - Gets a global vector with the coordinates associated with the DM. 35216636e97aSMatthew G Knepley 35226636e97aSMatthew G Knepley Not Collective 35236636e97aSMatthew G Knepley 35246636e97aSMatthew G Knepley Input Parameter: 35256636e97aSMatthew G Knepley . dm - the DM 35266636e97aSMatthew G Knepley 35276636e97aSMatthew G Knepley Output Parameter: 35286636e97aSMatthew G Knepley . c - global coordinate vector 35296636e97aSMatthew G Knepley 35306636e97aSMatthew G Knepley Note: 35316636e97aSMatthew G Knepley This is a borrowed reference, so the user should NOT destroy this vector 35326636e97aSMatthew G Knepley 35336636e97aSMatthew G Knepley Each process has only the local coordinates (does NOT have the ghost coordinates). 35346636e97aSMatthew G Knepley 35356636e97aSMatthew G Knepley For DMDA, in two and three dimensions coordinates are interlaced (x_0,y_0,x_1,y_1,...) 35366636e97aSMatthew G Knepley and (x_0,y_0,z_0,x_1,y_1,z_1...) 35376636e97aSMatthew G Knepley 35386636e97aSMatthew G Knepley Level: intermediate 35396636e97aSMatthew G Knepley 35406636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 35416636e97aSMatthew G Knepley .seealso: DMSetCoordinates(), DMGetCoordinatesLocal(), DMGetCoordinateDM() 35426636e97aSMatthew G Knepley @*/ 35436636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinates(DM dm, Vec *c) 35446636e97aSMatthew G Knepley { 35456636e97aSMatthew G Knepley PetscErrorCode ierr; 35466636e97aSMatthew G Knepley 35476636e97aSMatthew G Knepley PetscFunctionBegin; 35486636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 35496636e97aSMatthew G Knepley PetscValidPointer(c,2); 35501f588964SMatthew G Knepley if (!dm->coordinates && dm->coordinatesLocal) { 35510298fd71SBarry Smith DM cdm = NULL; 35526636e97aSMatthew G Knepley 35536636e97aSMatthew G Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 35546636e97aSMatthew G Knepley ierr = DMCreateGlobalVector(cdm, &dm->coordinates);CHKERRQ(ierr); 35556636e97aSMatthew G Knepley ierr = PetscObjectSetName((PetscObject) dm->coordinates, "coordinates");CHKERRQ(ierr); 35566636e97aSMatthew G Knepley ierr = DMLocalToGlobalBegin(cdm, dm->coordinatesLocal, INSERT_VALUES, dm->coordinates);CHKERRQ(ierr); 35576636e97aSMatthew G Knepley ierr = DMLocalToGlobalEnd(cdm, dm->coordinatesLocal, INSERT_VALUES, dm->coordinates);CHKERRQ(ierr); 35586636e97aSMatthew G Knepley } 35596636e97aSMatthew G Knepley *c = dm->coordinates; 35606636e97aSMatthew G Knepley PetscFunctionReturn(0); 35616636e97aSMatthew G Knepley } 35626636e97aSMatthew G Knepley 35636636e97aSMatthew G Knepley #undef __FUNCT__ 35646636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinatesLocal" 35656636e97aSMatthew G Knepley /*@ 35666636e97aSMatthew G Knepley DMGetCoordinatesLocal - Gets a local vector with the coordinates associated with the DM. 35676636e97aSMatthew G Knepley 35686636e97aSMatthew G Knepley Collective on DM 35696636e97aSMatthew G Knepley 35706636e97aSMatthew G Knepley Input Parameter: 35716636e97aSMatthew G Knepley . dm - the DM 35726636e97aSMatthew G Knepley 35736636e97aSMatthew G Knepley Output Parameter: 35746636e97aSMatthew G Knepley . c - coordinate vector 35756636e97aSMatthew G Knepley 35766636e97aSMatthew G Knepley Note: 35776636e97aSMatthew G Knepley This is a borrowed reference, so the user should NOT destroy this vector 35786636e97aSMatthew G Knepley 35796636e97aSMatthew G Knepley Each process has the local and ghost coordinates 35806636e97aSMatthew G Knepley 35816636e97aSMatthew G Knepley For DMDA, in two and three dimensions coordinates are interlaced (x_0,y_0,x_1,y_1,...) 35826636e97aSMatthew G Knepley and (x_0,y_0,z_0,x_1,y_1,z_1...) 35836636e97aSMatthew G Knepley 35846636e97aSMatthew G Knepley Level: intermediate 35856636e97aSMatthew G Knepley 35866636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 35876636e97aSMatthew G Knepley .seealso: DMSetCoordinatesLocal(), DMGetCoordinates(), DMSetCoordinates(), DMGetCoordinateDM() 35886636e97aSMatthew G Knepley @*/ 35896636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinatesLocal(DM dm, Vec *c) 35906636e97aSMatthew G Knepley { 35916636e97aSMatthew G Knepley PetscErrorCode ierr; 35926636e97aSMatthew G Knepley 35936636e97aSMatthew G Knepley PetscFunctionBegin; 35946636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 35956636e97aSMatthew G Knepley PetscValidPointer(c,2); 35961f588964SMatthew G Knepley if (!dm->coordinatesLocal && dm->coordinates) { 35970298fd71SBarry Smith DM cdm = NULL; 35986636e97aSMatthew G Knepley 35996636e97aSMatthew G Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 36006636e97aSMatthew G Knepley ierr = DMCreateLocalVector(cdm, &dm->coordinatesLocal);CHKERRQ(ierr); 36016636e97aSMatthew G Knepley ierr = PetscObjectSetName((PetscObject) dm->coordinatesLocal, "coordinates");CHKERRQ(ierr); 36026636e97aSMatthew G Knepley ierr = DMGlobalToLocalBegin(cdm, dm->coordinates, INSERT_VALUES, dm->coordinatesLocal);CHKERRQ(ierr); 36036636e97aSMatthew G Knepley ierr = DMGlobalToLocalEnd(cdm, dm->coordinates, INSERT_VALUES, dm->coordinatesLocal);CHKERRQ(ierr); 36046636e97aSMatthew G Knepley } 36056636e97aSMatthew G Knepley *c = dm->coordinatesLocal; 36066636e97aSMatthew G Knepley PetscFunctionReturn(0); 36076636e97aSMatthew G Knepley } 36086636e97aSMatthew G Knepley 36096636e97aSMatthew G Knepley #undef __FUNCT__ 36106636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinateDM" 36116636e97aSMatthew G Knepley /*@ 36121cfe2091SMatthew G. Knepley DMGetCoordinateDM - Gets the DM that prescribes coordinate layout and scatters between global and local coordinates 36136636e97aSMatthew G Knepley 36146636e97aSMatthew G Knepley Collective on DM 36156636e97aSMatthew G Knepley 36166636e97aSMatthew G Knepley Input Parameter: 36176636e97aSMatthew G Knepley . dm - the DM 36186636e97aSMatthew G Knepley 36196636e97aSMatthew G Knepley Output Parameter: 36206636e97aSMatthew G Knepley . cdm - coordinate DM 36216636e97aSMatthew G Knepley 36226636e97aSMatthew G Knepley Level: intermediate 36236636e97aSMatthew G Knepley 36246636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 36251cfe2091SMatthew G. Knepley .seealso: DMSetCoordinateDM(), DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 36266636e97aSMatthew G Knepley @*/ 36276636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinateDM(DM dm, DM *cdm) 36286636e97aSMatthew G Knepley { 36296636e97aSMatthew G Knepley PetscErrorCode ierr; 36306636e97aSMatthew G Knepley 36316636e97aSMatthew G Knepley PetscFunctionBegin; 36326636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 36336636e97aSMatthew G Knepley PetscValidPointer(cdm,2); 36346636e97aSMatthew G Knepley if (!dm->coordinateDM) { 363582f516ccSBarry Smith if (!dm->ops->createcoordinatedm) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Unable to create coordinates for this DM"); 36366636e97aSMatthew G Knepley ierr = (*dm->ops->createcoordinatedm)(dm, &dm->coordinateDM);CHKERRQ(ierr); 36376636e97aSMatthew G Knepley } 36386636e97aSMatthew G Knepley *cdm = dm->coordinateDM; 36396636e97aSMatthew G Knepley PetscFunctionReturn(0); 36406636e97aSMatthew G Knepley } 3641e87bb0d3SMatthew G Knepley 3642e87bb0d3SMatthew G Knepley #undef __FUNCT__ 36431cfe2091SMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateDM" 36441cfe2091SMatthew G. Knepley /*@ 36451cfe2091SMatthew G. Knepley DMSetCoordinateDM - Sets the DM that prescribes coordinate layout and scatters between global and local coordinates 36461cfe2091SMatthew G. Knepley 36471cfe2091SMatthew G. Knepley Logically Collective on DM 36481cfe2091SMatthew G. Knepley 36491cfe2091SMatthew G. Knepley Input Parameters: 36501cfe2091SMatthew G. Knepley + dm - the DM 36511cfe2091SMatthew G. Knepley - cdm - coordinate DM 36521cfe2091SMatthew G. Knepley 36531cfe2091SMatthew G. Knepley Level: intermediate 36541cfe2091SMatthew G. Knepley 36551cfe2091SMatthew G. Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 36561cfe2091SMatthew G. Knepley .seealso: DMGetCoordinateDM(), DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 36571cfe2091SMatthew G. Knepley @*/ 36581cfe2091SMatthew G. Knepley PetscErrorCode DMSetCoordinateDM(DM dm, DM cdm) 36591cfe2091SMatthew G. Knepley { 36601cfe2091SMatthew G. Knepley PetscErrorCode ierr; 36611cfe2091SMatthew G. Knepley 36621cfe2091SMatthew G. Knepley PetscFunctionBegin; 36631cfe2091SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 36641cfe2091SMatthew G. Knepley PetscValidHeaderSpecific(cdm,DM_CLASSID,2); 36651cfe2091SMatthew G. Knepley ierr = DMDestroy(&dm->coordinateDM);CHKERRQ(ierr); 36661cfe2091SMatthew G. Knepley dm->coordinateDM = cdm; 36671cfe2091SMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm->coordinateDM);CHKERRQ(ierr); 36681cfe2091SMatthew G. Knepley PetscFunctionReturn(0); 36691cfe2091SMatthew G. Knepley } 36701cfe2091SMatthew G. Knepley 36711cfe2091SMatthew G. Knepley #undef __FUNCT__ 367246e270d4SMatthew G. Knepley #define __FUNCT__ "DMGetCoordinateDim" 367346e270d4SMatthew G. Knepley /*@ 367446e270d4SMatthew G. Knepley DMGetCoordinateDim - Retrieve the dimension of embedding space for coordinate values. 367546e270d4SMatthew G. Knepley 367646e270d4SMatthew G. Knepley Not Collective 367746e270d4SMatthew G. Knepley 367846e270d4SMatthew G. Knepley Input Parameter: 367946e270d4SMatthew G. Knepley . dm - The DM object 368046e270d4SMatthew G. Knepley 368146e270d4SMatthew G. Knepley Output Parameter: 368246e270d4SMatthew G. Knepley . dim - The embedding dimension 368346e270d4SMatthew G. Knepley 368446e270d4SMatthew G. Knepley Level: intermediate 368546e270d4SMatthew G. Knepley 368646e270d4SMatthew G. Knepley .keywords: mesh, coordinates 368746e270d4SMatthew G. Knepley .seealso: DMSetCoordinateDim(), DMGetCoordinateSection(), DMGetCoordinateDM(), DMGetDefaultSection(), DMSetDefaultSection() 368846e270d4SMatthew G. Knepley @*/ 368946e270d4SMatthew G. Knepley PetscErrorCode DMGetCoordinateDim(DM dm, PetscInt *dim) 369046e270d4SMatthew G. Knepley { 369146e270d4SMatthew G. Knepley PetscFunctionBegin; 369246e270d4SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 369346e270d4SMatthew G. Knepley PetscValidPointer(dim, 2); 369446e270d4SMatthew G. Knepley *dim = dm->dimEmbed; 369546e270d4SMatthew G. Knepley PetscFunctionReturn(0); 369646e270d4SMatthew G. Knepley } 369746e270d4SMatthew G. Knepley 369846e270d4SMatthew G. Knepley #undef __FUNCT__ 369946e270d4SMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateDim" 370046e270d4SMatthew G. Knepley /*@ 370146e270d4SMatthew G. Knepley DMSetCoordinateDim - Set the dimension of the embedding space for coordinate values. 370246e270d4SMatthew G. Knepley 370346e270d4SMatthew G. Knepley Not Collective 370446e270d4SMatthew G. Knepley 370546e270d4SMatthew G. Knepley Input Parameters: 370646e270d4SMatthew G. Knepley + dm - The DM object 370746e270d4SMatthew G. Knepley - dim - The embedding dimension 370846e270d4SMatthew G. Knepley 370946e270d4SMatthew G. Knepley Level: intermediate 371046e270d4SMatthew G. Knepley 371146e270d4SMatthew G. Knepley .keywords: mesh, coordinates 371246e270d4SMatthew G. Knepley .seealso: DMGetCoordinateDim(), DMSetCoordinateSection(), DMGetCoordinateSection(), DMGetDefaultSection(), DMSetDefaultSection() 371346e270d4SMatthew G. Knepley @*/ 371446e270d4SMatthew G. Knepley PetscErrorCode DMSetCoordinateDim(DM dm, PetscInt dim) 371546e270d4SMatthew G. Knepley { 371646e270d4SMatthew G. Knepley PetscFunctionBegin; 371746e270d4SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 371846e270d4SMatthew G. Knepley dm->dimEmbed = dim; 371946e270d4SMatthew G. Knepley PetscFunctionReturn(0); 372046e270d4SMatthew G. Knepley } 372146e270d4SMatthew G. Knepley 372246e270d4SMatthew G. Knepley #undef __FUNCT__ 3723e8abe2deSMatthew G. Knepley #define __FUNCT__ "DMGetCoordinateSection" 3724e8abe2deSMatthew G. Knepley /*@ 3725e8abe2deSMatthew G. Knepley DMGetCoordinateSection - Retrieve the layout of coordinate values over the mesh. 3726e8abe2deSMatthew G. Knepley 3727e8abe2deSMatthew G. Knepley Not Collective 3728e8abe2deSMatthew G. Knepley 3729e8abe2deSMatthew G. Knepley Input Parameter: 3730e8abe2deSMatthew G. Knepley . dm - The DM object 3731e8abe2deSMatthew G. Knepley 3732e8abe2deSMatthew G. Knepley Output Parameter: 3733e8abe2deSMatthew G. Knepley . section - The PetscSection object 3734e8abe2deSMatthew G. Knepley 3735e8abe2deSMatthew G. Knepley Level: intermediate 3736e8abe2deSMatthew G. Knepley 3737e8abe2deSMatthew G. Knepley .keywords: mesh, coordinates 3738e8abe2deSMatthew G. Knepley .seealso: DMGetCoordinateDM(), DMGetDefaultSection(), DMSetDefaultSection() 3739e8abe2deSMatthew G. Knepley @*/ 3740e8abe2deSMatthew G. Knepley PetscErrorCode DMGetCoordinateSection(DM dm, PetscSection *section) 3741e8abe2deSMatthew G. Knepley { 3742e8abe2deSMatthew G. Knepley DM cdm; 3743e8abe2deSMatthew G. Knepley PetscErrorCode ierr; 3744e8abe2deSMatthew G. Knepley 3745e8abe2deSMatthew G. Knepley PetscFunctionBegin; 3746e8abe2deSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3747e8abe2deSMatthew G. Knepley PetscValidPointer(section, 2); 3748e8abe2deSMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 3749e8abe2deSMatthew G. Knepley ierr = DMGetDefaultSection(cdm, section);CHKERRQ(ierr); 3750e8abe2deSMatthew G. Knepley PetscFunctionReturn(0); 3751e8abe2deSMatthew G. Knepley } 3752e8abe2deSMatthew G. Knepley 3753e8abe2deSMatthew G. Knepley #undef __FUNCT__ 3754e8abe2deSMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateSection" 3755e8abe2deSMatthew G. Knepley /*@ 3756e8abe2deSMatthew G. Knepley DMSetCoordinateSection - Set the layout of coordinate values over the mesh. 3757e8abe2deSMatthew G. Knepley 3758e8abe2deSMatthew G. Knepley Not Collective 3759e8abe2deSMatthew G. Knepley 3760e8abe2deSMatthew G. Knepley Input Parameters: 3761e8abe2deSMatthew G. Knepley + dm - The DM object 376246e270d4SMatthew G. Knepley . dim - The embedding dimension, or PETSC_DETERMINE 3763e8abe2deSMatthew G. Knepley - section - The PetscSection object 3764e8abe2deSMatthew G. Knepley 3765e8abe2deSMatthew G. Knepley Level: intermediate 3766e8abe2deSMatthew G. Knepley 3767e8abe2deSMatthew G. Knepley .keywords: mesh, coordinates 3768e8abe2deSMatthew G. Knepley .seealso: DMGetCoordinateSection(), DMGetDefaultSection(), DMSetDefaultSection() 3769e8abe2deSMatthew G. Knepley @*/ 377046e270d4SMatthew G. Knepley PetscErrorCode DMSetCoordinateSection(DM dm, PetscInt dim, PetscSection section) 3771e8abe2deSMatthew G. Knepley { 3772e8abe2deSMatthew G. Knepley DM cdm; 3773e8abe2deSMatthew G. Knepley PetscErrorCode ierr; 3774e8abe2deSMatthew G. Knepley 3775e8abe2deSMatthew G. Knepley PetscFunctionBegin; 3776e8abe2deSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 377746e270d4SMatthew G. Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,3); 3778e8abe2deSMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 3779e8abe2deSMatthew G. Knepley ierr = DMSetDefaultSection(cdm, section);CHKERRQ(ierr); 378046e270d4SMatthew G. Knepley if (dim == PETSC_DETERMINE) { 378146e270d4SMatthew G. Knepley PetscInt d = dim; 378246e270d4SMatthew G. Knepley PetscInt pStart, pEnd, vStart, vEnd, v, dd; 378346e270d4SMatthew G. Knepley 378446e270d4SMatthew G. Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 378546e270d4SMatthew G. Knepley ierr = DMGetDimPoints(dm, 0, &vStart, &vEnd);CHKERRQ(ierr); 378646e270d4SMatthew G. Knepley pStart = PetscMax(vStart, pStart); 378746e270d4SMatthew G. Knepley pEnd = PetscMin(vEnd, pEnd); 378846e270d4SMatthew G. Knepley for (v = pStart; v < pEnd; ++v) { 378946e270d4SMatthew G. Knepley ierr = PetscSectionGetDof(section, v, &dd);CHKERRQ(ierr); 379046e270d4SMatthew G. Knepley if (dd) {d = dd; break;} 379146e270d4SMatthew G. Knepley } 379246e270d4SMatthew G. Knepley ierr = DMSetCoordinateDim(dm, d);CHKERRQ(ierr); 379346e270d4SMatthew G. Knepley } 3794e8abe2deSMatthew G. Knepley PetscFunctionReturn(0); 3795e8abe2deSMatthew G. Knepley } 3796e8abe2deSMatthew G. Knepley 3797e8abe2deSMatthew G. Knepley #undef __FUNCT__ 3798c6b900c6SMatthew G. Knepley #define __FUNCT__ "DMGetPeriodicity" 3799c6b900c6SMatthew G. Knepley PetscErrorCode DMGetPeriodicity(DM dm, const PetscReal **maxCell, const PetscReal **L) 3800c6b900c6SMatthew G. Knepley { 3801c6b900c6SMatthew G. Knepley PetscFunctionBegin; 3802c6b900c6SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3803c6b900c6SMatthew G. Knepley if (L) *L = dm->L; 3804c6b900c6SMatthew G. Knepley if (maxCell) *maxCell = dm->maxCell; 3805c6b900c6SMatthew G. Knepley PetscFunctionReturn(0); 3806c6b900c6SMatthew G. Knepley } 3807c6b900c6SMatthew G. Knepley 3808c6b900c6SMatthew G. Knepley #undef __FUNCT__ 3809c6b900c6SMatthew G. Knepley #define __FUNCT__ "DMSetPeriodicity" 3810c6b900c6SMatthew G. Knepley PetscErrorCode DMSetPeriodicity(DM dm, const PetscReal maxCell[], const PetscReal L[]) 3811c6b900c6SMatthew G. Knepley { 3812c6b900c6SMatthew G. Knepley Vec coordinates; 3813c6b900c6SMatthew G. Knepley PetscInt dim, d; 3814c6b900c6SMatthew G. Knepley PetscErrorCode ierr; 3815c6b900c6SMatthew G. Knepley 3816c6b900c6SMatthew G. Knepley PetscFunctionBegin; 3817c6b900c6SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3818*3a374d76SMatthew G. Knepley ierr = PetscFree(dm->L);CHKERRQ(ierr); 3819*3a374d76SMatthew G. Knepley ierr = PetscFree(dm->maxCell);CHKERRQ(ierr); 3820c6b900c6SMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coordinates);CHKERRQ(ierr); 3821c6b900c6SMatthew G. Knepley ierr = VecGetBlockSize(coordinates, &dim);CHKERRQ(ierr); 3822c6b900c6SMatthew G. Knepley ierr = PetscMalloc1(dim,&dm->L);CHKERRQ(ierr); 3823c6b900c6SMatthew G. Knepley ierr = PetscMalloc1(dim,&dm->maxCell);CHKERRQ(ierr); 3824c6b900c6SMatthew G. Knepley for (d = 0; d < dim; ++d) {dm->L[d] = L[d]; dm->maxCell[d] = maxCell[d];} 3825c6b900c6SMatthew G. Knepley PetscFunctionReturn(0); 3826c6b900c6SMatthew G. Knepley } 3827c6b900c6SMatthew G. Knepley 3828c6b900c6SMatthew G. Knepley #undef __FUNCT__ 3829e87bb0d3SMatthew G Knepley #define __FUNCT__ "DMLocatePoints" 3830e87bb0d3SMatthew G Knepley /*@ 3831e87bb0d3SMatthew G Knepley DMLocatePoints - Locate the points in v in the mesh and return an IS of the containing cells 3832e87bb0d3SMatthew G Knepley 3833e87bb0d3SMatthew G Knepley Not collective 3834e87bb0d3SMatthew G Knepley 3835e87bb0d3SMatthew G Knepley Input Parameters: 3836e87bb0d3SMatthew G Knepley + dm - The DM 3837e87bb0d3SMatthew G Knepley - v - The Vec of points 3838e87bb0d3SMatthew G Knepley 383961e3bb9bSMatthew G Knepley Output Parameter: 3840e87bb0d3SMatthew G Knepley . cells - The local cell numbers for cells which contain the points 3841e87bb0d3SMatthew G Knepley 3842e87bb0d3SMatthew G Knepley Level: developer 384361e3bb9bSMatthew G Knepley 384461e3bb9bSMatthew G Knepley .keywords: point location, mesh 384561e3bb9bSMatthew G Knepley .seealso: DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 384661e3bb9bSMatthew G Knepley @*/ 3847e87bb0d3SMatthew G Knepley PetscErrorCode DMLocatePoints(DM dm, Vec v, IS *cells) 3848e87bb0d3SMatthew G Knepley { 3849735aa83eSMatthew G Knepley PetscErrorCode ierr; 3850735aa83eSMatthew G Knepley 3851e87bb0d3SMatthew G Knepley PetscFunctionBegin; 3852e87bb0d3SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3853e87bb0d3SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,2); 3854e87bb0d3SMatthew G Knepley PetscValidPointer(cells,3); 3855735aa83eSMatthew G Knepley if (dm->ops->locatepoints) { 3856735aa83eSMatthew G Knepley ierr = (*dm->ops->locatepoints)(dm,v,cells);CHKERRQ(ierr); 385782f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Point location not available for this DM"); 3858e87bb0d3SMatthew G Knepley PetscFunctionReturn(0); 3859e87bb0d3SMatthew G Knepley } 386014f150ffSMatthew G. Knepley 386114f150ffSMatthew G. Knepley #undef __FUNCT__ 386214f150ffSMatthew G. Knepley #define __FUNCT__ "DMGetOutputDM" 3863f4d763aaSMatthew G. Knepley /*@ 3864f4d763aaSMatthew G. Knepley DMGetOutputDM - Retrieve the DM associated with the layout for output 3865f4d763aaSMatthew G. Knepley 3866f4d763aaSMatthew G. Knepley Input Parameter: 3867f4d763aaSMatthew G. Knepley . dm - The original DM 3868f4d763aaSMatthew G. Knepley 3869f4d763aaSMatthew G. Knepley Output Parameter: 3870f4d763aaSMatthew G. Knepley . odm - The DM which provides the layout for output 3871f4d763aaSMatthew G. Knepley 3872f4d763aaSMatthew G. Knepley Level: intermediate 3873f4d763aaSMatthew G. Knepley 3874f4d763aaSMatthew G. Knepley .seealso: VecView(), DMGetDefaultGlobalSection() 3875f4d763aaSMatthew G. Knepley @*/ 387614f150ffSMatthew G. Knepley PetscErrorCode DMGetOutputDM(DM dm, DM *odm) 387714f150ffSMatthew G. Knepley { 3878c26acbdeSMatthew G. Knepley PetscSection section; 3879c26acbdeSMatthew G. Knepley PetscBool hasConstraints; 388014f150ffSMatthew G. Knepley PetscErrorCode ierr; 388114f150ffSMatthew G. Knepley 388214f150ffSMatthew G. Knepley PetscFunctionBegin; 388314f150ffSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 388414f150ffSMatthew G. Knepley PetscValidPointer(odm,2); 3885c26acbdeSMatthew G. Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 3886c26acbdeSMatthew G. Knepley ierr = PetscSectionHasConstraints(section, &hasConstraints);CHKERRQ(ierr); 3887c26acbdeSMatthew G. Knepley if (!hasConstraints) { 3888c26acbdeSMatthew G. Knepley *odm = dm; 3889c26acbdeSMatthew G. Knepley PetscFunctionReturn(0); 3890c26acbdeSMatthew G. Knepley } 389114f150ffSMatthew G. Knepley if (!dm->dmBC) { 3892c26acbdeSMatthew G. Knepley PetscSection newSection, gsection; 389314f150ffSMatthew G. Knepley PetscSF sf; 389414f150ffSMatthew G. Knepley 389514f150ffSMatthew G. Knepley ierr = DMClone(dm, &dm->dmBC);CHKERRQ(ierr); 389614f150ffSMatthew G. Knepley ierr = PetscSectionClone(section, &newSection);CHKERRQ(ierr); 389714f150ffSMatthew G. Knepley ierr = DMSetDefaultSection(dm->dmBC, newSection);CHKERRQ(ierr); 389814f150ffSMatthew G. Knepley ierr = PetscSectionDestroy(&newSection);CHKERRQ(ierr); 389914f150ffSMatthew G. Knepley ierr = DMGetPointSF(dm->dmBC, &sf);CHKERRQ(ierr); 390014f150ffSMatthew G. Knepley ierr = PetscSectionCreateGlobalSection(section, sf, PETSC_TRUE, &gsection);CHKERRQ(ierr); 390114f150ffSMatthew G. Knepley ierr = DMSetDefaultGlobalSection(dm->dmBC, gsection);CHKERRQ(ierr); 390214f150ffSMatthew G. Knepley ierr = PetscSectionDestroy(&gsection);CHKERRQ(ierr); 390314f150ffSMatthew G. Knepley } 390414f150ffSMatthew G. Knepley *odm = dm->dmBC; 390514f150ffSMatthew G. Knepley PetscFunctionReturn(0); 390614f150ffSMatthew G. Knepley } 3907f4d763aaSMatthew G. Knepley 3908f4d763aaSMatthew G. Knepley #undef __FUNCT__ 3909f4d763aaSMatthew G. Knepley #define __FUNCT__ "DMGetOutputSequenceNumber" 3910f4d763aaSMatthew G. Knepley /*@ 3911cdb7a50dSMatthew G. Knepley DMGetOutputSequenceNumber - Retrieve the sequence number/value for output 3912f4d763aaSMatthew G. Knepley 3913f4d763aaSMatthew G. Knepley Input Parameter: 3914f4d763aaSMatthew G. Knepley . dm - The original DM 3915f4d763aaSMatthew G. Knepley 3916cdb7a50dSMatthew G. Knepley Output Parameters: 3917cdb7a50dSMatthew G. Knepley + num - The output sequence number 3918cdb7a50dSMatthew G. Knepley - val - The output sequence value 3919f4d763aaSMatthew G. Knepley 3920f4d763aaSMatthew G. Knepley Level: intermediate 3921f4d763aaSMatthew G. Knepley 3922f4d763aaSMatthew G. Knepley Note: This is intended for output that should appear in sequence, for instance 3923f4d763aaSMatthew G. Knepley a set of timesteps in an HDF5 file, or a set of realizations of a stochastic system. 3924f4d763aaSMatthew G. Knepley 3925f4d763aaSMatthew G. Knepley .seealso: VecView() 3926f4d763aaSMatthew G. Knepley @*/ 3927cdb7a50dSMatthew G. Knepley PetscErrorCode DMGetOutputSequenceNumber(DM dm, PetscInt *num, PetscReal *val) 3928f4d763aaSMatthew G. Knepley { 3929f4d763aaSMatthew G. Knepley PetscFunctionBegin; 3930f4d763aaSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3931cdb7a50dSMatthew G. Knepley if (num) {PetscValidPointer(num,2); *num = dm->outputSequenceNum;} 3932cdb7a50dSMatthew G. Knepley if (val) {PetscValidPointer(val,3);*val = dm->outputSequenceVal;} 3933f4d763aaSMatthew G. Knepley PetscFunctionReturn(0); 3934f4d763aaSMatthew G. Knepley } 3935f4d763aaSMatthew G. Knepley 3936f4d763aaSMatthew G. Knepley #undef __FUNCT__ 3937f4d763aaSMatthew G. Knepley #define __FUNCT__ "DMSetOutputSequenceNumber" 3938f4d763aaSMatthew G. Knepley /*@ 3939cdb7a50dSMatthew G. Knepley DMSetOutputSequenceNumber - Set the sequence number/value for output 3940f4d763aaSMatthew G. Knepley 3941f4d763aaSMatthew G. Knepley Input Parameters: 3942f4d763aaSMatthew G. Knepley + dm - The original DM 3943cdb7a50dSMatthew G. Knepley . num - The output sequence number 3944cdb7a50dSMatthew G. Knepley - val - The output sequence value 3945f4d763aaSMatthew G. Knepley 3946f4d763aaSMatthew G. Knepley Level: intermediate 3947f4d763aaSMatthew G. Knepley 3948f4d763aaSMatthew G. Knepley Note: This is intended for output that should appear in sequence, for instance 3949f4d763aaSMatthew G. Knepley a set of timesteps in an HDF5 file, or a set of realizations of a stochastic system. 3950f4d763aaSMatthew G. Knepley 3951f4d763aaSMatthew G. Knepley .seealso: VecView() 3952f4d763aaSMatthew G. Knepley @*/ 3953cdb7a50dSMatthew G. Knepley PetscErrorCode DMSetOutputSequenceNumber(DM dm, PetscInt num, PetscReal val) 3954f4d763aaSMatthew G. Knepley { 3955f4d763aaSMatthew G. Knepley PetscFunctionBegin; 3956f4d763aaSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3957f4d763aaSMatthew G. Knepley dm->outputSequenceNum = num; 3958cdb7a50dSMatthew G. Knepley dm->outputSequenceVal = val; 3959cdb7a50dSMatthew G. Knepley PetscFunctionReturn(0); 3960cdb7a50dSMatthew G. Knepley } 3961cdb7a50dSMatthew G. Knepley 3962cdb7a50dSMatthew G. Knepley #undef __FUNCT__ 3963cdb7a50dSMatthew G. Knepley #define __FUNCT__ "DMOutputSequenceLoad" 3964cdb7a50dSMatthew G. Knepley /*@C 3965cdb7a50dSMatthew G. Knepley DMOutputSequenceLoad - Retrieve the sequence value from a Viewer 3966cdb7a50dSMatthew G. Knepley 3967cdb7a50dSMatthew G. Knepley Input Parameters: 3968cdb7a50dSMatthew G. Knepley + dm - The original DM 3969cdb7a50dSMatthew G. Knepley . name - The sequence name 3970cdb7a50dSMatthew G. Knepley - num - The output sequence number 3971cdb7a50dSMatthew G. Knepley 3972cdb7a50dSMatthew G. Knepley Output Parameter: 3973cdb7a50dSMatthew G. Knepley . val - The output sequence value 3974cdb7a50dSMatthew G. Knepley 3975cdb7a50dSMatthew G. Knepley Level: intermediate 3976cdb7a50dSMatthew G. Knepley 3977cdb7a50dSMatthew G. Knepley Note: This is intended for output that should appear in sequence, for instance 3978cdb7a50dSMatthew G. Knepley a set of timesteps in an HDF5 file, or a set of realizations of a stochastic system. 3979cdb7a50dSMatthew G. Knepley 3980cdb7a50dSMatthew G. Knepley .seealso: DMGetOutputSequenceNumber(), DMSetOutputSequenceNumber(), VecView() 3981cdb7a50dSMatthew G. Knepley @*/ 3982cdb7a50dSMatthew G. Knepley PetscErrorCode DMOutputSequenceLoad(DM dm, PetscViewer viewer, const char *name, PetscInt num, PetscReal *val) 3983cdb7a50dSMatthew G. Knepley { 3984cdb7a50dSMatthew G. Knepley PetscBool ishdf5; 3985cdb7a50dSMatthew G. Knepley PetscErrorCode ierr; 3986cdb7a50dSMatthew G. Knepley 3987cdb7a50dSMatthew G. Knepley PetscFunctionBegin; 3988cdb7a50dSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3989cdb7a50dSMatthew G. Knepley PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 3990cdb7a50dSMatthew G. Knepley PetscValidPointer(val,4); 3991cdb7a50dSMatthew G. Knepley ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERHDF5, &ishdf5);CHKERRQ(ierr); 3992cdb7a50dSMatthew G. Knepley if (ishdf5) { 3993cdb7a50dSMatthew G. Knepley #if defined(PETSC_HAVE_HDF5) 3994cdb7a50dSMatthew G. Knepley PetscScalar value; 3995cdb7a50dSMatthew G. Knepley 3996cdb7a50dSMatthew G. Knepley ierr = DMSequenceLoad_HDF5(dm, name, num, &value, viewer);CHKERRQ(ierr); 39974aeb217fSMatthew G. Knepley *val = PetscRealPart(value); 3998cdb7a50dSMatthew G. Knepley #endif 3999cdb7a50dSMatthew G. Knepley } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Invalid viewer; open viewer with PetscViewerHDF5Open()"); 4000f4d763aaSMatthew G. Knepley PetscFunctionReturn(0); 4001f4d763aaSMatthew G. Knepley } 4002