www.mooseframework.org
NodalVariableValue.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "NodalVariableValue.h"
16 
17 // MOOSE includes
18 #include "MooseMesh.h"
19 #include "MooseVariable.h"
20 #include "SubProblem.h"
21 
22 #include "libmesh/node.h"
23 
24 template <>
27 {
29  params.addRequiredParam<VariableName>("variable", "The variable to be monitored");
30  params.addRequiredParam<unsigned int>("nodeid", "The ID of the node where we monitor");
31  params.addParam<Real>("scale_factor", 1, "A scale factor to be applied to the variable");
32  params.addClassDescription("Outputs values of a nodal variable at a particular location");
33  return params;
34 }
35 
37  : GeneralPostprocessor(parameters),
38  _mesh(_subproblem.mesh()),
39  _var_name(parameters.get<VariableName>("variable")),
40  _node_ptr(_mesh.getMesh().query_node_ptr(getParam<unsigned int>("nodeid"))),
41  _scale_factor(getParam<Real>("scale_factor"))
42 {
43  // This class may be too dangerous to use if renumbering is enabled,
44  // as the nodeid parameter obviously depends on a particular
45  // numbering.
46  if (_mesh.getMesh().allow_renumbering())
47  mooseError("NodalVariableValue should only be used when node renumbering is disabled.");
48 
49  bool found_node_ptr = _node_ptr;
50  _communicator.max(found_node_ptr);
51 
52  if (!found_node_ptr)
53  mooseError("Node #",
54  getParam<unsigned int>("nodeid"),
55  " specified in '",
56  name(),
57  "' not found in the mesh!");
58 }
59 
60 Real
62 {
63  Real value = 0;
64 
65  if (_node_ptr && _node_ptr->processor_id() == processor_id())
67 
68  gatherSum(value);
69 
70  return _scale_factor * value;
71 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
virtual MooseVariable & getVariable(THREAD_ID tid, const std::string &var_name)=0
Returns the variable reference for requested variable which may be in any system. ...
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:152
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:146
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
Definition: UserObject.h:119
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2355
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
Number getNodalValue(const Node &node)
Get the value of this variable at given node.