intersection with triangle plane for miss
[OpenFOAM-1.5.x.git] / src / lagrangian / dieselSpray / injector / injectorType / injectorType.C
blob8dc366d8bdd0265ae661a402919e8af7200de729
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 "injectorType.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 namespace Foam
34 defineTypeNameAndDebug(injectorType, 0);
35 defineRunTimeSelectionTable(injectorType, dictionary);
40 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
42 // Construct from components
43 Foam::injectorType::injectorType
45     const Foam::Time&,
46     const Foam::dictionary&
50 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
52 Foam::autoPtr<Foam::injectorType> Foam::injectorType::New
54     const Time& t,
55     const dictionary& dict
58     word injectorTypeName
59     (
60         dict.lookup("injectorType")
61     );
63     Info<< "Selecting injectorType "
64          << injectorTypeName << endl;
66     dictionaryConstructorTable::iterator cstrIter =
67         dictionaryConstructorTablePtr_->find(injectorTypeName);
69     if (cstrIter == dictionaryConstructorTablePtr_->end())
70     {
71         FatalError
72             << "injectorType::New(const dictionary&) : " << endl
73             << "    unknown injectorType type "
74             << injectorTypeName
75             << ", constructor not in hash table" << endl << endl
76             << "    Valid injector types are :" << endl;
77         Info<< dictionaryConstructorTablePtr_->toc() << abort(FatalError);
78     }
80     return autoPtr<injectorType>(cstrIter()(t, dict));
85 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
87 Foam::injectorType::~injectorType()
90 Foam::scalar Foam::injectorType::getTableValue
92     const List<pair>& table,
93     const scalar value
94 ) const
96     // iterator
97     label i = 0;
99     // max items
100     label maxRow = table.size() - 1;
102     // check lower bound
103     if (value < table[0][0])
104     {
105         return table[0][1];
106     }
107     // check upper bound
108     else if (value > table[maxRow][0])
109     {
110         return table[maxRow][1];
111     }
112     // interpolate intermediate value
113     else
114     {
115         while
116         (
117             (i < maxRow-1) && (table[i+1][0] < value)
118         )
119         {
120             i++;
121         }
122         // value sits bewteen table[i][0] and table[i+1][0]
123         return table[i][1] 
124                + (value-table[i][0])/(table[i+1][0]-table[i][0])
125                * (table[i+1][1]-table[i][1]);
126     }
129 Foam::scalar Foam::injectorType::integrateTable
131     const List<pair>& table,
132     const scalar value
133 ) const
135     label N = table.size() - 1;
136     scalar sum = 0.0;
137     scalar t = max(table[0][0], min(value, table[N][0]));
139     label i = 0;
140     while
141     (
142         (i < N - 1)
143      && (table[i+1][0] < t)
144     )
145     {
146         scalar deltaH = table[i+1][1] + table[i][1];
147         scalar deltaT = table[i+1][0] - table[i][0];
148         sum += 0.5*deltaH*deltaT;
149         i++;
150     }
152     scalar interpolatedValue =
153         table[i][1]
154       + (t - table[i][0])
155       * (table[i+1][1] - table[i][1])
156       / (table[i+1][0] - table[i][0]);
158     sum +=
159         0.5*(interpolatedValue + table[i][1])
160        *(t - table[i][0]);
162     return sum;
165 Foam::scalar Foam::injectorType::integrateTable
167     const List<pair>& table
168 ) const
170     scalar integratedTable = 0.0;
171     for (label i=0; i < table.size() - 1; i++)
172     {
173         scalar deltaH = table[i+1][1] + table[i][1];
174         scalar deltaT = table[i+1][0] - table[i][0];
175         integratedTable += 0.5*deltaH*deltaT;
176     }
178     return integratedTable;
181 // ************************************************************************* //