LCOV - code coverage report
Current view: top level - src/postprocessors - ScalarVariable.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 26 27 96.3 %
Date: 2026-05-29 20:35:17 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        3443 : ScalarVariable::validParams()
      22             : {
      23        3443 :   InputParameters params = GeneralPostprocessor::validParams();
      24        6886 :   params.addClassDescription("Returns the value of a scalar variable as a postprocessor value.");
      25       13772 :   params.addRequiredParam<VariableName>("variable", "Name of the variable");
      26       10329 :   params.addParam<unsigned int>("component", 0, "Component to output for this variable");
      27        3443 :   return params;
      28           0 : }
      29             : 
      30         191 : ScalarVariable::ScalarVariable(const InputParameters & parameters)
      31             :   : GeneralPostprocessor(parameters),
      32         191 :     _var(_subproblem.getScalarVariable(_tid, getParam<VariableName>("variable"))),
      33         382 :     _idx(getParam<unsigned int>("component")),
      34         191 :     _value(0)
      35             : {
      36         191 : }
      37             : 
      38             : void
      39         892 : ScalarVariable::initialize()
      40             : {
      41         892 : }
      42             : 
      43             : void
      44         892 : ScalarVariable::execute()
      45             : {
      46         892 :   _var.reinit();
      47         892 :   _value = std::numeric_limits<Real>::max();
      48         892 :   const DofMap & dof_map = _var.dofMap();
      49         892 :   const dof_id_type dof = _var.dofIndices()[_idx];
      50         892 :   if (dof >= dof_map.first_dof() && dof < dof_map.end_dof())
      51         748 :     _value = _var.sln()[_idx];
      52         892 : }
      53             : 
      54             : Real
      55         892 : ScalarVariable::getValue() const
      56             : {
      57         892 :   return _value;
      58             : }
      59             : 
      60             : void
      61         892 : ScalarVariable::finalize()
      62             : {
      63         892 :   gatherMin(_value);
      64         892 : }

Generated by: LCOV version 1.14