https://mooseframework.inl.gov
VariableValueVolumeHistogram.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 
19  VolumeHistogram,
20  "06/30/2022 24:00",
22 
25 {
27  params.addClassDescription(
28  "Compute a histogram of volume fractions binned according to variable values.");
29  params.addParam<unsigned int>("bin_number", 50, "Number of histogram bins");
30  params.addCoupledVar("variable", "Variable to bin the volume of");
31  params.addRequiredParam<Real>("min_value", "Minimum variable value");
32  params.addRequiredParam<Real>("max_value", "Maximum variable value");
33  return params;
34 }
35 
37  : ElementVectorPostprocessor(parameters),
38  _nbins(getParam<unsigned int>("bin_number")),
39  _min_value(getParam<Real>("min_value")),
40  _max_value(getParam<Real>("max_value")),
41  _deltaV((_max_value - _min_value) / _nbins),
42  _value(coupledValue("variable")),
43  _bin_center(declareVector(coupledName("variable"))),
44  _volume(declareVector("n"))
45 {
46  if (coupledComponents("variable") != 1)
47  mooseError("VariableValueVolumeHistogram works on exactly one coupled variable");
48 
49  // initialize the bin center value vector
50  _bin_center.resize(_nbins);
51  for (unsigned i = 0; i < _nbins; ++i)
52  _bin_center[i] = (i + 0.5) * _deltaV + _min_value;
53 }
54 
55 void
57 {
58  // reset the histogram
59  _volume.assign(_nbins, 0.0);
60 }
61 
62 void
64 {
65  // loop over quadrature points
66  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
67  {
68  // compute target bin
69  int bin = (_value[_qp] - _min_value) / _deltaV;
70 
71  // add the volume contributed by the current quadrature point
72  if (bin >= 0 && static_cast<unsigned int>(bin) < _nbins)
73  _volume[bin] += computeVolume();
74  }
75 }
76 
77 void
79 {
81 }
82 
83 void
85 {
86  const auto & uo = static_cast<const VariableValueVolumeHistogram &>(y);
87  mooseAssert(uo._volume.size() == _volume.size(),
88  "Inconsistent volume vector lengths across threads.");
89 
90  for (unsigned int i = 0; i < _volume.size(); ++i)
91  _volume[i] += uo._volume[i];
92 }
93 
94 Real
96 {
97  // overwrite this method to multiply with phase fraction order parameters etc.
98  return _JxW[_qp] * _coord[_qp];
99 }
const MooseArray< Real > & _coord
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
VariableValueVolumeHistogram(const InputParameters &parameters)
virtual void threadJoin(const UserObject &y) override
Must override.
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:126
virtual void finalize() override
Finalize.
registerMooseObject("MooseApp", VariableValueVolumeHistogram)
VectorPostprocessorValue & _volume
aggregated volume for the given bin
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:158
unsigned int _qp
current quadrature point - used in computeVolume()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const QBase *const & _qrule
virtual Real computeVolume()
compute the volume contribution at the current quadrature point
const MooseArray< Real > & _JxW
registerMooseObjectRenamed("MooseApp", VolumeHistogram, "06/30/2022 24:00", VariableValueVolumeHistogram)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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()
VectorPostprocessorValue & _bin_center
value mid point of the bin
const VariableValue & _value
coupled variable that is being binned
Compute a histogram of volume fractions binned according to variable values.
virtual void execute() override
Execute method.
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
const unsigned int _nbins
number of histogram bins
const Real _min_value
minimum variable value
void ErrorVector unsigned int
Base class for user-specific data.
Definition: UserObject.h:40