https://mooseframework.inl.gov
CombinedVectorPostprocessor.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 
12 #include "VectorPostprocessor.h"
13 
15 
18 {
20 
21  params.addRequiredParam<std::vector<VectorPostprocessorName>>(
22  "vectorpostprocessors", "The vectorpostprocessors whose vector values are to be combined");
23  params.addParam<std::vector<std::vector<std::string>>>(
24  "vectors", "Vectors to combine from each vectorpostprocessor");
25  params.addParam<Real>("vector_filler_value",
26  0,
27  "Which value to use to fill the smaller vectors (any smaller than the "
28  "largest vector) if the vectors are not the same size");
29  params.addClassDescription(
30  "Outputs the values of an arbitrary user-specified set of "
31  "vectorpostprocessors as a combined vector in the order specified by the user");
32 
33  // If the vectorpostprocessors are already broadcasted, this VPP should not need to
34  // broadcast on its own
35  params.set<bool>("_auto_broadcast") = false;
36 
37  return params;
38 }
39 
41  : GeneralVectorPostprocessor(parameters), _filler_value(getParam<Real>("vector_filler_value"))
42 {
43  // Get all the names of the vectors to combine them
44  const auto & vpps_names = getParam<std::vector<VectorPostprocessorName>>("vectorpostprocessors");
45  std::vector<std::vector<std::string>> vpp_vectors(vpps_names.size());
46  bool vecs_from_param = isParamValid("vectors");
47  if (!vecs_from_param)
48  for (const auto i : index_range(vpps_names))
49  {
50  const auto & vpp_name = vpps_names[i];
51  const auto & vpp = _vpp_fe_problem.getVectorPostprocessorObjectByName(vpp_name);
52  for (const auto & vec_name : vpp.getVectorNames())
53  vpp_vectors[i].push_back(vec_name);
54  }
55  else
56  {
57  vpp_vectors = getParam<std::vector<std::vector<std::string>>>("vectors");
58  if (vpp_vectors.size() != vpps_names.size())
59  paramError(
60  "vectors",
61  "Outer vector size should be the same size as the 'vectorpostprocessors' parameter");
62  }
63 
64  // Declare vectors
65  for (const auto i : index_range(vpp_vectors))
66  for (const auto j : index_range(vpp_vectors[i]))
67  _vpp_vecs.push_back(&this->declareVector(vpps_names[i] + "_" + vpp_vectors[i][j]));
68 
69  // Grab a reference to all the values
70  for (const auto i : index_range(vpps_names))
71  for (const auto & vec_name : vpp_vectors[i])
72  // This will error if the vectors don't exist in the VPP
74  &getVectorPostprocessorValueByName(vpps_names[i], vec_name));
75 }
76 
77 void
79 {
80  for (auto & vec : _vpp_vecs)
81  vec->clear();
82 }
83 
84 void
86 {
87  std::size_t max_size = 0;
88  // The vectors are already ordered
89  for (const auto i : index_range(_vectorpostprocessor_values))
90  {
92  max_size = std::max(max_size, _vectorpostprocessor_values[i]->size());
93  }
94 
95  // Resize to the max size
96  for (const auto i : index_range(_vectorpostprocessor_values))
97  _vpp_vecs[i]->resize(max_size);
98 
99  // Fill with the filler value
100  for (const auto i : index_range(_vectorpostprocessor_values))
101  for (const auto j : make_range(_vectorpostprocessor_values[i]->size(), max_size))
102  (*(_vpp_vecs[i]))[j] = _filler_value;
103 }
static InputParameters validParams()
virtual void initialize() override
Initialize, clears the postprocessor vector.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:467
This class is here to combine the VectorPostprocessor interface and the base class VectorPostprocesso...
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
CombinedVectorPostprocessor is a type of VectorPostprocessor that outputs the values of multiple vect...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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...
auto max(const L &left, const R &right)
CombinedVectorPostprocessor(const InputParameters &parameters)
Class constructor.
virtual void execute() override
Populates the postprocessor vector of values with the supplied vectorpostprocessors.
static InputParameters validParams()
registerMooseObject("MooseApp", CombinedVectorPostprocessor)
const VectorPostprocessor & getVectorPostprocessorObjectByName(const std::string &object_name, const THREAD_ID tid=0) const
Return the VPP object given the name.
const Real _filler_value
A filler value to place on vectors that are smaller than the longest vector.
FEProblemBase & _vpp_fe_problem
The FEProblemBase.
std::vector< const VectorPostprocessorValue * > _vectorpostprocessor_values
The vector of VectorPostprocessorValue objects that are used to get the values of the vectorpostproce...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< VectorPostprocessorValue * > _vpp_vecs
The VectorPostprocessorValue object where the results are stored.
IntRange< T > make_range(T beg, T end)
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...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:209
const VectorPostprocessorValue & getVectorPostprocessorValueByName(const VectorPostprocessorName &name, const std::string &vector_name) const
DEPRECATED: Use the new version where you need to specify whether or not the vector must be broadcast...
auto index_range(const T &sizable)