Added += and -= operators.

This commit is contained in:
henry
2008-07-24 12:40:43 +01:00
parent 898742e6eb
commit 5a4e09c772
6 changed files with 97 additions and 158 deletions

View File

@ -128,7 +128,7 @@ public:
// Member Functions // Member Functions
// fundamaental properties // Fundamaental properties
//- Heat capacity at constant pressure [J/(kmol K)] //- Heat capacity at constant pressure [J/(kmol K)]
inline scalar cp(const scalar T) const; inline scalar cp(const scalar T) const;
@ -152,10 +152,8 @@ public:
// Member operators // Member operators
inline eConstThermo& operator= inline void operator+=(const hConstThermo&);
( inline void operator-=(const hConstThermo&);
const eConstThermo&
);
// Friend operators // Friend operators

View File

@ -24,15 +24,9 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Construct from components inline Foam::eConstThermo::eConstThermo
inline eConstThermo::eConstThermo
( (
const specieThermo& st, const specieThermo& st,
const scalar cv, const scalar cv,
@ -47,8 +41,11 @@ inline eConstThermo::eConstThermo
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct as named copy inline Foam::eConstThermo::eConstThermo
inline eConstThermo::eConstThermo(const word& name, const eConstThermo& ct) (
const word& name,
const eConstThermo& ct
)
: :
specieThermo(name, ct), specieThermo(name, ct),
CV(ct.CV), CV(ct.CV),
@ -56,10 +53,9 @@ inline eConstThermo::eConstThermo(const word& name, const eConstThermo& ct)
{} {}
// Construct and return a clone
template<class equationOfState> template<class equationOfState>
inline autoPtr<eConstThermo<equationOfState> > eConstThermo<equationOfState>:: inline Foam::autoPtr<eConstThermo<equationOfState> >
clone() const Foam::eConstThermo<equationOfState>::clone() const
{ {
return autoPtr<eConstThermo<equationOfState> > return autoPtr<eConstThermo<equationOfState> >
( (
@ -68,10 +64,9 @@ clone() const
} }
// Selector from Istream
template<class equationOfState> template<class equationOfState>
inline autoPtr<eConstThermo<equationOfState> > eConstThermo<equationOfState>:: inline autoPtr<eConstThermo<equationOfState> >
New(Istream& is) Foam::eConstThermo<equationOfState>::New(Istream& is)
{ {
return autoPtr<eConstThermo<equationOfState> > return autoPtr<eConstThermo<equationOfState> >
( (
@ -82,37 +77,40 @@ New(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//- Heat capacity at constant pressure [J/(kmol K)] inline Foam::scalar Foam::eConstThermo::cp(const scalar) const
inline scalar eConstThermo::cp(const scalar) const
{ {
return CV*W() + RR; return CV*W() + RR;
} }
//- Enthalpy [J/kmol] inline Foam::scalar Foam::eConstThermo::h(const scalar T) const
inline scalar eConstThermo::h(const scalar T) const
{ {
return cp(T)*T + Hf*W(); return cp(T)*T + Hf*W();
} }
//- Entropy [J/(kmol K)] inline Foam::scalar Foam::eConstThermo::s(const scalar T) const
inline scalar eConstThermo::s(const scalar T) const
{ {
notImplemented("scalar eConstThermo::s(const scalar T) const"); notImplemented("scalar eConstThermo::s(const scalar T) const");
return T; return T;
} }
//- Temperature from Enthalpy given an initial temperature T0 inline Foam::scalar Foam::eConstThermo::TH
inline scalar eConstThermo::TH(const scalar h, const scalar T0) const (
const scalar h,
const scalar T0
) const
{ {
return (h - Hf)/Cp(T0); return (h - Hf)/Cp(T0);
} }
//- Temperature from internal energy given an initial temperature T0 inline Foam::scalar Foam::eConstThermo::TE
inline scalar eConstThermo::TE(const scalar e, const scalar) const (
const scalar e,
const scalar
) const
{ {
return (e - Hf)/CV; return (e - Hf)/CV;
} }
@ -120,7 +118,7 @@ inline scalar eConstThermo::TE(const scalar e, const scalar) const
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline eConstThermo& eConstThermo::operator= inline Foam::eConstThermo& Foam::eConstThermo::operator=
( (
const eConstThermo& ct const eConstThermo& ct
) )
@ -136,7 +134,7 @@ inline eConstThermo& eConstThermo::operator=
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
inline eConstThermo operator+ inline Foam::eConstThermo Foam::operator+
( (
const eConstThermo& ct1, const eConstThermo& ct1,
const eConstThermo& ct2 const eConstThermo& ct2
@ -153,7 +151,7 @@ inline eConstThermo operator+
} }
inline eConstThermo operator- inline Foam::eConstThermo Foam::operator-
( (
const eConstThermo& ct1, const eConstThermo& ct1,
const eConstThermo& ct2 const eConstThermo& ct2
@ -170,7 +168,7 @@ inline eConstThermo operator-
} }
inline eConstThermo operator* inline Foam::eConstThermo Foam::operator*
( (
const scalar s, const scalar s,
const eConstThermo& ct const eConstThermo& ct
@ -185,7 +183,7 @@ inline eConstThermo operator*
} }
inline eConstThermo operator== inline Foam::eConstThermo Foam::operator==
( (
const eConstThermo& ct1, const eConstThermo& ct1,
const eConstThermo& ct2 const eConstThermo& ct2
@ -195,8 +193,4 @@ inline eConstThermo operator==
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -108,6 +108,7 @@ class hConstThermo
const scalar hf const scalar hf
); );
public: public:
// Constructors // Constructors
@ -127,7 +128,7 @@ public:
// Member Functions // Member Functions
// fundamaental properties // Fundamaental properties
//- Heat capacity at constant pressure [J/(kmol K)] //- Heat capacity at constant pressure [J/(kmol K)]
inline scalar cp(const scalar T) const; inline scalar cp(const scalar T) const;
@ -141,10 +142,8 @@ public:
// Member operators // Member operators
inline hConstThermo& operator= inline void operator+=(const hConstThermo&);
( inline void operator-=(const hConstThermo&);
const hConstThermo&
);
// Friend operators // Friend operators

View File

@ -24,16 +24,10 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Construct from components
template<class equationOfState> template<class equationOfState>
inline hConstThermo<equationOfState>::hConstThermo inline Foam::hConstThermo<equationOfState>::hConstThermo
( (
const equationOfState& st, const equationOfState& st,
const scalar cp, const scalar cp,
@ -48,9 +42,8 @@ inline hConstThermo<equationOfState>::hConstThermo
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct as named copy
template<class equationOfState> template<class equationOfState>
inline hConstThermo<equationOfState>::hConstThermo inline Foam::hConstThermo<equationOfState>::hConstThermo
( (
const word& name, const word& name,
const hConstThermo& ct const hConstThermo& ct
@ -62,10 +55,9 @@ inline hConstThermo<equationOfState>::hConstThermo
{} {}
// Construct and return a clone
template<class equationOfState> template<class equationOfState>
inline autoPtr<hConstThermo<equationOfState> > hConstThermo<equationOfState>:: inline Foam::autoPtr<Foam::hConstThermo<equationOfState> >
clone() const Foam::hConstThermo<equationOfState>::clone() const
{ {
return autoPtr<hConstThermo<equationOfState> > return autoPtr<hConstThermo<equationOfState> >
( (
@ -74,10 +66,9 @@ clone() const
} }
// Selector from Istream
template<class equationOfState> template<class equationOfState>
inline autoPtr<hConstThermo<equationOfState> > hConstThermo<equationOfState>:: inline Foam::autoPtr<Foam::hConstThermo<equationOfState> >
New(Istream& is) Foam::hConstThermo<equationOfState>::New(Istream& is)
{ {
return autoPtr<hConstThermo<equationOfState> > return autoPtr<hConstThermo<equationOfState> >
( (
@ -88,68 +79,73 @@ New(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//- Heat capacity at constant pressure [J/(kmol K)]
template<class equationOfState> template<class equationOfState>
inline scalar hConstThermo<equationOfState>::cp(const scalar) const inline Foam::scalar Foam::hConstThermo<equationOfState>::cp(const scalar) const
{ {
return CP*this->W(); return CP*this->W();
} }
//- Enthalpy [J/kmol]
template<class equationOfState> template<class equationOfState>
inline scalar hConstThermo<equationOfState>::h(const scalar T) const inline Foam::scalar Foam::hConstThermo<equationOfState>::h(const scalar T) const
{ {
return (CP*T + Hf)*this->W(); return (CP*T + Hf)*this->W();
} }
//- Entropy [J/(kmol K)]
template<class equationOfState> template<class equationOfState>
inline scalar hConstThermo<equationOfState>::s(const scalar T) const inline Foam::scalar Foam::hConstThermo<equationOfState>::s(const scalar T) const
{ {
notImplemented("scalar hConstThermo<equationOfState>::s(const scalar T) const"); notImplemented
(
"scalar hConstThermo<equationOfState>::s(const scalar T) const"
);
return T; return T;
} }
/*
//- Temperature from Enthalpy given an initial temperature T0
template<class equationOfState>
inline scalar hConstThermo<equationOfState>::TH(const scalar h, const scalar T0) const
{
return (h - Hf)/Cp(T0);
}
//- Temperature from internal energy given an initial temperature T0
template<class equationOfState>
inline scalar hConstThermo<equationOfState>::TE(const scalar e, const scalar T0) const
{
return (e - Hf)/Cv(T0);
}
*/
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class equationOfState> template<class equationOfState>
inline hConstThermo<equationOfState>& hConstThermo<equationOfState>::operator= inline void Foam::hConstThermo<equationOfState>::operator+=
( (
const hConstThermo& ct const hConstThermo<equationOfState>& ct
) )
{ {
equationOfState::operator=(ct); scalar molr1 = this->nMoles();
CP = ct.CP; equationOfState::operator+=(ct);
Hf = ct.Hf;
return *this; molr1 /= this->nMoles();
scalar molr2 = ct.nMoles()/this->nMoles();
CP = molr1*CP + molr2*ct.CP;
Hf = molr1*Hf + molr2*ct.Hf;
}
template<class equationOfState>
inline void Foam::hConstThermo<equationOfState>::operator-=
(
const hConstThermo<equationOfState>& ct
)
{
scalar molr1 = this->nMoles();
equationOfState::operator-=(ct);
molr1 /= this->nMoles();
scalar molr2 = ct.nMoles()/this->nMoles();
CP = molr1*CP - molr2*ct.CP;
Hf = molr1*Hf - molr2*ct.Hf;
} }
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
template<class equationOfState> template<class equationOfState>
inline hConstThermo<equationOfState> operator+ inline Foam::hConstThermo<equationOfState> Foam::operator+
( (
const hConstThermo<equationOfState>& ct1, const hConstThermo<equationOfState>& ct1,
const hConstThermo<equationOfState>& ct2 const hConstThermo<equationOfState>& ct2
@ -158,7 +154,7 @@ inline hConstThermo<equationOfState> operator+
equationOfState eofs equationOfState eofs
( (
static_cast<const equationOfState&>(ct1) static_cast<const equationOfState&>(ct1)
+ static_cast<const equationOfState&>(ct2) + static_cast<const equationOfState&>(ct2)
); );
return hConstThermo<equationOfState> return hConstThermo<equationOfState>
@ -171,7 +167,7 @@ inline hConstThermo<equationOfState> operator+
template<class equationOfState> template<class equationOfState>
inline hConstThermo<equationOfState> operator- inline Foam::hConstThermo<equationOfState> Foam::operator-
( (
const hConstThermo<equationOfState>& ct1, const hConstThermo<equationOfState>& ct1,
const hConstThermo<equationOfState>& ct2 const hConstThermo<equationOfState>& ct2
@ -193,7 +189,7 @@ inline hConstThermo<equationOfState> operator-
template<class equationOfState> template<class equationOfState>
inline hConstThermo<equationOfState> operator* inline Foam::hConstThermo<equationOfState> Foam::operator*
( (
const scalar s, const scalar s,
const hConstThermo<equationOfState>& ct const hConstThermo<equationOfState>& ct
@ -209,7 +205,7 @@ inline hConstThermo<equationOfState> operator*
template<class equationOfState> template<class equationOfState>
inline hConstThermo<equationOfState> operator== inline Foam::hConstThermo<equationOfState> Foam::operator==
( (
const hConstThermo<equationOfState>& ct1, const hConstThermo<equationOfState>& ct1,
const hConstThermo<equationOfState>& ct2 const hConstThermo<equationOfState>& ct2
@ -219,8 +215,4 @@ inline hConstThermo<equationOfState> operator==
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef janafThermo2_H #ifndef janafThermo_H
#define janafThermo2_H #define janafThermo_H
#include "scalar.H" #include "scalar.H"
@ -85,11 +85,6 @@ Ostream& operator<<
); );
#ifdef __GNUC__
typedef scalar coeffArray2[7];
#endif
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class janafThermo Declaration Class janafThermo Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -122,13 +117,7 @@ private:
inline void checkT(const scalar T) const; inline void checkT(const scalar T) const;
//- Return the coefficients corresponding to the given temperature //- Return the coefficients corresponding to the given temperature
inline const inline const coeffArray& coeffs(const scalar T) const;
# ifdef __GNUC__
coeffArray2&
# else
coeffArray&
# endif
coeffs(const scalar T) const;
public: public:
@ -170,8 +159,6 @@ public:
inline void operator+=(const janafThermo&); inline void operator+=(const janafThermo&);
inline void operator-=(const janafThermo&); inline void operator-=(const janafThermo&);
inline void operator*=(const scalar);
// Friend operators // Friend operators

View File

@ -26,16 +26,10 @@ License
#include "janafThermo.H" #include "janafThermo.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Construct from components
template<class equationOfState> template<class equationOfState>
inline janafThermo<equationOfState>::janafThermo inline Foam::janafThermo<equationOfState>::janafThermo
( (
const equationOfState& st, const equationOfState& st,
const scalar Tlow, const scalar Tlow,
@ -58,9 +52,8 @@ inline janafThermo<equationOfState>::janafThermo
} }
// Check given temperature is within the range of the fitted coeffs.
template<class equationOfState> template<class equationOfState>
inline void janafThermo<equationOfState>::checkT(const scalar T) const inline void Foam::janafThermo<equationOfState>::checkT(const scalar T) const
{ {
if (T < Tlow_ || T > Thigh_) if (T < Tlow_ || T > Thigh_)
{ {
@ -75,15 +68,9 @@ inline void janafThermo<equationOfState>::checkT(const scalar T) const
} }
// Return the coefficients corresponding to the given temperature
template<class equationOfState> template<class equationOfState>
inline const inline const typename Foam::janafThermo<equationOfState>::coeffArray&
#ifdef __GNUC__ Foam::janafThermo<equationOfState>::coeffs
coeffArray2&
#else
typename janafThermo<equationOfState>::coeffArray&
#endif
janafThermo<equationOfState>::coeffs
( (
const scalar T const scalar T
) const ) const
@ -103,9 +90,8 @@ janafThermo<equationOfState>::coeffs
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct as a named copy
template<class equationOfState> template<class equationOfState>
inline janafThermo<equationOfState>::janafThermo inline Foam::janafThermo<equationOfState>::janafThermo
( (
const word& name, const word& name,
const janafThermo& jt const janafThermo& jt
@ -126,9 +112,8 @@ inline janafThermo<equationOfState>::janafThermo
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Heat capacity at constant pressure [J/(kmol K)]
template<class equationOfState> template<class equationOfState>
inline scalar janafThermo<equationOfState>::cp inline Foam::scalar Foam::janafThermo<equationOfState>::cp
( (
const scalar T const scalar T
) const ) const
@ -138,9 +123,8 @@ inline scalar janafThermo<equationOfState>::cp
} }
// Enthalpy [J/kmol]
template<class equationOfState> template<class equationOfState>
inline scalar janafThermo<equationOfState>::h inline Foam::scalar Foam::janafThermo<equationOfState>::h
( (
const scalar T const scalar T
) const ) const
@ -155,9 +139,8 @@ inline scalar janafThermo<equationOfState>::h
} }
// Entropy [J/(kmol K)]
template<class equationOfState> template<class equationOfState>
inline scalar janafThermo<equationOfState>::s inline Foam::scalar Foam::janafThermo<equationOfState>::s
( (
const scalar T const scalar T
) const ) const
@ -175,7 +158,7 @@ inline scalar janafThermo<equationOfState>::s
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class equationOfState> template<class equationOfState>
inline void janafThermo<equationOfState>::operator+= inline void Foam::janafThermo<equationOfState>::operator+=
( (
const janafThermo<equationOfState>& jt const janafThermo<equationOfState>& jt
) )
@ -210,7 +193,7 @@ inline void janafThermo<equationOfState>::operator+=
template<class equationOfState> template<class equationOfState>
inline void janafThermo<equationOfState>::operator-= inline void Foam::janafThermo<equationOfState>::operator-=
( (
const janafThermo<equationOfState>& jt const janafThermo<equationOfState>& jt
) )
@ -244,20 +227,10 @@ inline void janafThermo<equationOfState>::operator-=
} }
template<class equationOfState>
inline void janafThermo<equationOfState>::operator*=
(
const scalar s
)
{
equationOfState::operator*=(s);
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
template<class equationOfState> template<class equationOfState>
inline janafThermo<equationOfState> operator+ inline Foam::janafThermo<equationOfState> Foam::operator+
( (
const janafThermo<equationOfState>& jt1, const janafThermo<equationOfState>& jt1,
const janafThermo<equationOfState>& jt2 const janafThermo<equationOfState>& jt2
@ -301,7 +274,7 @@ inline janafThermo<equationOfState> operator+
template<class equationOfState> template<class equationOfState>
inline janafThermo<equationOfState> operator- inline Foam::janafThermo<equationOfState> Foam::operator-
( (
const janafThermo<equationOfState>& jt1, const janafThermo<equationOfState>& jt1,
const janafThermo<equationOfState>& jt2 const janafThermo<equationOfState>& jt2
@ -345,7 +318,7 @@ inline janafThermo<equationOfState> operator-
template<class equationOfState> template<class equationOfState>
inline janafThermo<equationOfState> operator* inline Foam::janafThermo<equationOfState> Foam::operator*
( (
const scalar s, const scalar s,
const janafThermo<equationOfState>& jt const janafThermo<equationOfState>& jt
@ -364,7 +337,7 @@ inline janafThermo<equationOfState> operator*
template<class equationOfState> template<class equationOfState>
inline janafThermo<equationOfState> operator== inline Foam::janafThermo<equationOfState> Foam::operator==
( (
const janafThermo<equationOfState>& jt1, const janafThermo<equationOfState>& jt1,
const janafThermo<equationOfState>& jt2 const janafThermo<equationOfState>& jt2
@ -374,8 +347,4 @@ inline janafThermo<equationOfState> operator==
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //