Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::TimePaths
29
30Description
31 Address the time paths without using the Time class.
32
33SourceFiles
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
47namespace Foam
48{
49
50// Forward Declarations
51class argList;
53/*---------------------------------------------------------------------------*\
54 Class TimePaths Declaration
55\*---------------------------------------------------------------------------*/
56
57class 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
90public:
91
92 // Constructors
93
94 //- Construct from all components
96 (
97 const bool processorCase,
98 const fileName& rootPath,
99 const bool distributed,
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()
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
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
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
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.
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.
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// ************************************************************************* //
Layout
The layout of the case structure.
instantList times() const
Search the case for valid time directories.
Definition TimePaths.C:230
const word & system() const noexcept
Return system name.
Definition TimePathsI.H:137
bool distributed() const noexcept
True if case running with parallel distributed directories (ie. not NFS mounted).
Definition TimePathsI.H:46
const fileName & rootPath() const noexcept
Return root path.
Definition TimePathsI.H:66
const word & constant() const noexcept
Return constant name.
Definition TimePathsI.H:131
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
static instantList findTimes(const fileName &directory, const word &constantDirName="constant")
Search a given directory for valid time directories.
Definition TimePaths.C:109
fileName caseConstant() const
Return the constant name for the case, which is ../constant() for parallel runs.
Definition TimePathsI.H:143
const fileName & globalCaseName() const noexcept
Return global case name.
Definition TimePathsI.H:72
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
fileName path() const
Return path for the case = rootPath/caseName.
Definition TimePathsI.H:102
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 caseSystem() const
Return the system name for the case, which is ../system() for parallel runs.
Definition TimePathsI.H:154
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 constantPath() const
Return constant path.
Definition TimePathsI.H:165
fileName systemPath() const
Return system path.
Definition TimePathsI.H:171
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
const fileName & caseName() const noexcept
Return case name.
Definition TimePathsI.H:78
fileName globalPath() const
Return global path for the case = rootPath/globalCaseName.
Definition TimePathsI.H:108
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
Extract command arguments and options from the supplied argc and argv parameters.
Definition argList.H:119
A class for handling file names.
Definition fileName.H:75
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
Definition instant.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
Namespace for OpenFOAM.
List< instant > instantList
List of instants.
Definition instantList.H:41
Foam::argList args(argc, argv)