Cantera  3.1.0a1
Loading...
Searching...
No Matches
Application Class Reference

Class to hold global data. More...

#include <application.h>

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 41 of file application.h.

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.
 
void addError (const string &r, const string &msg="")
 Set an error condition in the application class without throwing an exception.
 
int getErrorCount ()
 Return the number of errors that have been encountered so far.
 
void popError ()
 Discard the last error message.
 
string lastErrorMessage ()
 Retrieve the last error message in a string.
 
void getErrors (std::ostream &f)
 Prints all of the error messages to an ostream.
 
void logErrors ()
 Prints all of the error messages using writelog.
 
void addDataDirectory (const string &dir)
 Add a directory to the data file search path.
 
string findInputFile (const string &name)
 Find an input file.
 
string getDataDirectories (const string &sep)
 Get the Cantera data directories.
 
void loadExtension (const string &extType, const string &name)
 Load an extension implementing user-defined models.
 
void searchPythonVersions (const string &versions)
 Set the versions of Python to try when loading user-defined extensions, in order of preference.
 
void writelog (const string &msg)
 Write a message to the screen.
 
void writelogendl ()
 Write an endl to the screen and flush output.
 
void warnlog (const string &warning, const string &msg)
 Write a warning message to the screen.
 
void warn_deprecated (const string &method, const string &extra="")
 Print a warning indicating that method is deprecated.
 
void suppress_deprecation_warnings ()
 Globally disable printing of deprecation warnings.
 
void make_deprecation_warnings_fatal ()
 Turns deprecation warnings into exceptions.
 
void warn (const string &warning, const string &method, const string &extra="")
 Generate a general purpose warning; repeated warnings are not suppressed.
 
void suppress_warnings ()
 Globally disable printing of (user) warnings.
 
bool warnings_suppressed ()
 Returns true if warnings should be suppressed.
 
void make_warnings_fatal ()
 Turns Cantera warnings into exceptions.
 
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.
 
bool thermo_warnings_suppressed ()
 Returns true if thermo warnings should be suppressed.
 
void use_legacy_rate_constants (bool legacy=true)
 Set definition used for rate constant calculation.
 
bool legacy_rate_constants_used ()
 Returns true if legacy rate constant definition is used.
 
void setLogger (Logger *logwriter)
 Install a logger.
 
void thread_complete ()
 Delete and free memory allocated per thread in multithreaded applications.
 

Static Public Member Functions

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

Protected Types

typedef shared_ptr< MessagespMessages_t
 Typedef for thread specific messages.
 

Protected Member Functions

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

Protected Attributes

vector< string > inputDirs
 Current vector of input directories to search for input files.
 
vector< string > m_pythonSearchVersions = {"3.12", "3.11", "3.10", "3.9", "3.8"}
 Versions of Python to consider when attempting to load user extensions.
 
set< string > warnings
 Set of deprecation warnings that have been emitted (to suppress duplicates)
 
bool m_suppress_deprecation_warnings = false
 
bool m_fatal_deprecation_warnings = false
 
bool m_suppress_thermo_warnings = false
 
bool m_suppress_warnings = false
 
bool m_fatal_warnings = false
 
bool m_use_legacy_rate_constants = false
 
set< pair< string, string > > m_loaded_extensions
 
ThreadMessages pMessenger
 

Static Private Attributes

static Applications_app = 0
 Pointer to the single Application instance.
 

Member Typedef Documentation

◆ pMessages_t

typedef shared_ptr<Messages> pMessages_t
protected

Typedef for thread specific messages.

Definition at line 163 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 110 of file application.cpp.

◆ ~Application()

virtual ~Application ( )
inlinevirtual

Destructor for class deletes global data.

Definition at line 203 of file application.h.

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 117 of file application.cpp.

◆ ApplicationDestroy()

void ApplicationDestroy ( )
static

Static function that destroys the application class's data.

Definition at line 126 of file application.cpp.

◆ addError()

void addError ( const string &  r,
const 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 209 of file application.h.

◆ getErrorCount()

int getErrorCount ( )
inline

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

Definition at line 214 of file application.h.

◆ 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 219 of file application.h.

◆ lastErrorMessage()

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 224 of file application.h.

◆ 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 229 of file application.h.

◆ 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 234 of file application.h.

◆ loadExtension()

void loadExtension ( const string &  extType,
const string &  name 
)

Load an extension implementing user-defined models.

Parameters
extTypeSpecifies the interface / language of the extension, for example "python"
nameSpecifies the name of the extension. The meaning of this parameter depends on the specific extension interface. For example, for Python extensions, this is the name of the Python module containing the models.
Since
New in Cantera 3.0

Definition at line 378 of file application.cpp.

◆ searchPythonVersions()

void searchPythonVersions ( const string &  versions)

Set the versions of Python to try when loading user-defined extensions, in order of preference.

Separate multiple versions with commas, for example "3.11,3.10".

Since
New in Cantera 3.0

Definition at line 429 of file application.cpp.

◆ writelog()

void writelog ( const 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 305 of file application.h.

◆ writelogendl()

void writelogendl ( )
inline

Write an endl to the screen and flush output.

Definition at line 310 of file application.h.

◆ warnlog()

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

Write a warning message to the screen.

Parameters
warningString specifying type of warning; see Logger::warn()
msgString to be written to the screen

Definition at line 315 of file application.h.

◆ warn_deprecated()

void warn_deprecated ( const string &  method,
const 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 135 of file application.cpp.

◆ 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 327 of file application.h.

◆ 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 334 of file application.h.

◆ warn()

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

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

Parameters
warningWarning type; see Logger::warn()
methodName of method triggering the warning
extraAdditional information printed for the warning

Definition at line 146 of file application.cpp.

◆ suppress_warnings()

void suppress_warnings ( )
inline

Globally disable printing of (user) warnings.

Used primarily to prevent certain tests from failing.

Definition at line 346 of file application.h.

◆ warnings_suppressed()

bool warnings_suppressed ( )
inline

Returns true if warnings should be suppressed.

Definition at line 352 of file application.h.

◆ 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 358 of file application.h.

◆ 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 364 of file application.h.

◆ thermo_warnings_suppressed()

bool thermo_warnings_suppressed ( )
inline

Returns true if thermo warnings should be suppressed.

Definition at line 369 of file application.h.

◆ 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 (default value), rate constants of three-body reactions are consistent with conventional definitions (for example Eq. 9.75 in Kee, et al. [15]). If set to true, output for rate constants of three-body reactions is multiplied by third-body concentrations, consistent with Cantera's behavior prior to version 3.0.

Definition at line 383 of file application.h.

◆ legacy_rate_constants_used()

bool legacy_rate_constants_used ( )
inline

Returns true if legacy rate constant definition is used.

Definition at line 388 of file application.h.

◆ 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 393 of file application.h.

◆ 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 156 of file application.cpp.

Member Data Documentation

◆ inputDirs

vector<string> inputDirs
protected

Current vector of input directories to search for input files.

Definition at line 434 of file application.h.

◆ m_pythonSearchVersions

vector<string> m_pythonSearchVersions = {"3.12", "3.11", "3.10", "3.9", "3.8"}
protected

Versions of Python to consider when attempting to load user extensions.

Definition at line 437 of file application.h.

◆ warnings

set<string> warnings
protected

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

Definition at line 440 of file application.h.

◆ m_suppress_deprecation_warnings

bool m_suppress_deprecation_warnings = false
protected

Definition at line 442 of file application.h.

◆ m_fatal_deprecation_warnings

bool m_fatal_deprecation_warnings = false
protected

Definition at line 443 of file application.h.

◆ m_suppress_thermo_warnings

bool m_suppress_thermo_warnings = false
protected

Definition at line 444 of file application.h.

◆ m_suppress_warnings

bool m_suppress_warnings = false
protected

Definition at line 445 of file application.h.

◆ m_fatal_warnings

bool m_fatal_warnings = false
protected

Definition at line 446 of file application.h.

◆ m_use_legacy_rate_constants

bool m_use_legacy_rate_constants = false
protected

Definition at line 447 of file application.h.

◆ m_loaded_extensions

set<pair<string, string> > m_loaded_extensions
protected

Definition at line 449 of file application.h.

◆ pMessenger

ThreadMessages pMessenger
protected

Definition at line 451 of file application.h.

◆ s_app

Application * s_app = 0
staticprivate

Pointer to the single Application instance.

Definition at line 455 of file application.h.


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