FreeFOAM The Cross-Platform CFD Toolkit
injectorType.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 
33 defineTypeNameAndDebug(injectorType, 0);
34 defineRunTimeSelectionTable(injectorType, dictionary);
35 
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
41 // Construct from components
43 (
44  const Foam::Time&,
45  const Foam::dictionary&
46 )
47 {}
48 
49 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
50 
52 (
53  const Time& t,
54  const dictionary& dict
55 )
56 {
57  word injectorTypeName
58  (
59  dict.lookup("injectorType")
60  );
61 
62  Info<< "Selecting injectorType "
63  << injectorTypeName << endl;
64 
65  dictionaryConstructorTable::iterator cstrIter =
66  dictionaryConstructorTablePtr_->find(injectorTypeName);
67 
68  if (cstrIter == dictionaryConstructorTablePtr_->end())
69  {
71  << "injectorType::New(const dictionary&) : " << endl
72  << " unknown injectorType type "
73  << injectorTypeName
74  << ", constructor not in hash table" << endl << endl
75  << " Valid injector types are :" << endl;
76  Info<< dictionaryConstructorTablePtr_->sortedToc() << abort(FatalError);
77  }
78 
79  return autoPtr<injectorType>(cstrIter()(t, dict));
80 
81 }
82 
83 
84 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
85 
87 {}
88 
90 (
91  const List<pair>& table,
92  const scalar value
93 ) const
94 {
95  // iterator
96  label i = 0;
97 
98  // max items
99  label maxRow = table.size() - 1;
100 
101  // check lower bound
102  if (value < table[0][0])
103  {
104  return table[0][1];
105  }
106  // check upper bound
107  else if (value > table[maxRow][0])
108  {
109  return table[maxRow][1];
110  }
111  // interpolate intermediate value
112  else
113  {
114  while
115  (
116  (i < maxRow-1) && (table[i+1][0] < value)
117  )
118  {
119  i++;
120  }
121  // value sits bewteen table[i][0] and table[i+1][0]
122  return table[i][1]
123  + (value-table[i][0])/(table[i+1][0]-table[i][0])
124  * (table[i+1][1]-table[i][1]);
125  }
126 }
127 
129 (
130  const List<pair>& table,
131  const scalar value
132 ) const
133 {
134  label N = table.size() - 1;
135  scalar sum = 0.0;
136  scalar t = max(table[0][0], min(value, table[N][0]));
137 
138  label i = 0;
139  while
140  (
141  (i < N - 1)
142  && (table[i+1][0] < t)
143  )
144  {
145  scalar deltaH = table[i+1][1] + table[i][1];
146  scalar deltaT = table[i+1][0] - table[i][0];
147  sum += 0.5*deltaH*deltaT;
148  i++;
149  }
150 
151  scalar interpolatedValue =
152  table[i][1]
153  + (t - table[i][0])
154  * (table[i+1][1] - table[i][1])
155  / (table[i+1][0] - table[i][0]);
156 
157  sum +=
158  0.5*(interpolatedValue + table[i][1])
159  *(t - table[i][0]);
160 
161  return sum;
162 }
163 
165 (
166  const List<pair>& table
167 ) const
168 {
169  scalar integratedTable = 0.0;
170  for (label i=0; i < table.size() - 1; i++)
171  {
172  scalar deltaH = table[i+1][1] + table[i][1];
173  scalar deltaT = table[i+1][0] - table[i][0];
174  integratedTable += 0.5*deltaH*deltaT;
175  }
176 
177  return integratedTable;
178 }
179 
180 // ************************ vim: set sw=4 sts=4 et: ************************ //