26 TransportFactory* TransportFactory::s_factory = 0;
29 std::mutex TransportFactory::transport_mutex;
41 CanteraError(
"getTransportData",
"error reading transport data: " + msg +
"\n") {
47 TransportFactory::TransportFactory()
49 reg(
"", []() {
return new Transport(); });
50 m_synonyms[
"None"] =
"";
55 m_synonyms[
"CK_Mix"] =
"Mix";
56 m_synonyms[
"CK_Multi"] =
"Multi";
58 m_CK_mode[
"CK_Mix"] =
true;
59 m_CK_mode[
"CK_Multi"] =
true;
61 m_tranPropMap[
"viscosity"] = TP_VISCOSITY;
62 m_tranPropMap[
"ionConductivity"] = TP_IONCONDUCTIVITY;
63 m_tranPropMap[
"mobilityRatio"] = TP_MOBILITYRATIO;
64 m_tranPropMap[
"selfDiffusion"] = TP_SELFDIFFUSION;
65 m_tranPropMap[
"thermalConductivity"] = TP_THERMALCOND;
66 m_tranPropMap[
"speciesDiffusivity"] = TP_DIFFUSIVITY;
67 m_tranPropMap[
"hydrodynamicRadius"] = TP_HYDRORADIUS;
68 m_tranPropMap[
"electricalConductivity"] = TP_ELECTCOND;
69 m_tranPropMap[
"defectDiffusivity"] = TP_DEFECTDIFF;
70 m_tranPropMap[
"defectActivity"] = TP_DEFECTCONC;
72 m_LTRmodelMap[
""] = LTP_TD_CONSTANT;
73 m_LTRmodelMap[
"constant"] = LTP_TD_CONSTANT;
74 m_LTRmodelMap[
"arrhenius"] = LTP_TD_ARRHENIUS;
75 m_LTRmodelMap[
"coeffs"] = LTP_TD_POLY;
76 m_LTRmodelMap[
"exptemp"] = LTP_TD_EXPT;
78 m_LTImodelMap[
""] = LTI_MODEL_NOTSET;
79 m_LTImodelMap[
"solvent"] = LTI_MODEL_SOLVENT;
80 m_LTImodelMap[
"moleFractions"] = LTI_MODEL_MOLEFRACS;
81 m_LTImodelMap[
"massFractions"] = LTI_MODEL_MASSFRACS;
82 m_LTImodelMap[
"logMoleFractions"] = LTI_MODEL_LOG_MOLEFRACS;
83 m_LTImodelMap[
"pairwiseInteraction"] = LTI_MODEL_PAIRWISE_INTERACTION;
84 m_LTImodelMap[
"stefanMaxwell_PPN"] = LTI_MODEL_STEFANMAXWELL_PPN;
85 m_LTImodelMap[
"moleFractionsExpT"] = LTI_MODEL_MOLEFRACS_EXPT;
86 m_LTImodelMap[
"none"] = LTI_MODEL_NONE;
87 m_LTImodelMap[
"multiple"] = LTI_MODEL_MULTIPLE;
90 void TransportFactory::deleteFactory()
92 std::unique_lock<std::mutex> transportLock(transport_mutex);
102 switch (m_LTRmodelMap[model]) {
103 case LTP_TD_CONSTANT:
106 case LTP_TD_ARRHENIUS:
116 throw CanteraError(
"TransportFactory::newLTP",
"unknown transport model: " + model);
130 switch (m_LTImodelMap[trNode[
"model"]]) {
131 case LTI_MODEL_SOLVENT:
132 lti =
new LTI_Solvent(tp_ind);
135 case LTI_MODEL_MOLEFRACS:
139 case LTI_MODEL_MASSFRACS:
143 case LTI_MODEL_LOG_MOLEFRACS:
147 case LTI_MODEL_PAIRWISE_INTERACTION:
150 lti->setParameters(trParam);
152 case LTI_MODEL_STEFANMAXWELL_PPN:
155 lti->setParameters(trParam);
157 case LTI_MODEL_STOKES_EINSTEIN:
158 lti =
new LTI_StokesEinstein(tp_ind);
160 lti->setParameters(trParam);
162 case LTI_MODEL_MOLEFRACS_EXPT:
166 case LTI_MODEL_NOTSET:
168 case LTI_MODEL_MULTIPLE:
180 Transport* TransportFactory::newTransport(
const std::string& transportModel,
181 thermo_t* phase,
int log_level,
int ndim)
187 if (transportModel ==
"Solid") {
189 initSolidTransport(tr, phase, log_level);
191 }
else if (transportModel ==
"DustyGas") {
194 gastr->
init(phase, 0, log_level);
197 }
else if (transportModel ==
"Simple") {
199 initLiquidTransport(tr, phase, log_level);
201 }
else if (transportModel ==
"Liquid") {
203 initLiquidTransport(tr, phase, log_level);
206 tr = create(transportModel);
207 int mode = m_CK_mode[transportModel] ? CK_Mode : 0;
208 tr->
init(phase, mode, log_level);
216 std::string transportModel =
"None";
218 if (phaseNode.
hasChild(
"transport")) {
219 transportModel = phaseNode.
child(
"transport").
attrib(
"model");
221 return newTransport(transportModel, phase,log_level);
224 void TransportFactory::setupLiquidTransport(
thermo_t* thermo,
int log_level,
227 const std::vector<const XML_Node*> & species_database = thermo->
speciesData();
233 size_t nsp = trParam.
nsp_;
242 trParam.
LTData.resize(nsp);
252 getLiquidSpeciesTransportData(species_database, log, trParam.
thermo->
speciesNames(), trParam);
256 if (phase_database->
hasChild(
"transport")) {
257 XML_Node& transportNode = phase_database->
child(
"transport");
258 getLiquidInteractionsTransportData(transportNode, log, trParam.
thermo->
speciesNames(), trParam);
262 void TransportFactory::setupSolidTransport(
thermo_t* thermo,
int log_level,
279 if (phase_database->
hasChild(
"transport")) {
281 XML_Node& transportNode = phase_database->
child(
"transport");
282 getSolidTransportData(transportNode, log, thermo->
name(), trParam);
286 void TransportFactory::initLiquidTransport(
Transport* tran,
291 setupLiquidTransport(thermo, log_level, trParam);
296 void TransportFactory::initSolidTransport(
Transport* tran,
301 setupSolidTransport(thermo, log_level, trParam);
306 void TransportFactory::getLiquidSpeciesTransportData(
const std::vector<const XML_Node*> &xspecies,
308 const std::vector<std::string> &names,
312 std::map<std::string, LiquidTransportData> datatable;
315 size_t nsp = trParam.
nsp_;
318 size_t nBinInt = nsp*(nsp-1)/2;
323 for (
size_t i = 0; i < nsp; i++) {
325 string name = sp[
"name"];
339 for (
size_t iChild = 0; iChild < num; iChild++) {
341 std::string nodeName = xmlChild.
name();
343 switch (m_tranPropMap[nodeName]) {
345 data.
viscosity = newLTP(xmlChild, name, m_tranPropMap[nodeName], trParam.
thermo);
347 case TP_IONCONDUCTIVITY:
350 case TP_MOBILITYRATIO: {
351 for (
size_t iSpec = 0; iSpec< nBinInt; iSpec++) {
353 std::string specName = propSpecNode.
name();
354 size_t loc = specName.find(
":");
355 std::string firstSpec = specName.substr(0,loc);
356 std::string secondSpec = specName.substr(loc+1);
358 data.
mobilityRatio[index] = newLTP(propSpecNode, name, m_tranPropMap[nodeName], trParam.
thermo);
362 case TP_SELFDIFFUSION: {
363 for (
size_t iSpec = 0; iSpec< nsp; iSpec++) {
365 std::string specName = propSpecNode.
name();
367 data.
selfDiffusion[index] = newLTP(propSpecNode, name, m_tranPropMap[nodeName], trParam.
thermo);
374 m_tranPropMap[nodeName],
380 m_tranPropMap[nodeName],
386 m_tranPropMap[nodeName],
392 m_tranPropMap[nodeName],
396 throw CanteraError(
"getLiquidSpeciesTransportData",
"unknown transport property: " + nodeName);
399 datatable[name] = data;
404 for (
size_t i = 0; i < trParam.
nsp_; i++) {
407 auto it = datatable.find(names[i]);
408 if (it == datatable.end()) {
409 throw TransportDBError(0,
"No transport data found for species " + names[i]);
415 trParam.
LTData.push_back(it->second);
426 void TransportFactory::getLiquidInteractionsTransportData(
const XML_Node& transportNode,
428 const std::vector<std::string> &names,
432 size_t nsp = trParam.
nsp_;
433 size_t nBinInt = nsp*(nsp-1)/2;
434 for (
size_t iChild = 0; iChild < transportNode.
nChildren(); iChild++) {
437 std::string nodeName = tranTypeNode.
name();
441 if (tranTypeNode.
name() ==
"compositionDependence") {
442 std::string modelName = tranTypeNode.
attrib(
"model");
443 auto it = m_LTImodelMap.find(modelName);
444 if (it == m_LTImodelMap.end()) {
445 throw CanteraError(
"TransportFactory::getLiquidInteractionsTransportData",
446 "Unknown compositionDependence string: " + modelName);
451 if (tranTypeNode.
hasChild(
"compositionDependence")) {
453 XML_Node& compDepNode = tranTypeNode.
child(
"compositionDependence");
454 switch (m_tranPropMap[nodeName]) {
457 trParam.
viscosity = newLTI(compDepNode, m_tranPropMap[nodeName], trParam);
459 case TP_IONCONDUCTIVITY:
461 m_tranPropMap[nodeName],
464 case TP_MOBILITYRATIO: {
465 for (
size_t iSpec = 0; iSpec< nBinInt; iSpec++) {
467 string specName = propSpecNode.
name();
468 size_t loc = specName.find(
":");
469 string firstSpec = specName.substr(0,loc);
470 string secondSpec = specName.substr(loc+1);
473 m_tranPropMap[nodeName],
478 case TP_SELFDIFFUSION: {
479 for (
size_t iSpec = 0; iSpec< nsp; iSpec++) {
481 string specName = propSpecNode.
name();
484 m_tranPropMap[nodeName],
491 m_tranPropMap[nodeName],
496 m_tranPropMap[nodeName],
501 m_tranPropMap[nodeName],
506 m_tranPropMap[nodeName],
510 throw CanteraError(
"getLiquidInteractionsTransportData",
"unknown transport property: " + nodeName);
521 if (tranTypeNode.
hasChild(
"velocityBasis")) {
522 std::string velocityBasis =
523 tranTypeNode.
child(
"velocityBasis").
attrib(
"basis");
524 if (velocityBasis ==
"mass") {
526 }
else if (velocityBasis ==
"mole") {
531 int linenum = __LINE__;
532 throw TransportDBError(linenum,
"Unknown attribute \"" + velocityBasis +
"\" for <velocityBasis> node. ");
538 std::cout << err.
what() << std::endl;
543 void TransportFactory::getSolidTransportData(
const XML_Node& transportNode,
545 const std::string phaseName,
548 for (
size_t iChild = 0; iChild < transportNode.
nChildren(); iChild++) {
551 std::string nodeName = tranTypeNode.
name();
554 switch (m_tranPropMap[nodeName]) {
555 case TP_IONCONDUCTIVITY:
557 m_tranPropMap[nodeName],
562 m_tranPropMap[nodeName],
567 m_tranPropMap[nodeName],
572 m_tranPropMap[nodeName],
577 m_tranPropMap[nodeName],
581 throw CanteraError(
"getSolidTransportData",
"unknown transport property: " + nodeName);
586 Transport* newTransportMgr(
const std::string& transportModel,
thermo_t* thermo,
int loglevel,
int ndim)
589 return f->
newTransport(transportModel, thermo, loglevel, ndim);
594 return TransportFactory::factory()->newTransport(thermo, loglevel);
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.
virtual void setupFromXML(const XML_Node &propNode)
Set up the species transport property from the XML node, <propNode> that is a child of the <transport...
Factory class for creating new instances of classes derived from Transport.
Interface for class MultiTransport.
LTPspecies * defectActivity
Model type for the defectActivity.
void setName(const std::string &name)
Set the species name.
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.
size_t nSpecies() const
Returns the number of species in the phase.
void setThermo(thermo_t *thermo)
Set the ThermoPhase object, which is used to find the temperature.
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.
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 IonGasTransport implements Stockmayer-(n,6,4) model for transport of ions.
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.
void setTransportPropertyType(TransportPropertyType tp_ind)
TransportPropertyType containing the property id that this object is creating a parameterization for ...
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.
Class UnityLewisTransport implements the unity Lewis number approximation for the mixture-averaged sp...
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.
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 ...
Headers for the UnityLewisTransport object, which models transport properties in ideal gas solutions ...
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.
std::string toLowerCopy(const std::string &input)
Convert to lower case.
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.
Transport * newDefaultTransportMgr(thermo_t *thermo, int loglevel)
Create a new transport manager instance.
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...