Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KineticsFactory.h
Go to the documentation of this file.
1 /**
2  * @file KineticsFactory.h
3  */
4 // Copyright 2001 California Institute of Technology
5 
6 
7 #ifndef KINETICS_FACTORY_H
8 #define KINETICS_FACTORY_H
9 
10 #include "Kinetics.h"
12 #include "cantera/base/ct_thread.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  */
30 {
31 public:
32  static KineticsFactory* factory() {
33  ScopedLock lock(kinetics_mutex);
34  if (!s_factory) {
35  s_factory = new KineticsFactory;
36  }
37  return s_factory;
38  }
39 
40  virtual void deleteFactory() {
41  ScopedLock 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  *
64  * @return Pointer to the new kinetics manager.
65  */
66  virtual Kinetics* newKinetics(XML_Node& phase, std::vector<ThermoPhase*> th);
67 
68  /**
69  * Return a new, empty kinetics manager.
70  */
71  virtual Kinetics* newKinetics(const std::string& model);
72 
73 private:
74  static KineticsFactory* s_factory;
75  KineticsFactory() {}
76  static mutex_t kinetics_mutex;
77 };
78 
79 /**
80  * Create a new kinetics manager.
81  */
83  std::vector<ThermoPhase*> th, KineticsFactory* f=0)
84 {
85  if (f == 0) {
86  f = KineticsFactory::factory();
87  }
88  return f->newKinetics(phase, th);
89 }
90 
91 /**
92  * Create a new kinetics manager.
93  */
94 inline Kinetics* newKineticsMgr(const std::string& model, KineticsFactory* f=0)
95 {
96  if (f == 0) {
97  f = KineticsFactory::factory();
98  }
99  return f->newKinetics(model);
100 }
101 }
102 
103 #endif
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
Base class for factories.
Definition: FactoryBase.h:18
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...
Kinetics * newKineticsMgr(XML_Node &phase, std::vector< ThermoPhase * > th, KineticsFactory *f=0)
Create a new kinetics manager.
Public interface for kinetics managers.
Definition: Kinetics.h:128
CanteraError(const std::string &procedure, const std::string &msg)
Normal Constructor for the CanteraError base class.
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
File contains the FactoryBase class declarations.
Factory for kinetics managers.