108da532bSDmitry Karpeev #include <petscsnes.h> 2b45d2f2cSJed Brown #include <petsc-private/dmimpl.h> /*I "petscdm.h" I*/ 347c6ae99SBarry Smith 4732e2eb9SMatthew G Knepley PetscClassId DM_CLASSID; 567a56275SMatthew G Knepley PetscLogEvent DM_Convert, DM_GlobalToLocal, DM_LocalToGlobal; 667a56275SMatthew G Knepley 747c6ae99SBarry Smith #undef __FUNCT__ 8a4121054SBarry Smith #define __FUNCT__ "DMCreate" 9a4121054SBarry Smith /*@ 10de043629SMatthew G Knepley DMCreate - Creates an empty DM object. The type can then be set with DMSetType(). 11a4121054SBarry Smith 12a4121054SBarry Smith If you never call DMSetType() it will generate an 13a4121054SBarry Smith error when you try to use the vector. 14a4121054SBarry Smith 15a4121054SBarry Smith Collective on MPI_Comm 16a4121054SBarry Smith 17a4121054SBarry Smith Input Parameter: 18a4121054SBarry Smith . comm - The communicator for the DM object 19a4121054SBarry Smith 20a4121054SBarry Smith Output Parameter: 21a4121054SBarry Smith . dm - The DM object 22a4121054SBarry Smith 23a4121054SBarry Smith Level: beginner 24a4121054SBarry Smith 25a4121054SBarry Smith .seealso: DMSetType(), DMDA, DMSLICED, DMCOMPOSITE 26a4121054SBarry Smith @*/ 277087cfbeSBarry Smith PetscErrorCode DMCreate(MPI_Comm comm,DM *dm) 28a4121054SBarry Smith { 29a4121054SBarry Smith DM v; 30a4121054SBarry Smith PetscErrorCode ierr; 31a4121054SBarry Smith 32a4121054SBarry Smith PetscFunctionBegin; 331411c6eeSJed Brown PetscValidPointer(dm,2); 341411c6eeSJed Brown *dm = PETSC_NULL; 35a4121054SBarry Smith #ifndef PETSC_USE_DYNAMIC_LIBRARIES 36b84caa0eSBarry Smith ierr = VecInitializePackage(PETSC_NULL);CHKERRQ(ierr); 37b84caa0eSBarry Smith ierr = MatInitializePackage(PETSC_NULL);CHKERRQ(ierr); 38a4121054SBarry Smith ierr = DMInitializePackage(PETSC_NULL);CHKERRQ(ierr); 39a4121054SBarry Smith #endif 40a4121054SBarry Smith 413194b578SJed Brown ierr = PetscHeaderCreate(v, _p_DM, struct _DMOps, DM_CLASSID, -1, "DM", "Distribution Manager", "DM", comm, DMDestroy, DMView);CHKERRQ(ierr); 42a4121054SBarry Smith ierr = PetscMemzero(v->ops, sizeof(struct _DMOps));CHKERRQ(ierr); 431411c6eeSJed Brown 44e7c4fc90SDmitry Karpeev 45a89ea682SMatthew G Knepley v->workSize = 0; 46a89ea682SMatthew G Knepley v->workArray = PETSC_NULL; 471411c6eeSJed Brown v->ltogmap = PETSC_NULL; 481411c6eeSJed Brown v->ltogmapb = PETSC_NULL; 491411c6eeSJed Brown v->bs = 1; 50171400e9SBarry Smith v->coloringtype = IS_COLORING_GLOBAL; 51*970e74d5SMatthew G Knepley v->lf = PETSC_NULL; 52*970e74d5SMatthew G Knepley v->lj = PETSC_NULL; 531411c6eeSJed Brown 541411c6eeSJed Brown *dm = v; 55a4121054SBarry Smith PetscFunctionReturn(0); 56a4121054SBarry Smith } 57a4121054SBarry Smith 58a4121054SBarry Smith 59a4121054SBarry Smith #undef __FUNCT__ 609a42bb27SBarry Smith #define __FUNCT__ "DMSetVecType" 619a42bb27SBarry Smith /*@C 62564755cdSBarry Smith DMSetVecType - Sets the type of vector created with DMCreateLocalVector() and DMCreateGlobalVector() 639a42bb27SBarry Smith 64aa219208SBarry Smith Logically Collective on DMDA 659a42bb27SBarry Smith 669a42bb27SBarry Smith Input Parameter: 679a42bb27SBarry Smith + da - initial distributed array 688154be41SBarry Smith . ctype - the vector type, currently either VECSTANDARD or VECCUSP 699a42bb27SBarry Smith 709a42bb27SBarry Smith Options Database: 71dd85299cSBarry Smith . -dm_vec_type ctype 729a42bb27SBarry Smith 739a42bb27SBarry Smith Level: intermediate 749a42bb27SBarry Smith 75aa219208SBarry Smith .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMDestroy(), DMDA, DMDAInterpolationType, VecType 769a42bb27SBarry Smith @*/ 777087cfbeSBarry Smith PetscErrorCode DMSetVecType(DM da,const VecType ctype) 789a42bb27SBarry Smith { 799a42bb27SBarry Smith PetscErrorCode ierr; 809a42bb27SBarry Smith 819a42bb27SBarry Smith PetscFunctionBegin; 829a42bb27SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 839a42bb27SBarry Smith ierr = PetscFree(da->vectype);CHKERRQ(ierr); 849a42bb27SBarry Smith ierr = PetscStrallocpy(ctype,&da->vectype);CHKERRQ(ierr); 859a42bb27SBarry Smith PetscFunctionReturn(0); 869a42bb27SBarry Smith } 879a42bb27SBarry Smith 889a42bb27SBarry Smith #undef __FUNCT__ 89521d9a4cSLisandro Dalcin #define __FUNCT__ "DMSetMatType" 90521d9a4cSLisandro Dalcin /*@C 91521d9a4cSLisandro Dalcin DMSetMatType - Sets the type of matrix created with DMCreateMatrix() 92521d9a4cSLisandro Dalcin 93521d9a4cSLisandro Dalcin Logically Collective on DM 94521d9a4cSLisandro Dalcin 95521d9a4cSLisandro Dalcin Input Parameter: 96521d9a4cSLisandro Dalcin + dm - the DM context 97521d9a4cSLisandro Dalcin . ctype - the matrix type 98521d9a4cSLisandro Dalcin 99521d9a4cSLisandro Dalcin Options Database: 100521d9a4cSLisandro Dalcin . -dm_mat_type ctype 101521d9a4cSLisandro Dalcin 102521d9a4cSLisandro Dalcin Level: intermediate 103521d9a4cSLisandro Dalcin 104521d9a4cSLisandro Dalcin .seealso: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMCreateMatrix(), DMSetMatrixPreallocateOnly(), MatType 105521d9a4cSLisandro Dalcin @*/ 106521d9a4cSLisandro Dalcin PetscErrorCode DMSetMatType(DM dm,const MatType ctype) 107521d9a4cSLisandro Dalcin { 108521d9a4cSLisandro Dalcin PetscErrorCode ierr; 109521d9a4cSLisandro Dalcin PetscFunctionBegin; 110521d9a4cSLisandro Dalcin PetscValidHeaderSpecific(dm,DM_CLASSID,1); 111521d9a4cSLisandro Dalcin ierr = PetscFree(dm->mattype);CHKERRQ(ierr); 112521d9a4cSLisandro Dalcin ierr = PetscStrallocpy(ctype,&dm->mattype);CHKERRQ(ierr); 113521d9a4cSLisandro Dalcin PetscFunctionReturn(0); 114521d9a4cSLisandro Dalcin } 115521d9a4cSLisandro Dalcin 116521d9a4cSLisandro Dalcin #undef __FUNCT__ 1179a42bb27SBarry Smith #define __FUNCT__ "DMSetOptionsPrefix" 1189a42bb27SBarry Smith /*@C 1199a42bb27SBarry Smith DMSetOptionsPrefix - Sets the prefix used for searching for all 120aa219208SBarry Smith DMDA options in the database. 1219a42bb27SBarry Smith 122aa219208SBarry Smith Logically Collective on DMDA 1239a42bb27SBarry Smith 1249a42bb27SBarry Smith Input Parameter: 125aa219208SBarry Smith + da - the DMDA context 1269a42bb27SBarry Smith - prefix - the prefix to prepend to all option names 1279a42bb27SBarry Smith 1289a42bb27SBarry Smith Notes: 1299a42bb27SBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1309a42bb27SBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 1319a42bb27SBarry Smith 1329a42bb27SBarry Smith Level: advanced 1339a42bb27SBarry Smith 134aa219208SBarry Smith .keywords: DMDA, set, options, prefix, database 1359a42bb27SBarry Smith 1369a42bb27SBarry Smith .seealso: DMSetFromOptions() 1379a42bb27SBarry Smith @*/ 1387087cfbeSBarry Smith PetscErrorCode DMSetOptionsPrefix(DM dm,const char prefix[]) 1399a42bb27SBarry Smith { 1409a42bb27SBarry Smith PetscErrorCode ierr; 1419a42bb27SBarry Smith 1429a42bb27SBarry Smith PetscFunctionBegin; 1439a42bb27SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1449a42bb27SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)dm,prefix);CHKERRQ(ierr); 1459a42bb27SBarry Smith PetscFunctionReturn(0); 1469a42bb27SBarry Smith } 1479a42bb27SBarry Smith 1489a42bb27SBarry Smith #undef __FUNCT__ 14947c6ae99SBarry Smith #define __FUNCT__ "DMDestroy" 15047c6ae99SBarry Smith /*@ 151aa219208SBarry Smith DMDestroy - Destroys a vector packer or DMDA. 15247c6ae99SBarry Smith 15347c6ae99SBarry Smith Collective on DM 15447c6ae99SBarry Smith 15547c6ae99SBarry Smith Input Parameter: 15647c6ae99SBarry Smith . dm - the DM object to destroy 15747c6ae99SBarry Smith 15847c6ae99SBarry Smith Level: developer 15947c6ae99SBarry Smith 160e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 16147c6ae99SBarry Smith 16247c6ae99SBarry Smith @*/ 163fcfd50ebSBarry Smith PetscErrorCode DMDestroy(DM *dm) 16447c6ae99SBarry Smith { 165732e2eb9SMatthew G Knepley PetscInt i, cnt = 0; 166b17ce1afSJed Brown DMCoarsenHookLink link,next; 167dfe15315SJed Brown DMNamedVecLink nlink,nnext; 16847c6ae99SBarry Smith PetscErrorCode ierr; 16947c6ae99SBarry Smith 17047c6ae99SBarry Smith PetscFunctionBegin; 1716bf464f9SBarry Smith if (!*dm) PetscFunctionReturn(0); 1726bf464f9SBarry Smith PetscValidHeaderSpecific((*dm),DM_CLASSID,1); 17387e657c6SBarry Smith 17487e657c6SBarry Smith /* count all the circular references of DM and its contained Vecs */ 175732e2eb9SMatthew G Knepley for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 1766bf464f9SBarry Smith if ((*dm)->localin[i]) {cnt++;} 1776bf464f9SBarry Smith if ((*dm)->globalin[i]) {cnt++;} 178732e2eb9SMatthew G Knepley } 179dfe15315SJed Brown for (nlink=(*dm)->namedglobal; nlink; nlink=nlink->next) cnt++; 18071cd77b2SBarry Smith if ((*dm)->x) { 18171cd77b2SBarry Smith PetscObject obj; 18271cd77b2SBarry Smith ierr = PetscObjectQuery((PetscObject)(*dm)->x,"DM",&obj);CHKERRQ(ierr); 18371cd77b2SBarry Smith if (obj == (PetscObject)*dm) cnt++; 18471cd77b2SBarry Smith } 185732e2eb9SMatthew G Knepley 1866bf464f9SBarry Smith if (--((PetscObject)(*dm))->refct - cnt > 0) {*dm = 0; PetscFunctionReturn(0);} 187732e2eb9SMatthew G Knepley /* 188732e2eb9SMatthew G Knepley Need this test because the dm references the vectors that 189732e2eb9SMatthew G Knepley reference the dm, so destroying the dm calls destroy on the 190732e2eb9SMatthew G Knepley vectors that cause another destroy on the dm 191732e2eb9SMatthew G Knepley */ 1926bf464f9SBarry Smith if (((PetscObject)(*dm))->refct < 0) PetscFunctionReturn(0); 1936bf464f9SBarry Smith ((PetscObject) (*dm))->refct = 0; 194732e2eb9SMatthew G Knepley for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 1956bf464f9SBarry Smith if ((*dm)->localout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Destroying a DM that has a local vector obtained with DMGetLocalVector()"); 1966bf464f9SBarry Smith ierr = VecDestroy(&(*dm)->localin[i]);CHKERRQ(ierr); 197732e2eb9SMatthew G Knepley } 198dfe15315SJed Brown for (nlink=(*dm)->namedglobal; nlink; nlink=nnext) { /* Destroy the named vectors */ 199dfe15315SJed Brown nnext = nlink->next; 200dfe15315SJed Brown if (nlink->status != DMVEC_STATUS_IN) SETERRQ1(((PetscObject)*dm)->comm,PETSC_ERR_ARG_WRONGSTATE,"DM still has Vec named '%s' checked out",nlink->name); 201dfe15315SJed Brown ierr = PetscFree(nlink->name);CHKERRQ(ierr); 202dfe15315SJed Brown ierr = VecDestroy(&nlink->X);CHKERRQ(ierr); 203dfe15315SJed Brown ierr = PetscFree(nlink);CHKERRQ(ierr); 204dfe15315SJed Brown } 205dfe15315SJed Brown (*dm)->namedglobal = PETSC_NULL; 2061a266240SBarry Smith 207b17ce1afSJed Brown /* Destroy the list of hooks */ 208b17ce1afSJed Brown for (link=(*dm)->coarsenhook; link; link=next) { 209b17ce1afSJed Brown next = link->next; 210b17ce1afSJed Brown ierr = PetscFree(link);CHKERRQ(ierr); 211b17ce1afSJed Brown } 212b17ce1afSJed Brown (*dm)->coarsenhook = PETSC_NULL; 213b17ce1afSJed Brown 2141a266240SBarry Smith if ((*dm)->ctx && (*dm)->ctxdestroy) { 2151a266240SBarry Smith ierr = (*(*dm)->ctxdestroy)(&(*dm)->ctx);CHKERRQ(ierr); 2161a266240SBarry Smith } 21787e657c6SBarry Smith ierr = VecDestroy(&(*dm)->x);CHKERRQ(ierr); 21871cd77b2SBarry Smith ierr = MatFDColoringDestroy(&(*dm)->fd);CHKERRQ(ierr); 2194dcab191SBarry Smith ierr = DMClearGlobalVectors(*dm);CHKERRQ(ierr); 2206bf464f9SBarry Smith ierr = ISLocalToGlobalMappingDestroy(&(*dm)->ltogmap);CHKERRQ(ierr); 2216bf464f9SBarry Smith ierr = ISLocalToGlobalMappingDestroy(&(*dm)->ltogmapb);CHKERRQ(ierr); 2226bf464f9SBarry Smith ierr = PetscFree((*dm)->vectype);CHKERRQ(ierr); 223073dac72SJed Brown ierr = PetscFree((*dm)->mattype);CHKERRQ(ierr); 224a89ea682SMatthew G Knepley ierr = PetscFree((*dm)->workArray);CHKERRQ(ierr); 225732e2eb9SMatthew G Knepley /* if memory was published with AMS then destroy it */ 2266bf464f9SBarry Smith ierr = PetscObjectDepublish(*dm);CHKERRQ(ierr); 227732e2eb9SMatthew G Knepley 2286bf464f9SBarry Smith ierr = (*(*dm)->ops->destroy)(*dm);CHKERRQ(ierr); 2296bf464f9SBarry Smith ierr = PetscFree((*dm)->data);CHKERRQ(ierr); 230732e2eb9SMatthew G Knepley ierr = PetscHeaderDestroy(dm);CHKERRQ(ierr); 23147c6ae99SBarry Smith PetscFunctionReturn(0); 23247c6ae99SBarry Smith } 23347c6ae99SBarry Smith 23447c6ae99SBarry Smith #undef __FUNCT__ 235d7bf68aeSBarry Smith #define __FUNCT__ "DMSetUp" 236d7bf68aeSBarry Smith /*@ 237d7bf68aeSBarry Smith DMSetUp - sets up the data structures inside a DM object 238d7bf68aeSBarry Smith 239d7bf68aeSBarry Smith Collective on DM 240d7bf68aeSBarry Smith 241d7bf68aeSBarry Smith Input Parameter: 242d7bf68aeSBarry Smith . dm - the DM object to setup 243d7bf68aeSBarry Smith 244d7bf68aeSBarry Smith Level: developer 245d7bf68aeSBarry Smith 246e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 247d7bf68aeSBarry Smith 248d7bf68aeSBarry Smith @*/ 2497087cfbeSBarry Smith PetscErrorCode DMSetUp(DM dm) 250d7bf68aeSBarry Smith { 251d7bf68aeSBarry Smith PetscErrorCode ierr; 252d7bf68aeSBarry Smith 253d7bf68aeSBarry Smith PetscFunctionBegin; 254171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2558387afaaSJed Brown if (dm->setupcalled) PetscFunctionReturn(0); 256d7bf68aeSBarry Smith if (dm->ops->setup) { 257d7bf68aeSBarry Smith ierr = (*dm->ops->setup)(dm);CHKERRQ(ierr); 258d7bf68aeSBarry Smith } 2598387afaaSJed Brown dm->setupcalled = PETSC_TRUE; 260d7bf68aeSBarry Smith PetscFunctionReturn(0); 261d7bf68aeSBarry Smith } 262d7bf68aeSBarry Smith 263d7bf68aeSBarry Smith #undef __FUNCT__ 264d7bf68aeSBarry Smith #define __FUNCT__ "DMSetFromOptions" 265d7bf68aeSBarry Smith /*@ 266d7bf68aeSBarry Smith DMSetFromOptions - sets parameters in a DM from the options database 267d7bf68aeSBarry Smith 268d7bf68aeSBarry Smith Collective on DM 269d7bf68aeSBarry Smith 270d7bf68aeSBarry Smith Input Parameter: 271d7bf68aeSBarry Smith . dm - the DM object to set options for 272d7bf68aeSBarry Smith 273732e2eb9SMatthew G Knepley Options Database: 274dd85299cSBarry Smith + -dm_preallocate_only: Only preallocate the matrix for DMCreateMatrix(), but do not fill it with zeros 275dd85299cSBarry Smith . -dm_vec_type <type> type of vector to create inside DM 276171400e9SBarry Smith . -dm_mat_type <type> type of matrix to create inside DM 277171400e9SBarry Smith - -dm_coloring_type <global or ghosted> 278732e2eb9SMatthew G Knepley 279d7bf68aeSBarry Smith Level: developer 280d7bf68aeSBarry Smith 281e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 282d7bf68aeSBarry Smith 283d7bf68aeSBarry Smith @*/ 2847087cfbeSBarry Smith PetscErrorCode DMSetFromOptions(DM dm) 285d7bf68aeSBarry Smith { 28667ad5babSMatthew G Knepley PetscBool flg1 = PETSC_FALSE,flg2 = PETSC_FALSE,flg3 = PETSC_FALSE,flg4 = PETSC_FALSE,flg; 287d7bf68aeSBarry Smith PetscErrorCode ierr; 288f9ba7244SBarry Smith char typeName[256] = MATAIJ; 289d7bf68aeSBarry Smith 290d7bf68aeSBarry Smith PetscFunctionBegin; 291171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 2923194b578SJed Brown ierr = PetscObjectOptionsBegin((PetscObject)dm);CHKERRQ(ierr); 29382fcb398SMatthew G Knepley ierr = PetscOptionsBool("-dm_view", "Information on DM", "DMView", flg1, &flg1, PETSC_NULL);CHKERRQ(ierr); 294c4721b0eSMatthew G Knepley ierr = PetscOptionsBool("-dm_view_detail", "Exhaustive mesh description", "DMView", flg2, &flg2, PETSC_NULL);CHKERRQ(ierr); 295c4721b0eSMatthew G Knepley ierr = PetscOptionsBool("-dm_view_vtk", "Output mesh in VTK format", "DMView", flg3, &flg3, PETSC_NULL);CHKERRQ(ierr); 29667ad5babSMatthew G Knepley ierr = PetscOptionsBool("-dm_view_latex", "Output mesh in LaTeX TikZ format", "DMView", flg4, &flg4, PETSC_NULL);CHKERRQ(ierr); 297073dac72SJed Brown ierr = PetscOptionsBool("-dm_preallocate_only","only preallocate matrix, but do not set column indices","DMSetMatrixPreallocateOnly",dm->prealloc_only,&dm->prealloc_only,PETSC_NULL);CHKERRQ(ierr); 298f9ba7244SBarry Smith ierr = PetscOptionsList("-dm_vec_type","Vector type used for created vectors","DMSetVecType",VecList,dm->vectype,typeName,256,&flg);CHKERRQ(ierr); 299f9ba7244SBarry Smith if (flg) { 300f9ba7244SBarry Smith ierr = DMSetVecType(dm,typeName);CHKERRQ(ierr); 301f9ba7244SBarry Smith } 302521d9a4cSLisandro Dalcin ierr = PetscOptionsList("-dm_mat_type","Matrix type used for created matrices","DMSetMatType",MatList,dm->mattype?dm->mattype:typeName,typeName,sizeof typeName,&flg);CHKERRQ(ierr); 303073dac72SJed Brown if (flg) { 304521d9a4cSLisandro Dalcin ierr = DMSetMatType(dm,typeName);CHKERRQ(ierr); 305073dac72SJed Brown } 3061b89239cSHong Zhang ierr = PetscOptionsEnum("-dm_is_coloring_type","Global or local coloring of Jacobian","ISColoringType",ISColoringTypes,(PetscEnum)dm->coloringtype,(PetscEnum*)&dm->coloringtype,PETSC_NULL);CHKERRQ(ierr); 307f9ba7244SBarry Smith if (dm->ops->setfromoptions) { 308f9ba7244SBarry Smith ierr = (*dm->ops->setfromoptions)(dm);CHKERRQ(ierr); 309f9ba7244SBarry Smith } 310f9ba7244SBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 311f9ba7244SBarry Smith ierr = PetscObjectProcessOptionsHandlers((PetscObject) dm);CHKERRQ(ierr); 31282fcb398SMatthew G Knepley ierr = PetscOptionsEnd();CHKERRQ(ierr); 31382fcb398SMatthew G Knepley if (flg1) { 31482fcb398SMatthew G Knepley ierr = DMView(dm, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); 31582fcb398SMatthew G Knepley } 316c4721b0eSMatthew G Knepley if (flg2) { 317c4721b0eSMatthew G Knepley PetscViewer viewer; 318c4721b0eSMatthew G Knepley 319c4721b0eSMatthew G Knepley ierr = PetscViewerCreate(((PetscObject) dm)->comm, &viewer);CHKERRQ(ierr); 320c4721b0eSMatthew G Knepley ierr = PetscViewerSetType(viewer, PETSCVIEWERASCII);CHKERRQ(ierr); 321c4721b0eSMatthew G Knepley ierr = PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_INFO_DETAIL);CHKERRQ(ierr); 322c4721b0eSMatthew G Knepley ierr = DMView(dm, viewer);CHKERRQ(ierr); 323c4721b0eSMatthew G Knepley ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); 324c4721b0eSMatthew G Knepley } 325c4721b0eSMatthew G Knepley if (flg3) { 326c4721b0eSMatthew G Knepley PetscViewer viewer; 327c4721b0eSMatthew G Knepley 328c4721b0eSMatthew G Knepley ierr = PetscViewerCreate(((PetscObject) dm)->comm, &viewer);CHKERRQ(ierr); 329c4721b0eSMatthew G Knepley ierr = PetscViewerSetType(viewer, PETSCVIEWERASCII);CHKERRQ(ierr); 330c4721b0eSMatthew G Knepley ierr = PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_VTK);CHKERRQ(ierr); 331c4721b0eSMatthew G Knepley ierr = PetscViewerFileSetName(viewer, "mesh.vtk");CHKERRQ(ierr); 332c4721b0eSMatthew G Knepley ierr = DMView(dm, viewer);CHKERRQ(ierr); 333c4721b0eSMatthew G Knepley ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); 334c4721b0eSMatthew G Knepley } 33567ad5babSMatthew G Knepley if (flg4) { 33667ad5babSMatthew G Knepley PetscViewer viewer; 33767ad5babSMatthew G Knepley 33867ad5babSMatthew G Knepley ierr = PetscViewerCreate(((PetscObject) dm)->comm, &viewer);CHKERRQ(ierr); 33967ad5babSMatthew G Knepley ierr = PetscViewerSetType(viewer, PETSCVIEWERASCII);CHKERRQ(ierr); 34067ad5babSMatthew G Knepley ierr = PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_LATEX);CHKERRQ(ierr); 34167ad5babSMatthew G Knepley ierr = PetscViewerFileSetName(viewer, "mesh.tex");CHKERRQ(ierr); 34267ad5babSMatthew G Knepley ierr = DMView(dm, viewer);CHKERRQ(ierr); 34367ad5babSMatthew G Knepley ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); 34467ad5babSMatthew G Knepley } 345d7bf68aeSBarry Smith PetscFunctionReturn(0); 346d7bf68aeSBarry Smith } 347d7bf68aeSBarry Smith 348d7bf68aeSBarry Smith #undef __FUNCT__ 34947c6ae99SBarry Smith #define __FUNCT__ "DMView" 350fc9bc008SSatish Balay /*@C 351aa219208SBarry Smith DMView - Views a vector packer or DMDA. 35247c6ae99SBarry Smith 35347c6ae99SBarry Smith Collective on DM 35447c6ae99SBarry Smith 35547c6ae99SBarry Smith Input Parameter: 35647c6ae99SBarry Smith + dm - the DM object to view 35747c6ae99SBarry Smith - v - the viewer 35847c6ae99SBarry Smith 35947c6ae99SBarry Smith Level: developer 36047c6ae99SBarry Smith 361e727c939SJed Brown .seealso DMDestroy(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 36247c6ae99SBarry Smith 36347c6ae99SBarry Smith @*/ 3647087cfbeSBarry Smith PetscErrorCode DMView(DM dm,PetscViewer v) 36547c6ae99SBarry Smith { 36647c6ae99SBarry Smith PetscErrorCode ierr; 36747c6ae99SBarry Smith 36847c6ae99SBarry Smith PetscFunctionBegin; 369171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3703014e516SBarry Smith if (!v) { 3713014e516SBarry Smith ierr = PetscViewerASCIIGetStdout(((PetscObject)dm)->comm,&v);CHKERRQ(ierr); 3723014e516SBarry Smith } 3730c010503SBarry Smith if (dm->ops->view) { 3740c010503SBarry Smith ierr = (*dm->ops->view)(dm,v);CHKERRQ(ierr); 37547c6ae99SBarry Smith } 37647c6ae99SBarry Smith PetscFunctionReturn(0); 37747c6ae99SBarry Smith } 37847c6ae99SBarry Smith 37947c6ae99SBarry Smith #undef __FUNCT__ 38047c6ae99SBarry Smith #define __FUNCT__ "DMCreateGlobalVector" 38147c6ae99SBarry Smith /*@ 382aa219208SBarry Smith DMCreateGlobalVector - Creates a global vector from a DMDA or DMComposite object 38347c6ae99SBarry Smith 38447c6ae99SBarry Smith Collective on DM 38547c6ae99SBarry Smith 38647c6ae99SBarry Smith Input Parameter: 38747c6ae99SBarry Smith . dm - the DM object 38847c6ae99SBarry Smith 38947c6ae99SBarry Smith Output Parameter: 39047c6ae99SBarry Smith . vec - the global vector 39147c6ae99SBarry Smith 392073dac72SJed Brown Level: beginner 39347c6ae99SBarry Smith 394e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 39547c6ae99SBarry Smith 39647c6ae99SBarry Smith @*/ 3977087cfbeSBarry Smith PetscErrorCode DMCreateGlobalVector(DM dm,Vec *vec) 39847c6ae99SBarry Smith { 39947c6ae99SBarry Smith PetscErrorCode ierr; 40047c6ae99SBarry Smith 40147c6ae99SBarry Smith PetscFunctionBegin; 402171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 40347c6ae99SBarry Smith ierr = (*dm->ops->createglobalvector)(dm,vec);CHKERRQ(ierr); 40447c6ae99SBarry Smith PetscFunctionReturn(0); 40547c6ae99SBarry Smith } 40647c6ae99SBarry Smith 40747c6ae99SBarry Smith #undef __FUNCT__ 40847c6ae99SBarry Smith #define __FUNCT__ "DMCreateLocalVector" 40947c6ae99SBarry Smith /*@ 410aa219208SBarry Smith DMCreateLocalVector - Creates a local vector from a DMDA or DMComposite object 41147c6ae99SBarry Smith 41247c6ae99SBarry Smith Not Collective 41347c6ae99SBarry Smith 41447c6ae99SBarry Smith Input Parameter: 41547c6ae99SBarry Smith . dm - the DM object 41647c6ae99SBarry Smith 41747c6ae99SBarry Smith Output Parameter: 41847c6ae99SBarry Smith . vec - the local vector 41947c6ae99SBarry Smith 420073dac72SJed Brown Level: beginner 42147c6ae99SBarry Smith 422e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 42347c6ae99SBarry Smith 42447c6ae99SBarry Smith @*/ 4257087cfbeSBarry Smith PetscErrorCode DMCreateLocalVector(DM dm,Vec *vec) 42647c6ae99SBarry Smith { 42747c6ae99SBarry Smith PetscErrorCode ierr; 42847c6ae99SBarry Smith 42947c6ae99SBarry Smith PetscFunctionBegin; 430171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 43147c6ae99SBarry Smith ierr = (*dm->ops->createlocalvector)(dm,vec);CHKERRQ(ierr); 43247c6ae99SBarry Smith PetscFunctionReturn(0); 43347c6ae99SBarry Smith } 43447c6ae99SBarry Smith 43547c6ae99SBarry Smith #undef __FUNCT__ 4361411c6eeSJed Brown #define __FUNCT__ "DMGetLocalToGlobalMapping" 4371411c6eeSJed Brown /*@ 4381411c6eeSJed Brown DMGetLocalToGlobalMapping - Accesses the local-to-global mapping in a DM. 4391411c6eeSJed Brown 4401411c6eeSJed Brown Collective on DM 4411411c6eeSJed Brown 4421411c6eeSJed Brown Input Parameter: 4431411c6eeSJed Brown . dm - the DM that provides the mapping 4441411c6eeSJed Brown 4451411c6eeSJed Brown Output Parameter: 4461411c6eeSJed Brown . ltog - the mapping 4471411c6eeSJed Brown 4481411c6eeSJed Brown Level: intermediate 4491411c6eeSJed Brown 4501411c6eeSJed Brown Notes: 4511411c6eeSJed Brown This mapping can then be used by VecSetLocalToGlobalMapping() or 4521411c6eeSJed Brown MatSetLocalToGlobalMapping(). 4531411c6eeSJed Brown 4541411c6eeSJed Brown .seealso: DMCreateLocalVector(), DMGetLocalToGlobalMappingBlock() 4551411c6eeSJed Brown @*/ 4567087cfbeSBarry Smith PetscErrorCode DMGetLocalToGlobalMapping(DM dm,ISLocalToGlobalMapping *ltog) 4571411c6eeSJed Brown { 4581411c6eeSJed Brown PetscErrorCode ierr; 4591411c6eeSJed Brown 4601411c6eeSJed Brown PetscFunctionBegin; 4611411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4621411c6eeSJed Brown PetscValidPointer(ltog,2); 4631411c6eeSJed Brown if (!dm->ltogmap) { 4641411c6eeSJed Brown if (!dm->ops->createlocaltoglobalmapping) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_SUP,"DM can not create LocalToGlobalMapping"); 4651411c6eeSJed Brown ierr = (*dm->ops->createlocaltoglobalmapping)(dm);CHKERRQ(ierr); 4661411c6eeSJed Brown } 4671411c6eeSJed Brown *ltog = dm->ltogmap; 4681411c6eeSJed Brown PetscFunctionReturn(0); 4691411c6eeSJed Brown } 4701411c6eeSJed Brown 4711411c6eeSJed Brown #undef __FUNCT__ 4721411c6eeSJed Brown #define __FUNCT__ "DMGetLocalToGlobalMappingBlock" 4731411c6eeSJed Brown /*@ 4741411c6eeSJed Brown DMGetLocalToGlobalMappingBlock - Accesses the blocked local-to-global mapping in a DM. 4751411c6eeSJed Brown 4761411c6eeSJed Brown Collective on DM 4771411c6eeSJed Brown 4781411c6eeSJed Brown Input Parameter: 4791411c6eeSJed Brown . da - the distributed array that provides the mapping 4801411c6eeSJed Brown 4811411c6eeSJed Brown Output Parameter: 4821411c6eeSJed Brown . ltog - the block mapping 4831411c6eeSJed Brown 4841411c6eeSJed Brown Level: intermediate 4851411c6eeSJed Brown 4861411c6eeSJed Brown Notes: 4871411c6eeSJed Brown This mapping can then be used by VecSetLocalToGlobalMappingBlock() or 4881411c6eeSJed Brown MatSetLocalToGlobalMappingBlock(). 4891411c6eeSJed Brown 4901411c6eeSJed Brown .seealso: DMCreateLocalVector(), DMGetLocalToGlobalMapping(), DMGetBlockSize(), VecSetBlockSize(), MatSetBlockSize() 4911411c6eeSJed Brown @*/ 4927087cfbeSBarry Smith PetscErrorCode DMGetLocalToGlobalMappingBlock(DM dm,ISLocalToGlobalMapping *ltog) 4931411c6eeSJed Brown { 4941411c6eeSJed Brown PetscErrorCode ierr; 4951411c6eeSJed Brown 4961411c6eeSJed Brown PetscFunctionBegin; 4971411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4981411c6eeSJed Brown PetscValidPointer(ltog,2); 4991411c6eeSJed Brown if (!dm->ltogmapb) { 5001411c6eeSJed Brown PetscInt bs; 5011411c6eeSJed Brown ierr = DMGetBlockSize(dm,&bs);CHKERRQ(ierr); 5021411c6eeSJed Brown if (bs > 1) { 5031411c6eeSJed Brown if (!dm->ops->createlocaltoglobalmappingblock) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_SUP,"DM can not create LocalToGlobalMappingBlock"); 5041411c6eeSJed Brown ierr = (*dm->ops->createlocaltoglobalmappingblock)(dm);CHKERRQ(ierr); 5051411c6eeSJed Brown } else { 5061411c6eeSJed Brown ierr = DMGetLocalToGlobalMapping(dm,&dm->ltogmapb);CHKERRQ(ierr); 5071411c6eeSJed Brown ierr = PetscObjectReference((PetscObject)dm->ltogmapb);CHKERRQ(ierr); 5081411c6eeSJed Brown } 5091411c6eeSJed Brown } 5101411c6eeSJed Brown *ltog = dm->ltogmapb; 5111411c6eeSJed Brown PetscFunctionReturn(0); 5121411c6eeSJed Brown } 5131411c6eeSJed Brown 5141411c6eeSJed Brown #undef __FUNCT__ 5151411c6eeSJed Brown #define __FUNCT__ "DMGetBlockSize" 5161411c6eeSJed Brown /*@ 5171411c6eeSJed Brown DMGetBlockSize - Gets the inherent block size associated with a DM 5181411c6eeSJed Brown 5191411c6eeSJed Brown Not Collective 5201411c6eeSJed Brown 5211411c6eeSJed Brown Input Parameter: 5221411c6eeSJed Brown . dm - the DM with block structure 5231411c6eeSJed Brown 5241411c6eeSJed Brown Output Parameter: 5251411c6eeSJed Brown . bs - the block size, 1 implies no exploitable block structure 5261411c6eeSJed Brown 5271411c6eeSJed Brown Level: intermediate 5281411c6eeSJed Brown 5291411c6eeSJed Brown .seealso: ISCreateBlock(), VecSetBlockSize(), MatSetBlockSize(), DMGetLocalToGlobalMappingBlock() 5301411c6eeSJed Brown @*/ 5317087cfbeSBarry Smith PetscErrorCode DMGetBlockSize(DM dm,PetscInt *bs) 5321411c6eeSJed Brown { 5331411c6eeSJed Brown PetscFunctionBegin; 5341411c6eeSJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 5351411c6eeSJed Brown PetscValidPointer(bs,2); 5361411c6eeSJed 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"); 5371411c6eeSJed Brown *bs = dm->bs; 5381411c6eeSJed Brown PetscFunctionReturn(0); 5391411c6eeSJed Brown } 5401411c6eeSJed Brown 5411411c6eeSJed Brown #undef __FUNCT__ 542e727c939SJed Brown #define __FUNCT__ "DMCreateInterpolation" 54347c6ae99SBarry Smith /*@ 544e727c939SJed Brown DMCreateInterpolation - Gets interpolation matrix between two DMDA or DMComposite objects 54547c6ae99SBarry Smith 54647c6ae99SBarry Smith Collective on DM 54747c6ae99SBarry Smith 54847c6ae99SBarry Smith Input Parameter: 54947c6ae99SBarry Smith + dm1 - the DM object 55047c6ae99SBarry Smith - dm2 - the second, finer DM object 55147c6ae99SBarry Smith 55247c6ae99SBarry Smith Output Parameter: 55347c6ae99SBarry Smith + mat - the interpolation 55447c6ae99SBarry Smith - vec - the scaling (optional) 55547c6ae99SBarry Smith 55647c6ae99SBarry Smith Level: developer 55747c6ae99SBarry Smith 55885afcc9aSBarry 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 55985afcc9aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the interpolation. 560d52bd9f3SBarry Smith 561d52bd9f3SBarry Smith For DMDA objects you can use this interpolation (more precisely the interpolation from the DMDAGetCoordinateDA()) to interpolate the mesh coordinate vectors 562d52bd9f3SBarry Smith EXCEPT in the periodic case where it does not make sense since the coordinate vectors are not periodic. 56385afcc9aSBarry Smith 56485afcc9aSBarry Smith 565e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMRefine(), DMCoarsen() 56647c6ae99SBarry Smith 56747c6ae99SBarry Smith @*/ 568e727c939SJed Brown PetscErrorCode DMCreateInterpolation(DM dm1,DM dm2,Mat *mat,Vec *vec) 56947c6ae99SBarry Smith { 57047c6ae99SBarry Smith PetscErrorCode ierr; 57147c6ae99SBarry Smith 57247c6ae99SBarry Smith PetscFunctionBegin; 573171400e9SBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 574171400e9SBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 57525296bd5SBarry Smith ierr = (*dm1->ops->createinterpolation)(dm1,dm2,mat,vec);CHKERRQ(ierr); 57647c6ae99SBarry Smith PetscFunctionReturn(0); 57747c6ae99SBarry Smith } 57847c6ae99SBarry Smith 57947c6ae99SBarry Smith #undef __FUNCT__ 580e727c939SJed Brown #define __FUNCT__ "DMCreateInjection" 58147c6ae99SBarry Smith /*@ 582e727c939SJed Brown DMCreateInjection - Gets injection matrix between two DMDA or DMComposite objects 58347c6ae99SBarry Smith 58447c6ae99SBarry Smith Collective on DM 58547c6ae99SBarry Smith 58647c6ae99SBarry Smith Input Parameter: 58747c6ae99SBarry Smith + dm1 - the DM object 58847c6ae99SBarry Smith - dm2 - the second, finer DM object 58947c6ae99SBarry Smith 59047c6ae99SBarry Smith Output Parameter: 59147c6ae99SBarry Smith . ctx - the injection 59247c6ae99SBarry Smith 59347c6ae99SBarry Smith Level: developer 59447c6ae99SBarry Smith 59585afcc9aSBarry 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 59685afcc9aSBarry Smith DMCoarsen(). The coordinates set into the DMDA are completely ignored in computing the injection. 59785afcc9aSBarry Smith 598e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateColoring(), DMCreateMatrix(), DMCreateInterpolation() 59947c6ae99SBarry Smith 60047c6ae99SBarry Smith @*/ 601e727c939SJed Brown PetscErrorCode DMCreateInjection(DM dm1,DM dm2,VecScatter *ctx) 60247c6ae99SBarry Smith { 60347c6ae99SBarry Smith PetscErrorCode ierr; 60447c6ae99SBarry Smith 60547c6ae99SBarry Smith PetscFunctionBegin; 606171400e9SBarry Smith PetscValidHeaderSpecific(dm1,DM_CLASSID,1); 607171400e9SBarry Smith PetscValidHeaderSpecific(dm2,DM_CLASSID,2); 60847c6ae99SBarry Smith ierr = (*dm1->ops->getinjection)(dm1,dm2,ctx);CHKERRQ(ierr); 60947c6ae99SBarry Smith PetscFunctionReturn(0); 61047c6ae99SBarry Smith } 61147c6ae99SBarry Smith 61247c6ae99SBarry Smith #undef __FUNCT__ 613e727c939SJed Brown #define __FUNCT__ "DMCreateColoring" 614d1e2c406SBarry Smith /*@C 615e727c939SJed Brown DMCreateColoring - Gets coloring for a DMDA or DMComposite 61647c6ae99SBarry Smith 61747c6ae99SBarry Smith Collective on DM 61847c6ae99SBarry Smith 61947c6ae99SBarry Smith Input Parameter: 62047c6ae99SBarry Smith + dm - the DM object 62147c6ae99SBarry Smith . ctype - IS_COLORING_GHOSTED or IS_COLORING_GLOBAL 62247c6ae99SBarry Smith - matype - either MATAIJ or MATBAIJ 62347c6ae99SBarry Smith 62447c6ae99SBarry Smith Output Parameter: 62547c6ae99SBarry Smith . coloring - the coloring 62647c6ae99SBarry Smith 62747c6ae99SBarry Smith Level: developer 62847c6ae99SBarry Smith 629e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateMatrix() 63047c6ae99SBarry Smith 631aab9d709SJed Brown @*/ 632e727c939SJed Brown PetscErrorCode DMCreateColoring(DM dm,ISColoringType ctype,const MatType mtype,ISColoring *coloring) 63347c6ae99SBarry Smith { 63447c6ae99SBarry Smith PetscErrorCode ierr; 63547c6ae99SBarry Smith 63647c6ae99SBarry Smith PetscFunctionBegin; 637171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 63847c6ae99SBarry Smith if (!dm->ops->getcoloring) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_SUP,"No coloring for this type of DM yet"); 63947c6ae99SBarry Smith ierr = (*dm->ops->getcoloring)(dm,ctype,mtype,coloring);CHKERRQ(ierr); 64047c6ae99SBarry Smith PetscFunctionReturn(0); 64147c6ae99SBarry Smith } 64247c6ae99SBarry Smith 64347c6ae99SBarry Smith #undef __FUNCT__ 644950540a4SJed Brown #define __FUNCT__ "DMCreateMatrix" 64547c6ae99SBarry Smith /*@C 646950540a4SJed Brown DMCreateMatrix - Gets empty Jacobian for a DMDA or DMComposite 64747c6ae99SBarry Smith 64847c6ae99SBarry Smith Collective on DM 64947c6ae99SBarry Smith 65047c6ae99SBarry Smith Input Parameter: 65147c6ae99SBarry Smith + dm - the DM object 65247c6ae99SBarry Smith - mtype - Supported types are MATSEQAIJ, MATMPIAIJ, MATSEQBAIJ, MATMPIBAIJ, or 65394013140SBarry Smith any type which inherits from one of these (such as MATAIJ) 65447c6ae99SBarry Smith 65547c6ae99SBarry Smith Output Parameter: 65647c6ae99SBarry Smith . mat - the empty Jacobian 65747c6ae99SBarry Smith 658073dac72SJed Brown Level: beginner 65947c6ae99SBarry Smith 66094013140SBarry Smith Notes: This properly preallocates the number of nonzeros in the sparse matrix so you 66194013140SBarry Smith do not need to do it yourself. 66294013140SBarry Smith 66394013140SBarry Smith By default it also sets the nonzero structure and puts in the zero entries. To prevent setting 664aa219208SBarry Smith the nonzero pattern call DMDASetMatPreallocateOnly() 66594013140SBarry Smith 66694013140SBarry 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 66794013140SBarry Smith internally by PETSc. 66894013140SBarry Smith 66994013140SBarry Smith For structured grid problems, in general it is easiest to use MatSetValuesStencil() or MatSetValuesLocal() to put values into the matrix because MatSetValues() requires 670aa219208SBarry Smith the indices for the global numbering for DMDAs which is complicated. 67194013140SBarry Smith 672e727c939SJed Brown .seealso DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 67347c6ae99SBarry Smith 674aab9d709SJed Brown @*/ 675950540a4SJed Brown PetscErrorCode DMCreateMatrix(DM dm,const MatType mtype,Mat *mat) 67647c6ae99SBarry Smith { 67747c6ae99SBarry Smith PetscErrorCode ierr; 67847c6ae99SBarry Smith 67947c6ae99SBarry Smith PetscFunctionBegin; 680171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 681235683edSBarry Smith #ifndef PETSC_USE_DYNAMIC_LIBRARIES 682235683edSBarry Smith ierr = MatInitializePackage(PETSC_NULL);CHKERRQ(ierr); 683235683edSBarry Smith #endif 684c7b7c8a4SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 685c7b7c8a4SJed Brown PetscValidPointer(mat,3); 686073dac72SJed Brown if (dm->mattype) { 68725296bd5SBarry Smith ierr = (*dm->ops->creatematrix)(dm,dm->mattype,mat);CHKERRQ(ierr); 688073dac72SJed Brown } else { 68925296bd5SBarry Smith ierr = (*dm->ops->creatematrix)(dm,mtype,mat);CHKERRQ(ierr); 690c7b7c8a4SJed Brown } 69147c6ae99SBarry Smith PetscFunctionReturn(0); 69247c6ae99SBarry Smith } 69347c6ae99SBarry Smith 69447c6ae99SBarry Smith #undef __FUNCT__ 695732e2eb9SMatthew G Knepley #define __FUNCT__ "DMSetMatrixPreallocateOnly" 696732e2eb9SMatthew G Knepley /*@ 697950540a4SJed Brown DMSetMatrixPreallocateOnly - When DMCreateMatrix() is called the matrix will be properly 698732e2eb9SMatthew G Knepley preallocated but the nonzero structure and zero values will not be set. 699732e2eb9SMatthew G Knepley 700732e2eb9SMatthew G Knepley Logically Collective on DMDA 701732e2eb9SMatthew G Knepley 702732e2eb9SMatthew G Knepley Input Parameter: 703732e2eb9SMatthew G Knepley + dm - the DM 704732e2eb9SMatthew G Knepley - only - PETSC_TRUE if only want preallocation 705732e2eb9SMatthew G Knepley 706732e2eb9SMatthew G Knepley Level: developer 707950540a4SJed Brown .seealso DMCreateMatrix() 708732e2eb9SMatthew G Knepley @*/ 709732e2eb9SMatthew G Knepley PetscErrorCode DMSetMatrixPreallocateOnly(DM dm, PetscBool only) 710732e2eb9SMatthew G Knepley { 711732e2eb9SMatthew G Knepley PetscFunctionBegin; 712732e2eb9SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 713732e2eb9SMatthew G Knepley dm->prealloc_only = only; 714732e2eb9SMatthew G Knepley PetscFunctionReturn(0); 715732e2eb9SMatthew G Knepley } 716732e2eb9SMatthew G Knepley 717732e2eb9SMatthew G Knepley #undef __FUNCT__ 718a89ea682SMatthew G Knepley #define __FUNCT__ "DMGetWorkArray" 719a89ea682SMatthew G Knepley /*@C 720a89ea682SMatthew G Knepley DMGetWorkArray - Gets a work array guaranteed to be at least the input size 721a89ea682SMatthew G Knepley 722a89ea682SMatthew G Knepley Not Collective 723a89ea682SMatthew G Knepley 724a89ea682SMatthew G Knepley Input Parameters: 725a89ea682SMatthew G Knepley + dm - the DM object 726a89ea682SMatthew G Knepley - size - The minium size 727a89ea682SMatthew G Knepley 728a89ea682SMatthew G Knepley Output Parameter: 729a89ea682SMatthew G Knepley . array - the work array 730a89ea682SMatthew G Knepley 731a89ea682SMatthew G Knepley Level: developer 732a89ea682SMatthew G Knepley 733a89ea682SMatthew G Knepley .seealso DMDestroy(), DMCreate() 734a89ea682SMatthew G Knepley @*/ 735a89ea682SMatthew G Knepley PetscErrorCode DMGetWorkArray(DM dm,PetscInt size,PetscScalar **array) 736a89ea682SMatthew G Knepley { 737a89ea682SMatthew G Knepley PetscErrorCode ierr; 738a89ea682SMatthew G Knepley 739a89ea682SMatthew G Knepley PetscFunctionBegin; 740a89ea682SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 741a89ea682SMatthew G Knepley PetscValidPointer(array,3); 742a89ea682SMatthew G Knepley if (size > dm->workSize) { 743a89ea682SMatthew G Knepley dm->workSize = size; 744a89ea682SMatthew G Knepley ierr = PetscFree(dm->workArray);CHKERRQ(ierr); 745a89ea682SMatthew G Knepley ierr = PetscMalloc(dm->workSize * sizeof(PetscScalar), &dm->workArray);CHKERRQ(ierr); 746a89ea682SMatthew G Knepley } 747a89ea682SMatthew G Knepley *array = dm->workArray; 748a89ea682SMatthew G Knepley PetscFunctionReturn(0); 749a89ea682SMatthew G Knepley } 750a89ea682SMatthew G Knepley 7514d343eeaSMatthew G Knepley #undef __FUNCT__ 752e7c4fc90SDmitry Karpeev #define __FUNCT__ "DMCreateDecompositionDM" 753e7c4fc90SDmitry Karpeev /*@C 75401bc414fSDmitry Karpeev DMCreateDecompositionDM - creates a DM that encapsulates a decomposition of the original DM. 755e7c4fc90SDmitry Karpeev 756e7c4fc90SDmitry Karpeev Not Collective 757e7c4fc90SDmitry Karpeev 758e7c4fc90SDmitry Karpeev Input Parameters: 759e7c4fc90SDmitry Karpeev + dm - the DM object 760e7c4fc90SDmitry Karpeev - name - the name of the decomposition 761e7c4fc90SDmitry Karpeev 762e7c4fc90SDmitry Karpeev Output Parameter: 763e7c4fc90SDmitry Karpeev . ddm - the decomposition DM (PETSC_NULL, if no such decomposition is known) 764e7c4fc90SDmitry Karpeev 765e7c4fc90SDmitry Karpeev Level: advanced 766e7c4fc90SDmitry Karpeev 767e7c4fc90SDmitry Karpeev .seealso DMDestroy(), DMCreate(), DMCreateDecomposition() 768e7c4fc90SDmitry Karpeev @*/ 769e7c4fc90SDmitry Karpeev PetscErrorCode DMCreateDecompositionDM(DM dm, const char* name, DM *ddm) 770e7c4fc90SDmitry Karpeev { 771e7c4fc90SDmitry Karpeev PetscErrorCode ierr; 772e7c4fc90SDmitry Karpeev 773e7c4fc90SDmitry Karpeev PetscFunctionBegin; 774e7c4fc90SDmitry Karpeev PetscValidHeaderSpecific(dm,DM_CLASSID,1); 775e7c4fc90SDmitry Karpeev PetscValidCharPointer(name,2); 776e7c4fc90SDmitry Karpeev PetscValidPointer(ddm,3); 777e7c4fc90SDmitry Karpeev if(!dm->ops->createdecompositiondm) { 778e7c4fc90SDmitry Karpeev *ddm = PETSC_NULL; 779e7c4fc90SDmitry Karpeev } 780e7c4fc90SDmitry Karpeev else { 781e7c4fc90SDmitry Karpeev ierr = (*dm->ops->createdecompositiondm)(dm,name,ddm); CHKERRQ(ierr); 782e7c4fc90SDmitry Karpeev } 783e7c4fc90SDmitry Karpeev PetscFunctionReturn(0); 784e7c4fc90SDmitry Karpeev } 785e7c4fc90SDmitry Karpeev 786e7c4fc90SDmitry Karpeev #undef __FUNCT__ 7874d343eeaSMatthew G Knepley #define __FUNCT__ "DMCreateFieldIS" 7884f3b5142SJed Brown /*@C 7894d343eeaSMatthew G Knepley DMCreateFieldIS - Creates a set of IS objects with the global indices of dofs for each field 7904d343eeaSMatthew G Knepley 7914d343eeaSMatthew G Knepley Not collective 7924d343eeaSMatthew G Knepley 7934d343eeaSMatthew G Knepley Input Parameter: 7944d343eeaSMatthew G Knepley . dm - the DM object 7954d343eeaSMatthew G Knepley 7964d343eeaSMatthew G Knepley Output Parameters: 79721c9b008SJed Brown + numFields - The number of fields (or PETSC_NULL if not requested) 79821c9b008SJed Brown . names - The name for each field (or PETSC_NULL if not requested) 79921c9b008SJed Brown - fields - The global indices for each field (or PETSC_NULL if not requested) 8004d343eeaSMatthew G Knepley 8014d343eeaSMatthew G Knepley Level: intermediate 8024d343eeaSMatthew G Knepley 80321c9b008SJed Brown Notes: 80421c9b008SJed Brown The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 80521c9b008SJed Brown PetscFree(), every entry of fields should be destroyed with ISDestroy(), and both arrays should be freed with 80621c9b008SJed Brown PetscFree(). 80721c9b008SJed Brown 8084d343eeaSMatthew G Knepley .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix() 8094d343eeaSMatthew G Knepley @*/ 81021c9b008SJed Brown PetscErrorCode DMCreateFieldIS(DM dm, PetscInt *numFields, char ***names, IS **fields) 8114d343eeaSMatthew G Knepley { 8124d343eeaSMatthew G Knepley PetscErrorCode ierr; 8134d343eeaSMatthew G Knepley 8144d343eeaSMatthew G Knepley PetscFunctionBegin; 8154d343eeaSMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 81669ca1f37SDmitry Karpeev if (numFields) { 81769ca1f37SDmitry Karpeev PetscValidPointer(numFields,2); 81869ca1f37SDmitry Karpeev *numFields = 0; 81969ca1f37SDmitry Karpeev } 82069ca1f37SDmitry Karpeev if (names) { 82169ca1f37SDmitry Karpeev PetscValidPointer(names,3); 82269ca1f37SDmitry Karpeev *names = PETSC_NULL; 82369ca1f37SDmitry Karpeev } 82469ca1f37SDmitry Karpeev if (fields) { 82569ca1f37SDmitry Karpeev PetscValidPointer(fields,4); 82669ca1f37SDmitry Karpeev *fields = PETSC_NULL; 82769ca1f37SDmitry Karpeev } 82869ca1f37SDmitry Karpeev if(dm->ops->createfieldis) { 8294d343eeaSMatthew G Knepley ierr = (*dm->ops->createfieldis)(dm, numFields, names, fields);CHKERRQ(ierr); 83069ca1f37SDmitry Karpeev } 8314d343eeaSMatthew G Knepley PetscFunctionReturn(0); 8324d343eeaSMatthew G Knepley } 8334d343eeaSMatthew G Knepley 8345fe1f584SPeter Brune 835a89ea682SMatthew G Knepley #undef __FUNCT__ 836e7c4fc90SDmitry Karpeev #define __FUNCT__ "DMCreateDecomposition" 837e7c4fc90SDmitry Karpeev /*@C 838e7c4fc90SDmitry Karpeev DMCreateDecomposition - Returns a list of IS objects defining a decomposition of a problem into subproblems: 839e7c4fc90SDmitry Karpeev each IS contains the global indices of the dofs of the corresponding subproblem. 840e7c4fc90SDmitry Karpeev The optional list of DMs define the DM for each subproblem. 841e7c4fc90SDmitry Karpeev Generalizes DMCreateFieldIS(). 842e7c4fc90SDmitry Karpeev 843e7c4fc90SDmitry Karpeev Not collective 844e7c4fc90SDmitry Karpeev 845e7c4fc90SDmitry Karpeev Input Parameter: 846e7c4fc90SDmitry Karpeev . dm - the DM object 847e7c4fc90SDmitry Karpeev 848e7c4fc90SDmitry Karpeev Output Parameters: 849e7c4fc90SDmitry Karpeev + len - The number of subproblems in the decomposition (or PETSC_NULL if not requested) 850e7c4fc90SDmitry Karpeev . namelist - The name for each subproblem (or PETSC_NULL if not requested) 851e7c4fc90SDmitry Karpeev . islist - The global indices for each subproblem (or PETSC_NULL if not requested) 852e7c4fc90SDmitry Karpeev - dmlist - The DMs for each subproblem (or PETSC_NULL, if not requested; if PETSC_NULL is returned, no DMs are defined) 853e7c4fc90SDmitry Karpeev 854e7c4fc90SDmitry Karpeev Level: intermediate 855e7c4fc90SDmitry Karpeev 856e7c4fc90SDmitry Karpeev Notes: 857e7c4fc90SDmitry Karpeev The user is responsible for freeing all requested arrays. In particular, every entry of names should be freed with 858e7c4fc90SDmitry Karpeev PetscFree(), every entry of is should be destroyed with ISDestroy(), every entry of dm should be destroyed with DMDestroy(), 859e7c4fc90SDmitry Karpeev and all of the arrays should be freed with PetscFree(). 860e7c4fc90SDmitry Karpeev 861e7c4fc90SDmitry Karpeev .seealso DMDestroy(), DMView(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMCreateFieldIS() 862e7c4fc90SDmitry Karpeev @*/ 863e7c4fc90SDmitry Karpeev PetscErrorCode DMCreateDecomposition(DM dm, PetscInt *len, char ***namelist, IS **islist, DM **dmlist) 864e7c4fc90SDmitry Karpeev { 865e7c4fc90SDmitry Karpeev PetscErrorCode ierr; 866e7c4fc90SDmitry Karpeev 867e7c4fc90SDmitry Karpeev PetscFunctionBegin; 868e7c4fc90SDmitry Karpeev PetscValidHeaderSpecific(dm,DM_CLASSID,1); 869e7c4fc90SDmitry Karpeev if (len) {PetscValidPointer(len,2);} 870e7c4fc90SDmitry Karpeev if (namelist) {PetscValidPointer(namelist,3);} 871e7c4fc90SDmitry Karpeev if (islist) {PetscValidPointer(islist,4);} 872e7c4fc90SDmitry Karpeev if (dmlist) {PetscValidPointer(dmlist,5);} 873e7c4fc90SDmitry Karpeev if(!dm->ops->createdecomposition) { 87469ca1f37SDmitry Karpeev ierr = DMCreateFieldIS(dm, len, namelist, islist);CHKERRQ(ierr); 875e7c4fc90SDmitry Karpeev /* By default there are no DMs associated with subproblems. */ 876e7c4fc90SDmitry Karpeev if(dmlist) *dmlist = PETSC_NULL; 877e7c4fc90SDmitry Karpeev } 878e7c4fc90SDmitry Karpeev else { 879e7c4fc90SDmitry Karpeev ierr = (*dm->ops->createdecomposition)(dm,len,namelist,islist,dmlist); CHKERRQ(ierr); 880e7c4fc90SDmitry Karpeev } 881e7c4fc90SDmitry Karpeev PetscFunctionReturn(0); 882e7c4fc90SDmitry Karpeev } 883e7c4fc90SDmitry Karpeev 884e7c4fc90SDmitry Karpeev 885e7c4fc90SDmitry Karpeev #undef __FUNCT__ 88647c6ae99SBarry Smith #define __FUNCT__ "DMRefine" 88747c6ae99SBarry Smith /*@ 88847c6ae99SBarry Smith DMRefine - Refines a DM object 88947c6ae99SBarry Smith 89047c6ae99SBarry Smith Collective on DM 89147c6ae99SBarry Smith 89247c6ae99SBarry Smith Input Parameter: 89347c6ae99SBarry Smith + dm - the DM object 89491d95f02SJed Brown - comm - the communicator to contain the new DM object (or MPI_COMM_NULL) 89547c6ae99SBarry Smith 89647c6ae99SBarry Smith Output Parameter: 897ae0a1c52SMatthew G Knepley . dmf - the refined DM, or PETSC_NULL 898ae0a1c52SMatthew G Knepley 899ae0a1c52SMatthew G Knepley Note: If no refinement was done, the return value is PETSC_NULL 90047c6ae99SBarry Smith 90147c6ae99SBarry Smith Level: developer 90247c6ae99SBarry Smith 903e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 90447c6ae99SBarry Smith @*/ 9057087cfbeSBarry Smith PetscErrorCode DMRefine(DM dm,MPI_Comm comm,DM *dmf) 90647c6ae99SBarry Smith { 90747c6ae99SBarry Smith PetscErrorCode ierr; 90847c6ae99SBarry Smith 90947c6ae99SBarry Smith PetscFunctionBegin; 910732e2eb9SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 91147c6ae99SBarry Smith ierr = (*dm->ops->refine)(dm,comm,dmf);CHKERRQ(ierr); 9124057135bSMatthew G Knepley if (*dmf) { 91343842a1eSJed Brown (*dmf)->ops->creatematrix = dm->ops->creatematrix; 914644e2e5bSBarry Smith (*dmf)->ops->initialguess = dm->ops->initialguess; 915644e2e5bSBarry Smith (*dmf)->ops->function = dm->ops->function; 916644e2e5bSBarry Smith (*dmf)->ops->functionj = dm->ops->functionj; 917644e2e5bSBarry Smith if (dm->ops->jacobian != DMComputeJacobianDefault) { 918644e2e5bSBarry Smith (*dmf)->ops->jacobian = dm->ops->jacobian; 919644e2e5bSBarry Smith } 9208cd211a4SJed Brown ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)*dmf);CHKERRQ(ierr); 921644e2e5bSBarry Smith (*dmf)->ctx = dm->ctx; 922656b349aSBarry Smith (*dmf)->levelup = dm->levelup + 1; 9234057135bSMatthew G Knepley } 92447c6ae99SBarry Smith PetscFunctionReturn(0); 92547c6ae99SBarry Smith } 92647c6ae99SBarry Smith 92747c6ae99SBarry Smith #undef __FUNCT__ 928eb3f98d2SBarry Smith #define __FUNCT__ "DMGetRefineLevel" 929eb3f98d2SBarry Smith /*@ 930eb3f98d2SBarry Smith DMGetRefineLevel - Get's the number of refinements that have generated this DM. 931eb3f98d2SBarry Smith 932eb3f98d2SBarry Smith Not Collective 933eb3f98d2SBarry Smith 934eb3f98d2SBarry Smith Input Parameter: 935eb3f98d2SBarry Smith . dm - the DM object 936eb3f98d2SBarry Smith 937eb3f98d2SBarry Smith Output Parameter: 938eb3f98d2SBarry Smith . level - number of refinements 939eb3f98d2SBarry Smith 940eb3f98d2SBarry Smith Level: developer 941eb3f98d2SBarry Smith 9426a7d9d85SPeter Brune .seealso DMCoarsen(), DMGetCoarsenLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 943eb3f98d2SBarry Smith 944eb3f98d2SBarry Smith @*/ 945eb3f98d2SBarry Smith PetscErrorCode DMGetRefineLevel(DM dm,PetscInt *level) 946eb3f98d2SBarry Smith { 947eb3f98d2SBarry Smith PetscFunctionBegin; 948eb3f98d2SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 949eb3f98d2SBarry Smith *level = dm->levelup; 950eb3f98d2SBarry Smith PetscFunctionReturn(0); 951eb3f98d2SBarry Smith } 952eb3f98d2SBarry Smith 953eb3f98d2SBarry Smith #undef __FUNCT__ 95447c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalBegin" 95547c6ae99SBarry Smith /*@ 95647c6ae99SBarry Smith DMGlobalToLocalBegin - Begins updating local vectors from global vector 95747c6ae99SBarry Smith 95847c6ae99SBarry Smith Neighbor-wise Collective on DM 95947c6ae99SBarry Smith 96047c6ae99SBarry Smith Input Parameters: 96147c6ae99SBarry Smith + dm - the DM object 96247c6ae99SBarry Smith . g - the global vector 96347c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 96447c6ae99SBarry Smith - l - the local vector 96547c6ae99SBarry Smith 96647c6ae99SBarry Smith 96747c6ae99SBarry Smith Level: beginner 96847c6ae99SBarry Smith 969e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 97047c6ae99SBarry Smith 97147c6ae99SBarry Smith @*/ 9727087cfbeSBarry Smith PetscErrorCode DMGlobalToLocalBegin(DM dm,Vec g,InsertMode mode,Vec l) 97347c6ae99SBarry Smith { 97447c6ae99SBarry Smith PetscErrorCode ierr; 97547c6ae99SBarry Smith 97647c6ae99SBarry Smith PetscFunctionBegin; 977171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 978843c4018SMatthew G Knepley ierr = (*dm->ops->globaltolocalbegin)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 97947c6ae99SBarry Smith PetscFunctionReturn(0); 98047c6ae99SBarry Smith } 98147c6ae99SBarry Smith 98247c6ae99SBarry Smith #undef __FUNCT__ 98347c6ae99SBarry Smith #define __FUNCT__ "DMGlobalToLocalEnd" 98447c6ae99SBarry Smith /*@ 98547c6ae99SBarry Smith DMGlobalToLocalEnd - Ends updating local vectors from global vector 98647c6ae99SBarry Smith 98747c6ae99SBarry Smith Neighbor-wise Collective on DM 98847c6ae99SBarry Smith 98947c6ae99SBarry Smith Input Parameters: 99047c6ae99SBarry Smith + dm - the DM object 99147c6ae99SBarry Smith . g - the global vector 99247c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 99347c6ae99SBarry Smith - l - the local vector 99447c6ae99SBarry Smith 99547c6ae99SBarry Smith 99647c6ae99SBarry Smith Level: beginner 99747c6ae99SBarry Smith 998e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMLocalToGlobalBegin() 99947c6ae99SBarry Smith 100047c6ae99SBarry Smith @*/ 10017087cfbeSBarry Smith PetscErrorCode DMGlobalToLocalEnd(DM dm,Vec g,InsertMode mode,Vec l) 100247c6ae99SBarry Smith { 100347c6ae99SBarry Smith PetscErrorCode ierr; 100447c6ae99SBarry Smith 100547c6ae99SBarry Smith PetscFunctionBegin; 1006171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1007843c4018SMatthew G Knepley ierr = (*dm->ops->globaltolocalend)(dm,g,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),l);CHKERRQ(ierr); 100847c6ae99SBarry Smith PetscFunctionReturn(0); 100947c6ae99SBarry Smith } 101047c6ae99SBarry Smith 101147c6ae99SBarry Smith #undef __FUNCT__ 10129a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalBegin" 101347c6ae99SBarry Smith /*@ 10149a42bb27SBarry Smith DMLocalToGlobalBegin - updates global vectors from local vectors 10159a42bb27SBarry Smith 10169a42bb27SBarry Smith Neighbor-wise Collective on DM 10179a42bb27SBarry Smith 10189a42bb27SBarry Smith Input Parameters: 10199a42bb27SBarry Smith + dm - the DM object 1020f6813fd5SJed Brown . l - the local vector 10219a42bb27SBarry 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 10229a42bb27SBarry Smith base point. 1023f6813fd5SJed Brown - - the global vector 10249a42bb27SBarry Smith 10259a42bb27SBarry 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 10269a42bb27SBarry 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 10279a42bb27SBarry Smith global array to the final global array with VecAXPY(). 10289a42bb27SBarry Smith 10299a42bb27SBarry Smith Level: beginner 10309a42bb27SBarry Smith 1031e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalBegin() 10329a42bb27SBarry Smith 10339a42bb27SBarry Smith @*/ 10347087cfbeSBarry Smith PetscErrorCode DMLocalToGlobalBegin(DM dm,Vec l,InsertMode mode,Vec g) 10359a42bb27SBarry Smith { 10369a42bb27SBarry Smith PetscErrorCode ierr; 10379a42bb27SBarry Smith 10389a42bb27SBarry Smith PetscFunctionBegin; 1039171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1040843c4018SMatthew G Knepley ierr = (*dm->ops->localtoglobalbegin)(dm,l,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),g);CHKERRQ(ierr); 10419a42bb27SBarry Smith PetscFunctionReturn(0); 10429a42bb27SBarry Smith } 10439a42bb27SBarry Smith 10449a42bb27SBarry Smith #undef __FUNCT__ 10459a42bb27SBarry Smith #define __FUNCT__ "DMLocalToGlobalEnd" 10469a42bb27SBarry Smith /*@ 10479a42bb27SBarry Smith DMLocalToGlobalEnd - updates global vectors from local vectors 104847c6ae99SBarry Smith 104947c6ae99SBarry Smith Neighbor-wise Collective on DM 105047c6ae99SBarry Smith 105147c6ae99SBarry Smith Input Parameters: 105247c6ae99SBarry Smith + dm - the DM object 1053f6813fd5SJed Brown . l - the local vector 105447c6ae99SBarry Smith . mode - INSERT_VALUES or ADD_VALUES 1055f6813fd5SJed Brown - g - the global vector 105647c6ae99SBarry Smith 105747c6ae99SBarry Smith 105847c6ae99SBarry Smith Level: beginner 105947c6ae99SBarry Smith 1060e727c939SJed Brown .seealso DMCoarsen(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMGlobalToLocalEnd(), DMGlobalToLocalEnd() 106147c6ae99SBarry Smith 106247c6ae99SBarry Smith @*/ 10637087cfbeSBarry Smith PetscErrorCode DMLocalToGlobalEnd(DM dm,Vec l,InsertMode mode,Vec g) 106447c6ae99SBarry Smith { 106547c6ae99SBarry Smith PetscErrorCode ierr; 106647c6ae99SBarry Smith 106747c6ae99SBarry Smith PetscFunctionBegin; 1068171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 1069843c4018SMatthew G Knepley ierr = (*dm->ops->localtoglobalend)(dm,l,mode == INSERT_ALL_VALUES ? INSERT_VALUES : (mode == ADD_ALL_VALUES ? ADD_VALUES : mode),g);CHKERRQ(ierr); 107047c6ae99SBarry Smith PetscFunctionReturn(0); 107147c6ae99SBarry Smith } 107247c6ae99SBarry Smith 107347c6ae99SBarry Smith #undef __FUNCT__ 107447c6ae99SBarry Smith #define __FUNCT__ "DMComputeJacobianDefault" 107547c6ae99SBarry Smith /*@ 107647c6ae99SBarry Smith DMComputeJacobianDefault - computes the Jacobian using the DMComputeFunction() if Jacobian computer is not provided 107747c6ae99SBarry Smith 107847c6ae99SBarry Smith Collective on DM 107947c6ae99SBarry Smith 108047c6ae99SBarry Smith Input Parameter: 108147c6ae99SBarry Smith + dm - the DM object 108247c6ae99SBarry Smith . x - location to compute Jacobian at; may be ignored for linear problems 108347c6ae99SBarry Smith . A - matrix that defines the operator for the linear solve 108447c6ae99SBarry Smith - B - the matrix used to construct the preconditioner 108547c6ae99SBarry Smith 108647c6ae99SBarry Smith Level: developer 108747c6ae99SBarry Smith 1088e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetInitialGuess(), 108947c6ae99SBarry Smith DMSetFunction() 109047c6ae99SBarry Smith 109147c6ae99SBarry Smith @*/ 10927087cfbeSBarry Smith PetscErrorCode DMComputeJacobianDefault(DM dm,Vec x,Mat A,Mat B,MatStructure *stflag) 109347c6ae99SBarry Smith { 109447c6ae99SBarry Smith PetscErrorCode ierr; 1095171400e9SBarry Smith 109647c6ae99SBarry Smith PetscFunctionBegin; 1097171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 109847c6ae99SBarry Smith *stflag = SAME_NONZERO_PATTERN; 109947c6ae99SBarry Smith ierr = MatFDColoringApply(B,dm->fd,x,stflag,dm);CHKERRQ(ierr); 110047c6ae99SBarry Smith if (A != B) { 110147c6ae99SBarry Smith ierr = MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 110247c6ae99SBarry Smith ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 110347c6ae99SBarry Smith } 110447c6ae99SBarry Smith PetscFunctionReturn(0); 110547c6ae99SBarry Smith } 110647c6ae99SBarry Smith 110747c6ae99SBarry Smith #undef __FUNCT__ 110847c6ae99SBarry Smith #define __FUNCT__ "DMCoarsen" 110947c6ae99SBarry Smith /*@ 111047c6ae99SBarry Smith DMCoarsen - Coarsens a DM object 111147c6ae99SBarry Smith 111247c6ae99SBarry Smith Collective on DM 111347c6ae99SBarry Smith 111447c6ae99SBarry Smith Input Parameter: 111547c6ae99SBarry Smith + dm - the DM object 111691d95f02SJed Brown - comm - the communicator to contain the new DM object (or MPI_COMM_NULL) 111747c6ae99SBarry Smith 111847c6ae99SBarry Smith Output Parameter: 111947c6ae99SBarry Smith . dmc - the coarsened DM 112047c6ae99SBarry Smith 112147c6ae99SBarry Smith Level: developer 112247c6ae99SBarry Smith 1123e727c939SJed Brown .seealso DMRefine(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 112447c6ae99SBarry Smith 112547c6ae99SBarry Smith @*/ 11267087cfbeSBarry Smith PetscErrorCode DMCoarsen(DM dm, MPI_Comm comm, DM *dmc) 112747c6ae99SBarry Smith { 112847c6ae99SBarry Smith PetscErrorCode ierr; 1129b17ce1afSJed Brown DMCoarsenHookLink link; 113047c6ae99SBarry Smith 113147c6ae99SBarry Smith PetscFunctionBegin; 1132171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 113347c6ae99SBarry Smith ierr = (*dm->ops->coarsen)(dm, comm, dmc);CHKERRQ(ierr); 113443842a1eSJed Brown (*dmc)->ops->creatematrix = dm->ops->creatematrix; 113547c6ae99SBarry Smith (*dmc)->ops->initialguess = dm->ops->initialguess; 113647c6ae99SBarry Smith (*dmc)->ops->function = dm->ops->function; 113747c6ae99SBarry Smith (*dmc)->ops->functionj = dm->ops->functionj; 113847c6ae99SBarry Smith if (dm->ops->jacobian != DMComputeJacobianDefault) { 113947c6ae99SBarry Smith (*dmc)->ops->jacobian = dm->ops->jacobian; 114047c6ae99SBarry Smith } 11418cd211a4SJed Brown ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)dm,(PetscObject)*dmc);CHKERRQ(ierr); 1142644e2e5bSBarry Smith (*dmc)->ctx = dm->ctx; 1143656b349aSBarry Smith (*dmc)->leveldown = dm->leveldown + 1; 1144b17ce1afSJed Brown for (link=dm->coarsenhook; link; link=link->next) { 1145b17ce1afSJed Brown if (link->coarsenhook) {ierr = (*link->coarsenhook)(dm,*dmc,link->ctx);CHKERRQ(ierr);} 1146b17ce1afSJed Brown } 1147b17ce1afSJed Brown PetscFunctionReturn(0); 1148b17ce1afSJed Brown } 1149b17ce1afSJed Brown 1150b17ce1afSJed Brown #undef __FUNCT__ 1151b17ce1afSJed Brown #define __FUNCT__ "DMCoarsenHookAdd" 1152b17ce1afSJed Brown /*@ 1153b17ce1afSJed Brown DMCoarsenHookAdd - adds a callback to be run when restricting a nonlinear problem to the coarse grid 1154b17ce1afSJed Brown 1155b17ce1afSJed Brown Logically Collective 1156b17ce1afSJed Brown 1157b17ce1afSJed Brown Input Arguments: 1158b17ce1afSJed Brown + fine - nonlinear solver context on which to run a hook when restricting to a coarser level 1159b17ce1afSJed Brown . coarsenhook - function to run when setting up a coarser level 1160b17ce1afSJed Brown . restricthook - function to run to update data on coarser levels (once per SNESSolve()) 1161b17ce1afSJed Brown - ctx - [optional] user-defined context for provide data for the hooks (may be PETSC_NULL) 1162b17ce1afSJed Brown 1163b17ce1afSJed Brown Calling sequence of coarsenhook: 1164b17ce1afSJed Brown $ coarsenhook(DM fine,DM coarse,void *ctx); 1165b17ce1afSJed Brown 1166b17ce1afSJed Brown + fine - fine level DM 1167b17ce1afSJed Brown . coarse - coarse level DM to restrict problem to 1168b17ce1afSJed Brown - ctx - optional user-defined function context 1169b17ce1afSJed Brown 1170b17ce1afSJed Brown Calling sequence for restricthook: 1171b17ce1afSJed Brown $ restricthook(DM fine,Mat mrestrict,Mat inject,DM coarse,void *ctx) 1172b17ce1afSJed Brown 1173b17ce1afSJed Brown + fine - fine level DM 1174b17ce1afSJed Brown . mrestrict - matrix restricting a fine-level solution to the coarse grid 1175b17ce1afSJed Brown . inject - matrix restricting by applying the transpose of injection 1176b17ce1afSJed Brown . coarse - coarse level DM to update 1177b17ce1afSJed Brown - ctx - optional user-defined function context 1178b17ce1afSJed Brown 1179b17ce1afSJed Brown Level: advanced 1180b17ce1afSJed Brown 1181b17ce1afSJed Brown Notes: 1182b17ce1afSJed Brown This function is only needed if auxiliary data needs to be set up on coarse grids. 1183b17ce1afSJed Brown 1184b17ce1afSJed Brown If this function is called multiple times, the hooks will be run in the order they are added. 1185b17ce1afSJed Brown 1186b17ce1afSJed Brown In order to compose with nonlinear preconditioning without duplicating storage, the hook should be implemented to 1187b17ce1afSJed Brown extract the finest level information from its context (instead of from the SNES). 1188b17ce1afSJed Brown 1189b17ce1afSJed Brown .seealso: SNESFASGetInterpolation(), SNESFASGetInjection(), PetscObjectCompose(), PetscContainerCreate() 1190b17ce1afSJed Brown @*/ 1191b17ce1afSJed Brown PetscErrorCode DMCoarsenHookAdd(DM fine,PetscErrorCode (*coarsenhook)(DM,DM,void*),PetscErrorCode (*restricthook)(DM,Mat,Vec,Mat,DM,void*),void *ctx) 1192b17ce1afSJed Brown { 1193b17ce1afSJed Brown PetscErrorCode ierr; 1194b17ce1afSJed Brown DMCoarsenHookLink link,*p; 1195b17ce1afSJed Brown 1196b17ce1afSJed Brown PetscFunctionBegin; 1197b17ce1afSJed Brown PetscValidHeaderSpecific(fine,DM_CLASSID,1); 11986bfea28cSJed Brown for (p=&fine->coarsenhook; *p; p=&(*p)->next) {} /* Scan to the end of the current list of hooks */ 1199b17ce1afSJed Brown ierr = PetscMalloc(sizeof(struct _DMCoarsenHookLink),&link);CHKERRQ(ierr); 1200b17ce1afSJed Brown link->coarsenhook = coarsenhook; 1201b17ce1afSJed Brown link->restricthook = restricthook; 1202b17ce1afSJed Brown link->ctx = ctx; 12036cab3a1bSJed Brown link->next = PETSC_NULL; 1204b17ce1afSJed Brown *p = link; 1205b17ce1afSJed Brown PetscFunctionReturn(0); 1206b17ce1afSJed Brown } 1207b17ce1afSJed Brown 1208b17ce1afSJed Brown #undef __FUNCT__ 1209b17ce1afSJed Brown #define __FUNCT__ "DMRestrict" 1210b17ce1afSJed Brown /*@ 1211b17ce1afSJed Brown DMRestrict - restricts user-defined problem data to a coarser DM by running hooks registered by DMCoarsenHookAdd() 1212b17ce1afSJed Brown 1213b17ce1afSJed Brown Collective if any hooks are 1214b17ce1afSJed Brown 1215b17ce1afSJed Brown Input Arguments: 1216b17ce1afSJed Brown + fine - finer DM to use as a base 1217b17ce1afSJed Brown . restrct - restriction matrix, apply using MatRestrict() 1218b17ce1afSJed Brown . inject - injection matrix, also use MatRestrict() 1219b17ce1afSJed Brown - coarse - coarer DM to update 1220b17ce1afSJed Brown 1221b17ce1afSJed Brown Level: developer 1222b17ce1afSJed Brown 1223b17ce1afSJed Brown .seealso: DMCoarsenHookAdd(), MatRestrict() 1224b17ce1afSJed Brown @*/ 1225b17ce1afSJed Brown PetscErrorCode DMRestrict(DM fine,Mat restrct,Vec rscale,Mat inject,DM coarse) 1226b17ce1afSJed Brown { 1227b17ce1afSJed Brown PetscErrorCode ierr; 1228b17ce1afSJed Brown DMCoarsenHookLink link; 1229b17ce1afSJed Brown 1230b17ce1afSJed Brown PetscFunctionBegin; 1231b17ce1afSJed Brown for (link=fine->coarsenhook; link; link=link->next) { 1232b17ce1afSJed Brown if (link->restricthook) {ierr = (*link->restricthook)(fine,restrct,rscale,inject,coarse,link->ctx);CHKERRQ(ierr);} 1233b17ce1afSJed Brown } 123447c6ae99SBarry Smith PetscFunctionReturn(0); 123547c6ae99SBarry Smith } 123647c6ae99SBarry Smith 123747c6ae99SBarry Smith #undef __FUNCT__ 12385fe1f584SPeter Brune #define __FUNCT__ "DMGetCoarsenLevel" 12395fe1f584SPeter Brune /*@ 12406a7d9d85SPeter Brune DMGetCoarsenLevel - Get's the number of coarsenings that have generated this DM. 12415fe1f584SPeter Brune 12425fe1f584SPeter Brune Not Collective 12435fe1f584SPeter Brune 12445fe1f584SPeter Brune Input Parameter: 12455fe1f584SPeter Brune . dm - the DM object 12465fe1f584SPeter Brune 12475fe1f584SPeter Brune Output Parameter: 12486a7d9d85SPeter Brune . level - number of coarsenings 12495fe1f584SPeter Brune 12505fe1f584SPeter Brune Level: developer 12515fe1f584SPeter Brune 12526a7d9d85SPeter Brune .seealso DMCoarsen(), DMGetRefineLevel(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 12535fe1f584SPeter Brune 12545fe1f584SPeter Brune @*/ 12555fe1f584SPeter Brune PetscErrorCode DMGetCoarsenLevel(DM dm,PetscInt *level) 12565fe1f584SPeter Brune { 12575fe1f584SPeter Brune PetscFunctionBegin; 12585fe1f584SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 12595fe1f584SPeter Brune *level = dm->leveldown; 12605fe1f584SPeter Brune PetscFunctionReturn(0); 12615fe1f584SPeter Brune } 12625fe1f584SPeter Brune 12635fe1f584SPeter Brune 12645fe1f584SPeter Brune 12655fe1f584SPeter Brune #undef __FUNCT__ 126647c6ae99SBarry Smith #define __FUNCT__ "DMRefineHierarchy" 126747c6ae99SBarry Smith /*@C 126847c6ae99SBarry Smith DMRefineHierarchy - Refines a DM object, all levels at once 126947c6ae99SBarry Smith 127047c6ae99SBarry Smith Collective on DM 127147c6ae99SBarry Smith 127247c6ae99SBarry Smith Input Parameter: 127347c6ae99SBarry Smith + dm - the DM object 127447c6ae99SBarry Smith - nlevels - the number of levels of refinement 127547c6ae99SBarry Smith 127647c6ae99SBarry Smith Output Parameter: 127747c6ae99SBarry Smith . dmf - the refined DM hierarchy 127847c6ae99SBarry Smith 127947c6ae99SBarry Smith Level: developer 128047c6ae99SBarry Smith 1281e727c939SJed Brown .seealso DMCoarsenHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 128247c6ae99SBarry Smith 128347c6ae99SBarry Smith @*/ 12847087cfbeSBarry Smith PetscErrorCode DMRefineHierarchy(DM dm,PetscInt nlevels,DM dmf[]) 128547c6ae99SBarry Smith { 128647c6ae99SBarry Smith PetscErrorCode ierr; 128747c6ae99SBarry Smith 128847c6ae99SBarry Smith PetscFunctionBegin; 1289171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 129047c6ae99SBarry Smith if (nlevels < 0) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 129147c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 129247c6ae99SBarry Smith if (dm->ops->refinehierarchy) { 129347c6ae99SBarry Smith ierr = (*dm->ops->refinehierarchy)(dm,nlevels,dmf);CHKERRQ(ierr); 129447c6ae99SBarry Smith } else if (dm->ops->refine) { 129547c6ae99SBarry Smith PetscInt i; 129647c6ae99SBarry Smith 129747c6ae99SBarry Smith ierr = DMRefine(dm,((PetscObject)dm)->comm,&dmf[0]);CHKERRQ(ierr); 129847c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 129947c6ae99SBarry Smith ierr = DMRefine(dmf[i-1],((PetscObject)dm)->comm,&dmf[i]);CHKERRQ(ierr); 130047c6ae99SBarry Smith } 130147c6ae99SBarry Smith } else { 130247c6ae99SBarry Smith SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_SUP,"No RefineHierarchy for this DM yet"); 130347c6ae99SBarry Smith } 130447c6ae99SBarry Smith PetscFunctionReturn(0); 130547c6ae99SBarry Smith } 130647c6ae99SBarry Smith 130747c6ae99SBarry Smith #undef __FUNCT__ 130847c6ae99SBarry Smith #define __FUNCT__ "DMCoarsenHierarchy" 130947c6ae99SBarry Smith /*@C 131047c6ae99SBarry Smith DMCoarsenHierarchy - Coarsens a DM object, all levels at once 131147c6ae99SBarry Smith 131247c6ae99SBarry Smith Collective on DM 131347c6ae99SBarry Smith 131447c6ae99SBarry Smith Input Parameter: 131547c6ae99SBarry Smith + dm - the DM object 131647c6ae99SBarry Smith - nlevels - the number of levels of coarsening 131747c6ae99SBarry Smith 131847c6ae99SBarry Smith Output Parameter: 131947c6ae99SBarry Smith . dmc - the coarsened DM hierarchy 132047c6ae99SBarry Smith 132147c6ae99SBarry Smith Level: developer 132247c6ae99SBarry Smith 1323e727c939SJed Brown .seealso DMRefineHierarchy(), DMDestroy(), DMView(), DMCreateGlobalVector(), DMCreateInterpolation() 132447c6ae99SBarry Smith 132547c6ae99SBarry Smith @*/ 13267087cfbeSBarry Smith PetscErrorCode DMCoarsenHierarchy(DM dm, PetscInt nlevels, DM dmc[]) 132747c6ae99SBarry Smith { 132847c6ae99SBarry Smith PetscErrorCode ierr; 132947c6ae99SBarry Smith 133047c6ae99SBarry Smith PetscFunctionBegin; 1331171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 133247c6ae99SBarry Smith if (nlevels < 0) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_OUTOFRANGE,"nlevels cannot be negative"); 133347c6ae99SBarry Smith if (nlevels == 0) PetscFunctionReturn(0); 133447c6ae99SBarry Smith PetscValidPointer(dmc,3); 133547c6ae99SBarry Smith if (dm->ops->coarsenhierarchy) { 133647c6ae99SBarry Smith ierr = (*dm->ops->coarsenhierarchy)(dm, nlevels, dmc);CHKERRQ(ierr); 133747c6ae99SBarry Smith } else if (dm->ops->coarsen) { 133847c6ae99SBarry Smith PetscInt i; 133947c6ae99SBarry Smith 134047c6ae99SBarry Smith ierr = DMCoarsen(dm,((PetscObject)dm)->comm,&dmc[0]);CHKERRQ(ierr); 134147c6ae99SBarry Smith for (i=1; i<nlevels; i++) { 134247c6ae99SBarry Smith ierr = DMCoarsen(dmc[i-1],((PetscObject)dm)->comm,&dmc[i]);CHKERRQ(ierr); 134347c6ae99SBarry Smith } 134447c6ae99SBarry Smith } else { 134547c6ae99SBarry Smith SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_SUP,"No CoarsenHierarchy for this DM yet"); 134647c6ae99SBarry Smith } 134747c6ae99SBarry Smith PetscFunctionReturn(0); 134847c6ae99SBarry Smith } 134947c6ae99SBarry Smith 135047c6ae99SBarry Smith #undef __FUNCT__ 1351e727c939SJed Brown #define __FUNCT__ "DMCreateAggregates" 135247c6ae99SBarry Smith /*@ 1353e727c939SJed Brown DMCreateAggregates - Gets the aggregates that map between 135447c6ae99SBarry Smith grids associated with two DMs. 135547c6ae99SBarry Smith 135647c6ae99SBarry Smith Collective on DM 135747c6ae99SBarry Smith 135847c6ae99SBarry Smith Input Parameters: 135947c6ae99SBarry Smith + dmc - the coarse grid DM 136047c6ae99SBarry Smith - dmf - the fine grid DM 136147c6ae99SBarry Smith 136247c6ae99SBarry Smith Output Parameters: 136347c6ae99SBarry Smith . rest - the restriction matrix (transpose of the projection matrix) 136447c6ae99SBarry Smith 136547c6ae99SBarry Smith Level: intermediate 136647c6ae99SBarry Smith 136747c6ae99SBarry Smith .keywords: interpolation, restriction, multigrid 136847c6ae99SBarry Smith 1369e727c939SJed Brown .seealso: DMRefine(), DMCreateInjection(), DMCreateInterpolation() 137047c6ae99SBarry Smith @*/ 1371e727c939SJed Brown PetscErrorCode DMCreateAggregates(DM dmc, DM dmf, Mat *rest) 137247c6ae99SBarry Smith { 137347c6ae99SBarry Smith PetscErrorCode ierr; 137447c6ae99SBarry Smith 137547c6ae99SBarry Smith PetscFunctionBegin; 1376171400e9SBarry Smith PetscValidHeaderSpecific(dmc,DM_CLASSID,1); 1377171400e9SBarry Smith PetscValidHeaderSpecific(dmf,DM_CLASSID,2); 137847c6ae99SBarry Smith ierr = (*dmc->ops->getaggregates)(dmc, dmf, rest);CHKERRQ(ierr); 137947c6ae99SBarry Smith PetscFunctionReturn(0); 138047c6ae99SBarry Smith } 138147c6ae99SBarry Smith 138247c6ae99SBarry Smith #undef __FUNCT__ 13831a266240SBarry Smith #define __FUNCT__ "DMSetApplicationContextDestroy" 13841a266240SBarry Smith /*@C 13851a266240SBarry Smith DMSetApplicationContextDestroy - Sets a user function that will be called to destroy the application context when the DM is destroyed 13861a266240SBarry Smith 13871a266240SBarry Smith Not Collective 13881a266240SBarry Smith 13891a266240SBarry Smith Input Parameters: 13901a266240SBarry Smith + dm - the DM object 13911a266240SBarry Smith - destroy - the destroy function 13921a266240SBarry Smith 13931a266240SBarry Smith Level: intermediate 13941a266240SBarry Smith 1395e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 13961a266240SBarry Smith 1397f07f9ceaSJed Brown @*/ 13981a266240SBarry Smith PetscErrorCode DMSetApplicationContextDestroy(DM dm,PetscErrorCode (*destroy)(void**)) 13991a266240SBarry Smith { 14001a266240SBarry Smith PetscFunctionBegin; 1401171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 14021a266240SBarry Smith dm->ctxdestroy = destroy; 14031a266240SBarry Smith PetscFunctionReturn(0); 14041a266240SBarry Smith } 14051a266240SBarry Smith 14061a266240SBarry Smith #undef __FUNCT__ 14071b2093e4SBarry Smith #define __FUNCT__ "DMSetApplicationContext" 1408b07ff414SBarry Smith /*@ 14091b2093e4SBarry Smith DMSetApplicationContext - Set a user context into a DM object 141047c6ae99SBarry Smith 141147c6ae99SBarry Smith Not Collective 141247c6ae99SBarry Smith 141347c6ae99SBarry Smith Input Parameters: 141447c6ae99SBarry Smith + dm - the DM object 141547c6ae99SBarry Smith - ctx - the user context 141647c6ae99SBarry Smith 141747c6ae99SBarry Smith Level: intermediate 141847c6ae99SBarry Smith 1419e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 142047c6ae99SBarry Smith 142147c6ae99SBarry Smith @*/ 14221b2093e4SBarry Smith PetscErrorCode DMSetApplicationContext(DM dm,void *ctx) 142347c6ae99SBarry Smith { 142447c6ae99SBarry Smith PetscFunctionBegin; 1425171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 142647c6ae99SBarry Smith dm->ctx = ctx; 142747c6ae99SBarry Smith PetscFunctionReturn(0); 142847c6ae99SBarry Smith } 142947c6ae99SBarry Smith 143047c6ae99SBarry Smith #undef __FUNCT__ 14311b2093e4SBarry Smith #define __FUNCT__ "DMGetApplicationContext" 143247c6ae99SBarry Smith /*@ 14331b2093e4SBarry Smith DMGetApplicationContext - Gets a user context from a DM object 143447c6ae99SBarry Smith 143547c6ae99SBarry Smith Not Collective 143647c6ae99SBarry Smith 143747c6ae99SBarry Smith Input Parameter: 143847c6ae99SBarry Smith . dm - the DM object 143947c6ae99SBarry Smith 144047c6ae99SBarry Smith Output Parameter: 144147c6ae99SBarry Smith . ctx - the user context 144247c6ae99SBarry Smith 144347c6ae99SBarry Smith Level: intermediate 144447c6ae99SBarry Smith 1445e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext() 144647c6ae99SBarry Smith 144747c6ae99SBarry Smith @*/ 14481b2093e4SBarry Smith PetscErrorCode DMGetApplicationContext(DM dm,void *ctx) 144947c6ae99SBarry Smith { 145047c6ae99SBarry Smith PetscFunctionBegin; 1451171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 14521b2093e4SBarry Smith *(void**)ctx = dm->ctx; 145347c6ae99SBarry Smith PetscFunctionReturn(0); 145447c6ae99SBarry Smith } 145547c6ae99SBarry Smith 145647c6ae99SBarry Smith #undef __FUNCT__ 145747c6ae99SBarry Smith #define __FUNCT__ "DMSetInitialGuess" 14587e833e3aSBarry Smith /*@C 145947c6ae99SBarry Smith DMSetInitialGuess - sets a function to compute an initial guess vector entries for the solvers 146047c6ae99SBarry Smith 146147c6ae99SBarry Smith Logically Collective on DM 146247c6ae99SBarry Smith 146347c6ae99SBarry Smith Input Parameter: 146447c6ae99SBarry Smith + dm - the DM object to destroy 146547c6ae99SBarry Smith - f - the function to compute the initial guess 146647c6ae99SBarry Smith 146747c6ae99SBarry Smith Level: intermediate 146847c6ae99SBarry Smith 1469e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetFunction(), DMSetJacobian() 147047c6ae99SBarry Smith 1471f07f9ceaSJed Brown @*/ 14727087cfbeSBarry Smith PetscErrorCode DMSetInitialGuess(DM dm,PetscErrorCode (*f)(DM,Vec)) 147347c6ae99SBarry Smith { 147447c6ae99SBarry Smith PetscFunctionBegin; 1475171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 147647c6ae99SBarry Smith dm->ops->initialguess = f; 147747c6ae99SBarry Smith PetscFunctionReturn(0); 147847c6ae99SBarry Smith } 147947c6ae99SBarry Smith 148047c6ae99SBarry Smith #undef __FUNCT__ 148147c6ae99SBarry Smith #define __FUNCT__ "DMSetFunction" 14827e833e3aSBarry Smith /*@C 148347c6ae99SBarry Smith DMSetFunction - sets a function to compute the right hand side vector entries for the KSP solver or nonlinear function for SNES 148447c6ae99SBarry Smith 148547c6ae99SBarry Smith Logically Collective on DM 148647c6ae99SBarry Smith 148747c6ae99SBarry Smith Input Parameter: 148847c6ae99SBarry Smith + dm - the DM object 148947c6ae99SBarry Smith - f - the function to compute (use PETSC_NULL to cancel a previous function that was set) 149047c6ae99SBarry Smith 149147c6ae99SBarry Smith Level: intermediate 149247c6ae99SBarry Smith 149347c6ae99SBarry Smith Notes: This sets both the function for function evaluations and the function used to compute Jacobians via finite differences if no Jacobian 149447c6ae99SBarry Smith computer is provided with DMSetJacobian(). Canceling cancels the function, but not the function used to compute the Jacobian. 149547c6ae99SBarry Smith 1496e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetInitialGuess(), 149747c6ae99SBarry Smith DMSetJacobian() 149847c6ae99SBarry Smith 1499f07f9ceaSJed Brown @*/ 15007087cfbeSBarry Smith PetscErrorCode DMSetFunction(DM dm,PetscErrorCode (*f)(DM,Vec,Vec)) 150147c6ae99SBarry Smith { 150247c6ae99SBarry Smith PetscFunctionBegin; 1503171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 150447c6ae99SBarry Smith dm->ops->function = f; 150547c6ae99SBarry Smith if (f) { 150647c6ae99SBarry Smith dm->ops->functionj = f; 150747c6ae99SBarry Smith } 150847c6ae99SBarry Smith PetscFunctionReturn(0); 150947c6ae99SBarry Smith } 151047c6ae99SBarry Smith 151147c6ae99SBarry Smith #undef __FUNCT__ 151247c6ae99SBarry Smith #define __FUNCT__ "DMSetJacobian" 15137e833e3aSBarry Smith /*@C 151447c6ae99SBarry Smith DMSetJacobian - sets a function to compute the matrix entries for the KSP solver or Jacobian for SNES 151547c6ae99SBarry Smith 151647c6ae99SBarry Smith Logically Collective on DM 151747c6ae99SBarry Smith 151847c6ae99SBarry Smith Input Parameter: 151947c6ae99SBarry Smith + dm - the DM object to destroy 152047c6ae99SBarry Smith - f - the function to compute the matrix entries 152147c6ae99SBarry Smith 152247c6ae99SBarry Smith Level: intermediate 152347c6ae99SBarry Smith 1524e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetInitialGuess(), 152547c6ae99SBarry Smith DMSetFunction() 152647c6ae99SBarry Smith 1527f07f9ceaSJed Brown @*/ 15287087cfbeSBarry Smith PetscErrorCode DMSetJacobian(DM dm,PetscErrorCode (*f)(DM,Vec,Mat,Mat,MatStructure*)) 152947c6ae99SBarry Smith { 153047c6ae99SBarry Smith PetscFunctionBegin; 1531171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 153247c6ae99SBarry Smith dm->ops->jacobian = f; 153347c6ae99SBarry Smith PetscFunctionReturn(0); 153447c6ae99SBarry Smith } 153547c6ae99SBarry Smith 153647c6ae99SBarry Smith #undef __FUNCT__ 153708da532bSDmitry Karpeev #define __FUNCT__ "DMSetVariableBounds" 153808da532bSDmitry Karpeev /*@C 153908da532bSDmitry Karpeev DMSetVariableBounds - sets a function to compute the the lower and upper bound vectors for SNESVI. 154008da532bSDmitry Karpeev 154108da532bSDmitry Karpeev Logically Collective on DM 154208da532bSDmitry Karpeev 154308da532bSDmitry Karpeev Input Parameter: 154408da532bSDmitry Karpeev + dm - the DM object 154508da532bSDmitry Karpeev - f - the function that computes variable bounds used by SNESVI (use PETSC_NULL to cancel a previous function that was set) 154608da532bSDmitry Karpeev 154708da532bSDmitry Karpeev Level: intermediate 154808da532bSDmitry Karpeev 1549e88d7f4bSDmitry Karpeev .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetInitialGuess(), 155008da532bSDmitry Karpeev DMSetJacobian() 155108da532bSDmitry Karpeev 155208da532bSDmitry Karpeev @*/ 155308da532bSDmitry Karpeev PetscErrorCode DMSetVariableBounds(DM dm,PetscErrorCode (*f)(DM,Vec,Vec)) 155408da532bSDmitry Karpeev { 155508da532bSDmitry Karpeev PetscFunctionBegin; 155608da532bSDmitry Karpeev dm->ops->computevariablebounds = f; 155708da532bSDmitry Karpeev PetscFunctionReturn(0); 155808da532bSDmitry Karpeev } 155908da532bSDmitry Karpeev 156008da532bSDmitry Karpeev #undef __FUNCT__ 156108da532bSDmitry Karpeev #define __FUNCT__ "DMHasVariableBounds" 156208da532bSDmitry Karpeev /*@ 156308da532bSDmitry Karpeev DMHasVariableBounds - does the DM object have a variable bounds function? 156408da532bSDmitry Karpeev 156508da532bSDmitry Karpeev Not Collective 156608da532bSDmitry Karpeev 156708da532bSDmitry Karpeev Input Parameter: 156808da532bSDmitry Karpeev . dm - the DM object to destroy 156908da532bSDmitry Karpeev 157008da532bSDmitry Karpeev Output Parameter: 157108da532bSDmitry Karpeev . flg - PETSC_TRUE if the variable bounds function exists 157208da532bSDmitry Karpeev 157308da532bSDmitry Karpeev Level: developer 157408da532bSDmitry Karpeev 1575e88d7f4bSDmitry Karpeev .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetFunction(), DMSetJacobian() 157608da532bSDmitry Karpeev 157708da532bSDmitry Karpeev @*/ 157808da532bSDmitry Karpeev PetscErrorCode DMHasVariableBounds(DM dm,PetscBool *flg) 157908da532bSDmitry Karpeev { 158008da532bSDmitry Karpeev PetscFunctionBegin; 158108da532bSDmitry Karpeev *flg = (dm->ops->computevariablebounds) ? PETSC_TRUE : PETSC_FALSE; 158208da532bSDmitry Karpeev PetscFunctionReturn(0); 158308da532bSDmitry Karpeev } 158408da532bSDmitry Karpeev 158508da532bSDmitry Karpeev #undef __FUNCT__ 158608da532bSDmitry Karpeev #define __FUNCT__ "DMComputeVariableBounds" 158708da532bSDmitry Karpeev /*@C 158808da532bSDmitry Karpeev DMComputeVariableBounds - compute variable bounds used by SNESVI. 158908da532bSDmitry Karpeev 159008da532bSDmitry Karpeev Logically Collective on DM 159108da532bSDmitry Karpeev 159208da532bSDmitry Karpeev Input Parameters: 159308da532bSDmitry Karpeev + dm - the DM object to destroy 159408da532bSDmitry Karpeev - x - current solution at which the bounds are computed 159508da532bSDmitry Karpeev 159608da532bSDmitry Karpeev Output parameters: 159708da532bSDmitry Karpeev + xl - lower bound 159808da532bSDmitry Karpeev - xu - upper bound 159908da532bSDmitry Karpeev 160008da532bSDmitry Karpeev Level: intermediate 160108da532bSDmitry Karpeev 1602e88d7f4bSDmitry Karpeev .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetInitialGuess(), 160308da532bSDmitry Karpeev DMSetFunction(), DMSetVariableBounds() 160408da532bSDmitry Karpeev 160508da532bSDmitry Karpeev @*/ 160608da532bSDmitry Karpeev PetscErrorCode DMComputeVariableBounds(DM dm, Vec xl, Vec xu) 160708da532bSDmitry Karpeev { 160808da532bSDmitry Karpeev PetscErrorCode ierr; 160908da532bSDmitry Karpeev PetscFunctionBegin; 161008da532bSDmitry Karpeev PetscValidHeaderSpecific(xl,VEC_CLASSID,2); 161108da532bSDmitry Karpeev PetscValidHeaderSpecific(xu,VEC_CLASSID,2); 161208da532bSDmitry Karpeev if(dm->ops->computevariablebounds) { 161308da532bSDmitry Karpeev ierr = (*dm->ops->computevariablebounds)(dm, xl,xu); CHKERRQ(ierr); 161408da532bSDmitry Karpeev } 161508da532bSDmitry Karpeev else { 161608da532bSDmitry Karpeev ierr = VecSet(xl,SNES_VI_NINF); CHKERRQ(ierr); 161708da532bSDmitry Karpeev ierr = VecSet(xu,SNES_VI_INF); CHKERRQ(ierr); 161808da532bSDmitry Karpeev } 161908da532bSDmitry Karpeev PetscFunctionReturn(0); 162008da532bSDmitry Karpeev } 162108da532bSDmitry Karpeev 162208da532bSDmitry Karpeev #undef __FUNCT__ 162347c6ae99SBarry Smith #define __FUNCT__ "DMComputeInitialGuess" 162447c6ae99SBarry Smith /*@ 162547c6ae99SBarry Smith DMComputeInitialGuess - computes an initial guess vector entries for the KSP solvers 162647c6ae99SBarry Smith 162747c6ae99SBarry Smith Collective on DM 162847c6ae99SBarry Smith 162947c6ae99SBarry Smith Input Parameter: 163047c6ae99SBarry Smith + dm - the DM object to destroy 163147c6ae99SBarry Smith - x - the vector to hold the initial guess values 163247c6ae99SBarry Smith 163347c6ae99SBarry Smith Level: developer 163447c6ae99SBarry Smith 1635e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetRhs(), DMSetMat() 163647c6ae99SBarry Smith 163747c6ae99SBarry Smith @*/ 16387087cfbeSBarry Smith PetscErrorCode DMComputeInitialGuess(DM dm,Vec x) 163947c6ae99SBarry Smith { 164047c6ae99SBarry Smith PetscErrorCode ierr; 164147c6ae99SBarry Smith PetscFunctionBegin; 1642171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 164347c6ae99SBarry Smith if (!dm->ops->initialguess) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE,"Need to provide function with DMSetInitialGuess()"); 164447c6ae99SBarry Smith ierr = (*dm->ops->initialguess)(dm,x);CHKERRQ(ierr); 164547c6ae99SBarry Smith PetscFunctionReturn(0); 164647c6ae99SBarry Smith } 164747c6ae99SBarry Smith 164847c6ae99SBarry Smith #undef __FUNCT__ 164947c6ae99SBarry Smith #define __FUNCT__ "DMHasInitialGuess" 165047c6ae99SBarry Smith /*@ 165147c6ae99SBarry Smith DMHasInitialGuess - does the DM object have an initial guess function 165247c6ae99SBarry Smith 165347c6ae99SBarry Smith Not Collective 165447c6ae99SBarry Smith 165547c6ae99SBarry Smith Input Parameter: 165647c6ae99SBarry Smith . dm - the DM object to destroy 165747c6ae99SBarry Smith 165847c6ae99SBarry Smith Output Parameter: 165947c6ae99SBarry Smith . flg - PETSC_TRUE if function exists 166047c6ae99SBarry Smith 166147c6ae99SBarry Smith Level: developer 166247c6ae99SBarry Smith 1663e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetFunction(), DMSetJacobian() 166447c6ae99SBarry Smith 166547c6ae99SBarry Smith @*/ 16667087cfbeSBarry Smith PetscErrorCode DMHasInitialGuess(DM dm,PetscBool *flg) 166747c6ae99SBarry Smith { 166847c6ae99SBarry Smith PetscFunctionBegin; 1669171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 167047c6ae99SBarry Smith *flg = (dm->ops->initialguess) ? PETSC_TRUE : PETSC_FALSE; 167147c6ae99SBarry Smith PetscFunctionReturn(0); 167247c6ae99SBarry Smith } 167347c6ae99SBarry Smith 167447c6ae99SBarry Smith #undef __FUNCT__ 167547c6ae99SBarry Smith #define __FUNCT__ "DMHasFunction" 167647c6ae99SBarry Smith /*@ 167747c6ae99SBarry Smith DMHasFunction - does the DM object have a function 167847c6ae99SBarry Smith 167947c6ae99SBarry Smith Not Collective 168047c6ae99SBarry Smith 168147c6ae99SBarry Smith Input Parameter: 168247c6ae99SBarry Smith . dm - the DM object to destroy 168347c6ae99SBarry Smith 168447c6ae99SBarry Smith Output Parameter: 168547c6ae99SBarry Smith . flg - PETSC_TRUE if function exists 168647c6ae99SBarry Smith 168747c6ae99SBarry Smith Level: developer 168847c6ae99SBarry Smith 1689e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetFunction(), DMSetJacobian() 169047c6ae99SBarry Smith 169147c6ae99SBarry Smith @*/ 16927087cfbeSBarry Smith PetscErrorCode DMHasFunction(DM dm,PetscBool *flg) 169347c6ae99SBarry Smith { 169447c6ae99SBarry Smith PetscFunctionBegin; 1695171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 169647c6ae99SBarry Smith *flg = (dm->ops->function) ? PETSC_TRUE : PETSC_FALSE; 169747c6ae99SBarry Smith PetscFunctionReturn(0); 169847c6ae99SBarry Smith } 169947c6ae99SBarry Smith 170047c6ae99SBarry Smith #undef __FUNCT__ 170147c6ae99SBarry Smith #define __FUNCT__ "DMHasJacobian" 170247c6ae99SBarry Smith /*@ 170347c6ae99SBarry Smith DMHasJacobian - does the DM object have a matrix function 170447c6ae99SBarry Smith 170547c6ae99SBarry Smith Not Collective 170647c6ae99SBarry Smith 170747c6ae99SBarry Smith Input Parameter: 170847c6ae99SBarry Smith . dm - the DM object to destroy 170947c6ae99SBarry Smith 171047c6ae99SBarry Smith Output Parameter: 171147c6ae99SBarry Smith . flg - PETSC_TRUE if function exists 171247c6ae99SBarry Smith 171347c6ae99SBarry Smith Level: developer 171447c6ae99SBarry Smith 1715e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetFunction(), DMSetJacobian() 171647c6ae99SBarry Smith 171747c6ae99SBarry Smith @*/ 17187087cfbeSBarry Smith PetscErrorCode DMHasJacobian(DM dm,PetscBool *flg) 171947c6ae99SBarry Smith { 172047c6ae99SBarry Smith PetscFunctionBegin; 1721171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 172247c6ae99SBarry Smith *flg = (dm->ops->jacobian) ? PETSC_TRUE : PETSC_FALSE; 172347c6ae99SBarry Smith PetscFunctionReturn(0); 172447c6ae99SBarry Smith } 172547c6ae99SBarry Smith 172647c6ae99SBarry Smith #undef __FUNCT__ 172708da532bSDmitry Karpeev #define __FUNCT__ "DMSetVec" 1728748fac09SDmitry Karpeev /*@C 172908da532bSDmitry Karpeev DMSetVec - set the vector at which to compute residual, Jacobian and VI bounds, if the problem is nonlinear. 173008da532bSDmitry Karpeev 173108da532bSDmitry Karpeev Collective on DM 173208da532bSDmitry Karpeev 173308da532bSDmitry Karpeev Input Parameter: 173408da532bSDmitry Karpeev + dm - the DM object 1735e88d7f4bSDmitry Karpeev - x - location to compute residual and Jacobian, if PETSC_NULL is passed to those routines; will be PETSC_NULL for linear problems. 173608da532bSDmitry Karpeev 173708da532bSDmitry Karpeev Level: developer 173808da532bSDmitry Karpeev 1739e88d7f4bSDmitry Karpeev .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetInitialGuess(), 174008da532bSDmitry Karpeev DMSetFunction(), DMSetJacobian(), DMSetVariableBounds() 174108da532bSDmitry Karpeev 174208da532bSDmitry Karpeev @*/ 174308da532bSDmitry Karpeev PetscErrorCode DMSetVec(DM dm,Vec x) 174408da532bSDmitry Karpeev { 174508da532bSDmitry Karpeev PetscErrorCode ierr; 174608da532bSDmitry Karpeev PetscFunctionBegin; 174708da532bSDmitry Karpeev if (x) { 174808da532bSDmitry Karpeev if (!dm->x) { 174908da532bSDmitry Karpeev ierr = DMCreateGlobalVector(dm,&dm->x);CHKERRQ(ierr); 175008da532bSDmitry Karpeev } 175108da532bSDmitry Karpeev ierr = VecCopy(x,dm->x);CHKERRQ(ierr); 175208da532bSDmitry Karpeev } 175308da532bSDmitry Karpeev else if(dm->x) { 175408da532bSDmitry Karpeev ierr = VecDestroy(&dm->x); CHKERRQ(ierr); 175508da532bSDmitry Karpeev } 175608da532bSDmitry Karpeev PetscFunctionReturn(0); 175708da532bSDmitry Karpeev } 175808da532bSDmitry Karpeev 175908da532bSDmitry Karpeev 176008da532bSDmitry Karpeev #undef __FUNCT__ 176147c6ae99SBarry Smith #define __FUNCT__ "DMComputeFunction" 176247c6ae99SBarry Smith /*@ 176347c6ae99SBarry Smith DMComputeFunction - computes the right hand side vector entries for the KSP solver or nonlinear function for SNES 176447c6ae99SBarry Smith 176547c6ae99SBarry Smith Collective on DM 176647c6ae99SBarry Smith 176747c6ae99SBarry Smith Input Parameter: 176847c6ae99SBarry Smith + dm - the DM object to destroy 176947c6ae99SBarry Smith . x - the location where the function is evaluationed, may be ignored for linear problems 177047c6ae99SBarry Smith - b - the vector to hold the right hand side entries 177147c6ae99SBarry Smith 177247c6ae99SBarry Smith Level: developer 177347c6ae99SBarry Smith 1774e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetInitialGuess(), 177547c6ae99SBarry Smith DMSetJacobian() 177647c6ae99SBarry Smith 177747c6ae99SBarry Smith @*/ 17787087cfbeSBarry Smith PetscErrorCode DMComputeFunction(DM dm,Vec x,Vec b) 177947c6ae99SBarry Smith { 178047c6ae99SBarry Smith PetscErrorCode ierr; 178147c6ae99SBarry Smith PetscFunctionBegin; 1782171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 178347c6ae99SBarry Smith if (!dm->ops->function) SETERRQ(((PetscObject)dm)->comm,PETSC_ERR_ARG_WRONGSTATE,"Need to provide function with DMSetFunction()"); 1784644e2e5bSBarry Smith PetscStackPush("DM user function"); 178547c6ae99SBarry Smith ierr = (*dm->ops->function)(dm,x,b);CHKERRQ(ierr); 1786644e2e5bSBarry Smith PetscStackPop; 178747c6ae99SBarry Smith PetscFunctionReturn(0); 178847c6ae99SBarry Smith } 178947c6ae99SBarry Smith 179047c6ae99SBarry Smith 179108da532bSDmitry Karpeev 179247c6ae99SBarry Smith #undef __FUNCT__ 179347c6ae99SBarry Smith #define __FUNCT__ "DMComputeJacobian" 179447c6ae99SBarry Smith /*@ 179547c6ae99SBarry Smith DMComputeJacobian - compute the matrix entries for the solver 179647c6ae99SBarry Smith 179747c6ae99SBarry Smith Collective on DM 179847c6ae99SBarry Smith 179947c6ae99SBarry Smith Input Parameter: 180047c6ae99SBarry Smith + dm - the DM object 1801cab2e9ccSBarry Smith . x - location to compute Jacobian at; will be PETSC_NULL for linear problems, for nonlinear problems if not provided then pulled from DM 180247c6ae99SBarry Smith . A - matrix that defines the operator for the linear solve 180347c6ae99SBarry Smith - B - the matrix used to construct the preconditioner 180447c6ae99SBarry Smith 180547c6ae99SBarry Smith Level: developer 180647c6ae99SBarry Smith 1807e727c939SJed Brown .seealso DMView(), DMCreateGlobalVector(), DMCreateInterpolation(), DMCreateColoring(), DMCreateMatrix(), DMGetApplicationContext(), DMSetInitialGuess(), 180847c6ae99SBarry Smith DMSetFunction() 180947c6ae99SBarry Smith 181047c6ae99SBarry Smith @*/ 18117087cfbeSBarry Smith PetscErrorCode DMComputeJacobian(DM dm,Vec x,Mat A,Mat B,MatStructure *stflag) 181247c6ae99SBarry Smith { 181347c6ae99SBarry Smith PetscErrorCode ierr; 181447c6ae99SBarry Smith 181547c6ae99SBarry Smith PetscFunctionBegin; 1816171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 181747c6ae99SBarry Smith if (!dm->ops->jacobian) { 181847c6ae99SBarry Smith ISColoring coloring; 181947c6ae99SBarry Smith MatFDColoring fd; 18202c9966d7SBarry Smith const MatType mtype; 182147c6ae99SBarry Smith 18222c9966d7SBarry Smith ierr = PetscObjectGetType((PetscObject)B,&mtype);CHKERRQ(ierr); 18232c9966d7SBarry Smith ierr = DMCreateColoring(dm,dm->coloringtype,mtype,&coloring);CHKERRQ(ierr); 182447c6ae99SBarry Smith ierr = MatFDColoringCreate(B,coloring,&fd);CHKERRQ(ierr); 1825fcfd50ebSBarry Smith ierr = ISColoringDestroy(&coloring);CHKERRQ(ierr); 182647c6ae99SBarry Smith ierr = MatFDColoringSetFunction(fd,(PetscErrorCode (*)(void))dm->ops->functionj,dm);CHKERRQ(ierr); 18270bdded8aSJed Brown ierr = PetscObjectSetOptionsPrefix((PetscObject)fd,((PetscObject)dm)->prefix);CHKERRQ(ierr); 18280bdded8aSJed Brown ierr = MatFDColoringSetFromOptions(fd);CHKERRQ(ierr); 182971cd77b2SBarry Smith 183047c6ae99SBarry Smith dm->fd = fd; 183147c6ae99SBarry Smith dm->ops->jacobian = DMComputeJacobianDefault; 18322533e041SBarry Smith 183371cd77b2SBarry Smith /* don't know why this is needed */ 183471cd77b2SBarry Smith ierr = PetscObjectDereference((PetscObject)dm);CHKERRQ(ierr); 183547c6ae99SBarry Smith } 183647c6ae99SBarry Smith if (!x) x = dm->x; 183747c6ae99SBarry Smith ierr = (*dm->ops->jacobian)(dm,x,A,B,stflag);CHKERRQ(ierr); 1838cab2e9ccSBarry Smith 183971cd77b2SBarry Smith /* if matrix depends on x; i.e. nonlinear problem, keep copy of input vector since needed by multigrid methods to generate coarse grid matrices */ 1840649052a6SBarry Smith if (x) { 1841cab2e9ccSBarry Smith if (!dm->x) { 184271cd77b2SBarry Smith ierr = DMCreateGlobalVector(dm,&dm->x);CHKERRQ(ierr); 1843cab2e9ccSBarry Smith } 1844cab2e9ccSBarry Smith ierr = VecCopy(x,dm->x);CHKERRQ(ierr); 1845649052a6SBarry Smith } 1846a8248277SBarry Smith if (A != B) { 1847a8248277SBarry Smith ierr = MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 1848a8248277SBarry Smith ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); 1849a8248277SBarry Smith } 185047c6ae99SBarry Smith PetscFunctionReturn(0); 185147c6ae99SBarry Smith } 1852264ace61SBarry Smith 1853cab2e9ccSBarry Smith 1854264ace61SBarry Smith PetscFList DMList = PETSC_NULL; 1855264ace61SBarry Smith PetscBool DMRegisterAllCalled = PETSC_FALSE; 1856264ace61SBarry Smith 1857264ace61SBarry Smith #undef __FUNCT__ 1858264ace61SBarry Smith #define __FUNCT__ "DMSetType" 1859264ace61SBarry Smith /*@C 1860264ace61SBarry Smith DMSetType - Builds a DM, for a particular DM implementation. 1861264ace61SBarry Smith 1862264ace61SBarry Smith Collective on DM 1863264ace61SBarry Smith 1864264ace61SBarry Smith Input Parameters: 1865264ace61SBarry Smith + dm - The DM object 1866264ace61SBarry Smith - method - The name of the DM type 1867264ace61SBarry Smith 1868264ace61SBarry Smith Options Database Key: 1869264ace61SBarry Smith . -dm_type <type> - Sets the DM type; use -help for a list of available types 1870264ace61SBarry Smith 1871264ace61SBarry Smith Notes: 1872e1589f56SBarry Smith See "petsc/include/petscdm.h" for available DM types (for instance, DM1D, DM2D, or DM3D). 1873264ace61SBarry Smith 1874264ace61SBarry Smith Level: intermediate 1875264ace61SBarry Smith 1876264ace61SBarry Smith .keywords: DM, set, type 1877264ace61SBarry Smith .seealso: DMGetType(), DMCreate() 1878264ace61SBarry Smith @*/ 18797087cfbeSBarry Smith PetscErrorCode DMSetType(DM dm, const DMType method) 1880264ace61SBarry Smith { 1881264ace61SBarry Smith PetscErrorCode (*r)(DM); 1882264ace61SBarry Smith PetscBool match; 1883264ace61SBarry Smith PetscErrorCode ierr; 1884264ace61SBarry Smith 1885264ace61SBarry Smith PetscFunctionBegin; 1886264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 1887251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject) dm, method, &match);CHKERRQ(ierr); 1888264ace61SBarry Smith if (match) PetscFunctionReturn(0); 1889264ace61SBarry Smith 1890264ace61SBarry Smith if (!DMRegisterAllCalled) {ierr = DMRegisterAll(PETSC_NULL);CHKERRQ(ierr);} 18914b91b6eaSBarry Smith ierr = PetscFListFind(DMList, ((PetscObject)dm)->comm, method,PETSC_TRUE,(void (**)(void)) &r);CHKERRQ(ierr); 1892264ace61SBarry Smith if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE, "Unknown DM type: %s", method); 1893264ace61SBarry Smith 1894264ace61SBarry Smith if (dm->ops->destroy) { 1895264ace61SBarry Smith ierr = (*dm->ops->destroy)(dm);CHKERRQ(ierr); 1896b5c23020SJed Brown dm->ops->destroy = PETSC_NULL; 1897264ace61SBarry Smith } 1898264ace61SBarry Smith ierr = (*r)(dm);CHKERRQ(ierr); 1899264ace61SBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)dm,method);CHKERRQ(ierr); 1900264ace61SBarry Smith PetscFunctionReturn(0); 1901264ace61SBarry Smith } 1902264ace61SBarry Smith 1903264ace61SBarry Smith #undef __FUNCT__ 1904264ace61SBarry Smith #define __FUNCT__ "DMGetType" 1905264ace61SBarry Smith /*@C 1906264ace61SBarry Smith DMGetType - Gets the DM type name (as a string) from the DM. 1907264ace61SBarry Smith 1908264ace61SBarry Smith Not Collective 1909264ace61SBarry Smith 1910264ace61SBarry Smith Input Parameter: 1911264ace61SBarry Smith . dm - The DM 1912264ace61SBarry Smith 1913264ace61SBarry Smith Output Parameter: 1914264ace61SBarry Smith . type - The DM type name 1915264ace61SBarry Smith 1916264ace61SBarry Smith Level: intermediate 1917264ace61SBarry Smith 1918264ace61SBarry Smith .keywords: DM, get, type, name 1919264ace61SBarry Smith .seealso: DMSetType(), DMCreate() 1920264ace61SBarry Smith @*/ 19217087cfbeSBarry Smith PetscErrorCode DMGetType(DM dm, const DMType *type) 1922264ace61SBarry Smith { 1923264ace61SBarry Smith PetscErrorCode ierr; 1924264ace61SBarry Smith 1925264ace61SBarry Smith PetscFunctionBegin; 1926264ace61SBarry Smith PetscValidHeaderSpecific(dm, DM_CLASSID,1); 1927264ace61SBarry Smith PetscValidCharPointer(type,2); 1928264ace61SBarry Smith if (!DMRegisterAllCalled) { 1929264ace61SBarry Smith ierr = DMRegisterAll(PETSC_NULL);CHKERRQ(ierr); 1930264ace61SBarry Smith } 1931264ace61SBarry Smith *type = ((PetscObject)dm)->type_name; 1932264ace61SBarry Smith PetscFunctionReturn(0); 1933264ace61SBarry Smith } 1934264ace61SBarry Smith 193567a56275SMatthew G Knepley #undef __FUNCT__ 193667a56275SMatthew G Knepley #define __FUNCT__ "DMConvert" 193767a56275SMatthew G Knepley /*@C 193867a56275SMatthew G Knepley DMConvert - Converts a DM to another DM, either of the same or different type. 193967a56275SMatthew G Knepley 194067a56275SMatthew G Knepley Collective on DM 194167a56275SMatthew G Knepley 194267a56275SMatthew G Knepley Input Parameters: 194367a56275SMatthew G Knepley + dm - the DM 194467a56275SMatthew G Knepley - newtype - new DM type (use "same" for the same type) 194567a56275SMatthew G Knepley 194667a56275SMatthew G Knepley Output Parameter: 194767a56275SMatthew G Knepley . M - pointer to new DM 194867a56275SMatthew G Knepley 194967a56275SMatthew G Knepley Notes: 195067a56275SMatthew G Knepley Cannot be used to convert a sequential DM to parallel or parallel to sequential, 195167a56275SMatthew G Knepley the MPI communicator of the generated DM is always the same as the communicator 195267a56275SMatthew G Knepley of the input DM. 195367a56275SMatthew G Knepley 195467a56275SMatthew G Knepley Level: intermediate 195567a56275SMatthew G Knepley 195667a56275SMatthew G Knepley .seealso: DMCreate() 195767a56275SMatthew G Knepley @*/ 195867a56275SMatthew G Knepley PetscErrorCode DMConvert(DM dm, const DMType newtype, DM *M) 195967a56275SMatthew G Knepley { 196067a56275SMatthew G Knepley DM B; 196167a56275SMatthew G Knepley char convname[256]; 196267a56275SMatthew G Knepley PetscBool sametype, issame; 196367a56275SMatthew G Knepley PetscErrorCode ierr; 196467a56275SMatthew G Knepley 196567a56275SMatthew G Knepley PetscFunctionBegin; 196667a56275SMatthew G Knepley PetscValidHeaderSpecific(dm,DM_CLASSID,1); 196767a56275SMatthew G Knepley PetscValidType(dm,1); 196867a56275SMatthew G Knepley PetscValidPointer(M,3); 1969251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject) dm, newtype, &sametype);CHKERRQ(ierr); 197067a56275SMatthew G Knepley ierr = PetscStrcmp(newtype, "same", &issame);CHKERRQ(ierr); 197167a56275SMatthew G Knepley { 197267a56275SMatthew G Knepley PetscErrorCode (*conv)(DM, const DMType, DM *) = PETSC_NULL; 197367a56275SMatthew G Knepley 197467a56275SMatthew G Knepley /* 197567a56275SMatthew G Knepley Order of precedence: 197667a56275SMatthew G Knepley 1) See if a specialized converter is known to the current DM. 197767a56275SMatthew G Knepley 2) See if a specialized converter is known to the desired DM class. 197867a56275SMatthew G Knepley 3) See if a good general converter is registered for the desired class 197967a56275SMatthew G Knepley 4) See if a good general converter is known for the current matrix. 198067a56275SMatthew G Knepley 5) Use a really basic converter. 198167a56275SMatthew G Knepley */ 198267a56275SMatthew G Knepley 198367a56275SMatthew G Knepley /* 1) See if a specialized converter is known to the current DM and the desired class */ 198467a56275SMatthew G Knepley ierr = PetscStrcpy(convname,"DMConvert_");CHKERRQ(ierr); 198567a56275SMatthew G Knepley ierr = PetscStrcat(convname,((PetscObject) dm)->type_name);CHKERRQ(ierr); 198667a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_");CHKERRQ(ierr); 198767a56275SMatthew G Knepley ierr = PetscStrcat(convname,newtype);CHKERRQ(ierr); 198867a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_C");CHKERRQ(ierr); 198967a56275SMatthew G Knepley ierr = PetscObjectQueryFunction((PetscObject)dm,convname,(void (**)(void))&conv);CHKERRQ(ierr); 199067a56275SMatthew G Knepley if (conv) goto foundconv; 199167a56275SMatthew G Knepley 199267a56275SMatthew G Knepley /* 2) See if a specialized converter is known to the desired DM class. */ 199367a56275SMatthew G Knepley ierr = DMCreate(((PetscObject) dm)->comm, &B);CHKERRQ(ierr); 199467a56275SMatthew G Knepley ierr = DMSetType(B, newtype);CHKERRQ(ierr); 199567a56275SMatthew G Knepley ierr = PetscStrcpy(convname,"DMConvert_");CHKERRQ(ierr); 199667a56275SMatthew G Knepley ierr = PetscStrcat(convname,((PetscObject) dm)->type_name);CHKERRQ(ierr); 199767a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_");CHKERRQ(ierr); 199867a56275SMatthew G Knepley ierr = PetscStrcat(convname,newtype);CHKERRQ(ierr); 199967a56275SMatthew G Knepley ierr = PetscStrcat(convname,"_C");CHKERRQ(ierr); 200067a56275SMatthew G Knepley ierr = PetscObjectQueryFunction((PetscObject)B,convname,(void (**)(void))&conv);CHKERRQ(ierr); 200167a56275SMatthew G Knepley if (conv) { 2002fcfd50ebSBarry Smith ierr = DMDestroy(&B);CHKERRQ(ierr); 200367a56275SMatthew G Knepley goto foundconv; 200467a56275SMatthew G Knepley } 200567a56275SMatthew G Knepley 200667a56275SMatthew G Knepley #if 0 200767a56275SMatthew G Knepley /* 3) See if a good general converter is registered for the desired class */ 200867a56275SMatthew G Knepley conv = B->ops->convertfrom; 2009fcfd50ebSBarry Smith ierr = DMDestroy(&B);CHKERRQ(ierr); 201067a56275SMatthew G Knepley if (conv) goto foundconv; 201167a56275SMatthew G Knepley 201267a56275SMatthew G Knepley /* 4) See if a good general converter is known for the current matrix */ 201367a56275SMatthew G Knepley if (dm->ops->convert) { 201467a56275SMatthew G Knepley conv = dm->ops->convert; 201567a56275SMatthew G Knepley } 201667a56275SMatthew G Knepley if (conv) goto foundconv; 201767a56275SMatthew G Knepley #endif 201867a56275SMatthew G Knepley 201967a56275SMatthew G Knepley /* 5) Use a really basic converter. */ 202067a56275SMatthew G Knepley SETERRQ2(((PetscObject) dm)->comm, PETSC_ERR_SUP, "No conversion possible between DM types %s and %s", ((PetscObject) dm)->type_name, newtype); 202167a56275SMatthew G Knepley 202267a56275SMatthew G Knepley foundconv: 202367a56275SMatthew G Knepley ierr = PetscLogEventBegin(DM_Convert,dm,0,0,0);CHKERRQ(ierr); 202467a56275SMatthew G Knepley ierr = (*conv)(dm,newtype,M);CHKERRQ(ierr); 202567a56275SMatthew G Knepley ierr = PetscLogEventEnd(DM_Convert,dm,0,0,0);CHKERRQ(ierr); 202667a56275SMatthew G Knepley } 202767a56275SMatthew G Knepley ierr = PetscObjectStateIncrease((PetscObject) *M);CHKERRQ(ierr); 202867a56275SMatthew G Knepley PetscFunctionReturn(0); 202967a56275SMatthew G Knepley } 2030264ace61SBarry Smith 2031264ace61SBarry Smith /*--------------------------------------------------------------------------------------------------------------------*/ 2032264ace61SBarry Smith 2033264ace61SBarry Smith #undef __FUNCT__ 2034264ace61SBarry Smith #define __FUNCT__ "DMRegister" 2035264ace61SBarry Smith /*@C 2036264ace61SBarry Smith DMRegister - See DMRegisterDynamic() 2037264ace61SBarry Smith 2038264ace61SBarry Smith Level: advanced 2039264ace61SBarry Smith @*/ 20407087cfbeSBarry Smith PetscErrorCode DMRegister(const char sname[], const char path[], const char name[], PetscErrorCode (*function)(DM)) 2041264ace61SBarry Smith { 2042264ace61SBarry Smith char fullname[PETSC_MAX_PATH_LEN]; 2043264ace61SBarry Smith PetscErrorCode ierr; 2044264ace61SBarry Smith 2045264ace61SBarry Smith PetscFunctionBegin; 2046264ace61SBarry Smith ierr = PetscStrcpy(fullname, path);CHKERRQ(ierr); 2047264ace61SBarry Smith ierr = PetscStrcat(fullname, ":");CHKERRQ(ierr); 2048264ace61SBarry Smith ierr = PetscStrcat(fullname, name);CHKERRQ(ierr); 2049264ace61SBarry Smith ierr = PetscFListAdd(&DMList, sname, fullname, (void (*)(void)) function);CHKERRQ(ierr); 2050264ace61SBarry Smith PetscFunctionReturn(0); 2051264ace61SBarry Smith } 2052264ace61SBarry Smith 2053264ace61SBarry Smith 2054264ace61SBarry Smith /*--------------------------------------------------------------------------------------------------------------------*/ 2055264ace61SBarry Smith #undef __FUNCT__ 2056264ace61SBarry Smith #define __FUNCT__ "DMRegisterDestroy" 2057264ace61SBarry Smith /*@C 2058264ace61SBarry Smith DMRegisterDestroy - Frees the list of DM methods that were registered by DMRegister()/DMRegisterDynamic(). 2059264ace61SBarry Smith 2060264ace61SBarry Smith Not Collective 2061264ace61SBarry Smith 2062264ace61SBarry Smith Level: advanced 2063264ace61SBarry Smith 2064264ace61SBarry Smith .keywords: DM, register, destroy 2065264ace61SBarry Smith .seealso: DMRegister(), DMRegisterAll(), DMRegisterDynamic() 2066264ace61SBarry Smith @*/ 20677087cfbeSBarry Smith PetscErrorCode DMRegisterDestroy(void) 2068264ace61SBarry Smith { 2069264ace61SBarry Smith PetscErrorCode ierr; 2070264ace61SBarry Smith 2071264ace61SBarry Smith PetscFunctionBegin; 2072264ace61SBarry Smith ierr = PetscFListDestroy(&DMList);CHKERRQ(ierr); 2073264ace61SBarry Smith DMRegisterAllCalled = PETSC_FALSE; 2074264ace61SBarry Smith PetscFunctionReturn(0); 2075264ace61SBarry Smith } 207623f975d1SBarry Smith 207723f975d1SBarry Smith #if defined(PETSC_HAVE_MATLAB_ENGINE) 2078c6db04a5SJed Brown #include <mex.h> 207923f975d1SBarry Smith 20803014e516SBarry Smith typedef struct {char *funcname; char *jacname; mxArray *ctx;} DMMatlabContext; 208123f975d1SBarry Smith 208223f975d1SBarry Smith #undef __FUNCT__ 208323f975d1SBarry Smith #define __FUNCT__ "DMComputeFunction_Matlab" 208423f975d1SBarry Smith /* 208523f975d1SBarry Smith DMComputeFunction_Matlab - Calls the function that has been set with 208623f975d1SBarry Smith DMSetFunctionMatlab(). 208723f975d1SBarry Smith 208823f975d1SBarry Smith For linear problems x is null 208923f975d1SBarry Smith 209023f975d1SBarry Smith .seealso: DMSetFunction(), DMGetFunction() 209123f975d1SBarry Smith */ 20927087cfbeSBarry Smith PetscErrorCode DMComputeFunction_Matlab(DM dm,Vec x,Vec y) 209323f975d1SBarry Smith { 209423f975d1SBarry Smith PetscErrorCode ierr; 209523f975d1SBarry Smith DMMatlabContext *sctx; 209623f975d1SBarry Smith int nlhs = 1,nrhs = 4; 209723f975d1SBarry Smith mxArray *plhs[1],*prhs[4]; 209823f975d1SBarry Smith long long int lx = 0,ly = 0,ls = 0; 209923f975d1SBarry Smith 210023f975d1SBarry Smith PetscFunctionBegin; 210123f975d1SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 210223f975d1SBarry Smith PetscValidHeaderSpecific(y,VEC_CLASSID,3); 210323f975d1SBarry Smith PetscCheckSameComm(dm,1,y,3); 210423f975d1SBarry Smith 210523f975d1SBarry Smith /* call Matlab function in ctx with arguments x and y */ 21061b2093e4SBarry Smith ierr = DMGetApplicationContext(dm,&sctx);CHKERRQ(ierr); 210723f975d1SBarry Smith ierr = PetscMemcpy(&ls,&dm,sizeof(dm));CHKERRQ(ierr); 210823f975d1SBarry Smith ierr = PetscMemcpy(&lx,&x,sizeof(x));CHKERRQ(ierr); 21093014e516SBarry Smith ierr = PetscMemcpy(&ly,&y,sizeof(y));CHKERRQ(ierr); 211023f975d1SBarry Smith prhs[0] = mxCreateDoubleScalar((double)ls); 211123f975d1SBarry Smith prhs[1] = mxCreateDoubleScalar((double)lx); 211223f975d1SBarry Smith prhs[2] = mxCreateDoubleScalar((double)ly); 211323f975d1SBarry Smith prhs[3] = mxCreateString(sctx->funcname); 2114b807a863SBarry Smith ierr = mexCallMATLAB(nlhs,plhs,nrhs,prhs,"PetscDMComputeFunctionInternal");CHKERRQ(ierr); 211523f975d1SBarry Smith ierr = mxGetScalar(plhs[0]);CHKERRQ(ierr); 211623f975d1SBarry Smith mxDestroyArray(prhs[0]); 211723f975d1SBarry Smith mxDestroyArray(prhs[1]); 211823f975d1SBarry Smith mxDestroyArray(prhs[2]); 211923f975d1SBarry Smith mxDestroyArray(prhs[3]); 212023f975d1SBarry Smith mxDestroyArray(plhs[0]); 212123f975d1SBarry Smith PetscFunctionReturn(0); 212223f975d1SBarry Smith } 212323f975d1SBarry Smith 212423f975d1SBarry Smith 212523f975d1SBarry Smith #undef __FUNCT__ 212623f975d1SBarry Smith #define __FUNCT__ "DMSetFunctionMatlab" 212723f975d1SBarry Smith /* 212823f975d1SBarry Smith DMSetFunctionMatlab - Sets the function evaluation routine 212923f975d1SBarry Smith 213023f975d1SBarry Smith */ 21317087cfbeSBarry Smith PetscErrorCode DMSetFunctionMatlab(DM dm,const char *func) 213223f975d1SBarry Smith { 213323f975d1SBarry Smith PetscErrorCode ierr; 213423f975d1SBarry Smith DMMatlabContext *sctx; 213523f975d1SBarry Smith 213623f975d1SBarry Smith PetscFunctionBegin; 2137171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 213823f975d1SBarry Smith /* currently sctx is memory bleed */ 21391b2093e4SBarry Smith ierr = DMGetApplicationContext(dm,&sctx);CHKERRQ(ierr); 21403014e516SBarry Smith if (!sctx) { 214123f975d1SBarry Smith ierr = PetscMalloc(sizeof(DMMatlabContext),&sctx);CHKERRQ(ierr); 21423014e516SBarry Smith } 214323f975d1SBarry Smith ierr = PetscStrallocpy(func,&sctx->funcname);CHKERRQ(ierr); 21441b2093e4SBarry Smith ierr = DMSetApplicationContext(dm,sctx);CHKERRQ(ierr); 214523f975d1SBarry Smith ierr = DMSetFunction(dm,DMComputeFunction_Matlab);CHKERRQ(ierr); 214623f975d1SBarry Smith PetscFunctionReturn(0); 214723f975d1SBarry Smith } 21483014e516SBarry Smith 21493014e516SBarry Smith #undef __FUNCT__ 21503014e516SBarry Smith #define __FUNCT__ "DMComputeJacobian_Matlab" 21513014e516SBarry Smith /* 21523014e516SBarry Smith DMComputeJacobian_Matlab - Calls the function that has been set with 21533014e516SBarry Smith DMSetJacobianMatlab(). 21543014e516SBarry Smith 21553014e516SBarry Smith For linear problems x is null 21563014e516SBarry Smith 21573014e516SBarry Smith .seealso: DMSetFunction(), DMGetFunction() 21583014e516SBarry Smith */ 21597087cfbeSBarry Smith PetscErrorCode DMComputeJacobian_Matlab(DM dm,Vec x,Mat A,Mat B,MatStructure *str) 21603014e516SBarry Smith { 21613014e516SBarry Smith PetscErrorCode ierr; 21623014e516SBarry Smith DMMatlabContext *sctx; 21633014e516SBarry Smith int nlhs = 2,nrhs = 5; 21643014e516SBarry Smith mxArray *plhs[2],*prhs[5]; 21653014e516SBarry Smith long long int lx = 0,lA = 0,lB = 0,ls = 0; 21663014e516SBarry Smith 21673014e516SBarry Smith PetscFunctionBegin; 21683014e516SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 21693014e516SBarry Smith PetscValidHeaderSpecific(A,MAT_CLASSID,3); 21703014e516SBarry Smith 2171e3c5b3baSBarry Smith /* call MATLAB function in ctx with arguments x, A, and B */ 21721b2093e4SBarry Smith ierr = DMGetApplicationContext(dm,&sctx);CHKERRQ(ierr); 21733014e516SBarry Smith ierr = PetscMemcpy(&ls,&dm,sizeof(dm));CHKERRQ(ierr); 21743014e516SBarry Smith ierr = PetscMemcpy(&lx,&x,sizeof(x));CHKERRQ(ierr); 21753014e516SBarry Smith ierr = PetscMemcpy(&lA,&A,sizeof(A));CHKERRQ(ierr); 21763014e516SBarry Smith ierr = PetscMemcpy(&lB,&B,sizeof(B));CHKERRQ(ierr); 21773014e516SBarry Smith prhs[0] = mxCreateDoubleScalar((double)ls); 21783014e516SBarry Smith prhs[1] = mxCreateDoubleScalar((double)lx); 21793014e516SBarry Smith prhs[2] = mxCreateDoubleScalar((double)lA); 21803014e516SBarry Smith prhs[3] = mxCreateDoubleScalar((double)lB); 21813014e516SBarry Smith prhs[4] = mxCreateString(sctx->jacname); 2182b807a863SBarry Smith ierr = mexCallMATLAB(nlhs,plhs,nrhs,prhs,"PetscDMComputeJacobianInternal");CHKERRQ(ierr); 2183c980e822SBarry Smith *str = (MatStructure) mxGetScalar(plhs[0]); 2184c088a8dcSBarry Smith ierr = (PetscInt) mxGetScalar(plhs[1]);CHKERRQ(ierr); 21853014e516SBarry Smith mxDestroyArray(prhs[0]); 21863014e516SBarry Smith mxDestroyArray(prhs[1]); 21873014e516SBarry Smith mxDestroyArray(prhs[2]); 21883014e516SBarry Smith mxDestroyArray(prhs[3]); 21893014e516SBarry Smith mxDestroyArray(prhs[4]); 21903014e516SBarry Smith mxDestroyArray(plhs[0]); 21913014e516SBarry Smith mxDestroyArray(plhs[1]); 21923014e516SBarry Smith PetscFunctionReturn(0); 21933014e516SBarry Smith } 21943014e516SBarry Smith 21953014e516SBarry Smith 21963014e516SBarry Smith #undef __FUNCT__ 21973014e516SBarry Smith #define __FUNCT__ "DMSetJacobianMatlab" 21983014e516SBarry Smith /* 21993014e516SBarry Smith DMSetJacobianMatlab - Sets the Jacobian function evaluation routine 22003014e516SBarry Smith 22013014e516SBarry Smith */ 22027087cfbeSBarry Smith PetscErrorCode DMSetJacobianMatlab(DM dm,const char *func) 22033014e516SBarry Smith { 22043014e516SBarry Smith PetscErrorCode ierr; 22053014e516SBarry Smith DMMatlabContext *sctx; 22063014e516SBarry Smith 22073014e516SBarry Smith PetscFunctionBegin; 2208171400e9SBarry Smith PetscValidHeaderSpecific(dm,DM_CLASSID,1); 22093014e516SBarry Smith /* currently sctx is memory bleed */ 22101b2093e4SBarry Smith ierr = DMGetApplicationContext(dm,&sctx);CHKERRQ(ierr); 22113014e516SBarry Smith if (!sctx) { 22123014e516SBarry Smith ierr = PetscMalloc(sizeof(DMMatlabContext),&sctx);CHKERRQ(ierr); 22133014e516SBarry Smith } 22143014e516SBarry Smith ierr = PetscStrallocpy(func,&sctx->jacname);CHKERRQ(ierr); 22151b2093e4SBarry Smith ierr = DMSetApplicationContext(dm,sctx);CHKERRQ(ierr); 22163014e516SBarry Smith ierr = DMSetJacobian(dm,DMComputeJacobian_Matlab);CHKERRQ(ierr); 22173014e516SBarry Smith PetscFunctionReturn(0); 22183014e516SBarry Smith } 221923f975d1SBarry Smith #endif 2220b859378eSBarry Smith 2221b859378eSBarry Smith #undef __FUNCT__ 2222b859378eSBarry Smith #define __FUNCT__ "DMLoad" 2223b859378eSBarry Smith /*@C 2224b859378eSBarry Smith DMLoad - Loads a DM that has been stored in binary or HDF5 format 2225b859378eSBarry Smith with DMView(). 2226b859378eSBarry Smith 2227b859378eSBarry Smith Collective on PetscViewer 2228b859378eSBarry Smith 2229b859378eSBarry Smith Input Parameters: 2230b859378eSBarry Smith + newdm - the newly loaded DM, this needs to have been created with DMCreate() or 2231b859378eSBarry Smith some related function before a call to DMLoad(). 2232b859378eSBarry Smith - viewer - binary file viewer, obtained from PetscViewerBinaryOpen() or 2233b859378eSBarry Smith HDF5 file viewer, obtained from PetscViewerHDF5Open() 2234b859378eSBarry Smith 2235b859378eSBarry Smith Level: intermediate 2236b859378eSBarry Smith 2237b859378eSBarry Smith Notes: 2238b859378eSBarry Smith Defaults to the DM DA. 2239b859378eSBarry Smith 2240b859378eSBarry Smith Notes for advanced users: 2241b859378eSBarry Smith Most users should not need to know the details of the binary storage 2242b859378eSBarry Smith format, since DMLoad() and DMView() completely hide these details. 2243b859378eSBarry Smith But for anyone who's interested, the standard binary matrix storage 2244b859378eSBarry Smith format is 2245b859378eSBarry Smith .vb 2246b859378eSBarry Smith has not yet been determined 2247b859378eSBarry Smith .ve 2248b859378eSBarry Smith 2249b859378eSBarry Smith In addition, PETSc automatically does the byte swapping for 2250b859378eSBarry Smith machines that store the bytes reversed, e.g. DEC alpha, freebsd, 2251b859378eSBarry Smith linux, Windows and the paragon; thus if you write your own binary 2252b859378eSBarry Smith read/write routines you have to swap the bytes; see PetscBinaryRead() 2253b859378eSBarry Smith and PetscBinaryWrite() to see how this may be done. 2254b859378eSBarry Smith 2255b859378eSBarry Smith Concepts: vector^loading from file 2256b859378eSBarry Smith 2257b859378eSBarry Smith .seealso: PetscViewerBinaryOpen(), DMView(), MatLoad(), VecLoad() 2258b859378eSBarry Smith @*/ 2259b859378eSBarry Smith PetscErrorCode DMLoad(DM newdm, PetscViewer viewer) 2260b859378eSBarry Smith { 2261b859378eSBarry Smith PetscErrorCode ierr; 2262b859378eSBarry Smith 2263b859378eSBarry Smith PetscFunctionBegin; 2264b859378eSBarry Smith PetscValidHeaderSpecific(newdm,DM_CLASSID,1); 2265b859378eSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 2266b859378eSBarry Smith 2267b859378eSBarry Smith if (!((PetscObject)newdm)->type_name) { 2268b859378eSBarry Smith ierr = DMSetType(newdm, DMDA);CHKERRQ(ierr); 2269b859378eSBarry Smith } 2270b859378eSBarry Smith ierr = (*newdm->ops->load)(newdm,viewer);CHKERRQ(ierr); 2271b859378eSBarry Smith PetscFunctionReturn(0); 2272b859378eSBarry Smith } 2273b859378eSBarry Smith 22747da65231SMatthew G Knepley /******************************** FEM Support **********************************/ 22757da65231SMatthew G Knepley 22767da65231SMatthew G Knepley #undef __FUNCT__ 22777da65231SMatthew G Knepley #define __FUNCT__ "DMPrintCellVector" 22787da65231SMatthew G Knepley PetscErrorCode DMPrintCellVector(PetscInt c, const char name[], PetscInt len, const PetscScalar x[]) { 22791d47ebbbSSatish Balay PetscInt f; 22801b30c384SMatthew G Knepley PetscErrorCode ierr; 22811b30c384SMatthew G Knepley 22827da65231SMatthew G Knepley PetscFunctionBegin; 228374778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, "Cell %D Element %s\n", c, name);CHKERRQ(ierr); 22841d47ebbbSSatish Balay for(f = 0; f < len; ++f) { 228574778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " | %G |\n", PetscRealPart(x[f]));CHKERRQ(ierr); 22867da65231SMatthew G Knepley } 22877da65231SMatthew G Knepley PetscFunctionReturn(0); 22887da65231SMatthew G Knepley } 22897da65231SMatthew G Knepley 22907da65231SMatthew G Knepley #undef __FUNCT__ 22917da65231SMatthew G Knepley #define __FUNCT__ "DMPrintCellMatrix" 22927da65231SMatthew G Knepley PetscErrorCode DMPrintCellMatrix(PetscInt c, const char name[], PetscInt rows, PetscInt cols, const PetscScalar A[]) { 22931b30c384SMatthew G Knepley PetscInt f, g; 22947da65231SMatthew G Knepley PetscErrorCode ierr; 22957da65231SMatthew G Knepley 22967da65231SMatthew G Knepley PetscFunctionBegin; 229774778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, "Cell %D Element %s\n", c, name);CHKERRQ(ierr); 22981d47ebbbSSatish Balay for(f = 0; f < rows; ++f) { 229974778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " |");CHKERRQ(ierr); 23001d47ebbbSSatish Balay for(g = 0; g < cols; ++g) { 230174778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " % 9.5G", PetscRealPart(A[f*cols+g]));CHKERRQ(ierr); 23027da65231SMatthew G Knepley } 230374778d6cSJed Brown ierr = PetscPrintf(PETSC_COMM_SELF, " |\n");CHKERRQ(ierr); 23047da65231SMatthew G Knepley } 23057da65231SMatthew G Knepley PetscFunctionReturn(0); 23067da65231SMatthew G Knepley } 2307e7c4fc90SDmitry Karpeev 2308*970e74d5SMatthew G Knepley #undef __FUNCT__ 2309*970e74d5SMatthew G Knepley #define __FUNCT__ "DMGetLocalFunction" 2310*970e74d5SMatthew G Knepley /*@C 2311*970e74d5SMatthew G Knepley DMGetLocalFunction - Get the local residual function from this DM 2312*970e74d5SMatthew G Knepley 2313*970e74d5SMatthew G Knepley Not collective 2314*970e74d5SMatthew G Knepley 2315*970e74d5SMatthew G Knepley Input Parameter: 2316*970e74d5SMatthew G Knepley . dm - The DM 2317*970e74d5SMatthew G Knepley 2318*970e74d5SMatthew G Knepley Output Parameter: 2319*970e74d5SMatthew G Knepley . lf - The local residual function 2320*970e74d5SMatthew G Knepley 2321*970e74d5SMatthew G Knepley Calling sequence of lf: 2322*970e74d5SMatthew G Knepley $ lf (SNES snes, Vec x, Vec f, void *ctx); 2323*970e74d5SMatthew G Knepley 2324*970e74d5SMatthew G Knepley + snes - the SNES context 2325*970e74d5SMatthew G Knepley . x - local vector with the state at which to evaluate residual 2326*970e74d5SMatthew G Knepley . f - local vector to put residual in 2327*970e74d5SMatthew G Knepley - ctx - optional user-defined function context 2328*970e74d5SMatthew G Knepley 2329*970e74d5SMatthew G Knepley Level: intermediate 2330*970e74d5SMatthew G Knepley 2331*970e74d5SMatthew G Knepley .seealso DMSetLocalFunction(), DMGetLocalJacobian(), DMSetLocalJacobian() 2332*970e74d5SMatthew G Knepley @*/ 2333*970e74d5SMatthew G Knepley PetscErrorCode DMGetLocalFunction(DM dm, PetscErrorCode (**lf)(DM, Vec, Vec, void *)) 2334*970e74d5SMatthew G Knepley { 2335*970e74d5SMatthew G Knepley PetscFunctionBegin; 2336*970e74d5SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2337*970e74d5SMatthew G Knepley if (lf) *lf = dm->lf; 2338*970e74d5SMatthew G Knepley PetscFunctionReturn(0); 2339*970e74d5SMatthew G Knepley } 2340*970e74d5SMatthew G Knepley 2341*970e74d5SMatthew G Knepley #undef __FUNCT__ 2342*970e74d5SMatthew G Knepley #define __FUNCT__ "DMSetLocalFunction" 2343*970e74d5SMatthew G Knepley /*@C 2344*970e74d5SMatthew G Knepley DMSetLocalFunction - Set the local residual function from this DM 2345*970e74d5SMatthew G Knepley 2346*970e74d5SMatthew G Knepley Not collective 2347*970e74d5SMatthew G Knepley 2348*970e74d5SMatthew G Knepley Input Parameters: 2349*970e74d5SMatthew G Knepley + dm - The DM 2350*970e74d5SMatthew G Knepley - lf - The local residual function 2351*970e74d5SMatthew G Knepley 2352*970e74d5SMatthew G Knepley Calling sequence of lf: 2353*970e74d5SMatthew G Knepley $ lf (SNES snes, Vec x, Vec f, void *ctx); 2354*970e74d5SMatthew G Knepley 2355*970e74d5SMatthew G Knepley + snes - the SNES context 2356*970e74d5SMatthew G Knepley . x - local vector with the state at which to evaluate residual 2357*970e74d5SMatthew G Knepley . f - local vector to put residual in 2358*970e74d5SMatthew G Knepley - ctx - optional user-defined function context 2359*970e74d5SMatthew G Knepley 2360*970e74d5SMatthew G Knepley Level: intermediate 2361*970e74d5SMatthew G Knepley 2362*970e74d5SMatthew G Knepley .seealso DMGetLocalFunction(), DMGetLocalJacobian(), DMSetLocalJacobian() 2363*970e74d5SMatthew G Knepley @*/ 2364*970e74d5SMatthew G Knepley PetscErrorCode DMSetLocalFunction(DM dm, PetscErrorCode (*lf)(DM, Vec, Vec, void *)) 2365*970e74d5SMatthew G Knepley { 2366*970e74d5SMatthew G Knepley PetscFunctionBegin; 2367*970e74d5SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2368*970e74d5SMatthew G Knepley dm->lf = lf; 2369*970e74d5SMatthew G Knepley PetscFunctionReturn(0); 2370*970e74d5SMatthew G Knepley } 2371*970e74d5SMatthew G Knepley 2372*970e74d5SMatthew G Knepley #undef __FUNCT__ 2373*970e74d5SMatthew G Knepley #define __FUNCT__ "DMGetLocalJacobian" 2374*970e74d5SMatthew G Knepley /*@C 2375*970e74d5SMatthew G Knepley DMGetLocalJacobian - Get the local Jacobian function from this DM 2376*970e74d5SMatthew G Knepley 2377*970e74d5SMatthew G Knepley Not collective 2378*970e74d5SMatthew G Knepley 2379*970e74d5SMatthew G Knepley Input Parameter: 2380*970e74d5SMatthew G Knepley . dm - The DM 2381*970e74d5SMatthew G Knepley 2382*970e74d5SMatthew G Knepley Output Parameter: 2383*970e74d5SMatthew G Knepley . lj - The local Jacobian function 2384*970e74d5SMatthew G Knepley 2385*970e74d5SMatthew G Knepley Calling sequence of lj: 2386*970e74d5SMatthew G Knepley $ lj (SNES snes, Vec x, Mat J, Mat M, void *ctx); 2387*970e74d5SMatthew G Knepley 2388*970e74d5SMatthew G Knepley + snes - the SNES context 2389*970e74d5SMatthew G Knepley . x - local vector with the state at which to evaluate residual 2390*970e74d5SMatthew G Knepley . J - matrix to put Jacobian in 2391*970e74d5SMatthew G Knepley . M - matrix to use for defining Jacobian preconditioner 2392*970e74d5SMatthew G Knepley - ctx - optional user-defined function context 2393*970e74d5SMatthew G Knepley 2394*970e74d5SMatthew G Knepley Level: intermediate 2395*970e74d5SMatthew G Knepley 2396*970e74d5SMatthew G Knepley .seealso DMSetLocalJacobian(), DMGetLocalFunction(), DMSetLocalFunction() 2397*970e74d5SMatthew G Knepley @*/ 2398*970e74d5SMatthew G Knepley PetscErrorCode DMGetLocalJacobian(DM dm, PetscErrorCode (**lj)(DM, Vec, Mat, Mat, void *)) 2399*970e74d5SMatthew G Knepley { 2400*970e74d5SMatthew G Knepley PetscFunctionBegin; 2401*970e74d5SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2402*970e74d5SMatthew G Knepley if (lj) *lj = dm->lj; 2403*970e74d5SMatthew G Knepley PetscFunctionReturn(0); 2404*970e74d5SMatthew G Knepley } 2405*970e74d5SMatthew G Knepley 2406*970e74d5SMatthew G Knepley #undef __FUNCT__ 2407*970e74d5SMatthew G Knepley #define __FUNCT__ "DMSetLocalJacobian" 2408*970e74d5SMatthew G Knepley /*@C 2409*970e74d5SMatthew G Knepley DMSetLocalJacobian - Set the local Jacobian function from this DM 2410*970e74d5SMatthew G Knepley 2411*970e74d5SMatthew G Knepley Not collective 2412*970e74d5SMatthew G Knepley 2413*970e74d5SMatthew G Knepley Input Parameters: 2414*970e74d5SMatthew G Knepley + dm - The DM 2415*970e74d5SMatthew G Knepley - lj - The local Jacobian function 2416*970e74d5SMatthew G Knepley 2417*970e74d5SMatthew G Knepley Calling sequence of lj: 2418*970e74d5SMatthew G Knepley $ lj (SNES snes, Vec x, Mat J, Mat M, void *ctx); 2419*970e74d5SMatthew G Knepley 2420*970e74d5SMatthew G Knepley + snes - the SNES context 2421*970e74d5SMatthew G Knepley . x - local vector with the state at which to evaluate residual 2422*970e74d5SMatthew G Knepley . J - matrix to put Jacobian in 2423*970e74d5SMatthew G Knepley . M - matrix to use for defining Jacobian preconditioner 2424*970e74d5SMatthew G Knepley - ctx - optional user-defined function context 2425*970e74d5SMatthew G Knepley 2426*970e74d5SMatthew G Knepley Level: intermediate 2427*970e74d5SMatthew G Knepley 2428*970e74d5SMatthew G Knepley .seealso DMGetLocalJacobian(), DMGetLocalFunction(), DMSetLocalFunction() 2429*970e74d5SMatthew G Knepley @*/ 2430*970e74d5SMatthew G Knepley PetscErrorCode DMSetLocalJacobian(DM dm, PetscErrorCode (*lj)(DM, Vec, Mat, Mat, void *)) 2431*970e74d5SMatthew G Knepley { 2432*970e74d5SMatthew G Knepley PetscFunctionBegin; 2433*970e74d5SMatthew G Knepley PetscValidHeaderSpecific(dm, DM_CLASSID, 1); 2434*970e74d5SMatthew G Knepley dm->lj = lj; 2435*970e74d5SMatthew G Knepley PetscFunctionReturn(0); 2436*970e74d5SMatthew G Knepley } 2437