LCOV - code coverage report
Current view: top level - src/outputs - VariableResidualNormsDebugOutput.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 29 31 93.5 %
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             : // MOOSE includes
      11             : #include "VariableResidualNormsDebugOutput.h"
      12             : #include "FEProblem.h"
      13             : #include "MooseApp.h"
      14             : #include "Material.h"
      15             : #include "NonlinearSystemBase.h"
      16             : 
      17             : // libMesh includes
      18             : #include "libmesh/transient_system.h"
      19             : #include "libmesh/enum_norm_type.h"
      20             : 
      21             : registerMooseObject("MooseApp", VariableResidualNormsDebugOutput);
      22             : 
      23             : InputParameters
      24       16161 : VariableResidualNormsDebugOutput::validParams()
      25             : {
      26       16161 :   InputParameters params = PetscOutput::validParams();
      27       16161 :   params.addClassDescription("Reports the residual norm for each variable.");
      28             : 
      29             :   // By default this outputs on every nonlinear iteration
      30       16161 :   params.set<ExecFlagEnum>("execute_on") = EXEC_NONLINEAR;
      31       16161 :   params.suppressParameter<ExecFlagEnum>("execute_on");
      32       16161 :   params.addParam<NonlinearSystemName>(
      33             :       "nl_sys", "nl0", "The nonlinear system that we should output information for.");
      34       16161 :   return params;
      35           0 : }
      36             : 
      37         948 : VariableResidualNormsDebugOutput::VariableResidualNormsDebugOutput(
      38         948 :     const InputParameters & parameters)
      39             :   : PetscOutput(parameters),
      40         948 :     _nl(_problem_ptr->getNonlinearSystemBase(
      41         948 :         _problem_ptr->nlSysNum(getParam<NonlinearSystemName>("nl_sys")))),
      42        1896 :     _sys(_nl.system())
      43             : {
      44         948 : }
      45             : 
      46             : void
      47        9284 : VariableResidualNormsDebugOutput::output()
      48             : {
      49             :   // Only output if the problem is solving for the relevant nonlinear system
      50        9284 :   if (_nl.number() != _problem_ptr->currentNonlinearSystem().number())
      51           0 :     return;
      52             : 
      53             :   // Stream for outputting
      54        9284 :   std::ostringstream oss;
      55             : 
      56             :   // Determine the maximum variable name size
      57        9284 :   unsigned int max_name_size = 0;
      58       25386 :   for (unsigned int var_num = 0; var_num < _sys.n_vars(); var_num++)
      59             :   {
      60       16102 :     unsigned int var_name_size = _sys.variable_name(var_num).size();
      61       16102 :     if (var_name_size > max_name_size)
      62       13743 :       max_name_size = var_name_size;
      63             :   }
      64             : 
      65             :   // Perform the output of the variable residuals
      66        9284 :   oss << "    |residual|_2 of individual variables:\n";
      67       25386 :   for (unsigned int var_num = 0; var_num < _sys.n_vars(); var_num++)
      68             :   {
      69       16102 :     Real var_res_id = _sys.calculate_norm(_nl.RHS(), var_num, libMesh::DISCRETE_L2);
      70       16102 :     oss << std::setw(27 - max_name_size) << " "
      71       16102 :         << std::setw(max_name_size + 2) // match position of overall NL residual
      72       16102 :         << std::left << _sys.variable_name(var_num) + ":" << var_res_id << "\n";
      73             :   }
      74             : 
      75        9284 :   _console << oss.str() << std::flush;
      76        9284 : }

Generated by: LCOV version 1.14