Cantera  3.2.0a4
Loading...
Searching...
No Matches
ReactorFactory.cpp
Go to the documentation of this file.
1//! @file ReactorFactory.cpp
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
15#include "cantera/zeroD/IdealGasConstPressureReactor.h"
18
19namespace Cantera
20{
21
22ReactorFactory* ReactorFactory::s_factory = 0;
23std::mutex ReactorFactory::reactor_mutex;
24
25ReactorFactory::ReactorFactory()
26{
27 reg("Reservoir",
28 [](shared_ptr<Solution> sol, bool clone, const string& name)
29 { return new Reservoir(sol, clone, name); });
30 reg("Reactor",
31 [](shared_ptr<Solution> sol, bool clone, const string& name)
32 { return new Reactor(sol, clone, name); });
33 reg("ConstPressureReactor",
34 [](shared_ptr<Solution> sol, bool clone, const string& name)
35 { return new ConstPressureReactor(sol, clone, name); });
36 reg("FlowReactor",
37 [](shared_ptr<Solution> sol, bool clone, const string& name)
38 { return new FlowReactor(sol, clone, name); });
39 reg("IdealGasReactor",
40 [](shared_ptr<Solution> sol, bool clone, const string& name)
41 { return new IdealGasReactor(sol, clone, name); });
42 reg("IdealGasConstPressureReactor",
43 [](shared_ptr<Solution> sol, bool clone, const string& name)
44 { return new IdealGasConstPressureReactor(sol, clone, name); });
45 reg("ExtensibleReactor",
46 [](shared_ptr<Solution> sol, bool clone, const string& name)
47 { return new ReactorDelegator<Reactor>(sol, clone, name); });
48 reg("ExtensibleIdealGasReactor",
49 [](shared_ptr<Solution> sol, bool clone, const string& name)
50 { return new ReactorDelegator<IdealGasReactor>(sol, clone, name); });
51 reg("ExtensibleConstPressureReactor",
52 [](shared_ptr<Solution> sol, bool clone, const string& name)
53 { return new ReactorDelegator<ConstPressureReactor>(sol, clone, name); });
54 reg("ExtensibleIdealGasConstPressureReactor",
55 [](shared_ptr<Solution> sol, bool clone, const string& name)
56 { return new ReactorDelegator<IdealGasConstPressureReactor>(sol, clone, name); });
57 reg("ExtensibleMoleReactor",
58 [](shared_ptr<Solution> sol, bool clone, const string& name)
59 { return new ReactorDelegator<MoleReactor>(sol, clone, name); });
60 reg("ExtensibleConstPressureMoleReactor",
61 [](shared_ptr<Solution> sol, bool clone, const string& name)
62 { return new ReactorDelegator<ConstPressureMoleReactor>(sol, clone, name); });
63 reg("ExtensibleIdealGasMoleReactor",
64 [](shared_ptr<Solution> sol, bool clone, const string& name)
65 { return new ReactorDelegator<IdealGasMoleReactor>(sol, clone, name); });
66 reg("ExtensibleIdealGasConstPressureMoleReactor",
67 [](shared_ptr<Solution> sol, bool clone, const string& name)
68 { return new ReactorDelegator<IdealGasConstPressureMoleReactor>(sol, clone, name); });
69 reg("IdealGasConstPressureMoleReactor",
70 [](shared_ptr<Solution> sol, bool clone, const string& name)
71 { return new IdealGasConstPressureMoleReactor(sol, clone, name); });
72 reg("IdealGasMoleReactor",
73 [](shared_ptr<Solution> sol, bool clone, const string& name)
74 { return new IdealGasMoleReactor(sol, clone, name); });
75 reg("ConstPressureMoleReactor",
76 [](shared_ptr<Solution> sol, bool clone, const string& name)
77 { return new ConstPressureMoleReactor(sol, clone, name); });
78 reg("MoleReactor",
79 [](shared_ptr<Solution> sol, bool clone, const string& name)
80 { return new MoleReactor(sol, clone, name); });
81 // TODO: Remove after Cantera 3.2
82 reg("ReactorSurface",
83 [](shared_ptr<Solution> sol, bool clone, const string& name)
84 { return new ReactorSurface(sol, clone, name); });
85}
86
87ReactorFactory* ReactorFactory::factory() {
88 std::unique_lock<std::mutex> lock(reactor_mutex);
89 if (!s_factory) {
90 s_factory = new ReactorFactory;
91 }
92 return s_factory;
93}
94
96 std::unique_lock<std::mutex> lock(reactor_mutex);
97 delete s_factory;
98 s_factory = 0;
99}
100
101shared_ptr<ReactorBase> newReactorBase(
102 const string& model, shared_ptr<Solution> contents, bool clone, const string& name)
103{
104 return shared_ptr<ReactorBase>(
105 ReactorFactory::factory()->create(model, contents, clone, name));
106}
107
108shared_ptr<ReactorBase> newReactor(
109 const string& model, shared_ptr<Solution> contents, const string& name)
110{
111 warn_deprecated("newReactor", "Behavior changes after Cantera 3.2, when a "
112 "'shared_ptr<Reactor>' is returned.\nFor new behavior, use 'newReactor4'.");
113 warn_deprecated("newReactor", "`clone` argument not specified; Default behavior "
114 "will change from `clone=False` to `clone=True` after Cantera 3.2.\n"
115 "Use the transitional newReactor4() function to provide a value for the clone "
116 "argument");
117 return newReactorBase(model, contents, false, name);
118}
119
120shared_ptr<Reactor> newReactor4(
121 const string& model, shared_ptr<Solution> contents, bool clone, const string& name)
122{
123 auto reactor = std::dynamic_pointer_cast<Reactor>(
124 newReactorBase(model, contents, clone, name));
125 if (!reactor) {
126 throw CanteraError("newReactor4",
127 "Model type '{}' does not specify a bulk reactor.", model);
128 }
129 return reactor;
130}
131
132shared_ptr<Reservoir> newReservoir(
133 shared_ptr<Solution> contents, bool clone, const string& name)
134{
135 auto reservoir = std::dynamic_pointer_cast<Reservoir>(
136 newReactorBase("Reservoir", contents, clone, name));
137 if (!reservoir) {
138 throw CanteraError("newReservoir",
139 "Caught unexpected inconsistency in factory method.");
140 }
141 return reservoir;
142}
143
144shared_ptr<ReactorSurface> newReactorSurface(shared_ptr<Solution> contents,
145 const vector<shared_ptr<ReactorBase>>& reactors, bool clone, const string& name)
146{
147 return make_shared<ReactorSurface>(contents, reactors, clone, name);
148}
149
150}
Base class for exceptions thrown by Cantera classes.
void reg(const string &name, function< ReactorBase *(Args...)> f)
Register a new object construction function.
Definition FactoryBase.h:80
void deleteFactory() override
Virtual abstract function that deletes the factory.
shared_ptr< ReactorBase > newReactor(const string &model, shared_ptr< Solution > contents, const string &name)
Create a Reactor object of the specified type and contents.
shared_ptr< Reactor > newReactor4(const string &model, shared_ptr< Solution > contents, bool clone, const string &name)
Create a Reactor object of the specified type and contents.
shared_ptr< ReactorBase > newReactorBase(const string &model, shared_ptr< Solution > contents, bool clone, const string &name)
Create a ReactorBase object of the specified type and contents.
shared_ptr< ReactorSurface > newReactorSurface(shared_ptr< Solution > contents, const vector< shared_ptr< ReactorBase > > &reactors, bool clone, const string &name)
Create a ReactorSurface object with the specified contents and adjacent reactors participating in sur...
shared_ptr< Reservoir > newReservoir(shared_ptr< Solution > contents, bool clone, const string &name)
Create a Reservoir object with the specified contents.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1997