initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / conversion / meshReader / meshReaderAux.C
blobdafaf9c9f3bbb6674ba495f115c6b4d2fc0c79fd
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*----------------------------------------------------------------------------*/
27 #include "meshReader.H"
28 #include "IOMap.H"
29 #include "OFstream.H"
32 // * * * * * * * * * * * * * * * Static Functions  * * * * * * * * * * * * * //
34 void Foam::meshReader::warnDuplicates
36     const word& context,
37     const wordList& list
40     HashTable<label> hashed(list.size());
41     bool duplicates = false;
43     forAll(list, listI)
44     {
45         // check duplicate name
46         HashTable<label>::iterator iter = hashed.find(list[listI]);
47         if (iter != hashed.end())
48         {
49             (*iter)++;
50             duplicates = true;
51         }
52         else
53         {
54             hashed.insert(list[listI], 1);
55         }
56     }
58     // warn about duplicate names
59     if (duplicates)
60     {
61         Info << nl << "WARNING: " << context << " with identical names:";
62         forAllConstIter(HashTable<label>, hashed, iter)
63         {
64             if (*iter > 1)
65             {
66                 Info << "  " << iter.key();
67             }
68         }
69         Info << nl << endl;
70     }
74 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
76 void Foam::meshReader::writeInterfaces(const objectRegistry& registry) const
78     // write constant/polyMesh/interface
79     IOList<labelList> ioObj
80     (
81         IOobject
82         (
83             "interfaces",
84             "constant",
85             polyMesh::meshSubDir,
86             registry,
87             IOobject::NO_READ,
88             IOobject::NO_WRITE,
89             false
90         )
91     );
93     ioObj.note() = "as yet unsupported interfaces (baffles)";
95     Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
97     OFstream os(ioObj.objectPath());
98     ioObj.writeHeader(os);
100     os  << interfaces_
101         << "// *************************************"
102         << "************************************ //"
103         << endl;
107 void Foam::meshReader::writeMeshLabelList
109     const objectRegistry& registry,
110     const word& propertyName,
111     const labelList& list,
112     IOstream::streamFormat fmt
113 ) const
115     // write constant/polyMesh/propertyName
116     IOList<label> ioObj
117     (
118         IOobject
119         (
120             propertyName,
121             "constant",
122             polyMesh::meshSubDir,
123             registry,
124             IOobject::NO_READ,
125             IOobject::AUTO_WRITE,
126             false
127         ),
128         list
129     );
132     ioObj.note() = "persistent data for star-cd <-> foam translation";
133     Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
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
140     (
141         fmt,
142         IOstream::currentVersion,
143         IOstream::UNCOMPRESSED
144     );
148 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
150 void Foam::meshReader::writeAux(const objectRegistry& registry) const
152     cellTable_.writeDict(registry);
153     writeInterfaces(registry);
155     // write origCellId as List<label>
156     writeMeshLabelList
157     (
158         registry,
159         "origCellId",
160         origCellId_,
161         IOstream::BINARY
162     );
164     // write cellTableId as List<label>
165     // this is crucial for later conversion back to ccm/starcd
166     writeMeshLabelList
167     (
168         registry,
169         "cellTableId",
170         cellTableId_,
171         IOstream::ASCII
172     );
176 // ************************************************************************* //