initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / thermophysicalModels / specie / specie / specieI.H
blobcbc131f6a5cdfa0abfe0790f1c46a6f640af87ea
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "specie.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
36 // Construct from components
37 inline specie::specie
39     const word& name,
40     const scalar nMoles,
41     const scalar molWeight
44     name_(name),
45     nMoles_(nMoles),
46     molWeight_(molWeight)
50 // Construct from components without name
51 inline specie::specie
53     const scalar nMoles,
54     const scalar molWeight
57     //name_(),
58     nMoles_(nMoles),
59     molWeight_(molWeight)
63 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
65 // Construct as copy
66 inline specie::specie(const specie& st)
68     name_(st.name_),
69     nMoles_(st.nMoles_),
70     molWeight_(st.molWeight_)
74 // Construct as named copy
75 inline specie::specie(const word& name, const specie& st)
77     name_(name),
78     nMoles_(st.nMoles_),
79     molWeight_(st.molWeight_)
83 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
85 //- Molecular weight [kg/kmol]
86 inline scalar specie::W() const
88     return molWeight_;
91 //- No of moles of this species in mixture
92 inline scalar specie::nMoles() const
94     return nMoles_;
97 //- Gas constant [J/(kg K)]
98 inline scalar specie::R() const
100     return RR/molWeight_;
104 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
106 inline void specie::operator=(const specie& st)
108   //name_ = st.name_;
109     nMoles_ = st.nMoles_;
110     molWeight_ = st.molWeight_;
114 inline void specie::operator+=(const specie& st)
116     scalar sumNmoles_ = max(nMoles_ + st.nMoles_, SMALL);
118     molWeight_ =
119         nMoles_/sumNmoles_*molWeight_
120       + st.nMoles_/sumNmoles_*st.molWeight_;
122     nMoles_ = sumNmoles_;
126 inline void specie::operator-=(const specie& st)
128     scalar diffnMoles_ = nMoles_ - st.nMoles_;
129     if (mag(diffnMoles_) < SMALL)
130     {
131         diffnMoles_ = SMALL;
132     }
134     molWeight_ =
135         nMoles_/diffnMoles_*molWeight_
136       - st.nMoles_/diffnMoles_*st.molWeight_;
138     nMoles_ = diffnMoles_;
142 inline void specie::operator*=(const scalar s)
144     nMoles_ *= s;
148 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
150 inline specie operator+(const specie& st1, const specie& st2)
152     scalar sumNmoles_ = max(st1.nMoles_ + st2.nMoles_, SMALL);
154     return specie
155     (
156         sumNmoles_,
157         st1.nMoles_/sumNmoles_*st1.molWeight_
158       + st2.nMoles_/sumNmoles_*st2.molWeight_
159     );
163 inline specie operator-(const specie& st1, const specie& st2)
165     scalar diffNmoles_ = st1.nMoles_ - st2.nMoles_;
166     if (mag(diffNmoles_) < SMALL)
167     {
168         diffNmoles_ = SMALL;
169     }
171     return specie
172     (
173         diffNmoles_,
174         st1.nMoles_/diffNmoles_*st1.molWeight_
175       - st2.nMoles_/diffNmoles_*st2.molWeight_
176     );
180 inline specie operator*(const scalar s, const specie& st)
182     return specie
183     (
184         s*st.nMoles_,
185         st.molWeight_
186     );
190 inline specie operator==(const specie& st1, const specie& st2)
192     return st2 - st1;
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 } // End namespace Foam
200 // ************************************************************************* //