www.mooseframework.org
ElementalVariableValue.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 "ElementalVariableValue.h"
11 
12 // MOOSE includes
13 #include "MooseMesh.h"
14 #include "MooseVariable.h"
15 #include "SubProblem.h"
16 
18 
19 template <>
22 {
24  params.addRequiredParam<VariableName>("variable", "The variable to be monitored");
25  params.addRequiredParam<unsigned int>("elementid", "The ID of the element where we monitor");
26  params.addClassDescription("Outputs an elemental variable value at a particular location");
27  return params;
28 }
29 
31  : GeneralPostprocessor(parameters),
32  _mesh(_subproblem.mesh()),
33  _var_name(parameters.get<VariableName>("variable")),
34  _element(_mesh.getMesh().query_elem_ptr(parameters.get<unsigned int>("elementid")))
35 {
36  // This class may be too dangerous to use if renumbering is enabled,
37  // as the nodeid parameter obviously depends on a particular
38  // numbering.
39  if (_mesh.getMesh().allow_renumbering())
40  mooseError("ElementalVariableValue should only be used when node renumbering is disabled.");
41 }
42 
43 Real
45 {
46  Real value = 0;
47 
48  if (_element && (_element->processor_id() == processor_id()))
49  {
53 
55  const VariableValue & u = var.sln();
56  unsigned int n = u.size();
57  for (unsigned int i = 0; i < n; i++)
58  value += u[i];
59  value /= n;
60  }
61 
62  gatherSum(value);
63 
64  return value;
65 }
registerMooseObject("MooseApp", ElementalVariableValue)
virtual MooseVariable & getStandardVariable(THREAD_ID tid, const std::string &var_name)=0
Returns the variable reference for requested MooseVariable which may be in any system.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams< GeneralPostprocessor >()
const FieldVariableValue & sln() const
element solutions
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...
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
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2567
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
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:197
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:141
virtual void setCurrentSubdomainID(const Elem *elem, THREAD_ID tid) override
PetscInt n
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...
ElementalVariableValue(const InputParameters &parameters)
InputParameters validParams< ElementalVariableValue >()