www.mooseframework.org
SamplerInterface.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "ParallelUniqueId.h"
13 #include "InputParameters.h"
14 #include "FEProblemBase.h"
15 
16 // Forward declarations
17 class Sampler;
29 {
30 public:
32 
39  SamplerInterface(const MooseObject * moose_object);
40 
46  template <typename T = Sampler>
47  T & getSampler(const std::string & name);
48 
54  template <typename T = Sampler>
55  T & getSamplerByName(const SamplerName & name);
56 
57 private:
60 
63 
66 };
67 
68 template <typename T>
69 T &
70 SamplerInterface::getSampler(const std::string & name)
71 {
72  return getSamplerByName<T>(_si_params.get<SamplerName>(name));
73 }
74 
75 template <typename T>
76 T &
77 SamplerInterface::getSamplerByName(const SamplerName & name)
78 {
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 }
std::string name(const ElemQuality q)
FEProblemBase & _si_feproblem
Reference to FEProblemBase instance.
T & getSamplerByName(const SamplerName &name)
Get a sampler with a given name.
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:284
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.
static InputParameters validParams()
Interface for objects that need to use samplers.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:33
const InputParameters & _si_params
Parameters of the object with this interface.
T & getSampler(const std::string &name)
Get a sampler with a given name.
SamplerInterface(const MooseObject *moose_object)
THREAD_ID _si_tid
Thread ID.
virtual Sampler & getSampler(const std::string &name, const THREAD_ID tid=0)
unsigned int THREAD_ID
Definition: MooseTypes.h:198