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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12 
13 Description
14  Gets single or multiple region names based on command-line options:
15  (-allRegions | -regions | -regions)
16 
17 Priority
18  1. -allRegions
19  2. -regions = specify multiple regions to select, or a single region
20  3. -region = specify a single region
21 
22 Note
23  There is no semantical difference between "-regions name"
24  and "-region name"
25 
26 Required Variables
27  - args [argList]
28  - runTime [Time]
29 
30 Provides Variables
31  - regionNames [wordList]
32 
33 See Also
34  addAllRegionOptions.H
35 
36 \*---------------------------------------------------------------------------*/
37 
39 {
40  wordRes selectByName;
41 
42  if (args.found("allRegions"))
43  {
44  regionNames =
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  {
72  regionNames =
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  {
86  InfoErr
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 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::argList::readListIfPresent
bool readListIfPresent(const word &optName, List< T > &list) const
Definition: argListI.H:394
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::InfoErr
messageStream InfoErr
Information stream (stderr output on master, null elsewhere)
Foam::argList::get
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
regionNames
wordList regionNames
Definition: getAllRegionOptions.H:37
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:216
Foam::nl
constexpr char nl
Definition: Ostream.H:404
args
Foam::argList args(argc, argv)
Foam::argList::found
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178