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

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