35 virtual void execute()
override;
50 std::string prefix =
"")
override;
119 template <
typename T>
124 params.
addRequiredParam<SamplerName>(
"sampler",
"The sampler used to produce data.");
128 template <
typename T>
131 _sampler(this->template getSampler<
Sampler>(
"sampler")),
132 _need_sample(this->template declareStochasticReporter<bool>(
"need_sample", _sampler))
136 template <
typename T>
141 if (_input_data_requested)
144 _input_data.assign(_sampler.getNumberOfRows(),
145 std::vector<Real>(_sampler.getNumberOfCols(), 0.0));
146 for (
dof_id_type i = _sampler.getLocalRowBegin(); i < _sampler.getLocalRowEnd(); ++i)
147 _input_data[i] = _sampler.getNextLocalRow();
148 for (
auto & inp : _input_data)
151 if (_output_data_requested)
154 mooseError(
"Output data has been requested, but none was declared in this object.");
155 _output_data = *_data;
156 _communicator.allgather(_output_data);
167 for (
const auto & i :
make_range(_sampler.getNumberOfLocalRows()))
168 _need_sample[i] = needSample(_sampler.getNextLocalRow(),
170 i + _sampler.getLocalRowBegin(),
171 (_data ? (*_data)[i] : dummy));
174 template <
typename T>
183 this->
mooseError(type(),
" can only declare a single reporter value.");
185 else if (sampler.
name() != _sampler.name())
186 this->paramError(
"sampler",
187 "Inputted sampler, ",
189 ", is not the same as the one producing data, ",
194 this->
mooseError(
"Reporter value ", from_reporter,
" has not been declared.");
198 type(),
" can only use reporter values of type ", MooseUtils::prettyCppType<T>(),
".");
200 std::string value_name = (prefix.empty() ?
"" : prefix +
":") + from_reporter.
getObjectName() +
202 _data = &this->declareStochasticReporter<T>(value_name, sampler);
203 return {
name(), value_name};
const Sampler & sampler() const
Get a const reference to the sampler from the parameters.
virtual ReporterName declareStochasticReporterClone(const Sampler &sampler, const ReporterData &from_data, const ReporterName &from_reporter, std::string prefix="") override
This is overriden for the following reasons: 1) Only one vector can be declared and must match the ty...
const std::vector< T > & getGlobalOutputData() const
Get a const reference to the output data.
static InputParameters validParams()
void mooseError(Args &&... args)
virtual void preNeedSample()
Optional virtual function that is called before the sampler loop calling needSample.
virtual void execute() override
Here we loop through the samples and call the needSample function to determine if the sample needs to...
virtual bool needSample(const std::vector< Real > &, dof_id_type, dof_id_type, T &)
This routine is called during the sampler loop in execute() and is meant to fill in the "need_sample"...
virtual const std::string & name() const
std::vector< T > * _data
Reporter value declared with the transfer.
bool _output_data_requested
Whether or not to gather global output data.
const std::vector< std::vector< Real > > & getGlobalInputData() const
std::vector< T > _output_data
Global output data from sampler.
std::vector< bool > & _need_sample
Reporter value determining whether we need to evaluate the sample through a multiapp or other means...
const std::string & getObjectName() const
bool _input_data_requested
Whether or not to gather global input data.
std::vector< std::vector< Real > > _input_data
Global input data from sampler.
ActiveLearningReporterTempl(const InputParameters ¶meters)
static InputParameters validParams()
IntRange< T > make_range(T beg, T end)
const InputParameters & parameters() const
bool hasReporterValue(const ReporterName &reporter_name) const
const std::string & getValueName() const
Sampler & _sampler
Sampler given in the parameters, must match the one used to declare the transferred values...
This is a base class for performing active learning routines, meant to be used in conjunction with Sa...