Cantera  2.5.1
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"
17 #include "cantera/base/utilities.h"
18 
19 using namespace std;
20 
21 namespace Cantera
22 {
23 TransportFactory* TransportFactory::s_factory = 0;
24 
25 // declaration of static storage for the mutex
26 std::mutex TransportFactory::transport_mutex;
27 
28 //! Exception thrown if an error is encountered while reading the transport database
29 //! @deprecated Unused. To be removed after Cantera 2.5.
31 {
32 public:
33  //! Default constructor
34  /*!
35  * @param linenum inputs the line number
36  * @param msg String message to be sent to the user
37  */
38  TransportDBError(size_t linenum, const std::string& msg) :
39  CanteraError("getTransportData", "error reading transport data: " + msg + "\n") {
40  warn_deprecated("class TransportDBError",
41  "Unused. To be removed after Cantera 2.5.");
42  }
43 };
44 
45 //////////////////// class TransportFactory methods //////////////
46 
47 TransportFactory::TransportFactory()
48 {
49  reg("", []() { return new Transport(); });
50  addAlias("", "None");
51  reg("unity-Lewis-number", []() { return new UnityLewisTransport(); });
52  addAlias("unity-Lewis-number", "UnityLewis");
53  reg("mixture-averaged", []() { return new MixTransport(); });
54  addAlias("mixture-averaged", "Mix");
55  reg("mixture-averaged-CK", []() { return new MixTransport(); });
56  addAlias("mixture-averaged-CK", "CK_Mix");
57  reg("multicomponent", []() { return new MultiTransport(); });
58  addAlias("multicomponent", "Multi");
59  reg("multicomponent-CK", []() { return new MultiTransport(); });
60  addAlias("multicomponent-CK", "CK_Multi");
61  reg("ionized-gas", []() { return new IonGasTransport(); });
62  addAlias("ionized-gas", "Ion");
63  reg("water", []() { return new WaterTransport(); });
64  addAlias("water", "Water");
65  reg("high-pressure", []() { return new HighPressureGasTransport(); });
66  addAlias("high-pressure", "HighP");
67  m_CK_mode["CK_Mix"] = m_CK_mode["mixture-averaged-CK"] = true;
68  m_CK_mode["CK_Multi"] = m_CK_mode["multicomponent-CK"] = true;
69 }
70 
71 void TransportFactory::deleteFactory()
72 {
73  std::unique_lock<std::mutex> transportLock(transport_mutex);
74  delete s_factory;
75  s_factory = 0;
76 }
77 
78 Transport* TransportFactory::newTransport(const std::string& transportModel,
79  thermo_t* phase, int log_level, int ndim)
80 {
81  if (ndim != -99) {
82  warn_deprecated("TransportFactory::newTransport", "The 'ndim' parameter"
83  " is unused and will be removed after Cantera 2.5.");
84  }
85  vector_fp state;
86  Transport* tr = 0;
87  phase->saveState(state);
88 
89  if (transportModel == "DustyGas") {
90  tr = new DustyGasTransport;
91  Transport* gastr = new MultiTransport;
92  gastr->init(phase, 0, log_level);
94  dtr->initialize(phase, gastr);
95  } else {
96  tr = create(transportModel);
97  int mode = m_CK_mode[transportModel] ? CK_Mode : 0;
98  tr->init(phase, mode, log_level);
99  }
100  phase->restoreState(state);
101  return tr;
102 }
103 
104 Transport* TransportFactory::newTransport(thermo_t* phase, int log_level)
105 {
106  std::string transportModel = "None";
107  XML_Node& phaseNode = phase->xml();
108  AnyMap& input = phase->input();
109  if (input.hasKey("transport")) {
110  transportModel = input["transport"].asString();
111  } else if (phaseNode.hasChild("transport")) {
112  transportModel = phaseNode.child("transport").attrib("model");
113  }
114  return newTransport(transportModel, phase,log_level);
115 }
116 
117 Transport* newTransportMgr(const std::string& transportModel, thermo_t* thermo, int loglevel, int ndim)
118 {
119  TransportFactory* f = TransportFactory::factory();
120  return f->newTransport(transportModel, thermo, loglevel, ndim);
121 }
122 
124 {
125  return TransportFactory::factory()->newTransport(thermo, loglevel);
126 }
127 
128 }
Cantera::DustyGasTransport::initialize
void initialize(ThermoPhase *phase, Transport *gastr)
Initialization routine called by TransportFactory.
Definition: DustyGasTransport.cpp:36
TransportFactory.h
Cantera::Phase::xml
XML_Node & xml() const
Returns a const reference to the XML_Node that describes the phase.
Definition: Phase.cpp:45
UnityLewisTransport.h
MultiTransport.h
HighPressureGasTransport.h
DustyGasTransport.h
Cantera::warn_deprecated
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
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:528
Cantera::TransportFactory
Factory class for creating new instances of classes derived from Transport.
Definition: TransportFactory.h:30
Cantera::AnyMap::hasKey
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:984
Cantera::XML_Node::attrib
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:492
Cantera::HighPressureGasTransport
Class MultiTransport implements transport properties for high pressure gas mixtures.
Definition: HighPressureGasTransport.h:38
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:180
Cantera::newTransportMgr
Transport * newTransportMgr(const std::string &transportModel, thermo_t *thermo, int loglevel, int ndim)
Build a new transport manager using a transport manager that may not be the same as in the phase desc...
Definition: TransportFactory.cpp:117
Cantera::UnityLewisTransport
Class UnityLewisTransport implements the unity Lewis number approximation for the mixture-averaged sp...
Definition: UnityLewisTransport.h:24
Cantera::IonGasTransport
Class IonGasTransport implements Stockmayer-(n,6,4) model for transport of ions.
Definition: IonGasTransport.h:49
Cantera::MultiTransport
Class MultiTransport implements multicomponent transport properties for ideal gas mixtures.
Definition: MultiTransport.h:26
Cantera::TransportFactory::newTransport
virtual Transport * newTransport(const std::string &model, thermo_t *thermo, int log_level=0, int ndim=-99)
Build a new transport manager using a transport manager that may not be the same as in the phase desc...
Definition: TransportFactory.cpp:78
Cantera::TransportDBError::TransportDBError
TransportDBError(size_t linenum, const std::string &msg)
Default constructor.
Definition: TransportFactory.cpp:38
Cantera::ThermoPhase::input
const AnyMap & input() const
Access input data associated with the phase description.
Definition: ThermoPhase.cpp:1186
Cantera::WaterTransport
Transport Parameters for pure water.
Definition: WaterTransport.h:19
Cantera::Transport::init
virtual void init(thermo_t *thermo, int mode=0, int log_level=0)
Initialize a transport manager.
Definition: TransportBase.h:640
Cantera::MixTransport
Class MixTransport implements mixture-averaged transport properties for ideal gas mixtures.
Definition: MixTransport.h:56
Cantera::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Cantera::Phase::saveState
void saveState(vector_fp &state) const
Save the current internal state of the phase.
Definition: Phase.cpp:315
Cantera::Phase::restoreState
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
Definition: Phase.cpp:339
Cantera::Transport
Base class for transport property managers.
Definition: TransportBase.h:132
utilities.h
MixTransport.h
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
ctml.h
stringUtils.h
Cantera::DustyGasTransport
Class DustyGasTransport implements the Dusty Gas model for transport in porous media.
Definition: DustyGasTransport.h:62
WaterTransport.h
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:359
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:60
Cantera::newDefaultTransportMgr
Transport * newDefaultTransportMgr(thermo_t *thermo, int loglevel)
Create a new transport manager instance.
Definition: TransportFactory.cpp:123
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:263
Cantera::TransportDBError
Exception thrown if an error is encountered while reading the transport database.
Definition: TransportFactory.cpp:30
IonGasTransport.h
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:546