createBoundaryFaces.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 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 // Specialist version of face comparison to deal with
34 // PROSTAR boundary format idiosyncracies
35 bool Foam::starMesh::starEqualFace
36 (
37  const face& boundaryFace,
38  const face& cellFace
39 ) const
40 {
41  // A PROSTAR boundary face is defined by 4 vertices irrespective
42  // of its topology.
43  // In order to deal with all possibilities, cell face is
44  // considered equal if three of the vertices are the same.
45  bool cellFaceHappy = false;
46 
47  label nEqual = 0;
48 
49  forAll(cellFace, cellFaceLabelI)
50  {
51  const label curCellFaceLabel = cellFace[cellFaceLabelI];
52 
53  forAll(boundaryFace, bouFaceLabelI)
54  {
55  if (boundaryFace[bouFaceLabelI] == curCellFaceLabel)
56  {
57  nEqual++;
58 
59  break;
60  }
61  }
62  }
63 
64  if (nEqual >= 3)
65  {
66  cellFaceHappy = true;
67  }
68 
69  // Boundary face is happy if all of its vertices are recognised
70  bool boundaryFaceHappy = true;
71 
72  forAll(boundaryFace, bouFaceLabelI)
73  {
74  const label curBouFaceLabel = boundaryFace[bouFaceLabelI];
75 
76  bool found = false;
77 
78  forAll(cellFace, cellFaceLabelI)
79  {
80  if (curBouFaceLabel == cellFace[cellFaceLabelI])
81  {
82  found = true;
83  break;
84  }
85  }
86 
87  boundaryFaceHappy = boundaryFaceHappy && found;
88  }
89 
90  return (cellFaceHappy && boundaryFaceHappy);
91 }
92 
93 
94 void Foam::starMesh::markBoundaryFaces()
95 {
96  // set size of mark lists for the boundary
97  boundaryCellIDs_.setSize(boundary_.size());
98  boundaryCellFaceIDs_.setSize(boundary_.size());
99 
100  forAll(boundary_, patchi)
101  {
102  const faceList& patchFaces = boundary_[patchi];
103 
104  // set size of patch lists
105  labelList& curBoundaryCellIDs = boundaryCellIDs_[patchi];
106  labelList& curBoundaryCellFaceIDs = boundaryCellFaceIDs_[patchi];
107 
108  curBoundaryCellIDs.setSize(patchFaces.size());
109  curBoundaryCellFaceIDs.setSize(patchFaces.size());
110 
111  const labelListList& PointCells = pointCells();
112 
113  forAll(patchFaces, facei)
114  {
115  bool found = false;
116 
117  const face& curFace = patchFaces[facei];
118  const labelList& facePoints = curFace;
119 
120  forAll(facePoints, pointi)
121  {
122  const labelList& facePointCells =
123  PointCells[facePoints[pointi]];
124 
125  forAll(facePointCells, celli)
126  {
127  const label curCellIndex = facePointCells[celli];
128 
129  const faceList& curCellFaces =
130  cellFaces_[curCellIndex];
131 
132  forAll(curCellFaces, cellFacei)
133  {
134  if (starEqualFace(curFace, curCellFaces[cellFacei]))
135  {
136  // Found the cell face corresponding to this face
137  found = true;
138 
139  // Set boundary face to the corresponding cell face
140  curBoundaryCellIDs[facei] = curCellIndex;
141  curBoundaryCellFaceIDs[facei] = cellFacei;
142  }
143  if (found) break;
144  }
145  if (found) break;
146  }
147  if (found) break;
148  }
149  if (!found)
150  {
152  << "Face " << facei
153  << " does not have neighbour cell."
154  << " Face : " << endl << curFace << endl
155  << "PROSTAR Command: vset,news,vlis";
156 
157  forAll(curFace, spI)
158  {
159  if (curFace[spI] > -1 && curFace[spI] < starPointID_.size())
160  {
161  Info<< "," << starPointID_[curFace[spI]];
162  }
163  else
164  {
165  Info<< ",???";
166  }
167  }
168 
169  FatalError
170  << " $ bset,add,vset,all"
171  << abort(FatalError);
172  }
173  }
174  }
175 }
176 
177 
178 void Foam::starMesh::collectBoundaryFaces()
179 {
180  Info<< "Collecting boundary faces" << endl;
181  forAll(boundary_, patchi)
182  {
183  faceList& patchFaces = boundary_[patchi];
184 
185  // set size of patch lists
186  const labelList& curBoundaryCellIDs = boundaryCellIDs_[patchi];
187  const labelList& curBoundaryCellFaceIDs = boundaryCellFaceIDs_[patchi];
188 
189  forAll(curBoundaryCellIDs, facei)
190  {
191  patchFaces[facei] =
192  cellFaces_[curBoundaryCellIDs[facei]]
193  [curBoundaryCellFaceIDs[facei]];
194  }
195  }
196 
197  Info<< "Finished collecting boundary faces" << endl;
198 }
199 
200 
201 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void setSize(const label)
Reset size of List.
Definition: List.C:295
label patchi
messageStream Info
bool found