foamListRegions.C
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) 2017-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Application
27  foamListRegions
28 
29 Group
30  grpPostProcessingUtilities
31 
32 Description
33  List regions from constant/regionProperties.
34 
35 Usage
36  \b foamListRegions [OPTION]
37 
38 Note
39  The OpenFOAM banner information is suppressed so that the output can be
40  piped into another command.
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #include "argList.H"
45 #include "Time.H"
46 #include "regionProperties.H"
47 
48 using namespace Foam;
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 int main(int argc, char *argv[])
53 {
55  (
56  "List regions from constant/regionProperties"
57  );
58 
62  argList::noFunctionObjects(); // Never use function objects
63  // No profiling since there is no time loop
64 
65  // Arguments are optional (non-mandatory)
67  argList::addArgument("regionType ... regionType");
68 
69  #include "setRootCase.H"
70 
71  // Silent version of "createTime.H", without libraries
73  (
75  args,
76  false, // no enableFunctionObjects
77  false // no enableLibs
78  );
79 
81 
82  // We now handle checking args and general sanity etc.
83  wordList regionTypes;
84 
85  if (args.size() > 1)
86  {
87  regionTypes.resize(args.size()-1);
88 
89  // No duplicates
90  wordHashSet uniq;
91 
92  label nTypes = 0;
93  for (label argi = 1; argi < args.size(); ++argi)
94  {
95  regionTypes[nTypes] = args[argi];
96 
97  const word& regType = regionTypes[nTypes];
98 
99  if (uniq.insert(regType))
100  {
101  if (rp.found(regType))
102  {
103  ++nTypes;
104  }
105  else
106  {
107  InfoErr<< "No region-type: " << regType << nl;
108  }
109  }
110  }
111 
112  regionTypes.resize(nTypes);
113  }
114  else
115  {
116  regionTypes = rp.sortedToc();
117  }
118 
119 
120  for (const word& regionType : regionTypes)
121  {
122  const wordList& regionNames = rp[regionType];
123 
124  for (const word& regionName : regionNames)
125  {
126  Info<< regionName << nl;
127  }
128  }
129 
130  return 0;
131 }
132 
133 
134 // ************************************************************************* //
static void noJobInfo()
Suppress JobInfo, overriding controlDict setting.
Definition: argList.C:534
static void noFunctionObjects(bool addWithOption=false)
Remove &#39;-noFunctionObjects&#39; option and ignore any occurrences.
Definition: argList.C:514
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:453
static void noMandatoryArgs()
Flag command arguments as being optional (non-mandatory)
Definition: argList.C:470
messageStream InfoErr
Information stream (stderr output on master, null elsewhere)
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:132
bool found(const Key &key) const
True if hashed key is found in table.
Definition: HashTableI.H:93
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
engineTime & runTime
static void noParallel()
Remove the parallel options.
Definition: argList.C:551
wordList regionNames
Simple class to hold region information for coupled region simulations.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:227
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Foam::word regionName(Foam::polyMesh::defaultRegion)
A class for handling words, derived from Foam::string.
Definition: word.H:63
regionProperties rp(runTime)
label size() const noexcept
The number of arguments.
Definition: argListI.H:139
static word controlDictName
The default control dictionary name (normally "controlDict")
Definition: Time.H:275
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:130
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:342
messageStream Info
Information stream (stdout output on master, null elsewhere)
static void noBanner()
Disable emitting the banner information.
Definition: argList.C:482
Foam::argList args(argc, argv)
Namespace for OpenFOAM.