BUG: createBaffles.C: converting coupled faces into baffles
[OpenFOAM-2.0.x.git] / applications / utilities / mesh / conversion / sammToFoam / readCouples.C
blobb1bcec57a6220bb370d52f6ff4d551e9bbda6f9c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 Description
25     Create intermediate mesh from SAMM files
27 \*---------------------------------------------------------------------------*/
29 #include "sammMesh.H"
30 #include "IFstream.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 void sammMesh::readCouples()
36     fileName couplesFileName(casePrefix_ + ".cpl");
38     IFstream couplesFile(couplesFileName);
40     if (couplesFile.good())
41     {
42         Info<< "\nReading couples" << endl;
44         // A mesh with couples cannot be a shape mesh
45         isShapeMesh_ = false;
47         label matchLabel, nEntries, typeFlag;
48         label masterCell, masterFace;
49         label slaveCell, slaveFace;
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;
57             couplesFile >> typeFlag;
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             }
67             // read master cell and face
68             couplesFile >> masterCell >> masterFace;
70             // get reference to master cell faces
71             faceList& masterFaces = cellFaces_[masterCell - 1];
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;
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);
94             // number of slave faces
95             label nSlavesToRead = nEntries - 1;
97             // get index for slave face add
98             label slaveToAdd = masterFaces.size();
100             // reset size of master faces to accept new (couple) faces
101             masterFaces.setSize(masterFaces.size() + nSlavesToRead);
103             for (int i = 0; i < nSlavesToRead; i++)
104             {
105                 couplesFile >> slaveCell >> slaveFace;
107                 masterFaces[slaveToAdd] =
108                     cellFaces_
109                         [
110                             slaveCell - 1
111                         ]
112                         [
113                             shapeFaceLookup
114                                 [cellShapes_[slaveCell - 1].model().index()]
115                                 [slaveFace]
116                         ].reverseFace();
118 //                 Info<< " slave cell: " << slaveCell - 1 << " index: "
119 //                     << cellShapes_[slaveCell - 1].model().index()
120 //                     << " face: " << masterFaces[slaveToAdd] << endl;
122                 slaveToAdd++;
124             }
125 //             Info<< endl;
127         }
129         // Once all couples are read, remove zero size faces from all cells
130         forAll(cellFaces_, cellI)
131         {
132             faceList& curFaces = cellFaces_[cellI];
134             label zeroSizeFound = 0;
136             forAll(curFaces, faceI)
137             {
138                 if (curFaces[faceI].empty())
139                 {
140                     zeroSizeFound++;
141                 }
142             }
144             if (zeroSizeFound > 0)
145             {
146                 // compress the list. A copy needs to made first
147                 faceList oldFaces = curFaces;
149                 curFaces.setSize(curFaces.size() - zeroSizeFound);
151                 label nFaces = 0;
153                 forAll(oldFaces, faceI)
154                 {
155                     if (oldFaces[faceI].size())
156                     {
157                         curFaces[nFaces] = oldFaces[faceI];
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         }
177 // ************************************************************************* //