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 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 (-allRegions | -regions | -regions)
16
17Priority
18 1. -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
26Required Variables
27 - args [argList]
28 - runTime [Time]
29
30Provides Variables
31 - regionNames [wordList]
32
33See Also
34 addAllRegionOptions.H
35
36\*---------------------------------------------------------------------------*/
38wordList regionNames;
39{
40 wordRes selectByName;
42 if (args.found("allRegions"))
43 {
45 regionProperties(runTime, IOobject::READ_IF_PRESENT).names();
46
47 if (regionNames.empty())
48 {
49 InfoErr
50 << "Warning: No regionProperties, assume default region"
51 << nl << endl;
52 }
53 else
54 {
55 Info<< "Using all regions: " << flatOutput(regionNames) << nl;
56 }
57 }
58 else if (args.readListIfPresent<wordRe>("regions", selectByName))
59 {
60 if
61 (
62 selectByName.size() == 1
63 && selectByName.first().isLiteral()
64 )
65 {
66 // Identical to -region NAME
67 regionNames.resize(1);
68 regionNames.first() = selectByName.first();
69 }
70 else if (selectByName.size())
71 {
73 regionProperties(runTime, IOobject::READ_IF_PRESENT).names();
74
75 if (regionNames.empty())
76 {
77 Info<< "Warning: No regionProperties, assume default region"
78 << nl << endl;
79 }
80 else
81 {
82 const labelList matching = selectByName.matching(regionNames);
83
84 if (matching.empty())
85 {
87 << "No match in regions: "
89 << "... stopping" << nl << endl;
90 return 1;
91 }
92
93 regionNames = wordList(regionNames, matching);
94
95 Info<< "Using regions: " << flatOutput(regionNames) << nl;
96 }
97 }
98 }
99 else if (args.found("region"))
100 {
101 regionNames.resize(1);
102 regionNames.first() = args.get<word>("region");
103 }
104
105 // Fallback to defaultRegion
106 if (regionNames.empty())
107 {
108 regionNames.resize(1);
109 regionNames.first() = polyMesh::defaultRegion;
110 }
111}
112
113
114// ************************************************************************* //
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
bool readListIfPresent(const word &optName, List< T > &list) const
Definition: argListI.H:394
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
engineTime & runTime
wordList regionNames
List< word > wordList
A List of words.
Definition: fileName.H:63
List< label > labelList
A List of labels.
Definition: List.H:66
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
messageStream InfoErr
Information stream (stderr output on master, null elsewhere)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Foam::argList args(argc, argv)