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 3502 : ElementalVariableValue::validParams() 21 : { 22 3502 : InputParameters params = GeneralPostprocessor::validParams(); 23 14008 : params.addRequiredParam<VariableName>("variable", "The variable to be monitored"); 24 14008 : params.addRequiredParam<unsigned int>("elementid", "The ID of the element where we monitor"); 25 3502 : params.addClassDescription("Outputs an elemental variable value at a particular location"); 26 3502 : return params; 27 0 : } 28 : 29 205 : ElementalVariableValue::ElementalVariableValue(const InputParameters & parameters) 30 : : GeneralPostprocessor(parameters), 31 410 : _mesh(_subproblem.mesh()), 32 205 : _var(libMesh::cast_ref<MooseVariableField<Real> &>( 33 615 : _subproblem.getActualFieldVariable(_tid, getParam<VariableName>("variable")))), 34 205 : _var_sln(_var.sln()), 35 205 : _value(0) 36 : { 37 : // This class may be too dangerous to use if renumbering is enabled, 38 : // as the nodeid parameter obviously depends on a particular 39 : // numbering. 40 205 : if (_mesh.getMesh().allow_renumbering()) 41 0 : mooseError("ElementalVariableValue should only be used when node renumbering is disabled."); 42 205 : } 43 : 44 : void 45 199 : ElementalVariableValue::initialSetup() 46 : { 47 : // Do this in initialSetup instead of the constructor because elements may be deleted after this 48 : // object is constructed 49 398 : _element = _mesh.queryElemPtr(getParam<unsigned int>("elementid")); 50 199 : GeneralPostprocessor::initialSetup(); 51 199 : } 52 : 53 : void 54 753 : ElementalVariableValue::execute() 55 : { 56 753 : _value = 0; 57 753 : if (_element && (_element->processor_id() == processor_id())) 58 : { 59 548 : _fe_problem.setCurrentSubdomainID(_element, 0); 60 548 : _subproblem.prepare(_element, _tid); 61 548 : _subproblem.reinitElem(_element, _tid); 62 : 63 548 : unsigned int n = _var_sln.size(); 64 2516 : for (unsigned int i = 0; i < n; i++) 65 1968 : _value += _var_sln[i]; 66 548 : _value /= n; 67 : } 68 753 : } 69 : 70 : Real 71 753 : ElementalVariableValue::getValue() const 72 : { 73 753 : return _value; 74 : } 75 : 76 : void 77 753 : ElementalVariableValue::finalize() 78 : { 79 753 : gatherSum(_value); 80 753 : }