www.mooseframework.org
ElementalVariableValue.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 "ElementalVariableValue.h"
16 
17 // MOOSE includes
18 #include "MooseMesh.h"
19 #include "MooseVariable.h"
20 #include "SubProblem.h"
21 
22 template <>
25 {
27  params.addRequiredParam<VariableName>("variable", "The variable to be monitored");
28  params.addRequiredParam<unsigned int>("elementid", "The ID of the element where we monitor");
29  params.addClassDescription("Outputs an elemental variable value at a particular location");
30  return params;
31 }
32 
34  : GeneralPostprocessor(parameters),
35  _mesh(_subproblem.mesh()),
36  _var_name(parameters.get<VariableName>("variable")),
37  _element(_mesh.getMesh().query_elem_ptr(parameters.get<unsigned int>("elementid")))
38 {
39  // This class may be too dangerous to use if renumbering is enabled,
40  // as the nodeid parameter obviously depends on a particular
41  // numbering.
42  if (_mesh.getMesh().allow_renumbering())
43  mooseError("ElementalVariableValue should only be used when node renumbering is disabled.");
44 }
45 
46 Real
48 {
49  Real value = 0;
50 
51  if (_element && (_element->processor_id() == processor_id()))
52  {
55 
57  const VariableValue & u = var.sln();
58  unsigned int n = u.size();
59  for (unsigned int i = 0; i < n; i++)
60  value += u[i];
61  value /= n;
62  }
63 
64  gatherSum(value);
65 
66  return value;
67 }
Class for stuff related to variables.
Definition: MooseVariable.h:43
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. ...
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...
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:2408
virtual void prepare(const Elem *elem, THREAD_ID tid)=0
virtual Real getValue() override
This will get called to actually grab the final value the postprocessor has calculated.
virtual void reinitElem(const Elem *elem, THREAD_ID tid)=0
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:250
PetscInt n
const VariableValue & sln()
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 mooseError(Args &&...args) const
Definition: MooseObject.h:80
ElementalVariableValue(const InputParameters &parameters)
InputParameters validParams< ElementalVariableValue >()