Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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 Foam_ccmSolutionTable_H
32#define Foam_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
45// Forward Declarations
46class fieldEntry;
47class fieldTable;
48class solutionEntry;
49
50Ostream& operator<<(Ostream& os, const fieldEntry& entry);
51Ostream& operator<<(Ostream& os, const fieldTable& entry);
52Ostream& 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
59template<class Type>
60class namesList
61:
62 public SLList<Type>
64public:
65
66 using const_iterator = typename SLList<Type>::const_iterator;
67 using iterator = typename SLList<Type>::iterator;
68
69
70 // Constructors
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 {
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 );
146class 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
165public:
166
167 // Constructors
168
169 //- Construct from components with optional units
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
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())
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<<
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;
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 );
263class 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
276public:
277
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
337class fieldTable
338:
339 public namesList<fieldEntry>
340{
341public:
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)
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 }
382
383 return result;
384 }
385
386
387 // IOstream Operators
388
389 friend Ostream& operator<<
390 (
392 const fieldTable& tbl
393 )
394 {
396 << nl
397 << "maxCell: " << tbl.maxCellId()
398 << " maxFace: " << tbl.maxFaceId();
399
400 return os;
401 }
403
404
405// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
406
407} // End namespace ccm
408} // End namespace Foam
409
410// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
411
412#endif
413
414// ************************************************************************* //
Non-intrusive singly-linked list.
const iterator & end()
Definition LList.H:649
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
label size() const noexcept
The number of elements in list.
Definition SLListBase.H:180
A ccm field entry with short name, name, maxId and type.
void maxCellId(const int val)
Set the max cell Id for the field.
const string & fullName() const noexcept
The full field name.
label maxFaceId() const noexcept
The max face id for the field.
const string & units() const noexcept
The field units.
const word & name() const noexcept
The field name (PROSTAR short name).
label maxCellId() const noexcept
The max cell id for the field.
void maxFaceId(const int val)
Set the max face Id for the field.
fieldEntry(const word &shortName, const string &fullName, const char *units=nullptr)
Construct from components with optional units.
void units(const std::string &units)
Set the field units.
A list of the available fields.
label maxCellId() const
The maximum cell Id referenced in the list.
fieldTable()=default
Default construct.
label maxFaceId() const
The maximum face Id referenced in the list.
A linked-list that is searchable by the 'name()' of the items.
typename SLList< Type >::iterator iterator
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 list element by name.
namesList()=default
Default construct.
typename SLList< Type >::const_iterator const_iterator
bool found(const word &key) const
True if a list element has a name that matches key.
A ccm solution entry with name, iteration and time.
const word & name() const noexcept
The solution name.
label iteration() const noexcept
The solution iteration/timestep.
scalar timeValue() const noexcept
The solution time (sec).
solutionEntry(const word &name, const label iteration, const scalar timeValue=0)
Construct from components.
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
static bool match(const UList< wordRe > &selectors, const std::string &text, bool literal=false)
Test for a match of any selectors against the text.
Definition wordResI.H:47
A class for handling words, derived from Foam::string.
Definition word.H:66
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &os, const interfaceEntry &entry)
namesList< solutionEntry > solutionTable
Namespace for OpenFOAM.
LList< SLListBase, T > SLList
Definition SLListFwd.H:41
const direction noexcept
Definition scalarImpl.H:265
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50