Loading...
Searching...
No Matches
getAllRegionOptions.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) 2021-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12
13Description
14 Gets single or multiple region names based on command-line options:
15 (-all-regions | -regions | -regions)
16
17Priority
18 1. -all-regions (-allRegions)
19 2. -regions = specify multiple regions to select, or a single region
20 3. -region = specify a single region
21
22Note
23 There is no semantical difference between "-regions name"
24 and "-region name".
25 If regionProperties is missing (or empty) and the "-regions"
26 option is supplied with literal names, these will be used directly
27 instead of being used to filter the regionProperties.
28
29Required Classes
30 - Foam::polyMesh
31 - Foam::regionProperties
32 - Foam::IOobjectOption
34Required Variables
35 - args [argList]
36 - runTime [Time]
37
38Provides Variables
39 - regionNames [wordList]
41See Also
42 addAllRegionOptions.H
43
44\*---------------------------------------------------------------------------*/
45
46wordList regionNames;
47{
48 // Exit or fallback if nothing matches
49 constexpr bool exitOnNoMatches = true;
50
51 // Local aliases
52 auto& names = regionNames;
54
55 if
56 (
57 // Handle both here (independent of which is an alias)
58 args.found("all-regions")
59 || args.found("allRegions")
60 )
61 {
62 names =
63 (
65 (
66 runTime,
67 IOobjectOption::READ_IF_PRESENT
68 ).names()
69 );
71 if (names.empty())
72 {
73 InfoErr
74 << "Warning: No regionProperties, "
75 "assume default region" << nl << endl;
76 }
77 else
78 {
79 Info<< "Using all regions: "
80 << flatOutput(names) << nl;
81 }
82 }
83 else if
84 (
85 wordRes select;
86 args.readListIfPresent<wordRe>("regions", select)
87 )
88 {
89 select.uniq(); // Normally a no-op
90
91 if (select.size() == 1 && select[0].isLiteral())
92 {
93 // Identical to -region NAME
94 names.resize(1);
95 names[0] = select[0];
96 }
97 else if (select.size())
98 {
99 names =
100 (
102 (
103 runTime,
104 IOobjectOption::READ_IF_PRESENT
105 ).names()
106 );
107
108 if (!names.empty())
109 {
110 // Filter the region names
111 const auto indices = select.matching(names);
112
113 if (indices.empty())
114 {
115 InfoErr
116 << "No match in regions: "
117 << flatOutput(names) << nl;
118
119 if constexpr (exitOnNoMatches)
120 {
121 InfoErr<< "... stopping" << nl << endl;
122 return 1;
123 }
124 else
125 {
126 InfoErr
127 << "... ignoring and using default region"
128 << nl << endl;
129
130 names.resize(1);
131 names[0] = fallback;
132 }
133 }
134 else
135 {
136 names = wordList(names, indices);
137 Info<< "Using regions: "
138 << flatOutput(names) << nl;
139 }
140 }
141 else
142 {
143 // No information from regionProperties:
144 // - use literal names from select
145
146 names.resize(select.size());
147
148 label nGood(0);
149 for (const auto& val : select)
150 {
151 if (val.isLiteral())
152 {
153 names[nGood++] = val;
154 }
155 }
156 if (nGood)
157 {
158 names.resize(nGood);
159
160 InfoErr
161 << "Warning: No regionProperties, "
162 "using specified regions" << nl;
163
164 Info<< "Using regions: "
165 << flatOutput(names) << nl;
167 else
168 {
169 names.resize(1);
171
172 InfoErr
173 << "Warning: No regionProperties, "
174 "assume default region" << nl << endl;
175 }
176 }
177 }
178 }
179 else
180 {
181 // Single region option or fallback
182 names.resize(1);
183 auto& name = names[0];
184
185 if
186 (
187 !args.readIfPresent("region", name)
188 )
189 {
190 name = fallback;
191 }
192 }
193
194 // Final sanity checks and/or fallback
195 if (names.empty())
196 {
197 names.resize(1);
198 names[0] = fallback;
199 }
200 else if (names.size() == 1 && names[0].empty())
201 {
202 names[0] = fallback;
203 }
204}
205
206
207// ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
static word defaultRegion
Return the default region name.
Definition polyMesh.H:406
Simple class to hold region information for coupled region simulations.
wordList names() const
The region names (sorted by region type).
engineTime & runTime
auto & name
const auto & fallback
auto & names
wordList regionNames
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
Definition BitOps.C:139
List< word > wordList
List of word.
Definition fileName.H:60
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
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)