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 -------------------------------------------------------------------------------
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 "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
59 Foam::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 
74 Foam::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 
114 Foam::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 // ************************************************************************* //
Foam::TimeState::timeOutputValue
scalar timeOutputValue() const
Return current time value.
Definition: TimeStateI.H:31
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
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::fileFormats::edgeMeshFormatsCore::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: edgeMeshFormatsCore.C:159
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
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::string
A class for handling character strings derived from std::string.
Definition: string.H:76
Foam::fileFormats::edgeMeshFormatsCore::getLineNoComment
static string getLineNoComment(ISstream &is, const char comment='#')
Read non-comment line.
Definition: edgeMeshFormatsCore.C:42
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
edgeMesh.H
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::TimePaths::times
instantList times() const
Search the case for valid time directories.
Definition: TimePaths.C:149
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:216
Foam::fileFormats::edgeMeshFormatsCore::nativeExt
static word nativeExt
The file extension corresponding to 'native' edge format.
Definition: edgeMeshFormatsCore.H:75
Time.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:358
Foam::List< instant >
Foam::surfaceRegistry::defaultName
static word defaultName
The default surface name: default.
Definition: surfaceRegistry.H:74
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
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::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
edgeMeshFormatsCore.H