OpenFOAM logo
Open Source CFD Toolkit

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