LCOV - code coverage report
Current view: top level - src/postprocessors - VariableResidual.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 19 20 95.0 %
Date: 2025-07-17 01:28:37 Functions: 5 5 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             : #include "VariableResidual.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseVariable.h"
      14             : #include "NonlinearSystemBase.h"
      15             : 
      16             : // libMesh includes
      17             : #include "libmesh/enum_norm_type.h"
      18             : 
      19             : registerMooseObject("MooseApp", VariableResidual);
      20             : 
      21             : InputParameters
      22       14301 : VariableResidual::validParams()
      23             : {
      24       14301 :   InputParameters params = GeneralPostprocessor::validParams();
      25       14301 :   params.addRequiredParam<VariableName>("variable",
      26             :                                         "The name of the variable to compute the residual for");
      27             : 
      28       14301 :   params.addClassDescription(
      29             :       "Computes the L2 norm of the residual of a single variable in the solution vector.");
      30       14301 :   return params;
      31           0 : }
      32             : 
      33          18 : VariableResidual::VariableResidual(const InputParameters & parameters)
      34             :   : GeneralPostprocessor(parameters),
      35          54 :     _var(_fe_problem.getVariable(_tid,
      36          18 :                                  getParam<VariableName>("variable"),
      37             :                                  Moose::VarKindType::VAR_SOLVER,
      38          18 :                                  Moose::VarFieldType::VAR_FIELD_STANDARD))
      39             : {
      40          18 : }
      41             : 
      42             : void
      43          16 : VariableResidual::initialize()
      44             : {
      45          16 :   _var_residual = 0;
      46          16 : }
      47             : 
      48             : void
      49          16 : VariableResidual::execute()
      50             : {
      51          16 :   NonlinearSystemBase & nl = _fe_problem.getNonlinearSystemBase(_sys.number());
      52          16 :   _var_residual = nl.system().calculate_norm(nl.RHS(), _var.number(), libMesh::DISCRETE_L2);
      53          16 : }
      54             : 
      55             : PostprocessorValue
      56          16 : VariableResidual::getValue() const
      57             : {
      58          16 :   return _var_residual;
      59             : }

Generated by: LCOV version 1.14