https://mooseframework.inl.gov
NaNInterface.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 "InputParameters.h"
13 #include "MooseObject.h"
14 
23 {
24 public:
26 
27  NaNInterface(const MooseObject * moose_object);
28 
29 protected:
31  {
36  };
37 
38  const MooseObject * const _moose_object;
39 
42 
46  Real getNaN() const { return getNaN("A NaN was produced."); }
47 
53  std::vector<Real> getNaNVector(const unsigned int & n) const
54  {
55  return getNaNVector(n, "A NaN was produced.");
56  }
57 
61  template <typename... Args>
62  Real getNaN(Args &&... args) const
63  {
64  switch (_emit_on_nan)
65  {
66  case (NAN_MESSAGE_WARNING):
67  mooseWarning(_moose_object->name(), ": ", std::forward<Args>(args)...);
68  break;
69  case (NAN_MESSAGE_EXCEPTION):
70  mooseException(_moose_object->name(), ": ", std::forward<Args>(args)...);
71  break;
72  case (NAN_MESSAGE_ERROR):
73  mooseError(_moose_object->name(), ": ", std::forward<Args>(args)...);
74  break;
75  default:
76  break;
77  }
78  // return a quiet NaN
79  return std::nan("");
80  }
81 
87  template <typename... Args>
88  std::vector<Real> getNaNVector(const unsigned int & n, Args &&... args) const
89  {
90  switch (_emit_on_nan)
91  {
92  case (NAN_MESSAGE_WARNING):
93  mooseWarning(_moose_object->name(), ": ", std::forward<Args>(args)...);
94  break;
95  case (NAN_MESSAGE_EXCEPTION):
96  mooseException(_moose_object->name(), ": ", std::forward<Args>(args)...);
97  break;
98  case (NAN_MESSAGE_ERROR):
99  mooseError(_moose_object->name(), ": ", std::forward<Args>(args)...);
100  break;
101  default:
102  break;
103  }
104  // return quiet NaNs
105  return std::vector<Real>(n, std::nan(""));
106  }
107 };
NaNInterface(const MooseObject *moose_object)
Definition: NaNInterface.C:35
std::vector< Real > getNaNVector(const unsigned int &n, Args &&... args) const
Throws an error or returns NaNs with or without a warning.
Definition: NaNInterface.h:88
void mooseError(Args &&... args)
void mooseWarning(Args &&... args)
Real getNaN() const
Throws an error or returns a NaN with or without a warning, with a default message.
Definition: NaNInterface.h:46
virtual const std::string & name() const
enum NaNMessage _emit_on_nan
Raise mooseWarning or mooseError?
Definition: NaNInterface.h:41
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static InputParameters validParams()
Definition: NaNInterface.C:15
Real getNaN(Args &&... args) const
Throws an error or returns a NaN with or without a warning.
Definition: NaNInterface.h:62
const MooseObject *const _moose_object
Definition: NaNInterface.h:38
Interface class for producing errors, warnings, or just quiet NaNs.
Definition: NaNInterface.h:22
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:53