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-2018 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 "blockMeshTools.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 void Foam::blockDescriptor::check(const Istream& is)
32 {
33  forAll(blockShape_, pi)
34  {
35  if (blockShape_[pi] < 0)
36  {
38  << "Negative point label " << blockShape_[pi]
39  << " in block " << *this
40  << exit(FatalIOError);
41  }
42  else if (blockShape_[pi] >= vertices_.size())
43  {
45  << "Point label " << blockShape_[pi]
46  << " out of range 0.." << vertices_.size() - 1
47  << " in block " << *this
48  << exit(FatalIOError);
49  }
50  }
51 
52  const point blockCentre(blockShape_.centre(vertices_));
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  point faceCentre(faces[i].centre(vertices_));
62  vector faceArea(faces[i].area(vertices_));
63  if (mag(faceArea) > small)
64  {
65  if (((faceCentre - blockCentre) & faceArea) > 0)
66  {
67  outwardFaceCount++;
68  }
69  else
70  {
71  correctFaces[i] = false;
72  }
73  }
74  else
75  {
76  outwardFaceCount++;
77  }
78  }
79 
80  // If all faces are inward-pointing the block is inside-out
81  if (outwardFaceCount == 0)
82  {
84  << "Block " << *this << " is inside-out"
85  << exit(FatalIOError);
86  }
87  else if (outwardFaceCount != faces.size())
88  {
90  << "Block " << *this << " has inward-pointing faces"
91  << nl << " ";
92 
93  forAll(correctFaces, i)
94  {
95  if (!correctFaces[i])
96  {
97  FatalIOError<< faces[i] << token::SPACE;
98  }
99  }
100 
102  }
103 }
104 
105 
106 void Foam::blockDescriptor::findCurvedFaces()
107 {
108  const faceList blockFaces(blockShape().faces());
109 
110  forAll(blockFaces, blockFacei)
111  {
112  forAll(faces_, facei)
113  {
114  if
115  (
117  (
118  faces_[facei].vertices(),
119  blockFaces[blockFacei]
120  )
121  )
122  {
123  curvedFaces_[blockFacei] = facei;
124  nCurvedFaces_++;
125  break;
126  }
127  }
128  }
129 }
130 
131 
132 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
133 
135 (
136  const cellShape& bshape,
137  const pointField& vertices,
138  const blockEdgeList& edges,
139  const blockFaceList& faces,
140  const Vector<label>& density,
141  const UList<gradingDescriptors>& expand,
142  const word& zoneName
143 )
144 :
145  vertices_(vertices),
146  edges_(edges),
147  faces_(faces),
148  blockShape_(bshape),
149  density_(density),
150  expand_(expand),
151  zoneName_(zoneName),
152  curvedFaces_(-1),
153  nCurvedFaces_(0)
154 {
155  if (expand_.size() != 12)
156  {
158  << "Unknown definition of expansion ratios"
159  << exit(FatalError);
160  }
161 
162  findCurvedFaces();
163 }
164 
165 
167 (
168  const dictionary& dict,
169  const label index,
170  const pointField& vertices,
171  const blockEdgeList& edges,
172  const blockFaceList& faces,
173  Istream& is
174 )
175 :
176  vertices_(vertices),
177  edges_(edges),
178  faces_(faces),
179  density_(),
180  expand_(12, gradingDescriptors()),
181  zoneName_(),
182  curvedFaces_(-1),
183  nCurvedFaces_(0)
184 {
185  // Read cell model and list of vertices (potentially with variables)
186  word model(is);
187  blockShape_ = cellShape
188  (
189  model,
190  blockMeshTools::read<label>
191  (
192  is,
193  dict.subOrEmptyDict("namedVertices")
194  )
195  );
196 
197  // Examine next token
198  token t(is);
199 
200  // Optional zone name
201  if (t.isWord())
202  {
203  zoneName_ = t.wordToken();
204 
205  // Examine next token
206  is >> t;
207  }
208  is.putBack(t);
209 
210  if (t.isPunctuation())
211  {
212  // New-style: read a list of 3 values
213  if (t.pToken() == token::BEGIN_LIST)
214  {
215  is >> density_;
216  }
217  else
218  {
220  (
221  is
222  ) << "incorrect token while reading n, expected '(', found "
223  << t.info()
224  << exit(FatalIOError);
225  }
226  }
227  else
228  {
229  // Old-style: read three labels
230  is >> density_.x()
231  >> density_.y()
232  >> density_.z();
233  }
234 
235  is >> t;
236  if (!t.isWord())
237  {
238  is.putBack(t);
239  }
240 
241  List<gradingDescriptors> expRatios(is);
242 
243  if (expRatios.size() == 1)
244  {
245  // Identical in x/y/z-directions
246  expand_ = expRatios[0];
247  }
248  else if (expRatios.size() == 3)
249  {
250  // x-direction
251  expand_[0] = expRatios[0];
252  expand_[1] = expRatios[0];
253  expand_[2] = expRatios[0];
254  expand_[3] = expRatios[0];
255 
256  // y-direction
257  expand_[4] = expRatios[1];
258  expand_[5] = expRatios[1];
259  expand_[6] = expRatios[1];
260  expand_[7] = expRatios[1];
261 
262  // z-direction
263  expand_[8] = expRatios[2];
264  expand_[9] = expRatios[2];
265  expand_[10] = expRatios[2];
266  expand_[11] = expRatios[2];
267  }
268  else if (expRatios.size() == 12)
269  {
270  expand_ = expRatios;
271  }
272  else
273  {
275  << "Unknown definition of expansion ratios: " << expRatios
276  << exit(FatalIOError);
277  }
278 
279  check(is);
280 
281  findCurvedFaces();
282 }
283 
284 
285 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
286 
289 {
290  // Caches points for curvature correction
292 
293  // Set local variables for mesh specification
294  const label ni = density_.x();
295  const label nj = density_.y();
296  const label nk = density_.z();
297 
298  facePoints[0].setSize((nj + 1)*(nk + 1));
299  facePoints[1].setSize((nj + 1)*(nk + 1));
300 
301  for (label j=0; j<=nj; j++)
302  {
303  for (label k=0; k<=nk; k++)
304  {
305  facePoints[0][facePointLabel(0, j, k)] =
306  points[pointLabel(0, j, k)];
307  facePoints[1][facePointLabel(1, j, k)] =
308  points[pointLabel(ni, j, k)];
309  }
310  }
311 
312  facePoints[2].setSize((ni + 1)*(nk + 1));
313  facePoints[3].setSize((ni + 1)*(nk + 1));
314 
315  for (label i=0; i<=ni; i++)
316  {
317  for (label k=0; k<=nk; k++)
318  {
319  facePoints[2][facePointLabel(2, i, k)] =
320  points[pointLabel(i, 0, k)];
321  facePoints[3][facePointLabel(3, i, k)] =
322  points[pointLabel(i, nj, k)];
323  }
324  }
325 
326  facePoints[4].setSize((ni + 1)*(nj + 1));
327  facePoints[5].setSize((ni + 1)*(nj + 1));
328 
329  for (label i=0; i<=ni; i++)
330  {
331  for (label j=0; j<=nj; j++)
332  {
333  facePoints[4][facePointLabel(4, i, j)] =
334  points[pointLabel(i, j, 0)];
335  facePoints[5][facePointLabel(5, i, j)] =
336  points[pointLabel(i, j, nk)];
337  }
338  }
339 
340  return facePoints;
341 }
342 
343 
345 (
346  FixedList<pointField, 6>& facePoints
347 ) const
348 {
349  forAll(curvedFaces_, blockFacei)
350  {
351  if (curvedFaces_[blockFacei] != -1)
352  {
353  faces_[curvedFaces_[blockFacei]].project
354  (
355  *this,
356  blockFacei,
357  facePoints[blockFacei]
358  );
359  }
360  }
361 }
362 
363 
365 (
366  Ostream& os,
367  const label val,
368  const dictionary& d
369 )
370 {
371  const dictionary* varDictPtr = d.subDictPtr("namedBlocks");
372  if (varDictPtr)
373  {
374  blockMeshTools::write(os, val, *varDictPtr);
375  }
376  else
377  {
378  os << val;
379  }
380 }
381 
382 
383 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
384 
386 {
387  const cellShape& bshape = bd.blockShape();
388  const labelList& blockLabels = bshape;
389 
390  os << bshape.model().name() << " (";
391 
392  forAll(blockLabels, labelI)
393  {
394  if (labelI)
395  {
396  os << ' ';
397  }
398  os << blockLabels[labelI];
399  }
400  os << ')';
401 
402  if (bd.zoneName().size())
403  {
404  os << ' ' << bd.zoneName();
405  }
406 
407  os << ' ' << bd.density()
408  << " simpleGrading (";
409 
410 
411  const List<gradingDescriptors>& expand = bd.expand_;
412 
413  // Can we use a compact notation?
414  if
415  (
416  // x-direction
417  (
418  expand[0] == expand[1]
419  && expand[0] == expand[2]
420  && expand[0] == expand[3]
421  )
422  && // y-direction
423  (
424  expand[4] == expand[5]
425  && expand[4] == expand[6]
426  && expand[4] == expand[7]
427  )
428  && // z-direction
429  (
430  expand[8] == expand[9]
431  && expand[8] == expand[10]
432  && expand[8] == expand[11]
433  )
434  )
435  {
436  os << expand[0] << ' ' << expand[4] << ' ' << expand[8];
437  }
438  else
439  {
440  forAll(expand, edgei)
441  {
442  if (edgei)
443  {
444  os << ' ';
445  }
446  os << expand[edgei];
447  }
448  }
449 
450 
451  os << ")";
452 
453  return os;
454 }
455 
456 
457 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
bool isWord() const
Definition: tokenI.H:230
punctuationToken pToken() const
Definition: tokenI.H:217
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:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:380
const word & wordToken() const
Definition: tokenI.H:235
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:163
A token holds items read from Istream.
Definition: token.H:69
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:61
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:662
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:53
static const char nl
Definition: Ostream.H:265
const pointField & vertices() const
Reference to point field defining the block mesh.
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:400
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:331
point centre(const pointField &) const
Centroid of the cell.
Definition: cellShapeI.H:259
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:193
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:212
dictionary subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary as a copy, or.
Definition: dictionary.C:727
IOerror FatalIOError