https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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");
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())
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
77void
79{
80 for (auto & vec : _vpp_vecs)
81 vec->clear();
82}
83
84void
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}
registerMooseObject("MooseApp", CombinedVectorPostprocessor)
CombinedVectorPostprocessor is a type of VectorPostprocessor that outputs the values of multiple vect...
std::vector< VectorPostprocessorValue * > _vpp_vecs
The VectorPostprocessorValue object where the results are stored.
CombinedVectorPostprocessor(const InputParameters &parameters)
Class constructor.
std::vector< const VectorPostprocessorValue * > _vectorpostprocessor_values
The vector of VectorPostprocessorValue objects that are used to get the values of the vectorpostproce...
const Real _filler_value
A filler value to place on vectors that are smaller than the longest vector.
virtual void execute() override
Populates the postprocessor vector of values with the supplied vectorpostprocessors.
virtual void initialize() override
Initialize, clears the postprocessor vector.
const VectorPostprocessor & getVectorPostprocessorObjectByName(const std::string &object_name, const THREAD_ID tid=0) const
Return the VPP object given the name.
This class is here to combine the VectorPostprocessor interface and the base class VectorPostprocesso...
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
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:457
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
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...
FEProblemBase & _vpp_fe_problem
The FEProblemBase.