Cantera  2.1.2
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"
11 #include "cantera/base/xml.h"
13 #include "cantera/base/ct_thread.h"
14 
15 namespace Cantera
16 {
17 
18 class UnknownKineticsModel : public CanteraError
19 {
20 public:
21  UnknownKineticsModel(const std::string& proc, const std::string& kineticsModel) :
22  CanteraError(proc, "Specified Kinetics model "
23  + kineticsModel +
24  " does not match any known type.") {}
25 };
26 
27 /**
28  * Factory for kinetics managers.
29  */
31 {
32 public:
33  static KineticsFactory* factory() {
34  ScopedLock lock(kinetics_mutex);
35  if (!s_factory) {
36  s_factory = new KineticsFactory;
37  }
38  return s_factory;
39  }
40 
41  virtual void deleteFactory() {
42  ScopedLock lock(kinetics_mutex);
43  if (s_factory) {
44  delete s_factory ;
45  s_factory = 0 ;
46  }
47  }
48 
49  /**
50  * Return a new kinetics manager that implements a reaction mechanism
51  * specified in a CTML file. In other words, the kinetics manager, given
52  * the rate constants and formulation of the reactions that make up a
53  * kinetics mechanism, is responsible for calculating the rates of
54  * progress of the reactions and for calculating the source terms for
55  * species.
56  *
57  * @param phase An XML_Node that contains the xml data describing the
58  * phase. Of particular note to this routine is the child xml
59  * element called "kinetics". The element has one attribute
60  * called "model", with a string value. The value of this
61  * string is used to decide which kinetics manager is used to
62  * calculate the reaction mechanism.
63  * @param th Vector of phases. The first phase is the phase in which
64  * the reactions occur, and the subsequent phases (if any)
65  * are e.g. bulk phases adjacent to a reacting surface.
66  *
67  * @return Pointer to the new kinetics manager.
68  */
69  virtual Kinetics* newKinetics(XML_Node& phase,
70  std::vector<ThermoPhase*> th);
71 
72  /**
73  * Return a new, empty kinetics manager.
74  */
75  virtual Kinetics* newKinetics(const std::string& model);
76 
77 private:
78  static KineticsFactory* s_factory;
79  KineticsFactory() {}
80  static mutex_t kinetics_mutex;
81 };
82 
83 /**
84  * Create a new kinetics manager.
85  */
87  std::vector<ThermoPhase*> th, KineticsFactory* f=0)
88 {
89  if (f == 0) {
90  f = KineticsFactory::factory();
91  }
92  return f->newKinetics(phase, th);
93 }
94 
95 /**
96  * Create a new kinetics manager.
97  */
98 inline Kinetics* newKineticsMgr(const std::string& model, KineticsFactory* f=0)
99 {
100  if (f == 0) {
101  f = KineticsFactory::factory();
102  }
103  return f->newKinetics(model);
104 }
105 }
106 
107 #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.
Classes providing support for XML data files.
Public interface for kinetics managers.
Definition: Kinetics.h:131
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.