readCouples.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 SAMM files
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "sammMesh.H"
30 #include "IFstream.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 void Foam::sammMesh::readCouples()
35 {
36  fileName couplesFileName(casePrefix_ + ".cpl");
37 
38  IFstream couplesFile(couplesFileName);
39 
40  if (couplesFile.good())
41  {
42  Info<< "\nReading couples" << endl;
43 
44  // A mesh with couples cannot be a shape mesh
45  isShapeMesh_ = false;
46 
47  label matchLabel, nEntries, typeFlag;
48  label masterCell, masterFace;
49  label slaveCell, slaveFace;
50 
51  while (!(couplesFile >> matchLabel).eof())
52  {
53  // read number of entries and match type.
54  // Note. At the moment, only integral matches are supported
55  couplesFile >> nEntries;
56 
57  couplesFile >> typeFlag;
58 
59  if (typeFlag > 1)
60  {
61  Info
62  << "void sammMesh::readCouples() : "
63  << "couple " << matchLabel << " is not an integral match. "
64  << "Currently not supported" << endl;
65  }
66 
67  // read master cell and face
68  couplesFile >> masterCell >> masterFace;
69 
70  // get reference to master cell faces
71  faceList& masterFaces = cellFaces_[masterCell - 1];
72 
73 // Info<< "Master cell: " << masterCell - 1 << " index: "
74 // << cellShapes_[masterCell - 1].model().index()
75 // << " face: " <<
76 // masterFaces
77 // [
78 // shapeFaceLookup
79 // [cellShapes_[masterCell - 1].model().index()]
80 // [masterFace]
81 // ]
82 // << endl;
83 
84  // reset master face to zero size. It cannot be removed at this
85  // stage because thisw would mess up the numbering in case of
86  // more than one couple an a single master cell
87  masterFaces
88  [
89  shapeFaceLookup
90  [cellShapes_[masterCell - 1].model().index()]
91  [masterFace]
92  ].setSize(0);
93 
94  // number of slave faces
95  label nSlavesToRead = nEntries - 1;
96 
97  // get index for slave face add
98  label slaveToAdd = masterFaces.size();
99 
100  // reset size of master faces to accept new (couple) faces
101  masterFaces.setSize(masterFaces.size() + nSlavesToRead);
102 
103  for (int i = 0; i < nSlavesToRead; i++)
104  {
105  couplesFile >> slaveCell >> slaveFace;
106 
107  masterFaces[slaveToAdd] =
108  cellFaces_
109  [
110  slaveCell - 1
111  ]
112  [
113  shapeFaceLookup
114  [cellShapes_[slaveCell - 1].model().index()]
115  [slaveFace]
116  ].reverseFace();
117 
118 // Info<< " slave cell: " << slaveCell - 1 << " index: "
119 // << cellShapes_[slaveCell - 1].model().index()
120 // << " face: " << masterFaces[slaveToAdd] << endl;
121 
122  slaveToAdd++;
123 
124  }
125 // Info<< endl;
126 
127  }
128 
129  // Once all couples are read, remove zero size faces from all cells
130  forAll(cellFaces_, celli)
131  {
132  faceList& curFaces = cellFaces_[celli];
133 
134  label zeroSizeFound = 0;
135 
136  forAll(curFaces, facei)
137  {
138  if (curFaces[facei].empty())
139  {
140  zeroSizeFound++;
141  }
142  }
143 
144  if (zeroSizeFound > 0)
145  {
146  // compress the list. A copy needs to made first
147  faceList oldFaces = curFaces;
148 
149  curFaces.setSize(curFaces.size() - zeroSizeFound);
150 
151  label nFaces = 0;
152 
153  forAll(oldFaces, facei)
154  {
155  if (oldFaces[facei].size())
156  {
157  curFaces[nFaces] = oldFaces[facei];
158 
159  nFaces++;
160  }
161  }
162  }
163  }
164  }
165  else
166  {
167  Info
168  << "void sammMesh::readCouples() : "
169  << "Cannot read file "
170  << couplesFileName
171  << ". No matches defined."
172  << endl;
173  }
174 }
175 
176 
177 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
void setSize(const label)
Reset size of List.
Definition: List.C:281
messageStream Info