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

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