| Cantera 3.0.0

Loading...
Searching...
No Matches
TransportFactory.cpp
Go to the documentation of this file.
1//! @file TransportFactory.cpp Implementation file for class TransportFactory.
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
6// known transport models
7#include "cantera/transport/MultiTransport.h"
8#include "cantera/transport/MixTransport.h"
9#include "cantera/transport/UnityLewisTransport.h"
10#include "cantera/transport/IonGasTransport.h"
11#include "cantera/transport/WaterTransport.h"
12#include "cantera/transport/DustyGasTransport.h"
13#include "cantera/transport/HighPressureGasTransport.h"
14#include "cantera/transport/TransportFactory.h"
15#include "cantera/base/stringUtils.h"
16#include "cantera/base/utilities.h"
17
18 namespace Cantera
19{
20TransportFactory* TransportFactory::s_factory = 0;
21
22// declaration of static storage for the mutex
23std::mutex TransportFactory::transport_mutex;
24
25//////////////////// class TransportFactory methods //////////////
26
27 TransportFactory::TransportFactory()
28{
29 reg("none", []() { return new Transport(); });
30 addDeprecatedAlias("none", "Transport");
31 addDeprecatedAlias("none", "None");
32 addDeprecatedAlias("none", "");
33 reg("unity-Lewis-number", []() { return new UnityLewisTransport(); });
34 addDeprecatedAlias("unity-Lewis-number", "UnityLewis");
35 reg("mixture-averaged", []() { return new MixTransport(); });
36 addDeprecatedAlias("mixture-averaged", "Mix");
37 reg("mixture-averaged-CK", []() { return new MixTransport(); });
38 addDeprecatedAlias("mixture-averaged-CK", "CK_Mix");
39 reg("multicomponent", []() { return new MultiTransport(); });
40 addDeprecatedAlias("multicomponent", "Multi");
41 reg("multicomponent-CK", []() { return new MultiTransport(); });
42 addDeprecatedAlias("multicomponent-CK", "CK_Multi");
43 reg("ionized-gas", []() { return new IonGasTransport(); });
44 addDeprecatedAlias("ionized-gas", "Ion");
45 reg("water", []() { return new WaterTransport(); });
46 addDeprecatedAlias("water", "Water");
47 reg("high-pressure", []() { return new HighPressureGasTransport(); });
48 addDeprecatedAlias("high-pressure", "HighP");
49 m_CK_mode["CK_Mix"] = m_CK_mode["mixture-averaged-CK"] = true;
50 m_CK_mode["CK_Multi"] = m_CK_mode["multicomponent-CK"] = true;
51}
52
53 TransportFactory* TransportFactory::factory() {
54 std::unique_lock<std::mutex> transportLock(transport_mutex);
55 if (!s_factory) {
56 s_factory = new TransportFactory();
57 }
58 return s_factory;
59}
60
61 void TransportFactory::deleteFactory()
62{
63 std::unique_lock<std::mutex> transportLock(transport_mutex);
64 delete s_factory;
65 s_factory = 0;
66}
67
68 Transport* TransportFactory::newTransport(const string& transportModel,
69 ThermoPhase* phase, int log_level)
70{
71 if (transportModel != "DustyGas" && canonicalize(transportModel) == "none") {
72 return create(transportModel);
73 }
74 if (!phase) {
75 throw CanteraError("TransportFactory::newTransport",
76 "Valid phase definition required for initialization of "
77 "new '{}' object", transportModel);
78 }
79
80 vector<double> state;
81 Transport* tr = 0;
82 phase->saveState(state);
83
84 if (transportModel == "DustyGas") {
85 tr = new DustyGasTransport;
86 Transport* gastr = new MultiTransport;
87 gastr->init(phase, 0, log_level);
88 DustyGasTransport* dtr = (DustyGasTransport*)tr;
89 dtr->initialize(phase, gastr);
90 } else {
91 tr = create(transportModel);
92 int mode = m_CK_mode[transportModel] ? CK_Mode : 0;
93 tr->init(phase, mode, log_level);
94 }
95 phase->restoreState(state);
96 return tr;
97}
98
99 Transport* TransportFactory::newTransport(ThermoPhase* phase, int log_level)
100{
101 string transportModel = "none";
102 AnyMap& input = phase->input();
103 if (input.hasKey("transport")) {
104 transportModel = input["transport"].asString();
105 }
106 return newTransport(transportModel, phase,log_level);
107}
108
109 Transport* newTransportMgr(const string& model, ThermoPhase* thermo, int log_level)
110{
111 warn_deprecated("newTransportMgr",
112 "To be removed after Cantera 3.0; superseded by newTransport.");
113 TransportFactory* f = TransportFactory::factory();
114 return f->newTransport(model, thermo, log_level);
115}
116
117shared_ptr<Transport> newTransport(shared_ptr<ThermoPhase> thermo, const string& model)
118{
119 Transport* tr;
120 if (model == "default") {
121 tr = TransportFactory::factory()->newTransport(thermo.get(), 0);
122 } else {
123 tr = TransportFactory::factory()->newTransport(model, thermo.get(), 0);
124 }
125 return shared_ptr<Transport>(tr);
126}
127
128shared_ptr<Transport> newTransport(ThermoPhase* thermo, const string& model)
129{
130 warn_deprecated("newTransport",
131 "To be removed after Cantera 3.0; superseded by\n"
132 "newTransport(shared_ptr<ThermoPhase>, const string&).");
133 Transport* tr;
134 if (model == "default") {
135 tr = TransportFactory::factory()->newTransport(thermo, 0);
136 } else {
137 tr = TransportFactory::factory()->newTransport(model, thermo, 0);
138 }
139 return shared_ptr<Transport>(tr);
140}
141
142 Transport* newDefaultTransportMgr(ThermoPhase* thermo, int loglevel)
143{
144 warn_deprecated("newDefaultTransportMgr",
145 "To be removed after Cantera 3.0; superseded by newTransport.");
146 return TransportFactory::factory()->newTransport(thermo, loglevel);
147}
148
149}
DustyGasTransport.h
Headers for the DustyGasTransport object, which models transport properties in porous media using the...
HighPressureGasTransport.h
Interface for class HighPressureGasTransport.
IonGasTransport.h
MixTransport.h
Headers for the MixTransport object, which models transport properties in ideal gas solutions using a...
MultiTransport.h
Interface for class MultiTransport.
TransportFactory.h
Header file defining class TransportFactory (see TransportFactory)
UnityLewisTransport.h
Headers for the UnityLewisTransport object, which models transport properties in ideal gas solutions ...
WaterTransport.h
Header file defining class WaterTransport.
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
Cantera::AnyMap::hasKey
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1423
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::DustyGasTransport
Class DustyGasTransport implements the Dusty Gas model for transport in porous media.
Definition DustyGasTransport.h:53
Cantera::DustyGasTransport::initialize
void initialize(ThermoPhase *phase, Transport *gastr)
Initialization routine called by TransportFactory.
Definition DustyGasTransport.cpp:27
Cantera::Factory< Transport >::create
Transport * create(const string &name, Args... args)
Create an object using the object construction function corresponding to "name" and the provided cons...
Definition FactoryBase.h:75
Cantera::Factory< Transport >::reg
void reg(const string &name, function< Transport *(Args...)> f)
Register a new object construction function.
Definition FactoryBase.h:80
Cantera::Factory< Transport >::canonicalize
string canonicalize(const string &name)
Get the canonical name registered for a type.
Definition FactoryBase.h:94
Cantera::Factory< Transport >::addDeprecatedAlias
void addDeprecatedAlias(const string &original, const string &alias)
Add a deprecated alias for an existing registered type.
Definition FactoryBase.h:116
Cantera::HighPressureGasTransport
Class MultiTransport implements transport properties for high pressure gas mixtures.
Definition HighPressureGasTransport.h:41
Cantera::IonGasTransport
Class IonGasTransport implements Stockmayer-(n,6,4) model for transport of ions.
Definition IonGasTransport.h:35
Cantera::MixTransport
Class MixTransport implements mixture-averaged transport properties for ideal gas mixtures.
Definition MixTransport.h:55
Cantera::MultiTransport
Class MultiTransport implements multicomponent transport properties for ideal gas mixtures.
Definition MultiTransport.h:26
Cantera::Phase::restoreState
void restoreState(const vector< double > &state)
Restore a state saved on a previous call to saveState.
Definition Phase.cpp:275
Cantera::Phase::saveState
void saveState(vector< double > &state) const
Save the current internal state of the phase.
Definition Phase.cpp:251
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition ThermoPhase.h:390
Cantera::ThermoPhase::input
const AnyMap & input() const
Access input data associated with the phase description.
Definition ThermoPhase.cpp:1229
Cantera::TransportFactory
Factory class for creating new instances of classes derived from Transport.
Definition TransportFactory.h:31
Cantera::TransportFactory::s_factory
static TransportFactory * s_factory
Static instance of the factor -> This is the only instance of this object allowed.
Definition TransportFactory.h:71
Cantera::TransportFactory::deleteFactory
void deleteFactory() override
Deletes the statically allocated factory instance.
Definition TransportFactory.cpp:61
Cantera::TransportFactory::factory
static TransportFactory * factory()
Return a pointer to a TransportFactory instance.
Definition TransportFactory.cpp:53
Cantera::TransportFactory::transport_mutex
static std::mutex transport_mutex
Static instance of the mutex used to ensure the proper reading of the transport database.
Definition TransportFactory.h:75
Cantera::TransportFactory::m_CK_mode
map< string, bool > m_CK_mode
Models included in this map are initialized in CK compatibility mode.
Definition TransportFactory.h:86
Cantera::TransportFactory::TransportFactory
TransportFactory()
The constructor is private; use static method factory() to get a pointer to a factory instance.
Definition TransportFactory.cpp:27
Cantera::TransportFactory::newTransport
Transport * newTransport(const string &model, ThermoPhase *thermo, int log_level=0)
Build a new transport manager using a transport manager that may not be the same as in the phase desc...
Definition TransportFactory.cpp:68
Cantera::Transport
Base class for transport property managers.
Definition Transport.h:146
Cantera::Transport::init
virtual void init(ThermoPhase *thermo, int mode=0, int log_level=0)
Initialize a transport manager.
Definition Transport.h:778
Cantera::UnityLewisTransport
Class UnityLewisTransport implements the unity Lewis number approximation for the mixture-averaged sp...
Definition UnityLewisTransport.h:26
Cantera::WaterTransport
Transport Parameters for pure water.
Definition WaterTransport.h:20
Cantera::newTransport
shared_ptr< Transport > newTransport(shared_ptr< ThermoPhase > thermo, const string &model)
Create a new Transport instance.
Definition TransportFactory.cpp:117
Cantera::newDefaultTransportMgr
Transport * newDefaultTransportMgr(ThermoPhase *thermo, int loglevel)
Create a new transport manager instance.
Definition TransportFactory.cpp:142
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::newTransportMgr
Transport * newTransportMgr(const string &model, ThermoPhase *thermo, int log_level)
Build a new transport manager using a transport manager that may not be the same as in the phase desc...
Definition TransportFactory.cpp:109
Cantera::warn_deprecated
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1926
stringUtils.h
Contains declarations for string manipulation functions within Cantera.
utilities.h
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...