www.mooseframework.org
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
SamplerInterface Class Reference

Interface for objects that need to use samplers. More...

#include <SamplerInterface.h>

Inheritance diagram for SamplerInterface:
[legend]

Public Member Functions

 SamplerInterface (const MooseObject *moose_object)
 
template<typename T = Sampler>
T & getSampler (const std::string &name)
 Get a sampler with a given name. More...
 
template<typename T = Sampler>
T & getSamplerByName (const SamplerName &name)
 Get a sampler with a given name. More...
 
template<>
SamplergetSampler (const std::string &name)
 
template<>
SamplergetSamplerByName (const SamplerName &name)
 

Static Public Member Functions

static InputParameters validParams ()
 

Private Attributes

const InputParameters_si_params
 Parameters of the object with this interface. More...
 
FEProblemBase_si_feproblem
 Reference to FEProblemBase instance. More...
 
THREAD_ID _si_tid
 Thread ID. More...
 

Detailed Description

Interface for objects that need to use samplers.

This practically adds two methods for getting Sampler objects:

  1. Call getSampler or getSamplerByName without a template parameter and you will get a Sampler base object (see SamplerInterface.C for the template specialization).
  2. Call getSampler<MySampler> or getSamplerByName<MySampler> to perform a cast to the desired type, as done for UserObjects.

Definition at line 28 of file SamplerInterface.h.

Constructor & Destructor Documentation

◆ SamplerInterface()

SamplerInterface::SamplerInterface ( const MooseObject moose_object)
Parameters
paramsThe parameters used by the object being instantiated. This class needs them so it can get the sampler named in the input file, but the object calling getSampler only needs to use the name on the left hand side of the statement "sampler = sampler_name"

Definition at line 21 of file SamplerInterface.C.

22  : _si_params(moose_object->parameters()),
23  _si_feproblem(*_si_params.get<FEProblemBase *>("_fe_problem_base")),
25 {
26 }
FEProblemBase & _si_feproblem
Reference to FEProblemBase instance.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
bool have_parameter(std::string_view name) const
A wrapper around the Parameters base class method.
const InputParameters & _si_params
Parameters of the object with this interface.
const InputParameters & parameters() const
Get the parameters of the object.
THREAD_ID _si_tid
Thread ID.
unsigned int THREAD_ID
Definition: MooseTypes.h:198

Member Function Documentation

◆ getSampler() [1/2]

template<>
Sampler& SamplerInterface::getSampler ( const std::string &  name)

Definition at line 30 of file SamplerInterface.C.

31 {
32  return _si_feproblem.getSampler(_si_params.get<SamplerName>(name));
33 }
FEProblemBase & _si_feproblem
Reference to FEProblemBase instance.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
const InputParameters & _si_params
Parameters of the object with this interface.
virtual Sampler & getSampler(const std::string &name, const THREAD_ID tid=0)

◆ getSampler() [2/2]

template<typename T >
T & SamplerInterface::getSampler ( const std::string &  name)

Get a sampler with a given name.

Parameters
nameThe name of the parameter key of the sampler to retrieve
Returns
The sampler with name associated with the parameter 'name'

Definition at line 70 of file SamplerInterface.h.

71 {
72  return getSamplerByName<T>(_si_params.get<SamplerName>(name));
73 }
std::string name(const ElemQuality q)
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
const InputParameters & _si_params
Parameters of the object with this interface.

◆ getSamplerByName() [1/2]

template<>
Sampler& SamplerInterface::getSamplerByName ( const SamplerName &  name)

Definition at line 37 of file SamplerInterface.C.

38 {
39  return _si_feproblem.getSampler(name, _si_tid);
40 }
FEProblemBase & _si_feproblem
Reference to FEProblemBase instance.
THREAD_ID _si_tid
Thread ID.
virtual Sampler & getSampler(const std::string &name, const THREAD_ID tid=0)

◆ getSamplerByName() [2/2]

template<typename T >
T & SamplerInterface::getSamplerByName ( const SamplerName &  name)

Get a sampler with a given name.

Parameters
nameThe name of the sampler to retrieve
Returns
The sampler with name 'name'

Definition at line 77 of file SamplerInterface.h.

78 {
79  Sampler * base_ptr = &_si_feproblem.getSampler(name, _si_tid);
80  T * obj_ptr = dynamic_cast<T *>(base_ptr);
81  if (!obj_ptr)
82  mooseError("Failed to find a Sampler object with the name '", name, "' for the desired type.");
83  return *obj_ptr;
84 }
FEProblemBase & _si_feproblem
Reference to FEProblemBase instance.
This is the base class for Samplers as used within the Stochastic Tools module.
Definition: Sampler.h:43
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
THREAD_ID _si_tid
Thread ID.
virtual Sampler & getSampler(const std::string &name, const THREAD_ID tid=0)

◆ validParams()

InputParameters SamplerInterface::validParams ( )
static

Definition at line 16 of file SamplerInterface.C.

17 {
18  return emptyInputParameters();
19 }
InputParameters emptyInputParameters()

Member Data Documentation

◆ _si_feproblem

FEProblemBase& SamplerInterface::_si_feproblem
private

Reference to FEProblemBase instance.

Definition at line 62 of file SamplerInterface.h.

Referenced by getSampler(), and getSamplerByName().

◆ _si_params

const InputParameters& SamplerInterface::_si_params
private

Parameters of the object with this interface.

Definition at line 59 of file SamplerInterface.h.

Referenced by getSampler().

◆ _si_tid

THREAD_ID SamplerInterface::_si_tid
private

Thread ID.

Definition at line 65 of file SamplerInterface.h.

Referenced by getSamplerByName().


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