All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2020 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  );
73 
74  #include "setRootCase.H"
75 
76  label nProcs = 0;
77 
78  // Create the processor databases
79  PtrList<Time> databases(1);
80 
81  if (args.optionFound("processor"))
82  {
83  // Determine the processor count directly
84  while (isDir(args.path()/(word("processor") + name(nProcs))))
85  {
86  ++nProcs;
87  }
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  fileName procPath
142  (
143  args.path()/(word("processor") + name(proci))
144  );
145 
146  forAll(timeDirs, timeI)
147  {
148  rmDir(procPath/timeDirs[timeI].name());
149  }
150  }
151  }
152  else
153  {
154  forAll(timeDirs, timeI)
155  {
156  rmDir(args.path()/timeDirs[timeI].name());
157  }
158  }
159  }
160  else
161  {
162  forAll(timeDirs, timeI)
163  {
164  Info<< timeDirs[timeI].name() << endl;
165  }
166  }
167 
168  return 0;
169 }
170 
171 
172 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
A class for handling file names.
Definition: fileName.H:79
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
bool writeInfoHeader
const fileName & rootPath() const
Return root path.
Definition: argListI.H:42
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
static int disableFunctionEntries
Definition: entry.H:86
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
Definition: POSIX.C:539
A class for handling words, derived from string.
Definition: word.H:59
static word controlDictName
The default control dictionary name (normally "controlDict")
Definition: Time.H:197
instantList select(const instantList &) const
Select a list of Time values that are within the ranges.
Definition: timeSelector.C:100
bool rmDir(const fileName &)
Remove a directory and its contents.
Definition: POSIX.C:1051
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:48
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
fileName path() const
Return the path to the caseName.
Definition: argListI.H:66
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
messageStream Info
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:159
Foam::argList args(argc, argv)
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
Namespace for OpenFOAM.