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-2022 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.good())
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,
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_;
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  IOListRef<label> ioObj
117  (
118  IOobject
119  (
120  propertyName,
121  registry.time().constant(),
123  registry,
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
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 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
Output to file stream, using an OSstream.
Definition: OFstream.H:49
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
"ascii" (normal default)
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:410
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:30
A simple container for options an IOstream can normally have.
Ignore writing from objectRegistry::writeObject()
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:152
A class for handling words, derived from Foam::string.
Definition: word.H:63
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
Definition: HashTableI.H:86
const Time & time() const noexcept
Return time registry.
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:112
OBJstream os(runTime.globalPath()/outputName)
Nothing to be read.
messageStream Info
Information stream (stdout output on master, null elsewhere)
void writeAux(const objectRegistry &) const
Write auxiliary information.
List< label > labelList
A List of labels.
Definition: List.H:62
Registry of regIOobjects.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Do not request registration (bool: false)
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28