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 
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  //- If not already designated as a processor-case, determine from
74  //- the globalCaseName whether it is a processor directory
75  //- and adjust both the globalCaseName and processor-case accordingly
76  bool detectProcessorCase();
77 
78 public:
79 
80  // Constructors
81 
82  //- Construct from all components
83  TimePaths
84  (
85  const bool processorCase,
86  const fileName& rootPath,
87  const bool distributed,
88  const fileName& globalCaseName,
89  const fileName& caseName,
90  const word& systemDirName = "system",
91  const word& constantDirName = "constant"
92  );
93 
94  //- Construct using characteristics given by the argList
95  explicit TimePaths
96  (
97  const argList& args,
98  const word& systemDirName = "system",
99  const word& constantDirName = "constant"
100  );
101 
102  //- Construct from rootPath and casePath
103  inline TimePaths
104  (
105  const fileName& rootPath,
106  const fileName& caseName,
107  const word& systemDirName = "system",
108  const word& constantDirName = "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 noexcept;
117 
118  //- True if this is a processor case
119  inline bool processorCase() const noexcept;
120 
121  //- Set processor case status. Return old status
122  inline bool processorCase(bool on) noexcept;
123 
124  //- Return root path
125  inline const fileName& rootPath() const noexcept;
126 
127  //- Return global case name
128  inline const fileName& globalCaseName() const noexcept;
129 
130  //- Return case name
131  inline const fileName& caseName() const noexcept;
132 
133  //- The case name for modification (use with caution)
134  inline fileName& caseName() noexcept;
135 
136  //- Return path for the case = rootPath/caseName
137  inline fileName path() const;
138 
139  //- Return global path for the case = rootPath/globalCaseName
140  inline fileName globalPath() const;
141 
142  //- Return the input relative to the globalPath by stripping off
143  //- a leading value of the globalPath
144  //
145  // \param input the directory or filename to make case-relative
146  // \param caseTag replace globalPath with <case> for later
147  // use with expand(), or prefix <case> if the file name was
148  // not an absolute location
149  inline fileName relativePath
150  (
151  const fileName& input,
152  const bool caseTag = false
153  ) const;
154 
155 
156  //- Return constant name
157  inline const word& constant() const noexcept;
158 
159  //- Return system name
160  inline const word& system() const noexcept;
161 
162  //- Return the constant name for the case, which is
163  //- \c ../constant() for parallel runs.
164  inline fileName caseConstant() const;
165 
166  //- Return the system name for the case, which is
167  //- \c ../system() for parallel runs.
168  inline fileName caseSystem() const;
169 
170  //- Return constant path
171  inline fileName constantPath() const;
172 
173  //- Return system path
174  inline fileName systemPath() const;
175 
176 
177  // Searching
178 
179  //- Search a given directory for valid time directories
180  // Forwards to the current fileHandler
181  static instantList findTimes
182  (
183  const fileName& directory,
184  const word& constantDirName = "constant"
185  );
186 
187  //- Search instantList for the time index closest to the specified time
188  static label findClosestTimeIndex
189  (
190  const instantList& timeDirs,
191  const scalar t,
192  const word& constantDirName = "constant"
193  );
194 
195  //- Search the case for valid time directories
196  instantList times() const;
197 
198  //- Search the case for the time closest to the given time
199  instant findClosestTime(const scalar t) const;
200 };
201 
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 } // End namespace Foam
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 #include "TimePathsI.H"
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 #endif
214 
215 // ************************************************************************* //
fileName constantPath() const
Return constant path.
Definition: TimePathsI.H:146
Address the time paths without using the Time class.
Definition: TimePaths.H:52
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
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 label findClosestTimeIndex(const instantList &timeDirs, const scalar t, const word &constantDirName="constant")
Search instantList for the time index closest to the specified time.
Definition: TimePaths.C:125
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:152
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