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 | Copyright (C) 2011-2016 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 "error.H"
27 #include "blockDescriptor.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 (
33  const cellShape& bshape,
34  const pointField& blockPointField,
35  const curvedEdgeList& edges,
36  const Vector<label>& meshDensity,
37  const UList<gradingDescriptors>& expand,
38  const word& zoneName
39 )
40 :
41  blockPointField_(blockPointField),
42  curvedEdges_(edges),
43  blockShape_(bshape),
44  meshDensity_(meshDensity),
45  edgePoints_(12),
46  edgeWeights_(12),
47  expand_(expand),
48  zoneName_(zoneName)
49 {
50  if (expand_.size() != 12)
51  {
53  << "Unknown definition of expansion ratios"
54  << exit(FatalError);
55  }
56 
57  // Create a list of edges
58  makeBlockEdges();
59 }
60 
61 
63 (
64  const pointField& blockPointField,
65  const curvedEdgeList& edges,
66  Istream& is
67 )
68 :
69  blockPointField_(blockPointField),
70  curvedEdges_(edges),
71  blockShape_(is),
72  meshDensity_(),
73  edgePoints_(12),
74  edgeWeights_(12),
75  expand_
76  (
77  12,
79  ),
80  zoneName_()
81 {
82  // Examine next token
83  token t(is);
84 
85  // Optional zone name
86  if (t.isWord())
87  {
88  zoneName_ = t.wordToken();
89 
90  // Examine next token
91  is >> t;
92  }
93  is.putBack(t);
94 
95  if (t.isPunctuation())
96  {
97  // New-style: read a list of 3 values
98  if (t.pToken() == token::BEGIN_LIST)
99  {
100  is >> meshDensity_;
101  }
102  else
103  {
105  (
106  is
107  ) << "incorrect token while reading n, expected '(', found "
108  << t.info()
109  << exit(FatalIOError);
110  }
111  }
112  else
113  {
114  // Old-style: read three labels
115  is >> meshDensity_.x()
116  >> meshDensity_.y()
117  >> meshDensity_.z();
118  }
119 
120  is >> t;
121  if (!t.isWord())
122  {
123  is.putBack(t);
124  }
125 
126  List<gradingDescriptors> expRatios(is);
127 
128  if (expRatios.size() == 1)
129  {
130  // Identical in x/y/z-directions
131  expand_ = expRatios[0];
132  }
133  else if (expRatios.size() == 3)
134  {
135  // x-direction
136  expand_[0] = expRatios[0];
137  expand_[1] = expRatios[0];
138  expand_[2] = expRatios[0];
139  expand_[3] = expRatios[0];
140 
141  // y-direction
142  expand_[4] = expRatios[1];
143  expand_[5] = expRatios[1];
144  expand_[6] = expRatios[1];
145  expand_[7] = expRatios[1];
146 
147  // z-direction
148  expand_[8] = expRatios[2];
149  expand_[9] = expRatios[2];
150  expand_[10] = expRatios[2];
151  expand_[11] = expRatios[2];
152  }
153  else if (expRatios.size() == 12)
154  {
155  expand_ = expRatios;
156  }
157  else
158  {
160  << "Unknown definition of expansion ratios: " << expRatios
161  << exit(FatalError);
162  }
163 
164  // Create a list of edges
165  makeBlockEdges();
166 }
167 
168 
169 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
170 
172 {}
173 
174 
175 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
176 
178 {
179  return blockPointField_;
180 }
181 
182 
184 {
185  return blockShape_;
186 }
187 
188 
191 {
192  return edgePoints_;
193 }
194 
195 
197 {
198  return edgeWeights_;
199 }
200 
201 
203 {
204  return meshDensity_;
205 }
206 
207 
209 {
210  return zoneName_;
211 }
212 
213 
215 {
216  return
217  (
218  (meshDensity_.x() + 1)
219  * (meshDensity_.y() + 1)
220  * (meshDensity_.z() + 1)
221  );
222 }
223 
224 
226 {
227  return
228  (
229  meshDensity_.x()
230  * meshDensity_.y()
231  * meshDensity_.z()
232  );
233 }
234 
235 
237 {
238  return blockPointField_[blockShape_[i]];
239 }
240 
241 
242 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
243 
245 {
246  const cellShape& bshape = bd.blockShape();
247  const labelList& blockLabels = bshape;
248 
249  os << bshape.model().name() << " (";
250 
251  forAll(blockLabels, labelI)
252  {
253  if (labelI)
254  {
255  os << ' ';
256  }
257  os << blockLabels[labelI];
258  }
259  os << ')';
260 
261  if (bd.zoneName().size())
262  {
263  os << ' ' << bd.zoneName();
264  }
265 
266  os << ' ' << bd.meshDensity()
267  << " simpleGrading (";
268 
269 
270  const List<gradingDescriptors>& expand = bd.expand_;
271 
272  // Can we use a compact notation?
273  if
274  (
275  // x-direction
276  (
277  expand[0] == expand[1]
278  && expand[0] == expand[2]
279  && expand[0] == expand[3]
280  )
281  && // y-direction
282  (
283  expand[4] == expand[5]
284  && expand[4] == expand[6]
285  && expand[4] == expand[7]
286  )
287  && // z-direction
288  (
289  expand[8] == expand[9]
290  && expand[8] == expand[10]
291  && expand[8] == expand[11]
292  )
293  )
294  {
295  os << expand[0] << ' ' << expand[4] << ' ' << expand[8];
296  }
297  else
298  {
299  forAll(expand, edgeI)
300  {
301  if (edgeI)
302  {
303  os << ' ';
304  }
305  os << expand[edgeI];
306  }
307  }
308 
309 
310  os << ")";
311 
312  return os;
313 }
314 
315 
316 // ************************************************************************* //
const cellModel & model() const
Model reference.
Definition: cellShapeI.H:88
const Cmpt & z() const
Definition: VectorI.H:87
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
const scalarListList & blockEdgeWeights() const
Return the weightings along each edge.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const Cmpt & x() const
Definition: VectorI.H:75
error FatalError
#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:59
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:76
A token holds items read from Istream.
Definition: token.H:69
void putBack(const token &)
Put back token.
Definition: Istream.C:30
const word & name() const
Return model name.
Definition: cellModelI.H:38
const cellShape & blockShape() const
Return the block shape.
const Vector< label > & meshDensity() const
Return the mesh density (number of cells) in the i,j,k directions.
const point & blockPoint(const label i) const
Return block point at local label i.
static const labelSphericalTensor labelI(1)
Identity labelTensor.
bool isWord() const
Definition: tokenI.H:213
label nPoints() const
Return the number of points.
blockDescriptor(const cellShape &, const pointField &blockPointField, const curvedEdgeList &, const Vector< label > &meshDensity, const UList< gradingDescriptors > &expand, const word &zoneName="")
Construct from components. Optional cellSet/zone name.
A class for handling words, derived from string.
Definition: word.H:59
punctuationToken pToken() const
Definition: tokenI.H:200
const Cmpt & y() const
Definition: VectorI.H:81
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
~blockDescriptor()
Destructor.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const word & zoneName() const
Return the (optional) zone name.
const pointField & blockPointField() const
Reference to point field defining the block mesh.
label nCells() const
Return the number of cells.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:374
Ostream & operator<<(Ostream &, const ensightPart &)
const word & wordToken() const
Definition: tokenI.H:218
const List< List< point > > & blockEdgePoints() const
Return the block points along each edge.
bool isPunctuation() const
Definition: tokenI.H:195
List of gradingDescriptor for the sections of a block with additional IO functionality.
IOerror FatalIOError