OpenFOAM logo
Open Source CFD Toolkit

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-2005 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 Description
00026     Base class of the thermophysical property types.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "specie.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00038 
00039 // Construct from components
00040 inline specie::specie
00041 (
00042     const word& name,
00043     const scalar nMoles,
00044     const scalar molWeight
00045 )
00046 :
00047     name_(name),
00048     nMoles_(nMoles),
00049     molWeight_(molWeight)
00050 {}
00051 
00052 
00053 // Construct from components without name
00054 inline specie::specie
00055 (
00056     const scalar nMoles,
00057     const scalar molWeight
00058 )
00059 :
00060     //name_(),
00061     nMoles_(nMoles),
00062     molWeight_(molWeight)
00063 {}
00064 
00065 
00066 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00067 
00068 // Construct as copy
00069 inline specie::specie(const specie& st)
00070 :
00071     name_(st.name_),
00072     nMoles_(st.nMoles_),
00073     molWeight_(st.molWeight_)
00074 {}
00075 
00076 
00077 // Construct as named copy
00078 inline specie::specie(const word& name, const specie& st)
00079 :
00080     name_(name),
00081     nMoles_(st.nMoles_),
00082     molWeight_(st.molWeight_)
00083 {}
00084 
00085 
00086 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00087 
00088 //- Molecular weight [kg/kmol]
00089 inline scalar specie::W() const
00090 {
00091     return molWeight_;
00092 }
00093 
00094 //- No of moles of this species in mixture
00095 inline scalar specie::nMoles() const
00096 {
00097     return nMoles_;
00098 }
00099 
00100 //- Gas constant [J/(kg K)]
00101 inline scalar specie::R() const
00102 {
00103     return RR/molWeight_;
00104 }
00105 
00106 
00107 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00108 
00109 inline void specie::operator=(const specie& st)
00110 {
00111   //name_ = st.name_;
00112     nMoles_ = st.nMoles_;
00113     molWeight_ = st.molWeight_;
00114 }
00115 
00116 
00117 inline void specie::operator+=(const specie& st)
00118 {
00119     scalar sumNmoles_ = max(nMoles_ + st.nMoles_, SMALL);
00120 
00121     molWeight_ =
00122         nMoles_/sumNmoles_*molWeight_
00123       + st.nMoles_/sumNmoles_*st.molWeight_;
00124 
00125     nMoles_ = sumNmoles_;
00126 }
00127 
00128 
00129 inline void specie::operator-=(const specie& st)
00130 {
00131     scalar diffnMoles_ = nMoles_ - st.nMoles_;
00132     if (mag(diffnMoles_) < SMALL)
00133     {
00134         diffnMoles_ = SMALL;
00135     }
00136 
00137     molWeight_ =
00138         nMoles_/diffnMoles_*molWeight_
00139       - st.nMoles_/diffnMoles_*st.molWeight_;
00140 
00141     nMoles_ = diffnMoles_;
00142 }
00143 
00144 
00145 inline void specie::operator*=(const scalar s)
00146 {
00147     nMoles_ *= s;
00148 }
00149 
00150 
00151 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00152 
00153 inline specie operator+(const specie& st1, const specie& st2)
00154 {
00155     scalar sumNmoles_ = max(st1.nMoles_ + st2.nMoles_, SMALL);
00156 
00157     return specie
00158     (
00159         sumNmoles_,
00160         st1.nMoles_/sumNmoles_*st1.molWeight_
00161       + st2.nMoles_/sumNmoles_*st2.molWeight_
00162     );
00163 }
00164 
00165 
00166 inline specie operator-(const specie& st1, const specie& st2)
00167 {
00168     scalar diffNmoles_ = st1.nMoles_ - st2.nMoles_;
00169     if (mag(diffNmoles_) < SMALL)
00170     {
00171         diffNmoles_ = SMALL;
00172     }
00173 
00174     return specie
00175     (
00176         diffNmoles_,
00177         st1.nMoles_/diffNmoles_*st1.molWeight_
00178       - st2.nMoles_/diffNmoles_*st2.molWeight_
00179     );
00180 }
00181 
00182 
00183 inline specie operator*(const scalar s, const specie& st)
00184 {
00185     return specie
00186     (
00187         s*st.nMoles_,
00188         st.molWeight_
00189     );
00190 }
00191 
00192 
00193 inline specie operator==(const specie& st1, const specie& st2)
00194 {
00195     return st2 - st1;
00196 }
00197 
00198 
00199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00200 
00201 } // End namespace Foam
00202 
00203 // ************************************************************************* //
For further information go to www.openfoam.org