Actual source code: snessaws.c
petsc-3.7.3 2016-08-01
1: #include <petsc/private/snesimpl.h> /*I "petscsnes.h" I*/
2: #include <petscviewersaws.h>
4: typedef struct {
5: PetscViewer viewer;
6: } SNESMonitor_SAWs;
10: /*@C
11: SNESMonitorSAWsCreate - create an SAWs monitor context
13: Collective
15: Input Arguments:
16: . snes - SNES to monitor
18: Output Arguments:
19: . ctx - context for monitor
21: Level: developer
23: .seealso: SNESMonitorSAWs(), SNESMonitorSAWsDestroy()
24: @*/
25: PetscErrorCode SNESMonitorSAWsCreate(SNES snes,void **ctx)
26: {
27: PetscErrorCode ierr;
28: SNESMonitor_SAWs *mon;
31: PetscNewLog(snes,&mon);
32: mon->viewer = PETSC_VIEWER_SAWS_(PetscObjectComm((PetscObject)snes));
33: if (!mon->viewer) SETERRQ(PetscObjectComm((PetscObject)snes),PETSC_ERR_PLIB,"Cannot create SAWs default viewer");
34: *ctx = (void*)mon;
35: return(0);
36: }
40: /*@C
41: SNESMonitorSAWsDestroy - destroy a monitor context created with SNESMonitorSAWsCreate()
43: Collective
45: Input Arguments:
46: . ctx - monitor context
48: Level: developer
50: .seealso: SNESMonitorSAWsCreate()
51: @*/
52: PetscErrorCode SNESMonitorSAWsDestroy(void **ctx)
53: {
54: PetscErrorCode ierr;
57: PetscFree(*ctx);
58: return(0);
59: }
63: /*@C
64: SNESMonitorSAWs - monitor solution using SAWs
66: Logically Collective on SNES
68: Input Parameters:
69: + snes - iterative context
70: . n - iteration number
71: . rnorm - 2-norm (preconditioned) residual value (may be estimated).
72: - ctx - PetscViewer of type SAWs
74: Level: advanced
76: .keywords: SNES, monitor, SAWs
78: .seealso: PetscViewerSAWsOpen()
79: @*/
80: PetscErrorCode SNESMonitorSAWs(SNES snes,PetscInt n,PetscReal rnorm,void *ctx)
81: {
82: PetscErrorCode ierr;
83: PetscMPIInt rank;
88: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
89: if (!rank) {
90: PetscStackCallSAWs(SAWs_Register,("/PETSc/snes_monitor_saws/its",&snes->iter,1,SAWs_READ,SAWs_INT));
91: PetscStackCallSAWs(SAWs_Register,("/PETSc/snes_monitor_saws/rnorm",&snes->norm,1,SAWs_READ,SAWs_DOUBLE));
92: PetscSAWsBlock();
93: }
94: return(0);
95: }