Cantera 2.6.0
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Private Attributes | List of all members

Class to hold global data. More...

#include <application.h>

Collaboration diagram for Application:
[legend]

Classes

class  Messages
 Class to carry out messages. More...
 
class  ThreadMessages
 Class that stores thread messages for each thread, and retrieves them based on the thread id. More...
 

Public Member Functions

virtual ~Application ()
 Destructor for class deletes global data. More...
 
void addError (const std::string &r, const std::string &msg="")
 Set an error condition in the application class without throwing an exception. More...
 
int getErrorCount ()
 Return the number of errors that have been encountered so far. More...
 
void popError ()
 Discard the last error message. More...
 
std::string lastErrorMessage ()
 Retrieve the last error message in a string. More...
 
void getErrors (std::ostream &f)
 Prints all of the error messages to an ostream. More...
 
void logErrors ()
 Prints all of the error messages using writelog. More...
 
void addDataDirectory (const std::string &dir)
 Add a directory to the data file search path. More...
 
std::string findInputFile (const std::string &name)
 Find an input file. More...
 
std::string getDataDirectories (const std::string &sep)
 Get the Cantera data directories. More...
 
XML_Nodeget_XML_File (const std::string &file, int debug=0)
 Return a pointer to the XML tree for a Cantera input file. More...
 
XML_Nodeget_XML_from_string (const std::string &text)
 Read a CTI or CTML string and fill up an XML tree. More...
 
void close_XML_File (const std::string &file)
 Close an XML File. More...
 
void writelog (const std::string &msg)
 Write a message to the screen. More...
 
void writelogendl ()
 Write an endl to the screen and flush output. More...
 
void warnlog (const std::string &warning, const std::string &msg)
 Write a warning message to the screen. More...
 
void warn_deprecated (const std::string &method, const std::string &extra="")
 Print a warning indicating that method is deprecated. More...
 
void suppress_deprecation_warnings ()
 Globally disable printing of deprecation warnings. More...
 
void make_deprecation_warnings_fatal ()
 Turns deprecation warnings into exceptions. More...
 
void warn (const std::string &warning, const std::string &method, const std::string &extra="")
 Generate a general purpose warning; repeated warnings are not suppressed. More...
 
void suppress_warnings ()
 Globally disable printing of (user) warnings. More...
 
bool warnings_suppressed ()
 Returns true if warnings should be suppressed. More...
 
void make_warnings_fatal ()
 Turns Cantera warnings into exceptions. More...
 
void suppress_thermo_warnings (bool suppress=true)
 Globally disable printing of warnings about problematic thermo data, such as NASA polynomials with discontinuities at the midpoint temperature. More...
 
bool thermo_warnings_suppressed ()
 Returns true if thermo warnings should be suppressed. More...
 
void use_legacy_rate_constants (bool legacy=true)
 Set definition used for rate constant calculation. More...
 
bool legacy_rate_constants_used ()
 Returns true if legacy rate constant definition should be used. More...
 
void setLogger (Logger *logwriter)
 Install a logger. More...
 
void thread_complete ()
 Delete and free memory allocated per thread in multithreaded applications. More...
 

Static Public Member Functions

static ApplicationInstance ()
 Return a pointer to the one and only instance of class Application. More...
 
static void ApplicationDestroy ()
 Static function that destroys the application class's data. More...
 

Protected Types

typedef shared_ptr< MessagespMessages_t
 Typedef for thread specific messages. More...
 

Protected Member Functions

 Application ()
 Constructor for class sets up the initial conditions Protected ctor access thru static member function Instance. More...
 
void setDefaultDirectories ()
 Set the default directories for input files. More...
 

Protected Attributes

std::vector< std::string > inputDirs
 Current vector of input directories to search for input files. More...
 
std::map< std::string, std::pair< XML_Node *, int > > xmlfiles
 Current vector of XML file trees that have been previously parsed The second element of the value is used to store the last-modified time for the file, to enable change detection. More...
 
std::set< std::string > warnings
 Vector of deprecation warnings that have been emitted (to suppress duplicates) More...
 
bool m_suppress_deprecation_warnings
 
bool m_fatal_deprecation_warnings
 
bool m_suppress_thermo_warnings
 
bool m_suppress_warnings
 
bool m_fatal_warnings
 
bool m_use_legacy_rate_constants
 
ThreadMessages pMessenger
 

Static Private Attributes

static Applications_app = 0
 Pointer to the single Application instance. More...
 

Detailed Description

Class to hold global data.

Class Application is the top-level class that stores data that should persist for the duration of the process. The class should not be instantiated directly; instead, it is instantiated as needed by the functions declared here. At most one instance is created, and it is not destroyed until the process terminates.

Definition at line 46 of file application.h.

Member Typedef Documentation

◆ pMessages_t

typedef shared_ptr<Messages> pMessages_t
protected

Typedef for thread specific messages.

Definition at line 168 of file application.h.

Constructor & Destructor Documentation

◆ Application()

Application ( )
protected

Constructor for class sets up the initial conditions Protected ctor access thru static member function Instance.

Definition at line 131 of file application.cpp.

References Application::setDefaultDirectories(), and Unit::units().

Referenced by Application::Instance().

◆ ~Application()

~Application ( )
virtual

Destructor for class deletes global data.

Deletes any open XML trees.

Definition at line 158 of file application.cpp.

References Application::xmlfiles.

Member Function Documentation

◆ Instance()

Application * Instance ( )
static

Return a pointer to the one and only instance of class Application.

If the Application object has not yet been created, it is created

Definition at line 149 of file application.cpp.

References Cantera::app_mutex, Application::Application(), and Application::s_app.

Referenced by Cantera::app().

◆ ApplicationDestroy()

void ApplicationDestroy ( )
static

Static function that destroys the application class's data.

Definition at line 167 of file application.cpp.

References Cantera::app_mutex, and Application::s_app.

Referenced by Cantera::appdelete().

◆ addError()

void addError ( const std::string &  r,
const std::string &  msg = "" 
)
inline

Set an error condition in the application class without throwing an exception.

This routine adds an error message to the end of the stack of errors that Cantera accumulates in the Application class.

Parameters
rProcedure name which is generating the error condition
msgDescriptive message of the error condition.

If only one argument is specified, that string is used as the entire message.

Definition at line 217 of file application.h.

References Application::Messages::addError().

◆ getErrorCount()

int getErrorCount ( )
inline

Return the number of errors that have been encountered so far.

Definition at line 222 of file application.h.

References Application::Messages::getErrorCount().

◆ popError()

void popError ( )
inline

Discard the last error message.

Cantera saves a stack of exceptions that it has caught in the Application class. This routine eliminates the last exception to be added to that stack.

Definition at line 227 of file application.h.

References Application::Messages::popError().

◆ lastErrorMessage()

std::string lastErrorMessage ( )
inline

Retrieve the last error message in a string.

This routine will retrieve the last error message and return it in the return string.

Definition at line 232 of file application.h.

References Application::Messages::lastErrorMessage().

◆ getErrors()

void getErrors ( std::ostream &  f)
inline

Prints all of the error messages to an ostream.

Write out all of the saved error messages to the ostream f using the function Logger::writelog. Cantera saves a stack of exceptions that it has caught in the Application class. This routine writes out all of the error messages to the ostream and then clears them from internal storage.

Parameters
fostream which will receive the error messages

Definition at line 237 of file application.h.

References Application::Messages::getErrors().

◆ logErrors()

void logErrors ( )
inline

Prints all of the error messages using writelog.

Print all of the error messages using function writelog. Cantera saves a stack of exceptions that it has caught in the Application class. This routine writes out all of the error messages and then clears them from internal storage.

Definition at line 242 of file application.h.

References Application::Messages::logErrors().

◆ get_XML_File()

XML_Node * get_XML_File ( const std::string &  file,
int  debug = 0 
)

Return a pointer to the XML tree for a Cantera input file.

This routine will find the file and read the XML file into an XML tree structure. Then, a pointer will be returned. If the file has already been processed, then just the pointer will be returned.

Parameters
fileString containing the relative or absolute file name
debugDebug flag
Deprecated:
The XML input format is deprecated and will be removed in Cantera 3.0.

Definition at line 205 of file application.cpp.

References Application::findInputFile(), and Cantera::xml_mutex.

Referenced by Cantera::get_XML_File().

◆ get_XML_from_string()

XML_Node * get_XML_from_string ( const std::string &  text)

Read a CTI or CTML string and fill up an XML tree.

Return a pointer to the XML tree corresponding to the specified CTI or XML string. If the given string has been processed before, the cached XML tree will be returned. Otherwise, the XML tree will be generated and stored in the cache.

Parameters
textCTI or CTML string
Returns
Root of the corresponding XML tree
Deprecated:
The XML input format is deprecated and will be removed in Cantera 3.0.

Definition at line 242 of file application.cpp.

References Cantera::ct_string2ctml_string(), Cantera::xml_mutex, and Application::xmlfiles.

Referenced by Cantera::get_XML_from_string().

◆ close_XML_File()

void close_XML_File ( const std::string &  file)

Close an XML File.

Close a file that is opened by this application object

Parameters
fileString containing the relative or absolute file name

Definition at line 262 of file application.cpp.

References Cantera::xml_mutex, and Application::xmlfiles.

Referenced by Cantera::close_XML_File().

◆ writelog()

void writelog ( const std::string &  msg)
inline

Write a message to the screen.

The string may be of any length, and may contain end-of-line characters. This method is used throughout Cantera to write log messages. It can also be called by user programs. The advantage of using writelog over writing directly to the standard output is that messages written with writelog will display correctly even when Cantera is used from MATLAB or other application that do not have a standard output stream.

Parameters
msgc++ string to be written to the screen

Definition at line 333 of file application.h.

References Application::Messages::writelog().

Referenced by Application::Messages::logErrors(), and Cantera::writelog_direct().

◆ writelogendl()

void writelogendl ( )
inline

Write an endl to the screen and flush output.

Definition at line 338 of file application.h.

References Application::Messages::writelogendl().

Referenced by Application::Messages::logErrors(), and Cantera::writelogendl().

◆ warnlog()

void warnlog ( const std::string &  warning,
const std::string &  msg 
)
inline

Write a warning message to the screen.

Parameters
warningString specifying type of warning;
See also
Logger::warn
Parameters
msgString to be written to the screen

Definition at line 343 of file application.h.

References Application::Messages::warnlog().

Referenced by Application::warn(), and Application::warn_deprecated().

◆ warn_deprecated()

void warn_deprecated ( const std::string &  method,
const std::string &  extra = "" 
)

Print a warning indicating that method is deprecated.

Additional information (removal version, alternatives) can be specified in extra. Deprecation warnings are printed once per method per invocation of the application.

Definition at line 176 of file application.cpp.

References Application::warnings, and Application::warnlog().

Referenced by Cantera::_warn_deprecated().

◆ suppress_deprecation_warnings()

void suppress_deprecation_warnings ( )
inline

Globally disable printing of deprecation warnings.

Used primarily to prevent certain tests from failing.

Definition at line 355 of file application.h.

Referenced by Cantera::suppress_deprecation_warnings().

◆ make_deprecation_warnings_fatal()

void make_deprecation_warnings_fatal ( )
inline

Turns deprecation warnings into exceptions.

Activated within the test suite to make sure that no deprecated methods are being used.

Definition at line 362 of file application.h.

Referenced by Cantera::make_deprecation_warnings_fatal().

◆ warn()

void warn ( const std::string &  warning,
const std::string &  method,
const std::string &  extra = "" 
)

Generate a general purpose warning; repeated warnings are not suppressed.

Parameters
warningWarning type;
See also
Logger::warn
Parameters
methodName of method triggering the warning
extraAdditional information printed for the warning

Definition at line 188 of file application.cpp.

References Application::warnlog().

Referenced by Cantera::_warn().

◆ suppress_warnings()

void suppress_warnings ( )
inline

Globally disable printing of (user) warnings.

Used primarily to prevent certain tests from failing.

Definition at line 375 of file application.h.

Referenced by Cantera::suppress_warnings().

◆ warnings_suppressed()

bool warnings_suppressed ( )
inline

Returns true if warnings should be suppressed.

Definition at line 381 of file application.h.

Referenced by Cantera::warnings_suppressed().

◆ make_warnings_fatal()

void make_warnings_fatal ( )
inline

Turns Cantera warnings into exceptions.

Activated within the test suite to make sure that your warning message are being raised.

Definition at line 387 of file application.h.

Referenced by Cantera::make_warnings_fatal().

◆ suppress_thermo_warnings()

void suppress_thermo_warnings ( bool  suppress = true)
inline

Globally disable printing of warnings about problematic thermo data, such as NASA polynomials with discontinuities at the midpoint temperature.

Definition at line 393 of file application.h.

Referenced by Cantera::suppress_thermo_warnings().

◆ thermo_warnings_suppressed()

bool thermo_warnings_suppressed ( )
inline

Returns true if thermo warnings should be suppressed.

Definition at line 398 of file application.h.

Referenced by Cantera::thermo_warnings_suppressed().

◆ use_legacy_rate_constants()

void use_legacy_rate_constants ( bool  legacy = true)
inline

Set definition used for rate constant calculation.

See also
Kinetics::getFwdRateConstants()

If set to 'false', rate constants of three-body reactions are consistent with conventional definitions. If set to 'true', output for rate constants of three-body reactions is multipied by third-body concentrations (legacy behavior). For the pre-compiled Cantera 2.6 distribution, the default value is set to 'true', which implies no change compared to previous behavior. For user-compiled Cantera, the default behavior can be changed by the SCons flag 'legacy_rate_constants'.

Deprecated:
Behavior to change after Cantera 2.6; for Cantera 2.6, rate constants of three-body reactions are multiplied with third-body concentrations (no change to legacy behavior). After Cantera 2.6, results will no longer include third-body concentrations and be consistent with conventional definitions (see Eq. 9.75 in Kee, Coltrin and Glarborg, 'Chemically Reacting Flow', Wiley Interscience, 2003).

Definition at line 421 of file application.h.

Referenced by Cantera::use_legacy_rate_constants().

◆ legacy_rate_constants_used()

bool legacy_rate_constants_used ( )
inline

Returns true if legacy rate constant definition should be used.

Definition at line 426 of file application.h.

Referenced by Cantera::legacy_rate_constants_used().

◆ setLogger()

void setLogger ( Logger logwriter)
inline

Install a logger.

Called by the language interfaces to install an appropriate logger. The logger is used for the writelog() function

Parameters
logwriterPointer to a logger object
See also
Logger.

Definition at line 431 of file application.h.

References Application::Messages::setLogger().

Referenced by Cantera::setLogger().

◆ thread_complete()

void thread_complete ( )

Delete and free memory allocated per thread in multithreaded applications.

Delete the memory allocated per thread by Cantera. It should be called from within the thread just before the thread terminates. If your version of Cantera has not been specifically compiled for thread safety this function does nothing.

Definition at line 200 of file application.cpp.

References Application::ThreadMessages::removeThreadMessages().

Referenced by Cantera::thread_complete().

Member Data Documentation

◆ inputDirs

std::vector<std::string> inputDirs
protected

Current vector of input directories to search for input files.

Definition at line 474 of file application.h.

Referenced by Application::addDataDirectory(), Application::findInputFile(), Application::getDataDirectories(), and Application::setDefaultDirectories().

◆ xmlfiles

std::map<std::string, std::pair<XML_Node*, int> > xmlfiles
protected

Current vector of XML file trees that have been previously parsed The second element of the value is used to store the last-modified time for the file, to enable change detection.

Deprecated:
The XML input format is deprecated and will be removed in Cantera 3.0.

Definition at line 482 of file application.h.

Referenced by Application::close_XML_File(), Application::get_XML_from_string(), and Application::~Application().

◆ warnings

std::set<std::string> warnings
protected

Vector of deprecation warnings that have been emitted (to suppress duplicates)

Definition at line 485 of file application.h.

Referenced by Application::warn_deprecated().

◆ m_suppress_deprecation_warnings

bool m_suppress_deprecation_warnings
protected

Definition at line 487 of file application.h.

◆ m_fatal_deprecation_warnings

bool m_fatal_deprecation_warnings
protected

Definition at line 488 of file application.h.

◆ m_suppress_thermo_warnings

bool m_suppress_thermo_warnings
protected

Definition at line 489 of file application.h.

◆ m_suppress_warnings

bool m_suppress_warnings
protected

Definition at line 490 of file application.h.

◆ m_fatal_warnings

bool m_fatal_warnings
protected

Definition at line 491 of file application.h.

◆ m_use_legacy_rate_constants

bool m_use_legacy_rate_constants
protected

Definition at line 492 of file application.h.

◆ pMessenger

ThreadMessages pMessenger
protected

Definition at line 494 of file application.h.

◆ s_app

Application * s_app = 0
staticprivate

Pointer to the single Application instance.

Definition at line 498 of file application.h.

Referenced by Application::ApplicationDestroy(), and Application::Instance().


The documentation for this class was generated from the following files: