/*@C SNESMonitorSetRatio - Sets SNES to use a monitor that prints the ratio of the function norm at each iteration. Collective on SNES Input Parameters: + snes - the SNES context - viewer - ASCII viewer to print output Level: intermediate .keywords: SNES, nonlinear, monitor, norm .seealso: SNESMonitorSet(), SNESMonitorSolution(), SNESMonitorDefault() @*/ PetscErrorCode SNESMonitorSetRatio(SNES snes,PetscViewer viewer) { PetscErrorCode ierr; SNESMonitorRatioContext *ctx; PetscReal *history; PetscFunctionBegin; ierr = PetscNewLog(snes,&ctx);CHKERRQ(ierr); ierr = SNESGetConvergenceHistory(snes,&history,NULL,NULL);CHKERRQ(ierr); if (!history) { ierr = PetscMalloc1(100,&ctx->history);CHKERRQ(ierr); ierr = SNESSetConvergenceHistory(snes,ctx->history,0,100,PETSC_TRUE);CHKERRQ(ierr); } ctx->viewer = viewer; ierr = SNESMonitorSet(snes,SNESMonitorRatio,ctx,SNESMonitorRatioDestroy);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C SNESMonitorSetRatio - Sets SNES to use a monitor that prints the ratio of the function norm at each iteration. Collective on SNES Input Parameters: + snes - the SNES context - viewer - ASCII viewer to print output Level: intermediate .keywords: SNES, nonlinear, monitor, norm .seealso: SNESMonitorSet(), SNESMonitorSolution(), SNESMonitorDefault() @*/ PetscErrorCode SNESMonitorSetRatio(SNES snes,PetscViewer viewer) { PetscErrorCode ierr; SNESMonitorRatioContext *ctx; PetscReal *history; PetscFunctionBegin; if (!viewer) { ierr = PetscViewerASCIIOpen(((PetscObject)snes)->comm,"stdout",&viewer);CHKERRQ(ierr); ierr = PetscObjectReference((PetscObject)viewer);CHKERRQ(ierr); } ierr = PetscNewLog(snes,SNESMonitorRatioContext,&ctx);CHKERRQ(ierr); ierr = SNESGetConvergenceHistory(snes,&history,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr); if (!history) { ierr = PetscMalloc(100*sizeof(PetscReal),&ctx->history);CHKERRQ(ierr); ierr = SNESSetConvergenceHistory(snes,ctx->history,0,100,PETSC_TRUE);CHKERRQ(ierr); } ctx->viewer = viewer; ierr = SNESMonitorSet(snes,SNESMonitorRatio,ctx,SNESMonitorRatioDestroy);CHKERRQ(ierr); PetscFunctionReturn(0); }