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 "FEProblemBase.h"
15 
16 // Forward declarations
17 class Distribution;
19 
20 template <>
22 
30 {
31 public:
38  DistributionInterface(const MooseObject * moose_object);
39 
41 
46  const Distribution & getDistribution(const std::string & name) const;
47 
48  template <typename T>
49  const T & getDistribution(const std::string & name) const;
51 
53 
58  const Distribution & getDistributionByName(const DistributionName & name) const;
59 
60  template <typename T>
61  const T & getDistributionByName(const std::string & name) const;
63 
64 private:
67 
70 
73 };
74 
75 template <typename T>
76 const T &
77 DistributionInterface::getDistribution(const std::string & name) const
78 {
79  try
80  {
81  const T & dist = dynamic_cast<const T &>(getDistribution(name));
82  return dist;
83  }
84  catch (std::bad_cast & exception)
85  {
86  DistributionName dist_name = _dni_params.get<DistributionName>(name);
87  mooseError("The '",
89  "' object failed to retrieve '",
90  dist_name,
91  "' distribution with the desired type.");
92  }
93 }
94 
95 template <typename T>
96 const T &
97 DistributionInterface::getDistributionByName(const std::string & name) const
98 {
99  try
100  {
101  const T & dist = dynamic_cast<const T &>(getDistribution(name));
102  return dist;
103  }
104  catch (std::bad_cast & exception)
105  {
106  mooseError("The '",
108  "' object failed to retrieve '",
109  name,
110  "' distribution with the desired type.");
111  }
112 }
113 
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:207
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:22
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:42
Interface for objects that need to use distributions.
InputParameters validParams< DistributionInterface >()
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 std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
const InputParameters & _dni_params
Parameters of the object with this interface.
const MooseObject * _dni_moose_object_ptr
Pointer to the MooseObject.