Loading...
Searching...
No Matches
getAllFaRegionOptions.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) 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 area region names based on command-line options:
15 (-all-area-regions | -area-regions | -area-region)
16
17Priority
18 1. -all-area-regions (-allAreas)
19 2. -area-regions = specify multiple area regions to select,
20 or a single area region
21 3. -area-region = specify a single area region
22
23Note
24 There is no semantical difference between "-area-regions name"
25 and "-area-region name".
26 If regionProperties is missing (or empty) and the "-area-regions"
27 option is supplied with literal names, these will be used directly
28 instead of being used to filter the regionProperties.
29
30Required Classes
31 - Foam::polyMesh
32 - Foam::regionProperties
33 - Foam::IOobjectOption
34
35Required Variables
36 - args [argList]
37 - runTime [Time]
38
39Provides Variables
40 - areaRegionNames [wordList]
41
42See Also
43 addAllFaRegionOptions.H
44
45\*---------------------------------------------------------------------------*/
46
47wordList areaRegionNames;
48{
49 // Exit or fallback if nothing matches
50 constexpr bool exitOnNoMatches = false;
51
52 // Local aliases
53 auto& names = areaRegionNames;
55
56 if
57 (
58 // Handle both here (independent of which is an alias)
59 args.found("all-area-regions")
60 || args.found("allAreas")
61 )
62 {
63 names =
64 (
66 (
67 runTime,
68 "finite-area", // ie, faMesh::prefix()
69 IOobjectOption::READ_IF_PRESENT
70 ).names()
71 );
72
73 if (names.empty())
74 {
75 InfoErr
76 << "Warning: No finite-area regionProperties, "
77 "assume default region" << nl << endl;
78 }
79 else
80 {
81 Info<< "Using all area-regions: "
82 << flatOutput(names) << nl;
83 }
84 }
85 else if
86 (
87 wordRes select;
88 (
89 // Handle both here (independent of which is an alias)
90 args.readListIfPresent<wordRe>("area-regions", select)
91 || args.readListIfPresent<wordRe>("areaRegions", select)
92 )
93 )
94 {
95 select.uniq(); // Normally a no-op
96
97 if (select.size() == 1 && select[0].isLiteral())
98 {
99 // Identical to -area-region NAME
100 names.resize(1);
101 names[0] = select[0];
102 }
103 else if (select.size())
104 {
105 names =
106 (
108 (
109 runTime,
110 "finite-area", // ie, faMesh::prefix()
111 IOobjectOption::READ_IF_PRESENT
112 ).names()
113 );
114
115 if (!names.empty())
116 {
117 // Filter the region names
118 const auto indices = select.matching(names);
119
120 if (indices.empty())
121 {
122 InfoErr
123 << "No match in regions: "
124 << flatOutput(names) << nl;
125
126 if constexpr (exitOnNoMatches)
127 {
128 InfoErr<< "... stopping" << nl << endl;
129 return 1;
130 }
131 else
132 {
133 InfoErr
134 << "... ignoring and using default region"
135 << nl << endl;
136
137 names.resize(1);
138 names[0] = fallback;
139 }
140 }
141 else
142 {
143 names = wordList(names, indices);
144 Info<< "Using area-regions: "
145 << flatOutput(names) << nl;
146 }
147 }
148 else
149 {
150 // No information from regionProperties:
151 // - use literal names from select
152
153 names.resize(select.size());
154
155 label nGood(0);
156 for (const auto& val : select)
157 {
158 if (val.isLiteral())
159 {
160 names[nGood++] = val;
161 }
162 }
163 if (nGood)
164 {
165 names.resize(nGood);
166 InfoErr
167 << "Warning: No finite-area regionProperties, "
168 "using specified regions" << nl;
169
170 Info<< "Using area-regions: "
171 << flatOutput(names) << nl;
172 }
173 else
174 {
175 names.resize(1);
176 names[0] = fallback;
178 InfoErr
179 << "Warning: No finite-area regionProperties, "
180 "assume default region" << nl << endl;
181 }
182 }
183 }
184 }
185 else
186 {
187 // Single region option or fallback
188 names.resize(1);
189 auto& name = names[0];
190
191 if
192 (
193 // Handle both here (independent of which is an alias)
194 !args.readIfPresent("area-region", name)
195 && !args.readIfPresent("areaRegion", name)
196 )
197 {
198 name = fallback;
199 }
200 }
201
202 // Final sanity checks and/or fallback
203 if (names.empty())
204 {
205 names.resize(1);
206 names[0] = fallback;
207 }
208 else if (names.size() == 1 && names[0].empty())
209 {
210 names[0] = fallback;
211 }
212}
213
214
215// ************************************************************************* //
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 areaRegionNames
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)