1b45d2f2cSJed Brown #include <petsc-private/dmimpl.h> /*I "petscdm.h" I*/ 20c312b8eSJed Brown #include <petscsf.h> 347c6ae99SBarry Smith 4732e2eb9SMatthew G Knepley PetscClassId DM_CLASSID; 5f089877aSRichard Tran Mills PetscLogEvent DM_Convert, DM_GlobalToLocal, DM_LocalToGlobal, DM_LocalToLocal; 667a56275SMatthew G Knepley 7bff4a2f0SMatthew G. Knepley const char *const DMBoundaryTypes[] = {"NONE","GHOSTED","MIRROR","PERIODIC","TWIST","DM_BOUNDARY_",0}; 8bff4a2f0SMatthew G. Knepley 947c6ae99SBarry Smith #undef __FUNCT__ 10a4121054SBarry Smith #define __FUNCT__ "DMCreate" 11a4121054SBarry Smith /*@ 12de043629SMatthew G Knepley DMCreate - Creates an empty DM object. The type can then be set with DMSetType(). 13a4121054SBarry Smith 14a4121054SBarry Smith If you never call DMSetType() it will generate an 15a4121054SBarry Smith error when you try to use the vector. 16a4121054SBarry Smith 17a4121054SBarry Smith Collective on MPI_Comm 18a4121054SBarry Smith 19a4121054SBarry Smith Input Parameter: 20a4121054SBarry Smith . comm - The communicator for the DM object 21a4121054SBarry Smith 22a4121054SBarry Smith Output Parameter: 23a4121054SBarry Smith . dm - The DM object 24a4121054SBarry Smith 25a4121054SBarry Smith Level: beginner 26a4121054SBarry Smith 27a4121054SBarry Smith .seealso: DMSetType(), DMDA, DMSLICED, DMCOMPOSITE 28a4121054SBarry Smith @*/ 297087cfbeSBarry Smith PetscErrorCode DMCreate(MPI_Comm comm,DM *dm) 30a4121054SBarry Smith { 31a4121054SBarry Smith DM v; 32a4121054SBarry Smith PetscErrorCode ierr; 33a4121054SBarry Smith 34a4121054SBarry Smith PetscFunctionBegin; 351411c6eeSJed Brown PetscValidPointer(dm,2); 360298fd71SBarry Smith *dm = NULL; 378b984314SMatthew G. Knepley ierr = PetscSysInitializePackage();CHKERRQ(ierr); 38607a6623SBarry Smith ierr = VecInitializePackage();CHKERRQ(ierr); 39607a6623SBarry Smith ierr = MatInitializePackage();CHKERRQ(ierr); 40607a6623SBarry Smith ierr = DMInitializePackage();CHKERRQ(ierr); 41a4121054SBarry Smith 4267c2884eSBarry Smith ierr = PetscHeaderCreate(v, _p_DM, struct _DMOps, DM_CLASSID, "DM", "Distribution Manager", "DM", comm, DMDestroy, DMView);CHKERRQ(ierr); 43a4121054SBarry Smith ierr = PetscMemzero(v->ops, sizeof(struct _DMOps));CHKERRQ(ierr); 441411c6eeSJed Brown 45e7c4fc90SDmitry Karpeev 460298fd71SBarry Smith v->ltogmap = NULL; 470298fd71SBarry Smith v->ltogmapb = 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; 54435a35e8SMatthew G Knepley { 55435a35e8SMatthew G Knepley PetscInt i; 56435a35e8SMatthew G Knepley for (i = 0; i < 10; ++i) { 570298fd71SBarry Smith v->nullspaceConstructors[i] = NULL; 58435a35e8SMatthew G Knepley } 59435a35e8SMatthew G Knepley } 60af122d2aSMatthew G Knepley v->numFields = 0; 610298fd71SBarry Smith v->fields = NULL; 62c0dedaeaSBarry Smith ierr = DMSetVecType(v,VECSTANDARD);CHKERRQ(ierr); 63b412c318SBarry Smith ierr = DMSetMatType(v,MATAIJ);CHKERRQ(ierr); 641411c6eeSJed Brown *dm = v; 65a4121054SBarry Smith PetscFunctionReturn(0); 66a4121054SBarry Smith } 67a4121054SBarry Smith 68a4121054SBarry Smith #undef __FUNCT__ 6938221697SMatthew G. Knepley #define __FUNCT__ "DMClone" 7038221697SMatthew G. Knepley /*@ 7138221697SMatthew G. Knepley DMClone - Creates a DM object with the same topology as the original. 7238221697SMatthew G. Knepley 7338221697SMatthew G. Knepley Collective on MPI_Comm 7438221697SMatthew G. Knepley 7538221697SMatthew G. Knepley Input Parameter: 7638221697SMatthew G. Knepley . dm - The original DM object 7738221697SMatthew G. Knepley 7838221697SMatthew G. Knepley Output Parameter: 7938221697SMatthew G. Knepley . newdm - The new DM object 8038221697SMatthew G. Knepley 8138221697SMatthew G. Knepley Level: beginner 8238221697SMatthew G. Knepley 8338221697SMatthew G. Knepley .keywords: DM, topology, create 8438221697SMatthew G. Knepley @*/ 8538221697SMatthew G. Knepley PetscErrorCode DMClone(DM dm, DM *newdm) 8638221697SMatthew G. Knepley { 8738221697SMatthew G. Knepley PetscSF sf; 8838221697SMatthew G. Knepley Vec coords; 8938221697SMatthew G. Knepley void *ctx; 9038221697SMatthew G. Knepley PetscErrorCode ierr; 9138221697SMatthew G. Knepley 9238221697SMatthew G. Knepley PetscFunctionBegin; 9338221697SMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 9438221697SMatthew G. Knepley PetscValidPointer(newdm,2); 9538221697SMatthew G. Knepley ierr = DMCreate(PetscObjectComm((PetscObject)dm), newdm);CHKERRQ(ierr); 9638221697SMatthew G. Knepley if (dm->ops->clone) { 9738221697SMatthew G. Knepley ierr = (*dm->ops->clone)(dm, newdm);CHKERRQ(ierr); 9838221697SMatthew G. Knepley } 99cd27c7c9SMatthew G. Knepley (*newdm)->setupcalled = PETSC_TRUE; 10038221697SMatthew G. Knepley ierr = DMGetPointSF(dm, &sf);CHKERRQ(ierr); 10138221697SMatthew G. Knepley ierr = DMSetPointSF(*newdm, sf);CHKERRQ(ierr); 10238221697SMatthew G. Knepley ierr = DMGetApplicationContext(dm, &ctx);CHKERRQ(ierr); 10338221697SMatthew G. Knepley ierr = DMSetApplicationContext(*newdm, ctx);CHKERRQ(ierr); 10438221697SMatthew G. Knepley ierr = DMGetCoordinatesLocal(dm, &coords);CHKERRQ(ierr); 10538221697SMatthew G. Knepley if (coords) { 10638221697SMatthew G. Knepley ierr = DMSetCoordinatesLocal(*newdm, coords);CHKERRQ(ierr); 10738221697SMatthew G. Knepley } else { 10838221697SMatthew G. Knepley ierr = DMGetCoordinates(dm, &coords);CHKERRQ(ierr); 10938221697SMatthew G. Knepley if (coords) {ierr = DMSetCoordinates(*newdm, coords);CHKERRQ(ierr);} 11038221697SMatthew G. Knepley } 11138221697SMatthew G. Knepley PetscFunctionReturn(0); 11238221697SMatthew G. Knepley } 11338221697SMatthew G. Knepley 11438221697SMatthew G. Knepley #undef __FUNCT__ 1159a42bb27SBarry Smith #define __FUNCT__ "DMSetVecType" 1169a42bb27SBarry Smith /*@C 117564755cdSBarry Smith DMSetVecType - Sets the type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() 1189a42bb27SBarry Smith 119aa219208SBarry Smith Logically Collective on DMDA 1209a42bb27SBarry Smith 1219a42bb27SBarry Smith Input Parameter: 1229a42bb27SBarry Smith + da - initial distributed array 1238154be41SBarry Smith . ctype - the vector type, currently either VECSTANDARD or VECCUSP 1249a42bb27SBarry Smith 1259a42bb27SBarry Smith Options Database: 126dd85299cSBarry Smith . -dm_vec_type ctype 1279a42bb27SBarry Smith 1289a42bb27SBarry Smith Level: intermediate 1299a42bb27SBarry Smith 130c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMDestroy(), DMDA, DMDAInterpolationType, VecType, DMGetVecType() 1319a42bb27SBarry Smith @*/ 13219fd82e9SBarry Smith PetscErrorCode DMSetVecType(DM da,VecType ctype) 1339a42bb27SBarry Smith { 1349a42bb27SBarry Smith PetscErrorCode ierr; 1359a42bb27SBarry Smith 1369a42bb27SBarry Smith PetscFunctionBegin; 1379a42bb27SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 1389a42bb27SBarry Smith ierr = PetscFree(da->vectype);CHKERRQ(ierr); 13919fd82e9SBarry Smith ierr = PetscStrallocpy(ctype,(char**)&da->vectype);CHKERRQ(ierr); 1409a42bb27SBarry Smith PetscFunctionReturn(0); 1419a42bb27SBarry Smith } 1429a42bb27SBarry Smith 1439a42bb27SBarry Smith #undef __FUNCT__ 144c0dedaeaSBarry Smith #define __FUNCT__ "DMGetVecType" 145c0dedaeaSBarry Smith /*@C 146c0dedaeaSBarry Smith DMGetVecType - Gets the type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() 147c0dedaeaSBarry Smith 148c0dedaeaSBarry Smith Logically Collective on DMDA 149c0dedaeaSBarry Smith 150c0dedaeaSBarry Smith Input Parameter: 151c0dedaeaSBarry Smith . da - initial distributed array 152c0dedaeaSBarry Smith 153c0dedaeaSBarry Smith Output Parameter: 154c0dedaeaSBarry Smith . ctype - the vector type 155c0dedaeaSBarry Smith 156c0dedaeaSBarry Smith Level: intermediate 157c0dedaeaSBarry Smith 158c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMDestroy(), DMDA, DMDAInterpolationType, VecType 159c0dedaeaSBarry Smith @*/ 160c0dedaeaSBarry Smith PetscErrorCode DMGetVecType(DM da,VecType *ctype) 161c0dedaeaSBarry Smith { 162c0dedaeaSBarry Smith PetscFunctionBegin; 163c0dedaeaSBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 164c0dedaeaSBarry Smith *ctype = da->vectype; 165c0dedaeaSBarry Smith PetscFunctionReturn(0); 166c0dedaeaSBarry Smith } 167c0dedaeaSBarry Smith 168c0dedaeaSBarry Smith #undef __FUNCT__ 1695f1ad066SMatthew G Knepley #define __FUNCT__ "VecGetDM" 1705f1ad066SMatthew G Knepley /*@ 17134f98d34SBarry Smith VecGetDM - Gets the DM defining the data layout of the vector 1725f1ad066SMatthew G Knepley 1735f1ad066SMatthew G Knepley Not collective 1745f1ad066SMatthew G Knepley 1755f1ad066SMatthew G Knepley Input Parameter: 1765f1ad066SMatthew G Knepley . v - The Vec 1775f1ad066SMatthew G Knepley 1785f1ad066SMatthew G Knepley Output Parameter: 1795f1ad066SMatthew G Knepley . dm - The DM 1805f1ad066SMatthew G Knepley 1815f1ad066SMatthew G Knepley Level: intermediate 1825f1ad066SMatthew G Knepley 1835f1ad066SMatthew G Knepley .seealso: VecSetDM(), DMGetLocalVector(), DMGetGlobalVector(), DMSetVecType() 1845f1ad066SMatthew G Knepley @*/ 1855f1ad066SMatthew G Knepley PetscErrorCode VecGetDM(Vec v, DM *dm) 1865f1ad066SMatthew G Knepley { 1875f1ad066SMatthew G Knepley PetscErrorCode ierr; 1885f1ad066SMatthew G Knepley 1895f1ad066SMatthew G Knepley PetscFunctionBegin; 1905f1ad066SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,1); 1915f1ad066SMatthew G Knepley PetscValidPointer(dm,2); 1925f1ad066SMatthew G Knepley ierr = PetscObjectQuery((PetscObject) v, "__PETSc_dm", (PetscObject*) dm);CHKERRQ(ierr); 1935f1ad066SMatthew G Knepley PetscFunctionReturn(0); 1945f1ad066SMatthew G Knepley } 1955f1ad066SMatthew G Knepley 1965f1ad066SMatthew G Knepley #undef __FUNCT__ 1975f1ad066SMatthew G Knepley #define __FUNCT__ "VecSetDM" 1985f1ad066SMatthew G Knepley /*@ 1995f1ad066SMatthew G Knepley VecSetDM - Sets the DM defining the data layout of the vector 2005f1ad066SMatthew G Knepley 2015f1ad066SMatthew G Knepley Not collective 2025f1ad066SMatthew G Knepley 2035f1ad066SMatthew G Knepley Input Parameters: 2045f1ad066SMatthew G Knepley + v - The Vec 2055f1ad066SMatthew G Knepley - dm - The DM 2065f1ad066SMatthew G Knepley 2075f1ad066SMatthew G Knepley Level: intermediate 2085f1ad066SMatthew G Knepley 2095f1ad066SMatthew G Knepley .seealso: VecGetDM(), DMGetLocalVector(), DMGetGlobalVector(), DMSetVecType() 2105f1ad066SMatthew G Knepley @*/ 2115f1ad066SMatthew G Knepley PetscErrorCode VecSetDM(Vec v, DM dm) 2125f1ad066SMatthew G Knepley { 2135f1ad066SMatthew G Knepley PetscErrorCode ierr; 2145f1ad066SMatthew G Knepley 2155f1ad066SMatthew G Knepley PetscFunctionBegin; 2165f1ad066SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,1); 217d7f50e27SLisandro Dalcin if (dm) PetscValidHeaderSpecific(dm,DM_CLASSID,2); 2185f1ad066SMatthew G Knepley ierr = PetscObjectCompose((PetscObject) v, "__PETSc_dm", (PetscObject) dm);CHKERRQ(ierr); 2195f1ad066SMatthew G Knepley PetscFunctionReturn(0); 2205f1ad066SMatthew G Knepley } 2215f1ad066SMatthew G Knepley 2225f1ad066SMatthew G Knepley #undef __FUNCT__ 223521d9a4cSLisandro Dalcin #define __FUNCT__ "DMSetMatType" 224521d9a4cSLisandro Dalcin /*@C 225521d9a4cSLisandro Dalcin DMSetMatType - Sets the type of matrix created with DMCreateMatrix() 226521d9a4cSLisandro Dalcin 227521d9a4cSLisandro Dalcin Logically Collective on DM 228521d9a4cSLisandro Dalcin 229521d9a4cSLisandro Dalcin Input Parameter: 230521d9a4cSLisandro Dalcin + dm - the DM context 231521d9a4cSLisandro Dalcin . ctype - the matrix type 232521d9a4cSLisandro Dalcin 233521d9a4cSLisandro Dalcin Options Database: 234521d9a4cSLisandro Dalcin . -dm_mat_type ctype 235521d9a4cSLisandro Dalcin 236521d9a4cSLisandro Dalcin Level: intermediate 237521d9a4cSLisandro Dalcin 238c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateMatrix(), DMSetMatrixPreallocateOnly(), MatType, DMGetMatType() 239521d9a4cSLisandro Dalcin @*/ 24019fd82e9SBarry Smith PetscErrorCode DMSetMatType(DM dm,MatType ctype) 241521d9a4cSLisandro Dalcin { 242521d9a4cSLisandro Dalcin PetscErrorCode ierr; 24388f0584fSBarry Smith 244521d9a4cSLisandro Dalcin PetscFunctionBegin; 245521d9a4cSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 246521d9a4cSLisandro Dalcin ierr = PetscFree(dm->mattype);CHKERRQ(ierr); 24719fd82e9SBarry Smith ierr = PetscStrallocpy(ctype,(char**)&dm->mattype);CHKERRQ(ierr); 248521d9a4cSLisandro Dalcin PetscFunctionReturn(0); 249521d9a4cSLisandro Dalcin } 250521d9a4cSLisandro Dalcin 251521d9a4cSLisandro Dalcin #undef __FUNCT__ 252c0dedaeaSBarry Smith #define __FUNCT__ "DMGetMatType" 253c0dedaeaSBarry Smith /*@C 254c0dedaeaSBarry Smith DMGetMatType - Gets the type of matrix created with DMCreateMatrix() 255c0dedaeaSBarry Smith 256c0dedaeaSBarry Smith Logically Collective on DM 257c0dedaeaSBarry Smith 258c0dedaeaSBarry Smith Input Parameter: 259c0dedaeaSBarry Smith . dm - the DM context 260c0dedaeaSBarry Smith 261c0dedaeaSBarry Smith Output Parameter: 262c0dedaeaSBarry Smith . ctype - the matrix type 263c0dedaeaSBarry Smith 264c0dedaeaSBarry Smith Options Database: 265c0dedaeaSBarry Smith . -dm_mat_type ctype 266c0dedaeaSBarry Smith 267c0dedaeaSBarry Smith Level: intermediate 268c0dedaeaSBarry Smith 269c0dedaeaSBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateMatrix(), DMSetMatrixPreallocateOnly(), MatType, DMSetMatType() 270c0dedaeaSBarry Smith @*/ 271c0dedaeaSBarry Smith PetscErrorCode DMGetMatType(DM dm,MatType *ctype) 272c0dedaeaSBarry Smith { 273c0dedaeaSBarry Smith PetscFunctionBegin; 274c0dedaeaSBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 275c0dedaeaSBarry Smith *ctype = dm->mattype; 276c0dedaeaSBarry Smith PetscFunctionReturn(0); 277c0dedaeaSBarry Smith } 278c0dedaeaSBarry Smith 279c0dedaeaSBarry Smith #undef __FUNCT__ 280c688c046SMatthew G Knepley #define __FUNCT__ "MatGetDM" 281c688c046SMatthew G Knepley /*@ 28234f98d34SBarry Smith MatGetDM - Gets the DM defining the data layout of the matrix 283c688c046SMatthew G Knepley 284c688c046SMatthew G Knepley Not collective 285c688c046SMatthew G Knepley 286c688c046SMatthew G Knepley Input Parameter: 287c688c046SMatthew G Knepley . A - The Mat 288c688c046SMatthew G Knepley 289c688c046SMatthew G Knepley Output Parameter: 290c688c046SMatthew G Knepley . dm - The DM 291c688c046SMatthew G Knepley 292c688c046SMatthew G Knepley Level: intermediate 293c688c046SMatthew G Knepley 294c688c046SMatthew G Knepley .seealso: MatSetDM(), DMCreateMatrix(), DMSetMatType() 295c688c046SMatthew G Knepley @*/ 296c688c046SMatthew G Knepley PetscErrorCode MatGetDM(Mat A, DM *dm) 297c688c046SMatthew G Knepley { 298c688c046SMatthew G Knepley PetscErrorCode ierr; 299c688c046SMatthew G Knepley 300c688c046SMatthew G Knepley PetscFunctionBegin; 301c688c046SMatthew G Knepley PetscValidHeaderSpecific(A,MAT_CLASSID,1); 302c688c046SMatthew G Knepley PetscValidPointer(dm,2); 303c688c046SMatthew G Knepley ierr = PetscObjectQuery((PetscObject) A, "__PETSc_dm", (PetscObject*) dm);CHKERRQ(ierr); 304c688c046SMatthew G Knepley PetscFunctionReturn(0); 305c688c046SMatthew G Knepley } 306c688c046SMatthew G Knepley 307c688c046SMatthew G Knepley #undef __FUNCT__ 308c688c046SMatthew G Knepley #define __FUNCT__ "MatSetDM" 309c688c046SMatthew G Knepley /*@ 310c688c046SMatthew G Knepley MatSetDM - Sets the DM defining the data layout of the matrix 311c688c046SMatthew G Knepley 312c688c046SMatthew G Knepley Not collective 313c688c046SMatthew G Knepley 314c688c046SMatthew G Knepley Input Parameters: 315c688c046SMatthew G Knepley + A - The Mat 316c688c046SMatthew G Knepley - dm - The DM 317c688c046SMatthew G Knepley 318c688c046SMatthew G Knepley Level: intermediate 319c688c046SMatthew G Knepley 320c688c046SMatthew G Knepley .seealso: MatGetDM(), DMCreateMatrix(), DMSetMatType() 321c688c046SMatthew G Knepley @*/ 322c688c046SMatthew G Knepley PetscErrorCode MatSetDM(Mat A, DM dm) 323c688c046SMatthew G Knepley { 324c688c046SMatthew G Knepley PetscErrorCode ierr; 325c688c046SMatthew G Knepley 326c688c046SMatthew G Knepley PetscFunctionBegin; 327c688c046SMatthew G Knepley PetscValidHeaderSpecific(A,MAT_CLASSID,1); 3288865f1eaSKarl Rupp if (dm) PetscValidHeaderSpecific(dm,DM_CLASSID,2); 329c688c046SMatthew G Knepley ierr = PetscObjectCompose((PetscObject) A, "__PETSc_dm", (PetscObject) dm);CHKERRQ(ierr); 330c688c046SMatthew G Knepley PetscFunctionReturn(0); 331c688c046SMatthew G Knepley } 332c688c046SMatthew G Knepley 333c688c046SMatthew G Knepley #undef __FUNCT__ 3349a42bb27SBarry Smith #define __FUNCT__ "DMSetOptionsPrefix" 3359a42bb27SBarry Smith /*@C 3369a42bb27SBarry Smith DMSetOptionsPrefix - Sets the prefix used for searching for all 337aa219208SBarry Smith DMDA options in the database. 3389a42bb27SBarry Smith 339aa219208SBarry Smith Logically Collective on DMDA 3409a42bb27SBarry Smith 3419a42bb27SBarry Smith Input Parameter: 342aa219208SBarry Smith + da - the DMDA context 3439a42bb27SBarry Smith - prefix - the prefix to prepend to all option names 3449a42bb27SBarry Smith 3459a42bb27SBarry Smith Notes: 3469a42bb27SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 3479a42bb27SBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 3489a42bb27SBarry Smith 3499a42bb27SBarry Smith Level: advanced 3509a42bb27SBarry Smith 351aa219208SBarry Smith .keywords: DMDA, set, options, prefix, database 3529a42bb27SBarry Smith 3539a42bb27SBarry Smith .seealso: DMSetFromOptions() 3549a42bb27SBarry Smith @*/ 3557087cfbeSBarry Smith PetscErrorCode DMSetOptionsPrefix(DM dm,const char prefix[]) 3569a42bb27SBarry Smith { 3579a42bb27SBarry Smith PetscErrorCode ierr; 3589a42bb27SBarry Smith 3599a42bb27SBarry Smith PetscFunctionBegin; 3609a42bb27SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3619a42bb27SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)dm,prefix);CHKERRQ(ierr); 3629a42bb27SBarry Smith PetscFunctionReturn(0); 3639a42bb27SBarry Smith } 3649a42bb27SBarry Smith 3659a42bb27SBarry Smith #undef __FUNCT__ 36647c6ae99SBarry Smith #define __FUNCT__ "DMDestroy" 36747c6ae99SBarry Smith /*@ 368aa219208SBarry Smith DMDestroy - Destroys a vector packer or DMDA. 36947c6ae99SBarry Smith 37047c6ae99SBarry Smith Collective on DM 37147c6ae99SBarry Smith 37247c6ae99SBarry Smith Input Parameter: 37347c6ae99SBarry Smith . dm - the DM object to destroy 37447c6ae99SBarry Smith 37547c6ae99SBarry Smith Level: developer 37647c6ae99SBarry Smith 377e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 37847c6ae99SBarry Smith 37947c6ae99SBarry Smith @*/ 380fcfd50ebSBarry Smith PetscErrorCode DMDestroy(DM *dm) 38147c6ae99SBarry Smith { 382af122d2aSMatthew G Knepley PetscInt i, cnt = 0, f; 383dfe15315SJed Brown DMNamedVecLink nlink,nnext; 38447c6ae99SBarry Smith PetscErrorCode ierr; 38547c6ae99SBarry Smith 38647c6ae99SBarry Smith PetscFunctionBegin; 3876bf464f9SBarry Smith if (!*dm) PetscFunctionReturn(0); 3886bf464f9SBarry Smith PetscValidHeaderSpecific((*dm),DM_CLASSID,1); 38987e657c6SBarry Smith 390a546ed68SMatthew G. Knepley /* I think it makes sense to dump all attached things when you are destroyed, which also eliminates circular references */ 391a546ed68SMatthew G. Knepley for (f = 0; f < (*dm)->numFields; ++f) { 392decb47aaSMatthew G. Knepley ierr = PetscObjectCompose((PetscObject) (*dm)->fields[f], "pmat", NULL);CHKERRQ(ierr); 393decb47aaSMatthew G. Knepley ierr = PetscObjectCompose((PetscObject) (*dm)->fields[f], "nullspace", NULL);CHKERRQ(ierr); 394decb47aaSMatthew G. Knepley ierr = PetscObjectCompose((PetscObject) (*dm)->fields[f], "nearnullspace", NULL);CHKERRQ(ierr); 395a546ed68SMatthew G. Knepley } 39687e657c6SBarry Smith /* count all the circular references of DM and its contained Vecs */ 397732e2eb9SMatthew G Knepley for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 3988865f1eaSKarl Rupp if ((*dm)->localin[i]) cnt++; 3998865f1eaSKarl Rupp if ((*dm)->globalin[i]) cnt++; 400732e2eb9SMatthew G Knepley } 401dfe15315SJed Brown for (nlink=(*dm)->namedglobal; nlink; nlink=nlink->next) cnt++; 4022348bcf4SPeter Brune for (nlink=(*dm)->namedlocal; nlink; nlink=nlink->next) cnt++; 4032348bcf4SPeter Brune if ((*dm)->x) { 4042348bcf4SPeter Brune DM obj; 4052348bcf4SPeter Brune ierr = VecGetDM((*dm)->x, &obj);CHKERRQ(ierr); 4062348bcf4SPeter Brune if (obj == *dm) cnt++; 4072348bcf4SPeter Brune } 408732e2eb9SMatthew G Knepley 4096bf464f9SBarry Smith if (--((PetscObject)(*dm))->refct - cnt > 0) {*dm = 0; PetscFunctionReturn(0);} 410732e2eb9SMatthew G Knepley /* 411732e2eb9SMatthew G Knepley Need this test because the dm references the vectors that 412732e2eb9SMatthew G Knepley reference the dm, so destroying the dm calls destroy on the 413732e2eb9SMatthew G Knepley vectors that cause another destroy on the dm 414732e2eb9SMatthew G Knepley */ 4156bf464f9SBarry Smith if (((PetscObject)(*dm))->refct < 0) PetscFunctionReturn(0); 4166bf464f9SBarry Smith ((PetscObject) (*dm))->refct = 0; 417732e2eb9SMatthew G Knepley for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 4186bf464f9SBarry Smith if ((*dm)->localout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a local vector obtained with DMGetLocalVector()"); 4196bf464f9SBarry Smith ierr = VecDestroy(&(*dm)->localin[i]);CHKERRQ(ierr); 420732e2eb9SMatthew G Knepley } 421f490541aSPeter Brune nnext=(*dm)->namedglobal; 4220298fd71SBarry Smith (*dm)->namedglobal = NULL; 423f490541aSPeter Brune for (nlink=nnext; nlink; nlink=nnext) { /* Destroy the named vectors */ 4242348bcf4SPeter Brune nnext = nlink->next; 4252348bcf4SPeter 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); 4262348bcf4SPeter Brune ierr = PetscFree(nlink->name);CHKERRQ(ierr); 4272348bcf4SPeter Brune ierr = VecDestroy(&nlink->X);CHKERRQ(ierr); 4282348bcf4SPeter Brune ierr = PetscFree(nlink);CHKERRQ(ierr); 4292348bcf4SPeter Brune } 430f490541aSPeter Brune nnext=(*dm)->namedlocal; 4310298fd71SBarry Smith (*dm)->namedlocal = NULL; 432f490541aSPeter Brune for (nlink=nnext; nlink; nlink=nnext) { /* Destroy the named local vectors */ 433f490541aSPeter Brune nnext = nlink->next; 434f490541aSPeter 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); 435f490541aSPeter Brune ierr = PetscFree(nlink->name);CHKERRQ(ierr); 436f490541aSPeter Brune ierr = VecDestroy(&nlink->X);CHKERRQ(ierr); 437f490541aSPeter Brune ierr = PetscFree(nlink);CHKERRQ(ierr); 438f490541aSPeter Brune } 4392348bcf4SPeter Brune 440b17ce1afSJed Brown /* Destroy the list of hooks */ 441c833c3b5SJed Brown { 442c833c3b5SJed Brown DMCoarsenHookLink link,next; 443b17ce1afSJed Brown for (link=(*dm)->coarsenhook; link; link=next) { 444b17ce1afSJed Brown next = link->next; 445b17ce1afSJed Brown ierr = PetscFree(link);CHKERRQ(ierr); 446b17ce1afSJed Brown } 4470298fd71SBarry Smith (*dm)->coarsenhook = NULL; 448c833c3b5SJed Brown } 449c833c3b5SJed Brown { 450c833c3b5SJed Brown DMRefineHookLink link,next; 451c833c3b5SJed Brown for (link=(*dm)->refinehook; link; link=next) { 452c833c3b5SJed Brown next = link->next; 453c833c3b5SJed Brown ierr = PetscFree(link);CHKERRQ(ierr); 454c833c3b5SJed Brown } 4550298fd71SBarry Smith (*dm)->refinehook = NULL; 456c833c3b5SJed Brown } 457be081cd6SPeter Brune { 458be081cd6SPeter Brune DMSubDomainHookLink link,next; 459be081cd6SPeter Brune for (link=(*dm)->subdomainhook; link; link=next) { 460be081cd6SPeter Brune next = link->next; 461be081cd6SPeter Brune ierr = PetscFree(link);CHKERRQ(ierr); 462be081cd6SPeter Brune } 4630298fd71SBarry Smith (*dm)->subdomainhook = NULL; 464be081cd6SPeter Brune } 465baf369e7SPeter Brune { 466baf369e7SPeter Brune DMGlobalToLocalHookLink link,next; 467baf369e7SPeter Brune for (link=(*dm)->gtolhook; link; link=next) { 468baf369e7SPeter Brune next = link->next; 469baf369e7SPeter Brune ierr = PetscFree(link);CHKERRQ(ierr); 470baf369e7SPeter Brune } 4710298fd71SBarry Smith (*dm)->gtolhook = NULL; 472baf369e7SPeter Brune } 473aa1993deSMatthew G Knepley /* Destroy the work arrays */ 474aa1993deSMatthew G Knepley { 475aa1993deSMatthew G Knepley DMWorkLink link,next; 476aa1993deSMatthew G Knepley if ((*dm)->workout) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Work array still checked out"); 477aa1993deSMatthew G Knepley for (link=(*dm)->workin; link; link=next) { 478aa1993deSMatthew G Knepley next = link->next; 479aa1993deSMatthew G Knepley ierr = PetscFree(link->mem);CHKERRQ(ierr); 480aa1993deSMatthew G Knepley ierr = PetscFree(link);CHKERRQ(ierr); 481aa1993deSMatthew G Knepley } 4820298fd71SBarry Smith (*dm)->workin = NULL; 483aa1993deSMatthew G Knepley } 484b17ce1afSJed Brown 48552536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmksp);CHKERRQ(ierr); 48652536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmsnes);CHKERRQ(ierr); 48752536dc3SBarry Smith ierr = PetscObjectDestroy(&(*dm)->dmts);CHKERRQ(ierr); 48852536dc3SBarry Smith 4891a266240SBarry Smith if ((*dm)->ctx && (*dm)->ctxdestroy) { 4901a266240SBarry Smith ierr = (*(*dm)->ctxdestroy)(&(*dm)->ctx);CHKERRQ(ierr); 4911a266240SBarry Smith } 49287e657c6SBarry Smith ierr = VecDestroy(&(*dm)->x);CHKERRQ(ierr); 49371cd77b2SBarry Smith ierr = MatFDColoringDestroy(&(*dm)->fd);CHKERRQ(ierr); 4944dcab191SBarry Smith ierr = DMClearGlobalVectors(*dm);CHKERRQ(ierr); 4956bf464f9SBarry Smith ierr = ISLocalToGlobalMappingDestroy(&(*dm)->ltogmap);CHKERRQ(ierr); 4966bf464f9SBarry Smith ierr = ISLocalToGlobalMappingDestroy(&(*dm)->ltogmapb);CHKERRQ(ierr); 4976bf464f9SBarry Smith ierr = PetscFree((*dm)->vectype);CHKERRQ(ierr); 498073dac72SJed Brown ierr = PetscFree((*dm)->mattype);CHKERRQ(ierr); 49988ed4aceSMatthew G Knepley 50088ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&(*dm)->defaultSection);CHKERRQ(ierr); 50188ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&(*dm)->defaultGlobalSection);CHKERRQ(ierr); 5028b1ab98fSJed Brown ierr = PetscLayoutDestroy(&(*dm)->map);CHKERRQ(ierr); 50388ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&(*dm)->sf);CHKERRQ(ierr); 50488ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&(*dm)->defaultSF);CHKERRQ(ierr); 505af122d2aSMatthew G Knepley 5066636e97aSMatthew G Knepley ierr = DMDestroy(&(*dm)->coordinateDM);CHKERRQ(ierr); 5076636e97aSMatthew G Knepley ierr = VecDestroy(&(*dm)->coordinates);CHKERRQ(ierr); 5086636e97aSMatthew G Knepley ierr = VecDestroy(&(*dm)->coordinatesLocal);CHKERRQ(ierr); 5096636e97aSMatthew G Knepley 510af122d2aSMatthew G Knepley for (f = 0; f < (*dm)->numFields; ++f) { 511decb47aaSMatthew G. Knepley ierr = PetscObjectDestroy((PetscObject *) &(*dm)->fields[f]);CHKERRQ(ierr); 512af122d2aSMatthew G Knepley } 513af122d2aSMatthew G Knepley ierr = PetscFree((*dm)->fields);CHKERRQ(ierr); 514e04113cfSBarry Smith /* if memory was published with SAWs then destroy it */ 515e04113cfSBarry Smith ierr = PetscObjectSAWsViewOff((PetscObject)*dm);CHKERRQ(ierr); 516732e2eb9SMatthew G Knepley 5176bf464f9SBarry Smith ierr = (*(*dm)->ops->destroy)(*dm);CHKERRQ(ierr); 518435a35e8SMatthew G Knepley /* We do not destroy (*dm)->data here so that we can reference count backend objects */ 519732e2eb9SMatthew G Knepley ierr = PetscHeaderDestroy(dm);CHKERRQ(ierr); 52047c6ae99SBarry Smith PetscFunctionReturn(0); 52147c6ae99SBarry Smith } 52247c6ae99SBarry Smith 52347c6ae99SBarry Smith #undef __FUNCT__ 524d7bf68aeSBarry Smith #define __FUNCT__ "DMSetUp" 525d7bf68aeSBarry Smith /*@ 526d7bf68aeSBarry Smith DMSetUp - sets up the data structures inside a DM object 527d7bf68aeSBarry Smith 528d7bf68aeSBarry Smith Collective on DM 529d7bf68aeSBarry Smith 530d7bf68aeSBarry Smith Input Parameter: 531d7bf68aeSBarry Smith . dm - the DM object to setup 532d7bf68aeSBarry Smith 533d7bf68aeSBarry Smith Level: developer 534d7bf68aeSBarry Smith 535e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 536d7bf68aeSBarry Smith 537d7bf68aeSBarry Smith @*/ 5387087cfbeSBarry Smith PetscErrorCode DMSetUp(DM dm) 539d7bf68aeSBarry Smith { 540d7bf68aeSBarry Smith PetscErrorCode ierr; 541d7bf68aeSBarry Smith 542d7bf68aeSBarry Smith PetscFunctionBegin; 543171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5448387afaaSJed Brown if (dm->setupcalled) PetscFunctionReturn(0); 545d7bf68aeSBarry Smith if (dm->ops->setup) { 546d7bf68aeSBarry Smith ierr = (*dm->ops->setup)(dm);CHKERRQ(ierr); 547d7bf68aeSBarry Smith } 5488387afaaSJed Brown dm->setupcalled = PETSC_TRUE; 549d7bf68aeSBarry Smith PetscFunctionReturn(0); 550d7bf68aeSBarry Smith } 551d7bf68aeSBarry Smith 552d7bf68aeSBarry Smith #undef __FUNCT__ 553d7bf68aeSBarry Smith #define __FUNCT__ "DMSetFromOptions" 554d7bf68aeSBarry Smith /*@ 555d7bf68aeSBarry Smith DMSetFromOptions - sets parameters in a DM from the options database 556d7bf68aeSBarry Smith 557d7bf68aeSBarry Smith Collective on DM 558d7bf68aeSBarry Smith 559d7bf68aeSBarry Smith Input Parameter: 560d7bf68aeSBarry Smith . dm - the DM object to set options for 561d7bf68aeSBarry Smith 562732e2eb9SMatthew G Knepley Options Database: 563dd85299cSBarry Smith + -dm_preallocate_only: Only preallocate the matrix for DMCreateMatrix(), but do not fill it with zeros 564dd85299cSBarry Smith . -dm_vec_type <type> type of vector to create inside DM 565171400e9SBarry Smith . -dm_mat_type <type> type of matrix to create inside DM 566171400e9SBarry Smith - -dm_coloring_type <global or ghosted> 567732e2eb9SMatthew G Knepley 568d7bf68aeSBarry Smith Level: developer 569d7bf68aeSBarry Smith 570e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 571d7bf68aeSBarry Smith 572d7bf68aeSBarry Smith @*/ 5737087cfbeSBarry Smith PetscErrorCode DMSetFromOptions(DM dm) 574d7bf68aeSBarry Smith { 5757781c08eSBarry Smith char typeName[256]; 576ca266f36SBarry Smith PetscBool flg; 577d7bf68aeSBarry Smith PetscErrorCode ierr; 578d7bf68aeSBarry Smith 579d7bf68aeSBarry Smith PetscFunctionBegin; 580171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5813194b578SJed Brown ierr = PetscObjectOptionsBegin((PetscObject)dm);CHKERRQ(ierr); 5820298fd71SBarry 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); 583a264d7a6SBarry Smith ierr = PetscOptionsFList("-dm_vec_type","Vector type used for created vectors","DMSetVecType",VecList,dm->vectype,typeName,256,&flg);CHKERRQ(ierr); 584f9ba7244SBarry Smith if (flg) { 585f9ba7244SBarry Smith ierr = DMSetVecType(dm,typeName);CHKERRQ(ierr); 586f9ba7244SBarry Smith } 587a264d7a6SBarry 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); 588073dac72SJed Brown if (flg) { 589521d9a4cSLisandro Dalcin ierr = DMSetMatType(dm,typeName);CHKERRQ(ierr); 590073dac72SJed Brown } 5910298fd71SBarry Smith ierr = PetscOptionsEnum("-dm_is_coloring_type","Global or local coloring of Jacobian","ISColoringType",ISColoringTypes,(PetscEnum)dm->coloringtype,(PetscEnum*)&dm->coloringtype,NULL);CHKERRQ(ierr); 592f9ba7244SBarry Smith if (dm->ops->setfromoptions) { 593f9ba7244SBarry Smith ierr = (*dm->ops->setfromoptions)(dm);CHKERRQ(ierr); 594f9ba7244SBarry Smith } 595f9ba7244SBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 596f9ba7244SBarry Smith ierr = PetscObjectProcessOptionsHandlers((PetscObject) dm);CHKERRQ(ierr); 59782fcb398SMatthew G Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 598d7bf68aeSBarry Smith PetscFunctionReturn(0); 599d7bf68aeSBarry Smith } 600d7bf68aeSBarry Smith 601d7bf68aeSBarry Smith #undef __FUNCT__ 60247c6ae99SBarry Smith #define __FUNCT__ "DMView" 603fc9bc008SSatish Balay /*@C 604aa219208SBarry Smith DMView - Views a vector packer or DMDA. 60547c6ae99SBarry Smith 60647c6ae99SBarry Smith Collective on DM 60747c6ae99SBarry Smith 60847c6ae99SBarry Smith Input Parameter: 60947c6ae99SBarry Smith + dm - the DM object to view 61047c6ae99SBarry Smith - v - the viewer 61147c6ae99SBarry Smith 61247c6ae99SBarry Smith Level: developer 61347c6ae99SBarry Smith 614e727c939SJed Brown .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 61547c6ae99SBarry Smith 61647c6ae99SBarry Smith @*/ 6177087cfbeSBarry Smith PetscErrorCode DMView(DM dm,PetscViewer v) 61847c6ae99SBarry Smith { 61947c6ae99SBarry Smith PetscErrorCode ierr; 62032c0f0efSBarry Smith PetscBool isbinary; 62147c6ae99SBarry Smith 62247c6ae99SBarry Smith PetscFunctionBegin; 623171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 6243014e516SBarry Smith if (!v) { 625ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)dm),&v);CHKERRQ(ierr); 6263014e516SBarry Smith } 627*98c3331eSBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)dm,v);CHKERRQ(ierr); 62832c0f0efSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); 62932c0f0efSBarry Smith if (isbinary) { 63055849f57SBarry Smith PetscInt classid = DM_FILE_CLASSID; 63132c0f0efSBarry Smith char type[256]; 63232c0f0efSBarry Smith 63332c0f0efSBarry Smith ierr = PetscViewerBinaryWrite(v,&classid,1,PETSC_INT,PETSC_FALSE);CHKERRQ(ierr); 63432c0f0efSBarry Smith ierr = PetscStrncpy(type,((PetscObject)dm)->type_name,256);CHKERRQ(ierr); 63532c0f0efSBarry Smith ierr = PetscViewerBinaryWrite(v,type,256,PETSC_CHAR,PETSC_FALSE);CHKERRQ(ierr); 63632c0f0efSBarry Smith } 6370c010503SBarry Smith if (dm->ops->view) { 6380c010503SBarry Smith ierr = (*dm->ops->view)(dm,v);CHKERRQ(ierr); 63947c6ae99SBarry Smith } 64047c6ae99SBarry Smith PetscFunctionReturn(0); 64147c6ae99SBarry Smith } 64247c6ae99SBarry Smith 64347c6ae99SBarry Smith #undef __FUNCT__ 64447c6ae99SBarry Smith #define __FUNCT__ "DMCreateGlobalVector" 64547c6ae99SBarry Smith /*@ 646aa219208SBarry Smith DMCreateGlobalVector - Creates a global vector from a DMDA or DMComposite object 64747c6ae99SBarry Smith 64847c6ae99SBarry Smith Collective on DM 64947c6ae99SBarry Smith 65047c6ae99SBarry Smith Input Parameter: 65147c6ae99SBarry Smith . dm - the DM object 65247c6ae99SBarry Smith 65347c6ae99SBarry Smith Output Parameter: 65447c6ae99SBarry Smith . vec - the global vector 65547c6ae99SBarry Smith 656073dac72SJed Brown Level: beginner 65747c6ae99SBarry Smith 658e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 65947c6ae99SBarry Smith 66047c6ae99SBarry Smith @*/ 6617087cfbeSBarry Smith PetscErrorCode DMCreateGlobalVector(DM dm,Vec *vec) 66247c6ae99SBarry Smith { 66347c6ae99SBarry Smith PetscErrorCode ierr; 66447c6ae99SBarry Smith 66547c6ae99SBarry Smith PetscFunctionBegin; 666171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 66747c6ae99SBarry Smith ierr = (*dm->ops->createglobalvector)(dm,vec);CHKERRQ(ierr); 66847c6ae99SBarry Smith PetscFunctionReturn(0); 66947c6ae99SBarry Smith } 67047c6ae99SBarry Smith 67147c6ae99SBarry Smith #undef __FUNCT__ 67247c6ae99SBarry Smith #define __FUNCT__ "DMCreateLocalVector" 67347c6ae99SBarry Smith /*@ 674aa219208SBarry Smith DMCreateLocalVector - Creates a local vector from a DMDA or DMComposite object 67547c6ae99SBarry Smith 67647c6ae99SBarry Smith Not Collective 67747c6ae99SBarry Smith 67847c6ae99SBarry Smith Input Parameter: 67947c6ae99SBarry Smith . dm - the DM object 68047c6ae99SBarry Smith 68147c6ae99SBarry Smith Output Parameter: 68247c6ae99SBarry Smith . vec - the local vector 68347c6ae99SBarry Smith 684073dac72SJed Brown Level: beginner 68547c6ae99SBarry Smith 686e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 68747c6ae99SBarry Smith 68847c6ae99SBarry Smith @*/ 6897087cfbeSBarry Smith PetscErrorCode DMCreateLocalVector(DM dm,Vec *vec) 69047c6ae99SBarry Smith { 69147c6ae99SBarry Smith PetscErrorCode ierr; 69247c6ae99SBarry Smith 69347c6ae99SBarry Smith PetscFunctionBegin; 694171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 69547c6ae99SBarry Smith ierr = (*dm->ops->createlocalvector)(dm,vec);CHKERRQ(ierr); 69647c6ae99SBarry Smith PetscFunctionReturn(0); 69747c6ae99SBarry Smith } 69847c6ae99SBarry Smith 69947c6ae99SBarry Smith #undef __FUNCT__ 7001411c6eeSJed Brown #define __FUNCT__ "DMGetLocalToGlobalMapping" 7011411c6eeSJed Brown /*@ 7021411c6eeSJed Brown DMGetLocalToGlobalMapping - Accesses the local-to-global mapping in a DM. 7031411c6eeSJed Brown 7041411c6eeSJed Brown Collective on DM 7051411c6eeSJed Brown 7061411c6eeSJed Brown Input Parameter: 7071411c6eeSJed Brown . dm - the DM that provides the mapping 7081411c6eeSJed Brown 7091411c6eeSJed Brown Output Parameter: 7101411c6eeSJed Brown . ltog - the mapping 7111411c6eeSJed Brown 7121411c6eeSJed Brown Level: intermediate 7131411c6eeSJed Brown 7141411c6eeSJed Brown Notes: 7151411c6eeSJed Brown This mapping can then be used by VecSetLocalToGlobalMapping() or 7161411c6eeSJed Brown MatSetLocalToGlobalMapping(). 7171411c6eeSJed Brown 7181411c6eeSJed Brown .seealso: DMCreateLocalVector(), DMGetLocalToGlobalMappingBlock() 7191411c6eeSJed Brown @*/ 7207087cfbeSBarry Smith PetscErrorCode DMGetLocalToGlobalMapping(DM dm,ISLocalToGlobalMapping *ltog) 7211411c6eeSJed Brown { 7221411c6eeSJed Brown PetscErrorCode ierr; 7231411c6eeSJed Brown 7241411c6eeSJed Brown PetscFunctionBegin; 7251411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7261411c6eeSJed Brown PetscValidPointer(ltog,2); 7271411c6eeSJed Brown if (!dm->ltogmap) { 72837d0c07bSMatthew G Knepley PetscSection section, sectionGlobal; 72937d0c07bSMatthew G Knepley 73037d0c07bSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 73137d0c07bSMatthew G Knepley if (section) { 73237d0c07bSMatthew G Knepley PetscInt *ltog; 73337d0c07bSMatthew G Knepley PetscInt pStart, pEnd, size, p, l; 73437d0c07bSMatthew G Knepley 73537d0c07bSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 73637d0c07bSMatthew G Knepley ierr = PetscSectionGetChart(section, &pStart, &pEnd);CHKERRQ(ierr); 73737d0c07bSMatthew G Knepley ierr = PetscSectionGetStorageSize(section, &size);CHKERRQ(ierr); 738785e854fSJed Brown ierr = PetscMalloc1(size, <og);CHKERRQ(ierr); /* We want the local+overlap size */ 73937d0c07bSMatthew G Knepley for (p = pStart, l = 0; p < pEnd; ++p) { 74037d0c07bSMatthew G Knepley PetscInt dof, off, c; 74137d0c07bSMatthew G Knepley 74237d0c07bSMatthew G Knepley /* Should probably use constrained dofs */ 74337d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(section, p, &dof);CHKERRQ(ierr); 74437d0c07bSMatthew G Knepley ierr = PetscSectionGetOffset(sectionGlobal, p, &off);CHKERRQ(ierr); 74537d0c07bSMatthew G Knepley for (c = 0; c < dof; ++c, ++l) { 74637d0c07bSMatthew G Knepley ltog[l] = off+c; 74737d0c07bSMatthew G Knepley } 74837d0c07bSMatthew G Knepley } 74937d0c07bSMatthew G Knepley ierr = ISLocalToGlobalMappingCreate(PETSC_COMM_SELF, size, ltog, PETSC_OWN_POINTER, &dm->ltogmap);CHKERRQ(ierr); 7503bb1ff40SBarry Smith ierr = PetscLogObjectParent((PetscObject)dm, (PetscObject)dm->ltogmap);CHKERRQ(ierr); 75137d0c07bSMatthew G Knepley } else { 752184d77edSJed Brown if (!dm->ops->getlocaltoglobalmapping) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM can not create LocalToGlobalMapping"); 753184d77edSJed Brown ierr = (*dm->ops->getlocaltoglobalmapping)(dm);CHKERRQ(ierr); 7541411c6eeSJed Brown } 75537d0c07bSMatthew G Knepley } 7561411c6eeSJed Brown *ltog = dm->ltogmap; 7571411c6eeSJed Brown PetscFunctionReturn(0); 7581411c6eeSJed Brown } 7591411c6eeSJed Brown 7601411c6eeSJed Brown #undef __FUNCT__ 7611411c6eeSJed Brown #define __FUNCT__ "DMGetLocalToGlobalMappingBlock" 7621411c6eeSJed Brown /*@ 7631411c6eeSJed Brown DMGetLocalToGlobalMappingBlock - Accesses the blocked local-to-global mapping in a DM. 7641411c6eeSJed Brown 7651411c6eeSJed Brown Collective on DM 7661411c6eeSJed Brown 7671411c6eeSJed Brown Input Parameter: 7681411c6eeSJed Brown . da - the distributed array that provides the mapping 7691411c6eeSJed Brown 7701411c6eeSJed Brown Output Parameter: 7711411c6eeSJed Brown . ltog - the block mapping 7721411c6eeSJed Brown 7731411c6eeSJed Brown Level: intermediate 7741411c6eeSJed Brown 7751411c6eeSJed Brown Notes: 7761411c6eeSJed Brown This mapping can then be used by VecSetLocalToGlobalMappingBlock() or 7771411c6eeSJed Brown MatSetLocalToGlobalMappingBlock(). 7781411c6eeSJed Brown 7791411c6eeSJed Brown .seealso: DMCreateLocalVector(), DMGetLocalToGlobalMapping(), DMGetBlockSize(), VecSetBlockSize(), MatSetBlockSize() 7801411c6eeSJed Brown @*/ 7817087cfbeSBarry Smith PetscErrorCode DMGetLocalToGlobalMappingBlock(DM dm,ISLocalToGlobalMapping *ltog) 7821411c6eeSJed Brown { 7831411c6eeSJed Brown PetscErrorCode ierr; 7841411c6eeSJed Brown 7851411c6eeSJed Brown PetscFunctionBegin; 7861411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 7871411c6eeSJed Brown PetscValidPointer(ltog,2); 7881411c6eeSJed Brown if (!dm->ltogmapb) { 7891411c6eeSJed Brown PetscInt bs; 7901411c6eeSJed Brown ierr = DMGetBlockSize(dm,&bs);CHKERRQ(ierr); 7911411c6eeSJed Brown if (bs > 1) { 792184d77edSJed Brown if (!dm->ops->getlocaltoglobalmappingblock) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"DM can not create LocalToGlobalMappingBlock"); 793184d77edSJed Brown ierr = (*dm->ops->getlocaltoglobalmappingblock)(dm);CHKERRQ(ierr); 7941411c6eeSJed Brown } else { 7951411c6eeSJed Brown ierr = DMGetLocalToGlobalMapping(dm,&dm->ltogmapb);CHKERRQ(ierr); 7961411c6eeSJed Brown ierr = PetscObjectReference((PetscObject)dm->ltogmapb);CHKERRQ(ierr); 7971411c6eeSJed Brown } 7981411c6eeSJed Brown } 7991411c6eeSJed Brown *ltog = dm->ltogmapb; 8001411c6eeSJed Brown PetscFunctionReturn(0); 8011411c6eeSJed Brown } 8021411c6eeSJed Brown 8031411c6eeSJed Brown #undef __FUNCT__ 8041411c6eeSJed Brown #define __FUNCT__ "DMGetBlockSize" 8051411c6eeSJed Brown /*@ 8061411c6eeSJed Brown DMGetBlockSize - Gets the inherent block size associated with a DM 8071411c6eeSJed Brown 8081411c6eeSJed Brown Not Collective 8091411c6eeSJed Brown 8101411c6eeSJed Brown Input Parameter: 8111411c6eeSJed Brown . dm - the DM with block structure 8121411c6eeSJed Brown 8131411c6eeSJed Brown Output Parameter: 8141411c6eeSJed Brown . bs - the block size, 1 implies no exploitable block structure 8151411c6eeSJed Brown 8161411c6eeSJed Brown Level: intermediate 8171411c6eeSJed Brown 8181411c6eeSJed Brown .seealso: ISCreateBlock(), VecSetBlockSize(), MatSetBlockSize(), DMGetLocalToGlobalMappingBlock() 8191411c6eeSJed Brown @*/ 8207087cfbeSBarry Smith PetscErrorCode DMGetBlockSize(DM dm,PetscInt *bs) 8211411c6eeSJed Brown { 8221411c6eeSJed Brown PetscFunctionBegin; 8231411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8241411c6eeSJed Brown PetscValidPointer(bs,2); 8251411c6eeSJed 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"); 8261411c6eeSJed Brown *bs = dm->bs; 8271411c6eeSJed Brown PetscFunctionReturn(0); 8281411c6eeSJed Brown } 8291411c6eeSJed Brown 8301411c6eeSJed Brown #undef __FUNCT__ 831e727c939SJed Brown #define __FUNCT__ "DMCreateInterpolation" 83247c6ae99SBarry Smith /*@ 833e727c939SJed Brown DMCreateInterpolation - Gets interpolation 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 + mat - the interpolation 84347c6ae99SBarry Smith - vec - the scaling (optional) 84447c6ae99SBarry Smith 84547c6ae99SBarry Smith Level: developer 84647c6ae99SBarry Smith 84785afcc9aSBarry 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 84885afcc9aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the interpolation. 849d52bd9f3SBarry Smith 8501f588964SMatthew G Knepley For DMDA objects you can use this interpolation (more precisely the interpolation from the DMGetCoordinateDM()) to interpolate the mesh coordinate vectors 851d52bd9f3SBarry Smith EXCEPT in the periodic case where it does not make sense since the coordinate vectors are not periodic. 85285afcc9aSBarry Smith 85385afcc9aSBarry Smith 854e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMRefine(), DMCoarsen() 85547c6ae99SBarry Smith 85647c6ae99SBarry Smith @*/ 857e727c939SJed Brown PetscErrorCode DMCreateInterpolation(DM dm1,DM dm2,Mat *mat,Vec *vec) 85847c6ae99SBarry Smith { 85947c6ae99SBarry Smith PetscErrorCode ierr; 86047c6ae99SBarry Smith 86147c6ae99SBarry Smith PetscFunctionBegin; 862171400e9SBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 863171400e9SBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 86425296bd5SBarry Smith ierr = (*dm1->ops->createinterpolation)(dm1,dm2,mat,vec);CHKERRQ(ierr); 86547c6ae99SBarry Smith PetscFunctionReturn(0); 86647c6ae99SBarry Smith } 86747c6ae99SBarry Smith 86847c6ae99SBarry Smith #undef __FUNCT__ 869e727c939SJed Brown #define __FUNCT__ "DMCreateInjection" 87047c6ae99SBarry Smith /*@ 871e727c939SJed Brown DMCreateInjection - Gets injection matrix between two DMDA or DMComposite objects 87247c6ae99SBarry Smith 87347c6ae99SBarry Smith Collective on DM 87447c6ae99SBarry Smith 87547c6ae99SBarry Smith Input Parameter: 87647c6ae99SBarry Smith + dm1 - the DM object 87747c6ae99SBarry Smith - dm2 - the second, finer DM object 87847c6ae99SBarry Smith 87947c6ae99SBarry Smith Output Parameter: 88047c6ae99SBarry Smith . ctx - the injection 88147c6ae99SBarry Smith 88247c6ae99SBarry Smith Level: developer 88347c6ae99SBarry Smith 88485afcc9aSBarry 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 88585afcc9aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the injection. 88685afcc9aSBarry Smith 887e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMCreateInterpolation() 88847c6ae99SBarry Smith 88947c6ae99SBarry Smith @*/ 890e727c939SJed Brown PetscErrorCode DMCreateInjection(DM dm1,DM dm2,VecScatter *ctx) 89147c6ae99SBarry Smith { 89247c6ae99SBarry Smith PetscErrorCode ierr; 89347c6ae99SBarry Smith 89447c6ae99SBarry Smith PetscFunctionBegin; 895171400e9SBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 896171400e9SBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 89747c6ae99SBarry Smith ierr = (*dm1->ops->getinjection)(dm1,dm2,ctx);CHKERRQ(ierr); 89847c6ae99SBarry Smith PetscFunctionReturn(0); 89947c6ae99SBarry Smith } 90047c6ae99SBarry Smith 90147c6ae99SBarry Smith #undef __FUNCT__ 902e727c939SJed Brown #define __FUNCT__ "DMCreateColoring" 903b412c318SBarry Smith /*@ 904b412c318SBarry Smith DMCreateColoring - Gets coloring for a DM 90547c6ae99SBarry Smith 90647c6ae99SBarry Smith Collective on DM 90747c6ae99SBarry Smith 90847c6ae99SBarry Smith Input Parameter: 90947c6ae99SBarry Smith + dm - the DM object 910b412c318SBarry Smith - ctype - IS_COLORING_GHOSTED or IS_COLORING_GLOBAL 91147c6ae99SBarry Smith 91247c6ae99SBarry Smith Output Parameter: 91347c6ae99SBarry Smith . coloring - the coloring 91447c6ae99SBarry Smith 91547c6ae99SBarry Smith Level: developer 91647c6ae99SBarry Smith 917b412c318SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateMatrix(), DMSetMatType() 91847c6ae99SBarry Smith 919aab9d709SJed Brown @*/ 920b412c318SBarry Smith PetscErrorCode DMCreateColoring(DM dm,ISColoringType ctype,ISColoring *coloring) 92147c6ae99SBarry Smith { 92247c6ae99SBarry Smith PetscErrorCode ierr; 92347c6ae99SBarry Smith 92447c6ae99SBarry Smith PetscFunctionBegin; 925171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 926ce94432eSBarry Smith if (!dm->ops->getcoloring) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No coloring for this type of DM yet"); 927b412c318SBarry Smith ierr = (*dm->ops->getcoloring)(dm,ctype,coloring);CHKERRQ(ierr); 92847c6ae99SBarry Smith PetscFunctionReturn(0); 92947c6ae99SBarry Smith } 93047c6ae99SBarry Smith 93147c6ae99SBarry Smith #undef __FUNCT__ 932950540a4SJed Brown #define __FUNCT__ "DMCreateMatrix" 933b412c318SBarry Smith /*@ 934950540a4SJed Brown DMCreateMatrix - Gets empty Jacobian for a DMDA or DMComposite 93547c6ae99SBarry Smith 93647c6ae99SBarry Smith Collective on DM 93747c6ae99SBarry Smith 93847c6ae99SBarry Smith Input Parameter: 939b412c318SBarry Smith . dm - the DM object 94047c6ae99SBarry Smith 94147c6ae99SBarry Smith Output Parameter: 94247c6ae99SBarry Smith . mat - the empty Jacobian 94347c6ae99SBarry Smith 944073dac72SJed Brown Level: beginner 94547c6ae99SBarry Smith 94694013140SBarry Smith Notes: This properly preallocates the number of nonzeros in the sparse matrix so you 94794013140SBarry Smith do not need to do it yourself. 94894013140SBarry Smith 94994013140SBarry Smith By default it also sets the nonzero structure and puts in the zero entries. To prevent setting 950aa219208SBarry Smith the nonzero pattern call DMDASetMatPreallocateOnly() 95194013140SBarry Smith 95294013140SBarry 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 95394013140SBarry Smith internally by PETSc. 95494013140SBarry Smith 95594013140SBarry Smith For structured grid problems, in general it is easiest to use MatSetValuesStencil() or MatSetValuesLocal() to put values into the matrix because MatSetValues() requires 956aa219208SBarry Smith the indices for the global numbering for DMDAs which is complicated. 95794013140SBarry Smith 958b412c318SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMSetMatType() 95947c6ae99SBarry Smith 960aab9d709SJed Brown @*/ 961b412c318SBarry Smith PetscErrorCode DMCreateMatrix(DM dm,Mat *mat) 96247c6ae99SBarry Smith { 96347c6ae99SBarry Smith PetscErrorCode ierr; 96447c6ae99SBarry Smith 96547c6ae99SBarry Smith PetscFunctionBegin; 966171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 967607a6623SBarry Smith ierr = MatInitializePackage();CHKERRQ(ierr); 968c7b7c8a4SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 969c7b7c8a4SJed Brown PetscValidPointer(mat,3); 970b412c318SBarry Smith ierr = (*dm->ops->creatematrix)(dm,mat);CHKERRQ(ierr); 97147c6ae99SBarry Smith PetscFunctionReturn(0); 97247c6ae99SBarry Smith } 97347c6ae99SBarry Smith 97447c6ae99SBarry Smith #undef __FUNCT__ 975732e2eb9SMatthew G Knepley #define __FUNCT__ "DMSetMatrixPreallocateOnly" 976732e2eb9SMatthew G Knepley /*@ 977950540a4SJed Brown DMSetMatrixPreallocateOnly - When DMCreateMatrix() is called the matrix will be properly 978732e2eb9SMatthew G Knepley preallocated but the nonzero structure and zero values will not be set. 979732e2eb9SMatthew G Knepley 980732e2eb9SMatthew G Knepley Logically Collective on DMDA 981732e2eb9SMatthew G Knepley 982732e2eb9SMatthew G Knepley Input Parameter: 983732e2eb9SMatthew G Knepley + dm - the DM 984732e2eb9SMatthew G Knepley - only - PETSC_TRUE if only want preallocation 985732e2eb9SMatthew G Knepley 986732e2eb9SMatthew G Knepley Level: developer 987950540a4SJed Brown .seealso DMCreateMatrix() 988732e2eb9SMatthew G Knepley @*/ 989732e2eb9SMatthew G Knepley PetscErrorCode DMSetMatrixPreallocateOnly(DM dm, PetscBool only) 990732e2eb9SMatthew G Knepley { 991732e2eb9SMatthew G Knepley PetscFunctionBegin; 992732e2eb9SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 993732e2eb9SMatthew G Knepley dm->prealloc_only = only; 994732e2eb9SMatthew G Knepley PetscFunctionReturn(0); 995732e2eb9SMatthew G Knepley } 996732e2eb9SMatthew G Knepley 997732e2eb9SMatthew G Knepley #undef __FUNCT__ 998a89ea682SMatthew G Knepley #define __FUNCT__ "DMGetWorkArray" 999a89ea682SMatthew G Knepley /*@C 1000aa1993deSMatthew G Knepley DMGetWorkArray - Gets a work array guaranteed to be at least the input size, restore with DMRestoreWorkArray() 1001a89ea682SMatthew G Knepley 1002a89ea682SMatthew G Knepley Not Collective 1003a89ea682SMatthew G Knepley 1004a89ea682SMatthew G Knepley Input Parameters: 1005a89ea682SMatthew G Knepley + dm - the DM object 1006aa1993deSMatthew G Knepley . count - The minium size 1007aa1993deSMatthew G Knepley - dtype - data type (PETSC_REAL, PETSC_SCALAR, PETSC_INT) 1008a89ea682SMatthew G Knepley 1009a89ea682SMatthew G Knepley Output Parameter: 1010a89ea682SMatthew G Knepley . array - the work array 1011a89ea682SMatthew G Knepley 1012a89ea682SMatthew G Knepley Level: developer 1013a89ea682SMatthew G Knepley 1014a89ea682SMatthew G Knepley .seealso DMDestroy(), DMCreate() 1015a89ea682SMatthew G Knepley @*/ 1016aa1993deSMatthew G Knepley PetscErrorCode DMGetWorkArray(DM dm,PetscInt count,PetscDataType dtype,void *mem) 1017a89ea682SMatthew G Knepley { 1018a89ea682SMatthew G Knepley PetscErrorCode ierr; 1019aa1993deSMatthew G Knepley DMWorkLink link; 1020aa1993deSMatthew G Knepley size_t size; 1021a89ea682SMatthew G Knepley 1022a89ea682SMatthew G Knepley PetscFunctionBegin; 1023a89ea682SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1024aa1993deSMatthew G Knepley PetscValidPointer(mem,4); 1025aa1993deSMatthew G Knepley if (dm->workin) { 1026aa1993deSMatthew G Knepley link = dm->workin; 1027aa1993deSMatthew G Knepley dm->workin = dm->workin->next; 1028aa1993deSMatthew G Knepley } else { 1029b00a9115SJed Brown ierr = PetscNewLog(dm,&link);CHKERRQ(ierr); 1030a89ea682SMatthew G Knepley } 1031aa1993deSMatthew G Knepley ierr = PetscDataTypeGetSize(dtype,&size);CHKERRQ(ierr); 1032aa1993deSMatthew G Knepley if (size*count > link->bytes) { 1033aa1993deSMatthew G Knepley ierr = PetscFree(link->mem);CHKERRQ(ierr); 1034aa1993deSMatthew G Knepley ierr = PetscMalloc(size*count,&link->mem);CHKERRQ(ierr); 1035aa1993deSMatthew G Knepley link->bytes = size*count; 1036aa1993deSMatthew G Knepley } 1037aa1993deSMatthew G Knepley link->next = dm->workout; 1038aa1993deSMatthew G Knepley dm->workout = link; 1039aa1993deSMatthew G Knepley *(void**)mem = link->mem; 1040a89ea682SMatthew G Knepley PetscFunctionReturn(0); 1041a89ea682SMatthew G Knepley } 1042a89ea682SMatthew G Knepley 1043aa1993deSMatthew G Knepley #undef __FUNCT__ 1044aa1993deSMatthew G Knepley #define __FUNCT__ "DMRestoreWorkArray" 1045aa1993deSMatthew G Knepley /*@C 1046aa1993deSMatthew G Knepley DMRestoreWorkArray - Restores a work array guaranteed to be at least the input size, restore with DMRestoreWorkArray() 1047aa1993deSMatthew G Knepley 1048aa1993deSMatthew G Knepley Not Collective 1049aa1993deSMatthew G Knepley 1050aa1993deSMatthew G Knepley Input Parameters: 1051aa1993deSMatthew G Knepley + dm - the DM object 1052aa1993deSMatthew G Knepley . count - The minium size 1053aa1993deSMatthew G Knepley - dtype - data type (PETSC_REAL, PETSC_SCALAR, PETSC_INT) 1054aa1993deSMatthew G Knepley 1055aa1993deSMatthew G Knepley Output Parameter: 1056aa1993deSMatthew G Knepley . array - the work array 1057aa1993deSMatthew G Knepley 1058aa1993deSMatthew G Knepley Level: developer 1059aa1993deSMatthew G Knepley 1060aa1993deSMatthew G Knepley .seealso DMDestroy(), DMCreate() 1061aa1993deSMatthew G Knepley @*/ 1062aa1993deSMatthew G Knepley PetscErrorCode DMRestoreWorkArray(DM dm,PetscInt count,PetscDataType dtype,void *mem) 1063aa1993deSMatthew G Knepley { 1064aa1993deSMatthew G Knepley DMWorkLink *p,link; 1065aa1993deSMatthew G Knepley 1066aa1993deSMatthew G Knepley PetscFunctionBegin; 1067aa1993deSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1068aa1993deSMatthew G Knepley PetscValidPointer(mem,4); 1069aa1993deSMatthew G Knepley for (p=&dm->workout; (link=*p); p=&link->next) { 1070aa1993deSMatthew G Knepley if (link->mem == *(void**)mem) { 1071aa1993deSMatthew G Knepley *p = link->next; 1072aa1993deSMatthew G Knepley link->next = dm->workin; 1073aa1993deSMatthew G Knepley dm->workin = link; 10740298fd71SBarry Smith *(void**)mem = NULL; 1075aa1993deSMatthew G Knepley PetscFunctionReturn(0); 1076aa1993deSMatthew G Knepley } 1077aa1993deSMatthew G Knepley } 1078aa1993deSMatthew G Knepley SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Array was not checked out"); 1079aa1993deSMatthew G Knepley PetscFunctionReturn(0); 1080aa1993deSMatthew G Knepley } 1081e7c4fc90SDmitry Karpeev 1082e7c4fc90SDmitry Karpeev #undef __FUNCT__ 1083435a35e8SMatthew G Knepley #define __FUNCT__ "DMSetNullSpaceConstructor" 1084435a35e8SMatthew G Knepley PetscErrorCode DMSetNullSpaceConstructor(DM dm, PetscInt field, PetscErrorCode (*nullsp)(DM dm, PetscInt field, MatNullSpace *nullSpace)) 1085435a35e8SMatthew G Knepley { 1086435a35e8SMatthew G Knepley PetscFunctionBegin; 1087435a35e8SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 108882f516ccSBarry Smith if (field >= 10) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Cannot handle %d >= 10 fields", field); 1089435a35e8SMatthew G Knepley dm->nullspaceConstructors[field] = nullsp; 1090435a35e8SMatthew G Knepley PetscFunctionReturn(0); 1091435a35e8SMatthew G Knepley } 1092435a35e8SMatthew G Knepley 1093435a35e8SMatthew G Knepley #undef __FUNCT__ 10944d343eeaSMatthew G Knepley #define __FUNCT__ "DMCreateFieldIS" 10954f3b5142SJed Brown /*@C 10964d343eeaSMatthew G Knepley DMCreateFieldIS - Creates a set of IS objects with the global indices of dofs for each field 10974d343eeaSMatthew G Knepley 10984d343eeaSMatthew G Knepley Not collective 10994d343eeaSMatthew G Knepley 11004d343eeaSMatthew G Knepley Input Parameter: 11014d343eeaSMatthew G Knepley . dm - the DM object 11024d343eeaSMatthew G Knepley 11034d343eeaSMatthew G Knepley Output Parameters: 11040298fd71SBarry Smith + numFields - The number of fields (or NULL if not requested) 11050298fd71SBarry Smith . fieldNames - The name for each field (or NULL if not requested) 11060298fd71SBarry Smith - fields - The global indices for each field (or NULL if not requested) 11074d343eeaSMatthew G Knepley 11084d343eeaSMatthew G Knepley Level: intermediate 11094d343eeaSMatthew G Knepley 111021c9b008SJed Brown Notes: 111121c9b008SJed Brown The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 111221c9b008SJed Brown PetscFree(), every entry of fields should be destroyed with ISDestroy(), and both arrays should be freed with 111321c9b008SJed Brown PetscFree(). 111421c9b008SJed Brown 11154d343eeaSMatthew G Knepley .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 11164d343eeaSMatthew G Knepley @*/ 111737d0c07bSMatthew G Knepley PetscErrorCode DMCreateFieldIS(DM dm, PetscInt *numFields, char ***fieldNames, IS **fields) 11184d343eeaSMatthew G Knepley { 111937d0c07bSMatthew G Knepley PetscSection section, sectionGlobal; 11204d343eeaSMatthew G Knepley PetscErrorCode ierr; 11214d343eeaSMatthew G Knepley 11224d343eeaSMatthew G Knepley PetscFunctionBegin; 11234d343eeaSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 112469ca1f37SDmitry Karpeev if (numFields) { 112569ca1f37SDmitry Karpeev PetscValidPointer(numFields,2); 112669ca1f37SDmitry Karpeev *numFields = 0; 112769ca1f37SDmitry Karpeev } 112837d0c07bSMatthew G Knepley if (fieldNames) { 112937d0c07bSMatthew G Knepley PetscValidPointer(fieldNames,3); 11300298fd71SBarry Smith *fieldNames = NULL; 113169ca1f37SDmitry Karpeev } 113269ca1f37SDmitry Karpeev if (fields) { 113369ca1f37SDmitry Karpeev PetscValidPointer(fields,4); 11340298fd71SBarry Smith *fields = NULL; 113569ca1f37SDmitry Karpeev } 113637d0c07bSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 113737d0c07bSMatthew G Knepley if (section) { 113837d0c07bSMatthew G Knepley PetscInt *fieldSizes, **fieldIndices; 113937d0c07bSMatthew G Knepley PetscInt nF, f, pStart, pEnd, p; 114037d0c07bSMatthew G Knepley 114137d0c07bSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, §ionGlobal);CHKERRQ(ierr); 114237d0c07bSMatthew G Knepley ierr = PetscSectionGetNumFields(section, &nF);CHKERRQ(ierr); 1143dcca6d9dSJed Brown ierr = PetscMalloc2(nF,&fieldSizes,nF,&fieldIndices);CHKERRQ(ierr); 114437d0c07bSMatthew G Knepley ierr = PetscSectionGetChart(sectionGlobal, &pStart, &pEnd);CHKERRQ(ierr); 114537d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 114637d0c07bSMatthew G Knepley fieldSizes[f] = 0; 114737d0c07bSMatthew G Knepley } 114837d0c07bSMatthew G Knepley for (p = pStart; p < pEnd; ++p) { 114937d0c07bSMatthew G Knepley PetscInt gdof; 115037d0c07bSMatthew G Knepley 115137d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 115237d0c07bSMatthew G Knepley if (gdof > 0) { 115337d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 115437d0c07bSMatthew G Knepley PetscInt fdof, fcdof; 115537d0c07bSMatthew G Knepley 115637d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldDof(section, p, f, &fdof);CHKERRQ(ierr); 115737d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 115837d0c07bSMatthew G Knepley fieldSizes[f] += fdof-fcdof; 115937d0c07bSMatthew G Knepley } 116037d0c07bSMatthew G Knepley } 116137d0c07bSMatthew G Knepley } 116237d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 1163785e854fSJed Brown ierr = PetscMalloc1(fieldSizes[f], &fieldIndices[f]);CHKERRQ(ierr); 116437d0c07bSMatthew G Knepley fieldSizes[f] = 0; 116537d0c07bSMatthew G Knepley } 116637d0c07bSMatthew G Knepley for (p = pStart; p < pEnd; ++p) { 116737d0c07bSMatthew G Knepley PetscInt gdof, goff; 116837d0c07bSMatthew G Knepley 116937d0c07bSMatthew G Knepley ierr = PetscSectionGetDof(sectionGlobal, p, &gdof);CHKERRQ(ierr); 117037d0c07bSMatthew G Knepley if (gdof > 0) { 117137d0c07bSMatthew G Knepley ierr = PetscSectionGetOffset(sectionGlobal, p, &goff);CHKERRQ(ierr); 117237d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 117337d0c07bSMatthew G Knepley PetscInt fdof, fcdof, fc; 117437d0c07bSMatthew G Knepley 117537d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldDof(section, p, f, &fdof);CHKERRQ(ierr); 117637d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldConstraintDof(section, p, f, &fcdof);CHKERRQ(ierr); 117737d0c07bSMatthew G Knepley for (fc = 0; fc < fdof-fcdof; ++fc, ++fieldSizes[f]) { 117837d0c07bSMatthew G Knepley fieldIndices[f][fieldSizes[f]] = goff++; 117937d0c07bSMatthew G Knepley } 118037d0c07bSMatthew G Knepley } 118137d0c07bSMatthew G Knepley } 118237d0c07bSMatthew G Knepley } 11838865f1eaSKarl Rupp if (numFields) *numFields = nF; 118437d0c07bSMatthew G Knepley if (fieldNames) { 1185785e854fSJed Brown ierr = PetscMalloc1(nF, fieldNames);CHKERRQ(ierr); 118637d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 118737d0c07bSMatthew G Knepley const char *fieldName; 118837d0c07bSMatthew G Knepley 118937d0c07bSMatthew G Knepley ierr = PetscSectionGetFieldName(section, f, &fieldName);CHKERRQ(ierr); 119037d0c07bSMatthew G Knepley ierr = PetscStrallocpy(fieldName, (char**) &(*fieldNames)[f]);CHKERRQ(ierr); 119137d0c07bSMatthew G Knepley } 119237d0c07bSMatthew G Knepley } 119337d0c07bSMatthew G Knepley if (fields) { 1194785e854fSJed Brown ierr = PetscMalloc1(nF, fields);CHKERRQ(ierr); 119537d0c07bSMatthew G Knepley for (f = 0; f < nF; ++f) { 119682f516ccSBarry Smith ierr = ISCreateGeneral(PetscObjectComm((PetscObject)dm), fieldSizes[f], fieldIndices[f], PETSC_OWN_POINTER, &(*fields)[f]);CHKERRQ(ierr); 119737d0c07bSMatthew G Knepley } 119837d0c07bSMatthew G Knepley } 119937d0c07bSMatthew G Knepley ierr = PetscFree2(fieldSizes,fieldIndices);CHKERRQ(ierr); 12008865f1eaSKarl Rupp } else if (dm->ops->createfieldis) { 12018865f1eaSKarl Rupp ierr = (*dm->ops->createfieldis)(dm, numFields, fieldNames, fields);CHKERRQ(ierr); 120269ca1f37SDmitry Karpeev } 12034d343eeaSMatthew G Knepley PetscFunctionReturn(0); 12044d343eeaSMatthew G Knepley } 12054d343eeaSMatthew G Knepley 120616621825SDmitry Karpeev 120716621825SDmitry Karpeev #undef __FUNCT__ 120816621825SDmitry Karpeev #define __FUNCT__ "DMCreateFieldDecomposition" 120916621825SDmitry Karpeev /*@C 121016621825SDmitry Karpeev DMCreateFieldDecomposition - Returns a list of IS objects defining a decomposition of a problem into subproblems 121116621825SDmitry Karpeev corresponding to different fields: each IS contains the global indices of the dofs of the 121216621825SDmitry Karpeev corresponding field. The optional list of DMs define the DM for each subproblem. 1213e7c4fc90SDmitry Karpeev Generalizes DMCreateFieldIS(). 1214e7c4fc90SDmitry Karpeev 1215e7c4fc90SDmitry Karpeev Not collective 1216e7c4fc90SDmitry Karpeev 1217e7c4fc90SDmitry Karpeev Input Parameter: 1218e7c4fc90SDmitry Karpeev . dm - the DM object 1219e7c4fc90SDmitry Karpeev 1220e7c4fc90SDmitry Karpeev Output Parameters: 12210298fd71SBarry Smith + len - The number of subproblems in the field decomposition (or NULL if not requested) 12220298fd71SBarry Smith . namelist - The name for each field (or NULL if not requested) 12230298fd71SBarry Smith . islist - The global indices for each field (or NULL if not requested) 12240298fd71SBarry Smith - dmlist - The DMs for each field subproblem (or NULL, if not requested; if NULL is returned, no DMs are defined) 1225e7c4fc90SDmitry Karpeev 1226e7c4fc90SDmitry Karpeev Level: intermediate 1227e7c4fc90SDmitry Karpeev 1228e7c4fc90SDmitry Karpeev Notes: 1229e7c4fc90SDmitry Karpeev The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 1230e7c4fc90SDmitry Karpeev PetscFree(), every entry of is should be destroyed with ISDestroy(), every entry of dm should be destroyed with DMDestroy(), 1231e7c4fc90SDmitry Karpeev and all of the arrays should be freed with PetscFree(). 1232e7c4fc90SDmitry Karpeev 1233e7c4fc90SDmitry Karpeev .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1234e7c4fc90SDmitry Karpeev @*/ 123516621825SDmitry Karpeev PetscErrorCode DMCreateFieldDecomposition(DM dm, PetscInt *len, char ***namelist, IS **islist, DM **dmlist) 1236e7c4fc90SDmitry Karpeev { 1237e7c4fc90SDmitry Karpeev PetscErrorCode ierr; 1238e7c4fc90SDmitry Karpeev 1239e7c4fc90SDmitry Karpeev PetscFunctionBegin; 1240e7c4fc90SDmitry Karpeev PetscValidHeaderSpecific(dm,DM_CLASSID,1); 12418865f1eaSKarl Rupp if (len) { 12428865f1eaSKarl Rupp PetscValidPointer(len,2); 12438865f1eaSKarl Rupp *len = 0; 12448865f1eaSKarl Rupp } 12458865f1eaSKarl Rupp if (namelist) { 12468865f1eaSKarl Rupp PetscValidPointer(namelist,3); 12478865f1eaSKarl Rupp *namelist = 0; 12488865f1eaSKarl Rupp } 12498865f1eaSKarl Rupp if (islist) { 12508865f1eaSKarl Rupp PetscValidPointer(islist,4); 12518865f1eaSKarl Rupp *islist = 0; 12528865f1eaSKarl Rupp } 12538865f1eaSKarl Rupp if (dmlist) { 12548865f1eaSKarl Rupp PetscValidPointer(dmlist,5); 12558865f1eaSKarl Rupp *dmlist = 0; 12568865f1eaSKarl Rupp } 1257f3f0edfdSDmitry Karpeev /* 1258f3f0edfdSDmitry Karpeev Is it a good idea to apply the following check across all impls? 1259f3f0edfdSDmitry Karpeev Perhaps some impls can have a well-defined decomposition before DMSetUp? 1260f3f0edfdSDmitry Karpeev This, however, follows the general principle that accessors are not well-behaved until the object is set up. 1261f3f0edfdSDmitry Karpeev */ 1262ce94432eSBarry Smith if (!dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE, "Decomposition defined only after DMSetUp"); 126316621825SDmitry Karpeev if (!dm->ops->createfielddecomposition) { 1264435a35e8SMatthew G Knepley PetscSection section; 1265435a35e8SMatthew G Knepley PetscInt numFields, f; 1266435a35e8SMatthew G Knepley 1267435a35e8SMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 1268435a35e8SMatthew G Knepley if (section) {ierr = PetscSectionGetNumFields(section, &numFields);CHKERRQ(ierr);} 1269435a35e8SMatthew G Knepley if (section && numFields && dm->ops->createsubdm) { 1270435a35e8SMatthew G Knepley *len = numFields; 127103dc3394SMatthew G. Knepley if (namelist) {ierr = PetscMalloc1(numFields,namelist);CHKERRQ(ierr);} 127203dc3394SMatthew G. Knepley if (islist) {ierr = PetscMalloc1(numFields,islist);CHKERRQ(ierr);} 127303dc3394SMatthew G. Knepley if (dmlist) {ierr = PetscMalloc1(numFields,dmlist);CHKERRQ(ierr);} 1274435a35e8SMatthew G Knepley for (f = 0; f < numFields; ++f) { 1275435a35e8SMatthew G Knepley const char *fieldName; 1276435a35e8SMatthew G Knepley 127703dc3394SMatthew G. Knepley ierr = DMCreateSubDM(dm, 1, &f, islist ? &(*islist)[f] : NULL, dmlist ? &(*dmlist)[f] : NULL);CHKERRQ(ierr); 127803dc3394SMatthew G. Knepley if (namelist) { 1279435a35e8SMatthew G Knepley ierr = PetscSectionGetFieldName(section, f, &fieldName);CHKERRQ(ierr); 1280435a35e8SMatthew G Knepley ierr = PetscStrallocpy(fieldName, (char**) &(*namelist)[f]);CHKERRQ(ierr); 1281435a35e8SMatthew G Knepley } 128203dc3394SMatthew G. Knepley } 1283435a35e8SMatthew G Knepley } else { 128469ca1f37SDmitry Karpeev ierr = DMCreateFieldIS(dm, len, namelist, islist);CHKERRQ(ierr); 1285e7c4fc90SDmitry Karpeev /* By default there are no DMs associated with subproblems. */ 12860298fd71SBarry Smith if (dmlist) *dmlist = NULL; 1287e7c4fc90SDmitry Karpeev } 12888865f1eaSKarl Rupp } else { 128916621825SDmitry Karpeev ierr = (*dm->ops->createfielddecomposition)(dm,len,namelist,islist,dmlist);CHKERRQ(ierr); 129016621825SDmitry Karpeev } 129116621825SDmitry Karpeev PetscFunctionReturn(0); 129216621825SDmitry Karpeev } 129316621825SDmitry Karpeev 129416621825SDmitry Karpeev #undef __FUNCT__ 1295435a35e8SMatthew G Knepley #define __FUNCT__ "DMCreateSubDM" 1296435a35e8SMatthew G Knepley /*@C 1297435a35e8SMatthew G Knepley DMCreateSubDM - Returns an IS and DM encapsulating a subproblem defined by the fields passed in. 1298435a35e8SMatthew G Knepley The fields are defined by DMCreateFieldIS(). 1299435a35e8SMatthew G Knepley 1300435a35e8SMatthew G Knepley Not collective 1301435a35e8SMatthew G Knepley 1302435a35e8SMatthew G Knepley Input Parameters: 1303435a35e8SMatthew G Knepley + dm - the DM object 1304435a35e8SMatthew G Knepley . numFields - number of fields in this subproblem 13050298fd71SBarry Smith - len - The number of subproblems in the decomposition (or NULL if not requested) 1306435a35e8SMatthew G Knepley 1307435a35e8SMatthew G Knepley Output Parameters: 1308435a35e8SMatthew G Knepley . is - The global indices for the subproblem 1309435a35e8SMatthew G Knepley - dm - The DM for the subproblem 1310435a35e8SMatthew G Knepley 1311435a35e8SMatthew G Knepley Level: intermediate 1312435a35e8SMatthew G Knepley 1313435a35e8SMatthew G Knepley .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1314435a35e8SMatthew G Knepley @*/ 1315435a35e8SMatthew G Knepley PetscErrorCode DMCreateSubDM(DM dm, PetscInt numFields, PetscInt fields[], IS *is, DM *subdm) 1316435a35e8SMatthew G Knepley { 1317435a35e8SMatthew G Knepley PetscErrorCode ierr; 1318435a35e8SMatthew G Knepley 1319435a35e8SMatthew G Knepley PetscFunctionBegin; 1320435a35e8SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1321435a35e8SMatthew G Knepley PetscValidPointer(fields,3); 13228865f1eaSKarl Rupp if (is) PetscValidPointer(is,4); 13238865f1eaSKarl Rupp if (subdm) PetscValidPointer(subdm,5); 1324435a35e8SMatthew G Knepley if (dm->ops->createsubdm) { 1325435a35e8SMatthew G Knepley ierr = (*dm->ops->createsubdm)(dm, numFields, fields, is, subdm);CHKERRQ(ierr); 132682f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "This type has no DMCreateSubDM implementation defined"); 1327435a35e8SMatthew G Knepley PetscFunctionReturn(0); 1328435a35e8SMatthew G Knepley } 1329435a35e8SMatthew G Knepley 133016621825SDmitry Karpeev 133116621825SDmitry Karpeev #undef __FUNCT__ 133216621825SDmitry Karpeev #define __FUNCT__ "DMCreateDomainDecomposition" 133316621825SDmitry Karpeev /*@C 13348d4ac253SDmitry Karpeev DMCreateDomainDecomposition - Returns lists of IS objects defining a decomposition of a problem into subproblems 13358d4ac253SDmitry Karpeev corresponding to restrictions to pairs nested subdomains: each IS contains the global 13368d4ac253SDmitry Karpeev indices of the dofs of the corresponding subdomains. The inner subdomains conceptually 13378d4ac253SDmitry Karpeev define a nonoverlapping covering, while outer subdomains can overlap. 13388d4ac253SDmitry Karpeev The optional list of DMs define the DM for each subproblem. 133916621825SDmitry Karpeev 134016621825SDmitry Karpeev Not collective 134116621825SDmitry Karpeev 134216621825SDmitry Karpeev Input Parameter: 134316621825SDmitry Karpeev . dm - the DM object 134416621825SDmitry Karpeev 134516621825SDmitry Karpeev Output Parameters: 13460298fd71SBarry Smith + len - The number of subproblems in the domain decomposition (or NULL if not requested) 13470298fd71SBarry Smith . namelist - The name for each subdomain (or NULL if not requested) 13480298fd71SBarry Smith . innerislist - The global indices for each inner subdomain (or NULL, if not requested) 13490298fd71SBarry Smith . outerislist - The global indices for each outer subdomain (or NULL, if not requested) 13500298fd71SBarry Smith - dmlist - The DMs for each subdomain subproblem (or NULL, if not requested; if NULL is returned, no DMs are defined) 135116621825SDmitry Karpeev 135216621825SDmitry Karpeev Level: intermediate 135316621825SDmitry Karpeev 135416621825SDmitry Karpeev Notes: 135516621825SDmitry Karpeev The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 135616621825SDmitry Karpeev PetscFree(), every entry of is should be destroyed with ISDestroy(), every entry of dm should be destroyed with DMDestroy(), 135716621825SDmitry Karpeev and all of the arrays should be freed with PetscFree(). 135816621825SDmitry Karpeev 13598d4ac253SDmitry Karpeev .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateDomainDecompositionDM(), DMCreateFieldDecomposition() 136016621825SDmitry Karpeev @*/ 13618d4ac253SDmitry Karpeev PetscErrorCode DMCreateDomainDecomposition(DM dm, PetscInt *len, char ***namelist, IS **innerislist, IS **outerislist, DM **dmlist) 136216621825SDmitry Karpeev { 136316621825SDmitry Karpeev PetscErrorCode ierr; 1364be081cd6SPeter Brune DMSubDomainHookLink link; 1365be081cd6SPeter Brune PetscInt i,l; 136616621825SDmitry Karpeev 136716621825SDmitry Karpeev PetscFunctionBegin; 136816621825SDmitry Karpeev PetscValidHeaderSpecific(dm,DM_CLASSID,1); 136914a18fd3SPeter Brune if (len) {PetscValidPointer(len,2); *len = 0;} 13700298fd71SBarry Smith if (namelist) {PetscValidPointer(namelist,3); *namelist = NULL;} 13710298fd71SBarry Smith if (innerislist) {PetscValidPointer(innerislist,4); *innerislist = NULL;} 13720298fd71SBarry Smith if (outerislist) {PetscValidPointer(outerislist,5); *outerislist = NULL;} 13730298fd71SBarry Smith if (dmlist) {PetscValidPointer(dmlist,6); *dmlist = NULL;} 1374f3f0edfdSDmitry Karpeev /* 1375f3f0edfdSDmitry Karpeev Is it a good idea to apply the following check across all impls? 1376f3f0edfdSDmitry Karpeev Perhaps some impls can have a well-defined decomposition before DMSetUp? 1377f3f0edfdSDmitry Karpeev This, however, follows the general principle that accessors are not well-behaved until the object is set up. 1378f3f0edfdSDmitry Karpeev */ 1379ce94432eSBarry Smith if (!dm->setupcalled) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE, "Decomposition defined only after DMSetUp"); 138016621825SDmitry Karpeev if (dm->ops->createdomaindecomposition) { 1381be081cd6SPeter Brune ierr = (*dm->ops->createdomaindecomposition)(dm,&l,namelist,innerislist,outerislist,dmlist);CHKERRQ(ierr); 138214a18fd3SPeter Brune /* copy subdomain hooks and context over to the subdomain DMs */ 138314a18fd3SPeter Brune if (dmlist) { 1384be081cd6SPeter Brune for (i = 0; i < l; i++) { 1385be081cd6SPeter Brune for (link=dm->subdomainhook; link; link=link->next) { 1386be081cd6SPeter Brune if (link->ddhook) {ierr = (*link->ddhook)(dm,(*dmlist)[i],link->ctx);CHKERRQ(ierr);} 1387be081cd6SPeter Brune } 1388d425c654SPeter Brune (*dmlist)[i]->ctx = dm->ctx; 1389e7c4fc90SDmitry Karpeev } 139014a18fd3SPeter Brune } 139114a18fd3SPeter Brune if (len) *len = l; 139214a18fd3SPeter Brune } 1393e30e807fSPeter Brune PetscFunctionReturn(0); 1394e30e807fSPeter Brune } 1395e30e807fSPeter Brune 1396e30e807fSPeter Brune 1397e30e807fSPeter Brune #undef __FUNCT__ 1398e30e807fSPeter Brune #define __FUNCT__ "DMCreateDomainDecompositionScatters" 1399e30e807fSPeter Brune /*@C 1400e30e807fSPeter Brune DMCreateDomainDecompositionScatters - Returns scatters to the subdomain vectors from the global vector 1401e30e807fSPeter Brune 1402e30e807fSPeter Brune Not collective 1403e30e807fSPeter Brune 1404e30e807fSPeter Brune Input Parameters: 1405e30e807fSPeter Brune + dm - the DM object 1406e30e807fSPeter Brune . n - the number of subdomain scatters 1407e30e807fSPeter Brune - subdms - the local subdomains 1408e30e807fSPeter Brune 1409e30e807fSPeter Brune Output Parameters: 1410e30e807fSPeter Brune + n - the number of scatters returned 1411e30e807fSPeter Brune . iscat - scatter from global vector to nonoverlapping global vector entries on subdomain 1412e30e807fSPeter Brune . oscat - scatter from global vector to overlapping global vector entries on subdomain 1413e30e807fSPeter Brune - gscat - scatter from global vector to local vector on subdomain (fills in ghosts) 1414e30e807fSPeter Brune 1415e30e807fSPeter Brune Notes: This is an alternative to the iis and ois arguments in DMCreateDomainDecomposition that allow for the solution 1416e30e807fSPeter Brune of general nonlinear problems with overlapping subdomain methods. While merely having index sets that enable subsets 1417e30e807fSPeter Brune of the residual equations to be created is fine for linear problems, nonlinear problems require local assembly of 1418e30e807fSPeter Brune solution and residual data. 1419e30e807fSPeter Brune 1420e30e807fSPeter Brune Level: developer 1421e30e807fSPeter Brune 1422e30e807fSPeter Brune .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 1423e30e807fSPeter Brune @*/ 1424e30e807fSPeter Brune PetscErrorCode DMCreateDomainDecompositionScatters(DM dm,PetscInt n,DM *subdms,VecScatter **iscat,VecScatter **oscat,VecScatter **gscat) 1425e30e807fSPeter Brune { 1426e30e807fSPeter Brune PetscErrorCode ierr; 1427e30e807fSPeter Brune 1428e30e807fSPeter Brune PetscFunctionBegin; 1429e30e807fSPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1430e30e807fSPeter Brune PetscValidPointer(subdms,3); 1431e30e807fSPeter Brune if (dm->ops->createddscatters) { 1432e30e807fSPeter Brune ierr = (*dm->ops->createddscatters)(dm,n,subdms,iscat,oscat,gscat);CHKERRQ(ierr); 143382f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "This type has no DMCreateDomainDecompositionLocalScatter implementation defined"); 1434e7c4fc90SDmitry Karpeev PetscFunctionReturn(0); 1435e7c4fc90SDmitry Karpeev } 1436e7c4fc90SDmitry Karpeev 1437731c8d9eSDmitry Karpeev #undef __FUNCT__ 143847c6ae99SBarry Smith #define __FUNCT__ "DMRefine" 143947c6ae99SBarry Smith /*@ 144047c6ae99SBarry Smith DMRefine - Refines a DM object 144147c6ae99SBarry Smith 144247c6ae99SBarry Smith Collective on DM 144347c6ae99SBarry Smith 144447c6ae99SBarry Smith Input Parameter: 144547c6ae99SBarry Smith + dm - the DM object 144691d95f02SJed Brown - comm - the communicator to contain the new DM object (or MPI_COMM_NULL) 144747c6ae99SBarry Smith 144847c6ae99SBarry Smith Output Parameter: 14490298fd71SBarry Smith . dmf - the refined DM, or NULL 1450ae0a1c52SMatthew G Knepley 14510298fd71SBarry Smith Note: If no refinement was done, the return value is NULL 145247c6ae99SBarry Smith 145347c6ae99SBarry Smith Level: developer 145447c6ae99SBarry Smith 1455e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 145647c6ae99SBarry Smith @*/ 14577087cfbeSBarry Smith PetscErrorCode DMRefine(DM dm,MPI_Comm comm,DM *dmf) 145847c6ae99SBarry Smith { 145947c6ae99SBarry Smith PetscErrorCode ierr; 1460c833c3b5SJed Brown DMRefineHookLink link; 146147c6ae99SBarry Smith 146247c6ae99SBarry Smith PetscFunctionBegin; 1463732e2eb9SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 146447c6ae99SBarry Smith ierr = (*dm->ops->refine)(dm,comm,dmf);CHKERRQ(ierr); 14654057135bSMatthew G Knepley if (*dmf) { 146643842a1eSJed Brown (*dmf)->ops->creatematrix = dm->ops->creatematrix; 14678865f1eaSKarl Rupp 14688cd211a4SJed Brown ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)*dmf);CHKERRQ(ierr); 14698865f1eaSKarl Rupp 1470644e2e5bSBarry Smith (*dmf)->ctx = dm->ctx; 14710598a293SJed Brown (*dmf)->leveldown = dm->leveldown; 1472656b349aSBarry Smith (*dmf)->levelup = dm->levelup + 1; 14738865f1eaSKarl Rupp 1474e4b4b23bSJed Brown ierr = DMSetMatType(*dmf,dm->mattype);CHKERRQ(ierr); 1475c833c3b5SJed Brown for (link=dm->refinehook; link; link=link->next) { 14768865f1eaSKarl Rupp if (link->refinehook) { 14778865f1eaSKarl Rupp ierr = (*link->refinehook)(dm,*dmf,link->ctx);CHKERRQ(ierr); 14788865f1eaSKarl Rupp } 1479c833c3b5SJed Brown } 1480c833c3b5SJed Brown } 1481c833c3b5SJed Brown PetscFunctionReturn(0); 1482c833c3b5SJed Brown } 1483c833c3b5SJed Brown 1484c833c3b5SJed Brown #undef __FUNCT__ 1485c833c3b5SJed Brown #define __FUNCT__ "DMRefineHookAdd" 1486bb9467b5SJed Brown /*@C 1487c833c3b5SJed Brown DMRefineHookAdd - adds a callback to be run when interpolating a nonlinear problem to a finer grid 1488c833c3b5SJed Brown 1489c833c3b5SJed Brown Logically Collective 1490c833c3b5SJed Brown 1491c833c3b5SJed Brown Input Arguments: 1492c833c3b5SJed Brown + coarse - nonlinear solver context on which to run a hook when restricting to a coarser level 1493c833c3b5SJed Brown . refinehook - function to run when setting up a coarser level 1494c833c3b5SJed Brown . interphook - function to run to update data on finer levels (once per SNESSolve()) 14950298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1496c833c3b5SJed Brown 1497c833c3b5SJed Brown Calling sequence of refinehook: 1498c833c3b5SJed Brown $ refinehook(DM coarse,DM fine,void *ctx); 1499c833c3b5SJed Brown 1500c833c3b5SJed Brown + coarse - coarse level DM 1501c833c3b5SJed Brown . fine - fine level DM to interpolate problem to 1502c833c3b5SJed Brown - ctx - optional user-defined function context 1503c833c3b5SJed Brown 1504c833c3b5SJed Brown Calling sequence for interphook: 1505c833c3b5SJed Brown $ interphook(DM coarse,Mat interp,DM fine,void *ctx) 1506c833c3b5SJed Brown 1507c833c3b5SJed Brown + coarse - coarse level DM 1508c833c3b5SJed Brown . interp - matrix interpolating a coarse-level solution to the finer grid 1509c833c3b5SJed Brown . fine - fine level DM to update 1510c833c3b5SJed Brown - ctx - optional user-defined function context 1511c833c3b5SJed Brown 1512c833c3b5SJed Brown Level: advanced 1513c833c3b5SJed Brown 1514c833c3b5SJed Brown Notes: 1515c833c3b5SJed Brown This function is only needed if auxiliary data needs to be passed to fine grids while grid sequencing 1516c833c3b5SJed Brown 1517c833c3b5SJed Brown If this function is called multiple times, the hooks will be run in the order they are added. 1518c833c3b5SJed Brown 1519bb9467b5SJed Brown This function is currently not available from Fortran. 1520bb9467b5SJed Brown 1521c833c3b5SJed Brown .seealso: DMCoarsenHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1522c833c3b5SJed Brown @*/ 1523c833c3b5SJed Brown PetscErrorCode DMRefineHookAdd(DM coarse,PetscErrorCode (*refinehook)(DM,DM,void*),PetscErrorCode (*interphook)(DM,Mat,DM,void*),void *ctx) 1524c833c3b5SJed Brown { 1525c833c3b5SJed Brown PetscErrorCode ierr; 1526c833c3b5SJed Brown DMRefineHookLink link,*p; 1527c833c3b5SJed Brown 1528c833c3b5SJed Brown PetscFunctionBegin; 1529c833c3b5SJed Brown PetscValidHeaderSpecific(coarse,DM_CLASSID,1); 1530c833c3b5SJed Brown for (p=&coarse->refinehook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1531c833c3b5SJed Brown ierr = PetscMalloc(sizeof(struct _DMRefineHookLink),&link);CHKERRQ(ierr); 1532c833c3b5SJed Brown link->refinehook = refinehook; 1533c833c3b5SJed Brown link->interphook = interphook; 1534c833c3b5SJed Brown link->ctx = ctx; 15350298fd71SBarry Smith link->next = NULL; 1536c833c3b5SJed Brown *p = link; 1537c833c3b5SJed Brown PetscFunctionReturn(0); 1538c833c3b5SJed Brown } 1539c833c3b5SJed Brown 1540c833c3b5SJed Brown #undef __FUNCT__ 1541c833c3b5SJed Brown #define __FUNCT__ "DMInterpolate" 1542c833c3b5SJed Brown /*@ 1543c833c3b5SJed Brown DMInterpolate - interpolates user-defined problem data to a finer DM by running hooks registered by DMRefineHookAdd() 1544c833c3b5SJed Brown 1545c833c3b5SJed Brown Collective if any hooks are 1546c833c3b5SJed Brown 1547c833c3b5SJed Brown Input Arguments: 1548c833c3b5SJed Brown + coarse - coarser DM to use as a base 1549c833c3b5SJed Brown . restrct - interpolation matrix, apply using MatInterpolate() 1550c833c3b5SJed Brown - fine - finer DM to update 1551c833c3b5SJed Brown 1552c833c3b5SJed Brown Level: developer 1553c833c3b5SJed Brown 1554c833c3b5SJed Brown .seealso: DMRefineHookAdd(), MatInterpolate() 1555c833c3b5SJed Brown @*/ 1556c833c3b5SJed Brown PetscErrorCode DMInterpolate(DM coarse,Mat interp,DM fine) 1557c833c3b5SJed Brown { 1558c833c3b5SJed Brown PetscErrorCode ierr; 1559c833c3b5SJed Brown DMRefineHookLink link; 1560c833c3b5SJed Brown 1561c833c3b5SJed Brown PetscFunctionBegin; 1562c833c3b5SJed Brown for (link=fine->refinehook; link; link=link->next) { 15638865f1eaSKarl Rupp if (link->interphook) { 15648865f1eaSKarl Rupp ierr = (*link->interphook)(coarse,interp,fine,link->ctx);CHKERRQ(ierr); 15658865f1eaSKarl Rupp } 15664057135bSMatthew G Knepley } 156747c6ae99SBarry Smith PetscFunctionReturn(0); 156847c6ae99SBarry Smith } 156947c6ae99SBarry Smith 157047c6ae99SBarry Smith #undef __FUNCT__ 1571eb3f98d2SBarry Smith #define __FUNCT__ "DMGetRefineLevel" 1572eb3f98d2SBarry Smith /*@ 1573eb3f98d2SBarry Smith DMGetRefineLevel - Get's the number of refinements that have generated this DM. 1574eb3f98d2SBarry Smith 1575eb3f98d2SBarry Smith Not Collective 1576eb3f98d2SBarry Smith 1577eb3f98d2SBarry Smith Input Parameter: 1578eb3f98d2SBarry Smith . dm - the DM object 1579eb3f98d2SBarry Smith 1580eb3f98d2SBarry Smith Output Parameter: 1581eb3f98d2SBarry Smith . level - number of refinements 1582eb3f98d2SBarry Smith 1583eb3f98d2SBarry Smith Level: developer 1584eb3f98d2SBarry Smith 15856a7d9d85SPeter Brune .seealso DMCoarsen(), DMGetCoarsenLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 1586eb3f98d2SBarry Smith 1587eb3f98d2SBarry Smith @*/ 1588eb3f98d2SBarry Smith PetscErrorCode DMGetRefineLevel(DM dm,PetscInt *level) 1589eb3f98d2SBarry Smith { 1590eb3f98d2SBarry Smith PetscFunctionBegin; 1591eb3f98d2SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1592eb3f98d2SBarry Smith *level = dm->levelup; 1593eb3f98d2SBarry Smith PetscFunctionReturn(0); 1594eb3f98d2SBarry Smith } 1595eb3f98d2SBarry Smith 1596eb3f98d2SBarry Smith #undef __FUNCT__ 1597baf369e7SPeter Brune #define __FUNCT__ "DMGlobalToLocalHookAdd" 1598bb9467b5SJed Brown /*@C 1599baf369e7SPeter Brune DMGlobalToLocalHookAdd - adds a callback to be run when global to local is called 1600baf369e7SPeter Brune 1601baf369e7SPeter Brune Logically Collective 1602baf369e7SPeter Brune 1603baf369e7SPeter Brune Input Arguments: 1604baf369e7SPeter Brune + dm - the DM 1605baf369e7SPeter Brune . beginhook - function to run at the beginning of DMGlobalToLocalBegin() 1606baf369e7SPeter Brune . endhook - function to run after DMGlobalToLocalEnd() has completed 16070298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1608baf369e7SPeter Brune 1609baf369e7SPeter Brune Calling sequence for beginhook: 1610baf369e7SPeter Brune $ beginhook(DM fine,VecScatter out,VecScatter in,DM coarse,void *ctx) 1611baf369e7SPeter Brune 1612baf369e7SPeter Brune + dm - global DM 1613baf369e7SPeter Brune . g - global vector 1614baf369e7SPeter Brune . mode - mode 1615baf369e7SPeter Brune . l - local vector 1616baf369e7SPeter Brune - ctx - optional user-defined function context 1617baf369e7SPeter Brune 1618baf369e7SPeter Brune 1619baf369e7SPeter Brune Calling sequence for endhook: 1620ec4806b8SPeter Brune $ endhook(DM fine,VecScatter out,VecScatter in,DM coarse,void *ctx) 1621baf369e7SPeter Brune 1622baf369e7SPeter Brune + global - global DM 1623baf369e7SPeter Brune - ctx - optional user-defined function context 1624baf369e7SPeter Brune 1625baf369e7SPeter Brune Level: advanced 1626baf369e7SPeter Brune 1627baf369e7SPeter Brune .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1628baf369e7SPeter Brune @*/ 1629baf369e7SPeter Brune PetscErrorCode DMGlobalToLocalHookAdd(DM dm,PetscErrorCode (*beginhook)(DM,Vec,InsertMode,Vec,void*),PetscErrorCode (*endhook)(DM,Vec,InsertMode,Vec,void*),void *ctx) 1630baf369e7SPeter Brune { 1631baf369e7SPeter Brune PetscErrorCode ierr; 1632baf369e7SPeter Brune DMGlobalToLocalHookLink link,*p; 1633baf369e7SPeter Brune 1634baf369e7SPeter Brune PetscFunctionBegin; 1635baf369e7SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1636baf369e7SPeter Brune for (p=&dm->gtolhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1637baf369e7SPeter Brune ierr = PetscMalloc(sizeof(struct _DMGlobalToLocalHookLink),&link);CHKERRQ(ierr); 1638baf369e7SPeter Brune link->beginhook = beginhook; 1639baf369e7SPeter Brune link->endhook = endhook; 1640baf369e7SPeter Brune link->ctx = ctx; 16410298fd71SBarry Smith link->next = NULL; 1642baf369e7SPeter Brune *p = link; 1643baf369e7SPeter Brune PetscFunctionReturn(0); 1644baf369e7SPeter Brune } 1645baf369e7SPeter Brune 1646baf369e7SPeter Brune #undef __FUNCT__ 164747c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalBegin" 164847c6ae99SBarry Smith /*@ 164947c6ae99SBarry Smith DMGlobalToLocalBegin - Begins updating local vectors from global vector 165047c6ae99SBarry Smith 165147c6ae99SBarry Smith Neighbor-wise Collective on DM 165247c6ae99SBarry Smith 165347c6ae99SBarry Smith Input Parameters: 165447c6ae99SBarry Smith + dm - the DM object 165547c6ae99SBarry Smith . g - the global vector 165647c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 165747c6ae99SBarry Smith - l - the local vector 165847c6ae99SBarry Smith 165947c6ae99SBarry Smith 166047c6ae99SBarry Smith Level: beginner 166147c6ae99SBarry Smith 1662e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 166347c6ae99SBarry Smith 166447c6ae99SBarry Smith @*/ 16657087cfbeSBarry Smith PetscErrorCode DMGlobalToLocalBegin(DM dm,Vec g,InsertMode mode,Vec l) 166647c6ae99SBarry Smith { 16677128ae9fSMatthew G Knepley PetscSF sf; 166847c6ae99SBarry Smith PetscErrorCode ierr; 1669baf369e7SPeter Brune DMGlobalToLocalHookLink link; 167047c6ae99SBarry Smith 167147c6ae99SBarry Smith PetscFunctionBegin; 1672171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1673baf369e7SPeter Brune for (link=dm->gtolhook; link; link=link->next) { 16748865f1eaSKarl Rupp if (link->beginhook) { 16758865f1eaSKarl Rupp ierr = (*link->beginhook)(dm,g,mode,l,link->ctx);CHKERRQ(ierr); 16768865f1eaSKarl Rupp } 1677baf369e7SPeter Brune } 16787128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 16797128ae9fSMatthew G Knepley if (sf) { 16807128ae9fSMatthew G Knepley PetscScalar *lArray, *gArray; 16817128ae9fSMatthew G Knepley 168282f516ccSBarry Smith if (mode == ADD_VALUES) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 16837128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 16847128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 16857128ae9fSMatthew G Knepley ierr = PetscSFBcastBegin(sf, MPIU_SCALAR, gArray, lArray);CHKERRQ(ierr); 16867128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 16877128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 16887128ae9fSMatthew G Knepley } else { 1689843c4018SMatthew G Knepley ierr = (*dm->ops->globaltolocalbegin)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 16907128ae9fSMatthew G Knepley } 169147c6ae99SBarry Smith PetscFunctionReturn(0); 169247c6ae99SBarry Smith } 169347c6ae99SBarry Smith 169447c6ae99SBarry Smith #undef __FUNCT__ 169547c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalEnd" 169647c6ae99SBarry Smith /*@ 169747c6ae99SBarry Smith DMGlobalToLocalEnd - Ends updating local vectors from global vector 169847c6ae99SBarry Smith 169947c6ae99SBarry Smith Neighbor-wise Collective on DM 170047c6ae99SBarry Smith 170147c6ae99SBarry Smith Input Parameters: 170247c6ae99SBarry Smith + dm - the DM object 170347c6ae99SBarry Smith . g - the global vector 170447c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 170547c6ae99SBarry Smith - l - the local vector 170647c6ae99SBarry Smith 170747c6ae99SBarry Smith 170847c6ae99SBarry Smith Level: beginner 170947c6ae99SBarry Smith 1710e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 171147c6ae99SBarry Smith 171247c6ae99SBarry Smith @*/ 17137087cfbeSBarry Smith PetscErrorCode DMGlobalToLocalEnd(DM dm,Vec g,InsertMode mode,Vec l) 171447c6ae99SBarry Smith { 17157128ae9fSMatthew G Knepley PetscSF sf; 171647c6ae99SBarry Smith PetscErrorCode ierr; 171761a3c1faSSatish Balay PetscScalar *lArray, *gArray; 1718baf369e7SPeter Brune DMGlobalToLocalHookLink link; 171947c6ae99SBarry Smith 172047c6ae99SBarry Smith PetscFunctionBegin; 1721171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 17227128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 17237128ae9fSMatthew G Knepley if (sf) { 172482f516ccSBarry Smith if (mode == ADD_VALUES) SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 17257128ae9fSMatthew G Knepley 17267128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 17277128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 17287128ae9fSMatthew G Knepley ierr = PetscSFBcastEnd(sf, MPIU_SCALAR, gArray, lArray);CHKERRQ(ierr); 17297128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 17307128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 17317128ae9fSMatthew G Knepley } else { 1732843c4018SMatthew G Knepley ierr = (*dm->ops->globaltolocalend)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 17337128ae9fSMatthew G Knepley } 1734baf369e7SPeter Brune for (link=dm->gtolhook; link; link=link->next) { 1735baf369e7SPeter Brune if (link->endhook) {ierr = (*link->endhook)(dm,g,mode,l,link->ctx);CHKERRQ(ierr);} 1736baf369e7SPeter Brune } 173747c6ae99SBarry Smith PetscFunctionReturn(0); 173847c6ae99SBarry Smith } 173947c6ae99SBarry Smith 174047c6ae99SBarry Smith #undef __FUNCT__ 17419a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalBegin" 174247c6ae99SBarry Smith /*@ 17439a42bb27SBarry Smith DMLocalToGlobalBegin - updates global vectors from local vectors 17449a42bb27SBarry Smith 17459a42bb27SBarry Smith Neighbor-wise Collective on DM 17469a42bb27SBarry Smith 17479a42bb27SBarry Smith Input Parameters: 17489a42bb27SBarry Smith + dm - the DM object 1749f6813fd5SJed Brown . l - the local vector 17509a42bb27SBarry 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 17519a42bb27SBarry Smith base point. 1752f6813fd5SJed Brown - - the global vector 17539a42bb27SBarry Smith 17549a42bb27SBarry 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 17559a42bb27SBarry 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 17569a42bb27SBarry Smith global array to the final global array with VecAXPY(). 17579a42bb27SBarry Smith 17589a42bb27SBarry Smith Level: beginner 17599a42bb27SBarry Smith 1760e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalBegin() 17619a42bb27SBarry Smith 17629a42bb27SBarry Smith @*/ 17637087cfbeSBarry Smith PetscErrorCode DMLocalToGlobalBegin(DM dm,Vec l,InsertMode mode,Vec g) 17649a42bb27SBarry Smith { 17657128ae9fSMatthew G Knepley PetscSF sf; 17669a42bb27SBarry Smith PetscErrorCode ierr; 17679a42bb27SBarry Smith 17689a42bb27SBarry Smith PetscFunctionBegin; 1769171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 17707128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 17717128ae9fSMatthew G Knepley if (sf) { 17727128ae9fSMatthew G Knepley MPI_Op op; 17737128ae9fSMatthew G Knepley PetscScalar *lArray, *gArray; 17747128ae9fSMatthew G Knepley 17757128ae9fSMatthew G Knepley switch (mode) { 17767128ae9fSMatthew G Knepley case INSERT_VALUES: 17777128ae9fSMatthew G Knepley case INSERT_ALL_VALUES: 17788bfbc91cSJed Brown op = MPIU_REPLACE; break; 17797128ae9fSMatthew G Knepley case ADD_VALUES: 17807128ae9fSMatthew G Knepley case ADD_ALL_VALUES: 17817128ae9fSMatthew G Knepley op = MPI_SUM; break; 17827128ae9fSMatthew G Knepley default: 178382f516ccSBarry Smith SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 17847128ae9fSMatthew G Knepley } 17857128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 17867128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 17877128ae9fSMatthew G Knepley ierr = PetscSFReduceBegin(sf, MPIU_SCALAR, lArray, gArray, op);CHKERRQ(ierr); 17887128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 17897128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 17907128ae9fSMatthew G Knepley } else { 1791843c4018SMatthew G Knepley ierr = (*dm->ops->localtoglobalbegin)(dm,l,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),g);CHKERRQ(ierr); 17927128ae9fSMatthew G Knepley } 17939a42bb27SBarry Smith PetscFunctionReturn(0); 17949a42bb27SBarry Smith } 17959a42bb27SBarry Smith 17969a42bb27SBarry Smith #undef __FUNCT__ 17979a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalEnd" 17989a42bb27SBarry Smith /*@ 17999a42bb27SBarry Smith DMLocalToGlobalEnd - updates global vectors from local vectors 180047c6ae99SBarry Smith 180147c6ae99SBarry Smith Neighbor-wise Collective on DM 180247c6ae99SBarry Smith 180347c6ae99SBarry Smith Input Parameters: 180447c6ae99SBarry Smith + dm - the DM object 1805f6813fd5SJed Brown . l - the local vector 180647c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 1807f6813fd5SJed Brown - g - the global vector 180847c6ae99SBarry Smith 180947c6ae99SBarry Smith 181047c6ae99SBarry Smith Level: beginner 181147c6ae99SBarry Smith 1812e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalEnd() 181347c6ae99SBarry Smith 181447c6ae99SBarry Smith @*/ 18157087cfbeSBarry Smith PetscErrorCode DMLocalToGlobalEnd(DM dm,Vec l,InsertMode mode,Vec g) 181647c6ae99SBarry Smith { 18177128ae9fSMatthew G Knepley PetscSF sf; 181847c6ae99SBarry Smith PetscErrorCode ierr; 181947c6ae99SBarry Smith 182047c6ae99SBarry Smith PetscFunctionBegin; 1821171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 18227128ae9fSMatthew G Knepley ierr = DMGetDefaultSF(dm, &sf);CHKERRQ(ierr); 18237128ae9fSMatthew G Knepley if (sf) { 18247128ae9fSMatthew G Knepley MPI_Op op; 18257128ae9fSMatthew G Knepley PetscScalar *lArray, *gArray; 18267128ae9fSMatthew G Knepley 18277128ae9fSMatthew G Knepley switch (mode) { 18287128ae9fSMatthew G Knepley case INSERT_VALUES: 18297128ae9fSMatthew G Knepley case INSERT_ALL_VALUES: 18308bfbc91cSJed Brown op = MPIU_REPLACE; break; 18317128ae9fSMatthew G Knepley case ADD_VALUES: 18327128ae9fSMatthew G Knepley case ADD_ALL_VALUES: 18337128ae9fSMatthew G Knepley op = MPI_SUM; break; 18347128ae9fSMatthew G Knepley default: 183582f516ccSBarry Smith SETERRQ1(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Invalid insertion mode %D", mode); 18367128ae9fSMatthew G Knepley } 18377128ae9fSMatthew G Knepley ierr = VecGetArray(l, &lArray);CHKERRQ(ierr); 18387128ae9fSMatthew G Knepley ierr = VecGetArray(g, &gArray);CHKERRQ(ierr); 18397128ae9fSMatthew G Knepley ierr = PetscSFReduceEnd(sf, MPIU_SCALAR, lArray, gArray, op);CHKERRQ(ierr); 18407128ae9fSMatthew G Knepley ierr = VecRestoreArray(l, &lArray);CHKERRQ(ierr); 18417128ae9fSMatthew G Knepley ierr = VecRestoreArray(g, &gArray);CHKERRQ(ierr); 18427128ae9fSMatthew G Knepley } else { 1843843c4018SMatthew G Knepley ierr = (*dm->ops->localtoglobalend)(dm,l,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),g);CHKERRQ(ierr); 18447128ae9fSMatthew G Knepley } 184547c6ae99SBarry Smith PetscFunctionReturn(0); 184647c6ae99SBarry Smith } 184747c6ae99SBarry Smith 184847c6ae99SBarry Smith #undef __FUNCT__ 1849f089877aSRichard Tran Mills #define __FUNCT__ "DMLocalToLocalBegin" 1850f089877aSRichard Tran Mills /*@ 1851bc0a1609SRichard Tran Mills DMLocalToLocalBegin - Maps from a local vector (including ghost points 1852bc0a1609SRichard Tran Mills that contain irrelevant values) to another local vector where the ghost 1853d78e899eSRichard Tran Mills points in the second are set correctly. Must be followed by DMLocalToLocalEnd(). 1854f089877aSRichard Tran Mills 1855bc0a1609SRichard Tran Mills Neighbor-wise Collective on DM and Vec 1856f089877aSRichard Tran Mills 1857f089877aSRichard Tran Mills Input Parameters: 1858f089877aSRichard Tran Mills + dm - the DM object 1859bc0a1609SRichard Tran Mills . g - the original local vector 1860bc0a1609SRichard Tran Mills - mode - one of INSERT_VALUES or ADD_VALUES 1861f089877aSRichard Tran Mills 1862bc0a1609SRichard Tran Mills Output Parameter: 1863bc0a1609SRichard Tran Mills . l - the local vector with correct ghost values 1864f089877aSRichard Tran Mills 1865f089877aSRichard Tran Mills Level: intermediate 1866f089877aSRichard Tran Mills 1867bc0a1609SRichard Tran Mills Notes: 1868bc0a1609SRichard Tran Mills The local vectors used here need not be the same as those 1869bc0a1609SRichard Tran Mills obtained from DMCreateLocalVector(), BUT they 1870bc0a1609SRichard Tran Mills must have the same parallel data layout; they could, for example, be 1871bc0a1609SRichard Tran Mills obtained with VecDuplicate() from the DM originating vectors. 1872bc0a1609SRichard Tran Mills 1873bc0a1609SRichard Tran Mills .keywords: DM, local-to-local, begin 1874bc0a1609SRichard Tran Mills .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateLocalVector(), DMCreateGlobalVector(), DMCreateInterpolation(), DMLocalToLocalEnd(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 1875f089877aSRichard Tran Mills 1876f089877aSRichard Tran Mills @*/ 1877f089877aSRichard Tran Mills PetscErrorCode DMLocalToLocalBegin(DM dm,Vec g,InsertMode mode,Vec l) 1878f089877aSRichard Tran Mills { 1879f089877aSRichard Tran Mills PetscErrorCode ierr; 1880f089877aSRichard Tran Mills 1881f089877aSRichard Tran Mills PetscFunctionBegin; 1882f089877aSRichard Tran Mills PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1883f089877aSRichard Tran Mills ierr = (*dm->ops->localtolocalbegin)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 1884f089877aSRichard Tran Mills PetscFunctionReturn(0); 1885f089877aSRichard Tran Mills } 1886f089877aSRichard Tran Mills 1887f089877aSRichard Tran Mills #undef __FUNCT__ 1888f089877aSRichard Tran Mills #define __FUNCT__ "DMLocalToLocalEnd" 1889f089877aSRichard Tran Mills /*@ 1890bc0a1609SRichard Tran Mills DMLocalToLocalEnd - Maps from a local vector (including ghost points 1891bc0a1609SRichard Tran Mills that contain irrelevant values) to another local vector where the ghost 1892d78e899eSRichard Tran Mills points in the second are set correctly. Must be preceded by DMLocalToLocalBegin(). 1893f089877aSRichard Tran Mills 1894bc0a1609SRichard Tran Mills Neighbor-wise Collective on DM and Vec 1895f089877aSRichard Tran Mills 1896f089877aSRichard Tran Mills Input Parameters: 1897bc0a1609SRichard Tran Mills + da - the DM object 1898bc0a1609SRichard Tran Mills . g - the original local vector 1899bc0a1609SRichard Tran Mills - mode - one of INSERT_VALUES or ADD_VALUES 1900f089877aSRichard Tran Mills 1901bc0a1609SRichard Tran Mills Output Parameter: 1902bc0a1609SRichard Tran Mills . l - the local vector with correct ghost values 1903f089877aSRichard Tran Mills 1904f089877aSRichard Tran Mills Level: intermediate 1905f089877aSRichard Tran Mills 1906bc0a1609SRichard Tran Mills Notes: 1907bc0a1609SRichard Tran Mills The local vectors used here need not be the same as those 1908bc0a1609SRichard Tran Mills obtained from DMCreateLocalVector(), BUT they 1909bc0a1609SRichard Tran Mills must have the same parallel data layout; they could, for example, be 1910bc0a1609SRichard Tran Mills obtained with VecDuplicate() from the DM originating vectors. 1911bc0a1609SRichard Tran Mills 1912bc0a1609SRichard Tran Mills .keywords: DM, local-to-local, end 1913bc0a1609SRichard Tran Mills .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateLocalVector(), DMCreateGlobalVector(), DMCreateInterpolation(), DMLocalToLocalBegin(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 1914f089877aSRichard Tran Mills 1915f089877aSRichard Tran Mills @*/ 1916f089877aSRichard Tran Mills PetscErrorCode DMLocalToLocalEnd(DM dm,Vec g,InsertMode mode,Vec l) 1917f089877aSRichard Tran Mills { 1918f089877aSRichard Tran Mills PetscErrorCode ierr; 1919f089877aSRichard Tran Mills 1920f089877aSRichard Tran Mills PetscFunctionBegin; 1921f089877aSRichard Tran Mills PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1922f089877aSRichard Tran Mills ierr = (*dm->ops->localtolocalend)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 1923f089877aSRichard Tran Mills PetscFunctionReturn(0); 1924f089877aSRichard Tran Mills } 1925f089877aSRichard Tran Mills 1926f089877aSRichard Tran Mills 1927f089877aSRichard Tran Mills #undef __FUNCT__ 192847c6ae99SBarry Smith #define __FUNCT__ "DMCoarsen" 192947c6ae99SBarry Smith /*@ 193047c6ae99SBarry Smith DMCoarsen - Coarsens a DM object 193147c6ae99SBarry Smith 193247c6ae99SBarry Smith Collective on DM 193347c6ae99SBarry Smith 193447c6ae99SBarry Smith Input Parameter: 193547c6ae99SBarry Smith + dm - the DM object 193691d95f02SJed Brown - comm - the communicator to contain the new DM object (or MPI_COMM_NULL) 193747c6ae99SBarry Smith 193847c6ae99SBarry Smith Output Parameter: 193947c6ae99SBarry Smith . dmc - the coarsened DM 194047c6ae99SBarry Smith 194147c6ae99SBarry Smith Level: developer 194247c6ae99SBarry Smith 1943e727c939SJed Brown .seealso DMRefine(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 194447c6ae99SBarry Smith 194547c6ae99SBarry Smith @*/ 19467087cfbeSBarry Smith PetscErrorCode DMCoarsen(DM dm, MPI_Comm comm, DM *dmc) 194747c6ae99SBarry Smith { 194847c6ae99SBarry Smith PetscErrorCode ierr; 1949b17ce1afSJed Brown DMCoarsenHookLink link; 195047c6ae99SBarry Smith 195147c6ae99SBarry Smith PetscFunctionBegin; 1952171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 195347c6ae99SBarry Smith ierr = (*dm->ops->coarsen)(dm, comm, dmc);CHKERRQ(ierr); 195443842a1eSJed Brown (*dmc)->ops->creatematrix = dm->ops->creatematrix; 19558cd211a4SJed Brown ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)*dmc);CHKERRQ(ierr); 1956644e2e5bSBarry Smith (*dmc)->ctx = dm->ctx; 19570598a293SJed Brown (*dmc)->levelup = dm->levelup; 1958656b349aSBarry Smith (*dmc)->leveldown = dm->leveldown + 1; 1959e4b4b23bSJed Brown ierr = DMSetMatType(*dmc,dm->mattype);CHKERRQ(ierr); 1960b17ce1afSJed Brown for (link=dm->coarsenhook; link; link=link->next) { 1961b17ce1afSJed Brown if (link->coarsenhook) {ierr = (*link->coarsenhook)(dm,*dmc,link->ctx);CHKERRQ(ierr);} 1962b17ce1afSJed Brown } 1963b17ce1afSJed Brown PetscFunctionReturn(0); 1964b17ce1afSJed Brown } 1965b17ce1afSJed Brown 1966b17ce1afSJed Brown #undef __FUNCT__ 1967b17ce1afSJed Brown #define __FUNCT__ "DMCoarsenHookAdd" 1968bb9467b5SJed Brown /*@C 1969b17ce1afSJed Brown DMCoarsenHookAdd - adds a callback to be run when restricting a nonlinear problem to the coarse grid 1970b17ce1afSJed Brown 1971b17ce1afSJed Brown Logically Collective 1972b17ce1afSJed Brown 1973b17ce1afSJed Brown Input Arguments: 1974b17ce1afSJed Brown + fine - nonlinear solver context on which to run a hook when restricting to a coarser level 1975b17ce1afSJed Brown . coarsenhook - function to run when setting up a coarser level 1976b17ce1afSJed Brown . restricthook - function to run to update data on coarser levels (once per SNESSolve()) 19770298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 1978b17ce1afSJed Brown 1979b17ce1afSJed Brown Calling sequence of coarsenhook: 1980b17ce1afSJed Brown $ coarsenhook(DM fine,DM coarse,void *ctx); 1981b17ce1afSJed Brown 1982b17ce1afSJed Brown + fine - fine level DM 1983b17ce1afSJed Brown . coarse - coarse level DM to restrict problem to 1984b17ce1afSJed Brown - ctx - optional user-defined function context 1985b17ce1afSJed Brown 1986b17ce1afSJed Brown Calling sequence for restricthook: 1987c833c3b5SJed Brown $ restricthook(DM fine,Mat mrestrict,Vec rscale,Mat inject,DM coarse,void *ctx) 1988b17ce1afSJed Brown 1989b17ce1afSJed Brown + fine - fine level DM 1990b17ce1afSJed Brown . mrestrict - matrix restricting a fine-level solution to the coarse grid 1991c833c3b5SJed Brown . rscale - scaling vector for restriction 1992c833c3b5SJed Brown . inject - matrix restricting by injection 1993b17ce1afSJed Brown . coarse - coarse level DM to update 1994b17ce1afSJed Brown - ctx - optional user-defined function context 1995b17ce1afSJed Brown 1996b17ce1afSJed Brown Level: advanced 1997b17ce1afSJed Brown 1998b17ce1afSJed Brown Notes: 1999b17ce1afSJed Brown This function is only needed if auxiliary data needs to be set up on coarse grids. 2000b17ce1afSJed Brown 2001b17ce1afSJed Brown If this function is called multiple times, the hooks will be run in the order they are added. 2002b17ce1afSJed Brown 2003b17ce1afSJed Brown In order to compose with nonlinear preconditioning without duplicating storage, the hook should be implemented to 2004b17ce1afSJed Brown extract the finest level information from its context (instead of from the SNES). 2005b17ce1afSJed Brown 2006bb9467b5SJed Brown This function is currently not available from Fortran. 2007bb9467b5SJed Brown 2008c833c3b5SJed Brown .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 2009b17ce1afSJed Brown @*/ 2010b17ce1afSJed Brown PetscErrorCode DMCoarsenHookAdd(DM fine,PetscErrorCode (*coarsenhook)(DM,DM,void*),PetscErrorCode (*restricthook)(DM,Mat,Vec,Mat,DM,void*),void *ctx) 2011b17ce1afSJed Brown { 2012b17ce1afSJed Brown PetscErrorCode ierr; 2013b17ce1afSJed Brown DMCoarsenHookLink link,*p; 2014b17ce1afSJed Brown 2015b17ce1afSJed Brown PetscFunctionBegin; 2016b17ce1afSJed Brown PetscValidHeaderSpecific(fine,DM_CLASSID,1); 20176bfea28cSJed Brown for (p=&fine->coarsenhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 2018b17ce1afSJed Brown ierr = PetscMalloc(sizeof(struct _DMCoarsenHookLink),&link);CHKERRQ(ierr); 2019b17ce1afSJed Brown link->coarsenhook = coarsenhook; 2020b17ce1afSJed Brown link->restricthook = restricthook; 2021b17ce1afSJed Brown link->ctx = ctx; 20220298fd71SBarry Smith link->next = NULL; 2023b17ce1afSJed Brown *p = link; 2024b17ce1afSJed Brown PetscFunctionReturn(0); 2025b17ce1afSJed Brown } 2026b17ce1afSJed Brown 2027b17ce1afSJed Brown #undef __FUNCT__ 2028b17ce1afSJed Brown #define __FUNCT__ "DMRestrict" 2029b17ce1afSJed Brown /*@ 2030b17ce1afSJed Brown DMRestrict - restricts user-defined problem data to a coarser DM by running hooks registered by DMCoarsenHookAdd() 2031b17ce1afSJed Brown 2032b17ce1afSJed Brown Collective if any hooks are 2033b17ce1afSJed Brown 2034b17ce1afSJed Brown Input Arguments: 2035b17ce1afSJed Brown + fine - finer DM to use as a base 2036b17ce1afSJed Brown . restrct - restriction matrix, apply using MatRestrict() 2037b17ce1afSJed Brown . inject - injection matrix, also use MatRestrict() 2038b17ce1afSJed Brown - coarse - coarer DM to update 2039b17ce1afSJed Brown 2040b17ce1afSJed Brown Level: developer 2041b17ce1afSJed Brown 2042b17ce1afSJed Brown .seealso: DMCoarsenHookAdd(), MatRestrict() 2043b17ce1afSJed Brown @*/ 2044b17ce1afSJed Brown PetscErrorCode DMRestrict(DM fine,Mat restrct,Vec rscale,Mat inject,DM coarse) 2045b17ce1afSJed Brown { 2046b17ce1afSJed Brown PetscErrorCode ierr; 2047b17ce1afSJed Brown DMCoarsenHookLink link; 2048b17ce1afSJed Brown 2049b17ce1afSJed Brown PetscFunctionBegin; 2050b17ce1afSJed Brown for (link=fine->coarsenhook; link; link=link->next) { 20518865f1eaSKarl Rupp if (link->restricthook) { 20528865f1eaSKarl Rupp ierr = (*link->restricthook)(fine,restrct,rscale,inject,coarse,link->ctx);CHKERRQ(ierr); 20538865f1eaSKarl Rupp } 2054b17ce1afSJed Brown } 205547c6ae99SBarry Smith PetscFunctionReturn(0); 205647c6ae99SBarry Smith } 205747c6ae99SBarry Smith 205847c6ae99SBarry Smith #undef __FUNCT__ 2059be081cd6SPeter Brune #define __FUNCT__ "DMSubDomainHookAdd" 2060bb9467b5SJed Brown /*@C 2061be081cd6SPeter Brune DMSubDomainHookAdd - adds a callback to be run when restricting a problem to the coarse grid 20625dbd56e3SPeter Brune 20635dbd56e3SPeter Brune Logically Collective 20645dbd56e3SPeter Brune 20655dbd56e3SPeter Brune Input Arguments: 20665dbd56e3SPeter Brune + global - global DM 2067ec4806b8SPeter Brune . ddhook - function to run to pass data to the decomposition DM upon its creation 20685dbd56e3SPeter Brune . restricthook - function to run to update data on block solve (at the beginning of the block solve) 20690298fd71SBarry Smith - ctx - [optional] user-defined context for provide data for the hooks (may be NULL) 20705dbd56e3SPeter Brune 2071ec4806b8SPeter Brune 2072ec4806b8SPeter Brune Calling sequence for ddhook: 2073ec4806b8SPeter Brune $ ddhook(DM global,DM block,void *ctx) 2074ec4806b8SPeter Brune 2075ec4806b8SPeter Brune + global - global DM 2076ec4806b8SPeter Brune . block - block DM 2077ec4806b8SPeter Brune - ctx - optional user-defined function context 2078ec4806b8SPeter Brune 20795dbd56e3SPeter Brune Calling sequence for restricthook: 2080ec4806b8SPeter Brune $ restricthook(DM global,VecScatter out,VecScatter in,DM block,void *ctx) 20815dbd56e3SPeter Brune 20825dbd56e3SPeter Brune + global - global DM 20835dbd56e3SPeter Brune . out - scatter to the outer (with ghost and overlap points) block vector 20845dbd56e3SPeter Brune . in - scatter to block vector values only owned locally 2085ec4806b8SPeter Brune . block - block DM 20865dbd56e3SPeter Brune - ctx - optional user-defined function context 20875dbd56e3SPeter Brune 20885dbd56e3SPeter Brune Level: advanced 20895dbd56e3SPeter Brune 20905dbd56e3SPeter Brune Notes: 2091ec4806b8SPeter Brune This function is only needed if auxiliary data needs to be set up on subdomain DMs. 20925dbd56e3SPeter Brune 20935dbd56e3SPeter Brune If this function is called multiple times, the hooks will be run in the order they are added. 20945dbd56e3SPeter Brune 20955dbd56e3SPeter Brune In order to compose with nonlinear preconditioning without duplicating storage, the hook should be implemented to 2096ec4806b8SPeter Brune extract the global information from its context (instead of from the SNES). 20975dbd56e3SPeter Brune 2098bb9467b5SJed Brown This function is currently not available from Fortran. 2099bb9467b5SJed Brown 21005dbd56e3SPeter Brune .seealso: DMRefineHookAdd(), SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 21015dbd56e3SPeter Brune @*/ 2102be081cd6SPeter Brune PetscErrorCode DMSubDomainHookAdd(DM global,PetscErrorCode (*ddhook)(DM,DM,void*),PetscErrorCode (*restricthook)(DM,VecScatter,VecScatter,DM,void*),void *ctx) 21035dbd56e3SPeter Brune { 21045dbd56e3SPeter Brune PetscErrorCode ierr; 2105be081cd6SPeter Brune DMSubDomainHookLink link,*p; 21065dbd56e3SPeter Brune 21075dbd56e3SPeter Brune PetscFunctionBegin; 21085dbd56e3SPeter Brune PetscValidHeaderSpecific(global,DM_CLASSID,1); 2109be081cd6SPeter Brune for (p=&global->subdomainhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 2110be081cd6SPeter Brune ierr = PetscMalloc(sizeof(struct _DMSubDomainHookLink),&link);CHKERRQ(ierr); 21115dbd56e3SPeter Brune link->restricthook = restricthook; 2112be081cd6SPeter Brune link->ddhook = ddhook; 21135dbd56e3SPeter Brune link->ctx = ctx; 21140298fd71SBarry Smith link->next = NULL; 21155dbd56e3SPeter Brune *p = link; 21165dbd56e3SPeter Brune PetscFunctionReturn(0); 21175dbd56e3SPeter Brune } 21185dbd56e3SPeter Brune 21195dbd56e3SPeter Brune #undef __FUNCT__ 2120be081cd6SPeter Brune #define __FUNCT__ "DMSubDomainRestrict" 21215dbd56e3SPeter Brune /*@ 2122be081cd6SPeter Brune DMSubDomainRestrict - restricts user-defined problem data to a block DM by running hooks registered by DMSubDomainHookAdd() 21235dbd56e3SPeter Brune 21245dbd56e3SPeter Brune Collective if any hooks are 21255dbd56e3SPeter Brune 21265dbd56e3SPeter Brune Input Arguments: 21275dbd56e3SPeter Brune + fine - finer DM to use as a base 2128be081cd6SPeter Brune . oscatter - scatter from domain global vector filling subdomain global vector with overlap 2129be081cd6SPeter Brune . gscatter - scatter from domain global vector filling subdomain local vector with ghosts 21305dbd56e3SPeter Brune - coarse - coarer DM to update 21315dbd56e3SPeter Brune 21325dbd56e3SPeter Brune Level: developer 21335dbd56e3SPeter Brune 21345dbd56e3SPeter Brune .seealso: DMCoarsenHookAdd(), MatRestrict() 21355dbd56e3SPeter Brune @*/ 2136be081cd6SPeter Brune PetscErrorCode DMSubDomainRestrict(DM global,VecScatter oscatter,VecScatter gscatter,DM subdm) 21375dbd56e3SPeter Brune { 21385dbd56e3SPeter Brune PetscErrorCode ierr; 2139be081cd6SPeter Brune DMSubDomainHookLink link; 21405dbd56e3SPeter Brune 21415dbd56e3SPeter Brune PetscFunctionBegin; 2142be081cd6SPeter Brune for (link=global->subdomainhook; link; link=link->next) { 21438865f1eaSKarl Rupp if (link->restricthook) { 21448865f1eaSKarl Rupp ierr = (*link->restricthook)(global,oscatter,gscatter,subdm,link->ctx);CHKERRQ(ierr); 21458865f1eaSKarl Rupp } 21465dbd56e3SPeter Brune } 21475dbd56e3SPeter Brune PetscFunctionReturn(0); 21485dbd56e3SPeter Brune } 21495dbd56e3SPeter Brune 21505dbd56e3SPeter Brune #undef __FUNCT__ 21515fe1f584SPeter Brune #define __FUNCT__ "DMGetCoarsenLevel" 21525fe1f584SPeter Brune /*@ 21536a7d9d85SPeter Brune DMGetCoarsenLevel - Get's the number of coarsenings that have generated this DM. 21545fe1f584SPeter Brune 21555fe1f584SPeter Brune Not Collective 21565fe1f584SPeter Brune 21575fe1f584SPeter Brune Input Parameter: 21585fe1f584SPeter Brune . dm - the DM object 21595fe1f584SPeter Brune 21605fe1f584SPeter Brune Output Parameter: 21616a7d9d85SPeter Brune . level - number of coarsenings 21625fe1f584SPeter Brune 21635fe1f584SPeter Brune Level: developer 21645fe1f584SPeter Brune 21656a7d9d85SPeter Brune .seealso DMCoarsen(), DMGetRefineLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 21665fe1f584SPeter Brune 21675fe1f584SPeter Brune @*/ 21685fe1f584SPeter Brune PetscErrorCode DMGetCoarsenLevel(DM dm,PetscInt *level) 21695fe1f584SPeter Brune { 21705fe1f584SPeter Brune PetscFunctionBegin; 21715fe1f584SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 21725fe1f584SPeter Brune *level = dm->leveldown; 21735fe1f584SPeter Brune PetscFunctionReturn(0); 21745fe1f584SPeter Brune } 21755fe1f584SPeter Brune 21765fe1f584SPeter Brune 21775fe1f584SPeter Brune 21785fe1f584SPeter Brune #undef __FUNCT__ 217947c6ae99SBarry Smith #define __FUNCT__ "DMRefineHierarchy" 218047c6ae99SBarry Smith /*@C 218147c6ae99SBarry Smith DMRefineHierarchy - Refines a DM object, all levels at once 218247c6ae99SBarry Smith 218347c6ae99SBarry Smith Collective on DM 218447c6ae99SBarry Smith 218547c6ae99SBarry Smith Input Parameter: 218647c6ae99SBarry Smith + dm - the DM object 218747c6ae99SBarry Smith - nlevels - the number of levels of refinement 218847c6ae99SBarry Smith 218947c6ae99SBarry Smith Output Parameter: 219047c6ae99SBarry Smith . dmf - the refined DM hierarchy 219147c6ae99SBarry Smith 219247c6ae99SBarry Smith Level: developer 219347c6ae99SBarry Smith 2194e727c939SJed Brown .seealso DMCoarsenHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 219547c6ae99SBarry Smith 219647c6ae99SBarry Smith @*/ 21977087cfbeSBarry Smith PetscErrorCode DMRefineHierarchy(DM dm,PetscInt nlevels,DM dmf[]) 219847c6ae99SBarry Smith { 219947c6ae99SBarry Smith PetscErrorCode ierr; 220047c6ae99SBarry Smith 220147c6ae99SBarry Smith PetscFunctionBegin; 2202171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2203ce94432eSBarry Smith if (nlevels < 0) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 220447c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 220547c6ae99SBarry Smith if (dm->ops->refinehierarchy) { 220647c6ae99SBarry Smith ierr = (*dm->ops->refinehierarchy)(dm,nlevels,dmf);CHKERRQ(ierr); 220747c6ae99SBarry Smith } else if (dm->ops->refine) { 220847c6ae99SBarry Smith PetscInt i; 220947c6ae99SBarry Smith 2210ce94432eSBarry Smith ierr = DMRefine(dm,PetscObjectComm((PetscObject)dm),&dmf[0]);CHKERRQ(ierr); 221147c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 2212ce94432eSBarry Smith ierr = DMRefine(dmf[i-1],PetscObjectComm((PetscObject)dm),&dmf[i]);CHKERRQ(ierr); 221347c6ae99SBarry Smith } 2214ce94432eSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No RefineHierarchy for this DM yet"); 221547c6ae99SBarry Smith PetscFunctionReturn(0); 221647c6ae99SBarry Smith } 221747c6ae99SBarry Smith 221847c6ae99SBarry Smith #undef __FUNCT__ 221947c6ae99SBarry Smith #define __FUNCT__ "DMCoarsenHierarchy" 222047c6ae99SBarry Smith /*@C 222147c6ae99SBarry Smith DMCoarsenHierarchy - Coarsens a DM object, all levels at once 222247c6ae99SBarry Smith 222347c6ae99SBarry Smith Collective on DM 222447c6ae99SBarry Smith 222547c6ae99SBarry Smith Input Parameter: 222647c6ae99SBarry Smith + dm - the DM object 222747c6ae99SBarry Smith - nlevels - the number of levels of coarsening 222847c6ae99SBarry Smith 222947c6ae99SBarry Smith Output Parameter: 223047c6ae99SBarry Smith . dmc - the coarsened DM hierarchy 223147c6ae99SBarry Smith 223247c6ae99SBarry Smith Level: developer 223347c6ae99SBarry Smith 2234e727c939SJed Brown .seealso DMRefineHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 223547c6ae99SBarry Smith 223647c6ae99SBarry Smith @*/ 22377087cfbeSBarry Smith PetscErrorCode DMCoarsenHierarchy(DM dm, PetscInt nlevels, DM dmc[]) 223847c6ae99SBarry Smith { 223947c6ae99SBarry Smith PetscErrorCode ierr; 224047c6ae99SBarry Smith 224147c6ae99SBarry Smith PetscFunctionBegin; 2242171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2243ce94432eSBarry Smith if (nlevels < 0) SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 224447c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 224547c6ae99SBarry Smith PetscValidPointer(dmc,3); 224647c6ae99SBarry Smith if (dm->ops->coarsenhierarchy) { 224747c6ae99SBarry Smith ierr = (*dm->ops->coarsenhierarchy)(dm, nlevels, dmc);CHKERRQ(ierr); 224847c6ae99SBarry Smith } else if (dm->ops->coarsen) { 224947c6ae99SBarry Smith PetscInt i; 225047c6ae99SBarry Smith 2251ce94432eSBarry Smith ierr = DMCoarsen(dm,PetscObjectComm((PetscObject)dm),&dmc[0]);CHKERRQ(ierr); 225247c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 2253ce94432eSBarry Smith ierr = DMCoarsen(dmc[i-1],PetscObjectComm((PetscObject)dm),&dmc[i]);CHKERRQ(ierr); 225447c6ae99SBarry Smith } 2255ce94432eSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"No CoarsenHierarchy for this DM yet"); 225647c6ae99SBarry Smith PetscFunctionReturn(0); 225747c6ae99SBarry Smith } 225847c6ae99SBarry Smith 225947c6ae99SBarry Smith #undef __FUNCT__ 2260e727c939SJed Brown #define __FUNCT__ "DMCreateAggregates" 226147c6ae99SBarry Smith /*@ 2262e727c939SJed Brown DMCreateAggregates - Gets the aggregates that map between 226347c6ae99SBarry Smith grids associated with two DMs. 226447c6ae99SBarry Smith 226547c6ae99SBarry Smith Collective on DM 226647c6ae99SBarry Smith 226747c6ae99SBarry Smith Input Parameters: 226847c6ae99SBarry Smith + dmc - the coarse grid DM 226947c6ae99SBarry Smith - dmf - the fine grid DM 227047c6ae99SBarry Smith 227147c6ae99SBarry Smith Output Parameters: 227247c6ae99SBarry Smith . rest - the restriction matrix (transpose of the projection matrix) 227347c6ae99SBarry Smith 227447c6ae99SBarry Smith Level: intermediate 227547c6ae99SBarry Smith 227647c6ae99SBarry Smith .keywords: interpolation, restriction, multigrid 227747c6ae99SBarry Smith 2278e727c939SJed Brown .seealso: DMRefine(), DMCreateInjection(), DMCreateInterpolation() 227947c6ae99SBarry Smith @*/ 2280e727c939SJed Brown PetscErrorCode DMCreateAggregates(DM dmc, DM dmf, Mat *rest) 228147c6ae99SBarry Smith { 228247c6ae99SBarry Smith PetscErrorCode ierr; 228347c6ae99SBarry Smith 228447c6ae99SBarry Smith PetscFunctionBegin; 2285171400e9SBarry Smith PetscValidHeaderSpecific(dmc,DM_CLASSID,1); 2286171400e9SBarry Smith PetscValidHeaderSpecific(dmf,DM_CLASSID,2); 228747c6ae99SBarry Smith ierr = (*dmc->ops->getaggregates)(dmc, dmf, rest);CHKERRQ(ierr); 228847c6ae99SBarry Smith PetscFunctionReturn(0); 228947c6ae99SBarry Smith } 229047c6ae99SBarry Smith 229147c6ae99SBarry Smith #undef __FUNCT__ 22921a266240SBarry Smith #define __FUNCT__ "DMSetApplicationContextDestroy" 22931a266240SBarry Smith /*@C 22941a266240SBarry Smith DMSetApplicationContextDestroy - Sets a user function that will be called to destroy the application context when the DM is destroyed 22951a266240SBarry Smith 22961a266240SBarry Smith Not Collective 22971a266240SBarry Smith 22981a266240SBarry Smith Input Parameters: 22991a266240SBarry Smith + dm - the DM object 23001a266240SBarry Smith - destroy - the destroy function 23011a266240SBarry Smith 23021a266240SBarry Smith Level: intermediate 23031a266240SBarry Smith 2304e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 23051a266240SBarry Smith 2306f07f9ceaSJed Brown @*/ 23071a266240SBarry Smith PetscErrorCode DMSetApplicationContextDestroy(DM dm,PetscErrorCode (*destroy)(void**)) 23081a266240SBarry Smith { 23091a266240SBarry Smith PetscFunctionBegin; 2310171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 23111a266240SBarry Smith dm->ctxdestroy = destroy; 23121a266240SBarry Smith PetscFunctionReturn(0); 23131a266240SBarry Smith } 23141a266240SBarry Smith 23151a266240SBarry Smith #undef __FUNCT__ 23161b2093e4SBarry Smith #define __FUNCT__ "DMSetApplicationContext" 2317b07ff414SBarry Smith /*@ 23181b2093e4SBarry Smith DMSetApplicationContext - Set a user context into a DM object 231947c6ae99SBarry Smith 232047c6ae99SBarry Smith Not Collective 232147c6ae99SBarry Smith 232247c6ae99SBarry Smith Input Parameters: 232347c6ae99SBarry Smith + dm - the DM object 232447c6ae99SBarry Smith - ctx - the user context 232547c6ae99SBarry Smith 232647c6ae99SBarry Smith Level: intermediate 232747c6ae99SBarry Smith 2328e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 232947c6ae99SBarry Smith 233047c6ae99SBarry Smith @*/ 23311b2093e4SBarry Smith PetscErrorCode DMSetApplicationContext(DM dm,void *ctx) 233247c6ae99SBarry Smith { 233347c6ae99SBarry Smith PetscFunctionBegin; 2334171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 233547c6ae99SBarry Smith dm->ctx = ctx; 233647c6ae99SBarry Smith PetscFunctionReturn(0); 233747c6ae99SBarry Smith } 233847c6ae99SBarry Smith 233947c6ae99SBarry Smith #undef __FUNCT__ 23401b2093e4SBarry Smith #define __FUNCT__ "DMGetApplicationContext" 234147c6ae99SBarry Smith /*@ 23421b2093e4SBarry Smith DMGetApplicationContext - Gets a user context from a DM object 234347c6ae99SBarry Smith 234447c6ae99SBarry Smith Not Collective 234547c6ae99SBarry Smith 234647c6ae99SBarry Smith Input Parameter: 234747c6ae99SBarry Smith . dm - the DM object 234847c6ae99SBarry Smith 234947c6ae99SBarry Smith Output Parameter: 235047c6ae99SBarry Smith . ctx - the user context 235147c6ae99SBarry Smith 235247c6ae99SBarry Smith Level: intermediate 235347c6ae99SBarry Smith 2354e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 235547c6ae99SBarry Smith 235647c6ae99SBarry Smith @*/ 23571b2093e4SBarry Smith PetscErrorCode DMGetApplicationContext(DM dm,void *ctx) 235847c6ae99SBarry Smith { 235947c6ae99SBarry Smith PetscFunctionBegin; 2360171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 23611b2093e4SBarry Smith *(void**)ctx = dm->ctx; 236247c6ae99SBarry Smith PetscFunctionReturn(0); 236347c6ae99SBarry Smith } 236447c6ae99SBarry Smith 236547c6ae99SBarry Smith #undef __FUNCT__ 236608da532bSDmitry Karpeev #define __FUNCT__ "DMSetVariableBounds" 236708da532bSDmitry Karpeev /*@C 236808da532bSDmitry Karpeev DMSetVariableBounds - sets a function to compute the the lower and upper bound vectors for SNESVI. 236908da532bSDmitry Karpeev 237008da532bSDmitry Karpeev Logically Collective on DM 237108da532bSDmitry Karpeev 237208da532bSDmitry Karpeev Input Parameter: 237308da532bSDmitry Karpeev + dm - the DM object 23740298fd71SBarry Smith - f - the function that computes variable bounds used by SNESVI (use NULL to cancel a previous function that was set) 237508da532bSDmitry Karpeev 237608da532bSDmitry Karpeev Level: intermediate 237708da532bSDmitry Karpeev 2378835c3ec7SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), 237908da532bSDmitry Karpeev DMSetJacobian() 238008da532bSDmitry Karpeev 238108da532bSDmitry Karpeev @*/ 238208da532bSDmitry Karpeev PetscErrorCode DMSetVariableBounds(DM dm,PetscErrorCode (*f)(DM,Vec,Vec)) 238308da532bSDmitry Karpeev { 238408da532bSDmitry Karpeev PetscFunctionBegin; 238508da532bSDmitry Karpeev dm->ops->computevariablebounds = f; 238608da532bSDmitry Karpeev PetscFunctionReturn(0); 238708da532bSDmitry Karpeev } 238808da532bSDmitry Karpeev 238908da532bSDmitry Karpeev #undef __FUNCT__ 239008da532bSDmitry Karpeev #define __FUNCT__ "DMHasVariableBounds" 239108da532bSDmitry Karpeev /*@ 239208da532bSDmitry Karpeev DMHasVariableBounds - does the DM object have a variable bounds function? 239308da532bSDmitry Karpeev 239408da532bSDmitry Karpeev Not Collective 239508da532bSDmitry Karpeev 239608da532bSDmitry Karpeev Input Parameter: 239708da532bSDmitry Karpeev . dm - the DM object to destroy 239808da532bSDmitry Karpeev 239908da532bSDmitry Karpeev Output Parameter: 240008da532bSDmitry Karpeev . flg - PETSC_TRUE if the variable bounds function exists 240108da532bSDmitry Karpeev 240208da532bSDmitry Karpeev Level: developer 240308da532bSDmitry Karpeev 240474e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 240508da532bSDmitry Karpeev 240608da532bSDmitry Karpeev @*/ 240708da532bSDmitry Karpeev PetscErrorCode DMHasVariableBounds(DM dm,PetscBool *flg) 240808da532bSDmitry Karpeev { 240908da532bSDmitry Karpeev PetscFunctionBegin; 241008da532bSDmitry Karpeev *flg = (dm->ops->computevariablebounds) ? PETSC_TRUE : PETSC_FALSE; 241108da532bSDmitry Karpeev PetscFunctionReturn(0); 241208da532bSDmitry Karpeev } 241308da532bSDmitry Karpeev 241408da532bSDmitry Karpeev #undef __FUNCT__ 241508da532bSDmitry Karpeev #define __FUNCT__ "DMComputeVariableBounds" 241608da532bSDmitry Karpeev /*@C 241708da532bSDmitry Karpeev DMComputeVariableBounds - compute variable bounds used by SNESVI. 241808da532bSDmitry Karpeev 241908da532bSDmitry Karpeev Logically Collective on DM 242008da532bSDmitry Karpeev 242108da532bSDmitry Karpeev Input Parameters: 242208da532bSDmitry Karpeev + dm - the DM object to destroy 242308da532bSDmitry Karpeev - x - current solution at which the bounds are computed 242408da532bSDmitry Karpeev 242508da532bSDmitry Karpeev Output parameters: 242608da532bSDmitry Karpeev + xl - lower bound 242708da532bSDmitry Karpeev - xu - upper bound 242808da532bSDmitry Karpeev 242908da532bSDmitry Karpeev Level: intermediate 243008da532bSDmitry Karpeev 243174e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 243208da532bSDmitry Karpeev 243308da532bSDmitry Karpeev @*/ 243408da532bSDmitry Karpeev PetscErrorCode DMComputeVariableBounds(DM dm, Vec xl, Vec xu) 243508da532bSDmitry Karpeev { 243608da532bSDmitry Karpeev PetscErrorCode ierr; 24375fd66863SKarl Rupp 243808da532bSDmitry Karpeev PetscFunctionBegin; 243908da532bSDmitry Karpeev PetscValidHeaderSpecific(xl,VEC_CLASSID,2); 244008da532bSDmitry Karpeev PetscValidHeaderSpecific(xu,VEC_CLASSID,2); 244108da532bSDmitry Karpeev if (dm->ops->computevariablebounds) { 244208da532bSDmitry Karpeev ierr = (*dm->ops->computevariablebounds)(dm, xl,xu);CHKERRQ(ierr); 24438865f1eaSKarl Rupp } else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "This DM is incapable of computing variable bounds."); 244408da532bSDmitry Karpeev PetscFunctionReturn(0); 244508da532bSDmitry Karpeev } 244608da532bSDmitry Karpeev 244708da532bSDmitry Karpeev #undef __FUNCT__ 2448b0ae01b7SPeter Brune #define __FUNCT__ "DMHasColoring" 2449b0ae01b7SPeter Brune /*@ 2450b0ae01b7SPeter Brune DMHasColoring - does the DM object have a method of providing a coloring? 2451b0ae01b7SPeter Brune 2452b0ae01b7SPeter Brune Not Collective 2453b0ae01b7SPeter Brune 2454b0ae01b7SPeter Brune Input Parameter: 2455b0ae01b7SPeter Brune . dm - the DM object 2456b0ae01b7SPeter Brune 2457b0ae01b7SPeter Brune Output Parameter: 2458b0ae01b7SPeter Brune . flg - PETSC_TRUE if the DM has facilities for DMCreateColoring(). 2459b0ae01b7SPeter Brune 2460b0ae01b7SPeter Brune Level: developer 2461b0ae01b7SPeter Brune 2462b0ae01b7SPeter Brune .seealso DMHasFunction(), DMCreateColoring() 2463b0ae01b7SPeter Brune 2464b0ae01b7SPeter Brune @*/ 2465b0ae01b7SPeter Brune PetscErrorCode DMHasColoring(DM dm,PetscBool *flg) 2466b0ae01b7SPeter Brune { 2467b0ae01b7SPeter Brune PetscFunctionBegin; 2468b0ae01b7SPeter Brune *flg = (dm->ops->getcoloring) ? PETSC_TRUE : PETSC_FALSE; 2469b0ae01b7SPeter Brune PetscFunctionReturn(0); 2470b0ae01b7SPeter Brune } 2471b0ae01b7SPeter Brune 2472b0ae01b7SPeter Brune #undef __FUNCT__ 247308da532bSDmitry Karpeev #define __FUNCT__ "DMSetVec" 2474748fac09SDmitry Karpeev /*@C 247508da532bSDmitry Karpeev DMSetVec - set the vector at which to compute residual, Jacobian and VI bounds, if the problem is nonlinear. 247608da532bSDmitry Karpeev 247708da532bSDmitry Karpeev Collective on DM 247808da532bSDmitry Karpeev 247908da532bSDmitry Karpeev Input Parameter: 248008da532bSDmitry Karpeev + dm - the DM object 24810298fd71SBarry Smith - x - location to compute residual and Jacobian, if NULL is passed to those routines; will be NULL for linear problems. 248208da532bSDmitry Karpeev 248308da532bSDmitry Karpeev Level: developer 248408da532bSDmitry Karpeev 248574e1e8c1SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 248608da532bSDmitry Karpeev 248708da532bSDmitry Karpeev @*/ 248808da532bSDmitry Karpeev PetscErrorCode DMSetVec(DM dm,Vec x) 248908da532bSDmitry Karpeev { 249008da532bSDmitry Karpeev PetscErrorCode ierr; 24915fd66863SKarl Rupp 249208da532bSDmitry Karpeev PetscFunctionBegin; 249308da532bSDmitry Karpeev if (x) { 249408da532bSDmitry Karpeev if (!dm->x) { 249508da532bSDmitry Karpeev ierr = DMCreateGlobalVector(dm,&dm->x);CHKERRQ(ierr); 249608da532bSDmitry Karpeev } 249708da532bSDmitry Karpeev ierr = VecCopy(x,dm->x);CHKERRQ(ierr); 24988865f1eaSKarl Rupp } else if (dm->x) { 249908da532bSDmitry Karpeev ierr = VecDestroy(&dm->x);CHKERRQ(ierr); 250008da532bSDmitry Karpeev } 250108da532bSDmitry Karpeev PetscFunctionReturn(0); 250208da532bSDmitry Karpeev } 250308da532bSDmitry Karpeev 25040298fd71SBarry Smith PetscFunctionList DMList = NULL; 2505264ace61SBarry Smith PetscBool DMRegisterAllCalled = PETSC_FALSE; 2506264ace61SBarry Smith 2507264ace61SBarry Smith #undef __FUNCT__ 2508264ace61SBarry Smith #define __FUNCT__ "DMSetType" 2509264ace61SBarry Smith /*@C 2510264ace61SBarry Smith DMSetType - Builds a DM, for a particular DM implementation. 2511264ace61SBarry Smith 2512264ace61SBarry Smith Collective on DM 2513264ace61SBarry Smith 2514264ace61SBarry Smith Input Parameters: 2515264ace61SBarry Smith + dm - The DM object 2516264ace61SBarry Smith - method - The name of the DM type 2517264ace61SBarry Smith 2518264ace61SBarry Smith Options Database Key: 2519264ace61SBarry Smith . -dm_type <type> - Sets the DM type; use -help for a list of available types 2520264ace61SBarry Smith 2521264ace61SBarry Smith Notes: 2522e1589f56SBarry Smith See "petsc/include/petscdm.h" for available DM types (for instance, DM1D, DM2D, or DM3D). 2523264ace61SBarry Smith 2524264ace61SBarry Smith Level: intermediate 2525264ace61SBarry Smith 2526264ace61SBarry Smith .keywords: DM, set, type 2527264ace61SBarry Smith .seealso: DMGetType(), DMCreate() 2528264ace61SBarry Smith @*/ 252919fd82e9SBarry Smith PetscErrorCode DMSetType(DM dm, DMType method) 2530264ace61SBarry Smith { 2531264ace61SBarry Smith PetscErrorCode (*r)(DM); 2532264ace61SBarry Smith PetscBool match; 2533264ace61SBarry Smith PetscErrorCode ierr; 2534264ace61SBarry Smith 2535264ace61SBarry Smith PetscFunctionBegin; 2536264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 2537251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject) dm, method, &match);CHKERRQ(ierr); 2538264ace61SBarry Smith if (match) PetscFunctionReturn(0); 2539264ace61SBarry Smith 2540607a6623SBarry Smith if (!DMRegisterAllCalled) {ierr = DMRegisterAll();CHKERRQ(ierr);} 25411c9cd337SJed Brown ierr = PetscFunctionListFind(DMList,method,&r);CHKERRQ(ierr); 2542ce94432eSBarry Smith if (!r) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown DM type: %s", method); 2543264ace61SBarry Smith 2544264ace61SBarry Smith if (dm->ops->destroy) { 2545264ace61SBarry Smith ierr = (*dm->ops->destroy)(dm);CHKERRQ(ierr); 25460298fd71SBarry Smith dm->ops->destroy = NULL; 2547264ace61SBarry Smith } 2548264ace61SBarry Smith ierr = (*r)(dm);CHKERRQ(ierr); 2549264ace61SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)dm,method);CHKERRQ(ierr); 2550264ace61SBarry Smith PetscFunctionReturn(0); 2551264ace61SBarry Smith } 2552264ace61SBarry Smith 2553264ace61SBarry Smith #undef __FUNCT__ 2554264ace61SBarry Smith #define __FUNCT__ "DMGetType" 2555264ace61SBarry Smith /*@C 2556264ace61SBarry Smith DMGetType - Gets the DM type name (as a string) from the DM. 2557264ace61SBarry Smith 2558264ace61SBarry Smith Not Collective 2559264ace61SBarry Smith 2560264ace61SBarry Smith Input Parameter: 2561264ace61SBarry Smith . dm - The DM 2562264ace61SBarry Smith 2563264ace61SBarry Smith Output Parameter: 2564264ace61SBarry Smith . type - The DM type name 2565264ace61SBarry Smith 2566264ace61SBarry Smith Level: intermediate 2567264ace61SBarry Smith 2568264ace61SBarry Smith .keywords: DM, get, type, name 2569264ace61SBarry Smith .seealso: DMSetType(), DMCreate() 2570264ace61SBarry Smith @*/ 257119fd82e9SBarry Smith PetscErrorCode DMGetType(DM dm, DMType *type) 2572264ace61SBarry Smith { 2573264ace61SBarry Smith PetscErrorCode ierr; 2574264ace61SBarry Smith 2575264ace61SBarry Smith PetscFunctionBegin; 2576264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 2577264ace61SBarry Smith PetscValidCharPointer(type,2); 2578264ace61SBarry Smith if (!DMRegisterAllCalled) { 2579607a6623SBarry Smith ierr = DMRegisterAll();CHKERRQ(ierr); 2580264ace61SBarry Smith } 2581264ace61SBarry Smith *type = ((PetscObject)dm)->type_name; 2582264ace61SBarry Smith PetscFunctionReturn(0); 2583264ace61SBarry Smith } 2584264ace61SBarry Smith 258567a56275SMatthew G Knepley #undef __FUNCT__ 258667a56275SMatthew G Knepley #define __FUNCT__ "DMConvert" 258767a56275SMatthew G Knepley /*@C 258867a56275SMatthew G Knepley DMConvert - Converts a DM to another DM, either of the same or different type. 258967a56275SMatthew G Knepley 259067a56275SMatthew G Knepley Collective on DM 259167a56275SMatthew G Knepley 259267a56275SMatthew G Knepley Input Parameters: 259367a56275SMatthew G Knepley + dm - the DM 259467a56275SMatthew G Knepley - newtype - new DM type (use "same" for the same type) 259567a56275SMatthew G Knepley 259667a56275SMatthew G Knepley Output Parameter: 259767a56275SMatthew G Knepley . M - pointer to new DM 259867a56275SMatthew G Knepley 259967a56275SMatthew G Knepley Notes: 260067a56275SMatthew G Knepley Cannot be used to convert a sequential DM to parallel or parallel to sequential, 260167a56275SMatthew G Knepley the MPI communicator of the generated DM is always the same as the communicator 260267a56275SMatthew G Knepley of the input DM. 260367a56275SMatthew G Knepley 260467a56275SMatthew G Knepley Level: intermediate 260567a56275SMatthew G Knepley 260667a56275SMatthew G Knepley .seealso: DMCreate() 260767a56275SMatthew G Knepley @*/ 260819fd82e9SBarry Smith PetscErrorCode DMConvert(DM dm, DMType newtype, DM *M) 260967a56275SMatthew G Knepley { 261067a56275SMatthew G Knepley DM B; 261167a56275SMatthew G Knepley char convname[256]; 261267a56275SMatthew G Knepley PetscBool sametype, issame; 261367a56275SMatthew G Knepley PetscErrorCode ierr; 261467a56275SMatthew G Knepley 261567a56275SMatthew G Knepley PetscFunctionBegin; 261667a56275SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 261767a56275SMatthew G Knepley PetscValidType(dm,1); 261867a56275SMatthew G Knepley PetscValidPointer(M,3); 2619251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject) dm, newtype, &sametype);CHKERRQ(ierr); 262067a56275SMatthew G Knepley ierr = PetscStrcmp(newtype, "same", &issame);CHKERRQ(ierr); 262167a56275SMatthew G Knepley { 26220298fd71SBarry Smith PetscErrorCode (*conv)(DM, DMType, DM*) = NULL; 262367a56275SMatthew G Knepley 262467a56275SMatthew G Knepley /* 262567a56275SMatthew G Knepley Order of precedence: 262667a56275SMatthew G Knepley 1) See if a specialized converter is known to the current DM. 262767a56275SMatthew G Knepley 2) See if a specialized converter is known to the desired DM class. 262867a56275SMatthew G Knepley 3) See if a good general converter is registered for the desired class 262967a56275SMatthew G Knepley 4) See if a good general converter is known for the current matrix. 263067a56275SMatthew G Knepley 5) Use a really basic converter. 263167a56275SMatthew G Knepley */ 263267a56275SMatthew G Knepley 263367a56275SMatthew G Knepley /* 1) See if a specialized converter is known to the current DM and the desired class */ 263467a56275SMatthew G Knepley ierr = PetscStrcpy(convname,"DMConvert_");CHKERRQ(ierr); 263567a56275SMatthew G Knepley ierr = PetscStrcat(convname,((PetscObject) dm)->type_name);CHKERRQ(ierr); 263667a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_");CHKERRQ(ierr); 263767a56275SMatthew G Knepley ierr = PetscStrcat(convname,newtype);CHKERRQ(ierr); 263867a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_C");CHKERRQ(ierr); 26390005d66cSJed Brown ierr = PetscObjectQueryFunction((PetscObject)dm,convname,&conv);CHKERRQ(ierr); 264067a56275SMatthew G Knepley if (conv) goto foundconv; 264167a56275SMatthew G Knepley 264267a56275SMatthew G Knepley /* 2) See if a specialized converter is known to the desired DM class. */ 264382f516ccSBarry Smith ierr = DMCreate(PetscObjectComm((PetscObject)dm), &B);CHKERRQ(ierr); 264467a56275SMatthew G Knepley ierr = DMSetType(B, newtype);CHKERRQ(ierr); 264567a56275SMatthew G Knepley ierr = PetscStrcpy(convname,"DMConvert_");CHKERRQ(ierr); 264667a56275SMatthew G Knepley ierr = PetscStrcat(convname,((PetscObject) dm)->type_name);CHKERRQ(ierr); 264767a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_");CHKERRQ(ierr); 264867a56275SMatthew G Knepley ierr = PetscStrcat(convname,newtype);CHKERRQ(ierr); 264967a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_C");CHKERRQ(ierr); 26500005d66cSJed Brown ierr = PetscObjectQueryFunction((PetscObject)B,convname,&conv);CHKERRQ(ierr); 265167a56275SMatthew G Knepley if (conv) { 2652fcfd50ebSBarry Smith ierr = DMDestroy(&B);CHKERRQ(ierr); 265367a56275SMatthew G Knepley goto foundconv; 265467a56275SMatthew G Knepley } 265567a56275SMatthew G Knepley 265667a56275SMatthew G Knepley #if 0 265767a56275SMatthew G Knepley /* 3) See if a good general converter is registered for the desired class */ 265867a56275SMatthew G Knepley conv = B->ops->convertfrom; 2659fcfd50ebSBarry Smith ierr = DMDestroy(&B);CHKERRQ(ierr); 266067a56275SMatthew G Knepley if (conv) goto foundconv; 266167a56275SMatthew G Knepley 266267a56275SMatthew G Knepley /* 4) See if a good general converter is known for the current matrix */ 266367a56275SMatthew G Knepley if (dm->ops->convert) { 266467a56275SMatthew G Knepley conv = dm->ops->convert; 266567a56275SMatthew G Knepley } 266667a56275SMatthew G Knepley if (conv) goto foundconv; 266767a56275SMatthew G Knepley #endif 266867a56275SMatthew G Knepley 266967a56275SMatthew G Knepley /* 5) Use a really basic converter. */ 267082f516ccSBarry Smith SETERRQ2(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "No conversion possible between DM types %s and %s", ((PetscObject) dm)->type_name, newtype); 267167a56275SMatthew G Knepley 267267a56275SMatthew G Knepley foundconv: 267367a56275SMatthew G Knepley ierr = PetscLogEventBegin(DM_Convert,dm,0,0,0);CHKERRQ(ierr); 267467a56275SMatthew G Knepley ierr = (*conv)(dm,newtype,M);CHKERRQ(ierr); 267567a56275SMatthew G Knepley ierr = PetscLogEventEnd(DM_Convert,dm,0,0,0);CHKERRQ(ierr); 267667a56275SMatthew G Knepley } 267767a56275SMatthew G Knepley ierr = PetscObjectStateIncrease((PetscObject) *M);CHKERRQ(ierr); 267867a56275SMatthew G Knepley PetscFunctionReturn(0); 267967a56275SMatthew G Knepley } 2680264ace61SBarry Smith 2681264ace61SBarry Smith /*--------------------------------------------------------------------------------------------------------------------*/ 2682264ace61SBarry Smith 2683264ace61SBarry Smith #undef __FUNCT__ 2684264ace61SBarry Smith #define __FUNCT__ "DMRegister" 2685264ace61SBarry Smith /*@C 26861c84c290SBarry Smith DMRegister - Adds a new DM component implementation 26871c84c290SBarry Smith 26881c84c290SBarry Smith Not Collective 26891c84c290SBarry Smith 26901c84c290SBarry Smith Input Parameters: 26911c84c290SBarry Smith + name - The name of a new user-defined creation routine 26921c84c290SBarry Smith - create_func - The creation routine itself 26931c84c290SBarry Smith 26941c84c290SBarry Smith Notes: 26951c84c290SBarry Smith DMRegister() may be called multiple times to add several user-defined DMs 26961c84c290SBarry Smith 26971c84c290SBarry Smith 26981c84c290SBarry Smith Sample usage: 26991c84c290SBarry Smith .vb 2700bdf89e91SBarry Smith DMRegister("my_da", MyDMCreate); 27011c84c290SBarry Smith .ve 27021c84c290SBarry Smith 27031c84c290SBarry Smith Then, your DM type can be chosen with the procedural interface via 27041c84c290SBarry Smith .vb 27051c84c290SBarry Smith DMCreate(MPI_Comm, DM *); 27061c84c290SBarry Smith DMSetType(DM,"my_da"); 27071c84c290SBarry Smith .ve 27081c84c290SBarry Smith or at runtime via the option 27091c84c290SBarry Smith .vb 27101c84c290SBarry Smith -da_type my_da 27111c84c290SBarry Smith .ve 2712264ace61SBarry Smith 2713264ace61SBarry Smith Level: advanced 27141c84c290SBarry Smith 27151c84c290SBarry Smith .keywords: DM, register 2716bdf89e91SBarry Smith .seealso: DMRegisterAll(), DMRegisterDestroy() 27171c84c290SBarry Smith 2718264ace61SBarry Smith @*/ 2719bdf89e91SBarry Smith PetscErrorCode DMRegister(const char sname[],PetscErrorCode (*function)(DM)) 2720264ace61SBarry Smith { 2721264ace61SBarry Smith PetscErrorCode ierr; 2722264ace61SBarry Smith 2723264ace61SBarry Smith PetscFunctionBegin; 2724a240a19fSJed Brown ierr = PetscFunctionListAdd(&DMList,sname,function);CHKERRQ(ierr); 2725264ace61SBarry Smith PetscFunctionReturn(0); 2726264ace61SBarry Smith } 2727264ace61SBarry Smith 2728b859378eSBarry Smith #undef __FUNCT__ 2729b859378eSBarry Smith #define __FUNCT__ "DMLoad" 2730b859378eSBarry Smith /*@C 273155849f57SBarry Smith DMLoad - Loads a DM that has been stored in binary with DMView(). 2732b859378eSBarry Smith 2733b859378eSBarry Smith Collective on PetscViewer 2734b859378eSBarry Smith 2735b859378eSBarry Smith Input Parameters: 2736b859378eSBarry Smith + newdm - the newly loaded DM, this needs to have been created with DMCreate() or 2737b859378eSBarry Smith some related function before a call to DMLoad(). 2738b859378eSBarry Smith - viewer - binary file viewer, obtained from PetscViewerBinaryOpen() or 2739b859378eSBarry Smith HDF5 file viewer, obtained from PetscViewerHDF5Open() 2740b859378eSBarry Smith 2741b859378eSBarry Smith Level: intermediate 2742b859378eSBarry Smith 2743b859378eSBarry Smith Notes: 274455849f57SBarry Smith The type is determined by the data in the file, any type set into the DM before this call is ignored. 2745b859378eSBarry Smith 2746b859378eSBarry Smith Notes for advanced users: 2747b859378eSBarry Smith Most users should not need to know the details of the binary storage 2748b859378eSBarry Smith format, since DMLoad() and DMView() completely hide these details. 2749b859378eSBarry Smith But for anyone who's interested, the standard binary matrix storage 2750b859378eSBarry Smith format is 2751b859378eSBarry Smith .vb 2752b859378eSBarry Smith has not yet been determined 2753b859378eSBarry Smith .ve 2754b859378eSBarry Smith 2755b859378eSBarry Smith .seealso: PetscViewerBinaryOpen(), DMView(), MatLoad(), VecLoad() 2756b859378eSBarry Smith @*/ 2757b859378eSBarry Smith PetscErrorCode DMLoad(DM newdm, PetscViewer viewer) 2758b859378eSBarry Smith { 2759b859378eSBarry Smith PetscErrorCode ierr; 276032c0f0efSBarry Smith PetscBool isbinary; 276155849f57SBarry Smith PetscInt classid; 276232c0f0efSBarry Smith char type[256]; 2763b859378eSBarry Smith 2764b859378eSBarry Smith PetscFunctionBegin; 2765b859378eSBarry Smith PetscValidHeaderSpecific(newdm,DM_CLASSID,1); 2766b859378eSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 276732c0f0efSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); 276832c0f0efSBarry Smith if (!isbinary) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Invalid viewer; open viewer with PetscViewerBinaryOpen()"); 2769b859378eSBarry Smith 277032c0f0efSBarry Smith ierr = PetscViewerBinaryRead(viewer,&classid,1,PETSC_INT);CHKERRQ(ierr); 27719200755eSBarry Smith if (classid != DM_FILE_CLASSID) SETERRQ1(PetscObjectComm((PetscObject)newdm),PETSC_ERR_ARG_WRONG,"Not DM next in file, classid found %d",(int)classid); 277232c0f0efSBarry Smith ierr = PetscViewerBinaryRead(viewer,type,256,PETSC_CHAR);CHKERRQ(ierr); 277332c0f0efSBarry Smith ierr = DMSetType(newdm, type);CHKERRQ(ierr); 27742d53ad75SBarry Smith if (newdm->ops->load) { 2775b859378eSBarry Smith ierr = (*newdm->ops->load)(newdm,viewer);CHKERRQ(ierr); 27762d53ad75SBarry Smith } 2777b859378eSBarry Smith PetscFunctionReturn(0); 2778b859378eSBarry Smith } 2779b859378eSBarry Smith 27807da65231SMatthew G Knepley /******************************** FEM Support **********************************/ 27817da65231SMatthew G Knepley 27827da65231SMatthew G Knepley #undef __FUNCT__ 27837da65231SMatthew G Knepley #define __FUNCT__ "DMPrintCellVector" 2784a6dfd86eSKarl Rupp PetscErrorCode DMPrintCellVector(PetscInt c, const char name[], PetscInt len, const PetscScalar x[]) 2785a6dfd86eSKarl Rupp { 27861d47ebbbSSatish Balay PetscInt f; 27871b30c384SMatthew G Knepley PetscErrorCode ierr; 27881b30c384SMatthew G Knepley 27897da65231SMatthew G Knepley PetscFunctionBegin; 279074778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, "Cell %D Element %s\n", c, name);CHKERRQ(ierr); 27911d47ebbbSSatish Balay for (f = 0; f < len; ++f) { 279257622a8eSBarry Smith ierr = PetscPrintf(PETSC_COMM_SELF, " | %g |\n", (double)PetscRealPart(x[f]));CHKERRQ(ierr); 27937da65231SMatthew G Knepley } 27947da65231SMatthew G Knepley PetscFunctionReturn(0); 27957da65231SMatthew G Knepley } 27967da65231SMatthew G Knepley 27977da65231SMatthew G Knepley #undef __FUNCT__ 27987da65231SMatthew G Knepley #define __FUNCT__ "DMPrintCellMatrix" 2799a6dfd86eSKarl Rupp PetscErrorCode DMPrintCellMatrix(PetscInt c, const char name[], PetscInt rows, PetscInt cols, const PetscScalar A[]) 2800a6dfd86eSKarl Rupp { 28011b30c384SMatthew G Knepley PetscInt f, g; 28027da65231SMatthew G Knepley PetscErrorCode ierr; 28037da65231SMatthew G Knepley 28047da65231SMatthew G Knepley PetscFunctionBegin; 280574778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, "Cell %D Element %s\n", c, name);CHKERRQ(ierr); 28061d47ebbbSSatish Balay for (f = 0; f < rows; ++f) { 280774778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " |");CHKERRQ(ierr); 28081d47ebbbSSatish Balay for (g = 0; g < cols; ++g) { 2809e3556bceSMatthew G. Knepley ierr = PetscPrintf(PETSC_COMM_SELF, " % 9.5g", PetscRealPart(A[f*cols+g]));CHKERRQ(ierr); 28107da65231SMatthew G Knepley } 281174778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " |\n");CHKERRQ(ierr); 28127da65231SMatthew G Knepley } 28137da65231SMatthew G Knepley PetscFunctionReturn(0); 28147da65231SMatthew G Knepley } 2815e7c4fc90SDmitry Karpeev 2816970e74d5SMatthew G Knepley #undef __FUNCT__ 2817e759306cSMatthew G. Knepley #define __FUNCT__ "DMPrintLocalVec" 28186113b454SMatthew G. Knepley PetscErrorCode DMPrintLocalVec(DM dm, const char name[], PetscReal tol, Vec X) 2819e759306cSMatthew G. Knepley { 2820e759306cSMatthew G. Knepley PetscMPIInt rank, numProcs; 2821e759306cSMatthew G. Knepley PetscInt p; 2822e759306cSMatthew G. Knepley PetscErrorCode ierr; 2823e759306cSMatthew G. Knepley 2824e759306cSMatthew G. Knepley PetscFunctionBegin; 2825e759306cSMatthew G. Knepley ierr = MPI_Comm_rank(PetscObjectComm((PetscObject) dm), &rank);CHKERRQ(ierr); 2826e759306cSMatthew G. Knepley ierr = MPI_Comm_size(PetscObjectComm((PetscObject) dm), &numProcs);CHKERRQ(ierr); 2827e759306cSMatthew G. Knepley ierr = PetscPrintf(PetscObjectComm((PetscObject) dm), "%s:\n", name);CHKERRQ(ierr); 2828e759306cSMatthew G. Knepley for (p = 0; p < numProcs; ++p) { 2829e759306cSMatthew G. Knepley if (p == rank) { 2830e759306cSMatthew G. Knepley Vec x; 2831e759306cSMatthew G. Knepley 2832e759306cSMatthew G. Knepley ierr = VecDuplicate(X, &x);CHKERRQ(ierr); 2833e759306cSMatthew G. Knepley ierr = VecCopy(X, x);CHKERRQ(ierr); 28346113b454SMatthew G. Knepley ierr = VecChop(x, tol);CHKERRQ(ierr); 2835e759306cSMatthew G. Knepley ierr = VecView(x, PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); 2836e759306cSMatthew G. Knepley ierr = VecDestroy(&x);CHKERRQ(ierr); 2837e759306cSMatthew G. Knepley ierr = PetscViewerFlush(PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); 2838e759306cSMatthew G. Knepley } 2839e759306cSMatthew G. Knepley ierr = PetscBarrier((PetscObject) dm);CHKERRQ(ierr); 2840e759306cSMatthew G. Knepley } 2841e759306cSMatthew G. Knepley PetscFunctionReturn(0); 2842e759306cSMatthew G. Knepley } 2843e759306cSMatthew G. Knepley 2844e759306cSMatthew G. Knepley #undef __FUNCT__ 284588ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultSection" 284688ed4aceSMatthew G Knepley /*@ 284788ed4aceSMatthew G Knepley DMGetDefaultSection - Get the PetscSection encoding the local data layout for the DM. 284888ed4aceSMatthew G Knepley 284988ed4aceSMatthew G Knepley Input Parameter: 285088ed4aceSMatthew G Knepley . dm - The DM 285188ed4aceSMatthew G Knepley 285288ed4aceSMatthew G Knepley Output Parameter: 285388ed4aceSMatthew G Knepley . section - The PetscSection 285488ed4aceSMatthew G Knepley 285588ed4aceSMatthew G Knepley Level: intermediate 285688ed4aceSMatthew G Knepley 285788ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSection. 285888ed4aceSMatthew G Knepley 285988ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultGlobalSection() 286088ed4aceSMatthew G Knepley @*/ 28610adebc6cSBarry Smith PetscErrorCode DMGetDefaultSection(DM dm, PetscSection *section) 28620adebc6cSBarry Smith { 2863fd59a867SMatthew G. Knepley PetscErrorCode ierr; 2864fd59a867SMatthew G. Knepley 286588ed4aceSMatthew G Knepley PetscFunctionBegin; 286688ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 286788ed4aceSMatthew G Knepley PetscValidPointer(section, 2); 2868fd59a867SMatthew G. Knepley if (!dm->defaultSection && dm->ops->createdefaultsection) {ierr = (*dm->ops->createdefaultsection)(dm);CHKERRQ(ierr);} 286988ed4aceSMatthew G Knepley *section = dm->defaultSection; 287088ed4aceSMatthew G Knepley PetscFunctionReturn(0); 287188ed4aceSMatthew G Knepley } 287288ed4aceSMatthew G Knepley 287388ed4aceSMatthew G Knepley #undef __FUNCT__ 287488ed4aceSMatthew G Knepley #define __FUNCT__ "DMSetDefaultSection" 287588ed4aceSMatthew G Knepley /*@ 287688ed4aceSMatthew G Knepley DMSetDefaultSection - Set the PetscSection encoding the local data layout for the DM. 287788ed4aceSMatthew G Knepley 287888ed4aceSMatthew G Knepley Input Parameters: 287988ed4aceSMatthew G Knepley + dm - The DM 288088ed4aceSMatthew G Knepley - section - The PetscSection 288188ed4aceSMatthew G Knepley 288288ed4aceSMatthew G Knepley Level: intermediate 288388ed4aceSMatthew G Knepley 288488ed4aceSMatthew G Knepley Note: Any existing Section will be destroyed 288588ed4aceSMatthew G Knepley 288688ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultGlobalSection() 288788ed4aceSMatthew G Knepley @*/ 28880adebc6cSBarry Smith PetscErrorCode DMSetDefaultSection(DM dm, PetscSection section) 28890adebc6cSBarry Smith { 2890af122d2aSMatthew G Knepley PetscInt numFields; 2891af122d2aSMatthew G Knepley PetscInt f; 289288ed4aceSMatthew G Knepley PetscErrorCode ierr; 289388ed4aceSMatthew G Knepley 289488ed4aceSMatthew G Knepley PetscFunctionBegin; 289588ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 28961d799100SJed Brown PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 28971d799100SJed Brown ierr = PetscObjectReference((PetscObject)section);CHKERRQ(ierr); 289888ed4aceSMatthew G Knepley ierr = PetscSectionDestroy(&dm->defaultSection);CHKERRQ(ierr); 289988ed4aceSMatthew G Knepley dm->defaultSection = section; 2900af122d2aSMatthew G Knepley ierr = PetscSectionGetNumFields(dm->defaultSection, &numFields);CHKERRQ(ierr); 2901af122d2aSMatthew G Knepley if (numFields) { 2902af122d2aSMatthew G Knepley ierr = DMSetNumFields(dm, numFields);CHKERRQ(ierr); 2903af122d2aSMatthew G Knepley for (f = 0; f < numFields; ++f) { 2904af122d2aSMatthew G Knepley const char *name; 2905af122d2aSMatthew G Knepley 2906af122d2aSMatthew G Knepley ierr = PetscSectionGetFieldName(dm->defaultSection, f, &name);CHKERRQ(ierr); 2907decb47aaSMatthew G. Knepley ierr = PetscObjectSetName((PetscObject) dm->fields[f], name);CHKERRQ(ierr); 2908af122d2aSMatthew G Knepley } 2909af122d2aSMatthew G Knepley } 29101d799100SJed Brown /* The global section will be rebuilt in the next call to DMGetDefaultGlobalSection(). */ 29111d799100SJed Brown ierr = PetscSectionDestroy(&dm->defaultGlobalSection);CHKERRQ(ierr); 291288ed4aceSMatthew G Knepley PetscFunctionReturn(0); 291388ed4aceSMatthew G Knepley } 291488ed4aceSMatthew G Knepley 291588ed4aceSMatthew G Knepley #undef __FUNCT__ 291688ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultGlobalSection" 291788ed4aceSMatthew G Knepley /*@ 291888ed4aceSMatthew G Knepley DMGetDefaultGlobalSection - Get the PetscSection encoding the global data layout for the DM. 291988ed4aceSMatthew G Knepley 29208b1ab98fSJed Brown Collective on DM 29218b1ab98fSJed Brown 292288ed4aceSMatthew G Knepley Input Parameter: 292388ed4aceSMatthew G Knepley . dm - The DM 292488ed4aceSMatthew G Knepley 292588ed4aceSMatthew G Knepley Output Parameter: 292688ed4aceSMatthew G Knepley . section - The PetscSection 292788ed4aceSMatthew G Knepley 292888ed4aceSMatthew G Knepley Level: intermediate 292988ed4aceSMatthew G Knepley 293088ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSection. 293188ed4aceSMatthew G Knepley 293288ed4aceSMatthew G Knepley .seealso: DMSetDefaultSection(), DMGetDefaultSection() 293388ed4aceSMatthew G Knepley @*/ 29340adebc6cSBarry Smith PetscErrorCode DMGetDefaultGlobalSection(DM dm, PetscSection *section) 29350adebc6cSBarry Smith { 293688ed4aceSMatthew G Knepley PetscErrorCode ierr; 293788ed4aceSMatthew G Knepley 293888ed4aceSMatthew G Knepley PetscFunctionBegin; 293988ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 294088ed4aceSMatthew G Knepley PetscValidPointer(section, 2); 294188ed4aceSMatthew G Knepley if (!dm->defaultGlobalSection) { 2942fd59a867SMatthew G. Knepley PetscSection s; 2943fd59a867SMatthew G. Knepley 2944fd59a867SMatthew G. Knepley ierr = DMGetDefaultSection(dm, &s);CHKERRQ(ierr); 2945fd59a867SMatthew 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"); 2946fd59a867SMatthew 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"); 2947fd59a867SMatthew G. Knepley ierr = PetscSectionCreateGlobalSection(s, dm->sf, PETSC_FALSE, &dm->defaultGlobalSection);CHKERRQ(ierr); 2948cf06b437SMatthew G. Knepley ierr = PetscLayoutDestroy(&dm->map);CHKERRQ(ierr); 2949ce94432eSBarry Smith ierr = PetscSectionGetValueLayout(PetscObjectComm((PetscObject)dm), dm->defaultGlobalSection, &dm->map);CHKERRQ(ierr); 295088ed4aceSMatthew G Knepley } 295188ed4aceSMatthew G Knepley *section = dm->defaultGlobalSection; 295288ed4aceSMatthew G Knepley PetscFunctionReturn(0); 295388ed4aceSMatthew G Knepley } 295488ed4aceSMatthew G Knepley 295588ed4aceSMatthew G Knepley #undef __FUNCT__ 2956b21d0597SMatthew G Knepley #define __FUNCT__ "DMSetDefaultGlobalSection" 2957b21d0597SMatthew G Knepley /*@ 2958b21d0597SMatthew G Knepley DMSetDefaultGlobalSection - Set the PetscSection encoding the global data layout for the DM. 2959b21d0597SMatthew G Knepley 2960b21d0597SMatthew G Knepley Input Parameters: 2961b21d0597SMatthew G Knepley + dm - The DM 29625080bbdbSMatthew G Knepley - section - The PetscSection, or NULL 2963b21d0597SMatthew G Knepley 2964b21d0597SMatthew G Knepley Level: intermediate 2965b21d0597SMatthew G Knepley 2966b21d0597SMatthew G Knepley Note: Any existing Section will be destroyed 2967b21d0597SMatthew G Knepley 2968b21d0597SMatthew G Knepley .seealso: DMGetDefaultGlobalSection(), DMSetDefaultSection() 2969b21d0597SMatthew G Knepley @*/ 29700adebc6cSBarry Smith PetscErrorCode DMSetDefaultGlobalSection(DM dm, PetscSection section) 29710adebc6cSBarry Smith { 2972b21d0597SMatthew G Knepley PetscErrorCode ierr; 2973b21d0597SMatthew G Knepley 2974b21d0597SMatthew G Knepley PetscFunctionBegin; 2975b21d0597SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 29765080bbdbSMatthew G Knepley if (section) PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 29771d799100SJed Brown ierr = PetscObjectReference((PetscObject)section);CHKERRQ(ierr); 2978b21d0597SMatthew G Knepley ierr = PetscSectionDestroy(&dm->defaultGlobalSection);CHKERRQ(ierr); 2979b21d0597SMatthew G Knepley dm->defaultGlobalSection = section; 2980b21d0597SMatthew G Knepley PetscFunctionReturn(0); 2981b21d0597SMatthew G Knepley } 2982b21d0597SMatthew G Knepley 2983b21d0597SMatthew G Knepley #undef __FUNCT__ 298488ed4aceSMatthew G Knepley #define __FUNCT__ "DMGetDefaultSF" 298588ed4aceSMatthew G Knepley /*@ 298688ed4aceSMatthew G Knepley DMGetDefaultSF - Get the PetscSF encoding the parallel dof overlap for the DM. If it has not been set, 298788ed4aceSMatthew G Knepley it is created from the default PetscSection layouts in the DM. 298888ed4aceSMatthew G Knepley 298988ed4aceSMatthew G Knepley Input Parameter: 299088ed4aceSMatthew G Knepley . dm - The DM 299188ed4aceSMatthew G Knepley 299288ed4aceSMatthew G Knepley Output Parameter: 299388ed4aceSMatthew G Knepley . sf - The PetscSF 299488ed4aceSMatthew G Knepley 299588ed4aceSMatthew G Knepley Level: intermediate 299688ed4aceSMatthew G Knepley 299788ed4aceSMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSF. 299888ed4aceSMatthew G Knepley 299988ed4aceSMatthew G Knepley .seealso: DMSetDefaultSF(), DMCreateDefaultSF() 300088ed4aceSMatthew G Knepley @*/ 30010adebc6cSBarry Smith PetscErrorCode DMGetDefaultSF(DM dm, PetscSF *sf) 30020adebc6cSBarry Smith { 300388ed4aceSMatthew G Knepley PetscInt nroots; 300488ed4aceSMatthew G Knepley PetscErrorCode ierr; 300588ed4aceSMatthew G Knepley 300688ed4aceSMatthew G Knepley PetscFunctionBegin; 300788ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 300888ed4aceSMatthew G Knepley PetscValidPointer(sf, 2); 30090298fd71SBarry Smith ierr = PetscSFGetGraph(dm->defaultSF, &nroots, NULL, NULL, NULL);CHKERRQ(ierr); 301088ed4aceSMatthew G Knepley if (nroots < 0) { 301188ed4aceSMatthew G Knepley PetscSection section, gSection; 301288ed4aceSMatthew G Knepley 301388ed4aceSMatthew G Knepley ierr = DMGetDefaultSection(dm, §ion);CHKERRQ(ierr); 301431ea6d37SMatthew G Knepley if (section) { 301588ed4aceSMatthew G Knepley ierr = DMGetDefaultGlobalSection(dm, &gSection);CHKERRQ(ierr); 301688ed4aceSMatthew G Knepley ierr = DMCreateDefaultSF(dm, section, gSection);CHKERRQ(ierr); 301731ea6d37SMatthew G Knepley } else { 30180298fd71SBarry Smith *sf = NULL; 301931ea6d37SMatthew G Knepley PetscFunctionReturn(0); 302031ea6d37SMatthew G Knepley } 302188ed4aceSMatthew G Knepley } 302288ed4aceSMatthew G Knepley *sf = dm->defaultSF; 302388ed4aceSMatthew G Knepley PetscFunctionReturn(0); 302488ed4aceSMatthew G Knepley } 302588ed4aceSMatthew G Knepley 302688ed4aceSMatthew G Knepley #undef __FUNCT__ 302788ed4aceSMatthew G Knepley #define __FUNCT__ "DMSetDefaultSF" 302888ed4aceSMatthew G Knepley /*@ 302988ed4aceSMatthew G Knepley DMSetDefaultSF - Set the PetscSF encoding the parallel dof overlap for the DM 303088ed4aceSMatthew G Knepley 303188ed4aceSMatthew G Knepley Input Parameters: 303288ed4aceSMatthew G Knepley + dm - The DM 303388ed4aceSMatthew G Knepley - sf - The PetscSF 303488ed4aceSMatthew G Knepley 303588ed4aceSMatthew G Knepley Level: intermediate 303688ed4aceSMatthew G Knepley 303788ed4aceSMatthew G Knepley Note: Any previous SF is destroyed 303888ed4aceSMatthew G Knepley 303988ed4aceSMatthew G Knepley .seealso: DMGetDefaultSF(), DMCreateDefaultSF() 304088ed4aceSMatthew G Knepley @*/ 30410adebc6cSBarry Smith PetscErrorCode DMSetDefaultSF(DM dm, PetscSF sf) 30420adebc6cSBarry Smith { 304388ed4aceSMatthew G Knepley PetscErrorCode ierr; 304488ed4aceSMatthew G Knepley 304588ed4aceSMatthew G Knepley PetscFunctionBegin; 304688ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 304788ed4aceSMatthew G Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 2); 304888ed4aceSMatthew G Knepley ierr = PetscSFDestroy(&dm->defaultSF);CHKERRQ(ierr); 304988ed4aceSMatthew G Knepley dm->defaultSF = sf; 305088ed4aceSMatthew G Knepley PetscFunctionReturn(0); 305188ed4aceSMatthew G Knepley } 305288ed4aceSMatthew G Knepley 305388ed4aceSMatthew G Knepley #undef __FUNCT__ 305488ed4aceSMatthew G Knepley #define __FUNCT__ "DMCreateDefaultSF" 305588ed4aceSMatthew G Knepley /*@C 305688ed4aceSMatthew G Knepley DMCreateDefaultSF - Create the PetscSF encoding the parallel dof overlap for the DM based upon the PetscSections 305788ed4aceSMatthew G Knepley describing the data layout. 305888ed4aceSMatthew G Knepley 305988ed4aceSMatthew G Knepley Input Parameters: 306088ed4aceSMatthew G Knepley + dm - The DM 306188ed4aceSMatthew G Knepley . localSection - PetscSection describing the local data layout 306288ed4aceSMatthew G Knepley - globalSection - PetscSection describing the global data layout 306388ed4aceSMatthew G Knepley 306488ed4aceSMatthew G Knepley Level: intermediate 306588ed4aceSMatthew G Knepley 306688ed4aceSMatthew G Knepley .seealso: DMGetDefaultSF(), DMSetDefaultSF() 306788ed4aceSMatthew G Knepley @*/ 306888ed4aceSMatthew G Knepley PetscErrorCode DMCreateDefaultSF(DM dm, PetscSection localSection, PetscSection globalSection) 306988ed4aceSMatthew G Knepley { 307082f516ccSBarry Smith MPI_Comm comm; 307188ed4aceSMatthew G Knepley PetscLayout layout; 307288ed4aceSMatthew G Knepley const PetscInt *ranges; 307388ed4aceSMatthew G Knepley PetscInt *local; 307488ed4aceSMatthew G Knepley PetscSFNode *remote; 3075ecd73843SMatthew G. Knepley PetscInt pStart, pEnd, p, nroots, nleaves = 0, l; 307688ed4aceSMatthew G Knepley PetscMPIInt size, rank; 307788ed4aceSMatthew G Knepley PetscErrorCode ierr; 307888ed4aceSMatthew G Knepley 307988ed4aceSMatthew G Knepley PetscFunctionBegin; 308082f516ccSBarry Smith ierr = PetscObjectGetComm((PetscObject)dm,&comm);CHKERRQ(ierr); 308188ed4aceSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 308288ed4aceSMatthew G Knepley ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); 308388ed4aceSMatthew G Knepley ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); 308488ed4aceSMatthew G Knepley ierr = PetscSectionGetChart(globalSection, &pStart, &pEnd);CHKERRQ(ierr); 308588ed4aceSMatthew G Knepley ierr = PetscSectionGetConstrainedStorageSize(globalSection, &nroots);CHKERRQ(ierr); 308688ed4aceSMatthew G Knepley ierr = PetscLayoutCreate(comm, &layout);CHKERRQ(ierr); 308788ed4aceSMatthew G Knepley ierr = PetscLayoutSetBlockSize(layout, 1);CHKERRQ(ierr); 308888ed4aceSMatthew G Knepley ierr = PetscLayoutSetLocalSize(layout, nroots);CHKERRQ(ierr); 308988ed4aceSMatthew G Knepley ierr = PetscLayoutSetUp(layout);CHKERRQ(ierr); 309088ed4aceSMatthew G Knepley ierr = PetscLayoutGetRanges(layout, &ranges);CHKERRQ(ierr); 3091ecd73843SMatthew G. Knepley for (p = pStart; p < pEnd; ++p) { 30926636e97aSMatthew G Knepley PetscInt gdof, gcdof; 309388ed4aceSMatthew G Knepley 30946636e97aSMatthew G Knepley ierr = PetscSectionGetDof(globalSection, p, &gdof);CHKERRQ(ierr); 30956636e97aSMatthew G Knepley ierr = PetscSectionGetConstraintDof(globalSection, p, &gcdof);CHKERRQ(ierr); 30966636e97aSMatthew G Knepley nleaves += gdof < 0 ? -(gdof+1)-gcdof : gdof-gcdof; 309788ed4aceSMatthew G Knepley } 3098785e854fSJed Brown ierr = PetscMalloc1(nleaves, &local);CHKERRQ(ierr); 3099785e854fSJed Brown ierr = PetscMalloc1(nleaves, &remote);CHKERRQ(ierr); 310088ed4aceSMatthew G Knepley for (p = pStart, l = 0; p < pEnd; ++p) { 31011f588964SMatthew G Knepley const PetscInt *cind; 31026636e97aSMatthew G Knepley PetscInt dof, cdof, off, gdof, gcdof, goff, gsize, d, c; 310388ed4aceSMatthew G Knepley 310488ed4aceSMatthew G Knepley ierr = PetscSectionGetDof(localSection, p, &dof);CHKERRQ(ierr); 310588ed4aceSMatthew G Knepley ierr = PetscSectionGetOffset(localSection, p, &off);CHKERRQ(ierr); 310688ed4aceSMatthew G Knepley ierr = PetscSectionGetConstraintDof(localSection, p, &cdof);CHKERRQ(ierr); 310788ed4aceSMatthew G Knepley ierr = PetscSectionGetConstraintIndices(localSection, p, &cind);CHKERRQ(ierr); 310888ed4aceSMatthew G Knepley ierr = PetscSectionGetDof(globalSection, p, &gdof);CHKERRQ(ierr); 31096636e97aSMatthew G Knepley ierr = PetscSectionGetConstraintDof(globalSection, p, &gcdof);CHKERRQ(ierr); 311088ed4aceSMatthew G Knepley ierr = PetscSectionGetOffset(globalSection, p, &goff);CHKERRQ(ierr); 31116636e97aSMatthew G Knepley if (!gdof) continue; /* Censored point */ 31126636e97aSMatthew G Knepley gsize = gdof < 0 ? -(gdof+1)-gcdof : gdof-gcdof; 31136636e97aSMatthew G Knepley if (gsize != dof-cdof) { 3114057b4bcdSMatthew 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); 31156636e97aSMatthew G Knepley cdof = 0; /* Ignore constraints */ 31166636e97aSMatthew G Knepley } 311788ed4aceSMatthew G Knepley for (d = 0, c = 0; d < dof; ++d) { 311888ed4aceSMatthew G Knepley if ((c < cdof) && (cind[c] == d)) {++c; continue;} 311988ed4aceSMatthew G Knepley local[l+d-c] = off+d; 312088ed4aceSMatthew G Knepley } 312188ed4aceSMatthew G Knepley if (gdof < 0) { 31226636e97aSMatthew G Knepley for (d = 0; d < gsize; ++d, ++l) { 312388ed4aceSMatthew G Knepley PetscInt offset = -(goff+1) + d, r; 312488ed4aceSMatthew G Knepley 312505376888SMatthew G. Knepley ierr = PetscFindInt(offset,size+1,ranges,&r);CHKERRQ(ierr); 312631d3f06eSJed Brown if (r < 0) r = -(r+2); 312705376888SMatthew 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); 312888ed4aceSMatthew G Knepley remote[l].rank = r; 312988ed4aceSMatthew G Knepley remote[l].index = offset - ranges[r]; 313088ed4aceSMatthew G Knepley } 313188ed4aceSMatthew G Knepley } else { 31326636e97aSMatthew G Knepley for (d = 0; d < gsize; ++d, ++l) { 313388ed4aceSMatthew G Knepley remote[l].rank = rank; 313488ed4aceSMatthew G Knepley remote[l].index = goff+d - ranges[rank]; 313588ed4aceSMatthew G Knepley } 313688ed4aceSMatthew G Knepley } 313788ed4aceSMatthew G Knepley } 31386636e97aSMatthew G Knepley if (l != nleaves) SETERRQ2(comm, PETSC_ERR_PLIB, "Iteration error, l %d != nleaves %d", l, nleaves); 313988ed4aceSMatthew G Knepley ierr = PetscLayoutDestroy(&layout);CHKERRQ(ierr); 314088ed4aceSMatthew G Knepley ierr = PetscSFSetGraph(dm->defaultSF, nroots, nleaves, local, PETSC_OWN_POINTER, remote, PETSC_OWN_POINTER);CHKERRQ(ierr); 314188ed4aceSMatthew G Knepley PetscFunctionReturn(0); 314288ed4aceSMatthew G Knepley } 3143af122d2aSMatthew G Knepley 3144af122d2aSMatthew G Knepley #undef __FUNCT__ 3145b21d0597SMatthew G Knepley #define __FUNCT__ "DMGetPointSF" 3146b21d0597SMatthew G Knepley /*@ 3147b21d0597SMatthew G Knepley DMGetPointSF - Get the PetscSF encoding the parallel section point overlap for the DM. 3148b21d0597SMatthew G Knepley 3149b21d0597SMatthew G Knepley Input Parameter: 3150b21d0597SMatthew G Knepley . dm - The DM 3151b21d0597SMatthew G Knepley 3152b21d0597SMatthew G Knepley Output Parameter: 3153b21d0597SMatthew G Knepley . sf - The PetscSF 3154b21d0597SMatthew G Knepley 3155b21d0597SMatthew G Knepley Level: intermediate 3156b21d0597SMatthew G Knepley 3157b21d0597SMatthew G Knepley Note: This gets a borrowed reference, so the user should not destroy this PetscSF. 3158b21d0597SMatthew G Knepley 3159057b4bcdSMatthew G Knepley .seealso: DMSetPointSF(), DMGetDefaultSF(), DMSetDefaultSF(), DMCreateDefaultSF() 3160b21d0597SMatthew G Knepley @*/ 31610adebc6cSBarry Smith PetscErrorCode DMGetPointSF(DM dm, PetscSF *sf) 31620adebc6cSBarry Smith { 3163b21d0597SMatthew G Knepley PetscFunctionBegin; 3164b21d0597SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3165b21d0597SMatthew G Knepley PetscValidPointer(sf, 2); 3166b21d0597SMatthew G Knepley *sf = dm->sf; 3167b21d0597SMatthew G Knepley PetscFunctionReturn(0); 3168b21d0597SMatthew G Knepley } 3169b21d0597SMatthew G Knepley 3170b21d0597SMatthew G Knepley #undef __FUNCT__ 3171057b4bcdSMatthew G Knepley #define __FUNCT__ "DMSetPointSF" 3172057b4bcdSMatthew G Knepley /*@ 3173057b4bcdSMatthew G Knepley DMSetPointSF - Set the PetscSF encoding the parallel section point overlap for the DM. 3174057b4bcdSMatthew G Knepley 3175057b4bcdSMatthew G Knepley Input Parameters: 3176057b4bcdSMatthew G Knepley + dm - The DM 3177057b4bcdSMatthew G Knepley - sf - The PetscSF 3178057b4bcdSMatthew G Knepley 3179057b4bcdSMatthew G Knepley Level: intermediate 3180057b4bcdSMatthew G Knepley 3181057b4bcdSMatthew G Knepley .seealso: DMGetPointSF(), DMGetDefaultSF(), DMSetDefaultSF(), DMCreateDefaultSF() 3182057b4bcdSMatthew G Knepley @*/ 31830adebc6cSBarry Smith PetscErrorCode DMSetPointSF(DM dm, PetscSF sf) 31840adebc6cSBarry Smith { 3185057b4bcdSMatthew G Knepley PetscErrorCode ierr; 3186057b4bcdSMatthew G Knepley 3187057b4bcdSMatthew G Knepley PetscFunctionBegin; 3188057b4bcdSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3189057b4bcdSMatthew G Knepley PetscValidHeaderSpecific(sf, PETSCSF_CLASSID, 1); 3190057b4bcdSMatthew G Knepley ierr = PetscSFDestroy(&dm->sf);CHKERRQ(ierr); 3191057b4bcdSMatthew G Knepley ierr = PetscObjectReference((PetscObject) sf);CHKERRQ(ierr); 3192057b4bcdSMatthew G Knepley dm->sf = sf; 3193057b4bcdSMatthew G Knepley PetscFunctionReturn(0); 3194057b4bcdSMatthew G Knepley } 3195057b4bcdSMatthew G Knepley 3196057b4bcdSMatthew G Knepley #undef __FUNCT__ 3197af122d2aSMatthew G Knepley #define __FUNCT__ "DMGetNumFields" 3198af122d2aSMatthew G Knepley PetscErrorCode DMGetNumFields(DM dm, PetscInt *numFields) 3199af122d2aSMatthew G Knepley { 3200af122d2aSMatthew G Knepley PetscFunctionBegin; 3201af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3202af122d2aSMatthew G Knepley PetscValidPointer(numFields, 2); 3203af122d2aSMatthew G Knepley *numFields = dm->numFields; 3204af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3205af122d2aSMatthew G Knepley } 3206af122d2aSMatthew G Knepley 3207af122d2aSMatthew G Knepley #undef __FUNCT__ 3208af122d2aSMatthew G Knepley #define __FUNCT__ "DMSetNumFields" 3209af122d2aSMatthew G Knepley PetscErrorCode DMSetNumFields(DM dm, PetscInt numFields) 3210af122d2aSMatthew G Knepley { 3211af122d2aSMatthew G Knepley PetscInt f; 3212af122d2aSMatthew G Knepley PetscErrorCode ierr; 3213af122d2aSMatthew G Knepley 3214af122d2aSMatthew G Knepley PetscFunctionBegin; 3215af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3216decb47aaSMatthew G. Knepley if (dm->numFields == numFields) PetscFunctionReturn(0); 3217af122d2aSMatthew G Knepley for (f = 0; f < dm->numFields; ++f) { 3218decb47aaSMatthew G. Knepley ierr = PetscObjectDestroy((PetscObject *) &dm->fields[f]);CHKERRQ(ierr); 3219af122d2aSMatthew G Knepley } 3220af122d2aSMatthew G Knepley ierr = PetscFree(dm->fields);CHKERRQ(ierr); 3221af122d2aSMatthew G Knepley dm->numFields = numFields; 3222785e854fSJed Brown ierr = PetscMalloc1(dm->numFields, &dm->fields);CHKERRQ(ierr); 3223af122d2aSMatthew G Knepley for (f = 0; f < dm->numFields; ++f) { 322482f516ccSBarry Smith ierr = PetscContainerCreate(PetscObjectComm((PetscObject) dm), (PetscContainer *) &dm->fields[f]);CHKERRQ(ierr); 3225af122d2aSMatthew G Knepley } 3226af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3227af122d2aSMatthew G Knepley } 3228af122d2aSMatthew G Knepley 3229af122d2aSMatthew G Knepley #undef __FUNCT__ 3230af122d2aSMatthew G Knepley #define __FUNCT__ "DMGetField" 3231af122d2aSMatthew G Knepley PetscErrorCode DMGetField(DM dm, PetscInt f, PetscObject *field) 3232af122d2aSMatthew G Knepley { 3233af122d2aSMatthew G Knepley PetscFunctionBegin; 3234af122d2aSMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3235decb47aaSMatthew G. Knepley PetscValidPointer(field, 3); 323682f516ccSBarry Smith if (!dm->fields) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONGSTATE, "Fields have not been setup in this DM. Call DMSetNumFields()"); 323782f516ccSBarry Smith if ((f < 0) || (f >= dm->numFields)) SETERRQ3(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE, "Field %d should be in [%d,%d)", f, 0, dm->numFields); 3238decb47aaSMatthew G. Knepley *field = (PetscObject) dm->fields[f]; 3239decb47aaSMatthew G. Knepley PetscFunctionReturn(0); 3240decb47aaSMatthew G. Knepley } 3241decb47aaSMatthew G. Knepley 3242decb47aaSMatthew G. Knepley #undef __FUNCT__ 3243decb47aaSMatthew G. Knepley #define __FUNCT__ "DMSetField" 3244decb47aaSMatthew G. Knepley PetscErrorCode DMSetField(DM dm, PetscInt f, PetscObject field) 3245decb47aaSMatthew G. Knepley { 3246decb47aaSMatthew G. Knepley PetscErrorCode ierr; 3247decb47aaSMatthew G. Knepley 3248decb47aaSMatthew G. Knepley PetscFunctionBegin; 3249decb47aaSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3250decb47aaSMatthew G. Knepley if (!dm->fields) SETERRQ(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONGSTATE, "Fields have not been setup in this DM. Call DMSetNumFields()"); 3251decb47aaSMatthew G. Knepley if ((f < 0) || (f >= dm->numFields)) SETERRQ3(PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_OUTOFRANGE, "Field %d should be in [%d,%d)", f, 0, dm->numFields); 32529e8c3d3aSMatthew G. Knepley if (((PetscObject) dm->fields[f]) == field) PetscFunctionReturn(0); 3253decb47aaSMatthew G. Knepley ierr = PetscObjectDestroy((PetscObject *) &dm->fields[f]);CHKERRQ(ierr); 3254decb47aaSMatthew G. Knepley dm->fields[f] = (PetscFE) field; 3255decb47aaSMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm->fields[f]);CHKERRQ(ierr); 3256af122d2aSMatthew G Knepley PetscFunctionReturn(0); 3257af122d2aSMatthew G Knepley } 32586636e97aSMatthew G Knepley 32596636e97aSMatthew G Knepley #undef __FUNCT__ 3260b64e0483SPeter Brune #define __FUNCT__ "DMRestrictHook_Coordinates" 3261b64e0483SPeter Brune PetscErrorCode DMRestrictHook_Coordinates(DM dm,DM dmc,void *ctx) 3262b64e0483SPeter Brune { 3263b64e0483SPeter Brune DM dm_coord,dmc_coord; 3264b64e0483SPeter Brune PetscErrorCode ierr; 3265b64e0483SPeter Brune Vec coords,ccoords; 3266b64e0483SPeter Brune VecScatter scat; 3267b64e0483SPeter Brune PetscFunctionBegin; 3268b64e0483SPeter Brune ierr = DMGetCoordinateDM(dm,&dm_coord);CHKERRQ(ierr); 3269b64e0483SPeter Brune ierr = DMGetCoordinateDM(dmc,&dmc_coord);CHKERRQ(ierr); 3270b64e0483SPeter Brune ierr = DMGetCoordinates(dm,&coords);CHKERRQ(ierr); 3271b64e0483SPeter Brune ierr = DMGetCoordinates(dmc,&ccoords);CHKERRQ(ierr); 3272b64e0483SPeter Brune if (coords && !ccoords) { 3273b64e0483SPeter Brune ierr = DMCreateGlobalVector(dmc_coord,&ccoords);CHKERRQ(ierr); 3274b64e0483SPeter Brune ierr = DMCreateInjection(dmc_coord,dm_coord,&scat);CHKERRQ(ierr); 3275b64e0483SPeter Brune ierr = VecScatterBegin(scat,coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 3276b64e0483SPeter Brune ierr = VecScatterEnd(scat,coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 3277b64e0483SPeter Brune ierr = DMSetCoordinates(dmc,ccoords);CHKERRQ(ierr); 3278b64e0483SPeter Brune ierr = VecScatterDestroy(&scat);CHKERRQ(ierr); 3279b64e0483SPeter Brune ierr = VecDestroy(&ccoords);CHKERRQ(ierr); 3280b64e0483SPeter Brune } 3281b64e0483SPeter Brune PetscFunctionReturn(0); 3282b64e0483SPeter Brune } 3283b64e0483SPeter Brune 3284b64e0483SPeter Brune #undef __FUNCT__ 328503dadc2fSPeter Brune #define __FUNCT__ "DMSubDomainHook_Coordinates" 328603dadc2fSPeter Brune static PetscErrorCode DMSubDomainHook_Coordinates(DM dm,DM subdm,void *ctx) 328703dadc2fSPeter Brune { 328803dadc2fSPeter Brune DM dm_coord,subdm_coord; 328903dadc2fSPeter Brune PetscErrorCode ierr; 329003dadc2fSPeter Brune Vec coords,ccoords,clcoords; 329103dadc2fSPeter Brune VecScatter *scat_i,*scat_g; 329203dadc2fSPeter Brune PetscFunctionBegin; 329303dadc2fSPeter Brune ierr = DMGetCoordinateDM(dm,&dm_coord);CHKERRQ(ierr); 329403dadc2fSPeter Brune ierr = DMGetCoordinateDM(subdm,&subdm_coord);CHKERRQ(ierr); 329503dadc2fSPeter Brune ierr = DMGetCoordinates(dm,&coords);CHKERRQ(ierr); 329603dadc2fSPeter Brune ierr = DMGetCoordinates(subdm,&ccoords);CHKERRQ(ierr); 329703dadc2fSPeter Brune if (coords && !ccoords) { 329803dadc2fSPeter Brune ierr = DMCreateGlobalVector(subdm_coord,&ccoords);CHKERRQ(ierr); 329903dadc2fSPeter Brune ierr = DMCreateLocalVector(subdm_coord,&clcoords);CHKERRQ(ierr); 330003dadc2fSPeter Brune ierr = DMCreateDomainDecompositionScatters(dm_coord,1,&subdm_coord,NULL,&scat_i,&scat_g);CHKERRQ(ierr); 330103dadc2fSPeter Brune ierr = VecScatterBegin(scat_i[0],coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 330203dadc2fSPeter Brune ierr = VecScatterBegin(scat_g[0],coords,clcoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 330303dadc2fSPeter Brune ierr = VecScatterEnd(scat_i[0],coords,ccoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 330403dadc2fSPeter Brune ierr = VecScatterEnd(scat_g[0],coords,clcoords,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 330503dadc2fSPeter Brune ierr = DMSetCoordinates(subdm,ccoords);CHKERRQ(ierr); 330603dadc2fSPeter Brune ierr = DMSetCoordinatesLocal(subdm,clcoords);CHKERRQ(ierr); 330703dadc2fSPeter Brune ierr = VecScatterDestroy(&scat_i[0]);CHKERRQ(ierr); 330803dadc2fSPeter Brune ierr = VecScatterDestroy(&scat_g[0]);CHKERRQ(ierr); 330903dadc2fSPeter Brune ierr = VecDestroy(&ccoords);CHKERRQ(ierr); 331003dadc2fSPeter Brune ierr = VecDestroy(&clcoords);CHKERRQ(ierr); 331103dadc2fSPeter Brune ierr = PetscFree(scat_i);CHKERRQ(ierr); 331203dadc2fSPeter Brune ierr = PetscFree(scat_g);CHKERRQ(ierr); 331303dadc2fSPeter Brune } 331403dadc2fSPeter Brune PetscFunctionReturn(0); 331503dadc2fSPeter Brune } 331603dadc2fSPeter Brune 331703dadc2fSPeter Brune #undef __FUNCT__ 33186636e97aSMatthew G Knepley #define __FUNCT__ "DMSetCoordinates" 33196636e97aSMatthew G Knepley /*@ 33206636e97aSMatthew G Knepley DMSetCoordinates - Sets into the DM a global vector that holds the coordinates 33216636e97aSMatthew G Knepley 33226636e97aSMatthew G Knepley Collective on DM 33236636e97aSMatthew G Knepley 33246636e97aSMatthew G Knepley Input Parameters: 33256636e97aSMatthew G Knepley + dm - the DM 33266636e97aSMatthew G Knepley - c - coordinate vector 33276636e97aSMatthew G Knepley 33286636e97aSMatthew G Knepley Note: 33296636e97aSMatthew G Knepley The coordinates do include those for ghost points, which are in the local vector 33306636e97aSMatthew G Knepley 33316636e97aSMatthew G Knepley Level: intermediate 33326636e97aSMatthew G Knepley 33336636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 33346636e97aSMatthew G Knepley .seealso: DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLoca(), DMGetCoordinateDM() 33356636e97aSMatthew G Knepley @*/ 33366636e97aSMatthew G Knepley PetscErrorCode DMSetCoordinates(DM dm, Vec c) 33376636e97aSMatthew G Knepley { 33386636e97aSMatthew G Knepley PetscErrorCode ierr; 33396636e97aSMatthew G Knepley 33406636e97aSMatthew G Knepley PetscFunctionBegin; 33416636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 33426636e97aSMatthew G Knepley PetscValidHeaderSpecific(c,VEC_CLASSID,2); 33436636e97aSMatthew G Knepley ierr = PetscObjectReference((PetscObject) c);CHKERRQ(ierr); 33446636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinates);CHKERRQ(ierr); 33456636e97aSMatthew G Knepley dm->coordinates = c; 33466636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinatesLocal);CHKERRQ(ierr); 3347b64e0483SPeter Brune ierr = DMCoarsenHookAdd(dm,DMRestrictHook_Coordinates,NULL,NULL);CHKERRQ(ierr); 334803dadc2fSPeter Brune ierr = DMSubDomainHookAdd(dm,DMSubDomainHook_Coordinates,NULL,NULL);CHKERRQ(ierr); 33496636e97aSMatthew G Knepley PetscFunctionReturn(0); 33506636e97aSMatthew G Knepley } 33516636e97aSMatthew G Knepley 33526636e97aSMatthew G Knepley #undef __FUNCT__ 33536636e97aSMatthew G Knepley #define __FUNCT__ "DMSetCoordinatesLocal" 33546636e97aSMatthew G Knepley /*@ 33556636e97aSMatthew G Knepley DMSetCoordinatesLocal - Sets into the DM a local vector that holds the coordinates 33566636e97aSMatthew G Knepley 33576636e97aSMatthew G Knepley Collective on DM 33586636e97aSMatthew G Knepley 33596636e97aSMatthew G Knepley Input Parameters: 33606636e97aSMatthew G Knepley + dm - the DM 33616636e97aSMatthew G Knepley - c - coordinate vector 33626636e97aSMatthew G Knepley 33636636e97aSMatthew G Knepley Note: 33646636e97aSMatthew G Knepley The coordinates of ghost points can be set using DMSetCoordinates() 33656636e97aSMatthew G Knepley followed by DMGetCoordinatesLocal(). This is intended to enable the 33666636e97aSMatthew G Knepley setting of ghost coordinates outside of the domain. 33676636e97aSMatthew G Knepley 33686636e97aSMatthew G Knepley Level: intermediate 33696636e97aSMatthew G Knepley 33706636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 33716636e97aSMatthew G Knepley .seealso: DMGetCoordinatesLocal(), DMSetCoordinates(), DMGetCoordinates(), DMGetCoordinateDM() 33726636e97aSMatthew G Knepley @*/ 33736636e97aSMatthew G Knepley PetscErrorCode DMSetCoordinatesLocal(DM dm, Vec c) 33746636e97aSMatthew G Knepley { 33756636e97aSMatthew G Knepley PetscErrorCode ierr; 33766636e97aSMatthew G Knepley 33776636e97aSMatthew G Knepley PetscFunctionBegin; 33786636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 33796636e97aSMatthew G Knepley PetscValidHeaderSpecific(c,VEC_CLASSID,2); 33806636e97aSMatthew G Knepley ierr = PetscObjectReference((PetscObject) c);CHKERRQ(ierr); 33816636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinatesLocal);CHKERRQ(ierr); 33828865f1eaSKarl Rupp 33836636e97aSMatthew G Knepley dm->coordinatesLocal = c; 33848865f1eaSKarl Rupp 33856636e97aSMatthew G Knepley ierr = VecDestroy(&dm->coordinates);CHKERRQ(ierr); 33866636e97aSMatthew G Knepley PetscFunctionReturn(0); 33876636e97aSMatthew G Knepley } 33886636e97aSMatthew G Knepley 33896636e97aSMatthew G Knepley #undef __FUNCT__ 33906636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinates" 33916636e97aSMatthew G Knepley /*@ 33926636e97aSMatthew G Knepley DMGetCoordinates - Gets a global vector with the coordinates associated with the DM. 33936636e97aSMatthew G Knepley 33946636e97aSMatthew G Knepley Not Collective 33956636e97aSMatthew G Knepley 33966636e97aSMatthew G Knepley Input Parameter: 33976636e97aSMatthew G Knepley . dm - the DM 33986636e97aSMatthew G Knepley 33996636e97aSMatthew G Knepley Output Parameter: 34006636e97aSMatthew G Knepley . c - global coordinate vector 34016636e97aSMatthew G Knepley 34026636e97aSMatthew G Knepley Note: 34036636e97aSMatthew G Knepley This is a borrowed reference, so the user should NOT destroy this vector 34046636e97aSMatthew G Knepley 34056636e97aSMatthew G Knepley Each process has only the local coordinates (does NOT have the ghost coordinates). 34066636e97aSMatthew G Knepley 34076636e97aSMatthew G Knepley For DMDA, in two and three dimensions coordinates are interlaced (x_0,y_0,x_1,y_1,...) 34086636e97aSMatthew G Knepley and (x_0,y_0,z_0,x_1,y_1,z_1...) 34096636e97aSMatthew G Knepley 34106636e97aSMatthew G Knepley Level: intermediate 34116636e97aSMatthew G Knepley 34126636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 34136636e97aSMatthew G Knepley .seealso: DMSetCoordinates(), DMGetCoordinatesLocal(), DMGetCoordinateDM() 34146636e97aSMatthew G Knepley @*/ 34156636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinates(DM dm, Vec *c) 34166636e97aSMatthew G Knepley { 34176636e97aSMatthew G Knepley PetscErrorCode ierr; 34186636e97aSMatthew G Knepley 34196636e97aSMatthew G Knepley PetscFunctionBegin; 34206636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 34216636e97aSMatthew G Knepley PetscValidPointer(c,2); 34221f588964SMatthew G Knepley if (!dm->coordinates && dm->coordinatesLocal) { 34230298fd71SBarry Smith DM cdm = NULL; 34246636e97aSMatthew G Knepley 34256636e97aSMatthew G Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 34266636e97aSMatthew G Knepley ierr = DMCreateGlobalVector(cdm, &dm->coordinates);CHKERRQ(ierr); 34276636e97aSMatthew G Knepley ierr = PetscObjectSetName((PetscObject) dm->coordinates, "coordinates");CHKERRQ(ierr); 34286636e97aSMatthew G Knepley ierr = DMLocalToGlobalBegin(cdm, dm->coordinatesLocal, INSERT_VALUES, dm->coordinates);CHKERRQ(ierr); 34296636e97aSMatthew G Knepley ierr = DMLocalToGlobalEnd(cdm, dm->coordinatesLocal, INSERT_VALUES, dm->coordinates);CHKERRQ(ierr); 34306636e97aSMatthew G Knepley } 34316636e97aSMatthew G Knepley *c = dm->coordinates; 34326636e97aSMatthew G Knepley PetscFunctionReturn(0); 34336636e97aSMatthew G Knepley } 34346636e97aSMatthew G Knepley 34356636e97aSMatthew G Knepley #undef __FUNCT__ 34366636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinatesLocal" 34376636e97aSMatthew G Knepley /*@ 34386636e97aSMatthew G Knepley DMGetCoordinatesLocal - Gets a local vector with the coordinates associated with the DM. 34396636e97aSMatthew G Knepley 34406636e97aSMatthew G Knepley Collective on DM 34416636e97aSMatthew G Knepley 34426636e97aSMatthew G Knepley Input Parameter: 34436636e97aSMatthew G Knepley . dm - the DM 34446636e97aSMatthew G Knepley 34456636e97aSMatthew G Knepley Output Parameter: 34466636e97aSMatthew G Knepley . c - coordinate vector 34476636e97aSMatthew G Knepley 34486636e97aSMatthew G Knepley Note: 34496636e97aSMatthew G Knepley This is a borrowed reference, so the user should NOT destroy this vector 34506636e97aSMatthew G Knepley 34516636e97aSMatthew G Knepley Each process has the local and ghost coordinates 34526636e97aSMatthew G Knepley 34536636e97aSMatthew G Knepley For DMDA, in two and three dimensions coordinates are interlaced (x_0,y_0,x_1,y_1,...) 34546636e97aSMatthew G Knepley and (x_0,y_0,z_0,x_1,y_1,z_1...) 34556636e97aSMatthew G Knepley 34566636e97aSMatthew G Knepley Level: intermediate 34576636e97aSMatthew G Knepley 34586636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 34596636e97aSMatthew G Knepley .seealso: DMSetCoordinatesLocal(), DMGetCoordinates(), DMSetCoordinates(), DMGetCoordinateDM() 34606636e97aSMatthew G Knepley @*/ 34616636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinatesLocal(DM dm, Vec *c) 34626636e97aSMatthew G Knepley { 34636636e97aSMatthew G Knepley PetscErrorCode ierr; 34646636e97aSMatthew G Knepley 34656636e97aSMatthew G Knepley PetscFunctionBegin; 34666636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 34676636e97aSMatthew G Knepley PetscValidPointer(c,2); 34681f588964SMatthew G Knepley if (!dm->coordinatesLocal && dm->coordinates) { 34690298fd71SBarry Smith DM cdm = NULL; 34706636e97aSMatthew G Knepley 34716636e97aSMatthew G Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 34726636e97aSMatthew G Knepley ierr = DMCreateLocalVector(cdm, &dm->coordinatesLocal);CHKERRQ(ierr); 34736636e97aSMatthew G Knepley ierr = PetscObjectSetName((PetscObject) dm->coordinatesLocal, "coordinates");CHKERRQ(ierr); 34746636e97aSMatthew G Knepley ierr = DMGlobalToLocalBegin(cdm, dm->coordinates, INSERT_VALUES, dm->coordinatesLocal);CHKERRQ(ierr); 34756636e97aSMatthew G Knepley ierr = DMGlobalToLocalEnd(cdm, dm->coordinates, INSERT_VALUES, dm->coordinatesLocal);CHKERRQ(ierr); 34766636e97aSMatthew G Knepley } 34776636e97aSMatthew G Knepley *c = dm->coordinatesLocal; 34786636e97aSMatthew G Knepley PetscFunctionReturn(0); 34796636e97aSMatthew G Knepley } 34806636e97aSMatthew G Knepley 34816636e97aSMatthew G Knepley #undef __FUNCT__ 34826636e97aSMatthew G Knepley #define __FUNCT__ "DMGetCoordinateDM" 34836636e97aSMatthew G Knepley /*@ 34841cfe2091SMatthew G. Knepley DMGetCoordinateDM - Gets the DM that prescribes coordinate layout and scatters between global and local coordinates 34856636e97aSMatthew G Knepley 34866636e97aSMatthew G Knepley Collective on DM 34876636e97aSMatthew G Knepley 34886636e97aSMatthew G Knepley Input Parameter: 34896636e97aSMatthew G Knepley . dm - the DM 34906636e97aSMatthew G Knepley 34916636e97aSMatthew G Knepley Output Parameter: 34926636e97aSMatthew G Knepley . cdm - coordinate DM 34936636e97aSMatthew G Knepley 34946636e97aSMatthew G Knepley Level: intermediate 34956636e97aSMatthew G Knepley 34966636e97aSMatthew G Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 34971cfe2091SMatthew G. Knepley .seealso: DMSetCoordinateDM(), DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 34986636e97aSMatthew G Knepley @*/ 34996636e97aSMatthew G Knepley PetscErrorCode DMGetCoordinateDM(DM dm, DM *cdm) 35006636e97aSMatthew G Knepley { 35016636e97aSMatthew G Knepley PetscErrorCode ierr; 35026636e97aSMatthew G Knepley 35036636e97aSMatthew G Knepley PetscFunctionBegin; 35046636e97aSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 35056636e97aSMatthew G Knepley PetscValidPointer(cdm,2); 35066636e97aSMatthew G Knepley if (!dm->coordinateDM) { 350782f516ccSBarry Smith if (!dm->ops->createcoordinatedm) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Unable to create coordinates for this DM"); 35086636e97aSMatthew G Knepley ierr = (*dm->ops->createcoordinatedm)(dm, &dm->coordinateDM);CHKERRQ(ierr); 35096636e97aSMatthew G Knepley } 35106636e97aSMatthew G Knepley *cdm = dm->coordinateDM; 35116636e97aSMatthew G Knepley PetscFunctionReturn(0); 35126636e97aSMatthew G Knepley } 3513e87bb0d3SMatthew G Knepley 3514e87bb0d3SMatthew G Knepley #undef __FUNCT__ 35151cfe2091SMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateDM" 35161cfe2091SMatthew G. Knepley /*@ 35171cfe2091SMatthew G. Knepley DMSetCoordinateDM - Sets the DM that prescribes coordinate layout and scatters between global and local coordinates 35181cfe2091SMatthew G. Knepley 35191cfe2091SMatthew G. Knepley Logically Collective on DM 35201cfe2091SMatthew G. Knepley 35211cfe2091SMatthew G. Knepley Input Parameters: 35221cfe2091SMatthew G. Knepley + dm - the DM 35231cfe2091SMatthew G. Knepley - cdm - coordinate DM 35241cfe2091SMatthew G. Knepley 35251cfe2091SMatthew G. Knepley Level: intermediate 35261cfe2091SMatthew G. Knepley 35271cfe2091SMatthew G. Knepley .keywords: distributed array, get, corners, nodes, local indices, coordinates 35281cfe2091SMatthew G. Knepley .seealso: DMGetCoordinateDM(), DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 35291cfe2091SMatthew G. Knepley @*/ 35301cfe2091SMatthew G. Knepley PetscErrorCode DMSetCoordinateDM(DM dm, DM cdm) 35311cfe2091SMatthew G. Knepley { 35321cfe2091SMatthew G. Knepley PetscErrorCode ierr; 35331cfe2091SMatthew G. Knepley 35341cfe2091SMatthew G. Knepley PetscFunctionBegin; 35351cfe2091SMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 35361cfe2091SMatthew G. Knepley PetscValidHeaderSpecific(cdm,DM_CLASSID,2); 35371cfe2091SMatthew G. Knepley ierr = DMDestroy(&dm->coordinateDM);CHKERRQ(ierr); 35381cfe2091SMatthew G. Knepley dm->coordinateDM = cdm; 35391cfe2091SMatthew G. Knepley ierr = PetscObjectReference((PetscObject) dm->coordinateDM);CHKERRQ(ierr); 35401cfe2091SMatthew G. Knepley PetscFunctionReturn(0); 35411cfe2091SMatthew G. Knepley } 35421cfe2091SMatthew G. Knepley 35431cfe2091SMatthew G. Knepley #undef __FUNCT__ 3544e8abe2deSMatthew G. Knepley #define __FUNCT__ "DMGetCoordinateSection" 3545e8abe2deSMatthew G. Knepley /*@ 3546e8abe2deSMatthew G. Knepley DMGetCoordinateSection - Retrieve the layout of coordinate values over the mesh. 3547e8abe2deSMatthew G. Knepley 3548e8abe2deSMatthew G. Knepley Not Collective 3549e8abe2deSMatthew G. Knepley 3550e8abe2deSMatthew G. Knepley Input Parameter: 3551e8abe2deSMatthew G. Knepley . dm - The DM object 3552e8abe2deSMatthew G. Knepley 3553e8abe2deSMatthew G. Knepley Output Parameter: 3554e8abe2deSMatthew G. Knepley . section - The PetscSection object 3555e8abe2deSMatthew G. Knepley 3556e8abe2deSMatthew G. Knepley Level: intermediate 3557e8abe2deSMatthew G. Knepley 3558e8abe2deSMatthew G. Knepley .keywords: mesh, coordinates 3559e8abe2deSMatthew G. Knepley .seealso: DMGetCoordinateDM(), DMGetDefaultSection(), DMSetDefaultSection() 3560e8abe2deSMatthew G. Knepley @*/ 3561e8abe2deSMatthew G. Knepley PetscErrorCode DMGetCoordinateSection(DM dm, PetscSection *section) 3562e8abe2deSMatthew G. Knepley { 3563e8abe2deSMatthew G. Knepley DM cdm; 3564e8abe2deSMatthew G. Knepley PetscErrorCode ierr; 3565e8abe2deSMatthew G. Knepley 3566e8abe2deSMatthew G. Knepley PetscFunctionBegin; 3567e8abe2deSMatthew G. Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 3568e8abe2deSMatthew G. Knepley PetscValidPointer(section, 2); 3569e8abe2deSMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 3570e8abe2deSMatthew G. Knepley ierr = DMGetDefaultSection(cdm, section);CHKERRQ(ierr); 3571e8abe2deSMatthew G. Knepley PetscFunctionReturn(0); 3572e8abe2deSMatthew G. Knepley } 3573e8abe2deSMatthew G. Knepley 3574e8abe2deSMatthew G. Knepley #undef __FUNCT__ 3575e8abe2deSMatthew G. Knepley #define __FUNCT__ "DMSetCoordinateSection" 3576e8abe2deSMatthew G. Knepley /*@ 3577e8abe2deSMatthew G. Knepley DMSetCoordinateSection - Set the layout of coordinate values over the mesh. 3578e8abe2deSMatthew G. Knepley 3579e8abe2deSMatthew G. Knepley Not Collective 3580e8abe2deSMatthew G. Knepley 3581e8abe2deSMatthew G. Knepley Input Parameters: 3582e8abe2deSMatthew G. Knepley + dm - The DM object 3583e8abe2deSMatthew G. Knepley - section - The PetscSection object 3584e8abe2deSMatthew G. Knepley 3585e8abe2deSMatthew G. Knepley Level: intermediate 3586e8abe2deSMatthew G. Knepley 3587e8abe2deSMatthew G. Knepley .keywords: mesh, coordinates 3588e8abe2deSMatthew G. Knepley .seealso: DMGetCoordinateSection(), DMGetDefaultSection(), DMSetDefaultSection() 3589e8abe2deSMatthew G. Knepley @*/ 3590e8abe2deSMatthew G. Knepley PetscErrorCode DMSetCoordinateSection(DM dm, PetscSection section) 3591e8abe2deSMatthew G. Knepley { 3592e8abe2deSMatthew G. Knepley DM cdm; 3593e8abe2deSMatthew G. Knepley PetscErrorCode ierr; 3594e8abe2deSMatthew G. Knepley 3595e8abe2deSMatthew G. Knepley PetscFunctionBegin; 3596e8abe2deSMatthew G. Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3597e8abe2deSMatthew G. Knepley PetscValidHeaderSpecific(section,PETSC_SECTION_CLASSID,2); 3598e8abe2deSMatthew G. Knepley ierr = DMGetCoordinateDM(dm, &cdm);CHKERRQ(ierr); 3599e8abe2deSMatthew G. Knepley ierr = DMSetDefaultSection(cdm, section);CHKERRQ(ierr); 3600e8abe2deSMatthew G. Knepley PetscFunctionReturn(0); 3601e8abe2deSMatthew G. Knepley } 3602e8abe2deSMatthew G. Knepley 3603e8abe2deSMatthew G. Knepley #undef __FUNCT__ 3604e87bb0d3SMatthew G Knepley #define __FUNCT__ "DMLocatePoints" 3605e87bb0d3SMatthew G Knepley /*@ 3606e87bb0d3SMatthew G Knepley DMLocatePoints - Locate the points in v in the mesh and return an IS of the containing cells 3607e87bb0d3SMatthew G Knepley 3608e87bb0d3SMatthew G Knepley Not collective 3609e87bb0d3SMatthew G Knepley 3610e87bb0d3SMatthew G Knepley Input Parameters: 3611e87bb0d3SMatthew G Knepley + dm - The DM 3612e87bb0d3SMatthew G Knepley - v - The Vec of points 3613e87bb0d3SMatthew G Knepley 361461e3bb9bSMatthew G Knepley Output Parameter: 3615e87bb0d3SMatthew G Knepley . cells - The local cell numbers for cells which contain the points 3616e87bb0d3SMatthew G Knepley 3617e87bb0d3SMatthew G Knepley Level: developer 361861e3bb9bSMatthew G Knepley 361961e3bb9bSMatthew G Knepley .keywords: point location, mesh 362061e3bb9bSMatthew G Knepley .seealso: DMSetCoordinates(), DMSetCoordinatesLocal(), DMGetCoordinates(), DMGetCoordinatesLocal() 362161e3bb9bSMatthew G Knepley @*/ 3622e87bb0d3SMatthew G Knepley PetscErrorCode DMLocatePoints(DM dm, Vec v, IS *cells) 3623e87bb0d3SMatthew G Knepley { 3624735aa83eSMatthew G Knepley PetscErrorCode ierr; 3625735aa83eSMatthew G Knepley 3626e87bb0d3SMatthew G Knepley PetscFunctionBegin; 3627e87bb0d3SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3628e87bb0d3SMatthew G Knepley PetscValidHeaderSpecific(v,VEC_CLASSID,2); 3629e87bb0d3SMatthew G Knepley PetscValidPointer(cells,3); 3630735aa83eSMatthew G Knepley if (dm->ops->locatepoints) { 3631735aa83eSMatthew G Knepley ierr = (*dm->ops->locatepoints)(dm,v,cells);CHKERRQ(ierr); 363282f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_SUP, "Point location not available for this DM"); 3633e87bb0d3SMatthew G Knepley PetscFunctionReturn(0); 3634e87bb0d3SMatthew G Knepley } 3635