static PetscErrorCode PCView_Redundant(PC pc,PetscViewer viewer) { PC_Redundant *red = (PC_Redundant*)pc->data; PetscErrorCode ierr; PetscMPIInt rank; PetscTruth iascii,isstring; PetscViewer subviewer; PetscFunctionBegin; ierr = MPI_Comm_rank(((PetscObject)pc)->comm,&rank);CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_STRING,&isstring);CHKERRQ(ierr); if (iascii) { if (!red->psubcomm) { ierr = PetscViewerASCIIPrintf(viewer," Redundant preconditioner: Not yet setup\n");CHKERRQ(ierr); } else { ierr = PetscViewerASCIIPrintf(viewer," Redundant preconditioner: First (color=0) of %D PCs follows\n",red->nsubcomm);CHKERRQ(ierr); ierr = PetscViewerGetSubcomm(viewer,((PetscObject)red->pc)->comm,&subviewer);CHKERRQ(ierr); if (red->psubcomm->color) { /* only view first redundant pc */ ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); ierr = KSPView(red->ksp,subviewer);CHKERRQ(ierr); ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); } ierr = PetscViewerRestoreSubcomm(viewer,((PetscObject)red->pc)->comm,&subviewer);CHKERRQ(ierr); } } else if (isstring) { ierr = PetscViewerStringSPrintf(viewer," Redundant solver preconditioner");CHKERRQ(ierr); } else { SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported for PC redundant",((PetscObject)viewer)->type_name); } PetscFunctionReturn(0); }
PetscErrorCode PETSCSNES_DLLEXPORT DMMGSetUpLevel(DMMG *dmmg,KSP ksp,PetscInt nlevels) { PetscErrorCode ierr; PetscInt i; PC pc; PetscTruth ismg,ismf,isshell,ismffd; KSP lksp; /* solver internal to the multigrid preconditioner */ MPI_Comm *comms; PetscFunctionBegin; if (!dmmg) SETERRQ(PETSC_ERR_ARG_NULL,"Passing null as DMMG"); /* use fgmres on outer iteration by default */ ierr = KSPSetType(ksp,KSPFGMRES);CHKERRQ(ierr); ierr = KSPGetPC(ksp,&pc);CHKERRQ(ierr); ierr = PCSetType(pc,PCMG);CHKERRQ(ierr); ierr = PetscMalloc(nlevels*sizeof(MPI_Comm),&comms);CHKERRQ(ierr); for (i=0; i<nlevels; i++) { comms[i] = dmmg[i]->comm; } ierr = PCMGSetLevels(pc,nlevels,comms);CHKERRQ(ierr); ierr = PetscFree(comms);CHKERRQ(ierr); ierr = PCMGSetType(pc,PC_MG_FULL);CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject)pc,PCMG,&ismg);CHKERRQ(ierr); if (ismg) { /* set solvers for each level */ for (i=0; i<nlevels; i++) { if (i < nlevels-1) { /* don't set for finest level, they are set in PCApply_MG()*/ ierr = PCMGSetX(pc,i,dmmg[i]->x);CHKERRQ(ierr); ierr = PCMGSetRhs(pc,i,dmmg[i]->b);CHKERRQ(ierr); } if (i > 0) { ierr = PCMGSetR(pc,i,dmmg[i]->r);CHKERRQ(ierr); } /* If using a matrix free multiply and did not provide an explicit matrix to build the preconditioner then must use no preconditioner */ ierr = PetscTypeCompare((PetscObject)dmmg[i]->B,MATSHELL,&isshell);CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject)dmmg[i]->B,MATDAAD,&ismf);CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject)dmmg[i]->B,MATMFFD,&ismffd);CHKERRQ(ierr); if (isshell || ismf || ismffd) { PC lpc; ierr = PCMGGetSmoother(pc,i,&lksp);CHKERRQ(ierr); ierr = KSPGetPC(lksp,&lpc);CHKERRQ(ierr); ierr = PCSetType(lpc,PCNONE);CHKERRQ(ierr); } } /* Set interpolation/restriction between levels */ for (i=1; i<nlevels; i++) { ierr = PCMGSetInterpolation(pc,i,dmmg[i]->R);CHKERRQ(ierr); ierr = PCMGSetRestriction(pc,i,dmmg[i]->R);CHKERRQ(ierr); } } PetscFunctionReturn(0); }
/*@C DMMGView - prints information on a DA based multi-level preconditioner Collective on DMMG and PetscViewer Input Parameter: + dmmg - the context - viewer - the viewer Level: advanced .seealso DMMGCreate(), DMMGDestroy(), DMMGSetMatType() @*/ PetscErrorCode PETSCSNES_DLLEXPORT DMMGView(DMMG *dmmg,PetscViewer viewer) { PetscErrorCode ierr; PetscInt i,nlevels = dmmg[0]->nlevels; PetscMPIInt flag; MPI_Comm comm; PetscTruth iascii,isbinary; PetscFunctionBegin; PetscValidPointer(dmmg,1); PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE,2); ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr); ierr = MPI_Comm_compare(comm,dmmg[0]->comm,&flag);CHKERRQ(ierr); if (flag != MPI_CONGRUENT && flag != MPI_IDENT) { SETERRQ(PETSC_ERR_ARG_NOTSAMECOMM,"Different communicators in the DMMG and the PetscViewer"); } ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_BINARY,&isbinary);CHKERRQ(ierr); if (isbinary) { for (i=0; i<nlevels; i++) { ierr = MatView(dmmg[i]->J,viewer);CHKERRQ(ierr); } for (i=1; i<nlevels; i++) { ierr = MatView(dmmg[i]->R,viewer);CHKERRQ(ierr); } } else { if (iascii) { ierr = PetscViewerASCIIPrintf(viewer,"DMMG Object with %D levels\n",nlevels);CHKERRQ(ierr); if (dmmg[0]->isctype == IS_COLORING_GLOBAL) { ierr = PetscViewerASCIIPrintf(viewer,"Using global (nonghosted) Jacobian coloring computation\n");CHKERRQ(ierr); } else { ierr = PetscViewerASCIIPrintf(viewer,"Using ghosted Jacobian coloring computation\n");CHKERRQ(ierr); } } for (i=0; i<nlevels; i++) { ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); ierr = DMView(dmmg[i]->dm,viewer);CHKERRQ(ierr); ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); } if (iascii) { ierr = PetscViewerASCIIPrintf(viewer,"Using matrix type %s\n",dmmg[nlevels-1]->mtype);CHKERRQ(ierr); } if (DMMGGetKSP(dmmg)) { ierr = KSPView(DMMGGetKSP(dmmg),viewer);CHKERRQ(ierr); } else if (DMMGGetSNES(dmmg)) { ierr = SNESView(DMMGGetSNES(dmmg),viewer);CHKERRQ(ierr); } else if (iascii) { ierr = PetscViewerASCIIPrintf(viewer,"DMMG does not have a SNES or KSP set\n");CHKERRQ(ierr); } } PetscFunctionReturn(0); }
/*@C DMMGSetNullSpace - Indicates the null space in the linear operator (this is needed by the linear solver) Collective on DMMG Input Parameter: + dmmg - the context . has_cnst - is the constant vector in the null space . n - number of null vectors (excluding the possible constant vector) - func - a function that fills an array of vectors with the null vectors (must be orthonormal), may be PETSC_NULL Level: advanced .seealso DMMGCreate(), DMMGDestroy, DMMGSetDM(), DMMGSolve(), MatNullSpaceCreate(), KSPSetNullSpace(), DMMGSetMatType() @*/ PetscErrorCode PETSCSNES_DLLEXPORT DMMGSetNullSpace(DMMG *dmmg,PetscTruth has_cnst,PetscInt n,PetscErrorCode (*func)(DMMG,Vec[])) { PetscErrorCode ierr; PetscInt i,j,nlevels = dmmg[0]->nlevels; Vec *nulls = 0; MatNullSpace nullsp; KSP iksp; PC pc,ipc; PetscTruth ismg,isred; PetscFunctionBegin; if (!dmmg) SETERRQ(PETSC_ERR_ARG_NULL,"Passing null as DMMG"); if (!dmmg[0]->ksp) SETERRQ(PETSC_ERR_ORDER,"Must call AFTER DMMGSetKSP() or DMMGSetSNES()"); if ((n && !func) || (!n && func)) SETERRQ(PETSC_ERR_ARG_INCOMP,"Both n and func() must be set together"); if (n < 0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Cannot have negative number of vectors in null space n = %D",n) for (i=0; i<nlevels; i++) { if (n) { ierr = VecDuplicateVecs(dmmg[i]->b,n,&nulls);CHKERRQ(ierr); ierr = (*func)(dmmg[i],nulls);CHKERRQ(ierr); } ierr = MatNullSpaceCreate(dmmg[i]->comm,has_cnst,n,nulls,&nullsp);CHKERRQ(ierr); ierr = KSPSetNullSpace(dmmg[i]->ksp,nullsp);CHKERRQ(ierr); for (j=i; j<nlevels; j++) { ierr = KSPGetPC(dmmg[j]->ksp,&pc);CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject)pc,PCMG,&ismg);CHKERRQ(ierr); if (ismg) { ierr = PCMGGetSmoother(pc,i,&iksp);CHKERRQ(ierr); ierr = KSPSetNullSpace(iksp, nullsp);CHKERRQ(ierr); } } ierr = MatNullSpaceDestroy(nullsp);CHKERRQ(ierr); if (n) { ierr = VecDestroyVecs(nulls,n);CHKERRQ(ierr); } } /* make all the coarse grid solvers have LU shift since they are singular */ for (i=0; i<nlevels; i++) { ierr = KSPGetPC(dmmg[i]->ksp,&pc);CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject)pc,PCMG,&ismg);CHKERRQ(ierr); if (ismg) { ierr = PCMGGetSmoother(pc,0,&iksp);CHKERRQ(ierr); ierr = KSPGetPC(iksp,&ipc);CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject)ipc,PCREDUNDANT,&isred);CHKERRQ(ierr); if (isred) { ierr = PCRedundantGetPC(ipc,&ipc);CHKERRQ(ierr); } ierr = PCFactorSetShiftType(ipc,MAT_SHIFT_POSITIVE_DEFINITE);CHKERRQ(ierr); } } PetscFunctionReturn(0); }
PetscErrorCode PETSCTS_DLLEXPORT TSGLAdaptView(TSGLAdapt adapt,PetscViewer viewer) { PetscErrorCode ierr; PetscTruth iascii; PetscFunctionBegin; ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); if (iascii) { if (((PetscObject)adapt)->prefix) { ierr = PetscViewerASCIIPrintf(viewer,"TSGLAdapt object: (%s)\n",((PetscObject)adapt)->prefix);CHKERRQ(ierr); } else { ierr = PetscViewerASCIIPrintf(viewer,"TSGLAdapt object:\n");CHKERRQ(ierr); } ierr = PetscViewerASCIIPrintf(viewer," type: %s\n",((PetscObject)adapt)->type_name?((PetscObject)adapt)->type_name:"(not set yet)");CHKERRQ(ierr); if (adapt->ops->view) { ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); ierr = (*adapt->ops->view)(adapt,viewer);CHKERRQ(ierr); ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); } } else { SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported for TS_GL",((PetscObject)viewer)->type_name); } PetscFunctionReturn(0); }
/*@C PetscViewerDrawGetDrawAxis - Returns PetscDrawAxis object from PetscViewer object. This PetscDrawAxis object may then be used to perform graphics using PetscDrawAxisXXX() commands. Not Collective (but PetscDrawAxis object will be parallel if PetscViewer is) Input Parameter: + viewer - the PetscViewer (created with PetscViewerDrawOpen() - windownumber - indicates which subwindow (usually 0) Ouput Parameter: . drawaxis - the draw axis object Level: advanced Concepts: line graph^accessing context .seealso: PetscViewerDrawGetDraw(), PetscViewerDrawGetLG(), PetscViewerDrawOpen() @*/ PetscErrorCode PETSC_DLLEXPORT PetscViewerDrawGetDrawAxis(PetscViewer viewer,PetscInt windownumber,PetscDrawAxis *drawaxis) { PetscErrorCode ierr; PetscTruth isdraw; PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;; PetscFunctionBegin; PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE,1); PetscValidPointer(drawaxis,3); ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_DRAW,&isdraw);CHKERRQ(ierr); if (!isdraw) { SETERRQ(PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer"); } if (windownumber < 0) { SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative"); } if (windownumber+vdraw->draw_base >= vdraw->draw_max || !vdraw->draw[windownumber+vdraw->draw_base]) { ierr = PetscViewerDrawGetDraw(viewer,windownumber,PETSC_NULL);CHKERRQ(ierr); } if (!vdraw->drawaxis[windownumber+vdraw->draw_base]) { ierr = PetscDrawAxisCreate(vdraw->draw[windownumber+vdraw->draw_base],&vdraw->drawaxis[windownumber+vdraw->draw_base]);CHKERRQ(ierr); ierr = PetscLogObjectParent(viewer,vdraw->drawaxis[windownumber+vdraw->draw_base]);CHKERRQ(ierr); } *drawaxis = vdraw->drawaxis[windownumber+vdraw->draw_base]; PetscFunctionReturn(0); }
EXTERN_C_END #undef __FUNCT__ #define __FUNCT__ "PetscViewerDrawClear" /*@ PetscViewerDrawClear - Clears a PetscDraw graphic associated with a PetscViewer. Not Collective Input Parameter: . viewer - the PetscViewer Level: intermediate .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), @*/ PetscErrorCode PETSC_DLLEXPORT PetscViewerDrawClear(PetscViewer viewer) { PetscErrorCode ierr; PetscInt i; PetscTruth isdraw; PetscViewer_Draw *vdraw; PetscFunctionBegin; ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_DRAW,&isdraw);CHKERRQ(ierr); if (isdraw) { vdraw = (PetscViewer_Draw*)viewer->data; for (i=0; i<vdraw->draw_max; i++) { if (vdraw->draw[i]) {ierr = PetscDrawClear(vdraw->draw[i]);CHKERRQ(ierr);} } } PetscFunctionReturn(0); }
/** Create a cache for Dirichlet part of closure vector, and scatter from global closure to Dirichlet cache. @arg[in] gvec Global vector @arg[out] dcache New vector to hold the Dirichlet values @arg[out] dscat Scatter from global closure to \a dcache @note This could be local but it doesn't cost anything to make it global. **/ dErr VecDohpCreateDirichletCache(Vec gvec,Vec *dcache,VecScatter *dscat) { MPI_Comm comm; dErr err; dBool isdohp; IS from; Vec gc; dInt n,nc,crstart; dFunctionBegin; dValidHeader(gvec,VEC_CLASSID,1); dValidPointer(dcache,2); dValidPointer(dscat,3); err = PetscTypeCompare((PetscObject)gvec,VECDOHP,&isdohp);dCHK(err); if (!isdohp) dERROR(PETSC_COMM_SELF,PETSC_ERR_SUP,"Vec type %s",((PetscObject)gvec)->type_name); err = PetscObjectGetComm((PetscObject)gvec,&comm);dCHK(err); err = VecGetLocalSize(gvec,&n);dCHK(err); err = VecDohpGetClosure(gvec,&gc);dCHK(err); err = VecGetLocalSize(gc,&nc);dCHK(err); err = VecGetOwnershipRange(gc,&crstart,NULL);dCHK(err); err = VecCreateMPI(comm,nc-n,PETSC_DECIDE,dcache);dCHK(err); err = ISCreateStride(comm,nc-n,crstart+n,1,&from);dCHK(err); err = VecScatterCreate(gc,from,*dcache,NULL,dscat);dCHK(err); err = VecDohpRestoreClosure(gvec,&gc);dCHK(err); err = ISDestroy(&from);dCHK(err); /* \todo deal with rotations */ dFunctionReturn(0); }
/*@C ISLocalToGlobalMappingView - View a local to global mapping Not Collective Input Parameters: + ltog - local to global mapping - viewer - viewer Level: advanced Concepts: mapping^local to global .seealso: ISLocalToGlobalMappingDestroy(), ISLocalToGlobalMappingCreate() @*/ PetscErrorCode PETSCVEC_DLLEXPORT ISLocalToGlobalMappingView(ISLocalToGlobalMapping mapping,PetscViewer viewer) { PetscInt i; PetscMPIInt rank; PetscTruth iascii; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(mapping,IS_LTOGM_COOKIE,1); if (!viewer) { ierr = PetscViewerASCIIGetStdout(((PetscObject)mapping)->comm,&viewer);CHKERRQ(ierr); } PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE,2); ierr = MPI_Comm_rank(((PetscObject)mapping)->comm,&rank);CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); if (iascii) { for (i=0; i<mapping->n; i++) { ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] %d %d\n",rank,i,mapping->indices[i]);CHKERRQ(ierr); } ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); } else { SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported for ISLocalToGlobalMapping",((PetscObject)viewer)->type_name); } PetscFunctionReturn(0); }
static PetscErrorCode PCView_KSP(PC pc,PetscViewer viewer) { PC_KSP *jac = (PC_KSP*)pc->data; PetscErrorCode ierr; PetscTruth iascii; PetscFunctionBegin; if (!jac->ksp) {ierr = PCKSPCreateKSP_KSP(pc);CHKERRQ(ierr);} ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); if (iascii) { if (jac->use_true_matrix) { ierr = PetscViewerASCIIPrintf(viewer,"Using true matrix (not preconditioner matrix) on inner solve\n");CHKERRQ(ierr); } ierr = PetscViewerASCIIPrintf(viewer,"KSP and PC on KSP preconditioner follow\n");CHKERRQ(ierr); ierr = PetscViewerASCIIPrintf(viewer,"---------------------------------\n");CHKERRQ(ierr); } else { SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported for this object",((PetscObject)viewer)->type_name); } ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); ierr = KSPView(jac->ksp,viewer);CHKERRQ(ierr); ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); if (iascii) { ierr = PetscViewerASCIIPrintf(viewer,"---------------------------------\n");CHKERRQ(ierr); } PetscFunctionReturn(0); }
/*@C MatSetType - Builds matrix object for a particular matrix type Collective on Mat Input Parameters: + mat - the matrix object - matype - matrix type Options Database Key: . -mat_type <method> - Sets the type; use -help for a list of available methods (for instance, seqaij) Notes: See "${PETSC_DIR}/include/petscmat.h" for available methods Level: intermediate .keywords: Mat, MatType, set, method .seealso: PCSetType(), VecSetType(), MatCreate(), MatType, Mat @*/ PetscErrorCode PETSCMAT_DLLEXPORT MatSetType(Mat mat, const MatType matype) { PetscErrorCode ierr,(*r)(Mat); PetscTruth sametype; PetscFunctionBegin; PetscValidHeaderSpecific(mat,MAT_COOKIE,1); ierr = PetscTypeCompare((PetscObject)mat,matype,&sametype);CHKERRQ(ierr); if (sametype) PetscFunctionReturn(0); ierr = PetscFListFind(MatList,((PetscObject)mat)->comm,matype,(void(**)(void))&r);CHKERRQ(ierr); if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown Mat type given: %s",matype); /* free the old data structure if it existed */ if (mat->ops->destroy) { ierr = MatPreallocated(mat);CHKERRQ(ierr); ierr = (*mat->ops->destroy)(mat);CHKERRQ(ierr); mat->ops->destroy = PETSC_NULL; mat->preallocated = PETSC_FALSE; } /* create the new data structure */ if (mat->rmap->n < 0 && mat->rmap->N < 0 && mat->cmap->n < 0 && mat->cmap->N < 0) { mat->ops->create = r; } else { ierr = (*r)(mat);CHKERRQ(ierr); } ierr = PetscPublishAll(mat);CHKERRQ(ierr); PetscFunctionReturn(0); }
dErr dUnitsView(dUnits un,dViewer viewer) { dBool iascii; dErr err; dFunctionBegin; dValidHeader(un,dUNITS_CLASSID,1); if (!viewer) {err = PetscViewerASCIIGetStdout(((dObject)un)->comm,&viewer);dCHK(err);} dValidHeader(viewer,PETSC_VIEWER_CLASSID,2); PetscCheckSameComm(un,1,viewer,2); err = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);dCHK(err); if (iascii) { err = PetscObjectPrintClassNamePrefixType((PetscObject)un,viewer,"Units Manager");dCHK(err); err = PetscViewerASCIIPushTab(viewer);dCHK(err); for (dInt i=0; i<un->nalloc && un->list[i]; i++) { dUnit u = un->list[i]; err = PetscViewerASCIIPrintf(viewer,"%-12s: 1 internal unit = %10.4e %s (%s) = %10.4e %s\n", dUnitQuantityName(u),dUnitDimensionalize(u,1.0),dUnitName(u),dUnitShortName(u),dUnitDimensionalizeSI(u,1.0),dUnitSIName(u));dCHK(err); err = PetscViewerASCIIPrintf(viewer,"%-12s 1 %s = %10.4e %s\n","",dUnitShortName(u),dUnitDimensionalizeSI(u,dUnitNonDimensionalize(u,1.0)),dUnitSIName(u));dCHK(err); } err = PetscViewerASCIIPopTab(viewer);dCHK(err); } else dERROR(((dObject)un)->comm,PETSC_ERR_SUP,"Viewer type %s not supported",((PetscObject)viewer)->type_name); dFunctionReturn(0); }
PetscErrorCode CharacteristicView_DA(Characteristic c, PetscViewer viewer) { Characteristic_DA *da = (Characteristic_DA *) c->data; PetscTruth iascii, isstring; PetscErrorCode ierr; PetscFunctionBegin; /* Pull out field names from DA */ ierr = PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_STRING, &isstring);CHKERRQ(ierr); if (iascii) { ierr = PetscViewerASCIIPrintf(viewer," DA: dummy=%D\n", da->dummy);CHKERRQ(ierr); } else if (isstring) { ierr = PetscViewerStringSPrintf(viewer,"dummy %D", da->dummy);CHKERRQ(ierr); } else { SETERRQ1(PETSC_ERR_SUP, "Viewer type %s not supported for Characteristic DA", ((PetscObject) viewer)->type_name); } PetscFunctionReturn(0); }
static PetscErrorCode PCSetUp_CP(PC pc) { PC_CP *cp = (PC_CP*)pc->data; PetscInt i,j,*colcnt; PetscErrorCode ierr; PetscTruth flg; Mat_SeqAIJ *aij = (Mat_SeqAIJ*)pc->pmat->data; PetscFunctionBegin; ierr = PetscTypeCompare((PetscObject)pc->pmat,MATSEQAIJ,&flg);CHKERRQ(ierr); if (!flg) SETERRQ(PETSC_ERR_SUP,"Currently only handles SeqAIJ matrices"); ierr = MatGetLocalSize(pc->pmat,&cp->m,&cp->n);CHKERRQ(ierr); if (cp->m != cp->n) SETERRQ(PETSC_ERR_SUP,"Currently only for square matrices"); if (!cp->work) {ierr = MatGetVecs(pc->pmat,&cp->work,PETSC_NULL);CHKERRQ(ierr);} if (!cp->d) {ierr = PetscMalloc(cp->n*sizeof(PetscScalar),&cp->d);CHKERRQ(ierr);} if (cp->a && pc->flag != SAME_NONZERO_PATTERN) { ierr = PetscFree3(cp->a,cp->i,cp->j);CHKERRQ(ierr); cp->a = 0; } /* convert to column format */ if (!cp->a) { ierr = PetscMalloc3(aij->nz,PetscScalar,&cp->a,cp->n+1,PetscInt,&cp->i,aij->nz,PetscInt,&cp->j);CHKERRQ(ierr); } ierr = PetscMalloc(cp->n*sizeof(PetscInt),&colcnt);CHKERRQ(ierr); ierr = PetscMemzero(colcnt,cp->n*sizeof(PetscInt));CHKERRQ(ierr); for (i=0; i<aij->nz; i++) { colcnt[aij->j[i]]++; } cp->i[0] = 0; for (i=0; i<cp->n; i++) { cp->i[i+1] = cp->i[i] + colcnt[i]; } ierr = PetscMemzero(colcnt,cp->n*sizeof(PetscInt));CHKERRQ(ierr); for (i=0; i<cp->m; i++) { /* over rows */ for (j=aij->i[i]; j<aij->i[i+1]; j++) { /* over columns in row */ cp->j[cp->i[aij->j[j]]+colcnt[aij->j[j]]] = i; cp->a[cp->i[aij->j[j]]+colcnt[aij->j[j]]++] = aij->a[j]; } } ierr = PetscFree(colcnt);CHKERRQ(ierr); /* compute sum of squares of each column d[] */ for (i=0; i<cp->n; i++) { /* over columns */ cp->d[i] = 0.; for (j=cp->i[i]; j<cp->i[i+1]; j++) { /* over rows in column */ cp->d[i] += cp->a[j]*cp->a[j]; } cp->d[i] = 1.0/cp->d[i]; } PetscFunctionReturn(0); }
/*@ PetscDrawEllipse - Draws an ellipse onto a drawable. Not collective Input Parameters: + draw - The drawing context . x,y - The center . a,b - The major and minor axes lengths - c - The color Level: beginner .keywords: draw, ellipse .seealso: PetscDrawRectangle(), PetscDrawTriangle() @*/ PetscErrorCode PETSC_DLLEXPORT PetscDrawEllipse(PetscDraw draw, PetscReal x, PetscReal y, PetscReal a, PetscReal b, int c) { PetscTruth isdrawnull; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(draw, PETSC_DRAW_COOKIE,1); ierr = PetscTypeCompare((PetscObject) draw, PETSC_DRAW_NULL, &isdrawnull);CHKERRQ(ierr); if (isdrawnull) PetscFunctionReturn(0); ierr = (*draw->ops->ellipse)(draw, x, y, a, b, c);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode PFView_String(void *value,PetscViewer viewer) { PetscErrorCode ierr; PetscTruth iascii; PetscFunctionBegin; ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); if (iascii) { ierr = PetscViewerASCIIPrintf(viewer,"String = %s\n",(char*)value);CHKERRQ(ierr); } PetscFunctionReturn(0); }
/*@ PetscDrawSplitViewPort - Splits a window shared by several processes into smaller view ports. One for each process. Collective on PetscDraw Input Parameter: . draw - the drawing context Level: advanced Concepts: drawing^in subset of window .seealso: PetscDrawDivideViewPort(), PetscDrawSetViewPort() @*/ PetscErrorCode PETSC_DLLEXPORT PetscDrawSplitViewPort(PetscDraw draw) { PetscErrorCode ierr; PetscMPIInt rank,size; int n; PetscTruth isnull; PetscReal xl,xr,yl,yr,h; PetscFunctionBegin; PetscValidHeaderSpecific(draw,PETSC_DRAW_COOKIE,1); ierr = PetscTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull); CHKERRQ(ierr); if (isnull) PetscFunctionReturn(0); ierr = MPI_Comm_rank(((PetscObject)draw)->comm,&rank); CHKERRQ(ierr); ierr = MPI_Comm_size(((PetscObject)draw)->comm,&size); CHKERRQ(ierr); n = (int)(.1 + sqrt((double)size)); while (n*n < size) { n++; } h = 1.0/n; xl = (rank % n)*h; xr = xl + h; yl = (rank/n)*h; yr = yl + h; ierr = PetscDrawLine(draw,xl,yl,xl,yr,PETSC_DRAW_BLACK); CHKERRQ(ierr); ierr = PetscDrawLine(draw,xl,yr,xr,yr,PETSC_DRAW_BLACK); CHKERRQ(ierr); ierr = PetscDrawLine(draw,xr,yr,xr,yl,PETSC_DRAW_BLACK); CHKERRQ(ierr); ierr = PetscDrawLine(draw,xr,yl,xl,yl,PETSC_DRAW_BLACK); CHKERRQ(ierr); ierr = PetscDrawSynchronizedFlush(draw); CHKERRQ(ierr); draw->port_xl = xl + .1*h; draw->port_xr = xr - .1*h; draw->port_yl = yl + .1*h; draw->port_yr = yr - .1*h; if (draw->ops->setviewport) { ierr = (*draw->ops->setviewport)(draw,xl,yl,xr,yr); CHKERRQ(ierr); } PetscFunctionReturn(0); }
/*@C PetscViewerDrawGetDraw - Returns PetscDraw object from PetscViewer object. This PetscDraw object may then be used to perform graphics using PetscDrawXXX() commands. Not collective (but PetscDraw returned will be parallel object if PetscViewer is) Input Parameters: + viewer - the PetscViewer (created with PetscViewerDrawOpen()) - windownumber - indicates which subwindow (usually 0) Ouput Parameter: . draw - the draw object Level: intermediate Concepts: drawing^accessing PetscDraw context from PetscViewer Concepts: graphics .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen() @*/ PetscErrorCode PETSC_DLLEXPORT PetscViewerDrawGetDraw(PetscViewer viewer,PetscInt windownumber,PetscDraw *draw) { PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data; PetscErrorCode ierr; PetscTruth isdraw; char *title; PetscFunctionBegin; PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE,1); if (draw) PetscValidPointer(draw,3); ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_DRAW,&isdraw);CHKERRQ(ierr); if (!isdraw) { SETERRQ(PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer"); } if (windownumber < 0) { SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative"); } windownumber += vdraw->draw_base; if (windownumber >= vdraw->draw_max) { /* allocate twice as many slots as needed */ PetscInt draw_max = vdraw->draw_max; PetscDraw *tdraw = vdraw->draw; PetscDrawLG *drawlg = vdraw->drawlg; PetscDrawAxis *drawaxis = vdraw->drawaxis; vdraw->draw_max = 2*windownumber; ierr = PetscMalloc3(vdraw->draw_max,PetscDraw,&vdraw->draw,vdraw->draw_max,PetscDrawLG,&vdraw->drawlg,vdraw->draw_max,PetscDrawAxis,&vdraw->drawaxis);CHKERRQ(ierr); ierr = PetscMemzero(vdraw->draw,vdraw->draw_max*sizeof(PetscDraw));CHKERRQ(ierr); ierr = PetscMemzero(vdraw->drawlg,vdraw->draw_max*sizeof(PetscDrawLG));CHKERRQ(ierr); ierr = PetscMemzero(vdraw->drawaxis,vdraw->draw_max*sizeof(PetscDrawAxis));CHKERRQ(ierr); ierr = PetscMemcpy(vdraw->draw,tdraw,draw_max*sizeof(PetscDraw));CHKERRQ(ierr); ierr = PetscMemcpy(vdraw->drawlg,drawlg,draw_max*sizeof(PetscDrawLG));CHKERRQ(ierr); ierr = PetscMemcpy(vdraw->drawaxis,drawaxis,draw_max*sizeof(PetscDrawAxis));CHKERRQ(ierr); ierr = PetscFree3(tdraw,drawlg,drawaxis);CHKERRQ(ierr); } if (!vdraw->draw[windownumber]) { if (!windownumber) { title = vdraw->title; } else { char tmp_str[128]; ierr = PetscSNPrintf(tmp_str, 128, "%s:%d", vdraw->title,windownumber);CHKERRQ(ierr); title = tmp_str; } ierr = PetscDrawCreate(((PetscObject)viewer)->comm,vdraw->display,title,PETSC_DECIDE,PETSC_DECIDE,vdraw->w,vdraw->h,&vdraw->draw[windownumber]);CHKERRQ(ierr); ierr = PetscDrawSetFromOptions(vdraw->draw[windownumber]);CHKERRQ(ierr); } if (draw) *draw = vdraw->draw[windownumber]; PetscFunctionReturn(0); }
PetscErrorCode KSPView_BCGSL(KSP ksp, PetscViewer viewer) { KSP_BCGSL *bcgsl = (KSP_BCGSL *)ksp->data; PetscErrorCode ierr; PetscTruth isascii, isstring; PetscFunctionBegin; ierr = PetscTypeCompare((PetscObject)viewer, PETSC_VIEWER_ASCII, &isascii); CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject)viewer, PETSC_VIEWER_STRING, &isstring); CHKERRQ(ierr); if (isascii) { ierr = PetscViewerASCIIPrintf(viewer, " BCGSL: Ell = %D\n", bcgsl->ell); CHKERRQ(ierr); ierr = PetscViewerASCIIPrintf(viewer, " BCGSL: Delta = %lg\n", bcgsl->delta); CHKERRQ(ierr); } else { SETERRQ1(PETSC_ERR_SUP, "Viewer type %s not supported for KSP BCGSL", ((PetscObject)viewer)->type_name); } PetscFunctionReturn(0); }
PetscErrorCode PFView_Matlab(void *value,PetscViewer viewer) { PetscErrorCode ierr; PetscTruth iascii; PF_Matlab *matlab = (PF_Matlab*)value; PetscFunctionBegin; ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); if (iascii) { ierr = PetscViewerASCIIPrintf(viewer,"Matlab Matlab = %s\n",matlab->string);CHKERRQ(ierr); } PetscFunctionReturn(0); }
PetscErrorCode MatView_MPIAdj(Mat A,PetscViewer viewer) { PetscErrorCode ierr; PetscTruth iascii; PetscFunctionBegin; ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); if (iascii) { ierr = MatView_MPIAdj_ASCII(A,viewer);CHKERRQ(ierr); } else { SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by MPIAdj",((PetscObject)viewer)->type_name); } PetscFunctionReturn(0); }
/*@ PCShellSetContext - sets the context for a shell PC Collective on PC Input Parameters: + pc - the shell PC - ctx - the context Level: advanced Fortran Notes: The context can only be an integer or a PetscObject unfortunately it cannot be a Fortran array or derived type. .seealso: PCCreateShell(), PCShellGetContext() @*/ PetscErrorCode PETSCKSP_DLLEXPORT PCShellSetContext(PC pc,void *ctx) { PC_Shell *shell; PetscErrorCode ierr; PetscTruth flg; PetscFunctionBegin; PetscValidHeaderSpecific(pc,PC_COOKIE,1); shell = (PC_Shell*)pc->data; ierr = PetscTypeCompare((PetscObject)pc,PCSHELL,&flg);CHKERRQ(ierr); if (flg) { shell->ctx = ctx; } PetscFunctionReturn(0); }
static int TaoView_AUGMENTED(TAO_SOLVER tao,void* solver, Viewer viewer) { TAO_AUGMENTED *augmented = (TAO_AUGMENTED *)solver; PetscTruth isascii; int info; TaoFunctionBegin; info = PetscTypeCompare((PetscObject)viewer,ASCII_VIEWER,&isascii); CHKERRQ(info); if (isascii) { } else { SETERRQ(1,1,"Viewer type not supported for this object"); } TaoFunctionReturn(0); }
PetscErrorCode KSPView_Chebychev(KSP ksp,PetscViewer viewer) { KSP_Chebychev *cheb = (KSP_Chebychev*)ksp->data; PetscErrorCode ierr; PetscTruth iascii; PetscFunctionBegin; ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr); if (iascii) { ierr = PetscViewerASCIIPrintf(viewer," Chebychev: eigenvalue estimates: min = %G, max = %G\n",cheb->emin,cheb->emax);CHKERRQ(ierr); } else { SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported for KSP Chebychev",((PetscObject)viewer)->type_name); } PetscFunctionReturn(0); }
/*@ PetscDrawPointSetSize - Sets the point size for future draws. The size is relative to the user coordinates of the window; 0.0 denotes the natural width, 1.0 denotes the entire viewport. Not collective Input Parameters: + draw - the drawing context - width - the width in user coordinates Level: advanced Note: Even a size of zero insures that a single pixel is colored. Concepts: point^drawing size .seealso: PetscDrawPoint() @*/ PetscErrorCode PETSC_DLLEXPORT PetscDrawPointSetSize(PetscDraw draw,PetscReal width) { PetscErrorCode ierr; PetscTruth isnull; PetscFunctionBegin; PetscValidHeaderSpecific(draw,PETSC_DRAW_COOKIE,1); ierr = PetscTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);CHKERRQ(ierr); if (isnull) PetscFunctionReturn(0); if (width < 0.0 || width > 1.0) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Bad size %G, should be between 0 and 1",width); if (draw->ops->pointsetsize) { ierr = (*draw->ops->pointsetsize)(draw,width);CHKERRQ(ierr); } PetscFunctionReturn(0); }
dErr VecDohpZeroEntries(Vec v) { dErr err; dBool isdohp; Vec c; dFunctionBegin; dValidHeader(v,VEC_CLASSID,1); err = PetscTypeCompare((dObject)v,VECDOHP,&isdohp);dCHK(err); if (!isdohp) dERROR(PETSC_COMM_SELF,PETSC_ERR_SUP,"Vector type %s",((dObject)v)->type_name); err = VecDohpGetClosure(v,&c);dCHK(err); err = VecZeroEntries(c);dCHK(err); err = VecDohpRestoreClosure(v,&c);dCHK(err); dFunctionReturn(0); }
dErr VecDohpRestoreClosure(Vec v,Vec *c) { dErr err; dBool isdohp; dFunctionBegin; dValidHeader(v,VEC_CLASSID,1); dValidPointer(c,2); err = PetscTypeCompare((dObject)v,VECDOHP,&isdohp);dCHK(err); if (!isdohp) dERROR(PETSC_COMM_SELF,1,"Vector type %s does not have closure",((dObject)v)->type_name); if (*c != ((Vec_MPI*)v->data)->localrep) dERROR(PETSC_COMM_SELF,1,"attempting to restore incorrect closure"); err = VecStateSync_Private(v,*c);dCHK(err); err = PetscObjectDereference((dObject)*c);dCHK(err); *c = NULL; dFunctionReturn(0); }
/** Get the closed form of a Dohp vector * * @note Dohp vectors are basically just MPI vectors, the only difference is that instead of a local form, we have a * closed form. We subvert .localrep to mean the closed form. * **/ dErr VecDohpGetClosure(Vec v,Vec *c) { Vec_MPI *vmpi; dBool isdohp; dErr err; dFunctionBegin; dValidHeader(v,VEC_CLASSID,1); dValidPointer(c,2); err = PetscTypeCompare((dObject)v,VECDOHP,&isdohp);dCHK(err); if (!isdohp) dERROR(PETSC_COMM_SELF,1,"Vector type %s does not have closure",((dObject)v)->type_name); vmpi = v->data; if (!vmpi->localrep) dERROR(PETSC_COMM_SELF,1,"Vector has no closure"); *c = vmpi->localrep; err = VecStateSync_Private(v,*c);dCHK(err); err = PetscObjectReference((dObject)*c);dCHK(err); dFunctionReturn(0); }
/*@C PetscViewerDrawBaseSet - sets the base integer that is added to the windownumber passed to PetscViewerDrawGetDraw() Not collective (but PetscDraw returned will be parallel object if PetscViewer is) Input Parameters: + viewer - the PetscViewer (created with PetscViewerDrawOpen()) - windownumber - value to set the base Level: developer Concepts: drawing^accessing PetscDraw context from PetscViewer Concepts: graphics .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PetscViewerDrawBaseAdd() @*/ PetscErrorCode PETSC_DLLEXPORT PetscViewerDrawBaseSet(PetscViewer viewer,PetscInt windownumber) { PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data; PetscErrorCode ierr; PetscTruth isdraw; PetscFunctionBegin; PetscValidHeaderSpecific(viewer,PETSC_VIEWER_COOKIE,1); ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_DRAW,&isdraw);CHKERRQ(ierr); if (!isdraw) { SETERRQ(PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer"); } if (windownumber < 0) { SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"Resulting base %D cannot be negative",windownumber); } vdraw->draw_base = windownumber; PetscFunctionReturn(0); }
PetscErrorCode MatPartitioningView_Party(MatPartitioning part, PetscViewer viewer) { MatPartitioning_Party *party = (MatPartitioning_Party *) part->data; PetscErrorCode ierr; PetscMPIInt rank; PetscTruth iascii; PetscFunctionBegin; ierr = MPI_Comm_rank(((PetscObject)part)->comm, &rank);CHKERRQ(ierr); ierr = PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);CHKERRQ(ierr); if (iascii) { if (!rank && party->mesg_log) { ierr = PetscViewerASCIIPrintf(viewer, "%s\n", party->mesg_log);CHKERRQ(ierr); } } else { SETERRQ1(PETSC_ERR_SUP, "Viewer type %s not supported for this Party partitioner",((PetscObject) viewer)((PetscObject))->type_name); } PetscFunctionReturn(0); }