meshReaderAux.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 | Copyright (C) 2011-2013 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  );
142 }
143 
144 
145 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146 
147 void Foam::meshReader::writeAux(const objectRegistry& registry) const
148 {
149  cellTable_.writeDict(registry);
150  writeInterfaces(registry);
151 
152  // write origCellId as List<label>
153  writeMeshLabelList
154  (
155  registry,
156  "origCellId",
157  origCellId_,
159  );
160 
161  // write cellTableId as List<label>
162  // this is crucial for later conversion back to ccm/starcd
163  writeMeshLabelList
164  (
165  registry,
166  "cellTableId",
167  cellTableId_,
169  );
170 }
171 
172 
173 // ************************************************************************* //
const Time & time() const
Return time.
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:363
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
Definition: HashTable.H:106
Output to file stream.
Definition: OFstream.H:81
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:309
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
void writeDict(const objectRegistry &, const word &name="cellTable", const fileName &instance="constant") const
Write constant/cellTable for later reuse.
Definition: cellTable.C:348
void writeAux(const objectRegistry &) const
Write auxiliary information.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
bool writeHeader(Ostream &) const
Write header.
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:34
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:138
string & note()
Return non-constant access to the optional note.
Definition: IOobject.H:272
labelList origCellId_
Lookup original Cell number for a given cell.
Definition: meshReader.H:259
A class for handling words, derived from string.
Definition: word.H:59
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType) const
Write using given format, version and compression.
static const char nl
Definition: Ostream.H:262
cellTable cellTable_
Cell table persistent data saved as a dictionary.
Definition: meshReader.H:284
static Stream & writeEndDivider(Stream &os)
Write the standard end file divider.
Definition: IOobjectI.H:108
labelList cellTableId_
Cell table id for each cell.
Definition: meshReader.H:281
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
messageStream Info
Registry of regIOobjects.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
const word & name() const
Return name.
Definition: IOobject.H:260