https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
StochasticTools::VectorCalculator< InType, OutType, CalcType > Class Template Referenceabstract

#include <VectorCalculators.h>

Inheritance diagram for StochasticTools::VectorCalculator< InType, OutType, CalcType >:
[legend]

Public Member Functions

std::vector< OutType > compute (const std::vector< InType > &, bool)
 Evaluate the calculator on the full vector of data. More...
 
void initializeCalculator ()
 Public function that must be called before updateCalculator and finalizeCalculator. More...
 
void updateCalculator (const typename std::vector< InType > ::value_type &)
 Public function to update calculator with a piece of data. More...
 
void finalizeCalculator (bool)
 Public function to finalize the resulting calculator value. More...
 
std::vector< OutType > getValue () const
 Public function to return the calculated value _state must be FINALIZED. More...
 
const std::string & name () const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Protected Member Functions

virtual void initialize () override
 This function is used to reset the calculator to its initial state and prepare it for another evaluation. More...
 
virtual void update (const InType &data) override
 
virtual void finalize (bool is_distributed) override
 This is used to compute the resulting calculator value by performing necessary arithmetic and parallel communication. More...
 
virtual std::vector< OutType > get () const override
 Returns the resulting calculator value. More...
 
virtual void update (const typename std::vector< InType > ::value_type &)=0
 Updating the calculator with a piece of data. More...
 

Protected Attributes

const Parallel::Communicator & _communicator
 

Private Attributes

std::vector< CalcType< InType, OutType > > _calcs
 
std::vector< OutType > _values
 

Detailed Description

template<typename InType, typename OutType, template< typename, typename > class CalcType>
class StochasticTools::VectorCalculator< InType, OutType, CalcType >

Definition at line 18 of file VectorCalculators.h.

Member Function Documentation

◆ compute()

std::vector< OutType > StochasticTools::Calculator< std::vector< InType > , std::vector< OutType > >::compute ( const std::vector< InType > &  data,
bool  is_distributed 
)
inherited

Evaluate the calculator on the full vector of data.

This is basically a convenient wrapper around initializeCalculator, updateCalculator, finalizeCalculator, and getvalue.

Definition at line 288 of file Calculators.h.

Referenced by SobolStatistics::execute(), and TEST().

289 {
291  for (const auto & val : data)
292  updateCalculator(val);
293  finalizeCalculator(is_distributed);
294  return getValue();
295 }
void updateCalculator(const typename std::vector< InType > ::value_type &)
Public function to update calculator with a piece of data.
Definition: Calculators.h:307
void initializeCalculator()
Public function that must be called before updateCalculator and finalizeCalculator.
Definition: Calculators.h:299
std::vector< OutType > getValue() const
Public function to return the calculated value _state must be FINALIZED.
Definition: Calculators.h:325
void finalizeCalculator(bool)
Public function to finalize the resulting calculator value.
Definition: Calculators.h:315

◆ finalize()

template<typename InType , typename OutType , template< typename, typename > class CalcType>
void StochasticTools::VectorCalculator< InType, OutType, CalcType >::finalize ( bool  )
overrideprotectedvirtual

This is used to compute the resulting calculator value by performing necessary arithmetic and parallel communication.

This only called once after all the input data is entered through update.

Implements StochasticTools::Calculator< std::vector< InType >, std::vector< OutType > >.

Definition at line 59 of file VectorCalculators.h.

60 {
61  // Need to make calculator objects if some data added
62  if (is_distributed)
63  {
64  auto ncalc = _calcs.size();
65  this->_communicator.max(ncalc);
66  for (const auto & i : make_range(_calcs.size(), ncalc))
67  {
68  _calcs.emplace_back(*this, this->name() + "_" + std::to_string(i));
69  _calcs.back().initializeCalculator();
70  }
71  }
72 
73  _values.reserve(_calcs.size());
74  for (auto & cc : _calcs)
75  {
76  cc.finalizeCalculator(is_distributed);
77  _values.push_back(cc.getValue());
78  }
79 }
const Parallel::Communicator & _communicator
void max(const T &r, T &o, Request &req) const
IntRange< T > make_range(T beg, T end)
std::vector< CalcType< InType, OutType > > _calcs

◆ finalizeCalculator()

void StochasticTools::Calculator< std::vector< InType > , std::vector< OutType > >::finalizeCalculator ( bool  is_distributed)
inherited

Public function to finalize the resulting calculator value.

_state must be INITLIALIZED Sets _state to FINALIZED

Definition at line 315 of file Calculators.h.

316 {
317  if (_state != CalculatorState::INITIALIZED)
318  ::mooseError("Calculator is in wrong state.");
319  finalize(is_distributed);
320  _state = CalculatorState::FINALIZED;
321 }
virtual void finalize(bool)=0
This is used to compute the resulting calculator value by performing necessary arithmetic and paralle...

◆ get()

template<typename InType , typename OutType , template< typename, typename > class CalcType>
virtual std::vector<OutType> StochasticTools::VectorCalculator< InType, OutType, CalcType >::get ( ) const
inlineoverrideprotectedvirtual

Returns the resulting calculator value.

It is important to not modify member data here so the calculator can retain its state.

Implements StochasticTools::Calculator< std::vector< InType >, std::vector< OutType > >.

Definition at line 27 of file VectorCalculators.h.

27 { return _values; }

◆ getValue()

std::vector< OutType > StochasticTools::Calculator< std::vector< InType > , std::vector< OutType > >::getValue ( ) const
inherited

Public function to return the calculated value _state must be FINALIZED.

Definition at line 325 of file Calculators.h.

326 {
327  if (_state != CalculatorState::FINALIZED)
328  ::mooseError("Calculator is in wrong state.");
329  return get();
330 }

◆ initialize()

template<typename InType , typename OutType , template< typename, typename > class CalcType>
void StochasticTools::VectorCalculator< InType, OutType, CalcType >::initialize ( )
overrideprotectedvirtual

This function is used to reset the calculator to its initial state and prepare it for another evaluation.

This usually involves clearing class members.

Implements StochasticTools::Calculator< std::vector< InType >, std::vector< OutType > >.

Definition at line 36 of file VectorCalculators.h.

37 {
38  _calcs.clear();
39  _values.clear();
40 }
std::vector< CalcType< InType, OutType > > _calcs

◆ initializeCalculator()

void StochasticTools::Calculator< std::vector< InType > , std::vector< OutType > >::initializeCalculator ( )
inherited

Public function that must be called before updateCalculator and finalizeCalculator.

Sets _state to INITIALIZED

Definition at line 299 of file Calculators.h.

300 {
301  initialize();
302  _state = CalculatorState::INITIALIZED;
303 }
virtual void initialize()=0
This function is used to reset the calculator to its initial state and prepare it for another evaluat...

◆ name()

const std::string& StochasticTools::Calculator< std::vector< InType > , std::vector< OutType > >::name ( ) const
inlineinherited

Definition at line 99 of file Calculators.h.

◆ update() [1/2]

template<typename InType , typename OutType , template< typename, typename > class CalcType>
void StochasticTools::VectorCalculator< InType, OutType, CalcType >::update ( const InType &  data)
overrideprotectedvirtual

Definition at line 44 of file VectorCalculators.h.

45 {
46  for (const auto & i : index_range(data))
47  {
48  if (i >= _calcs.size())
49  {
50  _calcs.emplace_back(*this, this->name() + "_" + std::to_string(i));
51  _calcs.back().initializeCalculator();
52  }
53  _calcs[i].updateCalculator(data[i]);
54  }
55 }
std::vector< CalcType< InType, OutType > > _calcs
auto index_range(const T &sizable)

◆ update() [2/2]

virtual void StochasticTools::Calculator< std::vector< InType > , std::vector< OutType > >::update ( const typename std::vector< InType > ::value_type &  )
protectedpure virtualinherited

Updating the calculator with a piece of data.

Sometimes some clever arithmetic is required to avoid storing data.

◆ updateCalculator()

void StochasticTools::Calculator< std::vector< InType > , std::vector< OutType > >::updateCalculator ( const typename std::vector< InType > ::value_type &  val)
inherited

Public function to update calculator with a piece of data.

_state mush be INITIALIZED

Definition at line 307 of file Calculators.h.

308 {
309  mooseAssert(_state == CalculatorState::INITIALIZED, "Calculator is in wrong state.");
310  update(val);
311 }
virtual void update(const typename std::vector< InType > ::value_type &)=0
Updating the calculator with a piece of data.

Member Data Documentation

◆ _calcs

template<typename InType , typename OutType , template< typename, typename > class CalcType>
std::vector<CalcType<InType, OutType> > StochasticTools::VectorCalculator< InType, OutType, CalcType >::_calcs
private

Definition at line 30 of file VectorCalculators.h.

◆ _values

template<typename InType , typename OutType , template< typename, typename > class CalcType>
std::vector<OutType> StochasticTools::VectorCalculator< InType, OutType, CalcType >::_values
private

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