diff --git a/include/cantera/base/global.h b/include/cantera/base/global.h index b96dc6fc3..b63b88c86 100644 --- a/include/cantera/base/global.h +++ b/include/cantera/base/global.h @@ -216,6 +216,12 @@ void suppress_deprecation_warnings(); //! @copydoc Application::make_deprecation_warnings_fatal void make_deprecation_warnings_fatal(); +//! @copydoc Application::suppress_thermo_warnings +void suppress_thermo_warnings(bool suppress=true); + +//! @copydoc Application::thermo_warnings_suppressed +bool thermo_warnings_suppressed(); + //! @copydoc Application::Messages::setLogger void setLogger(Logger* logwriter); diff --git a/include/cantera/clib/ct.h b/include/cantera/clib/ct.h index 12cd51390..d679ab078 100644 --- a/include/cantera/clib/ct.h +++ b/include/cantera/clib/ct.h @@ -157,6 +157,7 @@ extern "C" { CANTERA_CAPI int ct_addCanteraDirectory(size_t buflen, const char* buf); CANTERA_CAPI int ct_getDataDirectories(int buflen, char* buf, const char* sep); CANTERA_CAPI int ct_getCanteraVersion(int buflen, char* buf); + CANTERA_CAPI int ct_suppress_thermo_warnings(int suppress); CANTERA_CAPI int ct_clearStorage(); CANTERA_CAPI int ct_ck2cti(const char* in_file, const char* db_file, diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index 1ba15e817..9d72b94a7 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -53,6 +53,7 @@ cdef extern from "cantera/base/global.h" namespace "Cantera": cdef XML_Node* CxxGetXmlFile "Cantera::get_XML_File" (string) except +translate_exception cdef XML_Node* CxxGetXmlFromString "Cantera::get_XML_from_string" (string) except +translate_exception cdef void Cxx_make_deprecation_warnings_fatal "Cantera::make_deprecation_warnings_fatal" () + cdef void Cxx_suppress_thermo_warnings "Cantera::suppress_thermo_warnings" (cbool) cdef extern from "": cppclass shared_ptr "std::shared_ptr" [T]: diff --git a/interfaces/cython/cantera/utils.pyx b/interfaces/cython/cantera/utils.pyx index 22daa43ea..b4e60db06 100644 --- a/interfaces/cython/cantera/utils.pyx +++ b/interfaces/cython/cantera/utils.pyx @@ -47,6 +47,9 @@ def appdelete(): def make_deprecation_warnings_fatal(): Cxx_make_deprecation_warnings_fatal() +def suppress_thermo_warnings(pybool suppress=True): + Cxx_suppress_thermo_warnings(suppress) + cdef Composition comp_map(X) except *: if isinstance(X, (str, unicode, bytes)): return parseCompString(stringify(X)) diff --git a/src/base/application.cpp b/src/base/application.cpp index 0135e0c73..b6e06bb39 100644 --- a/src/base/application.cpp +++ b/src/base/application.cpp @@ -125,7 +125,8 @@ void Application::ThreadMessages::removeThreadMessages() Application::Application() : m_suppress_deprecation_warnings(false), - m_fatal_deprecation_warnings(false) + m_fatal_deprecation_warnings(false), + m_suppress_thermo_warnings(false) { // install a default logwriter that writes to standard // output / standard error diff --git a/src/base/application.h b/src/base/application.h index c1996eb01..9c5df3014 100644 --- a/src/base/application.h +++ b/src/base/application.h @@ -344,6 +344,17 @@ public: m_fatal_deprecation_warnings = true; } + //! Globally disable printing of warnings about problematic thermo data, + //! e.g. NASA polynomials with discontinuities at the midpoint temperature. + void suppress_thermo_warnings(bool suppress=true) { + m_suppress_thermo_warnings = suppress; + } + + //! Returns `true` if thermo warnings should be suppressed. + bool thermo_warnings_suppressed() { + return m_suppress_thermo_warnings; + } + //! @copydoc Messages::setLogger void setLogger(Logger* logwriter) { pMessenger->setLogger(logwriter); @@ -400,6 +411,7 @@ protected: bool m_suppress_deprecation_warnings; bool m_fatal_deprecation_warnings; + bool m_suppress_thermo_warnings; ThreadMessages pMessenger; diff --git a/src/base/global.cpp b/src/base/global.cpp index edbab3862..686718c5a 100644 --- a/src/base/global.cpp +++ b/src/base/global.cpp @@ -66,6 +66,16 @@ void make_deprecation_warnings_fatal() app()->make_deprecation_warnings_fatal(); } +void suppress_thermo_warnings(bool suppress) +{ + app()->suppress_thermo_warnings(suppress); +} + +bool thermo_warnings_suppressed() +{ + return app()->thermo_warnings_suppressed(); +} + // **************** Global Data **************** Unit* Unit::s_u = 0; diff --git a/src/clib/ct.cpp b/src/clib/ct.cpp index cf6d48222..0a0efc692 100644 --- a/src/clib/ct.cpp +++ b/src/clib/ct.cpp @@ -1428,6 +1428,16 @@ extern "C" { } } + int ct_suppress_thermo_warnings(int suppress) + { + try { + suppress_thermo_warnings(static_cast(suppress)); + return 0; + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + int ct_setLogWriter(void* logger) { try { diff --git a/src/thermo/NasaPoly2.cpp b/src/thermo/NasaPoly2.cpp index 001dca560..628676a9a 100644 --- a/src/thermo/NasaPoly2.cpp +++ b/src/thermo/NasaPoly2.cpp @@ -9,6 +9,10 @@ namespace Cantera { void NasaPoly2::validate(const std::string& name) { + if (thermo_warnings_suppressed()) { + return; + } + double cp_low, h_low, s_low; double cp_high, h_high, s_high; mnp_low.updatePropertiesTemp(m_midT, &cp_low, &h_low, &s_low);