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
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/ctml.h"
16#include "cantera/base/stringUtils.h"
17#include "cantera/base/utilities.h"
18
19 using namespace std;
20
21 namespace Cantera
22{
23TransportFactory* TransportFactory::s_factory = 0;
24
25// declaration of static storage for the mutex
26std::mutex TransportFactory::transport_mutex;
27
28//////////////////// class TransportFactory methods //////////////
29
30 TransportFactory::TransportFactory()
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
56 void TransportFactory::deleteFactory()
57{
58 std::unique_lock<std::mutex> transportLock(transport_mutex);
59 delete s_factory;
60 s_factory = 0;
61}
62
63 Transport* 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);
83 DustyGasTransport* dtr = (DustyGasTransport*)tr;
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
94 Transport* TransportFactory::newTransport(ThermoPhase* phase, int log_level)
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
107 Transport* newTransportMgr(const std::string& model, ThermoPhase* thermo, int log_level)
108{
109 TransportFactory* f = TransportFactory::factory();
110 return f->newTransport(model, thermo, log_level);
111}
112
113 Transport* newDefaultTransportMgr(ThermoPhase* thermo, int loglevel)
114{
115 return TransportFactory::factory()->newTransport(thermo, loglevel);
116}
117
118}
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:399
Cantera::AnyMap::hasKey
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:1406
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::DustyGasTransport
Class DustyGasTransport implements the Dusty Gas model for transport in porous media.
Definition: DustyGasTransport.h:63
Cantera::DustyGasTransport::initialize
void initialize(ThermoPhase *phase, Transport *gastr)
Initialization routine called by TransportFactory.
Definition: DustyGasTransport.cpp:38
Cantera::Factory< Transport >::canonicalize
std::string canonicalize(const std::string &name)
Get the canonical name registered for a type.
Definition: FactoryBase.h:95
Cantera::Factory< Transport >::create
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
Cantera::Factory< Transport >::addAlias
void addAlias(const std::string &original, const std::string &alias)
Add an alias for an existing registered type.
Definition: FactoryBase.h:86
Cantera::Factory< Transport >::reg
void reg(const std::string &name, std::function< Transport *(Args...)> f)
Register a new object construction function.
Definition: FactoryBase.h:81
Cantera::HighPressureGasTransport
Class MultiTransport implements transport properties for high pressure gas mixtures.
Definition: HighPressureGasTransport.h:39
Cantera::IonGasTransport
Class IonGasTransport implements Stockmayer-(n,6,4) model for transport of ions.
Definition: IonGasTransport.h:50
Cantera::MixTransport
Class MixTransport implements mixture-averaged transport properties for ideal gas mixtures.
Definition: MixTransport.h:57
Cantera::MultiTransport
Class MultiTransport implements multicomponent transport properties for ideal gas mixtures.
Definition: MultiTransport.h:27
Cantera::Phase::xml
XML_Node & xml() const
Returns a const reference to the XML_Node that describes the phase.
Definition: Phase.cpp:46
Cantera::Phase::saveState
void saveState(vector_fp &state) const
Save the current internal state of the phase.
Definition: Phase.cpp:286
Cantera::Phase::restoreState
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
Definition: Phase.cpp:310
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
Cantera::ThermoPhase::input
const AnyMap & input() const
Access input data associated with the phase description.
Definition: ThermoPhase.cpp:1268
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:77
Cantera::TransportFactory::deleteFactory
virtual void deleteFactory()
Deletes the statically allocated factory instance.
Definition: TransportFactory.cpp:56
Cantera::TransportFactory::factory
static TransportFactory * factory()
Return a pointer to a TransportFactory instance.
Definition: TransportFactory.h:45
Cantera::TransportFactory::m_CK_mode
std::map< std::string, bool > m_CK_mode
Models included in this map are initialized in CK compatibility mode.
Definition: TransportFactory.h:92
Cantera::TransportFactory::newTransport
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...
Definition: TransportFactory.cpp:63
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:81
Cantera::TransportFactory::TransportFactory
TransportFactory()
The constructor is private; use static method factory() to get a pointer to a factory instance.
Definition: TransportFactory.cpp:30
Cantera::Transport
Base class for transport property managers.
Definition: TransportBase.h:138
Cantera::Transport::init
virtual void init(ThermoPhase *thermo, int mode=0, int log_level=0)
Initialize a transport manager.
Definition: TransportBase.h:734
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::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Cantera::XML_Node::attrib
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:493
Cantera::XML_Node::hasChild
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:529
Cantera::XML_Node::child
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.h
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
Cantera::newDefaultTransportMgr
Transport * newDefaultTransportMgr(ThermoPhase *thermo, int loglevel)
Create a new transport manager instance.
Definition: TransportFactory.cpp:113
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::newTransportMgr
Transport * newTransportMgr(const std::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:107
Cantera::vector_fp
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
stringUtils.h
Contains declarations for string manipulation functions within Cantera.
utilities.h
Various templated functions that carry out common vector operations (see Templated Utility Functions)...