Cantera  3.2.0
Loading...
Searching...
No Matches
ConnectorFactory.cpp
Go to the documentation of this file.
1//! @file ConnectorFactory.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
10
11namespace Cantera
12{
13
14ConnectorFactory* ConnectorFactory::s_factory = 0;
15std::mutex ConnectorFactory::connector_mutex;
16
17ConnectorFactory::ConnectorFactory()
18{
19 reg("MassFlowController",
20 [](shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1, const string& name)
21 { return new MassFlowController(r0, r1, name); });
22 reg("PressureController",
23 [](shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1, const string& name)
24 { return new PressureController(r0, r1, name); });
25 reg("Valve",
26 [](shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1, const string& name)
27 { return new Valve(r0, r1, name); });
28 reg("Wall",
29 [](shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1, const string& name)
30 { return new Wall(r0, r1, name); });
31}
32
33ConnectorFactory* ConnectorFactory::factory() {
34 std::unique_lock<std::mutex> lock(connector_mutex);
35 if (!s_factory) {
36 s_factory = new ConnectorFactory;
37 }
38 return s_factory;
39}
40
42 std::unique_lock<std::mutex> lock(connector_mutex);
43 delete s_factory;
44 s_factory = 0;
45}
46
47shared_ptr<ConnectorNode> newConnectorNode(
48 const string& model,
49 shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1, const string& name)
50{
51 return shared_ptr<ConnectorNode>(
52 ConnectorFactory::factory()->create(model, r0, r1, name));
53}
54
55shared_ptr<FlowDevice> newFlowDevice(
56 const string& model,
57 shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1, const string& name)
58{
59 auto dev = std::dynamic_pointer_cast<FlowDevice>(
60 newConnectorNode(model, r0, r1, name));
61 if (!dev) {
62 throw CanteraError("newFlowDevice",
63 "Detected incompatible ConnectorNode type '{}'", model);
64 }
65 return dev;
66}
67
68shared_ptr<FlowDevice> newFlowDevice(const string& model, const string& name)
69{
70 warn_deprecated("newFlowDevice",
71 "After Cantera 3.2, Reactors must be provided as parameters.");
72 return newFlowDevice(model, nullptr, nullptr, name);
73}
74
75shared_ptr<WallBase> newWall(
76 const string& model,
77 shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1, const string& name)
78{
79 auto wall = std::dynamic_pointer_cast<WallBase>(
80 newConnectorNode(model, r0, r1, name));
81 if (!wall) {
82 throw CanteraError("newWall",
83 "Detected incompatible ConnectorNode type '{}'", model);
84 }
85 return wall;
86}
87
88shared_ptr<WallBase> newWall(const string& model, const string& name)
89{
90 warn_deprecated("newWall",
91 "After Cantera 3.2, Reactors must be provided as parameters.");
92 return newWall(model, nullptr, nullptr, name);
93}
94
95}
Header file for base class WallBase.
Base class for exceptions thrown by Cantera classes.
Factory class to create ConnectorNode objects.
void deleteFactory() override
Virtual abstract function that deletes the factory.
Some flow devices derived from class FlowDevice.
shared_ptr< FlowDevice > newFlowDevice(const string &model, shared_ptr< ReactorBase > r0, shared_ptr< ReactorBase > r1, const string &name)
Create a FlowDevice object of the specified type.
shared_ptr< WallBase > newWall(const string &model, shared_ptr< ReactorBase > r0, shared_ptr< ReactorBase > r1, const string &name)
Create a WallBase object of the specified type.
shared_ptr< ConnectorNode > newConnectorNode(const string &model, shared_ptr< ReactorBase > r0, shared_ptr< ReactorBase > r1, const string &name)
Create a ConnectorNode object of the specified type.
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