readCouples.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Create intermediate mesh from PROSTAR files
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "starMesh.H"
30 #include "IFstream.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 void Foam::starMesh::readCouples()
35 {
36  fileName couplesFileName(casePrefix_ + ".cpl");
37 
38  label nCouples = 0;
39 
40  // Count number of couples
41  {
42  IFstream couplesFile(couplesFileName);
43 
44  if (couplesFile.good())
45  {
46  Info<< "\nReading couples" << endl;
47 
48  label matchLabel, nEntries, typeFlag;
49  label starMasterCell, rotXMasterFace;
50  label starSlaveCell, rotXSlaveFace;
51 
52  // count the number of entries to read
53  while (!(couplesFile >> matchLabel).eof())
54  {
55  // read number of entries and match type flag.
56  couplesFile >> nEntries;
57 
58  couplesFile >> typeFlag;
59 
60  // read master cell and face
61  couplesFile >> starMasterCell >> rotXMasterFace;
62 
63  // add number of couples from current match
64  label nSlavesToRead = nEntries - 1;
65 
66  nCouples += nSlavesToRead;
67 
68  for (int i = 0; i < nSlavesToRead; i++)
69  {
70  couplesFile >> starSlaveCell >> rotXSlaveFace;
71  }
72  }
73 
74  Info<< "Number of couples = " << nCouples << endl << endl;
75  }
76  else
77  {
78  Info<< endl << "No couple matches defined." << endl;
79  }
80  }
81 
82  // Read couples
83  if (nCouples > 0)
84  {
85  // read couples
86  couples_.setSize(nCouples);
87  label couplei = 0;
88 
89  // A mesh with couples cannot be a shape mesh
90  isShapeMesh_ = false;
91 
92  IFstream couplesFile(couplesFileName);
93 
94  label matchLabel, nEntries, typeFlag;
95  label starMasterCell, masterCell, rotXMasterFace, rotZeroMasterFace;
96  label starSlaveCell, slaveCell, rotXSlaveFace, rotZeroSlaveFace;
97 
98  while (!(couplesFile >> matchLabel).eof())
99  {
100  // read number of entries and match type flag.
101  // Note. At the moment, only integral matches are supported
102  couplesFile >> nEntries;
103 
104  couplesFile >> typeFlag;
105 
106  // read master cell and face
107  couplesFile >> starMasterCell >> rotXMasterFace;
108 
109  // translate the cell labels
110  masterCell = starCellLabelLookup_[starMasterCell];
111 
112  // translate the master face into rotation zero if applicable
113  if (starCellPermutation_[masterCell] > -1)
114  {
115  const label curMasterPermutation =
116  starCellPermutation_[masterCell];
117 
118  rotZeroMasterFace =
119  sammFacePermutationTable
120  [curMasterPermutation]
121  [rotXMasterFace];
122  }
123  else
124  {
125  rotZeroMasterFace = rotXMasterFace;
126  }
127 
128  // get master face index
129  label masterFaceID =
130  shapeFaceLookup
131  [cellShapes_[masterCell].model().index()]
132  [rotZeroMasterFace];
133 
134  // number of slave faces
135  label nSlavesToRead = nEntries - 1;
136 
137  for (int i = 0; i < nSlavesToRead; i++)
138  {
139  couplesFile >> starSlaveCell >> rotXSlaveFace;
140 
141  // translate the cell labels
142  slaveCell = starCellLabelLookup_[starSlaveCell];
143 
144  // translate the slave face into rotation zero if applicable
145  if (starCellPermutation_[slaveCell] > -1)
146  {
147  const label curSlavePermutation =
148  starCellPermutation_[slaveCell];
149 
150  rotZeroSlaveFace =
151  sammFacePermutationTable
152  [curSlavePermutation]
153  [rotXSlaveFace];
154  }
155  else
156  {
157  rotZeroSlaveFace = rotXSlaveFace;
158  }
159 
160  label slaveFaceID =
161  shapeFaceLookup
162  [cellShapes_[slaveCell].model().index()]
163  [rotZeroSlaveFace];
164 
165  // Set the couple
166  couples_.set
167  (
168  couplei++,
169  new coupledFacePair
170  (
171  matchLabel,
172  masterCell, masterFaceID,
173  slaveCell, slaveFaceID,
174  typeFlag
175  )
176  );
177  }
178  }
179 
180  Info<< "finished reading couples" << endl;
181  }
182 }
183 
184 
185 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
messageStream Info