Commits

Peter Brune  committed 971e163

SNESSetCountersReset() lets SNES to keep nfuncs and linear_its for many solves

  • Participants
  • Parent commits 902f982

Comments (0)

Files changed (3)

File include/petsc-private/snesimpl.h

   PetscBool   conv_hist_reset;    /* reset counter for each new SNES solve */
   PetscBool   conv_malloc;
 
+  PetscBool    counters_reset;    /* reset counter for each new SNES solve */
+
   /* the next two are used for failures in the line search; they should be put elsewhere */
   PetscInt    numFailures;        /* number of unsuccessful step attempts */
   PetscInt    maxFailures;        /* maximum number of unsuccessful step attempts */
   Vec         xl,xu;             /* upper and lower bounds for box constrained VI problems */
   PetscInt    ntruebounds;       /* number of non-infinite bounds set for VI box constraints */
   PetscBool   usersetbounds;     /* bounds have been set via SNESVISetVariableBounds(), rather than via computevariablebounds() callback. */
+
 };
 
 typedef struct _p_DMSNES *DMSNES;

File include/petscsnes.h

 PETSC_EXTERN PetscErrorCode SNESGetLinearSolveFailures(SNES,PetscInt*);
 PETSC_EXTERN PetscErrorCode SNESSetMaxLinearSolveFailures(SNES,PetscInt);
 PETSC_EXTERN PetscErrorCode SNESGetMaxLinearSolveFailures(SNES,PetscInt*);
+PETSC_EXTERN PetscErrorCode SNESSetCountersReset(SNES,PetscBool);
 
 PETSC_EXTERN PetscErrorCode SNESKSPSetUseEW(SNES,PetscBool );
 PETSC_EXTERN PetscErrorCode SNESKSPGetUseEW(SNES,PetscBool *);

File src/snes/interface/snes.c

 
    Level: intermediate
 
+   Notes: Reset every time SNESSolve is called unless SNESSetCountersReset() is used.
+
 .keywords: SNES, nonlinear, get, maximum, unsuccessful, steps
 
-.seealso: SNESGetMaxLinearSolveFailures(), SNESGetLinearSolveIterations(), SNESSetMaxLinearSolveFailures(), SNESGetLinearSolveFailures()
+.seealso: SNESGetMaxLinearSolveFailures(), SNESGetLinearSolveIterations(), SNESSetMaxLinearSolveFailures(), SNESGetLinearSolveFailures(), SNESSetCountersReset()
 @*/
 PetscErrorCode  SNESGetNumberFunctionEvals(SNES snes, PetscInt *nfuncs)
 {
 .  lits - number of linear iterations
 
    Notes:
-   This counter is reset to zero for each successive call to SNESSolve().
+   This counter is reset to zero for each successive call to SNESSolve() unless SNESSetCountersReset() is used.
 
    Level: intermediate
 
 .keywords: SNES, nonlinear, get, number, linear, iterations
 
-.seealso:  SNESGetIterationNumber(), SNESGetFunctionNorm(), SNESGetLinearSolveFailures(), SNESGetMaxLinearSolveFailures()
+.seealso:  SNESGetIterationNumber(), SNESGetFunctionNorm(), SNESGetLinearSolveFailures(), SNESGetMaxLinearSolveFailures(), SNESSetCountersReset()
 @*/
 PetscErrorCode  SNESGetLinearSolveIterations(SNES snes,PetscInt *lits)
 {
   PetscFunctionReturn(0);
 }
 
+#undef __FUNCT__
+#define __FUNCT__ "SNESSetCountersReset"
+/*@
+   SNESSetCountersReset - Sets whether or not the counters for linear iterations and function evaluations
+   are reset every time SNESSolve() is called.
+
+   Logically Collective on SNES
+
+   Input Parameter:
++  snes - SNES context
+-  reset - whether to reset the counters or not
+
+   Notes:
+   This is automatically called with FALSE
+
+   Level: developer
+
+.keywords: SNES, nonlinear, set, reset, number, linear, iterations
+
+.seealso:  SNESGetNumberFunctionEvals(), SNESGetNumberLinearSolveIterations(), SNESGetPC()
+@*/
+PetscErrorCode  SNESSetCountersReset(SNES snes,PetscBool reset)
+{
+  PetscFunctionBegin;
+  PetscValidHeaderSpecific(snes,SNES_CLASSID,1);
+  PetscValidLogicalCollectiveBool(snes,reset,2);
+  snes->counters_reset = reset;
+  PetscFunctionReturn(0);
+}
+
 
 #undef __FUNCT__
 #define __FUNCT__ "SNESSetKSP"
   snes->conv_hist         = NULL;
   snes->conv_hist_its     = NULL;
   snes->conv_hist_reset   = PETSC_TRUE;
+  snes->counters_reset    = PETSC_TRUE;
   snes->vec_func_init_set = PETSC_FALSE;
   snes->norm_init         = 0.;
   snes->norm_init_set     = PETSC_FALSE;
     }
 
     if (snes->conv_hist_reset) snes->conv_hist_len = 0;
-    snes->nfuncs = 0; snes->linear_its = 0; snes->numFailures = 0;
+    if (snes->counters_reset) {snes->nfuncs = 0; snes->linear_its = 0; snes->numFailures = 0;}
 
     ierr = PetscLogEventBegin(SNES_Solve,snes,0,0,0);CHKERRQ(ierr);
     ierr = (*snes->ops->solve)(snes);CHKERRQ(ierr);
     ierr = SNESGetOptionsPrefix(snes,&optionsprefix);CHKERRQ(ierr);
     ierr = SNESSetOptionsPrefix(snes->pc,optionsprefix);CHKERRQ(ierr);
     ierr = SNESAppendOptionsPrefix(snes->pc,"npc_");CHKERRQ(ierr);
+    ierr = SNESSetCountersReset(snes->pc,PETSC_FALSE);CHKERRQ(ierr);
   }
   *pc = snes->pc;
   PetscFunctionReturn(0);