surfaceFormatsCore.C
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-2012 OpenFOAM Foundation
9 Copyright (C) 2017-2020 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
27\*---------------------------------------------------------------------------*/
28
29#include "surfaceFormatsCore.H"
30#include "Time.H"
31#include "ListOps.H"
32#include "surfMesh.H"
33#include "stringListOps.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
38
39
40// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
41
43(
44 ISstream& is,
45 const char comment
46)
47{
49 do
50 {
51 is.getLine(line);
52 }
53 while ((line.empty() || line[0] == comment) && is.good());
54
55 return line;
56}
57
58
60(
61 const surfZoneList& patches,
62 const wordRes& allow,
63 const wordRes& deny
64)
65{
66 return
68 (
69 patches,
70 allow,
71 deny,
73 );
74}
75
76
77#if 0
78Foam::fileName Foam::fileFormats::surfaceFormatsCore::localMeshFileName
79(
80 const word& surfName
81)
82{
83 const word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
84
85 return fileName
86 (
88 / name + "." + nativeExt
89 );
90}
91
92
93Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshInstance
94(
95 const Time& t,
96 const word& surfName
97)
98{
99 fileName localName = localMeshFileName(surfName);
100
101 // Search back through the time directories list to find the time
102 // closest to and lower than current time
103
104 instantList ts = t.times();
105 label instanceI;
106
107 for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
108 {
109 if (ts[instanceI].value() <= t.timeOutputValue())
110 {
111 break;
112 }
113 }
114
115 // Noting that the current directory has already been searched
116 // for mesh data, start searching from the previously stored time directory
117
118 if (instanceI >= 0)
119 {
120 for (label i = instanceI; i >= 0; --i)
121 {
122 if (isFile(t.path()/ts[i].name()/localName))
123 {
124 return ts[i].name();
125 }
126 }
127 }
128
129 return t.constant();
130}
131
132
133Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshFile
134(
135 const Time& t,
136 const word& surfName
137)
138{
139 fileName localName = localMeshFileName(surfName);
140
141 // Search back through the time directories list to find the time
142 // closest to and lower than current time
143
144 instantList ts = t.times();
145 label instanceI;
146
147 for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
148 {
149 if (ts[instanceI].value() <= t.timeOutputValue())
150 {
151 break;
152 }
153 }
154
155 // Noting that the current directory has already been searched
156 // for mesh data, start searching from the previously stored time directory
157
158 if (instanceI >= 0)
159 {
160 for (label i = instanceI; i >= 0; --i)
161 {
162 fileName testName(t.path()/ts[i].name()/localName);
163
164 if (isFile(testName))
165 {
166 return testName;
167 }
168 }
169 }
170
171 // fallback to "constant"
172 return t.path()/t.constant()/localName;
173}
174#endif
175
176
178(
179 const IOobject& io,
180 const fileName& f,
181 const bool isGlobal
182)
183{
184 fileName fName(f);
185 fName.expand();
186 if (!fName.isAbsolute())
187 {
188 // Is the specified file:
189 // - local to the cwd?
190 // - local to the case dir?
191 // - or just another name?
192 fName = fileHandler().filePath
193 (
194 isGlobal,
195 IOobject(io, fName),
197 );
198 }
199 return fName;
200}
201
202
204(
205 const IOobject& io,
206 const bool isGlobal
207)
208{
209 fileName fName
210 (
211 isGlobal
212 ? io.globalFilePath(word::null)
213 : io.localFilePath(word::null)
214 );
215
216 if (!exists(fName))
217 {
218 fName.clear();
219 }
220
221 return fName;
222}
223
224
226(
227 const IOobject& io,
228 const dictionary& dict,
229 const bool isGlobal
230)
231{
232 fileName fName;
233 if (dict.readIfPresent("file", fName, keyType::LITERAL))
234 {
235 fName = relativeFilePath(io, fName, isGlobal);
236 }
237 else
238 {
239 fName =
240 (
241 isGlobal
242 ? io.globalFilePath(word::null)
243 : io.localFilePath(word::null)
244 );
245 }
246
247 if (!exists(fName))
248 {
249 fName.clear();
250 }
251
252 return fName;
253}
254
255
257(
258 const IOobject& io,
259 const bool isGlobal
260)
261{
262 fileName fName
263 (
264 isGlobal
265 ? io.globalFilePath(word::null)
266 : io.localFilePath(word::null)
267 );
268
269 if (fName.empty())
270 {
272 << "Cannot find surface starting from "
273 << io.objectPath() << nl
274 << exit(FatalError);
275 }
276
277 return fName;
278}
279
280
282(
283 const IOobject& io,
284 const dictionary& dict,
285 const bool isGlobal
286)
287{
288 fileName fName;
289 if (dict.readIfPresent("file", fName, keyType::LITERAL))
290 {
291 const fileName rawFName(fName);
292
293 fName = relativeFilePath(io, rawFName, isGlobal);
294
295 if (!exists(fName))
296 {
298 << "Cannot find surface " << rawFName
299 << " starting from " << io.objectPath() << nl
300 << exit(FatalError);
301 }
302 }
303 else
304 {
305 fName =
306 (
307 isGlobal
308 ? io.globalFilePath(word::null)
309 : io.localFilePath(word::null)
310 );
311
312 if (!exists(fName))
313 {
315 << "Cannot find surface starting from "
316 << io.objectPath() << nl
317 << exit(FatalError);
318 }
319 }
320
321 return fName;
322}
323
324
326(
327 const wordHashSet& available,
328 const word& fileType,
329 const bool verbose,
330 const char* functionName
331)
332{
333 if (available.found(fileType))
334 {
335 return true;
336 }
337 else if (verbose)
338 {
339 Info<< "Unknown file type";
340
341 if (functionName)
342 {
343 Info<< " for " << functionName;
344 }
345
346 Info<< " : " << fileType << nl
347 << "Valid types: " << flatOutput(available.sortedToc()) << nl
348 << nl;
349 }
350
351 return false;
352}
353
354
355// ************************************************************************* //
Various functions to operate on Lists.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:137
bool found(const Key &key) const
Return true if hashed entry is found in table.
Definition: HashTableI.H:100
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:58
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
Definition: ISstreamI.H:76
instantList times() const
Search the case for valid time directories.
Definition: TimePaths.C:149
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
scalar timeOutputValue() const
Return current time value.
Definition: TimeStateI.H:31
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
fileName path() const
Return path.
Definition: Time.H:358
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool checkSupport() const
Check if the patch is fully supported.
static labelList getSelectedPatches(const surfZoneList &patches, const wordRes &allow, const wordRes &deny=wordRes())
Return ids for zone/patch that match by name.
static fileName checkFile(const IOobject &io, const bool isGlobal=true)
Return fileName to load IOobject from.
static fileName findFile(const IOobject &io, const bool isGlobal=true)
static string getLineNoComment(ISstream &is, const char comment='#')
Read non-empty and non-comment line.
static fileName relativeFilePath(const IOobject &io, const fileName &f, const bool isGlobal=true)
Return fileName.
static word nativeExt
The file extension corresponding to 'native' surface format.
A class for handling file names.
Definition: fileName.H:76
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
Definition: fileNameI.H:199
static bool isAbsolute(const std::string &str)
Definition: fileNameI.H:136
virtual fileName filePath(const bool checkGlobal, const IOobject &, const word &typeName, const bool search=true) const =0
Search for an object. checkGlobal : also check undecomposed case.
@ LITERAL
String literal.
Definition: keyType.H:81
A line primitive.
Definition: line.H:68
A class for handling character strings derived from std::string.
Definition: string.H:79
string & expand(const bool allowEmpty=false)
Definition: string.C:173
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh")
Definition: surfMesh.H:153
static const word prefix
The prefix to local: surfaces.
static word defaultName
The default surface name: default.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
const polyBoundaryMesh & patches
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
labelList findMatching(const StringListType &input, const wordRes::filter &pred, AccessOp aop=identityOp())
Return ids for items with matching names.
const fileOperation & fileHandler()
Get current file handler.
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: MSwindows.C:633
messageStream Info
Information stream (stdout output on master, null elsewhere)
List< instant > instantList
List of instants.
Definition: instantList.H:47
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
Definition: MSwindows.C:666
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
labelList f(nPoints)
dictionary dict
Operations on lists of strings.
Extract name (as a word) from an object, typically using its name() method.
Definition: word.H:238