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-2023 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 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward Declarations
50 class argList;
51 
52 /*---------------------------------------------------------------------------*\
53  Class TimePaths Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class TimePaths
57 {
58  // Private Data
59 
60  bool processorCase_;
61  bool distributed_;
62 
63  const fileName rootPath_;
64  fileName globalCaseName_;
65  fileName case_;
66  const word system_;
67  const word constant_;
68 
69 
70  // Private Member Functions
71 
72  //- If not already designated as a processor-case, determine from
73  //- the globalCaseName whether it is a processor directory
74  //- and adjust both the globalCaseName and processor-case accordingly
75  bool detectProcessorCase();
76 
77 public:
78 
79  // Constructors
80 
81  //- Construct from all components
82  TimePaths
83  (
84  const bool processorCase,
85  const fileName& rootPath,
86  const bool distributed,
87  const fileName& globalCaseName,
88  const fileName& caseName,
89  const word& systemDirName = "system",
90  const word& constantDirName = "constant"
91  );
92 
93  //- Construct using characteristics given by the argList
94  explicit TimePaths
95  (
96  const argList& args,
97  const word& systemDirName = "system",
98  const word& constantDirName = "constant"
99  );
100 
101  //- Construct from rootPath and casePath
102  inline TimePaths
103  (
104  const fileName& rootPath,
105  const fileName& caseName,
106  const word& systemDirName = "system",
107  const word& constantDirName = "constant"
108  );
109 
110 
111  // Member Functions
112 
113  //- True if case running with parallel distributed directories
114  //- (ie. not NFS mounted)
115  inline bool distributed() const noexcept;
116 
117  //- True if this is a processor case
118  inline bool processorCase() const noexcept;
119 
120  //- Set processor case status. Return old status
121  inline bool processorCase(bool on) noexcept;
122 
123  //- Return root path
124  inline const fileName& rootPath() const noexcept;
125 
126  //- Return global case name
127  inline const fileName& globalCaseName() const noexcept;
128 
129  //- Return case name
130  inline const fileName& caseName() const noexcept;
131 
132  //- The case name for modification (use with caution)
133  inline fileName& caseName() noexcept;
134 
135  //- Return path for the case = rootPath/caseName
136  inline fileName path() const;
137 
138  //- Return global path for the case = rootPath/globalCaseName
139  inline fileName globalPath() const;
140 
141  //- Return the input relative to the globalPath by stripping off
142  //- a leading value of the globalPath
143  //
144  // \param input the directory or filename to make case-relative
145  // \param caseTag replace globalPath with <case> for later
146  // use with expand(), or prefix <case> if the file name was
147  // not an absolute location
148  inline fileName relativePath
149  (
150  const fileName& input,
151  const bool caseTag = false
152  ) const;
153 
154 
155  //- Return constant name
156  inline const word& constant() const noexcept;
157 
158  //- Return system name
159  inline const word& system() const noexcept;
160 
161  //- Return the constant name for the case, which is
162  //- \c ../constant() for parallel runs.
163  inline fileName caseConstant() const;
164 
165  //- Return the system name for the case, which is
166  //- \c ../system() for parallel runs.
167  inline fileName caseSystem() const;
168 
169  //- Return constant path
170  inline fileName constantPath() const;
171 
172  //- Return system path
173  inline fileName systemPath() const;
174 
175 
176  // Searching
177 
178  //- Search a given directory for valid time directories
179  // Forwards to the current fileHandler
180  static instantList findTimes
181  (
182  const fileName& directory,
183  const word& constantDirName = "constant"
184  );
185 
186  //- Search instantList for the time index closest to the specified time
187  static label findClosestTimeIndex
188  (
189  const UList<instant>& timeDirs,
190  const scalar t,
191  const word& constantDirName = "constant"
192  );
193 
194  //- Search instantList for matching time value,
195  //- return the instance name or word::null if nothing is equal.
196  static word findInstancePath
197  (
198  const UList<instant>& timeDirs,
199  const instant& t
200  );
201 
202  //- Search the case for valid time directories
203  instantList times() const;
204 
205  //- Search the case for the time closest to the given time
206  instant findClosestTime(const scalar t) const;
207 
208  //- Search the case for the time directory path
209  //- corresponding to the given instance
210  word findInstancePath(const instant& t) const;
211 };
212 
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 } // End namespace Foam
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 #include "TimePathsI.H"
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 #endif
225 
226 // ************************************************************************* //
fileName constantPath() const
Return constant path.
Definition: TimePathsI.H:146
Address the time paths without using the Time class.
Definition: TimePaths.H:51
A class for handling file names.
Definition: fileName.H:72
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:103
fileName systemPath() const
Return system path.
Definition: TimePathsI.H:152
static label findClosestTimeIndex(const UList< instant > &timeDirs, const scalar t, const word &constantDirName="constant")
Search instantList for the time index closest to the specified time.
Definition: TimePaths.C:176
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:135
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
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:33
const word & system() const noexcept
Return system name.
Definition: TimePathsI.H:118
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:125
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: Scalar.H:258
fileName caseConstant() const
Return the constant name for the case, which is ../constant() for parallel runs.
Definition: TimePathsI.H:124
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:112
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:118
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
fileName path() const
Return path for the case = rootPath/caseName.
Definition: TimePathsI.H:90
instant findClosestTime(const scalar t) const
Search the case for the time closest to the given time.
Definition: TimePaths.C:203
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:96