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

readCouples.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 Description
00025     Create intermediate mesh from SAMM files
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "sammMesh.H"
00030 #include <OpenFOAM/IFstream.H>
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 void sammMesh::readCouples()
00035 {
00036     fileName couplesFileName(casePrefix_ + ".cpl");
00037 
00038     IFstream couplesFile(couplesFileName);
00039 
00040     if (couplesFile.good())
00041     {
00042         Info << "\nReading couples" << endl;
00043 
00044         // A mesh with couples cannot be a shape mesh
00045         isShapeMesh_ = false;
00046 
00047         label matchLabel, nEntries, typeFlag;
00048         label masterCell, masterFace;
00049         label slaveCell, slaveFace;
00050 
00051         while (!(couplesFile >> matchLabel).eof())
00052         {
00053             // read number of entries and match type.
00054             // Note. At the moment, only integral matches are supported
00055             couplesFile >> nEntries;
00056 
00057             couplesFile >> typeFlag;
00058 
00059             if (typeFlag > 1)
00060             {
00061                 Info
00062                     << "void sammMesh::readCouples() : "
00063                     << "couple " << matchLabel << " is not an integral match. "
00064                     << "Currently not supported" << endl;
00065             }
00066 
00067             // read master cell and face
00068             couplesFile >> masterCell >> masterFace;
00069 
00070             // get reference to master cell faces
00071             faceList& masterFaces = cellFaces_[masterCell - 1];
00072 
00073 //             Info << "Master cell: " << masterCell - 1 << " index: "
00074 //                 << cellShapes_[masterCell - 1].model().index()
00075 //                 << " face: " <<
00076 //                 masterFaces
00077 //                 [
00078 //                     shapeFaceLookup
00079 //                        [cellShapes_[masterCell - 1].model().index()]
00080 //                        [masterFace]
00081 //                 ]
00082 //                 << endl;
00083 
00084             // reset master face to zero size. It cannot be removed at this
00085             // stage because thisw would mess up the numbering in case of
00086             // more than one couple an a single master cell
00087             masterFaces
00088                 [
00089                     shapeFaceLookup
00090                        [cellShapes_[masterCell - 1].model().index()]
00091                        [masterFace]
00092                 ].setSize(0);
00093 
00094             // number of slave faces
00095             label nSlavesToRead = nEntries - 1;
00096 
00097             // get index for slave face add
00098             label slaveToAdd = masterFaces.size();
00099 
00100             // reset size of master faces to accept new (couple) faces
00101             masterFaces.setSize(masterFaces.size() + nSlavesToRead);
00102 
00103             for (int i = 0; i < nSlavesToRead; i++)
00104             {
00105                 couplesFile >> slaveCell >> slaveFace;
00106 
00107                 masterFaces[slaveToAdd] =
00108                     cellFaces_
00109                         [
00110                             slaveCell - 1
00111                         ]
00112                         [
00113                             shapeFaceLookup
00114                                 [cellShapes_[slaveCell - 1].model().index()]
00115                                 [slaveFace]
00116                         ].reverseFace();
00117 
00118 //                 Info << " slave cell: " << slaveCell - 1 << " index: "
00119 //                     << cellShapes_[slaveCell - 1].model().index()
00120 //                     << " face: " << masterFaces[slaveToAdd] << endl;
00121 
00122                 slaveToAdd++;
00123 
00124             }
00125 //             Info << endl;
00126 
00127         }
00128 
00129         // Once all couples are read, remove zero size faces from all cells
00130         forAll (cellFaces_, cellI)
00131         {
00132             faceList& curFaces = cellFaces_[cellI];
00133 
00134             label zeroSizeFound = 0;
00135 
00136             forAll (curFaces, faceI)
00137             {
00138                 if (curFaces[faceI].empty())
00139                 {
00140                     zeroSizeFound++;
00141                 }
00142             }
00143 
00144             if (zeroSizeFound > 0)
00145             {
00146                 // compress the list. A copy needs to made first
00147                 faceList oldFaces = curFaces;
00148 
00149                 curFaces.setSize(curFaces.size() - zeroSizeFound);
00150 
00151                 label nFaces = 0;
00152 
00153                 forAll (oldFaces, faceI)
00154                 {
00155                     if (oldFaces[faceI].size())
00156                     {
00157                         curFaces[nFaces] = oldFaces[faceI];
00158 
00159                         nFaces++;
00160                     }
00161                 }
00162             }
00163         }
00164     }
00165     else
00166     {
00167         Info
00168             << "void sammMesh::readCouples() : "
00169             << "Cannot read file "
00170             << couplesFileName
00171             << ". No matches defined."
00172             << endl;
00173         }
00174 }
00175 
00176 
00177 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines