LCOV - code coverage report
Current view: top level - src/postprocessors - ScalarVariable.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 26 27 96.3 %
Date: 2025-07-17 01:28:37 Functions: 6 6 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 "ScalarVariable.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseVariableScalar.h"
      14             : #include "SubProblem.h"
      15             : 
      16             : #include "libmesh/dof_map.h"
      17             : 
      18             : registerMooseObject("MooseApp", ScalarVariable);
      19             : 
      20             : InputParameters
      21       14673 : ScalarVariable::validParams()
      22             : {
      23       14673 :   InputParameters params = GeneralPostprocessor::validParams();
      24       14673 :   params.addClassDescription("Returns the value of a scalar variable as a postprocessor value.");
      25       14673 :   params.addRequiredParam<VariableName>("variable", "Name of the variable");
      26       14673 :   params.addParam<unsigned int>("component", 0, "Component to output for this variable");
      27       14673 :   return params;
      28           0 : }
      29             : 
      30         204 : ScalarVariable::ScalarVariable(const InputParameters & parameters)
      31             :   : GeneralPostprocessor(parameters),
      32         204 :     _var(_subproblem.getScalarVariable(_tid, getParam<VariableName>("variable"))),
      33         204 :     _idx(getParam<unsigned int>("component")),
      34         204 :     _value(0)
      35             : {
      36         204 : }
      37             : 
      38             : void
      39         976 : ScalarVariable::initialize()
      40             : {
      41         976 : }
      42             : 
      43             : void
      44         976 : ScalarVariable::execute()
      45             : {
      46         976 :   _var.reinit();
      47         976 :   _value = std::numeric_limits<Real>::max();
      48         976 :   const DofMap & dof_map = _var.dofMap();
      49         976 :   const dof_id_type dof = _var.dofIndices()[_idx];
      50         976 :   if (dof >= dof_map.first_dof() && dof < dof_map.end_dof())
      51         832 :     _value = _var.sln()[_idx];
      52         976 : }
      53             : 
      54             : Real
      55         976 : ScalarVariable::getValue() const
      56             : {
      57         976 :   return _value;
      58             : }
      59             : 
      60             : void
      61         976 : ScalarVariable::finalize()
      62             : {
      63         976 :   gatherMin(_value);
      64         976 : }

Generated by: LCOV version 1.14