https://mooseframework.inl.gov
ArrayVariableValueVolumeHistogram.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 
12 // MOOSE includes
13 #include "MooseVariableFE.h"
14 
15 #include "libmesh/quadrature.h"
16 
18 
21 {
23  params.addClassDescription("Compute histograms of volume fractions binned according to component "
24  "values of an array variable.");
25  params.addParam<unsigned int>("bin_number", 50, "Number of histogram bins");
26  params.addCoupledVar("variable", "Variable to bin the volume of");
27  params.addRequiredParam<Real>("min_value", "Minimum variable value");
28  params.addRequiredParam<Real>("max_value", "Maximum variable value");
29  return params;
30 }
31 
33  const InputParameters & parameters)
34  : ElementVectorPostprocessor(parameters),
35  _nbins(getParam<unsigned int>("bin_number")),
36  _min_value(getParam<Real>("min_value")),
37  _max_value(getParam<Real>("max_value")),
38  _deltaV((_max_value - _min_value) / _nbins),
39  _value(coupledArrayValue("variable")),
40  _var(*getArrayVar("variable", 0)),
41  _bin_center(declareVector("value"))
42 {
43  if (coupledComponents("variable") != 1)
44  mooseError("ArrayVariableValueVolumeHistogram works on exactly one coupled variable");
45 
46  for (const unsigned int i : make_range(_var.count()))
48 
49  // initialize the bin center value vector
50  _bin_center.resize(_nbins);
51  for (const unsigned int i : make_range(_nbins))
52  _bin_center[i] = (i + 0.5) * _deltaV + _min_value;
53 }
54 
55 void
57 {
58  // reset the histogram
59  for (auto & volume : _volumes)
60  volume->assign(_nbins, 0.0);
61 }
62 
63 void
65 {
66  // loop over quadrature points
67  for (auto _qp : make_range(_qrule->n_points()))
68  {
69  for (const unsigned int i : make_range(_var.count()))
70  {
71  // compute target bin
72  int bin = (_value[_qp](i) - _min_value) / _deltaV;
73 
74  // add the volume contributed by the current quadrature point
75  if (bin >= 0 && static_cast<unsigned int>(bin) < _nbins)
76  (*_volumes[i])[bin] += _JxW[_qp] * _coord[_qp];
77  }
78  }
79 }
80 
81 void
83 {
84  for (const unsigned int i : make_range(_var.count()))
85  gatherSum(*_volumes[i]);
86 }
87 
88 void
90 {
91  const auto & uo = static_cast<const ArrayVariableValueVolumeHistogram &>(y);
92  mooseAssert(uo._volumes.size() == _volumes.size(),
93  "Inconsistent number of array variable components across threads.");
94 
95  for (const unsigned int i : make_range(_var.count()))
96  {
97  mooseAssert(uo._volumes[i]->size() == _volumes[i]->size(),
98  "Inconsistent volume vector lengths across threads.");
99  for (const unsigned int j : index_range(*_volumes[i]))
100  (*_volumes[i])[j] += (*uo._volumes[i])[j];
101  }
102 }
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
ArrayVariableValueVolumeHistogram(const InputParameters &parameters)
const MooseArray< Real > & _coord
unsigned int count() const
Get the number of components Note: For standard and vector variables, the number is one...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void execute() override
Execute method.
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...
const Real _min_value
minimum variable value
const ArrayVariableValue & _value
coupled variable that is being binned
virtual void threadJoin(const UserObject &y) override
Must override.
std::vector< VectorPostprocessorValue * > _volumes
aggregated volumes of all components for the given bin
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
VectorPostprocessorValue & _bin_center
value mid point of the bin
VectorPostprocessorValue & declareVector(const std::string &vector_name)
Register a new vector to fill up.
registerMooseObject("MooseApp", ArrayVariableValueVolumeHistogram)
Real volume(const MeshBase &mesh, unsigned int dim=libMesh::invalid_uint)
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
unsigned int coupledComponents(const std::string &var_name) const
Number of coupled components.
Definition: Coupleable.C:188
virtual void finalize() override
Finalize.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
const MooseArray< Real > & _JxW
const std::string & arrayVariableComponent(const unsigned int i) const
Returns the variable name of a component of an array variable.
IntRange< T > make_range(T beg, T end)
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:281
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
static InputParameters validParams()
Compute histograms of volume fractions binned according to component values of an array variable...
const unsigned int _nbins
number of histogram bins
const ArrayMooseVariable & _var
coupled array variable
void ErrorVector unsigned int
auto index_range(const T &sizable)
Base class for user-specific data.
Definition: UserObject.h:19
unsigned int _qp
current quadrature point - used in computeVolume()