From 3fd25abba9bbd16f5b1981894495837a4623aa38 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 5 Oct 2010 17:51:38 +0200 Subject: [PATCH 01/12] COMP: link liquids, thermophysicalFunctions libs when using liquidMixture --- src/thermophysicalModels/liquidMixture/Make/options | 4 ++++ src/thermophysicalModels/liquids/Make/options | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/thermophysicalModels/liquidMixture/Make/options b/src/thermophysicalModels/liquidMixture/Make/options index 506b8ac9a2..bfa6b569ba 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/liquids/Make/options b/src/thermophysicalModels/liquids/Make/options index 8a129fda6c..b964b61294 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 From e251b7b677a496ac19669ea7e3a98717323cb522 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 5 Oct 2010 17:53:30 +0200 Subject: [PATCH 02/12] STYLE: allow "solidProperties" dict entry for consistency with liquidMixture - add size() method to liquidMixture and solidMixture --- .../liquidMixture/liquidMixture.C | 35 ++++++++----------- .../liquidMixture/liquidMixture.H | 10 +++++- .../solidMixture/solidMixture/solidMixture.C | 25 +++++++++---- .../solidMixture/solidMixture/solidMixture.H | 22 ++++++++++-- 4 files changed, 62 insertions(+), 30 deletions(-) diff --git a/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.C b/src/thermophysicalModels/liquidMixture/liquidMixture/liquidMixture.C index 4941eab537..d46e3e110a 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 a5ae1c3fbb..8810256475 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& 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/solidMixture/solidMixture/solidMixture.C b/src/thermophysicalModels/solidMixture/solidMixture/solidMixture.C index 55ccd4057f..6cf5163397 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 50f8b54a6c..ba1d582ee5 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& 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; From 9fd0959b88a06d2ea2ca4671462248e414b7b4ad Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 5 Oct 2010 18:19:17 +0200 Subject: [PATCH 03/12] ENH: generalize speciesTable as hashedWordList BUG: incorrect speciesTable indices after assignment or reading from Istream --- src/OpenFOAM/Make/files | 1 + .../primitives/Lists/hashedWordList.C | 159 ++++++++++++++++++ .../primitives/Lists/hashedWordList.H | 149 ++++++++++++++++ .../primitives/Lists/hashedWordListI.H} | 36 ++-- .../chemkinReader/chemkinReader.C | 4 +- src/thermophysicalModels/specie/Make/files | 2 - .../specie/speciesTable/speciesTable.C | 83 --------- .../specie/speciesTable/speciesTable.H | 76 +-------- 8 files changed, 341 insertions(+), 169 deletions(-) create mode 100644 src/OpenFOAM/primitives/Lists/hashedWordList.C create mode 100644 src/OpenFOAM/primitives/Lists/hashedWordList.H rename src/{thermophysicalModels/specie/speciesTable/speciesTableI.H => OpenFOAM/primitives/Lists/hashedWordListI.H} (66%) delete mode 100644 src/thermophysicalModels/specie/speciesTable/speciesTable.C diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index d9548b67b1..78d9258543 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/primitives/Lists/hashedWordList.C b/src/OpenFOAM/primitives/Lists/hashedWordList.C new file mode 100644 index 0000000000..e9206bda8e --- /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 . + +\*---------------------------------------------------------------------------*/ + +#include "hashedWordList.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::hashedWordList::rehash() +{ + indices_.clear(); + forAll(*this, i) + { + indices_.insert(List::operator[](i), i); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::hashedWordList::hashedWordList() +: + List() +{} + + +Foam::hashedWordList::hashedWordList(const UList& names) +: + List(names) +{ + rehash(); +} + + +Foam::hashedWordList::hashedWordList(const hashedWordList& names) +: + List(static_cast&>(names)) +{ + rehash(); +} + + +Foam::hashedWordList::hashedWordList(const Xfer< List >& names) +: + List(names) +{ + rehash(); +} + + +Foam::hashedWordList::hashedWordList +( + const label nNames, + const char** names +) +: + List(nNames) +{ + forAll(*this, i) + { + List::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::setSize(nNames); + forAll(*this, i) + { + List::operator[](i) = names[i]; + } + + rehash(); +} + + +Foam::hashedWordList::hashedWordList(Istream& is) +{ + is >> *this; +} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::hashedWordList::clear() +{ + List::clear(); + indices_.clear(); +} + + +void Foam::hashedWordList::append(const word& name) +{ + const label idx = size(); + List::append(name); + indices_.insert(name, idx); +} + + +void Foam::hashedWordList::transfer(List& lst) +{ + List::transfer(lst); + rehash(); +} + + +// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // + +Foam::Istream& Foam::operator>>(Istream& is, hashedWordList& lst) +{ + is >> static_cast&>(lst); + lst.rehash(); + + return is; +} + + +Foam::Ostream& Foam::operator<<(Ostream& os, const hashedWordList& lst) +{ + os << static_cast&>(lst); + return os; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/Lists/hashedWordList.H b/src/OpenFOAM/primitives/Lists/hashedWordList.H new file mode 100644 index 0000000000..93a23d8db3 --- /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 . + +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 +{ + // Private data + + HashTable 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& names); + + //- Construct by transferring the parameter contents + hashedWordList(const Xfer< List >& 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&); + + + // Member Operators + + //- Assignment operator from list of names + inline void operator=(const UList& names); + + //- Assignment operator. + inline void operator=(const hashedWordList&); + + //- Allow readonly access to list of words + inline operator const Foam::UList&() 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 8a8c85694a..1e736aa6c5 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 . -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[] -( - const label specieIndex -) const +inline void Foam::hashedWordList::operator=(const UList& lst) { - return wordList::operator[](specieIndex); + List::operator=(lst); + rehash(); } -inline Foam::label Foam::speciesTable::operator[](const word& specieName) const +inline void Foam::hashedWordList::operator=(const hashedWordList& lst) { - return specieIndices_[specieName]; + operator=(static_cast&>(lst)); +} + + +inline const Foam::word& Foam::hashedWordList::operator[] +( + const label index +) const +{ + return List::operator[](index); +} + + +// could return -1 instead of bombing out +inline Foam::label Foam::hashedWordList::operator[](const word& name) const +{ + return indices_[name]; } diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C index 80418cbc83..b474c59451 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(wordList())) + speciesTable_() { read(CHEMKINFileName, thermoFileName); } @@ -870,7 +870,7 @@ Foam::chemkinReader::chemkinReader(const dictionary& thermoDict) : lineNo_(1), specieNames_(10), - speciesTable_(static_cast(wordList())) + speciesTable_() { fileName chemkinFile ( diff --git a/src/thermophysicalModels/specie/Make/files b/src/thermophysicalModels/specie/Make/files index 428f6d8fc7..0e0eacae89 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/speciesTable/speciesTable.C b/src/thermophysicalModels/specie/speciesTable/speciesTable.C deleted file mode 100644 index 3c5b0cb176..0000000000 --- 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 . - -\*---------------------------------------------------------------------------*/ - -#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(st); - st.setIndices(); - - return is; -} - -// ************************************************************************* // diff --git a/src/thermophysicalModels/specie/speciesTable/speciesTable.H b/src/thermophysicalModels/specie/speciesTable/speciesTable.H index 4e7013d015..72533ad0a6 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 . -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