LCOV - code coverage report
Current view: top level - src/postprocessors - ElementalVariableValue.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 34 36 94.4 %
Date: 2025-08-08 20:01:16 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       14723 : ElementalVariableValue::validParams()
      21             : {
      22       14723 :   InputParameters params = GeneralPostprocessor::validParams();
      23       14723 :   params.addRequiredParam<VariableName>("variable", "The variable to be monitored");
      24       14723 :   params.addRequiredParam<unsigned int>("elementid", "The ID of the element where we monitor");
      25       14723 :   params.addClassDescription("Outputs an elemental variable value at a particular location");
      26       14723 :   return params;
      27           0 : }
      28             : 
      29         227 : ElementalVariableValue::ElementalVariableValue(const InputParameters & parameters)
      30             :   : GeneralPostprocessor(parameters),
      31         454 :     _mesh(_subproblem.mesh()),
      32         227 :     _var_name(parameters.get<VariableName>("variable")),
      33         227 :     _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         227 :   if (_mesh.getMesh().allow_renumbering())
      39           0 :     mooseError("ElementalVariableValue should only be used when node renumbering is disabled.");
      40         227 : }
      41             : 
      42             : void
      43         219 : ElementalVariableValue::initialSetup()
      44             : {
      45             :   // Do this in initialSetup instead of the constructor because elements may be deleted after this
      46             :   // object is constructed
      47         219 :   _element = _mesh.queryElemPtr(getParam<unsigned int>("elementid"));
      48         219 :   GeneralPostprocessor::initialSetup();
      49         219 : }
      50             : 
      51             : void
      52         830 : ElementalVariableValue::execute()
      53             : {
      54         830 :   _value = 0;
      55         830 :   if (_element && (_element->processor_id() == processor_id()))
      56             :   {
      57         625 :     _fe_problem.setCurrentSubdomainID(_element, 0);
      58         625 :     _subproblem.prepare(_element, _tid);
      59         625 :     _subproblem.reinitElem(_element, _tid);
      60             : 
      61             :     MooseVariableField<Real> & var = static_cast<MooseVariableField<Real> &>(
      62         625 :         _subproblem.getActualFieldVariable(_tid, _var_name));
      63         625 :     const VariableValue & u = var.sln();
      64         625 :     unsigned int n = u.size();
      65        2868 :     for (unsigned int i = 0; i < n; i++)
      66        2243 :       _value += u[i];
      67         625 :     _value /= n;
      68             :   }
      69         830 : }
      70             : 
      71             : Real
      72         830 : ElementalVariableValue::getValue() const
      73             : {
      74         830 :   return _value;
      75             : }
      76             : 
      77             : void
      78         830 : ElementalVariableValue::finalize()
      79             : {
      80         830 :   gatherSum(_value);
      81         830 : }

Generated by: LCOV version 1.14