www.mooseframework.org
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
NaNInterface Class Reference

Interface class for producing errors, warnings, or just quiet NaNs. More...

#include <NaNInterface.h>

Inheritance diagram for NaNInterface:
[legend]

Public Member Functions

 NaNInterface (const MooseObject *moose_object)
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Types

enum  NaNMessage { NAN_MESSAGE_NONE = 0, NAN_MESSAGE_WARNING = 1, NAN_MESSAGE_ERROR = 2 }
 

Protected Member Functions

Real getNaN () const
 Throws an error or returns a NaN with or without a warning, with a default message. More...
 
std::vector< RealgetNaNVector (const unsigned int &n) const
 Throws an error or returns NaNs with or without a warning, with a default message. More...
 
template<typename... Args>
Real getNaN (Args &&... args) const
 Throws an error or returns a NaN with or without a warning. More...
 
template<typename... Args>
std::vector< RealgetNaNVector (const unsigned int &n, Args &&... args) const
 Throws an error or returns NaNs with or without a warning. More...
 

Protected Attributes

const MooseObject *const _moose_object
 
enum NaNMessage _emit_on_nan
 Raise mooseWarning or mooseError? More...
 

Detailed Description

Interface class for producing errors, warnings, or just quiet NaNs.

For some objects it is desirable to continue running despite generation of NaN(s). This class provides an interface for choosing whether to throw an error, a warning, or nothing at all, just using a quiet NaN.

Definition at line 22 of file NaNInterface.h.

Member Enumeration Documentation

◆ NaNMessage

enum NaNInterface::NaNMessage
protected
Enumerator
NAN_MESSAGE_NONE 
NAN_MESSAGE_WARNING 
NAN_MESSAGE_ERROR 

Definition at line 30 of file NaNInterface.h.

Constructor & Destructor Documentation

◆ NaNInterface()

NaNInterface::NaNInterface ( const MooseObject moose_object)

Definition at line 32 of file NaNInterface.C.

33  : _moose_object(moose_object),
36 {
37 }
T getEnum() const
const T & getParam(const std::string &name) const
enum NaNMessage _emit_on_nan
Raise mooseWarning or mooseError?
Definition: NaNInterface.h:40
const MooseObject *const _moose_object
Definition: NaNInterface.h:37

Member Function Documentation

◆ getNaN() [1/2]

Real NaNInterface::getNaN ( ) const
inlineprotected

◆ getNaN() [2/2]

template<typename... Args>
Real NaNInterface::getNaN ( Args &&...  args) const
inlineprotected

Throws an error or returns a NaN with or without a warning.

Definition at line 61 of file NaNInterface.h.

62  {
63  switch (_emit_on_nan)
64  {
65  case (NAN_MESSAGE_WARNING):
66  mooseWarning(_moose_object->name(), ": ", std::forward<Args>(args)...);
67  break;
68  case (NAN_MESSAGE_ERROR):
69  mooseError(_moose_object->name(), ": ", std::forward<Args>(args)...);
70  break;
71  default:
72  break;
73  }
74  // return a quiet NaN
75  return std::nan("");
76  }
void mooseError(Args &&... args)
void mooseWarning(Args &&... args)
virtual const std::string & name() const
enum NaNMessage _emit_on_nan
Raise mooseWarning or mooseError?
Definition: NaNInterface.h:40
const MooseObject *const _moose_object
Definition: NaNInterface.h:37

◆ getNaNVector() [1/2]

std::vector<Real> NaNInterface::getNaNVector ( const unsigned int n) const
inlineprotected

Throws an error or returns NaNs with or without a warning, with a default message.

Parameters
[in]nVector size

Definition at line 52 of file NaNInterface.h.

Referenced by NaNInterfaceTestFluidProperties::returnNaNVector().

53  {
54  return getNaNVector(n, "A NaN was produced.");
55  }
std::vector< Real > getNaNVector(const unsigned int &n) const
Throws an error or returns NaNs with or without a warning, with a default message.
Definition: NaNInterface.h:52

◆ getNaNVector() [2/2]

template<typename... Args>
std::vector<Real> NaNInterface::getNaNVector ( const unsigned int n,
Args &&...  args 
) const
inlineprotected

Throws an error or returns NaNs with or without a warning.

Parameters
[in]nVector size

Definition at line 84 of file NaNInterface.h.

85  {
86  switch (_emit_on_nan)
87  {
88  case (NAN_MESSAGE_WARNING):
89  mooseWarning(_moose_object->name(), ": ", std::forward<Args>(args)...);
90  break;
91  case (NAN_MESSAGE_ERROR):
92  mooseError(_moose_object->name(), ": ", std::forward<Args>(args)...);
93  break;
94  default:
95  break;
96  }
97  // return quiet NaNs
98  return std::vector<Real>(n, std::nan(""));
99  }
void mooseError(Args &&... args)
void mooseWarning(Args &&... args)
virtual const std::string & name() const
enum NaNMessage _emit_on_nan
Raise mooseWarning or mooseError?
Definition: NaNInterface.h:40
const MooseObject *const _moose_object
Definition: NaNInterface.h:37

◆ validParams()

InputParameters NaNInterface::validParams ( )
static

Definition at line 15 of file NaNInterface.C.

Referenced by NaNInterfaceTestFluidProperties::validParams(), StiffenedGasFluidProperties::validParams(), IdealGasFluidProperties::validParams(), IdealRealGasMixtureFluidProperties::validParams(), CaloricallyImperfectGas::validParams(), ADNumericalFlux3EqnHLLC::validParams(), and StiffenedGasTwoPhaseFluidProperties::validParams().

16 {
17 #ifdef NDEBUG
18  // in opt mode, getNaN() emits neither a warning nor an error by default
19  MooseEnum emit_on_nan("none warning error", "none");
20 #else
21  // in dbg mode, getNaN() raises an error by default
22  MooseEnum emit_on_nan("none warning error", "error");
23 #endif
24 
26 
27  params.addParam<MooseEnum>("emit_on_nan", emit_on_nan, "Raise mooseWarning or mooseError?");
28 
29  return params;
30 }
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
InputParameters emptyInputParameters()

Member Data Documentation

◆ _emit_on_nan

enum NaNMessage NaNInterface::_emit_on_nan
protected

Raise mooseWarning or mooseError?

Definition at line 40 of file NaNInterface.h.

Referenced by getNaN(), and getNaNVector().

◆ _moose_object

const MooseObject* const NaNInterface::_moose_object
protected

Definition at line 37 of file NaNInterface.h.

Referenced by getNaN(), and getNaNVector().


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