1 // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2 // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 3 4 /// @file 5 /// KSP related functiosn for HONEE 6 7 #include <petscksp.h> 8 9 PetscErrorCode KSPPostSolve_Honee(KSP ksp, Vec rhs, Vec x, void *ctx) { 10 const PetscReal *residual_history; 11 PetscReal first_residual, last_residual; 12 PetscInt num_its = -1, tab_level; 13 PetscViewer viewer = PETSC_VIEWER_STDOUT_(PetscObjectComm((PetscObject)ksp)); 14 15 PetscFunctionBeginUser; 16 PetscCall(KSPGetResidualHistory(ksp, &residual_history, &num_its)); 17 first_residual = residual_history[0]; 18 last_residual = residual_history[num_its - 1]; 19 PetscCall(PetscObjectGetTabLevel((PetscObject)ksp, &tab_level)); 20 PetscCall(PetscViewerASCIIAddTab(viewer, tab_level + 1)); 21 PetscCall(PetscViewerASCIIPrintf(viewer, "KSP Residual Summary: R_0 %.4e R_last %.4e R_last/R_0 %.4e\n", first_residual, last_residual, 22 last_residual / first_residual)); 23 PetscCall(PetscViewerASCIISubtractTab(viewer, tab_level + 1)); 24 PetscFunctionReturn(PETSC_SUCCESS); 25 } 26