ENH: sampledSet: make starting cell/position consistent with lagrangian tracking
[OpenFOAM-2.0.x.git] / src / conversion / meshReader / meshReaderAux.C
blob91708d8055734358c7823121d9fd59743b4081de
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*----------------------------------------------------------------------------*/
26 #include "meshReader.H"
27 #include "IOMap.H"
28 #include "OFstream.H"
31 // * * * * * * * * * * * * * * * Static Functions  * * * * * * * * * * * * * //
33 void Foam::meshReader::warnDuplicates
35     const word& context,
36     const wordList& list
39     HashTable<label> hashed(list.size());
40     bool duplicates = false;
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     }
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     }
73 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
75 void Foam::meshReader::writeInterfaces(const objectRegistry& registry) const
77     // write constant/polyMesh/interface
78     IOList<labelList> ioObj
79     (
80         IOobject
81         (
82             "interfaces",
83             "constant",
84             polyMesh::meshSubDir,
85             registry,
86             IOobject::NO_READ,
87             IOobject::NO_WRITE,
88             false
89         )
90     );
92     ioObj.note() = "as yet unsupported interfaces (baffles)";
94     Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
96     OFstream os(ioObj.objectPath());
97     ioObj.writeHeader(os);
99     os << interfaces_;
100     ioObj.writeEndDivider(os);
104 void Foam::meshReader::writeMeshLabelList
106     const objectRegistry& registry,
107     const word& propertyName,
108     const labelList& list,
109     IOstream::streamFormat fmt
110 ) const
112     // write constant/polyMesh/propertyName
113     IOList<label> ioObj
114     (
115         IOobject
116         (
117             propertyName,
118             "constant",
119             polyMesh::meshSubDir,
120             registry,
121             IOobject::NO_READ,
122             IOobject::AUTO_WRITE,
123             false
124         ),
125         list
126     );
129     ioObj.note() = "persistent data for star-cd <-> foam translation";
130     Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
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,
139         IOstream::currentVersion,
140         IOstream::UNCOMPRESSED
141     );
145 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
147 void Foam::meshReader::writeAux(const objectRegistry& registry) const
149     cellTable_.writeDict(registry);
150     writeInterfaces(registry);
152     // write origCellId as List<label>
153     writeMeshLabelList
154     (
155         registry,
156         "origCellId",
157         origCellId_,
158         IOstream::BINARY
159     );
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_,
168         IOstream::ASCII
169     );
173 // ************************************************************************* //