https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
55void
57{
58 // reset the histogram
59 for (auto & volume : _volumes)
60 volume->assign(_nbins, 0.0);
61}
62
63void
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
81void
83{
84 for (const unsigned int i : make_range(_var.count()))
86}
87
88void
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}
registerMooseObject("MooseApp", ArrayVariableValueVolumeHistogram)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
void ErrorVector unsigned int
Compute histograms of volume fractions binned according to component values of an array variable.
const unsigned int _nbins
number of histogram bins
virtual void execute() override
Execute method.
virtual void threadJoin(const UserObject &y) override
Must override.
ArrayVariableValueVolumeHistogram(const InputParameters &parameters)
std::vector< VectorPostprocessorValue * > _volumes
aggregated volumes of all components for the given bin
const ArrayVariableValue & _value
coupled variable that is being binned
VectorPostprocessorValue & _bin_center
value mid point of the bin
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
unsigned int _qp
current quadrature point - used in computeVolume()
const ArrayMooseVariable & _var
coupled array variable
unsigned int coupledComponents(const std::string &var_name) const
Number of coupled components.
Definition Coupleable.C:183
const QBase *const & _qrule
const MooseArray< Real > & _coord
const MooseArray< Real > & _JxW
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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 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 addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
const std::string & arrayVariableComponent(const unsigned int i) const
Returns the variable name of a component of an array variable.
unsigned int count() const
Get the number of components Note: For standard and vector variables, the number is one.
void gatherSum(T &value)
Gather the parallel sum of the variable passed in.
Base class for user-specific data.
Definition UserObject.h:20
VectorPostprocessorValue & declareVector(const std::string &vector_name)
Register a new vector to fill up.