Actual source code: snessaws.c

petsc-master 2019-09-16
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: .seealso: PetscViewerSAWsOpen()
 71: @*/
 72: PetscErrorCode SNESMonitorSAWs(SNES snes,PetscInt n,PetscReal rnorm,void *ctx)
 73: {
 74:   PetscErrorCode   ierr;
 75:   PetscMPIInt      rank;


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