LCOV - code coverage report
Current view: top level - src/postprocessors - ElementalVariableValue.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 34 36 94.4 %
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 "ElementalVariableValue.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseMesh.h"
      14             : #include "MooseVariable.h"
      15             : #include "SubProblem.h"
      16             : 
      17             : registerMooseObject("MooseApp", ElementalVariableValue);
      18             : 
      19             : InputParameters
      20       14693 : ElementalVariableValue::validParams()
      21             : {
      22       14693 :   InputParameters params = GeneralPostprocessor::validParams();
      23       14693 :   params.addRequiredParam<VariableName>("variable", "The variable to be monitored");
      24       14693 :   params.addRequiredParam<unsigned int>("elementid", "The ID of the element where we monitor");
      25       14693 :   params.addClassDescription("Outputs an elemental variable value at a particular location");
      26       14693 :   return params;
      27           0 : }
      28             : 
      29         212 : ElementalVariableValue::ElementalVariableValue(const InputParameters & parameters)
      30             :   : GeneralPostprocessor(parameters),
      31         424 :     _mesh(_subproblem.mesh()),
      32         212 :     _var_name(parameters.get<VariableName>("variable")),
      33         212 :     _value(0)
      34             : {
      35             :   // This class may be too dangerous to use if renumbering is enabled,
      36             :   // as the nodeid parameter obviously depends on a particular
      37             :   // numbering.
      38         212 :   if (_mesh.getMesh().allow_renumbering())
      39           0 :     mooseError("ElementalVariableValue should only be used when node renumbering is disabled.");
      40         212 : }
      41             : 
      42             : void
      43         204 : ElementalVariableValue::initialSetup()
      44             : {
      45             :   // Do this in initialSetup instead of the constructor because elements may be deleted after this
      46             :   // object is constructed
      47         204 :   _element = _mesh.queryElemPtr(getParam<unsigned int>("elementid"));
      48         204 :   GeneralPostprocessor::initialSetup();
      49         204 : }
      50             : 
      51             : void
      52         769 : ElementalVariableValue::execute()
      53             : {
      54         769 :   _value = 0;
      55         769 :   if (_element && (_element->processor_id() == processor_id()))
      56             :   {
      57         564 :     _fe_problem.setCurrentSubdomainID(_element, 0);
      58         564 :     _subproblem.prepare(_element, _tid);
      59         564 :     _subproblem.reinitElem(_element, _tid);
      60             : 
      61             :     MooseVariableField<Real> & var = static_cast<MooseVariableField<Real> &>(
      62         564 :         _subproblem.getActualFieldVariable(_tid, _var_name));
      63         564 :     const VariableValue & u = var.sln();
      64         564 :     unsigned int n = u.size();
      65        2591 :     for (unsigned int i = 0; i < n; i++)
      66        2027 :       _value += u[i];
      67         564 :     _value /= n;
      68             :   }
      69         769 : }
      70             : 
      71             : Real
      72         769 : ElementalVariableValue::getValue() const
      73             : {
      74         769 :   return _value;
      75             : }
      76             : 
      77             : void
      78         769 : ElementalVariableValue::finalize()
      79             : {
      80         769 :   gatherSum(_value);
      81         769 : }

Generated by: LCOV version 1.14