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