initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / mesh / conversion / sammToFoam / readBoundary.C
blobdcd23aa5db4a5de309c8975bd896d8e0711b526e
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 files from SAMM files
28 \*---------------------------------------------------------------------------*/
30 #include "sammMesh.H"
31 #include "Time.H"
32 #include "wallPolyPatch.H"
33 #include "cyclicPolyPatch.H"
34 #include "symmetryPolyPatch.H"
35 #include "preservePatchTypes.H"
36 #include "IFstream.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 void sammMesh::readBoundary()
42     label nPatches=0, nFaces=0;
43     labelList nPatchFaces(1000);
45     label lineIndex, sammLabel;
46     label sammRegion, configNumber;
48     labelList pointLabels(4);
49     labelList pointLabelsTri(3);
51     labelList patchLabels(1000, -1);
53     word patchType;
54     patchTypes_.setSize(1000);
55     patchNames_.setSize(1000);
57     fileName boundaryFileName(casePrefix_ + ".bnd");
59     {
60         IFstream boundaryFile(boundaryFileName);
62         // Collect no. of faces (nFaces),
63         // no. of patches (nPatches)
64         // and for each of these patches the number of faces
65         // (nPatchFaces[patchLabel])
66         // and a conversion table from Samm regions to (Foam) patchLabels
68         if (boundaryFile.good())
69         {
70             forAll(nPatchFaces, faceLabel)
71             {
72                 nPatchFaces[faceLabel] = 0;
73             }
75             while ((boundaryFile >> lineIndex).good())
76             {
77                 nFaces++;
79                 // Skip point numbers
80                 for (int i=0; i<4; i++)
81                 {
82                     boundaryFile >> sammLabel;
83                 }
85                 boundaryFile >> sammRegion;
86                 boundaryFile >> configNumber;
87                 boundaryFile >> patchType;
89                 // Build translation table to convert samm patch to foam patch
90                 label patchLabel = patchLabels[sammRegion];
91                 if (patchLabel == -1)
92                 {
93                     patchLabel = nPatches;
94                     patchLabels[sammRegion] = patchLabel;
95                     patchTypes_[patchLabel] = patchType;
96                     patchNames_[patchLabel] = patchType + name(sammRegion);
98                     nPatches++;
100                     Info<< "Samm region " << sammRegion
101                         << " with type " << patchType
102                         << " is now Foam patch " << patchLabel << endl;
104                 }
106                 nPatchFaces[patchLabel]++;
107             }
110             Info<< nl
111                 << "Setting size of shapePatchList to " << nPatches
112                 << nl << endl;
114             nPatchFaces.setSize(nPatches);
115             patchTypes_.setSize(nPatches);
116             patchNames_.setSize(nPatches);
117         }
118         else
119         {
120             FatalErrorIn("void sammMesh::readBoundary()")
121                 << "Cannot read file "
122                 << boundaryFileName
123                 << abort(FatalError);
124         }
125     }
127     if (nPatches > 0)
128     {
129         boundary_.setSize(nPatchFaces.size());
130         patchTypes_.setSize(nPatchFaces.size());
131         patchNames_.setSize(nPatchFaces.size());
133         // size the lists and reset the counters to be used again
134         forAll(boundary_, patchLabel)
135         {
136             boundary_[patchLabel].setSize(nPatchFaces[patchLabel]);
138             nPatchFaces[patchLabel] = 0;
139         }
141         IFstream boundaryFile(boundaryFileName);
143         for (label faceI=0; faceI<nFaces; faceI++)
144         {
145             boundaryFile >> lineIndex;
147             for (int i = 0; i < 4; i++)
148             {
149                 boundaryFile >> sammLabel;
151                 // convert Samm label to Foam point label
152                 // through lookup-list starPointLabelLookup_
153                 pointLabels[i] = starPointLabelLookup_[sammLabel];
155                 if (pointLabels[i] < 0)
156                 {
157                     Info<< "Boundary file not consistent with vertex file\n"
158                         << "Samm vertex number " << sammLabel
159                         << " does not exist\n";
160                 }
162             }
164             boundaryFile >> sammRegion;
165             label patchLabel = patchLabels[sammRegion];
167             boundaryFile >> configNumber;
168             boundaryFile >> patchType;
170             if   // Triangle
171             (
172                 pointLabels[2] == pointLabels[3]
173             )
174             {
175                 //Info<< "Converting collapsed quad into triangle"
176                 //    << " for face " << faceI
177                 //    << " in Samm boundary " << lineIndex << endl;
179                 pointLabelsTri[0] = pointLabels[0];
180                 pointLabelsTri[1] = pointLabels[1];
181                 pointLabelsTri[2] = pointLabels[2];
183                 boundary_[patchLabel][nPatchFaces[patchLabel]]
184                     = face(pointLabelsTri);
185             }
186             else
187             {
188                 boundary_[patchLabel][nPatchFaces[patchLabel]]
189                     = face(pointLabels);
190             }
191             
192             // increment counter of faces in current patch
193             nPatchFaces[patchLabel]++;
194         }
196         forAll(boundary_, patchLabel)
197         {
198             word patchType = patchTypes_[patchLabel];
200             if (patchType == "SYMP")
201             {
202                 patchTypes_[patchLabel] = symmetryPolyPatch::typeName;
203             }
204             else if (patchType == "WALL")
205             {
206                 patchTypes_[patchLabel] = wallPolyPatch::typeName;
207             }
208             else if (patchType == "CYCL")
209             {
210                 // incorrect. should be cyclicPatch but this
211                 // requires info on connected faces.
212                 patchTypes_[patchLabel] = cyclicPolyPatch::typeName;
213             }
214             else
215             {
216                 patchTypes_[patchLabel] = polyPatch::typeName;
217             }
219             Info<< "Foam patch " << patchLabel
220                 << " is of type " << patchTypes_[patchLabel]
221                 << " with name " << patchNames_[patchLabel] << endl;
222         }
223     }
224     else
225     {
226         FatalErrorIn("sammMesh::readBoundary()")
227             << "No boundary faces in file "
228             << boundaryFileName
229             << endl;
230     }
232     patchPhysicalTypes_.setSize(patchTypes_.size());
234     preservePatchTypes
235     (
236         runTime_,
237         runTime_.constant(),
238         polyMesh::defaultRegion,
239         patchNames_,
240         patchTypes_,
241         defaultFacesName_,
242         defaultFacesType_,
243         patchPhysicalTypes_
244     );
248 // ************************************************************************* //