Cantera  2.3.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 http://www.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  virtual Kinetics* newKinetics(XML_Node& phase, std::vector<ThermoPhase*> th);
66 
67  /**
68  * Return a new, empty kinetics manager.
69  */
70  virtual Kinetics* newKinetics(const std::string& model);
71 
72 private:
73  static KineticsFactory* s_factory;
75  static std::mutex kinetics_mutex;
76 };
77 
78 /**
79  * Create a new kinetics manager.
80  * @deprecated The `KineticsFactory*` argument to this function is deprecated
81  * and will be removed after Cantera 2.3.
82  */
84  std::vector<ThermoPhase*> th, KineticsFactory* f=0)
85 {
86  if (f == 0) {
87  f = KineticsFactory::factory();
88  } else {
89  warn_deprecated("newKineticsMgr(XML_Node&, KineticsFactory*)",
90  "The `KineticsFactory*` argument to this function is deprecated and"
91  " will be removed after Cantera 2.3.");
92  }
93  return f->newKinetics(phase, th);
94 }
95 
96 /**
97  * Create a new kinetics manager.
98  * @deprecated The `KineticsFactory*` argument to this function is deprecated
99  * and will be removed after Cantera 2.3.
100  */
101 inline Kinetics* newKineticsMgr(const std::string& model, KineticsFactory* f=0)
102 {
103  if (f == 0) {
104  f = KineticsFactory::factory();
105  } else {
106  warn_deprecated("newKineticsMgr(string, KineticsFactory*)",
107  "The `KineticsFactory*` argument to this function is deprecated and"
108  " will be removed after Cantera 2.3.");
109  }
110  return f->newKinetics(model);
111 }
112 }
113 
114 #endif
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
Kinetics * newKineticsMgr(XML_Node &phase, std::vector< ThermoPhase *> th, KineticsFactory *f=0)
Create a new kinetics manager.
virtual void deleteFactory()
Virtual abstract function that deletes the factory.
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...
Public interface for kinetics managers.
Definition: Kinetics.h:111
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Factory class that supports registering functions to create objects.
Definition: FactoryBase.h:69
CanteraError(const std::string &procedure, const std::string &msg, const Args &... args)
Normal Constructor for the CanteraError base class.
Definition: ctexceptions.h:79
Namespace for the Cantera kernel.
Definition: application.cpp:29
File contains the FactoryBase class declarations.
Factory for kinetics managers.