surfaceFormatsCore.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "surfaceFormatsCore.H"
27 
28 #include "Time.H"
29 #include "IFstream.H"
30 #include "OFstream.H"
31 #include "SortableList.H"
32 #include "surfMesh.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
37 
38 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
39 
41 (
42  IFstream& is
43 )
44 {
45  string line;
46  do
47  {
48  is.getLine(line);
49  }
50  while ((line.empty() || line[0] == '#') && is.good());
51 
52  return line;
53 }
54 
55 
56 #if 0
58 (
59  const word& surfName
60 )
61 {
62  const word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
63 
64  return fileName
65  (
67  / name + "." + nativeExt
68  );
69 }
70 
71 
73 (
74  const Time& t,
75  const word& surfName
76 )
77 {
78  fileName localName = localMeshFileName(surfName);
79 
80  // Search back through the time directories list to find the time
81  // closest to and lower than current time
82 
83  instantList ts = t.times();
84  label instanceI;
85 
86  for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
87  {
88  if (ts[instanceI].value() <= t.timeOutputValue())
89  {
90  break;
91  }
92  }
93 
94  // Noting that the current directory has already been searched
95  // for mesh data, start searching from the previously stored time directory
96 
97  if (instanceI >= 0)
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 
108  return t.constant();
109 }
110 
111 
113 (
114  const Time& t,
115  const word& surfName
116 )
117 {
118  fileName localName = localMeshFileName(surfName);
119 
120  // Search back through the time directories list to find the time
121  // closest to and lower than current time
122 
123  instantList ts = t.times();
124  label instanceI;
125 
126  for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
127  {
128  if (ts[instanceI].value() <= t.timeOutputValue())
129  {
130  break;
131  }
132  }
133 
134  // Noting that the current directory has already been searched
135  // for mesh data, start searching from the previously stored time directory
136 
137  if (instanceI >= 0)
138  {
139  for (label i = instanceI; i >= 0; --i)
140  {
141  fileName testName(t.path()/ts[i].name()/localName);
142 
143  if (isFile(testName))
144  {
145  return testName;
146  }
147  }
148  }
149 
150  // fallback to "constant"
151  return t.path()/t.constant()/localName;
152 }
153 #endif
154 
155 
157 (
158  const wordHashSet& available,
159  const word& ext,
160  const bool verbose,
161  const word& functionName
162 )
163 {
164  if (available.found(ext))
165  {
166  return true;
167  }
168  else if (verbose)
169  {
170  wordList toc = available.toc();
171  SortableList<word> known(move(toc));
172 
173  Info<<"Unknown file extension for " << functionName
174  << " : " << ext << nl
175  <<"Valid types: (";
176  // compact output:
177  forAll(known, i)
178  {
179  Info<<" " << known[i];
180  }
181  Info<<" )" << endl;
182  }
183 
184  return false;
185 }
186 
187 
188 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
189 
191 {}
192 
193 
194 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
195 
197 {}
198 
199 
200 // ************************************************************************* //
static const word prefix
The prefix to local: surfaces.
A HashTable with keys but without contents.
Definition: HashSet.H:59
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:59
A line primitive.
Definition: line.H:56
A class for handling file names.
Definition: fileName.H:79
A list that is sorted upon construction or when explicitly requested with the sort() method...
Definition: List.H:80
bool isFile(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist as a file in the file system?
Definition: POSIX.C:555
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static string getLineNoComment(IFstream &)
Read non-comment line.
static bool checkSupport(const wordHashSet &available, const word &ext, const bool verbose, const word &functionName)
static word nativeExt
The file extension corresponding to &#39;native&#39; surface format.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:330
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:113
static word meshSubDir
Return the mesh sub-directory name (normally "surfMesh")
Definition: surfMesh.H:137
A class for handling words, derived from string.
Definition: word.H:59
static fileName findMeshInstance(const Time &, const word &surfName="")
Find instance with surfName.
const word & constant() const
Return constant name.
Definition: TimePaths.H:123
static const char nl
Definition: Ostream.H:260
Input from file stream.
Definition: IFstream.H:81
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
ISstream & getLine(string &, const bool continuation=true)
Read line into a string.
Definition: ISstream.C:692
scalar timeOutputValue() const
Return current time value.
Definition: TimeStateI.H:29
instantList times() const
Search the case for valid time directories.
Definition: Time.C:652
static word defaultName
The default surface name: default.
messageStream Info
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:202
fileName path() const
Return path.
Definition: TimePaths.H:139
A class for handling character strings derived from std::string.
Definition: string.H:76
static fileName localMeshFileName(const word &surfName="")
Return the local file name (within time directory)
static fileName findMeshFile(const Time &, const word &surfName="")
Find mesh file with surfName.