initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / mesh / conversion / starToFoam / readBoundary.C
blob7bc9274247e4d31fa5a38ca3998899c550b2e128
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 PROSTAR files
28 \*---------------------------------------------------------------------------*/
30 #include "starMesh.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 starMesh::readBoundary()
42     label nPatches=0, nFaces=0;
43     labelList nPatchFaces(1000);
45     label lineIndex, starLabel;
46     label starRegion, 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 Star 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 >> starLabel;
83                 }
85                 boundaryFile >> starRegion;
86                 boundaryFile >> configNumber;
87                 boundaryFile >> patchType;
89                 // Build translation table to convert star patch to foam patch
90                 label patchLabel = patchLabels[starRegion];
91                 if (patchLabel == -1)
92                 {
93                     patchLabel = nPatches;
94                     patchLabels[starRegion] = patchLabel;
95                     patchTypes_[patchLabel] = patchType;
96                     patchNames_[patchLabel] = patchType + name(starRegion);
98                     nPatches++;
100                     Info<< "Star region " << starRegion
101                         << " with type " << patchType
102                         << " is now Foam patch " << patchLabel << endl;
104                 }
106                 nPatchFaces[patchLabel]++;
107             }
110             Info<< nl
111                 << "Setting size of boundary to " << nPatches
112                 << nl << endl;
114             nPatchFaces.setSize(nPatches);
115         }
116         else
117         {
118             FatalErrorIn("starMesh::readBoundary()")
119                 << "Cannot read file "
120                 << boundaryFileName
121                 << abort(FatalError);
122         }
123     }
125     if (nPatches > 0)
126     {
127         boundary_.setSize(nPatchFaces.size());
128         patchTypes_.setSize(nPatchFaces.size());
129         patchNames_.setSize(nPatchFaces.size());
131         // size the lists and reset the counters to be used again
132         forAll(boundary_, patchLabel)
133         {
134             boundary_[patchLabel].setSize(nPatchFaces[patchLabel]);
136             nPatchFaces[patchLabel] = 0;
137         }
139         IFstream boundaryFile(boundaryFileName);
141         for (label faceI=0; faceI<nFaces; faceI++)
142         {
143             boundaryFile >> lineIndex;
145             for (int i = 0; i < 4; i++)
146             {
147                 boundaryFile >> starLabel;
149                 // convert Star label to Foam point label
150                 // through lookup-list starPointLabelLookup_
151                 pointLabels[i] = starPointLabelLookup_[starLabel];
153                 if (pointLabels[i] < 0)
154                 {
155                     Info<< "Boundary file not consistent with vertex file\n"
156                         << "Star vertex number " << starLabel
157                         << " does not exist\n";
158                 }
160             }
162             boundaryFile >> starRegion;
163             label patchLabel = patchLabels[starRegion];
165             boundaryFile >> configNumber;
166             boundaryFile >> patchType;
168             if   // Triangle
169             (
170                 pointLabels[2] == pointLabels[3]
171             )
172             {
173                 //Info<< "Converting collapsed quad into triangle"
174                 //    << " for face " << faceI
175                 //    << " in Star boundary " << lineIndex << endl;
177                 pointLabelsTri[0] = pointLabels[0];
178                 pointLabelsTri[1] = pointLabels[1];
179                 pointLabelsTri[2] = pointLabels[2];
181                 boundary_[patchLabel][nPatchFaces[patchLabel]]
182                     = face(pointLabelsTri);
183             }
184             else
185             {
186                 boundary_[patchLabel][nPatchFaces[patchLabel]]
187                     = face(pointLabels);
188             }
189             
190             // increment counter of faces in current patch
191             nPatchFaces[patchLabel]++;
192         }
194         forAll(boundary_, patchLabel)
195         {
196             word patchType = patchTypes_[patchLabel];
198             if (patchType == "SYMP")
199             {
200                 patchTypes_[patchLabel] = symmetryPolyPatch::typeName;
201             }
202             else if (patchType == "WALL")
203             {
204                 patchTypes_[patchLabel] = wallPolyPatch::typeName;
205             }
206             else if (patchType == "CYCL")
207             {
208                 // incorrect. should be cyclicPatch but this
209                 // requires info on connected faces.
210                 patchTypes_[patchLabel] = cyclicPolyPatch::typeName;
211             }
212             else
213             {
214                 patchTypes_[patchLabel] = polyPatch::typeName;
215             }
217             Info<< "Foam patch " << patchLabel
218                 << " is of type " << patchTypes_[patchLabel]
219                 << " with name " << patchNames_[patchLabel] << endl;
220         }
221     }
222     else
223     {
224         WarningIn("void starMesh::readBoundary()")
225             << "no boundary faces in file "
226             << boundaryFileName
227             << endl;
228     }
230     patchPhysicalTypes_.setSize(patchTypes_.size());
232     preservePatchTypes
233     (
234         runTime_,
235         runTime_.constant(),
236         polyMesh::defaultRegion,
237         patchNames_,
238         patchTypes_,
239         defaultFacesName_,
240         defaultFacesType_,
241         patchPhysicalTypes_
242     );
246 // ************************************************************************* //