Esempio n. 1
0
void TransportFactory::getSolidTransportData(const XML_Node& transportNode,
        XML_Node& log,
        const std::string phaseName,
        SolidTransportData& trParam)
{
    try {

        size_t num = transportNode.nChildren();
        for (size_t iChild = 0; iChild < num; iChild++) {
            //tranTypeNode is a type of transport property like viscosity
            XML_Node& tranTypeNode = transportNode.child(iChild);
            std::string nodeName = tranTypeNode.name();

            ThermoPhase* temp_thermo = trParam.thermo;

            //tranTypeNode contains the interaction model
            switch (m_tranPropMap[nodeName]) {
            case TP_IONCONDUCTIVITY:
                trParam.ionConductivity = newLTP(tranTypeNode, phaseName,
                                                 m_tranPropMap[nodeName],
                                                 temp_thermo);
                break;
            case TP_THERMALCOND:
                trParam.thermalConductivity = newLTP(tranTypeNode, phaseName,
                                                     m_tranPropMap[nodeName],
                                                     temp_thermo);
                break;
            case TP_DEFECTDIFF:
                trParam.defectDiffusivity = newLTP(tranTypeNode, phaseName,
                                                   m_tranPropMap[nodeName],
                                                   temp_thermo);
                break;
            case TP_DEFECTCONC:
                trParam.defectActivity = newLTP(tranTypeNode, phaseName,
                                                m_tranPropMap[nodeName],
                                                temp_thermo);
                break;
            case TP_ELECTCOND:
                trParam.electConductivity = newLTP(tranTypeNode, phaseName,
                                                   m_tranPropMap[nodeName],
                                                   temp_thermo);
                break;
            default:
                throw CanteraError("getSolidTransportData","unknown transport property: " + nodeName);

            }
        }
    } catch (CanteraError) {
        showErrors(std::cout);
    }
    return;
}
void OutletRes1D::restore(const XML_Node& dom, doublereal* soln, int loglevel)
{
    Domain1D::restore(dom, soln, loglevel);
    m_temp = getFloat(dom, "temperature");

    m_yres.assign(m_nsp, 0.0);
    for (size_t i = 0; i < dom.nChildren(); i++) {
        const XML_Node& node = dom.child(i);
        if (node.name() == "massFraction") {
            size_t k = m_flow->phase().speciesIndex(node.attrib("type"));
            if (k != npos) {
                m_yres[k] = node.fp_value();
            }
        }
    }

    resize(1,1);
}
void ReactingSurf1D::restore(const XML_Node& dom, doublereal* soln,
                             int loglevel)
{
    Domain1D::restore(dom, soln, loglevel);
    soln[0] = m_temp = getFloat(dom, "temperature");

    m_fixed_cov.assign(m_nsp, 0.0);
    for (size_t i = 0; i < dom.nChildren(); i++) {
        const XML_Node& node = dom.child(i);
        if (node.name() == "coverage") {
            size_t k = m_sphase->speciesIndex(node.attrib("type"));
            if (k != npos) {
                m_fixed_cov[k] = soln[k+1] = node.fp_value();
            }
        }
    }
    m_sphase->setCoverages(&m_fixed_cov[0]);

    resize(m_nsp+1,1);
}
Esempio n. 4
0
void Inlet1D::
restore(const XML_Node& dom, doublereal* soln, int loglevel)
{
    Domain1D::restore(dom, soln, loglevel);
    soln[0] = m_mdot = ctml::getFloat(dom, "mdot", "massflowrate");
    soln[1] = m_temp = ctml::getFloat(dom, "temperature", "temperature");

    m_yin.assign(m_nsp, 0.0);

    for (size_t i = 0; i < dom.nChildren(); i++) {
        const XML_Node& node = dom.child(i);
        if (node.name() == "massFraction") {
            size_t k = m_flow->phase().speciesIndex(node.attrib("type"));
            if (k != npos) {
                m_yin[k] = node.fp_value();
            }
        }
    }
    resize(2,1);
}
void RedlichKisterVPSSTP::readXMLBinarySpecies(XML_Node& xmLBinarySpecies)
{
    std::string xname = xmLBinarySpecies.name();
    if (xname != "binaryNeutralSpeciesParameters") {
        throw CanteraError("RedlichKisterVPSSTP::readXMLBinarySpecies",
                           "Incorrect name for processing this routine: " + xname);
    }
    size_t Npoly = 0;
    vector_fp hParams, sParams;
    std::string iName = xmLBinarySpecies.attrib("speciesA");
    if (iName == "") {
        throw CanteraError("RedlichKisterVPSSTP::readXMLBinarySpecies", "no speciesA attrib");
    }
    std::string jName = xmLBinarySpecies.attrib("speciesB");
    if (jName == "") {
        throw CanteraError("RedlichKisterVPSSTP::readXMLBinarySpecies", "no speciesB attrib");
    }
    /*
     * Find the index of the species in the current phase. It's not
     * an error to not find the species. This means that the interaction doesn't occur for the current
     * implementation of the phase.
     */
    size_t iSpecies = speciesIndex(iName);
    if (iSpecies == npos) {
        return;
    }
    string ispName = speciesName(iSpecies);
    if (charge(iSpecies) != 0) {
        throw CanteraError("RedlichKisterVPSSTP::readXMLBinarySpecies", "speciesA charge problem");
    }
    size_t jSpecies = speciesIndex(jName);
    if (jSpecies == npos) {
        return;
    }
    std::string jspName = speciesName(jSpecies);
    if (charge(jSpecies) != 0) {
        throw CanteraError("RedlichKisterVPSSTP::readXMLBinarySpecies", "speciesB charge problem");
    }
    /*
     *  Ok we have found a valid interaction
     */
    numBinaryInteractions_++;
    size_t iSpot = numBinaryInteractions_ - 1;
    m_pSpecies_A_ij.resize(numBinaryInteractions_);
    m_pSpecies_B_ij.resize(numBinaryInteractions_);
    m_pSpecies_A_ij[iSpot] = iSpecies;
    m_pSpecies_B_ij[iSpot] = jSpecies;

    for (size_t iChild = 0; iChild < xmLBinarySpecies.nChildren(); iChild++) {
        XML_Node& xmlChild = xmLBinarySpecies.child(iChild);
        string nodeName = lowercase(xmlChild.name());
        /*
         * Process the binary species interaction child elements
         */
        if (nodeName == "excessenthalpy") {
            /*
             * Get the string containing all of the values
             */
            getFloatArray(xmlChild, hParams, true, "toSI", "excessEnthalpy");
            Npoly = std::max(hParams.size(), Npoly);
        }

        if (nodeName == "excessentropy") {
            /*
             * Get the string containing all of the values
             */
            getFloatArray(xmlChild, sParams, true, "toSI", "excessEntropy");
            Npoly = std::max(sParams.size(), Npoly);
        }
    }
    hParams.resize(Npoly, 0.0);
    sParams.resize(Npoly, 0.0);
    m_HE_m_ij.push_back(hParams);
    m_SE_m_ij.push_back(sParams);
    m_N_ij.push_back(Npoly);
    resizeNumInteractions(numBinaryInteractions_);
}
void MixedSolventElectrolyte::readXMLBinarySpecies(XML_Node& xmLBinarySpecies)
{
    string xname = xmLBinarySpecies.name();
    if (xname != "binaryNeutralSpeciesParameters") {
        throw CanteraError("MixedSolventElectrolyte::readXMLBinarySpecies",
                           "Incorrect name for processing this routine: " + xname);
    }
    string stemp;
    size_t nParamsFound;
    vector_fp vParams;
    string iName = xmLBinarySpecies.attrib("speciesA");
    if (iName == "") {
        throw CanteraError("MixedSolventElectrolyte::readXMLBinarySpecies", "no speciesA attrib");
    }
    string jName = xmLBinarySpecies.attrib("speciesB");
    if (jName == "") {
        throw CanteraError("MixedSolventElectrolyte::readXMLBinarySpecies", "no speciesB attrib");
    }
    /*
     * Find the index of the species in the current phase. It's not
     * an error to not find the species
     */
    size_t iSpecies = speciesIndex(iName);
    if (iSpecies == npos) {
        return;
    }
    string ispName = speciesName(iSpecies);
    if (charge(iSpecies) != 0) {
        throw CanteraError("MixedSolventElectrolyte::readXMLBinarySpecies", "speciesA charge problem");
    }
    size_t jSpecies = speciesIndex(jName);
    if (jSpecies == npos) {
        return;
    }
    string jspName = speciesName(jSpecies);
    if (charge(jSpecies) != 0) {
        throw CanteraError("MixedSolventElectrolyte::readXMLBinarySpecies", "speciesB charge problem");
    }

    resizeNumInteractions(numBinaryInteractions_ + 1);
    size_t iSpot = numBinaryInteractions_ - 1;
    m_pSpecies_A_ij[iSpot] = iSpecies;
    m_pSpecies_B_ij[iSpot] = jSpecies;

    size_t num = xmLBinarySpecies.nChildren();
    for (size_t iChild = 0; iChild < num; iChild++) {
        XML_Node& xmlChild = xmLBinarySpecies.child(iChild);
        stemp = xmlChild.name();
        string nodeName = lowercase(stemp);
        /*
         * Process the binary species interaction child elements
         */
        if (nodeName == "excessenthalpy") {
            /*
             * Get the string containing all of the values
             */
            ctml::getFloatArray(xmlChild, vParams, true, "toSI", "excessEnthalpy");
            nParamsFound = vParams.size();

            if (nParamsFound != 2) {
                throw CanteraError("MixedSolventElectrolyte::readXMLBinarySpecies::excessEnthalpy for " + ispName
                                   + "::" + jspName,
                                   "wrong number of params found");
            }
            m_HE_b_ij[iSpot] = vParams[0];
            m_HE_c_ij[iSpot] = vParams[1];
        }

        if (nodeName == "excessentropy") {
            /*
             * Get the string containing all of the values
             */
            ctml::getFloatArray(xmlChild, vParams, true, "toSI", "excessEntropy");
            nParamsFound = vParams.size();

            if (nParamsFound != 2) {
                throw CanteraError("MixedSolventElectrolyte::readXMLBinarySpecies::excessEntropy for " + ispName
                                   + "::" + jspName,
                                   "wrong number of params found");
            }
            m_SE_b_ij[iSpot] = vParams[0];
            m_SE_c_ij[iSpot] = vParams[1];
        }

        if (nodeName == "excessvolume_enthalpy") {
            /*
             * Get the string containing all of the values
             */
            ctml::getFloatArray(xmlChild, vParams, true, "toSI", "excessVolume_Enthalpy");
            nParamsFound = vParams.size();

            if (nParamsFound != 2) {
                throw CanteraError("MixedSolventElectrolyte::readXMLBinarySpecies::excessVolume_Enthalpy for " + ispName
                                   + "::" + jspName,
                                   "wrong number of params found");
            }
            m_VHE_b_ij[iSpot] = vParams[0];
            m_VHE_c_ij[iSpot] = vParams[1];
        }

        if (nodeName == "excessvolume_entropy") {
            /*
             * Get the string containing all of the values
             */
            ctml::getFloatArray(xmlChild, vParams, true, "toSI", "excessVolume_Entropy");
            nParamsFound = vParams.size();

            if (nParamsFound != 2) {
                throw CanteraError("MixedSolventElectrolyte::readXMLBinarySpecies::excessVolume_Entropy for " + ispName
                                   + "::" + jspName,
                                   "wrong number of params found");
            }
            m_VSE_b_ij[iSpot] = vParams[0];
            m_VSE_c_ij[iSpot] = vParams[1];
        }
    }
}
void MixedSolventElectrolyte::initThermoXML(XML_Node& phaseNode, const std::string& id_)
{
    string subname = "MixedSolventElectrolyte::initThermoXML";
    string stemp;

    if ((int) id_.size() > 0) {
        string idp = phaseNode.id();
        if (idp != id_) {
            throw CanteraError(subname, "phasenode and Id are incompatible");
        }
    }

    /*
     * Check on the thermo field. Must have:
     * <thermo model="MixedSolventElectrolyte" />
     */
    if (!phaseNode.hasChild("thermo")) {
        throw CanteraError(subname, "no thermo XML node");
    }
    XML_Node& thermoNode = phaseNode.child("thermo");
    string mStringa = thermoNode.attrib("model");
    string mString = lowercase(mStringa);
    if (mString != "mixedsolventelectrolyte") {
        throw CanteraError(subname, "Unknown thermo model: " + mStringa);
    }

    /*
     * Go get all of the coefficients and factors in the
     * activityCoefficients XML block
     */
    XML_Node* acNodePtr = 0;
    if (thermoNode.hasChild("activityCoefficients")) {
        XML_Node& acNode = thermoNode.child("activityCoefficients");
        acNodePtr = &acNode;
        mStringa = acNode.attrib("model");
        mString = lowercase(mStringa);
        if (mString != "margules") {
            throw CanteraError(subname.c_str(),
                               "Unknown activity coefficient model: " + mStringa);
        }
        size_t n = acNodePtr->nChildren();
        for (size_t i = 0; i < n; i++) {
            XML_Node& xmlACChild = acNodePtr->child(i);
            stemp = xmlACChild.name();
            string nodeName = lowercase(stemp);
            /*
             * Process a binary salt field, or any of the other XML fields
             * that make up the Pitzer Database. Entries will be ignored
             * if any of the species in the entry isn't in the solution.
             */
            if (nodeName == "binaryneutralspeciesparameters") {
                readXMLBinarySpecies(xmlACChild);

            }
        }
    }

    /*
     * Go down the chain
     */
    MolarityIonicVPSSTP::initThermoXML(phaseNode, id_);


}
Esempio n. 8
0
void MargulesVPSSTP::readXMLBinarySpecies(XML_Node& xmLBinarySpecies)
{
    string xname = xmLBinarySpecies.name();
    if (xname != "binaryNeutralSpeciesParameters") {
        throw CanteraError("MargulesVPSSTP::readXMLBinarySpecies",
                           "Incorrect name for processing this routine: " + xname);
    }
    string aName = xmLBinarySpecies.attrib("speciesA");
    if (aName == "") {
        throw CanteraError("MargulesVPSSTP::readXMLBinarySpecies", "no speciesA attrib");
    }
    string bName = xmLBinarySpecies.attrib("speciesB");
    if (bName == "") {
        throw CanteraError("MargulesVPSSTP::readXMLBinarySpecies", "no speciesB attrib");
    }

    vector_fp vParams;
    double h0 = 0.0;
    double h1 = 0.0;
    double s0 = 0.0;
    double s1 = 0.0;
    double vh0 = 0.0;
    double vh1 = 0.0;
    double vs0 = 0.0;
    double vs1 = 0.0;

    for (size_t iChild = 0; iChild < xmLBinarySpecies.nChildren(); iChild++) {
        XML_Node& xmlChild = xmLBinarySpecies.child(iChild);
        string nodeName = toLowerCopy(xmlChild.name());

        // Process the binary species interaction parameters.
        // They are in subblocks labeled:
        //           excessEnthalpy
        //           excessEntropy
        //           excessVolume_Enthalpy
        //           excessVolume_Entropy
        // Other blocks are currently ignored.
        // @TODO determine a policy about ignoring blocks that should or shouldn't be there.
        if (nodeName == "excessenthalpy") {
            // Get the string containing all of the values
            getFloatArray(xmlChild, vParams, true, "toSI", "excessEnthalpy");
            if (vParams.size() != 2) {
                throw CanteraError("MargulesVPSSTP::readXMLBinarySpecies"
                    "excessEnthalpy for {} : {}: wrong number of params found."
                    " Need 2", aName, bName);
            }
            h0 = vParams[0];
            h1 = vParams[1];
        } else if (nodeName == "excessentropy") {
            // Get the string containing all of the values
            getFloatArray(xmlChild, vParams, true, "toSI", "excessEntropy");
            if (vParams.size() != 2) {
                throw CanteraError("MargulesVPSSTP::readXMLBinarySpecies"
                    "excessEntropy for {} : {}: wrong number of params found."
                    " Need 2", aName, bName);
            }
            s0 = vParams[0];
            s1 = vParams[1];
        } else if (nodeName == "excessvolume_enthalpy") {
            // Get the string containing all of the values
            getFloatArray(xmlChild, vParams, true, "toSI", "excessVolume_Enthalpy");
            if (vParams.size() != 2) {
                throw CanteraError("MargulesVPSSTP::readXMLBinarySpecies"
                    "excessVolume_Enthalpy for {} : {}: wrong number of params"
                    "  found. Need 2", aName, bName);
            }
            vh0 = vParams[0];
            vh1 = vParams[1];
        } else if (nodeName == "excessvolume_entropy") {
            // Get the string containing all of the values
            getFloatArray(xmlChild, vParams, true, "toSI", "excessVolume_Entropy");
            if (vParams.size() != 2) {
                throw CanteraError("MargulesVPSSTP::readXMLBinarySpecies"
                    "excessVolume_Entropy for {} : {}: wrong number of params"
                    " found. Need 2", aName, bName);
            }
            vs0 = vParams[0];
            vs1 = vParams[1];
        }
    }
    addBinaryInteraction(aName, bName, h0, h1, s0, s1, vh0, vh1, vs0, vs1);
}
Esempio n. 9
0
void MolarityIonicVPSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id)
{
    std::string subname = "MolarityIonicVPSSTP::initThermoXML";
    std::string stemp;

    if ((int) id.size() > 0) {
        string idp = phaseNode.id();
        if (idp != id) {
            throw CanteraError(subname, "phasenode and Id are incompatible");
        }
    }

    /*
     * Check on the thermo field. Must have one of:
     * <thermo model="MolarityIonicVPSS" />
     * <thermo model="MolarityIonicVPSSTP" />
     */
    if (!phaseNode.hasChild("thermo")) {
        throw CanteraError(subname, "no thermo XML node");
    }
    XML_Node& thermoNode = phaseNode.child("thermo");
    std::string mStringa = thermoNode.attrib("model");
    std::string mString = lowercase(mStringa);
    if (mString != "molarityionicvpss" && mString != "molarityionicvpsstp") {
        throw CanteraError(subname.c_str(),
                           "Unknown thermo model: " + mStringa + " - This object only knows \"MolarityIonicVPSSTP\" ");
    }

    /*
     * Go get all of the coefficients and factors in the
     * activityCoefficients XML block
     */
    XML_Node* acNodePtr = 0;
    if (thermoNode.hasChild("activityCoefficients")) {
        XML_Node& acNode = thermoNode.child("activityCoefficients");
        acNodePtr = &acNode;
        mStringa = acNode.attrib("model");
        mString = lowercase(mStringa);
        // if (mString != "redlich-kister") {
        //   throw CanteraError(subname.c_str(),
        //        "Unknown activity coefficient model: " + mStringa);
        //}
        size_t n = acNodePtr->nChildren();
        for (size_t i = 0; i < n; i++) {
            XML_Node& xmlACChild = acNodePtr->child(i);
            stemp = xmlACChild.name();
            std::string nodeName = lowercase(stemp);
            /*
             * Process a binary interaction
             */
            if (nodeName == "binaryneutralspeciesparameters") {
                readXMLBinarySpecies(xmlACChild);
            }
        }
    }


    /*
     * Go down the chain
     */
    GibbsExcessVPSSTP::initThermoXML(phaseNode, id);
}
Esempio n. 10
0
/*
  Read transport property data from a file for interactions
  between species in a liquid.
  Given the name of a file containing transport property
  parameters and a list of species names, this method returns an
  instance of TransportParams containing the transport data for
  these species read from the file.
*/
void TransportFactory::getLiquidInteractionsTransportData(const XML_Node& transportNode,
							  XML_Node& log,
							  const std::vector<std::string> &names,
							  LiquidTransportParams& trParam)
{
    try {

        size_t nsp = trParam.nsp_;
        size_t nBinInt = nsp*(nsp-1)/2;

        size_t num = transportNode.nChildren();
        for (size_t iChild = 0; iChild < num; iChild++) {
            //tranTypeNode is a type of transport property like viscosity
            XML_Node& tranTypeNode = transportNode.child(iChild);
            std::string nodeName = tranTypeNode.name();

            trParam.mobilityRatio.resize(nsp*nsp,0);
            trParam.selfDiffusion.resize(nsp,0);
            ThermoPhase* temp_thermo = trParam.thermo;

	    if (tranTypeNode.name() == "compositionDependence") {
		std::string modelName = tranTypeNode.attrib("model");
		std::map<string, LiquidTranMixingModel>::iterator it = m_LTImodelMap.find(modelName);
		if (it == m_LTImodelMap.end()) {
		    throw CanteraError("TransportFactory::getLiquidInteractionsTransportData",
				       "Unknown compositionDependence string: " + modelName);
		} else {
		    trParam.compositionDepTypeDefault_ = it->second;
		}
	    } else {
		if (tranTypeNode.hasChild("compositionDependence")) {
		    //compDepNode contains the interaction model
		    XML_Node& compDepNode = tranTypeNode.child("compositionDependence");
		    switch (m_tranPropMap[nodeName]) {
			break;
		    case TP_VISCOSITY:
			trParam.viscosity = newLTI(compDepNode, m_tranPropMap[nodeName], trParam);
			break;
		    case TP_IONCONDUCTIVITY:
			trParam.ionConductivity = newLTI(compDepNode,
							 m_tranPropMap[nodeName],
							 trParam);
			break;
		    case TP_MOBILITYRATIO: {
			for (size_t iSpec = 0; iSpec< nBinInt; iSpec++) {
			    XML_Node& propSpecNode = compDepNode.child(iSpec);
			    string specName = propSpecNode.name();
			    size_t loc = specName.find(":");
			    string firstSpec = specName.substr(0,loc);
			    string secondSpec = specName.substr(loc+1);
			    size_t index = temp_thermo->speciesIndex(firstSpec.c_str())+nsp*temp_thermo->speciesIndex(secondSpec.c_str());
			    trParam.mobilityRatio[index] = newLTI(propSpecNode,
								  m_tranPropMap[nodeName],
								  trParam);
			};
		    };
			break;
		    case TP_SELFDIFFUSION: {
			for (size_t iSpec = 0; iSpec< nsp; iSpec++) {
			    XML_Node& propSpecNode = compDepNode.child(iSpec);
			    string specName = propSpecNode.name();
			    size_t index = temp_thermo->speciesIndex(specName.c_str());
			    trParam.selfDiffusion[index] = newLTI(propSpecNode,
								  m_tranPropMap[nodeName],
								  trParam);
			};
		    };
			break;
		    case TP_THERMALCOND:
			trParam.thermalCond = newLTI(compDepNode,
						     m_tranPropMap[nodeName],
						     trParam);
			break;
		    case TP_DIFFUSIVITY:
			trParam.speciesDiffusivity = newLTI(compDepNode,
							    m_tranPropMap[nodeName],
							    trParam);
			break;
		    case TP_HYDRORADIUS:
			trParam.hydroRadius = newLTI(compDepNode,
						     m_tranPropMap[nodeName],
						     trParam);
			break;
		    case TP_ELECTCOND:
			trParam.electCond = newLTI(compDepNode,
						   m_tranPropMap[nodeName],
						   trParam);
			break;
		    default:
			throw CanteraError("getLiquidInteractionsTransportData","unknown transport property: " + nodeName);

		    }
		}
		/* Allow a switch between mass-averaged, mole-averaged
		 * and solvent specified reference velocities.
		 * XML code within the transportProperty node
		 * (i.e. within <viscosity>) should read as follows
		 * <velocityBasis basis="mass"> <!-- mass averaged -->
		 * <velocityBasis basis="mole"> <!-- mole averaged -->
		 * <velocityBasis basis="H2O">  <!-- H2O solvent -->
		 */
		if (tranTypeNode.hasChild("velocityBasis")) {
		    std::string velocityBasis =
			tranTypeNode.child("velocityBasis").attrib("basis");
		    if (velocityBasis == "mass") {
			trParam.velocityBasis_ = VB_MASSAVG;
		    } else if (velocityBasis == "mole") {
			trParam.velocityBasis_ = VB_MOLEAVG;
		    } else if (trParam.thermo->speciesIndex(velocityBasis) > 0) {
			trParam.velocityBasis_ = static_cast<int>(trParam.thermo->speciesIndex(velocityBasis));
		    } else {
			int linenum = __LINE__;
			throw TransportDBError(linenum, "Unknown attribute \"" + velocityBasis + "\" for <velocityBasis> node. ");
		    }
		}
	    }
	}
    } catch (CanteraError& err) {
        std::cout << err.what() << std::endl;
    }
    return;
}