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-2018 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 
26 Description
27  Containers for holding ccm solution and field listings.
28 
29 \*---------------------------------------------------------------------------*/
30 #ifndef ccmSolutionTable_H
31 #define ccmSolutionTable_H
32 
33 #include "SLList.H"
34 #include "Ostream.H"
35 #include "wordRes.H"
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 namespace ccm
42 {
43 
44 class fieldEntry;
45 class fieldTable;
46 class solutionEntry;
47 
48 Ostream& operator<<(Ostream& os, const fieldEntry& entry);
49 Ostream& operator<<(Ostream& os, const fieldTable& entry);
50 Ostream& operator<<(Ostream& os, const solutionEntry& entry);
51 
52 /*---------------------------------------------------------------------------*\
53  Class Foam::ccm::namesList Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 //- A linked-list that is searchable by the 'name()' of the items
57 template<class T>
58 class namesList
59 :
60  public SLList<T>
61 {
62 public:
64  using iterator = typename SLList<T>::iterator;
65 
66  // Constructors
67 
68  //- Null construct
70  {}
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 matching white-list and not in black-list
107  (
108  const wordRes& white,
109  const wordRes& black = 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 (white.match(name) && !black.match(name))
120  {
121  matched[matchi++] = name;
122  }
123  }
124  matched.setSize(matchi);
125 
126  return matched;
127  }
128 
129 };
130 
131 
132 /*---------------------------------------------------------------------------*\
133  Class Foam::ccm::fieldEntry Declaration
134 \*---------------------------------------------------------------------------*/
135 
136 //- A ccm field entry with short name, name, maxId and type
137 // shortName => ( fullName, maxId, type );
139 {
140  // Private Data
141 
142  //- The field name (PROSTAR short name)
143  word name_;
144 
145  //- The full field name
146  string fullName_;
147 
148  //- The field units
149  string units_;
150 
151  //- The max cell id for the field
152  label maxCellId_;
153 
154  //- The max face id for the field
155  label maxFaceId_;
156 
157 public:
158 
159  // Constructors
160 
161  //- Construct from components with optional units
162  fieldEntry
163  (
164  const word& shortName,
165  const string& fullName,
166  const char* units = nullptr
167  )
168  :
169  name_(shortName),
170  fullName_(fullName),
171  units_(),
172  maxCellId_(0),
173  maxFaceId_(0)
174  {
175  if (units && *units)
176  {
177  units_ = units;
178  }
179  }
180 
181 
182  // Access
183 
184  //- The field name (PROSTAR short name)
185  const word& name() const
186  {
187  return name_;
188  }
189 
190  //- The full field name
191  const string& fullName() const
192  {
193  return fullName_;
194  }
195 
196  //- The field units
197  const string& units() const
198  {
199  return units_;
200  }
201 
202  //- The max cell id for the field
203  label maxCellId() const
204  {
205  return maxCellId_;
206  }
207 
208  //- The max face id for the field
209  label maxFaceId() const
210  {
211  return maxFaceId_;
212  }
213 
214 
215  // Edit
216 
217  //- Set the field units
218  void units(const std::string& units)
219  {
220  if (!units.empty())
221  {
222  units_ = units;
223  }
224  }
225 
226  //- Set the max cell Id for the field
227  void maxCellId(const int newMax)
228  {
229  if (maxCellId_ < newMax)
230  {
231  maxCellId_ = newMax;
232  }
233  }
234 
235 
236  //- Set the max face Id for the field
237  void maxFaceId(const int newMax)
238  {
239  if (maxFaceId_ < newMax)
240  {
241  maxFaceId_ = newMax;
242  }
243  }
244 
245 
246  // IOstream Operators
247 
248  friend Ostream& operator<<
249  (
250  Ostream& os,
251  const fieldEntry& entry
252  )
253  {
254  os << entry.name_ << " => " << entry.fullName_
255  << " [" << entry.units_.c_str()
256  << "] maxCell: " << entry.maxCellId_
257  << " maxFace: " << entry.maxFaceId_;
258 
259  return os;
260  }
261 
262 };
263 
264 
265 /*---------------------------------------------------------------------------*\
266  Class Foam::ccm::solutionEntry Declaration
267 \*---------------------------------------------------------------------------*/
268 
269 //- A ccm solution entry with name, iteration and time
270 // stateName => ( iteration, time );
272 {
273  // Private Data
274 
275  //- The solution name
276  word name_;
277 
278  //- The solution iteration/timestep
279  label iter_;
280 
281  //- The solution time (sec)
282  scalar time_;
283 
284 public:
285 
286  // Constructors
287 
288  //- Construct from components
290  (
291  const word& name,
292  const label iteration,
293  const scalar timeValue = 0
294  )
295  :
296  name_(name),
297  iter_(iteration),
298  time_(timeValue)
299  {}
300 
301  // Access
302 
303  //- The solution name
304  const word& name() const
305  {
306  return name_;
307  }
308 
309  //- The solution iteration/timestep
310  label iteration() const
311  {
312  return iter_;
313  }
314 
315  //- The solution time (sec)
316  scalar timeValue() const
317  {
318  return time_;
319  }
320 
321 
322  // IOstream Operators
323 
324  friend Ostream& operator<<
325  (
326  Ostream& os,
327  const solutionEntry& entry
328  )
329  {
330  os << entry.name_ << " =>"
331  << " iter: " << entry.iter_
332  << " time: " << entry.time_;
333 
334  return os;
335  }
336 
337 };
338 
339 
340 /*---------------------------------------------------------------------------*\
341  Class Foam::ccm::solutionTable Declaration
342 \*---------------------------------------------------------------------------*/
343 
344 // Typedef: ccm::solutionTable
345 // A list of all the available solutions
347 
348 
349 /*---------------------------------------------------------------------------*\
350  Class Foam::ccm::fieldTable Declaration
351 \*---------------------------------------------------------------------------*/
352 
353 //- A list of the available fields
355 :
356  public namesList<fieldEntry>
357 {
358 public:
359 
360  // Constructor
361 
362  //- Null construct
364  :
366  {}
367 
368 
369  // Access
370 
371  //- The maximum cell Id referenced in the list
372  label maxCellId() const
373  {
374  label maxId = 0;
375  forAllConstIters(*this, iter)
376  {
377  const label currMax = iter().maxCellId();
378 
379  if (maxId < currMax)
380  {
381  maxId = currMax;
382  }
383  }
384 
385  return maxId;
386  }
387 
388 
389  //- The maximum face Id referenced in the list
390  label maxFaceId() const
391  {
392  label maxId = 0;
393  forAllConstIters(*this, iter)
394  {
395  const label currMax = iter().maxFaceId();
396 
397  if (maxId < currMax)
398  {
399  maxId = currMax;
400  }
401  }
402 
403  return maxId;
404  }
405 
406 
407  // IOstream Operators
408 
409  friend Ostream& operator<<
410  (
411  Ostream& os,
412  const fieldTable& tbl
413  )
414  {
415  os << static_cast<const namesList<fieldEntry>&>(tbl)
416  << nl
417  << "maxCell: " << tbl.maxCellId()
418  << " maxFace: " << tbl.maxFaceId();
419 
420  return os;
421  }
422 
423 };
424 
425 
426 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
427 
428 } // End namespace ccm
429 } // End namespace Foam
430 
431 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
432 
433 #endif
434 
435 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::ccm::namesList::find
iterator find(const word &key)
Find a list element has a name matching key.
Definition: ccmSolutionTable.H:91
wordRes.H
Foam::ccm::namesList::namesList
namesList()
Null construct.
Definition: ccmSolutionTable.H:69
Foam::ccm::fieldEntry::maxFaceId
label maxFaceId() const
The max face id for the field.
Definition: ccmSolutionTable.H:209
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::ccm::solutionEntry::name
const word & name() const
The solution name.
Definition: ccmSolutionTable.H:304
Foam::ccm::namesList::findNames
List< word > findNames(const wordRes &white, const wordRes &black=wordRes()) const
Return a list of names matching white-list and not in black-list.
Definition: ccmSolutionTable.H:107
Foam::ccm::fieldEntry
A ccm field entry with short name, name, maxId and type.
Definition: ccmSolutionTable.H:138
Foam::ccm::fieldEntry::maxCellId
label maxCellId() const
The max cell id for the field.
Definition: ccmSolutionTable.H:203
Foam::ccm::solutionEntry
A ccm solution entry with name, iteration and time.
Definition: ccmSolutionTable.H:271
Foam::ccm::namesList
A linked-list that is searchable by the 'name()' of the items.
Definition: ccmSolutionTable.H:58
Foam::ccm::namesList< solutionEntry >::const_iterator
typename SLList< solutionEntry >::const_iterator const_iterator
Definition: ccmSolutionTable.H:63
Foam::ccm::solutionEntry::iteration
label iteration() const
The solution iteration/timestep.
Definition: ccmSolutionTable.H:310
Foam::ccm::fieldEntry::name
const word & name() const
The field name (PROSTAR short name)
Definition: ccmSolutionTable.H:185
Foam::LList::iterator
An STL-conforming iterator.
Definition: LList.H:322
Foam::ccm::namesList< solutionEntry >::iterator
typename SLList< solutionEntry >::iterator iterator
Definition: ccmSolutionTable.H:64
Foam::ccm::fieldTable
A list of the available fields.
Definition: ccmSolutionTable.H:354
Foam::ccm::operator<<
Ostream & operator<<(Ostream &os, const interfaceEntry &entry)
Definition: ccmInterfaceDefinitions.H:158
Foam::wordRes::match
bool match(const std::string &text, bool literal=false) const
Smart match as literal or regex, stopping on the first match.
Definition: wordResI.H:87
Foam::LList::end
const iterator & end()
End of list for forward iterators.
Definition: LList.H:531
Foam::LList
Template class for non-intrusive linked lists.
Definition: LList.H:54
Foam::ccm::fieldEntry::fullName
const string & fullName() const
The full field name.
Definition: ccmSolutionTable.H:191
Foam::ccm::namesList::found
bool found(const word &key) const
Return true if a list element has a name that matches key.
Definition: ccmSolutionTable.H:76
Foam::ccm::fieldEntry::units
const string & units() const
The field units.
Definition: ccmSolutionTable.H:197
Foam::ccm::fieldEntry::units
void units(const std::string &units)
Set the field units.
Definition: ccmSolutionTable.H:218
Foam::ccm::fieldTable::maxCellId
label maxCellId() const
The maximum cell Id referenced in the list.
Definition: ccmSolutionTable.H:372
Foam::ccm::fieldEntry::fieldEntry
fieldEntry(const word &shortName, const string &fullName, const char *units=nullptr)
Construct from components with optional units.
Definition: ccmSolutionTable.H:163
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::ccm::fieldTable::fieldTable
fieldTable()
Null construct.
Definition: ccmSolutionTable.H:363
Foam::ccm::solutionEntry::timeValue
scalar timeValue() const
The solution time (sec)
Definition: ccmSolutionTable.H:316
forAllIters
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:217
Foam::ccm::solutionEntry::solutionEntry
solutionEntry(const word &name, const label iteration, const scalar timeValue=0)
Construct from components.
Definition: ccmSolutionTable.H:290
Foam::ccm::solutionTable
namesList< solutionEntry > solutionTable
Definition: ccmSolutionTable.H:346
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Ostream.H
Foam::nl
constexpr char nl
Definition: Ostream.H:372
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
SLList.H
Non-intrusive singly-linked list.
Foam::List< word >
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::ccm::fieldTable::maxFaceId
label maxFaceId() const
The maximum face Id referenced in the list.
Definition: ccmSolutionTable.H:390
Foam::ccm::fieldEntry::maxFaceId
void maxFaceId(const int newMax)
Set the max face Id for the field.
Definition: ccmSolutionTable.H:237
Foam::ccm::fieldEntry::maxCellId
void maxCellId(const int newMax)
Set the max cell Id for the field.
Definition: ccmSolutionTable.H:227
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::LList::const_iterator
An STL-conforming const_iterator.
Definition: LList.H:366