168260fa0SJed Brown #include <petsc-private/dmimpl.h> /*I "petscdm.h" I*/ 268260fa0SJed Brown 368260fa0SJed Brown #undef __FUNCT__ 468260fa0SJed Brown #define __FUNCT__ "DMGetLocalVector" 568260fa0SJed Brown /*@ 668260fa0SJed Brown DMGetLocalVector - Gets a Seq PETSc vector that 768260fa0SJed Brown may be used with the DMXXX routines. This vector has spaces for the ghost values. 868260fa0SJed Brown 968260fa0SJed Brown Not Collective 1068260fa0SJed Brown 1168260fa0SJed Brown Input Parameter: 1268260fa0SJed Brown . dm - the distributed array 1368260fa0SJed Brown 1468260fa0SJed Brown Output Parameter: 1568260fa0SJed Brown . g - the local vector 1668260fa0SJed Brown 1768260fa0SJed Brown Level: beginner 1868260fa0SJed Brown 1968260fa0SJed Brown Note: 2068260fa0SJed Brown The vector values are NOT initialized and may have garbage in them, so you may need 2168260fa0SJed Brown to zero them. 2268260fa0SJed Brown 2368260fa0SJed Brown The output parameter, g, is a regular PETSc vector that should be returned with 2468260fa0SJed Brown DMRestoreLocalVector() DO NOT call VecDestroy() on it. 2568260fa0SJed Brown 2668260fa0SJed Brown VecStride*() operations can be useful when using DM with dof > 1 2768260fa0SJed Brown 2868260fa0SJed Brown .keywords: distributed array, create, local, vector 2968260fa0SJed Brown 3068260fa0SJed Brown .seealso: DMCreateGlobalVector(), VecDuplicate(), VecDuplicateVecs(), 3168260fa0SJed Brown DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(), 3268260fa0SJed Brown DMGlobalToLocalEnd(), DMLocalToGlobalBegin(), DMCreateLocalVector(), DMRestoreLocalVector(), 3368260fa0SJed Brown VecStrideMax(), VecStrideMin(), VecStrideNorm() 3468260fa0SJed Brown @*/ 3568260fa0SJed Brown PetscErrorCode DMGetLocalVector(DM dm,Vec *g) 3668260fa0SJed Brown { 3768260fa0SJed Brown PetscErrorCode ierr,i; 3868260fa0SJed Brown 3968260fa0SJed Brown PetscFunctionBegin; 4068260fa0SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4168260fa0SJed Brown PetscValidPointer(g,2); 4268260fa0SJed Brown for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 4368260fa0SJed Brown if (dm->localin[i]) { 4468260fa0SJed Brown *g = dm->localin[i]; 450298fd71SBarry Smith dm->localin[i] = NULL; 4668260fa0SJed Brown goto alldone; 4768260fa0SJed Brown } 4868260fa0SJed Brown } 4968260fa0SJed Brown ierr = DMCreateLocalVector(dm,g);CHKERRQ(ierr); 5068260fa0SJed Brown 5168260fa0SJed Brown alldone: 5268260fa0SJed Brown for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 5368260fa0SJed Brown if (!dm->localout[i]) { 5468260fa0SJed Brown dm->localout[i] = *g; 5568260fa0SJed Brown break; 5668260fa0SJed Brown } 5768260fa0SJed Brown } 5868260fa0SJed Brown PetscFunctionReturn(0); 5968260fa0SJed Brown } 6068260fa0SJed Brown 6168260fa0SJed Brown #undef __FUNCT__ 6268260fa0SJed Brown #define __FUNCT__ "DMRestoreLocalVector" 6368260fa0SJed Brown /*@ 6468260fa0SJed Brown DMRestoreLocalVector - Returns a Seq PETSc vector that 6568260fa0SJed Brown obtained from DMGetLocalVector(). Do not use with vector obtained via 6668260fa0SJed Brown DMCreateLocalVector(). 6768260fa0SJed Brown 6868260fa0SJed Brown Not Collective 6968260fa0SJed Brown 7068260fa0SJed Brown Input Parameter: 7168260fa0SJed Brown + dm - the distributed array 7268260fa0SJed Brown - g - the local vector 7368260fa0SJed Brown 7468260fa0SJed Brown Level: beginner 7568260fa0SJed Brown 7668260fa0SJed Brown .keywords: distributed array, create, local, vector 7768260fa0SJed Brown 7868260fa0SJed Brown .seealso: DMCreateGlobalVector(), VecDuplicate(), VecDuplicateVecs(), 7968260fa0SJed Brown DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(), 8068260fa0SJed Brown DMGlobalToLocalEnd(), DMLocalToGlobalBegin(), DMCreateLocalVector(), DMGetLocalVector() 8168260fa0SJed Brown @*/ 8268260fa0SJed Brown PetscErrorCode DMRestoreLocalVector(DM dm,Vec *g) 8368260fa0SJed Brown { 8468260fa0SJed Brown PetscErrorCode ierr; 8568260fa0SJed Brown PetscInt i,j; 8668260fa0SJed Brown 8768260fa0SJed Brown PetscFunctionBegin; 8868260fa0SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 8968260fa0SJed Brown PetscValidPointer(g,2); 9068260fa0SJed Brown for (j=0; j<DM_MAX_WORK_VECTORS; j++) { 9168260fa0SJed Brown if (*g == dm->localout[j]) { 920298fd71SBarry Smith dm->localout[j] = NULL; 9368260fa0SJed Brown for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 9468260fa0SJed Brown if (!dm->localin[i]) { 9568260fa0SJed Brown dm->localin[i] = *g; 9668260fa0SJed Brown goto alldone; 9768260fa0SJed Brown } 9868260fa0SJed Brown } 9968260fa0SJed Brown } 10068260fa0SJed Brown } 10168260fa0SJed Brown ierr = VecDestroy(g);CHKERRQ(ierr); 10268260fa0SJed Brown alldone: 10368260fa0SJed Brown PetscFunctionReturn(0); 10468260fa0SJed Brown } 10568260fa0SJed Brown 10668260fa0SJed Brown #undef __FUNCT__ 10768260fa0SJed Brown #define __FUNCT__ "DMGetGlobalVector" 10868260fa0SJed Brown /*@ 10968260fa0SJed Brown DMGetGlobalVector - Gets a MPI PETSc vector that 11068260fa0SJed Brown may be used with the DMXXX routines. 11168260fa0SJed Brown 11268260fa0SJed Brown Collective on DM 11368260fa0SJed Brown 11468260fa0SJed Brown Input Parameter: 11568260fa0SJed Brown . dm - the distributed array 11668260fa0SJed Brown 11768260fa0SJed Brown Output Parameter: 11868260fa0SJed Brown . g - the global vector 11968260fa0SJed Brown 12068260fa0SJed Brown Level: beginner 12168260fa0SJed Brown 12268260fa0SJed Brown Note: 12368260fa0SJed Brown The vector values are NOT initialized and may have garbage in them, so you may need 12468260fa0SJed Brown to zero them. 12568260fa0SJed Brown 12668260fa0SJed Brown The output parameter, g, is a regular PETSc vector that should be returned with 12768260fa0SJed Brown DMRestoreGlobalVector() DO NOT call VecDestroy() on it. 12868260fa0SJed Brown 12968260fa0SJed Brown VecStride*() operations can be useful when using DM with dof > 1 13068260fa0SJed Brown 13168260fa0SJed Brown .keywords: distributed array, create, Global, vector 13268260fa0SJed Brown 13368260fa0SJed Brown .seealso: DMCreateGlobalVector(), VecDuplicate(), VecDuplicateVecs(), 13468260fa0SJed Brown DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(), 13568260fa0SJed Brown DMGlobalToLocalEnd(), DMLocalToGlobalBegin(), DMCreateLocalVector(), DMRestoreLocalVector() 13668260fa0SJed Brown VecStrideMax(), VecStrideMin(), VecStrideNorm() 13768260fa0SJed Brown 13868260fa0SJed Brown @*/ 13968260fa0SJed Brown PetscErrorCode DMGetGlobalVector(DM dm,Vec *g) 14068260fa0SJed Brown { 14168260fa0SJed Brown PetscErrorCode ierr; 14268260fa0SJed Brown PetscInt i; 14368260fa0SJed Brown 14468260fa0SJed Brown PetscFunctionBegin; 14568260fa0SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 14668260fa0SJed Brown PetscValidPointer(g,2); 14768260fa0SJed Brown for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 14868260fa0SJed Brown if (dm->globalin[i]) { 14968260fa0SJed Brown *g = dm->globalin[i]; 1500298fd71SBarry Smith dm->globalin[i] = NULL; 15168260fa0SJed Brown goto alldone; 15268260fa0SJed Brown } 15368260fa0SJed Brown } 15468260fa0SJed Brown ierr = DMCreateGlobalVector(dm,g);CHKERRQ(ierr); 15568260fa0SJed Brown 15668260fa0SJed Brown alldone: 15768260fa0SJed Brown for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 15868260fa0SJed Brown if (!dm->globalout[i]) { 15968260fa0SJed Brown dm->globalout[i] = *g; 16068260fa0SJed Brown break; 16168260fa0SJed Brown } 16268260fa0SJed Brown } 16368260fa0SJed Brown PetscFunctionReturn(0); 16468260fa0SJed Brown } 16568260fa0SJed Brown 16668260fa0SJed Brown #undef __FUNCT__ 16768260fa0SJed Brown #define __FUNCT__ "DMClearGlobalVectors" 16868260fa0SJed Brown /*@ 16968260fa0SJed Brown DMClearGlobalVectors - Destroys all the global vectors that have been stashed in this DM 17068260fa0SJed Brown 17168260fa0SJed Brown Collective on DM 17268260fa0SJed Brown 17368260fa0SJed Brown Input Parameter: 17468260fa0SJed Brown . dm - the distributed array 17568260fa0SJed Brown 17668260fa0SJed Brown Level: developer 17768260fa0SJed Brown 17868260fa0SJed Brown .keywords: distributed array, create, Global, vector 17968260fa0SJed Brown 18068260fa0SJed Brown .seealso: DMCreateGlobalVector(), VecDuplicate(), VecDuplicateVecs(), 18168260fa0SJed Brown DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(), 18268260fa0SJed Brown DMGlobalToLocalEnd(), DMLocalToGlobalBegin(), DMCreateLocalVector(), DMRestoreLocalVector() 18368260fa0SJed Brown VecStrideMax(), VecStrideMin(), VecStrideNorm() 18468260fa0SJed Brown 18568260fa0SJed Brown @*/ 18668260fa0SJed Brown PetscErrorCode DMClearGlobalVectors(DM dm) 18768260fa0SJed Brown { 18868260fa0SJed Brown PetscErrorCode ierr; 18968260fa0SJed Brown PetscInt i; 19068260fa0SJed Brown 19168260fa0SJed Brown PetscFunctionBegin; 19268260fa0SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 19368260fa0SJed Brown for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 19468260fa0SJed Brown if (dm->globalout[i]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Clearing DM of global vectors that has a global vector obtained with DMGetGlobalVector()"); 19568260fa0SJed Brown ierr = VecDestroy(&dm->globalin[i]);CHKERRQ(ierr); 19668260fa0SJed Brown } 19768260fa0SJed Brown PetscFunctionReturn(0); 19868260fa0SJed Brown } 19968260fa0SJed Brown 20068260fa0SJed Brown #undef __FUNCT__ 20168260fa0SJed Brown #define __FUNCT__ "DMRestoreGlobalVector" 20268260fa0SJed Brown /*@ 20368260fa0SJed Brown DMRestoreGlobalVector - Returns a Seq PETSc vector that 20468260fa0SJed Brown obtained from DMGetGlobalVector(). Do not use with vector obtained via 20568260fa0SJed Brown DMCreateGlobalVector(). 20668260fa0SJed Brown 20768260fa0SJed Brown Not Collective 20868260fa0SJed Brown 20968260fa0SJed Brown Input Parameter: 21068260fa0SJed Brown + dm - the distributed array 21168260fa0SJed Brown - g - the global vector 21268260fa0SJed Brown 21368260fa0SJed Brown Level: beginner 21468260fa0SJed Brown 21568260fa0SJed Brown .keywords: distributed array, create, global, vector 21668260fa0SJed Brown 21768260fa0SJed Brown .seealso: DMCreateGlobalVector(), VecDuplicate(), VecDuplicateVecs(), 21868260fa0SJed Brown DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToGlobalBegin(), 21968260fa0SJed Brown DMGlobalToGlobalEnd(), DMGlobalToGlobal(), DMCreateLocalVector(), DMGetGlobalVector() 22068260fa0SJed Brown @*/ 22168260fa0SJed Brown PetscErrorCode DMRestoreGlobalVector(DM dm,Vec *g) 22268260fa0SJed Brown { 22368260fa0SJed Brown PetscErrorCode ierr; 22468260fa0SJed Brown PetscInt i,j; 22568260fa0SJed Brown 22668260fa0SJed Brown PetscFunctionBegin; 22768260fa0SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 22868260fa0SJed Brown PetscValidPointer(g,2); 22968260fa0SJed Brown for (j=0; j<DM_MAX_WORK_VECTORS; j++) { 23068260fa0SJed Brown if (*g == dm->globalout[j]) { 2310298fd71SBarry Smith dm->globalout[j] = NULL; 23268260fa0SJed Brown for (i=0; i<DM_MAX_WORK_VECTORS; i++) { 23368260fa0SJed Brown if (!dm->globalin[i]) { 23468260fa0SJed Brown dm->globalin[i] = *g; 23568260fa0SJed Brown goto alldone; 23668260fa0SJed Brown } 23768260fa0SJed Brown } 23868260fa0SJed Brown } 23968260fa0SJed Brown } 24068260fa0SJed Brown ierr = VecDestroy(g);CHKERRQ(ierr); 24168260fa0SJed Brown alldone: 24268260fa0SJed Brown PetscFunctionReturn(0); 24368260fa0SJed Brown } 24468260fa0SJed Brown 24568260fa0SJed Brown #undef __FUNCT__ 24668260fa0SJed Brown #define __FUNCT__ "DMGetNamedGlobalVector" 24768260fa0SJed Brown /*@C 24868260fa0SJed Brown DMGetNamedGlobalVector - get access to a named, persistent global vector 24968260fa0SJed Brown 25068260fa0SJed Brown Collective on DM 25168260fa0SJed Brown 25268260fa0SJed Brown Input Arguments: 25368260fa0SJed Brown + dm - DM to hold named vectors 25468260fa0SJed Brown - name - unique name for Vec 25568260fa0SJed Brown 25668260fa0SJed Brown Output Arguments: 25768260fa0SJed Brown . X - named Vec 25868260fa0SJed Brown 25968260fa0SJed Brown Level: developer 26068260fa0SJed Brown 26168260fa0SJed Brown Note: If a Vec with the given name does not exist, it is created. 26268260fa0SJed Brown 26368260fa0SJed Brown .seealso: DMRestoreNamedGlobalVector() 26468260fa0SJed Brown @*/ 26568260fa0SJed Brown PetscErrorCode DMGetNamedGlobalVector(DM dm,const char *name,Vec *X) 26668260fa0SJed Brown { 26768260fa0SJed Brown PetscErrorCode ierr; 26868260fa0SJed Brown DMNamedVecLink link; 26968260fa0SJed Brown 27068260fa0SJed Brown PetscFunctionBegin; 27168260fa0SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 27268260fa0SJed Brown PetscValidCharPointer(name,2); 27368260fa0SJed Brown PetscValidPointer(X,3); 27468260fa0SJed Brown for (link=dm->namedglobal; link; link=link->next) { 27568260fa0SJed Brown PetscBool match; 27668260fa0SJed Brown ierr = PetscStrcmp(name,link->name,&match);CHKERRQ(ierr); 27768260fa0SJed Brown if (match) { 278*ce94432eSBarry Smith if (link->status != DMVEC_STATUS_IN) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Vec name '%s' already checked out",name); 27968260fa0SJed Brown goto found; 28068260fa0SJed Brown } 28168260fa0SJed Brown } 28268260fa0SJed Brown 28368260fa0SJed Brown /* Create the Vec */ 2848caf3d72SBarry Smith ierr = PetscMalloc(sizeof(*link),&link);CHKERRQ(ierr); 28568260fa0SJed Brown ierr = PetscStrallocpy(name,&link->name);CHKERRQ(ierr); 28668260fa0SJed Brown ierr = DMCreateGlobalVector(dm,&link->X);CHKERRQ(ierr); 28768260fa0SJed Brown link->next = dm->namedglobal; 28868260fa0SJed Brown dm->namedglobal = link; 28968260fa0SJed Brown 29068260fa0SJed Brown found: 29168260fa0SJed Brown *X = link->X; 29268260fa0SJed Brown link->status = DMVEC_STATUS_OUT; 29368260fa0SJed Brown PetscFunctionReturn(0); 29468260fa0SJed Brown } 29568260fa0SJed Brown 29668260fa0SJed Brown #undef __FUNCT__ 29768260fa0SJed Brown #define __FUNCT__ "DMRestoreNamedGlobalVector" 29868260fa0SJed Brown /*@C 29968260fa0SJed Brown DMRestoreNamedGlobalVector - restore access to a named, persistent global vector 30068260fa0SJed Brown 30168260fa0SJed Brown Collective on DM 30268260fa0SJed Brown 30368260fa0SJed Brown Input Arguments: 30468260fa0SJed Brown + dm - DM on which the vector was gotten 30568260fa0SJed Brown . name - name under which the vector was gotten 30668260fa0SJed Brown - X - Vec to restore 30768260fa0SJed Brown 30868260fa0SJed Brown Output Arguments: 30968260fa0SJed Brown 31068260fa0SJed Brown Level: developer 31168260fa0SJed Brown 31268260fa0SJed Brown .seealso: DMGetNamedGlobalVector() 31368260fa0SJed Brown @*/ 31468260fa0SJed Brown PetscErrorCode DMRestoreNamedGlobalVector(DM dm,const char *name,Vec *X) 31568260fa0SJed Brown { 31668260fa0SJed Brown PetscErrorCode ierr; 31768260fa0SJed Brown DMNamedVecLink link; 31868260fa0SJed Brown 31968260fa0SJed Brown PetscFunctionBegin; 32068260fa0SJed Brown PetscValidHeaderSpecific(dm,DM_CLASSID,1); 32168260fa0SJed Brown PetscValidCharPointer(name,2); 32268260fa0SJed Brown PetscValidPointer(X,3); 32368260fa0SJed Brown PetscValidHeaderSpecific(*X,VEC_CLASSID,3); 32468260fa0SJed Brown for (link=dm->namedglobal; link; link=link->next) { 32568260fa0SJed Brown PetscBool match; 32668260fa0SJed Brown ierr = PetscStrcmp(name,link->name,&match);CHKERRQ(ierr); 32768260fa0SJed Brown if (match) { 328*ce94432eSBarry Smith if (link->status != DMVEC_STATUS_OUT) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Vec name '%s' was not checked out",name); 329*ce94432eSBarry Smith if (link->X != *X) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_INCOMP,"Attempt to restore Vec name '%s', but Vec does not match the cache",name); 33068260fa0SJed Brown link->status = DMVEC_STATUS_IN; 3310298fd71SBarry Smith *X = NULL; 33268260fa0SJed Brown PetscFunctionReturn(0); 33368260fa0SJed Brown } 33468260fa0SJed Brown } 335*ce94432eSBarry Smith SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_INCOMP,"Could not find Vec name '%s' to restore",name); 33668260fa0SJed Brown PetscFunctionReturn(0); 33768260fa0SJed Brown } 3382348bcf4SPeter Brune 3392348bcf4SPeter Brune #undef __FUNCT__ 3402348bcf4SPeter Brune #define __FUNCT__ "DMGetNamedLocalVector" 3412348bcf4SPeter Brune /*@C 3422348bcf4SPeter Brune DMGetNamedLocalVector - get access to a named, persistent local vector 3432348bcf4SPeter Brune 3442348bcf4SPeter Brune Not Collective 3452348bcf4SPeter Brune 3462348bcf4SPeter Brune Input Arguments: 3472348bcf4SPeter Brune + dm - DM to hold named vectors 3482348bcf4SPeter Brune - name - unique name for Vec 3492348bcf4SPeter Brune 3502348bcf4SPeter Brune Output Arguments: 3512348bcf4SPeter Brune . X - named Vec 3522348bcf4SPeter Brune 3532348bcf4SPeter Brune Level: developer 3542348bcf4SPeter Brune 3552348bcf4SPeter Brune Note: If a Vec with the given name does not exist, it is created. 3562348bcf4SPeter Brune 3572348bcf4SPeter Brune .seealso: DMGetNamedGlobalVector(),DMRestoreNamedLocalVector() 3582348bcf4SPeter Brune @*/ 3592348bcf4SPeter Brune PetscErrorCode DMGetNamedLocalVector(DM dm,const char *name,Vec *X) 3602348bcf4SPeter Brune { 3612348bcf4SPeter Brune PetscErrorCode ierr; 3622348bcf4SPeter Brune DMNamedVecLink link; 3632348bcf4SPeter Brune 3642348bcf4SPeter Brune PetscFunctionBegin; 3652348bcf4SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 3662348bcf4SPeter Brune PetscValidCharPointer(name,2); 3672348bcf4SPeter Brune PetscValidPointer(X,3); 3682348bcf4SPeter Brune for (link=dm->namedlocal; link; link=link->next) { 3692348bcf4SPeter Brune PetscBool match; 3702348bcf4SPeter Brune ierr = PetscStrcmp(name,link->name,&match);CHKERRQ(ierr); 3712348bcf4SPeter Brune if (match) { 372*ce94432eSBarry Smith if (link->status != DMVEC_STATUS_IN) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Vec name '%s' already checked out",name); 3732348bcf4SPeter Brune goto found; 3742348bcf4SPeter Brune } 3752348bcf4SPeter Brune } 3762348bcf4SPeter Brune 3772348bcf4SPeter Brune /* Create the Vec */ 3782348bcf4SPeter Brune ierr = PetscMalloc(sizeof(*link),&link);CHKERRQ(ierr); 3792348bcf4SPeter Brune ierr = PetscStrallocpy(name,&link->name);CHKERRQ(ierr); 3802348bcf4SPeter Brune ierr = DMCreateLocalVector(dm,&link->X);CHKERRQ(ierr); 3812348bcf4SPeter Brune link->next = dm->namedlocal; 3822348bcf4SPeter Brune dm->namedlocal = link; 3832348bcf4SPeter Brune 3842348bcf4SPeter Brune found: 3852348bcf4SPeter Brune *X = link->X; 3862348bcf4SPeter Brune link->status = DMVEC_STATUS_OUT; 3872348bcf4SPeter Brune PetscFunctionReturn(0); 3882348bcf4SPeter Brune } 3892348bcf4SPeter Brune 3902348bcf4SPeter Brune #undef __FUNCT__ 3912348bcf4SPeter Brune #define __FUNCT__ "DMRestoreNamedLocalVector" 3922348bcf4SPeter Brune /*@C 3932348bcf4SPeter Brune DMRestoreNamedLocalVector - restore access to a named, persistent local vector 3942348bcf4SPeter Brune 3952348bcf4SPeter Brune Not Collective 3962348bcf4SPeter Brune 3972348bcf4SPeter Brune Input Arguments: 3982348bcf4SPeter Brune + dm - DM on which the vector was gotten 3992348bcf4SPeter Brune . name - name under which the vector was gotten 4002348bcf4SPeter Brune - X - Vec to restore 4012348bcf4SPeter Brune 4022348bcf4SPeter Brune Output Arguments: 4032348bcf4SPeter Brune 4042348bcf4SPeter Brune Level: developer 4052348bcf4SPeter Brune 4062348bcf4SPeter Brune .seealso: DMRestoreNamedGlobalVector(),DMGetNamedLocalVector() 4072348bcf4SPeter Brune @*/ 4082348bcf4SPeter Brune PetscErrorCode DMRestoreNamedLocalVector(DM dm,const char *name,Vec *X) 4092348bcf4SPeter Brune { 4102348bcf4SPeter Brune PetscErrorCode ierr; 4112348bcf4SPeter Brune DMNamedVecLink link; 4122348bcf4SPeter Brune 4132348bcf4SPeter Brune PetscFunctionBegin; 4142348bcf4SPeter Brune PetscValidHeaderSpecific(dm,DM_CLASSID,1); 4152348bcf4SPeter Brune PetscValidCharPointer(name,2); 4162348bcf4SPeter Brune PetscValidPointer(X,3); 4172348bcf4SPeter Brune PetscValidHeaderSpecific(*X,VEC_CLASSID,3); 4182348bcf4SPeter Brune for (link=dm->namedlocal; link; link=link->next) { 4192348bcf4SPeter Brune PetscBool match; 4202348bcf4SPeter Brune ierr = PetscStrcmp(name,link->name,&match);CHKERRQ(ierr); 4212348bcf4SPeter Brune if (match) { 422*ce94432eSBarry Smith if (link->status != DMVEC_STATUS_OUT) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Vec name '%s' was not checked out",name); 423*ce94432eSBarry Smith if (link->X != *X) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_INCOMP,"Attempt to restore Vec name '%s', but Vec does not match the cache",name); 4242348bcf4SPeter Brune link->status = DMVEC_STATUS_IN; 4250298fd71SBarry Smith *X = NULL; 4262348bcf4SPeter Brune PetscFunctionReturn(0); 4272348bcf4SPeter Brune } 4282348bcf4SPeter Brune } 429*ce94432eSBarry Smith SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_INCOMP,"Could not find Vec name '%s' to restore",name); 4302348bcf4SPeter Brune PetscFunctionReturn(0); 4312348bcf4SPeter Brune } 432