LCOV - code coverage report
Current view: top level - include/outputs - PetscOutput.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 4 4 100.0 %
Date: 2025-07-17 01:28:37 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : // MOOSE includes
      13             : #include "Output.h"
      14             : 
      15             : class PetscOutput;
      16             : 
      17             : class PetscOutputInterface
      18             : {
      19             : public:
      20             :   PetscOutputInterface(PetscOutput * obj);
      21             : 
      22             : protected:
      23             :   PetscOutput * _petsc_output;
      24             : 
      25             :   /**
      26             :    * Performs the output on non-linear iterations
      27             :    * This is the monitor method that PETSc will call on non-linear iterations
      28             :    */
      29             :   static PetscErrorCode petscNonlinearOutput(SNES, PetscInt its, PetscReal fnorm, void * void_ptr);
      30             : 
      31             :   /**
      32             :    * Performs the output onlinear iterations
      33             :    * This is the monitor method that PETSc will call on linear iterations
      34             :    */
      35             :   static PetscErrorCode petscLinearOutput(KSP, PetscInt its, PetscReal fnorm, void * void_ptr);
      36             : };
      37             : 
      38             : /**
      39             :  * Adds the ability to output on every nonlinear and/or linear residual
      40             :  */
      41             : class PetscOutput : public Output, public PetscOutputInterface
      42             : {
      43             : public:
      44             :   static InputParameters validParams();
      45             : 
      46             :   /**
      47             :    * Class constructor
      48             :    * @param parameters Outputter input file parameters
      49             :    */
      50             :   PetscOutput(const InputParameters & parameters);
      51             : 
      52             :   /**
      53             :    * Get the output time.
      54             :    * This outputter enables the ability to perform output on the nonlinear and linear iterations
      55             :    * performed
      56             :    * by PETSc. To separate theses outputs within the output a pseudo time is defined, this function
      57             :    * provides
      58             :    * this time and it should be used in place of _time from Outputter.
      59             :    */
      60             :   virtual Real time() override;
      61             : 
      62             : protected:
      63     2060473 :   bool inNonlinearTimeWindow()
      64             :   {
      65     2060473 :     return _time >= _nonlinear_start_time - _t_tol && _time <= _nonlinear_end_time + _t_tol;
      66             :   }
      67     6641916 :   bool inLinearTimeWindow()
      68             :   {
      69     6641916 :     return _time >= _linear_start_time - _t_tol && _time <= _linear_end_time + _t_tol;
      70             :   }
      71             :   /**
      72             :    * Get the time that will be used for stream/file outputting. This method is intended to
      73             :    * override the output given by time() for cases that do not conform to the linear, nonlinear,
      74             :    * time step pattern. For example, this can be used for optimization or fixed point iteration
      75             :    * solves. If you override this method for your application, replace time() calls with
      76             :    * getOutputTime() calls and ensure output consistency.
      77             :    */
      78             :   virtual Real getOutputTime();
      79             : 
      80             :   /// Current norm returned from PETSc
      81             :   Real _norm;
      82             : 
      83             :   /// Current non-linear iteration returned from PETSc
      84             :   PetscInt _nonlinear_iter;
      85             : 
      86             :   /// Current linear iteration returned from PETSc
      87             :   PetscInt _linear_iter;
      88             : 
      89             :   /// True if current output calls is on the linear residual (used by time())
      90             :   bool _on_linear_residual;
      91             : 
      92             :   /// True if current output call is on the non-linear residual (used by time())
      93             :   bool _on_nonlinear_residual;
      94             : 
      95             : private:
      96             :   /**
      97             :    * Internal setup function that executes at the beginning of the time step
      98             :    */
      99             :   void solveSetup() override;
     100             : 
     101             :   /// The psuedo non-linear time
     102             :   Real _nonlinear_time;
     103             : 
     104             :   /// The pseuedo non-linear time step
     105             :   Real _nonlinear_dt;
     106             : 
     107             :   /// Psuedo linear time
     108             :   Real _linear_time;
     109             : 
     110             :   /// Psuedo linear time step
     111             :   Real _linear_dt;
     112             : 
     113             :   /// Pseudo non-linear timestep divisor
     114             :   Real _nonlinear_dt_divisor;
     115             : 
     116             :   /// Pseudo linear timestep divisor
     117             :   Real _linear_dt_divisor;
     118             : 
     119             :   /// Non-linear residual output start time
     120             :   Real _nonlinear_start_time;
     121             : 
     122             :   /// Linear residual output start time
     123             :   Real _linear_start_time;
     124             : 
     125             :   /// Non-linear residual output end time
     126             :   Real _nonlinear_end_time;
     127             : 
     128             :   /// Linear residual output end time
     129             :   Real _linear_end_time;
     130             : 
     131             :   friend class PetscOutputInterface;
     132             : };

Generated by: LCOV version 1.14