Cantera
2.5.1
src
base
checkFinite.cpp
Go to the documentation of this file.
1
/**
2
* @file checkFinite.cpp Declarations for routines that check for the
3
* presence of NaNs in the code.
4
*/
5
6
// This file is part of Cantera. See License.txt in the top-level directory or
7
// at https://cantera.org/license.txt for license and copyright information.
8
9
#include "
cantera/base/ct_defs.h
"
10
#include "
cantera/base/stringUtils.h
"
11
#include "
cantera/base/ctexceptions.h
"
12
13
namespace
Cantera
{
14
15
void
checkFinite
(
const
double
tmp)
16
{
17
if
(!std::isfinite(tmp)) {
18
if
(std::isnan(tmp)) {
19
throw
CanteraError
(
"checkFinite"
,
"found NaN"
);
20
}
else
if
(tmp > 0) {
21
throw
CanteraError
(
"checkFinite"
,
"found +Inf"
);
22
}
else
{
23
throw
CanteraError
(
"checkFinite"
,
"found -Inf"
);
24
}
25
}
26
}
27
28
void
checkFinite
(
const
std::string& name,
double
* values,
size_t
N)
29
{
30
for
(
size_t
i = 0; i < N; i++) {
31
if
(!std::isfinite(values[i])) {
32
std::string message = name +
" contains non-finite elements:\n\n"
;
33
for
(
size_t
j = 0; j < N; j++) {
34
if
(!std::isfinite(values[j])) {
35
message += fmt::format(
"{}[{}] = {}\n"
, name, j, values[j]);
36
}
37
}
38
throw
CanteraError
(
"checkFinite"
, message);
39
}
40
}
41
}
42
43
}
Cantera::checkFinite
void checkFinite(const double tmp)
Check to see that a number is finite (not NaN, +Inf or -Inf)
Definition:
checkFinite.cpp:15
ct_defs.h
stringUtils.h
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition:
ctexceptions.h:60
ctexceptions.h
Cantera
Namespace for the Cantera kernel.
Definition:
AnyMap.cpp:263
Generated by
1.8.17