mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'olesenm'
This commit is contained in:
@ -1,3 +1,3 @@
|
||||
EXE_INC = \
|
||||
EXE_INC =
|
||||
|
||||
EXE_LIBS = \
|
||||
EXE_LIBS =
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
testPoly
|
||||
(
|
||||
0.11
|
||||
0.45
|
||||
-0.94
|
||||
1.58
|
||||
-2.58
|
||||
0.08
|
||||
3.15
|
||||
-4.78
|
||||
)
|
||||
@ -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
|
||||
|
||||
159
src/OpenFOAM/primitives/Lists/hashedWordList.C
Normal file
159
src/OpenFOAM/primitives/Lists/hashedWordList.C
Normal file
@ -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;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
149
src/OpenFOAM/primitives/Lists/hashedWordList.H
Normal file
149
src/OpenFOAM/primitives/Lists/hashedWordList.H
Normal file
@ -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
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -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[]
|
||||
(
|
||||
const label specieIndex
|
||||
) const
|
||||
inline void Foam::hashedWordList::operator=(const UList<word>& lst)
|
||||
{
|
||||
return wordList::operator[](specieIndex);
|
||||
List<word>::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<const UList<word>&>(lst));
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::word& Foam::hashedWordList::operator[]
|
||||
(
|
||||
const label index
|
||||
) const
|
||||
{
|
||||
return List<word>::operator[](index);
|
||||
}
|
||||
|
||||
|
||||
// could return -1 instead of bombing out
|
||||
inline Foam::label Foam::hashedWordList::operator[](const word& name) const
|
||||
{
|
||||
return indices_[name];
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -5,3 +5,7 @@ EXE_INC = \
|
||||
-I$(LIB_SRC)/thermophysicalModels/combustion/lnInclude \
|
||||
-I$(LIB_SRC)/thermophysicalModels/thermophysicalFunctions/lnInclude
|
||||
|
||||
LIB_LIBS = \
|
||||
-lliquids \
|
||||
-lthermophysicalFunctions
|
||||
|
||||
|
||||
@ -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]))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -1 +1,5 @@
|
||||
EXE_INC = -I$(LIB_SRC)/thermophysicalModels/thermophysicalFunctions/lnInclude
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/thermophysicalModels/thermophysicalFunctions/lnInclude
|
||||
|
||||
LIB_LIBS = \
|
||||
-lthermophysicalFunctions
|
||||
|
||||
@ -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
|
||||
|
||||
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
|
||||
);
|
||||
|
||||
}
|
||||
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
|
||||
|
||||
@ -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
|
||||
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);
|
||||
}
|
||||
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);
|
||||
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
|
||||
|
||||
@ -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
|
||||
(
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -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;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
Reference in New Issue
Block a user