edgeMeshFormatsCore.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-2017 OpenFOAM Foundation
9 Copyright (C) 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 "edgeMeshFormatsCore.H"
30#include "Time.H"
31#include "ListOps.H"
32#include "edgeMesh.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
37
38
39// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
40
42(
43 ISstream& is,
44 const char comment
45)
46{
47 string line;
48 do
49 {
50 is.getLine(line);
51 }
52 while ((line.empty() || line[0] == comment) && is.good());
53
54 return line;
55}
56
57
58#if 0
59Foam::fileName Foam::fileFormats::edgeMeshFormatsCore::localMeshFileName
60(
61 const word& meshName
62)
63{
64 const word name(meshName.size() ? meshName : surfaceRegistry::defaultName);
65
66 return fileName
67 (
69 / name + "." + nativeExt
70 );
71}
72
73
74Foam::fileName Foam::fileFormats::edgeMeshFormatsCore::findMeshInstance
75(
76 const Time& t,
77 const word& meshName
78)
79{
80 fileName localName = localMeshFileName(meshName);
81
82 // Search back through the time directories list to find the time
83 // closest to and lower than current time
84
85 instantList ts = t.times();
86 label instanceI;
87
88 for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
89 {
90 if (ts[instanceI].value() <= t.timeOutputValue())
91 {
92 break;
93 }
94 }
95
96 // Noting that the current directory has already been searched
97 // for mesh data, start searching from the previously stored time directory
98
99 if (instanceI >= 0)
100 {
101 for (label i = instanceI; i >= 0; --i)
102 {
103 if (isFile(t.path()/ts[i].name()/localName))
104 {
105 return ts[i].name();
106 }
107 }
108 }
109
110 return t.constant();
111}
112
113
114Foam::fileName Foam::fileFormats::edgeMeshFormatsCore::findMeshFile
115(
116 const Time& t,
117 const word& meshName
118)
119{
120 fileName localName = localMeshFileName(meshName);
121
122 // Search back through the time directories list to find the time
123 // closest to and lower than current time
124
125 instantList ts = t.times();
126 label instanceI;
127
128 for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
129 {
130 if (ts[instanceI].value() <= t.timeOutputValue())
131 {
132 break;
133 }
134 }
135
136 // Noting that the current directory has already been searched
137 // for mesh data, start searching from the previously stored time directory
138
139 if (instanceI >= 0)
140 {
141 for (label i = instanceI; i >= 0; --i)
142 {
143 fileName testName(t.path()/ts[i].name()/localName);
144
145 if (isFile(testName))
146 {
147 return testName;
148 }
149 }
150 }
151
152 // fallback to "constant"
153 return t.path()/t.constant()/localName;
154}
155#endif
156
157
159(
160 const wordHashSet& available,
161 const word& fileType,
162 const bool verbose,
163 const char* functionName
164)
165{
166 if (available.found(fileType))
167 {
168 return true;
169 }
170 else if (verbose)
171 {
172 Info<< "Unknown file type";
173
174 if (functionName)
175 {
176 Info<< " for " << functionName;
177 }
178
179 Info<< " : " << fileType << nl
180 << "Valid types: " << flatOutput(available.sortedToc()) << nl
181 << nl;
182 }
183
184 return false;
185}
186
187
188// ************************************************************************* //
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
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
bool checkSupport() const
Check if the patch is fully supported.
static string getLineNoComment(ISstream &is, const char comment='#')
Read non-comment line.
static word nativeExt
The file extension corresponding to 'native' edge 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
A line primitive.
Definition: line.H:68
A class for handling character strings derived from std::string.
Definition: string.H:79
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 class for handling words, derived from Foam::string.
Definition: word.H:68
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
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53