https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SamplerPostprocessorTransfer.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// StochasticTools includes
14#include "SamplerReceiver.h"
15#include "StochasticResults.h"
16#include "Sampler.h"
17
19
20std::vector<VectorPostprocessorName>
21getVectorNamesHelper(const std::string & prefix, const std::vector<PostprocessorName> & pp_names)
22{
23 std::vector<VectorPostprocessorName> vec_names;
24 vec_names.reserve(pp_names.size());
25 for (const auto & pp_name : pp_names)
26 {
27 if (!prefix.empty())
28 vec_names.push_back(prefix + ":" + pp_name);
29 else
30 vec_names.push_back(pp_name);
31 }
32 return vec_names;
33}
34
37{
39 params.addClassDescription("Transfers data from Postprocessors on the sub-application to a "
40 "VectorPostprocessor on the master application.");
41
42 params.addParam<std::vector<PostprocessorName>>(
43 "from_postprocessor", "The name(s) of the Postprocessor(s) on the sub-app to transfer from.");
44 params.addParam<VectorPostprocessorName>("to_vector_postprocessor",
45 "The name of the VectorPostprocessor in "
46 "the MultiApp to transfer values "
47 "to.");
48
49 params.addParam<std::string>("prefix",
50 "Use the supplied string as the prefix for vector postprocessor "
51 "name rather than the transfer name.");
52
53 params.addParam<bool>("keep_solve_fail_value",
54 false,
55 "If true, whatever the value the sub app has upon exitting is used. "
56 "If false, NaN will be transferred.");
57
58 params.suppressParameter<MultiMooseEnum>("direction");
59 params.suppressParameter<MultiAppName>("multi_app");
60 return params;
61}
62
64 : StochasticToolsTransfer(parameters),
65 _sub_pp_names(getParam<std::vector<PostprocessorName>>("from_postprocessor")),
66 _master_vpp_name(getParam<VectorPostprocessorName>("to_vector_postprocessor")),
67 _vpp_names(isParamValid("prefix")
68 ? getVectorNamesHelper(getParam<std::string>("prefix"), _sub_pp_names)
69 : getVectorNamesHelper(_name, _sub_pp_names)),
70 _keep_diverge(getParam<bool>("keep_solve_fail_value"))
71{
72 if (hasToMultiApp())
73 paramError("to_multi_app", "To and between multiapp directions are not implemented");
74}
75
76const std::vector<VectorPostprocessorName> &
81
82void
84{
85 // Get the StochasticResults VPP object to populate
87 _results = dynamic_cast<StochasticResults *>(&uo);
88 if (!_results)
89 mooseError("The 'results' object must be a 'StochasticResults' object.");
90
91 // Check that postprocessor on sub-application exists and create vectors on results VPP
92 const dof_id_type n = getFromMultiApp()->numGlobalApps();
93 for (MooseIndex(n) i = 0; i < n; i++)
94 {
95 if (getFromMultiApp()->hasLocalApp(i))
96 {
97 FEProblemBase & app_problem = getFromMultiApp()->appProblemBase(i);
98 for (const auto & sub_pp_name : _sub_pp_names)
99 if (!app_problem.hasPostprocessorValueByName(sub_pp_name))
100 mooseError("Unknown postprocesssor name '",
101 sub_pp_name,
102 "' on sub-application '",
103 getFromMultiApp()->name(),
104 "'");
105 }
106 }
107
108 // Initialize storage for accumulating VPP data
109 _current_data.resize(_sub_pp_names.size());
110}
111
112void
114{
116 {
117 current.clear();
118 current.reserve(_sampler_ptr->getNumberOfLocalRows());
119 }
120}
121
122void
124{
125 if (getFromMultiApp()->isRootProcessor())
126 {
127 const dof_id_type n = getFromMultiApp()->numGlobalApps();
128 for (MooseIndex(n) i = 0; i < n; i++)
129 {
130 if (getFromMultiApp()->hasLocalApp(i))
131 {
132 FEProblemBase & app_problem = getFromMultiApp()->appProblemBase(i);
133 if (app_problem.converged(/*nl_sys_num=*/0) || _keep_diverge)
134 for (std::size_t j = 0; j < _sub_pp_names.size(); ++j)
135 _current_data[j].emplace_back(
137 else
138 for (std::size_t j = 0; j < _sub_pp_names.size(); ++j)
139 _current_data[j].emplace_back(std::numeric_limits<double>::quiet_NaN());
140 }
141 }
142 }
143}
144
145void
147{
148 for (std::size_t j = 0; j < _sub_pp_names.size(); ++j)
149 {
151 _current_data[j].clear();
152 }
153}
154
155void
157{
158 for (std::size_t j = 0; j < _sub_pp_names.size(); ++j)
159 {
161 current.reserve(_sampler_ptr->getNumberOfLocalRows());
162 for (dof_id_type i = _sampler_ptr->getLocalRowBegin(); i < _sampler_ptr->getLocalRowEnd(); ++i)
163 {
164 FEProblemBase & app_problem = getFromMultiApp()->appProblemBase(i);
165 if (app_problem.converged(/*nl_sys_num=*/0) || _keep_diverge)
166 current.emplace_back(app_problem.getPostprocessorValueByName(_sub_pp_names[j]));
167 else
168 current.emplace_back(std::numeric_limits<double>::quiet_NaN());
169 }
171 }
172}
std::vector< Real > VectorPostprocessorValue
std::vector< VectorPostprocessorName > getVectorNamesHelper(const std::string &prefix, const std::vector< PostprocessorName > &pp_names)
registerMooseObject("StochasticToolsApp", SamplerPostprocessorTransfer)
T & getUserObject(const std::string &name, unsigned int tid=0) const
const PostprocessorValue & getPostprocessorValueByName(const PostprocessorName &name, std::size_t t_index=0) const
bool hasPostprocessorValueByName(const PostprocessorName &name) const
void suppressParameter(const std::string &name)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
bool hasToMultiApp() const
const std::shared_ptr< MultiApp > getFromMultiApp() const
Transfer Postprocessor from sub-applications to a VectorPostprocessor on the master application.
SamplerPostprocessorTransfer(const InputParameters &parameters)
std::vector< VectorPostprocessorValue > _current_data
Temporary storage for batch mode execution.
virtual void execute() override
Traditional Transfer callback.
virtual void initializeFromMultiapp() override
Methods used when running in batch mode (see SamplerFullSolveMultiApp)
StochasticResults * _results
Storage for StochasticResults object that data will be transferred to/from.
const std::vector< VectorPostprocessorName > & vectorNames() const
The name of the vector to be created on the StochasticResults object, see StochasticResultsAction)
const VectorPostprocessorName & _master_vpp_name
Name of vector-postprocessor on the master.
const std::vector< PostprocessorName > & _sub_pp_names
Name of postprocessor on the sub-applications.
const std::vector< VectorPostprocessorName > _vpp_names
Storage vector names.
dof_id_type getNumberOfLocalRows() const
dof_id_type getLocalRowEnd() const
dof_id_type getLocalRowBegin() const
A tool for output Sampler data.
void setCurrentLocalVectorPostprocessorValue(const std::string &vector_name, const VectorPostprocessorValue &&current)
The class creates an additional API to allow Transfers to work when running the StochasticTools<FullS...
static InputParameters validParams()
Sampler * _sampler_ptr
Pointer to the Sampler object used by the SamplerTransientMultiApp or SamplerFullSolveMultiApp.
virtual bool converged(const unsigned int sys_num)
FEProblemBase & _fe_problem