Cantera 2.6.0
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
15#include "cantera/base/ctml.h"
18
19using namespace std;
20
21namespace Cantera
22{
23TransportFactory* TransportFactory::s_factory = 0;
24
25// declaration of static storage for the mutex
27
28//////////////////// class TransportFactory methods //////////////
29
31{
32 reg("none", []() { return new Transport(); });
33 addAlias("none", "Transport");
34 addAlias("none", "None");
35 addAlias("none", "");
36 reg("unity-Lewis-number", []() { return new UnityLewisTransport(); });
37 addAlias("unity-Lewis-number", "UnityLewis");
38 reg("mixture-averaged", []() { return new MixTransport(); });
39 addAlias("mixture-averaged", "Mix");
40 reg("mixture-averaged-CK", []() { return new MixTransport(); });
41 addAlias("mixture-averaged-CK", "CK_Mix");
42 reg("multicomponent", []() { return new MultiTransport(); });
43 addAlias("multicomponent", "Multi");
44 reg("multicomponent-CK", []() { return new MultiTransport(); });
45 addAlias("multicomponent-CK", "CK_Multi");
46 reg("ionized-gas", []() { return new IonGasTransport(); });
47 addAlias("ionized-gas", "Ion");
48 reg("water", []() { return new WaterTransport(); });
49 addAlias("water", "Water");
50 reg("high-pressure", []() { return new HighPressureGasTransport(); });
51 addAlias("high-pressure", "HighP");
52 m_CK_mode["CK_Mix"] = m_CK_mode["mixture-averaged-CK"] = true;
53 m_CK_mode["CK_Multi"] = m_CK_mode["multicomponent-CK"] = true;
54}
55
57{
58 std::unique_lock<std::mutex> transportLock(transport_mutex);
59 delete s_factory;
60 s_factory = 0;
61}
62
63Transport* TransportFactory::newTransport(const std::string& transportModel,
64 ThermoPhase* phase, int log_level)
65{
66 if (transportModel != "DustyGas" && canonicalize(transportModel) == "none") {
67 return create(transportModel);
68 }
69 if (!phase) {
70 throw CanteraError("TransportFactory::newTransport",
71 "Valid phase definition required for initialization of "
72 "new '{}' object", transportModel);
73 }
74
75 vector_fp state;
76 Transport* tr = 0;
77 phase->saveState(state);
78
79 if (transportModel == "DustyGas") {
80 tr = new DustyGasTransport;
81 Transport* gastr = new MultiTransport;
82 gastr->init(phase, 0, log_level);
84 dtr->initialize(phase, gastr);
85 } else {
86 tr = create(transportModel);
87 int mode = m_CK_mode[transportModel] ? CK_Mode : 0;
88 tr->init(phase, mode, log_level);
89 }
90 phase->restoreState(state);
91 return tr;
92}
93
95{
96 std::string transportModel = "None";
97 XML_Node& phaseNode = phase->xml();
98 AnyMap& input = phase->input();
99 if (input.hasKey("transport")) {
100 transportModel = input["transport"].asString();
101 } else if (phaseNode.hasChild("transport")) {
102 transportModel = phaseNode.child("transport").attrib("model");
103 }
104 return newTransport(transportModel, phase,log_level);
105}
106
107Transport* newTransportMgr(const std::string& model, ThermoPhase* thermo, int log_level)
108{
110 return f->newTransport(model, thermo, log_level);
111}
112
114{
115 return TransportFactory::factory()->newTransport(thermo, loglevel);
116}
117
118}
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:399
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:1406
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Class DustyGasTransport implements the Dusty Gas model for transport in porous media.
void initialize(ThermoPhase *phase, Transport *gastr)
Initialization routine called by TransportFactory.
std::string canonicalize(const std::string &name)
Get the canonical name registered for a type.
Definition: FactoryBase.h:95
Transport * create(const std::string &name, Args... args)
Create an object using the object construction function corresponding to "name" and the provided cons...
Definition: FactoryBase.h:76
void addAlias(const std::string &original, const std::string &alias)
Add an alias for an existing registered type.
Definition: FactoryBase.h:86
void reg(const std::string &name, std::function< Transport *(Args...)> f)
Register a new object construction function.
Definition: FactoryBase.h:81
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.
Definition: MixTransport.h:57
Class MultiTransport implements multicomponent transport properties for ideal gas mixtures.
XML_Node & xml() const
Returns a const reference to the XML_Node that describes the phase.
Definition: Phase.cpp:46
void saveState(vector_fp &state) const
Save the current internal state of the phase.
Definition: Phase.cpp:286
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
Definition: Phase.cpp:310
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
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.
virtual void deleteFactory()
Deletes the statically allocated factory instance.
static TransportFactory * factory()
Return a pointer to a TransportFactory instance.
std::map< std::string, bool > m_CK_mode
Models included in this map are initialized in CK compatibility mode.
virtual Transport * newTransport(const std::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...
static std::mutex transport_mutex
Static instance of the mutex used to ensure the proper reading of the transport database.
TransportFactory()
The constructor is private; use static method factory() to get a pointer to a factory instance.
Base class for transport property managers.
virtual void init(ThermoPhase *thermo, int mode=0, int log_level=0)
Initialize a transport manager.
Class UnityLewisTransport implements the unity Lewis number approximation for the mixture-averaged sp...
Transport Parameters for pure water.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:493
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:529
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:547
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
Transport * newDefaultTransportMgr(ThermoPhase *thermo, int loglevel=0)
Create a new transport manager instance.
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
Transport * newTransportMgr(const std::string &model="", ThermoPhase *thermo=0, int log_level=0)
Build a new transport manager using a transport manager that may not be the same as in the phase desc...
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:184
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...