/*@ KSPGetTabLevel - Gets the number of tabs that ASCII output used by ksp. Not Collective Input Parameter: . ksp - a KSP object. Output Parameter: . tab - the number of tabs Level: developer Notes: this is used in conjunction with KSPSetTabLevel() to manage the output from the KSP and its PC coherently. .seealso: KSPSetTabLevel() @*/ PetscErrorCode KSPGetTabLevel(KSP ksp,PetscInt *tab) { PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(ksp,KSP_CLASSID,1); ierr = PetscObjectGetTabLevel((PetscObject)ksp, tab);CHKERRQ(ierr); PetscFunctionReturn(0); }
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); }
/*@C SNESMonitorDefaultField - Monitors progress of the SNES solvers, separated into fields. Collective on SNES Input Parameters: + snes - the SNES context . its - iteration number . fgnorm - 2-norm of residual - ctx - the PetscViewer Notes: This routine uses the DM attached to the residual vector Level: intermediate .keywords: SNES, nonlinear, field, monitor, norm .seealso: SNESMonitorSet(), SNESMonitorSolution(), SNESMonitorDefault(), SNESMonitorDefaultShort() @*/ PetscErrorCode SNESMonitorDefaultField(SNES snes, PetscInt its, PetscReal fgnorm, void *ctx) { PetscViewer viewer = (PetscViewer) ctx; Vec r; DM dm; PetscReal res[256]; PetscInt tablevel; PetscErrorCode ierr; PetscFunctionBegin; PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,4); ierr = SNESGetFunction(snes, &r, NULL, NULL);CHKERRQ(ierr); ierr = VecGetDM(r, &dm);CHKERRQ(ierr); if (!dm) {ierr = SNESMonitorDefault(snes, its, fgnorm, ctx);CHKERRQ(ierr);} else { PetscSection s, gs; PetscInt Nf, f; ierr = DMGetDefaultSection(dm, &s);CHKERRQ(ierr); ierr = DMGetDefaultGlobalSection(dm, &gs);CHKERRQ(ierr); if (!s || !gs) {ierr = SNESMonitorDefault(snes, its, fgnorm, ctx);CHKERRQ(ierr);} ierr = PetscSectionGetNumFields(s, &Nf);CHKERRQ(ierr); if (Nf > 256) SETERRQ1(PetscObjectComm((PetscObject) snes), PETSC_ERR_SUP, "Do not support %d fields > 256", Nf); ierr = PetscSectionVecNorm(s, gs, r, NORM_2, res);CHKERRQ(ierr); ierr = PetscObjectGetTabLevel((PetscObject) snes, &tablevel);CHKERRQ(ierr); ierr = PetscViewerASCIIAddTab(viewer, tablevel);CHKERRQ(ierr); ierr = PetscViewerASCIIPrintf(viewer, "%3D SNES Function norm %14.12e [", its, (double) fgnorm);CHKERRQ(ierr); for (f = 0; f < Nf; ++f) { if (f) {ierr = PetscViewerASCIIPrintf(viewer, ", ");CHKERRQ(ierr);} ierr = PetscViewerASCIIPrintf(viewer, "%14.12e", res[f]);CHKERRQ(ierr); } ierr = PetscViewerASCIIPrintf(viewer, "] \n");CHKERRQ(ierr); ierr = PetscViewerASCIISubtractTab(viewer, tablevel);CHKERRQ(ierr); } PetscFunctionReturn(0); }
PetscErrorCode DMView_AKKT(DM dm, PetscViewer v) { DM_AKKT* kkt = (DM_AKKT*)(dm->data); PetscErrorCode ierr; PetscBool isascii; PetscInt i, tab, vtab; const char* name, *prefix; PetscFunctionBegin; ierr = PetscObjectTypeCompare((PetscObject)v, PETSCVIEWERASCII, &isascii); CHKERRQ(ierr); if(!isascii) SETERRQ(((PetscObject)dm)->comm, PETSC_ERR_SUP, "No support for non-ASCII viewers"); ierr = PetscObjectGetTabLevel((PetscObject)dm, &tab); CHKERRQ(ierr); ierr = PetscObjectGetName((PetscObject)dm, &name); CHKERRQ(ierr); ierr = PetscObjectGetOptionsPrefix((PetscObject)dm, &prefix); CHKERRQ(ierr); ierr = PetscViewerASCIIUseTabs(v,PETSC_TRUE); CHKERRQ(ierr); ierr = PetscViewerASCIIGetTab(v,&vtab); CHKERRQ(ierr); ierr = PetscViewerASCIISetTab(v,tab); CHKERRQ(ierr); ierr = PetscViewerASCIIPrintf(v, "DM Algebraic KKT, name: %s, prefix: %s\n", ((PetscObject)dm)->name, ((PetscObject)dm)->prefix); CHKERRQ(ierr); if(kkt->dm) { ierr = PetscViewerASCIIPrintf(v, "DM:\n"); CHKERRQ(ierr); ierr = PetscViewerASCIIPushTab(v); CHKERRQ(ierr); ierr = DMView(kkt->dm,v); CHKERRQ(ierr); ierr = PetscViewerASCIIPopTab(v); CHKERRQ(ierr); } if(kkt->Aff) { ierr = PetscViewerASCIIPrintf(v, "Aff:\n"); CHKERRQ(ierr); ierr = PetscViewerASCIIPushTab(v); CHKERRQ(ierr); ierr = MatView(kkt->Aff,v); CHKERRQ(ierr); ierr = PetscViewerASCIIPopTab(v); CHKERRQ(ierr); } if(kkt->dname) { ierr = PetscViewerASCIIPrintf(v, "Decomposition, name %s:\n"); CHKERRQ(ierr); } for(i = 0; i < 2; ++i) { const char* label; if(i == 0) { label = "Primal"; } else { label = "Dual"; } if(kkt->names[i]) { ierr = PetscViewerASCIIPrintf(v, "%s, name %s:\n", label, kkt->names[i]); CHKERRQ(ierr); } if(kkt->isf[i]){ ierr = PetscViewerASCIIPrintf(v, "%s, IS:\n",label); CHKERRQ(ierr); ierr = PetscViewerASCIIPushTab(v); CHKERRQ(ierr); ierr = ISView(kkt->isf[i],v); CHKERRQ(ierr); ierr = PetscViewerASCIIPopTab(v); CHKERRQ(ierr); } if(kkt->dmf[i]){ ierr = PetscViewerASCIIPrintf(v, "%s, DM:\n", label); CHKERRQ(ierr); ierr = PetscViewerASCIIPushTab(v); CHKERRQ(ierr); ierr = DMView(kkt->dmf[i],v); CHKERRQ(ierr); ierr = PetscViewerASCIIPopTab(v); CHKERRQ(ierr); } } if(kkt->Pfc) { ierr = PetscViewerASCIIPrintf(v, "Prolongation:\n"); CHKERRQ(ierr); ierr = PetscViewerASCIIPushTab(v); CHKERRQ(ierr); ierr = MatView(kkt->Pfc,v); CHKERRQ(ierr); ierr = PetscViewerASCIIPopTab(v); CHKERRQ(ierr); } ierr = PetscViewerASCIISetTab(v,vtab); CHKERRQ(ierr); PetscFunctionReturn(0); }