initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / mesh / conversion / starToFoam / readCouples.C
blob975dab47d8199ea17b4f94c387de8372dcefb0e1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
26     Create intermediate mesh from PROSTAR files
28 \*---------------------------------------------------------------------------*/
30 #include "starMesh.H"
31 #include "IFstream.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 void starMesh::readCouples()
37     fileName couplesFileName(casePrefix_ + ".cpl");
39     label nCouples = 0;
41     // Count number of couples
42     {
43         IFstream couplesFile(couplesFileName);
45         if (couplesFile.good())
46         {
47             Info << "\nReading couples" << endl;
49             label matchLabel, nEntries, typeFlag;
50             label starMasterCell, rotXMasterFace;
51             label starSlaveCell, rotXSlaveFace;
53             // count the number of entries to read
54             while (!(couplesFile >> matchLabel).eof())
55             {
56                 // read number of entries and match type flag.
57                 couplesFile >> nEntries;
59                 couplesFile >> typeFlag;
61                 // read master cell and face
62                 couplesFile >> starMasterCell >> rotXMasterFace;
64                 // add number of couples from current match
65                 label nSlavesToRead = nEntries - 1;
67                 nCouples += nSlavesToRead;
69                 for (int i = 0; i < nSlavesToRead; i++)
70                 {
71                     couplesFile >> starSlaveCell >> rotXSlaveFace;
72                 }
73             }
75             Info<< "Number of couples = " << nCouples << endl << endl;
76         }
77         else
78         {
79             Info<< endl << "No couple matches defined." << endl;
80         }
81     }
83     // Read couples
84     if (nCouples > 0)
85     {
86         // read couples
87         couples_.setSize(nCouples);
88         label couplei = 0;
90         // A mesh with couples cannot be a shape mesh
91         isShapeMesh_ = false;
93         IFstream couplesFile(couplesFileName);
95         label matchLabel, nEntries, typeFlag;
96         label starMasterCell, masterCell, rotXMasterFace, rotZeroMasterFace;
97         label starSlaveCell, slaveCell, rotXSlaveFace, rotZeroSlaveFace;
99         while (!(couplesFile >> matchLabel).eof())
100         {
101             // read number of entries and match type flag.
102             // Note. At the moment, only integral matches are supported
103             couplesFile >> nEntries;
105             couplesFile >> typeFlag;
107             // read master cell and face
108             couplesFile >> starMasterCell >> rotXMasterFace;
110             // translate the cell labels
111             masterCell = starCellLabelLookup_[starMasterCell];
113             // translate the master face into rotation zero if applicable
114             if (starCellPermutation_[masterCell] > -1)
115             {
116                 const label curMasterPermutation =
117                     starCellPermutation_[masterCell];
119                 rotZeroMasterFace =
120                     sammFacePermutationTable
121                         [curMasterPermutation]
122                         [rotXMasterFace];
123             }
124             else
125             {
126                 rotZeroMasterFace = rotXMasterFace;
127             }
129             // get master face index
130             label masterFaceID =
131                 shapeFaceLookup
132                     [cellShapes_[masterCell].model().index()]
133                     [rotZeroMasterFace];
135             // number of slave faces
136             label nSlavesToRead = nEntries - 1;
138             for (int i = 0; i < nSlavesToRead; i++)
139             {
140                 couplesFile >> starSlaveCell >> rotXSlaveFace;
142                 // translate the cell labels
143                 slaveCell = starCellLabelLookup_[starSlaveCell];
145                 // translate the slave face into rotation zero if applicable
146                 if (starCellPermutation_[slaveCell] > -1)
147                 {
148                     const label curSlavePermutation =
149                         starCellPermutation_[slaveCell];
151                     rotZeroSlaveFace =
152                         sammFacePermutationTable
153                             [curSlavePermutation]
154                             [rotXSlaveFace];
155                 }
156                 else
157                 {
158                     rotZeroSlaveFace = rotXSlaveFace;
159                 }
161                 label slaveFaceID =
162                     shapeFaceLookup
163                         [cellShapes_[slaveCell].model().index()]
164                         [rotZeroSlaveFace];
166                 // Set the couple
167                 couples_.set
168                 (
169                     couplei++,
170                     new coupledFacePair
171                     (
172                         matchLabel,
173                         masterCell, masterFaceID,
174                         slaveCell, slaveFaceID,
175                         typeFlag
176                     )
177                 );
178             }
179         }
181         Info << "finished reading couples" << endl;
182     }
186 // ************************************************************************* //