PDRblockCreate.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) 2019-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "PDRblock.H"
29 #include "polyMesh.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 void Foam::PDRblock::createPoints(pointField& pts) const
34 {
35  const label ni = sizes().x();
36  const label nj = sizes().y();
37  const label nk = sizes().z();
38 
39  pts.resize(nPoints());
40 
41  for (label k=0; k<=nk; ++k)
42  {
43  for (label j=0; j<=nj; ++j)
44  {
45  for (label i=0; i<=ni; ++i)
46  {
47  point& pt = pts[pointLabel(i,j,k)];
48 
49  pt.x() = grid_.x()[i];
50  pt.y() = grid_.y()[j];
51  pt.z() = grid_.z()[k];
52  }
53  }
54  }
55 }
56 
57 
58 Foam::label Foam::PDRblock::addInternalFaces
59 (
60  faceList::iterator& faceIter,
61  labelList::iterator& ownIter,
62  labelList::iterator& neiIter
63 ) const
64 {
65  const label ni = sizes().x();
66  const label nj = sizes().y();
67  const label nk = sizes().z();
68 
69  const labelList::iterator firstIter = ownIter;
70 
71  for (label k=0; k<nk; ++k)
72  {
73  for (label j=0; j<nj; ++j)
74  {
75  for (label i=0; i<ni; ++i)
76  {
77  const label celli = cellLabel(i, j, k);
78 
79  // Local Face 1 == x-max
80  if (i < ni-1)
81  {
82  auto& f = *faceIter;
83  ++faceIter;
84  f.resize(4);
85 
86  f[0] = pointLabel(i+1, j, k);
87  f[1] = pointLabel(i+1, j+1, k);
88  f[2] = pointLabel(i+1, j+1, k+1);
89  f[3] = pointLabel(i+1, j, k+1);
90 
91  *ownIter = celli;
92  *neiIter = cellLabel(i+1, j, k);
93 
94  ++ownIter;
95  ++neiIter;
96  }
97 
98  // Local Face 3 == y-max
99  if (j < nj-1)
100  {
101  auto& f = *faceIter;
102  ++faceIter;
103  f.resize(4);
104 
105  f[0] = pointLabel(i, j+1, k);
106  f[1] = pointLabel(i, j+1, k+1);
107  f[2] = pointLabel(i+1, j+1, k+1);
108  f[3] = pointLabel(i+1, j+1, k);
109 
110  *ownIter = celli;
111  *neiIter = cellLabel(i, j+1, k);
112 
113  ++ownIter;
114  ++neiIter;
115  }
116 
117  // Local Face 5 == z-max
118  if (k < nk-1)
119  {
120  auto& f = *faceIter;
121  ++faceIter;
122  f.resize(4);
123 
124  f[0] = pointLabel(i, j, k+1);
125  f[1] = pointLabel(i+1, j, k+1);
126  f[2] = pointLabel(i+1, j+1, k+1);
127  f[3] = pointLabel(i, j+1, k+1);
128 
129  *ownIter = celli;
130  *neiIter = cellLabel(i, j, k+1);
131 
132  ++ownIter;
133  ++neiIter;
134  }
135  }
136  }
137  }
138 
139  // Return the number of faces added
140  return (ownIter - firstIter);
141 }
142 
143 
144 Foam::label Foam::PDRblock::addBoundaryFaces
145 (
146  const direction shapeFacei,
147  faceList::iterator& faceIter,
148  labelList::iterator& ownIter
149 ) const
150 {
151  const label ni = sizes().x();
152  const label nj = sizes().y();
153  const label nk = sizes().z();
154 
155  const labelList::iterator firstIter = ownIter;
156 
157  switch (shapeFacei)
158  {
159  // Face 0 == x-min
160  case 0:
161  {
162  for (label k=0; k<nk; ++k)
163  {
164  for (label j=0; j<nj; ++j)
165  {
166  auto& f = *faceIter;
167  ++faceIter;
168  f.resize(4);
169 
170  f[0] = pointLabel(0, j, k);
171  f[1] = pointLabel(0, j, k+1);
172  f[2] = pointLabel(0, j+1, k+1);
173  f[3] = pointLabel(0, j+1, k);
174 
175  *ownIter = cellLabel(0, j, k);
176  ++ownIter;
177  }
178  }
179  }
180  break;
181 
182  // Face 1 == x-max
183  case 1:
184  {
185  for (label k=0; k<nk; ++k)
186  {
187  for (label j=0; j<nj; ++j)
188  {
189  auto& f = *faceIter;
190  ++faceIter;
191  f.resize(4);
192 
193  f[0] = pointLabel(ni, j, k);
194  f[1] = pointLabel(ni, j+1, k);
195  f[2] = pointLabel(ni, j+1, k+1);
196  f[3] = pointLabel(ni, j, k+1);
197 
198  *ownIter = cellLabel(ni-1, j, k);
199  ++ownIter;
200  }
201  }
202  }
203  break;
204 
205  // Face 2 == y-min
206  case 2:
207  {
208  for (label i=0; i<ni; ++i)
209  {
210  for (label k=0; k<nk; ++k)
211  {
212  auto& f = *faceIter;
213  ++faceIter;
214  f.resize(4);
215 
216  f[0] = pointLabel(i, 0, k);
217  f[1] = pointLabel(i+1, 0, k);
218  f[2] = pointLabel(i+1, 0, k+1);
219  f[3] = pointLabel(i, 0, k+1);
220 
221  *ownIter = cellLabel(i, 0, k);
222  ++ownIter;
223  }
224  }
225  }
226  break;
227 
228  // Face 3 == y-max
229  case 3:
230  {
231  for (label i=0; i<ni; ++i)
232  {
233  for (label k=0; k<nk; ++k)
234  {
235  auto& f = *faceIter;
236  ++faceIter;
237  f.resize(4);
238 
239  f[0] = pointLabel(i, nj, k);
240  f[1] = pointLabel(i, nj, k+1);
241  f[2] = pointLabel(i+1, nj, k+1);
242  f[3] = pointLabel(i+1, nj, k);
243 
244  *ownIter = cellLabel(i, nj-1, k);
245  ++ownIter;
246  }
247  }
248  }
249  break;
250 
251  // Face 4 == z-min
252  case 4:
253  {
254  for (label i=0; i<ni; ++i)
255  {
256  for (label j=0; j<nj; ++j)
257  {
258  auto& f = *faceIter;
259  ++faceIter;
260  f.resize(4);
261 
262  f[0] = pointLabel(i, j, 0);
263  f[1] = pointLabel(i, j+1, 0);
264  f[2] = pointLabel(i+1, j+1, 0);
265  f[3] = pointLabel(i+1, j, 0);
266 
267  *ownIter = cellLabel(i, j, 0);
268  ++ownIter;
269  }
270  }
271  }
272  break;
273 
274  // Face 5 == z-max
275  case 5:
276  {
277  for (label i=0; i<ni; ++i)
278  {
279  for (label j=0; j<nj; ++j)
280  {
281  auto& f = *faceIter;
282  ++faceIter;
283  f.resize(4);
284 
285  f[0] = pointLabel(i, j, nk);
286  f[1] = pointLabel(i+1, j, nk);
287  f[2] = pointLabel(i+1, j+1, nk);
288  f[3] = pointLabel(i, j+1, nk);
289 
290  *ownIter = cellLabel(i, j, nk-1);
291  ++ownIter;
292  }
293  }
294  }
295  break;
296  }
297 
298  // Return the number of faces added
299  return (ownIter - firstIter);
300 }
301 
302 
305 {
306  pointField pts(nPoints());
307 
308  faceList faces(nFaces());
309  labelList own(nFaces());
310  labelList nei(nInternalFaces());
311 
312  auto faceIter = faces.begin();
313  auto ownIter = own.begin();
314  auto neiIter = nei.begin();
315 
316  createPoints(pts);
317 
318  addInternalFaces(faceIter, ownIter, neiIter);
319 
320  // After readBoundary() we have a complete list of patches
321  // without any conflicts, and the correct size per-patch
322 
323  // Add boundary faces and adjust patch sizes
324  for (const boundaryEntry& bentry : patches_)
325  {
326  for (const label shapeFacei : bentry.faces_)
327  {
328  addBoundaryFaces(shapeFacei, faceIter, ownIter);
329  }
330  }
331 
332 
333  IOobject iomesh(io);
335 
337  (
338  iomesh,
339  std::move(pts),
340  std::move(faces),
341  std::move(own),
342  std::move(nei)
343  );
344  polyMesh& pmesh = *meshPtr;
345 
346  PtrList<polyPatch> patches(patches_.size());
347 
348  label startFace = nInternalFaces();
349 
350  label patchi = 0;
351 
352  for (const boundaryEntry& bentry : patches_)
353  {
354  patches.set
355  (
356  patchi,
358  (
359  bentry.type_,
360  bentry.name_,
361  bentry.size_,
362  startFace,
363  patchi, // index
364  pmesh.boundaryMesh()
365  )
366  );
367 
368  // physicalType?
369 
370  startFace += bentry.size_;
371  ++patchi;
372  }
373 
374  pmesh.addPatches(patches);
375 
376  return meshPtr;
377 }
378 
379 
382 {
383  if (outer_.active())
384  {
385  Info<< "Outer region is active, using blockMesh generation" << nl;
386  return meshBlockMesh(io);
387  }
388  else
389  {
390  Info<< "Outer region is inactive, using ijk generation" << nl;
391  return innerMesh(io);
392  }
393 }
394 
395 
396 // ************************************************************************* //
Foam::polyMesh::addPatches
void addPatches(PtrList< polyPatch > &plist, const bool validBoundary=true)
Add boundary patches.
Definition: polyMesh.C:961
Foam::autoPtr::New
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::PDRblock::innerMesh
autoPtr< polyMesh > innerMesh(const IOobject &io) const
Definition: PDRblockCreate.C:304
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
meshPtr
Foam::autoPtr< Foam::fvMesh > meshPtr(nullptr)
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::ijkAddressing::sizes
const labelVector & sizes() const
The (i,j,k) addressing dimensions.
Definition: ijkAddressingI.H:69
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::PtrList::set
const T * set(const label i) const
Return const pointer to element (can be nullptr),.
Definition: PtrList.H:138
polyMesh.H
Foam::IOobject::writeOpt
writeOption writeOpt() const noexcept
The write option.
Definition: IOobjectI.H:179
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::PDRblock::mesh
autoPtr< polyMesh > mesh(const IOobject &io) const
Create polyMesh for grid definition and patch information.
Definition: PDRblockCreate.C:381
Foam::ijkMesh::pointLabel
label pointLabel(const label i, const label j, const label k) const
The linear point index for an i-j-k position.
Definition: ijkMeshI.H:183
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
PDRblock.H
Foam::polyPatch::New
static autoPtr< polyPatch > New(const word &patchType, const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm)
Return pointer to a new patch created on freestore from components.
Definition: polyPatchNew.C:35
Foam::autoPtr< Foam::polyMesh >
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
Foam::nl
constexpr char nl
Definition: Ostream.H:404
f
labelList f(nPoints)
Foam::ijkMesh::nPoints
label nPoints() const
The number of mesh points (nx+1)*(ny+1)*(nz+1) in the i-j-k mesh.
Definition: ijkMeshI.H:55
Foam::List< face >
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::direction
uint8_t direction
Definition: direction.H:52
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::point
vector point
Point is a vector.
Definition: point.H:43