本文整理汇总了C++中PetscViewerASCIIAddTab函数的典型用法代码示例。如果您正苦于以下问题:C++ PetscViewerASCIIAddTab函数的具体用法?C++ PetscViewerASCIIAddTab怎么用?C++ PetscViewerASCIIAddTab使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PetscViewerASCIIAddTab函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: value
/*@C
KSPMonitorRange - Prints the percentage of residual elements that are more then 10 percent of the maximum value.
Collective on KSP
Input Parameters:
+ ksp - iterative context
. it - iteration number
. rnorm - 2-norm (preconditioned) residual value (may be estimated).
- dummy - an ASCII viewer
Options Database Key:
. -ksp_monitor_range - Activates KSPMonitorRange()
Level: intermediate
.keywords: KSP, default, monitor, residual
.seealso: KSPMonitorSet(), KSPMonitorDefault(), KSPMonitorLGResidualNormCreate()
@*/
PetscErrorCode KSPMonitorRange(KSP ksp,PetscInt it,PetscReal rnorm,PetscViewerAndFormat *dummy)
{
PetscErrorCode ierr;
PetscReal perc,rel;
PetscViewer viewer = dummy->viewer;
/* should be in a MonitorRangeContext */
static PetscReal prev;
PetscFunctionBegin;
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,4);
ierr = PetscViewerPushFormat(viewer,dummy->format);
CHKERRQ(ierr);
ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)ksp)->tablevel);
CHKERRQ(ierr);
if (!it) prev = rnorm;
if (it == 0 && ((PetscObject)ksp)->prefix) {
ierr = PetscViewerASCIIPrintf(viewer," Residual norms for %s solve.\n",((PetscObject)ksp)->prefix);
CHKERRQ(ierr);
}
ierr = KSPMonitorRange_Private(ksp,it,&perc);
CHKERRQ(ierr);
rel = (prev - rnorm)/prev;
prev = rnorm;
ierr = PetscViewerASCIIPrintf(viewer,"%3D KSP preconditioned resid norm %14.12e Percent values above 20 percent of maximum %5.2f relative decrease %5.2e ratio %5.2e \n",it,(double)rnorm,(double)(100.0*perc),(double)rel,(double)(rel/perc));
CHKERRQ(ierr);
ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)ksp)->tablevel);
CHKERRQ(ierr);
ierr = PetscViewerPopFormat(viewer);
CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例2: norm
/*@C
KSPMonitorTrueResidualMaxNorm - Prints the true residual max norm as well as the preconditioned
residual norm at each iteration of an iterative solver.
Collective on KSP
Input Parameters:
+ ksp - iterative context
. n - iteration number
. rnorm - norm (preconditioned) residual value (may be estimated).
- dummy - an ASCII viewer
Options Database Key:
. -ksp_monitor_max - Activates KSPMonitorTrueResidualMaxNorm()
Notes:
This could be implemented (better) with a flag in ksp.
Level: intermediate
.keywords: KSP, default, monitor, residual
.seealso: KSPMonitorSet(), KSPMonitorDefault(), KSPMonitorLGResidualNormCreate(),KSPMonitorTrueResidualNorm()
@*/
PetscErrorCode KSPMonitorTrueResidualMaxNorm(KSP ksp,PetscInt n,PetscReal rnorm,void *dummy)
{
PetscErrorCode ierr;
Vec resid;
PetscReal truenorm,bnorm;
PetscViewer viewer = (PetscViewer)dummy;
char normtype[256];
PetscFunctionBegin;
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,4);
ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)ksp)->tablevel);CHKERRQ(ierr);
if (n == 0 && ((PetscObject)ksp)->prefix) {
ierr = PetscViewerASCIIPrintf(viewer," Residual norms (max) for %s solve.\n",((PetscObject)ksp)->prefix);CHKERRQ(ierr);
}
ierr = KSPBuildResidual(ksp,NULL,NULL,&resid);CHKERRQ(ierr);
ierr = VecNorm(resid,NORM_INFINITY,&truenorm);CHKERRQ(ierr);
ierr = VecDestroy(&resid);CHKERRQ(ierr);
ierr = VecNorm(ksp->vec_rhs,NORM_INFINITY,&bnorm);CHKERRQ(ierr);
ierr = PetscStrncpy(normtype,KSPNormTypes[ksp->normtype],sizeof(normtype));CHKERRQ(ierr);
ierr = PetscStrtolower(normtype);CHKERRQ(ierr);
/* ierr = PetscViewerASCIIPrintf(viewer,"%3D KSP %s resid norm %14.12e true resid norm %14.12e ||r(i)||_inf/||b||_inf %14.12e\n",n,normtype,(double)rnorm,(double)truenorm,(double)(truenorm/bnorm));CHKERRQ(ierr); */
ierr = PetscViewerASCIIPrintf(viewer,"%3D KSP true resid max norm %14.12e ||r(i)||/||b|| %14.12e\n",n,(double)truenorm,(double)(truenorm/bnorm));CHKERRQ(ierr);
ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)ksp)->tablevel);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例3: value
/*@C
KSPMonitorSNES - Print the residual norm of the nonlinear function at each iteration of the linear iterative solver.
Collective on KSP
Input Parameters:
+ ksp - iterative context
. n - iteration number
. rnorm - 2-norm (preconditioned) residual value (may be estimated).
- dummy - unused monitor context
Level: intermediate
.keywords: KSP, default, monitor, residual
.seealso: KSPMonitorSet(), KSPMonitorTrueResidualNorm(), KSPMonitorLGResidualNormCreate()
@*/
PetscErrorCode KSPMonitorSNES(KSP ksp,PetscInt n,PetscReal rnorm,void *dummy)
{
PetscErrorCode ierr;
PetscViewer viewer;
SNES snes = (SNES) dummy;
Vec snes_solution,work1,work2;
PetscReal snorm;
PetscFunctionBegin;
ierr = SNESGetSolution(snes,&snes_solution);CHKERRQ(ierr);
ierr = VecDuplicate(snes_solution,&work1);CHKERRQ(ierr);
ierr = VecDuplicate(snes_solution,&work2);CHKERRQ(ierr);
ierr = KSPBuildSolution(ksp,work1,NULL);CHKERRQ(ierr);
ierr = VecAYPX(work1,-1.0,snes_solution);CHKERRQ(ierr);
ierr = SNESComputeFunction(snes,work1,work2);CHKERRQ(ierr);
ierr = VecNorm(work2,NORM_2,&snorm);CHKERRQ(ierr);
ierr = VecDestroy(&work1);CHKERRQ(ierr);
ierr = VecDestroy(&work2);CHKERRQ(ierr);
ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)ksp),&viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)ksp)->tablevel);CHKERRQ(ierr);
if (n == 0 && ((PetscObject)ksp)->prefix) {
ierr = PetscViewerASCIIPrintf(viewer," Residual norms for %s solve.\n",((PetscObject)ksp)->prefix);CHKERRQ(ierr);
}
ierr = PetscViewerASCIIPrintf(viewer,"%3D SNES Residual norm %5.3e KSP Residual norm %5.3e \n",n,(double)snorm,(double)rnorm);CHKERRQ(ierr);
ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)ksp)->tablevel);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例4: SNESCreate
/*@
PetscConvEstRateView - Displays the convergence rate to a viewer
Collective on SNES
Parameter:
+ snes - iterative context obtained from SNESCreate()
. alpha - the convergence rate for each field
- viewer - the viewer to display the reason
Options Database Keys:
. -snes_convergence_estimate - print the convergence rate
Level: developer
.seealso: PetscConvEstGetRate()
@*/
PetscErrorCode PetscConvEstRateView(PetscConvEst ce, const PetscReal alpha[], PetscViewer viewer)
{
PetscBool isAscii;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscObjectTypeCompare((PetscObject) viewer, PETSCVIEWERASCII, &isAscii);CHKERRQ(ierr);
if (isAscii) {
DM dm;
PetscInt Nf, f;
ierr = SNESGetDM(ce->snes, &dm);CHKERRQ(ierr);
ierr = DMGetNumFields(dm, &Nf);CHKERRQ(ierr);
ierr = PetscViewerASCIIAddTab(viewer, ((PetscObject) ce)->tablevel);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer, "L_2 convergence rate: ");CHKERRQ(ierr);
if (Nf > 1) {ierr = PetscViewerASCIIPrintf(viewer, "[");CHKERRQ(ierr);}
for (f = 0; f < Nf; ++f) {
if (f > 0) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);}
ierr = PetscViewerASCIIPrintf(viewer, "%#.2g", (double) alpha[f]);CHKERRQ(ierr);
}
if (Nf > 1) {ierr = PetscViewerASCIIPrintf(viewer, "]");CHKERRQ(ierr);}
ierr = PetscViewerASCIIPrintf(viewer, "\n");CHKERRQ(ierr);
ierr = PetscViewerASCIISubtractTab(viewer, ((PetscObject) ce)->tablevel);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例5: value
/*@C
KSPMonitorTrueResidualNorm - Prints the true residual norm as well as the preconditioned
residual norm at each iteration of an iterative solver.
Collective on KSP
Input Parameters:
+ ksp - iterative context
. n - iteration number
. rnorm - 2-norm (preconditioned) residual value (may be estimated).
- dummy - unused monitor context
Options Database Key:
. -ksp_monitor_true_residual - Activates KSPMonitorTrueResidualNorm()
Notes:
When using right preconditioning, these values are equivalent.
Level: intermediate
.keywords: KSP, default, monitor, residual
.seealso: KSPMonitorSet(), KSPMonitorDefault(), KSPMonitorLGResidualNormCreate(),KSPMonitorTrueResidualMaxNorm()
@*/
PetscErrorCode KSPMonitorTrueResidualNorm(KSP ksp,PetscInt n,PetscReal rnorm,void *dummy)
{
PetscErrorCode ierr;
Vec resid;
PetscReal truenorm,bnorm;
PetscViewer viewer = (PetscViewer)dummy;
char normtype[256];
PetscFunctionBegin;
if (!viewer) {
ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)ksp),&viewer);CHKERRQ(ierr);
}
ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)ksp)->tablevel);CHKERRQ(ierr);
if (n == 0 && ((PetscObject)ksp)->prefix) {
ierr = PetscViewerASCIIPrintf(viewer," Residual norms for %s solve.\n",((PetscObject)ksp)->prefix);CHKERRQ(ierr);
}
ierr = KSPBuildResidual(ksp,NULL,NULL,&resid);CHKERRQ(ierr);
ierr = VecNorm(resid,NORM_2,&truenorm);CHKERRQ(ierr);
ierr = VecDestroy(&resid);CHKERRQ(ierr);
ierr = VecNorm(ksp->vec_rhs,NORM_2,&bnorm);CHKERRQ(ierr);
ierr = PetscStrncpy(normtype,KSPNormTypes[ksp->normtype],sizeof(normtype));CHKERRQ(ierr);
ierr = PetscStrtolower(normtype);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer,"%3D KSP %s resid norm %14.12e true resid norm %14.12e ||r(i)||/||b|| %14.12e\n",n,normtype,(double)rnorm,(double)truenorm,(double)(truenorm/bnorm));CHKERRQ(ierr);
ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)ksp)->tablevel);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例6: KSPMonitorSingularValue
/*@C
KSPMonitorSingularValue - Prints the two norm of the true residual and
estimation of the extreme singular values of the preconditioned problem
at each iteration.
Logically Collective on KSP
Input Parameters:
+ ksp - the iterative context
. n - the iteration
- rnorm - the two norm of the residual
Options Database Key:
. -ksp_monitor_singular_value - Activates KSPMonitorSingularValue()
Notes:
The CG solver uses the Lanczos technique for eigenvalue computation,
while GMRES uses the Arnoldi technique; other iterative methods do
not currently compute singular values.
Level: intermediate
.keywords: KSP, CG, default, monitor, extreme, singular values, Lanczos, Arnoldi
.seealso: KSPComputeExtremeSingularValues()
@*/
PetscErrorCode KSPMonitorSingularValue(KSP ksp,PetscInt n,PetscReal rnorm,PetscViewerAndFormat *dummy)
{
PetscReal emin,emax,c;
PetscErrorCode ierr;
PetscViewer viewer = dummy->viewer;
PetscFunctionBegin;
PetscValidHeaderSpecific(ksp,KSP_CLASSID,1);
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,4);
ierr = PetscViewerPushFormat(viewer,dummy->format);
CHKERRQ(ierr);
ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)ksp)->tablevel);
CHKERRQ(ierr);
if (!ksp->calc_sings) {
ierr = PetscViewerASCIIPrintf(viewer,"%3D KSP Residual norm %14.12e \n",n,(double)rnorm);
CHKERRQ(ierr);
} else {
ierr = KSPComputeExtremeSingularValues(ksp,&emax,&emin);
CHKERRQ(ierr);
c = emax/emin;
ierr = PetscViewerASCIIPrintf(viewer,"%3D KSP Residual norm %14.12e %% max %14.12e min %14.12e max/min %14.12e\n",n,(double)rnorm,(double)emax,(double)emin,(double)c);
CHKERRQ(ierr);
}
ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)ksp)->tablevel);
CHKERRQ(ierr);
ierr = PetscViewerPopFormat(viewer);
CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例7: Default
/*
Default (short) KSP Monitor, same as KSPMonitorDefault() except
it prints fewer digits of the residual as the residual gets smaller.
This is because the later digits are meaningless and are often
different on different machines; by using this routine different
machines will usually generate the same output.
*/
PetscErrorCode KSPMonitorDefaultShort(KSP ksp,PetscInt its,PetscReal fnorm,PetscViewerAndFormat *dummy)
{
PetscErrorCode ierr;
PetscViewer viewer = dummy->viewer;
PetscFunctionBegin;
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,4);
ierr = PetscViewerPushFormat(viewer,dummy->format);
CHKERRQ(ierr);
ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)ksp)->tablevel);
CHKERRQ(ierr);
if (its == 0 && ((PetscObject)ksp)->prefix) {
ierr = PetscViewerASCIIPrintf(viewer," Residual norms for %s solve.\n",((PetscObject)ksp)->prefix);
CHKERRQ(ierr);
}
if (fnorm > 1.e-9) {
ierr = PetscViewerASCIIPrintf(viewer,"%3D KSP Residual norm %g \n",its,(double)fnorm);
CHKERRQ(ierr);
} else if (fnorm > 1.e-11) {
ierr = PetscViewerASCIIPrintf(viewer,"%3D KSP Residual norm %5.3e \n",its,(double)fnorm);
CHKERRQ(ierr);
} else {
ierr = PetscViewerASCIIPrintf(viewer,"%3D KSP Residual norm < 1.e-11\n",its);
CHKERRQ(ierr);
}
ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)ksp)->tablevel);
CHKERRQ(ierr);
ierr = PetscViewerPopFormat(viewer);
CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例8: SNESQNApply_BadBroyden
PetscErrorCode SNESQNApply_BadBroyden(SNES snes,PetscInt it,Vec Y,Vec X,Vec Xold,Vec D,Vec Dold)
{
PetscErrorCode ierr;
SNES_QN *qn = (SNES_QN*)snes->data;
Vec W = snes->work[3];
Vec *U = qn->U;
Vec *T = qn->V;
/* ksp thing for Jacobian scaling */
PetscInt h,k,j,i,lits;
PetscInt m = qn->m;
PetscScalar gdot,udot;
PetscInt l = m;
PetscFunctionBegin;
if (it < m) l = it;
ierr = VecCopy(D,Y);CHKERRQ(ierr);
if (l > 0) {
k = (it-1)%l;
ierr = SNESLineSearchGetLambda(snes->linesearch,&qn->lambda[k]);CHKERRQ(ierr);
ierr = VecCopy(Dold,U[k]);CHKERRQ(ierr);
ierr = VecAXPY(U[k],-1.0,D);CHKERRQ(ierr);
ierr = VecCopy(Xold,T[k]);CHKERRQ(ierr);
ierr = VecAXPY(T[k],-1.0,X);CHKERRQ(ierr);
}
if (qn->scale_type == SNES_QN_SCALE_JACOBIAN) {
ierr = KSPSolve(snes->ksp,Y,W);CHKERRQ(ierr);
SNESCheckKSPSolve(snes);
ierr = KSPGetIterationNumber(snes->ksp,&lits);CHKERRQ(ierr);
snes->linear_its += lits;
ierr = VecCopy(W,Y);CHKERRQ(ierr);
} else {
ierr = VecScale(Y,qn->scaling);CHKERRQ(ierr);
}
/* inward recursion starting at the first update and working forward */
if (l > 0) {
for (i = 0; i < l-1; i++) {
j = (it+i-l)%l;
k = (it+i-l+1)%l;
h = (it-1)%l;
ierr = VecDotBegin(U[j],U[h],&gdot);CHKERRQ(ierr);
ierr = VecDotBegin(U[j],U[j],&udot);CHKERRQ(ierr);
ierr = VecDotEnd(U[j],U[h],&gdot);CHKERRQ(ierr);
ierr = VecDotEnd(U[j],U[j],&udot);CHKERRQ(ierr);
ierr = VecAXPY(Y,PetscRealPart(gdot)/PetscRealPart(udot),T[k]);CHKERRQ(ierr);
ierr = VecAXPY(Y,-(1.-qn->lambda[k])*PetscRealPart(gdot)/PetscRealPart(udot),T[j]);CHKERRQ(ierr);
if (qn->monitor) {
ierr = PetscViewerASCIIAddTab(qn->monitor,((PetscObject)snes)->tablevel+2);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(qn->monitor, "it: %d k: %d gdot: %14.12e\n", it, k, PetscRealPart(gdot));CHKERRQ(ierr);
ierr = PetscViewerASCIISubtractTab(qn->monitor,((PetscObject)snes)->tablevel+2);CHKERRQ(ierr);
}
}
}
PetscFunctionReturn(0);
}
示例9: TSAdaptCheckStage
/*@
TSAdaptCheckStage - checks whether to accept a stage, (e.g. reject and change time step size if nonlinear solve fails)
Collective on TSAdapt
Input Arguments:
+ adapt - adaptive controller context
. ts - time stepper
. t - Current simulation time
- Y - Current solution vector
Output Arguments:
. accept - PETSC_TRUE to accept the stage, PETSC_FALSE to reject
Level: developer
.seealso:
@*/
PetscErrorCode TSAdaptCheckStage(TSAdapt adapt,TS ts,PetscReal t,Vec Y,PetscBool *accept)
{
PetscErrorCode ierr;
SNESConvergedReason snesreason = SNES_CONVERGED_ITERATING;
PetscFunctionBegin;
PetscValidHeaderSpecific(adapt,TSADAPT_CLASSID,1);
PetscValidHeaderSpecific(ts,TS_CLASSID,2);
PetscValidIntPointer(accept,3);
if (ts->snes) {ierr = SNESGetConvergedReason(ts->snes,&snesreason);CHKERRQ(ierr);}
if (snesreason < 0) {
*accept = PETSC_FALSE;
if (++ts->num_snes_failures >= ts->max_snes_failures && ts->max_snes_failures > 0) {
ts->reason = TS_DIVERGED_NONLINEAR_SOLVE;
ierr = PetscInfo2(ts,"Step=%D, nonlinear solve failures %D greater than current TS allowed, stopping solve\n",ts->steps,ts->num_snes_failures);CHKERRQ(ierr);
if (adapt->monitor) {
ierr = PetscViewerASCIIAddTab(adapt->monitor,((PetscObject)adapt)->tablevel);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(adapt->monitor," TSAdapt %s step %3D stage rejected t=%-11g+%10.3e, nonlinear solve failures %D greater than current TS allowed\n",((PetscObject)adapt)->type_name,ts->steps,(double)ts->ptime,(double)ts->time_step,ts->num_snes_failures);CHKERRQ(ierr);
ierr = PetscViewerASCIISubtractTab(adapt->monitor,((PetscObject)adapt)->tablevel);CHKERRQ(ierr);
}
}
} else {
*accept = PETSC_TRUE;
ierr = TSFunctionDomainError(ts,t,Y,accept);CHKERRQ(ierr);
if(*accept && adapt->checkstage) {
ierr = (*adapt->checkstage)(adapt,ts,t,Y,accept);CHKERRQ(ierr);
}
}
if(!(*accept) && !ts->reason) {
PetscReal dt,new_dt;
ierr = TSGetTimeStep(ts,&dt);CHKERRQ(ierr);
new_dt = dt * adapt->scale_solve_failed;
ierr = TSSetTimeStep(ts,new_dt);CHKERRQ(ierr);
adapt->timestepjustdecreased += adapt->timestepjustdecreased_delay;
if (adapt->monitor) {
ierr = PetscViewerASCIIAddTab(adapt->monitor,((PetscObject)adapt)->tablevel);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(adapt->monitor," TSAdapt %s step %3D stage rejected (%s) t=%-11g+%10.3e retrying with dt=%-10.3e\n",((PetscObject)adapt)->type_name,ts->steps,SNESConvergedReasons[snesreason],(double)ts->ptime,(double)dt,(double)new_dt);CHKERRQ(ierr);
ierr = PetscViewerASCIISubtractTab(adapt->monitor,((PetscObject)adapt)->tablevel);CHKERRQ(ierr);
}
}
PetscFunctionReturn(0);
}
示例10: solvers
/*@C
SNESMonitorDefault - Monitors progress of the SNES solvers (default).
Collective on SNES
Input Parameters:
+ snes - the SNES context
. its - iteration number
. fgnorm - 2-norm of residual
- dummy - unused context
Notes:
This routine prints the residual norm at each iteration.
Level: intermediate
.keywords: SNES, nonlinear, default, monitor, norm
.seealso: SNESMonitorSet(), SNESMonitorSolution()
@*/
PetscErrorCode SNESMonitorDefault(SNES snes,PetscInt its,PetscReal fgnorm,void *dummy)
{
PetscErrorCode ierr;
PetscViewer viewer = dummy ? (PetscViewer) dummy : PETSC_VIEWER_STDOUT_(((PetscObject)snes)->comm);
PetscFunctionBegin;
ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)snes)->tablevel);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer,"%3D SNES Function norm %14.12e \n",its,(double)fgnorm);CHKERRQ(ierr);
ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)snes)->tablevel);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例11: solvers
/*@C
SNESMonitorDefault - Monitors progress of the SNES solvers (default).
Collective on SNES
Input Parameters:
+ snes - the SNES context
. its - iteration number
. fgnorm - 2-norm of residual
- dummy - unused context
Notes:
This routine prints the residual norm at each iteration.
Level: intermediate
.keywords: SNES, nonlinear, default, monitor, norm
.seealso: SNESMonitorSet(), SNESMonitorSolution()
@*/
PetscErrorCode SNESMonitorDefault(SNES snes,PetscInt its,PetscReal fgnorm,void *dummy)
{
PetscErrorCode ierr;
PetscViewer viewer = (PetscViewer) dummy;
PetscFunctionBegin;
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,4);
ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)snes)->tablevel);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer,"%3D SNES Function norm %14.12e \n",its,(double)fgnorm);CHKERRQ(ierr);
ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)snes)->tablevel);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例12: TSAdaptCandidatesClear
/*@C
TSAdaptChoose - choose which method and step size to use for the next step
Collective on TSAdapt
Input Arguments:
+ adapt - adaptive contoller
- h - current step size
Output Arguments:
+ next_sc - optional, scheme to use for the next step
. next_h - step size to use for the next step
- accept - PETSC_TRUE to accept the current step, PETSC_FALSE to repeat the current step with the new step size
Note:
The input value of parameter accept is retained from the last time step, so it will be PETSC_FALSE if the step is
being retried after an initial rejection.
Level: developer
.seealso: TSAdapt, TSAdaptCandidatesClear(), TSAdaptCandidateAdd()
@*/
PetscErrorCode TSAdaptChoose(TSAdapt adapt,TS ts,PetscReal h,PetscInt *next_sc,PetscReal *next_h,PetscBool *accept)
{
PetscErrorCode ierr;
PetscInt ncandidates = adapt->candidates.n;
PetscInt scheme = 0;
PetscReal wlte = -1.0;
PetscReal wltea = -1.0;
PetscReal wlter = -1.0;
PetscFunctionBegin;
PetscValidHeaderSpecific(adapt,TSADAPT_CLASSID,1);
PetscValidHeaderSpecific(ts,TS_CLASSID,2);
if (next_sc) PetscValidIntPointer(next_sc,4);
PetscValidPointer(next_h,5);
PetscValidIntPointer(accept,6);
if (next_sc) *next_sc = 0;
/* Do not mess with adaptivity while handling events*/
if (ts->event && ts->event->status != TSEVENT_NONE) {
*next_h = h;
*accept = PETSC_TRUE;
PetscFunctionReturn(0);
}
ierr = (*adapt->ops->choose)(adapt,ts,h,&scheme,next_h,accept,&wlte,&wltea,&wlter);CHKERRQ(ierr);
if (scheme < 0 || (ncandidates > 0 && scheme >= ncandidates)) SETERRQ2(PetscObjectComm((PetscObject)adapt),PETSC_ERR_ARG_OUTOFRANGE,"Chosen scheme %D not in valid range 0..%D",scheme,ncandidates-1);
if (*next_h < 0) SETERRQ1(PetscObjectComm((PetscObject)adapt),PETSC_ERR_ARG_OUTOFRANGE,"Computed step size %g must be positive",(double)*next_h);
if (next_sc) *next_sc = scheme;
if (*accept && ts->exact_final_time == TS_EXACTFINALTIME_MATCHSTEP) {
/* Increase/reduce step size if end time of next step is close to or overshoots max time */
PetscReal t = ts->ptime + ts->time_step, h = *next_h;
PetscReal tend = t + h, tmax = ts->max_time, hmax = tmax - t;
PetscReal a = (PetscReal)(1.0 + adapt->matchstepfac[0]);
PetscReal b = adapt->matchstepfac[1];
if (t < tmax && tend > tmax) *next_h = hmax;
if (t < tmax && tend < tmax && h*b > hmax) *next_h = hmax/2;
if (t < tmax && tend < tmax && h*a > hmax) *next_h = hmax;
}
if (adapt->monitor) {
const char *sc_name = (scheme < ncandidates) ? adapt->candidates.name[scheme] : "";
ierr = PetscViewerASCIIAddTab(adapt->monitor,((PetscObject)adapt)->tablevel);CHKERRQ(ierr);
if (wlte < 0) {
ierr = PetscViewerASCIIPrintf(adapt->monitor," TSAdapt %s %s %D:%s step %3D %s t=%-11g+%10.3e dt=%-10.3e\n",((PetscObject)adapt)->type_name,((PetscObject)ts)->type_name,scheme,sc_name,ts->steps,*accept ? "accepted" : "rejected",(double)ts->ptime,(double)h,(double)*next_h);CHKERRQ(ierr);
} else {
ierr = PetscViewerASCIIPrintf(adapt->monitor," TSAdapt %s %s %D:%s step %3D %s t=%-11g+%10.3e dt=%-10.3e wlte=%5.3g wltea=%5.3g wlter=%5.3g\n",((PetscObject)adapt)->type_name,((PetscObject)ts)->type_name,scheme,sc_name,ts->steps,*accept ? "accepted" : "rejected",(double)ts->ptime,(double)h,(double)*next_h,(double)wlte,(double)wltea,(double)wlter);CHKERRQ(ierr);
}
ierr = PetscViewerASCIISubtractTab(adapt->monitor,((PetscObject)adapt)->tablevel);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例13: value
/*@C
KSPMonitorDefault - Print the residual norm at each iteration of an
iterative solver.
Collective on KSP
Input Parameters:
+ ksp - iterative context
. n - iteration number
. rnorm - 2-norm (preconditioned) residual value (may be estimated).
- dummy - an ASCII PetscViewer
Level: intermediate
.keywords: KSP, default, monitor, residual
.seealso: KSPMonitorSet(), KSPMonitorTrueResidualNorm(), KSPMonitorLGResidualNormCreate()
@*/
PetscErrorCode KSPMonitorDefault(KSP ksp,PetscInt n,PetscReal rnorm,void *dummy)
{
PetscErrorCode ierr;
PetscViewer viewer = (PetscViewer) dummy;
PetscFunctionBegin;
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,4);
ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)ksp)->tablevel);CHKERRQ(ierr);
if (n == 0 && ((PetscObject)ksp)->prefix) {
ierr = PetscViewerASCIIPrintf(viewer," Residual norms for %s solve.\n",((PetscObject)ksp)->prefix);CHKERRQ(ierr);
}
ierr = PetscViewerASCIIPrintf(viewer,"%3D KSP Residual norm %14.12e \n",n,(double)rnorm);CHKERRQ(ierr);
ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)ksp)->tablevel);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例14: MonitorNorms
static PetscErrorCode
MonitorNorms(SNES snes, PetscInt its, PetscReal fgnorm, void *dummy)
{
PetscViewer viewer = PETSC_VIEWER_STDOUT_WORLD;
Vec dx;
SNESGetSolutionUpdate(snes, &dx);
PetscReal dxnorm;
VecNorm(dx, NORM_2, &dxnorm);
PetscInt tablevel;
PetscObjectGetTabLevel(((PetscObject)snes), &tablevel);
PetscViewerASCIIAddTab(viewer, tablevel);
PetscViewerASCIIPrintf(viewer,"%3D SNES Function norm %14.12e, Solution residual norm %14.12e\n",
its, (double)fgnorm, (double)dxnorm);
PetscViewerASCIISubtractTab(viewer, tablevel);
return(0);
}
示例15: Default
/*
Default (short) SNES Monitor, same as SNESMonitorDefault() except
it prints fewer digits of the residual as the residual gets smaller.
This is because the later digits are meaningless and are often
different on different machines; by using this routine different
machines will usually generate the same output.
*/
PetscErrorCode SNESMonitorDefaultShort(SNES snes,PetscInt its,PetscReal fgnorm,void *dummy)
{
PetscErrorCode ierr;
PetscViewer viewer = dummy ? (PetscViewer) dummy : PETSC_VIEWER_STDOUT_(((PetscObject)snes)->comm);
PetscFunctionBegin;
ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)snes)->tablevel);CHKERRQ(ierr);
if (fgnorm > 1.e-9) {
ierr = PetscViewerASCIIPrintf(viewer,"%3D SNES Function norm %G \n",its,fgnorm);CHKERRQ(ierr);
} else if (fgnorm > 1.e-11){
ierr = PetscViewerASCIIPrintf(viewer,"%3D SNES Function norm %5.3e \n",its,fgnorm);CHKERRQ(ierr);
} else {
ierr = PetscViewerASCIIPrintf(viewer,"%3D SNES Function norm < 1.e-11\n",its);CHKERRQ(ierr);
}
ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)snes)->tablevel);CHKERRQ(ierr);
PetscFunctionReturn(0);
}