Cantera 2.6.0
KineticsFactory.h
Go to the documentation of this file.
1/**
2 * @file KineticsFactory.h
3 */
4
5// This file is part of Cantera. See License.txt in the top-level directory or
6// at https://cantera.org/license.txt for license and copyright information.
7
8#ifndef KINETICS_FACTORY_H
9#define KINETICS_FACTORY_H
10
11#include "Kinetics.h"
13#include "cantera/base/AnyMap.h"
14
15namespace Cantera
16{
17
18//! @deprecated Unused. To be removed after Cantera 2.6.
20{
21public:
22 UnknownKineticsModel(const std::string& proc, const std::string& kineticsModel) :
23 CanteraError(proc, "Specified Kinetics model "
24 + kineticsModel +
25 " does not match any known type.") {
26 warn_deprecated("class UnknownKineticsModel",
27 "Unused. To be removed after Cantera 2.6.");
28 }
29};
30
31/**
32 * Factory for kinetics managers.
33 */
34class KineticsFactory : public Factory<Kinetics>
35{
36public:
37 static KineticsFactory* factory() {
38 std::unique_lock<std::mutex> lock(kinetics_mutex);
39 if (!s_factory) {
40 s_factory = new KineticsFactory;
41 }
42 return s_factory;
43 }
44
45 virtual void deleteFactory() {
46 std::unique_lock<std::mutex> lock(kinetics_mutex);
47 delete s_factory;
48 s_factory = 0;
49 }
50
51 /**
52 * Return a new kinetics manager that implements a reaction mechanism
53 * specified in a CTML file. In other words, the kinetics manager, given
54 * the rate constants and formulation of the reactions that make up a
55 * kinetics mechanism, is responsible for calculating the rates of
56 * progress of the reactions and for calculating the source terms for
57 * species.
58 *
59 * @param phase An XML_Node that contains the XML data describing the
60 * phase. Of particular note to this routine is the child XML
61 * element called "kinetics". The element has one attribute
62 * called "model", with a string value. The value of this
63 * string is used to decide which kinetics manager is used to
64 * calculate the reaction mechanism.
65 * @param th Vector of phases. The first phase is the phase in which
66 * the reactions occur, and the subsequent phases (if any)
67 * are for example bulk phases adjacent to a reacting surface.
68 * @return Pointer to the new kinetics manager.
69 *
70 * @deprecated The XML input format is deprecated and will be removed in
71 * Cantera 3.0.
72 */
73 virtual Kinetics* newKinetics(XML_Node& phase, std::vector<ThermoPhase*> th);
74
75 /**
76 * Return a new, empty kinetics manager.
77 */
78 virtual Kinetics* newKinetics(const std::string& model);
79
80private:
81 static KineticsFactory* s_factory;
83 static std::mutex kinetics_mutex;
84};
85
86/**
87 * Create a new kinetics manager.
88 *
89 * @deprecated The XML input format is deprecated and will be removed in
90 * Cantera 3.0.
91 */
92inline Kinetics* newKineticsMgr(XML_Node& phase, std::vector<ThermoPhase*> th)
93{
94 return KineticsFactory::factory()->newKinetics(phase, th);
95}
96
97/**
98 * Create a new kinetics manager.
99 */
100inline Kinetics* newKineticsMgr(const std::string& model)
101{
102 return KineticsFactory::factory()->newKinetics(model);
103}
104
105/**
106 * Create a new Kinetics instance.
107 */
108inline shared_ptr<Kinetics> newKinetics(const std::string& model)
109{
110 shared_ptr<Kinetics> kin(KineticsFactory::factory()->newKinetics(model));
111 return kin;
112}
113
114/*!
115 * Create a new kinetics manager, initialize it, and add reactions
116 *
117 * @param phases Vector of phases containing species which participate in
118 * reactions, with the phase where the reactions occur (lowest-dimensional
119 * phase) listed first.
120 * @param phaseNode Phase entry for the phase where the reactions occur. This
121 * phase definition is used to determine the source of the reactions added
122 * to the Kinetics object.
123 * @param rootNode The root node of the file containing the phase definition,
124 * which will be treated as the default source for reactions
125 */
126unique_ptr<Kinetics> newKinetics(const std::vector<ThermoPhase*>& phases,
127 const AnyMap& phaseNode,
128 const AnyMap& rootNode=AnyMap());
129
130/*!
131 * Create a new kinetics manager, initialize it, and add reactions
132 *
133 * @param phases Vector of phases containing species which participate in
134 * reactions, with the phase where the reactions occur (lowest-dimensional
135 * phase) listed first.
136 * @param filename File containing the phase definition for the phase where
137 * the reactions occur. Searches the Cantera data for this file.
138 * @param phase_name The name of the reacting phase in the input file (that is, the
139 * name of the first phase in the `phases` vector)
140 */
141unique_ptr<Kinetics> newKinetics(const std::vector<ThermoPhase*>& phases,
142 const std::string& filename,
143 const std::string& phase_name);
144
145/*!
146 * Add reactions to a Kinetics object
147 *
148 * @param kin The Kinetics object to be initialized
149 * @param phaseNode Phase entry for the phase where the reactions occur. This
150 * phase definition is used to determine the source of the reactions added
151 * to the Kinetics object.
152 * @param rootNode The root node of the file containing the phase definition,
153 * which will be treated as the default source for reactions
154 */
155void addReactions(Kinetics& kin, const AnyMap& phaseNode,
156 const AnyMap& rootNode=AnyMap());
157
158}
159
160#endif
File contains the FactoryBase class declarations.
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
CanteraError()
Protected default constructor discourages throwing errors containing no information.
Definition: ctexceptions.h:106
Factory class that supports registering functions to create objects.
Definition: FactoryBase.h:70
Factory for kinetics managers.
virtual Kinetics * newKinetics(XML_Node &phase, std::vector< ThermoPhase * > th)
Return a new kinetics manager that implements a reaction mechanism specified in a CTML file.
virtual void deleteFactory()
Virtual abstract function that deletes the factory.
Public interface for kinetics managers.
Definition: Kinetics.h:114
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
void addReactions(Kinetics &kin, const AnyMap &phaseNode, const AnyMap &rootNode=AnyMap())
void warn_deprecated(const std::string &source, const AnyBase &node, const std::string &message)
A deprecation warning for syntax in an input file.
Definition: AnyMap.cpp:1901
Kinetics * newKineticsMgr(XML_Node &phase, std::vector< ThermoPhase * > th)
Create a new kinetics manager.
shared_ptr< Kinetics > newKinetics(const std::string &model)
Create a new Kinetics instance.