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-------------------------------------------------------------------------------
11License
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
78void Foam::meshReader::writeInterfaces(const objectRegistry& registry) const
79{
80 // write constant/polyMesh/interface
82 (
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
107void 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
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// ************************************************************************* //
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
Definition: HashTableI.H:114
A List of objects of type <T> with automated input and output.
Definition: IOList.H:58
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
The IOstreamOption is a simple container for options an IOstream can normally have.
@ ASCII
"ascii" (normal default)
Output to file stream, using an OSstream.
Definition: OFstream.H:57
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
static void warnDuplicates(const word &context, const wordList &)
Warn about repeated names.
Definition: meshReaderAux.C:37
void writeAux(const objectRegistry &) const
Write auxiliary information.
Registry of regIOobjects.
const Time & time() const noexcept
Return time registry.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:324
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
List< label > labelList
A List of labels.
Definition: List.H:66
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278