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