147c6ae99SBarry Smith #define PETSCDM_DLL 247c6ae99SBarry Smith 347c6ae99SBarry Smith #include "private/dmimpl.h" /*I "petscda.h" I*/ 447c6ae99SBarry Smith 547c6ae99SBarry Smith #undef __FUNCT__ 69a42bb27SBarry Smith #define __FUNCT__ "DMSetVecType" 79a42bb27SBarry Smith /*@C 8564755cdSBarry Smith DMSetVecType - Sets the type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() 99a42bb27SBarry Smith 109a42bb27SBarry Smith Logically Collective on DA 119a42bb27SBarry Smith 129a42bb27SBarry Smith Input Parameter: 139a42bb27SBarry Smith + da - initial distributed array 149a42bb27SBarry Smith . ctype - the vector type, currently either VECSTANDARD or VECCUDA 159a42bb27SBarry Smith 169a42bb27SBarry Smith Options Database: 179a42bb27SBarry Smith . -da_vec_type ctype 189a42bb27SBarry Smith 199a42bb27SBarry Smith Level: intermediate 209a42bb27SBarry Smith 219a42bb27SBarry Smith .seealso: DACreate1d(), DACreate2d(), DACreate3d(), DMDestroy(), DA, DAInterpolationType, VecType 229a42bb27SBarry Smith @*/ 239a42bb27SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMSetVecType(DM da,const VecType ctype) 249a42bb27SBarry Smith { 259a42bb27SBarry Smith PetscErrorCode ierr; 269a42bb27SBarry Smith 279a42bb27SBarry Smith PetscFunctionBegin; 289a42bb27SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 299a42bb27SBarry Smith ierr = PetscFree(da->vectype);CHKERRQ(ierr); 309a42bb27SBarry Smith ierr = PetscStrallocpy(ctype,&da->vectype);CHKERRQ(ierr); 319a42bb27SBarry Smith PetscFunctionReturn(0); 329a42bb27SBarry Smith } 339a42bb27SBarry Smith 349a42bb27SBarry Smith #undef __FUNCT__ 359a42bb27SBarry Smith #define __FUNCT__ "DMSetOptionsPrefix" 369a42bb27SBarry Smith /*@C 379a42bb27SBarry Smith DMSetOptionsPrefix - Sets the prefix used for searching for all 389a42bb27SBarry Smith DA options in the database. 399a42bb27SBarry Smith 409a42bb27SBarry Smith Logically Collective on DA 419a42bb27SBarry Smith 429a42bb27SBarry Smith Input Parameter: 439a42bb27SBarry Smith + da - the DA context 449a42bb27SBarry Smith - prefix - the prefix to prepend to all option names 459a42bb27SBarry Smith 469a42bb27SBarry Smith Notes: 479a42bb27SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 489a42bb27SBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 499a42bb27SBarry Smith 509a42bb27SBarry Smith Level: advanced 519a42bb27SBarry Smith 529a42bb27SBarry Smith .keywords: DA, set, options, prefix, database 539a42bb27SBarry Smith 549a42bb27SBarry Smith .seealso: DMSetFromOptions() 559a42bb27SBarry Smith @*/ 569a42bb27SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMSetOptionsPrefix(DM dm,const char prefix[]) 579a42bb27SBarry Smith { 589a42bb27SBarry Smith PetscErrorCode ierr; 599a42bb27SBarry Smith 609a42bb27SBarry Smith PetscFunctionBegin; 619a42bb27SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 629a42bb27SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)dm,prefix);CHKERRQ(ierr); 639a42bb27SBarry Smith PetscFunctionReturn(0); 649a42bb27SBarry Smith } 659a42bb27SBarry Smith 669a42bb27SBarry Smith #undef __FUNCT__ 6747c6ae99SBarry Smith #define __FUNCT__ "DMDestroy" 6847c6ae99SBarry Smith /*@ 6947c6ae99SBarry Smith DMDestroy - Destroys a vector packer or DA. 7047c6ae99SBarry Smith 7147c6ae99SBarry Smith Collective on DM 7247c6ae99SBarry Smith 7347c6ae99SBarry Smith Input Parameter: 7447c6ae99SBarry Smith . dm - the DM object to destroy 7547c6ae99SBarry Smith 7647c6ae99SBarry Smith Level: developer 7747c6ae99SBarry Smith 7847c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix() 7947c6ae99SBarry Smith 8047c6ae99SBarry Smith @*/ 8147c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMDestroy(DM dm) 8247c6ae99SBarry Smith { 8347c6ae99SBarry Smith PetscErrorCode ierr; 8447c6ae99SBarry Smith 8547c6ae99SBarry Smith PetscFunctionBegin; 860c010503SBarry Smith ierr = (*dm->ops->destroy)(dm);CHKERRQ(ierr); 8747c6ae99SBarry Smith PetscFunctionReturn(0); 8847c6ae99SBarry Smith } 8947c6ae99SBarry Smith 9047c6ae99SBarry Smith #undef __FUNCT__ 91d7bf68aeSBarry Smith #define __FUNCT__ "DMSetUp" 92d7bf68aeSBarry Smith /*@ 93d7bf68aeSBarry Smith DMSetUp - sets up the data structures inside a DM object 94d7bf68aeSBarry Smith 95d7bf68aeSBarry Smith Collective on DM 96d7bf68aeSBarry Smith 97d7bf68aeSBarry Smith Input Parameter: 98d7bf68aeSBarry Smith . dm - the DM object to setup 99d7bf68aeSBarry Smith 100d7bf68aeSBarry Smith Level: developer 101d7bf68aeSBarry Smith 102d7bf68aeSBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix() 103d7bf68aeSBarry Smith 104d7bf68aeSBarry Smith @*/ 105d7bf68aeSBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMSetUp(DM dm) 106d7bf68aeSBarry Smith { 107d7bf68aeSBarry Smith PetscErrorCode ierr; 108d7bf68aeSBarry Smith 109d7bf68aeSBarry Smith PetscFunctionBegin; 110d7bf68aeSBarry Smith if (dm->ops->setup) { 111d7bf68aeSBarry Smith ierr = (*dm->ops->setup)(dm);CHKERRQ(ierr); 112d7bf68aeSBarry Smith } 113d7bf68aeSBarry Smith PetscFunctionReturn(0); 114d7bf68aeSBarry Smith } 115d7bf68aeSBarry Smith 116d7bf68aeSBarry Smith #undef __FUNCT__ 117d7bf68aeSBarry Smith #define __FUNCT__ "DMSetFromOptions" 118d7bf68aeSBarry Smith /*@ 119d7bf68aeSBarry Smith DMSetFromOptions - sets parameters in a DM from the options database 120d7bf68aeSBarry Smith 121d7bf68aeSBarry Smith Collective on DM 122d7bf68aeSBarry Smith 123d7bf68aeSBarry Smith Input Parameter: 124d7bf68aeSBarry Smith . dm - the DM object to set options for 125d7bf68aeSBarry Smith 126d7bf68aeSBarry Smith Level: developer 127d7bf68aeSBarry Smith 128d7bf68aeSBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix() 129d7bf68aeSBarry Smith 130d7bf68aeSBarry Smith @*/ 131d7bf68aeSBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMSetFromOptions(DM dm) 132d7bf68aeSBarry Smith { 133d7bf68aeSBarry Smith PetscErrorCode ierr; 134d7bf68aeSBarry Smith 135d7bf68aeSBarry Smith PetscFunctionBegin; 136d7bf68aeSBarry Smith if (dm->ops->setfromoptions) { 137d7bf68aeSBarry Smith ierr = (*dm->ops->setfromoptions)(dm);CHKERRQ(ierr); 138d7bf68aeSBarry Smith } 139d7bf68aeSBarry Smith PetscFunctionReturn(0); 140d7bf68aeSBarry Smith } 141d7bf68aeSBarry Smith 142d7bf68aeSBarry Smith #undef __FUNCT__ 14347c6ae99SBarry Smith #define __FUNCT__ "DMView" 14447c6ae99SBarry Smith /*@ 14547c6ae99SBarry Smith DMView - Views a vector packer or DA. 14647c6ae99SBarry Smith 14747c6ae99SBarry Smith Collective on DM 14847c6ae99SBarry Smith 14947c6ae99SBarry Smith Input Parameter: 15047c6ae99SBarry Smith + dm - the DM object to view 15147c6ae99SBarry Smith - v - the viewer 15247c6ae99SBarry Smith 15347c6ae99SBarry Smith Level: developer 15447c6ae99SBarry Smith 15547c6ae99SBarry Smith .seealso DMDestroy(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix() 15647c6ae99SBarry Smith 15747c6ae99SBarry Smith @*/ 15847c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMView(DM dm,PetscViewer v) 15947c6ae99SBarry Smith { 16047c6ae99SBarry Smith PetscErrorCode ierr; 16147c6ae99SBarry Smith 16247c6ae99SBarry Smith PetscFunctionBegin; 1630c010503SBarry Smith if (dm->ops->view) { 1640c010503SBarry Smith ierr = (*dm->ops->view)(dm,v);CHKERRQ(ierr); 16547c6ae99SBarry Smith } 16647c6ae99SBarry Smith PetscFunctionReturn(0); 16747c6ae99SBarry Smith } 16847c6ae99SBarry Smith 16947c6ae99SBarry Smith #undef __FUNCT__ 17047c6ae99SBarry Smith #define __FUNCT__ "DMCreateGlobalVector" 17147c6ae99SBarry Smith /*@ 17247c6ae99SBarry Smith DMCreateGlobalVector - Creates a global vector from a DA or DMComposite object 17347c6ae99SBarry Smith 17447c6ae99SBarry Smith Collective on DM 17547c6ae99SBarry Smith 17647c6ae99SBarry Smith Input Parameter: 17747c6ae99SBarry Smith . dm - the DM object 17847c6ae99SBarry Smith 17947c6ae99SBarry Smith Output Parameter: 18047c6ae99SBarry Smith . vec - the global vector 18147c6ae99SBarry Smith 18247c6ae99SBarry Smith Level: developer 18347c6ae99SBarry Smith 18447c6ae99SBarry Smith .seealso DMDestroy(), DMView(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix() 18547c6ae99SBarry Smith 18647c6ae99SBarry Smith @*/ 18747c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMCreateGlobalVector(DM dm,Vec *vec) 18847c6ae99SBarry Smith { 18947c6ae99SBarry Smith PetscErrorCode ierr; 19047c6ae99SBarry Smith 19147c6ae99SBarry Smith PetscFunctionBegin; 19247c6ae99SBarry Smith ierr = (*dm->ops->createglobalvector)(dm,vec);CHKERRQ(ierr); 19347c6ae99SBarry Smith PetscFunctionReturn(0); 19447c6ae99SBarry Smith } 19547c6ae99SBarry Smith 19647c6ae99SBarry Smith #undef __FUNCT__ 19747c6ae99SBarry Smith #define __FUNCT__ "DMCreateLocalVector" 19847c6ae99SBarry Smith /*@ 19947c6ae99SBarry Smith DMCreateLocalVector - Creates a local vector from a DA or DMComposite object 20047c6ae99SBarry Smith 20147c6ae99SBarry Smith Not Collective 20247c6ae99SBarry Smith 20347c6ae99SBarry Smith Input Parameter: 20447c6ae99SBarry Smith . dm - the DM object 20547c6ae99SBarry Smith 20647c6ae99SBarry Smith Output Parameter: 20747c6ae99SBarry Smith . vec - the local vector 20847c6ae99SBarry Smith 20947c6ae99SBarry Smith Level: developer 21047c6ae99SBarry Smith 21147c6ae99SBarry Smith .seealso DMDestroy(), DMView(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix() 21247c6ae99SBarry Smith 21347c6ae99SBarry Smith @*/ 21447c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMCreateLocalVector(DM dm,Vec *vec) 21547c6ae99SBarry Smith { 21647c6ae99SBarry Smith PetscErrorCode ierr; 21747c6ae99SBarry Smith 21847c6ae99SBarry Smith PetscFunctionBegin; 21947c6ae99SBarry Smith ierr = (*dm->ops->createlocalvector)(dm,vec);CHKERRQ(ierr); 22047c6ae99SBarry Smith PetscFunctionReturn(0); 22147c6ae99SBarry Smith } 22247c6ae99SBarry Smith 22347c6ae99SBarry Smith #undef __FUNCT__ 22447c6ae99SBarry Smith #define __FUNCT__ "DMGetInterpolation" 22547c6ae99SBarry Smith /*@ 22647c6ae99SBarry Smith DMGetInterpolation - Gets interpolation matrix between two DA or DMComposite objects 22747c6ae99SBarry Smith 22847c6ae99SBarry Smith Collective on DM 22947c6ae99SBarry Smith 23047c6ae99SBarry Smith Input Parameter: 23147c6ae99SBarry Smith + dm1 - the DM object 23247c6ae99SBarry Smith - dm2 - the second, finer DM object 23347c6ae99SBarry Smith 23447c6ae99SBarry Smith Output Parameter: 23547c6ae99SBarry Smith + mat - the interpolation 23647c6ae99SBarry Smith - vec - the scaling (optional) 23747c6ae99SBarry Smith 23847c6ae99SBarry Smith Level: developer 23947c6ae99SBarry Smith 24047c6ae99SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMGetColoring(), DMGetMatrix() 24147c6ae99SBarry Smith 24247c6ae99SBarry Smith @*/ 24347c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMGetInterpolation(DM dm1,DM dm2,Mat *mat,Vec *vec) 24447c6ae99SBarry Smith { 24547c6ae99SBarry Smith PetscErrorCode ierr; 24647c6ae99SBarry Smith 24747c6ae99SBarry Smith PetscFunctionBegin; 24847c6ae99SBarry Smith ierr = (*dm1->ops->getinterpolation)(dm1,dm2,mat,vec);CHKERRQ(ierr); 24947c6ae99SBarry Smith PetscFunctionReturn(0); 25047c6ae99SBarry Smith } 25147c6ae99SBarry Smith 25247c6ae99SBarry Smith #undef __FUNCT__ 25347c6ae99SBarry Smith #define __FUNCT__ "DMGetInjection" 25447c6ae99SBarry Smith /*@ 25547c6ae99SBarry Smith DMGetInjection - Gets injection matrix between two DA or DMComposite objects 25647c6ae99SBarry Smith 25747c6ae99SBarry Smith Collective on DM 25847c6ae99SBarry Smith 25947c6ae99SBarry Smith Input Parameter: 26047c6ae99SBarry Smith + dm1 - the DM object 26147c6ae99SBarry Smith - dm2 - the second, finer DM object 26247c6ae99SBarry Smith 26347c6ae99SBarry Smith Output Parameter: 26447c6ae99SBarry Smith . ctx - the injection 26547c6ae99SBarry Smith 26647c6ae99SBarry Smith Level: developer 26747c6ae99SBarry Smith 26847c6ae99SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMGetColoring(), DMGetMatrix(), DMGetInterpolation() 26947c6ae99SBarry Smith 27047c6ae99SBarry Smith @*/ 27147c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMGetInjection(DM dm1,DM dm2,VecScatter *ctx) 27247c6ae99SBarry Smith { 27347c6ae99SBarry Smith PetscErrorCode ierr; 27447c6ae99SBarry Smith 27547c6ae99SBarry Smith PetscFunctionBegin; 27647c6ae99SBarry Smith ierr = (*dm1->ops->getinjection)(dm1,dm2,ctx);CHKERRQ(ierr); 27747c6ae99SBarry Smith PetscFunctionReturn(0); 27847c6ae99SBarry Smith } 27947c6ae99SBarry Smith 28047c6ae99SBarry Smith #undef __FUNCT__ 28147c6ae99SBarry Smith #define __FUNCT__ "DMGetColoring" 28247c6ae99SBarry Smith /*@ 28347c6ae99SBarry Smith DMGetColoring - Gets coloring for a DA or DMComposite 28447c6ae99SBarry Smith 28547c6ae99SBarry Smith Collective on DM 28647c6ae99SBarry Smith 28747c6ae99SBarry Smith Input Parameter: 28847c6ae99SBarry Smith + dm - the DM object 28947c6ae99SBarry Smith . ctype - IS_COLORING_GHOSTED or IS_COLORING_GLOBAL 29047c6ae99SBarry Smith - matype - either MATAIJ or MATBAIJ 29147c6ae99SBarry Smith 29247c6ae99SBarry Smith Output Parameter: 29347c6ae99SBarry Smith . coloring - the coloring 29447c6ae99SBarry Smith 29547c6ae99SBarry Smith Level: developer 29647c6ae99SBarry Smith 29747c6ae99SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetMatrix() 29847c6ae99SBarry Smith 29947c6ae99SBarry Smith @*/ 30047c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMGetColoring(DM dm,ISColoringType ctype,const MatType mtype,ISColoring *coloring) 30147c6ae99SBarry Smith { 30247c6ae99SBarry Smith PetscErrorCode ierr; 30347c6ae99SBarry Smith 30447c6ae99SBarry Smith PetscFunctionBegin; 30547c6ae99SBarry Smith if (!dm->ops->getcoloring) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_SUP,"No coloring for this type of DM yet"); 30647c6ae99SBarry Smith ierr = (*dm->ops->getcoloring)(dm,ctype,mtype,coloring);CHKERRQ(ierr); 30747c6ae99SBarry Smith PetscFunctionReturn(0); 30847c6ae99SBarry Smith } 30947c6ae99SBarry Smith 31047c6ae99SBarry Smith #undef __FUNCT__ 31147c6ae99SBarry Smith #define __FUNCT__ "DMGetMatrix" 31247c6ae99SBarry Smith /*@C 31347c6ae99SBarry Smith DMGetMatrix - Gets empty Jacobian for a DA or DMComposite 31447c6ae99SBarry Smith 31547c6ae99SBarry Smith Collective on DM 31647c6ae99SBarry Smith 31747c6ae99SBarry Smith Input Parameter: 31847c6ae99SBarry Smith + dm - the DM object 31947c6ae99SBarry Smith - mtype - Supported types are MATSEQAIJ, MATMPIAIJ, MATSEQBAIJ, MATMPIBAIJ, or 320*94013140SBarry Smith any type which inherits from one of these (such as MATAIJ) 32147c6ae99SBarry Smith 32247c6ae99SBarry Smith Output Parameter: 32347c6ae99SBarry Smith . mat - the empty Jacobian 32447c6ae99SBarry Smith 32547c6ae99SBarry Smith Level: developer 32647c6ae99SBarry Smith 327*94013140SBarry Smith Notes: This properly preallocates the number of nonzeros in the sparse matrix so you 328*94013140SBarry Smith do not need to do it yourself. 329*94013140SBarry Smith 330*94013140SBarry Smith By default it also sets the nonzero structure and puts in the zero entries. To prevent setting 331*94013140SBarry Smith the nonzero pattern call DASetMatPreallocateOnly() 332*94013140SBarry Smith 333*94013140SBarry 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 334*94013140SBarry Smith internally by PETSc. 335*94013140SBarry Smith 336*94013140SBarry Smith For structured grid problems, in general it is easiest to use MatSetValuesStencil() or MatSetValuesLocal() to put values into the matrix because MatSetValues() requires 337*94013140SBarry Smith the indices for the global numbering for DAs which is complicated. 338*94013140SBarry Smith 33947c6ae99SBarry Smith .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetMatrix() 34047c6ae99SBarry Smith 34147c6ae99SBarry Smith @*/ 34247c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMGetMatrix(DM dm, const MatType mtype,Mat *mat) 34347c6ae99SBarry Smith { 34447c6ae99SBarry Smith PetscErrorCode ierr; 34547c6ae99SBarry Smith 34647c6ae99SBarry Smith PetscFunctionBegin; 34747c6ae99SBarry Smith ierr = (*dm->ops->getmatrix)(dm,mtype,mat);CHKERRQ(ierr); 34847c6ae99SBarry Smith PetscFunctionReturn(0); 34947c6ae99SBarry Smith } 35047c6ae99SBarry Smith 35147c6ae99SBarry Smith #undef __FUNCT__ 35247c6ae99SBarry Smith #define __FUNCT__ "DMRefine" 35347c6ae99SBarry Smith /*@ 35447c6ae99SBarry Smith DMRefine - Refines a DM object 35547c6ae99SBarry Smith 35647c6ae99SBarry Smith Collective on DM 35747c6ae99SBarry Smith 35847c6ae99SBarry Smith Input Parameter: 35947c6ae99SBarry Smith + dm - the DM object 36047c6ae99SBarry Smith - comm - the communicator to contain the new DM object (or PETSC_NULL) 36147c6ae99SBarry Smith 36247c6ae99SBarry Smith Output Parameter: 36347c6ae99SBarry Smith . dmf - the refined DM 36447c6ae99SBarry Smith 36547c6ae99SBarry Smith Level: developer 36647c6ae99SBarry Smith 36747c6ae99SBarry Smith .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMGetInterpolation() 36847c6ae99SBarry Smith 36947c6ae99SBarry Smith @*/ 37047c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMRefine(DM dm,MPI_Comm comm,DM *dmf) 37147c6ae99SBarry Smith { 37247c6ae99SBarry Smith PetscErrorCode ierr; 37347c6ae99SBarry Smith 37447c6ae99SBarry Smith PetscFunctionBegin; 37547c6ae99SBarry Smith ierr = (*dm->ops->refine)(dm,comm,dmf);CHKERRQ(ierr); 37647c6ae99SBarry Smith PetscFunctionReturn(0); 37747c6ae99SBarry Smith } 37847c6ae99SBarry Smith 37947c6ae99SBarry Smith #undef __FUNCT__ 38047c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalBegin" 38147c6ae99SBarry Smith /*@ 38247c6ae99SBarry Smith DMGlobalToLocalBegin - Begins updating local vectors from global vector 38347c6ae99SBarry Smith 38447c6ae99SBarry Smith Neighbor-wise Collective on DM 38547c6ae99SBarry Smith 38647c6ae99SBarry Smith Input Parameters: 38747c6ae99SBarry Smith + dm - the DM object 38847c6ae99SBarry Smith . g - the global vector 38947c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 39047c6ae99SBarry Smith - l - the local vector 39147c6ae99SBarry Smith 39247c6ae99SBarry Smith 39347c6ae99SBarry Smith Level: beginner 39447c6ae99SBarry Smith 3959a42bb27SBarry Smith .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 39647c6ae99SBarry Smith 39747c6ae99SBarry Smith @*/ 39847c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMGlobalToLocalBegin(DM dm,Vec g,InsertMode mode,Vec l) 39947c6ae99SBarry Smith { 40047c6ae99SBarry Smith PetscErrorCode ierr; 40147c6ae99SBarry Smith 40247c6ae99SBarry Smith PetscFunctionBegin; 40347c6ae99SBarry Smith ierr = (*dm->ops->globaltolocalbegin)(dm,g,mode,l);CHKERRQ(ierr); 40447c6ae99SBarry Smith PetscFunctionReturn(0); 40547c6ae99SBarry Smith } 40647c6ae99SBarry Smith 40747c6ae99SBarry Smith #undef __FUNCT__ 40847c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalEnd" 40947c6ae99SBarry Smith /*@ 41047c6ae99SBarry Smith DMGlobalToLocalEnd - Ends updating local vectors from global vector 41147c6ae99SBarry Smith 41247c6ae99SBarry Smith Neighbor-wise Collective on DM 41347c6ae99SBarry Smith 41447c6ae99SBarry Smith Input Parameters: 41547c6ae99SBarry Smith + dm - the DM object 41647c6ae99SBarry Smith . g - the global vector 41747c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 41847c6ae99SBarry Smith - l - the local vector 41947c6ae99SBarry Smith 42047c6ae99SBarry Smith 42147c6ae99SBarry Smith Level: beginner 42247c6ae99SBarry Smith 4239a42bb27SBarry Smith .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 42447c6ae99SBarry Smith 42547c6ae99SBarry Smith @*/ 42647c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMGlobalToLocalEnd(DM dm,Vec g,InsertMode mode,Vec l) 42747c6ae99SBarry Smith { 42847c6ae99SBarry Smith PetscErrorCode ierr; 42947c6ae99SBarry Smith 43047c6ae99SBarry Smith PetscFunctionBegin; 43147c6ae99SBarry Smith ierr = (*dm->ops->globaltolocalend)(dm,g,mode,l);CHKERRQ(ierr); 43247c6ae99SBarry Smith PetscFunctionReturn(0); 43347c6ae99SBarry Smith } 43447c6ae99SBarry Smith 43547c6ae99SBarry Smith #undef __FUNCT__ 4369a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalBegin" 43747c6ae99SBarry Smith /*@ 4389a42bb27SBarry Smith DMLocalToGlobalBegin - updates global vectors from local vectors 4399a42bb27SBarry Smith 4409a42bb27SBarry Smith Neighbor-wise Collective on DM 4419a42bb27SBarry Smith 4429a42bb27SBarry Smith Input Parameters: 4439a42bb27SBarry Smith + dm - the DM object 4449a42bb27SBarry Smith . g - the global vector 4459a42bb27SBarry 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 4469a42bb27SBarry Smith base point. 4479a42bb27SBarry Smith - l - the local vector 4489a42bb27SBarry Smith 4499a42bb27SBarry 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 4509a42bb27SBarry 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 4519a42bb27SBarry Smith global array to the final global array with VecAXPY(). 4529a42bb27SBarry Smith 4539a42bb27SBarry Smith Level: beginner 4549a42bb27SBarry Smith 4559a42bb27SBarry Smith .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalBegin() 4569a42bb27SBarry Smith 4579a42bb27SBarry Smith @*/ 4589a42bb27SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMLocalToGlobalBegin(DM dm,Vec g,InsertMode mode,Vec l) 4599a42bb27SBarry Smith { 4609a42bb27SBarry Smith PetscErrorCode ierr; 4619a42bb27SBarry Smith 4629a42bb27SBarry Smith PetscFunctionBegin; 4639a42bb27SBarry Smith ierr = (*dm->ops->localtoglobalbegin)(dm,g,mode,l);CHKERRQ(ierr); 4649a42bb27SBarry Smith PetscFunctionReturn(0); 4659a42bb27SBarry Smith } 4669a42bb27SBarry Smith 4679a42bb27SBarry Smith #undef __FUNCT__ 4689a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalEnd" 4699a42bb27SBarry Smith /*@ 4709a42bb27SBarry Smith DMLocalToGlobalEnd - updates global vectors from local vectors 47147c6ae99SBarry Smith 47247c6ae99SBarry Smith Neighbor-wise Collective on DM 47347c6ae99SBarry Smith 47447c6ae99SBarry Smith Input Parameters: 47547c6ae99SBarry Smith + dm - the DM object 47647c6ae99SBarry Smith . g - the global vector 47747c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 47847c6ae99SBarry Smith - l - the local vector 47947c6ae99SBarry Smith 48047c6ae99SBarry Smith 48147c6ae99SBarry Smith Level: beginner 48247c6ae99SBarry Smith 4839a42bb27SBarry Smith .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalEnd() 48447c6ae99SBarry Smith 48547c6ae99SBarry Smith @*/ 4869a42bb27SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMLocalToGlobalEnd(DM dm,Vec g,InsertMode mode,Vec l) 48747c6ae99SBarry Smith { 48847c6ae99SBarry Smith PetscErrorCode ierr; 48947c6ae99SBarry Smith 49047c6ae99SBarry Smith PetscFunctionBegin; 4919a42bb27SBarry Smith ierr = (*dm->ops->localtoglobalend)(dm,g,mode,l);CHKERRQ(ierr); 49247c6ae99SBarry Smith PetscFunctionReturn(0); 49347c6ae99SBarry Smith } 49447c6ae99SBarry Smith 49547c6ae99SBarry Smith #undef __FUNCT__ 49647c6ae99SBarry Smith #define __FUNCT__ "DMComputeJacobianDefault" 49747c6ae99SBarry Smith /*@ 49847c6ae99SBarry Smith DMComputeJacobianDefault - computes the Jacobian using the DMComputeFunction() if Jacobian computer is not provided 49947c6ae99SBarry Smith 50047c6ae99SBarry Smith Collective on DM 50147c6ae99SBarry Smith 50247c6ae99SBarry Smith Input Parameter: 50347c6ae99SBarry Smith + dm - the DM object 50447c6ae99SBarry Smith . x - location to compute Jacobian at; may be ignored for linear problems 50547c6ae99SBarry Smith . A - matrix that defines the operator for the linear solve 50647c6ae99SBarry Smith - B - the matrix used to construct the preconditioner 50747c6ae99SBarry Smith 50847c6ae99SBarry Smith Level: developer 50947c6ae99SBarry Smith 51047c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix(), DMGetContext(), DMSetInitialGuess(), 51147c6ae99SBarry Smith DMSetFunction() 51247c6ae99SBarry Smith 51347c6ae99SBarry Smith @*/ 51447c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMComputeJacobianDefault(DM dm,Vec x,Mat A,Mat B,MatStructure *stflag) 51547c6ae99SBarry Smith { 51647c6ae99SBarry Smith PetscErrorCode ierr; 51747c6ae99SBarry Smith PetscFunctionBegin; 51847c6ae99SBarry Smith *stflag = SAME_NONZERO_PATTERN; 51947c6ae99SBarry Smith ierr = MatFDColoringApply(B,dm->fd,x,stflag,dm);CHKERRQ(ierr); 52047c6ae99SBarry Smith if (A != B) { 52147c6ae99SBarry Smith ierr = MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 52247c6ae99SBarry Smith ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 52347c6ae99SBarry Smith } 52447c6ae99SBarry Smith PetscFunctionReturn(0); 52547c6ae99SBarry Smith } 52647c6ae99SBarry Smith 52747c6ae99SBarry Smith #undef __FUNCT__ 52847c6ae99SBarry Smith #define __FUNCT__ "DMCoarsen" 52947c6ae99SBarry Smith /*@ 53047c6ae99SBarry Smith DMCoarsen - Coarsens a DM object 53147c6ae99SBarry Smith 53247c6ae99SBarry Smith Collective on DM 53347c6ae99SBarry Smith 53447c6ae99SBarry Smith Input Parameter: 53547c6ae99SBarry Smith + dm - the DM object 53647c6ae99SBarry Smith - comm - the communicator to contain the new DM object (or PETSC_NULL) 53747c6ae99SBarry Smith 53847c6ae99SBarry Smith Output Parameter: 53947c6ae99SBarry Smith . dmc - the coarsened DM 54047c6ae99SBarry Smith 54147c6ae99SBarry Smith Level: developer 54247c6ae99SBarry Smith 54347c6ae99SBarry Smith .seealso DMRefine(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMGetInterpolation() 54447c6ae99SBarry Smith 54547c6ae99SBarry Smith @*/ 54647c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMCoarsen(DM dm, MPI_Comm comm, DM *dmc) 54747c6ae99SBarry Smith { 54847c6ae99SBarry Smith PetscErrorCode ierr; 54947c6ae99SBarry Smith 55047c6ae99SBarry Smith PetscFunctionBegin; 55147c6ae99SBarry Smith ierr = (*dm->ops->coarsen)(dm, comm, dmc);CHKERRQ(ierr); 55247c6ae99SBarry Smith (*dmc)->ops->initialguess = dm->ops->initialguess; 55347c6ae99SBarry Smith (*dmc)->ops->function = dm->ops->function; 55447c6ae99SBarry Smith (*dmc)->ops->functionj = dm->ops->functionj; 55547c6ae99SBarry Smith if (dm->ops->jacobian != DMComputeJacobianDefault) { 55647c6ae99SBarry Smith (*dmc)->ops->jacobian = dm->ops->jacobian; 55747c6ae99SBarry Smith } 55847c6ae99SBarry Smith PetscFunctionReturn(0); 55947c6ae99SBarry Smith } 56047c6ae99SBarry Smith 56147c6ae99SBarry Smith #undef __FUNCT__ 56247c6ae99SBarry Smith #define __FUNCT__ "DMRefineHierarchy" 56347c6ae99SBarry Smith /*@C 56447c6ae99SBarry Smith DMRefineHierarchy - Refines a DM object, all levels at once 56547c6ae99SBarry Smith 56647c6ae99SBarry Smith Collective on DM 56747c6ae99SBarry Smith 56847c6ae99SBarry Smith Input Parameter: 56947c6ae99SBarry Smith + dm - the DM object 57047c6ae99SBarry Smith - nlevels - the number of levels of refinement 57147c6ae99SBarry Smith 57247c6ae99SBarry Smith Output Parameter: 57347c6ae99SBarry Smith . dmf - the refined DM hierarchy 57447c6ae99SBarry Smith 57547c6ae99SBarry Smith Level: developer 57647c6ae99SBarry Smith 57747c6ae99SBarry Smith .seealso DMCoarsenHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMGetInterpolation() 57847c6ae99SBarry Smith 57947c6ae99SBarry Smith @*/ 58047c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMRefineHierarchy(DM dm,PetscInt nlevels,DM dmf[]) 58147c6ae99SBarry Smith { 58247c6ae99SBarry Smith PetscErrorCode ierr; 58347c6ae99SBarry Smith 58447c6ae99SBarry Smith PetscFunctionBegin; 58547c6ae99SBarry Smith if (nlevels < 0) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 58647c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 58747c6ae99SBarry Smith if (dm->ops->refinehierarchy) { 58847c6ae99SBarry Smith ierr = (*dm->ops->refinehierarchy)(dm,nlevels,dmf);CHKERRQ(ierr); 58947c6ae99SBarry Smith } else if (dm->ops->refine) { 59047c6ae99SBarry Smith PetscInt i; 59147c6ae99SBarry Smith 59247c6ae99SBarry Smith ierr = DMRefine(dm,((PetscObject)dm)->comm,&dmf[0]);CHKERRQ(ierr); 59347c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 59447c6ae99SBarry Smith ierr = DMRefine(dmf[i-1],((PetscObject)dm)->comm,&dmf[i]);CHKERRQ(ierr); 59547c6ae99SBarry Smith } 59647c6ae99SBarry Smith } else { 59747c6ae99SBarry Smith SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_SUP,"No RefineHierarchy for this DM yet"); 59847c6ae99SBarry Smith } 59947c6ae99SBarry Smith PetscFunctionReturn(0); 60047c6ae99SBarry Smith } 60147c6ae99SBarry Smith 60247c6ae99SBarry Smith #undef __FUNCT__ 60347c6ae99SBarry Smith #define __FUNCT__ "DMCoarsenHierarchy" 60447c6ae99SBarry Smith /*@C 60547c6ae99SBarry Smith DMCoarsenHierarchy - Coarsens a DM object, all levels at once 60647c6ae99SBarry Smith 60747c6ae99SBarry Smith Collective on DM 60847c6ae99SBarry Smith 60947c6ae99SBarry Smith Input Parameter: 61047c6ae99SBarry Smith + dm - the DM object 61147c6ae99SBarry Smith - nlevels - the number of levels of coarsening 61247c6ae99SBarry Smith 61347c6ae99SBarry Smith Output Parameter: 61447c6ae99SBarry Smith . dmc - the coarsened DM hierarchy 61547c6ae99SBarry Smith 61647c6ae99SBarry Smith Level: developer 61747c6ae99SBarry Smith 61847c6ae99SBarry Smith .seealso DMRefineHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMGetInterpolation() 61947c6ae99SBarry Smith 62047c6ae99SBarry Smith @*/ 62147c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMCoarsenHierarchy(DM dm, PetscInt nlevels, DM dmc[]) 62247c6ae99SBarry Smith { 62347c6ae99SBarry Smith PetscErrorCode ierr; 62447c6ae99SBarry Smith 62547c6ae99SBarry Smith PetscFunctionBegin; 62647c6ae99SBarry Smith if (nlevels < 0) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 62747c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 62847c6ae99SBarry Smith PetscValidPointer(dmc,3); 62947c6ae99SBarry Smith if (dm->ops->coarsenhierarchy) { 63047c6ae99SBarry Smith ierr = (*dm->ops->coarsenhierarchy)(dm, nlevels, dmc);CHKERRQ(ierr); 63147c6ae99SBarry Smith } else if (dm->ops->coarsen) { 63247c6ae99SBarry Smith PetscInt i; 63347c6ae99SBarry Smith 63447c6ae99SBarry Smith ierr = DMCoarsen(dm,((PetscObject)dm)->comm,&dmc[0]);CHKERRQ(ierr); 63547c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 63647c6ae99SBarry Smith ierr = DMCoarsen(dmc[i-1],((PetscObject)dm)->comm,&dmc[i]);CHKERRQ(ierr); 63747c6ae99SBarry Smith } 63847c6ae99SBarry Smith } else { 63947c6ae99SBarry Smith SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_SUP,"No CoarsenHierarchy for this DM yet"); 64047c6ae99SBarry Smith } 64147c6ae99SBarry Smith PetscFunctionReturn(0); 64247c6ae99SBarry Smith } 64347c6ae99SBarry Smith 64447c6ae99SBarry Smith #undef __FUNCT__ 64547c6ae99SBarry Smith #define __FUNCT__ "DMGetAggregates" 64647c6ae99SBarry Smith /*@ 64747c6ae99SBarry Smith DMGetAggregates - Gets the aggregates that map between 64847c6ae99SBarry Smith grids associated with two DMs. 64947c6ae99SBarry Smith 65047c6ae99SBarry Smith Collective on DM 65147c6ae99SBarry Smith 65247c6ae99SBarry Smith Input Parameters: 65347c6ae99SBarry Smith + dmc - the coarse grid DM 65447c6ae99SBarry Smith - dmf - the fine grid DM 65547c6ae99SBarry Smith 65647c6ae99SBarry Smith Output Parameters: 65747c6ae99SBarry Smith . rest - the restriction matrix (transpose of the projection matrix) 65847c6ae99SBarry Smith 65947c6ae99SBarry Smith Level: intermediate 66047c6ae99SBarry Smith 66147c6ae99SBarry Smith .keywords: interpolation, restriction, multigrid 66247c6ae99SBarry Smith 66347c6ae99SBarry Smith .seealso: DMRefine(), DMGetInjection(), DMGetInterpolation() 66447c6ae99SBarry Smith @*/ 66547c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMGetAggregates(DM dmc, DM dmf, Mat *rest) 66647c6ae99SBarry Smith { 66747c6ae99SBarry Smith PetscErrorCode ierr; 66847c6ae99SBarry Smith 66947c6ae99SBarry Smith PetscFunctionBegin; 67047c6ae99SBarry Smith ierr = (*dmc->ops->getaggregates)(dmc, dmf, rest);CHKERRQ(ierr); 67147c6ae99SBarry Smith PetscFunctionReturn(0); 67247c6ae99SBarry Smith } 67347c6ae99SBarry Smith 67447c6ae99SBarry Smith #undef __FUNCT__ 67547c6ae99SBarry Smith #define __FUNCT__ "DMSetContext" 67647c6ae99SBarry Smith /*@ 67747c6ae99SBarry Smith DMSetContext - Set a user context into a DM object 67847c6ae99SBarry Smith 67947c6ae99SBarry Smith Not Collective 68047c6ae99SBarry Smith 68147c6ae99SBarry Smith Input Parameters: 68247c6ae99SBarry Smith + dm - the DM object 68347c6ae99SBarry Smith - ctx - the user context 68447c6ae99SBarry Smith 68547c6ae99SBarry Smith Level: intermediate 68647c6ae99SBarry Smith 68747c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix(), DMGetContext() 68847c6ae99SBarry Smith 68947c6ae99SBarry Smith @*/ 69047c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMSetContext(DM dm,void *ctx) 69147c6ae99SBarry Smith { 69247c6ae99SBarry Smith PetscFunctionBegin; 69347c6ae99SBarry Smith dm->ctx = ctx; 69447c6ae99SBarry Smith PetscFunctionReturn(0); 69547c6ae99SBarry Smith } 69647c6ae99SBarry Smith 69747c6ae99SBarry Smith #undef __FUNCT__ 69847c6ae99SBarry Smith #define __FUNCT__ "DMGetContext" 69947c6ae99SBarry Smith /*@ 70047c6ae99SBarry Smith DMGetContext - Gets a user context from a DM object 70147c6ae99SBarry Smith 70247c6ae99SBarry Smith Not Collective 70347c6ae99SBarry Smith 70447c6ae99SBarry Smith Input Parameter: 70547c6ae99SBarry Smith . dm - the DM object 70647c6ae99SBarry Smith 70747c6ae99SBarry Smith Output Parameter: 70847c6ae99SBarry Smith . ctx - the user context 70947c6ae99SBarry Smith 71047c6ae99SBarry Smith Level: intermediate 71147c6ae99SBarry Smith 71247c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix(), DMGetContext() 71347c6ae99SBarry Smith 71447c6ae99SBarry Smith @*/ 71547c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMGetContext(DM dm,void **ctx) 71647c6ae99SBarry Smith { 71747c6ae99SBarry Smith PetscFunctionBegin; 71847c6ae99SBarry Smith *ctx = dm->ctx; 71947c6ae99SBarry Smith PetscFunctionReturn(0); 72047c6ae99SBarry Smith } 72147c6ae99SBarry Smith 72247c6ae99SBarry Smith #undef __FUNCT__ 72347c6ae99SBarry Smith #define __FUNCT__ "DMSetInitialGuess" 72447c6ae99SBarry Smith /*@ 72547c6ae99SBarry Smith DMSetInitialGuess - sets a function to compute an initial guess vector entries for the solvers 72647c6ae99SBarry Smith 72747c6ae99SBarry Smith Logically Collective on DM 72847c6ae99SBarry Smith 72947c6ae99SBarry Smith Input Parameter: 73047c6ae99SBarry Smith + dm - the DM object to destroy 73147c6ae99SBarry Smith - f - the function to compute the initial guess 73247c6ae99SBarry Smith 73347c6ae99SBarry Smith Level: intermediate 73447c6ae99SBarry Smith 73547c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix(), DMGetContext(), DMSetFunction(), DMSetJacobian() 73647c6ae99SBarry Smith 73747c6ae99SBarry Smith @*/ 73847c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMSetInitialGuess(DM dm,PetscErrorCode (*f)(DM,Vec)) 73947c6ae99SBarry Smith { 74047c6ae99SBarry Smith PetscFunctionBegin; 74147c6ae99SBarry Smith dm->ops->initialguess = f; 74247c6ae99SBarry Smith PetscFunctionReturn(0); 74347c6ae99SBarry Smith } 74447c6ae99SBarry Smith 74547c6ae99SBarry Smith #undef __FUNCT__ 74647c6ae99SBarry Smith #define __FUNCT__ "DMSetFunction" 74747c6ae99SBarry Smith /*@ 74847c6ae99SBarry Smith DMSetFunction - sets a function to compute the right hand side vector entries for the KSP solver or nonlinear function for SNES 74947c6ae99SBarry Smith 75047c6ae99SBarry Smith Logically Collective on DM 75147c6ae99SBarry Smith 75247c6ae99SBarry Smith Input Parameter: 75347c6ae99SBarry Smith + dm - the DM object 75447c6ae99SBarry Smith - f - the function to compute (use PETSC_NULL to cancel a previous function that was set) 75547c6ae99SBarry Smith 75647c6ae99SBarry Smith Level: intermediate 75747c6ae99SBarry Smith 75847c6ae99SBarry Smith Notes: This sets both the function for function evaluations and the function used to compute Jacobians via finite differences if no Jacobian 75947c6ae99SBarry Smith computer is provided with DMSetJacobian(). Canceling cancels the function, but not the function used to compute the Jacobian. 76047c6ae99SBarry Smith 76147c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix(), DMGetContext(), DMSetInitialGuess(), 76247c6ae99SBarry Smith DMSetJacobian() 76347c6ae99SBarry Smith 76447c6ae99SBarry Smith @*/ 76547c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMSetFunction(DM dm,PetscErrorCode (*f)(DM,Vec,Vec)) 76647c6ae99SBarry Smith { 76747c6ae99SBarry Smith PetscFunctionBegin; 76847c6ae99SBarry Smith dm->ops->function = f; 76947c6ae99SBarry Smith if (f) { 77047c6ae99SBarry Smith dm->ops->functionj = f; 77147c6ae99SBarry Smith } 77247c6ae99SBarry Smith PetscFunctionReturn(0); 77347c6ae99SBarry Smith } 77447c6ae99SBarry Smith 77547c6ae99SBarry Smith #undef __FUNCT__ 77647c6ae99SBarry Smith #define __FUNCT__ "DMSetJacobian" 77747c6ae99SBarry Smith /*@ 77847c6ae99SBarry Smith DMSetJacobian - sets a function to compute the matrix entries for the KSP solver or Jacobian for SNES 77947c6ae99SBarry Smith 78047c6ae99SBarry Smith Logically Collective on DM 78147c6ae99SBarry Smith 78247c6ae99SBarry Smith Input Parameter: 78347c6ae99SBarry Smith + dm - the DM object to destroy 78447c6ae99SBarry Smith - f - the function to compute the matrix entries 78547c6ae99SBarry Smith 78647c6ae99SBarry Smith Level: intermediate 78747c6ae99SBarry Smith 78847c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix(), DMGetContext(), DMSetInitialGuess(), 78947c6ae99SBarry Smith DMSetFunction() 79047c6ae99SBarry Smith 79147c6ae99SBarry Smith @*/ 79247c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMSetJacobian(DM dm,PetscErrorCode (*f)(DM,Vec,Mat,Mat,MatStructure*)) 79347c6ae99SBarry Smith { 79447c6ae99SBarry Smith PetscFunctionBegin; 79547c6ae99SBarry Smith dm->ops->jacobian = f; 79647c6ae99SBarry Smith PetscFunctionReturn(0); 79747c6ae99SBarry Smith } 79847c6ae99SBarry Smith 79947c6ae99SBarry Smith #undef __FUNCT__ 80047c6ae99SBarry Smith #define __FUNCT__ "DMComputeInitialGuess" 80147c6ae99SBarry Smith /*@ 80247c6ae99SBarry Smith DMComputeInitialGuess - computes an initial guess vector entries for the KSP solvers 80347c6ae99SBarry Smith 80447c6ae99SBarry Smith Collective on DM 80547c6ae99SBarry Smith 80647c6ae99SBarry Smith Input Parameter: 80747c6ae99SBarry Smith + dm - the DM object to destroy 80847c6ae99SBarry Smith - x - the vector to hold the initial guess values 80947c6ae99SBarry Smith 81047c6ae99SBarry Smith Level: developer 81147c6ae99SBarry Smith 81247c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix(), DMGetContext(), DMSetRhs(), DMSetMat() 81347c6ae99SBarry Smith 81447c6ae99SBarry Smith @*/ 81547c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMComputeInitialGuess(DM dm,Vec x) 81647c6ae99SBarry Smith { 81747c6ae99SBarry Smith PetscErrorCode ierr; 81847c6ae99SBarry Smith PetscFunctionBegin; 81947c6ae99SBarry Smith if (!dm->ops->initialguess) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE,"Need to provide function with DMSetInitialGuess()"); 82047c6ae99SBarry Smith ierr = (*dm->ops->initialguess)(dm,x);CHKERRQ(ierr); 82147c6ae99SBarry Smith PetscFunctionReturn(0); 82247c6ae99SBarry Smith } 82347c6ae99SBarry Smith 82447c6ae99SBarry Smith #undef __FUNCT__ 82547c6ae99SBarry Smith #define __FUNCT__ "DMHasInitialGuess" 82647c6ae99SBarry Smith /*@ 82747c6ae99SBarry Smith DMHasInitialGuess - does the DM object have an initial guess function 82847c6ae99SBarry Smith 82947c6ae99SBarry Smith Not Collective 83047c6ae99SBarry Smith 83147c6ae99SBarry Smith Input Parameter: 83247c6ae99SBarry Smith . dm - the DM object to destroy 83347c6ae99SBarry Smith 83447c6ae99SBarry Smith Output Parameter: 83547c6ae99SBarry Smith . flg - PETSC_TRUE if function exists 83647c6ae99SBarry Smith 83747c6ae99SBarry Smith Level: developer 83847c6ae99SBarry Smith 83947c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix(), DMGetContext(), DMSetFunction(), DMSetJacobian() 84047c6ae99SBarry Smith 84147c6ae99SBarry Smith @*/ 84247c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMHasInitialGuess(DM dm,PetscBool *flg) 84347c6ae99SBarry Smith { 84447c6ae99SBarry Smith PetscFunctionBegin; 84547c6ae99SBarry Smith *flg = (dm->ops->initialguess) ? PETSC_TRUE : PETSC_FALSE; 84647c6ae99SBarry Smith PetscFunctionReturn(0); 84747c6ae99SBarry Smith } 84847c6ae99SBarry Smith 84947c6ae99SBarry Smith #undef __FUNCT__ 85047c6ae99SBarry Smith #define __FUNCT__ "DMHasFunction" 85147c6ae99SBarry Smith /*@ 85247c6ae99SBarry Smith DMHasFunction - does the DM object have a function 85347c6ae99SBarry Smith 85447c6ae99SBarry Smith Not Collective 85547c6ae99SBarry Smith 85647c6ae99SBarry Smith Input Parameter: 85747c6ae99SBarry Smith . dm - the DM object to destroy 85847c6ae99SBarry Smith 85947c6ae99SBarry Smith Output Parameter: 86047c6ae99SBarry Smith . flg - PETSC_TRUE if function exists 86147c6ae99SBarry Smith 86247c6ae99SBarry Smith Level: developer 86347c6ae99SBarry Smith 86447c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix(), DMGetContext(), DMSetFunction(), DMSetJacobian() 86547c6ae99SBarry Smith 86647c6ae99SBarry Smith @*/ 86747c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMHasFunction(DM dm,PetscBool *flg) 86847c6ae99SBarry Smith { 86947c6ae99SBarry Smith PetscFunctionBegin; 87047c6ae99SBarry Smith *flg = (dm->ops->function) ? PETSC_TRUE : PETSC_FALSE; 87147c6ae99SBarry Smith PetscFunctionReturn(0); 87247c6ae99SBarry Smith } 87347c6ae99SBarry Smith 87447c6ae99SBarry Smith #undef __FUNCT__ 87547c6ae99SBarry Smith #define __FUNCT__ "DMHasJacobian" 87647c6ae99SBarry Smith /*@ 87747c6ae99SBarry Smith DMHasJacobian - does the DM object have a matrix function 87847c6ae99SBarry Smith 87947c6ae99SBarry Smith Not Collective 88047c6ae99SBarry Smith 88147c6ae99SBarry Smith Input Parameter: 88247c6ae99SBarry Smith . dm - the DM object to destroy 88347c6ae99SBarry Smith 88447c6ae99SBarry Smith Output Parameter: 88547c6ae99SBarry Smith . flg - PETSC_TRUE if function exists 88647c6ae99SBarry Smith 88747c6ae99SBarry Smith Level: developer 88847c6ae99SBarry Smith 88947c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix(), DMGetContext(), DMSetFunction(), DMSetJacobian() 89047c6ae99SBarry Smith 89147c6ae99SBarry Smith @*/ 89247c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMHasJacobian(DM dm,PetscBool *flg) 89347c6ae99SBarry Smith { 89447c6ae99SBarry Smith PetscFunctionBegin; 89547c6ae99SBarry Smith *flg = (dm->ops->jacobian) ? PETSC_TRUE : PETSC_FALSE; 89647c6ae99SBarry Smith PetscFunctionReturn(0); 89747c6ae99SBarry Smith } 89847c6ae99SBarry Smith 89947c6ae99SBarry Smith #undef __FUNCT__ 90047c6ae99SBarry Smith #define __FUNCT__ "DMComputeFunction" 90147c6ae99SBarry Smith /*@ 90247c6ae99SBarry Smith DMComputeFunction - computes the right hand side vector entries for the KSP solver or nonlinear function for SNES 90347c6ae99SBarry Smith 90447c6ae99SBarry Smith Collective on DM 90547c6ae99SBarry Smith 90647c6ae99SBarry Smith Input Parameter: 90747c6ae99SBarry Smith + dm - the DM object to destroy 90847c6ae99SBarry Smith . x - the location where the function is evaluationed, may be ignored for linear problems 90947c6ae99SBarry Smith - b - the vector to hold the right hand side entries 91047c6ae99SBarry Smith 91147c6ae99SBarry Smith Level: developer 91247c6ae99SBarry Smith 91347c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix(), DMGetContext(), DMSetInitialGuess(), 91447c6ae99SBarry Smith DMSetJacobian() 91547c6ae99SBarry Smith 91647c6ae99SBarry Smith @*/ 91747c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMComputeFunction(DM dm,Vec x,Vec b) 91847c6ae99SBarry Smith { 91947c6ae99SBarry Smith PetscErrorCode ierr; 92047c6ae99SBarry Smith PetscFunctionBegin; 92147c6ae99SBarry Smith if (!dm->ops->function) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE,"Need to provide function with DMSetFunction()"); 92247c6ae99SBarry Smith if (!x) x = dm->x; 92347c6ae99SBarry Smith ierr = (*dm->ops->function)(dm,x,b);CHKERRQ(ierr); 92447c6ae99SBarry Smith PetscFunctionReturn(0); 92547c6ae99SBarry Smith } 92647c6ae99SBarry Smith 92747c6ae99SBarry Smith 92847c6ae99SBarry Smith #undef __FUNCT__ 92947c6ae99SBarry Smith #define __FUNCT__ "DMComputeJacobian" 93047c6ae99SBarry Smith /*@ 93147c6ae99SBarry Smith DMComputeJacobian - compute the matrix entries for the solver 93247c6ae99SBarry Smith 93347c6ae99SBarry Smith Collective on DM 93447c6ae99SBarry Smith 93547c6ae99SBarry Smith Input Parameter: 93647c6ae99SBarry Smith + dm - the DM object 93747c6ae99SBarry Smith . x - location to compute Jacobian at; may be ignored for linear problems 93847c6ae99SBarry Smith . A - matrix that defines the operator for the linear solve 93947c6ae99SBarry Smith - B - the matrix used to construct the preconditioner 94047c6ae99SBarry Smith 94147c6ae99SBarry Smith Level: developer 94247c6ae99SBarry Smith 94347c6ae99SBarry Smith .seealso DMView(), DMCreateGlobalVector(), DMGetInterpolation(), DMGetColoring(), DMGetMatrix(), DMGetContext(), DMSetInitialGuess(), 94447c6ae99SBarry Smith DMSetFunction() 94547c6ae99SBarry Smith 94647c6ae99SBarry Smith @*/ 94747c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMComputeJacobian(DM dm,Vec x,Mat A,Mat B,MatStructure *stflag) 94847c6ae99SBarry Smith { 94947c6ae99SBarry Smith PetscErrorCode ierr; 95047c6ae99SBarry Smith 95147c6ae99SBarry Smith PetscFunctionBegin; 95247c6ae99SBarry Smith if (!dm->ops->jacobian) { 95347c6ae99SBarry Smith ISColoring coloring; 95447c6ae99SBarry Smith MatFDColoring fd; 95547c6ae99SBarry Smith 95647c6ae99SBarry Smith ierr = DMGetColoring(dm,IS_COLORING_GHOSTED,MATAIJ,&coloring);CHKERRQ(ierr); 95747c6ae99SBarry Smith ierr = MatFDColoringCreate(B,coloring,&fd);CHKERRQ(ierr); 95847c6ae99SBarry Smith ierr = ISColoringDestroy(coloring);CHKERRQ(ierr); 95947c6ae99SBarry Smith ierr = MatFDColoringSetFunction(fd,(PetscErrorCode (*)(void))dm->ops->functionj,dm);CHKERRQ(ierr); 96047c6ae99SBarry Smith dm->fd = fd; 96147c6ae99SBarry Smith dm->ops->jacobian = DMComputeJacobianDefault; 96247c6ae99SBarry Smith 96347c6ae99SBarry Smith if (!dm->x) { 96447c6ae99SBarry Smith ierr = MatGetVecs(B,&dm->x,PETSC_NULL);CHKERRQ(ierr); 96547c6ae99SBarry Smith } 96647c6ae99SBarry Smith } 96747c6ae99SBarry Smith if (!x) x = dm->x; 96847c6ae99SBarry Smith ierr = (*dm->ops->jacobian)(dm,x,A,B,stflag);CHKERRQ(ierr); 96947c6ae99SBarry Smith PetscFunctionReturn(0); 97047c6ae99SBarry Smith } 971264ace61SBarry Smith 972264ace61SBarry Smith PetscFList DMList = PETSC_NULL; 973264ace61SBarry Smith PetscBool DMRegisterAllCalled = PETSC_FALSE; 974264ace61SBarry Smith 975264ace61SBarry Smith #undef __FUNCT__ 976264ace61SBarry Smith #define __FUNCT__ "DMSetType" 977264ace61SBarry Smith /*@C 978264ace61SBarry Smith DMSetType - Builds a DM, for a particular DM implementation. 979264ace61SBarry Smith 980264ace61SBarry Smith Collective on DM 981264ace61SBarry Smith 982264ace61SBarry Smith Input Parameters: 983264ace61SBarry Smith + dm - The DM object 984264ace61SBarry Smith - method - The name of the DM type 985264ace61SBarry Smith 986264ace61SBarry Smith Options Database Key: 987264ace61SBarry Smith . -dm_type <type> - Sets the DM type; use -help for a list of available types 988264ace61SBarry Smith 989264ace61SBarry Smith Notes: 990264ace61SBarry Smith See "petsc/include/petscda.h" for available DM types (for instance, DM1D, DM2D, or DM3D). 991264ace61SBarry Smith 992264ace61SBarry Smith Level: intermediate 993264ace61SBarry Smith 994264ace61SBarry Smith .keywords: DM, set, type 995264ace61SBarry Smith .seealso: DMGetType(), DMCreate() 996264ace61SBarry Smith @*/ 997264ace61SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMSetType(DM dm, const DMType method) 998264ace61SBarry Smith { 999264ace61SBarry Smith PetscErrorCode (*r)(DM); 1000264ace61SBarry Smith PetscBool match; 1001264ace61SBarry Smith PetscErrorCode ierr; 1002264ace61SBarry Smith 1003264ace61SBarry Smith PetscFunctionBegin; 1004264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 1005264ace61SBarry Smith ierr = PetscTypeCompare((PetscObject) dm, method, &match);CHKERRQ(ierr); 1006264ace61SBarry Smith if (match) PetscFunctionReturn(0); 1007264ace61SBarry Smith 1008264ace61SBarry Smith if (!DMRegisterAllCalled) {ierr = DMRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 1009264ace61SBarry Smith ierr = PetscFListFind(DMList, ((PetscObject)dm)->comm, method,(void (**)(void)) &r);CHKERRQ(ierr); 1010264ace61SBarry Smith if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown DM type: %s", method); 1011264ace61SBarry Smith 1012264ace61SBarry Smith if (dm->ops->destroy) { 1013264ace61SBarry Smith ierr = (*dm->ops->destroy)(dm);CHKERRQ(ierr); 1014264ace61SBarry Smith } 1015264ace61SBarry Smith ierr = (*r)(dm);CHKERRQ(ierr); 1016264ace61SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)dm,method);CHKERRQ(ierr); 1017264ace61SBarry Smith PetscFunctionReturn(0); 1018264ace61SBarry Smith } 1019264ace61SBarry Smith 1020264ace61SBarry Smith #undef __FUNCT__ 1021264ace61SBarry Smith #define __FUNCT__ "DMGetType" 1022264ace61SBarry Smith /*@C 1023264ace61SBarry Smith DMGetType - Gets the DM type name (as a string) from the DM. 1024264ace61SBarry Smith 1025264ace61SBarry Smith Not Collective 1026264ace61SBarry Smith 1027264ace61SBarry Smith Input Parameter: 1028264ace61SBarry Smith . dm - The DM 1029264ace61SBarry Smith 1030264ace61SBarry Smith Output Parameter: 1031264ace61SBarry Smith . type - The DM type name 1032264ace61SBarry Smith 1033264ace61SBarry Smith Level: intermediate 1034264ace61SBarry Smith 1035264ace61SBarry Smith .keywords: DM, get, type, name 1036264ace61SBarry Smith .seealso: DMSetType(), DMCreate() 1037264ace61SBarry Smith @*/ 1038264ace61SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMGetType(DM dm, const DMType *type) 1039264ace61SBarry Smith { 1040264ace61SBarry Smith PetscErrorCode ierr; 1041264ace61SBarry Smith 1042264ace61SBarry Smith PetscFunctionBegin; 1043264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 1044264ace61SBarry Smith PetscValidCharPointer(type,2); 1045264ace61SBarry Smith if (!DMRegisterAllCalled) { 1046264ace61SBarry Smith ierr = DMRegisterAll(PETSC_NULL);CHKERRQ(ierr); 1047264ace61SBarry Smith } 1048264ace61SBarry Smith *type = ((PetscObject)dm)->type_name; 1049264ace61SBarry Smith PetscFunctionReturn(0); 1050264ace61SBarry Smith } 1051264ace61SBarry Smith 1052264ace61SBarry Smith 1053264ace61SBarry Smith /*--------------------------------------------------------------------------------------------------------------------*/ 1054264ace61SBarry Smith 1055264ace61SBarry Smith #undef __FUNCT__ 1056264ace61SBarry Smith #define __FUNCT__ "DMRegister" 1057264ace61SBarry Smith /*@C 1058264ace61SBarry Smith DMRegister - See DMRegisterDynamic() 1059264ace61SBarry Smith 1060264ace61SBarry Smith Level: advanced 1061264ace61SBarry Smith @*/ 1062264ace61SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(DM)) 1063264ace61SBarry Smith { 1064264ace61SBarry Smith char fullname[PETSC_MAX_PATH_LEN]; 1065264ace61SBarry Smith PetscErrorCode ierr; 1066264ace61SBarry Smith 1067264ace61SBarry Smith PetscFunctionBegin; 1068264ace61SBarry Smith ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr); 1069264ace61SBarry Smith ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr); 1070264ace61SBarry Smith ierr = PetscStrcat(fullname, name);CHKERRQ(ierr); 1071264ace61SBarry Smith ierr = PetscFListAdd(&DMList, sname, fullname, (void (*)(void)) function);CHKERRQ(ierr); 1072264ace61SBarry Smith PetscFunctionReturn(0); 1073264ace61SBarry Smith } 1074264ace61SBarry Smith 1075264ace61SBarry Smith 1076264ace61SBarry Smith /*--------------------------------------------------------------------------------------------------------------------*/ 1077264ace61SBarry Smith #undef __FUNCT__ 1078264ace61SBarry Smith #define __FUNCT__ "DMRegisterDestroy" 1079264ace61SBarry Smith /*@C 1080264ace61SBarry Smith DMRegisterDestroy - Frees the list of DM methods that were registered by DMRegister()/DMRegisterDynamic(). 1081264ace61SBarry Smith 1082264ace61SBarry Smith Not Collective 1083264ace61SBarry Smith 1084264ace61SBarry Smith Level: advanced 1085264ace61SBarry Smith 1086264ace61SBarry Smith .keywords: DM, register, destroy 1087264ace61SBarry Smith .seealso: DMRegister(), DMRegisterAll(), DMRegisterDynamic() 1088264ace61SBarry Smith @*/ 1089264ace61SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DMRegisterDestroy(void) 1090264ace61SBarry Smith { 1091264ace61SBarry Smith PetscErrorCode ierr; 1092264ace61SBarry Smith 1093264ace61SBarry Smith PetscFunctionBegin; 1094264ace61SBarry Smith ierr = PetscFListDestroy(&DMList);CHKERRQ(ierr); 1095264ace61SBarry Smith DMRegisterAllCalled = PETSC_FALSE; 1096264ace61SBarry Smith PetscFunctionReturn(0); 1097264ace61SBarry Smith } 1098