blockDescriptor.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-2019 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 \*---------------------------------------------------------------------------*/
25 
26 #include "blockDescriptor.H"
27 #include "blockMesh.H"
28 #include "blockMeshTools.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 void Foam::blockDescriptor::check(const Istream& is)
33 {
34  forAll(blockShape_, pi)
35  {
36  if (blockShape_[pi] < 0)
37  {
39  << "Negative point label " << blockShape_[pi]
40  << " in block " << *this
41  << exit(FatalIOError);
42  }
43  else if (blockShape_[pi] >= vertices_.size())
44  {
46  << "Point label " << blockShape_[pi]
47  << " out of range 0.." << vertices_.size() - 1
48  << " in block " << *this
49  << exit(FatalIOError);
50  }
51  }
52 
53  const faceList faces(blockShape_.faces());
54 
55  // Check each face is outward-pointing with respect to the block centre
56  label outwardFaceCount = 0;
57  boolList correctFaces(faces.size(), true);
58 
59  forAll(faces, i)
60  {
61  const point faceCentre(faces[i].centre(vertices_));
62  const vector faceArea(faces[i].area(vertices_));
63 
64  if (mag(faceArea) > small)
65  {
66  bool outwardFace = false;
67  forAll(faces, j)
68  {
69  if (j != i)
70  {
71  if
72  (
73  ((faceCentre - faces[j].centre(vertices_)) & faceArea)
74  > 0
75  )
76  {
77  outwardFace = true;
78  }
79  }
80  }
81 
82  if (outwardFace)
83  {
84  outwardFaceCount++;
85  }
86  else
87  {
88  correctFaces[i] = false;
89  }
90  }
91  else
92  {
93  outwardFaceCount++;
94  }
95  }
96 
97  // If all faces are inward-pointing the block is inside-out
98  if (outwardFaceCount == 0)
99  {
101  << "Block " << *this << " is inside-out"
102  << exit(FatalIOError);
103  }
104  else if (outwardFaceCount != faces.size())
105  {
107  << "Block " << *this << " has inward-pointing faces"
108  << nl << " ";
109 
110  forAll(correctFaces, i)
111  {
112  if (!correctFaces[i])
113  {
114  FatalIOError<< faces[i] << token::SPACE;
115  }
116  }
117 
119  }
120 }
121 
122 
123 void Foam::blockDescriptor::findCurvedFaces()
124 {
125  const faceList blockFaces(blockShape().faces());
126 
127  forAll(blockFaces, blockFacei)
128  {
129  forAll(faces_, facei)
130  {
131  if
132  (
134  (
135  faces_[facei].vertices(),
136  blockFaces[blockFacei]
137  )
138  )
139  {
140  curvedFaces_[blockFacei] = facei;
141  nCurvedFaces_++;
142  break;
143  }
144  }
145  }
146 }
147 
148 
149 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
150 
152 (
153  const cellShape& bshape,
154  const pointField& vertices,
155  const blockEdgeList& edges,
156  const blockFaceList& faces,
157  const Vector<label>& density,
158  const UList<gradingDescriptors>& expand,
159  const word& zoneName
160 )
161 :
162  vertices_(vertices),
163  edges_(edges),
164  faces_(faces),
165  blockShape_(bshape),
166  density_(density),
167  expand_(expand),
168  zoneName_(zoneName),
169  curvedFaces_(-1),
170  nCurvedFaces_(0)
171 {
172  if (expand_.size() != 12)
173  {
175  << "Unknown definition of expansion ratios"
176  << exit(FatalError);
177  }
178 
179  findCurvedFaces();
180 }
181 
182 
184 (
185  const dictionary& dict,
186  const label index,
187  const pointField& vertices,
188  const blockEdgeList& edges,
189  const blockFaceList& faces,
190  Istream& is
191 )
192 :
193  vertices_(vertices),
194  edges_(edges),
195  faces_(faces),
196  density_(),
197  expand_(12, gradingDescriptors()),
198  zoneName_(),
199  curvedFaces_(-1),
200  nCurvedFaces_(0)
201 {
202  // Read cell model and list of vertices (potentially with variables)
203  word model(is);
204  blockShape_ = cellShape
205  (
206  model,
207  blockMeshTools::read<label>
208  (
209  is,
210  dict.subOrEmptyDict("namedVertices")
211  )
212  );
213 
214  // Examine next token
215  token t(is);
216 
217  // Optional zone name
218  if (t.isWord())
219  {
220  zoneName_ = t.wordToken();
221 
222  // Examine next token
223  is >> t;
224  }
225  is.putBack(t);
226 
227  if (t.isPunctuation())
228  {
229  // New-style: read a list of 3 values
230  if (t.pToken() == token::BEGIN_LIST)
231  {
232  is >> density_;
233  }
234  else
235  {
237  (
238  is
239  ) << "incorrect token while reading n, expected '(', found "
240  << t.info()
241  << exit(FatalIOError);
242  }
243  }
244  else
245  {
246  // Old-style: read three labels
247  is >> density_.x()
248  >> density_.y()
249  >> density_.z();
250  }
251 
252  is >> t;
253  if (!t.isWord())
254  {
255  is.putBack(t);
256  }
257 
258  List<gradingDescriptors> expRatios(is);
259 
260  if (expRatios.size() == 1)
261  {
262  // Identical in x/y/z-directions
263  expand_ = expRatios[0];
264  }
265  else if (expRatios.size() == 3)
266  {
267  // x-direction
268  expand_[0] = expRatios[0];
269  expand_[1] = expRatios[0];
270  expand_[2] = expRatios[0];
271  expand_[3] = expRatios[0];
272 
273  // y-direction
274  expand_[4] = expRatios[1];
275  expand_[5] = expRatios[1];
276  expand_[6] = expRatios[1];
277  expand_[7] = expRatios[1];
278 
279  // z-direction
280  expand_[8] = expRatios[2];
281  expand_[9] = expRatios[2];
282  expand_[10] = expRatios[2];
283  expand_[11] = expRatios[2];
284  }
285  else if (expRatios.size() == 12)
286  {
287  expand_ = expRatios;
288  }
289  else
290  {
292  << "Unknown definition of expansion ratios: " << expRatios
293  << exit(FatalIOError);
294  }
295 
297  {
298  check(is);
299  }
300 
301  findCurvedFaces();
302 }
303 
304 
305 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
306 
309 {
310  // Caches points for curvature correction
312 
313  // Set local variables for mesh specification
314  const label ni = density_.x();
315  const label nj = density_.y();
316  const label nk = density_.z();
317 
318  facePoints[0].setSize((nj + 1)*(nk + 1));
319  facePoints[1].setSize((nj + 1)*(nk + 1));
320 
321  for (label j=0; j<=nj; j++)
322  {
323  for (label k=0; k<=nk; k++)
324  {
325  facePoints[0][facePointLabel(0, j, k)] =
326  points[pointLabel(0, j, k)];
327  facePoints[1][facePointLabel(1, j, k)] =
328  points[pointLabel(ni, j, k)];
329  }
330  }
331 
332  facePoints[2].setSize((ni + 1)*(nk + 1));
333  facePoints[3].setSize((ni + 1)*(nk + 1));
334 
335  for (label i=0; i<=ni; i++)
336  {
337  for (label k=0; k<=nk; k++)
338  {
339  facePoints[2][facePointLabel(2, i, k)] =
340  points[pointLabel(i, 0, k)];
341  facePoints[3][facePointLabel(3, i, k)] =
342  points[pointLabel(i, nj, k)];
343  }
344  }
345 
346  facePoints[4].setSize((ni + 1)*(nj + 1));
347  facePoints[5].setSize((ni + 1)*(nj + 1));
348 
349  for (label i=0; i<=ni; i++)
350  {
351  for (label j=0; j<=nj; j++)
352  {
353  facePoints[4][facePointLabel(4, i, j)] =
354  points[pointLabel(i, j, 0)];
355  facePoints[5][facePointLabel(5, i, j)] =
356  points[pointLabel(i, j, nk)];
357  }
358  }
359 
360  return facePoints;
361 }
362 
363 
365 (
366  FixedList<pointField, 6>& facePoints
367 ) const
368 {
369  forAll(curvedFaces_, blockFacei)
370  {
371  if (curvedFaces_[blockFacei] != -1)
372  {
373  faces_[curvedFaces_[blockFacei]].project
374  (
375  *this,
376  blockFacei,
377  facePoints[blockFacei]
378  );
379  }
380  }
381 }
382 
383 
385 (
386  Ostream& os,
387  const label val,
388  const dictionary& d
389 )
390 {
391  const dictionary* varDictPtr = d.subDictPtr("namedBlocks");
392  if (varDictPtr)
393  {
394  blockMeshTools::write(os, val, *varDictPtr);
395  }
396  else
397  {
398  os << val;
399  }
400 }
401 
402 
403 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
404 
406 {
407  const cellShape& bshape = bd.blockShape();
408  const labelList& blockLabels = bshape;
409 
410  os << bshape.model().name() << " (";
411 
412  forAll(blockLabels, labelI)
413  {
414  if (labelI)
415  {
416  os << ' ';
417  }
418  os << blockLabels[labelI];
419  }
420  os << ')';
421 
422  if (bd.zoneName().size())
423  {
424  os << ' ' << bd.zoneName();
425  }
426 
427  os << ' ' << bd.density()
428  << " simpleGrading (";
429 
430 
431  const List<gradingDescriptors>& expand = bd.expand_;
432 
433  // Can we use a compact notation?
434  if
435  (
436  // x-direction
437  (
438  expand[0] == expand[1]
439  && expand[0] == expand[2]
440  && expand[0] == expand[3]
441  )
442  && // y-direction
443  (
444  expand[4] == expand[5]
445  && expand[4] == expand[6]
446  && expand[4] == expand[7]
447  )
448  && // z-direction
449  (
450  expand[8] == expand[9]
451  && expand[8] == expand[10]
452  && expand[8] == expand[11]
453  )
454  )
455  {
456  os << expand[0] << ' ' << expand[4] << ' ' << expand[8];
457  }
458  else
459  {
460  forAll(expand, edgei)
461  {
462  if (edgei)
463  {
464  os << ' ';
465  }
466  os << expand[edgei];
467  }
468  }
469 
470 
471  os << ")";
472 
473  return os;
474 }
475 
476 
477 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
bool isWord() const
Definition: tokenI.H:261
punctuationToken pToken() const
Definition: tokenI.H:248
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:54
const Vector< label > & density() const
Return the mesh density (number of cells) in the i,j,k directions.
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:391
const word & wordToken() const
Definition: tokenI.H:266
An analytical geometric cellShape.
Definition: cellShape.H:69
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Takes the description of the block and the list of curved edges and creates a list of points on edges...
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A token holds items read from Istream.
Definition: token.H:72
List< face > faceList
Definition: faceListFwd.H:43
void putBack(const token &)
Put back token.
Definition: Istream.C:30
const Cmpt & z() const
Definition: VectorI.H:87
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
label k
Boltzmann constant.
FixedList< pointField, 6 > facePoints(const pointField &points) const
Return the list of face-points for all of the faces of the block.
const Cmpt & y() const
Definition: VectorI.H:81
static void write(Ostream &, const label blocki, const dictionary &)
Write block index with dictionary lookup.
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
const cellShape & blockShape() const
Return the block shape.
void write(Ostream &, const label, const dictionary &)
Write with dictionary lookup.
blockDescriptor(const cellShape &, const pointField &vertices, const blockEdgeList &, const blockFaceList &, const Vector< label > &density, const UList< gradingDescriptors > &expand, const word &zoneName="")
Construct from components. Optional cellSet/zone name.
label facePointLabel(const label facei, const label i, const label j) const
Face vertex label offset for a particular i,j,k position.
faceList faces() const
Faces of this cell.
Definition: cellShapeI.H:180
static const labelSphericalTensor labelI(1)
Identity labelTensor.
const pointField & points
A class for handling words, derived from string.
Definition: word.H:59
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
const Cmpt & x() const
Definition: VectorI.H:75
const dictionary * subDictPtr(const word &) const
Find and return a sub-dictionary pointer if present.
Definition: dictionary.C:952
void correctFacePoints(FixedList< pointField, 6 > &) const
Correct the location of the given face-points.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
const pointField & vertices() const
Reference to point field defining the block mesh.
static Switch checkBlockFaceOrientation
Switch checking block face orientation.
Definition: blockMesh.H:204
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
static bool sameVertices(const face &, const face &)
Return true if the faces have the same vertices.
Definition: face.C:150
const cellModel & model() const
Model reference.
Definition: cellShapeI.H:106
vector point
Point is a vector.
Definition: point.H:41
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:335
Ostream & operator<<(Ostream &, const ensightPart &)
label pointLabel(const label i, const label j, const label k) const
Vertex label offset for a particular i,j,k position.
dimensioned< scalar > mag(const dimensioned< Type > &)
void setSize(const label)
Dummy setSize function.
Definition: FixedListI.H:183
const word & zoneName() const
Return the (optional) zone name.
const word & name() const
Return model name.
Definition: cellModelI.H:38
List of gradingDescriptor for the sections of a block with additional IO functionality.
const blockFaceList & faces() const
Return reference to the list of curved faces.
bool isPunctuation() const
Definition: tokenI.H:243
dictionary subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary as a copy, or.
Definition: dictionary.C:1013
IOerror FatalIOError