23 "vpp",
"The VectorPostprocessor to compute histogram of");
25 params.
addRequiredParam<
unsigned int>(
"num_bins",
"The number of bins for the histograms");
32 _vpp_name(getParam<VectorPostprocessorName>(
"vpp")),
33 _num_bins(getParam<unsigned
int>(
"num_bins"))
46 paramError(
"vpp",
"The specified VectorPostprocessor does not have any declared vectors");
65 mooseAssert(
_histogram_data.count(vec_name),
"Error retrieving VPP vector");
82 mooseError(
"Cannot compute histogram without data!");
85 auto & lower_vector = *histo_data.
_lower;
86 auto & upper_vector = *histo_data.
_upper;
97 std::vector<Real> sorted_values(
values.size());
98 std::partial_sort_copy(
values.begin(),
values.end(), sorted_values.begin(), sorted_values.end());
101 auto min = sorted_values.front();
102 auto max = sorted_values.back();
105 auto bin_stride = (max - min) /
static_cast<Real
>(
_num_bins);
107 auto current_value_iter = sorted_values.begin();
108 auto sorted_values_end = sorted_values.end();
111 for (
unsigned int bin = 0; bin <
_num_bins; bin++)
116 auto lower = (bin * bin_stride) + min;
117 auto upper = ((bin + 1) * bin_stride) + min;
119 lower_vector[bin] = lower;
120 upper_vector[bin] = upper;
123 unsigned long int num_values = 0;
124 while (current_value_iter != sorted_values_end && *current_value_iter <= upper)
127 current_value_iter++;
130 histogram[bin] =
static_cast<Real
>(num_values);
registerMooseObject("MooseApp", HistogramVectorPostprocessor)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
std::array< Real, 2 > values
void ErrorVector unsigned int
const VectorPostprocessorValue & getVectorPostprocessorValueByName(const std::string &object_name, const std::string &vector_name, std::size_t t_index=0) const
Get a read-only reference to the vector value associated with the VectorPostprocessor.
This class is here to combine the VectorPostprocessor interface and the base class VectorPostprocesso...
static InputParameters validParams()
Computes a histogram for each column in a given VectorPostprocessor.
virtual void finalize() override
Finalize.
static InputParameters validParams()
HistogramVectorPostprocessor(const InputParameters ¶meters)
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
void computeHistogram(const std::vector< Real > &values, HistoData &histo_data)
Compute the histogram of a vector and fill in the lower/upper edges.
const unsigned int & _num_bins
The number of bins.
std::map< std::string, HistoData > _histogram_data
The VPP vectors that will hold the Histogram for each column.
virtual void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
const VectorPostprocessorName & _vpp_name
The name of the VPP to work on.
virtual void execute() override
Execute method.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Base class for Postprocessors that produce a vector of values.
const std::set< std::string > & getVectorNames() const
Return the names of the vectors associated with this object.
VectorPostprocessorValue & declareVector(const std::string &vector_name)
Register a new vector to fill up.
processor_id_type processor_id() const
Helper class to hold the vectors for the histogram.
VectorPostprocessorValue * _upper
The upper edges for each bin.
VectorPostprocessorValue * _histogram
Where the data will actually be stored.
VectorPostprocessorValue * _lower
The lower edges for each bin.