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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "edgeMeshFormatsCore.H"
29 
30 #include "Time.H"
31 #include "Fstream.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 {
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& ext,
162  const bool verbose,
163  const word& functionName
164 )
165 {
166  if (available.found(ext))
167  {
168  return true;
169  }
170  else if (verbose)
171  {
172  wordList known = available.sortedToc();
173 
174  Info<<"Unknown file extension for " << functionName
175  << " : " << ext << nl
176  <<"Valid types: (";
177  // compact output:
178  forAll(known, i)
179  {
180  Info<<" " << known[i];
181  }
182  Info<<" )" << endl;
183  }
184 
185  return false;
186 }
187 
188 
189 // ************************************************************************* //
Foam::TimeState::timeOutputValue
scalar timeOutputValue() const
Return current time value.
Definition: TimeStateI.H:30
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:62
Foam::ISstream::getLine
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline into a string function.
Definition: ISstreamI.H:78
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::ISstream
Generic input stream using standard (STL) streams.
Definition: ISstream.H:54
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::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:73
Foam::fileFormats::edgeMeshFormatsCore::getLineNoComment
static string getLineNoComment(ISstream &is, const char comment='#')
Read non-comment line.
Definition: edgeMeshFormatsCore.C:42
Foam::HashSet< 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:164
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
edgeMesh.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::TimePaths::times
instantList times() const
Search the case for valid time directories.
Definition: TimePaths.C:149
Foam::fileFormats::edgeMeshFormatsCore::nativeExt
static word nativeExt
The file extension corresponding to 'native' edge format.
Definition: edgeMeshFormatsCore.H:75
Foam::HashTable::sortedToc
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:136
Time.H
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::Time::path
fileName path() const
Return path.
Definition: Time.H:303
Fstream.H
Input/output from file streams.
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:59
Foam::surfaceRegistry::prefix
static const word prefix
The prefix to local: surfaces.
Definition: surfaceRegistry.H:71
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:216
Foam::HashTable::found
bool found(const Key &key) const
Return true if hashed entry is found in table.
Definition: HashTableI.H:100
Foam::fileFormats::edgeMeshFormatsCore::checkSupport
static bool checkSupport(const wordHashSet &available, const word &ext, const bool verbose, const word &functionName)
Definition: edgeMeshFormatsCore.C:159
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
edgeMeshFormatsCore.H