www.mooseframework.org
VolumeHistogram.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 "VolumeHistogram.h"
11 
12 // MOOSE includes
13 #include "MooseVariableFE.h"
14 
15 #include "libmesh/quadrature.h"
16 
18 
19 template <>
22 {
24  params.addParam<unsigned int>("bin_number", 50, "Number of histogram bins");
25  params.addCoupledVar("variable", "Variable to bin the volume of");
26  params.addRequiredParam<Real>("min_value", "Minimum variable value");
27  params.addRequiredParam<Real>("max_value", "Maximum variable value");
28  return params;
29 }
30 
32  : ElementVectorPostprocessor(parameters),
33  _nbins(getParam<unsigned int>("bin_number")),
34  _min_value(getParam<Real>("min_value")),
35  _max_value(getParam<Real>("max_value")),
36  _deltaV((_max_value - _min_value) / _nbins),
37  _value(coupledValue("variable")),
38  _bin_center(declareVector(getVar("variable", 0)->name())),
39  _volume(declareVector("n"))
40 {
41  if (coupledComponents("variable") != 1)
42  mooseError("VolumeHistogram works on exactly one coupled variable");
43 
44  // initialize the bin center value vector
45  _bin_center.resize(_nbins);
46  for (unsigned i = 0; i < _nbins; ++i)
47  _bin_center[i] = (i + 0.5) * _deltaV + _min_value;
48 }
49 
50 void
52 {
53  // reset the histogram
54  _volume.assign(_nbins, 0.0);
55 }
56 
57 void
59 {
60  // loop over quadrature points
61  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
62  {
63  // compute target bin
64  int bin = (_value[_qp] - _min_value) / _deltaV;
65 
66  // add the volume contributed by the current quadrature point
67  if (bin >= 0 && static_cast<unsigned int>(bin) < _nbins)
68  _volume[bin] += computeVolume();
69  }
70 }
71 
72 void
74 {
76 }
77 
78 void
80 {
81  const VolumeHistogram & uo = static_cast<const VolumeHistogram &>(y);
82  mooseAssert(uo._volume.size() == _volume.size(),
83  "Inconsistent volume vector lengths across threads.");
84 
85  for (unsigned int i = 0; i < _volume.size(); ++i)
86  _volume[i] += uo._volume[i];
87 }
88 
89 Real
91 {
92  // overwrite this method to multiply with phase fraction order parameters etc.
93  return _JxW[_qp] * _coord[_qp];
94 }
VectorPostprocessorValue & _volume
aggregated volume for the given bin
unsigned int coupledComponents(const std::string &var_name)
Number of coupled components.
Definition: Coupleable.C:166
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
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
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:103
const unsigned int _nbins
number of histogram bins
registerMooseObject("MooseApp", VolumeHistogram)
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 QBase *const & _qrule
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...
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:37
InputParameters validParams< ElementVectorPostprocessor >()
VectorPostprocessorValue & _bin_center
value mid point of the bin