PetscErrorCode PETSC_DLLEXPORT PetscObjectComposeFunction(PetscObject obj,const char name[],const char fname[],void (*ptr)(void)) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeader(obj,1); PetscValidCharPointer(name,2); PetscValidCharPointer(fname,2); ierr = (*obj->bops->composefunction)(obj,name,fname,ptr);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C PetscDrawSetSave - Saves images produced in a PetscDraw into a file Collective on PetscDraw Input Parameter: + draw - the graphics context . filename - name of the file, if .ext then uses name of draw object plus .ext using .ext to determine the image type - movieext - if not NULL, produces a movie of all the images Options Database Command: + -draw_save <filename> - filename could be name.ext or .ext (where .ext determines the type of graphics file to save, for example .png) . -draw_save_movie <.ext> - saves a movie to filename.ext . -draw_save_final_image [optional filename] - saves the final image displayed in a window - -draw_save_single_file - saves each new image in the same file, normally each new image is saved in a new file with filename/filename_%d.ext Level: intermediate Concepts: X windows^graphics Notes: You should call this BEFORE creating your image and calling PetscDrawSave(). The supported image types are .png, .gif, .jpg, and .ppm (PETSc chooses the default in that order). Support for .png images requires configure --with-libpng. Support for .gif images requires configure --with-giflib. Support for .jpg images requires configure --with-libjpeg. Support for .ppm images is built-in. The PPM format has no compression (640x480 pixels ~ 900 KiB). The ffmpeg utility must be in your path to make the movie. .seealso: PetscDrawSetFromOptions(), PetscDrawCreate(), PetscDrawDestroy(), PetscDrawSetSaveFinalImage() @*/ PetscErrorCode PetscDrawSetSave(PetscDraw draw,const char filename[],const char movieext[]) { const char *savename = NULL; const char *imageext = NULL; char buf[PETSC_MAX_PATH_LEN]; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); if (filename) PetscValidCharPointer(filename,2); if (movieext) PetscValidCharPointer(movieext,2); /* determine save filename and image extension */ if (filename && filename[0]) { ierr = PetscStrchr(filename,'.',(char **)&imageext);CHKERRQ(ierr); if (!imageext) savename = filename; else if (imageext != filename) { size_t l1 = 0,l2 = 0; ierr = PetscStrlen(filename,&l1);CHKERRQ(ierr); ierr = PetscStrlen(imageext,&l2);CHKERRQ(ierr); ierr = PetscStrncpy(buf,filename,l1-l2+1);CHKERRQ(ierr); savename = buf; } } if (!savename) {ierr = PetscObjectGetName((PetscObject)draw,&savename);CHKERRQ(ierr);} ierr = PetscDrawImageCheckFormat(&imageext);CHKERRQ(ierr); if (movieext) {ierr = PetscDrawMovieCheckFormat(&movieext);CHKERRQ(ierr);} if (movieext) draw->savesinglefile = PETSC_FALSE; /* otherwise we cannot generage movies */ if (draw->savesinglefile) { ierr = PetscInfo2(NULL,"Will save image to file %s%s\n",savename,imageext);CHKERRQ(ierr); } else { ierr = PetscInfo3(NULL,"Will save images to file %s/%s_%%d%s\n",savename,savename,imageext);CHKERRQ(ierr); } if (movieext) { ierr = PetscInfo2(NULL,"Will save movie to file %s%s\n",savename,movieext);CHKERRQ(ierr); } draw->savefilecount = 0; ierr = PetscFree(draw->savefilename);CHKERRQ(ierr); ierr = PetscFree(draw->saveimageext);CHKERRQ(ierr); ierr = PetscFree(draw->savemovieext);CHKERRQ(ierr); ierr = PetscStrallocpy(savename,&draw->savefilename);CHKERRQ(ierr); ierr = PetscStrallocpy(imageext,&draw->saveimageext);CHKERRQ(ierr); ierr = PetscStrallocpy(movieext,&draw->savemovieext);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C MatCoarsenSetType - Sets the type of aggregator to use Collective on MatCoarsen Input Parameter: . coarser - the coarsen context. . type - a known method Options Database Command: $ -mat_coarsen_type <type> $ Use -help for a list of available methods $ (for instance, mis) Level: intermediate .keywords: coarsen, set, method, type .seealso: MatCoarsenCreate(), MatCoarsenApply(), MatCoarsenType @*/ PetscErrorCode MatCoarsenSetType(MatCoarsen coarser, MatCoarsenType type) { PetscErrorCode ierr,(*r)(MatCoarsen); PetscBool match; PetscFunctionBegin; PetscValidHeaderSpecific(coarser,MAT_COARSEN_CLASSID,1); PetscValidCharPointer(type,2); ierr = PetscObjectTypeCompare((PetscObject)coarser,type,&match);CHKERRQ(ierr); if (match) PetscFunctionReturn(0); if (coarser->setupcalled) { ierr = (*coarser->ops->destroy)(coarser);CHKERRQ(ierr); coarser->ops->destroy = NULL; coarser->subctx = 0; coarser->setupcalled = 0; } ierr = PetscFunctionListFind(MatCoarsenList,type,&r);CHKERRQ(ierr); if (!r) SETERRQ1(PetscObjectComm((PetscObject)coarser),PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown coarsen type %s",type); coarser->ops->destroy = (PetscErrorCode (*)(MatCoarsen)) 0; coarser->ops->view = (PetscErrorCode (*)(MatCoarsen,PetscViewer)) 0; ierr = (*r)(coarser);CHKERRQ(ierr); ierr = PetscFree(((PetscObject)coarser)->type_name);CHKERRQ(ierr); ierr = PetscStrallocpy(type,&((PetscObject)coarser)->type_name);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C MatPartitioningSetType - Sets the type of partitioner to use Collective on MatPartitioning Input Parameter: . part - the partitioning context. . type - a known method Options Database Command: $ -mat_partitioning_type <type> $ Use -help for a list of available methods $ (for instance, parmetis) Level: intermediate .keywords: partitioning, set, method, type .seealso: MatPartitioningCreate(), MatPartitioningApply(), MatPartitioningType @*/ PetscErrorCode MatPartitioningSetType(MatPartitioning part,MatPartitioningType type) { PetscErrorCode ierr,(*r)(MatPartitioning); PetscBool match; PetscFunctionBegin; PetscValidHeaderSpecific(part,MAT_PARTITIONING_CLASSID,1); PetscValidCharPointer(type,2); ierr = PetscObjectTypeCompare((PetscObject)part,type,&match);CHKERRQ(ierr); if (match) PetscFunctionReturn(0); if (part->setupcalled) { ierr = (*part->ops->destroy)(part);CHKERRQ(ierr); part->ops->destroy = NULL; part->data = 0; part->setupcalled = 0; } ierr = PetscFunctionListFind(MatPartitioningList,type,&r);CHKERRQ(ierr); if (!r) SETERRQ1(PetscObjectComm((PetscObject)part),PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown partitioning type %s",type); part->ops->destroy = (PetscErrorCode (*)(MatPartitioning)) 0; part->ops->view = (PetscErrorCode (*)(MatPartitioning,PetscViewer)) 0; ierr = (*r)(part);CHKERRQ(ierr); ierr = PetscFree(((PetscObject)part)->type_name);CHKERRQ(ierr); ierr = PetscStrallocpy(type,&((PetscObject)part)->type_name);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C KSPSetType - Builds KSP for a particular solver. Logically Collective on KSP Input Parameters: + ksp - the Krylov space context - type - a known method Options Database Key: . -ksp_type <method> - Sets the method; use -help for a list of available methods (for instance, cg or gmres) Notes: See "petsc/include/petscksp.h" for available methods (for instance, KSPCG or KSPGMRES). Normally, it is best to use the KSPSetFromOptions() command and then set the KSP type from the options database rather than by using this routine. Using the options database provides the user with maximum flexibility in evaluating the many different Krylov methods. The KSPSetType() routine is provided for those situations where it is necessary to set the iterative solver independently of the command line or options database. This might be the case, for example, when the choice of iterative solver changes during the execution of the program, and the user's application is taking responsibility for choosing the appropriate method. In other words, this routine is not for beginners. Level: intermediate Developer Note: KSPRegister() is used to add Krylov types to KSPList from which they are accessed by KSPSetType(). .keywords: KSP, set, method .seealso: PCSetType(), KSPType, KSPRegister(), KSPCreate() @*/ PetscErrorCode KSPSetType(KSP ksp, KSPType type) { PetscErrorCode ierr,(*r)(KSP); PetscBool match; PetscFunctionBegin; PetscValidHeaderSpecific(ksp,KSP_CLASSID,1); PetscValidCharPointer(type,2); ierr = PetscObjectTypeCompare((PetscObject)ksp,type,&match);CHKERRQ(ierr); if (match) PetscFunctionReturn(0); ierr = PetscFunctionListFind(KSPList,type,&r);CHKERRQ(ierr); if (!r) SETERRQ1(PetscObjectComm((PetscObject)ksp),PETSC_ERR_ARG_UNKNOWN_TYPE,"Unable to find requested KSP type %s",type); /* Destroy the previous private KSP context */ if (ksp->ops->destroy) { ierr = (*ksp->ops->destroy)(ksp);CHKERRQ(ierr); ksp->ops->destroy = NULL; } /* Reinitialize function pointers in KSPOps structure */ ierr = PetscMemzero(ksp->ops,sizeof(struct _KSPOps));CHKERRQ(ierr); ksp->ops->buildsolution = KSPBuildSolutionDefault; ksp->ops->buildresidual = KSPBuildResidualDefault; ierr = KSPNormSupportTableReset_Private(ksp);CHKERRQ(ierr); /* Call the KSPCreate_XXX routine for this particular Krylov solver */ ksp->setupstage = KSP_SETUP_NEW; ierr = PetscObjectChangeTypeName((PetscObject)ksp,type);CHKERRQ(ierr); ierr = (*r)(ksp);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C SNESMSRegister - register a multistage scheme Not Collective, but the same schemes should be registered on all processes on which they will be used Input Parameters: + name - identifier for method . nstages - number of stages . nregisters - number of registers used by low-storage implementation . gamma - coefficients, see Ketcheson's paper . delta - coefficients, see Ketcheson's paper - betasub - subdiagonal of Shu-Osher form Notes: The notation is described in Ketcheson (2010) Runge-Kutta methods with minimum storage implementations. Level: advanced .keywords: SNES, register .seealso: SNESMS @*/ PetscErrorCode SNESMSRegister(const SNESMSType name,PetscInt nstages,PetscInt nregisters,PetscReal stability,const PetscReal gamma[],const PetscReal delta[],const PetscReal betasub[]) { PetscErrorCode ierr; SNESMSTableauLink link; SNESMSTableau t; PetscFunctionBegin; PetscValidCharPointer(name,1); if (nstages < 1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Must have at least one stage"); if (nregisters != 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Only support for methods written in 3-register form"); PetscValidPointer(gamma,4); PetscValidPointer(delta,5); PetscValidPointer(betasub,6); ierr = PetscMalloc(sizeof(*link),&link);CHKERRQ(ierr); ierr = PetscMemzero(link,sizeof(*link));CHKERRQ(ierr); t = &link->tab; ierr = PetscStrallocpy(name,&t->name);CHKERRQ(ierr); t->nstages = nstages; t->nregisters = nregisters; t->stability = stability; ierr = PetscMalloc3(nstages*nregisters,PetscReal,&t->gamma,nstages,PetscReal,&t->delta,nstages,PetscReal,&t->betasub);CHKERRQ(ierr); ierr = PetscMemcpy(t->gamma,gamma,nstages*nregisters*sizeof(PetscReal));CHKERRQ(ierr); ierr = PetscMemcpy(t->delta,delta,nstages*sizeof(PetscReal));CHKERRQ(ierr); ierr = PetscMemcpy(t->betasub,betasub,nstages*sizeof(PetscReal));CHKERRQ(ierr); link->next = SNESMSTableauList; SNESMSTableauList = link; PetscFunctionReturn(0); }
/*@C PetscViewerStringSPrintf - Prints information to a PetscViewer string. Logically Collective on PetscViewer (Hmmm, each processor maintains a separate string) Input Parameters: + v - a string PetscViewer, formed by PetscViewerStringOpen() - format - the format of the input Level: developer Fortran Note: This routine is not supported in Fortran. Concepts: printing^to string .seealso: PetscViewerStringOpen(), PetscViewerStringGetStringRead(), PetscViewerStringSetString(), PETSCVIEWERSTRING @*/ PetscErrorCode PetscViewerStringSPrintf(PetscViewer viewer,const char format[],...) { va_list Argp; size_t fullLength; size_t shift,cshift; PetscErrorCode ierr; PetscBool isstring; char tmp[4096]; PetscViewer_String *vstr = (PetscViewer_String*)viewer->data; PetscFunctionBegin; PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); PetscValidCharPointer(format,2); ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSTRING,&isstring);CHKERRQ(ierr); if (!isstring) PetscFunctionReturn(0); if (!vstr->string) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Must call PetscViewerStringSetString() before using"); va_start(Argp,format); ierr = PetscVSNPrintf(tmp,4096,format,&fullLength,Argp);CHKERRQ(ierr); va_end(Argp); ierr = PetscStrlen(tmp,&shift);CHKERRQ(ierr); cshift = shift+1; if (cshift >= vstr->maxlen - vstr->curlen - 1) cshift = vstr->maxlen - vstr->curlen - 1; ierr = PetscStrncpy(vstr->head,tmp,cshift);CHKERRQ(ierr); vstr->head += shift; vstr->curlen += shift; PetscFunctionReturn(0); }
/*@C PCSetType - Builds PC for a particular preconditioner type Collective on PC Input Parameter: + pc - the preconditioner context. - type - a known method Options Database Key: . -pc_type <type> - Sets PC type Use -help for a list of available methods (for instance, jacobi or bjacobi) Notes: See "petsc/include/petscpc.h" for available methods (for instance, PCJACOBI, PCILU, or PCBJACOBI). Normally, it is best to use the KSPSetFromOptions() command and then set the PC type from the options database rather than by using this routine. Using the options database provides the user with maximum flexibility in evaluating the many different preconditioners. The PCSetType() routine is provided for those situations where it is necessary to set the preconditioner independently of the command line or options database. This might be the case, for example, when the choice of preconditioner changes during the execution of the program, and the user's application is taking responsibility for choosing the appropriate preconditioner. In other words, this routine is not for beginners. Level: intermediate Developer Note: PCRegister() is used to add preconditioner types to PCList from which they are accessed by PCSetType(). .keywords: PC, set, method, type .seealso: KSPSetType(), PCType, PCRegister(), PCCreate(), KSPGetPC() @*/ PetscErrorCode PCSetType(PC pc,PCType type) { PetscErrorCode ierr,(*r)(PC); PetscBool match; PetscFunctionBegin; PetscValidHeaderSpecific(pc,PC_CLASSID,1); PetscValidCharPointer(type,2); ierr = PetscObjectTypeCompare((PetscObject)pc,type,&match);CHKERRQ(ierr); if (match) PetscFunctionReturn(0); ierr = PetscFunctionListFind(PCList,type,&r);CHKERRQ(ierr); if (!r) SETERRQ1(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_UNKNOWN_TYPE,"Unable to find requested PC type %s",type); /* Destroy the previous private PC context */ if (pc->ops->destroy) { ierr = (*pc->ops->destroy)(pc);CHKERRQ(ierr); pc->ops->destroy = NULL; pc->data = 0; } ierr = PetscFunctionListDestroy(&((PetscObject)pc)->qlist);CHKERRQ(ierr); /* Reinitialize function pointers in PCOps structure */ ierr = PetscMemzero(pc->ops,sizeof(struct _PCOps));CHKERRQ(ierr); /* XXX Is this OK?? */ pc->modifysubmatrices = 0; pc->modifysubmatricesP = 0; /* Call the PCCreate_XXX routine for this particular preconditioner */ pc->setupcalled = 0; ierr = PetscObjectChangeTypeName((PetscObject)pc,type);CHKERRQ(ierr); ierr = (*r)(pc);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C EPSSetType - Selects the particular solver to be used in the EPS object. Logically Collective on EPS Input Parameters: + eps - the eigensolver context - type - a known method Options Database Key: . -eps_type <method> - Sets the method; use -help for a list of available methods Notes: See "slepc/include/slepceps.h" for available methods. The default is EPSKRYLOVSCHUR. Normally, it is best to use the EPSSetFromOptions() command and then set the EPS type from the options database rather than by using this routine. Using the options database provides the user with maximum flexibility in evaluating the different available methods. The EPSSetType() routine is provided for those situations where it is necessary to set the iterative solver independently of the command line or options database. Level: intermediate .seealso: STSetType(), EPSType @*/ PetscErrorCode EPSSetType(EPS eps,EPSType type) { PetscErrorCode ierr,(*r)(EPS); PetscBool match; PetscFunctionBegin; PetscValidHeaderSpecific(eps,EPS_CLASSID,1); PetscValidCharPointer(type,2); ierr = PetscObjectTypeCompare((PetscObject)eps,type,&match); CHKERRQ(ierr); if (match) PetscFunctionReturn(0); ierr = PetscFunctionListFind(EPSList,type,&r); CHKERRQ(ierr); if (!r) SETERRQ1(PetscObjectComm((PetscObject)eps),PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown EPS type given: %s",type); if (eps->ops->destroy) { ierr = (*eps->ops->destroy)(eps); CHKERRQ(ierr); } ierr = PetscMemzero(eps->ops,sizeof(struct _EPSOps)); CHKERRQ(ierr); eps->state = EPS_STATE_INITIAL; ierr = PetscObjectChangeTypeName((PetscObject)eps,type); CHKERRQ(ierr); ierr = (*r)(eps); CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C PFSetType - Builds PF for a particular function Collective on PF Input Parameter: + pf - the function context. . type - a known method - ctx - optional type dependent context Options Database Key: . -pf_type <type> - Sets PF type Notes: See "petsc/include/petscpf.h" for available methods (for instance, PFCONSTANT) Level: intermediate .keywords: PF, set, method, type .seealso: PFSet(), PFRegister(), PFCreate(), DMDACreatePF() @*/ PetscErrorCode PFSetType(PF pf,PFType type,void *ctx) { PetscErrorCode ierr,(*r)(PF,void*); PetscBool match; PetscFunctionBegin; PetscValidHeaderSpecific(pf,PF_CLASSID,1); PetscValidCharPointer(type,2); ierr = PetscObjectTypeCompare((PetscObject)pf,type,&match);CHKERRQ(ierr); if (match) PetscFunctionReturn(0); if (pf->ops->destroy) {ierr = (*pf->ops->destroy)(pf);CHKERRQ(ierr);} pf->data = 0; /* Determine the PFCreateXXX routine for a particular function */ ierr = PetscFunctionListFind(PFList,type,&r);CHKERRQ(ierr); if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unable to find requested PF type %s",type); pf->ops->destroy = 0; pf->ops->view = 0; pf->ops->apply = 0; pf->ops->applyvec = 0; /* Call the PFCreateXXX routine for this particular function */ ierr = (*r)(pf,ctx);CHKERRQ(ierr); ierr = PetscObjectChangeTypeName((PetscObject)pf,type);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C DMGetNamedLocalVector - get access to a named, persistent local vector Not Collective Input Arguments: + dm - DM to hold named vectors - name - unique name for Vec Output Arguments: . X - named Vec Level: developer Note: If a Vec with the given name does not exist, it is created. .seealso: DMGetNamedGlobalVector(),DMRestoreNamedLocalVector() @*/ PetscErrorCode DMGetNamedLocalVector(DM dm,const char *name,Vec *X) { PetscErrorCode ierr; DMNamedVecLink link; PetscFunctionBegin; PetscValidHeaderSpecific(dm,DM_CLASSID,1); PetscValidCharPointer(name,2); PetscValidPointer(X,3); for (link=dm->namedlocal; link; link=link->next) { PetscBool match; ierr = PetscStrcmp(name,link->name,&match);CHKERRQ(ierr); if (match) { if (link->status != DMVEC_STATUS_IN) SETERRQ1(PetscObjectComm((PetscObject)dm),PETSC_ERR_ARG_WRONGSTATE,"Vec name '%s' already checked out",name); goto found; } } /* Create the Vec */ ierr = PetscNew(&link);CHKERRQ(ierr); ierr = PetscStrallocpy(name,&link->name);CHKERRQ(ierr); ierr = DMCreateLocalVector(dm,&link->X);CHKERRQ(ierr); link->next = dm->namedlocal; dm->namedlocal = link; found: *X = link->X; link->status = DMVEC_STATUS_OUT; PetscFunctionReturn(0); }
EXTERN_C_END #undef __FUNCT__ #define __FUNCT__ "PetscPythonMonitorSet" /*@C PetscPythonMonitorSet - Set Python monitor Level: developer .keywords: Python @*/ PetscErrorCode PetscPythonMonitorSet(PetscObject obj, const char url[]) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeader(obj,1); PetscValidCharPointer(url,2); if (PetscPythonMonitorSet_C == PETSC_NULL) { ierr = PetscPythonInitialize(PETSC_NULL,PETSC_NULL);CHKERRQ(ierr); if (PetscPythonMonitorSet_C == PETSC_NULL) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Couldn't initialize Python support for monitors"); } ierr = PetscPythonMonitorSet_C(obj,url);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C MatMFFDSetType - Sets the method that is used to compute the differencing parameter for finite differene matrix-free formulations. Input Parameters: + mat - the "matrix-free" matrix created via MatCreateSNESMF(), or MatCreateMFFD() or MatSetType(mat,MATMFFD); - ftype - the type requested, either MATMFFD_WP or MATMFFD_DS Level: advanced Notes: For example, such routines can compute h for use in Jacobian-vector products of the form F(x+ha) - F(x) F'(u)a ~= ---------------- h .seealso: MatCreateSNESMF(), MatMFFDRegister(), MatMFFDSetFunction(), MatCreateMFFD() @*/ PetscErrorCode MatMFFDSetType(Mat mat,MatMFFDType ftype) { PetscErrorCode ierr,(*r)(MatMFFD); MatMFFD ctx = (MatMFFD)mat->data; PetscBool match; PetscFunctionBegin; PetscValidHeaderSpecific(mat,MAT_CLASSID,1); PetscValidCharPointer(ftype,2); ierr = PetscObjectTypeCompare((PetscObject)mat,MATMFFD,&match);CHKERRQ(ierr); if (!match) PetscFunctionReturn(0); /* already set, so just return */ ierr = PetscObjectTypeCompare((PetscObject)ctx,ftype,&match);CHKERRQ(ierr); if (match) PetscFunctionReturn(0); /* destroy the old one if it exists */ if (ctx->ops->destroy) { ierr = (*ctx->ops->destroy)(ctx);CHKERRQ(ierr); } ierr = PetscFunctionListFind(MatMFFDList,ftype,&r);CHKERRQ(ierr); if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown MatMFFD type %s given",ftype); ierr = (*r)(ctx);CHKERRQ(ierr); ierr = PetscObjectChangeTypeName((PetscObject)ctx,ftype);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C DMPlexCreateLabel - Create a label of the given name if it does not already exist Not Collective Input Parameters: + dm - The DMPlex object - name - The label name Level: intermediate .keywords: mesh .seealso: DMLabelCreate(), DMPlexHasLabel(), DMPlexGetLabelValue(), DMPlexSetLabelValue(), DMPlexGetStratumIS() @*/ PetscErrorCode DMPlexCreateLabel(DM dm, const char name[]) { DM_Plex *mesh = (DM_Plex*) dm->data; PlexLabel next = mesh->labels; PetscBool flg = PETSC_FALSE; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(dm, DM_CLASSID, 1); PetscValidCharPointer(name, 2); while (next) { ierr = PetscStrcmp(name, next->label->name, &flg);CHKERRQ(ierr); if (flg) break; next = next->next; } if (!flg) { PlexLabel tmpLabel; ierr = PetscCalloc1(1, &tmpLabel);CHKERRQ(ierr); ierr = DMLabelCreate(name, &tmpLabel->label);CHKERRQ(ierr); tmpLabel->output = PETSC_TRUE; tmpLabel->next = mesh->labels; mesh->labels = tmpLabel; } PetscFunctionReturn(0); }
/*@C PetscObjectSetType - Sets the object type of any PetscObject. Not Collective Input Parameters: + obj - any PETSc object, for example a Vec, Mat or KSP. Thus must be cast with a (PetscObject), for example, PetscObjectGetType((PetscObject)mat,&type); - type - the object type Note: This does not currently work since we need to dispatch by type. Level: advanced Concepts: object type @*/ PetscErrorCode PETSC_DLLEXPORT PetscObjectSetType(PetscObject obj, const char type[]) { PetscFunctionBegin; PetscValidHeader(obj,1); PetscValidCharPointer(type,2); SETERRQ(PETSC_ERR_SUP, "Cannot set the type of a generic PetscObject") }
/*@C PetscViewerSetType - Builds PetscViewer for a particular implementation. Collective on PetscViewer Input Parameter: + viewer - the PetscViewer context - type - for example, PETSCVIEWERASCII Options Database Command: . -draw_type <type> - Sets the type; use -help for a list of available methods (for instance, ascii) Level: advanced Notes: See "include/petscviewer.h" for available methods (for instance, PETSCVIEWERSOCKET) .seealso: PetscViewerCreate(), PetscViewerGetType(), PetscViewerType, PetscViewerSetFormat() @*/ PetscErrorCode PetscViewerSetType(PetscViewer viewer,PetscViewerType type) { PetscErrorCode ierr,(*r)(PetscViewer); PetscBool match; PetscFunctionBegin; PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); PetscValidCharPointer(type,2); ierr = PetscObjectTypeCompare((PetscObject)viewer,type,&match);CHKERRQ(ierr); if (match) PetscFunctionReturn(0); /* cleanup any old type that may be there */ if (viewer->data) { ierr = (*viewer->ops->destroy)(viewer);CHKERRQ(ierr); viewer->ops->destroy = NULL; viewer->data = 0; } ierr = PetscMemzero(viewer->ops,sizeof(struct _PetscViewerOps));CHKERRQ(ierr); ierr = PetscFunctionListFind(PetscViewerList,type,&r);CHKERRQ(ierr); if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown PetscViewer type given: %s",type); ierr = PetscObjectChangeTypeName((PetscObject)viewer,type);CHKERRQ(ierr); ierr = (*r)(viewer);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C MatColoringSetType - Sets the type of coloring algorithm used Collective on MatColoring Input Parameter: + mc - the MatColoring context - type - the type of coloring Level: beginner Notes: Possible types include the sequential types MATCOLORINGLF, MATCOLORINGSL, and MATCOLORINGID from the MINPACK package as well as a parallel MATCOLORINGMIS algorithm. .keywords: Coloring, type .seealso: MatColoringCreate(), MatColoringApply() @*/ PetscErrorCode MatColoringSetType(MatColoring mc,MatColoringType type) { PetscBool match; PetscErrorCode ierr,(*r)(MatColoring); PetscFunctionBegin; PetscValidHeaderSpecific(mc,MAT_COLORING_CLASSID,1); PetscValidCharPointer(type,2); ierr = PetscObjectTypeCompare((PetscObject)mc,type,&match);CHKERRQ(ierr); if (match) PetscFunctionReturn(0); ierr = PetscFunctionListFind(MatColoringList,type,&r);CHKERRQ(ierr); if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unable to find requested MatColoring type %s",type); if (mc->ops->destroy) { ierr = (*(mc)->ops->destroy)(mc);CHKERRQ(ierr); mc->ops->destroy = NULL; } mc->ops->apply = 0; mc->ops->view = 0; mc->ops->setfromoptions = 0; mc->ops->destroy = 0; ierr = PetscObjectChangeTypeName((PetscObject)mc,type);CHKERRQ(ierr); ierr = (*r)(mc);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C TSPythonSetType - Initalize a TS object implemented in Python. Collective on TS Input Parameter: + ts - the nonlinear solver (TS) context. - pyname - full dotted Python name [package].module[.{class|function}] Options Database Key: . -ts_python_type <pyname> Level: intermediate .keywords: TS, Python .seealso: TSCreate(), TSSetType(), TSPYTHON, PetscPythonInitialize() @*/ PetscErrorCode TSPythonSetType(TS ts,const char pyname[]) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(ts,TS_CLASSID,1); PetscValidCharPointer(pyname,2); ierr = PetscTryMethod(ts,"TSPythonSetType_C",(TS, const char[]),(ts,pyname));CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C PetscDrawSetType - Builds graphics object for a particular implementation Collective on PetscDraw Input Parameter: + draw - the graphics context - type - for example, PETSC_DRAW_X Options Database Command: . -draw_type <type> - Sets the type; use -help for a list of available methods (for instance, x) Level: intermediate Notes: See "petsc/include/petscdraw.h" for available methods (for instance, PETSC_DRAW_X) Concepts: drawing^X windows Concepts: X windows^graphics Concepts: drawing^Microsoft Windows .seealso: PetscDrawSetFromOptions(), PetscDrawCreate(), PetscDrawDestroy() @*/ PetscErrorCode PetscDrawSetType(PetscDraw draw,PetscDrawType type) { PetscErrorCode ierr,(*r)(PetscDraw); PetscBool match; PetscBool flg=PETSC_FALSE; PetscFunctionBegin; PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); PetscValidCharPointer(type,2); ierr = PetscObjectTypeCompare((PetscObject)draw,type,&match); CHKERRQ(ierr); if (match) PetscFunctionReturn(0); /* User requests no graphics */ ierr = PetscOptionsHasName(NULL,"-nox",&flg); CHKERRQ(ierr); /* This is not ideal, but it allows codes to continue to run if X graphics was requested but is not installed on this machine. Mostly this is for testing. */ #if !defined(PETSC_HAVE_X) if (!flg) { ierr = PetscStrcmp(type,PETSC_DRAW_X,&match); CHKERRQ(ierr); if (match) { PetscBool dontwarn = PETSC_TRUE; flg = PETSC_TRUE; ierr = PetscOptionsHasName(NULL,"-nox_warning",&dontwarn); CHKERRQ(ierr); if (!dontwarn) (*PetscErrorPrintf)("PETSc installed without X windows on this machine\nproceeding without graphics\n"); } } #endif if (flg) type = PETSC_DRAW_NULL; if (draw->data) { /* destroy the old private PetscDraw context */ ierr = (*draw->ops->destroy)(draw); CHKERRQ(ierr); draw->ops->destroy = NULL; draw->data = 0; } ierr = PetscFunctionListFind(PetscDrawList,type,&r); CHKERRQ(ierr); if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown PetscDraw type given: %s",type); ierr = PetscObjectChangeTypeName((PetscObject)draw,type); CHKERRQ(ierr); draw->data = 0; ierr = (*r)(draw); CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C PetscViewerFileSetName - Sets the name of the file the PetscViewer uses. Collective on PetscViewer Input Parameters: + viewer - the PetscViewer; either ASCII or binary - name - the name of the file it should use Level: advanced .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PetscViewerDestroy(), PetscViewerASCIIGetPointer(), PetscViewerASCIIPrintf(), PetscViewerASCIISynchronizedPrintf() @*/ PetscErrorCode PetscViewerFileSetName(PetscViewer viewer,const char name[]) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); PetscValidCharPointer(name,2); ierr = PetscTryMethod(viewer,"PetscViewerFileSetName_C",(PetscViewer,const char[]),(viewer,name));CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C KSPPythonSetType - Initalize a KSP object implemented in Python. Collective on KSP Input Parameter: + ksp - the linear solver (KSP) context. - pyname - full dotted Python name [package].module[.{class|function}] Options Database Key: . -ksp_python_type <pyname> Level: intermediate .keywords: KSP, Python .seealso: KSPCreate(), KSPSetType(), KSPPYTHON, PetscPythonInitialize() @*/ PetscErrorCode KSPPythonSetType(KSP ksp,const char pyname[]) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(ksp,KSP_CLASSID,1); PetscValidCharPointer(pyname,2); ierr = PetscTryMethod(ksp,"KSPPythonSetType_C",(KSP, const char[]),(ksp,pyname));CHKERRQ(ierr); PetscFunctionReturn(0); }
/*MC PetscObjectQueryFunction - Gets a function associated with a given object. Synopsis: #include <petscsys.h> PetscErrorCode PetscObjectQueryFunction(PetscObject obj,const char name[],void (**fptr)(void)) Logically Collective on PetscObject Input Parameters: + obj - the PETSc object; this must be cast with (PetscObject), for example, PetscObjectQueryFunction((PetscObject)ksp,...); - name - name associated with the child function Output Parameter: . fptr - function pointer Level: advanced Concepts: objects^composing functions Concepts: composing functions Concepts: functions^querying Concepts: objects^querying Concepts: querying objects .seealso: PetscObjectComposeFunction(), PetscFunctionListFind() M*/ PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject obj,const char name[],void (**ptr)(void)) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeader(obj,1); PetscValidCharPointer(name,2); ierr = (*obj->bops->queryfunction)(obj,name,ptr);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode PetscObjectComposeFunction_Private(PetscObject obj,const char name[],void (*fptr)(void)) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeader(obj,1); PetscValidCharPointer(name,2); ierr = (*obj->bops->composefunction)(obj,name,fptr);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C PetscDrawBoxedString - Draws a string with a box around it Not Collective Input Parameters: + draw - the drawing context . sxl - the coordinates of center of the box . syl - the coordinates of top line of box . sc - the color of the text . bc - the color of the bounding box - text - the text to draw Output Parameter: . w,h - width and height of resulting box (optional) Level: beginner Concepts: drawing^string Concepts: string^drawing .seealso: PetscDrawStringVertical(), PetscDrawBoxedStringSize() @*/ PetscErrorCode PetscDrawBoxedString(PetscDraw draw,PetscReal sxl,PetscReal syl,int sc,int bc,const char text[],PetscReal *w,PetscReal *h) { PetscErrorCode ierr ; PetscBool isnull; PetscReal top,left,right,bottom,tw,th; size_t len,mlen = 0; char **array; int cnt,i; PetscFunctionBegin; PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); PetscValidCharPointer(text,5); ierr = PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);CHKERRQ(ierr); if (isnull) PetscFunctionReturn(0); if (draw->ops->boxedstring) { ierr = (*draw->ops->boxedstring)(draw,sxl,syl,sc,bc,text,w,h);CHKERRQ(ierr); PetscFunctionReturn(0); } ierr = PetscStrToArray(text,'\n',&cnt,&array);CHKERRQ(ierr); for (i=0; i<cnt; i++) { ierr = PetscStrlen(array[i],&len);CHKERRQ(ierr); mlen = PetscMax(mlen,len); } ierr = PetscDrawStringGetSize(draw,&tw,&th);CHKERRQ(ierr); top = syl; left = sxl - .5*(mlen + 2)*tw; right = sxl + .5*(mlen + 2)*tw; bottom = syl - (1.0 + cnt)*th; if (w) *w = right - left; if (h) *h = top - bottom; /* compute new bounding box */ draw->boundbox_xl = PetscMin(draw->boundbox_xl,left); draw->boundbox_xr = PetscMax(draw->boundbox_xr,right); draw->boundbox_yl = PetscMin(draw->boundbox_yl,bottom); draw->boundbox_yr = PetscMax(draw->boundbox_yr,top); /* top, left, bottom, right lines */ ierr = PetscDrawLine(draw,left,top,right,top,bc);CHKERRQ(ierr); ierr = PetscDrawLine(draw,left,bottom,left,top,bc);CHKERRQ(ierr); ierr = PetscDrawLine(draw,right,bottom,right,top,bc);CHKERRQ(ierr); ierr = PetscDrawLine(draw,left,bottom,right,bottom,bc);CHKERRQ(ierr); for (i=0; i<cnt; i++) { ierr = PetscDrawString(draw,left + tw,top - (1.5 + i)*th,sc,array[i]);CHKERRQ(ierr); } ierr = PetscStrToArrayDestroy(cnt,array);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode PetscViewerMathematicaSetLinkHost(PetscViewer v, const char *host) { PetscViewer_Mathematica *vmath = (PetscViewer_Mathematica*) v->data; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1); PetscValidCharPointer(host,2); ierr = PetscStrallocpy(host, &vmath->linkhost);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C PetscViewerHDF5GetGroup - Get the current HDF5 group for output. If none has been assigned, returns NULL. Not collective Input Parameter: . viewer - the PetscViewer Output Parameter: . name - The group name Level: intermediate .seealso: PetscViewerHDF5Open(),PetscViewerHDF5PushGroup(),PetscViewerHDF5PopGroup() @*/ PetscErrorCode PetscViewerHDF5GetGroup(PetscViewer viewer, const char **name) { PetscViewer_HDF5 *hdf5 = (PetscViewer_HDF5 *) viewer->data; PetscFunctionBegin; PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); PetscValidCharPointer(name,2); if (hdf5->groups) *name = hdf5->groups->name; else *name = NULL; PetscFunctionReturn(0); }
/*@ SNESMultiblockSetIS - Sets the global row indices for the block Logically Collective on SNES Input Parameters: + snes - the solver context . name - name of this block, if PETSC_NULL the number of the block is used - is - the index set that defines the global row indices in this block Notes: Use SNESMultiblockSetFields(), for blocks defined by strides. This function is called once per block (it creates a new block each time). Solve options for this block will be available under the prefix -multiblock_BLOCKNAME_. Level: intermediate .seealso: SNESMultiblockGetSubSNES(), SNESMULTIBLOCK, SNESMultiblockSetBlockSize() @*/ PetscErrorCode SNESMultiblockSetIS(SNES snes, const char name[], IS is) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); PetscValidCharPointer(name, 2); PetscValidHeaderSpecific(is, IS_CLASSID, 3); ierr = PetscTryMethod(snes, "SNESMultiblockSetIS_C", (SNES, const char[], IS), (snes, name, is));CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C PetscObjectQuery - Gets a PETSc object associated with a given object. Not Collective Input Parameters: + obj - the PETSc object Thus must be cast with a (PetscObject), for example, PetscObjectCompose((PetscObject)mat,...); . name - name associated with child object - ptr - the other PETSc object associated with the PETSc object, this must be cast with (PetscObject*) Level: advanced The reference count of neither object is increased in this call Concepts: objects^composing Concepts: composing objects Concepts: objects^querying Concepts: querying objects .seealso: PetscObjectCompose() @*/ PetscErrorCode PetscObjectQuery(PetscObject obj,const char name[],PetscObject *ptr) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeader(obj,1); PetscValidCharPointer(name,2); PetscValidPointer(ptr,3); ierr = (*obj->bops->query)(obj,name,ptr);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C PetscObjectCompose - Associates another PETSc object with a given PETSc object. Not Collective Input Parameters: + obj - the PETSc object; this must be cast with (PetscObject), for example, PetscObjectCompose((PetscObject)mat,...); . name - name associated with the child object - ptr - the other PETSc object to associate with the PETSc object; this must also be cast with (PetscObject) Level: advanced Notes: The second objects reference count is automatically increased by one when it is composed. Replaces any previous object that had the same name. If ptr is null and name has previously been composed using an object, then that entry is removed from the obj. PetscObjectCompose() can be used with any PETSc object (such as Mat, Vec, KSP, SNES, etc.) or any user-provided object. See PetscContainerCreate() for info on how to create an object from a user-provided pointer that may then be composed with PETSc objects. Concepts: objects^composing Concepts: composing objects .seealso: PetscObjectQuery(), PetscContainerCreate() @*/ PetscErrorCode PETSC_DLLEXPORT PetscObjectCompose(PetscObject obj,const char name[],PetscObject ptr) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeader(obj,1); PetscValidCharPointer(name,2); if (ptr) PetscValidHeader(ptr,3); ierr = (*obj->bops->compose)(obj,name,ptr);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C PetscObjectCompose - Associates another PETSc object with a given PETSc object. Not Collective Input Parameters: + obj - the PETSc object; this must be cast with (PetscObject), for example, PetscObjectCompose((PetscObject)mat,...); . name - name associated with the child object - ptr - the other PETSc object to associate with the PETSc object; this must also be cast with (PetscObject) Level: advanced Notes: The second objects reference count is automatically increased by one when it is composed. Replaces any previous object that had the same name. If ptr is null and name has previously been composed using an object, then that entry is removed from the obj. PetscObjectCompose() can be used with any PETSc object (such as Mat, Vec, KSP, SNES, etc.) or any user-provided object. See PetscContainerCreate() for info on how to create an object from a user-provided pointer that may then be composed with PETSc objects. Concepts: objects^composing Concepts: composing objects .seealso: PetscObjectQuery(), PetscContainerCreate() @*/ PetscErrorCode PetscObjectCompose(PetscObject obj,const char name[],PetscObject ptr) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeader(obj,1); PetscValidCharPointer(name,2); if (ptr) PetscValidHeader(ptr,3); if (obj == ptr) SETERRQ(PetscObjectComm((PetscObject)obj),PETSC_ERR_SUP,"Cannot compose object with itself"); ierr = (*obj->bops->compose)(obj,name,ptr);CHKERRQ(ierr); PetscFunctionReturn(0); }