createBoundaryFaces.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 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 idiosyncrasies
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  boundaryCellIndices_.setSize(boundary_.size());
98  boundaryCellFaceIndices_.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 = boundaryCellIndices_[patchi];
106  labelList& curBoundaryCellFaceIDs = boundaryCellFaceIndices_[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
160  (
161  curFace[spI] > -1
162  && curFace[spI] < starPointIndex_.size()
163  )
164  {
165  Info<< "," << starPointIndex_[curFace[spI]];
166  }
167  else
168  {
169  Info<< ",???";
170  }
171  }
172 
173  FatalError
174  << " $ bset,add,vset,all"
175  << abort(FatalError);
176  }
177  }
178  }
179 }
180 
181 
182 void Foam::starMesh::collectBoundaryFaces()
183 {
184  Info<< "Collecting boundary faces" << endl;
185  forAll(boundary_, patchi)
186  {
187  faceList& patchFaces = boundary_[patchi];
188 
189  // set size of patch lists
190  const labelList& curBoundaryCellIDs = boundaryCellIndices_[patchi];
191  const labelList& curBoundaryCellFaceIDs =
192  boundaryCellFaceIndices_[patchi];
193 
194  forAll(curBoundaryCellIDs, facei)
195  {
196  patchFaces[facei] =
197  cellFaces_[curBoundaryCellIDs[facei]]
198  [curBoundaryCellFaceIDs[facei]];
199  }
200  }
201 
202  Info<< "Finished collecting boundary faces" << endl;
203 }
204 
205 
206 // ************************************************************************* //
bool found
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void setSize(const label)
Reset size of List.
Definition: List.C:281
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label patchi
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
errorManip< error > abort(error &err)
Definition: errorManip.H:131
messageStream Info
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
error FatalError
List< face > faceList
Definition: faceListFwd.H:41