24 TransportFactory* TransportFactory::s_factory = 0;
27 std::mutex TransportFactory::transport_mutex;
39 CanteraError(
"getTransportData",
"error reading transport data: " + msg +
"\n") {
45 TransportFactory::TransportFactory()
47 reg(
"", []() {
return new Transport(); });
48 reg(
"None", []() {
return new Transport(); });
54 m_CK_mode[
"CK_Mix"] =
true;
55 m_CK_mode[
"CK_Multi"] =
true;
57 m_models[
"Mix"] = cMixtureAveraged;
58 m_models[
"Multi"] = cMulticomponent;
59 m_models[
"Solid"] = cSolidTransport;
60 m_models[
"DustyGas"] = cDustyGasTransport;
61 m_models[
"CK_Multi"] = CK_Multicomponent;
62 m_models[
"CK_Mix"] = CK_MixtureAveraged;
63 m_models[
"Liquid"] = cLiquidTransport;
64 m_models[
"Simple"] = cSimpleTransport;
65 m_models[
"User"] = cUserTransport;
66 m_models[
"HighP"] = cHighP;
67 m_models[
"None"] = None;
68 for (
const auto& model : m_models) {
69 m_modelNames[model.second] = model.first;
72 m_tranPropMap[
"viscosity"] = TP_VISCOSITY;
73 m_tranPropMap[
"ionConductivity"] = TP_IONCONDUCTIVITY;
74 m_tranPropMap[
"mobilityRatio"] = TP_MOBILITYRATIO;
75 m_tranPropMap[
"selfDiffusion"] = TP_SELFDIFFUSION;
76 m_tranPropMap[
"thermalConductivity"] = TP_THERMALCOND;
77 m_tranPropMap[
"speciesDiffusivity"] = TP_DIFFUSIVITY;
78 m_tranPropMap[
"hydrodynamicRadius"] = TP_HYDRORADIUS;
79 m_tranPropMap[
"electricalConductivity"] = TP_ELECTCOND;
80 m_tranPropMap[
"defectDiffusivity"] = TP_DEFECTDIFF;
81 m_tranPropMap[
"defectActivity"] = TP_DEFECTCONC;
83 m_LTRmodelMap[
""] = LTP_TD_CONSTANT;
84 m_LTRmodelMap[
"constant"] = LTP_TD_CONSTANT;
85 m_LTRmodelMap[
"arrhenius"] = LTP_TD_ARRHENIUS;
86 m_LTRmodelMap[
"coeffs"] = LTP_TD_POLY;
87 m_LTRmodelMap[
"exptemp"] = LTP_TD_EXPT;
89 m_LTImodelMap[
""] = LTI_MODEL_NOTSET;
90 m_LTImodelMap[
"solvent"] = LTI_MODEL_SOLVENT;
91 m_LTImodelMap[
"moleFractions"] = LTI_MODEL_MOLEFRACS;
92 m_LTImodelMap[
"massFractions"] = LTI_MODEL_MASSFRACS;
93 m_LTImodelMap[
"logMoleFractions"] = LTI_MODEL_LOG_MOLEFRACS;
94 m_LTImodelMap[
"pairwiseInteraction"] = LTI_MODEL_PAIRWISE_INTERACTION;
95 m_LTImodelMap[
"stefanMaxwell_PPN"] = LTI_MODEL_STEFANMAXWELL_PPN;
96 m_LTImodelMap[
"moleFractionsExpT"] = LTI_MODEL_MOLEFRACS_EXPT;
97 m_LTImodelMap[
"none"] = LTI_MODEL_NONE;
98 m_LTImodelMap[
"multiple"] = LTI_MODEL_MULTIPLE;
101 void TransportFactory::deleteFactory()
103 std::unique_lock<std::mutex> transportLock(transport_mutex);
108 std::string TransportFactory::modelName(
int model)
111 "To be removed after Cantera 2.3.");
112 return getValue<int,string>(factory()->m_modelNames, model,
"");
118 std::string model = ba::to_lower_copy(trNode[
"model"]);
119 switch (m_LTRmodelMap[model]) {
120 case LTP_TD_CONSTANT:
122 case LTP_TD_ARRHENIUS:
129 throw CanteraError(
"TransportFactory::newLTP",
"unknown transport model: " + model);
138 switch (m_LTImodelMap[trNode[
"model"]]) {
139 case LTI_MODEL_SOLVENT:
140 lti =
new LTI_Solvent(tp_ind);
143 case LTI_MODEL_MOLEFRACS:
147 case LTI_MODEL_MASSFRACS:
151 case LTI_MODEL_LOG_MOLEFRACS:
155 case LTI_MODEL_PAIRWISE_INTERACTION:
158 lti->setParameters(trParam);
160 case LTI_MODEL_STEFANMAXWELL_PPN:
163 lti->setParameters(trParam);
165 case LTI_MODEL_STOKES_EINSTEIN:
166 lti =
new LTI_StokesEinstein(tp_ind);
168 lti->setParameters(trParam);
170 case LTI_MODEL_MOLEFRACS_EXPT:
174 case LTI_MODEL_NOTSET:
176 case LTI_MODEL_MULTIPLE:
188 Transport* TransportFactory::newTransport(
const std::string& transportModel,
189 thermo_t* phase,
int log_level,
int ndim)
195 if (transportModel ==
"Solid") {
197 initSolidTransport(tr, phase, log_level);
199 }
else if (transportModel ==
"DustyGas") {
202 gastr->
init(phase, 0, log_level);
205 }
else if (transportModel ==
"Simple") {
207 initLiquidTransport(tr, phase, log_level);
209 }
else if (transportModel ==
"Liquid") {
211 initLiquidTransport(tr, phase, log_level);
214 tr = create(transportModel);
215 tr->
init(phase, m_CK_mode[transportModel], log_level);
223 std::string transportModel =
"None";
225 if (phaseNode.
hasChild(
"transport")) {
226 transportModel = phaseNode.
child(
"transport").
attrib(
"model");
228 return newTransport(transportModel, phase,log_level);
231 void TransportFactory::setupLiquidTransport(
thermo_t* thermo,
int log_level,
234 const std::vector<const XML_Node*> & species_database = thermo->
speciesData();
240 size_t nsp = trParam.
nsp_;
249 trParam.
LTData.resize(nsp);
259 getLiquidSpeciesTransportData(species_database, log, trParam.
thermo->
speciesNames(), trParam);
263 if (phase_database->
hasChild(
"transport")) {
264 XML_Node& transportNode = phase_database->
child(
"transport");
265 getLiquidInteractionsTransportData(transportNode, log, trParam.
thermo->
speciesNames(), trParam);
269 void TransportFactory::setupSolidTransport(
thermo_t* thermo,
int log_level,
286 if (phase_database->
hasChild(
"transport")) {
288 XML_Node& transportNode = phase_database->
child(
"transport");
289 getSolidTransportData(transportNode, log, thermo->
name(), trParam);
293 void TransportFactory::initLiquidTransport(
Transport* tran,
298 setupLiquidTransport(thermo, log_level, trParam);
303 void TransportFactory::initSolidTransport(
Transport* tran,
308 setupSolidTransport(thermo, log_level, trParam);
313 void TransportFactory::getLiquidSpeciesTransportData(
const std::vector<const XML_Node*> &xspecies,
315 const std::vector<std::string> &names,
319 std::map<std::string, LiquidTransportData> datatable;
322 size_t nsp = trParam.
nsp_;
325 size_t nBinInt = nsp*(nsp-1)/2;
330 for (
size_t i = 0; i < nsp; i++) {
332 string name = sp[
"name"];
346 for (
size_t iChild = 0; iChild < num; iChild++) {
348 std::string nodeName = xmlChild.
name();
350 switch (m_tranPropMap[nodeName]) {
352 data.
viscosity = newLTP(xmlChild, name, m_tranPropMap[nodeName], trParam.
thermo);
354 case TP_IONCONDUCTIVITY:
357 case TP_MOBILITYRATIO: {
358 for (
size_t iSpec = 0; iSpec< nBinInt; iSpec++) {
360 std::string specName = propSpecNode.
name();
361 size_t loc = specName.find(
":");
362 std::string firstSpec = specName.substr(0,loc);
363 std::string secondSpec = specName.substr(loc+1);
365 data.
mobilityRatio[index] = newLTP(propSpecNode, name, m_tranPropMap[nodeName], trParam.
thermo);
369 case TP_SELFDIFFUSION: {
370 for (
size_t iSpec = 0; iSpec< nsp; iSpec++) {
372 std::string specName = propSpecNode.
name();
374 data.
selfDiffusion[index] = newLTP(propSpecNode, name, m_tranPropMap[nodeName], trParam.
thermo);
381 m_tranPropMap[nodeName],
387 m_tranPropMap[nodeName],
393 m_tranPropMap[nodeName],
399 m_tranPropMap[nodeName],
403 throw CanteraError(
"getLiquidSpeciesTransportData",
"unknown transport property: " + nodeName);
406 datatable[name] = data;
411 for (
size_t i = 0; i < trParam.
nsp_; i++) {
414 auto it = datatable.find(names[i]);
415 if (it == datatable.end()) {
416 throw TransportDBError(0,
"No transport data found for species " + names[i]);
422 trParam.
LTData.push_back(it->second);
433 void TransportFactory::getLiquidInteractionsTransportData(
const XML_Node& transportNode,
435 const std::vector<std::string> &names,
439 size_t nsp = trParam.
nsp_;
440 size_t nBinInt = nsp*(nsp-1)/2;
441 for (
size_t iChild = 0; iChild < transportNode.
nChildren(); iChild++) {
444 std::string nodeName = tranTypeNode.
name();
448 if (tranTypeNode.
name() ==
"compositionDependence") {
449 std::string modelName = tranTypeNode.
attrib(
"model");
450 auto it = m_LTImodelMap.find(modelName);
451 if (it == m_LTImodelMap.end()) {
452 throw CanteraError(
"TransportFactory::getLiquidInteractionsTransportData",
453 "Unknown compositionDependence string: " + modelName);
458 if (tranTypeNode.
hasChild(
"compositionDependence")) {
460 XML_Node& compDepNode = tranTypeNode.
child(
"compositionDependence");
461 switch (m_tranPropMap[nodeName]) {
464 trParam.
viscosity = newLTI(compDepNode, m_tranPropMap[nodeName], trParam);
466 case TP_IONCONDUCTIVITY:
468 m_tranPropMap[nodeName],
471 case TP_MOBILITYRATIO: {
472 for (
size_t iSpec = 0; iSpec< nBinInt; iSpec++) {
474 string specName = propSpecNode.
name();
475 size_t loc = specName.find(
":");
476 string firstSpec = specName.substr(0,loc);
477 string secondSpec = specName.substr(loc+1);
480 m_tranPropMap[nodeName],
485 case TP_SELFDIFFUSION: {
486 for (
size_t iSpec = 0; iSpec< nsp; iSpec++) {
488 string specName = propSpecNode.
name();
491 m_tranPropMap[nodeName],
498 m_tranPropMap[nodeName],
503 m_tranPropMap[nodeName],
508 m_tranPropMap[nodeName],
513 m_tranPropMap[nodeName],
517 throw CanteraError(
"getLiquidInteractionsTransportData",
"unknown transport property: " + nodeName);
528 if (tranTypeNode.
hasChild(
"velocityBasis")) {
529 std::string velocityBasis =
530 tranTypeNode.
child(
"velocityBasis").
attrib(
"basis");
531 if (velocityBasis ==
"mass") {
533 }
else if (velocityBasis ==
"mole") {
538 int linenum = __LINE__;
539 throw TransportDBError(linenum,
"Unknown attribute \"" + velocityBasis +
"\" for <velocityBasis> node. ");
545 std::cout << err.
what() << std::endl;
550 void TransportFactory::getSolidTransportData(
const XML_Node& transportNode,
552 const std::string phaseName,
555 for (
size_t iChild = 0; iChild < transportNode.
nChildren(); iChild++) {
558 std::string nodeName = tranTypeNode.
name();
561 switch (m_tranPropMap[nodeName]) {
562 case TP_IONCONDUCTIVITY:
564 m_tranPropMap[nodeName],
569 m_tranPropMap[nodeName],
574 m_tranPropMap[nodeName],
579 m_tranPropMap[nodeName],
584 m_tranPropMap[nodeName],
588 throw CanteraError(
"getSolidTransportData",
"unknown transport property: " + nodeName);
596 warn_deprecated(
"newTransportMgr(string, thermo_t*, int, TransportFactory*, int)",
597 "This overload is deprecated and will be removed after Cantera 2.3." 598 " Use the version that does not take a TransportFactory*.");
600 f = TransportFactory::factory();
602 return f->
newTransport(transportModel, thermo, loglevel, ndim);
605 Transport* newTransportMgr(
const std::string& transportModel,
thermo_t* thermo,
int loglevel,
int ndim)
607 TransportFactory* f = TransportFactory::factory();
608 return f->newTransport(transportModel, thermo, loglevel, ndim);
614 f = TransportFactory::factory();
616 warn_deprecated(
"newDefaultTransportMgr(ThermoPhase*, int, TransportFactory*)",
617 "The `TransportFactory*` argument to this function is deprecated" 618 " and will be removed after Cantera 2.3.");
LTPspecies * defectDiffusivity
Model type for the defectDiffusivity – or more like a defect diffusivity in the context of the solid...
doublereal tmin
Minimum temperatures for parameter fits.
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Headers for the DustyGasTransport object, which models transport properties in porous media using the...
TransportPropertyType
Enumeration of the types of transport properties that can be handled by the variables in the various ...
void restoreState(const vector_fp &state)
Restore a state saved on a previous call to saveState.
DenseMatrix radius_Aij
Interaction associated with hydrodynamic radius.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
std::string name() const
Returns the name of the XML node.
std::vector< LiquidTranInteraction * > mobilityRatio
Vector of pointer to the LiquidTranInteraction object which handles the calculation of the mobility r...
thermo_t * thermo
Pointer to the ThermoPhase object: shallow pointer.
const std::vector< const XML_Node * > & speciesData() const
Return a pointer to the vector of XML nodes containing the species data for this phase.
virtual Transport * newTransport(const std::string &model, thermo_t *thermo, int log_level=0, int ndim=1)
Build a new transport manager using a transport manager that may not be the same as in the phase desc...
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
LTPspecies * thermalCond
Model type for the thermal conductivity.
Simple mass fraction weighting of transport properties.
void saveState(vector_fp &state) const
Save the current internal state of the phase.
Factory class for creating new instances of classes derived from Transport.
Interface for class MultiTransport.
LTPspecies * defectActivity
Model type for the defectActivity.
size_t nsp_
Local storage of the number of species.
doublereal tmax
Maximum temperatures for parameter fits.
const char * what() const
Get a description of the error.
Class LiquidTransport implements models for transport properties for liquid phases.
Class DustyGasTransport implements the Dusty Gas model for transport in porous media.
Class XML_Node is a tree-based representation of the contents of an XML file.
Header file defining class SolidTransportData.
Transport properties that act like pairwise interactions as in binary diffusion coefficients.
Base class for transport property managers.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
size_t nSpecies() const
Returns the number of species in the phase.
LiquidTranInteraction * viscosity
Object that specifies the viscosity interaction for the mixture.
Class LiquidTransportData holds transport parameters for a specific liquid-phase species.
virtual doublereal minTemp(size_t k=npos) const
Minimum temperature for which the thermodynamic data for the species or phase are valid...
virtual bool initSolid(SolidTransportData &tr)
Called by TransportFactory to set parameters.
Class LTPspecies_Arrhenius holds transport parameters for a specific liquid- phase species (LTPspecie...
TransportDBError(size_t linenum, const std::string &msg)
Default constructor.
virtual void init(thermo_t *thermo, int mode=0, int log_level=0)
Initialize a transport manager.
LTPspecies * electConductivity
Model type for the electrical conductivity.
LTPspecies * speciesDiffusivity
Model type for the speciesDiffusivity.
Header file for defining the class SolidTransport, which handles transport of ions within solid phase...
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
std::vector< LiquidTransportData > LTData
Species transport parameters.
Header file defining class TransportFactory (see TransportFactory)
Class SolidTransport implements transport properties for solids.
ThermoPhase thermo_t
typedef for the ThermoPhase class
Base class for a phase with thermodynamic properties.
Class LiquidTransportParams holds transport model parameters relevant to transport in mixtures...
std::vector< LiquidTranInteraction * > selfDiffusion
Vector of pointer to the LiquidTranInteraction object which handles the calculation of each species' ...
Class MultiTransport implements transport properties for high pressure gas mixtures.
LiquidTranInteraction * ionConductivity
Object that specifies the ionic Conductivity of the mixture.
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the matrix.
VelocityBasis velocityBasis_
A basis for the average velocity can be specified.
Mixing rule using logarithms of the mole fractions.
Header file for the class SimpleTransport which provides simple transport properties for liquids and ...
void initialize(ThermoPhase *phase, Transport *gastr)
Initialization routine called by TransportFactory.
DenseMatrix thermalCond_Aij
Interaction associated with linear weighting of thermal conductivity.
Base class for exceptions thrown by Cantera classes.
LiquidTranMixingModel compositionDepTypeDefault_
Default composition dependence of the transport properties.
Class LTPspecies_Const holds transport parameters for a specific liquid- phase species (LTPspecies) w...
Interface for class HighPressureGasTransport.
LiquidTranInteraction * speciesDiffusivity
Pointer to the LiquidTranInteraction object which handles the calculation of the species diffusivity ...
Class LTPspecies holds transport parameterizations for a specific liquid- phase species.
XML_Node & xml() const
Returns a const reference to the XML_Node that describes the phase.
vector_fp mw
Local storage of the molecular weights of the species.
Simple mole fraction weighting of transport properties.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Class MultiTransport implements multicomponent transport properties for ideal gas mixtures...
const VelocityBasis VB_MOLEAVG
Diffusion velocities are based on the mole averaged velocities.
LTPspecies * electCond
Model type for the electrical conductivity.
Class LTPspecies_ExpT holds transport parameters for a specific liquid- phase species (LTPspecies) wh...
Header file defining class LiquidTransport.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
virtual bool initLiquid(LiquidTransportParams &tr)
Called by TransportFactory to set parameters.
Transport * newTransportMgr(const std::string &transportModel, thermo_t *thermo, int loglevel, TransportFactory *f, int ndim)
Create a new transport manager instance.
std::string speciesName
A LiquidTransportData object is instantiated for each species.
std::vector< LTPspecies * > mobilityRatio
Model type for the mobility ratio.
LTPspecies * ionConductivity
Model type for the ionic conductivity.
Exception thrown if an error is encountered while reading the transport database. ...
std::string name() const
Return the name of the phase.
LTPspecies * hydroRadius
Model type for the hydroradius.
Stefan Maxwell Diffusion Coefficients can be solved for given ion conductivity, mobility ratios...
DenseMatrix diff_Dij
Interaction associated with linear weighting of thermal conductivity.
Contains declarations for string manipulation functions within Cantera.
std::vector< LTPspecies * > selfDiffusion
Model type for the self diffusion coefficients.
LTPspecies * viscosity
Model type for the viscosity.
Simple mole fraction weighting of transport properties.
LiquidTranInteraction * hydroRadius
Pointer to the LiquidTranInteraction object which handles the calculation of the hydrodynamic radius ...
const VelocityBasis VB_MASSAVG
Diffusion velocities are based on the mass averaged velocity.
virtual void setThermo(thermo_t &thermo)
Specifies the ThermoPhase object.
virtual void init(const XML_Node &compModelNode=XML_Node(), thermo_t *thermo=0)
initialize LiquidTranInteraction objects with thermo and XML node
LTPspecies * thermalConductivity
Model type for the thermal conductivity.
Transport * newDefaultTransportMgr(thermo_t *thermo, int loglevel, TransportFactory *f)
Create a new transport manager instance.
Namespace for the Cantera kernel.
Class MixTransport implements mixture-averaged transport properties for ideal gas mixtures...
LTPspecies * ionConductivity
Model type for the ionic conductivity.
virtual doublereal maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
Class LTPspecies_Poly holds transport parameters for a specific liquid-phase species (LTPspecies) whe...
Class SolidTransportData holds transport parameters for a specific solid- phase species.
Headers for the MixTransport object, which models transport properties in ideal gas solutions using a...
Base class to handle transport property evaluation in a mixture.
LiquidTranInteraction * thermalCond
Pointer to the LiquidTranInteraction object which handles the calculation of the mixture thermal cond...
size_t nChildren(bool discardComments=false) const
Return the number of children.
Class SimpleTransport implements mixture-averaged transport properties for liquid phases...
LiquidTranInteraction * electCond
Pointer to the LiquidTranInteraction object which handles the calculation of the electrical conductiv...