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 
23 {
25  params.addRequiredParam<VariableName>("variable", "The variable to be monitored");
26  params.addRequiredParam<unsigned int>("nodeid", "The ID of the node where we monitor");
27  params.addParam<Real>("scale_factor", 1, "A scale factor to be applied to the variable");
28  params.addClassDescription("Outputs values of a nodal variable at a particular location");
29  return params;
30 }
31 
33  : GeneralPostprocessor(parameters),
34  _mesh(_subproblem.mesh()),
35  _var_name(parameters.get<VariableName>("variable")),
36  _node_ptr(nullptr),
37  _scale_factor(getParam<Real>("scale_factor")),
38  _value(0)
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 
47 void
49 {
50  _node_ptr = _mesh.getMesh().query_node_ptr(getParam<unsigned int>("nodeid"));
51  bool found_node_ptr = _node_ptr;
52  _communicator.max(found_node_ptr);
53 
54  if (!found_node_ptr)
55  mooseError("Node #",
56  getParam<unsigned int>("nodeid"),
57  " specified in '",
58  name(),
59  "' not found in the mesh!");
60 }
61 
62 void
64 {
65  _value = 0;
66 
67  if (_node_ptr && _node_ptr->processor_id() == processor_id())
69 }
70 
71 Real
73 {
74  return _scale_factor * _value;
75 }
76 
77 void
79 {
81 }
virtual void finalize() override
This is called after execute() and after threadJoin()! This is probably where you want to do MPI comm...
virtual void execute() override
Execute method.
NodalVariableValue(const InputParameters &parameters)
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1147
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
const Parallel::Communicator & _communicator
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
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...
SubProblem & _subproblem
Reference to the Subproblem for this user object.
Definition: UserObject.h:207
static InputParameters validParams()
void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
Definition: UserObject.h:125
registerMooseObject("MooseApp", NodalVariableValue)
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3198
Sums a nodal value across all processors and multiplies the result by a scale factor.
virtual Real getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
virtual MooseVariable & getStandardVariable(const THREAD_ID tid, const std::string &var_name)=0
Returns the variable reference for requested MooseVariable which may be in any system.
OutputData getNodalValue(const Node &node) const
Get the value of this variable at given node.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void max(const T &r, T &o, Request &req) const
const THREAD_ID _tid
Thread ID of this postprocessor.
Definition: UserObject.h:217
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
processor_id_type processor_id() const