www.mooseframework.org
VolumeHistogram.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 "VolumeHistogram.h"
16 
17 // MOOSE includes
18 #include "MooseVariable.h"
19 
20 #include "libmesh/quadrature.h"
21 
22 template <>
25 {
27  params.addParam<unsigned int>("bin_number", 50, "Number of histogram bins");
28  params.addCoupledVar("variable", "Variable to bin the volume of");
29  params.addRequiredParam<Real>("min_value", "Minimum variable value");
30  params.addRequiredParam<Real>("max_value", "Maximum variable value");
31  return params;
32 }
33 
35  : ElementVectorPostprocessor(parameters),
36  _nbins(getParam<unsigned int>("bin_number")),
37  _min_value(getParam<Real>("min_value")),
38  _max_value(getParam<Real>("max_value")),
39  _deltaV((_max_value - _min_value) / _nbins),
40  _value(coupledValue("variable")),
41  _bin_center(declareVector(getVar("variable", 0)->name())),
42  _volume(declareVector("n"))
43 {
44  if (coupledComponents("variable") != 1)
45  mooseError("VolumeHistogram works on exactly one coupled variable");
46 
47  // initialize the bin center value vector
48  _bin_center.resize(_nbins);
49  for (unsigned i = 0; i < _nbins; ++i)
50  _bin_center[i] = (i + 0.5) * _deltaV + _min_value;
51 }
52 
53 void
55 {
56  // reset the histogram
57  _volume.assign(_nbins, 0.0);
58 }
59 
60 void
62 {
63  // loop over quadrature points
64  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
65  {
66  // compute target bin
67  int bin = (_value[_qp] - _min_value) / _deltaV;
68 
69  // add the volume contributed by the current quadrature point
70  if (bin >= 0 && static_cast<unsigned int>(bin) < _nbins)
71  _volume[bin] += computeVolume();
72  }
73 }
74 
75 void
77 {
79 }
80 
81 void
83 {
84  const VolumeHistogram & uo = static_cast<const VolumeHistogram &>(y);
85  mooseAssert(uo._volume.size() == _volume.size(),
86  "Inconsistent volume vector lengths across threads.");
87 
88  for (unsigned int i = 0; i < _volume.size(); ++i)
89  _volume[i] += uo._volume[i];
90 }
91 
92 Real
94 {
95  // overwrite this method to multiply with phase fraction order parameters etc.
96  return _JxW[_qp] * _coord[_qp];
97 }
VectorPostprocessorValue & _volume
aggregated volume for the given bin
unsigned int coupledComponents(const std::string &var_name)
Number of coupled components.
Definition: Coupleable.C:111
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
Compute a histogram of volume fractions binned according to variable values.
const MooseArray< Real > & _coord
virtual void execute() override
Execute method.
const VariableValue & _value
coupled variable that is being binned
const Real _deltaV
bin width
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Real _min_value
minimum variable value
unsigned int _qp
current quadrature point - used in computeVolume()
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...
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
Definition: UserObject.h:119
const unsigned int _nbins
number of histogram bins
VolumeHistogram(const InputParameters &parameters)
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
virtual void finalize() override
Finalize.
const MooseArray< Real > & _JxW
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
virtual void threadJoin(const UserObject &y) override
Must override.
InputParameters validParams< VolumeHistogram >()
virtual Real computeVolume()
compute the volume contribution at the current quadrature point
Base class for user-specific data.
Definition: UserObject.h:42
InputParameters validParams< ElementVectorPostprocessor >()
VectorPostprocessorValue & _bin_center
value mid point of the bin