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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2019-2021 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 "meshReader.H"
30 #include "IOMap.H"
31 #include "OFstream.H"
32 #include "Time.H"
33 
34 // * * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * //
35 
37 (
38  const word& context,
39  const wordList& list
40 )
41 {
42  HashTable<label> hashed(list.size());
43  bool duplicates = false;
44 
45  for (const word& w : list)
46  {
47  // Check duplicate name
48  auto iter = hashed.find(w);
49  if (iter.found())
50  {
51  ++(*iter);
52  duplicates = true;
53  }
54  else
55  {
56  hashed.insert(w, 1);
57  }
58  }
59 
60  // Warn about duplicate names
61  if (duplicates)
62  {
63  Info<< nl << "WARNING: " << context << " with identical names:";
64  forAllConstIters(hashed, iter)
65  {
66  if (*iter > 1)
67  {
68  Info<< " " << iter.key();
69  }
70  }
71  Info<< nl << endl;
72  }
73 }
74 
75 
76 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
77 
78 void Foam::meshReader::writeInterfaces(const objectRegistry& registry) const
79 {
80  // write constant/polyMesh/interface
81  IOList<labelList> ioObj
82  (
83  IOobject
84  (
85  "interfaces",
86  registry.time().constant(),
88  registry,
91  false
92  )
93  );
94 
95  ioObj.note() = "as yet unsupported interfaces (baffles)";
96 
97  Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
98 
99  OFstream os(ioObj.objectPath());
100  ioObj.writeHeader(os);
101 
102  os << interfaces_;
103  ioObj.writeEndDivider(os);
104 }
105 
106 
107 void Foam::meshReader::writeMeshLabelList
108 (
109  const objectRegistry& registry,
110  const word& propertyName,
111  const labelList& list,
112  IOstreamOption streamOpt
113 ) const
114 {
115  // write constant/polyMesh/propertyName
116  IOList<label> ioObj
117  (
118  IOobject
119  (
120  propertyName,
121  registry.time().constant(),
123  registry,
126  false
127  ),
128  list
129  );
130 
131 
132  ioObj.note() = "persistent data for STARCD <-> OPENFOAM translation";
133  Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
134 
135  // NOTE:
136  // the cellTableId is an integer and almost always < 1000, thus ASCII
137  // will be compacter than binary and makes external scripting easier
138 
139  ioObj.writeObject(streamOpt, true);
140 }
141 
142 
143 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
144 
145 void Foam::meshReader::writeAux(const objectRegistry& registry) const
146 {
147  cellTable_.writeDict(registry);
148  writeInterfaces(registry);
149 
150  // write origCellId as List<label>
151  writeMeshLabelList
152  (
153  registry,
154  "origCellId",
155  origCellId_,
157  );
158 
159  // write cellTableId as List<label>
160  // this is crucial for later conversion back to ccm/starcd
161  writeMeshLabelList
162  (
163  registry,
164  "cellTableId",
165  cellTableId_,
167  );
168 }
169 
170 
171 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::meshReader::warnDuplicates
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:321
Foam::HashTable::insert
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
OFstream.H
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
IOMap.H
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
os
OBJstream os(runTime.globalPath()/outputName)
Foam::HashTable::find
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
Definition: HashTableI.H:114
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:53
Foam::HashTable< label >
Time.H
Foam::IOstreamOption::BINARY
"binary"
Definition: IOstreamOption.H:73
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
Foam::meshReader::writeAux
void writeAux(const objectRegistry &) const
Write auxiliary information.
Definition: meshReaderAux.C:145
Foam::nl
constexpr char nl
Definition: Ostream.H:404
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::List< word >
Foam::IOList< labelList >
meshReader.H
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::objectRegistry::time
const Time & time() const noexcept
Return time registry.
Definition: objectRegistry.H:178