www.mooseframework.org
NodalVariableValue.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
20 
21 template <>
24 {
26  params.addRequiredParam<VariableName>("variable", "The variable to be monitored");
27  params.addRequiredParam<unsigned int>("nodeid", "The ID of the node where we monitor");
28  params.addParam<Real>("scale_factor", 1, "A scale factor to be applied to the variable");
29  params.addClassDescription("Outputs values of a nodal variable at a particular location");
30  return params;
31 }
32 
34  : GeneralPostprocessor(parameters),
35  _mesh(_subproblem.mesh()),
36  _var_name(parameters.get<VariableName>("variable")),
37  _node_ptr(_mesh.getMesh().query_node_ptr(getParam<unsigned int>("nodeid"))),
38  _scale_factor(getParam<Real>("scale_factor"))
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  if (_mesh.getMesh().allow_renumbering())
44  mooseError("NodalVariableValue should only be used when node renumbering is disabled.");
45 
46  bool found_node_ptr = _node_ptr;
47  _communicator.max(found_node_ptr);
48 
49  if (!found_node_ptr)
50  mooseError("Node #",
51  getParam<unsigned int>("nodeid"),
52  " specified in '",
53  name(),
54  "' not found in the mesh!");
55 }
56 
57 Real
59 {
60  Real value = 0;
61 
62  if (_node_ptr && _node_ptr->processor_id() == processor_id())
63  value = _subproblem
64  .getVariable(_tid,
65  _var_name,
68  .getNodalValue(*_node_ptr);
69 
70  gatherSum(value);
71 
72  return _scale_factor * value;
73 }
NodalVariableValue(const InputParameters &parameters)
InputParameters validParams< NodalVariableValue >()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams< GeneralPostprocessor >()
THREAD_ID _tid
Thread ID of this postprocessor.
Definition: UserObject.h:144
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
virtual Real getValue() override
This will get called to actually grab the final value the postprocessor has calculated.
SubProblem & _subproblem
Reference to the Subproblem for this user object.
Definition: UserObject.h:138
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
Definition: UserObject.h:103
registerMooseObject("MooseApp", NodalVariableValue)
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
Sums a nodal value across all processors and multiplies the result by a scale factor.
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...