https://mooseframework.inl.gov
ElementalVariableValue.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 
21 {
23  params.addRequiredParam<VariableName>("variable", "The variable to be monitored");
24  params.addRequiredParam<unsigned int>("elementid", "The ID of the element where we monitor");
25  params.addClassDescription("Outputs an elemental variable value at a particular location");
26  return params;
27 }
28 
30  : GeneralPostprocessor(parameters),
31  _mesh(_subproblem.mesh()),
33  _subproblem.getActualFieldVariable(_tid, getParam<VariableName>("variable")))),
34  _var_sln(_var.sln()),
35  _value(0)
36 {
37  // This class may be too dangerous to use if renumbering is enabled,
38  // as the nodeid parameter obviously depends on a particular
39  // numbering.
40  if (_mesh.getMesh().allow_renumbering())
41  mooseError("ElementalVariableValue should only be used when node renumbering is disabled.");
42 }
43 
44 void
46 {
47  // Do this in initialSetup instead of the constructor because elements may be deleted after this
48  // object is constructed
49  _element = _mesh.queryElemPtr(getParam<unsigned int>("elementid"));
51 }
52 
53 void
55 {
56  _value = 0;
57  if (_element && (_element->processor_id() == processor_id()))
58  {
62 
63  unsigned int n = _var_sln.size();
64  for (unsigned int i = 0; i < n; i++)
65  _value += _var_sln[i];
66  _value /= n;
67  }
68 }
69 
70 Real
72 {
73  return _value;
74 }
75 
76 void
78 {
80 }
virtual void execute() override
Execute method.
const THREAD_ID _tid
Thread ID of this postprocessor.
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
registerMooseObject("MooseApp", ElementalVariableValue)
virtual void finalize() override
This is called after execute() and after threadJoin()! This is probably where you want to do MPI comm...
virtual void reinitElem(const Elem *elem, const THREAD_ID tid)=0
Class for stuff related to variables.
const VariableValue & _var_sln
The element solution values of the monitored variable.
Tnew cast_ref(Told &oldvar)
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
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 Elem * queryElemPtr(const dof_id_type i)
Definition: MooseMesh.C:3225
static InputParameters validParams()
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Real _value
The computed elemental variable value.
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3548
SubProblem & _subproblem
Reference to the Subproblem for this user object.
virtual void prepare(const Elem *elem, const THREAD_ID tid)=0
virtual void setCurrentSubdomainID(const Elem *elem, const THREAD_ID tid) override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const MooseMesh & _mesh
The mesh.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:271
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...
virtual void initialSetup()
Gets called at the beginning of the simulation before this object is asked to do its job...
virtual Real getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
processor_id_type processor_id() const
const Elem * _element
The element on which the variable value is monitored.
ElementalVariableValue(const InputParameters &parameters)
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...