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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
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
78 Foam::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 
93 Foam::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 
133 Foam::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),
196  word::null
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
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
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
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
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 // ************************************************************************* //
Foam::TimeState::timeOutputValue
scalar timeOutputValue() const
Return current time value.
Definition: TimeStateI.H:31
Foam::fileFormats::surfaceFormatsCore::checkFile
static fileName checkFile(const IOobject &io, const bool isGlobal=true)
Return fileName to load IOobject from.
Definition: surfaceFormatsCore.C:257
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::exists
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:625
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::IOobject::localFilePath
fileName localFilePath(const word &typeName, const bool search=true) const
Helper for filePath that searches locally.
Definition: IOobject.C:569
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::ISstream::getLine
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
Definition: ISstreamI.H:76
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::fileFormats::surfaceFormatsCore::nativeExt
static word nativeExt
The file extension corresponding to 'native' surface format.
Definition: surfaceFormatsCore.H:140
Foam::fileOperation::filePath
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.
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
Foam::PtrListOps::findMatching
labelList findMatching(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Extract list indices for all items with 'name()' that matches.
Foam::isFile
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:658
Foam::fileHandler
const fileOperation & fileHandler()
Get current file handler.
Definition: fileOperation.C:1485
Foam::fileFormats::surfaceFormatsCore::getSelectedPatches
static labelList getSelectedPatches(const surfZoneList &patches, const wordRes &allow, const wordRes &deny=wordRes())
Return ids for zone/patch that match by name.
Definition: surfaceFormatsCore.C:60
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:76
Foam::HashSet< word, Hash< word > >
Foam::instantList
List< instant > instantList
List of instants.
Definition: instantList.H:44
Foam::surfMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh")
Definition: surfMesh.H:153
Foam::IOstream::good
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
Foam::fileFormats::surfaceFormatsCore::checkSupport
static bool checkSupport(const wordHashSet &available, const word &fileType, const bool verbose=false, const char *functionName=nullptr)
Verbose checking of fileType in the list of available types.
Definition: surfaceFormatsCore.C:326
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::fileFormats::surfaceFormatsCore::getLineNoComment
static string getLineNoComment(ISstream &is, const char comment='#')
Read non-empty and non-comment line.
Definition: surfaceFormatsCore.C:43
Foam::TimePaths::times
instantList times() const
Search the case for valid time directories.
Definition: TimePaths.C:149
Foam::nameOp
Extract name (as a word) from an object, typically using its name() method.
Definition: word.H:237
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::IOobject::globalFilePath
fileName globalFilePath(const word &typeName, const bool search=true) const
Helper for filePath that searches up if in parallel.
Definition: IOobject.C:580
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
surfMesh.H
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:216
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:358
f
labelList f(nPoints)
Foam::List< label >
Foam::surfaceRegistry::defaultName
static word defaultName
The default surface name: default.
Definition: surfaceRegistry.H:74
Foam::fileFormats::surfaceFormatsCore::relativeFilePath
static fileName relativeFilePath(const IOobject &io, const fileName &f, const bool isGlobal=true)
Return fileName.
Definition: surfaceFormatsCore.C:178
Foam::string::expand
string & expand(const bool allowEmpty=false)
Definition: string.C:173
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::line
A line primitive.
Definition: line.H:53
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fileFormats::surfaceFormatsCore::findFile
static fileName findFile(const IOobject &io, const bool isGlobal=true)
Definition: surfaceFormatsCore.C:204
stringListOps.H
Operations on lists of strings.
ListOps.H
Various functions to operate on Lists.
Foam::surfaceRegistry::prefix
static const word prefix
The prefix to local: surfaces.
Definition: surfaceRegistry.H:71
Foam::keyType::LITERAL
String literal.
Definition: keyType.H:81
Foam::IOobject::objectPath
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:214
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
surfaceFormatsCore.H
Foam::fileName::isAbsolute
static bool isAbsolute(const std::string &str)
Definition: fileNameI.H:136