ccmSolutionTable.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2016-2020 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Description
27 Containers for holding ccm solution and field listings.
28
29\*---------------------------------------------------------------------------*/
30
31#ifndef ccmSolutionTable_H
32#define ccmSolutionTable_H
33
34#include "SLList.H"
35#include "Ostream.H"
36#include "wordRes.H"
37
38// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39
40namespace Foam
41{
42namespace ccm
43{
44
45class fieldEntry;
46class fieldTable;
47class solutionEntry;
48
49Ostream& operator<<(Ostream& os, const fieldEntry& entry);
50Ostream& operator<<(Ostream& os, const fieldTable& entry);
51Ostream& operator<<(Ostream& os, const solutionEntry& entry);
52
53/*---------------------------------------------------------------------------*\
54 Class Foam::ccm::namesList Declaration
55\*---------------------------------------------------------------------------*/
56
57//- A linked-list that is searchable by the 'name()' of the items
58template<class T>
60:
61 public SLList<T>
62{
63public:
65 using iterator = typename SLList<T>::iterator;
66
67 // Constructors
68
69 //- Default construct
70 namesList() = default;
71
72
73 // Access
74
75 //- Return true if a list element has a name that matches key
76 bool found(const word& key) const
77 {
78 forAllConstIters(*this, iter)
79 {
80 if (iter().name() == key)
81 {
82 return true;
83 }
84 }
85
86 return false;
87 }
88
89
90 //- Find a list element has a name matching key
91 iterator find(const word& key)
92 {
93 forAllIters(*this, iter)
94 {
95 if (iter().name() == key)
96 {
97 return iter;
98 }
99 }
100
101 return SLList<T>::end();
102 }
103
104
105 //- Return a list of names in allow-list and not in deny-list
107 (
108 const wordRes& allow,
109 const wordRes& deny = wordRes()
110 ) const
111 {
112 List<word> matched(SLList<T>::size());
113
114 label matchi = 0;
115 forAllConstIters(*this, iter)
116 {
117 const word& name = iter().name();
118
119 if (allow.match(name) && !deny.match(name))
120 {
121 matched[matchi++] = name;
122 }
123 }
124 matched.resize(matchi);
125
126 return matched;
127 }
128};
129
130
131/*---------------------------------------------------------------------------*\
132 Class Foam::ccm::fieldEntry Declaration
133\*---------------------------------------------------------------------------*/
134
135//- A ccm field entry with short name, name, maxId and type
136// shortName => ( fullName, maxId, type );
138{
139 // Private Data
140
141 //- The field name (PROSTAR short name)
142 word name_;
143
144 //- The full field name
145 string fullName_;
146
147 //- The field units
148 string units_;
149
150 //- The max cell id for the field
151 label maxCellId_;
152
153 //- The max face id for the field
154 label maxFaceId_;
155
156public:
157
158 // Constructors
159
160 //- Construct from components with optional units
162 (
163 const word& shortName,
164 const string& fullName,
165 const char* units = nullptr
166 )
167 :
168 name_(shortName),
169 fullName_(fullName),
170 units_(),
171 maxCellId_(0),
172 maxFaceId_(0)
173 {
174 if (units && *units)
175 {
176 units_ = units;
177 }
178 }
179
180
181 // Access
182
183 //- The field name (PROSTAR short name)
184 const word& name() const
185 {
186 return name_;
187 }
188
189 //- The full field name
190 const string& fullName() const
191 {
192 return fullName_;
193 }
194
195 //- The field units
196 const string& units() const
197 {
198 return units_;
199 }
200
201 //- The max cell id for the field
202 label maxCellId() const
203 {
204 return maxCellId_;
205 }
206
207 //- The max face id for the field
208 label maxFaceId() const
209 {
210 return maxFaceId_;
211 }
212
213
214 // Edit
215
216 //- Set the field units
217 void units(const std::string& units)
218 {
219 if (!units.empty())
220 {
221 units_ = units;
222 }
223 }
224
225 //- Set the max cell Id for the field
226 void maxCellId(const int newMax)
227 {
228 if (maxCellId_ < newMax)
229 {
230 maxCellId_ = newMax;
231 }
232 }
233
234
235 //- Set the max face Id for the field
236 void maxFaceId(const int newMax)
237 {
238 if (maxFaceId_ < newMax)
239 {
240 maxFaceId_ = newMax;
241 }
242 }
243
244
245 // IOstream Operators
246
247 friend Ostream& operator<<
248 (
249 Ostream& os,
250 const fieldEntry& entry
251 )
252 {
253 os << entry.name_ << " => " << entry.fullName_
254 << " [" << entry.units_.c_str()
255 << "] maxCell: " << entry.maxCellId_
256 << " maxFace: " << entry.maxFaceId_;
257
258 return os;
259 }
260};
261
262
263/*---------------------------------------------------------------------------*\
264 Class Foam::ccm::solutionEntry Declaration
265\*---------------------------------------------------------------------------*/
266
267//- A ccm solution entry with name, iteration and time
268// stateName => ( iteration, time );
270{
271 // Private Data
272
273 //- The solution name
274 word name_;
275
276 //- The solution iteration/timestep
277 label iter_;
278
279 //- The solution time (sec)
280 scalar time_;
281
282public:
283
284 // Constructors
285
286 //- Construct from components
288 (
289 const word& name,
290 const label iteration,
291 const scalar timeValue = 0
292 )
293 :
294 name_(name),
295 iter_(iteration),
296 time_(timeValue)
297 {}
298
299 // Access
300
301 //- The solution name
302 const word& name() const
303 {
304 return name_;
305 }
306
307 //- The solution iteration/timestep
308 label iteration() const
309 {
310 return iter_;
311 }
312
313 //- The solution time (sec)
314 scalar timeValue() const
315 {
316 return time_;
317 }
318
319
320 // IOstream Operators
321
322 friend Ostream& operator<<
323 (
324 Ostream& os,
325 const solutionEntry& entry
326 )
327 {
328 os << entry.name_ << " =>"
329 << " iter: " << entry.iter_
330 << " time: " << entry.time_;
331
332 return os;
333 }
334};
335
336
337/*---------------------------------------------------------------------------*\
338 Class Foam::ccm::solutionTable Declaration
339\*---------------------------------------------------------------------------*/
340
341// Typedef: ccm::solutionTable
342// A list of all the available solutions
344
345
346/*---------------------------------------------------------------------------*\
347 Class Foam::ccm::fieldTable Declaration
348\*---------------------------------------------------------------------------*/
349
350//- A list of the available fields
352:
353 public namesList<fieldEntry>
354{
355public:
356
357 // Constructor
358
359 //- Null construct
361 :
363 {}
364
365
366 // Access
367
368 //- The maximum cell Id referenced in the list
369 label maxCellId() const
370 {
371 label maxId = 0;
372 forAllConstIters(*this, iter)
373 {
374 const label currMax = iter().maxCellId();
375
376 if (maxId < currMax)
377 {
378 maxId = currMax;
379 }
380 }
381
382 return maxId;
383 }
384
385
386 //- The maximum face Id referenced in the list
387 label maxFaceId() const
388 {
389 label maxId = 0;
390 forAllConstIters(*this, iter)
391 {
392 const label currMax = iter().maxFaceId();
393
394 if (maxId < currMax)
395 {
396 maxId = currMax;
397 }
398 }
399
400 return maxId;
401 }
402
403
404 // IOstream Operators
405
406 friend Ostream& operator<<
407 (
408 Ostream& os,
409 const fieldTable& tbl
410 )
411 {
412 os << static_cast<const namesList<fieldEntry>&>(tbl)
413 << nl
414 << "maxCell: " << tbl.maxCellId()
415 << " maxFace: " << tbl.maxFaceId();
416
417 return os;
418 }
419};
420
421
422// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
423
424} // End namespace ccm
425} // End namespace Foam
426
427// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
428
429#endif
430
431// ************************************************************************* //
Non-intrusive singly-linked list.
An STL-conforming const_iterator.
Definition: LList.H:378
An STL-conforming iterator.
Definition: LList.H:334
Template class for non-intrusive linked lists.
Definition: LList.H:79
const iterator & end()
End of list for forward iterators.
Definition: LList.H:540
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A ccm field entry with short name, name, maxId and type.
void maxFaceId(const int newMax)
Set the max face Id for the field.
const string & units() const
The field units.
label maxCellId() const
The max cell id for the field.
const word & name() const
The field name (PROSTAR short name)
fieldEntry(const word &shortName, const string &fullName, const char *units=nullptr)
Construct from components with optional units.
label maxFaceId() const
The max face id for the field.
void units(const std::string &units)
Set the field units.
const string & fullName() const
The full field name.
void maxCellId(const int newMax)
Set the max cell Id for the field.
A list of the available fields.
label maxCellId() const
The maximum cell Id referenced in the list.
fieldTable()
Null construct.
label maxFaceId() const
The maximum face Id referenced in the list.
A linked-list that is searchable by the 'name()' of the items.
List< word > findNames(const wordRes &allow, const wordRes &deny=wordRes()) const
Return a list of names in allow-list and not in deny-list.
iterator find(const word &key)
Find a list element has a name matching key.
namesList()=default
Default construct.
typename SLList< T >::const_iterator const_iterator
bool found(const word &key) const
Return true if a list element has a name that matches key.
typename SLList< T >::iterator iterator
A ccm solution entry with name, iteration and time.
const word & name() const
The solution name.
scalar timeValue() const
The solution time (sec)
solutionEntry(const word &name, const label iteration, const scalar timeValue=0)
Construct from components.
label iteration() const
The solution iteration/timestep.
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
bool match(const std::string &text, bool literal=false) const
Smart match as literal or regex, stopping on the first match.
Definition: wordResI.H:91
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &os, const interfaceEntry &entry)
namesList< solutionEntry > solutionTable
Namespace for OpenFOAM.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:260
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278