blockMeshCreate.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "blockMesh.H"
30 #include "cellModel.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 void Foam::blockMesh::createPoints() const
35 {
36  const blockList& blocks = *this;
37 
38  if (verboseOutput)
39  {
40  Info<< "Creating points with scale " << scaleFactor_ << endl;
41  }
42 
43  points_.setSize(nPoints_);
44 
45  forAll(blocks, blocki)
46  {
47  const pointField& blockPoints = blocks[blocki].points();
48 
49  if (verboseOutput)
50  {
51  const label nx = blocks[blocki].density().x();
52  const label ny = blocks[blocki].density().y();
53  const label nz = blocks[blocki].density().z();
54 
55  label v0 = blocks[blocki].pointLabel(0, 0, 0);
56  label vi1 = blocks[blocki].pointLabel(1, 0, 0);
57  scalar diStart = mag(blockPoints[vi1] - blockPoints[v0]);
58 
59  label vinM1 = blocks[blocki].pointLabel(nx-1, 0, 0);
60  label vin = blocks[blocki].pointLabel(nx, 0, 0);
61  scalar diFinal = mag(blockPoints[vin] - blockPoints[vinM1]);
62 
63  label vj1 = blocks[blocki].pointLabel(0, 1, 0);
64  scalar djStart = mag(blockPoints[vj1] - blockPoints[v0]);
65  label vjnM1 = blocks[blocki].pointLabel(0, ny-1, 0);
66  label vjn = blocks[blocki].pointLabel(0, ny, 0);
67  scalar djFinal = mag(blockPoints[vjn] - blockPoints[vjnM1]);
68 
69  label vk1 = blocks[blocki].pointLabel(0, 0, 1);
70  scalar dkStart = mag(blockPoints[vk1] - blockPoints[v0]);
71  label vknM1 = blocks[blocki].pointLabel(0, 0, nz-1);
72  label vkn = blocks[blocki].pointLabel(0, 0, nz);
73  scalar dkFinal = mag(blockPoints[vkn] - blockPoints[vknM1]);
74 
75  Info<< " Block " << blocki << " cell size :" << nl
76  << " i : " << scaleFactor_*diStart << " .. "
77  << scaleFactor_*diFinal << nl
78  << " j : " << scaleFactor_*djStart << " .. "
79  << scaleFactor_*djFinal << nl
80  << " k : " << scaleFactor_*dkStart << " .. "
81  << scaleFactor_*dkFinal << nl
82  << endl;
83  }
84 
85  forAll(blockPoints, blockPointi)
86  {
87  points_
88  [
89  mergeList_
90  [
91  blockOffsets_[blocki] + blockPointi
92  ]
93  ] = scaleFactor_ * blockPoints[blockPointi];
94  }
95  }
96 }
97 
98 
99 void Foam::blockMesh::createCells() const
100 {
101  const blockList& blocks = *this;
102  const cellModel& hex = cellModel::ref(cellModel::HEX);
103 
104  if (verboseOutput)
105  {
106  Info<< "Creating cells" << endl;
107  }
108 
109  cells_.setSize(nCells_);
110 
111  label celli = 0;
112 
113  forAll(blocks, blocki)
114  {
115  const List<FixedList<label, 8>>& blockCells = blocks[blocki].cells();
116 
117  forAll(blockCells, blockCelli)
118  {
119  labelList cellPoints(blockCells[blockCelli].size());
120 
121  forAll(cellPoints, cellPointi)
122  {
123  cellPoints[cellPointi] =
124  mergeList_
125  [
126  blockCells[blockCelli][cellPointi]
127  + blockOffsets_[blocki]
128  ];
129  }
130 
131  // Construct collapsed cell and add to list
132  cells_[celli] = cellShape(hex, cellPoints, true);
133 
134  ++celli;
135  }
136  }
137 }
138 
139 
140 Foam::faceList Foam::blockMesh::createPatchFaces
141 (
142  const polyPatch& patchTopologyFaces
143 ) const
144 {
145  const blockList& blocks = *this;
146 
147  labelList blockLabels = patchTopologyFaces.polyPatch::faceCells();
148 
149  label nFaces = 0;
150 
151  forAll(patchTopologyFaces, patchTopologyFaceLabel)
152  {
153  const label blocki = blockLabels[patchTopologyFaceLabel];
154 
155  faceList blockFaces = blocks[blocki].blockShape().faces();
156 
157  forAll(blockFaces, blockFaceLabel)
158  {
159  if
160  (
161  blockFaces[blockFaceLabel]
162  == patchTopologyFaces[patchTopologyFaceLabel]
163  )
164  {
165  nFaces +=
166  blocks[blocki].boundaryPatches()[blockFaceLabel].size();
167  }
168  }
169  }
170 
171 
172  faceList patchFaces(nFaces);
173  face quadFace(4);
174  label faceLabel = 0;
175 
176  forAll(patchTopologyFaces, patchTopologyFaceLabel)
177  {
178  const label blocki = blockLabels[patchTopologyFaceLabel];
179 
180  faceList blockFaces = blocks[blocki].blockShape().faces();
181 
182  forAll(blockFaces, blockFaceLabel)
183  {
184  if
185  (
186  blockFaces[blockFaceLabel]
187  == patchTopologyFaces[patchTopologyFaceLabel]
188  )
189  {
190  const List<FixedList<label, 4>>& blockPatchFaces =
191  blocks[blocki].boundaryPatches()[blockFaceLabel];
192 
193  forAll(blockPatchFaces, blockFaceLabel)
194  {
195  // Lookup the face points
196  // and collapse duplicate point labels
197 
198  quadFace[0] =
199  mergeList_
200  [
201  blockPatchFaces[blockFaceLabel][0]
202  + blockOffsets_[blocki]
203  ];
204 
205  label nUnique = 1;
206 
207  for
208  (
209  label facePointLabel = 1;
210  facePointLabel < 4;
211  facePointLabel++
212  )
213  {
214  quadFace[nUnique] =
215  mergeList_
216  [
217  blockPatchFaces[blockFaceLabel][facePointLabel]
218  + blockOffsets_[blocki]
219  ];
220 
221  if (quadFace[nUnique] != quadFace[nUnique-1])
222  {
223  nUnique++;
224  }
225  }
226 
227  if (quadFace[nUnique-1] == quadFace[0])
228  {
229  nUnique--;
230  }
231 
232  if (nUnique == 4)
233  {
234  patchFaces[faceLabel++] = quadFace;
235  }
236  else if (nUnique == 3)
237  {
238  patchFaces[faceLabel++] = face
239  (
241  );
242  }
243  // else the face has collapsed to an edge or point
244  }
245  }
246  }
247  }
248 
249  patchFaces.setSize(faceLabel);
250 
251  return patchFaces;
252 }
253 
254 
255 void Foam::blockMesh::createPatches() const
256 {
257  const polyPatchList& topoPatches = topology().boundaryMesh();
258 
259  if (verboseOutput)
260  {
261  Info<< "Creating patches" << endl;
262  }
263 
264  patches_.setSize(topoPatches.size());
265 
266  forAll(topoPatches, patchi)
267  {
268  patches_[patchi] = createPatchFaces(topoPatches[patchi]);
269  }
270 }
271 
272 
273 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::cellModel::HEX
hex
Definition: cellModel.H:81
quadFace
face quadFace(4)
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
blockMesh.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
cellModel.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::polyPatchList
PtrList< polyPatch > polyPatchList
container classes for polyPatch
Definition: polyPatchList.H:47
Foam::cellModel::ref
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
Definition: cellModels.C:157
Foam::List< label >::subList
SubList< label > subList
Declare type of subList.
Definition: List.H:114
Foam::hex
IOstream & hex(IOstream &io)
Definition: IOstream.H:437
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::blockList
PtrList< block > blockList
A PtrList of blocks.
Definition: blockList.H:47