www.mooseframework.org
NaNInterface.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 "MooseObject.h"
14 
23 {
24 public:
26 
27  NaNInterface(const MooseObject * moose_object);
28 
29 protected:
31  {
35  };
36 
37  const MooseObject * const _moose_object;
38 
41 
45  Real getNaN() const { return getNaN("A NaN was produced."); }
46 
52  std::vector<Real> getNaNVector(const unsigned int & n) const
53  {
54  return getNaNVector(n, "A NaN was produced.");
55  }
56 
60  template <typename... Args>
61  Real getNaN(Args &&... args) const
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  }
77 
83  template <typename... Args>
84  std::vector<Real> getNaNVector(const unsigned int & n, Args &&... args) const
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  }
100 };
NaNInterface(const MooseObject *moose_object)
Definition: NaNInterface.C:32
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:84
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:45
virtual const std::string & name() const
enum NaNMessage _emit_on_nan
Raise mooseWarning or mooseError?
Definition: NaNInterface.h:40
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:61
const MooseObject *const _moose_object
Definition: NaNInterface.h:37
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:52