https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
24public:
26
27 NaNInterface(const MooseObject * moose_object);
28
29protected:
37
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 {
67 mooseWarning(_moose_object->name(), ": ", std::forward<Args>(args)...);
68 break;
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 {
93 mooseWarning(_moose_object->name(), ": ", std::forward<Args>(args)...);
94 break;
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};
void mooseWarning(Args &&... args)
void mooseError(Args &&... args)
const std::string & name() const
Interface class for producing errors, warnings, or just quiet NaNs.
enum NaNMessage _emit_on_nan
Raise mooseWarning or mooseError?
const MooseObject *const _moose_object
std::vector< Real > getNaNVector(const unsigned int &n) const
Throws an error or returns NaNs with or without a warning, with a default message.
Real getNaN() const
Throws an error or returns a NaN with or without a warning, with a default message.
Real getNaN(Args &&... args) const
Throws an error or returns a NaN with or without a warning.
std::vector< Real > getNaNVector(const unsigned int &n, Args &&... args) const
Throws an error or returns NaNs with or without a warning.
static InputParameters validParams()