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 -------------------------------------------------------------------------------
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 
31 #ifndef ccmSolutionTable_H
32 #define ccmSolutionTable_H
33 
34 #include "SLList.H"
35 #include "Ostream.H"
36 #include "wordRes.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 namespace ccm
43 {
44 
45 class fieldEntry;
46 class fieldTable;
47 class solutionEntry;
48 
49 Ostream& operator<<(Ostream& os, const fieldEntry& entry);
50 Ostream& operator<<(Ostream& os, const fieldTable& entry);
51 Ostream& 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
58 template<class T>
59 class namesList
60 :
61  public SLList<T>
62 {
63 public:
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
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 
156 public:
157 
158  // Constructors
159 
160  //- Construct from components with optional units
161  fieldEntry
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 
282 public:
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 {
355 public:
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 // ************************************************************************* //
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::fieldEntry::maxFaceId
label maxFaceId() const
The max face id for the field.
Definition: ccmSolutionTable.H:208
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::ccm::solutionEntry::name
const word & name() const
The solution name.
Definition: ccmSolutionTable.H:302
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::ccm::fieldEntry
A ccm field entry with short name, name, maxId and type.
Definition: ccmSolutionTable.H:137
Foam::ccm::fieldEntry::maxCellId
label maxCellId() const
The max cell id for the field.
Definition: ccmSolutionTable.H:202
Foam::ccm::solutionEntry
A ccm solution entry with name, iteration and time.
Definition: ccmSolutionTable.H:269
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::ccm::namesList
A linked-list that is searchable by the 'name()' of the items.
Definition: ccmSolutionTable.H:59
Foam::ccm::namesList< solutionEntry >::const_iterator
typename SLList< solutionEntry >::const_iterator const_iterator
Definition: ccmSolutionTable.H:64
Foam::ccm::solutionEntry::iteration
label iteration() const
The solution iteration/timestep.
Definition: ccmSolutionTable.H:308
Foam::ccm::fieldEntry::name
const word & name() const
The field name (PROSTAR short name)
Definition: ccmSolutionTable.H:184
Foam::LList::iterator
An STL-conforming iterator.
Definition: LList.H:325
Foam::ccm::namesList< solutionEntry >::iterator
typename SLList< solutionEntry >::iterator iterator
Definition: ccmSolutionTable.H:65
Foam::ccm::fieldTable
A list of the available fields.
Definition: ccmSolutionTable.H:351
Foam::ccm::operator<<
Ostream & operator<<(Ostream &os, const interfaceEntry &entry)
Definition: ccmInterfaceDefinitions.H:159
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:91
Foam::LList::end
const iterator & end()
End of list for forward iterators.
Definition: LList.H:534
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:190
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:196
Foam::ccm::fieldEntry::units
void units(const std::string &units)
Set the field units.
Definition: ccmSolutionTable.H:217
Foam::ccm::fieldTable::maxCellId
label maxCellId() const
The maximum cell Id referenced in the list.
Definition: ccmSolutionTable.H:369
Foam::ccm::fieldEntry::fieldEntry
fieldEntry(const word &shortName, const string &fullName, const char *units=nullptr)
Construct from components with optional units.
Definition: ccmSolutionTable.H:162
Foam::ccm::namesList::namesList
namesList()=default
Default construct.
Foam::ccm::fieldTable::fieldTable
fieldTable()
Null construct.
Definition: ccmSolutionTable.H:360
Foam::ccm::solutionEntry::timeValue
scalar timeValue() const
The solution time (sec)
Definition: ccmSolutionTable.H:314
forAllIters
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:223
Foam::ccm::solutionEntry::solutionEntry
solutionEntry(const word &name, const label iteration, const scalar timeValue=0)
Construct from components.
Definition: ccmSolutionTable.H:288
os
OBJstream os(runTime.globalPath()/outputName)
Foam::ccm::solutionTable
namesList< solutionEntry > solutionTable
Definition: ccmSolutionTable.H:343
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Ostream.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
SLList.H
Non-intrusive singly-linked list.
Foam::List< word >
Foam::ccm::namesList::findNames
List< word > findNames(const wordRes &allow, const wordRes &deny=wordRes()) const
Return a list of names in allow-list and not in deny-list.
Definition: ccmSolutionTable.H:107
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:387
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::ccm::fieldEntry::maxFaceId
void maxFaceId(const int newMax)
Set the max face Id for the field.
Definition: ccmSolutionTable.H:236
Foam::ccm::fieldEntry::maxCellId
void maxCellId(const int newMax)
Set the max cell Id for the field.
Definition: ccmSolutionTable.H:226
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::LList::const_iterator
An STL-conforming const_iterator.
Definition: LList.H:369