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

thirdBodyEfficienciesI.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 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00027 
00028 //- Construct from components
00029 inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies
00030 (
00031     const speciesTable& species,
00032     const scalarList& efficiencies
00033 )
00034 :
00035     scalarList(efficiencies),
00036     species_(species)
00037 {
00038     if (size() != species_.size())
00039     {
00040         FatalErrorIn
00041         (
00042             "thirdBodyEfficiencies::thirdBodyEfficiencies"
00043             "(const speciesTable& species, const scalarList& efficiencies)"
00044         )   << "number of efficiencies = " << size()
00045             << " is not equat to the number of species " << species_.size()
00046             << exit(FatalError);
00047     }
00048 }
00049 
00050 
00051 //- Construct from Istream
00052 inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies
00053 (
00054     const speciesTable& species,
00055     Istream& is
00056 )
00057 :
00058     scalarList(species.size()),
00059     species_(species)
00060 {
00061     is.readBeginList
00062     (
00063         "thirdBodyEfficiencies::thirdBodyEfficiencies"
00064         "(const speciesTable& species, Istream& is)"
00065     );
00066     scalar defaultEff = readScalar(is);
00067     scalarList::operator=(defaultEff);
00068 
00069     token t;
00070 
00071     while ((is >> t) && !t.isPunctuation())
00072     {
00073         if (t.isWord())
00074         {
00075             operator[](species[t.wordToken()]) = readScalar(is);
00076         }
00077         else
00078         {
00079             FatalIOErrorIn
00080             (
00081                 "thirdBodyEfficiencies::thirdBodyEfficiencies"
00082                 "(const speciesTable& species, Istream& is)",
00083                 is
00084             )   << "expected <word>, found " << t.info()
00085                 << exit(FatalIOError);
00086         }
00087     }
00088 
00089     if (t.pToken() != token::END_LIST)
00090     {
00091         FatalIOErrorIn
00092         (
00093             "thirdBodyEfficiencies::thirdBodyEfficiencies"
00094             "(const speciesTable& species, Istream& is)",
00095             is
00096         )   << "expected ')', found " << t.info()
00097             << exit(FatalIOError);
00098     }
00099 
00100     if (size() != species_.size())
00101     {
00102         FatalIOErrorIn
00103         (
00104             "thirdBodyEfficiencies::thirdBodyEfficiencies"
00105             "(const speciesTable& species, Istream& is)",
00106             is
00107         )   << "number of efficiencies = " << size()
00108             << " is not equat to the number of species " << species_.size()
00109             << exit(FatalIOError);
00110     }
00111 }
00112 
00113 
00114 // * * * * * * * * * * * * * * * Member functions  * * * * * * * * * * * * * //
00115 
00116 inline Foam::scalar Foam::thirdBodyEfficiencies::M(const scalarList& c) const
00117 {
00118     scalar M = 0.0;
00119     forAll (*this, i)
00120     {
00121         M += operator[](i)*c[i];
00122     }
00123 
00124     return M;
00125 }
00126 
00127 
00128 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
00129 
00130 inline Foam::Ostream& Foam::operator<<
00131 (
00132     Ostream& os,
00133     const thirdBodyEfficiencies& tbes
00134 )
00135 {
00136     scalarList orderedTbes = tbes;
00137     sort(orderedTbes);
00138 
00139     scalar val = orderedTbes[0];
00140     label count = 1;
00141 
00142     scalar valMaxCount = val;
00143     label maxCount = 1;
00144 
00145     for (label i=1; i<orderedTbes.size(); i++)
00146     {
00147         if (equal(orderedTbes[i], val))
00148         {
00149             count++;
00150         }
00151         else
00152         {
00153             if (count > maxCount)
00154             {
00155                 maxCount = count;
00156                 valMaxCount = val;
00157             }
00158 
00159             count = 1;
00160             val = orderedTbes[i];
00161         }
00162     }
00163 
00164     if (count > maxCount)
00165     {
00166         maxCount = count;
00167         valMaxCount = val;
00168     }
00169 
00170     os << token::BEGIN_LIST << valMaxCount;
00171 
00172     forAll (tbes, i)
00173     {
00174         if (notEqual(tbes[i], valMaxCount))
00175         {
00176             os  << token::SPACE << tbes.species_[i]
00177                 << token::SPACE << tbes[i];
00178         }
00179     }
00180 
00181     os << token::END_LIST;
00182 
00183     return os;
00184 }
00185 
00186 
00187 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines