Chi-Tech
tools.cc
Go to the documentation of this file.
1#include "tools.h"
2#include "chi_log.h"
3#include "../mg_diffusion_solver.h"
4
5#include <iomanip>
6
7#include "chi_runtime.h"
8
9//###################################################################
10/**My personal monitor monitor.*/
12 KSP ksp, PetscInt n, PetscReal rnorm, void*)
13{
14 Vec Rhs;
15 KSPGetRhs(ksp,&Rhs);
16 double rhs_norm;
17 VecNorm(Rhs,NORM_2,&rhs_norm);
18 if (rhs_norm < 1.0e-12)
19 rhs_norm = 1.0;
20
21 //Get solver name
22 const char* ksp_name;
23 KSPGetOptionsPrefix(ksp,&ksp_name);
24
25 //Default to this if ksp_name is NULL
26 const char NONAME_SOLVER[] = "NoName-Solver\0";
27
28 if (ksp_name == nullptr)
29 ksp_name = NONAME_SOLVER;
30
31 mg_diffusion::KSPAppContext* my_app_context;
32 KSPGetApplicationContext(ksp, &my_app_context);
33
34 //Print message
35 if (my_app_context->verbose == PETSC_TRUE)
36 {
37 std::stringstream buff;
38 buff
39 << ksp_name
40 << " iteration "
41 << std::setw(4) << n
42 << " - Residual "
43 << std::scientific << std::setprecision(7) << rnorm / rhs_norm
44 << std::endl;
45
46 Chi::log.Log() << buff.str();
47 }
48
49 return 0;
50}
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
PetscErrorCode MGKSPMonitor(KSP ksp, PetscInt n, PetscReal rnorm, void *)
Definition: tools.cc:11
struct _p_Vec * Vec