Cantera  3.1.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
17
18namespace Cantera
19{
20TransportFactory* TransportFactory::s_factory = 0;
21
22// declaration of static storage for the mutex
24
25//////////////////// class TransportFactory methods //////////////
26
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
54 std::unique_lock<std::mutex> transportLock(transport_mutex);
55 if (!s_factory) {
57 }
58 return s_factory;
59}
60
62{
63 std::unique_lock<std::mutex> transportLock(transport_mutex);
64 delete s_factory;
65 s_factory = 0;
66}
67
68Transport* TransportFactory::newTransport(const string& transportModel,
69 ThermoPhase* phase, int log_level)
70{
71 if (log_level != -7) {
72 warn_deprecated("TransportFactory::newTransport", "The log_level parameter "
73 "is deprecated and will be removed after Cantera 3.1.");
74 }
75 if (transportModel != "DustyGas" && canonicalize(transportModel) == "none") {
76 return create(transportModel);
77 }
78 if (!phase) {
79 throw CanteraError("TransportFactory::newTransport",
80 "Valid phase definition required for initialization of "
81 "new '{}' object", transportModel);
82 }
83
84 vector<double> state;
85 Transport* tr = 0;
86 phase->saveState(state);
87
88 if (transportModel == "DustyGas") {
89 tr = new DustyGasTransport;
90 Transport* gastr = new MultiTransport;
91 gastr->init(phase, 0, log_level);
93 dtr->initialize(phase, gastr);
94 } else {
95 tr = create(transportModel);
96 int mode = m_CK_mode[transportModel] ? CK_Mode : 0;
97 tr->init(phase, mode, log_level);
98 }
99 phase->restoreState(state);
100 return tr;
101}
102
104{
105 if (log_level != -7) {
106 warn_deprecated("TransportFactory::newTransport", "The log_level parameter "
107 "is deprecated and will be removed after Cantera 3.1.");
108 }
109 string transportModel = "none";
110 AnyMap& input = phase->input();
111 if (input.hasKey("transport")) {
112 transportModel = input["transport"].asString();
113 }
114 return newTransport(transportModel, phase,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());
122 } else {
123 tr = TransportFactory::factory()->newTransport(model, thermo.get());
124 }
125 return shared_ptr<Transport>(tr);
126}
127
128}
Headers for the DustyGasTransport object, which models transport properties in porous media using the...
Interface for class HighPressureGasTransport.
Headers for the MixTransport object, which models transport properties in ideal gas solutions using a...
Interface for class MultiTransport.
Header file defining class TransportFactory (see TransportFactory)
Headers for the UnityLewisTransport object, which models transport properties in ideal gas solutions ...
Header file defining class WaterTransport.
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:431
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1477
Base class for exceptions thrown by Cantera classes.
Class DustyGasTransport implements the Dusty Gas model for transport in porous media.
void initialize(ThermoPhase *phase, Transport *gastr)
Initialization routine called by TransportFactory.
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
void reg(const string &name, function< Transport *(Args...)> f)
Register a new object construction function.
Definition FactoryBase.h:80
string canonicalize(const string &name)
Get the canonical name registered for a type.
Definition FactoryBase.h:94
void addDeprecatedAlias(const string &original, const string &alias)
Add a deprecated alias for an existing registered type.
Class MultiTransport implements transport properties for high pressure gas mixtures.
Class IonGasTransport implements Stockmayer-(n,6,4) model for transport of ions.
Class MixTransport implements mixture-averaged transport properties for ideal gas mixtures.
Class MultiTransport implements multicomponent transport properties for ideal gas mixtures.
void restoreState(const vector< double > &state)
Restore a state saved on a previous call to saveState.
Definition Phase.cpp:260
void saveState(vector< double > &state) const
Save the current internal state of the phase.
Definition Phase.cpp:236
Base class for a phase with thermodynamic properties.
const AnyMap & input() const
Access input data associated with the phase description.
Factory class for creating new instances of classes derived from Transport.
static TransportFactory * s_factory
Static instance of the factor -> This is the only instance of this object allowed.
Transport * newTransport(const string &model, ThermoPhase *thermo, int log_level=-7)
Build a new transport manager using a transport manager that may not be the same as in the phase desc...
void deleteFactory() override
Deletes the statically allocated factory instance.
static TransportFactory * factory()
Return a pointer to a TransportFactory instance.
static std::mutex transport_mutex
Static instance of the mutex used to ensure the proper reading of the transport database.
map< string, bool > m_CK_mode
Models included in this map are initialized in CK compatibility mode.
TransportFactory()
The constructor is private; use static method factory() to get a pointer to a factory instance.
Base class for transport property managers.
Definition Transport.h:72
virtual void init(ThermoPhase *thermo, int mode=0, int log_level=-7)
Initialize a transport manager.
Definition Transport.h:419
Class UnityLewisTransport implements the unity Lewis number approximation for the mixture-averaged sp...
Transport Parameters for pure water.
shared_ptr< Transport > newTransport(shared_ptr< ThermoPhase > thermo, const string &model)
Create a new Transport instance.
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
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...