www.mooseframework.org
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
StochasticResults Class Reference

A tool for output Sampler data. More...

#include <StochasticResults.h>

Inheritance diagram for StochasticResults:
[legend]

Public Member Functions

 StochasticResults (const InputParameters &parameters)
 
virtual void initialize () override
 
virtual void finalize () override
 
virtual void execute () override
 
void setCurrentLocalVectorPostprocessorValue (const std::string &vector_name, const VectorPostprocessorValue &&current)
 
void init (Sampler &_sampler)
 DEPRECATED Initialize storage based on the Sampler returned by the SamplerTransientMultiApp or SamplerFullSolveMultiApp. More...
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Attributes

std::vector< StochasticResultsData_sample_vectors
 Storage for declared vectors. More...
 
const MooseEnum _parallel_type
 Parallel operation mode. More...
 
const processor_id_type _output_distributed_rank
 The rank data to output if parallel type is distributed. More...
 

Detailed Description

A tool for output Sampler data.

Definition at line 35 of file StochasticResults.h.

Constructor & Destructor Documentation

◆ StochasticResults()

StochasticResults::StochasticResults ( const InputParameters &  parameters)

Definition at line 54 of file StochasticResults.C.

55  : GeneralVectorPostprocessor(parameters),
56  SamplerInterface(this),
57  _parallel_type(getParam<MooseEnum>("parallel_type")),
58  _output_distributed_rank(getParam<processor_id_type>("output_distributed_rank"))
59 {
60 
61  if (_output_distributed_rank != Moose::INVALID_PROCESSOR_ID)
62  {
63  if (_parallel_type == "replicated")
64  paramError("output_distributed_rank",
65  "The output rank cannot be used with 'parallel_type' set to replicated.");
66  else if (_output_distributed_rank >= n_processors())
67  paramError("output_distributed_rank",
68  "The supplied value is greater than the number of available processors: ",
70  }
71  else
72  {
73  if ((_parallel_type == "DISTRIBUTED") && (getOutputs().count("none") == 0) &&
74  (n_processors() > 1))
75  paramWarning("parallel_type",
76  "The parallel_type was set to DISTRIBUTED and output is enabled for the object, "
77  "when running in parallel the results output will only contain the data on the "
78  "root processor. Output can be disabled by setting 'outputs = none' in the "
79  "input block. If output is desired the 'output_distributed_rank' can be set.");
80  }
81 
82  if (isParamValid("samplers"))
83  for (const SamplerName & name : getParam<std::vector<SamplerName>>("samplers"))
84  {
85  Sampler & sampler = getSamplerByName(name);
86  _sample_vectors.emplace_back(sampler.name(), &declareVector(sampler.name()));
87  }
88 }

Member Function Documentation

◆ execute()

virtual void StochasticResults::execute ( )
inlineoverridevirtual

Definition at line 43 of file StochasticResults.h.

43 {}

◆ finalize()

void StochasticResults::finalize ( )
overridevirtual

Definition at line 100 of file StochasticResults.C.

101 {
102  if (_parallel_type == "REPLICATED")
103  {
104  for (auto & data : _sample_vectors)
105  _communicator.gather(0, data.current);
106  }
107 
108  else if (_output_distributed_rank != 0 && _output_distributed_rank != Moose::INVALID_PROCESSOR_ID)
109  {
110  if (processor_id() == _output_distributed_rank)
111  for (auto & data : _sample_vectors)
112  _communicator.send(0, data.current);
113 
114  else if (processor_id() == 0)
115  for (auto & data : _sample_vectors)
116  _communicator.receive(_output_distributed_rank, data.current);
117  }
118 
119  for (auto & data : _sample_vectors)
120  {
121  data.vector->insert(data.vector->end(), data.current.begin(), data.current.end());
122  data.current.clear();
123  }
124 }

◆ init()

void StochasticResults::init ( Sampler &  _sampler)

DEPRECATED Initialize storage based on the Sampler returned by the SamplerTransientMultiApp or SamplerFullSolveMultiApp.

Parameters
samplerThe Sampler associated with the MultiApp that this VPP is working with.

This an internal method that is called by the SamplerPostprocessorTransfer, it should not be called otherwise.

Definition at line 141 of file StochasticResults.C.

142 {
143  if (!isParamValid("samplers"))
144  {
145  paramWarning("samplers",
146  "Support for the 'StochasticResults' objects without the 'samplers' input "
147  "parameter is being removed, please update your input file(s).");
148  _sample_vectors.emplace_back(sampler.name(), &declareVector(sampler.name()));
149  }
150 }

Referenced by SamplerPostprocessorTransfer::initialSetup().

◆ initialize()

void StochasticResults::initialize ( )
overridevirtual

Definition at line 91 of file StochasticResults.C.

92 {
93  // Clear any existing data, unless the complete history is desired
94  if (!containsCompleteHistory())
95  for (auto & data : _sample_vectors)
96  data.vector->clear();
97 }

◆ setCurrentLocalVectorPostprocessorValue()

void StochasticResults::setCurrentLocalVectorPostprocessorValue ( const std::string &  vector_name,
const VectorPostprocessorValue &&  current 
)

Definition at line 127 of file StochasticResults.C.

129 {
130  mooseAssert(!hasVectorPostprocessorByName(name),
131  "The supplied name must be a valid vector postprocessor name.");
132  auto data_ptr = std::find_if(_sample_vectors.begin(),
133  _sample_vectors.end(),
134  [&name](StochasticResultsData & data) { return data.name == name; });
135 
136  data_ptr->current = current;
137 }

Referenced by SamplerPostprocessorTransfer::execute(), and SamplerPostprocessorTransfer::finalizeFromMultiapp().

◆ validParams()

InputParameters StochasticResults::validParams ( )
static

Definition at line 27 of file StochasticResults.C.

28 {
29  InputParameters params = GeneralVectorPostprocessor::validParams();
30  params.addClassDescription(
31  "Storage container for stochastic simulation results coming from a Postprocessor.");
33 
34  params.addParam<std::vector<SamplerName>>("samplers",
35  "A list of sampler names of associated data.");
36 
37  MooseEnum parallel_type("REPLICATED DISTRIBUTED", "REPLICATED");
38  params.addParam<MooseEnum>(
39  "parallel_type",
40  parallel_type,
41  "Specify if the stored data vector is replicated or distributed across processors.");
42 
43  params.addParam<processor_id_type>(
44  "output_distributed_rank",
45  Moose::INVALID_PROCESSOR_ID,
46  "When 'parallel_type = DISTRIBUTED' set this to copy the data from the specified processor "
47  "for output. This is mainly for testing since the data from that rank will override the data "
48  "on the root process.");
49 
50  params.set<bool>("_is_broadcast") = false;
51  return params;
52 }

Member Data Documentation

◆ _output_distributed_rank

const processor_id_type StochasticResults::_output_distributed_rank
protected

The rank data to output if parallel type is distributed.

Definition at line 82 of file StochasticResults.h.

Referenced by finalize(), and StochasticResults().

◆ _parallel_type

const MooseEnum StochasticResults::_parallel_type
protected

Parallel operation mode.

Definition at line 79 of file StochasticResults.h.

Referenced by finalize(), and StochasticResults().

◆ _sample_vectors

std::vector<StochasticResultsData> StochasticResults::_sample_vectors
protected

Storage for declared vectors.

Definition at line 76 of file StochasticResults.h.

Referenced by finalize(), init(), initialize(), setCurrentLocalVectorPostprocessorValue(), and StochasticResults().


The documentation for this class was generated from the following files:
StochasticResults::_sample_vectors
std::vector< StochasticResultsData > _sample_vectors
Storage for declared vectors.
Definition: StochasticResults.h:76
StochasticResultsData
Storage helper for managing data being assigned to this VPP by a Transfer object.
Definition: StochasticResults.h:24
validParams
InputParameters validParams()
name
const std::string name
Definition: Setup.h:21
StochasticResults::_parallel_type
const MooseEnum _parallel_type
Parallel operation mode.
Definition: StochasticResults.h:79
StochasticResults::_output_distributed_rank
const processor_id_type _output_distributed_rank
The rank data to output if parallel type is distributed.
Definition: StochasticResults.h:82