foamListTimes.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 | Copyright (C) 2011-2016 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 {
52  argList::addNote("List times using timeSelector");
53 
54  timeSelector::addOptions(true, true);
58  (
59  "processor",
60  "list times from processor0/ directory"
61  );
63  (
64  "rm",
65  "remove selected time directories"
66  );
67  #include "setRootCase.H"
68 
69  label nProcs = 0;
70 
71  // Create the processor databases
72  PtrList<Time> databases(1);
73 
74  if (args.optionFound("processor"))
75  {
76  // Determine the processor count directly
77  while (isDir(args.path()/(word("processor") + name(nProcs))))
78  {
79  ++nProcs;
80  }
81 
82  if (!nProcs)
83  {
85  << "No processor* directories found"
86  << exit(FatalError);
87  }
88 
89  // Create the processor databases
90  databases.setSize(nProcs);
91 
92  forAll(databases, proci)
93  {
94  databases.set
95  (
96  proci,
97  new Time
98  (
100  args.rootPath(),
101  args.caseName()/fileName(word("processor") + name(proci))
102  )
103  );
104  }
105  }
106  else
107  {
108  databases.set
109  (
110  0,
111  new Time
112  (
114  args.rootPath(),
115  args.caseName()
116  )
117  );
118  }
119 
120  // Use the times list from the master processor
121  // and select a subset based on the command-line options
123  (
124  databases[0].times(),
125  args
126  );
127 
128  if (args.optionFound("rm"))
129  {
130  if (args.optionFound("processor"))
131  {
132  for (label proci=0; proci<nProcs; proci++)
133  {
134  fileName procPath
135  (
136  args.path()/(word("processor") + name(proci))
137  );
138 
139  forAll(timeDirs, timeI)
140  {
141  rmDir(procPath/timeDirs[timeI].name());
142  }
143  }
144  }
145  else
146  {
147  forAll(timeDirs, timeI)
148  {
149  rmDir(args.path()/timeDirs[timeI].name());
150  }
151  }
152  }
153  else
154  {
155  forAll(timeDirs, timeI)
156  {
157  Info<< timeDirs[timeI].name() << endl;
158  }
159  }
160 
161  return 0;
162 }
163 
164 
165 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:69
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static void noParallel()
Remove the parallel options.
Definition: argList.C:146
instantList select(const instantList &) const
Select a list of Time values that are within the ranges.
Definition: timeSelector.C:100
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:486
const fileName & rootPath() const
Return root path.
Definition: argListI.H:36
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
fileName path() const
Return the path to the caseName.
Definition: argListI.H:60
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:42
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
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:201
bool rmDir(const fileName &)
Remove a dirctory and its contents.
Definition: POSIX.C:839
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:62
messageStream Info
static void noBanner()
Disable emitting the banner information.
Definition: argList.C:140
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:83
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:124
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.