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-2017 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 
26 Description
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 
42 Foam::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().lookupOrDefault<label>("PorosityId", 0) != 0)
52  {
53  lookup.insert
54  (
55  iter.key(),
56  iter().lookupOrDefault<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 
111 void Foam::ccm::reader::writeInterfaces
112 (
113  const objectRegistry& registry
114 ) const
115 {
116  // Write constant/polyMesh/interface
117  IOList<labelList> ioObj
118  (
119  IOobject
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
144 void Foam::ccm::reader::writeMeshLabelList
145 (
146  const objectRegistry& registry,
147  const word& propertyName,
148  const labelList& list,
150 ) const
151 {
152  // Write constant/polyMesh/propertyName
153  IOList<label> ioObj
154  (
155  IOobject
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
176  (
177  fmt,
180  true
181  );
182 }
183 
184 
185 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
186 
188 (
189  const objectRegistry& registry
190 ) const
191 {
192  cellTable_.writeDict(registry);
193  boundaryRegion_.writeDict(registry);
194  writeInterfaces(registry);
195 
196  // Write origCellId as List<label>
197  writeMeshLabelList
198  (
199  registry,
200  "origCellId",
201  origCellId_,
203  );
204 
205  // Write cellTableId as List<label>
206  // - this is crucial for later conversion back to ccm/starcd
207  writeMeshLabelList
208  (
209  registry,
210  "cellTableId",
211  cellTableId_,
213  );
214 }
215 
216 
217 // ************************************************************************* //
Foam::IOstreamOption::UNCOMPRESSED
compression = false
Definition: IOstreamOption.H:73
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:129
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:315
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number.
Definition: IOstreamOption.H:193
Foam::HashTable::insert
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:168
Foam::Map< Foam::word >
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
OFstream.H
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::ccm::reader::writeAux
void writeAux(const objectRegistry &registry) const
Write cellTable, boundaryRegion and interface information.
Definition: ccmReaderAux.C:188
Foam::ccm::reader::warnDuplicates
static void warnDuplicates(const word &context, const wordList &lst)
Warn about repeated name.
Definition: ccmReaderAux.C:70
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::cellModeller::lookup
const cellModel * lookup(const word &modelName)
Deprecated(2017-11) equivalent to cellModel::ptr static method.
Definition: cellModeller.H:46
ccmInternal.H
Internal bits for wrapping libccmio - do not use directly.
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
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:99
Foam::HashTable< label >
Foam::IOstreamOption::BINARY
"binary"
Definition: IOstreamOption.H:67
Foam::IOstreamOption::ASCII
"ascii"
Definition: IOstreamOption.H:66
Foam::nl
constexpr char nl
Definition: Ostream.H:372
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::List< word >
Foam::IOList< labelList >
ccmReader.H
Foam::IOobject::NO_READ
Definition: IOobject.H:123