Cantera  3.1.0a1
Loading...
Searching...
No Matches
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
12
13namespace Cantera {
14
15void 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
28void checkFinite(const string& name, double* values, size_t N)
29{
30 for (size_t i = 0; i < N; i++) {
31 if (!std::isfinite(values[i])) {
32 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}
Base class for exceptions thrown by Cantera classes.
This file contains definitions of constants, types and terms that are used in internal routines and a...
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
void checkFinite(const double tmp)
Check to see that a number is finite (not NaN, +Inf or -Inf)
Contains declarations for string manipulation functions within Cantera.