TimePaths.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2014 OpenFOAM Foundation
9  Copyright (C) 2016-2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::TimePaths
29 
30 Description
31  Address the time paths without using the Time class.
32 
33 SourceFiles
34  TimePaths.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef TimePaths_H
39 #define TimePaths_H
40 
41 #include "fileName.H"
42 #include "instantList.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward Declarations
50 class argList;
51 
52 /*---------------------------------------------------------------------------*\
53  Class TimePaths Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 
57 class TimePaths
58 {
59  // Private Data
60 
61  bool processorCase_;
62  bool distributed_;
63 
64  const fileName rootPath_;
65  fileName globalCaseName_;
66  fileName case_;
67  const word system_;
68  const word constant_;
69 
70 
71  // Private Member Functions
72 
73  //- Determine from case name whether it is a processor directory
74  bool detectProcessorCase();
75 
76 
77 public:
78 
79  // Constructors
80 
81  //- Construct using characteristics given by the argList
82  explicit TimePaths
83  (
84  const argList& args,
85  const word& systemName = "system",
86  const word& constantName = "constant"
87  );
88 
89  //- Construct given database name, rootPath and casePath
90  TimePaths
91  (
92  const fileName& rootPath,
93  const fileName& caseName,
94  const word& systemName = "system",
95  const word& constantName = "constant"
96  );
97 
98 
99  //- Construct given database name, rootPath and casePath
100  TimePaths
101  (
102  const bool processorCase,
103  const fileName& rootPath,
104  const bool distributed,
105  const fileName& globalCaseName,
106  const fileName& caseName,
107  const word& systemName = "system",
108  const word& constantName = "constant"
109  );
110 
111 
112  // Member Functions
113 
114  //- True if case running with parallel distributed directories
115  //- (ie. not NFS mounted)
116  inline bool distributed() const;
117 
118  //- Return true if this is a processor case
119  inline bool processorCase() const;
120 
121  //- Return root path
122  inline const fileName& rootPath() const;
123 
124  //- Return global case name
125  inline const fileName& globalCaseName() const;
126 
127  //- Return case name
128  inline const fileName& caseName() const;
129 
130  //- The case name for modification (use with caution)
131  inline fileName& caseName();
132 
133  //- Return path for the case
134  inline fileName path() const;
135 
136  //- Return global path for the case
137  inline fileName globalPath() const;
138 
139  //- Return the input relative to the globalPath by stripping off
140  //- a leading value of the globalPath
141  //
142  // \param input the directory or filename to make case-relative
143  // \param caseTag replace globalPath with <case> for later
144  // use with expand(), or prefix <case> if the file name was
145  // not an absolute location
146  inline fileName relativePath
147  (
148  const fileName& input,
149  const bool caseTag = false
150  ) const;
151 
152 
153  //- Return constant name
154  inline const word& constant() const;
155 
156  //- Return system name
157  inline const word& system() const;
158 
159  //- Return the constant name for the case, which is
160  //- \c ../constant() for parallel runs.
161  inline fileName caseConstant() const;
162 
163  //- Return the system name for the case, which is
164  //- \c ../system() for parallel runs.
165  inline fileName caseSystem() const;
166 
167  //- Return constant path
168  inline fileName constantPath() const;
169 
170  //- Return system path
171  inline fileName systemPath() const;
172 
173 
174  // Searching
175 
176  //- Search a given directory for valid time directories
177  // Forwards to the current fileHandler
178  static instantList findTimes
179  (
180  const fileName& directory,
181  const word& constantName = "constant"
182  );
183 
184  //- Search instantList for the time index closest to the specified time
185  static label findClosestTimeIndex
186  (
187  const instantList& timeDirs,
188  const scalar t,
189  const word& constantName = "constant"
190  );
191 
192  //- Search the case for valid time directories
193  instantList times() const;
194 
195  //- Search the case for the time closest to the given time
196  instant findClosestTime(const scalar t) const;
197 
198 };
199 
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 } // End namespace Foam
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 #include "TimePathsI.H"
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 #endif
212 
213 // ************************************************************************* //
Foam::TimePaths::findTimes
static instantList findTimes(const fileName &directory, const word &constantName="constant")
Search a given directory for valid time directories.
Definition: TimePaths.C:140
Foam::TimePaths::rootPath
const fileName & rootPath() const
Return root path.
Definition: TimePathsI.H:42
Foam::TimePaths::findClosestTimeIndex
static label findClosestTimeIndex(const instantList &timeDirs, const scalar t, const word &constantName="constant")
Search instantList for the time index closest to the specified time.
Definition: TimePaths.C:156
instantList.H
Foam::TimePaths::globalCaseName
const fileName & globalCaseName() const
Return global case name.
Definition: TimePathsI.H:48
Foam::TimePaths::path
fileName path() const
Return path for the case.
Definition: TimePathsI.H:66
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::TimePaths::systemPath
fileName systemPath() const
Return system path.
Definition: TimePathsI.H:128
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::TimePaths::TimePaths
TimePaths(const argList &args, const word &systemName="system", const word &constantName="constant")
Construct using characteristics given by the argList.
Definition: TimePaths.C:69
Foam::TimePaths::caseSystem
fileName caseSystem() const
Definition: TimePathsI.H:111
Foam::TimePaths::caseName
const fileName & caseName() const
Return case name.
Definition: TimePathsI.H:54
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:123
Foam::TimePaths::constantPath
fileName constantPath() const
Return constant path.
Definition: TimePathsI.H:122
Foam::TimePaths::distributed
bool distributed() const
Definition: TimePathsI.H:30
Foam::TimePaths::relativePath
fileName relativePath(const fileName &input, const bool caseTag=false) const
Definition: TimePathsI.H:79
Foam::TimePaths::times
instantList times() const
Search the case for valid time directories.
Definition: TimePaths.C:149
fileName.H
Foam::TimePaths::findClosestTime
instant findClosestTime(const scalar t) const
Search the case for the time closest to the given time.
Definition: TimePaths.C:183
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::TimePaths
Address the time paths without using the Time class.
Definition: TimePaths.H:56
TimePathsI.H
Foam::TimePaths::system
const word & system() const
Return system name.
Definition: TimePathsI.H:94
Foam::List< instant >
Foam::TimePaths::caseConstant
fileName caseConstant() const
Definition: TimePathsI.H:100
Foam::TimePaths::globalPath
fileName globalPath() const
Return global path for the case.
Definition: TimePathsI.H:72
Foam::instant
An instant of time. Contains the time value and name.
Definition: instant.H:52
Foam::TimePaths::processorCase
bool processorCase() const
Return true if this is a processor case.
Definition: TimePathsI.H:36
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
args
Foam::argList args(argc, argv)