Cantera  2.1.2
ReactorFactory.cpp
Go to the documentation of this file.
1 /**
2  * @file ReactorFactory.cpp
3  */
4 // Copyright 2006 California Institute of Technology
5 
7 
13 #include "cantera/zeroD/IdealGasConstPressureReactor.h"
14 
15 using namespace std;
16 namespace Cantera
17 {
18 
19 ReactorFactory* ReactorFactory::s_factory = 0;
20 mutex_t ReactorFactory::reactor_mutex;
21 
22 static int ntypes = 6;
23 static string _types[] = {"Reservoir", "Reactor", "ConstPressureReactor",
24  "FlowReactor", "IdealGasReactor",
25  "IdealGasConstPressureReactor"
26  };
27 
28 // these constants are defined in ReactorBase.h
29 static int _itypes[] = {ReservoirType, ReactorType, ConstPressureReactorType,
30  FlowReactorType, IdealGasReactorType,
31  IdealGasConstPressureReactorType
32  };
33 
34 /**
35  * This method returns a new instance of a subclass of ThermoPhase
36  */
37 ReactorBase* ReactorFactory::newReactor(const std::string& reactorType)
38 {
39 
40  int ir=-1;
41 
42  for (int n = 0; n < ntypes; n++) {
43  if (reactorType == _types[n]) {
44  ir = _itypes[n];
45  }
46  }
47 
48  return newReactor(ir);
49 }
50 
51 
52 ReactorBase* ReactorFactory::newReactor(int ir)
53 {
54  switch (ir) {
55  case ReservoirType:
56  return new Reservoir();
57  case ReactorType:
58  return new Reactor();
59  case FlowReactorType:
60  return new FlowReactor();
61  case ConstPressureReactorType:
62  return new ConstPressureReactor();
63  case IdealGasReactorType:
64  return new IdealGasReactor();
65  case IdealGasConstPressureReactorType:
66  return new IdealGasConstPressureReactor();
67  default:
68  throw Cantera::CanteraError("ReactorFactory::newReactor",
69  "unknown reactor type!");
70  }
71  return 0;
72 }
73 
74 }
75 
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68