surfaceFormatsCore.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-2012 OpenFOAM Foundation
9  Copyright (C) 2017 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 "surfaceFormatsCore.H"
30 
31 #include "Time.H"
32 #include "ListOps.H"
33 #include "Fstream.H"
34 #include "surfMesh.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
39 
40 
41 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
42 
44 (
45  ISstream& is,
46  const char comment
47 )
48 {
50  do
51  {
52  is.getLine(line);
53  }
54  while ((line.empty() || line[0] == comment) && is.good());
55 
56  return line;
57 }
58 
59 
60 #if 0
62 (
63  const word& surfName
64 )
65 {
66  const word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
67 
68  return fileName
69  (
71  / name + "." + nativeExt
72  );
73 }
74 
75 
77 (
78  const Time& t,
79  const word& surfName
80 )
81 {
82  fileName localName = localMeshFileName(surfName);
83 
84  // Search back through the time directories list to find the time
85  // closest to and lower than current time
86 
87  instantList ts = t.times();
88  label instanceI;
89 
90  for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
91  {
92  if (ts[instanceI].value() <= t.timeOutputValue())
93  {
94  break;
95  }
96  }
97 
98  // Noting that the current directory has already been searched
99  // for mesh data, start searching from the previously stored time directory
100 
101  if (instanceI >= 0)
102  {
103  for (label i = instanceI; i >= 0; --i)
104  {
105  if (isFile(t.path()/ts[i].name()/localName))
106  {
107  return ts[i].name();
108  }
109  }
110  }
111 
112  return t.constant();
113 }
114 
115 
117 (
118  const Time& t,
119  const word& surfName
120 )
121 {
122  fileName localName = localMeshFileName(surfName);
123 
124  // Search back through the time directories list to find the time
125  // closest to and lower than current time
126 
127  instantList ts = t.times();
128  label instanceI;
129 
130  for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
131  {
132  if (ts[instanceI].value() <= t.timeOutputValue())
133  {
134  break;
135  }
136  }
137 
138  // Noting that the current directory has already been searched
139  // for mesh data, start searching from the previously stored time directory
140 
141  if (instanceI >= 0)
142  {
143  for (label i = instanceI; i >= 0; --i)
144  {
145  fileName testName(t.path()/ts[i].name()/localName);
146 
147  if (isFile(testName))
148  {
149  return testName;
150  }
151  }
152  }
153 
154  // fallback to "constant"
155  return t.path()/t.constant()/localName;
156 }
157 #endif
158 
159 
161 (
162  const wordHashSet& available,
163  const word& ext,
164  const bool verbose,
165  const word& functionName
166 )
167 {
168  if (available.found(ext))
169  {
170  return true;
171  }
172  else if (verbose)
173  {
174  Info<<"Unknown file extension for " << functionName
175  << " : " << ext << nl
176  << "Valid types: " << flatOutput(available.sortedToc()) << nl
177  << endl;
178  }
179 
180  return false;
181 }
182 
183 
184 // ************************************************************************* //
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::fileFormats::surfaceFormatsCore::nativeExt
static word nativeExt
The file extension corresponding to 'native' surface format.
Definition: surfaceFormatsCore.H:87
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::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
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
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::fileFormats::surfaceFormatsCore::getLineNoComment
static string getLineNoComment(ISstream &is, const char comment='#')
Read non-empty and non-comment line.
Definition: surfaceFormatsCore.C:44
Foam::TimePaths::times
instantList times() const
Search the case for valid time directories.
Definition: TimePaths.C:149
surfMesh.H
Foam::HashTable::sortedToc
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:136
Foam::fileFormats::surfaceFormatsCore::findMeshFile
static fileName findMeshFile(const Time &, const word &surfName=word::null)
Find mesh file with surfName.
Foam::fileFormats::surfaceFormatsCore::localMeshFileName
static fileName localMeshFileName(const word &surfName=word::null)
Return the local file name (within time directory)
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::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
Foam::List< instant >
Foam::surfaceRegistry::defaultName
static word defaultName
The default surface name: default.
Definition: surfaceRegistry.H:74
Foam::fileFormats::surfaceFormatsCore::findMeshInstance
static fileName findMeshInstance(const Time &, const word &surfName=word::null)
Find instance with surfName.
Foam::line
A line primitive.
Definition: line.H: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::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::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
surfaceFormatsCore.H
Foam::fileFormats::surfaceFormatsCore::checkSupport
static bool checkSupport(const wordHashSet &available, const word &ext, const bool verbose, const word &functionName)
Helper function when checking if a file extension is supported.
Definition: surfaceFormatsCore.C:161