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-2023 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 Classes
27  - Foam::polyMesh
28  - Foam::regionProperties
29  - Foam::IOobjectOption
30 
31 Required Variables
32  - args [argList]
33  - runTime [Time]
34 
35 Provides Variables
36  - regionNames [wordList]
37 
38 See Also
39  addAllRegionOptions.H
40 
41 \*---------------------------------------------------------------------------*/
42 
44 {
45  wordRes selectByName;
46 
47  if (args.found("allRegions"))
48  {
49  regionNames =
50  (
51  Foam::regionProperties(runTime, IOobjectOption::READ_IF_PRESENT)
52  .names()
53  );
54 
55  if (regionNames.empty())
56  {
57  InfoErr
58  << "Warning: No regionProperties, assume default region"
59  << nl << endl;
60  }
61  else
62  {
63  Info<< "Using all regions: " << flatOutput(regionNames) << nl;
64  }
65  }
66  else if (args.readListIfPresent<wordRe>("regions", selectByName))
67  {
68  if
69  (
70  selectByName.size() == 1
71  && selectByName.front().isLiteral()
72  )
73  {
74  // Identical to -region NAME
75  regionNames.resize(1);
76  regionNames.front() = selectByName.front();
77  }
78  else if (selectByName.size())
79  {
80  regionNames =
81  (
82  Foam::regionProperties(runTime, IOobjectOption::READ_IF_PRESENT)
83  .names()
84  );
85 
86  if (regionNames.empty())
87  {
88  Info<< "Warning: No regionProperties, assume default region"
89  << nl << endl;
90  }
91  else
92  {
93  const labelList matching = selectByName.matching(regionNames);
94 
95  if (matching.empty())
96  {
97  InfoErr
98  << "No match in regions: "
100  << "... stopping" << nl << endl;
101  return 1;
102  }
103 
104  regionNames = wordList(regionNames, matching);
105 
106  Info<< "Using regions: " << flatOutput(regionNames) << nl;
107  }
108  }
109  }
110  else if (args.found("region"))
111  {
112  regionNames.resize(1);
113  regionNames.front() = args.get<word>("region");
114  }
115 
116  // Fallback to defaultRegion
117  if (regionNames.empty())
118  {
119  regionNames.resize(1);
121  }
122 }
123 
124 
125 // ************************************************************************* //
messageStream InfoErr
Information stream (stderr output on master, null elsewhere)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
wordList regionNames
Simple class to hold region information for coupled region simulations.
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:405
bool readListIfPresent(const word &optName, List< T > &list) const
If named option is present, get a List of values treating a single entry like a list of size 1...
Definition: argListI.H:387
List< word > wordList
List of word.
Definition: fileName.H:59
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
messageStream Info
Information stream (stdout output on master, null elsewhere)
List< label > labelList
A List of labels.
Definition: List.H:62
Foam::argList args(argc, argv)
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225
wordList names() const
The region names. Sorted by region type.