PetscErrorCode PCISDestroy(PC pc) { PC_IS *pcis = (PC_IS*)(pc->data); PetscErrorCode ierr; PetscFunctionBegin; ierr = ISDestroy(&pcis->is_B_local);CHKERRQ(ierr); ierr = ISDestroy(&pcis->is_I_local);CHKERRQ(ierr); ierr = ISDestroy(&pcis->is_B_global);CHKERRQ(ierr); ierr = ISDestroy(&pcis->is_I_global);CHKERRQ(ierr); ierr = MatDestroy(&pcis->A_II);CHKERRQ(ierr); ierr = MatDestroy(&pcis->A_IB);CHKERRQ(ierr); ierr = MatDestroy(&pcis->A_BI);CHKERRQ(ierr); ierr = MatDestroy(&pcis->A_BB);CHKERRQ(ierr); ierr = VecDestroy(&pcis->D);CHKERRQ(ierr); ierr = KSPDestroy(&pcis->ksp_N);CHKERRQ(ierr); ierr = KSPDestroy(&pcis->ksp_D);CHKERRQ(ierr); ierr = VecDestroy(&pcis->vec1_N);CHKERRQ(ierr); ierr = VecDestroy(&pcis->vec2_N);CHKERRQ(ierr); ierr = VecDestroy(&pcis->vec1_D);CHKERRQ(ierr); ierr = VecDestroy(&pcis->vec2_D);CHKERRQ(ierr); ierr = VecDestroy(&pcis->vec3_D);CHKERRQ(ierr); ierr = VecDestroy(&pcis->vec1_B);CHKERRQ(ierr); ierr = VecDestroy(&pcis->vec2_B);CHKERRQ(ierr); ierr = VecDestroy(&pcis->vec3_B);CHKERRQ(ierr); ierr = VecDestroy(&pcis->vec1_global);CHKERRQ(ierr); ierr = VecScatterDestroy(&pcis->global_to_D);CHKERRQ(ierr); ierr = VecScatterDestroy(&pcis->N_to_B);CHKERRQ(ierr); ierr = VecScatterDestroy(&pcis->global_to_B);CHKERRQ(ierr); ierr = PetscFree(pcis->work_N);CHKERRQ(ierr); if (pcis->ISLocalToGlobalMappingGetInfoWasCalled) { ierr = ISLocalToGlobalMappingRestoreInfo((ISLocalToGlobalMapping)0,&(pcis->n_neigh),&(pcis->neigh),&(pcis->n_shared),&(pcis->shared));CHKERRQ(ierr); } ierr = PetscObjectComposeFunction((PetscObject)pc,"PCISSetUseStiffnessScaling_C",NULL);CHKERRQ(ierr); ierr = PetscObjectComposeFunction((PetscObject)pc,"PCISSetSubdomainScalingFactor_C",NULL);CHKERRQ(ierr); ierr = PetscObjectComposeFunction((PetscObject)pc,"PCISSetSubdomainDiagonalScaling_C",NULL);CHKERRQ(ierr); PetscFunctionReturn(0); }

int main(int argc,char **argv) { PetscErrorCode ierr; PetscInt n = 6,idx1[3] = {0,1,2},loc[6] = {0,1,2,3,4,5}; PetscScalar two = 2.0,vals[6] = {10,11,12,13,14,15}; Vec x,y; IS is1,is2; VecScatter ctx = 0; ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr; /* create two vectors */ ierr = VecCreateSeq(PETSC_COMM_SELF,n,&x);CHKERRQ(ierr); ierr = VecDuplicate(x,&y);CHKERRQ(ierr); /* create two index sets */ ierr = ISCreateStride(PETSC_COMM_SELF,3,0,2,&is1);CHKERRQ(ierr); ierr = ISCreateGeneral(PETSC_COMM_SELF,3,idx1,PETSC_COPY_VALUES,&is2);CHKERRQ(ierr); ierr = VecSetValues(x,6,loc,vals,INSERT_VALUES);CHKERRQ(ierr); ierr = VecView(x,PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_SELF,"----\n");CHKERRQ(ierr); ierr = VecSet(y,two);CHKERRQ(ierr); ierr = VecScatterCreate(x,is1,y,is2,&ctx);CHKERRQ(ierr); ierr = VecScatterBegin(ctx,x,y,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); ierr = VecScatterEnd(ctx,x,y,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); ierr = VecScatterDestroy(&ctx);CHKERRQ(ierr); ierr = VecView(y,PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); ierr = ISDestroy(&is1);CHKERRQ(ierr); ierr = ISDestroy(&is2);CHKERRQ(ierr); ierr = VecDestroy(&x);CHKERRQ(ierr); ierr = VecDestroy(&y);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; }

int main(int argc,char **argv) { PetscErrorCode ierr; PetscInt i,n,first,step; IS set; const PetscInt *indices; ierr = PetscInitialize(&argc,&argv,(char*)0,help); CHKERRQ(ierr); n = 10; first = 3; step = 2; /* Create stride index set, starting at 3 with a stride of 2 Note each processor is generating its own index set (in this case they are all identical) */ ierr = ISCreateStride(PETSC_COMM_SELF,n,first,step,&set); CHKERRQ(ierr); ierr = ISView(set,PETSC_VIEWER_STDOUT_SELF); CHKERRQ(ierr); /* Extract indices from set. */ ierr = ISGetIndices(set,&indices); CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"Printing indices directly\n"); CHKERRQ(ierr); for (i=0; i<n; i++) { ierr = PetscPrintf(PETSC_COMM_WORLD,"%D\n",indices[i]); CHKERRQ(ierr); } ierr = ISRestoreIndices(set,&indices); CHKERRQ(ierr); /* Determine information on stride */ ierr = ISStrideGetInfo(set,&first,&step); CHKERRQ(ierr); if (first != 3 || step != 2) SETERRQ(PETSC_COMM_SELF,1,"Stride info not correct!\n"); ierr = ISDestroy(&set); CHKERRQ(ierr); ierr = PetscFinalize(); return 0; }

int main(int argc,char **argv) { PetscInt n = 5; PetscErrorCode ierr; PetscMPIInt rank,size; IS ispetsc,isapp; AO ao; ierr = PetscInitialize(&argc,&argv,(char*)0,help);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,"-n",&n,NULL);CHKERRQ(ierr); ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr); /* create the index sets */ ierr = ISCreateStride(PETSC_COMM_WORLD,n,rank,size,&ispetsc);CHKERRQ(ierr); ierr = ISCreateStride(PETSC_COMM_WORLD,n,n*rank,1,&isapp);CHKERRQ(ierr); /* create the application ordering */ ierr = AOCreateBasicIS(isapp,ispetsc,&ao);CHKERRQ(ierr); ierr = AOView(ao,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = ISView(ispetsc,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = ISView(isapp,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = AOPetscToApplicationIS(ao,ispetsc);CHKERRQ(ierr); ierr = ISView(isapp,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = ISView(ispetsc,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = ISDestroy(&ispetsc);CHKERRQ(ierr); ierr = ISDestroy(&isapp);CHKERRQ(ierr); ierr = AODestroy(&ao);CHKERRQ(ierr); ierr = PetscFinalize(); return 0; }

int main(int argc,char **args) { Mat BAIJ,SBAIJ,*subBAIJ,*subSBAIJ; PetscViewer viewer; char file[PETSC_MAX_PATH_LEN]; PetscBool flg; PetscErrorCode ierr; PetscInt n = 2,issize; PetscMPIInt rank; IS is,iss[2]; PetscInitialize(&argc,&args,(char*)0,help); ierr = PetscOptionsGetString(NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr); ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&viewer);CHKERRQ(ierr); ierr = MatCreate(PETSC_COMM_WORLD,&BAIJ);CHKERRQ(ierr); ierr = MatSetType(BAIJ,MATMPIBAIJ);CHKERRQ(ierr); ierr = MatLoad(BAIJ,viewer);CHKERRQ(ierr); ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&viewer);CHKERRQ(ierr); ierr = MatCreate(PETSC_COMM_WORLD,&SBAIJ);CHKERRQ(ierr); ierr = MatSetType(SBAIJ,MATMPISBAIJ);CHKERRQ(ierr); ierr = MatLoad(SBAIJ,viewer);CHKERRQ(ierr); ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); ierr = MatGetSize(BAIJ,&issize,0);CHKERRQ(ierr); issize = 9; ierr = ISCreateStride(PETSC_COMM_SELF,issize,0,1,&is);CHKERRQ(ierr); iss[0] = is;iss[1] = is; ierr = MatGetSubMatrices(BAIJ,n,iss,iss,MAT_INITIAL_MATRIX,&subBAIJ);CHKERRQ(ierr); ierr = MatGetSubMatrices(SBAIJ,n,iss,iss,MAT_INITIAL_MATRIX,&subSBAIJ);CHKERRQ(ierr); ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); #if defined(PETSC_USE_SOCKET_VIEWER) if (!rank) { ierr = MatView(subBAIJ[0],PETSC_VIEWER_SOCKET_SELF);CHKERRQ(ierr); ierr = MatView(subSBAIJ[0],PETSC_VIEWER_SOCKET_SELF);CHKERRQ(ierr); } #endif /* Free data structures */ ierr = ISDestroy(&is);CHKERRQ(ierr); ierr = MatDestroyMatrices(n,&subBAIJ);CHKERRQ(ierr); ierr = MatDestroyMatrices(n,&subSBAIJ);CHKERRQ(ierr); ierr = MatDestroy(&BAIJ);CHKERRQ(ierr); ierr = MatDestroy(&SBAIJ);CHKERRQ(ierr); ierr = PetscFinalize(); return 0; }

int main(int argc,char **argv) { PetscErrorCode ierr; PetscInt i,n,*indices; PetscInt rank,size; IS is,newis; ierr = PetscInitialize(&argc,&argv,(char*)0,help);CHKERRQ(ierr); ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr); /* Create IS */ n = 4 + rank; ierr = PetscMalloc(n*sizeof(PetscInt),&indices);CHKERRQ(ierr); for (i=0; i<n; i++) { indices[i] = rank + i; } ierr = ISCreateGeneral(PETSC_COMM_WORLD,n,indices,PETSC_COPY_VALUES,&is);CHKERRQ(ierr); ierr = PetscFree(indices);CHKERRQ(ierr); /* Stick them together from all processors */ ierr = ISAllGather(is,&newis);CHKERRQ(ierr); if (!rank) { ierr = ISView(newis,PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); } ierr = ISDestroy(&newis);CHKERRQ(ierr); ierr = ISDestroy(&is);CHKERRQ(ierr); ierr = PetscFinalize(); return 0; }

static PetscErrorCode TaoDestroy_ASILS(Tao tao) { TAO_SSLS *ssls = (TAO_SSLS *)tao->data; PetscErrorCode ierr; PetscFunctionBegin; ierr = VecDestroy(&ssls->ff);CHKERRQ(ierr); ierr = VecDestroy(&ssls->dpsi);CHKERRQ(ierr); ierr = VecDestroy(&ssls->da);CHKERRQ(ierr); ierr = VecDestroy(&ssls->db);CHKERRQ(ierr); ierr = VecDestroy(&ssls->w);CHKERRQ(ierr); ierr = VecDestroy(&ssls->t1);CHKERRQ(ierr); ierr = VecDestroy(&ssls->t2);CHKERRQ(ierr); ierr = VecDestroy(&ssls->r1);CHKERRQ(ierr); ierr = VecDestroy(&ssls->r2);CHKERRQ(ierr); ierr = VecDestroy(&ssls->r3);CHKERRQ(ierr); ierr = VecDestroy(&ssls->dxfree);CHKERRQ(ierr); ierr = MatDestroy(&ssls->J_sub);CHKERRQ(ierr); ierr = MatDestroy(&ssls->Jpre_sub);CHKERRQ(ierr); ierr = ISDestroy(&ssls->fixed);CHKERRQ(ierr); ierr = ISDestroy(&ssls->free);CHKERRQ(ierr); ierr = PetscFree(tao->data);CHKERRQ(ierr); PetscFunctionReturn(0); }

PetscErrorCode MatPartitioningHierarchical_AssembleSubdomain(Mat adj,IS destination,Mat *sadj, ISLocalToGlobalMapping *mapping) { IS irows,icols; PetscInt irows_ln; PetscMPIInt rank; const PetscInt *irows_indices; MPI_Comm comm; PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscObjectGetComm((PetscObject)adj,&comm);CHKERRQ(ierr); ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); /* figure out where data comes from */ ierr = ISBuildTwoSided(destination,NULL,&irows);CHKERRQ(ierr); ierr = ISDuplicate(irows,&icols);CHKERRQ(ierr); ierr = ISGetLocalSize(irows,&irows_ln);CHKERRQ(ierr); ierr = ISGetIndices(irows,&irows_indices);CHKERRQ(ierr); ierr = ISLocalToGlobalMappingCreate(comm,1,irows_ln,irows_indices,PETSC_COPY_VALUES,mapping);CHKERRQ(ierr); ierr = ISRestoreIndices(irows,&irows_indices);CHKERRQ(ierr); ierr = MatGetSubMatrices(adj,1,&irows,&icols,MAT_INITIAL_MATRIX,&sadj);CHKERRQ(ierr); ierr = ISDestroy(&irows);CHKERRQ(ierr); ierr = ISDestroy(&icols);CHKERRQ(ierr); PetscFunctionReturn(0); }

static PetscErrorCode ISView_Block(IS is, PetscViewer viewer) { IS_Block *sub = (IS_Block*)is->data; PetscErrorCode ierr; PetscInt i,bs,n,*idx = sub->idx; PetscBool iascii; PetscFunctionBegin; ierr = PetscLayoutGetBlockSize(is->map, &bs);CHKERRQ(ierr); ierr = PetscLayoutGetLocalSize(is->map, &n);CHKERRQ(ierr); n /= bs; ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); if (iascii) { PetscViewerFormat fmt; ierr = PetscViewerGetFormat(viewer,&fmt);CHKERRQ(ierr); if (fmt == PETSC_VIEWER_ASCII_MATLAB) { IS ist; const char *name; const PetscInt *idx; PetscInt n; ierr = PetscObjectGetName((PetscObject)is,&name);CHKERRQ(ierr); ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr); ierr = ISGetIndices(is,&idx);CHKERRQ(ierr); ierr = ISCreateGeneral(PetscObjectComm((PetscObject)is),n,idx,PETSC_USE_POINTER,&ist);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject)ist,name);CHKERRQ(ierr); ierr = ISView(ist,viewer);CHKERRQ(ierr); ierr = ISDestroy(&ist);CHKERRQ(ierr); ierr = ISRestoreIndices(is,&idx);CHKERRQ(ierr); } else { ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr); if (is->isperm) { ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block Index set is permutation\n");CHKERRQ(ierr); } ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block size %D\n",bs);CHKERRQ(ierr); ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Number of block indices in set %D\n",n);CHKERRQ(ierr); ierr = PetscViewerASCIISynchronizedPrintf(viewer,"The first indices of each block are\n");CHKERRQ(ierr); for (i=0; i<n; i++) { ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block %D Index %D\n",i,idx[i]);CHKERRQ(ierr); } ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); ierr = PetscViewerASCIIPopSynchronized(viewer);CHKERRQ(ierr); } } PetscFunctionReturn(0); }

PetscErrorCode DMDestroy_AKKT(DM dm) { DM_AKKT *kkt = (DM_AKKT*)(dm->data); PetscInt i; PetscErrorCode ierr; PetscFunctionBegin; ierr = MatDestroy(&(kkt->Aff)); CHKERRQ(ierr); ierr = DMDestroy(&(kkt->dm)); CHKERRQ(ierr); for(i = 0; i < 2; ++i) { ierr = DMDestroy(&(kkt->dmf[i])); CHKERRQ(ierr); ierr = ISDestroy(&(kkt->isf[i])); CHKERRQ(ierr); ierr = PetscFree(kkt->names[i]); CHKERRQ(ierr); } ierr = DMDestroy(&(kkt->cdm)); CHKERRQ(ierr); ierr = MatDestroy(&(kkt->Pfc)); CHKERRQ(ierr); ierr = PetscFree(kkt); CHKERRQ(ierr); PetscFunctionReturn(0); }

static PetscErrorCode PCDestroy_Redistribute(PC pc) { PC_Redistribute *red = (PC_Redistribute*)pc->data; PetscErrorCode ierr; PetscFunctionBegin; ierr = VecScatterDestroy(&red->scatter);CHKERRQ(ierr); ierr = ISDestroy(&red->is);CHKERRQ(ierr); ierr = VecDestroy(&red->b);CHKERRQ(ierr); ierr = VecDestroy(&red->x);CHKERRQ(ierr); ierr = KSPDestroy(&red->ksp);CHKERRQ(ierr); ierr = VecDestroy(&red->work);CHKERRQ(ierr); ierr = PetscFree(red->drows);CHKERRQ(ierr); ierr = PetscFree(red->diag);CHKERRQ(ierr); ierr = PetscFree(pc->data);CHKERRQ(ierr); PetscFunctionReturn(0); }

PetscErrorCode DMDestroy_SNESVI(DM_SNESVI *dmsnesvi) { PetscErrorCode ierr; PetscFunctionBegin; /* reset the base methods in the DM object that were changed when the DM_SNESVI was reset */ dmsnesvi->dm->ops->createinterpolation = dmsnesvi->createinterpolation; dmsnesvi->dm->ops->coarsen = dmsnesvi->coarsen; dmsnesvi->dm->ops->createglobalvector = dmsnesvi->createglobalvector; /* need to clear out this vectors because some of them may not have a reference to the DM but they are counted as having references to the DM in DMDestroy() */ ierr = DMClearGlobalVectors(dmsnesvi->dm);CHKERRQ(ierr); ierr = ISDestroy(&dmsnesvi->inactive);CHKERRQ(ierr); ierr = PetscFree(dmsnesvi);CHKERRQ(ierr); PetscFunctionReturn(0); }

/* There is a problem here with uninterpolated meshes. The index in numDof[] is not dimension in this case, but sieve depth. */ PetscErrorCode SetupSection(DM dm, AppCtx *user) { PetscSection section; const PetscInt numFields = NUM_FIELDS; PetscInt dim = user->dim; PetscInt numBC = 0; PetscInt bcFields[1] = {0}; IS bcPoints[1] = {NULL}; PetscInt numComp[NUM_FIELDS]; const PetscInt *numFieldDof[NUM_FIELDS]; PetscInt *numDof; PetscInt f, d; PetscErrorCode ierr; PetscFunctionBeginUser; ierr = PetscFEGetNumComponents(user->fe[0], &numComp[0]);CHKERRQ(ierr); ierr = PetscFEGetNumComponents(user->fe[1], &numComp[1]);CHKERRQ(ierr); ierr = PetscFEGetNumDof(user->fe[0], &numFieldDof[0]);CHKERRQ(ierr); ierr = PetscFEGetNumDof(user->fe[1], &numFieldDof[1]);CHKERRQ(ierr); ierr = PetscMalloc(NUM_FIELDS*(dim+1) * sizeof(PetscInt), &numDof);CHKERRQ(ierr); for (f = 0; f < NUM_FIELDS; ++f) { for (d = 0; d <= dim; ++d) { numDof[f*(dim+1)+d] = numFieldDof[f][d]; } } for (f = 0; f < numFields; ++f) { for (d = 1; d < dim; ++d) { if ((numDof[f*(dim+1)+d] > 0) && !user->interpolate) SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONG, "Mesh must be interpolated when unknowns are specified on edges or faces."); } } if (user->bcType == DIRICHLET) { numBC = 1; ierr = DMPlexGetStratumIS(dm, "marker", 1, &bcPoints[0]);CHKERRQ(ierr); } ierr = DMPlexCreateSection(dm, dim, numFields, numComp, numDof, numBC, bcFields, bcPoints, §ion);CHKERRQ(ierr); ierr = PetscSectionSetFieldName(section, 0, "velocity");CHKERRQ(ierr); ierr = PetscSectionSetFieldName(section, 1, "pressure");CHKERRQ(ierr); ierr = DMSetDefaultSection(dm, section);CHKERRQ(ierr); ierr = PetscSectionDestroy(§ion);CHKERRQ(ierr); if (user->bcType == DIRICHLET) { ierr = ISDestroy(&bcPoints[0]);CHKERRQ(ierr); } ierr = PetscFree(numDof);CHKERRQ(ierr); PetscFunctionReturn(0); }

/* DMLabelMakeInvalid_Private - Transfer stratum data from the sorted list format to the hash format Input parameter: + label - The DMLabel - v - The stratum value Output parameter: . label - The DMLabel with stratum in hash format Level: developer .seealso: DMLabelCreate() */ static PetscErrorCode DMLabelMakeInvalid_Private(DMLabel label, PetscInt v) { PETSC_UNUSED PetscHashIIter ret, iter; PetscInt p; const PetscInt *points; PetscErrorCode ierr; PetscFunctionBegin; if (!label->validIS[v]) PetscFunctionReturn(0); if (label->points[v]) { ierr = ISGetIndices(label->points[v],&points);CHKERRQ(ierr); for (p = 0; p < label->stratumSizes[v]; ++p) PetscHashIPut(label->ht[v], points[p], ret, iter); ierr = ISRestoreIndices(label->points[v],&points);CHKERRQ(ierr); ierr = ISDestroy(&(label->points[v]));CHKERRQ(ierr); } label->validIS[v] = PETSC_FALSE; PetscFunctionReturn(0); }

static PetscErrorCode test5(DM dm, AppCtx *options) { IS cells; Vec locX, locX_t, locA; PetscScalar *u, *u_t, *a; PetscErrorCode ierr; PetscFunctionBegin; locX_t = NULL; locA = NULL; ierr = ISCreateStride(PETSC_COMM_SELF, 0, 0, 1, &cells);CHKERRQ(ierr); ierr = DMGetLocalVector(dm, &locX);CHKERRQ(ierr); ierr = DMPlexGetCellFields( dm, cells, locX, locX_t, locA, &u, &u_t, &a);CHKERRQ(ierr); ierr = DMPlexRestoreCellFields(dm, cells, locX, locX_t, locA, &u, &u_t, &a);CHKERRQ(ierr); ierr = DMRestoreLocalVector(dm, &locX);CHKERRQ(ierr); ierr = ISDestroy(&cells);CHKERRQ(ierr); PetscFunctionReturn(0); }

int main(int argc,char **argv) { PetscErrorCode ierr; PetscInt step = 2; IS is; ierr = PetscInitialize(&argc,&argv,(char*)0,help);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,"-step",&step,NULL);CHKERRQ(ierr); ierr = ISCreateStride(PETSC_COMM_SELF,10,0,step,&is);CHKERRQ(ierr); ierr = ISToGeneral(is);CHKERRQ(ierr); ierr = ISDestroy(&is);CHKERRQ(ierr); ierr = PetscFinalize(); return 0; }

static PetscErrorCode GPCGGradProjections(Tao tao) { PetscErrorCode ierr; TAO_GPCG *gpcg = (TAO_GPCG *)tao->data; PetscInt i; PetscReal actred=-1.0,actred_max=0.0, gAg,gtg=gpcg->gnorm,alpha; PetscReal f_new,gdx,stepsize; Vec DX=tao->stepdirection,XL=tao->XL,XU=tao->XU,Work=gpcg->Work; Vec X=tao->solution,G=tao->gradient; TaoLineSearchConvergedReason lsflag=TAOLINESEARCH_CONTINUE_ITERATING; /* The free, active, and binding variables should be already identified */ PetscFunctionBegin; for (i=0;i<gpcg->maxgpits;i++){ if ( -actred <= (gpcg->pg_ftol)*actred_max) break; ierr = VecBoundGradientProjection(G,X,XL,XU,DX);CHKERRQ(ierr); ierr = VecScale(DX,-1.0);CHKERRQ(ierr); ierr = VecDot(DX,G,&gdx);CHKERRQ(ierr); ierr = MatMult(tao->hessian,DX,Work);CHKERRQ(ierr); ierr = VecDot(DX,Work,&gAg);CHKERRQ(ierr); gpcg->gp_iterates++; gpcg->total_gp_its++; gtg=-gdx; alpha = PetscAbsReal(gtg/gAg); ierr = TaoLineSearchSetInitialStepLength(tao->linesearch,alpha);CHKERRQ(ierr); f_new=gpcg->f; ierr = TaoLineSearchApply(tao->linesearch,X,&f_new,G,DX,&stepsize,&lsflag);CHKERRQ(ierr); /* Update the iterate */ actred = f_new - gpcg->f; actred_max = PetscMax(actred_max,-(f_new - gpcg->f)); gpcg->f = f_new; ierr = ISDestroy(&gpcg->Free_Local);CHKERRQ(ierr); ierr = VecWhichBetween(XL,X,XU,&gpcg->Free_Local);CHKERRQ(ierr); } gpcg->gnorm=gtg; PetscFunctionReturn(0); } /* End gradient projections */

int main(int argc,char **args) { Mat C; PetscInt i,j,m = 5,n = 5,Ii,J; PetscErrorCode ierr; PetscScalar v,five = 5.0; IS isrow; PetscBool keepnonzeropattern; ierr = PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr; /* create the matrix for the five point stencil, YET AGAIN*/ ierr = MatCreate(PETSC_COMM_SELF,&C);CHKERRQ(ierr); ierr = MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,m*n,m*n);CHKERRQ(ierr); ierr = MatSetFromOptions(C);CHKERRQ(ierr); ierr = MatSetUp(C);CHKERRQ(ierr); for (i=0; i<m; i++) { for (j=0; j<n; j++) { v = -1.0; Ii = j + n*i; if (i>0) {J = Ii - n; ierr = MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);CHKERRQ(ierr);} if (i<m-1) {J = Ii + n; ierr = MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);CHKERRQ(ierr);} if (j>0) {J = Ii - 1; ierr = MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);CHKERRQ(ierr);} if (j<n-1) {J = Ii + 1; ierr = MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);CHKERRQ(ierr);} v = 4.0; ierr = MatSetValues(C,1,&Ii,1,&Ii,&v,INSERT_VALUES);CHKERRQ(ierr); } } ierr = MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); ierr = MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr); ierr = ISCreateStride(PETSC_COMM_SELF,(m*n)/2,0,2,&isrow);CHKERRQ(ierr); ierr = PetscOptionsHasName(NULL,NULL,"-keep_nonzero_pattern",&keepnonzeropattern);CHKERRQ(ierr); if (keepnonzeropattern) { ierr = MatSetOption(C,MAT_KEEP_NONZERO_PATTERN,PETSC_TRUE);CHKERRQ(ierr); } ierr = MatZeroRowsIS(C,isrow,five,0,0);CHKERRQ(ierr); ierr = MatView(C,PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); ierr = ISDestroy(&isrow);CHKERRQ(ierr); ierr = MatDestroy(&C);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; }

static PetscErrorCode TaoDestroy_TRON(Tao tao) { TAO_TRON *tron = (TAO_TRON *)tao->data; PetscErrorCode ierr; PetscFunctionBegin; ierr = VecDestroy(&tron->X_New);CHKERRQ(ierr); ierr = VecDestroy(&tron->G_New);CHKERRQ(ierr); ierr = VecDestroy(&tron->Work);CHKERRQ(ierr); ierr = VecDestroy(&tron->DXFree);CHKERRQ(ierr); ierr = VecDestroy(&tron->R);CHKERRQ(ierr); ierr = VecDestroy(&tron->diag);CHKERRQ(ierr); ierr = VecScatterDestroy(&tron->scatter);CHKERRQ(ierr); ierr = ISDestroy(&tron->Free_Local);CHKERRQ(ierr); ierr = MatDestroy(&tron->H_sub);CHKERRQ(ierr); ierr = MatDestroy(&tron->Hpre_sub);CHKERRQ(ierr); ierr = PetscFree(tao->data);CHKERRQ(ierr); PetscFunctionReturn(0); }

PetscErrorCode SNESReset_Multiblock(SNES snes) { SNES_Multiblock *mb = (SNES_Multiblock *) snes->data; BlockDesc blocks = mb->blocks, next; PetscErrorCode ierr; PetscFunctionBegin; while (blocks) { ierr = SNESReset(blocks->snes);CHKERRQ(ierr); #if 0 ierr = VecDestroy(&blocks->x);CHKERRQ(ierr); #endif ierr = VecScatterDestroy(&blocks->sctx);CHKERRQ(ierr); ierr = ISDestroy(&blocks->is);CHKERRQ(ierr); next = blocks->next; blocks = next; } PetscFunctionReturn(0); }

PetscErrorCode DMLabelFilter(DMLabel label, PetscInt start, PetscInt end) { PetscInt v; PetscErrorCode ierr; PetscFunctionBegin; ierr = DMLabelMakeAllValid_Private(label);CHKERRQ(ierr); label->pStart = start; label->pEnd = end; if (label->bt) {ierr = PetscBTDestroy(&label->bt);CHKERRQ(ierr);} /* Could squish offsets, but would only make sense if I reallocate the storage */ for (v = 0; v < label->numStrata; ++v) { PetscInt off, q; const PetscInt *points; PetscInt *pointsNew = NULL; ierr = ISGetIndices(label->points[v],&points);CHKERRQ(ierr); for (off = 0, q = 0; q < label->stratumSizes[v]; ++q) { const PetscInt point = points[q]; if ((point < start) || (point >= end)) { if (!pointsNew) { ierr = PetscMalloc1(label->stratumSizes[v],&pointsNew);CHKERRQ(ierr); ierr = PetscMemcpy(pointsNew,points,(size_t) off * sizeof(PetscInt));CHKERRQ(ierr); } continue; } if (pointsNew) { pointsNew[off++] = point; } } ierr = ISRestoreIndices(label->points[v],&points);CHKERRQ(ierr); if (pointsNew) { ierr = ISDestroy(&(label->points[v]));CHKERRQ(ierr); ierr = ISCreateGeneral(PETSC_COMM_SELF,off,pointsNew,PETSC_OWN_POINTER,&(label->points[v]));CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject) (label->points[v]), "indices");CHKERRQ(ierr); } label->stratumSizes[v] = off; } ierr = DMLabelCreateIndex(label, start, end);CHKERRQ(ierr); PetscFunctionReturn(0); }

PetscErrorCode DiffIE(Vec originalVec, Vec reducedVec, Vec Distance, Vec nParticlePerCube) { // Find the distance between 2 solutions originalVec and reducedVec PetscInt s,t; PetscInt n,xstart,xend; PetscScalar tmp,v,diff; Vec vec; VecScatter scat; IS is; PetscFunctionBegin; VecGetOwnershipRange(originalVec,&xstart,&xend); VecGetSize(reducedVec,&n); VecCreate(PETSC_COMM_SELF,&vec); VecSetSizes(vec,PETSC_DECIDE,n); VecSetFromOptions(vec); ISCreateStride(PETSC_COMM_WORLD,n,0,1,&is); VecScatterCreate(reducedVec,PETSC_NULL,vec,is,&scat); //VecScatterCreateToAll(reducedVec,&scat,&vec); VecScatterBegin(scat,reducedVec,vec,INSERT_VALUES,SCATTER_FORWARD); VecScatterEnd(scat,reducedVec,vec,INSERT_VALUES,SCATTER_FORWARD); for(s=xstart;s<xend;s++) { t = ScatIE.FindCube(s); VecGetValues(vec,1,&t,&tmp); VecGetValues(originalVec,1,&s,&v); diff = cabs(v - tmp); VecSetValues(Distance,1,&t,&diff,ADD_VALUES); tmp = 1; VecSetValues(nParticlePerCube,1,&t,&tmp,ADD_VALUES); } VecDestroy(&vec); VecScatterDestroy(&scat); ISDestroy(&is); PetscFunctionReturn(0); }

PetscErrorCode ISInvertPermutation_Stride(IS is,PetscInt nlocal,IS *perm) { IS_Stride *isstride = (IS_Stride*)is->data; PetscErrorCode ierr; PetscFunctionBegin; if (is->isidentity) { ierr = ISCreateStride(PETSC_COMM_SELF,isstride->n,0,1,perm);CHKERRQ(ierr); } else { IS tmp; const PetscInt *indices,n = isstride->n; ierr = ISGetIndices(is,&indices);CHKERRQ(ierr); ierr = ISCreateGeneral(PetscObjectComm((PetscObject)is),n,indices,PETSC_COPY_VALUES,&tmp);CHKERRQ(ierr); ierr = ISSetPermutation(tmp);CHKERRQ(ierr); ierr = ISRestoreIndices(is,&indices);CHKERRQ(ierr); ierr = ISInvertPermutation(tmp,nlocal,perm);CHKERRQ(ierr); ierr = ISDestroy(&tmp);CHKERRQ(ierr); } PetscFunctionReturn(0); }

int SkewSymmetricScatter(Vec *x,PetscScalar *cacheScalar ,PetscInt *cacheInt, PetscInt n2,PetscInt Istart,PetscInt localsizex , VecScatter *ctx){ PetscInt i,k; IS isbc; Vec bcvec; VecCreateSeqWithArray(MPI_COMM_SELF,localsizex*4,cacheScalar,&bcvec); k = 0; for(i=0;i<localsizex;i++){*(cacheInt+k)= n2*(n2*2-Istart)-1-i*n2;k++;} for(i=0;i<localsizex;i++){*(cacheInt+k)= n2*(n2*2-Istart)-2-i*n2;k++;} for(i=0;i<localsizex;i++){*(cacheInt+k)= n2*(n2*2-Istart)-n2+1-i*n2;k++;} for(i=0;i<localsizex;i++){*(cacheInt+k)= n2*(n2*2-Istart)-n2-i*n2;k++;} ISCreateGeneralWithArray(MPI_COMM_WORLD,4*localsizex,cacheInt,&isbc); VecScatterCreate(*x,isbc,bcvec,PETSC_NULL,ctx); ISDestroy(isbc); return 0; }

static PetscErrorCode test6(DM dm, AppCtx *options) { IS cells; Vec locX, locX_t, locA; PetscScalar *u, *u_t, *a; PetscMPIInt rank; PetscErrorCode ierr; PetscFunctionBegin; ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)dm), &rank);CHKERRQ(ierr); locX_t = NULL; locA = NULL; ierr = ISCreateStride(PETSC_COMM_SELF, rank ? 0 : 1, 0, 1, &cells);CHKERRQ(ierr); ierr = DMGetLocalVector(dm, &locX);CHKERRQ(ierr); ierr = DMPlexGetCellFields( dm, cells, locX, locX_t, locA, &u, &u_t, &a);CHKERRQ(ierr); ierr = DMPlexRestoreCellFields(dm, cells, locX, locX_t, locA, &u, &u_t, &a);CHKERRQ(ierr); ierr = DMRestoreLocalVector(dm, &locX);CHKERRQ(ierr); ierr = ISDestroy(&cells);CHKERRQ(ierr); PetscFunctionReturn(0); }

/*@C DMSwarmViewXDMF - Write DMSwarm fields to an XDMF3 file Collective on DM Input parameters: + dm - the DMSwarm - filename - the file name of the XDMF file (must have the extension .xmf) Level: beginner Notes: Only fields user registered with data type PETSC_DOUBLE or PETSC_INT will be written into the file .seealso: DMSwarmViewFieldsXDMF() @*/ PETSC_EXTERN PetscErrorCode DMSwarmViewXDMF(DM dm,const char filename[]) { DM_Swarm *swarm = (DM_Swarm*)dm->data; PetscErrorCode ierr; Vec dvec; PetscInt f; PetscViewer viewer; PetscFunctionBegin; ierr = private_PetscViewerCreate_XDMF(PetscObjectComm((PetscObject)dm),filename,&viewer);CHKERRQ(ierr); ierr = private_DMSwarmView_XDMF(dm,viewer);CHKERRQ(ierr); for (f=4; f<swarm->db->nfields; f++) { /* only examine user defined fields - the first 4 are internally created by DMSwarmPIC */ DMSwarmDataField field; /* query field type - accept all those of type PETSC_DOUBLE */ field = swarm->db->field[f]; if (field->petsc_type == PETSC_DOUBLE) { ierr = DMSwarmCreateGlobalVectorFromField(dm,field->name,&dvec);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject)dvec,field->name);CHKERRQ(ierr); ierr = private_VecView_Swarm_XDMF(dvec,viewer);CHKERRQ(ierr); ierr = DMSwarmDestroyGlobalVectorFromField(dm,field->name,&dvec);CHKERRQ(ierr); } else if (field->petsc_type == PETSC_INT) { IS is; PetscInt N; const PetscInt *idx; void *data; ierr = DMSwarmGetLocalSize(dm,&N);CHKERRQ(ierr); ierr = DMSwarmGetField(dm,field->name,NULL,NULL,&data);CHKERRQ(ierr); idx = (const PetscInt*)data; ierr = ISCreateGeneral(PetscObjectComm((PetscObject)dm),N,idx,PETSC_USE_POINTER,&is);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject)is,field->name);CHKERRQ(ierr); ierr = private_ISView_Swarm_XDMF(is,viewer);CHKERRQ(ierr); ierr = ISDestroy(&is);CHKERRQ(ierr); ierr = DMSwarmRestoreField(dm,field->name,NULL,NULL,&data);CHKERRQ(ierr); } } ierr = private_PetscViewerDestroy_XDMF(&viewer);CHKERRQ(ierr); PetscFunctionReturn(0); }

/*@C DMSwarmViewFieldsXDMF - Write a selection of DMSwarm fields to an XDMF3 file Collective on DM Input parameters: + dm - the DMSwarm . filename - the file name of the XDMF file (must have the extension .xmf) . nfields - the number of fields to write into the XDMF file - field_name_list - array of length nfields containing the textual name of fields to write Level: beginner Notes: Only fields registered with data type PETSC_DOUBLE or PETSC_INT can be written into the file .seealso: DMSwarmViewXDMF() @*/ PETSC_EXTERN PetscErrorCode DMSwarmViewFieldsXDMF(DM dm,const char filename[],PetscInt nfields,const char *field_name_list[]) { PetscErrorCode ierr; Vec dvec; PetscInt f,N; PetscViewer viewer; PetscFunctionBegin; ierr = private_PetscViewerCreate_XDMF(PetscObjectComm((PetscObject)dm),filename,&viewer);CHKERRQ(ierr); ierr = private_DMSwarmView_XDMF(dm,viewer);CHKERRQ(ierr); ierr = DMSwarmGetLocalSize(dm,&N);CHKERRQ(ierr); for (f=0; f<nfields; f++) { void *data; PetscDataType type; ierr = DMSwarmGetField(dm,field_name_list[f],NULL,&type,&data);CHKERRQ(ierr); ierr = DMSwarmRestoreField(dm,field_name_list[f],NULL,&type,&data);CHKERRQ(ierr); if (type == PETSC_DOUBLE) { ierr = DMSwarmCreateGlobalVectorFromField(dm,field_name_list[f],&dvec);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject)dvec,field_name_list[f]);CHKERRQ(ierr); ierr = private_VecView_Swarm_XDMF(dvec,viewer);CHKERRQ(ierr); ierr = DMSwarmDestroyGlobalVectorFromField(dm,field_name_list[f],&dvec);CHKERRQ(ierr); } else if (type == PETSC_INT) { IS is; const PetscInt *idx; ierr = DMSwarmGetField(dm,field_name_list[f],NULL,&type,&data);CHKERRQ(ierr); idx = (const PetscInt*)data; ierr = ISCreateGeneral(PetscObjectComm((PetscObject)dm),N,idx,PETSC_USE_POINTER,&is);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject)is,field_name_list[f]);CHKERRQ(ierr); ierr = private_ISView_Swarm_XDMF(is,viewer);CHKERRQ(ierr); ierr = ISDestroy(&is);CHKERRQ(ierr); ierr = DMSwarmRestoreField(dm,field_name_list[f],NULL,&type,&data);CHKERRQ(ierr); } else SETERRQ(PetscObjectComm((PetscObject)dm),PETSC_ERR_SUP,"Can only write PETSC_INT and PETSC_DOUBLE"); } ierr = private_PetscViewerDestroy_XDMF(&viewer);CHKERRQ(ierr); PetscFunctionReturn(0); }

void PetscVector::copyFromArray( char v[] ) { int ierr; Vec sv; IS is; VecScatter ctx; ierr = VecCreateSeq(PETSC_COMM_SELF, n, &sv); assert(ierr == 0); { double * a; ierr = VecGetArray( sv, &a ); assert( ierr == 0); int i; for( i = 0; i < n; i++ ) { a[i] = v[i]; } ierr = VecRestoreArray( sv, &a ); assert( ierr == 0); } ierr = ISCreateStride(PETSC_COMM_WORLD, n, 0, 1, &is); assert( ierr == 0); ierr = VecScatterCreate( sv, is, pv, is, &ctx); assert( ierr == 0); ierr = VecScatterBegin( sv, pv,INSERT_VALUES,SCATTER_FORWARD, ctx); assert( ierr == 0); ierr = VecScatterEnd( sv, pv,INSERT_VALUES,SCATTER_FORWARD, ctx); assert( ierr == 0); ierr = VecScatterDestroy(ctx); assert( ierr == 0); ierr = ISDestroy( is ); assert(ierr == 0); ierr = VecDestroy( sv ); assert(ierr == 0); }

int main(int argc,char **args) { Mat mesh,dual; PetscErrorCode ierr; PetscInt Nvertices = 6; /* total number of vertices */ PetscInt ncells = 2; /* number cells on this process */ PetscInt *ii,*jj; PetscMPIInt size,rank; MatPartitioning part; IS is; PetscInitialize(&argc,&args,(char*)0,help); ierr = MPI_Comm_size(MPI_COMM_WORLD,&size);CHKERRQ(ierr); if (size != 2) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"This example is for exactly two processes"); ierr = MPI_Comm_rank(MPI_COMM_WORLD,&rank);CHKERRQ(ierr); ierr = PetscMalloc(3*sizeof(PetscInt),&ii);CHKERRQ(ierr); ierr = PetscMalloc(6*sizeof(PetscInt),&jj);CHKERRQ(ierr); ii[0] = 0; ii[1] = 3; ii[2] = 6; if (!rank) { jj[0] = 0; jj[1] = 1; jj[2] = 2; jj[3] = 1; jj[4] = 3; jj[5] = 2; } else { jj[0] = 1; jj[1] = 4; jj[2] = 5; jj[3] = 1; jj[4] = 5; jj[5] = 3; } ierr = MatCreateMPIAdj(MPI_COMM_WORLD,ncells,Nvertices,ii,jj,NULL,&mesh);CHKERRQ(ierr); ierr = MatMeshToCellGraph(mesh,2,&dual);CHKERRQ(ierr); ierr = MatView(dual,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = MatPartitioningCreate(MPI_COMM_WORLD,&part);CHKERRQ(ierr); ierr = MatPartitioningSetAdjacency(part,dual);CHKERRQ(ierr); ierr = MatPartitioningSetFromOptions(part);CHKERRQ(ierr); ierr = MatPartitioningApply(part,&is);CHKERRQ(ierr); ierr = ISView(is,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = ISDestroy(&is);CHKERRQ(ierr); ierr = MatPartitioningDestroy(&part);CHKERRQ(ierr); ierr = MatDestroy(&mesh);CHKERRQ(ierr); ierr = MatDestroy(&dual);CHKERRQ(ierr); ierr = PetscFinalize(); return 0; }

PetscErrorCode DMAKKTSetFieldDecomposition(DM dm, PetscInt n, const char* const *names, IS *iss, DM *dms) { PetscBool iskkt; DM_AKKT *kkt = (DM_AKKT*)(dm->data); PetscInt i; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(dm, DM_CLASSID,1); PetscValidPointer(names,3); PetscValidPointer(iss,4); PetscValidPointer(dms,5); ierr = PetscObjectTypeCompare((PetscObject)dm, DMAKKT, &iskkt); CHKERRQ(ierr); if(!iskkt) SETERRQ(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "DM not of type DMAKKT"); if(n < 1 || n > 2) SETERRQ1(((PetscObject)dm)->comm, PETSC_ERR_ARG_WRONG, "Number of parts in decomposition must be between 1 and 2. Got %D instead",n); for(i = 0; i < 2; ++i) { if(kkt->names[i]) { ierr = PetscFree(kkt->names[i]); CHKERRQ(ierr); } if(names[i]){ ierr = PetscStrallocpy(names[i], &(kkt->names[i])); CHKERRQ(ierr); } if(iss[i]) { ierr = PetscObjectReference((PetscObject)iss[i]); CHKERRQ(ierr); } if(kkt->isf[i]) { ierr = ISDestroy(&(kkt->isf[i])); CHKERRQ(ierr); } kkt->isf[i] = iss[i]; if(dms[i]) { ierr = PetscObjectReference((PetscObject)dms[i]); CHKERRQ(ierr); } if(kkt->dmf[i]) { ierr = DMDestroy(&(kkt->dmf[i])); CHKERRQ(ierr); } kkt->dmf[i] = dms[i]; } ierr = DMDestroy(&(kkt->cdm)); CHKERRQ(ierr); ierr = MatDestroy(&(kkt->Pfc)); CHKERRQ(ierr); dm->setupcalled = PETSC_FALSE; PetscFunctionReturn(0); }