https://mooseframework.inl.gov
StochasticResults.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 // Stocastic Tools Includes
11 #include "StochasticResults.h"
12 
13 // MOOSE includes
14 #include "Sampler.h"
16 
17 registerMooseObject("StochasticToolsApp", StochasticResults);
18 
19 StochasticResultsData::StochasticResultsData(const VectorPostprocessorName & name,
21  : name(name), vector(vpp)
22 {
23 }
24 
27 {
29  params.addClassDescription(
30  "Storage container for stochastic simulation results coming from a Postprocessor.");
31 
32  params.addDeprecatedParam<std::vector<SamplerName>>(
33  "samplers",
34  "A list of sampler names of associated data.",
35  "This parameter is no longer needed, please remove it from your input file.");
36 
37  // If 'parallel_type = REPLICATED' broadcast the vector automatically
38  params.set<bool>("_auto_broadcast") = true;
39  return params;
40 }
41 
43  : GeneralVectorPostprocessor(parameters)
44 {
45 }
46 
47 void
49 {
50  // Clear any existing data, unless the complete history is desired
52  for (auto & data : _sample_vectors)
53  data.vector->clear();
54 }
55 
56 void
58 {
59  if (!isDistributed())
60  {
61  for (auto & data : _sample_vectors)
62  _communicator.gather(0, data.current);
63  }
64 
65  for (auto & data : _sample_vectors)
66  {
67  data.vector->insert(data.vector->end(), data.current.begin(), data.current.end());
68  data.current.clear();
69  }
70 }
71 
72 void
74  const std::string & vector_name, const VectorPostprocessorValue && current)
75 {
76  auto data_ptr = std::find_if(_sample_vectors.begin(),
77  _sample_vectors.end(),
78  [&vector_name](StochasticResultsData & data)
79  { return data.name == vector_name; });
80 
81  mooseAssert(data_ptr != _sample_vectors.end(),
82  "Unable to locate a vector with the supplied name of '" << vector_name << "'.");
83  data_ptr->current = current;
84 }
85 
86 void
87 StochasticResults::initVector(const std::string & vector_name)
88 {
89  _sample_vectors.emplace_back(vector_name, &declareVector(vector_name));
90 }
static InputParameters validParams()
std::vector< StochasticResultsData > _sample_vectors
Storage for declared vectors.
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
StochasticResults(const InputParameters &parameters)
void gather(const unsigned int root_id, const T &send_data, std::vector< T, A > &recv) const
T & set(const std::string &name, bool quiet_mode=false)
Storage helper for managing data being assigned to this VPP by a Transfer object. ...
const Parallel::Communicator & _communicator
virtual void finalize() override
bool containsCompleteHistory() const
static InputParameters validParams()
A tool for output Sampler data.
void initVector(const std::string &vector_name)
Create a VPP vector for results data for a given Sampler, see StochasticResultsAction for more detail...
const std::string name
Definition: Setup.h:20
void setCurrentLocalVectorPostprocessorValue(const std::string &vector_name, const VectorPostprocessorValue &&current)
StochasticResultsData(const VectorPostprocessorName &name, VectorPostprocessorValue *)
VectorPostprocessorValue & declareVector(const std::string &vector_name)
virtual void initialize() override
std::vector< Real > VectorPostprocessorValue
registerMooseObject("StochasticToolsApp", StochasticResults)
void addClassDescription(const std::string &doc_string)