https://mooseframework.inl.gov
AverageNodalVariableValue.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 
11 #include "MooseMesh.h"
12 #include "SubProblem.h"
13 
15 
18 {
20 
21  params.addClassDescription("Computes the average value of a field by sampling all nodal "
22  "solutions on the domain or within a subdomain");
23  return params;
24 }
25 
27  : NodalVariablePostprocessor(parameters), _sum(0), _n(0)
28 {
29 }
30 
31 // doco-init-start
32 void
34 {
35  _sum = 0;
36  _n = 0;
37 }
38 // doco-init-end
39 
40 // doco-execute-get-start
41 void
43 {
44  _sum += _u[_qp];
45  _n++;
46 }
47 
48 Real
50 {
51  return _sum / _n;
52 }
53 // doco-execute-get-end
54 
55 // doco-final-start
56 void
58 {
59  gatherSum(_sum);
60  gatherSum(_n);
61 }
62 // doco-final-end
63 
64 // doco-thread-start
65 void
67 {
68  const auto & pps = static_cast<const AverageNodalVariableValue &>(y);
69  _sum += pps._sum;
70  _n += pps._n;
71 }
72 // doco-thread-end
virtual void execute() override
Execute method.
This is a base class for other classes which compute post-processed values based on nodal solution va...
static InputParameters validParams()
const VariableValue & _u
Holds the solution at current quadrature points.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual Real getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
Definition: UserObject.h:126
const unsigned int _qp
Quadrature point index.
virtual void finalize() override
This is called after execute() and after threadJoin()! This is probably where you want to do MPI comm...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
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 threadJoin(const UserObject &y) override
Must override.
registerMooseObject("MooseApp", AverageNodalVariableValue)
static InputParameters validParams()
Base class for user-specific data.
Definition: UserObject.h:40
AverageNodalVariableValue(const InputParameters &parameters)