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 }
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:360
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:984
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.
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:45
void saveState(vector_fp &state) const
Save the current internal state of the phase.
Definition: Phase.cpp:315
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
Definition: Phase.cpp:339
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
const AnyMap & input() const
Access input data associated with the phase description.
Exception thrown if an error is encountered while reading the transport database.
TransportDBError(size_t linenum, const std::string &msg)
Default constructor.
Factory class for creating new instances of classes derived from Transport.
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...
Base class for transport property managers.
virtual void init(thermo_t *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:104
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
Definition: xml.cpp:492
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:528
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
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
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
Transport * newDefaultTransportMgr(thermo_t *thermo, int loglevel)
Create a new transport manager instance.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
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...
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...