Actual source code: snessaws.c

petsc-3.8.4 2018-03-24
Report Typos and Errors
  1:  #include <petsc/private/snesimpl.h>
  2:  #include <petscviewersaws.h>

  4: typedef struct {
  5:   PetscViewer    viewer;
  6: } SNESMonitor_SAWs;

  8: /*@C
  9:    SNESMonitorSAWsCreate - create an SAWs monitor context

 11:    Collective

 13:    Input Arguments:
 14: .  snes - SNES to monitor

 16:    Output Arguments:
 17: .  ctx - context for monitor

 19:    Level: developer

 21: .seealso: SNESMonitorSAWs(), SNESMonitorSAWsDestroy()
 22: @*/
 23: PetscErrorCode SNESMonitorSAWsCreate(SNES snes,void **ctx)
 24: {
 25:   PetscErrorCode  ierr;
 26:   SNESMonitor_SAWs *mon;

 29:   PetscNewLog(snes,&mon);
 30:   mon->viewer = PETSC_VIEWER_SAWS_(PetscObjectComm((PetscObject)snes));
 31:   if (!mon->viewer) SETERRQ(PetscObjectComm((PetscObject)snes),PETSC_ERR_PLIB,"Cannot create SAWs default viewer");
 32:   *ctx = (void*)mon;
 33:   return(0);
 34: }

 36: /*@C
 37:    SNESMonitorSAWsDestroy - destroy a monitor context created with SNESMonitorSAWsCreate()

 39:    Collective

 41:    Input Arguments:
 42: .  ctx - monitor context

 44:    Level: developer

 46: .seealso: SNESMonitorSAWsCreate()
 47: @*/
 48: PetscErrorCode SNESMonitorSAWsDestroy(void **ctx)
 49: {
 50:   PetscErrorCode  ierr;

 53:   PetscFree(*ctx);
 54:   return(0);
 55: }

 57: /*@C
 58:    SNESMonitorSAWs - monitor solution using SAWs

 60:    Logically Collective on SNES

 62:    Input Parameters:
 63: +  snes   - iterative context
 64: .  n     - iteration number
 65: .  rnorm - 2-norm (preconditioned) residual value (may be estimated).
 66: -  ctx -  PetscViewer of type SAWs

 68:    Level: advanced

 70: .keywords: SNES, monitor, SAWs

 72: .seealso: PetscViewerSAWsOpen()
 73: @*/
 74: PetscErrorCode SNESMonitorSAWs(SNES snes,PetscInt n,PetscReal rnorm,void *ctx)
 75: {
 76:   PetscErrorCode   ierr;
 77:   PetscMPIInt      rank;


 82:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 83:   if (!rank) {
 84:     PetscStackCallSAWs(SAWs_Register,("/PETSc/snes_monitor_saws/its",&snes->iter,1,SAWs_READ,SAWs_INT));
 85:     PetscStackCallSAWs(SAWs_Register,("/PETSc/snes_monitor_saws/rnorm",&snes->norm,1,SAWs_READ,SAWs_DOUBLE));
 86:     PetscSAWsBlock();
 87:   }
 88:   return(0);
 89: }