OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

meshReaderAux.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*----------------------------------------------------------------------------*/
00026 
00027 #include "meshReader.H"
00028 #include "IOMap.H"
00029 #include "OFstream.H"
00030 
00031 
00032 // * * * * * * * * * * * * * * * Static Functions  * * * * * * * * * * * * * //
00033 
00034 void Foam::meshReader::warnDuplicates
00035 (
00036     const word& context,
00037     const wordList& list
00038 )
00039 {
00040     HashTable<label> hashed(list.size());
00041     bool duplicates = false;
00042 
00043     forAll(list, listI)
00044     {
00045         // check duplicate name
00046         HashTable<label>::iterator iter = hashed.find(list[listI]);
00047         if (iter != hashed.end())
00048         {
00049             (*iter)++;
00050             duplicates = true;
00051         }
00052         else
00053         {
00054             hashed.insert(list[listI], 1);
00055         }
00056     }
00057 
00058     // warn about duplicate names
00059     if (duplicates)
00060     {
00061         Info << nl << "WARNING: " << context << " with identical names:";
00062         forAllConstIter(HashTable<label>, hashed, iter)
00063         {
00064             if (*iter > 1)
00065             {
00066                 Info << "  " << iter.key();
00067             }
00068         }
00069         Info << nl << endl;
00070     }
00071 }
00072 
00073 
00074 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00075 
00076 void Foam::meshReader::writeInterfaces(const objectRegistry& registry) const
00077 {
00078     // write constant/polyMesh/interface
00079     IOList<labelList> ioObj
00080     (
00081         IOobject
00082         (
00083             "interfaces",
00084             "constant",
00085             polyMesh::meshSubDir,
00086             registry,
00087             IOobject::NO_READ,
00088             IOobject::NO_WRITE,
00089             false
00090         )
00091     );
00092 
00093     ioObj.note() = "as yet unsupported interfaces (baffles)";
00094 
00095     Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
00096 
00097     OFstream os(ioObj.objectPath());
00098     ioObj.writeHeader(os);
00099 
00100     os << interfaces_;
00101     ioObj.writeEndDivider(os);
00102 }
00103 
00104 
00105 void Foam::meshReader::writeMeshLabelList
00106 (
00107     const objectRegistry& registry,
00108     const word& propertyName,
00109     const labelList& list,
00110     IOstream::streamFormat fmt
00111 ) const
00112 {
00113     // write constant/polyMesh/propertyName
00114     IOList<label> ioObj
00115     (
00116         IOobject
00117         (
00118             propertyName,
00119             "constant",
00120             polyMesh::meshSubDir,
00121             registry,
00122             IOobject::NO_READ,
00123             IOobject::AUTO_WRITE,
00124             false
00125         ),
00126         list
00127     );
00128 
00129 
00130     ioObj.note() = "persistent data for star-cd <-> foam translation";
00131     Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
00132 
00133     // NOTE:
00134     // the cellTableId is an integer and almost always < 1000, thus ASCII
00135     // will be compacter than binary and makes external scripting easier
00136     //
00137     ioObj.writeObject
00138     (
00139         fmt,
00140         IOstream::currentVersion,
00141         IOstream::UNCOMPRESSED
00142     );
00143 }
00144 
00145 
00146 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00147 
00148 void Foam::meshReader::writeAux(const objectRegistry& registry) const
00149 {
00150     cellTable_.writeDict(registry);
00151     writeInterfaces(registry);
00152 
00153     // write origCellId as List<label>
00154     writeMeshLabelList
00155     (
00156         registry,
00157         "origCellId",
00158         origCellId_,
00159         IOstream::BINARY
00160     );
00161 
00162     // write cellTableId as List<label>
00163     // this is crucial for later conversion back to ccm/starcd
00164     writeMeshLabelList
00165     (
00166         registry,
00167         "cellTableId",
00168         cellTableId_,
00169         IOstream::ASCII
00170     );
00171 }
00172 
00173 
00174 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd