LCOV - code coverage report
Current view: top level - include/outputs - TopResidualDebugOutput.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 20 20 100.0 %
Date: 2025-07-17 01:28:37 Functions: 3 3 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 "PetscOutput.h"
      14             : 
      15             : #include "libmesh/system.h"
      16             : 
      17             : class NonlinearSystemBase;
      18             : 
      19             : /**
      20             :  * A structure for storing data related to top residuals
      21             :  *  @see TopResidualDebugOutput::printTopResiduals()
      22             :  */
      23             : struct TopResidualDebugOutputTopResidualData
      24             : {
      25             :   unsigned int _var;
      26             :   std::set<SubdomainID> _subdomain_ids;
      27             :   dof_id_type _id;
      28             :   Point _point;
      29             :   Real _residual;
      30             :   bool _is_scalar;
      31             :   bool _is_nodal;
      32             : 
      33        4697 :   TopResidualDebugOutputTopResidualData()
      34        4697 :     : _var(0),
      35        4697 :       _subdomain_ids(),
      36        4697 :       _id(0),
      37        4697 :       _point(Point()),
      38        4697 :       _residual(0.),
      39        4697 :       _is_scalar(false),
      40        4697 :       _is_nodal(true)
      41             :   {
      42        4697 :   }
      43             : 
      44        4697 :   TopResidualDebugOutputTopResidualData(unsigned int var,
      45             :                                         std::set<SubdomainID> subdomain_ids,
      46             :                                         dof_id_type id,
      47             :                                         Point point,
      48             :                                         Real residual,
      49             :                                         bool is_scalar = false,
      50             :                                         bool is_nodal = true)
      51        4697 :     : _var(var),
      52        4697 :       _subdomain_ids(subdomain_ids),
      53        4697 :       _id(id),
      54        4697 :       _point(point),
      55        4697 :       _residual(residual),
      56        4697 :       _is_scalar(is_scalar),
      57        4697 :       _is_nodal(is_nodal)
      58             :   {
      59        4697 :   }
      60             : };
      61             : 
      62             : /**
      63             :  * A class for producing various debug related outputs
      64             :  *
      65             :  * This currently considers the following degrees of freedom:
      66             :  * \li first component of all nodal variables
      67             :  * \li first component of all elemental variables
      68             :  * \li all scalar variables
      69             :  *
      70             :  * This class may be used from inside the [Outputs] block or via the [Debug] block (preferred)
      71             :  */
      72             : class TopResidualDebugOutput : public PetscOutput
      73             : {
      74             : public:
      75             :   static InputParameters validParams();
      76             : 
      77             :   /**
      78             :    * Class constructor
      79             :    * @param parameters Object input parameters
      80             :    */
      81             :   TopResidualDebugOutput(const InputParameters & parameters);
      82             : 
      83             : protected:
      84             :   /**
      85             :    * Perform the debugging output
      86             :    */
      87             :   virtual void output() override;
      88             : 
      89             :   /**
      90             :    * Prints the n top residuals for the variables in the system
      91             :    * @param residual A reference to the residual vector
      92             :    * @param n The number of residuals to print
      93             :    */
      94             :   void printTopResiduals(const NumericVector<Number> & residual, unsigned int n);
      95             : 
      96             :   /**
      97             :    * Method for sorting the residuals data from TopResidualDebugOutputTopResidualData structs
      98             :    * @see printTopResiduals
      99             :    */
     100       27902 :   static bool sortTopResidualData(TopResidualDebugOutputTopResidualData i,
     101             :                                   TopResidualDebugOutputTopResidualData j)
     102             :   {
     103       27902 :     return (fabs(i._residual) > fabs(j._residual));
     104             :   }
     105             : 
     106             :   /// Number of residuals to display
     107             :   unsigned int _num_residuals;
     108             : 
     109             :   /// Reference to MOOSE's nonlinear system
     110             :   NonlinearSystemBase & _nl;
     111             : 
     112             :   /// Reference to libMesh system
     113             :   libMesh::System & _sys;
     114             : };

Generated by: LCOV version 1.14