Cantera  3.2.0a2
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, const string& name)
29 { return new Reservoir(sol, name); });
30 reg("Reactor",
31 [](shared_ptr<Solution> sol, const string& name)
32 { return new Reactor(sol, name); });
33 reg("ConstPressureReactor",
34 [](shared_ptr<Solution> sol, const string& name)
35 { return new ConstPressureReactor(sol, name); });
36 reg("FlowReactor",
37 [](shared_ptr<Solution> sol, const string& name)
38 { return new FlowReactor(sol, name); });
39 reg("IdealGasReactor",
40 [](shared_ptr<Solution> sol, const string& name)
41 { return new IdealGasReactor(sol, name); });
42 reg("IdealGasConstPressureReactor",
43 [](shared_ptr<Solution> sol, const string& name)
44 { return new IdealGasConstPressureReactor(sol, name); });
45 reg("ExtensibleReactor",
46 [](shared_ptr<Solution> sol, const string& name)
47 { return new ReactorDelegator<Reactor>(sol, name); });
48 reg("ExtensibleIdealGasReactor",
49 [](shared_ptr<Solution> sol, const string& name)
50 { return new ReactorDelegator<IdealGasReactor>(sol, name); });
51 reg("ExtensibleConstPressureReactor",
52 [](shared_ptr<Solution> sol, const string& name)
53 { return new ReactorDelegator<ConstPressureReactor>(sol, name); });
54 reg("ExtensibleIdealGasConstPressureReactor",
55 [](shared_ptr<Solution> sol, const string& name)
56 { return new ReactorDelegator<IdealGasConstPressureReactor>(sol, name); });
57 reg("ExtensibleMoleReactor",
58 [](shared_ptr<Solution> sol, const string& name)
59 { return new ReactorDelegator<MoleReactor>(sol, name); });
60 reg("ExtensibleConstPressureMoleReactor",
61 [](shared_ptr<Solution> sol, const string& name)
62 { return new ReactorDelegator<ConstPressureMoleReactor>(sol, name); });
63 reg("ExtensibleIdealGasMoleReactor",
64 [](shared_ptr<Solution> sol, const string& name)
65 { return new ReactorDelegator<IdealGasMoleReactor>(sol, name); });
66 reg("ExtensibleIdealGasConstPressureMoleReactor",
67 [](shared_ptr<Solution> sol, const string& name)
68 { return new ReactorDelegator<IdealGasConstPressureMoleReactor>(sol, name); });
69 reg("IdealGasConstPressureMoleReactor",
70 [](shared_ptr<Solution> sol, const string& name)
71 { return new IdealGasConstPressureMoleReactor(sol, name); });
72 reg("IdealGasMoleReactor",
73 [](shared_ptr<Solution> sol, const string& name)
74 { return new IdealGasMoleReactor(sol, name); });
75 reg("ConstPressureMoleReactor",
76 [](shared_ptr<Solution> sol, const string& name)
77 { return new ConstPressureMoleReactor(sol, name); });
78 reg("MoleReactor",
79 [](shared_ptr<Solution> sol, const string& name)
80 { return new MoleReactor(sol, name); });
81 reg("ReactorSurface",
82 [](shared_ptr<Solution> sol, const string& name)
83 { return new ReactorSurface(sol, name); });
84}
85
86ReactorFactory* ReactorFactory::factory() {
87 std::unique_lock<std::mutex> lock(reactor_mutex);
88 if (!s_factory) {
89 s_factory = new ReactorFactory;
90 }
91 return s_factory;
92}
93
95 std::unique_lock<std::mutex> lock(reactor_mutex);
96 delete s_factory;
97 s_factory = 0;
98}
99
100shared_ptr<ReactorBase> newReactorBase(
101 const string& model, shared_ptr<Solution> contents, const string& name)
102{
103 return shared_ptr<ReactorBase>(
104 ReactorFactory::factory()->create(model, contents, name));
105}
106
107shared_ptr<ReactorBase> newReactor(
108 const string& model, shared_ptr<Solution> contents, const string& name)
109{
110 warn_deprecated("newReactor", "Behavior changes after Cantera 3.2, when a "
111 "'shared_ptr<Reactor>' is returned.\nFor new behavior, use 'newReactor4'.");
112 return newReactorBase(model, contents, name);
113}
114
115shared_ptr<Reactor> newReactor4(
116 const string& model, shared_ptr<Solution> contents, const string& name)
117{
118 auto reactor = std::dynamic_pointer_cast<Reactor>(
119 newReactorBase(model, contents, name));
120 if (!reactor) {
121 throw CanteraError("newReactor4",
122 "Model type '{}' does not specify a bulk reactor.", model);
123 }
124 return reactor;
125}
126
127shared_ptr<Reservoir> newReservoir(shared_ptr<Solution> contents, const string& name)
128{
129 auto reservoir = std::dynamic_pointer_cast<Reservoir>(
130 newReactorBase("Reservoir", contents, name));
131 if (!reservoir) {
132 throw CanteraError("newReservoir",
133 "Caught unexpected inconsistency in factory method.");
134 }
135 return reservoir;
136}
137
138}
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< ReactorBase > newReactorBase(const string &model, shared_ptr< Solution > contents, const string &name)
Create a ReactorBase object of the specified type and contents.
shared_ptr< Reactor > newReactor4(const string &model, shared_ptr< Solution > contents, const string &name)
Create a Reactor object of the specified type and contents.
shared_ptr< Reservoir > newReservoir(shared_ptr< Solution > contents, 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