ccmReaderAux.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) 2016-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Description
27 read/write auxiliary files for aiding STARCD/OPENFOAM interoperability
28
29 - cellTable information
30 - boundaryRegion information
31 - interface information
32
33\*----------------------------------------------------------------------------*/
34
35#include "OFstream.H"
36#include "ccmReader.H"
37#include "ccmInternal.H" // include last to avoid any strange interactions
38
39
40// * * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * //
41
42Foam::Map<Foam::word> Foam::ccm::reader::selectPorous
43(
44 const Map<dictionary>& table
45)
46{
47 Map<word> lookup;
48
49 forAllConstIters(table, iter)
50 {
51 if (iter().getOrDefault<label>("PorosityId", 0) != 0)
52 {
53 lookup.insert
54 (
55 iter.key(),
56 iter().getOrDefault<word>
57 (
58 "Label",
59 "cellTable_" + Foam::name(iter.key())
60 )
61 );
62 }
63 }
64
65 return lookup;
66}
67
68
70(
71 const word& context,
72 const wordList& lst
73)
74{
75 HashTable<label> hashed(2*lst.size());
76 bool duplicates = false;
77
78 for (const word& item : lst)
79 {
80 // Check duplicate names
81 auto iter = hashed.find(item);
82 if (iter.found())
83 {
84 (*iter)++;
85 duplicates = true;
86 }
87 else
88 {
89 hashed.insert(item, 1);
90 }
91 }
92
93 // Warn about duplicate names
94 if (duplicates)
95 {
96 Info << nl << "WARNING: " << context << " with identical names:";
97 forAllConstIters(hashed, iter)
98 {
99 if (iter.val() > 1)
100 {
101 Info << " " << iter.key();
102 }
103 }
104 Info << nl << endl;
105 }
106}
107
108
109// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
110
111void Foam::ccm::reader::writeInterfaces
112(
113 const objectRegistry& registry
114) const
115{
116 // Write constant/polyMesh/interface
118 (
120 (
121 "interfaces",
122 "constant",
124 registry,
127 false
128 )
129 );
130
131 ioObj.note() = "as yet unsupported interfaces (baffles)";
132
133 Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
134
135 OFstream os(ioObj.objectPath());
136 ioObj.writeHeader(os);
137
138 os << bafInterfaces_;
139}
140
141
142// Write List<label> in constant/polyMesh
143// - this is crucial for later conversion back to ccm/starcd
144void Foam::ccm::reader::writeMeshLabelList
145(
146 const objectRegistry& registry,
147 const word& propertyName,
148 const labelList& list,
149 IOstreamOption streamOpt
150) const
151{
152 // Write constant/polyMesh/propertyName
153 IOList<label> ioObj
154 (
156 (
157 propertyName,
158 "constant",
160 registry,
163 false
164 ),
165 list
166 );
167
168 ioObj.note() = "persistent data for STARCD <-> OPENFOAM translation";
169 Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
170
171 // NOTE:
172 // The cellTableId is an integer and almost always < 1000, thus ASCII
173 // will be compacter than binary and makes external scripting easier
174
175 ioObj.writeObject(streamOpt, true);
176}
177
178
179// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
180
182(
183 const objectRegistry& registry
184) const
185{
186 cellTable_.writeDict(registry);
187 boundaryRegion_.writeDict(registry);
188 writeInterfaces(registry);
189
190 // Write origCellId as List<label>
191 writeMeshLabelList
192 (
193 registry,
194 "origCellId",
195 origCellId_,
197 );
198
199 // Write cellTableId as List<label>
200 // - this is crucial for later conversion back to ccm/starcd
201 writeMeshLabelList
202 (
203 registry,
204 "cellTableId",
205 cellTableId_,
207 );
208}
209
210
211// ************************************************************************* //
Internal bits for wrapping libccmio - do not use directly.
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)
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
Output to file stream, using an OSstream.
Definition: OFstream.H:57
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
void writeAux(const objectRegistry &registry) const
Write cellTable, boundaryRegion and interface information.
Definition: ccmReaderAux.C:182
static void warnDuplicates(const word &context, const wordList &lst)
Warn about repeated name.
Definition: ccmReaderAux.C:70
Registry of regIOobjects.
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)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
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