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 PROSTAR files
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "starMesh.H"
00031 #include "IFstream.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 void starMesh::readCouples()
00036 {
00037     fileName couplesFileName(casePrefix_ + ".cpl");
00038 
00039     label nCouples = 0;
00040 
00041     // Count number of couples
00042     {
00043         IFstream couplesFile(couplesFileName);
00044 
00045         if (couplesFile.good())
00046         {
00047             Info << "\nReading couples" << endl;
00048 
00049             label matchLabel, nEntries, typeFlag;
00050             label starMasterCell, rotXMasterFace;
00051             label starSlaveCell, rotXSlaveFace;
00052 
00053             // count the number of entries to read
00054             while (!(couplesFile >> matchLabel).eof())
00055             {
00056                 // read number of entries and match type flag.
00057                 couplesFile >> nEntries;
00058 
00059                 couplesFile >> typeFlag;
00060 
00061                 // read master cell and face
00062                 couplesFile >> starMasterCell >> rotXMasterFace;
00063 
00064                 // add number of couples from current match
00065                 label nSlavesToRead = nEntries - 1;
00066 
00067                 nCouples += nSlavesToRead;
00068 
00069                 for (int i = 0; i < nSlavesToRead; i++)
00070                 {
00071                     couplesFile >> starSlaveCell >> rotXSlaveFace;
00072                 }
00073             }
00074 
00075             Info<< "Number of couples = " << nCouples << endl << endl;
00076         }
00077         else
00078         {
00079             Info<< endl << "No couple matches defined." << endl;
00080         }
00081     }
00082 
00083     // Read couples
00084     if (nCouples > 0)
00085     {
00086         // read couples
00087         couples_.setSize(nCouples);
00088         label couplei = 0;
00089 
00090         // A mesh with couples cannot be a shape mesh
00091         isShapeMesh_ = false;
00092 
00093         IFstream couplesFile(couplesFileName);
00094 
00095         label matchLabel, nEntries, typeFlag;
00096         label starMasterCell, masterCell, rotXMasterFace, rotZeroMasterFace;
00097         label starSlaveCell, slaveCell, rotXSlaveFace, rotZeroSlaveFace;
00098 
00099         while (!(couplesFile >> matchLabel).eof())
00100         {
00101             // read number of entries and match type flag.
00102             // Note. At the moment, only integral matches are supported
00103             couplesFile >> nEntries;
00104 
00105             couplesFile >> typeFlag;
00106 
00107             // read master cell and face
00108             couplesFile >> starMasterCell >> rotXMasterFace;
00109 
00110             // translate the cell labels
00111             masterCell = starCellLabelLookup_[starMasterCell];
00112 
00113             // translate the master face into rotation zero if applicable
00114             if (starCellPermutation_[masterCell] > -1)
00115             {
00116                 const label curMasterPermutation =
00117                     starCellPermutation_[masterCell];
00118 
00119                 rotZeroMasterFace =
00120                     sammFacePermutationTable
00121                         [curMasterPermutation]
00122                         [rotXMasterFace];
00123             }
00124             else
00125             {
00126                 rotZeroMasterFace = rotXMasterFace;
00127             }
00128 
00129             // get master face index
00130             label masterFaceID =
00131                 shapeFaceLookup
00132                     [cellShapes_[masterCell].model().index()]
00133                     [rotZeroMasterFace];
00134 
00135             // number of slave faces
00136             label nSlavesToRead = nEntries - 1;
00137 
00138             for (int i = 0; i < nSlavesToRead; i++)
00139             {
00140                 couplesFile >> starSlaveCell >> rotXSlaveFace;
00141 
00142                 // translate the cell labels
00143                 slaveCell = starCellLabelLookup_[starSlaveCell];
00144 
00145                 // translate the slave face into rotation zero if applicable
00146                 if (starCellPermutation_[slaveCell] > -1)
00147                 {
00148                     const label curSlavePermutation =
00149                         starCellPermutation_[slaveCell];
00150 
00151                     rotZeroSlaveFace =
00152                         sammFacePermutationTable
00153                             [curSlavePermutation]
00154                             [rotXSlaveFace];
00155                 }
00156                 else
00157                 {
00158                     rotZeroSlaveFace = rotXSlaveFace;
00159                 }
00160 
00161                 label slaveFaceID =
00162                     shapeFaceLookup
00163                         [cellShapes_[slaveCell].model().index()]
00164                         [rotZeroSlaveFace];
00165 
00166                 // Set the couple
00167                 couples_.set
00168                 (
00169                     couplei++,
00170                     new coupledFacePair
00171                     (
00172                         matchLabel,
00173                         masterCell, masterFaceID,
00174                         slaveCell, slaveFaceID,
00175                         typeFlag
00176                     )
00177                 );
00178             }
00179         }
00180 
00181         Info << "finished reading couples" << endl;
00182     }
00183 }
00184 
00185 
00186 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd