https://mooseframework.inl.gov
Loading...
Searching...
No Matches
VectorPostprocessor.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
10// MOOSE includes
11#include "VectorPostprocessor.h"
12#include "SubProblem.h"
13#include "Conversion.h"
14#include "UserObject.h"
15#include "FEProblem.h"
16
19{
22 params.addParam<bool>("contains_complete_history",
23 false,
24 "Set this flag to indicate that the values in all vectors declared by this "
25 "VPP represent a time history (e.g. with each invocation, new values are "
26 "added and old values are never removed). This changes the output so that "
27 "only a single file is output and updated with each invocation");
28
29 // VPPs can set this to true if their resulting vectors are naturally replicated in parallel
30 // setting this to false will keep MOOSE from unnecessarily broadcasting those vectors
31 params.addPrivateParam<bool>("_auto_broadcast", true);
32
33 // VPPs can operate in "distributed" mode, which disables the automatic broadcasting
34 // and results in an individual file per processor if CSV output is enabled
35 MooseEnum parallel_type("DISTRIBUTED REPLICATED", "REPLICATED");
36 params.addParam<MooseEnum>(
37 "parallel_type",
38 parallel_type,
39 "Set how the data is represented within the VectorPostprocessor (VPP); 'distributed' "
40 "indicates that data within the VPP is distributed and no auto communication is performed, "
41 "this setting will result in parallel output within the CSV output; 'replicated' indicates "
42 "that the data within the VPP is correct on processor 0, the data will automatically be "
43 "broadcast to all processors unless the '_auto_broadcast' param is set to false within the "
44 "validParams function.");
45
46 params.addParamNamesToGroup("outputs", "Advanced");
47 params.registerBase("VectorPostprocessor");
48 return params;
49}
50
52 : OutputInterface(moose_object->parameters()),
53 NonADFunctorInterface(moose_object),
54 _vpp_name(moose_object->name()),
55 _vpp_fe_problem(
56 *moose_object->parameters().getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
57 _parallel_type(moose_object->parameters().get<MooseEnum>("parallel_type")),
58 _vpp_moose_object(*moose_object),
59 _vpp_tid(moose_object->parameters().isParamValid("_tid")
60 ? moose_object->parameters().get<THREAD_ID>("_tid")
61 : 0),
62 _contains_complete_history(moose_object->parameters().get<bool>("contains_complete_history")),
63 _is_distributed(_parallel_type == "DISTRIBUTED"),
64 _is_broadcast(_is_distributed || !moose_object->parameters().get<bool>("_auto_broadcast"))
65{
66}
67
68#ifdef MOOSE_KOKKOS_ENABLED
71 : OutputInterface(object, key),
72 NonADFunctorInterface(object, key),
73 _vpp_name(object._vpp_name),
74 _vpp_fe_problem(object._vpp_fe_problem),
75 _parallel_type(object._parallel_type),
76 _vpp_moose_object(object._vpp_moose_object),
77 _vpp_tid(object._vpp_tid),
78 _contains_complete_history(object._contains_complete_history),
79 _is_distributed(object._is_distributed),
80 _is_broadcast(object._is_broadcast)
81{
82}
83#endif
84
86VectorPostprocessor::declareVector(const std::string & vector_name)
87{
88 _vector_names.insert(vector_name);
89
90 if (_vpp_tid)
91 return _thread_local_vectors.emplace(vector_name, VectorPostprocessorValue()).first->second;
92
93 // _is_broadcast = true (_auto_broadcast = false) then data is produced in a replicated manner
95 if (_is_broadcast)
99
104}
105
106const std::set<std::string> &
111
113
114template <typename T>
116 const MooseObject & producer,
117 ReporterState<T> & state)
118 : ReporterGeneralContext<T>(other, producer, state)
119{
120}
121
122template <typename T>
123void
125{
127
128 const auto & consumer_modes = this->state().getConsumers();
129 auto func = [](const std::pair<ReporterMode, const MooseObject *> & mode_pair)
130 { return mode_pair.first == REPORTER_MODE_VPP_SCATTER; };
131 if (std::find_if(consumer_modes.begin(), consumer_modes.end(), func) != consumer_modes.end())
132 {
133 const T & value = this->state().value();
134 if (this->processor_id() == 0 && value.size() != this->n_processors())
135 mooseError("The VectorPostprocessor value to be scatter has a length of ",
136 value.size(),
137 "; it must be the same length as the number of processors (",
138 this->n_processors(),
139 ").");
140
141 this->comm().scatter(value, _scatter_value);
142 }
143}
144
145template <typename T>
146void
148{
150 _scatter_value_old = _scatter_value;
151}
152
153template <typename T>
156{
157 return _scatter_value;
158}
159
160template <typename T>
163{
164 return _scatter_value_old;
165}
166
167// Explicit instantiation
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Real ScatterVectorPostprocessorValue
Definition MooseTypes.h:232
unsigned int THREAD_ID
Definition MooseTypes.h:237
std::vector< Real > VectorPostprocessorValue
Definition MooseTypes.h:231
const ReporterMode REPORTER_MODE_REPLICATED
const ReporterMode REPORTER_MODE_DISTRIBUTED
const ReporterMode REPORTER_MODE_ROOT
const ReporterMode REPORTER_MODE_VPP_SCATTER("VPP_SCATTER")
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const ReporterData & getReporterData() const
Provides const access the ReporterData object.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
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 addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
An interface for accessing Moose::Functors for systems that do not care about automatic differentiati...
static InputParameters validParams()
A class to provide an common interface to objects requiring "outputs" option.
static InputParameters validParams()
virtual void copyValuesBack()=0
Called by FEProblemBase::advanceState via ReporterData.
virtual void finalize()=0
Called by FEProblemBase::joinAndFinalize via ReporterData.
T & declareReporterValue(const ReporterName &reporter_name, const ReporterMode &mode, const MooseObject &producer, Args &&... args)
Method for returning a writable reference to the current Reporter value.
MooseEnumItem that automatically creates the ID and doesn't allow the ID to be assigned.
A special version of RestartableData to aid in storing Reporter values.
const ScatterVectorPostprocessorValue & getScatterValueOld() const
VectorPostprocessorContext(const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< T > &state)
virtual void copyValuesBack() override
Called by FEProblemBase::advanceState via ReporterData.
const ScatterVectorPostprocessorValue & getScatterValue() const
virtual void finalize() override
Perform automatic parallel communication based on the producer/consumer modes.
A ReporterName that represents a VectorPostprocessor.
Base class for Postprocessors that produce a vector of values.
const MooseObject & _vpp_moose_object
std::set< std::string > _vector_names
std::map< std::string, VectorPostprocessorValue > _thread_local_vectors
VectorPostprocessor(const MooseObject *moose_object)
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.
FEProblemBase & _vpp_fe_problem
The FEProblemBase.
const std::string _vpp_name
The name of the VectorPostprocessor.
static InputParameters validParams()