blockDescriptor.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 "blockDescriptor.H"
30 #include "blockMeshTools.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 void Foam::blockDescriptor::check(const Istream& is)
35 {
36  for (const label pointi : blockShape_)
37  {
38  if (pointi < 0 || pointi >= vertices_.size())
39  {
41  << "Point label " << pointi
42  << " out of range 0.." << vertices_.size() - 1
43  << " in block " << *this
44  << exit(FatalIOError);
45  }
46  }
47 
48  const point blockCentre(blockShape_.centre(vertices_));
49  const faceList faces(blockShape_.faces());
50 
51  // Check each face is outward-pointing with respect to the block centre
52  label outwardFaceCount = 0;
53  boolList correctFaces(faces.size(), true);
54 
55  forAll(faces, i)
56  {
57  point faceCentre(faces[i].centre(vertices_));
58  vector faceNormal(faces[i].areaNormal(vertices_));
59 
60  if (mag(faceNormal) > SMALL)
61  {
62  if (((faceCentre - blockCentre) & faceNormal) > 0)
63  {
64  outwardFaceCount++;
65  }
66  else
67  {
68  correctFaces[i] = false;
69  }
70  }
71  else
72  {
73  outwardFaceCount++;
74  }
75  }
76 
77  // If all faces are inward-pointing the block is inside-out
78  if (outwardFaceCount == 0)
79  {
81  << "Block " << *this << " is inside-out"
82  << exit(FatalIOError);
83  }
84  else if (outwardFaceCount != faces.size())
85  {
87  << "Block " << *this << " has inward-pointing faces"
88  << nl << " ";
89 
90  forAll(correctFaces, i)
91  {
92  if (!correctFaces[i])
93  {
94  FatalIOError<< faces[i] << token::SPACE;
95  }
96  }
97 
99  }
100 }
101 
102 
103 void Foam::blockDescriptor::findCurvedFaces()
104 {
105  const faceList shapeFaces(blockShape().faces());
106 
107  forAll(shapeFaces, shapeFacei)
108  {
109  forAll(blockFaces_, facei)
110  {
111  if
112  (
114  (
115  blockFaces_[facei].vertices(),
116  shapeFaces[shapeFacei]
117  )
118  )
119  {
120  curvedFaces_[shapeFacei] = facei;
121  nCurvedFaces_++;
122  break;
123  }
124  }
125  }
126 }
127 
128 
129 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
130 
132 (
133  const cellShape& bshape,
134  const pointField& vertices,
135  const blockEdgeList& edges,
136  const blockFaceList& faces,
137  const labelVector& density,
139  const word& zoneName
140 )
141 :
142  ijkMesh(density),
143  vertices_(vertices),
144  blockEdges_(edges),
145  blockFaces_(faces),
146  blockShape_(bshape),
147  expand_(expand),
148  zoneName_(zoneName),
149  curvedFaces_(-1),
150  nCurvedFaces_(0)
151 {
152  if (expand_.empty())
153  {
154  expand_.resize(12, gradingDescriptors());
155  }
156  else if (expand_.size() != 12)
157  {
159  << "Unknown definition of expansion ratios"
160  << exit(FatalError);
161  }
162 
163  findCurvedFaces();
164 }
165 
166 
168 (
169  const dictionary& dict,
170  const label index,
171  const pointField& vertices,
172  const blockEdgeList& edges,
173  const blockFaceList& faces,
174  Istream& is
175 )
176 :
177  ijkMesh(),
178  vertices_(vertices),
179  blockEdges_(edges),
180  blockFaces_(faces),
181  expand_(12, gradingDescriptors()),
182  zoneName_(),
183  curvedFaces_(-1),
184  nCurvedFaces_(0)
185 {
186  // Read cell model and list of vertices (potentially with variables)
187  word model(is);
188  blockShape_ = cellShape
189  (
190  model,
191  blockMeshTools::read<label>
192  (
193  is,
194  dict.subOrEmptyDict("namedVertices")
195  )
196  );
197 
198  // Examine next token
199  token t(is);
200 
201  // Optional zone name
202  if (t.isWord())
203  {
204  zoneName_ = t.wordToken();
205 
206  // Examine next token
207  is >> t;
208  }
209  is.putBack(t);
210 
211  if (t.isPunctuation())
212  {
213  // New-style: read a list of 3 values
214  if (t.pToken() == token::BEGIN_LIST)
215  {
216  is >> ijkMesh::sizes();
217  }
218  else
219  {
221  << "incorrect token while reading n, expected '(', found "
222  << t.info()
223  << exit(FatalIOError);
224  }
225  }
226  else
227  {
228  // Old-style: read three labels
229  is >> ijkMesh::sizes().x()
230  >> ijkMesh::sizes().y()
231  >> ijkMesh::sizes().z();
232  }
233 
234  is >> t;
235  if (!t.isWord())
236  {
237  is.putBack(t);
238  }
239 
240  List<gradingDescriptors> expRatios(is);
241 
242  if (expRatios.size() == 1)
243  {
244  // Identical in x/y/z-directions
245  expand_ = expRatios[0];
246  }
247  else if (expRatios.size() == 3)
248  {
249  // x-direction
250  expand_[0] = expRatios[0];
251  expand_[1] = expRatios[0];
252  expand_[2] = expRatios[0];
253  expand_[3] = expRatios[0];
254 
255  // y-direction
256  expand_[4] = expRatios[1];
257  expand_[5] = expRatios[1];
258  expand_[6] = expRatios[1];
259  expand_[7] = expRatios[1];
260 
261  // z-direction
262  expand_[8] = expRatios[2];
263  expand_[9] = expRatios[2];
264  expand_[10] = expRatios[2];
265  expand_[11] = expRatios[2];
266  }
267  else if (expRatios.size() == 12)
268  {
269  expand_ = expRatios;
270  }
271  else
272  {
274  << "Unknown definition of expansion ratios: " << expRatios
275  << exit(FatalIOError);
276  }
277 
278  check(is);
279 
280  findCurvedFaces();
281 }
282 
283 
284 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
285 
288 {
289  const label ni = sizes().x();
290  const label nj = sizes().y();
291  const label nk = sizes().z();
292 
293  // Caches points for curvature correction
294  FixedList<pointField, 6> facePoints;
295 
296  facePoints[0].setSize((nj + 1)*(nk + 1));
297  facePoints[1].setSize((nj + 1)*(nk + 1));
298 
299  for (label j=0; j<=nj; j++)
300  {
301  for (label k=0; k<=nk; k++)
302  {
303  facePoints[0][facePointLabel(0, j, k)] =
304  points[pointLabel(0, j, k)];
305  facePoints[1][facePointLabel(1, j, k)] =
306  points[pointLabel(ni, j, k)];
307  }
308  }
309 
310  facePoints[2].setSize((ni + 1)*(nk + 1));
311  facePoints[3].setSize((ni + 1)*(nk + 1));
312 
313  for (label i=0; i<=ni; i++)
314  {
315  for (label k=0; k<=nk; k++)
316  {
317  facePoints[2][facePointLabel(2, i, k)] =
318  points[pointLabel(i, 0, k)];
319  facePoints[3][facePointLabel(3, i, k)] =
320  points[pointLabel(i, nj, k)];
321  }
322  }
323 
324  facePoints[4].setSize((ni + 1)*(nj + 1));
325  facePoints[5].setSize((ni + 1)*(nj + 1));
326 
327  for (label i=0; i<=ni; i++)
328  {
329  for (label j=0; j<=nj; j++)
330  {
331  facePoints[4][facePointLabel(4, i, j)] =
332  points[pointLabel(i, j, 0)];
333  facePoints[5][facePointLabel(5, i, j)] =
334  points[pointLabel(i, j, nk)];
335  }
336  }
337 
338  return facePoints;
339 }
340 
341 
343 (
344  FixedList<pointField, 6>& facePoints
345 ) const
346 {
347  forAll(curvedFaces_, blockFacei)
348  {
349  if (curvedFaces_[blockFacei] != -1)
350  {
351  blockFaces_[curvedFaces_[blockFacei]].project
352  (
353  *this,
354  blockFacei,
355  facePoints[blockFacei]
356  );
357  }
358  }
359 }
360 
361 
363 (
364  Ostream& os,
365  const label val,
366  const dictionary& d
367 )
368 {
369  const dictionary* varDictPtr = d.findDict("namedBlocks");
370  if (varDictPtr)
371  {
372  blockMeshTools::write(os, val, *varDictPtr);
373  }
374  else
375  {
376  os << val;
377  }
378 }
379 
380 
381 // * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * //
382 
384 {
385  const cellShape& bshape = bd.blockShape();
386  const labelList& blockLabels = bshape;
387 
388  os << bshape.model().name() << " (";
389 
390  forAll(blockLabels, labeli)
391  {
392  if (labeli)
393  {
394  os << ' ';
395  }
396  os << blockLabels[labeli];
397  }
398  os << ')';
399 
400  if (bd.zoneName().size())
401  {
402  os << ' ' << bd.zoneName();
403  }
404 
405  os << ' ' << bd.density()
406  << " simpleGrading (";
407 
408 
410 
411  // Can we use a compact notation?
412  if
413  (
414  // x-direction
415  (
416  expand[0] == expand[1]
417  && expand[0] == expand[2]
418  && expand[0] == expand[3]
419  )
420  && // y-direction
421  (
422  expand[4] == expand[5]
423  && expand[4] == expand[6]
424  && expand[4] == expand[7]
425  )
426  && // z-direction
427  (
428  expand[8] == expand[9]
429  && expand[8] == expand[10]
430  && expand[8] == expand[11]
431  )
432  )
433  {
434  os << expand[0] << ' ' << expand[4] << ' ' << expand[8];
435  }
436  else
437  {
438  forAll(expand, edgei)
439  {
440  if (edgei)
441  {
442  os << ' ';
443  }
444  os << expand[edgei];
445  }
446  }
447 
448 
449  os << ")";
450 
451  return os;
452 }
453 
454 
455 Foam::Ostream& Foam::operator<<
456 (
457  Ostream& os,
458  const InfoProxy<blockDescriptor>& iproxy
459 )
460 {
461  const blockDescriptor& bd = iproxy.t_;
462 
463  os << "Dimensions:" << bd.density()
464  << " nPoints:" << bd.nPoints()
465  << " nCells:" << bd.nCells()
466  << " nFaces:" << bd.nFaces()
467  << " nInternalFaces:" << bd.nInternalFaces()
468  << nl;
469 
470  return os;
471 }
472 
473 
474 // ************************************************************************* //
Foam::ijkMesh::nFaces
label nFaces() const
The total number of mesh faces in the i-j-k mesh.
Definition: ijkMeshI.H:74
Foam::dictionary::findDict
dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary pointer if present.
Definition: dictionary.C:508
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::InfoProxy
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:47
Foam::blockDescriptor::blockShape
const cellShape & blockShape() const
Return the block shape.
Definition: blockDescriptorI.H:43
Foam::blockDescriptor::write
static void write(Ostream &, const label blocki, const dictionary &)
Write block index with dictionary lookup.
Definition: blockDescriptor.C:363
Foam::ijkAddressing::sizes
const labelVector & sizes() const
The (i,j,k) addressing dimensions.
Definition: ijkAddressingI.H:69
Foam::face::sameVertices
static bool sameVertices(const face &a, const face &b)
Return true if the faces have the same vertices.
Definition: face.C:402
Foam::boolList
List< bool > boolList
A List of bools.
Definition: List.H:69
Foam::blockDescriptor::zoneName
const word & zoneName() const
Return the (optional) zone name.
Definition: blockDescriptorI.H:62
Foam::FatalIOError
IOerror FatalIOError
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::gradingDescriptors
List of gradingDescriptor for the sections of a block with additional IO functionality.
Definition: gradingDescriptors.H:58
Foam::blockMeshTools::write
void write(Ostream &, const label, const dictionary &)
Write with dictionary lookup.
Definition: blockMeshTools.C:88
blockDescriptor.H
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::token::pToken
punctuationToken pToken() const
Return punctuation character.
Definition: tokenI.H:459
Foam::token::isWord
bool isWord() const noexcept
Token is WORD or DIRECTIVE word.
Definition: tokenI.H:583
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::stringOps::expand
string expand(const std::string &s, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Definition: stringOps.C:720
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::ijkMesh
A simple i-j-k (row-major order) to linear addressing for a rectilinear mesh. Since the underlying me...
Definition: ijkMesh.H:53
Foam::Field< vector >
Foam::token::info
InfoProxy< token > info() const
Return info proxy for printing token information to a stream.
Definition: token.H:551
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::token::isPunctuation
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:453
Foam::PtrList< blockEdge >
Foam::blockDescriptor::grading
const List< gradingDescriptors > & grading() const
Expansion ratios in all directions.
Definition: blockDescriptorI.H:56
Foam::blockDescriptor::facePoints
FixedList< pointField, 6 > facePoints(const pointField &points) const
Return the list of face-points for all of the faces of the block.
Definition: blockDescriptor.C:287
Foam::blockDescriptor::correctFacePoints
void correctFacePoints(FixedList< pointField, 6 > &) const
Correct the location of the given face-points.
Definition: blockDescriptor.C:343
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::vertices
pointField vertices(const blockVertexList &bvl)
Definition: blockVertexList.H:49
Foam::ijkMesh::nInternalFaces
label nInternalFaces() const
The number of internal faces in the i-j-k mesh.
Definition: ijkMeshI.H:92
Foam::FixedList::setSize
void setSize(const label n)
Dummy function, to make FixedList consistent with List.
Definition: FixedListI.H:331
Foam::cellShape
An analytical geometric cellShape.
Definition: cellShape.H:69
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::token::wordToken
const word & wordToken() const
Return const reference to the word contents.
Definition: tokenI.H:599
Foam::dictionary::subOrEmptyDict
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Definition: dictionary.C:608
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::cellModel::name
const word & name() const noexcept
Return model name.
Definition: cellModelI.H:31
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
blockMeshTools.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::ijkMesh::nCells
label nCells() const
The number of mesh cells (nx*ny*nz) in the i-j-k mesh.
Definition: ijkMeshI.H:68
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::Vector< label >
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
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::Istream::putBack
void putBack(const token &tok)
Put back token.
Definition: Istream.C:53
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
Foam::token::SPACE
Space [isspace].
Definition: token.H:117
Foam::UList
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:103
points
const pointField & points
Definition: gmvOutputHeader.H:1
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::blockDescriptor::blockDescriptor
blockDescriptor(const blockDescriptor &)=default
Copy construct.
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::blockDescriptor::density
const labelVector & density() const
Return the mesh density (number of cells) in the i,j,k directions.
Definition: blockDescriptorI.H:49
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:122
Foam::blockDescriptor
Takes the description of the block and the list of curved edges and creates a list of points on edges...
Definition: blockDescriptor.H:78
Foam::cellShape::model
const cellModel & model() const
Model reference.
Definition: cellShapeI.H:126