OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

specieI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "specie.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00035 
00036 // Construct from components
00037 inline specie::specie
00038 (
00039     const word& name,
00040     const scalar nMoles,
00041     const scalar molWeight
00042 )
00043 :
00044     name_(name),
00045     nMoles_(nMoles),
00046     molWeight_(molWeight)
00047 {}
00048 
00049 
00050 // Construct from components without name
00051 inline specie::specie
00052 (
00053     const scalar nMoles,
00054     const scalar molWeight
00055 )
00056 :
00057     //name_(),
00058     nMoles_(nMoles),
00059     molWeight_(molWeight)
00060 {}
00061 
00062 
00063 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00064 
00065 // Construct as copy
00066 inline specie::specie(const specie& st)
00067 :
00068     name_(st.name_),
00069     nMoles_(st.nMoles_),
00070     molWeight_(st.molWeight_)
00071 {}
00072 
00073 
00074 // Construct as named copy
00075 inline specie::specie(const word& name, const specie& st)
00076 :
00077     name_(name),
00078     nMoles_(st.nMoles_),
00079     molWeight_(st.molWeight_)
00080 {}
00081 
00082 
00083 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00084 
00085 //- Molecular weight [kg/kmol]
00086 inline scalar specie::W() const
00087 {
00088     return molWeight_;
00089 }
00090 
00091 //- No of moles of this species in mixture
00092 inline scalar specie::nMoles() const
00093 {
00094     return nMoles_;
00095 }
00096 
00097 //- Gas constant [J/(kg K)]
00098 inline scalar specie::R() const
00099 {
00100     return RR/molWeight_;
00101 }
00102 
00103 
00104 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00105 
00106 inline void specie::operator=(const specie& st)
00107 {
00108   //name_ = st.name_;
00109     nMoles_ = st.nMoles_;
00110     molWeight_ = st.molWeight_;
00111 }
00112 
00113 
00114 inline void specie::operator+=(const specie& st)
00115 {
00116     scalar sumNmoles_ = max(nMoles_ + st.nMoles_, SMALL);
00117 
00118     molWeight_ =
00119         nMoles_/sumNmoles_*molWeight_
00120       + st.nMoles_/sumNmoles_*st.molWeight_;
00121 
00122     nMoles_ = sumNmoles_;
00123 }
00124 
00125 
00126 inline void specie::operator-=(const specie& st)
00127 {
00128     scalar diffnMoles_ = nMoles_ - st.nMoles_;
00129     if (mag(diffnMoles_) < SMALL)
00130     {
00131         diffnMoles_ = SMALL;
00132     }
00133 
00134     molWeight_ =
00135         nMoles_/diffnMoles_*molWeight_
00136       - st.nMoles_/diffnMoles_*st.molWeight_;
00137 
00138     nMoles_ = diffnMoles_;
00139 }
00140 
00141 
00142 inline void specie::operator*=(const scalar s)
00143 {
00144     nMoles_ *= s;
00145 }
00146 
00147 
00148 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00149 
00150 inline specie operator+(const specie& st1, const specie& st2)
00151 {
00152     scalar sumNmoles_ = max(st1.nMoles_ + st2.nMoles_, SMALL);
00153 
00154     return specie
00155     (
00156         sumNmoles_,
00157         st1.nMoles_/sumNmoles_*st1.molWeight_
00158       + st2.nMoles_/sumNmoles_*st2.molWeight_
00159     );
00160 }
00161 
00162 
00163 inline specie operator-(const specie& st1, const specie& st2)
00164 {
00165     scalar diffNmoles_ = st1.nMoles_ - st2.nMoles_;
00166     if (mag(diffNmoles_) < SMALL)
00167     {
00168         diffNmoles_ = SMALL;
00169     }
00170 
00171     return specie
00172     (
00173         diffNmoles_,
00174         st1.nMoles_/diffNmoles_*st1.molWeight_
00175       - st2.nMoles_/diffNmoles_*st2.molWeight_
00176     );
00177 }
00178 
00179 
00180 inline specie operator*(const scalar s, const specie& st)
00181 {
00182     return specie
00183     (
00184         s*st.nMoles_,
00185         st.molWeight_
00186     );
00187 }
00188 
00189 
00190 inline specie operator==(const specie& st1, const specie& st2)
00191 {
00192     return st2 - st1;
00193 }
00194 
00195 
00196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00197 
00198 } // End namespace Foam
00199 
00200 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd