FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*----------------------------------------------------------------------------*/
25 
26 #include "meshReader.H"
27 #include <OpenFOAM/IOMap.H>
28 #include <OpenFOAM/OFstream.H>
29 
30 
31 // * * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * //
32 
34 (
35  const word& context,
36  const wordList& list
37 )
38 {
39  HashTable<label> hashed(list.size());
40  bool duplicates = false;
41 
42  forAll(list, listI)
43  {
44  // check duplicate name
45  HashTable<label>::iterator iter = hashed.find(list[listI]);
46  if (iter != hashed.end())
47  {
48  (*iter)++;
49  duplicates = true;
50  }
51  else
52  {
53  hashed.insert(list[listI], 1);
54  }
55  }
56 
57  // warn about duplicate names
58  if (duplicates)
59  {
60  Info << nl << "WARNING: " << context << " with identical names:";
61  forAllConstIter(HashTable<label>, hashed, iter)
62  {
63  if (*iter > 1)
64  {
65  Info << " " << iter.key();
66  }
67  }
68  Info << nl << endl;
69  }
70 }
71 
72 
73 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
74 
75 void Foam::meshReader::writeInterfaces(const objectRegistry& registry) const
76 {
77  // write constant/polyMesh/interface
78  IOList<labelList> ioObj
79  (
80  IOobject
81  (
82  "interfaces",
83  "constant",
85  registry,
88  false
89  )
90  );
91 
92  ioObj.note() = "as yet unsupported interfaces (baffles)";
93 
94  Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
95 
96  OFstream os(ioObj.objectPath());
97  ioObj.writeHeader(os);
98 
99  os << interfaces_;
100  ioObj.writeEndDivider(os);
101 }
102 
103 
104 void Foam::meshReader::writeMeshLabelList
105 (
106  const objectRegistry& registry,
107  const word& propertyName,
108  const labelList& list,
110 ) const
111 {
112  // write constant/polyMesh/propertyName
113  IOList<label> ioObj
114  (
115  IOobject
116  (
117  propertyName,
118  "constant",
120  registry,
123  false
124  ),
125  list
126  );
127 
128 
129  ioObj.note() = "persistent data for star-cd <-> foam translation";
130  Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
131 
132  // NOTE:
133  // the cellTableId is an integer and almost always < 1000, thus ASCII
134  // will be compacter than binary and makes external scripting easier
135  //
136  ioObj.writeObject
137  (
138  fmt,
141  );
142 }
143 
144 
145 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146 
147 void Foam::meshReader::writeAux(const objectRegistry& registry) const
148 {
149  cellTable_.writeDict(registry);
150  writeInterfaces(registry);
151 
152  // write origCellId as List<label>
153  writeMeshLabelList
154  (
155  registry,
156  "origCellId",
157  origCellId_,
159  );
160 
161  // write cellTableId as List<label>
162  // this is crucial for later conversion back to ccm/starcd
163  writeMeshLabelList
164  (
165  registry,
166  "cellTableId",
167  cellTableId_,
169  );
170 }
171 
172 
173 // ************************ vim: set sw=4 sts=4 et: ************************ //