Loading...
Searching...
No Matches
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 = (ts.size()-1);
87
88 for (; instanceI >= 0; --instanceI)
89 {
90 if (ts[instanceI] <= 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 for (label i = instanceI; i >= 0; --i)
100 {
101 if (isFile(t.path()/ts[i].name()/localName))
102 {
103 return ts[i].name();
104 }
105 }
106
107 return t.constant();
108}
109
110
111Foam::fileName Foam::fileFormats::edgeMeshFormatsCore::findMeshFile
112(
113 const Time& t,
114 const word& meshName
115)
116{
117 fileName localName = localMeshFileName(meshName);
118
119 // Search back through the time directories list to find the time
120 // closest to and lower than current time
121
122 instantList ts = t.times();
123 label instanceI = (ts.size()-1);
124
125 for (; instanceI >= 0; --instanceI)
126 {
127 if (ts[instanceI] <= t.timeOutputValue())
128 {
129 break;
130 }
131 }
132
133 // Noting that the current directory has already been searched
134 // for mesh data, start searching from the previously stored time directory
135
136 for (label i = instanceI; i >= 0; --i)
137 {
138 fileName testName(t.path()/ts[i].name()/localName);
139
140 if (isFile(testName))
141 {
142 return testName;
143 }
144 }
146 // fallback to "constant"
147 return t.path()/t.constant()/localName;
148}
149#endif
150
151
153(
154 const wordHashSet& available,
155 const word& fileType,
156 const bool verbose,
157 const char* functionName
158)
159{
160 if (available.found(fileType))
161 {
162 return true;
163 }
164 else if (verbose)
165 {
166 Info<< "Unknown file type";
167
168 if (functionName)
169 {
170 Info<< " for " << functionName;
171 }
172
173 Info<< " : " << fileType << nl
174 << "Valid types: " << flatOutput(available.sortedToc()) << nl
175 << nl;
176 }
177
178 return false;
179}
180
181
182// ************************************************************************* //
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
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
static string getLineNoComment(ISstream &is, const char comment='#')
Read non-comment line.
static word nativeExt
The file extension corresponding to 'native' edge 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
A line primitive.
Definition line.H:180
A class for handling character strings derived from std::string.
Definition string.H:76
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 class for handling words, derived from Foam::string.
Definition word.H:66
auto & name
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition HashSet.H:80
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
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50