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-2025 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 Foam_TimePaths_H
39 #define Foam_TimePaths_H
40 
41 #include "fileName.H"
42 #include "instantList.H"
43 #include "IOobjectOption.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward Declarations
51 class argList;
52 
53 /*---------------------------------------------------------------------------*\
54  Class TimePaths Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 class TimePaths
58 {
59  // Private Data
60 
61  //- True if this is a processor case
62  bool processorCase_;
63 
64  //- True running with distributed directories
65  bool distributed_;
66 
67  //- The root path
68  const fileName rootPath_;
69 
70  //- The global case name
71  fileName globalCaseName_;
72 
73  //- The local (processor) case name
74  fileName caseName_;
75 
76  //- The name for the "system" directory
77  const word system_;
78 
79  //- The name for the "constant" directory
80  const word constant_;
81 
82 
83  // Private Member Functions
84 
85  //- If not already designated as a processor-case, determine from
86  //- the globalCaseName whether it is a processor directory
87  //- and adjust both the globalCaseName and processor-case accordingly
88  bool detectProcessorCase();
89 
90 public:
91 
92  // Constructors
93 
94  //- Construct from all components
95  TimePaths
96  (
97  const bool processorCase,
98  const fileName& rootPath,
99  const bool distributed,
100  const fileName& globalCaseName,
101  const fileName& caseName,
102  const word& systemDirName = "system",
103  const word& constantDirName = "constant"
104  );
105 
106  //- Construct using characteristics given by the argList
107  explicit TimePaths
108  (
109  const argList& args,
110  const word& systemDirName = "system",
111  const word& constantDirName = "constant"
112  );
113 
114  //- Construct from rootPath and casePath
115  inline TimePaths
116  (
117  const fileName& rootPath,
118  const fileName& caseName,
119  const word& systemDirName = "system",
120  const word& constantDirName = "constant"
121  );
122 
123 
124  // Member Functions
125 
126  //- True if case running with parallel distributed directories
127  //- (ie. not NFS mounted)
128  inline bool distributed() const noexcept;
129 
130  //- True if this is a processor case
131  inline bool processorCase() const noexcept;
132 
133  //- Set processor case status. Return old status
134  inline bool processorCase(bool on) noexcept;
135 
136  //- Return root path
137  inline const fileName& rootPath() const noexcept;
138 
139  //- Return global case name
140  inline const fileName& globalCaseName() const noexcept;
141 
142  //- Return case name
143  inline const fileName& caseName() const noexcept;
144 
145  //- The case name for modification (use with caution)
146  inline fileName& caseName() noexcept;
147 
148  //- Return caseName() or globalCaseName()
149  inline const fileName& caseName(IOobjectOption::Layout) const noexcept;
150 
151  //- Return path for the case = rootPath/caseName
152  inline fileName path() const;
153 
154  //- Return global path for the case = rootPath/globalCaseName
155  inline fileName globalPath() const;
156 
157  //- Return path() or globalPath()
158  inline fileName path(IOobjectOption::Layout) const;
159 
160  //- Return the input relative to the globalPath by stripping off
161  //- a leading value of the globalPath
162  //
163  // \param input the directory or filename to make case-relative
164  // \param caseTag replace globalPath with <case> for later
165  // use with expand(), or prefix <case> if the file name was
166  // not an absolute location
167  inline fileName relativePath
168  (
169  const fileName& input,
170  const bool caseTag = false
171  ) const;
172 
173 
174  //- Return constant name
175  inline const word& constant() const noexcept;
176 
177  //- Return system name
178  inline const word& system() const noexcept;
179 
180  //- Return the constant name for the case, which is
181  //- \c ../constant() for parallel runs.
182  inline fileName caseConstant() const;
183 
184  //- Return the system name for the case, which is
185  //- \c ../system() for parallel runs.
186  inline fileName caseSystem() const;
187 
188  //- Return constant path
189  inline fileName constantPath() const;
190 
191  //- Return system path
192  inline fileName systemPath() const;
193 
194 
195  // Searching (Static Methods)
196 
197  //- Search a given directory for valid time directories
198  // \note forwards to the current fileHandler
199  static instantList findTimes
200  (
201  const fileName& directory,
202  const word& constantDirName = "constant"
203  );
204 
205  //- Search instant list for the time index closest to the specified time
206  // \returns -1 if nothing close is found
207  static label findClosestTimeIndex
208  (
209  const UList<instant>& timeDirs,
210  const scalar t,
211  const word& constantDirName = "constant"
212  );
213 
214  //- Search instant list for the instant closest to the specified time
215  static instant findClosestTime
216  (
217  const UList<instant>& timeDirs,
218  const scalar t,
219  const word& constantDirName = "constant"
220  );
221 
222  //- Search instantList for matching time value,
223  //- return the instance name or word::null if nothing is equal.
224  static word findInstancePath
225  (
226  const UList<instant>& timeDirs,
227  const instant& t
228  );
229 
230  //- Search the given directory for matching time value,
231  //- return the instance name or word::null if nothing is equal.
232  static word findInstancePath
233  (
234  const fileName& directory,
235  const instant& t,
236  const word& constantDirName = "constant"
237  );
238 
239 
240  // Searching
241 
242  //- Search the case for valid time directories
243  // \note forwards to the current fileHandler
244  instantList times() const;
245 
246  //- Search local or global locations for valid time directories
247  // \note forwards to the current fileHandler
249 
250  //- Search the case for the time closest to the given time
251  // \note forwards to the current fileHandler
252  instant findClosestTime(const scalar t) const;
253 
254  //- Search local or global locations for the time closest to
255  //- the given time
256  // \note forwards to the current fileHandler
257  instant findClosestTime(IOobjectOption::Layout, const scalar t) const;
258 
259  //- Search the case for the time directory path
260  //- corresponding to the given instance
261  // \note forwards to the current fileHandler
262  word findInstancePath(const instant& t) const;
263 
264  //- Search local or global locations for the time directory path
265  //- corresponding to the given instance
266  // \note forwards to the current fileHandler
268 };
269 
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 } // End namespace Foam
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 #include "TimePathsI.H"
278 
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 
281 #endif
282 
283 // ************************************************************************* //
fileName constantPath() const
Return constant path.
Definition: TimePathsI.H:165
Address the time paths without using the Time class.
Definition: TimePaths.H:52
A class for handling file names.
Definition: fileName.H:72
static instant findClosestTime(const UList< instant > &timeDirs, const scalar t, const word &constantDirName="constant")
Search instant list for the instant closest to the specified time.
Definition: TimePaths.C:147
fileName relativePath(const fileName &input, const bool caseTag=false) const
Return the input relative to the globalPath by stripping off a leading value of the globalPath...
Definition: TimePathsI.H:122
fileName systemPath() const
Return system path.
Definition: TimePathsI.H:171
static label findClosestTimeIndex(const UList< instant > &timeDirs, const scalar t, const word &constantDirName="constant")
Search instant list for the time index closest to the specified time.
Definition: TimePaths.C:119
bool processorCase() const noexcept
True if this is a processor case.
Definition: TimePathsI.H:52
fileName caseSystem() const
Return the system name for the case, which is ../system() for parallel runs.
Definition: TimePathsI.H:154
A class for handling words, derived from Foam::string.
Definition: word.H:63
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:118
const word & system() const noexcept
Return system name.
Definition: TimePathsI.H:137
static word findInstancePath(const UList< instant > &timeDirs, const instant &t)
Search instantList for matching time value, return the instance name or word::null if nothing is equa...
Definition: TimePaths.C:192
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
const direction noexcept
Definition: scalarImpl.H:265
fileName caseConstant() const
Return the constant name for the case, which is ../constant() for parallel runs.
Definition: TimePathsI.H:143
bool distributed() const noexcept
True if case running with parallel distributed directories (ie. not NFS mounted)
Definition: TimePathsI.H:46
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:131
static instantList findTimes(const fileName &directory, const word &constantDirName="constant")
Search a given directory for valid time directories.
Definition: TimePaths.C:109
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
Definition: instant.H:53
const fileName & rootPath() const noexcept
Return root path.
Definition: TimePathsI.H:66
instantList times() const
Search the case for valid time directories.
Definition: TimePaths.C:230
const fileName & globalCaseName() const noexcept
Return global case name.
Definition: TimePathsI.H:72
TimePaths(const bool processorCase, const fileName &rootPath, const bool distributed, const fileName &globalCaseName, const fileName &caseName, const word &systemDirName="system", const word &constantDirName="constant")
Construct from all components.
Definition: TimePaths.C:62
Layout
The layout of the case structure.
fileName path() const
Return path for the case = rootPath/caseName.
Definition: TimePathsI.H:102
Foam::argList args(argc, argv)
const fileName & caseName() const noexcept
Return case name.
Definition: TimePathsI.H:78
Namespace for OpenFOAM.
fileName globalPath() const
Return global path for the case = rootPath/globalCaseName.
Definition: TimePathsI.H:108