Date: 2022-03-31T04:48:29+00:00

Actual source code: snessaws.c

      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 Parameter:
     14: .  snes - SNES to monitor

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

     19:    Level: developer

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

     27:   PetscNewLog(snes,&mon);
     28:   mon->viewer = PETSC_VIEWER_SAWS_(PetscObjectComm((PetscObject)snes));
     30:   *ctx = (void*)mon;
     31:   return 0;
     32: }

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

     37:    Collective

     39:    Input Parameter:
     40: .  ctx - monitor context

     42:    Level: developer

     44: .seealso: SNESMonitorSAWsCreate()
     45: @*/
     46: PetscErrorCode SNESMonitorSAWsDestroy(void **ctx)
     47: {
     48:   PetscFree(*ctx);
     49:   return 0;
     50: }

     52: /*@C
     53:    SNESMonitorSAWs - monitor solution using SAWs

     55:    Logically Collective on SNES

     57:    Input Parameters:
     58: +  snes   - iterative context
     59: .  n     - iteration number
     60: .  rnorm - 2-norm (preconditioned) residual value (may be estimated).
     61: -  ctx -  PetscViewer of type SAWs

     63:    Level: advanced

     65: .seealso: PetscViewerSAWsOpen()
     66: @*/
     67: PetscErrorCode SNESMonitorSAWs(SNES snes,PetscInt n,PetscReal rnorm,void *ctx)
     68: {
     69:   PetscMPIInt      rank;

     73:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
     74:   if (rank == 0) {
     75:     PetscStackCallSAWs(SAWs_Register,("/PETSc/snes_monitor_saws/its",&snes->iter,1,SAWs_READ,SAWs_INT));
     76:     PetscStackCallSAWs(SAWs_Register,("/PETSc/snes_monitor_saws/rnorm",&snes->norm,1,SAWs_READ,SAWs_DOUBLE));
     77:     PetscSAWsBlock();
     78:   }
     79:   return 0;
     80: }