www.mooseframework.org
DistributionInterface.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 "InputParameters.h"
13 #include "ParallelUniqueId.h"
14 #include "MooseObject.h"
15 
16 // Forward declarations
17 class Distribution;
18 class FEProblemBase;
19 
26 {
27 public:
29 
30  DistributionInterface(const MooseObject * moose_object);
31 
33 
38  const Distribution & getDistribution(const std::string & name) const;
39 
40  template <typename T>
41  const T & getDistribution(const std::string & name) const;
43 
45 
50  const Distribution & getDistributionByName(const DistributionName & name) const;
51 
52  template <typename T>
53  const T & getDistributionByName(const std::string & name) const;
55 
56 private:
59 
62 
65 };
66 
67 template <typename T>
68 const T &
69 DistributionInterface::getDistribution(const std::string & name) const
70 {
71  try
72  {
73  const T & dist = dynamic_cast<const T &>(getDistribution(name));
74  return dist;
75  }
76  catch (std::bad_cast & exception)
77  {
78  DistributionName dist_name = _dni_params.get<DistributionName>(name);
79  mooseError("The '",
81  "' object failed to retrieve '",
82  dist_name,
83  "' distribution with the desired type.");
84  }
85 }
86 
87 template <typename T>
88 const T &
89 DistributionInterface::getDistributionByName(const std::string & name) const
90 {
91  try
92  {
93  const T & dist = dynamic_cast<const T &>(getDistribution(name));
94  return dist;
95  }
96  catch (std::bad_cast & exception)
97  {
98  mooseError("The '",
100  "' object failed to retrieve '",
101  name,
102  "' distribution with the desired type.");
103  }
104 }
std::string name(const ElemQuality q)
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.
DistributionInterface(const MooseObject *moose_object)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
All Distributions should inherit from this class.
Definition: Distribution.h:18
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
static InputParameters validParams()
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:33
Interface for objects that need to use distributions.
const Distribution & getDistributionByName(const DistributionName &name) const
Get a distribution with a given name.
FEProblemBase & _dni_feproblem
Reference to FEProblemBase instance.
const Distribution & getDistribution(const std::string &name) const
Get a distribution with a given name.
const InputParameters & _dni_params
Parameters of the object with this interface.
const MooseObject *const _dni_moose_object_ptr
Pointer to the MooseObject.