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) 2011-2016 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 files from PROSTAR files
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "starMesh.H"
30 #include "Time.H"
31 #include "wallPolyPatch.H"
32 #include "oldCyclicPolyPatch.H"
33 #include "symmetryPolyPatch.H"
34 #include "preservePatchTypes.H"
35 #include "IFstream.H"
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 void Foam::starMesh::readBoundary()
40 {
41  label nPatches=0, nFaces=0;
42  labelList nPatchFaces(1000);
43 
44  label lineIndex, starLabel;
45  label starRegion, configNumber;
46 
48  labelList pointLabelsTri(3);
49 
50  labelList patchLabels(1000, label(-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 Star 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 >> starLabel;
82  }
83 
84  boundaryFile >> starRegion;
85  boundaryFile >> configNumber;
86  boundaryFile >> patchType;
87 
88  // Build translation table to convert star patch to foam patch
89  label patchLabel = patchLabels[starRegion];
90  if (patchLabel == -1)
91  {
92  patchLabel = nPatches;
93  patchLabels[starRegion] = patchLabel;
94  patchTypes_[patchLabel] = patchType;
95  patchNames_[patchLabel] = patchType + name(starRegion);
96 
97  nPatches++;
98 
99  Info<< "Star region " << starRegion
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 boundary to " << nPatches
111  << nl << endl;
112 
113  nPatchFaces.setSize(nPatches);
114  }
115  else
116  {
118  << "Cannot read file "
119  << boundaryFileName
120  << abort(FatalError);
121  }
122  }
123 
124  if (nPatches > 0)
125  {
126  boundary_.setSize(nPatchFaces.size());
127  patchTypes_.setSize(nPatchFaces.size());
128  patchNames_.setSize(nPatchFaces.size());
129 
130  // size the lists and reset the counters to be used again
131  forAll(boundary_, patchLabel)
132  {
133  boundary_[patchLabel].setSize(nPatchFaces[patchLabel]);
134 
135  nPatchFaces[patchLabel] = 0;
136  }
137 
138  IFstream boundaryFile(boundaryFileName);
139 
140  for (label facei=0; facei<nFaces; facei++)
141  {
142  boundaryFile >> lineIndex;
143 
144  for (int i = 0; i < 4; i++)
145  {
146  boundaryFile >> starLabel;
147 
148  // convert Star label to Foam point label
149  // through lookup-list starPointLabelLookup_
150  pointLabels[i] = starPointLabelLookup_[starLabel];
151 
152  if (pointLabels[i] < 0)
153  {
154  Info<< "Boundary file not consistent with vertex file\n"
155  << "Star vertex number " << starLabel
156  << " does not exist\n";
157  }
158 
159  }
160 
161  boundaryFile >> starRegion;
162  label patchLabel = patchLabels[starRegion];
163 
164  boundaryFile >> configNumber;
165  boundaryFile >> patchType;
166 
167  if // Triangle
168  (
169  pointLabels[2] == pointLabels[3]
170  )
171  {
172  //Info<< "Converting collapsed quad into triangle"
173  // << " for face " << facei
174  // << " in Star boundary " << lineIndex << endl;
175 
176  pointLabelsTri[0] = pointLabels[0];
177  pointLabelsTri[1] = pointLabels[1];
178  pointLabelsTri[2] = pointLabels[2];
179 
180  boundary_[patchLabel][nPatchFaces[patchLabel]]
181  = face(pointLabelsTri);
182  }
183  else
184  {
185  boundary_[patchLabel][nPatchFaces[patchLabel]]
186  = face(pointLabels);
187  }
188 
189  // increment counter of faces in current patch
190  nPatchFaces[patchLabel]++;
191  }
192 
193  forAll(boundary_, patchLabel)
194  {
195  word patchType = patchTypes_[patchLabel];
196 
197  if (patchType == "SYMP")
198  {
199  patchTypes_[patchLabel] = symmetryPolyPatch::typeName;
200  }
201  else if (patchType == "WALL")
202  {
203  patchTypes_[patchLabel] = wallPolyPatch::typeName;
204  }
205  else if (patchType == "CYCL")
206  {
207  // incorrect. should be cyclicPatch but this
208  // requires info on connected faces.
209  patchTypes_[patchLabel] = oldCyclicPolyPatch::typeName;
210  }
211  else
212  {
213  patchTypes_[patchLabel] = polyPatch::typeName;
214  }
215 
216  Info<< "Foam patch " << patchLabel
217  << " is of type " << patchTypes_[patchLabel]
218  << " with name " << patchNames_[patchLabel] << endl;
219  }
220  }
221  else
222  {
224  << "no boundary faces in file "
225  << boundaryFileName
226  << endl;
227  }
228 
229  patchPhysicalTypes_.setSize(patchTypes_.size());
230 
231  PtrList<dictionary> patchDicts;
232 
234  (
235  runTime_,
236  runTime_.constant(),
238  patchNames_,
239  patchDicts,
240  defaultFacesName_,
241  defaultFacesType_
242  );
243 
244  forAll(patchDicts, patchi)
245  {
246  if (patchDicts.set(patchi))
247  {
248  const dictionary& dict = patchDicts[patchi];
249  dict.readIfPresent("type", patchTypes_[patchi]);
250  dict.readIfPresent("physicalType", patchPhysicalTypes_[patchi]);
251  }
252  }
253 }
254 
255 
256 // ************************************************************************* //
label nPatches
Definition: readKivaGrid.H:402
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:309
labelList pointLabels(nPoints,-1)
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
preservePatchTypes
static const char nl
Definition: Ostream.H:262
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
void preservePatchTypes(const objectRegistry &obr, const word &meshInstance, const fileName &meshDir, const wordList &patchNames, PtrList< dictionary > &patchDicts, const word &defaultFacesName, word &defaultFacesType)
Preserve patch types.
void setSize(const label)
Reset size of List.
Definition: List.C:295
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
messageStream Info
PtrList< dictionary > patchDicts
Definition: readKivaGrid.H:537