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-2024 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 // Forward Declarations
46 class fieldEntry;
47 class fieldTable;
48 class solutionEntry;
49 
50 Ostream& operator<<(Ostream& os, const fieldEntry& entry);
51 Ostream& operator<<(Ostream& os, const fieldTable& entry);
52 Ostream& operator<<(Ostream& os, const solutionEntry& entry);
53 
54 /*---------------------------------------------------------------------------*\
55  Class Foam::ccm::namesList Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 //- A linked-list that is searchable by the 'name()' of the items
59 template<class Type>
60 class namesList
61 :
62  public SLList<Type>
63 {
64 public:
65 
67  using iterator = typename SLList<Type>::iterator;
68 
69 
70  // Constructors
71 
72  //- Default construct
73  namesList() = default;
74 
75 
76  // Access
77 
78  //- True if a list element has a name that matches key
79  bool found(const word& key) const
80  {
81  for (const Type& item : *this)
82  {
83  if (item.name() == key)
84  {
85  return true;
86  }
87  }
88 
89  return false;
90  }
91 
92 
93  //- Find list element by name
94  iterator find(const word& key)
95  {
96  const auto last = SLList<Type>::end();
97 
99 
100  for (; (iter != last); ++iter)
101  {
102  if ((*iter).name() == key)
103  {
104  break;
105  }
106  }
107 
108  return iter;
109  }
110 
111 
112  //- Return a list of names in allow-list and not in deny-list
113  List<word> findNames
114  (
115  const wordRes& allow,
116  const wordRes& deny = wordRes()
117  ) const
118  {
119  List<word> matched(SLList<Type>::size());
120 
121  label count = 0;
122 
123  for (const Type& item : *this)
124  {
125  const word& name = item.name();
126 
127  if (allow.match(name) && !deny.match(name))
128  {
129  matched[count] = name;
130  ++count;
131  }
132  }
133 
134  matched.resize(count);
135  return matched;
136  }
137 };
138 
139 
140 /*---------------------------------------------------------------------------*\
141  Class Foam::ccm::fieldEntry Declaration
142 \*---------------------------------------------------------------------------*/
143 
144 //- A ccm field entry with short name, name, maxId and type
145 // shortName => ( fullName, maxId, type );
146 class fieldEntry
147 {
148  // Private Data
149 
150  //- The field name (PROSTAR short name)
151  word name_;
152 
153  //- The full field name
154  string fullName_;
155 
156  //- The field units
157  string units_;
158 
159  //- The max cell id for the field
160  label maxCellId_;
161 
162  //- The max face id for the field
163  label maxFaceId_;
164 
165 public:
166 
167  // Constructors
168 
169  //- Construct from components with optional units
170  fieldEntry
171  (
172  const word& shortName,
173  const string& fullName,
174  const char* units = nullptr
175  )
176  :
177  name_(shortName),
178  fullName_(fullName),
179  units_(),
180  maxCellId_(0),
181  maxFaceId_(0)
182  {
183  if (units && *units)
184  {
185  units_ = units;
186  }
187  }
188 
189 
190  // Access
191 
192  //- The field name (PROSTAR short name)
193  const word& name() const noexcept { return name_; }
194 
195  //- The full field name
196  const string& fullName() const noexcept { return fullName_; }
197 
198  //- The field units
199  const string& units() const noexcept { return units_; }
200 
201  //- The max cell id for the field
202  label maxCellId() const noexcept { return maxCellId_; }
203 
204  //- The max face id for the field
205  label maxFaceId() const noexcept { return maxFaceId_; }
206 
207 
208  // Edit
209 
210  //- Set the field units
211  void units(const std::string& units)
212  {
213  if (!units.empty())
214  {
215  units_ = units;
216  }
217  }
218 
219  //- Set the max cell Id for the field
220  void maxCellId(const int val)
221  {
222  if (maxCellId_ < val)
223  {
224  maxCellId_ = val;
225  }
226  }
227 
228 
229  //- Set the max face Id for the field
230  void maxFaceId(const int val)
231  {
232  if (maxFaceId_ < val)
233  {
234  maxFaceId_ = val;
235  }
236  }
237 
238 
239  // IOstream Operators
240 
241  friend Ostream& operator<<
242  (
243  Ostream& os,
244  const fieldEntry& entry
245  )
246  {
247  os << entry.name_ << " => " << entry.fullName_
248  << " [" << entry.units_.c_str()
249  << "] maxCell: " << entry.maxCellId_
250  << " maxFace: " << entry.maxFaceId_;
251 
252  return os;
253  }
254 };
255 
256 
257 /*---------------------------------------------------------------------------*\
258  Class Foam::ccm::solutionEntry Declaration
259 \*---------------------------------------------------------------------------*/
260 
261 //- A ccm solution entry with name, iteration and time
262 // stateName => ( iteration, time );
263 class solutionEntry
264 {
265  // Private Data
266 
267  //- The solution name
268  word name_;
269 
270  //- The solution iteration/timestep
271  label iter_;
272 
273  //- The solution time (sec)
274  scalar time_;
275 
276 public:
278  // Constructors
279 
280  //- Construct from components
282  (
283  const word& name,
284  const label iteration,
285  const scalar timeValue = 0
286  )
287  :
288  name_(name),
289  iter_(iteration),
290  time_(timeValue)
291  {}
292 
293  // Access
294 
295  //- The solution name
296  const word& name() const noexcept { return name_; }
297 
298  //- The solution iteration/timestep
299  label iteration() const noexcept { return iter_; }
300 
301  //- The solution time (sec)
302  scalar timeValue() const noexcept { return time_; }
303 
304 
305  // IOstream Operators
306 
307  friend Ostream& operator<<
308  (
309  Ostream& os,
310  const solutionEntry& entry
311  )
312  {
313  os << entry.name_ << " =>"
314  << " iter: " << entry.iter_
315  << " time: " << entry.time_;
316 
317  return os;
318  }
319 };
320 
321 
322 /*---------------------------------------------------------------------------*\
323  Class Foam::ccm::solutionTable Declaration
324 \*---------------------------------------------------------------------------*/
325 
326 // Typedef: ccm::solutionTable
327 // A list of all the available solutions
329 
330 
331 /*---------------------------------------------------------------------------*\
332  Class Foam::ccm::fieldTable Declaration
333 \*---------------------------------------------------------------------------*/
334 
335 //- A list of the available fields
336 class fieldTable
337 :
338  public namesList<fieldEntry>
339 {
340 public:
341 
342  // Constructor
343 
344  //- Default construct
345  fieldTable() = default;
346 
347 
348  // Access
350  //- The maximum cell Id referenced in the list
351  label maxCellId() const
352  {
353  label result = 0;
354  for (const auto& item : *this)
355  {
356  const label val = item.maxCellId();
357 
358  if (result < val)
359  {
360  result = val;
361  }
362  }
363 
364  return result;
365  }
366 
367 
368  //- The maximum face Id referenced in the list
369  label maxFaceId() const
370  {
371  label result = 0;
372  for (const auto& item : *this)
373  {
374  const label val = item.maxFaceId();
375 
376  if (result < val)
377  {
378  result = val;
379  }
380  }
381 
382  return result;
383  }
384 
385 
386  // IOstream Operators
387 
388  friend Ostream& operator<<
389  (
391  const fieldTable& tbl
392  )
393  {
394  os << static_cast<const namesList<fieldEntry>&>(tbl)
395  << nl
396  << "maxCell: " << tbl.maxCellId()
397  << " maxFace: " << tbl.maxFaceId();
398 
399  return os;
400  }
401 };
402 
403 
404 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
405 
406 } // End namespace ccm
407 } // End namespace Foam
408 
409 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410 
411 #endif
412 
413 // ************************************************************************* //
typename SLList< solutionEntry >::const_iterator const_iterator
label iteration() const noexcept
The solution iteration/timestep.
typename SLList< solutionEntry >::iterator iterator
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:153
A ccm solution entry with name, iteration and time.
const iterator & end()
End of list for forward iterators.
Definition: LList.H:649
scalar timeValue() const noexcept
The solution time (sec)
Template class for non-intrusive linked lists.
Definition: LList.H:46
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
An STL-conforming const_iterator.
Definition: LList.H:458
An STL-conforming iterator.
Definition: LList.H:410
label maxCellId() const
The maximum cell Id referenced in the list.
label maxFaceId() const noexcept
The max face id for the field.
fieldEntry(const word &shortName, const string &fullName, const char *units=nullptr)
Construct from components with optional units.
const string & units() const noexcept
The field units.
label maxFaceId() const
The maximum face Id referenced in the list.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
const string & fullName() const noexcept
The full field name.
A class for handling words, derived from Foam::string.
Definition: word.H:63
reference last()
The last entry in the list.
Definition: LList.H:716
const word & name() const noexcept
The field name (PROSTAR short name)
bool found(const word &key) const
True if a list element has a name that matches key.
solutionEntry(const word &name, const label iteration, const scalar timeValue=0)
Construct from components.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
iterator begin()
Iterator to first item in list with non-const access.
Definition: LList.H:600
A ccm field entry with short name, name, maxId and type.
namesList< solutionEntry > solutionTable
A list of the available fields.
label maxCellId() const noexcept
The max cell id for the field.
namesList()=default
Default construct.
List< word > findNames(const wordRes &allow, const wordRes &deny=wordRes()) const
Return a list of names in allow-list and not in deny-list.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
A linked-list that is searchable by the &#39;name()&#39; of the items.
fieldTable()=default
Default construct.
Ostream & operator<<(Ostream &os, const interfaceEntry &entry)
const word & name() const noexcept
The solution name.
Non-intrusive singly-linked list.
iterator find(const word &key)
Find list element by name.
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63