FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*----------------------------------------------------------------------------*/
00025 
00026 #include "meshReader.H"
00027 #include <OpenFOAM/IOMap.H>
00028 #include <OpenFOAM/OFstream.H>
00029 
00030 
00031 // * * * * * * * * * * * * * * * Static Functions  * * * * * * * * * * * * * //
00032 
00033 void Foam::meshReader::warnDuplicates
00034 (
00035     const word& context,
00036     const wordList& list
00037 )
00038 {
00039     HashTable<label> hashed(list.size());
00040     bool duplicates = false;
00041 
00042     forAll(list, listI)
00043     {
00044         // check duplicate name
00045         HashTable<label>::iterator iter = hashed.find(list[listI]);
00046         if (iter != hashed.end())
00047         {
00048             (*iter)++;
00049             duplicates = true;
00050         }
00051         else
00052         {
00053             hashed.insert(list[listI], 1);
00054         }
00055     }
00056 
00057     // warn about duplicate names
00058     if (duplicates)
00059     {
00060         Info << nl << "WARNING: " << context << " with identical names:";
00061         forAllConstIter(HashTable<label>, hashed, iter)
00062         {
00063             if (*iter > 1)
00064             {
00065                 Info << "  " << iter.key();
00066             }
00067         }
00068         Info << nl << endl;
00069     }
00070 }
00071 
00072 
00073 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00074 
00075 void Foam::meshReader::writeInterfaces(const objectRegistry& registry) const
00076 {
00077     // write constant/polyMesh/interface
00078     IOList<labelList> ioObj
00079     (
00080         IOobject
00081         (
00082             "interfaces",
00083             "constant",
00084             polyMesh::meshSubDir,
00085             registry,
00086             IOobject::NO_READ,
00087             IOobject::NO_WRITE,
00088             false
00089         )
00090     );
00091 
00092     ioObj.note() = "as yet unsupported interfaces (baffles)";
00093 
00094     Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
00095 
00096     OFstream os(ioObj.objectPath());
00097     ioObj.writeHeader(os);
00098 
00099     os << interfaces_;
00100     ioObj.writeEndDivider(os);
00101 }
00102 
00103 
00104 void Foam::meshReader::writeMeshLabelList
00105 (
00106     const objectRegistry& registry,
00107     const word& propertyName,
00108     const labelList& list,
00109     IOstream::streamFormat fmt
00110 ) const
00111 {
00112     // write constant/polyMesh/propertyName
00113     IOList<label> ioObj
00114     (
00115         IOobject
00116         (
00117             propertyName,
00118             "constant",
00119             polyMesh::meshSubDir,
00120             registry,
00121             IOobject::NO_READ,
00122             IOobject::AUTO_WRITE,
00123             false
00124         ),
00125         list
00126     );
00127 
00128 
00129     ioObj.note() = "persistent data for star-cd <-> foam translation";
00130     Info<< "Writing " << ioObj.name() << " to " << ioObj.objectPath() << endl;
00131 
00132     // NOTE:
00133     // the cellTableId is an integer and almost always < 1000, thus ASCII
00134     // will be compacter than binary and makes external scripting easier
00135     //
00136     ioObj.writeObject
00137     (
00138         fmt,
00139         IOstream::currentVersion,
00140         IOstream::UNCOMPRESSED
00141     );
00142 }
00143 
00144 
00145 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00146 
00147 void Foam::meshReader::writeAux(const objectRegistry& registry) const
00148 {
00149     cellTable_.writeDict(registry);
00150     writeInterfaces(registry);
00151 
00152     // write origCellId as List<label>
00153     writeMeshLabelList
00154     (
00155         registry,
00156         "origCellId",
00157         origCellId_,
00158         IOstream::BINARY
00159     );
00160 
00161     // write cellTableId as List<label>
00162     // this is crucial for later conversion back to ccm/starcd
00163     writeMeshLabelList
00164     (
00165         registry,
00166         "cellTableId",
00167         cellTableId_,
00168         IOstream::ASCII
00169     );
00170 }
00171 
00172 
00173 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines