LCOV - code coverage report
Current view: top level - src/postprocessors - NodalVariableValue.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 31 35 88.6 %
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 "NodalVariableValue.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseMesh.h"
      14             : #include "MooseVariable.h"
      15             : #include "SubProblem.h"
      16             : 
      17             : #include "libmesh/node.h"
      18             : 
      19             : registerMooseObject("MooseApp", NodalVariableValue);
      20             : 
      21             : InputParameters
      22       14657 : NodalVariableValue::validParams()
      23             : {
      24       14657 :   InputParameters params = GeneralPostprocessor::validParams();
      25       14657 :   params.addRequiredParam<VariableName>("variable", "The variable to be monitored");
      26       14657 :   params.addRequiredParam<unsigned int>("nodeid", "The ID of the node where we monitor");
      27       14657 :   params.addParam<Real>("scale_factor", 1, "A scale factor to be applied to the variable");
      28       14657 :   params.addClassDescription("Outputs values of a nodal variable at a particular location");
      29       14657 :   return params;
      30           0 : }
      31             : 
      32         196 : NodalVariableValue::NodalVariableValue(const InputParameters & parameters)
      33             :   : GeneralPostprocessor(parameters),
      34         392 :     _mesh(_subproblem.mesh()),
      35         196 :     _var_name(parameters.get<VariableName>("variable")),
      36         196 :     _node_ptr(nullptr),
      37         196 :     _scale_factor(getParam<Real>("scale_factor")),
      38         196 :     _value(0)
      39             : {
      40             :   // This class may be too dangerous to use if renumbering is enabled,
      41             :   // as the nodeid parameter obviously depends on a particular
      42             :   // numbering.
      43         196 :   if (_mesh.getMesh().allow_renumbering())
      44           0 :     mooseError("NodalVariableValue should only be used when node renumbering is disabled.");
      45         196 : }
      46             : 
      47             : void
      48         196 : NodalVariableValue::initialSetup()
      49             : {
      50         196 :   _node_ptr = _mesh.getMesh().query_node_ptr(getParam<unsigned int>("nodeid"));
      51         196 :   bool found_node_ptr = _node_ptr;
      52         196 :   _communicator.max(found_node_ptr);
      53             : 
      54         196 :   if (!found_node_ptr)
      55           0 :     mooseError("Node #",
      56             :                getParam<unsigned int>("nodeid"),
      57             :                " specified in '",
      58           0 :                name(),
      59             :                "' not found in the mesh!");
      60         196 : }
      61             : 
      62             : void
      63        1654 : NodalVariableValue::execute()
      64             : {
      65        1654 :   _value = 0;
      66             : 
      67        1654 :   if (_node_ptr && _node_ptr->processor_id() == processor_id())
      68        1192 :     _value = _subproblem.getStandardVariable(_tid, _var_name).getNodalValue(*_node_ptr);
      69        1654 : }
      70             : 
      71             : Real
      72        1654 : NodalVariableValue::getValue() const
      73             : {
      74        1654 :   return _scale_factor * _value;
      75             : }
      76             : 
      77             : void
      78        1654 : NodalVariableValue::finalize()
      79             : {
      80        1654 :   gatherSum(_value);
      81        1654 : }

Generated by: LCOV version 1.14