OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

injectorType.C

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-2009 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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "injectorType.H"
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 defineTypeNameAndDebug(injectorType, 0);
00035 defineRunTimeSelectionTable(injectorType, dictionary);
00036 
00037 }
00038 
00039 
00040 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00041 
00042 // Construct from components
00043 Foam::injectorType::injectorType
00044 (
00045     const Foam::Time&,
00046     const Foam::dictionary&
00047 )
00048 {}
00049 
00050 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
00051 
00052 Foam::autoPtr<Foam::injectorType> Foam::injectorType::New
00053 (
00054     const Time& t,
00055     const dictionary& dict
00056 )
00057 {
00058     word injectorTypeName
00059     (
00060         dict.lookup("injectorType")
00061     );
00062 
00063     Info<< "Selecting injectorType "
00064          << injectorTypeName << endl;
00065 
00066     dictionaryConstructorTable::iterator cstrIter =
00067         dictionaryConstructorTablePtr_->find(injectorTypeName);
00068 
00069     if (cstrIter == dictionaryConstructorTablePtr_->end())
00070     {
00071         FatalError
00072             << "injectorType::New(const dictionary&) : " << endl
00073             << "    unknown injectorType type "
00074             << injectorTypeName
00075             << ", constructor not in hash table" << endl << endl
00076             << "    Valid injector types are :" << endl;
00077         Info<< dictionaryConstructorTablePtr_->toc() << abort(FatalError);
00078     }
00079 
00080     return autoPtr<injectorType>(cstrIter()(t, dict));
00081 
00082 }
00083 
00084 
00085 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00086 
00087 Foam::injectorType::~injectorType()
00088 {}
00089 
00090 Foam::scalar Foam::injectorType::getTableValue
00091 (
00092     const List<pair>& table,
00093     const scalar value
00094 ) const
00095 {
00096     // iterator
00097     label i = 0;
00098 
00099     // max items
00100     label maxRow = table.size() - 1;
00101 
00102     // check lower bound
00103     if (value < table[0][0])
00104     {
00105         return table[0][1];
00106     }
00107     // check upper bound
00108     else if (value > table[maxRow][0])
00109     {
00110         return table[maxRow][1];
00111     }
00112     // interpolate intermediate value
00113     else
00114     {
00115         while
00116         (
00117             (i < maxRow-1) && (table[i+1][0] < value)
00118         )
00119         {
00120             i++;
00121         }
00122         // value sits bewteen table[i][0] and table[i+1][0]
00123         return table[i][1] 
00124                + (value-table[i][0])/(table[i+1][0]-table[i][0])
00125                * (table[i+1][1]-table[i][1]);
00126     }
00127 }
00128 
00129 Foam::scalar Foam::injectorType::integrateTable
00130 (
00131     const List<pair>& table,
00132     const scalar value
00133 ) const
00134 {
00135     label N = table.size() - 1;
00136     scalar sum = 0.0;
00137     scalar t = max(table[0][0], min(value, table[N][0]));
00138 
00139     label i = 0;
00140     while
00141     (
00142         (i < N - 1)
00143      && (table[i+1][0] < t)
00144     )
00145     {
00146         scalar deltaH = table[i+1][1] + table[i][1];
00147         scalar deltaT = table[i+1][0] - table[i][0];
00148         sum += 0.5*deltaH*deltaT;
00149         i++;
00150     }
00151 
00152     scalar interpolatedValue =
00153         table[i][1]
00154       + (t - table[i][0])
00155       * (table[i+1][1] - table[i][1])
00156       / (table[i+1][0] - table[i][0]);
00157 
00158     sum +=
00159         0.5*(interpolatedValue + table[i][1])
00160        *(t - table[i][0]);
00161 
00162     return sum;
00163 }
00164 
00165 Foam::scalar Foam::injectorType::integrateTable
00166 (
00167     const List<pair>& table
00168 ) const
00169 {
00170     scalar integratedTable = 0.0;
00171     for (label i=0; i < table.size() - 1; i++)
00172     {
00173         scalar deltaH = table[i+1][1] + table[i][1];
00174         scalar deltaT = table[i+1][0] - table[i][0];
00175         integratedTable += 0.5*deltaH*deltaT;
00176     }
00177 
00178     return integratedTable;
00179 }
00180 
00181 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd