ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / mesh / blockMesh / blockDescriptor / blockDescriptor.C
blob7fd7ad315b4ea3bf30860330e3c7005cdc11c4ce
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "error.H"
27 #include "blockDescriptor.H"
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 Foam::blockDescriptor::blockDescriptor
33     const cellShape& bshape,
34     const pointField& blockPointField,
35     const curvedEdgeList& edges,
36     const Vector<label>& meshDensity,
37     const UList<scalar>& expand,
38     const word& zoneName
41     blockPointField_(blockPointField),
42     curvedEdges_(edges),
43     blockShape_(bshape),
44     meshDensity_(meshDensity),
45     edgePoints_(12),
46     edgeWeights_(12),
47     expand_(expand),
48     zoneName_(zoneName)
50     if (expand_.size() != 12)
51     {
52         FatalErrorIn
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     }
62     // create a list of edges
63     makeBlockEdges();
67 Foam::blockDescriptor::blockDescriptor
69     const pointField& blockPointField,
70     const curvedEdgeList& edges,
71     Istream& is
74     blockPointField_(blockPointField),
75     curvedEdges_(edges),
76     blockShape_(is),
77     meshDensity_(),
78     edgePoints_(12),
79     edgeWeights_(12),
80     expand_(12, 1.0),
81     zoneName_()
83     // Examine next token
84     token t(is);
86     // Optional zone name
87     if (t.isWord())
88     {
89         zoneName_ = t.wordToken();
91         // Examine next token
92         is >> t;
93     }
94     is.putBack(t);
96     if (t.isPunctuation())
97     {
98         // new-style: read a list of 3 values
99         if (t.pToken() == token::BEGIN_LIST)
100         {
101             is >> meshDensity_;
102         }
103         else
104         {
105             FatalIOErrorIn
106             (
107                 "blockDescriptor::blockDescriptor"
108                 "(const pointField&, const curvedEdgeList&, Istream&)",
109                 is
110             )   << "incorrect token while reading n, expected '(', found "
111                 << t.info()
112                 << exit(FatalIOError);
113         }
114     }
115     else
116     {
117         // old-style: read three labels
118         is  >> meshDensity_.x()
119             >> meshDensity_.y()
120             >> meshDensity_.z();
121     }
123     is >> t;
124     if (!t.isWord())
125     {
126         is.putBack(t);
127     }
129     scalarList expRatios(is);
131     if (expRatios.size() == 1)
132     {
133         // identical in x/y/z-directions
134         expand_ = expRatios[0];
135     }
136     else if (expRatios.size() == 3)
137     {
138         // x-direction
139         expand_[0]  = expRatios[0];
140         expand_[1]  = expRatios[0];
141         expand_[2]  = expRatios[0];
142         expand_[3]  = expRatios[0];
144         // y-direction
145         expand_[4]  = expRatios[1];
146         expand_[5]  = expRatios[1];
147         expand_[6]  = expRatios[1];
148         expand_[7]  = expRatios[1];
150         // z-direction
151         expand_[8]  = expRatios[2];
152         expand_[9]  = expRatios[2];
153         expand_[10] = expRatios[2];
154         expand_[11] = expRatios[2];
155     }
156     else if (expRatios.size() == 12)
157     {
158         expand_ = expRatios;
159     }
160     else
161     {
162         FatalErrorIn
163         (
164             "blockDescriptor::blockDescriptor"
165             "(const pointField&, const curvedEdgeList&, Istream&)"
166         )   << "Unknown definition of expansion ratios: " << expRatios
167             << exit(FatalError);
168     }
170     // create a list of edges
171     makeBlockEdges();
175 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
177 Foam::blockDescriptor::~blockDescriptor()
181 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
183 const Foam::pointField& Foam::blockDescriptor::blockPointField() const
185     return blockPointField_;
189 const Foam::cellShape& Foam::blockDescriptor::blockShape() const
191     return blockShape_;
195 const Foam::List< Foam::List< Foam::point > >&
196 Foam::blockDescriptor::blockEdgePoints() const
198     return edgePoints_;
202 const Foam::scalarListList& Foam::blockDescriptor::blockEdgeWeights() const
204     return edgeWeights_;
208 const Foam::Vector<Foam::label>& Foam::blockDescriptor::meshDensity() const
210     return meshDensity_;
214 const Foam::word& Foam::blockDescriptor::zoneName() const
216     return zoneName_;
220 Foam::label Foam::blockDescriptor::nPoints() const
222     return
223     (
224         (meshDensity_.x() + 1)
225       * (meshDensity_.y() + 1)
226       * (meshDensity_.z() + 1)
227     );
231 Foam::label Foam::blockDescriptor::nCells() const
233     return
234     (
235         meshDensity_.x()
236       * meshDensity_.y()
237       * meshDensity_.z()
238     );
242 const Foam::point& Foam::blockDescriptor::blockPoint(const label i) const
244     return blockPointField_[blockShape_[i]];
248 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
250 Foam::Ostream& Foam::operator<<(Ostream& os, const blockDescriptor& bd)
252     const cellShape& bshape = bd.blockShape();
253     const labelList& blockLabels = bshape;
255     os  << bshape.model().name() << " (";
257     forAll(blockLabels, labelI)
258     {
259         if (labelI)
260         {
261             os  << ' ';
262         }
263         os  << blockLabels[labelI];
264     }
265     os  << ')';
267     if (bd.zoneName().size())
268     {
269         os  << ' ' << bd.zoneName();
270     }
272     os  << ' '  << bd.meshDensity()
273         << " simpleGrading (";
276     const scalarList& expand = bd.expand_;
278     // can we use a compact notation?
279     if
280     (
281         // x-direction
282         (
283             expand[0] == expand[1]
284          && expand[0] == expand[2]
285          && expand[0] == expand[3]
286         )
287      && // y-direction
288         (
289             expand[4] == expand[5]
290          && expand[4] == expand[6]
291          && expand[4] == expand[7]
292         )
293      && // z-direction
294         (
295             expand[8] == expand[9]
296          && expand[8] == expand[10]
297          && expand[8] == expand[11]
298         )
299     )
300     {
301         os  << expand[0] << ' ' << expand[4] << ' ' << expand[8];
302     }
303     else
304     {
305         forAll(expand, edgeI)
306         {
307             if (edgeI)
308             {
309                 os  << ' ';
310             }
311             os  << expand[edgeI];
312         }
313     }
316     os  << ")";
318     return os;
322 // ************************************************************************* //