foamListTimes.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  foamListTimes
26 
27 Description
28  List times using timeSelector.
29 
30 Usage
31  \b foamListTimes [OPTION]
32 
33  Options:
34  - \par -rm
35  Remove selected time directories
36 
37  - \par -processor
38  List times from processor0/ directory
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #include "argList.H"
43 #include "timeSelector.H"
44 #include "Time.H"
45 
46 using namespace Foam;
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 int main(int argc, char *argv[])
51 {
53  writeInfoHeader = false;
54 
55  argList::addNote("List times using timeSelector");
56  timeSelector::addOptions(true, true);
59  (
60  "processor",
61  "list times from processor0/ directory"
62  );
64  (
65  "rm",
66  "remove selected time directories"
67  );
69  (
70  "withFunctionObjects",
71  "execute functionObjects"
72  );
74  (
75  "withFunctionEntries",
76  "execute functionEntries"
77  );
78 
79  #include "setRootCase.H"
80 
81  entry::disableFunctionEntries = !args.optionFound("withFunctionEntries");
82 
83  label nProcs = 0;
84 
85  // Create the processor databases
86  PtrList<Time> databases(1);
87 
88  if (args.optionFound("processor"))
89  {
90  // Determine the processor count
91  nProcs = fileHandler().nProcs(args.path());
92 
93  if (!nProcs)
94  {
96  << "No processor* directories found"
97  << exit(FatalError);
98  }
99 
100  // Create the processor databases
101  databases.setSize(nProcs);
102 
103  forAll(databases, proci)
104  {
105  databases.set
106  (
107  proci,
108  new Time
109  (
111  args.rootPath(),
112  args.caseName()/fileName(word("processor") + name(proci))
113  )
114  );
115  }
116  }
117  else
118  {
119  databases.set
120  (
121  0,
122  new Time
123  (
125  args.rootPath(),
126  args.caseName()
127  )
128  );
129  }
130 
131  // Use the times list from the master processor
132  // and select a subset based on the command-line options
134  (
135  databases[0].times(),
136  args
137  );
138 
139  if (args.optionFound("rm"))
140  {
141  if (args.optionFound("processor"))
142  {
143  for (label proci=0; proci<nProcs; proci++)
144  {
145  const fileName procPath
146  (
147  args.path()/(word("processor") + name(proci))
148  );
149 
150  forAll(timeDirs, timeI)
151  {
152  const fileName procTimePath
153  (
154  fileHandler().filePath(procPath/timeDirs[timeI].name())
155  );
156 
157  if (isDir(procTimePath))
158  {
159  rmDir(procTimePath);
160  }
161  }
162  }
163  }
164  else
165  {
166  forAll(timeDirs, timeI)
167  {
168  const fileName procTimePath
169  (
170  fileHandler().filePath(args.path()/timeDirs[timeI].name())
171  );
172 
173  rmDir(procTimePath);
174  }
175  }
176  }
177  else
178  {
179  forAll(timeDirs, timeI)
180  {
181  Info<< timeDirs[timeI].name() << endl;
182  }
183  }
184 
185  return 0;
186 }
187 
188 
189 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
static word controlDictName
The default control dictionary name (normally "controlDict")
Definition: Time.H:204
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:48
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:159
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
static void noParallel()
Remove the parallel options.
Definition: argList.C:175
fileName path() const
Return the path to the caseName.
Definition: argListI.H:66
const fileName & rootPath() const
Return root path.
Definition: argListI.H:42
static int disableFunctionEntries
Definition: entry.H:86
A class for handling file names.
Definition: fileName.H:82
virtual label nProcs(const fileName &dir, const fileName &local="") const
Get number of processor directories/results. Used for e.g.
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
instantList select(const instantList &) const
Select a list of Time values that are within the ranges.
Definition: timeSelector.C:100
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
int main(int argc, char *argv[])
Definition: financialFoam.C:44
static instantList timeDirs
Definition: globalFoam.H:44
Namespace for OpenFOAM.
const fileOperation & fileHandler()
Get current file handler.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
bool writeInfoHeader
messageStream Info
bool rmDir(const fileName &)
Remove a directory and its contents.
Definition: POSIX.C:1047
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
Definition: POSIX.C:539
error FatalError
Foam::argList args(argc, argv)