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 14711 : ScalarVariable::validParams() 22 : { 23 14711 : InputParameters params = GeneralPostprocessor::validParams(); 24 14711 : params.addClassDescription("Returns the value of a scalar variable as a postprocessor value."); 25 14711 : params.addRequiredParam<VariableName>("variable", "Name of the variable"); 26 14711 : params.addParam<unsigned int>("component", 0, "Component to output for this variable"); 27 14711 : return params; 28 0 : } 29 : 30 223 : ScalarVariable::ScalarVariable(const InputParameters & parameters) 31 : : GeneralPostprocessor(parameters), 32 223 : _var(_subproblem.getScalarVariable(_tid, getParam<VariableName>("variable"))), 33 223 : _idx(getParam<unsigned int>("component")), 34 223 : _value(0) 35 : { 36 223 : } 37 : 38 : void 39 1093 : ScalarVariable::initialize() 40 : { 41 1093 : } 42 : 43 : void 44 1093 : ScalarVariable::execute() 45 : { 46 1093 : _var.reinit(); 47 1093 : _value = std::numeric_limits<Real>::max(); 48 1093 : const DofMap & dof_map = _var.dofMap(); 49 1093 : const dof_id_type dof = _var.dofIndices()[_idx]; 50 1093 : if (dof >= dof_map.first_dof() && dof < dof_map.end_dof()) 51 949 : _value = _var.sln()[_idx]; 52 1093 : } 53 : 54 : Real 55 1093 : ScalarVariable::getValue() const 56 : { 57 1093 : return _value; 58 : } 59 : 60 : void 61 1093 : ScalarVariable::finalize() 62 : { 63 1093 : gatherMin(_value); 64 1093 : }