https://mooseframework.inl.gov
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
SobolReporterContext< InType, OutType > Class Template Reference

#include <SobolReporter.h>

Inheritance diagram for SobolReporterContext< InType, OutType >:
[legend]

Public Types

enum  AutoOperation
 

Public Member Functions

 SobolReporterContext (const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< SobolState< OutType >> &state, const InType &data, const ReporterProducerEnum &mode, const SobolSampler &sampler)
 
 SobolReporterContext (const libMesh::ParallelObject &other, const MooseObject &producer, ReporterState< SobolState< OutType >> &state, const InType &data, const ReporterProducerEnum &mode, const SobolSampler &sampler, const MooseEnum &ci_method, const std::vector< Real > &ci_levels, unsigned int ci_replicates, unsigned int ci_seed)
 
virtual void finalize () override
 
virtual std::string type () const override
 
virtual void declareClone (ReporterData &r_data, const ReporterName &r_name, const ReporterMode &mode, const MooseObject &producer) const override
 
virtual void declareVectorClone (ReporterData &r_data, const ReporterName &r_name, const ReporterMode &mode, const MooseObject &producer) const override
 
virtual void resize (dof_id_type local_size) final
 
virtual void clear () final
 
virtual void vectorSum () final
 
virtual std::string contextType () const override
 
const ReporterNamename () const override final
 
const ReporterState< SobolState< OutType > > & state () const
 
virtual void transfer (ReporterData &r_data, const ReporterName &r_name, unsigned int time_index=0) const override
 
virtual void transferToVector (ReporterData &r_data, const ReporterName &r_name, dof_id_type index, unsigned int time_index=0) const override
 
virtual void transferFromVector (ReporterData &r_data, const ReporterName &r_name, dof_id_type index, unsigned int time_index=0) const override
 
void init (const ReporterMode &mode)
 
const MooseObjectgetProducer () const
 
const ReporterProducerEnumgetProducerModeEnum () const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static void storeSobol (nlohmann::json &json, const SobolState< OutType > &val, unsigned int nparam)
 

Protected Member Functions

virtual void store (nlohmann::json &json) const override
 
void broadcast ()
 
virtual void storeInfo (nlohmann::json &json) const override
 
virtual void copyValuesBack () override
 
virtual bool restoreState () override
 
void requiresConsumerModes (const ReporterStateBase &state, const std::set< ReporterMode > &modes) const
 

Protected Attributes

ReporterState< SobolState< OutType > > & _state
 
const MooseObject_producer
 
ReporterProducerEnum _producer_enum
 
const Parallel::Communicator & _communicator
 

Private Attributes

const InType & _data
 Data used for the statistic calculation. More...
 
const ReporterProducerEnum_data_mode
 Mode in which the above data was produced. More...
 
const SobolSampler_sampler
 Sobol sampler to get info on number of matrices and whatnot. More...
 
StochasticTools::SobolCalculator< InType, OutType > _calc
 Storage for the SobolCalculator object, this is created in constructor. More...
 
std::unique_ptr< StochasticTools::BootstrapCalculator< std::vector< InType >, std::vector< OutType > > > _ci_calc_ptr = nullptr
 Storage for the BootstrapCalculator for the desired confidence interval calculations (optional) More...
 

Detailed Description

template<typename InType, typename OutType>
class SobolReporterContext< InType, OutType >

Definition at line 18 of file SobolReporter.h.

Constructor & Destructor Documentation

◆ SobolReporterContext() [1/2]

template<typename InType , typename OutType >
SobolReporterContext< InType, OutType >::SobolReporterContext ( const libMesh::ParallelObject other,
const MooseObject producer,
ReporterState< SobolState< OutType >> &  state,
const InType &  data,
const ReporterProducerEnum mode,
const SobolSampler sampler 
)

Definition at line 169 of file SobolReporter.C.

177  _data(data),
178  _data_mode(mode),
179  _sampler(sampler),
180  _calc(other, "SOBOL", _sampler.resample())
181 {
182 }
bool resample() const
Resampling flag, see SobolStatistics.
Definition: SobolSampler.h:31
const ReporterState< SobolState< OutType > > & state() const
const SobolSampler & _sampler
Sobol sampler to get info on number of matrices and whatnot.
const InType & _data
Data used for the statistic calculation.
Definition: SobolReporter.h:99
const ReporterProducerEnum & _data_mode
Mode in which the above data was produced.
StochasticTools::SobolCalculator< InType, OutType > _calc
Storage for the SobolCalculator object, this is created in constructor.

◆ SobolReporterContext() [2/2]

template<typename InType , typename OutType >
SobolReporterContext< InType, OutType >::SobolReporterContext ( const libMesh::ParallelObject other,
const MooseObject producer,
ReporterState< SobolState< OutType >> &  state,
const InType &  data,
const ReporterProducerEnum mode,
const SobolSampler sampler,
const MooseEnum ci_method,
const std::vector< Real > &  ci_levels,
unsigned int  ci_replicates,
unsigned int  ci_seed 
)

Definition at line 185 of file SobolReporter.C.

196  : SobolReporterContext<InType, OutType>(other, producer, state, data, mode, sampler)
197 {
198  _ci_calc_ptr =
199  StochasticTools::makeBootstrapCalculator<std::vector<InType>, std::vector<OutType>>(
200  ci_method, other, ci_levels, ci_replicates, ci_seed, _calc);
201 }
const ReporterState< SobolState< OutType > > & state() const
std::unique_ptr< StochasticTools::BootstrapCalculator< std::vector< InType >, std::vector< OutType > > > _ci_calc_ptr
Storage for the BootstrapCalculator for the desired confidence interval calculations (optional) ...
StochasticTools::SobolCalculator< InType, OutType > _calc
Storage for the SobolCalculator object, this is created in constructor.

Member Function Documentation

◆ finalize()

template<typename InType , typename OutType >
void SobolReporterContext< InType, OutType >::finalize ( )
overridevirtual

Reimplemented from ReporterGeneralContext< SobolState< OutType > >.

Definition at line 205 of file SobolReporter.C.

206 {
207  auto & val = this->_state.value(); // Convenience
208  val.first.clear();
209  val.second.clear();
210 
211  const bool is_dist = _data_mode == REPORTER_MODE_DISTRIBUTED;
212  if (is_dist || this->processor_id() == 0)
213  {
214  const std::size_t ncol =
216  const std::vector<InType> data_reshape =
217  StochasticTools::reshapeVector(_data, ncol, /*row_major =*/true);
218 
219  val.first = _calc.compute(data_reshape, is_dist);
220  if (_ci_calc_ptr)
221  val.second = _ci_calc_ptr->compute(data_reshape, is_dist);
222  }
223 
225 }
std::vector< std::vector< T > > reshapeVector(const std::vector< T > &vec, std::size_t n, bool row_major)
Reshape a vector into matrix-like vector of vectors.
bool resample() const
Resampling flag, see SobolStatistics.
Definition: SobolSampler.h:31
std::unique_ptr< StochasticTools::BootstrapCalculator< std::vector< InType >, std::vector< OutType > > > _ci_calc_ptr
Storage for the BootstrapCalculator for the desired confidence interval calculations (optional) ...
ReporterState< SobolState< OutType > > & _state
const SobolSampler & _sampler
Sobol sampler to get info on number of matrices and whatnot.
virtual void finalize() override
const InType & _data
Data used for the statistic calculation.
Definition: SobolReporter.h:99
const ReporterMode REPORTER_MODE_DISTRIBUTED
const ReporterProducerEnum & _data_mode
Mode in which the above data was produced.
StochasticTools::SobolCalculator< InType, OutType > _calc
Storage for the SobolCalculator object, this is created in constructor.
T & value(const std::size_t time_index=0)
processor_id_type processor_id() const
dof_id_type getNumberOfCols() const

◆ store()

template<typename InType , typename OutType >
void SobolReporterContext< InType, OutType >::store ( nlohmann::json &  json) const
overrideprotectedvirtual

Reimplemented from ReporterGeneralContext< SobolState< OutType > >.

Definition at line 229 of file SobolReporter.C.

230 {
231  storeSobol(json, this->_state.value(), _sampler.getNumberOfCols());
232 }
ReporterState< SobolState< OutType > > & _state
const SobolSampler & _sampler
Sobol sampler to get info on number of matrices and whatnot.
static void storeSobol(nlohmann::json &json, const SobolState< OutType > &val, unsigned int nparam)
T & value(const std::size_t time_index=0)
dof_id_type getNumberOfCols() const

◆ storeSobol()

template<typename InType , typename OutType >
void SobolReporterContext< InType, OutType >::storeSobol ( nlohmann::json &  json,
const SobolState< OutType > &  val,
unsigned int  nparam 
)
static

Definition at line 236 of file SobolReporter.C.

239 {
240  if (val.first.empty())
241  return;
242 
243  // Convenience
244  const unsigned int nlevels = val.second.size();
245 
246  std::pair<std::vector<OutType>, std::vector<std::vector<OutType>>> first_order;
247  std::pair<std::vector<OutType>, std::vector<std::vector<OutType>>> total;
248 
249  first_order.first.assign(val.first.begin(), val.first.begin() + nparam);
250  total.first.assign(val.first.begin() + nparam, val.first.begin() + nparam + nparam);
251  if (nlevels > 0)
252  {
253  first_order.second.resize(nlevels);
254  total.second.resize(nlevels);
255  for (const auto & l : make_range(nlevels))
256  {
257  first_order.second[l].assign(val.second[l].begin(), val.second[l].begin() + nparam);
258  total.second[l].assign(val.second[l].begin() + nparam,
259  val.second[l].begin() + nparam + nparam);
260  }
261  }
262  json["FIRST_ORDER"] = first_order;
263  json["TOTAL"] = total;
264 
265  if (val.first.size() > 2 * nparam)
266  {
267  std::pair<std::vector<std::vector<OutType>>, std::vector<std::vector<std::vector<OutType>>>>
268  second_order;
269 
270  second_order.first.resize(nparam, std::vector<OutType>(nparam));
271  for (const auto & i : make_range(nparam))
272  second_order.first[i][i] = val.first[i];
273  unsigned int ind = 2 * nparam;
274  for (const auto & i : make_range(nparam))
275  for (const auto & j : make_range(i + 1, nparam))
276  {
277  second_order.first[i][j] = val.first[ind++];
278  second_order.first[j][i] = second_order.first[i][j];
279  }
280 
281  if (nlevels > 0)
282  {
283  second_order.second.resize(nlevels, second_order.first);
284 
285  for (const auto & l : make_range(nlevels))
286  {
287  for (const auto & i : make_range(nparam))
288  second_order.second[l][i][i] = val.second[l][i];
289  ind = 2 * nparam;
290  for (const auto & i : make_range(nparam))
291  for (const auto & j : make_range(i + 1, nparam))
292  {
293  second_order.second[l][i][j] = val.second[l][ind++];
294  second_order.second[l][j][i] = second_order.second[l][i][j];
295  }
296  }
297  }
298  json["SECOND_ORDER"] = second_order;
299  }
300 }
IntRange< T > make_range(T beg, T end)
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")

◆ type()

template<typename InType, typename OutType>
virtual std::string SobolReporterContext< InType, OutType >::type ( ) const
inlineoverridevirtual

Reimplemented from ReporterGeneralContext< SobolState< OutType > >.

Definition at line 87 of file SobolReporter.h.

88  {
89  return "SobolIndices<" + MooseUtils::prettyCppType<OutType>() + ">";
90  }

Member Data Documentation

◆ _calc

template<typename InType, typename OutType>
StochasticTools::SobolCalculator<InType, OutType> SobolReporterContext< InType, OutType >::_calc
private

Storage for the SobolCalculator object, this is created in constructor.

Definition at line 108 of file SobolReporter.h.

Referenced by SobolReporterContext< InType, OutType >::SobolReporterContext().

◆ _ci_calc_ptr

template<typename InType, typename OutType>
std::unique_ptr<StochasticTools::BootstrapCalculator<std::vector<InType>, std::vector<OutType> > > SobolReporterContext< InType, OutType >::_ci_calc_ptr = nullptr
private

Storage for the BootstrapCalculator for the desired confidence interval calculations (optional)

Definition at line 112 of file SobolReporter.h.

Referenced by SobolReporterContext< InType, OutType >::SobolReporterContext().

◆ _data

template<typename InType, typename OutType>
const InType& SobolReporterContext< InType, OutType >::_data
private

Data used for the statistic calculation.

Definition at line 99 of file SobolReporter.h.

◆ _data_mode

template<typename InType, typename OutType>
const ReporterProducerEnum& SobolReporterContext< InType, OutType >::_data_mode
private

Mode in which the above data was produced.

Definition at line 102 of file SobolReporter.h.

◆ _sampler

template<typename InType, typename OutType>
const SobolSampler& SobolReporterContext< InType, OutType >::_sampler
private

Sobol sampler to get info on number of matrices and whatnot.

Definition at line 105 of file SobolReporter.h.


The documentation for this class was generated from the following files: