本文整理汇总了C++中PetscCheckSameComm函数的典型用法代码示例。如果您正苦于以下问题:C++ PetscCheckSameComm函数的具体用法?C++ PetscCheckSameComm怎么用?C++ PetscCheckSameComm使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PetscCheckSameComm函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MatColoringApply
/*@
MatColoringView - Output details about the MatColoring.
Collective on MatColoring
Input Parameters:
- mc - the MatColoring context
+ viewer - the Viewer context
Level: beginner
.keywords: Coloring, view
.seealso: MatColoring, MatColoringApply()
@*/
PetscErrorCode MatColoringView(MatColoring mc,PetscViewer viewer)
{
PetscErrorCode ierr;
PetscBool iascii;
PetscFunctionBegin;
PetscValidHeaderSpecific(mc,MAT_COLORING_CLASSID,1);
if (!viewer) {
ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)mc),&viewer);CHKERRQ(ierr);
}
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
PetscCheckSameComm(mc,1,viewer,2);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
if (iascii) {
ierr = PetscObjectPrintClassNamePrefixType((PetscObject)mc,viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer," Weight type: %s\n",MatColoringWeightTypes[mc->weight_type]);CHKERRQ(ierr);
if (mc->maxcolors > 0) {
ierr = PetscViewerASCIIPrintf(viewer," Distance %d, Max. Colors %d\n",mc->dist,mc->maxcolors);CHKERRQ(ierr);
} else {
ierr = PetscViewerASCIIPrintf(viewer," Distance %d\n",mc->dist);CHKERRQ(ierr);
}
}
PetscFunctionReturn(0);
}
示例2: output
/*@C
MatPartitioningView - Prints the partitioning data structure.
Collective on MatPartitioning
Input Parameters:
. part - the partitioning context
. viewer - optional visualization context
Level: intermediate
Note:
The available visualization contexts include
+ PETSC_VIEWER_STDOUT_SELF - standard output (default)
- PETSC_VIEWER_STDOUT_WORLD - synchronized standard
output where only the first processor opens
the file. All other processors send their
data to the first processor to print.
The user can open alternative visualization contexts with
. PetscViewerASCIIOpen() - output to a specified file
.keywords: Partitioning, view
.seealso: PetscViewerASCIIOpen()
@*/
PetscErrorCode MatPartitioningView(MatPartitioning part,PetscViewer viewer)
{
PetscErrorCode ierr;
PetscBool iascii;
PetscFunctionBegin;
PetscValidHeaderSpecific(part,MAT_PARTITIONING_CLASSID,1);
if (!viewer) {
ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)part),&viewer);CHKERRQ(ierr);
}
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
PetscCheckSameComm(part,1,viewer,2);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
if (iascii) {
ierr = PetscObjectPrintClassNamePrefixType((PetscObject)part,viewer);CHKERRQ(ierr);
if (part->vertex_weights) {
ierr = PetscViewerASCIIPrintf(viewer," Using vertex weights\n");CHKERRQ(ierr);
}
}
if (part->ops->view) {
ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
ierr = (*part->ops->view)(part,viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例3: output
/*@C
MatPartitioningView - Prints the partitioning data structure.
Collective on MatPartitioning
Input Parameters:
. part - the partitioning context
. viewer - optional visualization context
Level: intermediate
Note:
The available visualization contexts include
+ PETSC_VIEWER_STDOUT_SELF - standard output (default)
- PETSC_VIEWER_STDOUT_WORLD - synchronized standard
output where only the first processor opens
the file. All other processors send their
data to the first processor to print.
The user can open alternative visualization contexts with
. PetscViewerASCIIOpen() - output to a specified file
.keywords: Partitioning, view
.seealso: PetscViewerASCIIOpen()
@*/
PetscErrorCode MatPartitioningView(MatPartitioning part,PetscViewer viewer)
{
PetscErrorCode ierr;
PetscBool iascii;
PetscFunctionBegin;
PetscValidHeaderSpecific(part,MAT_PARTITIONING_CLASSID,1);
if (!viewer) {
ierr = PetscViewerASCIIGetStdout(((PetscObject)part)->comm,&viewer);CHKERRQ(ierr);
}
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
PetscCheckSameComm(part,1,viewer,2);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
if (iascii) {
ierr = PetscObjectPrintClassNamePrefixType((PetscObject)part,viewer,"MatPartitioning Object");CHKERRQ(ierr);
if (part->vertex_weights) {
ierr = PetscViewerASCIIPrintf(viewer," Using vertex weights\n");CHKERRQ(ierr);
}
} else {
SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Viewer type %s not supported for this MatParitioning",((PetscObject)viewer)->type_name);
}
if (part->ops->view) {
ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
ierr = (*part->ops->view)(part,viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例4: BVGetColumn
/*@
BVInsertConstraints - Insert a set of vectors as constraints.
Collective on BV
Input Parameters:
+ V - basis vectors
- C - set of vectors to be inserted as constraints
Input/Output Parameter:
. nc - number of input vectors, on output the number of linearly independent
vectors
Notes:
The constraints are relevant only during orthogonalization. Constraint
vectors span a subspace that is deflated in every orthogonalization
operation, so they are intended for removing those directions from the
orthogonal basis computed in regular BV columns.
Constraints are not stored in regular BV colums, but in a special part of
the storage. They can be accessed with negative indices in BVGetColumn().
This operation is DESTRUCTIVE, meaning that all data contained in the
columns of V is lost. This is typically invoked just after creating the BV.
Once a set of constraints has been set, it is not allowed to call this
function again.
The vectors are copied one by one and then orthogonalized against the
previous ones. If any of them is linearly dependent then it is discarded
and the value of nc is decreased. The behaviour is similar to BVInsertVecs().
Level: advanced
.seealso: BVInsertVecs(), BVOrthogonalizeColumn(), BVGetColumn(), BVGetNumConstraints()
@*/
PetscErrorCode BVInsertConstraints(BV V,PetscInt *nc,Vec *C)
{
PetscErrorCode ierr;
PetscInt msave;
PetscFunctionBegin;
PetscValidHeaderSpecific(V,BV_CLASSID,1);
PetscValidPointer(nc,2);
PetscValidLogicalCollectiveInt(V,*nc,2);
if (!*nc) PetscFunctionReturn(0);
if (*nc<0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Number of constraints (given %D) cannot be negative",*nc);
PetscValidPointer(C,3);
PetscValidHeaderSpecific(*C,VEC_CLASSID,3);
PetscValidType(V,1);
BVCheckSizes(V,1);
PetscCheckSameComm(V,1,*C,3);
if (V->nc) SETERRQ(PetscObjectComm((PetscObject)V),PETSC_ERR_ARG_WRONGSTATE,"Constraints already present in this BV object");
if (V->ci[0]!=-1 || V->ci[1]!=-1) SETERRQ(PetscObjectComm((PetscObject)V),PETSC_ERR_SUP,"Cannot call BVInsertConstraints after BVGetColumn");
msave = V->m;
ierr = BVResize(V,*nc+V->m,PETSC_FALSE);CHKERRQ(ierr);
ierr = BVInsertVecs(V,0,nc,C,PETSC_TRUE);CHKERRQ(ierr);
V->nc = *nc;
V->m = msave;
V->ci[0] = -V->nc-1;
V->ci[1] = -V->nc-1;
ierr = PetscObjectStateIncrease((PetscObject)V);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例5: BVInsertVecs
/*@
BVInsertVec - Insert a vector into the specified column.
Collective on BV
Input Parameters:
+ V - basis vectors
. j - the column of V to be overwritten
- w - the vector to be copied
Level: intermediate
.seealso: BVInsertVecs()
@*/
PetscErrorCode BVInsertVec(BV V,PetscInt j,Vec w)
{
PetscErrorCode ierr;
PetscInt n,N;
Vec v;
PetscFunctionBegin;
PetscValidHeaderSpecific(V,BV_CLASSID,1);
PetscValidLogicalCollectiveInt(V,j,2);
PetscValidHeaderSpecific(w,VEC_CLASSID,3);
PetscValidType(V,1);
BVCheckSizes(V,1);
PetscCheckSameComm(V,1,w,3);
ierr = VecGetSize(w,&N);CHKERRQ(ierr);
ierr = VecGetLocalSize(w,&n);CHKERRQ(ierr);
if (N!=V->N || n!=V->n) SETERRQ4(PetscObjectComm((PetscObject)V),PETSC_ERR_ARG_INCOMP,"Vec sizes (global %D, local %D) do not match BV sizes (global %D, local %D)",N,n,V->N,V->n);
if (j<-V->nc || j>=V->m) SETERRQ3(PetscObjectComm((PetscObject)V),PETSC_ERR_ARG_OUTOFRANGE,"Argument j has wrong value %D, should be between %D and %D",j,-V->nc,V->m-1);
ierr = BVGetColumn(V,j,&v);CHKERRQ(ierr);
ierr = VecCopy(w,v);CHKERRQ(ierr);
ierr = BVRestoreColumn(V,j,&v);CHKERRQ(ierr);
ierr = PetscObjectStateIncrease((PetscObject)V);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例6: MatHeaderReplace
PETSC_EXTERN PetscErrorCode MatHeaderReplace(Mat A,Mat C)
{
PetscErrorCode ierr;
PetscInt refct;
PetscObjectState state;
PetscFunctionBegin;
PetscValidHeaderSpecific(A,MAT_CLASSID,1);
PetscValidHeaderSpecific(C,MAT_CLASSID,2);
if (A == C) PetscFunctionReturn(0);
PetscCheckSameComm(A,1,C,2);
if (((PetscObject)C)->refct != 1) SETERRQ1(PetscObjectComm((PetscObject)C),PETSC_ERR_ARG_WRONGSTATE,"Object C has refct %D > 1, would leave hanging reference",((PetscObject)C)->refct);
/* free all the interior data structures from mat */
ierr = (*A->ops->destroy)(A);CHKERRQ(ierr);
ierr = PetscHeaderDestroy_Private((PetscObject)A);CHKERRQ(ierr);
ierr = PetscLayoutDestroy(&A->rmap);CHKERRQ(ierr);
ierr = PetscLayoutDestroy(&A->cmap);CHKERRQ(ierr);
ierr = PetscFree(A->spptr);CHKERRQ(ierr);
/* copy C over to A */
refct = ((PetscObject)A)->refct;
state = ((PetscObject)A)->state;
ierr = PetscMemcpy(A,C,sizeof(struct _p_Mat));CHKERRQ(ierr);
((PetscObject)A)->refct = refct;
((PetscObject)A)->state = state + 1;
ierr = PetscFree(C);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例7: MatHeaderReplace
PETSC_EXTERN PetscErrorCode MatHeaderReplace(Mat A,Mat *C)
{
PetscErrorCode ierr;
PetscInt refct;
PetscObjectState state;
struct _p_Mat buffer;
PetscFunctionBegin;
PetscValidHeaderSpecific(A,MAT_CLASSID,1);
PetscValidHeaderSpecific(*C,MAT_CLASSID,2);
if (A == *C) PetscFunctionReturn(0);
PetscCheckSameComm(A,1,*C,2);
if (((PetscObject)*C)->refct != 1) SETERRQ1(PetscObjectComm((PetscObject)C),PETSC_ERR_ARG_WRONGSTATE,"Object C has refct %D > 1, would leave hanging reference",((PetscObject)*C)->refct);
/* swap C and A */
refct = ((PetscObject)A)->refct;
state = ((PetscObject)A)->state;
ierr = PetscMemcpy(&buffer,A,sizeof(struct _p_Mat));CHKERRQ(ierr);
ierr = PetscMemcpy(A,*C,sizeof(struct _p_Mat));CHKERRQ(ierr);
ierr = PetscMemcpy(*C,&buffer,sizeof(struct _p_Mat));CHKERRQ(ierr);
((PetscObject)A)->refct = refct;
((PetscObject)A)->state = state + 1;
((PetscObject)*C)->refct = 1;
ierr = MatDestroy(C);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例8: BVOrthogonalizeColumn
/*@
BVOrthogonalizeVec - Orthogonalize a given vector with respect to all
active columns.
Collective on BV
Input Parameters:
+ bv - the basis vectors context
- v - the vector
Output Parameters:
+ H - (optional) coefficients computed during orthogonalization
. norm - (optional) norm of the vector after being orthogonalized
- lindep - (optional) flag indicating that refinement did not improve the quality
of orthogonalization
Notes:
This function is equivalent to BVOrthogonalizeColumn() but orthogonalizes
a vector as an argument rather than taking one of the BV columns. The
vector is orthogonalized against all active columns.
Level: advanced
.seealso: BVOrthogonalizeColumn(), BVSetOrthogonalization(), BVSetActiveColumns()
@*/
PetscErrorCode BVOrthogonalizeVec(BV bv,Vec v,PetscScalar *H,PetscReal *norm,PetscBool *lindep)
{
PetscErrorCode ierr;
PetscInt i,ksave,lsave;
PetscFunctionBegin;
PetscValidHeaderSpecific(bv,BV_CLASSID,1);
PetscValidHeaderSpecific(v,VEC_CLASSID,2);
PetscValidType(bv,1);
BVCheckSizes(bv,1);
PetscValidType(v,2);
PetscCheckSameComm(bv,1,v,2);
ierr = PetscLogEventBegin(BV_Orthogonalize,bv,0,0,0);CHKERRQ(ierr);
ksave = bv->k;
lsave = bv->l;
bv->l = -bv->nc; /* must also orthogonalize against constraints and leading columns */
ierr = BV_AllocateCoeffs(bv);CHKERRQ(ierr);
ierr = BV_AllocateSignature(bv);CHKERRQ(ierr);
switch (bv->orthog_type) {
case BV_ORTHOG_CGS:
ierr = BVOrthogonalizeCGS(bv,0,v,H,norm,lindep);CHKERRQ(ierr);
break;
case BV_ORTHOG_MGS:
ierr = BVOrthogonalizeMGS(bv,0,v,NULL,H,norm,lindep);CHKERRQ(ierr);
break;
}
bv->k = ksave;
bv->l = lsave;
if (H) for (i=bv->l;i<bv->k;i++) H[i-bv->l] = bv->h[bv->nc+i];
ierr = PetscLogEventEnd(BV_Orthogonalize,bv,0,0,0);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例9: output
/*@
PFView - Prints information about a mathematical function
Collective on PF unless PetscViewer is PETSC_VIEWER_STDOUT_SELF
Input Parameters:
+ PF - the PF context
- viewer - optional visualization context
Note:
The available visualization contexts include
+ PETSC_VIEWER_STDOUT_SELF - standard output (default)
- PETSC_VIEWER_STDOUT_WORLD - synchronized standard
output where only the first processor opens
the file. All other processors send their
data to the first processor to print.
The user can open an alternative visualization contexts with
PetscViewerASCIIOpen() (output to a specified file).
Level: developer
.keywords: PF, view
.seealso: PetscViewerCreate(), PetscViewerASCIIOpen()
@*/
PetscErrorCode PFView(PF pf,PetscViewer viewer)
{
PetscErrorCode ierr;
PetscBool iascii;
PetscViewerFormat format;
PetscFunctionBegin;
PetscValidHeaderSpecific(pf,PF_CLASSID,1);
if (!viewer) {
ierr = PetscViewerASCIIGetStdout(((PetscObject)pf)->comm,&viewer);CHKERRQ(ierr);
}
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
PetscCheckSameComm(pf,1,viewer,2);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
if (iascii) {
ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
ierr = PetscObjectPrintClassNamePrefixType((PetscObject)pf,viewer,"PF Object");CHKERRQ(ierr);
if (pf->ops->view) {
ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
ierr = (*pf->ops->view)(pf->data,viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
}
} else {
SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Viewer type %s not supported by PF",((PetscObject)viewer)->type_name);
}
PetscFunctionReturn(0);
}
示例10: MatSetLocalToGlobalMapping_IS
PetscErrorCode MatSetLocalToGlobalMapping_IS(Mat A,ISLocalToGlobalMapping rmapping,ISLocalToGlobalMapping cmapping)
{
PetscErrorCode ierr;
PetscInt n,bs;
Mat_IS *is = (Mat_IS*)A->data;
IS from,to;
Vec global;
PetscFunctionBegin;
PetscCheckSameComm(A,1,rmapping,2);
if (rmapping != cmapping) SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_ARG_INCOMP,"MATIS requires the row and column mappings to be identical");
if (is->mapping) { /* Currenly destroys the objects that will be created by this routine. Is there anything else that should be checked? */
ierr = ISLocalToGlobalMappingDestroy(&is->mapping);CHKERRQ(ierr);
ierr = VecDestroy(&is->x);CHKERRQ(ierr);
ierr = VecDestroy(&is->y);CHKERRQ(ierr);
ierr = VecScatterDestroy(&is->ctx);CHKERRQ(ierr);
ierr = MatDestroy(&is->A);CHKERRQ(ierr);
}
ierr = PetscObjectReference((PetscObject)rmapping);CHKERRQ(ierr);
ierr = ISLocalToGlobalMappingDestroy(&is->mapping);CHKERRQ(ierr);
is->mapping = rmapping;
/*
ierr = PetscLayoutSetISLocalToGlobalMapping(A->rmap,rmapping);CHKERRQ(ierr);
ierr = PetscLayoutSetISLocalToGlobalMapping(A->cmap,cmapping);CHKERRQ(ierr);
*/
/* Create the local matrix A */
ierr = ISLocalToGlobalMappingGetSize(rmapping,&n);CHKERRQ(ierr);
ierr = ISLocalToGlobalMappingGetBlockSize(rmapping,&bs);CHKERRQ(ierr);
ierr = MatCreate(PETSC_COMM_SELF,&is->A);CHKERRQ(ierr);
if (bs > 1) {
ierr = MatSetType(is->A,MATSEQBAIJ);CHKERRQ(ierr);
} else {
ierr = MatSetType(is->A,MATSEQAIJ);CHKERRQ(ierr);
}
ierr = MatSetSizes(is->A,n,n,n,n);CHKERRQ(ierr);
ierr = MatSetBlockSize(is->A,bs);CHKERRQ(ierr);
ierr = MatSetOptionsPrefix(is->A,((PetscObject)A)->prefix);CHKERRQ(ierr);
ierr = MatAppendOptionsPrefix(is->A,"is_");CHKERRQ(ierr);
ierr = MatSetFromOptions(is->A);CHKERRQ(ierr);
/* Create the local work vectors */
ierr = VecCreate(PETSC_COMM_SELF,&is->x);CHKERRQ(ierr);
ierr = VecSetBlockSize(is->x,bs);CHKERRQ(ierr);
ierr = VecSetSizes(is->x,n,n);CHKERRQ(ierr);
ierr = VecSetOptionsPrefix(is->x,((PetscObject)A)->prefix);CHKERRQ(ierr);
ierr = VecAppendOptionsPrefix(is->x,"is_");CHKERRQ(ierr);
ierr = VecSetFromOptions(is->x);CHKERRQ(ierr);
ierr = VecDuplicate(is->x,&is->y);CHKERRQ(ierr);
/* setup the global to local scatter */
ierr = ISCreateStride(PETSC_COMM_SELF,n,0,1,&to);CHKERRQ(ierr);
ierr = ISLocalToGlobalMappingApplyIS(rmapping,to,&from);CHKERRQ(ierr);
ierr = MatCreateVecs(A,&global,NULL);CHKERRQ(ierr);
ierr = VecScatterCreate(global,from,is->x,to,&is->ctx);CHKERRQ(ierr);
ierr = VecDestroy(&global);CHKERRQ(ierr);
ierr = ISDestroy(&to);CHKERRQ(ierr);
ierr = ISDestroy(&from);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例11: dUnitsView
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 = PetscObjectTypeCompare((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);
}
示例12: routine
/*@C
TaoSetJacobianDesignRoutine - Sets the function to compute the Jacobian of
the constraint function with respect to the design variables. Used only for
pde-constrained optimization.
Logically collective on Tao
Input Parameters:
+ tao - the Tao context
. J - Matrix used for the jacobian
. jac - Jacobian evaluation routine
- ctx - [optional] user-defined context for private data for the
Jacobian evaluation routine (may be NULL)
Calling sequence of jac:
$ jac (Tao tao,Vec x,Mat *J,void *ctx);
+ tao - the Tao context
. x - input vector
. J - Jacobian matrix
- ctx - [optional] user-defined Jacobian context
Notes:
The function jac() takes Mat * as the matrix arguments rather than Mat.
This allows the Jacobian evaluation routine to replace A and/or B with a
completely new new matrix structure (not just different matrix elements)
when appropriate, for instance, if the nonzero structure is changing
throughout the global iterations.
Level: intermediate
.seealso: TaoComputeJacobianDesign(), TaoSetJacobianStateRoutine(), TaoSetStateDesignIS()
@*/
PetscErrorCode TaoSetJacobianDesignRoutine(Tao tao, Mat J, PetscErrorCode (*func)(Tao, Vec, Mat, void*), void *ctx)
{
PetscErrorCode ierr;
PetscFunctionBegin;
PetscValidHeaderSpecific(tao,TAO_CLASSID,1);
if (J) {
PetscValidHeaderSpecific(J,MAT_CLASSID,2);
PetscCheckSameComm(tao,1,J,2);
}
if (ctx) {
tao->user_jac_designP = ctx;
}
if (func) {
tao->ops->computejacobiandesign = func;
}
if (J) {
ierr = PetscObjectReference((PetscObject)J);
CHKERRQ(ierr);
ierr = MatDestroy(&tao->jacobian_design);
CHKERRQ(ierr);
tao->jacobian_design = J;
}
PetscFunctionReturn(0);
}
示例13: TaoLineSearchComputeObjective
/*@
TaoLineSearchComputeObjective - Computes the objective function value at a given point
Collective on TaoLineSearch
Input Parameters:
+ ls - the TaoLineSearch context
- x - input vector
Output Parameter:
. f - Objective value at X
Notes: TaoLineSearchComputeObjective() is typically used within line searches
so most users would not generally call this routine themselves.
Level: developer
.seealso: TaoLineSearchComputeGradient(), TaoLineSearchComputeObjectiveAndGradient(), TaoLineSearchSetObjectiveRoutine()
@*/
PetscErrorCode TaoLineSearchComputeObjective(TaoLineSearch ls, Vec x, PetscReal *f)
{
PetscErrorCode ierr;
Vec gdummy;
PetscReal gts;
PetscFunctionBegin;
PetscValidHeaderSpecific(ls,TAOLINESEARCH_CLASSID,1);
PetscValidHeaderSpecific(x,VEC_CLASSID,2);
PetscValidPointer(f,3);
PetscCheckSameComm(ls,1,x,2);
if (ls->usetaoroutines) {
ierr = TaoComputeObjective(ls->tao,x,f);CHKERRQ(ierr);
} else {
ierr = PetscLogEventBegin(TaoLineSearch_EvalEvent,ls,0,0,0);CHKERRQ(ierr);
if (!ls->ops->computeobjective && !ls->ops->computeobjectiveandgradient && !ls->ops->computeobjectiveandgts) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"Line Search does not have objective function set");
PetscStackPush("TaoLineSearch user objective routine");
if (ls->ops->computeobjective) {
ierr = (*ls->ops->computeobjective)(ls,x,f,ls->userctx_func);CHKERRQ(ierr);
} else if (ls->ops->computeobjectiveandgradient) {
ierr = VecDuplicate(x,&gdummy);CHKERRQ(ierr);
ierr = (*ls->ops->computeobjectiveandgradient)(ls,x,f,gdummy,ls->userctx_funcgrad);CHKERRQ(ierr);
ierr = VecDestroy(&gdummy);CHKERRQ(ierr);
} else {
ierr = (*ls->ops->computeobjectiveandgts)(ls,x,ls->stepdirection,f,>s,ls->userctx_funcgts);CHKERRQ(ierr);
}
PetscStackPop;
ierr = PetscLogEventEnd(TaoLineSearch_EvalEvent,ls,0,0,0);CHKERRQ(ierr);
}
ls->nfeval++;
PetscFunctionReturn(0);
}
示例14: BVMult
/*@
BVMultVec - Computes y = beta*y + alpha*X*q.
Logically Collective on BV and Vec
Input Parameters:
+ X - a basis vectors object
. alpha,beta - scalars
. y - a vector
- q - an array of scalars
Output Parameter:
. y - the modified vector
Notes:
This operation is the analogue of BVMult() but with a BV and a Vec,
instead of two BV. Note that arguments are listed in different order
with respect to BVMult().
If X has leading columns specified, then these columns do not participate
in the computation.
The length of array q must be equal to the number of active columns of X
minus the number of leading columns, i.e. the first entry of q multiplies
the first non-leading column.
Level: intermediate
.seealso: BVMult(), BVMultColumn(), BVMultInPlace(), BVSetActiveColumns()
@*/
PetscErrorCode BVMultVec(BV X,PetscScalar alpha,PetscScalar beta,Vec y,PetscScalar *q)
{
PetscErrorCode ierr;
PetscInt n,N;
PetscFunctionBegin;
PetscValidHeaderSpecific(X,BV_CLASSID,1);
PetscValidLogicalCollectiveScalar(X,alpha,2);
PetscValidLogicalCollectiveScalar(X,beta,3);
PetscValidHeaderSpecific(y,VEC_CLASSID,4);
PetscValidPointer(q,5);
PetscValidType(X,1);
BVCheckSizes(X,1);
PetscValidType(y,4);
PetscCheckSameComm(X,1,y,4);
ierr = VecGetSize(y,&N);CHKERRQ(ierr);
ierr = VecGetLocalSize(y,&n);CHKERRQ(ierr);
if (N!=X->N || n!=X->n) SETERRQ4(PetscObjectComm((PetscObject)X),PETSC_ERR_ARG_INCOMP,"Vec sizes (global %D, local %D) do not match BV sizes (global %D, local %D)",N,n,X->N,X->n);
if (!X->n) PetscFunctionReturn(0);
ierr = PetscLogEventBegin(BV_Mult,X,y,0,0);CHKERRQ(ierr);
ierr = (*X->ops->multvec)(X,alpha,beta,y,q);CHKERRQ(ierr);
ierr = PetscLogEventEnd(BV_Mult,X,y,0,0);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例15: TSAdaptView
PetscErrorCode TSAdaptView(TSAdapt adapt,PetscViewer viewer)
{
PetscErrorCode ierr;
PetscBool iascii,isbinary;
PetscFunctionBegin;
PetscValidHeaderSpecific(adapt,TSADAPT_CLASSID,1);
if (!viewer) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)adapt),&viewer);CHKERRQ(ierr);}
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
PetscCheckSameComm(adapt,1,viewer,2);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr);
if (iascii) {
ierr = PetscObjectPrintClassNamePrefixType((PetscObject)adapt,viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer," number of candidates %D\n",adapt->candidates.n);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 if (isbinary) {
char type[256];
/* need to save FILE_CLASS_ID for adapt class */
ierr = PetscStrncpy(type,((PetscObject)adapt)->type_name,256);CHKERRQ(ierr);
ierr = PetscViewerBinaryWrite(viewer,type,256,PETSC_CHAR,PETSC_FALSE);CHKERRQ(ierr);
} else if (adapt->ops->view) {
ierr = (*adapt->ops->view)(adapt,viewer);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}