diff --git a/applications/test/Polynomial/Make/options b/applications/test/Polynomial/Make/options index 1b983985770833401ab9dbd2bbce72c2c867c0c8..4c3dd783cb4170feefb3f5385510a83257b43b18 100644 --- a/applications/test/Polynomial/Make/options +++ b/applications/test/Polynomial/Make/options @@ -1,3 +1,3 @@ -EXE_INC = \ +EXE_INC = -EXE_LIBS = \ +EXE_LIBS = diff --git a/applications/test/Polynomial/PolynomialTest.C b/applications/test/Polynomial/PolynomialTest.C index 4b7db7ef6f9b767871a5af50ea8583f421ed075f..fbfbcc20006505bcabf9ff34e117f7021bbf6dab 100644 --- a/applications/test/Polynomial/PolynomialTest.C +++ b/applications/test/Polynomial/PolynomialTest.C @@ -29,24 +29,30 @@ Description \*---------------------------------------------------------------------------*/ -#include "IFstream.H" +#include "IStringStream.H" #include "Polynomial.H" #include "Random.H" +#include "cpuTime.H" using namespace Foam; +const int PolySize = 8; +const scalar coeff[] = { 0.11, 0.45, -0.94, 1.58, -2.58, 0.08, 3.15, -4.78 }; +const char* polyDef = "testPoly (0.11 0.45 -0.94 1.58 -2.58 0.08 3.15 -4.78)"; + + scalar polyValue(const scalar x) { // Hard-coded polynomial 8 coeff (7th order) return - 0.11 - + 0.45*x - - 0.94*sqr(x) - + 1.58*pow3(x) - - 2.58*pow4(x) - + 0.08*pow5(x) - + 3.15*pow6(x) - - 4.78*x*pow6(x); + coeff[0] + + coeff[1]*x + + coeff[2]*sqr(x) + + coeff[3]*pow3(x) + + coeff[4]*pow4(x) + + coeff[5]*pow5(x) + + coeff[6]*pow6(x) + + coeff[7]*x*pow6(x); } @@ -54,14 +60,44 @@ scalar intPolyValue(const scalar x) { // Hard-coded integrated form of above polynomial return - 0.11*x - + 0.45/2.0*sqr(x) - - 0.94/3.0*pow3(x) - + 1.58/4.0*pow4(x) - - 2.58/5.0*pow5(x) - + 0.08/6.0*pow6(x) - + 3.15/7.0*x*pow6(x) - - 4.78/8.0*x*x*pow6(x); + coeff[0]*x + + coeff[1]/2.0*sqr(x) + + coeff[2]/3.0*pow3(x) + + coeff[3]/4.0*pow4(x) + + coeff[4]/5.0*pow5(x) + + coeff[5]/6.0*pow6(x) + + coeff[6]/7.0*x*pow6(x) + + coeff[7]/8.0*x*x*pow6(x); +} + + +scalar polyValue1(const scalar x) +{ + // "normal" evaluation using pow() + scalar value = coeff[0]; + + for (int i=1; i < PolySize; ++i) + { + value += coeff[i]*pow(x, i); + } + + return value; +} + + +scalar polyValue2(const scalar x) +{ + // calculation avoiding pow() + scalar value = coeff[0]; + + scalar powX = x; + for (int i=1; i < PolySize; ++i) + { + value += coeff[i] * powX; + powX *= x; + } + + return value; } @@ -69,9 +105,14 @@ scalar intPolyValue(const scalar x) int main(int argc, char *argv[]) { - IFstream is("polyTestInput"); + const label n = 10000; + const label nIters = 1000; + scalar sum = 0.0; - Polynomial<8> poly("testPoly", is); + Info<< "null poly = " << (Polynomial<8>()) << nl << endl; + + // Polynomial<8> poly("testPoly", IStringStream(polyDef)()); + Polynomial<8> poly(coeff); Polynomial<9> intPoly(poly.integrate(0.0)); Info<< "poly = " << poly << endl; @@ -118,6 +159,62 @@ int main(int argc, char *argv[]) Info<< endl; } + + // + // test speed of Polynomial: + // + Info<< "start timing loops" << nl + << "~~~~~~~~~~~~~~~~~~" << endl; + + cpuTime timer; + + for (int loop = 0; loop < n; ++loop) + { + sum = 0.0; + for (label iter = 0; iter < nIters; ++iter) + { + sum += poly.evaluate(loop+iter); + } + } + Info<< "evaluate: " << sum + << " in " << timer.cpuTimeIncrement() << " s\n"; + + + for (int loop = 0; loop < n; ++loop) + { + sum = 0.0; + for (label iter = 0; iter < nIters; ++iter) + { + sum += polyValue(loop+iter); + } + } + Info<< "hard-coded 0: " << sum + << " in " << timer.cpuTimeIncrement() << " s\n"; + + + for (int loop = 0; loop < n; ++loop) + { + sum = 0.0; + for (label iter = 0; iter < nIters; ++iter) + { + sum += polyValue1(loop+iter); + } + } + Info<< "hard-coded 1: " << sum + << " in " << timer.cpuTimeIncrement() << " s\n"; + + for (int loop = 0; loop < n; ++loop) + { + sum = 0.0; + for (label iter = 0; iter < nIters; ++iter) + { + sum += polyValue2(loop+iter); + } + } + Info<< "hard-coded 2: " << sum + << " in " << timer.cpuTimeIncrement() << " s\n"; + + Info<< nl << "Done." << endl; return 0; diff --git a/applications/test/Polynomial/polyTestInput b/applications/test/Polynomial/polyTestInput deleted file mode 100644 index 4ba8f65e51f4dc8a68381d3e9af7bbf30a1d2a39..0000000000000000000000000000000000000000 --- a/applications/test/Polynomial/polyTestInput +++ /dev/null @@ -1,11 +0,0 @@ - testPoly - ( - 0.11 - 0.45 - -0.94 - 1.58 - -2.58 - 0.08 - 3.15 - -4.78 - ) diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 94bc86f2efeacf8cfc767223e141b8b27c02f058..97513b339d4a3a3ecf513e47f95b365a81a98b06 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -85,6 +85,7 @@ $(primitiveLists)/vectorListIOList.C $(primitiveLists)/sphericalTensorList.C $(primitiveLists)/symmTensorList.C $(primitiveLists)/tensorList.C +$(primitiveLists)/hashedWordList.C Streams = db/IOstreams $(Streams)/token/tokenIO.C diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/polyMeshTetDecomposition.C b/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/polyMeshTetDecomposition.C index 23e7a3c52e2ef55168f48aeecfcec773fa6c4c40..8f29b9e9343d81bcb1a6815d63196fa22b461e7e 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/polyMeshTetDecomposition.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/polyMeshTetDecomposition.C @@ -27,7 +27,7 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -const Foam::scalar Foam::polyMeshTetDecomposition::minTetQuality = 1e-9; +const Foam::scalar Foam::polyMeshTetDecomposition::minTetQuality = 1e-12; // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/Lists/hashedWordList.C b/src/OpenFOAM/primitives/Lists/hashedWordList.C new file mode 100644 index 0000000000000000000000000000000000000000..e9206bda8e00bf05c468a9be718c4b80664f108d --- /dev/null +++ b/src/OpenFOAM/primitives/Lists/hashedWordList.C @@ -0,0 +1,159 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "hashedWordList.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::hashedWordList::rehash() +{ + indices_.clear(); + forAll(*this, i) + { + indices_.insert(List<word>::operator[](i), i); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::hashedWordList::hashedWordList() +: + List<word>() +{} + + +Foam::hashedWordList::hashedWordList(const UList<word>& names) +: + List<word>(names) +{ + rehash(); +} + + +Foam::hashedWordList::hashedWordList(const hashedWordList& names) +: + List<word>(static_cast<const UList<word>&>(names)) +{ + rehash(); +} + + +Foam::hashedWordList::hashedWordList(const Xfer< List<word> >& names) +: + List<word>(names) +{ + rehash(); +} + + +Foam::hashedWordList::hashedWordList +( + const label nNames, + const char** names +) +: + List<word>(nNames) +{ + forAll(*this, i) + { + List<word>::operator[](i) = names[i]; + } + + rehash(); +} + + +Foam::hashedWordList::hashedWordList +( + const char** names +) +{ + // count names + label nNames = 0; + for (unsigned i = 0; names[i] && *(names[i]); ++i) + { + ++nNames; + } + + List<word>::setSize(nNames); + forAll(*this, i) + { + List<word>::operator[](i) = names[i]; + } + + rehash(); +} + + +Foam::hashedWordList::hashedWordList(Istream& is) +{ + is >> *this; +} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::hashedWordList::clear() +{ + List<word>::clear(); + indices_.clear(); +} + + +void Foam::hashedWordList::append(const word& name) +{ + const label idx = size(); + List<word>::append(name); + indices_.insert(name, idx); +} + + +void Foam::hashedWordList::transfer(List<word>& lst) +{ + List<word>::transfer(lst); + rehash(); +} + + +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + +Foam::Istream& Foam::operator>>(Istream& is, hashedWordList& lst) +{ + is >> static_cast<List<word>&>(lst); + lst.rehash(); + + return is; +} + + +Foam::Ostream& Foam::operator<<(Ostream& os, const hashedWordList& lst) +{ + os << static_cast<const List<word>&>(lst); + return os; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/Lists/hashedWordList.H b/src/OpenFOAM/primitives/Lists/hashedWordList.H new file mode 100644 index 0000000000000000000000000000000000000000..93a23d8db362b0ce1b7bc460d87a14a0042e237c --- /dev/null +++ b/src/OpenFOAM/primitives/Lists/hashedWordList.H @@ -0,0 +1,149 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::hashedWordList + +Description + A wordList with hashed indices for faster lookup by name. + +SourceFiles + hashedWordListI.H + hashedWordList.C + +\*---------------------------------------------------------------------------*/ + +#ifndef hashedWordList_H +#define hashedWordList_H + +#include "wordList.H" +#include "HashTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class hashedWordList; + +// Forward declaration of friend functions and operators +Istream& operator>>(Istream&, hashedWordList&); +Ostream& operator<<(Ostream&, const hashedWordList&); + + +/*---------------------------------------------------------------------------*\ + Class hashedWordList Declaration +\*---------------------------------------------------------------------------*/ + +class hashedWordList +: + public List<word> +{ + // Private data + + HashTable<label, word> indices_; + + + // Private Member Functions + + //- rebuild the hash of indices + void rehash(); + +public: + + // Constructors + + //- Construct null + hashedWordList(); + + //- Copy constructor. + hashedWordList(const hashedWordList&); + + //- Construct from list of names + hashedWordList(const UList<word>& names); + + //- Construct by transferring the parameter contents + hashedWordList(const Xfer< List<word> >& names); + + //- Construct from number and list of names + hashedWordList(const label nNames, const char** names); + + //- Construct from a NULL-terminated list of names + hashedWordList(const char** names); + + //- Construct from Istream + hashedWordList(Istream&); + + + // Member Functions + + //- Clear the list, i.e. set size to zero. + void clear(); + + //- Append an element at the end of the list + void append(const word&); + + //- Does the list contain the specified name + inline bool contains(const word&) const; + + //- Transfer the contents of the argument List into this list + // and annul the argument list. + void transfer(List<word>&); + + + // Member Operators + + //- Assignment operator from list of names + inline void operator=(const UList<word>& names); + + //- Assignment operator. + inline void operator=(const hashedWordList&); + + //- Allow readonly access to list of words + inline operator const Foam::UList<word>&() const; + + //- Return name corresponding to specified index + inline const word& operator[](const label index) const; + + //- Return index corresponding to specified name + inline label operator[](const word&) const; + + + // Istream operators + + friend Istream& operator>>(Istream&, hashedWordList&); + friend Ostream& operator<<(Ostream&, const hashedWordList&); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "hashedWordListI.H" + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/specie/speciesTable/speciesTableI.H b/src/OpenFOAM/primitives/Lists/hashedWordListI.H similarity index 66% rename from src/thermophysicalModels/specie/speciesTable/speciesTableI.H rename to src/OpenFOAM/primitives/Lists/hashedWordListI.H index 8a8c85694a41d0672badda70c3b1fa42838bf947..1e736aa6c58217d95b6b56f94883b769a764bd94 100644 --- a/src/thermophysicalModels/specie/speciesTable/speciesTableI.H +++ b/src/OpenFOAM/primitives/Lists/hashedWordListI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -21,32 +21,44 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. -Description - \*---------------------------------------------------------------------------*/ // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline bool Foam::speciesTable::contains(const word& specieName) const +inline bool Foam::hashedWordList::contains(const word& name) const { - return specieIndices_.found(specieName); + return indices_.found(name); } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -inline const Foam::word& Foam::speciesTable::operator[] +inline void Foam::hashedWordList::operator=(const UList<word>& lst) +{ + List<word>::operator=(lst); + rehash(); +} + + +inline void Foam::hashedWordList::operator=(const hashedWordList& lst) +{ + operator=(static_cast<const UList<word>&>(lst)); +} + + +inline const Foam::word& Foam::hashedWordList::operator[] ( - const label specieIndex + const label index ) const { - return wordList::operator[](specieIndex); + return List<word>::operator[](index); } -inline Foam::label Foam::speciesTable::operator[](const word& specieName) const +// could return -1 instead of bombing out +inline Foam::label Foam::hashedWordList::operator[](const word& name) const { - return specieIndices_[specieName]; + return indices_[name]; } diff --git a/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.C b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.C index 1e7b7aa6180d037cca9ddd0f06a73aaf87b79fe1..cff374464498d84cfacb4f0dae5c036d75606e81 100644 --- a/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.C +++ b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.C @@ -33,7 +33,50 @@ Foam::Polynomial<PolySize>::Polynomial() VectorSpace<Polynomial<PolySize>, scalar, PolySize>(), logActive_(false), logCoeff_(0.0) -{} +{ + for (int i = 0; i < PolySize; ++i) + { + this->v_[i] = 0.0; + } +} + + +template<int PolySize> +Foam::Polynomial<PolySize>::Polynomial(const scalar coeffs[PolySize]) +: + VectorSpace<Polynomial<PolySize>, scalar, PolySize>(), + logActive_(false), + logCoeff_(0.0) +{ + for (int i=0; i<PolySize; i++) + { + this->v_[i] = coeffs[i]; + } +} + + +template<int PolySize> +Foam::Polynomial<PolySize>::Polynomial(const UList<scalar>& coeffs) +: + VectorSpace<Polynomial<PolySize>, scalar, PolySize>(), + logActive_(false), + logCoeff_(0.0) +{ + if (coeffs.size() != PolySize) + { + FatalErrorIn + ( + "Polynomial<PolySize>::Polynomial(const UList<scalar>&)" + ) << "Size mismatch: Needed " << PolySize + << " but got " << coeffs.size() + << nl << exit(FatalError); + } + + for (int i = 0; i < PolySize; ++i) + { + this->v_[i] = coeffs[i]; + } +} template<int PolySize> @@ -101,9 +144,12 @@ Foam::scalar Foam::Polynomial<PolySize>::evaluate(const scalar x) const { scalar y = this->v_[0]; - for (label i=1; i<PolySize; i++) + // avoid costly pow() in calculation + scalar powX = x; + for (label i=1; i<PolySize; ++i) { - y += this->v_[i]*pow(x, i); + y += this->v_[i]*powX; + powX *= x; } if (logActive_) @@ -170,13 +216,9 @@ Foam::Polynomial<PolySize>::integrateMinus1(const scalar intConstant) } newCoeffs[0] = intConstant; - - if (PolySize > 0) + for (label i=1; i<PolySize; ++i) { - for (label i=1; i<PolySize; i++) - { - newCoeffs[i] = this->v_[i]/i; - } + newCoeffs[i] = this->v_[i]/i; } return newCoeffs; diff --git a/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H index cbfe045803289a0801ee7ed34f05abe112662653..f2449d1835a7a792b5c3dae53c2e92b3f537ba35 100644 --- a/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H +++ b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H @@ -29,7 +29,7 @@ Description poly = logCoeff*log(x) + sum(coeff_[i]*x^i) - where 0 <= i <= n + where 0 \<= i \<= n - integer powers, starting at zero - evaluate(x) to evaluate the poly for a given value @@ -51,6 +51,7 @@ SourceFiles #include "scalar.H" #include "Ostream.H" #include "VectorSpace.H" +#include "StaticAssert.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -79,6 +80,9 @@ class Polynomial : public VectorSpace<Polynomial<PolySize>, scalar, PolySize> { + //- Size must be positive (non-zero) + StaticAssert(PolySize > 0); + // Private data //- Include the log term? - only activated using integrateMinus1() @@ -97,9 +101,15 @@ public: // Constructors - //- Construct null + //- Construct null, with all coefficients = 0.0 Polynomial(); + //- Construct from C-array of coefficients + explicit Polynomial(const scalar coeffs[PolySize]); + + //- Construct from a list of coefficients + explicit Polynomial(const UList<scalar>& coeffs); + //- Construct from name and Istream Polynomial(const word& name, Istream& is); diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.C index 5b608b0fd9d283f4529f9915ca20178823a6acff..0010ab4a0a0b40b4f2611c509954d9a9ed32f610 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.C @@ -205,6 +205,13 @@ void cyclicFvPatchField<Type>::updateInterfaceMatrix } +template<class Type> +void cyclicFvPatchField<Type>::write(Ostream& os) const +{ + fvPatchField<Type>::write(os); +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.H index 6efcc50b2caab87e608f6f973e76b9b4cdbd104d..654bd0831a560a95b6b1e86d0d5f9c8ad53e99e6 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.H @@ -165,7 +165,7 @@ public: ) const; - //- Cyclic coupled interface functions + // Cyclic coupled interface functions //- Does the patch field perform the transfromation virtual bool doTransform() const @@ -190,6 +190,12 @@ public: { return pTraits<Type>::rank; } + + + // I-O + + //- Write + virtual void write(Ostream& os) const; }; diff --git a/src/thermophysicalModels/liquidMixture/Make/options b/src/thermophysicalModels/liquidMixture/Make/options index 506b8ac9a2b80e5a2cc7947815d3e43f9b64d635..bfa6b569ba77177a6a88d674a674ce257c84e2fd 100644 --- a/src/thermophysicalModels/liquidMixture/Make/options +++ b/src/thermophysicalModels/liquidMixture/Make/options @@ -5,3 +5,7 @@ EXE_INC = \ -I$(LIB_SRC)/thermophysicalModels/combustion/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/thermophysicalFunctions/lnInclude +LIB_LIBS = \ + -lliquids \ + -lthermophysicalFunctions + diff --git a/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.C b/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.C index 4941eab537034429aa425d448ba492a7f4929856..d46e3e110ac888a0c514bbcf0acbd74e32234143 100644 --- a/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.C +++ b/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.C @@ -31,6 +31,7 @@ License const Foam::scalar Foam::liquidMixture::TrMax = 0.999; + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::liquidMixture::liquidMixture @@ -41,32 +42,26 @@ Foam::liquidMixture::liquidMixture components_(thermophysicalProperties.lookup("liquidComponents")), properties_(components_.size()) { - // use sub-dictionary "liquidProperties" if possible to avoid + // can use sub-dictionary "liquidProperties" to avoid // collisions with identically named gas-phase entries // (eg, H2O liquid vs. gas) + const dictionary* subDictPtr = thermophysicalProperties.subDictPtr + ( + "liquidProperties" + ); + + const dictionary& props = + ( + subDictPtr ? *subDictPtr : thermophysicalProperties + ); + forAll(components_, i) { - const dictionary* subDictPtr = thermophysicalProperties.subDictPtr + properties_.set ( - "liquidProperties" + i, + liquid::New(props.lookup(components_[i])) ); - - if (subDictPtr) - { - properties_.set - ( - i, - liquid::New(subDictPtr->lookup(components_[i])) - ); - } - else - { - properties_.set - ( - i, - liquid::New(thermophysicalProperties.lookup(components_[i])) - ); - } } } diff --git a/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.H b/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.H index a5ae1c3fbb43324c2accb65869b24b9661e94463..88102564759a053bf1c4421141dc93631ab64397 100644 --- a/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.H +++ b/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.H @@ -103,7 +103,7 @@ class liquidMixture { // Private data - // maximum reduced temperature + //- Maximum reduced temperature static const scalar TrMax; //- The names of the liquids @@ -130,6 +130,7 @@ public: // Member Functions + //- Return the liquid names inline const List<word>& components() const { return components_; @@ -141,6 +142,13 @@ public: return properties_; } + //- Return the number of liquids in the mixture + inline label size() const + { + return components_.size(); + } + + //- Calculate the critical temperature of mixture scalar Tc(const scalarField& x) const; diff --git a/src/thermophysicalModels/liquids/Make/options b/src/thermophysicalModels/liquids/Make/options index 8a129fda6c391f107f38f8ca5031a3bb352b884d..b964b61294c787fe650b03faee1b09bbb9b48256 100644 --- a/src/thermophysicalModels/liquids/Make/options +++ b/src/thermophysicalModels/liquids/Make/options @@ -1 +1,5 @@ -EXE_INC = -I$(LIB_SRC)/thermophysicalModels/thermophysicalFunctions/lnInclude +EXE_INC = \ + -I$(LIB_SRC)/thermophysicalModels/thermophysicalFunctions/lnInclude + +LIB_LIBS = \ + -lthermophysicalFunctions diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/greyMeanAbsorptionEmission/greyMeanAbsorptionEmission.H b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/greyMeanAbsorptionEmission/greyMeanAbsorptionEmission.H index deec87298df9e19e0dfa7003c1e1e2f6c0047605..0ac653c9c032ff54c4ddd4feee21e994a9d4b610 100644 --- a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/greyMeanAbsorptionEmission/greyMeanAbsorptionEmission.H +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/greyMeanAbsorptionEmission/greyMeanAbsorptionEmission.H @@ -44,38 +44,38 @@ Description The look-up table ("speciesTable") file should be in constant i.e. dictionary + @verbatim + LookUpTableFileName "speciesTable"; - LookUpTableFileName "speciesTable"; + EhrrCoeff 0.0; - EhrrCoeff 0.0; - - CO2 - { - Tcommon 300.; // Common Temp - invTemp true; // Is the polynomial using inverse temperature? - Tlow 300.; // Low Temp - Thigh 2500.; // High Temp - - loTcoeffs // coeffs for T < Tcommon - ( - 0 // a0 + - 0 // a1*T + - 0 // a2*T^(+/-)2 + - 0 // a3*T^(+/-)3 + - 0 // a4*T^(+/-)4 + - 0 // a5*T^(+/-)5 + - ); - hiTcoeffs // coeffs for T > Tcommon - ( - 18.741 - -121.31e3 - 273.5e6 - -194.05e9 - 56.31e12 - -5.8169e15 - ); - - } + CO2 + { + Tcommon 300.; // Common Temp + invTemp true; // Is the polynomial using inverse temperature? + Tlow 300.; // Low Temp + Thigh 2500.; // High Temp + + loTcoeffs // coeffs for T < Tcommon + ( + 0 // a0 + + 0 // a1*T + + 0 // a2*T^(+/-)2 + + 0 // a3*T^(+/-)3 + + 0 // a4*T^(+/-)4 + + 0 // a5*T^(+/-)5 + + ); + hiTcoeffs // coeffs for T > Tcommon + ( + 18.741 + -121.31e3 + 273.5e6 + -194.05e9 + 56.31e12 + -5.8169e15 + ); + } + @endverbatim SourceFiles greyMeanAbsorptionEmission.C diff --git a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.H b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.H index f1194b3f0cce046053b8f4386f2925e9d6f68bab..4b93da89de9a4f2a8bea7f12ed2e0f2cfe5c1b6d 100644 --- a/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.H +++ b/src/thermophysicalModels/radiation/submodels/absorptionEmissionModel/wideBandAbsorptionEmission/wideBandAbsorptionEmission.H @@ -46,53 +46,52 @@ Description The look Up table file should be in the constant directory. band dictionary: - - band0 - { - bandLimits (1.0e-6 2.63e-6); - EhrrCoeff 0.0; - species + @verbatim + band0 { - CH4 - { - Tcommon 300.; - Tlow 300.; - Thigh 2500.; - invTemp false; - loTcoeffs (0 0 0 0 0 0) ; - hiTcoeffs (.1 0 0 0 0 0); - } - CO2 - { - Tcommon 300.; - Tlow 300.; - Thigh 2500.; - invTemp false; - loTcoeffs (0 0 0 0 0 0) ; - hiTcoeffs (.1 0 0 0 0 0); - } - - H2O - { - Tcommon 300.; - Tlow 300.; - Thigh 2500.; - invTemp false; - loTcoeffs (0 0 0 0 0 0) ; - hiTcoeffs (.1 0 0 0 0 0); - } - - Ysoot + bandLimits (1.0e-6 2.63e-6); + EhrrCoeff 0.0; + species { - Tcommon 300.; - Tlow 300.; - Thigh 2500.; - invTemp false; - loTcoeffs (0 0 0 0 0 0) ; - hiTcoeffs (.1 0 0 0 0 0); + CH4 + { + Tcommon 300.; + Tlow 300.; + Thigh 2500.; + invTemp false; + loTcoeffs (0 0 0 0 0 0) ; + hiTcoeffs (.1 0 0 0 0 0); + } + CO2 + { + Tcommon 300.; + Tlow 300.; + Thigh 2500.; + invTemp false; + loTcoeffs (0 0 0 0 0 0) ; + hiTcoeffs (.1 0 0 0 0 0); + } + H2O + { + Tcommon 300.; + Tlow 300.; + Thigh 2500.; + invTemp false; + loTcoeffs (0 0 0 0 0 0) ; + hiTcoeffs (.1 0 0 0 0 0); + } + Ysoot + { + Tcommon 300.; + Tlow 300.; + Thigh 2500.; + invTemp false; + loTcoeffs (0 0 0 0 0 0) ; + hiTcoeffs (.1 0 0 0 0 0); + } } } - } + @endverbatim SourceFiles diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C index 80418cbc8379ce669b481e1a39e57dd4ad5c32b9..b474c59451893ac60dc5a827f5a373208d06b8cc 100644 --- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C +++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C @@ -859,7 +859,7 @@ Foam::chemkinReader::chemkinReader : lineNo_(1), specieNames_(10), - speciesTable_(static_cast<const wordList&>(wordList())) + speciesTable_() { read(CHEMKINFileName, thermoFileName); } @@ -870,7 +870,7 @@ Foam::chemkinReader::chemkinReader(const dictionary& thermoDict) : lineNo_(1), specieNames_(10), - speciesTable_(static_cast<const wordList&>(wordList())) + speciesTable_() { fileName chemkinFile ( diff --git a/src/thermophysicalModels/solidMixture/solidMixture/solidMixture.C b/src/thermophysicalModels/solidMixture/solidMixture/solidMixture.C index 55ccd4057f79feb030897afd879066cab33fdbdc..6cf516339739f5c8f2fe0349bda1b7f832d6fa71 100644 --- a/src/thermophysicalModels/solidMixture/solidMixture/solidMixture.C +++ b/src/thermophysicalModels/solidMixture/solidMixture/solidMixture.C @@ -35,13 +35,24 @@ Foam::solidMixture::solidMixture components_(thermophysicalProperties.lookup("solidComponents")), properties_(components_.size()) { + // can use sub-dictionary "solidProperties" to avoid + // collisions with identically named gas-phase entries + const dictionary* subDictPtr = thermophysicalProperties.subDictPtr + ( + "solidProperties" + ); + + const dictionary& props = + ( + subDictPtr ? *subDictPtr : thermophysicalProperties + ); forAll(components_, i) { properties_.set ( i, - solid::New(thermophysicalProperties.lookup(components_[i])) + solid::New(props.lookup(components_[i])) ); } } @@ -82,12 +93,12 @@ Foam::scalar Foam::solidMixture::rho const scalarField& X ) const { - scalar tmp = 0.0; + scalar val = 0.0; forAll(properties_, i) { - tmp += properties_[i].rho()*X[i]; + val += properties_[i].rho()*X[i]; } - return tmp; + return val; } @@ -96,12 +107,12 @@ Foam::scalar Foam::solidMixture::cp const scalarField& Y ) const { - scalar tmp = 0.0; + scalar val = 0.0; forAll(properties_, i) { - tmp += properties_[i].cp()*Y[i]; + val += properties_[i].cp()*Y[i]; } - return tmp; + return val; } diff --git a/src/thermophysicalModels/solidMixture/solidMixture/solidMixture.H b/src/thermophysicalModels/solidMixture/solidMixture/solidMixture.H index 50f8b54a6c2dbd86d869d363d744ca7defe93bd1..ba1d582ee58735f5c8b446cd9b64e181fb1b9bac 100644 --- a/src/thermophysicalModels/solidMixture/solidMixture/solidMixture.H +++ b/src/thermophysicalModels/solidMixture/solidMixture/solidMixture.H @@ -25,7 +25,18 @@ Class Foam::solidMixture Description - Foam::solidMixture + A mixture of solids. + +Note + The dictionary constructor searches for the entry @c solidComponents, + which is a wordList. The solid properties of each component can either + be contained within a @c solidProperties sub-dictionary or (for legacy + purposes) can be found directly in the dictionary. + The @c solidProperties sub-dictionary entry should be used when possible + to avoid conflicts with identically named gas-phase entries. + +SeeAlso + Foam::liquidMixture \*---------------------------------------------------------------------------*/ @@ -74,7 +85,7 @@ public: // Member Functions - //- Return the sold names + //- Return the solid names inline const List<word>& components() const { return components_; @@ -86,6 +97,13 @@ public: return properties_; } + //- Return the number of solids in the mixture + inline label size() const + { + return components_.size(); + } + + //- Returns the mass fractions, given mole fractions scalarField Y(const scalarField& X) const; diff --git a/src/thermophysicalModels/specie/Make/files b/src/thermophysicalModels/specie/Make/files index 428f6d8fc7784f5ba6e2226740d0ffddfada9b4f..0e0eacae89436c09f3c49416c7310b318d5dc6ae 100644 --- a/src/thermophysicalModels/specie/Make/files +++ b/src/thermophysicalModels/specie/Make/files @@ -1,12 +1,10 @@ atomicWeights = atomicWeights specie = specie -speciesTable = speciesTable equationOfState = equationOfState reactions = reaction/reactions $(atomicWeights)/atomicWeights.C $(specie)/specie.C -$(speciesTable)/speciesTable.C $(equationOfState)/perfectGas/perfectGas.C $(reactions)/makeChemkinReactions.C $(reactions)/makeReactionThermoReactions.C diff --git a/src/thermophysicalModels/specie/reaction/reactionRate/thirdBodyEfficiencies/thirdBodyEfficienciesI.H b/src/thermophysicalModels/specie/reaction/reactionRate/thirdBodyEfficiencies/thirdBodyEfficienciesI.H index 8e8096fa7183f41dc4bd8d8c6fc04acfe01af0af..dd6008f09ec713f26e37efb256aaa15971bb6467 100644 --- a/src/thermophysicalModels/specie/reaction/reactionRate/thirdBodyEfficiencies/thirdBodyEfficienciesI.H +++ b/src/thermophysicalModels/specie/reaction/reactionRate/thirdBodyEfficiencies/thirdBodyEfficienciesI.H @@ -42,7 +42,7 @@ inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies "thirdBodyEfficiencies::thirdBodyEfficiencies" "(const speciesTable& species, const scalarList& efficiencies)" ) << "number of efficiencies = " << size() - << " is not equat to the number of species " << species_.size() + << " is not equal to the number of species " << species_.size() << exit(FatalError); } } @@ -105,7 +105,7 @@ inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies "(const speciesTable& species, Istream& is)", is ) << "number of efficiencies = " << size() - << " is not equat to the number of species " << species_.size() + << " is not equal to the number of species " << species_.size() << exit(FatalIOError); } } diff --git a/src/thermophysicalModels/specie/speciesTable/speciesTable.C b/src/thermophysicalModels/specie/speciesTable/speciesTable.C deleted file mode 100644 index 3c5b0cb176b9d5a7c6f43e8133e89ad058c60c5b..0000000000000000000000000000000000000000 --- a/src/thermophysicalModels/specie/speciesTable/speciesTable.C +++ /dev/null @@ -1,83 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "speciesTable.H" - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -void Foam::speciesTable::setIndices() -{ - forAll(*this, i) - { - specieIndices_.insert(wordList::operator[](i), i); - } -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -// Construct from list of specie names -Foam::speciesTable::speciesTable(const wordList& specieNames) -: - wordList(specieNames) -{ - setIndices(); -} - - -// Construct from number of species and list of specie names -Foam::speciesTable::speciesTable(const label nSpecies, const char** specieNames) -: - wordList(nSpecies) -{ - forAll(*this, i) - { - wordList::operator[](i) = specieNames[i]; - } - - setIndices(); -} - - -// Construct from Istream -Foam::speciesTable::speciesTable(Istream& is) -: - wordList(is) -{ - setIndices(); -} - - -// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // - -Foam::Istream& Foam::operator>>(Istream& is, speciesTable& st) -{ - is >> static_cast<wordList&>(st); - st.setIndices(); - - return is; -} - -// ************************************************************************* // diff --git a/src/thermophysicalModels/specie/speciesTable/speciesTable.H b/src/thermophysicalModels/specie/speciesTable/speciesTable.H index 4e7013d015ef65086b39b76cd9ef61fbe5bf9ce6..72533ad0a69b3ebb46cca696c0149222468929b1 100644 --- a/src/thermophysicalModels/specie/speciesTable/speciesTable.H +++ b/src/thermophysicalModels/specie/speciesTable/speciesTable.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -21,89 +21,25 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. -Class +Typedef Foam::speciesTable Description - A table of species - -SourceFiles - speciesTableI.H - speciesTable.C + A table of species as a hashedWordList \*---------------------------------------------------------------------------*/ #ifndef speciesTable_H #define speciesTable_H -#include "wordList.H" -#include "HashTable.H" +#include "hashedWordList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { - -/*---------------------------------------------------------------------------*\ - Class speciesTable Declaration -\*---------------------------------------------------------------------------*/ - -class speciesTable -: - public wordList -{ - // Private data - - HashTable<label> specieIndices_; - - - // Private Member Functions - - void setIndices(); - - -public: - - // Constructors - - //- Construct from list of specie names - speciesTable(const wordList& specieNames); - - //- Construct from number of species and list of specie names - speciesTable(const label nSpecies, const char** specieNames); - - //- Construct from Istream - speciesTable(Istream&); - - - // Member Functions - - //- Does the table contain the given specie - inline bool contains(const word& specieName) const; - - - // Member Operators - - //- Return a specie's name - inline const word& operator[](const label) const; - - //- Lookup a specie's name and return its index - inline label operator[](const word&) const; - - - // Istream operators - - friend Istream& operator>>(Istream&, speciesTable&); -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#include "speciesTableI.H" + typedef hashedWordList speciesTable; +} // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //