/*@C SNESMonitorSolutionUpdate - Monitors progress of the SNES solvers by calling VecView() for the UPDATE to the solution at each iteration. Collective on SNES Input Parameters: + snes - the SNES context . its - iteration number . fgnorm - 2-norm of residual - dummy - a viewer Level: intermediate .keywords: SNES, nonlinear, vector, monitor, view .seealso: SNESMonitorSet(), SNESMonitorDefault(), VecView() @*/ PetscErrorCode SNESMonitorSolutionUpdate(SNES snes,PetscInt its,PetscReal fgnorm,void *dummy) { PetscErrorCode ierr; Vec x; PetscViewer viewer = (PetscViewer) dummy; PetscFunctionBegin; PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,4); ierr = SNESGetSolutionUpdate(snes,&x);CHKERRQ(ierr); ierr = VecView(x,viewer);CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@C SNESMonitorSolutionUpdate - Monitors progress of the SNES solvers by calling VecView() for the UPDATE to the solution at each iteration. Collective on SNES Input Parameters: + snes - the SNES context . its - iteration number . fgnorm - 2-norm of residual - dummy - either a viewer or NULL Level: intermediate .keywords: SNES, nonlinear, vector, monitor, view .seealso: SNESMonitorSet(), SNESMonitorDefault(), VecView() @*/ PetscErrorCode SNESMonitorSolutionUpdate(SNES snes,PetscInt its,PetscReal fgnorm,void *dummy) { PetscErrorCode ierr; Vec x; PetscViewer viewer = (PetscViewer) dummy; PetscFunctionBegin; ierr = SNESGetSolutionUpdate(snes,&x);CHKERRQ(ierr); if (!viewer) { MPI_Comm comm; ierr = PetscObjectGetComm((PetscObject)snes,&comm);CHKERRQ(ierr); viewer = PETSC_VIEWER_DRAW_(comm); } ierr = VecView(x,viewer);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); }
// Function to hand to PETSc's SNES, // which monitors convergence at X PetscErrorCode __libmesh_petsc_diff_solver_monitor (SNES snes, PetscInt its, PetscReal fnorm, void *ctx) { PetscDiffSolver& solver = *(static_cast<PetscDiffSolver*> (ctx)); if (solver.verbose) libMesh::out << " PetscDiffSolver step " << its << ", |residual|_2 = " << fnorm << std::endl; if (solver.linear_solution_monitor.get()) { int ierr = 0; Vec petsc_delta_u; ierr = SNESGetSolutionUpdate(snes, &petsc_delta_u); CHKERRABORT(libMesh::COMM_WORLD, ierr); PetscVector<Number> delta_u(petsc_delta_u, solver.comm()); delta_u.close(); Vec petsc_u; ierr = SNESGetSolution(snes, &petsc_u); CHKERRABORT(libMesh::COMM_WORLD, ierr); PetscVector<Number> u(petsc_u, solver.comm()); u.close(); Vec petsc_res; ierr = SNESGetFunction(snes, &petsc_res, NULL, NULL); CHKERRABORT(libMesh::COMM_WORLD, ierr); PetscVector<Number> res(petsc_res, solver.comm()); res.close(); (*solver.linear_solution_monitor)( delta_u, delta_u.l2_norm(), u, u.l2_norm(), res, res.l2_norm(), its); } return 0; }