From 3efddbac8a3ecd9e751bf9e471f627657f7797f8 Mon Sep 17 00:00:00 2001 From: ignis Date: Fri, 2 Jun 2017 20:50:09 +0900 Subject: [PATCH] new attr nCharges_ and related methods of specie and chemkinReader mod for cation name --- .../chemkinReader/chemkinLexer.L | 5 +- .../chemkinReader/chemkinReader.C | 22 +++++++ .../chemkinReader/chemkinReader.H | 5 ++ .../mixtures/SpecieMixture/SpecieMixture.C | 10 +++ .../mixtures/SpecieMixture/SpecieMixture.H | 3 + .../specie/specie/specie.C | 28 +++++++- .../specie/specie/specie.H | 46 +++++++++++++ .../specie/specie/specieI.H | 66 +++++++++++++++++-- .../specie/thermo/thermo/thermo.H | 16 +++++ .../specie/thermo/thermo/thermoI.H | 16 +++++ 10 files changed, 205 insertions(+), 12 deletions(-) diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L index 318cd7ab4..a5652d133 100644 --- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L +++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L @@ -148,7 +148,7 @@ irreversibleReactionDelimiter {space}"=>"{space} startPDependentSpecie {space}"("{space}"+"{space} pDependentSpecie {specieName}")"{space} reactionCoeffs {space}{floatNum}{some_space}{floatNum}{some_space}{floatNum}{space} -reactionKeyword {space}[A-Za-z](([A-Za-z0-9)*-])|("("[^+]))*{space} +reactionKeyword {space}[A-Za-z](([A-Za-z0-9)*-])|("("[^+]))*((\+({some_space}))?){space} reactionKeywordSlash {reactionKeyword}"/"{space} thirdBodyEfficiency {space}{floatNum}{space}"/"{space} startReactionCoeffs {space}"/"{space} @@ -637,7 +637,8 @@ bool finishReaction = false; ( currentSpecieName, 1.0, - molecularWeight(currentSpecieComposition) + molecularWeight(currentSpecieComposition), + chargeNumber(currentSpecieComposition) ), currentLowT, currentHighT, diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C index eef9f3a4d..e21d86ffb 100644 --- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C +++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C @@ -144,6 +144,28 @@ Foam::scalar Foam::chemkinReader::molecularWeight } +Foam::scalar Foam::chemkinReader::chargeNumber +( + const List& specieComposition +) const +{ + scalar nElemCharges = 0.0; + + forAll(specieComposition, i) + { + label nAtoms = specieComposition[i].nAtoms; + const word& elementName = specieComposition[i].elementName; + + if (elementName[0] == 'e') + { + nElemCharges -= nAtoms; + } + } + + return nElemCharges; +} + + void Foam::chemkinReader::checkCoeffs ( const scalarList& reactionCoeffs, diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.H b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.H index 916c8c06f..e9d228811 100644 --- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.H +++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.H @@ -254,6 +254,11 @@ private: const List& specieComposition ) const; + scalar chargeNumber + ( + const List& specieComposition + ) const; + void finishElements(labelList& currentAtoms); void checkCoeffs diff --git a/src/thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.C b/src/thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.C index f69cbeca5..853fe889a 100644 --- a/src/thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.C +++ b/src/thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.C @@ -68,6 +68,16 @@ Foam::scalar Foam::SpecieMixture::W } +template +Foam::scalar Foam::SpecieMixture::z +( + const label speciei +) const +{ + return this->getLocalThermo(speciei).z(); +} + + template Foam::scalar Foam::SpecieMixture::Cp ( diff --git a/src/thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.H index 24f95915a..1fc03f531 100644 --- a/src/thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.H +++ b/src/thermophysicalModels/reactionThermo/mixtures/SpecieMixture/SpecieMixture.H @@ -81,6 +81,9 @@ public: //- Molecular weight of the given specie [kg/kmol] virtual scalar W(const label speciei) const; + //- Number of elementary charges of the given specie [] + virtual scalar z(const label specieI) const; + // Per specie thermo properties diff --git a/src/thermophysicalModels/specie/specie/specie.C b/src/thermophysicalModels/specie/specie/specie.C index 8a4f7612a..8571e2263 100644 --- a/src/thermophysicalModels/specie/specie/specie.C +++ b/src/thermophysicalModels/specie/specie/specie.C @@ -29,6 +29,24 @@ License /* * * * * * * * * * * * * * * public constants * * * * * * * * * * * * * * */ +//- Universal gas constant (default in [J/(kmol K)]) +const Foam::scalar Foam::specie::RR = constant::physicoChemical::R.value()*1000; + +//- Standard pressure (default in [Pa]) +const Foam::scalar Foam::specie::Pstd = constant::standard::Pstd.value(); + +//- Standard temperature (default in [K]) +const Foam::scalar Foam::specie::Tstd = constant::standard::Tstd.value(); + +//- Elementary charge (default in [C]) +const Foam::scalar Foam::specie::e = constant::electromagnetic::e.value(); + +//- Avogadro number (default in [1/mol]) +const Foam::scalar Foam::specie::NA = constant::physicoChemical::NA.value()*1000; + +//- Boltzmann constant (default in [J/K]) +const Foam::scalar Foam::specie::k = constant::physicoChemical::k.value(); + namespace Foam { defineTypeNameAndDebug(specie, 0); @@ -41,7 +59,8 @@ Foam::specie::specie(Istream& is) : name_(is), nMoles_(readScalar(is)), - molWeight_(readScalar(is)) + molWeight_(readScalar(is)), + nCharges_(readScalar(is)) { is.check("specie::specie(Istream& is)"); } @@ -51,7 +70,8 @@ Foam::specie::specie(const dictionary& dict) : name_(dict.dictName()), nMoles_(readScalar(dict.subDict("specie").lookup("nMoles"))), - molWeight_(readScalar(dict.subDict("specie").lookup("molWeight"))) + molWeight_(readScalar(dict.subDict("specie").lookup("molWeight"))), + nCharges_(dict.subDict("specie").lookupOrDefault("nCharges", 0.0)) {} @@ -62,6 +82,7 @@ void Foam::specie::write(Ostream& os) const dictionary dict("specie"); dict.add("nMoles", nMoles_); dict.add("molWeight", molWeight_); + dict.add("nCharges", nCharges_); os << indent << dict.dictName() << dict; } @@ -72,7 +93,8 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const specie& st) { os << st.name_ << tab << st.nMoles_ << tab - << st.molWeight_; + << st.molWeight_ << tab + << st.nCharges_; os.check("Ostream& operator<<(Ostream& os, const specie& st)"); return os; diff --git a/src/thermophysicalModels/specie/specie/specie.H b/src/thermophysicalModels/specie/specie/specie.H index 28d729081..e48be854f 100644 --- a/src/thermophysicalModels/specie/specie/specie.H +++ b/src/thermophysicalModels/specie/specie/specie.H @@ -77,6 +77,9 @@ class specie //- Molecular weight of specie [kg/kmol] scalar molWeight_; + //- Number of elementary charges of specie + scalar nCharges_; + public: @@ -84,6 +87,29 @@ public: ClassName("specie"); + // Public constants + + // Thermodynamic constants + + //- Universal gas constant [J/(kmol K)] + static const scalar RR; + + //- Standard pressure [Pa] + static const scalar Pstd; + + //- Standard temperature [K] + static const scalar Tstd; + + //- Elementary charge [C] + static const scalar e; + + //- Avogadro number [1/kmol] + static const scalar NA; + + //- Boltzmann constant [J/K] + static const scalar k; + + // Constructors @@ -98,6 +124,23 @@ public: const scalar molWeight ); + //- Construct from components without name + inline specie + ( + const scalar nMoles, + const scalar molWeight, + const scalar nCharges + ); + + //- Construct from components with name + inline specie + ( + const word& name, + const scalar nMoles, + const scalar molWeight, + const scalar nCharges + ); + //- Construct as copy inline specie(const specie&); @@ -127,6 +170,9 @@ public: //- Gas constant [J/(kg K)] inline scalar R() const; + //- Charge number + inline scalar z() const; + // I-O diff --git a/src/thermophysicalModels/specie/specie/specieI.H b/src/thermophysicalModels/specie/specie/specieI.H index 76d979b3c..a0d498b5e 100644 --- a/src/thermophysicalModels/specie/specie/specieI.H +++ b/src/thermophysicalModels/specie/specie/specieI.H @@ -41,7 +41,8 @@ inline specie::specie : name_(name), nMoles_(nMoles), - molWeight_(molWeight) + molWeight_(molWeight), + nCharges_(0.0) {} @@ -52,7 +53,36 @@ inline specie::specie ) : nMoles_(nMoles), - molWeight_(molWeight) + molWeight_(molWeight), + nCharges_(0.0) +{} + + +inline specie::specie +( + const word& name, + const scalar nMoles, + const scalar molWeight, + const scalar nCharges +) +: + name_(name), + nMoles_(nMoles), + molWeight_(molWeight), + nCharges_(nCharges) +{} + + +inline specie::specie +( + const scalar nMoles, + const scalar molWeight, + const scalar nCharges +) +: + nMoles_(nMoles), + molWeight_(molWeight), + nCharges_(nCharges) {} @@ -62,7 +92,8 @@ inline specie::specie(const specie& st) : name_(st.name_), nMoles_(st.nMoles_), - molWeight_(st.molWeight_) + molWeight_(st.molWeight_), + nCharges_(st.nCharges_) {} @@ -70,7 +101,8 @@ inline specie::specie(const word& name, const specie& st) : name_(name), nMoles_(st.nMoles_), - molWeight_(st.molWeight_) + molWeight_(st.molWeight_), + nCharges_(st.nCharges_) {} @@ -100,6 +132,12 @@ inline scalar specie::R() const } +inline scalar specie::z() const +{ + return nCharges_; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // inline void specie::operator=(const specie& st) @@ -107,6 +145,7 @@ inline void specie::operator=(const specie& st) //name_ = st.name_; nMoles_ = st.nMoles_; molWeight_ = st.molWeight_; + nCharges_ = st.nCharges_; } @@ -114,6 +153,10 @@ inline void specie::operator+=(const specie& st) { scalar sumNmoles = max(nMoles_ + st.nMoles_, SMALL); + nCharges_ = + nMoles_/sumNmoles*nCharges_ + + st.nMoles_/sumNmoles*st.nCharges_; + molWeight_ = nMoles_/sumNmoles*molWeight_ + st.nMoles_/sumNmoles*st.molWeight_; @@ -130,6 +173,10 @@ inline void specie::operator-=(const specie& st) diffnMoles = SMALL; } + nCharges_ = + nMoles_/diffnMoles*nCharges_ + - st.nMoles_/diffnMoles*st.nCharges_; + molWeight_ = nMoles_/diffnMoles*molWeight_ - st.nMoles_/diffnMoles*st.molWeight_; @@ -154,7 +201,9 @@ inline specie operator+(const specie& st1, const specie& st2) ( sumNmoles, st1.nMoles_/sumNmoles*st1.molWeight_ - + st2.nMoles_/sumNmoles*st2.molWeight_ + + st2.nMoles_/sumNmoles*st2.molWeight_, + st1.nMoles_/sumNmoles*st1.nCharges_ + + st2.nMoles_/sumNmoles*st2.nCharges_ ); } @@ -171,7 +220,9 @@ inline specie operator-(const specie& st1, const specie& st2) ( diffNmoles, st1.nMoles_/diffNmoles*st1.molWeight_ - - st2.nMoles_/diffNmoles*st2.molWeight_ + - st2.nMoles_/diffNmoles*st2.molWeight_, + st1.nMoles_/diffNmoles*st1.nCharges_ + - st2.nMoles_/diffNmoles*st2.nCharges_ ); } @@ -181,7 +232,8 @@ inline specie operator*(const scalar s, const specie& st) return specie ( s*st.nMoles_, - st.molWeight_ + st.molWeight_, + st.nCharges_ ); } diff --git a/src/thermophysicalModels/specie/thermo/thermo/thermo.H b/src/thermophysicalModels/specie/thermo/thermo/thermo.H index 9820f1147..c0c42c479 100644 --- a/src/thermophysicalModels/specie/thermo/thermo/thermo.H +++ b/src/thermophysicalModels/specie/thermo/thermo/thermo.H @@ -336,6 +336,22 @@ public: ) const; + // Electric charge function + + + // Mole specific properties + + //- Electric charge [C/kmol] + inline scalar qc() const; + + + // Mass specific properties + + //- Electric charge [C/kg] + inline scalar QC() const; + + + // I-O //- Write to Ostream diff --git a/src/thermophysicalModels/specie/thermo/thermo/thermoI.H b/src/thermophysicalModels/specie/thermo/thermo/thermoI.H index 44197fd18..4252c50d2 100644 --- a/src/thermophysicalModels/specie/thermo/thermo/thermoI.H +++ b/src/thermophysicalModels/specie/thermo/thermo/thermoI.H @@ -530,4 +530,20 @@ inline Foam::species::thermo Foam::species::operator== } +template class Type> +inline Foam::scalar +Foam::species::thermo::qc() const +{ + return this->z() * this->NA * this->e; +} + + +template class Type> +inline Foam::scalar +Foam::species::thermo::QC() const +{ + return this->z() * this->NA * this->e / this->W(); +} + + // ************************************************************************* //