Actual source code: snessaws.c
petsc-3.6.4 2016-04-12
1: #include <petsc/private/snesimpl.h> /*I "petscsnes.h" I*/
2: #include <petscviewersaws.h>
4: typedef struct {
5: PetscViewer viewer;
6: PetscReal rnorm;
7: } SNESMonitor_SAWs;
11: /*@C
12: SNESMonitorSAWsCreate - create an SAWs monitor context
14: Collective
16: Input Arguments:
17: . snes - SNES to monitor
19: Output Arguments:
20: . ctx - context for monitor
22: Level: developer
24: .seealso: SNESMonitorSAWs(), SNESMonitorSAWsDestroy()
25: @*/
26: PetscErrorCode SNESMonitorSAWsCreate(SNES snes,void **ctx)
27: {
28: PetscErrorCode ierr;
29: SNESMonitor_SAWs *mon;
32: PetscNewLog(snes,&mon);
33: mon->viewer = PETSC_VIEWER_SAWS_(PetscObjectComm((PetscObject)snes));
34: if (!mon->viewer) SETERRQ(PetscObjectComm((PetscObject)snes),PETSC_ERR_PLIB,"Cannot create SAWs default viewer");
35: *ctx = (void*)mon;
36: return(0);
37: }
41: /*@C
42: SNESMonitorSAWsDestroy - destroy a monitor context created with SNESMonitorSAWsCreate()
44: Collective
46: Input Arguments:
47: . ctx - monitor context
49: Level: developer
51: .seealso: SNESMonitorSAWsCreate()
52: @*/
53: PetscErrorCode SNESMonitorSAWsDestroy(void **ctx)
54: {
55: PetscErrorCode ierr;
58: PetscFree(*ctx);
59: return(0);
60: }
64: /*@C
65: SNESMonitorSAWs - monitor solution using SAWs
67: Logically Collective on SNES
69: Input Parameters:
70: + snes - iterative context
71: . n - iteration number
72: . rnorm - 2-norm (preconditioned) residual value (may be estimated).
73: - ctx - PetscViewer of type SAWs
75: Level: advanced
77: .keywords: SNES, monitor, SAWs
79: .seealso: PetscViewerSAWsOpen()
80: @*/
81: PetscErrorCode SNESMonitorSAWs(SNES snes,PetscInt n,PetscReal rnorm,void *ctx)
82: {
83: PetscErrorCode ierr;
84: PetscMPIInt rank;
89: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
90: if (!rank) {
91: PetscStackCallSAWs(SAWs_Register,("/PETSc/snes_monitor_saws/its",&snes->iter,1,SAWs_READ,SAWs_INT));
92: PetscStackCallSAWs(SAWs_Register,("/PETSc/snes_monitor_saws/rnorm",&snes->norm,1,SAWs_READ,SAWs_DOUBLE));
93: PetscSAWsBlock();
94: }
95: return(0);
96: }