50 std::string prefix =
"")
override;
124 params.
addRequiredParam<SamplerName>(
"sampler",
"The sampler used to produce data.");
131 _sampler(this->template getSampler<
Sampler>(
"sampler")),
132 _need_sample(this->template declareStochasticReporter<bool>(
"need_sample", _sampler))
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));
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};
void mooseError(Args &&... args)
This is a base class for performing active learning routines, meant to be used in conjunction with Sa...
const std::vector< std::vector< Real > > & getGlobalInputData() const
const Sampler & sampler() const
Get a const reference to the sampler from the parameters.
static InputParameters validParams()
virtual void execute() override
Here we loop through the samples and call the needSample function to determine if the sample needs to...
bool _output_data_requested
Whether or not to gather global output data.
ActiveLearningReporterTempl(const InputParameters ¶meters)
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...
std::vector< T > _output_data
Global output data from sampler.
bool _input_data_requested
Whether or not to gather global input data.
std::vector< bool > & _need_sample
Reporter value determining whether we need to evaluate the sample through a multiapp or other means.
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 void preNeedSample()
Optional virtual function that is called before the sampler loop calling needSample.
const std::vector< T > & getGlobalOutputData() const
Get a const reference to the output data.
Sampler & _sampler
Sampler given in the parameters, must match the one used to declare the transferred values.
std::vector< std::vector< Real > > _input_data
Global input data from sampler.
std::vector< T > * _data
Reporter value declared with the transfer.
const InputParameters & parameters() const
const std::string & name() const
bool hasReporterValue(const ReporterName &reporter_name) const
const std::string & getObjectName() const
const std::string & getValueName() const
static InputParameters validParams()