meshReaderAux.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-2018 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 "meshReader.H"
27 #include "IOMap.H"
28 #include "OFstream.H"
29 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * //
32 
34 (
35  const word& context,
36  const wordList& list
37 )
38 {
39  HashTable<label> hashed(list.size());
40  bool duplicates = false;
41 
42  forAll(list, listI)
43  {
44  // check duplicate name
45  HashTable<label>::iterator iter = hashed.find(list[listI]);
46  if (iter != hashed.end())
47  {
48  (*iter)++;
49  duplicates = true;
50  }
51  else
52  {
53  hashed.insert(list[listI], 1);
54  }
55  }
56 
57  // warn about duplicate names
58  if (duplicates)
59  {
60  Info<< nl << "WARNING: " << context << " with identical names:";
61  forAllConstIter(HashTable<label>, hashed, iter)
62  {
63  if (*iter > 1)
64  {
65  Info<< " " << iter.key();
66  }
67  }
68  Info<< nl << endl;
69  }
70 }
71 
72 
73 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
74 
75 void Foam::meshReader::writeInterfaces(const objectRegistry& registry) const
76 {
77  // write constant/polyMesh/interface
78  IOList<labelList> ioObj
79  (
80  IOobject
81  (
82  "interfaces",
83  registry.time().constant(),
85  registry,
88  false
89  )
90  );
91 
92  ioObj.note() = "as yet unsupported interfaces (baffles)";
93 
94  Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
95 
96  OFstream os(ioObj.objectPath());
97  ioObj.writeHeader(os);
98 
99  os << interfaces_;
100  ioObj.writeEndDivider(os);
101 }
102 
103 
104 void Foam::meshReader::writeMeshLabelList
105 (
106  const objectRegistry& registry,
107  const word& propertyName,
108  const labelList& list,
110 ) const
111 {
112  // write constant/polyMesh/propertyName
113  IOList<label> ioObj
114  (
115  IOobject
116  (
117  propertyName,
118  registry.time().constant(),
120  registry,
123  false
124  ),
125  list
126  );
127 
128 
129  ioObj.note() = "persistent data for star-cd <-> foam translation";
130  Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
131 
132  // NOTE:
133  // the cellTableId is an integer and almost always < 1000, thus ASCII
134  // will be compacter than binary and makes external scripting easier
135  //
136  ioObj.writeObject
137  (
138  fmt,
141  true
142  );
143 }
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
148 void Foam::meshReader::writeAux(const objectRegistry& registry) const
149 {
150  cellTable_.writeDict(registry);
151  writeInterfaces(registry);
152 
153  // write origCellId as List<label>
154  writeMeshLabelList
155  (
156  registry,
157  "origCellId",
158  origCellId_,
160  );
161 
162  // write cellTableId as List<label>
163  // this is crucial for later conversion back to ccm/starcd
164  writeMeshLabelList
165  (
166  registry,
167  "cellTableId",
168  cellTableId_,
170  );
171 }
172 
173 
174 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
const word & name() const
Return name.
Definition: IOobject.H:315
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Output to file stream.
Definition: OFstream.H:82
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:328
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
fileName objectPath() const
Return complete path + object name.
Definition: regIOobject.H:159
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:34
void writeDict(const objectRegistry &, const word &name="cellTable", const fileName &instance="constant") const
Write constant/cellTable for later reuse.
Definition: cellTable.C:348
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
An STL-conforming iterator.
Definition: HashTable.H:426
string & note()
Return non-constant access to the optional note.
Definition: IOobject.H:333
labelList origCellId_
Lookup original Cell number for a given cell.
Definition: meshReader.H:252
A class for handling words, derived from string.
Definition: word.H:59
const word & constant() const
Return constant name.
Definition: TimePaths.H:123
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
An STL-conforming hash table.
Definition: HashTable.H:61
static const char nl
Definition: Ostream.H:260
const Time & time() const
Return time.
cellTable cellTable_
Cell table persistent data saved as a dictionary.
Definition: meshReader.H:277
static Stream & writeEndDivider(Stream &os)
Write the standard end file divider.
Definition: IOobjectI.H:123
labelList cellTableId_
Cell table id for each cell.
Definition: meshReader.H:274
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
bool writeHeader(Ostream &) const
Write header.
messageStream Info
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write) const
Write using given format, version and compression.
void writeAux(const objectRegistry &) const
Write auxiliary information.
Registry of regIOobjects.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98