Loading...
Searching...
No Matches
foamListRegions.C
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) 2017-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
26Application
27 foamListRegions
28
29Group
30 grpPostProcessingUtilities
31
32Description
33 List volume regions from constant/regionProperties
34 or area regions from constant/finite-area/regionProperties
35
36Usage
37 \b foamListRegions [OPTION]
38
39Note
40 The OpenFOAM banner information is suppressed so that the output can be
41 piped into another command.
42
43\*---------------------------------------------------------------------------*/
44
45#include "argList.H"
46#include "Time.H"
47#include "regionProperties.H"
48
49// Same as faMesh::prefix() but without additional linkage
50constexpr const char* const faMeshPrefix = "finite-area";
51
52using namespace Foam;
53
54// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55
56int main(int argc, char *argv[])
57{
59 (
60 "List volume regions from constant/regionProperties,\n"
61 "or area regions from constant/finite-area/regionProperties"
62 );
63
67 argList::noFunctionObjects(); // Never use function objects
68 // No profiling since there is no time loop
69
71 (
72 "finite-area",
73 "List constant/finite-area/regionProperties (if available)"
74 );
75
77 (
78 "optional",
79 "A missing regionProperties is not treated as an error"
80 );
81
83 (
84 "Make reading optional and add verbosity"
85 );
86 argList::addVerboseOption("Additional verbosity");
87
88 // Arguments are optional (non-mandatory)
90 argList::addArgument("regionType ... regionType");
91
92 #include "setRootCase.H"
93
94 const bool dryRun = args.dryRun();
95 int optVerbose = args.verbose();
96
97 if (dryRun && !optVerbose)
98 {
99 ++optVerbose;
100 }
101
102 // File is optional, not an error
103 const bool isOptional = args.found("optional");
104
105 // Use finite-area regions
106 const bool doFiniteArea = args.found("finite-area");
107
108 // The number of optional region filters to apply
109 const label nFilters = (args.size()-1);
110
112
113 if (dryRun || isOptional || doFiniteArea)
114 {
115 // The finite-area regionProperties are also considered optional
117 }
118
119 // Silent version of "createTime.H", without libraries
121 (
123 args,
124 false, // no enableFunctionObjects
125 false // no enableLibs
126 );
127
128 regionProperties regionProps;
129 if (doFiniteArea)
130 {
131 regionProps = regionProperties(runTime, faMeshPrefix, readOpt);
132 }
133 else
134 {
135 regionProps = regionProperties(runTime, readOpt);
136 }
137
138 // Some reporting...
139 if (regionProps.empty())
140 {
141 if (doFiniteArea)
142 {
143 InfoErr<< "No finite-area region types" << nl;
144 }
145 else if (isOptional)
146 {
147 InfoErr<< "No region types" << nl;
148 }
149 }
150 else if (optVerbose)
151 {
152 InfoErr << "Have " << regionProps.size();
153
154 if (doFiniteArea)
155 {
156 InfoErr<< " finite-area";
157 }
158 InfoErr
159 << " region types, "
160 << regionProps.count() << " regions" << nl << nl;
161 }
162
163
164 // We now handle checking args and general sanity etc.
165
166 DynamicList<word> regionTypes;
167
168 if (isOptional && regionProps.empty())
169 {
170 // Nothing to do...
171 }
172 else if (nFilters > 0)
173 {
174 // Apply region filters
175
176 regionTypes.reserve_exact
177 (
178 Foam::min(nFilters, regionProps.size())
179 );
180
181 // No duplicates, and no duplicate warnings
182 wordHashSet uniq;
183
184 for (label argi = 1; argi < args.size(); ++argi)
185 {
186 word regType(args[argi]);
187
188 if (uniq.insert(regType))
189 {
190 if (regionProps.contains(regType))
191 {
192 if (!regionTypes.contains(regType))
193 {
194 regionTypes.push_back(std::move(regType));
195 }
196 }
197 else
198 {
199 InfoErr<< "No region-type: " << regType << nl;
200 }
201 }
202 }
203 }
204 else
205 {
206 // Take all regions
207 regionTypes = regionProps.sortedToc();
208 }
209
210
211 for (const word& regionType : regionTypes)
212 {
213 if (const auto iter = regionProps.cfind(regionType); iter.good())
214 {
215 for (const word& regionName : iter.val())
216 {
217 Info<< regionName << nl;
218 }
219 }
220 }
221
222 return 0;
223}
224
225
226// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
void reserve_exact(const label len)
Reserve allocation space for at least this size, allocating new space if required and retaining old c...
void push_back(const T &val)
Copy append an element to the end of this list.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition HashSet.H:229
Foam::List< Key > sortedToc(const Compare &comp) const
Definition HashTable.C:168
bool empty() const noexcept
True if the hash table is empty.
Definition HashTable.H:353
bool contains(const Key &key) const
True if hashed key is contained (found) in table.
Definition HashTableI.H:72
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
Definition HashTableI.H:113
label size() const noexcept
The number of elements in table.
Definition HashTable.H:358
readOption
Enumeration defining read preferences.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ MUST_READ
Reading required.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
static word controlDictName
The default control dictionary name (normally "controlDict").
Definition Time.H:267
bool contains(const T &val) const
True if the value is contained in the list.
Definition UListI.H:302
static void noBanner()
Disable emitting the banner information.
Definition argList.C:506
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition argList.C:562
static void addVerboseOption(const string &usage="", bool advanced=false)
Enable a 'verbose' bool option, with usage information.
Definition argList.C:535
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
static void noJobInfo()
Suppress JobInfo, overriding controlDict setting.
Definition argList.C:582
static void addDryRunOption(const string &usage, bool advanced=false)
Enable a 'dry-run' bool option, with usage information.
Definition argList.C:519
static void noMandatoryArgs()
Flag command arguments as being optional (non-mandatory).
Definition argList.C:494
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition argList.C:389
static void noParallel()
Remove the parallel options.
Definition argList.C:599
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
Simple class to hold region information for coupled region simulations.
label count() const
Total count of all region names.
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
Namespace for OpenFOAM.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition HashSet.H:80
messageStream Info
Information stream (stdout output on master, null elsewhere).
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
messageStream InfoErr
Information stream (stderr output on master, null elsewhere).
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)