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-2024 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  Foam::argList::removeOption("noFunctionObjects");
74 
75  #include "setRootCase.H"
76 
77  entry::disableFunctionEntries = !args.optionFound("functionEntries");
78 
79  label nProcs = 0;
80 
81  // Create the processor databases
82  PtrList<Time> databases(1);
83 
84  if (args.optionFound("processor"))
85  {
86  // Determine the processor count
87  nProcs = fileHandler().nProcs(args.path());
88 
89  if (!nProcs)
90  {
92  << "No processor* directories found"
93  << exit(FatalError);
94  }
95 
96  // Create the processor databases
97  databases.setSize(nProcs);
98 
99  forAll(databases, proci)
100  {
101  databases.set
102  (
103  proci,
104  new Time
105  (
107  args.rootPath(),
108  args.caseName()/fileName(word("processor") + name(proci))
109  )
110  );
111  }
112  }
113  else
114  {
115  databases.set
116  (
117  0,
118  new Time
119  (
121  args.rootPath(),
122  args.caseName()
123  )
124  );
125  }
126 
127  // Use the times list from the master processor
128  // and select a subset based on the command-line options
130  (
131  databases[0].times(),
132  args
133  );
134 
135  if (args.optionFound("rm"))
136  {
137  if (args.optionFound("processor"))
138  {
139  for (label proci=0; proci<nProcs; proci++)
140  {
141  const fileName procPath
142  (
143  args.path()/(word("processor") + name(proci))
144  );
145 
146  forAll(timeDirs, timeI)
147  {
148  const fileName procTimePath
149  (
150  fileHandler().filePath(procPath/timeDirs[timeI].name())
151  );
152 
153  if (isDir(procTimePath))
154  {
155  rmDir(procTimePath);
156  }
157  }
158  }
159  }
160  else
161  {
162  forAll(timeDirs, timeI)
163  {
164  const fileName procTimePath
165  (
166  fileHandler().filePath(args.path()/timeDirs[timeI].name())
167  );
168 
169  rmDir(procTimePath);
170  }
171  }
172  }
173  else
174  {
175  forAll(timeDirs, timeI)
176  {
177  Info<< timeDirs[timeI].name() << endl;
178  }
179  }
180 
181  return 0;
182 }
183 
184 
185 // ************************************************************************* //
#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: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: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 void removeOption(const word &opt)
Remove option from validOptions and from optionUsage.
Definition: argList.C:168
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: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:257
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)