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-2025 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 Foam_ccmSolutionTable_H
32 #define Foam_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 
294  // Access
295 
296  //- The solution name
297  const word& name() const noexcept { return name_; }
298 
299  //- The solution iteration/timestep
300  label iteration() const noexcept { return iter_; }
302  //- The solution time (sec)
303  scalar timeValue() const noexcept { return time_; }
304 
305 
306  // IOstream Operators
307 
308  friend Ostream& operator<<
309  (
310  Ostream& os,
311  const solutionEntry& entry
312  )
313  {
314  os << entry.name_ << " =>"
315  << " iter: " << entry.iter_
316  << " time: " << entry.time_;
317 
318  return os;
319  }
320 };
321 
322 
323 /*---------------------------------------------------------------------------*\
324  Class Foam::ccm::solutionTable Declaration
325 \*---------------------------------------------------------------------------*/
326 
327 // Typedef: ccm::solutionTable
328 // A list of all the available solutions
330 
331 
332 /*---------------------------------------------------------------------------*\
333  Class Foam::ccm::fieldTable Declaration
334 \*---------------------------------------------------------------------------*/
335 
336 //- A list of the available fields
337 class fieldTable
338 :
339  public namesList<fieldEntry>
340 {
341 public:
342 
343  // Constructor
344 
345  //- Default construct
346  fieldTable() = default;
347 
348 
349  // Access
351  //- The maximum cell Id referenced in the list
352  label maxCellId() const
353  {
354  label result = 0;
355  for (const auto& item : *this)
356  {
357  const label val = item.maxCellId();
358 
359  if (result < val)
360  {
361  result = val;
362  }
363  }
364 
365  return result;
366  }
367 
368 
369  //- The maximum face Id referenced in the list
370  label maxFaceId() const
371  {
372  label result = 0;
373  for (const auto& item : *this)
374  {
375  const label val = item.maxFaceId();
376 
377  if (result < val)
378  {
379  result = val;
380  }
381  }
382 
383  return result;
384  }
385 
386 
387  // IOstream Operators
388 
389  friend Ostream& operator<<
390  (
392  const fieldTable& tbl
393  )
394  {
395  os << static_cast<const namesList<fieldEntry>&>(tbl)
396  << nl
397  << "maxCell: " << tbl.maxCellId()
398  << " maxFace: " << tbl.maxFaceId();
399 
400  return os;
401  }
402 };
403 
404 
405 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
406 
407 } // End namespace ccm
408 } // End namespace Foam
409 
410 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
411 
412 #endif
413 
414 // ************************************************************************* //
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:150
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.
auto key(const Type &t) -> std::enable_if_t< std::is_enum_v< Type >, std::underlying_type_t< Type > >
Definition: foamGltfBase.H:103
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: scalarImpl.H:255
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.
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