Cantera  2.4.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  */
81 inline Kinetics* newKineticsMgr(XML_Node& phase, std::vector<ThermoPhase*> th)
82 {
83  return KineticsFactory::factory()->newKinetics(phase, th);
84 }
85 
86 /**
87  * Create a new kinetics manager.
88  */
89 inline Kinetics* newKineticsMgr(const std::string& model)
90 {
91  return KineticsFactory::factory()->newKinetics(model);
92 }
93 
94 }
95 
96 #endif
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
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:110
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:71
CanteraError(const std::string &procedure, const std::string &msg, const Args &... args)
Normal Constructor for the CanteraError base class.
Definition: ctexceptions.h:79
Kinetics * newKineticsMgr(XML_Node &phase, std::vector< ThermoPhase *> th)
Create a new kinetics manager.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
File contains the FactoryBase class declarations.
Factory for kinetics managers.