FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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