https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SamplerInterface.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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
17class Sampler;
29{
30public:
32
39 SamplerInterface(const MooseObject * moose_object);
40
41#ifdef MOOSE_KOKKOS_ENABLED
46#endif
47
53 template <typename T = Sampler>
54 T & getSampler(const std::string & name);
55
61 template <typename T = Sampler>
62 T & getSamplerByName(const SamplerName & name);
63
64private:
67
70
73};
74
75template <typename T>
76T &
77SamplerInterface::getSampler(const std::string & name)
78{
79 return getSamplerByName<T>(_si_params.get<SamplerName>(name));
80}
81
82template <typename T>
83T &
84SamplerInterface::getSamplerByName(const SamplerName & name)
85{
86 Sampler * base_ptr = &_si_feproblem.getSampler(name, _si_tid);
87 T * obj_ptr = dynamic_cast<T *>(base_ptr);
88 if (!obj_ptr)
89 mooseError("Failed to find a Sampler object with the name '", name, "' for the desired type.");
90 return *obj_ptr;
91}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
unsigned int THREAD_ID
Definition MooseTypes.h:237
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual Sampler & getSampler(const std::string &name, const THREAD_ID tid=0)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
Interface for objects that need to use samplers.
static InputParameters validParams()
T & getSamplerByName(const SamplerName &name)
Get a sampler with a given name.
T & getSampler(const std::string &name)
Get a sampler with a given name.
const InputParameters & _si_params
Parameters of the object with this interface.
FEProblemBase & _si_feproblem
Reference to FEProblemBase instance.
THREAD_ID _si_tid
Thread ID.
This is the base class for Samplers as used within the Stochastic Tools module.
Definition Sampler.h:52