Loading...
Searching...
No Matches
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-2024 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" // For stringListOps::findMatching()
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 = (ts.size()-1);
106
107 for (; instanceI >= 0; --instanceI)
108 {
109 if (ts[instanceI] <= 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 for (label i = instanceI; i >= 0; --i)
119 {
120 if (isFile(t.path()/ts[i].name()/localName))
121 {
122 return ts[i].name();
123 }
124 }
125
126 return t.constant();
127}
128
129
130Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshFile
131(
132 const Time& t,
133 const word& surfName
134)
135{
136 fileName localName = localMeshFileName(surfName);
137
138 // Search back through the time directories list to find the time
139 // closest to and lower than current time
140
141 instantList ts = t.times();
142 label instanceI = (ts.size()-1);
143
144 for (; instanceI >= 0; --instanceI)
145 {
146 if (ts[instanceI] <= t.timeOutputValue())
147 {
148 break;
149 }
150 }
151
152 // Noting that the current directory has already been searched
153 // for mesh data, start searching from the previously stored time directory
154
155 for (label i = instanceI; i >= 0; --i)
156 {
157 fileName testName(t.path()/ts[i].name()/localName);
158
159 if (isFile(testName))
160 {
161 return testName;
162 }
163 }
165 // fallback to "constant"
166 return t.path()/t.constant()/localName;
167}
168#endif
169
170
172(
173 const IOobject& io,
174 const fileName& f,
175 const bool isGlobal
176)
177{
178 fileName fName(f);
179 fName.expand();
180 if (!fName.isAbsolute())
181 {
182 // Is the specified file:
183 // - local to the cwd?
184 // - local to the case dir?
185 // - or just another name?
186 fName = fileHandler().filePath
187 (
188 isGlobal,
189 IOobject(io, fName),
191 );
192 }
193 return fName;
194}
195
196
198(
199 const IOobject& io,
200 const bool isGlobal
201)
202{
203 fileName fName
204 (
205 isGlobal
206 ? io.globalFilePath(word::null)
207 : io.localFilePath(word::null)
208 );
209
210 if (!exists(fName))
211 {
212 fName.clear();
213 }
214
215 return fName;
216}
217
218
220(
221 const IOobject& io,
222 const dictionary& dict,
223 const bool isGlobal
224)
225{
226 fileName fName;
227 if (dict.readIfPresent("file", fName, keyType::LITERAL))
228 {
229 fName = relativeFilePath(io, fName, isGlobal);
230 }
231 else
232 {
233 fName =
234 (
235 isGlobal
236 ? io.globalFilePath(word::null)
237 : io.localFilePath(word::null)
238 );
239 }
240
241 if (!exists(fName))
242 {
243 fName.clear();
244 }
245
246 return fName;
247}
248
249
251(
252 const IOobject& io,
253 const bool isGlobal
254)
255{
256 fileName fName
257 (
258 isGlobal
259 ? io.globalFilePath(word::null)
260 : io.localFilePath(word::null)
261 );
262
263 if (fName.empty())
264 {
266 << "Cannot find surface starting from "
267 << io.objectPath() << nl
269 }
270
271 return fName;
272}
273
274
276(
277 const IOobject& io,
278 const dictionary& dict,
279 const bool isGlobal
280)
281{
282 fileName fName;
283 if (dict.readIfPresent("file", fName, keyType::LITERAL))
284 {
285 const fileName rawFName(fName);
286
287 fName = relativeFilePath(io, rawFName, isGlobal);
288
289 if (!exists(fName))
290 {
292 << "Cannot find surface " << rawFName
293 << " starting from " << io.objectPath() << nl
294 << exit(FatalError);
295 }
296 }
297 else
298 {
299 fName =
300 (
301 isGlobal
302 ? io.globalFilePath(word::null)
303 : io.localFilePath(word::null)
304 );
305
306 if (!exists(fName))
307 {
309 << "Cannot find surface starting from "
310 << io.objectPath() << nl
311 << exit(FatalError);
313 }
314
315 return fName;
316}
317
318
320(
321 const wordHashSet& available,
322 const word& fileType,
323 const bool verbose,
324 const char* functionName
325)
326{
327 if (available.found(fileType))
328 {
329 return true;
330 }
331 else if (verbose)
332 {
333 Info<< "Unknown file type";
334
335 if (functionName)
336 {
337 Info<< " for " << functionName;
338 }
339
340 Info<< " : " << fileType << nl
341 << "Valid types: " << flatOutput(available.sortedToc()) << nl
342 << nl;
343 }
344
345 return false;
346}
347
348
349// ************************************************************************* //
Various functions to operate on Lists.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition HashTable.C:156
bool found(const Key &key) const
Same as contains().
Definition HashTable.H:1370
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
bool good() const noexcept
True if next operation might succeed.
Definition IOstream.H:281
Generic input stream using a standard (STL) stream.
Definition ISstream.H:54
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
Definition ISstreamI.H:69
instantList times() const
Search the case for valid time directories.
Definition TimePaths.C:230
const word & constant() const noexcept
Return constant name.
Definition TimePathsI.H:131
scalar timeOutputValue() const
Return the current user-time value. (ie, after applying any timeToUserTime() conversion).
Definition TimeStateI.H:24
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
fileName path() const
The path for the case = rootPath/caseName.
Definition TimePathsI.H:102
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
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)
Use IOobject information to resolve file to load from, or empty if the file does not exist.
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.
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.
A class for handling file names.
Definition fileName.H:75
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
Definition fileNameI.H:192
static bool isAbsolute(const std::string &str)
Return true if filename starts with a '/' or '\' or (windows-only) with a filesystem-root.
Definition fileNameI.H:129
@ LITERAL
String literal.
Definition keyType.H:82
A line primitive.
Definition line.H:180
A class for handling character strings derived from std::string.
Definition string.H:76
string & expand(const bool allowEmpty=false)
Inplace expand initial tags, tildes, and all occurrences of environment variables as per stringOps::e...
Definition string.C:166
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh").
Definition surfMesh.H:171
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:56
A class for handling words, derived from Foam::string.
Definition word.H:66
static const word null
An empty word.
Definition word.H:84
const polyBoundaryMesh & patches
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
const auto & io
auto & name
labelList findMatching(const StringListType &input, const wordRes::filter &pred, AccessOp aop=identityOp())
Return ids for items with matching names.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition HashSet.H:80
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 POSIX.C:837
List< label > labelList
A List of labels.
Definition List.H:62
List< surfZone > surfZoneList
List of surfZone.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< instant > instantList
List of instants.
Definition instantList.H:41
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
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 POSIX.C:879
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
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:341