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