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