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-2026 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  "functionEntries",
71  "execute functionEntries"
72  );
73 
75 
76  entry::disableFunctionEntries = !args.optionFound("functionEntries");
77 
78  label nProcs = 0;
79 
80  // Create the processor databases
81  PtrList<Time> databases(1);
82 
83  if (args.optionFound("processor"))
84  {
85  // Determine the processor count
86  nProcs = fileHandler().nProcs(args.path());
87 
88  if (!nProcs)
89  {
91  << "No processor* directories found"
92  << exit(FatalError);
93  }
94 
95  // Create the processor databases
96  databases.setSize(nProcs);
97 
98  forAll(databases, proci)
99  {
100  databases.set
101  (
102  proci,
103  new Time
104  (
106  args.rootPath(),
107  args.caseName()/fileName(word("processor") + name(proci))
108  )
109  );
110  }
111  }
112  else
113  {
114  databases.set
115  (
116  0,
117  new Time
118  (
120  args.rootPath(),
121  args.caseName()
122  )
123  );
124  }
125 
126  // Use the times list from the master processor
127  // and select a subset based on the command-line options
129  (
130  databases[0].times(),
131  args
132  );
133 
134  if (args.optionFound("rm"))
135  {
136  if (args.optionFound("processor"))
137  {
138  for (label proci=0; proci<nProcs; proci++)
139  {
140  const fileName procPath
141  (
142  args.path()/(word("processor") + name(proci))
143  );
144 
145  forAll(timeDirs, timeI)
146  {
147  const fileName procTimePath
148  (
149  fileHandler().filePath(procPath/timeDirs[timeI].name())
150  );
151 
152  if (isDir(procTimePath))
153  {
154  rmDir(procTimePath);
155  }
156  }
157  }
158  }
159  else
160  {
161  forAll(timeDirs, timeI)
162  {
163  const fileName procTimePath
164  (
165  fileHandler().filePath(args.path()/timeDirs[timeI].name())
166  );
167 
168  rmDir(procTimePath);
169  }
170  }
171  }
172  else
173  {
174  forAll(timeDirs, timeI)
175  {
176  Info<< timeDirs[timeI].name() << endl;
177  }
178  }
179 
180  return 0;
181 }
182 
183 
184 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
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:208
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:152
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:111
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:168
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:102
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:63
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
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:288
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
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
Foam::argList args(argc, argv)