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

#include <Calculators.h>

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

Public Member Functions

OutType compute (const 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 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...
 
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 update (const typename InType::value_type &val) override
 Updating the calculator with a piece of data. More...
 
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 finalize (bool is_distributed) override
 This is used to compute the resulting calculator value by performing necessary arithmetic and parallel communication. More...
 
virtual OutType get () const override
 Returns the resulting calculator value. More...
 

Protected Attributes

dof_id_type _count
 
OutType _sum
 
const Parallel::Communicator & _communicator
 

Detailed Description

template<typename InType, typename OutType>
class StochasticTools::MeanAbsoluteValue< InType, OutType >

Definition at line 153 of file Calculators.h.

Member Function Documentation

◆ compute()

template<typename InType, typename OutType >
OutType StochasticTools::Calculator< InType, OutType >::compute ( const 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.

289 {
291  for (const auto & val : data)
292  updateCalculator(val);
293  finalizeCalculator(is_distributed);
294  return getValue();
295 }
void updateCalculator(const typename 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
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 >
void StochasticTools::Mean< InType, OutType >::finalize ( bool  )
overrideprotectedvirtualinherited

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< InType, OutType >.

Reimplemented in StochasticTools::Sum< InType, OutType >.

Definition at line 41 of file Calculators.C.

42 {
43  if (is_distributed)
44  {
45  this->_communicator.sum(_count);
46  this->_communicator.sum(_sum);
47  }
48  if (_count > 0)
49  _sum /= static_cast<OutType>(_count);
50 }
const Parallel::Communicator & _communicator

◆ finalizeCalculator()

template<typename InType , typename OutType >
void StochasticTools::Calculator< InType, 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 >
virtual OutType StochasticTools::Mean< InType, OutType >::get ( ) const
inlineoverrideprotectedvirtualinherited

Returns the resulting calculator value.

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

Implements StochasticTools::Calculator< InType, OutType >.

Definition at line 146 of file Calculators.h.

146 { return _sum; }

◆ getValue()

template<typename InType , typename OutType >
OutType StochasticTools::Calculator< InType, 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 >
void StochasticTools::Mean< InType, OutType >::initialize ( )
overrideprotectedvirtualinherited

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< InType, OutType >.

Definition at line 25 of file Calculators.C.

26 {
27  _count = 0;
28  _sum = OutType();
29 }

◆ initializeCalculator()

template<typename InType , typename OutType >
void StochasticTools::Calculator< InType, 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.

Referenced by StochasticTools::SobolCalculator< std::vector< InType >, std::vector< OutType > >::finalize(), and StochasticTools::SobolCalculator< std::vector< InType >, std::vector< OutType > >::update().

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()

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

Definition at line 99 of file Calculators.h.

99 { return _name; }
const std::string _name
Definition: Calculators.h:132

◆ update()

template<typename InType , typename OutType >
void StochasticTools::MeanAbsoluteValue< InType, OutType >::update ( const typename InType::value_type &  )
overrideprotectedvirtual

Updating the calculator with a piece of data.

Sometimes some clever arithmetic is required to avoid storing data.

Reimplemented from StochasticTools::Mean< InType, OutType >.

Definition at line 55 of file Calculators.C.

56 {
57  Mean<InType, OutType>::update(std::abs(val));
58 }
virtual void update(const typename InType::value_type &val) override
Updating the calculator with a piece of data.
Definition: Calculators.C:33

◆ updateCalculator()

template<typename InType, typename OutType >
void StochasticTools::Calculator< InType, OutType >::updateCalculator ( const typename 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 InType::value_type &)=0
Updating the calculator with a piece of data.

Member Data Documentation

◆ _count

template<typename InType , typename OutType >
dof_id_type StochasticTools::Mean< InType, OutType >::_count
protectedinherited

Definition at line 148 of file Calculators.h.

◆ _sum

template<typename InType , typename OutType >
OutType StochasticTools::Mean< InType, OutType >::_sum
protectedinherited

Definition at line 149 of file Calculators.h.

Referenced by StochasticTools::Mean< InType, OutType >::get().


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