Cantera  2.5.1
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 
14 namespace Cantera
15 {
16 
17 class UnknownKineticsModel : public CanteraError
18 {
19 public:
20  UnknownKineticsModel(const std::string& proc, const std::string& kineticsModel) :
21  CanteraError(proc, "Specified Kinetics model "
22  + kineticsModel +
23  " does not match any known type.") {}
24 };
25 
26 /**
27  * Factory for kinetics managers.
28  */
29 class KineticsFactory : public Factory<Kinetics>
30 {
31 public:
32  static KineticsFactory* factory() {
33  std::unique_lock<std::mutex> lock(kinetics_mutex);
34  if (!s_factory) {
35  s_factory = new KineticsFactory;
36  }
37  return s_factory;
38  }
39 
40  virtual void deleteFactory() {
41  std::unique_lock<std::mutex> lock(kinetics_mutex);
42  delete s_factory;
43  s_factory = 0;
44  }
45 
46  /**
47  * Return a new kinetics manager that implements a reaction mechanism
48  * specified in a CTML file. In other words, the kinetics manager, given
49  * the rate constants and formulation of the reactions that make up a
50  * kinetics mechanism, is responsible for calculating the rates of
51  * progress of the reactions and for calculating the source terms for
52  * species.
53  *
54  * @param phase An XML_Node that contains the XML data describing the
55  * phase. Of particular note to this routine is the child XML
56  * element called "kinetics". The element has one attribute
57  * called "model", with a string value. The value of this
58  * string is used to decide which kinetics manager is used to
59  * calculate the reaction mechanism.
60  * @param th Vector of phases. The first phase is the phase in which
61  * the reactions occur, and the subsequent phases (if any)
62  * are e.g. bulk phases adjacent to a reacting surface.
63  * @return Pointer to the new kinetics manager.
64  *
65  * @deprecated The XML input format is deprecated and will be removed in
66  * Cantera 3.0.
67  */
68  virtual Kinetics* newKinetics(XML_Node& phase, std::vector<ThermoPhase*> th);
69 
70  /**
71  * Return a new, empty kinetics manager.
72  */
73  virtual Kinetics* newKinetics(const std::string& model);
74 
75 private:
76  static KineticsFactory* s_factory;
78  static std::mutex kinetics_mutex;
79 };
80 
81 /**
82  * Create a new kinetics manager.
83  *
84  * @deprecated The XML input format is deprecated and will be removed in
85  * Cantera 3.0.
86  */
87 inline Kinetics* newKineticsMgr(XML_Node& phase, std::vector<ThermoPhase*> th)
88 {
89  return KineticsFactory::factory()->newKinetics(phase, th);
90 }
91 
92 /**
93  * Create a new kinetics manager.
94  */
95 inline Kinetics* newKineticsMgr(const std::string& model)
96 {
97  return KineticsFactory::factory()->newKinetics(model);
98 }
99 
100 /*!
101  * Create a new kinetics manager, initialize it, and add reactions
102  *
103  * @param phases Vector of phases containing species which participate in
104  * reactions, with the phase where the reactions occur (lowest-dimensional
105  * phase) listed first.
106  * @param phaseNode Phase entry for the phase where the reactions occur. This
107  * phase definition is used to determine the source of the reactions added
108  * to the Kinetics object.
109  * @param rootNode The root node of the file containing the phase definition,
110  * which will be treated as the default source for reactions
111  */
112 unique_ptr<Kinetics> newKinetics(std::vector<ThermoPhase*>& phases,
113  const AnyMap& phaseNode,
114  const AnyMap& rootNode=AnyMap());
115 
116 /*!
117  * Create a new kinetics manager, initialize it, and add reactions
118  *
119  * @param phases Vector of phases containing species which participate in
120  * reactions, with the phase where the reactions occur (lowest-dimensional
121  * phase) listed first.
122  * @param filename File containing the phase definition for the phase where
123  * the reactions occur. Searches the Cantera data for this file.
124  * @param phase_name The name of the reacting phase in the input file (i.e. the
125  * name of the first phase in the `phases` vector)
126  */
127 unique_ptr<Kinetics> newKinetics(std::vector<ThermoPhase*>& phases,
128  const std::string& filename,
129  const std::string& phase_name);
130 
131 /*!
132  * Add reactions to a Kinetics object
133  *
134  * @param kin The Kinetics object to be initialized
135  * @param phaseNode Phase entry for the phase where the reactions occur. This
136  * phase definition is used to determine the source of the reactions added
137  * to the Kinetics object.
138  * @param rootNode The root node of the file containing the phase definition,
139  * which will be treated as the default source for reactions
140  */
141 void addReactions(Kinetics& kin, const AnyMap& phaseNode,
142  const AnyMap& rootNode=AnyMap());
143 
144 }
145 
146 #endif
File contains the FactoryBase class declarations.
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
CanteraError(const std::string &procedure, const std::string &msg, const Args &... args)
Normal Constructor for the CanteraError base class.
Definition: ctexceptions.h:78
Factory class that supports registering functions to create objects.
Definition: FactoryBase.h:71
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:111
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:104
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
Kinetics * newKineticsMgr(XML_Node &phase, std::vector< ThermoPhase * > th)
Create a new kinetics manager.
void addReactions(Kinetics &kin, const AnyMap &phaseNode, const AnyMap &rootNode)
unique_ptr< Kinetics > newKinetics(vector< ThermoPhase * > &phases, const AnyMap &phaseNode, const AnyMap &rootNode)